From fb4d59f2de8ca9f128b2f38a5e782e6c5122ee14 Mon Sep 17 00:00:00 2001 From: Neil Deakin Date: Wed, 15 Aug 2012 14:52:37 -0400 Subject: [PATCH] Bug 743975 - remove accessibility events from widget, replace with a nsBaseWidget::GetAccessible method, r=trevsaunders --- content/events/src/nsDOMEvent.cpp | 8 ---- layout/base/nsPresShell.cpp | 36 --------------- widget/cocoa/nsChildView.mm | 12 ++--- widget/gtk2/nsWindow.cpp | 21 ++------- widget/gtk2/nsWindow.h | 6 --- widget/nsEvent.h | 3 -- widget/nsGUIEvent.h | 30 +------------ widget/windows/nsWindow.cpp | 28 ++---------- widget/windows/nsWindow.h | 1 - widget/xpwidgets/nsBaseWidget.cpp | 62 +++++++++++++++++++++++--- widget/xpwidgets/nsBaseWidget.h | 9 ++++ xpfe/appshell/src/nsWebShellWindow.cpp | 8 ---- 12 files changed, 77 insertions(+), 147 deletions(-) diff --git a/content/events/src/nsDOMEvent.cpp b/content/events/src/nsDOMEvent.cpp index 01f8a688ad62..87a47d7c7cdb 100644 --- a/content/events/src/nsDOMEvent.cpp +++ b/content/events/src/nsDOMEvent.cpp @@ -792,14 +792,6 @@ nsDOMEvent::DuplicatePrivateData() newEvent = mutationEvent; break; } -#ifdef ACCESSIBILITY - case NS_ACCESSIBLE_EVENT: - { - newEvent = new nsAccessibleEvent(false, msg, nullptr); - isInputEvent = true; - break; - } -#endif case NS_FORM_EVENT: { newEvent = new nsFormEvent(false, msg); diff --git a/layout/base/nsPresShell.cpp b/layout/base/nsPresShell.cpp index c4a11858f70d..7460659cad5b 100644 --- a/layout/base/nsPresShell.cpp +++ b/layout/base/nsPresShell.cpp @@ -5662,16 +5662,6 @@ PresShell::HandleEvent(nsIFrame *aFrame, RecordMouseLocation(aEvent); -#ifdef ACCESSIBILITY - if (aEvent->eventStructType == NS_ACCESSIBLE_EVENT) { - NS_TIME_FUNCTION_MIN(1.0); - - // Accessibility events come through OS requests and not from scripts, - // so it is safe to handle here - return HandleEventInternal(aEvent, aEventStatus); - } -#endif - if (!nsContentUtils::IsSafeToRunScript()) return NS_OK; @@ -6291,32 +6281,6 @@ PresShell::HandleEventInternal(nsEvent* aEvent, nsEventStatus* aStatus) { NS_TIME_FUNCTION_MIN(1.0); -#ifdef ACCESSIBILITY - if (aEvent->eventStructType == NS_ACCESSIBLE_EVENT) - { - nsAccessibleEvent *accEvent = static_cast(aEvent); - accEvent->mAccessible = nullptr; - - nsCOMPtr accService = - do_GetService("@mozilla.org/accessibilityService;1"); - if (accService) { - nsCOMPtr container = mPresContext->GetContainer(); - if (!container) { - // This presshell is not active. This often happens when a - // preshell is being held onto for fastback. - return NS_OK; - } - - // Accessible creation might be not safe so we make sure it's not created - // at unsafe times. - accEvent->mAccessible = - accService->GetRootDocumentAccessible(this, nsContentUtils::IsSafeToRunScript()); - - return NS_OK; - } - } -#endif - nsRefPtr manager = mPresContext->EventStateManager(); nsresult rv = NS_OK; diff --git a/widget/cocoa/nsChildView.mm b/widget/cocoa/nsChildView.mm index a008ad2cfd5e..78ca3f2708ab 100644 --- a/widget/cocoa/nsChildView.mm +++ b/widget/cocoa/nsChildView.mm @@ -1925,16 +1925,12 @@ nsChildView::GetDocumentAccessible() } // need to fetch the accessible anew, because it has gone away. - nsEventStatus status; - nsAccessibleEvent event(true, NS_GETACCESSIBLE, this); - DispatchEvent(&event, status); - // cache the accessible in our weak ptr - mAccessible = - do_GetWeakReference(static_cast(event.mAccessible)); + Accessible* acc = GetAccessible(); + mAccessible = do_GetWeakReference(static_cast(acc)); - NS_IF_ADDREF(event.mAccessible); - return event.mAccessible; + NS_IF_ADDREF(acc); + return acc; } #endif diff --git a/widget/gtk2/nsWindow.cpp b/widget/gtk2/nsWindow.cpp index fbe5fad367a3..9d186d3f83c9 100644 --- a/widget/gtk2/nsWindow.cpp +++ b/widget/gtk2/nsWindow.cpp @@ -5828,25 +5828,10 @@ nsWindow::CreateRootAccessible() { if (mIsTopLevel && !mRootAccessible) { LOG(("nsWindow:: Create Toplevel Accessibility\n")); - Accessible* acc = DispatchAccessibleEvent(); - - if (acc) { - mRootAccessible = acc; - } + mRootAccessible = GetAccessible(); } } -Accessible* -nsWindow::DispatchAccessibleEvent() -{ - nsAccessibleEvent event(true, NS_GETACCESSIBLE, this); - - nsEventStatus status; - DispatchEvent(&event, status); - - return event.mAccessible; -} - void nsWindow::DispatchEventToRootAccessible(PRUint32 aEventType) { @@ -5861,12 +5846,14 @@ nsWindow::DispatchEventToRootAccessible(PRUint32 aEventType) } // Get the root document accessible and fire event to it. - Accessible* acc = DispatchAccessibleEvent(); + Accessible *acc = GetAccessible(); if (acc) { accService->FireAccessibleEvent(aEventType, acc); } } +// XXXndeakin what is all this for? Accessibility should be receiving these +// notifications of gtk the same as other platforms. void nsWindow::DispatchActivateEventAccessible(void) { diff --git a/widget/gtk2/nsWindow.h b/widget/gtk2/nsWindow.h index c0119b0255d4..df7184e43f88 100644 --- a/widget/gtk2/nsWindow.h +++ b/widget/gtk2/nsWindow.h @@ -383,12 +383,6 @@ private: */ void CreateRootAccessible(); - /** - * Generate the NS_GETACCESSIBLE event to get accessible for this window - * and return it. - */ - Accessible *DispatchAccessibleEvent(); - /** * Dispatch accessible event for the top level window accessible. * diff --git a/widget/nsEvent.h b/widget/nsEvent.h index 159071704663..b429b887622a 100644 --- a/widget/nsEvent.h +++ b/widget/nsEvent.h @@ -59,9 +59,6 @@ class nsInputEvent; class nsMouseEvent_base; class nsMouseEvent; class nsDragEvent; -#ifdef ACCESSIBILITY -class nsAccessibleEvent; -#endif class nsKeyEvent; class nsTextEvent; class nsCompositionEvent; diff --git a/widget/nsGUIEvent.h b/widget/nsGUIEvent.h index baf719606308..fe3fc31615a6 100644 --- a/widget/nsGUIEvent.h +++ b/widget/nsGUIEvent.h @@ -39,9 +39,6 @@ namespace plugins { } } -#ifdef ACCESSIBILITY -class Accessible; -#endif class nsRenderingContext; class nsIMenuItem; class nsIContent; @@ -67,7 +64,6 @@ class nsHashKey; #define NS_MOUSE_SCROLL_EVENT 16 #define NS_SCROLLPORT_EVENT 18 #define NS_MUTATION_EVENT 19 // |nsMutationEvent| in content -#define NS_ACCESSIBLE_EVENT 20 #define NS_FORM_EVENT 21 #define NS_FOCUS_EVENT 22 #define NS_POPUP_EVENT 23 @@ -296,10 +292,6 @@ class nsHashKey; // Mutation events defined elsewhere starting at 1800 -// accessible events -#define NS_ACCESSIBLE_START 1900 -#define NS_GETACCESSIBLE (NS_ACCESSIBLE_START) - #define NS_USER_DEFINED_EVENT 2000 // composition events @@ -1033,24 +1025,6 @@ public: bool userCancelled; }; -#ifdef ACCESSIBILITY -/** - * Accessible event - */ - -class nsAccessibleEvent : public nsInputEvent -{ -public: - nsAccessibleEvent(bool isTrusted, PRUint32 msg, nsIWidget *w) - : nsInputEvent(isTrusted, msg, w, NS_ACCESSIBLE_EVENT), - mAccessible(nullptr) - { - } - - Accessible *mAccessible; -}; -#endif - /** * Keyboard event */ @@ -1798,7 +1772,6 @@ enum nsDragDropEventStatus { #define NS_IS_INPUT_EVENT(evnt) \ (((evnt)->eventStructType == NS_INPUT_EVENT) || \ - ((evnt)->eventStructType == NS_ACCESSIBLE_EVENT) || \ ((evnt)->eventStructType == NS_MOUSE_EVENT) || \ ((evnt)->eventStructType == NS_KEY_EVENT) || \ ((evnt)->eventStructType == NS_TEXT_EVENT) || \ @@ -1940,8 +1913,7 @@ inline bool NS_IsEventUsingCoordinates(nsEvent* aEvent) return !NS_IS_KEY_EVENT(aEvent) && !NS_IS_IME_RELATED_EVENT(aEvent) && !NS_IS_CONTEXT_MENU_KEY(aEvent) && !NS_IS_ACTIVATION_EVENT(aEvent) && !NS_IS_PLUGIN_EVENT(aEvent) && - !NS_IS_CONTENT_COMMAND_EVENT(aEvent) && - aEvent->eventStructType != NS_ACCESSIBLE_EVENT; + !NS_IS_CONTENT_COMMAND_EVENT(aEvent); } /** diff --git a/widget/windows/nsWindow.cpp b/widget/windows/nsWindow.cpp index 2b934348046a..677c14354ff1 100644 --- a/widget/windows/nsWindow.cpp +++ b/widget/windows/nsWindow.cpp @@ -3949,27 +3949,6 @@ bool nsWindow::DispatchMouseEvent(PRUint32 aEventType, WPARAM wParam, return result; } -// Deal with accessibile event -#ifdef ACCESSIBILITY -Accessible* -nsWindow::DispatchAccessibleEvent(PRUint32 aEventType) -{ - if (nullptr == mEventCallback) { - return nullptr; - } - - nsAccessibleEvent event(true, aEventType, this); - InitEvent(event, nullptr); - - ModifierKeyState modifierKeyState; - modifierKeyState.InitInputEvent(event); - - DispatchWindowEvent(&event); - - return event.mAccessible; -} -#endif - bool nsWindow::DispatchFocusToTopLevelWindow(PRUint32 aEventType) { if (aEventType == NS_ACTIVATE) @@ -7413,8 +7392,7 @@ bool nsWindow::AssociateDefaultIMC(bool aAssociate) #ifdef DEBUG_WMGETOBJECT #define NS_LOG_WMGETOBJECT_WNDACC(aWnd) \ - Accessible* acc = aWnd ? \ - aWnd->DispatchAccessibleEvent(NS_GETACCESSIBLE) : nullptr; \ + Accessible* acc = aWnd ? aWind->GetAccessible() : nullptr; \ PR_LOG(gWindowsLog, PR_LOG_ALWAYS, (" acc: %p", acc)); \ if (acc) { \ nsAutoString name; \ @@ -7422,7 +7400,7 @@ bool nsWindow::AssociateDefaultIMC(bool aAssociate) PR_LOG(gWindowsLog, PR_LOG_ALWAYS, \ (", accname: %s", NS_ConvertUTF16toUTF8(name).get())); \ nsCOMPtr doc = do_QueryObject(acc); \ - void *hwnd = nullptr; \ + void *hwnd = nullptr; \ doc->GetWindowHandle(&hwnd); \ PR_LOG(gWindowsLog, PR_LOG_ALWAYS, (", acc hwnd: %d", hwnd)); \ } @@ -7466,7 +7444,7 @@ nsWindow::GetRootAccessible() NS_LOG_WMGETOBJECT_THISWND NS_LOG_WMGETOBJECT_WND("This Window", mWnd); - return DispatchAccessibleEvent(NS_GETACCESSIBLE); + return GetAccessible(); } #endif diff --git a/widget/windows/nsWindow.h b/widget/windows/nsWindow.h index 5db782269542..a0a94a1c0c11 100644 --- a/widget/windows/nsWindow.h +++ b/widget/windows/nsWindow.h @@ -206,7 +206,6 @@ public: void SuppressBlurEvents(bool aSuppress); // Called from nsFilePicker bool BlurEventsSuppressed(); #ifdef ACCESSIBILITY - Accessible* DispatchAccessibleEvent(PRUint32 aEventType); Accessible* GetRootAccessible(); #endif // ACCESSIBILITY diff --git a/widget/xpwidgets/nsBaseWidget.cpp b/widget/xpwidgets/nsBaseWidget.cpp index f72da05858ef..6b921540d0f5 100644 --- a/widget/xpwidgets/nsBaseWidget.cpp +++ b/widget/xpwidgets/nsBaseWidget.cpp @@ -22,6 +22,8 @@ #include "BasicLayers.h" #include "LayerManagerOGL.h" #include "nsIXULRuntime.h" +#include "nsIXULWindow.h" +#include "nsIDocShell.h" #include "nsView.h" #include "nsIViewManager.h" #include "nsEventStateManager.h" @@ -31,6 +33,10 @@ #include "prenv.h" #include "mozilla/Attributes.h" +#ifdef ACCESSIBILITY +#include "nsAccessibilityService.h" +#endif + #ifdef DEBUG #include "nsIObserver.h" @@ -1339,16 +1345,34 @@ const widget::SizeConstraints& nsBaseWidget::GetSizeConstraints() const return mSizeConstraints; } -static nsIPresShell* GetPresShell(nsIWidget* aWidget) +// If clientData is non-null, then get the presShell from either the window +// or the view. Otherwise, assume that this is a widget attached to a view. +static nsIPresShell* GetPresShell(nsIWidget* aWidget, void* clientData) { - nsIView* view = nsView::GetViewFor(aWidget); - return view ? view->GetViewManager()->GetPresShell() : nullptr; + nsCOMPtr window(do_QueryInterface(static_cast(clientData))); + if (window) { + nsCOMPtr docShell; + window->GetDocShell(getter_AddRefs(docShell)); + if (docShell) { + nsCOMPtr presShell; + docShell->GetPresShell(getter_AddRefs(presShell)); + return presShell.get(); + } + } + else { + nsIView* view = nsView::GetViewFor(aWidget); + if (view) { + return view->GetViewManager()->GetPresShell(); + } + } + + return nullptr; } void nsBaseWidget::NotifySizeMoveDone() { - nsIPresShell* presShell = GetPresShell(this); + nsIPresShell* presShell = GetPresShell(this, nullptr); if (presShell) { presShell->WindowSizeMoveDone(); } @@ -1357,7 +1381,7 @@ nsBaseWidget::NotifySizeMoveDone() void nsBaseWidget::NotifySysColorChanged() { - nsIPresShell* presShell = GetPresShell(this); + nsIPresShell* presShell = GetPresShell(this, nullptr); if (presShell) { presShell->SysColorChanged(); } @@ -1366,12 +1390,38 @@ nsBaseWidget::NotifySysColorChanged() void nsBaseWidget::NotifyThemeChanged() { - nsIPresShell* presShell = GetPresShell(this); + nsIPresShell* presShell = GetPresShell(this, nullptr); if (presShell) { presShell->ThemeChanged(); } } +#ifdef ACCESSIBILITY + +Accessible* +nsBaseWidget::GetAccessible() +{ + nsIPresShell* presShell = GetPresShell(this, mClientData); + NS_ENSURE_TRUE(presShell, nullptr); + + // If container is null then the presshell is not active. This often happens + // when a preshell is being held onto for fastback. + nsPresContext* presContext = presShell->GetPresContext(); + nsCOMPtr container = presContext->GetContainer(); + NS_ENSURE_TRUE(container, nullptr); + + // Accessible creation might be not safe so use IsSafeToRunScript to + // make sure it's not created at unsafe times. + nsCOMPtr accService = services::GetAccessibilityService(); + if (accService) { + return accService->GetRootDocumentAccessible(presShell, nsContentUtils::IsSafeToRunScript()); + } + + return nullptr; +} + +#endif + #ifdef DEBUG ////////////////////////////////////////////////////////////// // diff --git a/widget/xpwidgets/nsBaseWidget.h b/widget/xpwidgets/nsBaseWidget.h index c3b473281cb6..e33167691671 100644 --- a/widget/xpwidgets/nsBaseWidget.h +++ b/widget/xpwidgets/nsBaseWidget.h @@ -19,6 +19,10 @@ class nsIContent; class nsAutoRollup; class gfxContext; +#ifdef ACCESSIBILITY +class Accessible; +#endif + namespace mozilla { namespace layers { class BasicLayerManager; @@ -167,6 +171,11 @@ public: void NotifySysColorChanged(); void NotifyThemeChanged(); +#ifdef ACCESSIBILITY + // Get the accessible for the window. + Accessible* GetAccessible(); +#endif + nsPopupLevel PopupLevel() { return mPopupLevel; } virtual nsIntSize ClientToWindowSize(const nsIntSize& aClientSize) diff --git a/xpfe/appshell/src/nsWebShellWindow.cpp b/xpfe/appshell/src/nsWebShellWindow.cpp index 7b7525f825a4..d01150a69ef7 100644 --- a/xpfe/appshell/src/nsWebShellWindow.cpp +++ b/xpfe/appshell/src/nsWebShellWindow.cpp @@ -428,14 +428,6 @@ nsWebShellWindow::HandleEvent(nsGUIEvent *aEvent) break; } - case NS_GETACCESSIBLE: { - nsCOMPtr presShell; - docShell->GetPresShell(getter_AddRefs(presShell)); - if (presShell) { - presShell->HandleEventWithTarget(aEvent, nullptr, nullptr, &result); - } - break; - } default: break;