2012-05-21 04:12:37 -07: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-27 18:46:11 -07:00
|
|
|
|
|
|
|
#include "FocusManager.h"
|
|
|
|
|
2012-04-13 07:17:03 -07:00
|
|
|
#include "Accessible-inl.h"
|
2013-11-08 16:25:29 -08:00
|
|
|
#include "AccIterator.h"
|
2012-06-01 11:39:47 -07:00
|
|
|
#include "DocAccessible-inl.h"
|
2011-09-27 18:46:11 -07:00
|
|
|
#include "nsAccessibilityService.h"
|
|
|
|
#include "nsAccUtils.h"
|
2012-07-27 21:21:40 -07:00
|
|
|
#include "nsEventShell.h"
|
2012-01-11 19:07:35 -08:00
|
|
|
#include "Role.h"
|
2011-09-27 18:46:11 -07:00
|
|
|
|
2011-10-25 23:42:20 -07:00
|
|
|
#include "nsEventStateManager.h"
|
2011-09-27 18:46:11 -07:00
|
|
|
#include "nsFocusManager.h"
|
2013-09-10 15:18:59 -07:00
|
|
|
#include "mozilla/dom/Element.h"
|
2011-09-27 18:46:11 -07:00
|
|
|
|
|
|
|
namespace dom = mozilla::dom;
|
|
|
|
using namespace mozilla::a11y;
|
|
|
|
|
|
|
|
FocusManager::FocusManager()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
FocusManager::~FocusManager()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible*
|
2011-09-27 18:46:11 -07:00
|
|
|
FocusManager::FocusedAccessible() const
|
|
|
|
{
|
|
|
|
if (mActiveItem)
|
|
|
|
return mActiveItem;
|
|
|
|
|
|
|
|
nsINode* focusedNode = FocusedDOMNode();
|
2012-02-07 14:38:54 -08:00
|
|
|
if (focusedNode) {
|
2012-05-27 02:01:40 -07:00
|
|
|
DocAccessible* doc =
|
2012-02-07 14:38:54 -08:00
|
|
|
GetAccService()->GetDocAccessible(focusedNode->OwnerDoc());
|
2012-07-30 07:20:58 -07:00
|
|
|
return doc ? doc->GetAccessibleOrContainer(focusedNode) : nullptr;
|
2012-02-07 14:38:54 -08:00
|
|
|
}
|
2011-09-27 18:46:11 -07:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2011-09-27 18:46:11 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-05-28 18:18:45 -07:00
|
|
|
FocusManager::IsFocused(const Accessible* aAccessible) const
|
2011-09-27 18:46:11 -07: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 03:53:36 -07:00
|
|
|
if (focusedNode->OwnerDoc() == aAccessible->GetNode()->OwnerDoc()) {
|
2012-05-27 02:01:40 -07:00
|
|
|
DocAccessible* doc =
|
2012-02-07 14:38:54 -08:00
|
|
|
GetAccService()->GetDocAccessible(focusedNode->OwnerDoc());
|
2011-09-27 18:46:11 -07:00
|
|
|
return aAccessible ==
|
2012-09-05 04:03:39 -07:00
|
|
|
(doc ? doc->GetAccessibleOrContainer(focusedNode) : nullptr);
|
2011-09-27 18:46:11 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-05-28 18:18:45 -07:00
|
|
|
FocusManager::IsFocusWithin(const Accessible* aContainer) const
|
2011-09-27 18:46:11 -07:00
|
|
|
{
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* child = FocusedAccessible();
|
2011-09-27 18:46:11 -07:00
|
|
|
while (child) {
|
|
|
|
if (child == aContainer)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
child = child->Parent();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
FocusManager::FocusDisposition
|
2012-05-28 18:18:45 -07:00
|
|
|
FocusManager::IsInOrContainsFocus(const Accessible* aAccessible) const
|
2011-09-27 18:46:11 -07:00
|
|
|
{
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* focus = FocusedAccessible();
|
2011-09-27 18:46:11 -07:00
|
|
|
if (!focus)
|
|
|
|
return eNone;
|
|
|
|
|
|
|
|
// If focused.
|
|
|
|
if (focus == aAccessible)
|
|
|
|
return eFocused;
|
|
|
|
|
|
|
|
// If contains the focus.
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* child = focus->Parent();
|
2011-09-27 18:46:11 -07: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 02:57:09 -07:00
|
|
|
#ifdef A11Y_LOG
|
2012-09-26 16:53:23 -07:00
|
|
|
if (logging::IsEnabled(logging::eFocus))
|
|
|
|
logging::FocusNotificationTarget("DOM focus", "Target", aTarget);
|
|
|
|
#endif
|
2011-09-27 18:46:11 -07:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
mActiveItem = nullptr;
|
2011-09-27 18:46:11 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsINode> targetNode(do_QueryInterface(aTarget));
|
|
|
|
if (targetNode) {
|
2012-05-27 02:01:40 -07:00
|
|
|
DocAccessible* document =
|
2011-10-18 03:53:36 -07:00
|
|
|
GetAccService()->GetDocAccessible(targetNode->OwnerDoc());
|
2011-09-27 18:46:11 -07:00
|
|
|
if (document) {
|
|
|
|
// Set selection listener for focused element.
|
2013-03-07 04:16:10 -08:00
|
|
|
if (targetNode->IsElement())
|
|
|
|
SelectionMgr()->SetControlSelectionListener(targetNode->AsElement());
|
2011-09-27 18:46:11 -07:00
|
|
|
|
|
|
|
document->HandleNotification<FocusManager, nsINode>
|
|
|
|
(this, &FocusManager::ProcessDOMFocus, targetNode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FocusManager::NotifyOfDOMBlur(nsISupports* aTarget)
|
|
|
|
{
|
2012-10-04 02:57:09 -07:00
|
|
|
#ifdef A11Y_LOG
|
2012-09-26 16:53:23 -07:00
|
|
|
if (logging::IsEnabled(logging::eFocus))
|
|
|
|
logging::FocusNotificationTarget("DOM blur", "Target", aTarget);
|
|
|
|
#endif
|
2011-09-27 18:46:11 -07:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
mActiveItem = nullptr;
|
2011-09-27 18:46:11 -07: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 03:53:36 -07:00
|
|
|
if (targetNode && targetNode->OwnerDoc() == FocusedDOMDocument()) {
|
|
|
|
nsIDocument* DOMDoc = targetNode->OwnerDoc();
|
2012-05-27 02:01:40 -07:00
|
|
|
DocAccessible* document =
|
2011-09-27 18:46:11 -07:00
|
|
|
GetAccService()->GetDocAccessible(DOMDoc);
|
|
|
|
if (document) {
|
2013-03-22 18:59:48 -07:00
|
|
|
// Clear selection listener for previously focused element.
|
|
|
|
if (targetNode->IsElement())
|
|
|
|
SelectionMgr()->ClearControlSelectionListener();
|
|
|
|
|
2011-09-27 18:46:11 -07:00
|
|
|
document->HandleNotification<FocusManager, nsINode>
|
|
|
|
(this, &FocusManager::ProcessDOMFocus, DOMDoc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-05-28 18:18:45 -07:00
|
|
|
FocusManager::ActiveItemChanged(Accessible* aItem, bool aCheckIfActive)
|
2011-09-27 18:46:11 -07:00
|
|
|
{
|
2012-10-04 02:57:09 -07:00
|
|
|
#ifdef A11Y_LOG
|
2012-09-26 16:53:23 -07:00
|
|
|
if (logging::IsEnabled(logging::eFocus))
|
|
|
|
logging::FocusNotificationTarget("active item changed", "Item", aItem);
|
|
|
|
#endif
|
2011-09-27 18:46:11 -07:00
|
|
|
|
|
|
|
// Nothing changed, happens for XUL trees and HTML selects.
|
|
|
|
if (aItem && aItem == mActiveItem)
|
|
|
|
return;
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
mActiveItem = nullptr;
|
2011-09-27 18:46:11 -07:00
|
|
|
|
|
|
|
if (aItem && aCheckIfActive) {
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* widget = aItem->ContainerWidget();
|
2012-10-04 02:57:09 -07:00
|
|
|
#ifdef A11Y_LOG
|
2012-09-26 16:53:23 -07:00
|
|
|
if (logging::IsEnabled(logging::eFocus))
|
|
|
|
logging::ActiveWidget(widget);
|
|
|
|
#endif
|
2011-09-27 18:46:11 -07: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-28 18:18:45 -07:00
|
|
|
Accessible* target = FocusedAccessible();
|
2011-09-27 18:46:11 -07:00
|
|
|
if (target)
|
2011-11-09 14:52:00 -08:00
|
|
|
DispatchFocusEvent(target->Document(), target);
|
2011-09-27 18:46:11 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FocusManager::ForceFocusEvent()
|
|
|
|
{
|
|
|
|
nsINode* focusedNode = FocusedDOMNode();
|
|
|
|
if (focusedNode) {
|
2012-05-27 02:01:40 -07:00
|
|
|
DocAccessible* document =
|
2011-10-18 03:53:36 -07:00
|
|
|
GetAccService()->GetDocAccessible(focusedNode->OwnerDoc());
|
2011-09-27 18:46:11 -07:00
|
|
|
if (document) {
|
|
|
|
document->HandleNotification<FocusManager, nsINode>
|
|
|
|
(this, &FocusManager::ProcessDOMFocus, focusedNode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-05-27 02:01:40 -07:00
|
|
|
FocusManager::DispatchFocusEvent(DocAccessible* aDocument,
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* aTarget)
|
2011-09-27 18:46:11 -07:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aDocument, "No document for focused accessible!");
|
|
|
|
if (aDocument) {
|
|
|
|
nsRefPtr<AccEvent> event =
|
|
|
|
new AccEvent(nsIAccessibleEvent::EVENT_FOCUS, aTarget,
|
|
|
|
eAutoDetect, AccEvent::eCoalesceOfSameType);
|
2012-11-19 20:53:38 -08:00
|
|
|
aDocument->FireDelayedEvent(event);
|
2011-09-27 18:46:11 -07:00
|
|
|
|
2012-10-04 02:57:09 -07:00
|
|
|
#ifdef A11Y_LOG
|
2012-09-26 16:53:23 -07:00
|
|
|
if (logging::IsEnabled(logging::eFocus))
|
|
|
|
logging::FocusDispatched(aTarget);
|
|
|
|
#endif
|
2011-09-27 18:46:11 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FocusManager::ProcessDOMFocus(nsINode* aTarget)
|
|
|
|
{
|
2012-10-04 02:57:09 -07:00
|
|
|
#ifdef A11Y_LOG
|
2012-09-26 16:53:23 -07:00
|
|
|
if (logging::IsEnabled(logging::eFocus))
|
|
|
|
logging::FocusNotificationTarget("process DOM focus", "Target", aTarget);
|
|
|
|
#endif
|
2011-09-27 18:46:11 -07:00
|
|
|
|
2012-05-27 02:01:40 -07:00
|
|
|
DocAccessible* document =
|
2011-10-18 03:53:36 -07:00
|
|
|
GetAccService()->GetDocAccessible(aTarget->OwnerDoc());
|
2011-09-27 18:46:11 -07:00
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* target = document->GetAccessibleOrContainer(aTarget);
|
2012-02-07 14:38:54 -08:00
|
|
|
if (target && document) {
|
2011-09-27 18:46:11 -07:00
|
|
|
// Check if still focused. Otherwise we can end up with storing the active
|
|
|
|
// item for control that isn't focused anymore.
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* DOMFocus =
|
2012-02-07 14:38:54 -08:00
|
|
|
document->GetAccessibleOrContainer(FocusedDOMNode());
|
2011-09-27 18:46:11 -07:00
|
|
|
if (target != DOMFocus)
|
|
|
|
return;
|
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* activeItem = target->CurrentItem();
|
2011-09-27 18:46:11 -07: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-28 18:18:45 -07:00
|
|
|
Accessible* target = aEvent->GetAccessible();
|
2011-09-27 18:46:11 -07:00
|
|
|
if (target != mActiveItem) {
|
2012-02-11 18:35:55 -08:00
|
|
|
|
2011-09-27 18:46:11 -07: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 02:01:40 -07:00
|
|
|
DocAccessible* document = aEvent->GetDocAccessible();
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* DOMFocus = document->GetAccessibleOrContainer(FocusedDOMNode());
|
2012-02-11 18:35:55 -08:00
|
|
|
|
2011-09-27 18:46:11 -07:00
|
|
|
if (target != DOMFocus)
|
|
|
|
return;
|
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* activeItem = target->CurrentItem();
|
2011-09-27 18:46:11 -07:00
|
|
|
if (activeItem) {
|
|
|
|
mActiveItem = activeItem;
|
|
|
|
target = activeItem;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fire menu start/end events for ARIA menus.
|
2013-11-13 05:58:12 -08:00
|
|
|
if (target->IsARIARole(nsGkAtoms::menuitem)) {
|
2011-09-27 18:46:11 -07:00
|
|
|
// The focus was moved into menu.
|
2013-11-08 16:25:29 -08: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();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If no required context role then check aria-owns relation.
|
|
|
|
RelatedAccIterator iter(child->Document(), child->GetContent(),
|
|
|
|
nsGkAtoms::aria_owns);
|
|
|
|
parent = iter.Next();
|
|
|
|
}
|
2011-09-27 18:46:11 -07:00
|
|
|
|
|
|
|
if (ARIAMenubar != mActiveARIAMenubar) {
|
|
|
|
// Leaving ARIA menu. Fire menu_end event on current menubar.
|
|
|
|
if (mActiveARIAMenubar) {
|
|
|
|
nsRefPtr<AccEvent> menuEndEvent =
|
|
|
|
new AccEvent(nsIAccessibleEvent::EVENT_MENU_END, mActiveARIAMenubar,
|
2013-10-26 07:58:53 -07:00
|
|
|
aEvent->FromUserInput());
|
2011-09-27 18:46:11 -07:00
|
|
|
nsEventShell::FireEvent(menuEndEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
mActiveARIAMenubar = ARIAMenubar;
|
|
|
|
|
|
|
|
// Entering ARIA menu. Fire menu_start event.
|
|
|
|
if (mActiveARIAMenubar) {
|
|
|
|
nsRefPtr<AccEvent> menuStartEvent =
|
|
|
|
new AccEvent(nsIAccessibleEvent::EVENT_MENU_START,
|
2013-10-26 07:58:53 -07:00
|
|
|
mActiveARIAMenubar, aEvent->FromUserInput());
|
2011-09-27 18:46:11 -07:00
|
|
|
nsEventShell::FireEvent(menuStartEvent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (mActiveARIAMenubar) {
|
|
|
|
// Focus left a menu. Fire menu_end event.
|
|
|
|
nsRefPtr<AccEvent> menuEndEvent =
|
|
|
|
new AccEvent(nsIAccessibleEvent::EVENT_MENU_END, mActiveARIAMenubar,
|
2013-10-26 07:58:53 -07:00
|
|
|
aEvent->FromUserInput());
|
2011-09-27 18:46:11 -07:00
|
|
|
nsEventShell::FireEvent(menuEndEvent);
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
mActiveARIAMenubar = nullptr;
|
2011-09-27 18:46:11 -07:00
|
|
|
}
|
|
|
|
|
2012-10-04 02:57:09 -07:00
|
|
|
#ifdef A11Y_LOG
|
2012-09-26 16:53:23 -07:00
|
|
|
if (logging::IsEnabled(logging::eFocus))
|
|
|
|
logging::FocusNotificationTarget("fire focus event", "Target", target);
|
|
|
|
#endif
|
2011-09-27 18:46:11 -07:00
|
|
|
|
|
|
|
nsRefPtr<AccEvent> focusEvent =
|
2013-10-26 07:58:53 -07:00
|
|
|
new AccEvent(nsIAccessibleEvent::EVENT_FOCUS, target, aEvent->FromUserInput());
|
2011-09-27 18:46:11 -07:00
|
|
|
nsEventShell::FireEvent(focusEvent);
|
2011-10-07 22:16:37 -07: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 02:01:40 -07:00
|
|
|
DocAccessible* targetDocument = target->Document();
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* anchorJump = targetDocument->AnchorJump();
|
2011-10-07 22:16:37 -07: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 07:58:53 -07:00
|
|
|
anchorJump, aEvent->FromUserInput());
|
2011-10-07 22:16:37 -07:00
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
targetDocument->SetAnchorJump(nullptr);
|
2011-10-07 22:16:37 -07:00
|
|
|
}
|
2011-09-27 18:46:11 -07:00
|
|
|
}
|
|
|
|
|
2011-10-25 23:42:20 -07:00
|
|
|
nsINode*
|
|
|
|
FocusManager::FocusedDOMNode() const
|
2011-09-27 18:46:11 -07:00
|
|
|
{
|
|
|
|
nsFocusManager* DOMFocusManager = nsFocusManager::GetFocusManager();
|
2011-10-25 23:42:20 -07: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) {
|
|
|
|
if (nsEventStateManager::IsRemoteTarget(focusedElm))
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2011-10-25 23:42:20 -07:00
|
|
|
return focusedElm;
|
|
|
|
}
|
2011-09-27 18:46:11 -07:00
|
|
|
|
2011-10-25 23:42:20 -07:00
|
|
|
// Otherwise the focus can be on DOM document.
|
2012-05-22 02:25:44 -07:00
|
|
|
nsPIDOMWindow* focusedWnd = DOMFocusManager->GetFocusedWindow();
|
2012-07-30 07:20:58 -07:00
|
|
|
return focusedWnd ? focusedWnd->GetExtantDoc() : nullptr;
|
2011-09-27 18:46:11 -07:00
|
|
|
}
|
2011-10-25 23:42:20 -07:00
|
|
|
|
|
|
|
nsIDocument*
|
|
|
|
FocusManager::FocusedDOMDocument() const
|
|
|
|
{
|
|
|
|
nsINode* focusedNode = FocusedDOMNode();
|
2012-07-30 07:20:58 -07:00
|
|
|
return focusedNode ? focusedNode->OwnerDoc() : nullptr;
|
2011-10-25 23:42:20 -07:00
|
|
|
}
|