Skip to content

Commit

Permalink
Bug 1309271 - Fire accessibility focus events from focused content el…
Browse files Browse the repository at this point in the history
…ements when focus changes from chrome to content. r=surkov

MozReview-Commit-ID: 5Iu2TQ58kGa
  • Loading branch information
jmathies committed Jun 6, 2017
1 parent d6f6f61 commit 10b72ec
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 2 deletions.
25 changes: 24 additions & 1 deletion accessible/base/FocusManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "nsFocusManager.h"
#include "mozilla/EventStateManager.h"
#include "mozilla/dom/Element.h"
#include "mozilla/dom/TabParent.h"

namespace mozilla {
namespace a11y {
Expand Down Expand Up @@ -190,12 +191,34 @@ FocusManager::ActiveItemChanged(Accessible* aItem, bool aCheckIfActive)
}
mActiveItem = aItem;

// If mActiveItem is null, we might need to shift a11y focus to a remote
// element.
if (!mActiveItem && XRE_IsParentProcess()) {
nsFocusManager* domfm = nsFocusManager::GetFocusManager();
if (domfm) {
nsIContent* focusedElm = domfm->GetFocusedContent();
if (focusedElm) {
bool remote = EventStateManager::IsRemoteTarget(focusedElm);
if (remote) {
dom::TabParent* tab = dom::TabParent::GetFrom(focusedElm);
if (tab) {
a11y::DocAccessibleParent* dap = tab->GetTopLevelDocAccessible();
if (dap) {
Unused << dap->SendRestoreFocus();
}
}
}
}
}
}

// If active item is changed then fire accessible focus event on it, otherwise
// if there's no an active item then fire focus event to accessible having
// DOM focus.
Accessible* target = FocusedAccessible();
if (target)
if (target) {
DispatchFocusEvent(target->Document(), target);
}
}

void
Expand Down
8 changes: 8 additions & 0 deletions accessible/ipc/other/DocAccessibleChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "DocAccessibleChild.h"

#include "nsAccessibilityService.h"
#include "Accessible-inl.h"
#include "ProxyAccessible.h"
#include "Relation.h"
Expand Down Expand Up @@ -2003,5 +2004,12 @@ DocAccessibleChild::RecvDOMNodeID(const uint64_t& aID, nsString* aDOMNodeID)
return IPC_OK();
}

mozilla::ipc::IPCResult
DocAccessibleChild::RecvRestoreFocus()
{
FocusMgr()->ForceFocusEvent();
return IPC_OK();
}

}
}
2 changes: 2 additions & 0 deletions accessible/ipc/other/DocAccessibleChild.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class DocAccessibleChild : public DocAccessibleChildBase
MOZ_COUNT_DTOR_INHERITED(DocAccessibleChild, DocAccessibleChildBase);
}

virtual mozilla::ipc::IPCResult RecvRestoreFocus() override;

/*
* Return the state for the accessible with given ID.
*/
Expand Down
6 changes: 6 additions & 0 deletions accessible/ipc/other/PDocAccessible.ipdl
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ parent:
child:
async __delete__();

/*
* Called as a result of focus shifting from chrome to content
* elements through keyboard navigation.
*/
async RestoreFocus();

// Accessible
nested(inside_sync) sync State(uint64_t aID) returns(uint64_t states);
nested(inside_sync) sync NativeState(uint64_t aID) returns(uint64_t states);
Expand Down
8 changes: 8 additions & 0 deletions accessible/ipc/win/DocAccessibleChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "DocAccessibleChild.h"

#include "nsAccessibilityService.h"
#include "Accessible-inl.h"
#include "mozilla/a11y/PlatformChild.h"
#include "mozilla/ClearOnShutdown.h"
Expand Down Expand Up @@ -307,6 +308,13 @@ DocAccessibleChild::SendBindChildDoc(DocAccessibleChild* aChildDoc,
return true;
}

ipc::IPCResult
DocAccessibleChild::RecvRestoreFocus()
{
FocusMgr()->ForceFocusEvent();
return IPC_OK();
}

} // namespace a11y
} // namespace mozilla

4 changes: 3 additions & 1 deletion accessible/ipc/win/DocAccessibleChild.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ class DocAccessibleChild : public DocAccessibleChildBase
virtual void Shutdown() override;

virtual ipc::IPCResult
RecvParentCOMProxy(const IAccessibleHolder& aParentCOMProxy) override;
RecvParentCOMProxy(const IAccessibleHolder& aParentCOMProxy) override;
virtual ipc::IPCResult
RecvEmulatedWindow(const WindowsHandle& aEmulatedWindowHandle,
const IAccessibleHolder& aEmulatedWindowCOMProxy) override;
virtual ipc::IPCResult
RecvRestoreFocus() override;

HWND GetNativeWindowHandle() const;
IAccessible* GetEmulatedWindowIAccessible() const { return mEmulatedWindowProxy.get(); }
Expand Down
5 changes: 5 additions & 0 deletions accessible/ipc/win/PDocAccessible.ipdl
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ child:
async ParentCOMProxy(IAccessibleHolder aParentCOMProxy);
async EmulatedWindow(WindowsHandle aEmulatedWindowHandle,
IAccessibleHolder aEmulatedWindowCOMProxy);
/*
* Called as a result of focus shifting from chrome to content
* elements through keyboard navigation.
*/
async RestoreFocus();

async __delete__();
};
Expand Down

0 comments on commit 10b72ec

Please sign in to comment.