diff --git a/accessible/android/AccessibleWrap.cpp b/accessible/android/AccessibleWrap.cpp index c84651ab35d0..4f10945bd1fc 100644 --- a/accessible/android/AccessibleWrap.cpp +++ b/accessible/android/AccessibleWrap.cpp @@ -65,25 +65,6 @@ nsresult AccessibleWrap::HandleAccEvent(AccEvent* aEvent) { static_cast(accessible->Document()); if (doc) { switch (aEvent->GetEventType()) { - case nsIAccessibleEvent::EVENT_TEXT_CARET_MOVED: { - if (accessible != aEvent->Document() && !aEvent->IsFromUserInput()) { - AccCaretMoveEvent* caretEvent = downcast_accEvent(aEvent); - HyperTextAccessible* ht = AsHyperText(); - // Pivot to the caret's position if it has an expanded selection. - // This is used mostly for find in page. - if ((ht && ht->SelectionCount())) { - DOMPoint point = - AsHyperText()->OffsetToDOMPoint(caretEvent->GetCaretOffset()); - if (LocalAccessible* newPos = - doc->GetAccessibleOrContainer(point.node)) { - static_cast(newPos)->PivotTo( - java::SessionAccessibility::HTML_GRANULARITY_DEFAULT, true, - true); - } - } - } - break; - } case nsIAccessibleEvent::EVENT_SCROLLING_START: { accessible->PivotTo( java::SessionAccessibility::HTML_GRANULARITY_DEFAULT, true, true); diff --git a/accessible/android/Platform.cpp b/accessible/android/Platform.cpp index b912f644383c..d302e648b167 100644 --- a/accessible/android/Platform.cpp +++ b/accessible/android/Platform.cpp @@ -146,10 +146,23 @@ void a11y::PlatformCaretMoveEvent(Accessible* aTarget, int32_t aOffset, bool aFromUser) { RefPtr sessionAcc = SessionAccessibility::GetInstanceFor(aTarget); - - if (sessionAcc) { - sessionAcc->SendTextSelectionChangedEvent(aTarget, aOffset); + if (!sessionAcc) { + return; } + + if (!aTarget->IsDoc() && !aFromUser && !aIsSelectionCollapsed) { + // Pivot to the caret's position if it has an expanded selection. + // This is used mostly for find in page. + Accessible* leaf = TextLeafPoint::GetCaret(aTarget).ActualizeCaret().mAcc; + MOZ_ASSERT(leaf); + if (Accessible* result = AccessibleWrap::DoPivot( + leaf, java::SessionAccessibility::HTML_GRANULARITY_DEFAULT, true, + true)) { + sessionAcc->SendAccessibilityFocusedEvent(result); + } + } + + sessionAcc->SendTextSelectionChangedEvent(aTarget, aOffset); } void a11y::PlatformTextChangeEvent(Accessible* aTarget, const nsAString& aStr,