gecko-dev/dom/events/ShortcutKeys.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

119 строки
3.3 KiB
C++
Исходник Обычный вид История

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */
Bug 1550058: Move most keyboard shortcut handling out of XBL. r=masayuki Most of our keyboard shortcut handling is handled by nsXBLWindowKeyHandler along with nsXBLPrototypeHandler. With the impending removal of XBL this needs to change. This patch moves nsXBLWindowKeyHandler to dom/events/GlobalKeyListener and copies nsXBLPrototypeHandler to dom/events/KeyEventHandler. Windows, text elements and XUL <keyset> are changed to use the new copies and anything unnecessary for those is stripped out. XBL handler elements still remain using the existing nsXBLPrototypeHandler path. Some of the code is ripped out there to make it compile. There is probably a lot more that can be removed but since the whole of XBL is likely gone soon I'm not sure it is worth cleaning that up much. Differential Revision: https://phabricator.services.mozilla.com/D42336 --HG-- rename : dom/xbl/nsXBLWindowKeyHandler.cpp => dom/events/GlobalKeyListener.cpp rename : dom/xbl/nsXBLWindowKeyHandler.h => dom/events/GlobalKeyListener.h rename : dom/xbl/nsXBLPrototypeHandler.cpp => dom/events/KeyEventHandler.cpp rename : dom/xbl/nsXBLPrototypeHandler.h => dom/events/KeyEventHandler.h rename : dom/xbl/builtin/ShortcutKeyDefinitionsForBrowserCommon.h => dom/events/ShortcutKeyDefinitionsForBrowserCommon.h rename : dom/xbl/builtin/ShortcutKeyDefinitionsForEditorCommon.h => dom/events/ShortcutKeyDefinitionsForEditorCommon.h rename : dom/xbl/builtin/ShortcutKeyDefinitionsForInputCommon.h => dom/events/ShortcutKeyDefinitionsForInputCommon.h rename : dom/xbl/builtin/ShortcutKeyDefinitionsForInputCommon.h => dom/events/ShortcutKeyDefinitionsForTextAreaCommon.h rename : dom/xbl/builtin/ShortcutKeys.cpp => dom/events/ShortcutKeys.cpp rename : dom/xbl/builtin/ShortcutKeys.h => dom/events/ShortcutKeys.h rename : dom/xbl/builtin/android/ShortcutKeyDefinitions.cpp => dom/events/android/ShortcutKeyDefinitions.cpp rename : dom/xbl/builtin/android/moz.build => dom/events/android/moz.build rename : dom/xbl/builtin/emacs/ShortcutKeyDefinitions.cpp => dom/events/emacs/ShortcutKeyDefinitions.cpp rename : dom/xbl/builtin/android/moz.build => dom/events/emacs/moz.build rename : dom/xbl/builtin/mac/ShortcutKeyDefinitions.cpp => dom/events/mac/ShortcutKeyDefinitions.cpp rename : dom/xbl/builtin/android/moz.build => dom/events/mac/moz.build rename : dom/xbl/builtin/unix/ShortcutKeyDefinitions.cpp => dom/events/unix/ShortcutKeyDefinitions.cpp rename : dom/xbl/builtin/android/moz.build => dom/events/unix/moz.build rename : dom/xbl/builtin/win/ShortcutKeyDefinitions.cpp => dom/events/win/ShortcutKeyDefinitions.cpp rename : dom/xbl/builtin/android/moz.build => dom/events/win/moz.build extra : moz-landing-system : lando
2019-09-06 20:10:40 +03:00
#include "ShortcutKeys.h"
#include "mozilla/KeyEventHandler.h"
#include "nsContentUtils.h"
#include "nsAtom.h"
#include "mozilla/TextEvents.h"
namespace mozilla {
NS_IMPL_ISUPPORTS(ShortcutKeys, nsIObserver);
StaticRefPtr<ShortcutKeys> ShortcutKeys::sInstance;
ShortcutKeys::ShortcutKeys()
: mBrowserHandlers(nullptr),
mEditorHandlers(nullptr),
mInputHandlers(nullptr),
mTextAreaHandlers(nullptr) {
MOZ_ASSERT(!sInstance, "Attempt to instantiate a second ShortcutKeys.");
nsContentUtils::RegisterShutdownObserver(this);
}
ShortcutKeys::~ShortcutKeys() {
delete mBrowserHandlers;
delete mEditorHandlers;
delete mInputHandlers;
delete mTextAreaHandlers;
}
nsresult ShortcutKeys::Observe(nsISupports* aSubject, const char* aTopic,
const char16_t* aData) {
// Clear our strong reference so we can clean up.
sInstance = nullptr;
return NS_OK;
}
/* static */
Bug 1550058: Move most keyboard shortcut handling out of XBL. r=masayuki Most of our keyboard shortcut handling is handled by nsXBLWindowKeyHandler along with nsXBLPrototypeHandler. With the impending removal of XBL this needs to change. This patch moves nsXBLWindowKeyHandler to dom/events/GlobalKeyListener and copies nsXBLPrototypeHandler to dom/events/KeyEventHandler. Windows, text elements and XUL <keyset> are changed to use the new copies and anything unnecessary for those is stripped out. XBL handler elements still remain using the existing nsXBLPrototypeHandler path. Some of the code is ripped out there to make it compile. There is probably a lot more that can be removed but since the whole of XBL is likely gone soon I'm not sure it is worth cleaning that up much. Differential Revision: https://phabricator.services.mozilla.com/D42336 --HG-- rename : dom/xbl/nsXBLWindowKeyHandler.cpp => dom/events/GlobalKeyListener.cpp rename : dom/xbl/nsXBLWindowKeyHandler.h => dom/events/GlobalKeyListener.h rename : dom/xbl/nsXBLPrototypeHandler.cpp => dom/events/KeyEventHandler.cpp rename : dom/xbl/nsXBLPrototypeHandler.h => dom/events/KeyEventHandler.h rename : dom/xbl/builtin/ShortcutKeyDefinitionsForBrowserCommon.h => dom/events/ShortcutKeyDefinitionsForBrowserCommon.h rename : dom/xbl/builtin/ShortcutKeyDefinitionsForEditorCommon.h => dom/events/ShortcutKeyDefinitionsForEditorCommon.h rename : dom/xbl/builtin/ShortcutKeyDefinitionsForInputCommon.h => dom/events/ShortcutKeyDefinitionsForInputCommon.h rename : dom/xbl/builtin/ShortcutKeyDefinitionsForInputCommon.h => dom/events/ShortcutKeyDefinitionsForTextAreaCommon.h rename : dom/xbl/builtin/ShortcutKeys.cpp => dom/events/ShortcutKeys.cpp rename : dom/xbl/builtin/ShortcutKeys.h => dom/events/ShortcutKeys.h rename : dom/xbl/builtin/android/ShortcutKeyDefinitions.cpp => dom/events/android/ShortcutKeyDefinitions.cpp rename : dom/xbl/builtin/android/moz.build => dom/events/android/moz.build rename : dom/xbl/builtin/emacs/ShortcutKeyDefinitions.cpp => dom/events/emacs/ShortcutKeyDefinitions.cpp rename : dom/xbl/builtin/android/moz.build => dom/events/emacs/moz.build rename : dom/xbl/builtin/mac/ShortcutKeyDefinitions.cpp => dom/events/mac/ShortcutKeyDefinitions.cpp rename : dom/xbl/builtin/android/moz.build => dom/events/mac/moz.build rename : dom/xbl/builtin/unix/ShortcutKeyDefinitions.cpp => dom/events/unix/ShortcutKeyDefinitions.cpp rename : dom/xbl/builtin/android/moz.build => dom/events/unix/moz.build rename : dom/xbl/builtin/win/ShortcutKeyDefinitions.cpp => dom/events/win/ShortcutKeyDefinitions.cpp rename : dom/xbl/builtin/android/moz.build => dom/events/win/moz.build extra : moz-landing-system : lando
2019-09-06 20:10:40 +03:00
KeyEventHandler* ShortcutKeys::GetHandlers(HandlerType aType) {
if (!sInstance) {
sInstance = new ShortcutKeys();
}
return sInstance->EnsureHandlers(aType);
}
/* static */
nsAtom* ShortcutKeys::ConvertEventToDOMEventType(
const WidgetKeyboardEvent* aWidgetKeyboardEvent) {
if (aWidgetKeyboardEvent->IsKeyDownOrKeyDownOnPlugin()) {
return nsGkAtoms::keydown;
}
if (aWidgetKeyboardEvent->IsKeyUpOrKeyUpOnPlugin()) {
return nsGkAtoms::keyup;
}
// eAccessKeyNotFound event is always created from eKeyPress event and
// the original eKeyPress event has stopped its propagation before dispatched
// into the DOM tree in this process and not matched with remote content's
// access keys. So, we should treat it as an eKeyPress event and execute
// a command if it's registered as a shortcut key.
if (aWidgetKeyboardEvent->mMessage == eKeyPress ||
aWidgetKeyboardEvent->mMessage == eAccessKeyNotFound) {
return nsGkAtoms::keypress;
}
MOZ_ASSERT_UNREACHABLE(
"All event messages relating to shortcut keys should be handled");
return nullptr;
}
Bug 1550058: Move most keyboard shortcut handling out of XBL. r=masayuki Most of our keyboard shortcut handling is handled by nsXBLWindowKeyHandler along with nsXBLPrototypeHandler. With the impending removal of XBL this needs to change. This patch moves nsXBLWindowKeyHandler to dom/events/GlobalKeyListener and copies nsXBLPrototypeHandler to dom/events/KeyEventHandler. Windows, text elements and XUL <keyset> are changed to use the new copies and anything unnecessary for those is stripped out. XBL handler elements still remain using the existing nsXBLPrototypeHandler path. Some of the code is ripped out there to make it compile. There is probably a lot more that can be removed but since the whole of XBL is likely gone soon I'm not sure it is worth cleaning that up much. Differential Revision: https://phabricator.services.mozilla.com/D42336 --HG-- rename : dom/xbl/nsXBLWindowKeyHandler.cpp => dom/events/GlobalKeyListener.cpp rename : dom/xbl/nsXBLWindowKeyHandler.h => dom/events/GlobalKeyListener.h rename : dom/xbl/nsXBLPrototypeHandler.cpp => dom/events/KeyEventHandler.cpp rename : dom/xbl/nsXBLPrototypeHandler.h => dom/events/KeyEventHandler.h rename : dom/xbl/builtin/ShortcutKeyDefinitionsForBrowserCommon.h => dom/events/ShortcutKeyDefinitionsForBrowserCommon.h rename : dom/xbl/builtin/ShortcutKeyDefinitionsForEditorCommon.h => dom/events/ShortcutKeyDefinitionsForEditorCommon.h rename : dom/xbl/builtin/ShortcutKeyDefinitionsForInputCommon.h => dom/events/ShortcutKeyDefinitionsForInputCommon.h rename : dom/xbl/builtin/ShortcutKeyDefinitionsForInputCommon.h => dom/events/ShortcutKeyDefinitionsForTextAreaCommon.h rename : dom/xbl/builtin/ShortcutKeys.cpp => dom/events/ShortcutKeys.cpp rename : dom/xbl/builtin/ShortcutKeys.h => dom/events/ShortcutKeys.h rename : dom/xbl/builtin/android/ShortcutKeyDefinitions.cpp => dom/events/android/ShortcutKeyDefinitions.cpp rename : dom/xbl/builtin/android/moz.build => dom/events/android/moz.build rename : dom/xbl/builtin/emacs/ShortcutKeyDefinitions.cpp => dom/events/emacs/ShortcutKeyDefinitions.cpp rename : dom/xbl/builtin/android/moz.build => dom/events/emacs/moz.build rename : dom/xbl/builtin/mac/ShortcutKeyDefinitions.cpp => dom/events/mac/ShortcutKeyDefinitions.cpp rename : dom/xbl/builtin/android/moz.build => dom/events/mac/moz.build rename : dom/xbl/builtin/unix/ShortcutKeyDefinitions.cpp => dom/events/unix/ShortcutKeyDefinitions.cpp rename : dom/xbl/builtin/android/moz.build => dom/events/unix/moz.build rename : dom/xbl/builtin/win/ShortcutKeyDefinitions.cpp => dom/events/win/ShortcutKeyDefinitions.cpp rename : dom/xbl/builtin/android/moz.build => dom/events/win/moz.build extra : moz-landing-system : lando
2019-09-06 20:10:40 +03:00
KeyEventHandler* ShortcutKeys::EnsureHandlers(HandlerType aType) {
ShortcutKeyData* keyData;
Bug 1550058: Move most keyboard shortcut handling out of XBL. r=masayuki Most of our keyboard shortcut handling is handled by nsXBLWindowKeyHandler along with nsXBLPrototypeHandler. With the impending removal of XBL this needs to change. This patch moves nsXBLWindowKeyHandler to dom/events/GlobalKeyListener and copies nsXBLPrototypeHandler to dom/events/KeyEventHandler. Windows, text elements and XUL <keyset> are changed to use the new copies and anything unnecessary for those is stripped out. XBL handler elements still remain using the existing nsXBLPrototypeHandler path. Some of the code is ripped out there to make it compile. There is probably a lot more that can be removed but since the whole of XBL is likely gone soon I'm not sure it is worth cleaning that up much. Differential Revision: https://phabricator.services.mozilla.com/D42336 --HG-- rename : dom/xbl/nsXBLWindowKeyHandler.cpp => dom/events/GlobalKeyListener.cpp rename : dom/xbl/nsXBLWindowKeyHandler.h => dom/events/GlobalKeyListener.h rename : dom/xbl/nsXBLPrototypeHandler.cpp => dom/events/KeyEventHandler.cpp rename : dom/xbl/nsXBLPrototypeHandler.h => dom/events/KeyEventHandler.h rename : dom/xbl/builtin/ShortcutKeyDefinitionsForBrowserCommon.h => dom/events/ShortcutKeyDefinitionsForBrowserCommon.h rename : dom/xbl/builtin/ShortcutKeyDefinitionsForEditorCommon.h => dom/events/ShortcutKeyDefinitionsForEditorCommon.h rename : dom/xbl/builtin/ShortcutKeyDefinitionsForInputCommon.h => dom/events/ShortcutKeyDefinitionsForInputCommon.h rename : dom/xbl/builtin/ShortcutKeyDefinitionsForInputCommon.h => dom/events/ShortcutKeyDefinitionsForTextAreaCommon.h rename : dom/xbl/builtin/ShortcutKeys.cpp => dom/events/ShortcutKeys.cpp rename : dom/xbl/builtin/ShortcutKeys.h => dom/events/ShortcutKeys.h rename : dom/xbl/builtin/android/ShortcutKeyDefinitions.cpp => dom/events/android/ShortcutKeyDefinitions.cpp rename : dom/xbl/builtin/android/moz.build => dom/events/android/moz.build rename : dom/xbl/builtin/emacs/ShortcutKeyDefinitions.cpp => dom/events/emacs/ShortcutKeyDefinitions.cpp rename : dom/xbl/builtin/android/moz.build => dom/events/emacs/moz.build rename : dom/xbl/builtin/mac/ShortcutKeyDefinitions.cpp => dom/events/mac/ShortcutKeyDefinitions.cpp rename : dom/xbl/builtin/android/moz.build => dom/events/mac/moz.build rename : dom/xbl/builtin/unix/ShortcutKeyDefinitions.cpp => dom/events/unix/ShortcutKeyDefinitions.cpp rename : dom/xbl/builtin/android/moz.build => dom/events/unix/moz.build rename : dom/xbl/builtin/win/ShortcutKeyDefinitions.cpp => dom/events/win/ShortcutKeyDefinitions.cpp rename : dom/xbl/builtin/android/moz.build => dom/events/win/moz.build extra : moz-landing-system : lando
2019-09-06 20:10:40 +03:00
KeyEventHandler** cache;
switch (aType) {
case HandlerType::eBrowser:
keyData = &sBrowserHandlers[0];
cache = &mBrowserHandlers;
break;
case HandlerType::eEditor:
keyData = &sEditorHandlers[0];
cache = &mEditorHandlers;
break;
case HandlerType::eInput:
keyData = &sInputHandlers[0];
cache = &mInputHandlers;
break;
case HandlerType::eTextArea:
keyData = &sTextAreaHandlers[0];
cache = &mTextAreaHandlers;
break;
default:
MOZ_ASSERT(false, "Unknown handler type requested.");
}
if (*cache) {
return *cache;
}
Bug 1550058: Move most keyboard shortcut handling out of XBL. r=masayuki Most of our keyboard shortcut handling is handled by nsXBLWindowKeyHandler along with nsXBLPrototypeHandler. With the impending removal of XBL this needs to change. This patch moves nsXBLWindowKeyHandler to dom/events/GlobalKeyListener and copies nsXBLPrototypeHandler to dom/events/KeyEventHandler. Windows, text elements and XUL <keyset> are changed to use the new copies and anything unnecessary for those is stripped out. XBL handler elements still remain using the existing nsXBLPrototypeHandler path. Some of the code is ripped out there to make it compile. There is probably a lot more that can be removed but since the whole of XBL is likely gone soon I'm not sure it is worth cleaning that up much. Differential Revision: https://phabricator.services.mozilla.com/D42336 --HG-- rename : dom/xbl/nsXBLWindowKeyHandler.cpp => dom/events/GlobalKeyListener.cpp rename : dom/xbl/nsXBLWindowKeyHandler.h => dom/events/GlobalKeyListener.h rename : dom/xbl/nsXBLPrototypeHandler.cpp => dom/events/KeyEventHandler.cpp rename : dom/xbl/nsXBLPrototypeHandler.h => dom/events/KeyEventHandler.h rename : dom/xbl/builtin/ShortcutKeyDefinitionsForBrowserCommon.h => dom/events/ShortcutKeyDefinitionsForBrowserCommon.h rename : dom/xbl/builtin/ShortcutKeyDefinitionsForEditorCommon.h => dom/events/ShortcutKeyDefinitionsForEditorCommon.h rename : dom/xbl/builtin/ShortcutKeyDefinitionsForInputCommon.h => dom/events/ShortcutKeyDefinitionsForInputCommon.h rename : dom/xbl/builtin/ShortcutKeyDefinitionsForInputCommon.h => dom/events/ShortcutKeyDefinitionsForTextAreaCommon.h rename : dom/xbl/builtin/ShortcutKeys.cpp => dom/events/ShortcutKeys.cpp rename : dom/xbl/builtin/ShortcutKeys.h => dom/events/ShortcutKeys.h rename : dom/xbl/builtin/android/ShortcutKeyDefinitions.cpp => dom/events/android/ShortcutKeyDefinitions.cpp rename : dom/xbl/builtin/android/moz.build => dom/events/android/moz.build rename : dom/xbl/builtin/emacs/ShortcutKeyDefinitions.cpp => dom/events/emacs/ShortcutKeyDefinitions.cpp rename : dom/xbl/builtin/android/moz.build => dom/events/emacs/moz.build rename : dom/xbl/builtin/mac/ShortcutKeyDefinitions.cpp => dom/events/mac/ShortcutKeyDefinitions.cpp rename : dom/xbl/builtin/android/moz.build => dom/events/mac/moz.build rename : dom/xbl/builtin/unix/ShortcutKeyDefinitions.cpp => dom/events/unix/ShortcutKeyDefinitions.cpp rename : dom/xbl/builtin/android/moz.build => dom/events/unix/moz.build rename : dom/xbl/builtin/win/ShortcutKeyDefinitions.cpp => dom/events/win/ShortcutKeyDefinitions.cpp rename : dom/xbl/builtin/android/moz.build => dom/events/win/moz.build extra : moz-landing-system : lando
2019-09-06 20:10:40 +03:00
KeyEventHandler* lastHandler = nullptr;
while (keyData->event) {
Bug 1550058: Move most keyboard shortcut handling out of XBL. r=masayuki Most of our keyboard shortcut handling is handled by nsXBLWindowKeyHandler along with nsXBLPrototypeHandler. With the impending removal of XBL this needs to change. This patch moves nsXBLWindowKeyHandler to dom/events/GlobalKeyListener and copies nsXBLPrototypeHandler to dom/events/KeyEventHandler. Windows, text elements and XUL <keyset> are changed to use the new copies and anything unnecessary for those is stripped out. XBL handler elements still remain using the existing nsXBLPrototypeHandler path. Some of the code is ripped out there to make it compile. There is probably a lot more that can be removed but since the whole of XBL is likely gone soon I'm not sure it is worth cleaning that up much. Differential Revision: https://phabricator.services.mozilla.com/D42336 --HG-- rename : dom/xbl/nsXBLWindowKeyHandler.cpp => dom/events/GlobalKeyListener.cpp rename : dom/xbl/nsXBLWindowKeyHandler.h => dom/events/GlobalKeyListener.h rename : dom/xbl/nsXBLPrototypeHandler.cpp => dom/events/KeyEventHandler.cpp rename : dom/xbl/nsXBLPrototypeHandler.h => dom/events/KeyEventHandler.h rename : dom/xbl/builtin/ShortcutKeyDefinitionsForBrowserCommon.h => dom/events/ShortcutKeyDefinitionsForBrowserCommon.h rename : dom/xbl/builtin/ShortcutKeyDefinitionsForEditorCommon.h => dom/events/ShortcutKeyDefinitionsForEditorCommon.h rename : dom/xbl/builtin/ShortcutKeyDefinitionsForInputCommon.h => dom/events/ShortcutKeyDefinitionsForInputCommon.h rename : dom/xbl/builtin/ShortcutKeyDefinitionsForInputCommon.h => dom/events/ShortcutKeyDefinitionsForTextAreaCommon.h rename : dom/xbl/builtin/ShortcutKeys.cpp => dom/events/ShortcutKeys.cpp rename : dom/xbl/builtin/ShortcutKeys.h => dom/events/ShortcutKeys.h rename : dom/xbl/builtin/android/ShortcutKeyDefinitions.cpp => dom/events/android/ShortcutKeyDefinitions.cpp rename : dom/xbl/builtin/android/moz.build => dom/events/android/moz.build rename : dom/xbl/builtin/emacs/ShortcutKeyDefinitions.cpp => dom/events/emacs/ShortcutKeyDefinitions.cpp rename : dom/xbl/builtin/android/moz.build => dom/events/emacs/moz.build rename : dom/xbl/builtin/mac/ShortcutKeyDefinitions.cpp => dom/events/mac/ShortcutKeyDefinitions.cpp rename : dom/xbl/builtin/android/moz.build => dom/events/mac/moz.build rename : dom/xbl/builtin/unix/ShortcutKeyDefinitions.cpp => dom/events/unix/ShortcutKeyDefinitions.cpp rename : dom/xbl/builtin/android/moz.build => dom/events/unix/moz.build rename : dom/xbl/builtin/win/ShortcutKeyDefinitions.cpp => dom/events/win/ShortcutKeyDefinitions.cpp rename : dom/xbl/builtin/android/moz.build => dom/events/win/moz.build extra : moz-landing-system : lando
2019-09-06 20:10:40 +03:00
KeyEventHandler* handler = new KeyEventHandler(keyData);
if (lastHandler) {
lastHandler->SetNextHandler(handler);
} else {
*cache = handler;
}
lastHandler = handler;
keyData++;
}
return *cache;
}
} // namespace mozilla