2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
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/. */
|
2000-09-22 09:02:20 +04:00
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
2003-02-28 04:04:45 +03:00
|
|
|
#include "nsXBLPrototypeHandler.h"
|
2000-09-22 09:02:20 +04:00
|
|
|
#include "nsXBLWindowKeyHandler.h"
|
|
|
|
#include "nsIContent.h"
|
2017-10-03 01:05:19 +03:00
|
|
|
#include "nsAtom.h"
|
2000-09-22 09:02:20 +04:00
|
|
|
#include "nsXBLService.h"
|
|
|
|
#include "nsIServiceManager.h"
|
2007-01-30 03:06:41 +03:00
|
|
|
#include "nsGkAtoms.h"
|
2010-07-15 05:53:11 +04:00
|
|
|
#include "nsXBLDocumentInfo.h"
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 22:00:39 +04:00
|
|
|
#include "nsFocusManager.h"
|
2007-01-09 10:33:18 +03:00
|
|
|
#include "nsIURI.h"
|
|
|
|
#include "nsNetUtil.h"
|
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsXBLPrototypeBinding.h"
|
|
|
|
#include "nsPIDOMWindow.h"
|
|
|
|
#include "nsIDocShell.h"
|
2017-08-07 09:08:02 +03:00
|
|
|
#include "nsISelectionController.h"
|
2007-01-09 10:33:18 +03:00
|
|
|
#include "nsIPresShell.h"
|
2016-03-16 04:58:28 +03:00
|
|
|
#include "mozilla/EventListenerManager.h"
|
2014-04-01 08:09:23 +04:00
|
|
|
#include "mozilla/EventStateManager.h"
|
2017-08-07 09:08:02 +03:00
|
|
|
#include "mozilla/HTMLEditor.h"
|
2017-06-06 02:29:04 +03:00
|
|
|
#include "mozilla/Move.h"
|
2011-05-28 11:03:00 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
2017-06-06 02:29:04 +03:00
|
|
|
#include "mozilla/StaticPtr.h"
|
2013-09-25 15:21:19 +04:00
|
|
|
#include "mozilla/TextEvents.h"
|
2011-07-20 23:18:54 +04:00
|
|
|
#include "mozilla/dom/Element.h"
|
2014-03-18 19:16:47 +04:00
|
|
|
#include "mozilla/dom/Event.h"
|
2018-04-20 07:49:29 +03:00
|
|
|
#include "mozilla/dom/EventBinding.h"
|
2018-02-09 19:17:09 +03:00
|
|
|
#include "mozilla/dom/KeyboardEvent.h"
|
2017-06-16 01:06:00 +03:00
|
|
|
#include "mozilla/layers/KeyboardMap.h"
|
2018-10-08 21:09:31 +03:00
|
|
|
#include "mozilla/ShortcutKeys.h"
|
2011-05-28 11:03:00 +04:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2013-04-06 04:44:26 +04:00
|
|
|
using namespace mozilla::dom;
|
2017-06-06 02:29:04 +03:00
|
|
|
using namespace mozilla::layers;
|
2000-09-22 09:02:20 +04:00
|
|
|
|
2018-04-27 06:37:34 +03:00
|
|
|
nsXBLWindowKeyHandler::nsXBLWindowKeyHandler(Element* aElement,
|
2013-04-14 22:27:33 +04:00
|
|
|
EventTarget* aTarget)
|
2007-05-14 13:11:38 +04:00
|
|
|
: mTarget(aTarget), mHandler(nullptr) {
|
2007-01-09 10:33:18 +03:00
|
|
|
mWeakPtrForElement = do_GetWeakReference(aElement);
|
2000-09-22 09:02:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsXBLWindowKeyHandler::~nsXBLWindowKeyHandler() {
|
2006-11-15 09:11:42 +03:00
|
|
|
// If mWeakPtrForElement is non-null, we created a prototype handler.
|
|
|
|
if (mWeakPtrForElement) delete mHandler;
|
2000-09-22 09:02:20 +04:00
|
|
|
}
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsXBLWindowKeyHandler, nsIDOMEventListener)
|
2000-09-22 09:02:20 +04:00
|
|
|
|
2003-02-28 04:04:45 +03:00
|
|
|
static void BuildHandlerChain(nsIContent* aContent,
|
|
|
|
nsXBLPrototypeHandler** aResult) {
|
2012-07-30 18:20:58 +04:00
|
|
|
*aResult = nullptr;
|
2003-09-27 08:18:26 +04:00
|
|
|
|
2006-05-13 02:58:10 +04:00
|
|
|
// Since we chain each handler onto the next handler,
|
|
|
|
// we'll enumerate them here in reverse so that when we
|
|
|
|
// walk the chain they'll come out in the original order
|
2011-09-27 11:54:58 +04:00
|
|
|
for (nsIContent* key = aContent->GetLastChild(); key;
|
|
|
|
key = key->GetPreviousSibling()) {
|
2017-12-07 21:13:50 +03:00
|
|
|
if (!key->NodeInfo()->Equals(nsGkAtoms::key, kNameSpaceID_XUL)) {
|
|
|
|
continue;
|
|
|
|
}
|
2003-09-27 08:18:26 +04:00
|
|
|
|
2017-12-07 21:13:50 +03:00
|
|
|
Element* keyElement = key->AsElement();
|
|
|
|
// Check whether the key element has empty value at key/char attribute.
|
|
|
|
// Such element is used by localizers for alternative shortcut key
|
|
|
|
// definition on the locale. See bug 426501.
|
|
|
|
nsAutoString valKey, valCharCode, valKeyCode;
|
2018-04-20 14:48:20 +03:00
|
|
|
// Hopefully at least one of the attributes is set:
|
|
|
|
keyElement->GetAttr(kNameSpaceID_None, nsGkAtoms::key, valKey) ||
|
2017-12-07 21:13:50 +03:00
|
|
|
keyElement->GetAttr(kNameSpaceID_None, nsGkAtoms::charcode,
|
|
|
|
valCharCode) ||
|
|
|
|
keyElement->GetAttr(kNameSpaceID_None, nsGkAtoms::keycode, valKeyCode);
|
2018-04-20 14:48:20 +03:00
|
|
|
// If not, ignore this key element.
|
|
|
|
if (valKey.IsEmpty() && valCharCode.IsEmpty() && valKeyCode.IsEmpty()) {
|
2017-12-07 21:13:50 +03:00
|
|
|
continue;
|
2018-04-20 14:48:20 +03:00
|
|
|
}
|
2008-04-15 08:16:24 +04:00
|
|
|
|
2017-12-07 21:13:50 +03:00
|
|
|
// reserved="pref" is the default for <key> elements.
|
|
|
|
XBLReservedKey reserved = XBLReservedKey_Unset;
|
|
|
|
if (keyElement->AttrValueIs(kNameSpaceID_None, nsGkAtoms::reserved,
|
|
|
|
nsGkAtoms::_true, eCaseMatters)) {
|
|
|
|
reserved = XBLReservedKey_True;
|
|
|
|
} else if (keyElement->AttrValueIs(kNameSpaceID_None, nsGkAtoms::reserved,
|
|
|
|
nsGkAtoms::_false, eCaseMatters)) {
|
|
|
|
reserved = XBLReservedKey_False;
|
|
|
|
}
|
2017-11-10 02:42:39 +03:00
|
|
|
|
2017-12-07 21:13:50 +03:00
|
|
|
nsXBLPrototypeHandler* handler =
|
|
|
|
new nsXBLPrototypeHandler(keyElement, reserved);
|
2003-09-27 08:18:26 +04:00
|
|
|
|
2017-12-07 21:13:50 +03:00
|
|
|
handler->SetNextHandler(*aResult);
|
|
|
|
*aResult = handler;
|
2001-11-02 04:53:13 +03:00
|
|
|
}
|
|
|
|
}
|
2000-09-28 00:23:49 +04:00
|
|
|
|
2000-11-29 09:01:33 +03:00
|
|
|
//
|
|
|
|
// EnsureHandlers
|
2017-05-10 06:45:11 +03:00
|
|
|
//
|
2000-11-29 09:01:33 +03:00
|
|
|
// Lazily load the XBL handlers. Overridden to handle being attached
|
|
|
|
// to a particular element rather than the document
|
|
|
|
//
|
2014-01-23 07:18:51 +04:00
|
|
|
nsresult nsXBLWindowKeyHandler::EnsureHandlers() {
|
2013-04-14 22:27:33 +04:00
|
|
|
nsCOMPtr<Element> el = GetElement();
|
2006-11-15 09:11:42 +03:00
|
|
|
NS_ENSURE_STATE(!mWeakPtrForElement || el);
|
2006-11-04 12:15:32 +03:00
|
|
|
if (el) {
|
2001-11-02 04:53:13 +03:00
|
|
|
// We are actually a XUL <keyset>.
|
2000-09-22 09:02:20 +04:00
|
|
|
if (mHandler) return NS_OK;
|
2004-09-10 11:17:31 +04:00
|
|
|
|
2018-08-13 12:05:19 +03:00
|
|
|
BuildHandlerChain(el, &mHandler);
|
2007-01-09 10:33:18 +03:00
|
|
|
} else { // We are an XBL file of handlers.
|
|
|
|
// Now determine which handlers we should be using.
|
2014-01-23 07:18:51 +04:00
|
|
|
if (IsHTMLEditableFieldFocused()) {
|
2018-10-08 21:09:31 +03:00
|
|
|
mHandler = ShortcutKeys::GetHandlers(HandlerType::eEditor);
|
2007-01-09 10:33:18 +03:00
|
|
|
} else {
|
2018-10-08 21:09:31 +03:00
|
|
|
mHandler = ShortcutKeys::GetHandlers(HandlerType::eBrowser);
|
2007-01-09 10:33:18 +03:00
|
|
|
}
|
2000-09-22 09:02:20 +04:00
|
|
|
}
|
2007-01-09 10:33:18 +03:00
|
|
|
|
2001-11-02 04:53:13 +03:00
|
|
|
return NS_OK;
|
2000-09-22 09:02:20 +04:00
|
|
|
}
|
|
|
|
|
2018-10-15 22:19:30 +03:00
|
|
|
nsresult nsXBLWindowKeyHandler::WalkHandlers(KeyboardEvent* aKeyEvent) {
|
2018-02-09 19:17:09 +03:00
|
|
|
if (aKeyEvent->DefaultPrevented()) {
|
2000-09-22 09:02:20 +04:00
|
|
|
return NS_OK;
|
2018-02-09 19:17:09 +03:00
|
|
|
}
|
2000-09-22 09:02:20 +04:00
|
|
|
|
2012-08-04 11:44:00 +04:00
|
|
|
// Don't process the event if it was not dispatched from a trusted source
|
2018-02-09 19:17:09 +03:00
|
|
|
if (!aKeyEvent->IsTrusted()) {
|
2004-09-02 19:25:39 +04:00
|
|
|
return NS_OK;
|
2018-02-09 19:17:09 +03:00
|
|
|
}
|
2004-09-02 19:25:39 +04:00
|
|
|
|
2014-01-23 07:18:51 +04:00
|
|
|
nsresult rv = EnsureHandlers();
|
2006-11-04 12:15:32 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2013-04-14 22:27:33 +04:00
|
|
|
|
2014-03-18 19:16:47 +04:00
|
|
|
bool isDisabled;
|
|
|
|
nsCOMPtr<Element> el = GetElement(&isDisabled);
|
2000-09-22 09:02:20 +04:00
|
|
|
|
2008-08-06 18:32:09 +04:00
|
|
|
// skip keysets that are disabled
|
2014-03-18 19:16:47 +04:00
|
|
|
if (el && isDisabled) {
|
2008-08-06 18:32:09 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2018-10-15 22:19:30 +03:00
|
|
|
WalkHandlersInternal(aKeyEvent, true);
|
2004-09-10 11:17:31 +04:00
|
|
|
|
2000-09-22 09:02:20 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-03-16 04:58:28 +03:00
|
|
|
void nsXBLWindowKeyHandler::InstallKeyboardEventListenersTo(
|
|
|
|
EventListenerManager* aEventListenerManager) {
|
|
|
|
// For marking each keyboard event as if it's reserved by chrome,
|
|
|
|
// nsXBLWindowKeyHandlers need to listen each keyboard events before
|
|
|
|
// web contents.
|
|
|
|
aEventListenerManager->AddEventListenerByType(
|
|
|
|
this, NS_LITERAL_STRING("keydown"), TrustedEventsAtCapture());
|
|
|
|
aEventListenerManager->AddEventListenerByType(
|
|
|
|
this, NS_LITERAL_STRING("keyup"), TrustedEventsAtCapture());
|
|
|
|
aEventListenerManager->AddEventListenerByType(
|
|
|
|
this, NS_LITERAL_STRING("keypress"), TrustedEventsAtCapture());
|
2016-04-22 20:12:54 +03:00
|
|
|
aEventListenerManager->AddEventListenerByType(
|
|
|
|
this, NS_LITERAL_STRING("mozkeydownonplugin"), TrustedEventsAtCapture());
|
|
|
|
aEventListenerManager->AddEventListenerByType(
|
|
|
|
this, NS_LITERAL_STRING("mozkeyuponplugin"), TrustedEventsAtCapture());
|
2016-03-16 04:58:28 +03:00
|
|
|
|
|
|
|
// For reducing the IPC cost, preventing to dispatch reserved keyboard
|
|
|
|
// events into the content process.
|
|
|
|
aEventListenerManager->AddEventListenerByType(
|
|
|
|
this, NS_LITERAL_STRING("keydown"), TrustedEventsAtSystemGroupCapture());
|
|
|
|
aEventListenerManager->AddEventListenerByType(
|
|
|
|
this, NS_LITERAL_STRING("keyup"), TrustedEventsAtSystemGroupCapture());
|
|
|
|
aEventListenerManager->AddEventListenerByType(
|
|
|
|
this, NS_LITERAL_STRING("keypress"), TrustedEventsAtSystemGroupCapture());
|
2016-04-22 20:12:54 +03:00
|
|
|
aEventListenerManager->AddEventListenerByType(
|
|
|
|
this, NS_LITERAL_STRING("mozkeydownonplugin"),
|
|
|
|
TrustedEventsAtSystemGroupCapture());
|
|
|
|
aEventListenerManager->AddEventListenerByType(
|
|
|
|
this, NS_LITERAL_STRING("mozkeyuponplugin"),
|
|
|
|
TrustedEventsAtSystemGroupCapture());
|
2016-03-16 04:58:28 +03:00
|
|
|
|
|
|
|
// Handle keyboard events in bubbling phase of the system event group.
|
|
|
|
aEventListenerManager->AddEventListenerByType(
|
|
|
|
this, NS_LITERAL_STRING("keydown"), TrustedEventsAtSystemGroupBubble());
|
|
|
|
aEventListenerManager->AddEventListenerByType(
|
|
|
|
this, NS_LITERAL_STRING("keyup"), TrustedEventsAtSystemGroupBubble());
|
|
|
|
aEventListenerManager->AddEventListenerByType(
|
|
|
|
this, NS_LITERAL_STRING("keypress"), TrustedEventsAtSystemGroupBubble());
|
2018-02-05 12:27:30 +03:00
|
|
|
// mozaccesskeynotfound event is fired when modifiers of keypress event
|
|
|
|
// matches with modifier of content access key but it's not consumed by
|
|
|
|
// remote content.
|
|
|
|
aEventListenerManager->AddEventListenerByType(
|
|
|
|
this, NS_LITERAL_STRING("mozaccesskeynotfound"),
|
|
|
|
TrustedEventsAtSystemGroupBubble());
|
2016-04-22 20:12:54 +03:00
|
|
|
aEventListenerManager->AddEventListenerByType(
|
|
|
|
this, NS_LITERAL_STRING("mozkeydownonplugin"),
|
|
|
|
TrustedEventsAtSystemGroupBubble());
|
|
|
|
aEventListenerManager->AddEventListenerByType(
|
|
|
|
this, NS_LITERAL_STRING("mozkeyuponplugin"),
|
|
|
|
TrustedEventsAtSystemGroupBubble());
|
2016-03-16 04:58:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsXBLWindowKeyHandler::RemoveKeyboardEventListenersFrom(
|
|
|
|
EventListenerManager* aEventListenerManager) {
|
|
|
|
aEventListenerManager->RemoveEventListenerByType(
|
|
|
|
this, NS_LITERAL_STRING("keydown"), TrustedEventsAtCapture());
|
|
|
|
aEventListenerManager->RemoveEventListenerByType(
|
|
|
|
this, NS_LITERAL_STRING("keyup"), TrustedEventsAtCapture());
|
|
|
|
aEventListenerManager->RemoveEventListenerByType(
|
|
|
|
this, NS_LITERAL_STRING("keypress"), TrustedEventsAtCapture());
|
2016-04-22 20:12:54 +03:00
|
|
|
aEventListenerManager->RemoveEventListenerByType(
|
|
|
|
this, NS_LITERAL_STRING("mozkeydownonplugin"), TrustedEventsAtCapture());
|
|
|
|
aEventListenerManager->RemoveEventListenerByType(
|
|
|
|
this, NS_LITERAL_STRING("mozkeyuponplugin"), TrustedEventsAtCapture());
|
2016-03-16 04:58:28 +03:00
|
|
|
|
|
|
|
aEventListenerManager->RemoveEventListenerByType(
|
|
|
|
this, NS_LITERAL_STRING("keydown"), TrustedEventsAtSystemGroupCapture());
|
|
|
|
aEventListenerManager->RemoveEventListenerByType(
|
|
|
|
this, NS_LITERAL_STRING("keyup"), TrustedEventsAtSystemGroupCapture());
|
|
|
|
aEventListenerManager->RemoveEventListenerByType(
|
|
|
|
this, NS_LITERAL_STRING("keypress"), TrustedEventsAtSystemGroupCapture());
|
2016-04-22 20:12:54 +03:00
|
|
|
aEventListenerManager->RemoveEventListenerByType(
|
|
|
|
this, NS_LITERAL_STRING("mozkeydownonplugin"),
|
|
|
|
TrustedEventsAtSystemGroupCapture());
|
|
|
|
aEventListenerManager->RemoveEventListenerByType(
|
|
|
|
this, NS_LITERAL_STRING("mozkeyuponplugin"),
|
|
|
|
TrustedEventsAtSystemGroupCapture());
|
2016-03-16 04:58:28 +03:00
|
|
|
|
|
|
|
aEventListenerManager->RemoveEventListenerByType(
|
|
|
|
this, NS_LITERAL_STRING("keydown"), TrustedEventsAtSystemGroupBubble());
|
|
|
|
aEventListenerManager->RemoveEventListenerByType(
|
|
|
|
this, NS_LITERAL_STRING("keyup"), TrustedEventsAtSystemGroupBubble());
|
|
|
|
aEventListenerManager->RemoveEventListenerByType(
|
|
|
|
this, NS_LITERAL_STRING("keypress"), TrustedEventsAtSystemGroupBubble());
|
2018-02-05 12:27:30 +03:00
|
|
|
aEventListenerManager->RemoveEventListenerByType(
|
|
|
|
this, NS_LITERAL_STRING("mozaccesskeynotfound"),
|
|
|
|
TrustedEventsAtSystemGroupBubble());
|
2016-04-22 20:12:54 +03:00
|
|
|
aEventListenerManager->RemoveEventListenerByType(
|
|
|
|
this, NS_LITERAL_STRING("mozkeydownonplugin"),
|
|
|
|
TrustedEventsAtSystemGroupBubble());
|
|
|
|
aEventListenerManager->RemoveEventListenerByType(
|
|
|
|
this, NS_LITERAL_STRING("mozkeyuponplugin"),
|
|
|
|
TrustedEventsAtSystemGroupBubble());
|
|
|
|
}
|
|
|
|
|
2017-06-06 02:29:04 +03:00
|
|
|
/* static */ KeyboardMap nsXBLWindowKeyHandler::CollectKeyboardShortcuts() {
|
2018-10-08 21:09:31 +03:00
|
|
|
nsXBLPrototypeHandler* handlers =
|
|
|
|
ShortcutKeys::GetHandlers(HandlerType::eBrowser);
|
2017-06-06 02:29:04 +03:00
|
|
|
|
|
|
|
// Convert the handlers into keyboard shortcuts, using an AutoTArray with
|
|
|
|
// the maximum amount of shortcuts used on any platform to minimize
|
|
|
|
// allocations
|
2017-06-28 23:06:47 +03:00
|
|
|
AutoTArray<KeyboardShortcut, 48> shortcuts;
|
|
|
|
|
|
|
|
// Append keyboard shortcuts for hardcoded actions like tab
|
|
|
|
KeyboardShortcut::AppendHardcodedShortcuts(shortcuts);
|
2017-06-06 02:29:04 +03:00
|
|
|
|
|
|
|
for (nsXBLPrototypeHandler* handler = handlers; handler;
|
|
|
|
handler = handler->GetNextHandler()) {
|
|
|
|
KeyboardShortcut shortcut;
|
|
|
|
if (handler->TryConvertToKeyboardShortcut(&shortcut)) {
|
|
|
|
shortcuts.AppendElement(shortcut);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-30 22:15:35 +03:00
|
|
|
return KeyboardMap(std::move(shortcuts));
|
2017-06-06 02:29:04 +03:00
|
|
|
}
|
|
|
|
|
2011-06-25 03:12:34 +04:00
|
|
|
NS_IMETHODIMP
|
2018-04-20 07:49:29 +03:00
|
|
|
nsXBLWindowKeyHandler::HandleEvent(Event* aEvent) {
|
2018-04-20 07:49:29 +03:00
|
|
|
RefPtr<KeyboardEvent> keyEvent = aEvent->AsKeyboardEvent();
|
2008-09-16 05:37:13 +04:00
|
|
|
NS_ENSURE_TRUE(keyEvent, NS_ERROR_INVALID_ARG);
|
2000-09-22 09:02:20 +04:00
|
|
|
|
2018-06-26 00:20:54 +03:00
|
|
|
if (aEvent->EventPhase() == Event_Binding::CAPTURING_PHASE) {
|
2016-03-16 04:58:28 +03:00
|
|
|
if (aEvent->WidgetEventPtr()->mFlags.mInSystemGroup) {
|
|
|
|
HandleEventOnCaptureInSystemEventGroup(keyEvent);
|
|
|
|
} else {
|
|
|
|
HandleEventOnCaptureInDefaultEventGroup(keyEvent);
|
|
|
|
}
|
2014-03-18 19:16:47 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-04-22 20:12:54 +03:00
|
|
|
WidgetKeyboardEvent* widgetKeyboardEvent =
|
|
|
|
aEvent->WidgetEventPtr()->AsKeyboardEvent();
|
|
|
|
if (widgetKeyboardEvent->IsKeyEventOnPlugin()) {
|
|
|
|
// key events on plugin shouldn't execute shortcut key handlers which are
|
|
|
|
// not reserved.
|
2017-07-05 07:58:41 +03:00
|
|
|
if (!widgetKeyboardEvent->IsReservedByChrome()) {
|
2016-04-22 20:12:54 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the event is untrusted event or was already consumed, do nothing.
|
|
|
|
if (!widgetKeyboardEvent->IsTrusted() ||
|
|
|
|
widgetKeyboardEvent->DefaultPrevented()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-09-22 09:02:20 +04:00
|
|
|
|
2016-04-22 20:12:54 +03:00
|
|
|
// XXX Don't check isReserved here because even if the handler in this
|
|
|
|
// instance isn't reserved but another instance reserves the key
|
|
|
|
// combination, it will be executed when the event is normal keyboard
|
|
|
|
// events...
|
|
|
|
bool isReserved = false;
|
|
|
|
if (!HasHandlerForEvent(keyEvent, &isReserved)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-30 20:08:17 +03:00
|
|
|
// If this event was handled by APZ then don't do the default action, and
|
|
|
|
// preventDefault to prevent any other listeners from handling the event.
|
|
|
|
if (widgetKeyboardEvent->mFlags.mHandledByAPZ) {
|
|
|
|
aEvent->PreventDefault();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2018-10-15 22:19:30 +03:00
|
|
|
return WalkHandlers(keyEvent);
|
2014-03-18 19:16:47 +04:00
|
|
|
}
|
|
|
|
|
2016-03-16 04:58:28 +03:00
|
|
|
void nsXBLWindowKeyHandler::HandleEventOnCaptureInDefaultEventGroup(
|
2018-02-09 19:17:09 +03:00
|
|
|
KeyboardEvent* aEvent) {
|
2016-03-16 04:58:28 +03:00
|
|
|
WidgetKeyboardEvent* widgetKeyboardEvent =
|
2018-02-09 19:17:09 +03:00
|
|
|
aEvent->WidgetEventPtr()->AsKeyboardEvent();
|
2016-03-16 04:58:28 +03:00
|
|
|
|
2017-07-05 07:58:41 +03:00
|
|
|
if (widgetKeyboardEvent->IsReservedByChrome()) {
|
2016-03-16 04:58:28 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isReserved = false;
|
|
|
|
if (HasHandlerForEvent(aEvent, &isReserved) && isReserved) {
|
2017-07-05 07:58:41 +03:00
|
|
|
widgetKeyboardEvent->MarkAsReservedByChrome();
|
2016-03-16 04:58:28 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsXBLWindowKeyHandler::HandleEventOnCaptureInSystemEventGroup(
|
2018-02-09 19:17:09 +03:00
|
|
|
KeyboardEvent* aEvent) {
|
2014-03-18 19:16:47 +04:00
|
|
|
WidgetKeyboardEvent* widgetEvent =
|
2018-02-09 19:17:09 +03:00
|
|
|
aEvent->WidgetEventPtr()->AsKeyboardEvent();
|
2014-03-18 19:16:47 +04:00
|
|
|
|
2017-07-19 12:39:34 +03:00
|
|
|
// If the event won't be sent to remote process, this listener needs to do
|
2018-02-14 09:21:15 +03:00
|
|
|
// nothing. Note that even if mOnlySystemGroupDispatchInContent is true,
|
|
|
|
// we need to send the event to remote process and check reply event
|
|
|
|
// before matching it with registered shortcut keys because event listeners
|
|
|
|
// in the system event group may want to handle the event before registered
|
|
|
|
// shortcut key handlers.
|
|
|
|
if (!widgetEvent->WillBeSentToRemoteProcess()) {
|
2014-03-18 19:16:47 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-03-16 04:58:28 +03:00
|
|
|
if (!HasHandlerForEvent(aEvent)) {
|
2014-03-18 19:16:47 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-07-05 07:58:41 +03:00
|
|
|
// If this event wasn't marked as IsCrossProcessForwardingStopped,
|
2016-03-16 04:58:28 +03:00
|
|
|
// yet, it means it wasn't processed by content. We'll not call any
|
2017-07-05 07:58:41 +03:00
|
|
|
// of the handlers at this moment, and will wait the reply event.
|
|
|
|
// So, stop immediate propagation in this event first, then, mark it as
|
|
|
|
// waiting reply from remote process. Finally, when this process receives
|
|
|
|
// a reply from the remote process, it should be dispatched into this
|
|
|
|
// DOM tree again.
|
|
|
|
widgetEvent->StopImmediatePropagation();
|
|
|
|
widgetEvent->MarkAsWaitingReplyFromRemoteProcess();
|
2000-09-22 09:02:20 +04:00
|
|
|
}
|
2000-11-29 09:01:33 +03:00
|
|
|
|
2014-01-23 07:18:51 +04:00
|
|
|
bool nsXBLWindowKeyHandler::IsHTMLEditableFieldFocused() {
|
2018-04-27 06:35:19 +03:00
|
|
|
nsFocusManager* fm = nsFocusManager::GetFocusManager();
|
2011-10-17 18:59:28 +04:00
|
|
|
if (!fm) return false;
|
2007-01-09 10:33:18 +03:00
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<mozIDOMWindowProxy> focusedWindow;
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 22:00:39 +04:00
|
|
|
fm->GetFocusedWindow(getter_AddRefs(focusedWindow));
|
2007-01-09 10:33:18 +03:00
|
|
|
if (!focusedWindow) return false;
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 22:00:39 +04:00
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
auto* piwin = nsPIDOMWindowOuter::From(focusedWindow);
|
2007-01-09 10:33:18 +03:00
|
|
|
nsIDocShell* docShell = piwin->GetDocShell();
|
2014-01-23 07:18:51 +04:00
|
|
|
if (!docShell) {
|
|
|
|
return false;
|
|
|
|
}
|
2007-01-09 10:33:18 +03:00
|
|
|
|
2017-08-07 09:08:02 +03:00
|
|
|
RefPtr<HTMLEditor> htmlEditor = docShell->GetHTMLEditor();
|
2014-01-23 07:18:51 +04:00
|
|
|
if (!htmlEditor) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-08-07 09:08:02 +03:00
|
|
|
nsCOMPtr<nsIDocument> doc = htmlEditor->GetDocument();
|
2014-02-10 23:55:01 +04:00
|
|
|
if (doc->HasFlag(NODE_IS_EDITABLE)) {
|
|
|
|
// Don't need to perform any checks in designMode documents.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-04-27 06:35:19 +03:00
|
|
|
nsINode* focusedNode = fm->GetFocusedElement();
|
|
|
|
if (focusedNode && focusedNode->IsElement()) {
|
2014-01-23 07:18:51 +04:00
|
|
|
// If there is a focused element, make sure it's in the active editing host.
|
|
|
|
// Note that GetActiveEditingHost finds the current editing host based on
|
|
|
|
// the document's selection. Even though the document selection is usually
|
|
|
|
// collapsed to where the focus is, but the page may modify the selection
|
|
|
|
// without our knowledge, in which case this check will do something useful.
|
|
|
|
nsCOMPtr<Element> activeEditingHost = htmlEditor->GetActiveEditingHost();
|
|
|
|
if (!activeEditingHost) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return nsContentUtils::ContentIsDescendantOf(focusedNode,
|
|
|
|
activeEditingHost);
|
2007-01-09 10:33:18 +03:00
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2007-01-09 10:33:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2008-04-15 08:16:24 +04:00
|
|
|
// WalkHandlersInternal and WalkHandlersAndExecute
|
2007-01-09 10:33:18 +03:00
|
|
|
//
|
|
|
|
// Given a particular DOM event and a pointer to the first handler in the list,
|
2014-03-18 19:16:47 +04:00
|
|
|
// scan through the list to find something to handle the event. If aExecute =
|
|
|
|
// true, the handler will be executed; otherwise just return an answer telling
|
|
|
|
// if a handler for that event was found.
|
2007-01-09 10:33:18 +03:00
|
|
|
//
|
2018-02-09 19:17:09 +03:00
|
|
|
bool nsXBLWindowKeyHandler::WalkHandlersInternal(KeyboardEvent* aKeyEvent,
|
2015-03-12 18:03:08 +03:00
|
|
|
bool aExecute,
|
|
|
|
bool* aOutReservedForChrome) {
|
2016-03-18 05:22:37 +03:00
|
|
|
WidgetKeyboardEvent* nativeKeyboardEvent =
|
2018-02-09 19:17:09 +03:00
|
|
|
aKeyEvent->WidgetEventPtr()->AsKeyboardEvent();
|
2016-03-18 05:22:37 +03:00
|
|
|
MOZ_ASSERT(nativeKeyboardEvent);
|
2008-04-15 08:16:24 +04:00
|
|
|
|
2016-03-18 05:22:37 +03:00
|
|
|
AutoShortcutKeyCandidateArray shortcutKeys;
|
|
|
|
nativeKeyboardEvent->GetShortcutKeyCandidates(shortcutKeys);
|
|
|
|
|
|
|
|
if (shortcutKeys.IsEmpty()) {
|
2018-10-15 22:19:30 +03:00
|
|
|
return WalkHandlersAndExecute(aKeyEvent, 0, IgnoreModifierState(), aExecute,
|
2015-03-12 18:03:08 +03:00
|
|
|
aOutReservedForChrome);
|
2008-04-15 08:16:24 +04:00
|
|
|
}
|
|
|
|
|
2016-03-18 05:22:37 +03:00
|
|
|
for (uint32_t i = 0; i < shortcutKeys.Length(); ++i) {
|
|
|
|
ShortcutKeyCandidate& key = shortcutKeys[i];
|
2014-12-12 15:17:37 +03:00
|
|
|
IgnoreModifierState ignoreModifierState;
|
|
|
|
ignoreModifierState.mShift = key.mIgnoreShift;
|
2018-10-15 22:19:30 +03:00
|
|
|
if (WalkHandlersAndExecute(aKeyEvent, key.mCharCode, ignoreModifierState,
|
2015-03-12 18:03:08 +03:00
|
|
|
aExecute, aOutReservedForChrome)) {
|
2014-03-18 19:16:47 +04:00
|
|
|
return true;
|
2014-12-12 15:17:37 +03:00
|
|
|
}
|
2008-04-15 08:16:24 +04:00
|
|
|
}
|
2014-03-18 19:16:47 +04:00
|
|
|
return false;
|
2008-04-15 08:16:24 +04:00
|
|
|
}
|
|
|
|
|
2014-12-12 15:17:37 +03:00
|
|
|
bool nsXBLWindowKeyHandler::WalkHandlersAndExecute(
|
2018-02-09 19:17:09 +03:00
|
|
|
KeyboardEvent* aKeyEvent, uint32_t aCharCode,
|
2014-12-12 15:17:37 +03:00
|
|
|
const IgnoreModifierState& aIgnoreModifierState, bool aExecute,
|
2015-03-12 18:03:08 +03:00
|
|
|
bool* aOutReservedForChrome) {
|
2016-04-22 20:12:54 +03:00
|
|
|
if (aOutReservedForChrome) {
|
|
|
|
*aOutReservedForChrome = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
WidgetKeyboardEvent* widgetKeyboardEvent =
|
2018-02-09 19:17:09 +03:00
|
|
|
aKeyEvent->WidgetEventPtr()->AsKeyboardEvent();
|
2016-04-22 20:12:54 +03:00
|
|
|
if (NS_WARN_IF(!widgetKeyboardEvent)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-10-15 22:19:30 +03:00
|
|
|
nsAtom* eventType =
|
|
|
|
ShortcutKeys::ConvertEventToDOMEventType(widgetKeyboardEvent);
|
|
|
|
|
2007-01-09 10:33:18 +03:00
|
|
|
// Try all of the handlers until we find one that matches the event.
|
2018-06-13 22:32:55 +03:00
|
|
|
for (nsXBLPrototypeHandler* handler = mHandler; handler;
|
2016-03-18 05:25:08 +03:00
|
|
|
handler = handler->GetNextHandler()) {
|
2018-02-09 19:17:09 +03:00
|
|
|
bool stopped = aKeyEvent->IsDispatchStopped();
|
2007-01-09 10:33:18 +03:00
|
|
|
if (stopped) {
|
|
|
|
// The event is finished, don't execute any more handlers
|
2012-08-07 19:11:35 +04:00
|
|
|
return false;
|
2007-01-09 10:33:18 +03:00
|
|
|
}
|
|
|
|
|
2016-03-22 09:05:25 +03:00
|
|
|
if (aExecute) {
|
2016-04-22 20:12:54 +03:00
|
|
|
// If the event is eKeyDownOnPlugin, it should execute either keydown
|
|
|
|
// handler or keypress handler because eKeyDownOnPlugin events are
|
|
|
|
// never followed by keypress events.
|
|
|
|
if (widgetKeyboardEvent->mMessage == eKeyDownOnPlugin) {
|
|
|
|
if (!handler->EventTypeEquals(nsGkAtoms::keydown) &&
|
|
|
|
!handler->EventTypeEquals(nsGkAtoms::keypress)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// The other event types should exactly be matched with the handler's
|
|
|
|
// event type.
|
2018-10-15 22:19:30 +03:00
|
|
|
} else if (!handler->EventTypeEquals(eventType)) {
|
2016-03-22 09:05:25 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (handler->EventTypeEquals(nsGkAtoms::keypress)) {
|
|
|
|
// If the handler is a keypress event handler, we also need to check
|
|
|
|
// if coming keydown event is a preceding event of reserved key
|
|
|
|
// combination because if default action of a keydown event is
|
|
|
|
// prevented, following keypress event won't be fired. However, if
|
|
|
|
// following keypress event is reserved, we shouldn't allow web
|
|
|
|
// contents to prevent the default of the preceding keydown event.
|
2018-10-15 22:19:30 +03:00
|
|
|
if (eventType != nsGkAtoms::keydown &&
|
|
|
|
eventType != nsGkAtoms::keypress) {
|
2016-03-22 09:05:25 +03:00
|
|
|
continue;
|
|
|
|
}
|
2018-10-15 22:19:30 +03:00
|
|
|
} else if (!handler->EventTypeEquals(eventType)) {
|
|
|
|
// Otherwise, eventType should exactly be matched.
|
2016-03-22 09:05:25 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the keyboard event *may* execute the handler.
|
|
|
|
if (!handler->KeyEventMatched(aKeyEvent, aCharCode, aIgnoreModifierState)) {
|
2007-01-09 10:33:18 +03:00
|
|
|
continue; // try the next one
|
2014-12-12 15:17:37 +03:00
|
|
|
}
|
2007-01-09 10:33:18 +03:00
|
|
|
|
|
|
|
// Before executing this handler, check that it's not disabled,
|
|
|
|
// and that it has something to do (oncommand of the <key> or its
|
|
|
|
// <command> is non-empty).
|
2016-03-18 05:25:08 +03:00
|
|
|
nsCOMPtr<Element> commandElement;
|
2016-03-18 05:25:22 +03:00
|
|
|
if (!GetElementForHandler(handler, getter_AddRefs(commandElement))) {
|
|
|
|
continue;
|
2007-01-09 10:33:18 +03:00
|
|
|
}
|
|
|
|
|
2016-03-18 05:25:08 +03:00
|
|
|
if (commandElement) {
|
2016-05-06 12:38:44 +03:00
|
|
|
if (aExecute && !IsExecutableElement(commandElement)) {
|
2016-03-19 17:16:21 +03:00
|
|
|
continue;
|
2007-01-09 10:33:18 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-18 19:16:47 +04:00
|
|
|
if (!aExecute) {
|
2018-10-15 22:19:30 +03:00
|
|
|
if (handler->EventTypeEquals(eventType)) {
|
2017-11-10 02:42:39 +03:00
|
|
|
if (aOutReservedForChrome) {
|
|
|
|
*aOutReservedForChrome = IsReservedKey(widgetKeyboardEvent, handler);
|
|
|
|
}
|
|
|
|
|
2016-03-22 09:05:25 +03:00
|
|
|
return true;
|
|
|
|
}
|
2017-11-10 02:42:39 +03:00
|
|
|
|
2016-03-22 09:05:25 +03:00
|
|
|
// If the command is reserved and the event is keydown, check also if
|
|
|
|
// the handler is for keypress because if following keypress event is
|
|
|
|
// reserved, we shouldn't dispatch the event into web contents.
|
2018-10-15 22:19:30 +03:00
|
|
|
if (eventType == nsGkAtoms::keydown &&
|
2016-03-22 09:05:25 +03:00
|
|
|
handler->EventTypeEquals(nsGkAtoms::keypress)) {
|
2017-11-10 02:42:39 +03:00
|
|
|
if (IsReservedKey(widgetKeyboardEvent, handler)) {
|
|
|
|
if (aOutReservedForChrome) {
|
|
|
|
*aOutReservedForChrome = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2016-03-22 09:05:25 +03:00
|
|
|
}
|
|
|
|
// Otherwise, we've not found a handler for the event yet.
|
|
|
|
continue;
|
2014-03-18 19:16:47 +04:00
|
|
|
}
|
|
|
|
|
2017-11-10 02:42:39 +03:00
|
|
|
// This should only be assigned when aExecute is false.
|
|
|
|
MOZ_ASSERT(!aOutReservedForChrome);
|
|
|
|
|
2016-04-22 20:12:54 +03:00
|
|
|
// If it's not reserved and the event is a key event on a plugin,
|
|
|
|
// the handler shouldn't be executed.
|
2017-11-10 02:42:39 +03:00
|
|
|
if (widgetKeyboardEvent->IsKeyEventOnPlugin() &&
|
|
|
|
!IsReservedKey(widgetKeyboardEvent, handler)) {
|
2016-04-22 20:12:54 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-03-18 05:25:08 +03:00
|
|
|
nsCOMPtr<EventTarget> target;
|
2016-03-18 05:25:22 +03:00
|
|
|
nsCOMPtr<Element> chromeHandlerElement = GetElement();
|
2016-03-18 05:25:08 +03:00
|
|
|
if (chromeHandlerElement) {
|
2016-03-19 17:16:21 +03:00
|
|
|
// XXX commandElement may be nullptr...
|
2016-03-18 05:25:08 +03:00
|
|
|
target = commandElement;
|
|
|
|
} else {
|
|
|
|
target = mTarget;
|
|
|
|
}
|
|
|
|
|
2016-03-22 09:05:25 +03:00
|
|
|
// XXX Do we execute only one handler even if the handler neither stops
|
|
|
|
// propagation nor prevents default of the event?
|
2018-02-09 19:17:09 +03:00
|
|
|
nsresult rv = handler->ExecuteHandler(target, aKeyEvent);
|
2007-01-09 10:33:18 +03:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2007-01-09 10:33:18 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-12 15:17:37 +03:00
|
|
|
#ifdef XP_WIN
|
|
|
|
// Windows native applications ignore Windows-Logo key state when checking
|
|
|
|
// shortcut keys even if the key is pressed. Therefore, if there is no
|
|
|
|
// shortcut key which exactly matches current modifier state, we should
|
|
|
|
// retry to look for a shortcut key without the Windows-Logo key press.
|
2016-04-22 20:12:54 +03:00
|
|
|
if (!aIgnoreModifierState.mOS && widgetKeyboardEvent->IsOS()) {
|
|
|
|
IgnoreModifierState ignoreModifierState(aIgnoreModifierState);
|
|
|
|
ignoreModifierState.mOS = true;
|
2018-10-15 22:19:30 +03:00
|
|
|
return WalkHandlersAndExecute(aKeyEvent, aCharCode, ignoreModifierState,
|
|
|
|
aExecute);
|
2014-12-12 15:17:37 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2007-01-09 10:33:18 +03:00
|
|
|
}
|
|
|
|
|
2017-11-10 02:42:39 +03:00
|
|
|
bool nsXBLWindowKeyHandler::IsReservedKey(WidgetKeyboardEvent* aKeyEvent,
|
|
|
|
nsXBLPrototypeHandler* aHandler) {
|
|
|
|
XBLReservedKey reserved = aHandler->GetIsReserved();
|
|
|
|
// reserved="true" means that the key is always reserved. reserved="false"
|
|
|
|
// means that the key is never reserved. Otherwise, we check site-specific
|
|
|
|
// permissions.
|
2017-11-10 02:42:39 +03:00
|
|
|
if (reserved == XBLReservedKey_False) {
|
|
|
|
return false;
|
2017-11-10 02:42:39 +03:00
|
|
|
}
|
|
|
|
|
2017-11-10 02:42:39 +03:00
|
|
|
if (reserved == XBLReservedKey_True) {
|
|
|
|
return true;
|
2017-11-10 02:42:39 +03:00
|
|
|
}
|
|
|
|
|
2017-11-10 02:42:39 +03:00
|
|
|
return nsContentUtils::ShouldBlockReservedKeys(aKeyEvent);
|
2017-11-10 02:42:39 +03:00
|
|
|
}
|
|
|
|
|
2018-02-09 19:17:09 +03:00
|
|
|
bool nsXBLWindowKeyHandler::HasHandlerForEvent(KeyboardEvent* aEvent,
|
2015-03-12 18:03:08 +03:00
|
|
|
bool* aOutReservedForChrome) {
|
2016-04-22 20:12:54 +03:00
|
|
|
WidgetKeyboardEvent* widgetKeyboardEvent =
|
2018-02-09 19:17:09 +03:00
|
|
|
aEvent->WidgetEventPtr()->AsKeyboardEvent();
|
2016-04-22 20:12:54 +03:00
|
|
|
if (NS_WARN_IF(!widgetKeyboardEvent) || !widgetKeyboardEvent->IsTrusted()) {
|
2014-03-18 19:16:47 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv = EnsureHandlers();
|
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
|
|
|
|
|
|
|
bool isDisabled;
|
|
|
|
nsCOMPtr<Element> el = GetElement(&isDisabled);
|
|
|
|
if (el && isDisabled) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-10-15 22:19:30 +03:00
|
|
|
return WalkHandlersInternal(aEvent, false, aOutReservedForChrome);
|
2014-03-18 19:16:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<Element> nsXBLWindowKeyHandler::GetElement(bool* aIsDisabled) {
|
2013-04-14 22:27:33 +04:00
|
|
|
nsCOMPtr<Element> element = do_QueryReferent(mWeakPtrForElement);
|
2014-03-18 19:16:47 +04:00
|
|
|
if (element && aIsDisabled) {
|
|
|
|
*aIsDisabled = element->AttrValueIs(kNameSpaceID_None, nsGkAtoms::disabled,
|
|
|
|
nsGkAtoms::_true, eCaseMatters);
|
|
|
|
}
|
2013-04-14 22:27:33 +04:00
|
|
|
return element.forget();
|
2007-01-09 10:33:18 +03:00
|
|
|
}
|
|
|
|
|
2016-03-18 05:25:22 +03:00
|
|
|
bool nsXBLWindowKeyHandler::GetElementForHandler(
|
|
|
|
nsXBLPrototypeHandler* aHandler, Element** aElementForHandler) {
|
|
|
|
MOZ_ASSERT(aElementForHandler);
|
|
|
|
*aElementForHandler = nullptr;
|
|
|
|
|
2018-08-13 12:05:19 +03:00
|
|
|
RefPtr<Element> keyElement = aHandler->GetHandlerElement();
|
|
|
|
if (!keyElement) {
|
2016-03-19 17:12:39 +03:00
|
|
|
return true; // XXX Even though no key element?
|
|
|
|
}
|
2016-03-18 05:25:22 +03:00
|
|
|
|
|
|
|
nsCOMPtr<Element> chromeHandlerElement = GetElement();
|
2016-03-19 17:12:39 +03:00
|
|
|
if (!chromeHandlerElement) {
|
2018-08-13 12:05:19 +03:00
|
|
|
NS_WARNING_ASSERTION(keyElement->IsInUncomposedDoc(), "uncomposed");
|
2016-03-19 17:12:39 +03:00
|
|
|
keyElement.swap(*aElementForHandler);
|
|
|
|
return true;
|
2016-03-18 05:25:22 +03:00
|
|
|
}
|
|
|
|
|
2016-03-19 17:12:39 +03:00
|
|
|
// We are in a XUL doc. Obtain our command attribute.
|
|
|
|
nsAutoString command;
|
2018-08-13 12:05:19 +03:00
|
|
|
keyElement->GetAttr(kNameSpaceID_None, nsGkAtoms::command, command);
|
2016-03-19 17:12:39 +03:00
|
|
|
if (command.IsEmpty()) {
|
|
|
|
// There is no command element associated with the key element.
|
2018-08-13 12:05:19 +03:00
|
|
|
NS_WARNING_ASSERTION(keyElement->IsInUncomposedDoc(), "uncomposed");
|
2016-03-18 05:25:22 +03:00
|
|
|
keyElement.swap(*aElementForHandler);
|
2016-03-19 17:12:39 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX Shouldn't we check this earlier?
|
2018-08-13 12:05:19 +03:00
|
|
|
nsIDocument* doc = keyElement->GetUncomposedDoc();
|
2016-03-19 17:12:39 +03:00
|
|
|
if (NS_WARN_IF(!doc)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-08-13 12:05:19 +03:00
|
|
|
nsCOMPtr<Element> commandElement = doc->GetElementById(command);
|
2016-03-19 17:12:39 +03:00
|
|
|
if (!commandElement) {
|
|
|
|
NS_ERROR(
|
|
|
|
"A XUL <key> is observing a command that doesn't exist. "
|
|
|
|
"Unable to execute key binding!");
|
|
|
|
return false;
|
2016-03-18 05:25:22 +03:00
|
|
|
}
|
|
|
|
|
2016-03-19 17:12:39 +03:00
|
|
|
commandElement.swap(*aElementForHandler);
|
2016-03-18 05:25:22 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-03-19 17:16:21 +03:00
|
|
|
bool nsXBLWindowKeyHandler::IsExecutableElement(Element* aElement) const {
|
|
|
|
if (!aElement) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString value;
|
|
|
|
aElement->GetAttribute(NS_LITERAL_STRING("disabled"), value);
|
|
|
|
if (value.EqualsLiteral("true")) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
aElement->GetAttribute(NS_LITERAL_STRING("oncommand"), value);
|
|
|
|
if (value.IsEmpty()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2000-09-22 09:02:20 +04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2013-04-14 22:27:33 +04:00
|
|
|
already_AddRefed<nsXBLWindowKeyHandler> NS_NewXBLWindowKeyHandler(
|
2018-04-27 06:37:34 +03:00
|
|
|
Element* aElement, EventTarget* aTarget) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsXBLWindowKeyHandler> result =
|
2013-04-14 22:27:33 +04:00
|
|
|
new nsXBLWindowKeyHandler(aElement, aTarget);
|
|
|
|
return result.forget();
|
2000-09-22 09:02:20 +04:00
|
|
|
}
|