Bug 743975 - remove accessibility events from widget, replace with a nsBaseWidget::GetAccessible method, r=trevsaunders

This commit is contained in:
Neil Deakin 2012-08-15 14:52:37 -04:00
parent a534b0b037
commit fb4d59f2de
12 changed files with 77 additions and 147 deletions

View File

@ -792,14 +792,6 @@ nsDOMEvent::DuplicatePrivateData()
newEvent = mutationEvent; newEvent = mutationEvent;
break; break;
} }
#ifdef ACCESSIBILITY
case NS_ACCESSIBLE_EVENT:
{
newEvent = new nsAccessibleEvent(false, msg, nullptr);
isInputEvent = true;
break;
}
#endif
case NS_FORM_EVENT: case NS_FORM_EVENT:
{ {
newEvent = new nsFormEvent(false, msg); newEvent = new nsFormEvent(false, msg);

View File

@ -5662,16 +5662,6 @@ PresShell::HandleEvent(nsIFrame *aFrame,
RecordMouseLocation(aEvent); 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()) if (!nsContentUtils::IsSafeToRunScript())
return NS_OK; return NS_OK;
@ -6291,32 +6281,6 @@ PresShell::HandleEventInternal(nsEvent* aEvent, nsEventStatus* aStatus)
{ {
NS_TIME_FUNCTION_MIN(1.0); NS_TIME_FUNCTION_MIN(1.0);
#ifdef ACCESSIBILITY
if (aEvent->eventStructType == NS_ACCESSIBLE_EVENT)
{
nsAccessibleEvent *accEvent = static_cast<nsAccessibleEvent*>(aEvent);
accEvent->mAccessible = nullptr;
nsCOMPtr<nsIAccessibilityService> accService =
do_GetService("@mozilla.org/accessibilityService;1");
if (accService) {
nsCOMPtr<nsISupports> 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<nsEventStateManager> manager = mPresContext->EventStateManager(); nsRefPtr<nsEventStateManager> manager = mPresContext->EventStateManager();
nsresult rv = NS_OK; nsresult rv = NS_OK;

View File

@ -1925,16 +1925,12 @@ nsChildView::GetDocumentAccessible()
} }
// need to fetch the accessible anew, because it has gone away. // 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 // cache the accessible in our weak ptr
mAccessible = Accessible* acc = GetAccessible();
do_GetWeakReference(static_cast<nsIAccessible*>(event.mAccessible)); mAccessible = do_GetWeakReference(static_cast<nsIAccessible *>(acc));
NS_IF_ADDREF(event.mAccessible); NS_IF_ADDREF(acc);
return event.mAccessible; return acc;
} }
#endif #endif

View File

@ -5828,25 +5828,10 @@ nsWindow::CreateRootAccessible()
{ {
if (mIsTopLevel && !mRootAccessible) { if (mIsTopLevel && !mRootAccessible) {
LOG(("nsWindow:: Create Toplevel Accessibility\n")); LOG(("nsWindow:: Create Toplevel Accessibility\n"));
Accessible* acc = DispatchAccessibleEvent(); mRootAccessible = GetAccessible();
if (acc) {
mRootAccessible = acc;
}
} }
} }
Accessible*
nsWindow::DispatchAccessibleEvent()
{
nsAccessibleEvent event(true, NS_GETACCESSIBLE, this);
nsEventStatus status;
DispatchEvent(&event, status);
return event.mAccessible;
}
void void
nsWindow::DispatchEventToRootAccessible(PRUint32 aEventType) nsWindow::DispatchEventToRootAccessible(PRUint32 aEventType)
{ {
@ -5861,12 +5846,14 @@ nsWindow::DispatchEventToRootAccessible(PRUint32 aEventType)
} }
// Get the root document accessible and fire event to it. // Get the root document accessible and fire event to it.
Accessible* acc = DispatchAccessibleEvent(); Accessible *acc = GetAccessible();
if (acc) { if (acc) {
accService->FireAccessibleEvent(aEventType, 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 void
nsWindow::DispatchActivateEventAccessible(void) nsWindow::DispatchActivateEventAccessible(void)
{ {

View File

@ -383,12 +383,6 @@ private:
*/ */
void CreateRootAccessible(); 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. * Dispatch accessible event for the top level window accessible.
* *

View File

@ -59,9 +59,6 @@ class nsInputEvent;
class nsMouseEvent_base; class nsMouseEvent_base;
class nsMouseEvent; class nsMouseEvent;
class nsDragEvent; class nsDragEvent;
#ifdef ACCESSIBILITY
class nsAccessibleEvent;
#endif
class nsKeyEvent; class nsKeyEvent;
class nsTextEvent; class nsTextEvent;
class nsCompositionEvent; class nsCompositionEvent;

View File

@ -39,9 +39,6 @@ namespace plugins {
} }
} }
#ifdef ACCESSIBILITY
class Accessible;
#endif
class nsRenderingContext; class nsRenderingContext;
class nsIMenuItem; class nsIMenuItem;
class nsIContent; class nsIContent;
@ -67,7 +64,6 @@ class nsHashKey;
#define NS_MOUSE_SCROLL_EVENT 16 #define NS_MOUSE_SCROLL_EVENT 16
#define NS_SCROLLPORT_EVENT 18 #define NS_SCROLLPORT_EVENT 18
#define NS_MUTATION_EVENT 19 // |nsMutationEvent| in content #define NS_MUTATION_EVENT 19 // |nsMutationEvent| in content
#define NS_ACCESSIBLE_EVENT 20
#define NS_FORM_EVENT 21 #define NS_FORM_EVENT 21
#define NS_FOCUS_EVENT 22 #define NS_FOCUS_EVENT 22
#define NS_POPUP_EVENT 23 #define NS_POPUP_EVENT 23
@ -296,10 +292,6 @@ class nsHashKey;
// Mutation events defined elsewhere starting at 1800 // 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 #define NS_USER_DEFINED_EVENT 2000
// composition events // composition events
@ -1033,24 +1025,6 @@ public:
bool userCancelled; 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 * Keyboard event
*/ */
@ -1798,7 +1772,6 @@ enum nsDragDropEventStatus {
#define NS_IS_INPUT_EVENT(evnt) \ #define NS_IS_INPUT_EVENT(evnt) \
(((evnt)->eventStructType == NS_INPUT_EVENT) || \ (((evnt)->eventStructType == NS_INPUT_EVENT) || \
((evnt)->eventStructType == NS_ACCESSIBLE_EVENT) || \
((evnt)->eventStructType == NS_MOUSE_EVENT) || \ ((evnt)->eventStructType == NS_MOUSE_EVENT) || \
((evnt)->eventStructType == NS_KEY_EVENT) || \ ((evnt)->eventStructType == NS_KEY_EVENT) || \
((evnt)->eventStructType == NS_TEXT_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) && 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_CONTEXT_MENU_KEY(aEvent) && !NS_IS_ACTIVATION_EVENT(aEvent) &&
!NS_IS_PLUGIN_EVENT(aEvent) && !NS_IS_PLUGIN_EVENT(aEvent) &&
!NS_IS_CONTENT_COMMAND_EVENT(aEvent) && !NS_IS_CONTENT_COMMAND_EVENT(aEvent);
aEvent->eventStructType != NS_ACCESSIBLE_EVENT;
} }
/** /**

View File

@ -3949,27 +3949,6 @@ bool nsWindow::DispatchMouseEvent(PRUint32 aEventType, WPARAM wParam,
return result; 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) bool nsWindow::DispatchFocusToTopLevelWindow(PRUint32 aEventType)
{ {
if (aEventType == NS_ACTIVATE) if (aEventType == NS_ACTIVATE)
@ -7413,8 +7392,7 @@ bool nsWindow::AssociateDefaultIMC(bool aAssociate)
#ifdef DEBUG_WMGETOBJECT #ifdef DEBUG_WMGETOBJECT
#define NS_LOG_WMGETOBJECT_WNDACC(aWnd) \ #define NS_LOG_WMGETOBJECT_WNDACC(aWnd) \
Accessible* acc = aWnd ? \ Accessible* acc = aWnd ? aWind->GetAccessible() : nullptr; \
aWnd->DispatchAccessibleEvent(NS_GETACCESSIBLE) : nullptr; \
PR_LOG(gWindowsLog, PR_LOG_ALWAYS, (" acc: %p", acc)); \ PR_LOG(gWindowsLog, PR_LOG_ALWAYS, (" acc: %p", acc)); \
if (acc) { \ if (acc) { \
nsAutoString name; \ nsAutoString name; \
@ -7422,7 +7400,7 @@ bool nsWindow::AssociateDefaultIMC(bool aAssociate)
PR_LOG(gWindowsLog, PR_LOG_ALWAYS, \ PR_LOG(gWindowsLog, PR_LOG_ALWAYS, \
(", accname: %s", NS_ConvertUTF16toUTF8(name).get())); \ (", accname: %s", NS_ConvertUTF16toUTF8(name).get())); \
nsCOMPtr<nsIAccessibleDocument> doc = do_QueryObject(acc); \ nsCOMPtr<nsIAccessibleDocument> doc = do_QueryObject(acc); \
void *hwnd = nullptr; \ void *hwnd = nullptr; \
doc->GetWindowHandle(&hwnd); \ doc->GetWindowHandle(&hwnd); \
PR_LOG(gWindowsLog, PR_LOG_ALWAYS, (", acc hwnd: %d", hwnd)); \ PR_LOG(gWindowsLog, PR_LOG_ALWAYS, (", acc hwnd: %d", hwnd)); \
} }
@ -7466,7 +7444,7 @@ nsWindow::GetRootAccessible()
NS_LOG_WMGETOBJECT_THISWND NS_LOG_WMGETOBJECT_THISWND
NS_LOG_WMGETOBJECT_WND("This Window", mWnd); NS_LOG_WMGETOBJECT_WND("This Window", mWnd);
return DispatchAccessibleEvent(NS_GETACCESSIBLE); return GetAccessible();
} }
#endif #endif

View File

@ -206,7 +206,6 @@ public:
void SuppressBlurEvents(bool aSuppress); // Called from nsFilePicker void SuppressBlurEvents(bool aSuppress); // Called from nsFilePicker
bool BlurEventsSuppressed(); bool BlurEventsSuppressed();
#ifdef ACCESSIBILITY #ifdef ACCESSIBILITY
Accessible* DispatchAccessibleEvent(PRUint32 aEventType);
Accessible* GetRootAccessible(); Accessible* GetRootAccessible();
#endif // ACCESSIBILITY #endif // ACCESSIBILITY

View File

@ -22,6 +22,8 @@
#include "BasicLayers.h" #include "BasicLayers.h"
#include "LayerManagerOGL.h" #include "LayerManagerOGL.h"
#include "nsIXULRuntime.h" #include "nsIXULRuntime.h"
#include "nsIXULWindow.h"
#include "nsIDocShell.h"
#include "nsView.h" #include "nsView.h"
#include "nsIViewManager.h" #include "nsIViewManager.h"
#include "nsEventStateManager.h" #include "nsEventStateManager.h"
@ -31,6 +33,10 @@
#include "prenv.h" #include "prenv.h"
#include "mozilla/Attributes.h" #include "mozilla/Attributes.h"
#ifdef ACCESSIBILITY
#include "nsAccessibilityService.h"
#endif
#ifdef DEBUG #ifdef DEBUG
#include "nsIObserver.h" #include "nsIObserver.h"
@ -1339,16 +1345,34 @@ const widget::SizeConstraints& nsBaseWidget::GetSizeConstraints() const
return mSizeConstraints; 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); nsCOMPtr<nsIXULWindow> window(do_QueryInterface(static_cast<nsISupports *>(clientData)));
return view ? view->GetViewManager()->GetPresShell() : nullptr; if (window) {
nsCOMPtr<nsIDocShell> docShell;
window->GetDocShell(getter_AddRefs(docShell));
if (docShell) {
nsCOMPtr<nsIPresShell> presShell;
docShell->GetPresShell(getter_AddRefs(presShell));
return presShell.get();
}
}
else {
nsIView* view = nsView::GetViewFor(aWidget);
if (view) {
return view->GetViewManager()->GetPresShell();
}
}
return nullptr;
} }
void void
nsBaseWidget::NotifySizeMoveDone() nsBaseWidget::NotifySizeMoveDone()
{ {
nsIPresShell* presShell = GetPresShell(this); nsIPresShell* presShell = GetPresShell(this, nullptr);
if (presShell) { if (presShell) {
presShell->WindowSizeMoveDone(); presShell->WindowSizeMoveDone();
} }
@ -1357,7 +1381,7 @@ nsBaseWidget::NotifySizeMoveDone()
void void
nsBaseWidget::NotifySysColorChanged() nsBaseWidget::NotifySysColorChanged()
{ {
nsIPresShell* presShell = GetPresShell(this); nsIPresShell* presShell = GetPresShell(this, nullptr);
if (presShell) { if (presShell) {
presShell->SysColorChanged(); presShell->SysColorChanged();
} }
@ -1366,12 +1390,38 @@ nsBaseWidget::NotifySysColorChanged()
void void
nsBaseWidget::NotifyThemeChanged() nsBaseWidget::NotifyThemeChanged()
{ {
nsIPresShell* presShell = GetPresShell(this); nsIPresShell* presShell = GetPresShell(this, nullptr);
if (presShell) { if (presShell) {
presShell->ThemeChanged(); 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<nsISupports> 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<nsIAccessibilityService> accService = services::GetAccessibilityService();
if (accService) {
return accService->GetRootDocumentAccessible(presShell, nsContentUtils::IsSafeToRunScript());
}
return nullptr;
}
#endif
#ifdef DEBUG #ifdef DEBUG
////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////
// //

View File

@ -19,6 +19,10 @@ class nsIContent;
class nsAutoRollup; class nsAutoRollup;
class gfxContext; class gfxContext;
#ifdef ACCESSIBILITY
class Accessible;
#endif
namespace mozilla { namespace mozilla {
namespace layers { namespace layers {
class BasicLayerManager; class BasicLayerManager;
@ -167,6 +171,11 @@ public:
void NotifySysColorChanged(); void NotifySysColorChanged();
void NotifyThemeChanged(); void NotifyThemeChanged();
#ifdef ACCESSIBILITY
// Get the accessible for the window.
Accessible* GetAccessible();
#endif
nsPopupLevel PopupLevel() { return mPopupLevel; } nsPopupLevel PopupLevel() { return mPopupLevel; }
virtual nsIntSize ClientToWindowSize(const nsIntSize& aClientSize) virtual nsIntSize ClientToWindowSize(const nsIntSize& aClientSize)

View File

@ -428,14 +428,6 @@ nsWebShellWindow::HandleEvent(nsGUIEvent *aEvent)
break; break;
} }
case NS_GETACCESSIBLE: {
nsCOMPtr<nsIPresShell> presShell;
docShell->GetPresShell(getter_AddRefs(presShell));
if (presShell) {
presShell->HandleEventWithTarget(aEvent, nullptr, nullptr, &result);
}
break;
}
default: default:
break; break;