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;
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);

View File

@ -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<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();
nsresult rv = NS_OK;

View File

@ -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<nsIAccessible*>(event.mAccessible));
Accessible* acc = GetAccessible();
mAccessible = do_GetWeakReference(static_cast<nsIAccessible *>(acc));
NS_IF_ADDREF(event.mAccessible);
return event.mAccessible;
NS_IF_ADDREF(acc);
return acc;
}
#endif

View File

@ -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)
{

View File

@ -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.
*

View File

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

View File

@ -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);
}
/**

View File

@ -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<nsIAccessibleDocument> 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

View File

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

View File

@ -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<nsIXULWindow> window(do_QueryInterface(static_cast<nsISupports *>(clientData)));
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
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<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
//////////////////////////////////////////////////////////////
//

View File

@ -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)

View File

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