From d3a3a264d7ac860fec17fb3a32912032db209cf3 Mon Sep 17 00:00:00 2001 From: Colomban Wendling Date: Thu, 21 Mar 2019 16:46:30 +0100 Subject: [PATCH] Revert ATSPI event handling logic changes We don't want to introduce behavioral changes here yet, so revert changes doing so. --- .../focuspoll/src/accessibilitywatcher.cpp | 108 ++++-------------- 1 file changed, 21 insertions(+), 87 deletions(-) diff --git a/plugins/focuspoll/src/accessibilitywatcher.cpp b/plugins/focuspoll/src/accessibilitywatcher.cpp index d62784d0f..41844a99b 100644 --- a/plugins/focuspoll/src/accessibilitywatcher.cpp +++ b/plugins/focuspoll/src/accessibilitywatcher.cpp @@ -260,26 +260,13 @@ AccessibilityWatcher::registerEvent (const AtspiEvent *event, const gchar *type) { // prevents skipping events that are not designated as active. we check the activeness of parents. auto parent = unique_gobject (atspi_accessible_get_parent (event->source, NULL)); - while (parent.get ()) + while (!res->active && parent.get ()) { auto stateSet = unique_gobject (atspi_accessible_get_state_set (parent.get ())); if (atspi_state_set_contains (stateSet.get (), ATSPI_STATE_ACTIVE)) { res->active = true; } - if (atspi_state_set_contains (stateSet.get (), ATSPI_STATE_EXPANDABLE)) - { - if (!atspi_state_set_contains (stateSet.get (), ATSPI_STATE_EXPANDED)) - { - auto role = unique_gmem (atspi_accessible_get_role_name (parent.get (), NULL)); - if (!strcmp (role.get (), "menu")) - { - // parent is expandable but not expanded, we do not want to track what is happening inside - delete (res); - return; - } - } - } auto child = unique_gobject (atspi_accessible_get_parent (parent.get (), NULL)); if (child.get () == parent.get ()) { @@ -294,48 +281,7 @@ AccessibilityWatcher::registerEvent (const AtspiEvent *event, const gchar *type) if (strcmp (res->type, "active-descendant-changed") == 0) { - component_target = unique_gobject (atspi_accessible_get_child_at_index (component_target.get (), event->detail1, NULL)); - if (!component_target.get ()) - { - delete (res); - return; - } - } - - if (strcmp (unique_gmem (atspi_accessible_get_role_name (component_target.get (), NULL)).get (), "tree table") == 0) - { - // This is a table, it is not generally useful to look at the whole - // table, but rather just at the selected file, if any, otherwise the first - // file, if any. - decltype (component_target) sub_target = NULL; - auto selection = unique_gobject (atspi_accessible_get_selection_iface (component_target.get ())); - - if (selection.get ()) - { - sub_target = unique_gobject (atspi_selection_get_selected_child (selection.get (), 0, NULL)); - } - - if (sub_target.get () == NULL) - { - // No selection, try to get first real child. - unsigned i = 0; - - while (1) { - sub_target = unique_gobject (atspi_accessible_get_child_at_index (component_target.get (), i, NULL)); - i++; - - if (sub_target.get () == NULL) - // No other children than table column header - break; - - if (strcmp (unique_gmem (atspi_accessible_get_role_name (sub_target.get (), NULL)).get (), "table column header") != 0) - // Found a real child - break; - } - } - - if (sub_target.get ()) - component_target = unique_gobject_ref (sub_target.get ()); + component_target = unique_gobject (atspi_accessible_get_child_at_index (event->source, event->detail1, NULL)); } auto component = unique_gobject (atspi_accessible_get_component (component_target.get ())); @@ -368,11 +314,8 @@ AccessibilityWatcher::registerEvent (const AtspiEvent *event, const gchar *type) res->w = size.get ()->width; res->h = size.get ()->height; } - // correcting a missing offset when caret is at end of text - if (((res->x == 0 && res->y == 0) || - res->x + res->w < 0 || - res->y + res->h < 0) - && offset > 0) + // correcting a missing offset to a caret move event in firefox + if (res->x == 0 && res->y == 0 && offset > 0) { auto size = unique_gmem (atspi_text_get_character_extents (text.get (), offset-1, ATSPI_COORD_TYPE_SCREEN, NULL)); res->x = size.get ()->x; @@ -455,8 +398,7 @@ AccessibilityWatcher::appSpecificFilter (FocusInfo *focus, const AtspiEvent* eve (strcmp (focus->role, "menu item") == 0 || strcmp (focus->role, "menu") == 0 || strcmp (focus->role, "check menu item") == 0 || - strcmp (focus->role, "radio menu item") == 0 || - strcmp (focus->role, "tearoff menu item") == 0) && + strcmp (focus->role, "radio menu item") == 0) && strcmp (focus->application, "mate-panel") != 0) { if (!focus->selected && returnToPrevMenu ()) @@ -486,12 +428,12 @@ AccessibilityWatcher::appSpecificFilter (FocusInfo *focus, const AtspiEvent* eve { auto text = unique_gobject (atspi_accessible_get_text (event->source)); // next if deals with a special newline char, that remained buggy. hypra issue #430 auto offset = atspi_text_get_caret_offset (text.get (), NULL); - auto string = unique_gmem (atspi_text_get_string_at_offset (text.get (), offset, ATSPI_TEXT_GRANULARITY_CHAR, NULL)); - auto stringM1 = unique_gmem (atspi_text_get_string_at_offset (text.get (), offset - 1, ATSPI_TEXT_GRANULARITY_CHAR, NULL)); + auto string = unique_gmem (atspi_text_get_text_at_offset (text.get (), offset, ATSPI_TEXT_BOUNDARY_CHAR, NULL)); + auto stringM1 = unique_gmem (atspi_text_get_text_at_offset (text.get (), offset - 1, ATSPI_TEXT_BOUNDARY_CHAR, NULL)); gchar character = string.get ()->content[0]; gchar characterM1 = stringM1.get ()->content[0]; - if (offset == atspi_text_get_character_count (text.get (), NULL) && character == '\0' && characterM1 == '\n') + if (offset == atspi_text_get_character_count (text.get (), NULL) && character == '\0' && (characterM1 == '\n' || int(characterM1) == -17)) { getAlternativeCaret (focus, event); focus->x = focus->xAlt; @@ -591,28 +533,11 @@ AccessibilityWatcher::filterBadEvents (const FocusInfo *event) { return true; } - if (event->w < 0 || - event->h < 0) - { - return true; - } - if (event->x == 0 && - event->y == 0 && - event->w == 0 && - event->h == 0) - { - return true; - } - if (event->x + event->w < 0 || - event->y + event->h < 0) - { - return true; - } if (getScreenWidth () != 0 && getScreenHeight () != 0 && (event->x > getScreenWidth () || event->y > getScreenHeight () || - event->w > getScreenWidth () || - event->h > getScreenHeight ())) + event->x < 0 || + event->y < 0)) { return true; } @@ -772,6 +697,7 @@ AccessibilityWatcher::getAlternativeCaret (FocusInfo *focus, const AtspiEvent* e auto offset = atspi_text_get_caret_offset (text.get (), NULL); auto string = unique_gmem (atspi_text_get_string_at_offset (text.get (), offset, ATSPI_TEXT_GRANULARITY_CHAR, NULL)); gchar caretChar = string.get ()->content[0]; + bool hasSeenDeviceControl1 = false; // if we're at a newline, sometimes at-spi isn't giving us a caret position. unknown bug in some apps. if (caretChar == '\n' || caretChar == '\0') @@ -788,7 +714,7 @@ AccessibilityWatcher::getAlternativeCaret (FocusInfo *focus, const AtspiEvent* e string = unique_gmem (atspi_text_get_string_at_offset (text.get (), offset - charIndex, ATSPI_TEXT_GRANULARITY_CHAR, NULL)); caretChar = string.get ()->content[0]; // if we found a caret, check we're at beginning of line (or of text) to extrapolate position - if (size.get ()->x != 0 || size.get ()->y != 0) + if ((size.get ()->x != 0 || size.get ()->y != 0) && int(caretChar) != -17) { 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') { @@ -801,12 +727,20 @@ AccessibilityWatcher::getAlternativeCaret (FocusInfo *focus, const AtspiEvent* e charExtentsFound = true; } } - else if (caretChar == '\n') + else if (caretChar == '\n' || int (caretChar) == -17) { ++lines; } + if (!hasSeenDeviceControl1 && int (caretChar) == -17 ) + { + hasSeenDeviceControl1 = true; + } ++charIndex; } + if (!hasSeenDeviceControl1) + { + lines--; + } focus->xAlt = size.get ()->x; focus->yAlt = size.get ()->y + (lines-1) * size.get ()->height; focus->wAlt = size.get ()->width; -- GitLab