2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-09-28 05:46:11 +04:00
|
|
|
|
|
|
|
#include "FocusManager.h"
|
|
|
|
|
2012-04-13 18:17:03 +04:00
|
|
|
#include "Accessible-inl.h"
|
2013-11-09 04:25:29 +04:00
|
|
|
#include "AccIterator.h"
|
2012-06-01 22:39:47 +04:00
|
|
|
#include "DocAccessible-inl.h"
|
2011-09-28 05:46:11 +04:00
|
|
|
#include "nsAccessibilityService.h"
|
|
|
|
#include "nsAccUtils.h"
|
2012-07-28 08:21:40 +04:00
|
|
|
#include "nsEventShell.h"
|
2012-01-12 07:07:35 +04:00
|
|
|
#include "Role.h"
|
2011-09-28 05:46:11 +04:00
|
|
|
|
|
|
|
#include "nsFocusManager.h"
|
2014-04-01 08:09:23 +04:00
|
|
|
#include "mozilla/EventStateManager.h"
|
2013-09-11 02:18:59 +04:00
|
|
|
#include "mozilla/dom/Element.h"
|
2011-09-28 05:46:11 +04:00
|
|
|
|
2014-04-01 08:09:23 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace a11y {
|
2011-09-28 05:46:11 +04:00
|
|
|
|
|
|
|
FocusManager::FocusManager()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
FocusManager::~FocusManager()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-05-29 05:18:45 +04:00
|
|
|
Accessible*
|
2011-09-28 05:46:11 +04:00
|
|
|
FocusManager::FocusedAccessible() const
|
|
|
|
{
|
|
|
|
if (mActiveItem)
|
|
|
|
return mActiveItem;
|
|
|
|
|
|
|
|
nsINode* focusedNode = FocusedDOMNode();
|
2012-02-08 02:38:54 +04:00
|
|
|
if (focusedNode) {
|
2012-05-27 13:01:40 +04:00
|
|
|
DocAccessible* doc =
|
2012-02-08 02:38:54 +04:00
|
|
|
GetAccService()->GetDocAccessible(focusedNode->OwnerDoc());
|
2014-03-06 04:36:56 +04:00
|
|
|
return doc ? doc->GetAccessibleEvenIfNotInMapOrContainer(focusedNode) : nullptr;
|
2012-02-08 02:38:54 +04:00
|
|
|
}
|
2011-09-28 05:46:11 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2011-09-28 05:46:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-05-29 05:18:45 +04:00
|
|
|
FocusManager::IsFocused(const Accessible* aAccessible) const
|
2011-09-28 05:46:11 +04:00
|
|
|
{
|
|
|
|
if (mActiveItem)
|
|
|
|
return mActiveItem == aAccessible;
|
|
|
|
|
|
|
|
nsINode* focusedNode = FocusedDOMNode();
|
|
|
|
if (focusedNode) {
|
|
|
|
// XXX: Before getting an accessible for node having a DOM focus make sure
|
|
|
|
// they belong to the same document because it can trigger unwanted document
|
|
|
|
// accessible creation for temporary about:blank document. Without this
|
|
|
|
// peculiarity we would end up with plain implementation based on
|
|
|
|
// FocusedAccessible() method call. Make sure this issue is fixed in
|
|
|
|
// bug 638465.
|
2011-10-18 14:53:36 +04:00
|
|
|
if (focusedNode->OwnerDoc() == aAccessible->GetNode()->OwnerDoc()) {
|
2012-05-27 13:01:40 +04:00
|
|
|
DocAccessible* doc =
|
2012-02-08 02:38:54 +04:00
|
|
|
GetAccService()->GetDocAccessible(focusedNode->OwnerDoc());
|
2011-09-28 05:46:11 +04:00
|
|
|
return aAccessible ==
|
2014-03-06 04:36:56 +04:00
|
|
|
(doc ? doc->GetAccessibleEvenIfNotInMapOrContainer(focusedNode) : nullptr);
|
2011-09-28 05:46:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-05-29 05:18:45 +04:00
|
|
|
FocusManager::IsFocusWithin(const Accessible* aContainer) const
|
2011-09-28 05:46:11 +04:00
|
|
|
{
|
2012-05-29 05:18:45 +04:00
|
|
|
Accessible* child = FocusedAccessible();
|
2011-09-28 05:46:11 +04:00
|
|
|
while (child) {
|
|
|
|
if (child == aContainer)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
child = child->Parent();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
FocusManager::FocusDisposition
|
2012-05-29 05:18:45 +04:00
|
|
|
FocusManager::IsInOrContainsFocus(const Accessible* aAccessible) const
|
2011-09-28 05:46:11 +04:00
|
|
|
{
|
2012-05-29 05:18:45 +04:00
|
|
|
Accessible* focus = FocusedAccessible();
|
2011-09-28 05:46:11 +04:00
|
|
|
if (!focus)
|
|
|
|
return eNone;
|
|
|
|
|
|
|
|
// If focused.
|
|
|
|
if (focus == aAccessible)
|
|
|
|
return eFocused;
|
|
|
|
|
|
|
|
// If contains the focus.
|
2012-05-29 05:18:45 +04:00
|
|
|
Accessible* child = focus->Parent();
|
2011-09-28 05:46:11 +04:00
|
|
|
while (child) {
|
|
|
|
if (child == aAccessible)
|
|
|
|
return eContainsFocus;
|
|
|
|
|
|
|
|
child = child->Parent();
|
|
|
|
}
|
|
|
|
|
|
|
|
// If contained by focus.
|
|
|
|
child = aAccessible->Parent();
|
|
|
|
while (child) {
|
|
|
|
if (child == focus)
|
|
|
|
return eContainedByFocus;
|
|
|
|
|
|
|
|
child = child->Parent();
|
|
|
|
}
|
|
|
|
|
|
|
|
return eNone;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FocusManager::NotifyOfDOMFocus(nsISupports* aTarget)
|
|
|
|
{
|
2012-10-04 13:57:09 +04:00
|
|
|
#ifdef A11Y_LOG
|
2012-09-27 03:53:23 +04:00
|
|
|
if (logging::IsEnabled(logging::eFocus))
|
|
|
|
logging::FocusNotificationTarget("DOM focus", "Target", aTarget);
|
|
|
|
#endif
|
2011-09-28 05:46:11 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
mActiveItem = nullptr;
|
2011-09-28 05:46:11 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsINode> targetNode(do_QueryInterface(aTarget));
|
|
|
|
if (targetNode) {
|
2012-05-27 13:01:40 +04:00
|
|
|
DocAccessible* document =
|
2011-10-18 14:53:36 +04:00
|
|
|
GetAccService()->GetDocAccessible(targetNode->OwnerDoc());
|
2011-09-28 05:46:11 +04:00
|
|
|
if (document) {
|
|
|
|
// Set selection listener for focused element.
|
2013-03-07 16:16:10 +04:00
|
|
|
if (targetNode->IsElement())
|
|
|
|
SelectionMgr()->SetControlSelectionListener(targetNode->AsElement());
|
2011-09-28 05:46:11 +04:00
|
|
|
|
|
|
|
document->HandleNotification<FocusManager, nsINode>
|
|
|
|
(this, &FocusManager::ProcessDOMFocus, targetNode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FocusManager::NotifyOfDOMBlur(nsISupports* aTarget)
|
|
|
|
{
|
2012-10-04 13:57:09 +04:00
|
|
|
#ifdef A11Y_LOG
|
2012-09-27 03:53:23 +04:00
|
|
|
if (logging::IsEnabled(logging::eFocus))
|
|
|
|
logging::FocusNotificationTarget("DOM blur", "Target", aTarget);
|
|
|
|
#endif
|
2011-09-28 05:46:11 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
mActiveItem = nullptr;
|
2011-09-28 05:46:11 +04:00
|
|
|
|
|
|
|
// If DOM document stays focused then fire accessible focus event to process
|
|
|
|
// the case when no element within this DOM document will be focused.
|
|
|
|
nsCOMPtr<nsINode> targetNode(do_QueryInterface(aTarget));
|
2011-10-18 14:53:36 +04:00
|
|
|
if (targetNode && targetNode->OwnerDoc() == FocusedDOMDocument()) {
|
|
|
|
nsIDocument* DOMDoc = targetNode->OwnerDoc();
|
2012-05-27 13:01:40 +04:00
|
|
|
DocAccessible* document =
|
2011-09-28 05:46:11 +04:00
|
|
|
GetAccService()->GetDocAccessible(DOMDoc);
|
|
|
|
if (document) {
|
2013-03-23 05:59:48 +04:00
|
|
|
// Clear selection listener for previously focused element.
|
|
|
|
if (targetNode->IsElement())
|
|
|
|
SelectionMgr()->ClearControlSelectionListener();
|
|
|
|
|
2011-09-28 05:46:11 +04:00
|
|
|
document->HandleNotification<FocusManager, nsINode>
|
|
|
|
(this, &FocusManager::ProcessDOMFocus, DOMDoc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-05-29 05:18:45 +04:00
|
|
|
FocusManager::ActiveItemChanged(Accessible* aItem, bool aCheckIfActive)
|
2011-09-28 05:46:11 +04:00
|
|
|
{
|
2012-10-04 13:57:09 +04:00
|
|
|
#ifdef A11Y_LOG
|
2012-09-27 03:53:23 +04:00
|
|
|
if (logging::IsEnabled(logging::eFocus))
|
|
|
|
logging::FocusNotificationTarget("active item changed", "Item", aItem);
|
|
|
|
#endif
|
2011-09-28 05:46:11 +04:00
|
|
|
|
|
|
|
// Nothing changed, happens for XUL trees and HTML selects.
|
|
|
|
if (aItem && aItem == mActiveItem)
|
|
|
|
return;
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
mActiveItem = nullptr;
|
2011-09-28 05:46:11 +04:00
|
|
|
|
|
|
|
if (aItem && aCheckIfActive) {
|
2012-05-29 05:18:45 +04:00
|
|
|
Accessible* widget = aItem->ContainerWidget();
|
2012-10-04 13:57:09 +04:00
|
|
|
#ifdef A11Y_LOG
|
2012-09-27 03:53:23 +04:00
|
|
|
if (logging::IsEnabled(logging::eFocus))
|
|
|
|
logging::ActiveWidget(widget);
|
|
|
|
#endif
|
2011-09-28 05:46:11 +04:00
|
|
|
if (!widget || !widget->IsActiveWidget() || !widget->AreItemsOperable())
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mActiveItem = aItem;
|
|
|
|
|
|
|
|
// 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.
|
2012-05-29 05:18:45 +04:00
|
|
|
Accessible* target = FocusedAccessible();
|
2011-09-28 05:46:11 +04:00
|
|
|
if (target)
|
2011-11-10 02:52:00 +04:00
|
|
|
DispatchFocusEvent(target->Document(), target);
|
2011-09-28 05:46:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FocusManager::ForceFocusEvent()
|
|
|
|
{
|
|
|
|
nsINode* focusedNode = FocusedDOMNode();
|
|
|
|
if (focusedNode) {
|
2012-05-27 13:01:40 +04:00
|
|
|
DocAccessible* document =
|
2011-10-18 14:53:36 +04:00
|
|
|
GetAccService()->GetDocAccessible(focusedNode->OwnerDoc());
|
2011-09-28 05:46:11 +04:00
|
|
|
if (document) {
|
|
|
|
document->HandleNotification<FocusManager, nsINode>
|
|
|
|
(this, &FocusManager::ProcessDOMFocus, focusedNode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-05-27 13:01:40 +04:00
|
|
|
FocusManager::DispatchFocusEvent(DocAccessible* aDocument,
|
2012-05-29 05:18:45 +04:00
|
|
|
Accessible* aTarget)
|
2011-09-28 05:46:11 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aDocument, "No document for focused accessible!");
|
|
|
|
if (aDocument) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<AccEvent> event =
|
2011-09-28 05:46:11 +04:00
|
|
|
new AccEvent(nsIAccessibleEvent::EVENT_FOCUS, aTarget,
|
|
|
|
eAutoDetect, AccEvent::eCoalesceOfSameType);
|
2012-11-20 08:53:38 +04:00
|
|
|
aDocument->FireDelayedEvent(event);
|
2011-09-28 05:46:11 +04:00
|
|
|
|
2012-10-04 13:57:09 +04:00
|
|
|
#ifdef A11Y_LOG
|
2012-09-27 03:53:23 +04:00
|
|
|
if (logging::IsEnabled(logging::eFocus))
|
|
|
|
logging::FocusDispatched(aTarget);
|
|
|
|
#endif
|
2011-09-28 05:46:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FocusManager::ProcessDOMFocus(nsINode* aTarget)
|
|
|
|
{
|
2012-10-04 13:57:09 +04:00
|
|
|
#ifdef A11Y_LOG
|
2012-09-27 03:53:23 +04:00
|
|
|
if (logging::IsEnabled(logging::eFocus))
|
|
|
|
logging::FocusNotificationTarget("process DOM focus", "Target", aTarget);
|
|
|
|
#endif
|
2011-09-28 05:46:11 +04:00
|
|
|
|
2012-05-27 13:01:40 +04:00
|
|
|
DocAccessible* document =
|
2011-10-18 14:53:36 +04:00
|
|
|
GetAccService()->GetDocAccessible(aTarget->OwnerDoc());
|
2014-03-29 01:22:53 +04:00
|
|
|
if (!document)
|
|
|
|
return;
|
2011-09-28 05:46:11 +04:00
|
|
|
|
2014-03-06 04:36:56 +04:00
|
|
|
Accessible* target = document->GetAccessibleEvenIfNotInMapOrContainer(aTarget);
|
2014-03-29 01:22:53 +04:00
|
|
|
if (target) {
|
2011-09-28 05:46:11 +04:00
|
|
|
// Check if still focused. Otherwise we can end up with storing the active
|
|
|
|
// item for control that isn't focused anymore.
|
2014-02-11 00:52:34 +04:00
|
|
|
nsINode* focusedNode = FocusedDOMNode();
|
|
|
|
if (!focusedNode)
|
|
|
|
return;
|
|
|
|
|
2014-03-06 04:36:56 +04:00
|
|
|
Accessible* DOMFocus =
|
|
|
|
document->GetAccessibleEvenIfNotInMapOrContainer(focusedNode);
|
2011-09-28 05:46:11 +04:00
|
|
|
if (target != DOMFocus)
|
|
|
|
return;
|
|
|
|
|
2012-05-29 05:18:45 +04:00
|
|
|
Accessible* activeItem = target->CurrentItem();
|
2011-09-28 05:46:11 +04:00
|
|
|
if (activeItem) {
|
|
|
|
mActiveItem = activeItem;
|
|
|
|
target = activeItem;
|
|
|
|
}
|
|
|
|
|
|
|
|
DispatchFocusEvent(document, target);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FocusManager::ProcessFocusEvent(AccEvent* aEvent)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aEvent->GetEventType() == nsIAccessibleEvent::EVENT_FOCUS,
|
|
|
|
"Focus event is expected!");
|
|
|
|
|
|
|
|
// Emit focus event if event target is the active item. Otherwise then check
|
|
|
|
// if it's still focused and then update active item and emit focus event.
|
2012-05-29 05:18:45 +04:00
|
|
|
Accessible* target = aEvent->GetAccessible();
|
2011-09-28 05:46:11 +04:00
|
|
|
if (target != mActiveItem) {
|
2012-02-12 06:35:55 +04:00
|
|
|
|
2011-09-28 05:46:11 +04:00
|
|
|
// Check if still focused. Otherwise we can end up with storing the active
|
|
|
|
// item for control that isn't focused anymore.
|
2012-05-27 13:01:40 +04:00
|
|
|
DocAccessible* document = aEvent->GetDocAccessible();
|
2014-02-11 00:52:34 +04:00
|
|
|
nsINode* focusedNode = FocusedDOMNode();
|
|
|
|
if (!focusedNode)
|
|
|
|
return;
|
2012-02-12 06:35:55 +04:00
|
|
|
|
2014-03-06 04:36:56 +04:00
|
|
|
Accessible* DOMFocus =
|
|
|
|
document->GetAccessibleEvenIfNotInMapOrContainer(focusedNode);
|
2011-09-28 05:46:11 +04:00
|
|
|
if (target != DOMFocus)
|
|
|
|
return;
|
|
|
|
|
2012-05-29 05:18:45 +04:00
|
|
|
Accessible* activeItem = target->CurrentItem();
|
2011-09-28 05:46:11 +04:00
|
|
|
if (activeItem) {
|
|
|
|
mActiveItem = activeItem;
|
|
|
|
target = activeItem;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fire menu start/end events for ARIA menus.
|
2013-11-13 17:58:12 +04:00
|
|
|
if (target->IsARIARole(nsGkAtoms::menuitem)) {
|
2011-09-28 05:46:11 +04:00
|
|
|
// The focus was moved into menu.
|
2014-02-11 02:18:43 +04:00
|
|
|
bool tryOwnsParent = true;
|
2013-11-09 04:25:29 +04:00
|
|
|
Accessible* ARIAMenubar = nullptr;
|
|
|
|
Accessible* child = target;
|
|
|
|
Accessible* parent = child->Parent();
|
|
|
|
while (parent) {
|
|
|
|
nsRoleMapEntry* roleMap = parent->ARIARoleMap();
|
|
|
|
if (roleMap) {
|
|
|
|
if (roleMap->Is(nsGkAtoms::menubar)) {
|
|
|
|
ARIAMenubar = parent;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Go up in the parent chain of the menu hierarchy.
|
|
|
|
if (roleMap->Is(nsGkAtoms::menuitem) || roleMap->Is(nsGkAtoms::menu)) {
|
|
|
|
child = parent;
|
|
|
|
parent = child->Parent();
|
2014-02-11 02:18:43 +04:00
|
|
|
tryOwnsParent = true;
|
2013-11-09 04:25:29 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If no required context role then check aria-owns relation.
|
2014-02-11 02:18:43 +04:00
|
|
|
if (!tryOwnsParent)
|
|
|
|
break;
|
|
|
|
|
2015-01-21 00:16:08 +03:00
|
|
|
parent = ARIAOwnedByIterator(child).Next();
|
2014-02-11 02:18:43 +04:00
|
|
|
tryOwnsParent = false;
|
2013-11-09 04:25:29 +04:00
|
|
|
}
|
2011-09-28 05:46:11 +04:00
|
|
|
|
|
|
|
if (ARIAMenubar != mActiveARIAMenubar) {
|
|
|
|
// Leaving ARIA menu. Fire menu_end event on current menubar.
|
|
|
|
if (mActiveARIAMenubar) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<AccEvent> menuEndEvent =
|
2011-09-28 05:46:11 +04:00
|
|
|
new AccEvent(nsIAccessibleEvent::EVENT_MENU_END, mActiveARIAMenubar,
|
2013-10-26 18:58:53 +04:00
|
|
|
aEvent->FromUserInput());
|
2011-09-28 05:46:11 +04:00
|
|
|
nsEventShell::FireEvent(menuEndEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
mActiveARIAMenubar = ARIAMenubar;
|
|
|
|
|
|
|
|
// Entering ARIA menu. Fire menu_start event.
|
|
|
|
if (mActiveARIAMenubar) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<AccEvent> menuStartEvent =
|
2011-09-28 05:46:11 +04:00
|
|
|
new AccEvent(nsIAccessibleEvent::EVENT_MENU_START,
|
2013-10-26 18:58:53 +04:00
|
|
|
mActiveARIAMenubar, aEvent->FromUserInput());
|
2011-09-28 05:46:11 +04:00
|
|
|
nsEventShell::FireEvent(menuStartEvent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (mActiveARIAMenubar) {
|
|
|
|
// Focus left a menu. Fire menu_end event.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<AccEvent> menuEndEvent =
|
2011-09-28 05:46:11 +04:00
|
|
|
new AccEvent(nsIAccessibleEvent::EVENT_MENU_END, mActiveARIAMenubar,
|
2013-10-26 18:58:53 +04:00
|
|
|
aEvent->FromUserInput());
|
2011-09-28 05:46:11 +04:00
|
|
|
nsEventShell::FireEvent(menuEndEvent);
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
mActiveARIAMenubar = nullptr;
|
2011-09-28 05:46:11 +04:00
|
|
|
}
|
|
|
|
|
2012-10-04 13:57:09 +04:00
|
|
|
#ifdef A11Y_LOG
|
2012-09-27 03:53:23 +04:00
|
|
|
if (logging::IsEnabled(logging::eFocus))
|
|
|
|
logging::FocusNotificationTarget("fire focus event", "Target", target);
|
|
|
|
#endif
|
2011-09-28 05:46:11 +04:00
|
|
|
|
2014-05-01 19:45:40 +04:00
|
|
|
// Reset cached caret value. The cache will be updated upon processing the
|
|
|
|
// next caret move event. This ensures that we will return the correct caret
|
|
|
|
// offset before the caret move event is handled.
|
|
|
|
SelectionMgr()->ResetCaretOffset();
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<AccEvent> focusEvent =
|
2013-10-26 18:58:53 +04:00
|
|
|
new AccEvent(nsIAccessibleEvent::EVENT_FOCUS, target, aEvent->FromUserInput());
|
2011-09-28 05:46:11 +04:00
|
|
|
nsEventShell::FireEvent(focusEvent);
|
2011-10-08 09:16:37 +04:00
|
|
|
|
|
|
|
// Fire scrolling_start event when the document receives the focus if it has
|
|
|
|
// an anchor jump. If an accessible within the document receive the focus
|
|
|
|
// then null out the anchor jump because it no longer applies.
|
2012-05-27 13:01:40 +04:00
|
|
|
DocAccessible* targetDocument = target->Document();
|
2012-05-29 05:18:45 +04:00
|
|
|
Accessible* anchorJump = targetDocument->AnchorJump();
|
2011-10-08 09:16:37 +04:00
|
|
|
if (anchorJump) {
|
|
|
|
if (target == targetDocument) {
|
|
|
|
// XXX: bug 625699, note in some cases the node could go away before we
|
|
|
|
// we receive focus event, for example if the node is removed from DOM.
|
|
|
|
nsEventShell::FireEvent(nsIAccessibleEvent::EVENT_SCROLLING_START,
|
2013-10-26 18:58:53 +04:00
|
|
|
anchorJump, aEvent->FromUserInput());
|
2011-10-08 09:16:37 +04:00
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
targetDocument->SetAnchorJump(nullptr);
|
2011-10-08 09:16:37 +04:00
|
|
|
}
|
2011-09-28 05:46:11 +04:00
|
|
|
}
|
|
|
|
|
2011-10-26 10:42:20 +04:00
|
|
|
nsINode*
|
|
|
|
FocusManager::FocusedDOMNode() const
|
2011-09-28 05:46:11 +04:00
|
|
|
{
|
|
|
|
nsFocusManager* DOMFocusManager = nsFocusManager::GetFocusManager();
|
2011-10-26 10:42:20 +04:00
|
|
|
nsIContent* focusedElm = DOMFocusManager->GetFocusedContent();
|
|
|
|
|
|
|
|
// No focus on remote target elements like xul:browser having DOM focus and
|
|
|
|
// residing in chrome process because it means an element in content process
|
|
|
|
// keeps the focus.
|
|
|
|
if (focusedElm) {
|
2014-04-01 08:09:23 +04:00
|
|
|
if (EventStateManager::IsRemoteTarget(focusedElm)) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2014-04-01 08:09:23 +04:00
|
|
|
}
|
2011-10-26 10:42:20 +04:00
|
|
|
return focusedElm;
|
|
|
|
}
|
2011-09-28 05:46:11 +04:00
|
|
|
|
2011-10-26 10:42:20 +04:00
|
|
|
// Otherwise the focus can be on DOM document.
|
2012-05-22 13:25:44 +04:00
|
|
|
nsPIDOMWindow* focusedWnd = DOMFocusManager->GetFocusedWindow();
|
2012-07-30 18:20:58 +04:00
|
|
|
return focusedWnd ? focusedWnd->GetExtantDoc() : nullptr;
|
2011-09-28 05:46:11 +04:00
|
|
|
}
|
2011-10-26 10:42:20 +04:00
|
|
|
|
|
|
|
nsIDocument*
|
|
|
|
FocusManager::FocusedDOMDocument() const
|
|
|
|
{
|
|
|
|
nsINode* focusedNode = FocusedDOMNode();
|
2012-07-30 18:20:58 +04:00
|
|
|
return focusedNode ? focusedNode->OwnerDoc() : nullptr;
|
2011-10-26 10:42:20 +04:00
|
|
|
}
|
2014-04-01 08:09:23 +04:00
|
|
|
|
|
|
|
} // namespace a11y
|
|
|
|
} // namespace mozilla
|