Commit d3a3a264d7ac860fec17fb3a32912032db209cf3

Authored by Colomban Wendling
1 parent 6d6ceb51

Revert ATSPI event handling logic changes

We don't want to introduce behavioral changes here yet, so revert
changes doing so.
Showing 1 changed file with 21 additions and 87 deletions   Show diff stats
plugins/focuspoll/src/accessibilitywatcher.cpp
... ... @@ -260,26 +260,13 @@ AccessibilityWatcher::registerEvent (const AtspiEvent *event, const gchar *type)
260 260 {
261 261 // prevents skipping events that are not designated as active. we check the activeness of parents.
262 262 auto parent = unique_gobject (atspi_accessible_get_parent (event->source, NULL));
263   - while (parent.get ())
  263 + while (!res->active && parent.get ())
264 264 {
265 265 auto stateSet = unique_gobject (atspi_accessible_get_state_set (parent.get ()));
266 266 if (atspi_state_set_contains (stateSet.get (), ATSPI_STATE_ACTIVE))
267 267 {
268 268 res->active = true;
269 269 }
270   - if (atspi_state_set_contains (stateSet.get (), ATSPI_STATE_EXPANDABLE))
271   - {
272   - if (!atspi_state_set_contains (stateSet.get (), ATSPI_STATE_EXPANDED))
273   - {
274   - auto role = unique_gmem (atspi_accessible_get_role_name (parent.get (), NULL));
275   - if (!strcmp (role.get (), "menu"))
276   - {
277   - // parent is expandable but not expanded, we do not want to track what is happening inside
278   - delete (res);
279   - return;
280   - }
281   - }
282   - }
283 270 auto child = unique_gobject (atspi_accessible_get_parent (parent.get (), NULL));
284 271 if (child.get () == parent.get ())
285 272 {
... ... @@ -294,48 +281,7 @@ AccessibilityWatcher::registerEvent (const AtspiEvent *event, const gchar *type)
294 281  
295 282 if (strcmp (res->type, "active-descendant-changed") == 0)
296 283 {
297   - component_target = unique_gobject (atspi_accessible_get_child_at_index (component_target.get (), event->detail1, NULL));
298   - if (!component_target.get ())
299   - {
300   - delete (res);
301   - return;
302   - }
303   - }
304   -
305   - if (strcmp (unique_gmem (atspi_accessible_get_role_name (component_target.get (), NULL)).get (), "tree table") == 0)
306   - {
307   - // This is a table, it is not generally useful to look at the whole
308   - // table, but rather just at the selected file, if any, otherwise the first
309   - // file, if any.
310   - decltype (component_target) sub_target = NULL;
311   - auto selection = unique_gobject (atspi_accessible_get_selection_iface (component_target.get ()));
312   -
313   - if (selection.get ())
314   - {
315   - sub_target = unique_gobject (atspi_selection_get_selected_child (selection.get (), 0, NULL));
316   - }
317   -
318   - if (sub_target.get () == NULL)
319   - {
320   - // No selection, try to get first real child.
321   - unsigned i = 0;
322   -
323   - while (1) {
324   - sub_target = unique_gobject (atspi_accessible_get_child_at_index (component_target.get (), i, NULL));
325   - i++;
326   -
327   - if (sub_target.get () == NULL)
328   - // No other children than table column header
329   - break;
330   -
331   - if (strcmp (unique_gmem (atspi_accessible_get_role_name (sub_target.get (), NULL)).get (), "table column header") != 0)
332   - // Found a real child
333   - break;
334   - }
335   - }
336   -
337   - if (sub_target.get ())
338   - component_target = unique_gobject_ref (sub_target.get ());
  284 + component_target = unique_gobject (atspi_accessible_get_child_at_index (event->source, event->detail1, NULL));
339 285 }
340 286  
341 287 auto component = unique_gobject (atspi_accessible_get_component (component_target.get ()));
... ... @@ -368,11 +314,8 @@ AccessibilityWatcher::registerEvent (const AtspiEvent *event, const gchar *type)
368 314 res->w = size.get ()->width;
369 315 res->h = size.get ()->height;
370 316 }
371   - // correcting a missing offset when caret is at end of text
372   - if (((res->x == 0 && res->y == 0) ||
373   - res->x + res->w < 0 ||
374   - res->y + res->h < 0)
375   - && offset > 0)
  317 + // correcting a missing offset to a caret move event in firefox
  318 + if (res->x == 0 && res->y == 0 && offset > 0)
376 319 {
377 320 auto size = unique_gmem (atspi_text_get_character_extents (text.get (), offset-1, ATSPI_COORD_TYPE_SCREEN, NULL));
378 321 res->x = size.get ()->x;
... ... @@ -455,8 +398,7 @@ AccessibilityWatcher::appSpecificFilter (FocusInfo *focus, const AtspiEvent* eve
455 398 (strcmp (focus->role, "menu item") == 0 ||
456 399 strcmp (focus->role, "menu") == 0 ||
457 400 strcmp (focus->role, "check menu item") == 0 ||
458   - strcmp (focus->role, "radio menu item") == 0 ||
459   - strcmp (focus->role, "tearoff menu item") == 0) &&
  401 + strcmp (focus->role, "radio menu item") == 0) &&
460 402 strcmp (focus->application, "mate-panel") != 0)
461 403 {
462 404 if (!focus->selected && returnToPrevMenu ())
... ... @@ -486,12 +428,12 @@ AccessibilityWatcher::appSpecificFilter (FocusInfo *focus, const AtspiEvent* eve
486 428 {
487 429 auto text = unique_gobject (atspi_accessible_get_text (event->source)); // next if deals with a special newline char, that remained buggy. hypra issue #430
488 430 auto offset = atspi_text_get_caret_offset (text.get (), NULL);
489   - auto string = unique_gmem (atspi_text_get_string_at_offset (text.get (), offset, ATSPI_TEXT_GRANULARITY_CHAR, NULL));
490   - auto stringM1 = unique_gmem (atspi_text_get_string_at_offset (text.get (), offset - 1, ATSPI_TEXT_GRANULARITY_CHAR, NULL));
  431 + auto string = unique_gmem (atspi_text_get_text_at_offset (text.get (), offset, ATSPI_TEXT_BOUNDARY_CHAR, NULL));
  432 + auto stringM1 = unique_gmem (atspi_text_get_text_at_offset (text.get (), offset - 1, ATSPI_TEXT_BOUNDARY_CHAR, NULL));
491 433 gchar character = string.get ()->content[0];
492 434 gchar characterM1 = stringM1.get ()->content[0];
493 435  
494   - if (offset == atspi_text_get_character_count (text.get (), NULL) && character == '\0' && characterM1 == '\n')
  436 + if (offset == atspi_text_get_character_count (text.get (), NULL) && character == '\0' && (characterM1 == '\n' || int(characterM1) == -17))
495 437 {
496 438 getAlternativeCaret (focus, event);
497 439 focus->x = focus->xAlt;
... ... @@ -591,28 +533,11 @@ AccessibilityWatcher::filterBadEvents (const FocusInfo *event)
591 533 {
592 534 return true;
593 535 }
594   - if (event->w < 0 ||
595   - event->h < 0)
596   - {
597   - return true;
598   - }
599   - if (event->x == 0 &&
600   - event->y == 0 &&
601   - event->w == 0 &&
602   - event->h == 0)
603   - {
604   - return true;
605   - }
606   - if (event->x + event->w < 0 ||
607   - event->y + event->h < 0)
608   - {
609   - return true;
610   - }
611 536 if (getScreenWidth () != 0 && getScreenHeight () != 0 &&
612 537 (event->x > getScreenWidth () ||
613 538 event->y > getScreenHeight () ||
614   - event->w > getScreenWidth () ||
615   - event->h > getScreenHeight ()))
  539 + event->x < 0 ||
  540 + event->y < 0))
616 541 {
617 542 return true;
618 543 }
... ... @@ -772,6 +697,7 @@ AccessibilityWatcher::getAlternativeCaret (FocusInfo *focus, const AtspiEvent* e
772 697 auto offset = atspi_text_get_caret_offset (text.get (), NULL);
773 698 auto string = unique_gmem (atspi_text_get_string_at_offset (text.get (), offset, ATSPI_TEXT_GRANULARITY_CHAR, NULL));
774 699 gchar caretChar = string.get ()->content[0];
  700 + bool hasSeenDeviceControl1 = false;
775 701  
776 702 // if we're at a newline, sometimes at-spi isn't giving us a caret position. unknown bug in some apps.
777 703 if (caretChar == '\n' || caretChar == '\0')
... ... @@ -788,7 +714,7 @@ AccessibilityWatcher::getAlternativeCaret (FocusInfo *focus, const AtspiEvent* e
788 714 string = unique_gmem (atspi_text_get_string_at_offset (text.get (), offset - charIndex, ATSPI_TEXT_GRANULARITY_CHAR, NULL));
789 715 caretChar = string.get ()->content[0];
790 716 // if we found a caret, check we're at beginning of line (or of text) to extrapolate position
791   - if (size.get ()->x != 0 || size.get ()->y != 0)
  717 + if ((size.get ()->x != 0 || size.get ()->y != 0) && int(caretChar) != -17)
792 718 {
793 719 if (offset - charIndex -1 >= 0 && unique_gmem (atspi_text_get_string_at_offset (text.get (), offset - charIndex -1, ATSPI_TEXT_GRANULARITY_CHAR, NULL)).get ()->content[0] == '\n')
794 720 {
... ... @@ -801,12 +727,20 @@ AccessibilityWatcher::getAlternativeCaret (FocusInfo *focus, const AtspiEvent* e
801 727 charExtentsFound = true;
802 728 }
803 729 }
804   - else if (caretChar == '\n')
  730 + else if (caretChar == '\n' || int (caretChar) == -17)
805 731 {
806 732 ++lines;
807 733 }
  734 + if (!hasSeenDeviceControl1 && int (caretChar) == -17 )
  735 + {
  736 + hasSeenDeviceControl1 = true;
  737 + }
808 738 ++charIndex;
809 739 }
  740 + if (!hasSeenDeviceControl1)
  741 + {
  742 + lines--;
  743 + }
810 744 focus->xAlt = size.get ()->x;
811 745 focus->yAlt = size.get ()->y + (lines-1) * size.get ()->height;
812 746 focus->wAlt = size.get ()->width;
... ...