diff --git a/accessible/mac/AccessibleWrap.mm b/accessible/mac/AccessibleWrap.mm index 7b7d9c221486..d31648cef634 100644 --- a/accessible/mac/AccessibleWrap.mm +++ b/accessible/mac/AccessibleWrap.mm @@ -110,10 +110,68 @@ nsresult AccessibleWrap::HandleAccEvent(AccEvent* aEvent) { } uint32_t eventType = aEvent->GetEventType(); - - mozAccessible* nativeAcc = nil; + Accessible* eventTarget = nullptr; switch (eventType) { + case nsIAccessibleEvent::EVENT_SELECTION: + case nsIAccessibleEvent::EVENT_SELECTION_ADD: + case nsIAccessibleEvent::EVENT_SELECTION_REMOVE: { + AccSelChangeEvent* selEvent = downcast_accEvent(aEvent); + // The "widget" is the selected widget's container. In OSX + // it is the target of the selection changed event. + eventTarget = selEvent->Widget(); + break; + } + default: + eventTarget = aEvent->GetAccessible(); + break; + } + + mozAccessible* nativeAcc = nil; + eventTarget->GetNativeInterface((void**)&nativeAcc); + if (!nativeAcc) { + return NS_ERROR_FAILURE; + } + + switch (eventType) { + case nsIAccessibleEvent::EVENT_STATE_CHANGE: { + AccStateChangeEvent* event = downcast_accEvent(aEvent); + [nativeAcc stateChanged:event->GetState() isEnabled:event->IsStateEnabled()]; + break; + } + + case nsIAccessibleEvent::EVENT_TEXT_SELECTION_CHANGED: { + MOXTextMarkerDelegate* delegate = + [MOXTextMarkerDelegate getOrCreateForDoc:aEvent->Document()]; + AccTextSelChangeEvent* event = downcast_accEvent(aEvent); + AutoTArray ranges; + event->SelectionRanges(&ranges); + + if (ranges.Length()) { + // Cache selection in delegate. + [delegate setSelectionFrom:ranges[0].StartContainer() + at:ranges[0].StartOffset() + to:ranges[0].EndContainer() + at:ranges[0].EndOffset()]; + } + + [nativeAcc handleAccessibleEvent:eventType]; + break; + } + + case nsIAccessibleEvent::EVENT_TEXT_CARET_MOVED: { + AccCaretMoveEvent* event = downcast_accEvent(aEvent); + if (event->IsSelectionCollapsed()) { + // If the selection is collapsed, invalidate our text selection cache. + MOXTextMarkerDelegate* delegate = + [MOXTextMarkerDelegate getOrCreateForDoc:aEvent->Document()]; + [delegate invalidateSelection]; + } + + [nativeAcc handleAccessibleEvent:eventType]; + break; + } + case nsIAccessibleEvent::EVENT_FOCUS: case nsIAccessibleEvent::EVENT_VALUE_CHANGE: case nsIAccessibleEvent::EVENT_TEXT_VALUE_CHANGE: @@ -121,85 +179,16 @@ nsresult AccessibleWrap::HandleAccEvent(AccEvent* aEvent) { case nsIAccessibleEvent::EVENT_MENUPOPUP_START: case nsIAccessibleEvent::EVENT_MENUPOPUP_END: case nsIAccessibleEvent::EVENT_REORDER: - if (Accessible* accessible = aEvent->GetAccessible()) { - accessible->GetNativeInterface((void**)&nativeAcc); - if (!nativeAcc) { - return NS_ERROR_FAILURE; - } - } - break; case nsIAccessibleEvent::EVENT_SELECTION: case nsIAccessibleEvent::EVENT_SELECTION_ADD: - case nsIAccessibleEvent::EVENT_SELECTION_REMOVE: { - AccSelChangeEvent* selEvent = downcast_accEvent(aEvent); - // The "widget" is the selected widget's container. In OSX - // it is the target of the selection changed event. - if (Accessible* accessible = selEvent->Widget()) { - accessible->GetNativeInterface((void**)&nativeAcc); - if (!nativeAcc) { - return NS_ERROR_FAILURE; - } - } + case nsIAccessibleEvent::EVENT_SELECTION_REMOVE: + [nativeAcc handleAccessibleEvent:eventType]; break; - } - case nsIAccessibleEvent::EVENT_STATE_CHANGE: - if (Accessible* accessible = aEvent->GetAccessible()) { - accessible->GetNativeInterface((void**)&nativeAcc); - if (nativeAcc) { - AccStateChangeEvent* event = downcast_accEvent(aEvent); - [nativeAcc stateChanged:event->GetState() isEnabled:event->IsStateEnabled()]; - return NS_OK; - } else { - return NS_ERROR_FAILURE; - } - } - break; - case nsIAccessibleEvent::EVENT_TEXT_SELECTION_CHANGED: - if (Accessible* accessible = aEvent->GetAccessible()) { - accessible->GetNativeInterface((void**)&nativeAcc); - if (!nativeAcc) { - return NS_ERROR_FAILURE; - } - MOXTextMarkerDelegate* delegate = - [MOXTextMarkerDelegate getOrCreateForDoc:aEvent->Document()]; - AccTextSelChangeEvent* event = downcast_accEvent(aEvent); - AutoTArray ranges; - event->SelectionRanges(&ranges); - - if (ranges.Length()) { - // Cache selection in delegate. - [delegate setSelectionFrom:ranges[0].StartContainer() - at:ranges[0].StartOffset() - to:ranges[0].EndContainer() - at:ranges[0].EndOffset()]; - } - } - break; - case nsIAccessibleEvent::EVENT_TEXT_CARET_MOVED: - if (Accessible* accessible = aEvent->GetAccessible()) { - accessible->GetNativeInterface((void**)&nativeAcc); - if (!nativeAcc) { - return NS_ERROR_FAILURE; - } - - AccCaretMoveEvent* event = downcast_accEvent(aEvent); - if (event->IsSelectionCollapsed()) { - // If the selection is collapsed, invalidate our text selection cache. - MOXTextMarkerDelegate* delegate = - [MOXTextMarkerDelegate getOrCreateForDoc:aEvent->Document()]; - [delegate invalidateSelection]; - } - } - break; default: break; } - if (nativeAcc) { - [nativeAcc handleAccessibleEvent:eventType]; - } - return NS_OK; NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;