[GTK] ATK text-caret-moved and text-selection-changed events not being emitted
https://bugs.webkit.org/show_bug.cgi?id=76069
Reviewed by Martin Robinson.
Source/WebCore:
Fix bug introduced with patch for Bug 72830.
* accessibility/AccessibilityObject.cpp:
(WebCore::AccessibilityObject::isDescendantOfObject): New function,
to check if an accessibility object is a descendant of other object.
(WebCore::AccessibilityObject::isAncestorOfObject): New function,
to check if an accessibility object is an ancestor of other object.
* accessibility/AccessibilityObject.h:
* accessibility/gtk/AccessibilityObjectWrapperAtk.cpp:
(webkit_accessible_text_get_caret_offset): Make sure to pass the
right reference object to objectFocusedAndCaretOffsetUnignored.
(objectFocusedAndCaretOffsetUnignored): Use positionBeforeNode
instead of firstPositionInNode for calculating the begining of the
range used to calculate the offsets. Ensure that the reference
object is never a descendant of the actual object being returned.
* editing/gtk/FrameSelectionGtk.cpp:
(WebCore::FrameSelection::notifyAccessibilityForSelectionChange):
Pass the right accessibility object associated with the current
selection to objectFocusedAndCaretOffsetUnignored.
Source/WebKit/gtk:
Update caret browsing related unit tests to check emissions of
'text-caret-moved' and 'text-selection-changed' signals.
* tests/testatk.c:
(textCaretMovedCallback): New callback for 'text-caret-moved'.
(testWebkitAtkCaretOffsets): Check emissions of 'text-caret-moved'.
(textSelectionChangedCallback): New callback for 'text-selection-changed'.
(testWebkitAtkTextSelections): Check emissions of 'text-selection-changed'.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@105590 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/accessibility/gtk/AccessibilityObjectWrapperAtk.cpp b/Source/WebCore/accessibility/gtk/AccessibilityObjectWrapperAtk.cpp
index eadacaf..fe9f007 100644
--- a/Source/WebCore/accessibility/gtk/AccessibilityObjectWrapperAtk.cpp
+++ b/Source/WebCore/accessibility/gtk/AccessibilityObjectWrapperAtk.cpp
@@ -1345,6 +1345,12 @@
if (!coreObject->isAccessibilityRenderObject())
return 0;
+ // We need to make sure we pass a valid object as reference.
+ if (coreObject->accessibilityIsIgnored())
+ coreObject = coreObject->parentObjectUnignored();
+ if (!coreObject)
+ return 0;
+
int offset;
if (!objectFocusedAndCaretOffsetUnignored(coreObject, offset))
return 0;
@@ -2736,19 +2742,25 @@
return 0;
// Look for the actual (not ignoring accessibility) selected object.
- if (focusedObject->accessibilityIsIgnored())
- focusedObject = focusedObject->parentObjectUnignored();
- if (!focusedObject)
+ AccessibilityObject* firstUnignoredParent = focusedObject;
+ if (firstUnignoredParent->accessibilityIsIgnored())
+ firstUnignoredParent = firstUnignoredParent->parentObjectUnignored();
+ if (!firstUnignoredParent)
return 0;
// Don't ignore links if the offset is being requested for a link.
- if (!referenceObject->isLink() && focusedObject->isLink())
- focusedObject = focusedObject->parentObjectUnignored();
- if (!focusedObject)
+ if (!referenceObject->isLink() && firstUnignoredParent->isLink())
+ firstUnignoredParent = firstUnignoredParent->parentObjectUnignored();
+ if (!firstUnignoredParent)
return 0;
+ // The reference object must either coincide with the focused
+ // object being considered, or be a descendant of it.
+ if (referenceObject->isDescendantOfObject(firstUnignoredParent))
+ referenceObject = firstUnignoredParent;
+
Node* startNode = 0;
- if (focusedObject != referenceObject || focusedObject->isTextControl()) {
+ if (firstUnignoredParent != referenceObject || firstUnignoredParent->isTextControl()) {
// We need to use the first child's node of the reference
// object as the start point to calculate the caret offset
// because we want it to be relative to the object of
@@ -2759,10 +2771,10 @@
startNode = axFirstChild->node();
}
if (!startNode)
- startNode = focusedObject->node();
+ startNode = firstUnignoredParent->node();
- VisiblePosition startPosition = VisiblePosition(firstPositionInNode(startNode), DOWNSTREAM);
- VisiblePosition endPosition = focusedObject->selection().visibleEnd();
+ VisiblePosition startPosition = VisiblePosition(positionBeforeNode(startNode), DOWNSTREAM);
+ VisiblePosition endPosition = firstUnignoredParent->selection().visibleEnd();
if (startPosition == endPosition)
offset = 0;
@@ -2774,7 +2786,7 @@
offset = TextIterator::rangeLength(range.get(), true);
}
- return focusedObject;
+ return firstUnignoredParent;
}
#endif // HAVE(ACCESSIBILITY)