diff --git a/accessible/mac/AccessibleWrap.mm b/accessible/mac/AccessibleWrap.mm index 9ea6ac2094a7..336f20f768eb 100644 --- a/accessible/mac/AccessibleWrap.mm +++ b/accessible/mac/AccessibleWrap.mm @@ -166,8 +166,7 @@ nsresult AccessibleWrap::HandleAccEvent(AccEvent* aEvent) { // If the selection is collapsed, invalidate our text selection cache. MOXTextMarkerDelegate* delegate = [MOXTextMarkerDelegate getOrCreateForDoc:aEvent->Document()]; - int32_t caretOffset = event->GetCaretOffset(); - [delegate setSelectionFrom:eventTarget at:caretOffset to:eventTarget at:caretOffset]; + [delegate invalidateSelection]; } [nativeAcc handleAccessibleEvent:eventType]; diff --git a/accessible/mac/Platform.mm b/accessible/mac/Platform.mm index f8b634885185..32c28cd47492 100644 --- a/accessible/mac/Platform.mm +++ b/accessible/mac/Platform.mm @@ -100,7 +100,7 @@ void ProxyCaretMoveEvent(ProxyAccessible* aTarget, int32_t aOffset, bool aIsSele if (aIsSelectionCollapsed) { // If selection is collapsed, invalidate selection. MOXTextMarkerDelegate* delegate = [MOXTextMarkerDelegate getOrCreateForDoc:aTarget->Document()]; - [delegate setSelectionFrom:aTarget at:aOffset to:aTarget at:aOffset]; + [delegate invalidateSelection]; } if (wrapper) { diff --git a/accessible/mac/mozAccessible.mm b/accessible/mac/mozAccessible.mm index 74d060b089b4..570f3537db4a 100644 --- a/accessible/mac/mozAccessible.mm +++ b/accessible/mac/mozAccessible.mm @@ -840,21 +840,10 @@ enum AXTextStateChangeType { case nsIAccessibleEvent::EVENT_SELECTION_WITHIN: [self moxPostNotification:NSAccessibilitySelectedChildrenChangedNotification]; break; - case nsIAccessibleEvent::EVENT_TEXT_CARET_MOVED: { - // We consider any caret move event to be a selected text change event. - // So dispatching an event for EVENT_TEXT_SELECTION_CHANGED would be reduntant. - id delegate = [self moxTextMarkerDelegate]; - id selectedRange = [delegate moxSelectedTextMarkerRange]; - NSDictionary* userInfo = @{ - @"AXTextChangeElement": self, - @"AXSelectedTextMarkerRange": (selectedRange ? selectedRange : [NSNull null]) - }; - - mozAccessible* webArea = GetNativeFromGeckoAccessible([self geckoDocument]); - [webArea moxPostNotification:NSAccessibilitySelectedTextChangedNotification withUserInfo:userInfo]; - [self moxPostNotification:NSAccessibilitySelectedTextChangedNotification withUserInfo:userInfo]; + case nsIAccessibleEvent::EVENT_TEXT_CARET_MOVED: + case nsIAccessibleEvent::EVENT_TEXT_SELECTION_CHANGED: + [self moxPostNotification:NSAccessibilitySelectedTextChangedNotification]; break; - } } } diff --git a/accessible/tests/browser/mac/browser_text_input.js b/accessible/tests/browser/mac/browser_text_input.js index 0105f0a044b1..0dfeedf2da62 100644 --- a/accessible/tests/browser/mac/browser_text_input.js +++ b/accessible/tests/browser/mac/browser_text_input.js @@ -64,51 +64,7 @@ function testValueChangedEventData( is(str, expectedWordAtLeft); } -function waitForTextEventDuo(eventName, expectedId) { - return Promise.all([ - waitForMacEventWithInfo(eventName, (iface, data) => { - return ( - iface.getAttributeValue("AXRole") == "AXWebArea" && - !!data && - data.AXTextChangeElement.getAttributeValue("AXDOMIdentifier") == - expectedId - ); - }), - waitForMacEventWithInfo( - eventName, - (iface, data) => - iface.getAttributeValue("AXDOMIdentifier") == expectedId && !!data - ), - ]); -} - -async function synthKeyAndTestSelectionChanged( - synthKey, - synthEvent, - expectedId, - expectedSelectionString -) { - let valueChangedEvents = waitForTextEventDuo( - "AXSelectedTextChanged", - expectedId - ); - - EventUtils.synthesizeKey(synthKey, synthEvent); - let [, inputEvent] = await valueChangedEvents; - is( - inputEvent.data.AXTextChangeElement.getAttributeValue("AXDOMIdentifier"), - expectedId, - "Correct AXTextChangeElement" - ); - - let rangeString = inputEvent.macIface.getParameterizedAttributeValue( - "AXStringForTextMarkerRange", - inputEvent.data.AXSelectedTextMarkerRange - ); - is(rangeString, expectedSelectionString, "selection has correct length"); -} - -async function synthKeyAndTestValueChanged( +async function synthKeyAndTestEvent( synthKey, synthEvent, expectedId, @@ -116,7 +72,20 @@ async function synthKeyAndTestValueChanged( expectedEditType, expectedWordAtLeft ) { - let valueChangedEvents = waitForTextEventDuo("AXValueChanged", "input"); + let valueChangedEvents = Promise.all([ + waitForMacEventWithInfo("AXValueChanged", (iface, data) => { + return ( + iface.getAttributeValue("AXRole") == "AXWebArea" && + !!data && + data.AXTextChangeElement.getAttributeValue("AXDOMIdentifier") == "input" + ); + }), + waitForMacEventWithInfo( + "AXValueChanged", + (iface, data) => + iface.getAttributeValue("AXDOMIdentifier") == "input" && !!data + ), + ]); EventUtils.synthesizeKey(synthKey, synthEvent); let [webareaEvent, inputEvent] = await valueChangedEvents; @@ -158,7 +127,7 @@ addAccessibleTask( expectedChangeValue, expectedWordAtLeft ) { - await synthKeyAndTestValueChanged( + await synthKeyAndTestEvent( synthKey, null, "input", @@ -184,7 +153,7 @@ addAccessibleTask( await testTextInput("d", "d", "world"); async function testTextDelete(expectedChangeValue, expectedWordAtLeft) { - await synthKeyAndTestValueChanged( + await synthKeyAndTestEvent( "KEY_Backspace", null, "input", @@ -196,33 +165,5 @@ addAccessibleTask( await testTextDelete("d", "worl"); await testTextDelete("l", "wor"); - - await synthKeyAndTestSelectionChanged("KEY_ArrowLeft", null, "input", ""); - await synthKeyAndTestSelectionChanged( - "KEY_ArrowLeft", - { shiftKey: true }, - "input", - "o" - ); - await synthKeyAndTestSelectionChanged( - "KEY_ArrowLeft", - { shiftKey: true }, - "input", - "wo" - ); - await synthKeyAndTestSelectionChanged("KEY_ArrowLeft", null, "input", ""); - await synthKeyAndTestSelectionChanged( - "KEY_Home", - { shiftKey: true }, - "input", - "hello " - ); - await synthKeyAndTestSelectionChanged("KEY_ArrowLeft", null, "input", ""); - await synthKeyAndTestSelectionChanged( - "KEY_ArrowRight", - { shiftKey: true, altKey: true }, - "input", - "hello" - ); } );