From 3ddae5ea36e6bc47560e374a7581437ca057822c Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Sun, 25 Jan 2015 22:46:50 -0800 Subject: [PATCH] Switch KeyboardEvents over to NewEventHandler This CL moves KeyboardEvents from the old event model to NewEventHandler. This CL keeps the basic structure of keydown, keypress, keyup events even though that's a bit wacky. As with pointer and gesture events, this CL removes PlatformKeyboardEvent in favor of just using WebKeyboardEvent. I've also made WebKeyboardEvent align more closely with Mojo's keyboard event. The CL does change one important aspect of key event handling: on the web the "keyCode" property of KeyboardEvent changes its meaning depending on whether the event is a keydown or a keypress event. For the former events, keyCode is the "virtual" (i.e., windows) key code where for the latter events, keyCode is the character code. To be more precise, I've renamed keyCode to virtualKeyCode and I've given it a zero (unknown key code) value during keypress events. R=ojan@chromium.org, eseidel@chromium.org Review URL: https://codereview.chromium.org/872233002 --- engine/core/dom/Node.cpp | 5 - engine/core/dom/Node.h | 4 - engine/core/editing/EditingBehavior.cpp | 27 +-- engine/core/editing/EditorKeyBindings.cpp | 22 +- engine/core/events/GestureEvent.cpp | 2 +- engine/core/events/KeyboardEvent.cpp | 242 +++++---------------- engine/core/events/KeyboardEvent.h | 129 ++++------- engine/core/events/KeyboardEvent.idl | 60 ++--- engine/core/frame/NewEventHandler.cpp | 50 ++++- engine/core/frame/NewEventHandler.h | 5 + engine/core/page/ChromeClient.h | 4 - engine/core/page/EventHandler.cpp | 62 +----- engine/core/page/EventHandler.h | 2 - engine/platform/BUILD.gn | 3 - engine/platform/PlatformEvent.h | 6 - engine/platform/PlatformKeyboardEvent.cpp | 65 ------ engine/platform/PlatformKeyboardEvent.h | 105 --------- engine/platform/exported/WebInputEvent.cpp | 221 ------------------- engine/public/platform/WebInputEvent.h | 61 +----- engine/public/web/WebFrameClient.h | 4 - engine/web/BUILD.gn | 2 - engine/web/ChromeClientImpl.cpp | 17 -- engine/web/ChromeClientImpl.h | 4 - engine/web/WebInputEventConversion.cpp | 238 -------------------- engine/web/WebInputEventConversion.h | 67 ------ engine/web/WebViewImpl.cpp | 178 +-------------- engine/web/WebViewImpl.h | 16 -- framework/sky-input.sky | 2 +- tests/services/event-sender.sky | 6 +- viewer/converters/input_event_types.cc | 13 +- 30 files changed, 200 insertions(+), 1422 deletions(-) delete mode 100644 engine/platform/PlatformKeyboardEvent.cpp delete mode 100644 engine/platform/PlatformKeyboardEvent.h delete mode 100644 engine/platform/exported/WebInputEvent.cpp delete mode 100644 engine/web/WebInputEventConversion.cpp delete mode 100644 engine/web/WebInputEventConversion.h diff --git a/engine/core/dom/Node.cpp b/engine/core/dom/Node.cpp index 9702cdb54c1..b4f47aba3ce 100644 --- a/engine/core/dom/Node.cpp +++ b/engine/core/dom/Node.cpp @@ -1446,11 +1446,6 @@ bool Node::dispatchDOMActivateEvent(int detail, PassRefPtr underlyingEven return event->defaultHandled(); } -bool Node::dispatchKeyEvent(const PlatformKeyboardEvent& event) -{ - return EventDispatcher::dispatchEvent(this, KeyboardEventDispatchMediator::create(KeyboardEvent::create(event, document().domWindow()))); -} - void Node::dispatchInputEvent() { dispatchScopedEvent(Event::createBubble(EventTypeNames::input)); diff --git a/engine/core/dom/Node.h b/engine/core/dom/Node.h index 056e57b545e..9828601c2cb 100644 --- a/engine/core/dom/Node.h +++ b/engine/core/dom/Node.h @@ -60,7 +60,6 @@ class NSResolver; class NodeEventContext; class NodeList; class NodeRareData; -class PlatformKeyboardEvent; class QualifiedName; class RegisteredEventListener; class RenderBox; @@ -463,9 +462,6 @@ public: virtual void handleLocalEvents(Event*); bool dispatchDOMActivateEvent(int detail, PassRefPtr underlyingEvent); - - bool dispatchKeyEvent(const PlatformKeyboardEvent&); - void dispatchInputEvent(); // Perform the default action for an event. diff --git a/engine/core/editing/EditingBehavior.cpp b/engine/core/editing/EditingBehavior.cpp index 53d8ba6b926..8f87f254a14 100644 --- a/engine/core/editing/EditingBehavior.cpp +++ b/engine/core/editing/EditingBehavior.cpp @@ -27,9 +27,9 @@ #include "sky/engine/config.h" #include "sky/engine/core/editing/EditingBehavior.h" +#include "gen/sky/core/EventTypeNames.h" #include "sky/engine/core/events/KeyboardEvent.h" #include "sky/engine/platform/KeyboardCodes.h" -#include "sky/engine/platform/PlatformKeyboardEvent.h" namespace blink { @@ -120,10 +120,6 @@ static const KeyPressEntry keyPressEntries[] = { const char* EditingBehavior::interpretKeyEvent(const KeyboardEvent& event) const { - const PlatformKeyboardEvent* keyEvent = event.keyEvent(); - if (!keyEvent) - return ""; - static HashMap* keyDownCommandsMap = 0; static HashMap* keyPressCommandsMap = 0; @@ -141,17 +137,17 @@ const char* EditingBehavior::interpretKeyEvent(const KeyboardEvent& event) const } unsigned modifiers = 0; - if (keyEvent->shiftKey()) + if (event.shiftKey()) modifiers |= ShiftKey; - if (keyEvent->altKey()) + if (event.altKey()) modifiers |= AltKey; - if (keyEvent->ctrlKey()) + if (event.ctrlKey()) modifiers |= CtrlKey; - if (keyEvent->metaKey()) + if (event.metaKey()) modifiers |= MetaKey; - if (keyEvent->type() == PlatformEvent::RawKeyDown) { - int mapKey = modifiers << 16 | event.keyCode(); + if (event.type() == EventTypeNames::keydown) { + int mapKey = modifiers << 16 | event.key(); return mapKey ? keyDownCommandsMap->get(mapKey) : 0; } @@ -161,9 +157,6 @@ const char* EditingBehavior::interpretKeyEvent(const KeyboardEvent& event) const bool EditingBehavior::shouldInsertCharacter(const KeyboardEvent& event) const { - if (event.keyEvent()->text().length() != 1) - return true; - // On Gtk/Linux, it emits key events with ASCII text and ctrl on for ctrl-. // In Webkit, EditorClient::handleKeyboardEvent in // WebKit/gtk/WebCoreSupport/EditorClientGtk.cpp drop such events. @@ -180,7 +173,7 @@ bool EditingBehavior::shouldInsertCharacter(const KeyboardEvent& event) const // which may be configured to do it so by user. // See also http://en.wikipedia.org/wiki/Keyboard_Layout // FIXME(ukai): investigate more detail for various keyboard layout. - UChar ch = event.keyEvent()->text()[0U]; + UChar ch = event.charCode(); // Don't insert null or control characters as they can result in // unexpected behaviour @@ -190,10 +183,10 @@ bool EditingBehavior::shouldInsertCharacter(const KeyboardEvent& event) const // Don't insert ASCII character if ctrl w/o alt or meta is on. // On Mac, we should ignore events when meta is on (Command-). if (ch < 0x80) { - if (event.keyEvent()->ctrlKey() && !event.keyEvent()->altKey()) + if (event.ctrlKey() && !event.altKey()) return false; #if OS(MACOSX) - if (event.keyEvent()->metaKey()) + if (event.metaKey()) return false; #endif } diff --git a/engine/core/editing/EditorKeyBindings.cpp b/engine/core/editing/EditorKeyBindings.cpp index f94fc34297f..40d5e50b7ee 100644 --- a/engine/core/editing/EditorKeyBindings.cpp +++ b/engine/core/editing/EditorKeyBindings.cpp @@ -27,24 +27,19 @@ #include "sky/engine/config.h" #include "sky/engine/core/editing/Editor.h" +#include "gen/sky/core/EventTypeNames.h" #include "sky/engine/core/events/KeyboardEvent.h" #include "sky/engine/core/frame/LocalFrame.h" #include "sky/engine/core/page/EditorClient.h" -#include "sky/engine/platform/PlatformKeyboardEvent.h" namespace blink { -bool Editor::handleEditingKeyboardEvent(KeyboardEvent* evt) +bool Editor::handleEditingKeyboardEvent(KeyboardEvent* event) { - const PlatformKeyboardEvent* keyEvent = evt->keyEvent(); - // do not treat this as text input if it's a system key event - if (!keyEvent || keyEvent->isSystemKey()) - return false; - - String commandName = behavior().interpretKeyEvent(*evt); + String commandName = behavior().interpretKeyEvent(*event); Command command = this->command(commandName); - if (keyEvent->type() == PlatformEvent::RawKeyDown) { + if (event->type() == EventTypeNames::keydown) { // WebKit doesn't have enough information about mode to decide how // commands that just insert text if executed via Editor should be treated, // so we leave it upon WebCore to either handle them immediately @@ -52,16 +47,17 @@ bool Editor::handleEditingKeyboardEvent(KeyboardEvent* evt) // (e.g. Tab that inserts a Tab character, or Enter). if (command.isTextInsertion() || commandName.isEmpty()) return false; - return command.execute(evt); + return command.execute(event); } - if (command.execute(evt)) + if (command.execute(event)) return true; - if (!behavior().shouldInsertCharacter(*evt) || !canEdit()) + if (!behavior().shouldInsertCharacter(*event) || !canEdit()) return false; - return insertText(evt->keyEvent()->text(), evt); + UChar charCode = event->charCode(); + return insertText(String(&charCode, 1), event); } void Editor::handleKeyboardEvent(KeyboardEvent* evt) diff --git a/engine/core/events/GestureEvent.cpp b/engine/core/events/GestureEvent.cpp index 4d0afdd0a83..8bf0d55f90f 100644 --- a/engine/core/events/GestureEvent.cpp +++ b/engine/core/events/GestureEvent.cpp @@ -87,7 +87,7 @@ GestureEvent::GestureEvent(const WebGestureEvent& event) } GestureEvent::GestureEvent(const AtomicString& type, const GestureEventInit& initializer) - : Event(type, true, true) + : Event(type, initializer) , m_x(initializer.x) , m_y(initializer.y) , m_dx(initializer.dx) diff --git a/engine/core/events/KeyboardEvent.cpp b/engine/core/events/KeyboardEvent.cpp index 1bedfa96033..dde48ac3fac 100644 --- a/engine/core/events/KeyboardEvent.cpp +++ b/engine/core/events/KeyboardEvent.cpp @@ -1,195 +1,39 @@ -/** - * Copyright (C) 2001 Peter Kelly (pmk@post.com) - * Copyright (C) 2001 Tobias Anton (anton@stud.fbi.fh-darmstadt.de) - * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) - * Copyright (C) 2003, 2005, 2006, 2007 Apple Inc. All rights reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. #include "sky/engine/config.h" #include "sky/engine/core/events/KeyboardEvent.h" -#include "sky/engine/platform/PlatformKeyboardEvent.h" -#include "sky/engine/platform/WindowsKeyboardCodes.h" - namespace blink { -static inline const AtomicString& eventTypeForKeyboardEventType(PlatformEvent::Type type) +static AtomicString stringForType(WebInputEvent::Type type) { - switch (type) { - case PlatformEvent::KeyUp: - return EventTypeNames::keyup; - case PlatformEvent::RawKeyDown: - return EventTypeNames::keydown; - case PlatformEvent::Char: - return EventTypeNames::keypress; - case PlatformEvent::KeyDown: - // The caller should disambiguate the combined event into RawKeyDown or Char events. - break; - default: - break; - } + if (type == WebInputEvent::KeyDown) + return EventTypeNames::keydown; + if (type == WebInputEvent::Char) + return EventTypeNames::keypress; + if (type == WebInputEvent::KeyUp) + return EventTypeNames::keyup; ASSERT_NOT_REACHED(); - return EventTypeNames::keydown; + return AtomicString(); } -static inline int windowsVirtualKeyCodeWithoutLocation(int keycode) -{ - switch (keycode) { - case VK_LCONTROL: - case VK_RCONTROL: - return VK_CONTROL; - case VK_LSHIFT: - case VK_RSHIFT: - return VK_SHIFT; - case VK_LMENU: - case VK_RMENU: - return VK_MENU; - default: - return keycode; - } -} - -static inline KeyboardEvent::KeyLocationCode keyLocationCode(const PlatformKeyboardEvent& key) -{ - if (key.isKeypad()) - return KeyboardEvent::DOM_KEY_LOCATION_NUMPAD; - - switch (key.windowsVirtualKeyCode()) { - case VK_LCONTROL: - case VK_LSHIFT: - case VK_LMENU: - case VK_LWIN: - return KeyboardEvent::DOM_KEY_LOCATION_LEFT; - case VK_RCONTROL: - case VK_RSHIFT: - case VK_RMENU: - case VK_RWIN: - return KeyboardEvent::DOM_KEY_LOCATION_RIGHT; - default: - return KeyboardEvent::DOM_KEY_LOCATION_STANDARD; - } -} - -KeyboardEventInit::KeyboardEventInit() - : location(0) - , ctrlKey(false) - , altKey(false) - , shiftKey(false) - , metaKey(false) - , repeat(false) -{ -} - -KeyboardEvent::KeyboardEvent() - : m_location(DOM_KEY_LOCATION_STANDARD) - , m_isAutoRepeat(false) -{ -} - -KeyboardEvent::KeyboardEvent(const PlatformKeyboardEvent& key, AbstractView* view) - : UIEventWithKeyState(eventTypeForKeyboardEventType(key.type()), - true, true, view, 0, key.ctrlKey(), key.altKey(), key.shiftKey(), key.metaKey()) - , m_keyEvent(adoptPtr(new PlatformKeyboardEvent(key))) - , m_keyIdentifier(key.keyIdentifier()) - , m_location(keyLocationCode(key)) - , m_isAutoRepeat(key.isAutoRepeat()) -{ -} - -KeyboardEvent::KeyboardEvent(const AtomicString& eventType, const KeyboardEventInit& initializer) - : UIEventWithKeyState(eventType, initializer.bubbles, initializer.cancelable, initializer.view, initializer.detail, initializer.ctrlKey, initializer.altKey, initializer.shiftKey, initializer.metaKey) - , m_keyIdentifier(initializer.keyIdentifier) - , m_location(initializer.location) - , m_isAutoRepeat(initializer.repeat) -{ -} - -KeyboardEvent::KeyboardEvent(const AtomicString& eventType, bool canBubble, bool cancelable, AbstractView *view, - const String &keyIdentifier, unsigned location, - bool ctrlKey, bool altKey, bool shiftKey, bool metaKey) - : UIEventWithKeyState(eventType, canBubble, cancelable, view, 0, ctrlKey, altKey, shiftKey, metaKey) - , m_keyIdentifier(keyIdentifier) - , m_location(location) - , m_isAutoRepeat(false) +static String locationFromModifiers(int modifiers) { + if (modifiers & WebInputEvent::IsKeyPad) + return "numpad"; + if (modifiers & WebInputEvent::IsLeft) + return "left"; + if (modifiers & WebInputEvent::IsRight) + return "right"; + return "standard"; } KeyboardEvent::~KeyboardEvent() { } -void KeyboardEvent::initKeyboardEvent(const AtomicString& type, bool canBubble, bool cancelable, AbstractView* view, - const String &keyIdentifier, unsigned location, - bool ctrlKey, bool altKey, bool shiftKey, bool metaKey) -{ - if (dispatched()) - return; - - initUIEvent(type, canBubble, cancelable, view, 0); - - m_keyIdentifier = keyIdentifier; - m_location = location; - m_ctrlKey = ctrlKey; - m_shiftKey = shiftKey; - m_altKey = altKey; - m_metaKey = metaKey; -} - -bool KeyboardEvent::getModifierState(const String& keyIdentifier) const -{ - // FIXME: The following keyIdentifiers are not supported yet (crbug.com/265458): - // "AltGraph", "CapsLock", "Fn", "NumLock", "ScrollLock", "SymbolLock", "OS". - if (keyIdentifier == "Control") - return ctrlKey(); - if (keyIdentifier == "Shift") - return shiftKey(); - if (keyIdentifier == "Alt") - return altKey(); - if (keyIdentifier == "Meta") - return metaKey(); - return false; -} - -int KeyboardEvent::keyCode() const -{ - // IE: virtual key code for keyup/keydown, character code for keypress - // Firefox: virtual key code for keyup/keydown, zero for keypress - // We match IE. - if (!m_keyEvent) - return 0; - if (type() == EventTypeNames::keydown || type() == EventTypeNames::keyup) - return windowsVirtualKeyCodeWithoutLocation(m_keyEvent->windowsVirtualKeyCode()); - - return charCode(); -} - -int KeyboardEvent::charCode() const -{ - // IE: not supported - // Firefox: 0 for keydown/keyup events, character code for keypress - // We match Firefox - - if (!m_keyEvent || (type() != EventTypeNames::keypress)) - return 0; - String text = m_keyEvent->text(); - return static_cast(text.characterStartingAt(0)); -} - const AtomicString& KeyboardEvent::interfaceName() const { return EventNames::KeyboardEvent; @@ -200,27 +44,41 @@ bool KeyboardEvent::isKeyboardEvent() const return true; } -int KeyboardEvent::which() const -{ - // Netscape's "which" returns a virtual key code for keydown and keyup, and a character code for keypress. - // That's exactly what IE's "keyCode" returns. So they are the same for keyboard events. - return keyCode(); -} - -PassRefPtr KeyboardEventDispatchMediator::create(PassRefPtr event) -{ - return adoptRef(new KeyboardEventDispatchMediator(event)); -} - -KeyboardEventDispatchMediator::KeyboardEventDispatchMediator(PassRefPtr event) - : EventDispatchMediator(event) +KeyboardEvent::KeyboardEvent() + : KeyboardEvent(AtomicString(), KeyboardEventInit()) { } -bool KeyboardEventDispatchMediator::dispatchEvent(EventDispatcher* dispatcher) const +KeyboardEvent::KeyboardEvent(const WebKeyboardEvent& event) + : Event(stringForType(event.type), true, true) + , m_key(event.key) + , m_location(locationFromModifiers(event.modifiers)) + , m_charCode(event.charCode) + , m_ctrlKey(event.modifiers & WebInputEvent::ControlKey) + , m_shiftKey(event.modifiers & WebInputEvent::ShiftKey) + , m_altKey(event.modifiers & WebInputEvent::AltKey) + , m_metaKey(event.modifiers & WebInputEvent::MetaKey) + , m_repeat(event.modifiers & WebInputEvent::IsAutoRepeat) +{ + if (event.type == WebInputEvent::KeyDown || event.type == WebInputEvent::KeyUp) { + m_charCode = 0; + } else if (event.type == WebInputEvent::Char) { + m_key = 0; + m_location = String(); + } +} + +KeyboardEvent::KeyboardEvent(const AtomicString& type, const KeyboardEventInit& initializer) + : Event(type, initializer) + , m_key(initializer.key) + , m_location(initializer.location) + , m_charCode(initializer.charCode) + , m_ctrlKey(initializer.ctrlKey) + , m_shiftKey(initializer.shiftKey) + , m_altKey(initializer.altKey) + , m_metaKey(initializer.metaKey) + , m_repeat(initializer.repeat) { - // Make sure not to return true if we already took default action while handling the event. - return EventDispatchMediator::dispatchEvent(dispatcher) && !event()->defaultHandled(); } } // namespace blink diff --git a/engine/core/events/KeyboardEvent.h b/engine/core/events/KeyboardEvent.h index c5e5c3c69b9..7517b70abd4 100644 --- a/engine/core/events/KeyboardEvent.h +++ b/engine/core/events/KeyboardEvent.h @@ -1,124 +1,69 @@ -/* - * Copyright (C) 2001 Peter Kelly (pmk@post.com) - * Copyright (C) 2001 Tobias Anton (anton@stud.fbi.fh-darmstadt.de) - * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) - * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - */ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. #ifndef SKY_ENGINE_CORE_EVENTS_KEYBOARDEVENT_H_ #define SKY_ENGINE_CORE_EVENTS_KEYBOARDEVENT_H_ -#include "sky/engine/core/events/EventDispatchMediator.h" -#include "sky/engine/core/events/UIEventWithKeyState.h" +#include "sky/engine/core/events/Event.h" +#include "sky/engine/public/platform/WebInputEvent.h" namespace blink { -class EventDispatcher; -class Node; -class PlatformKeyboardEvent; - -struct KeyboardEventInit : public UIEventInit { - KeyboardEventInit(); - - String keyIdentifier; - unsigned location; - bool ctrlKey; - bool altKey; - bool shiftKey; - bool metaKey; - bool repeat; +struct KeyboardEventInit : public EventInit { + unsigned key = 0; + String location; + unsigned charCode = 0; + bool ctrlKey = false; + bool shiftKey = false; + bool altKey = false; + bool metaKey = false; + bool repeat = false; }; -class KeyboardEvent final : public UIEventWithKeyState { +class KeyboardEvent : public Event { DEFINE_WRAPPERTYPEINFO(); public: - enum KeyLocationCode { - DOM_KEY_LOCATION_STANDARD = 0x00, - DOM_KEY_LOCATION_LEFT = 0x01, - DOM_KEY_LOCATION_RIGHT = 0x02, - DOM_KEY_LOCATION_NUMPAD = 0x03 - }; - static PassRefPtr create() { return adoptRef(new KeyboardEvent); } - - static PassRefPtr create(const PlatformKeyboardEvent& platformEvent, AbstractView* view) + static PassRefPtr create(const WebKeyboardEvent& event) { - return adoptRef(new KeyboardEvent(platformEvent, view)); + return adoptRef(new KeyboardEvent(event)); } - static PassRefPtr create(const AtomicString& type, const KeyboardEventInit& initializer) { return adoptRef(new KeyboardEvent(type, initializer)); } - static PassRefPtr create(const AtomicString& type, bool canBubble, bool cancelable, AbstractView* view, - const String& keyIdentifier, unsigned location, - bool ctrlKey, bool altKey, bool shiftKey, bool metaKey) - { - return adoptRef(new KeyboardEvent(type, canBubble, cancelable, view, keyIdentifier, location, - ctrlKey, altKey, shiftKey, metaKey)); - } + ~KeyboardEvent() override; + const AtomicString& interfaceName() const override; - virtual ~KeyboardEvent(); + bool isKeyboardEvent() const override; - void initKeyboardEvent(const AtomicString& type, bool canBubble, bool cancelable, AbstractView*, - const String& keyIdentifier, unsigned location, - bool ctrlKey, bool altKey, bool shiftKey, bool metaKey); - - const String& keyIdentifier() const { return m_keyIdentifier; } - unsigned location() const { return m_location; } - - bool getModifierState(const String& keyIdentifier) const; - - const PlatformKeyboardEvent* keyEvent() const { return m_keyEvent.get(); } - - virtual int keyCode() const override; // key code for keydown and keyup, character for keypress - virtual int charCode() const override; // character code for keypress, 0 for keydown and keyup - bool repeat() const { return m_isAutoRepeat; } - - virtual const AtomicString& interfaceName() const override; - virtual bool isKeyboardEvent() const override; - virtual int which() const override; + unsigned key() const { return m_key; } + const String& location() const { return m_location; } + unsigned charCode() const { return m_charCode; } + bool ctrlKey() const { return m_ctrlKey; } + bool shiftKey() const { return m_shiftKey; } + bool altKey() const { return m_altKey; } + bool metaKey() const { return m_metaKey; } + bool repeat() const { return m_repeat; } private: KeyboardEvent(); - KeyboardEvent(const PlatformKeyboardEvent&, AbstractView*); + explicit KeyboardEvent(const WebKeyboardEvent& event); KeyboardEvent(const AtomicString&, const KeyboardEventInit&); - KeyboardEvent(const AtomicString& type, bool canBubble, bool cancelable, AbstractView*, - const String& keyIdentifier, unsigned location, - bool ctrlKey, bool altKey, bool shiftKey, bool metaKey); - OwnPtr m_keyEvent; - String m_keyIdentifier; - unsigned m_location; - bool m_isAutoRepeat : 1; -}; - -class KeyboardEventDispatchMediator : public EventDispatchMediator { -public: - static PassRefPtr create(PassRefPtr); -private: - explicit KeyboardEventDispatchMediator(PassRefPtr); - virtual bool dispatchEvent(EventDispatcher*) const override; + unsigned m_key; + String m_location; + unsigned m_charCode; + bool m_ctrlKey; + bool m_shiftKey; + bool m_altKey; + bool m_metaKey; + bool m_repeat; }; DEFINE_EVENT_TYPE_CASTS(KeyboardEvent); diff --git a/engine/core/events/KeyboardEvent.idl b/engine/core/events/KeyboardEvent.idl index ca68d367b11..a618623506b 100644 --- a/engine/core/events/KeyboardEvent.idl +++ b/engine/core/events/KeyboardEvent.idl @@ -1,52 +1,20 @@ -/* - * Copyright (C) 2006 Apple Computer, Inc. - * Copyright (C) 2006 Samuel Weinig - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. [ EventConstructor, -] interface KeyboardEvent : UIEvent { - const unsigned long DOM_KEY_LOCATION_STANDARD = 0x00; - const unsigned long DOM_KEY_LOCATION_LEFT = 0x01; - const unsigned long DOM_KEY_LOCATION_RIGHT = 0x02; - const unsigned long DOM_KEY_LOCATION_NUMPAD = 0x03; +] interface KeyboardEvent : Event { + // For keydown and keyup events: + [InitializedByEventConstructor] readonly attribute long key; + [InitializedByEventConstructor] readonly attribute DOMString location; - [InitializedByEventConstructor] readonly attribute DOMString keyIdentifier; - [InitializedByEventConstructor] readonly attribute unsigned long location; - [ImplementedAs=location, DeprecateAs=KeyboardEventKeyLocation, InitializedByEventConstructor] readonly attribute unsigned long keyLocation; // Deprecated. - [InitializedByEventConstructor] readonly attribute boolean ctrlKey; - [InitializedByEventConstructor] readonly attribute boolean shiftKey; - [InitializedByEventConstructor] readonly attribute boolean altKey; - [InitializedByEventConstructor] readonly attribute boolean metaKey; - [InitializedByEventConstructor] readonly attribute boolean repeat; + // For keypress events: + [InitializedByEventConstructor] readonly attribute long charCode; - boolean getModifierState(DOMString keyArgument); - - // FIXME: this does not match the version in the DOM spec. - void initKeyboardEvent([Default=Undefined] optional DOMString type, - [Default=Undefined] optional boolean canBubble, - [Default=Undefined] optional boolean cancelable, - [Default=Undefined] optional Window view, - [Default=Undefined] optional DOMString keyIdentifier, - [Default=Undefined] optional unsigned long location, - [Default=Undefined] optional boolean ctrlKey, - [Default=Undefined] optional boolean altKey, - [Default=Undefined] optional boolean shiftKey, - [Default=Undefined] optional boolean metaKey); + [InitializedByEventConstructor] readonly attribute boolean ctrlKey; + [InitializedByEventConstructor] readonly attribute boolean shiftKey; + [InitializedByEventConstructor] readonly attribute boolean altKey; + [InitializedByEventConstructor] readonly attribute boolean metaKey; + [InitializedByEventConstructor] readonly attribute boolean repeat; }; - diff --git a/engine/core/frame/NewEventHandler.cpp b/engine/core/frame/NewEventHandler.cpp index ebafd720e81..5318bdec935 100644 --- a/engine/core/frame/NewEventHandler.cpp +++ b/engine/core/frame/NewEventHandler.cpp @@ -11,12 +11,14 @@ #include "sky/engine/core/editing/FrameSelection.h" #include "sky/engine/core/editing/htmlediting.h" #include "sky/engine/core/events/GestureEvent.h" +#include "sky/engine/core/events/KeyboardEvent.h" #include "sky/engine/core/events/PointerEvent.h" #include "sky/engine/core/frame/LocalFrame.h" #include "sky/engine/core/frame/FrameView.h" #include "sky/engine/core/page/EventWithHitTestResults.h" #include "sky/engine/core/rendering/RenderObject.h" #include "sky/engine/core/rendering/RenderView.h" +#include "sky/engine/platform/KeyboardCodes.h" #include "sky/engine/platform/geometry/FloatPoint.h" #include "sky/engine/public/platform/WebInputEvent.h" @@ -39,6 +41,7 @@ static LayoutPoint positionForEvent(const EventType& event) NewEventHandler::NewEventHandler(LocalFrame& frame) : m_frame(frame) + , m_suppressNextCharEvent(false) { } @@ -46,11 +49,19 @@ NewEventHandler::~NewEventHandler() { } +Node* NewEventHandler::targetForKeyboardEvent() const +{ + Document* document = m_frame.document(); + if (Node* focusedElement = document->focusedElement()) + return focusedElement; + return document->documentElement(); +} + Node* NewEventHandler::targetForHitTestResult(const HitTestResult& hitTestResult) { Node* node = hitTestResult.innerNode(); if (!node) - return m_frame.document(); + return m_frame.document()->documentElement(); if (node->isTextNode()) return NodeRenderingTraversal::parent(node); return node; @@ -79,6 +90,12 @@ bool NewEventHandler::dispatchGestureEvent(Node& target, const WebGestureEvent& return target.dispatchEvent(gestureEvent.release()); } +bool NewEventHandler::dispatchKeyboardEvent(Node& target, const WebKeyboardEvent& event) +{ + RefPtr keyboardEvent = KeyboardEvent::create(event); + return target.dispatchEvent(keyboardEvent.release()); +} + bool NewEventHandler::dispatchClickEvent(Node& capturingTarget, const WebPointerEvent& event) { ASSERT(event.type == WebInputEvent::PointerUp); @@ -121,7 +138,34 @@ bool NewEventHandler::handleGestureEvent(const WebGestureEvent& event) { HitTestResult hitTestResult = performHitTest(positionForEvent(event)); RefPtr target = targetForHitTestResult(hitTestResult); - return !dispatchGestureEvent(*target, event); + return target && !dispatchGestureEvent(*target, event); +} + +bool NewEventHandler::handleKeyboardEvent(const WebKeyboardEvent& event) +{ + bool shouldSuppressCharEvent = m_suppressNextCharEvent; + m_suppressNextCharEvent = false; + + if (event.type == WebInputEvent::Char) { + if (shouldSuppressCharEvent) + return true; + // Do we really need to suppress keypress events for these keys anymore? + if (event.key == VKEY_BACK + || event.key == VKEY_ESCAPE) + return true; + } + + RefPtr target = targetForKeyboardEvent(); + bool handled = target && !dispatchKeyboardEvent(*target, event); + + // If the keydown event was handled, we don't want to "generate" a keypress + // event for that keystroke. However, we'll receive a Char event from the + // embedder regardless, so we set m_suppressNextCharEvent, will will prevent + // us from dispatching the keypress event when we receive that Char event. + if (handled && event.type == WebInputEvent::KeyDown) + m_suppressNextCharEvent = true; + + return handled; } bool NewEventHandler::handlePointerDownEvent(const WebPointerEvent& event) @@ -129,6 +173,8 @@ bool NewEventHandler::handlePointerDownEvent(const WebPointerEvent& event) ASSERT(m_targetForPointer.find(event.pointer) == m_targetForPointer.end()); HitTestResult hitTestResult = performHitTest(positionForEvent(event)); RefPtr target = targetForHitTestResult(hitTestResult); + if (!target) + return false; m_targetForPointer[event.pointer] = target; bool eventSwallowed = !dispatchPointerEvent(*target, event); // TODO(abarth): Set the target for the pointer to something determined when diff --git a/engine/core/frame/NewEventHandler.h b/engine/core/frame/NewEventHandler.h index bcbb726af22..3bd62ca28ed 100644 --- a/engine/core/frame/NewEventHandler.h +++ b/engine/core/frame/NewEventHandler.h @@ -15,6 +15,7 @@ namespace blink { class LocalFrame; class WebGestureEvent; +class WebKeyboardEvent; class WebPointerEvent; class NewEventHandler { @@ -25,6 +26,7 @@ public: bool handlePointerEvent(const WebPointerEvent&); bool handleGestureEvent(const WebGestureEvent&); + bool handleKeyboardEvent(const WebKeyboardEvent&); private: bool handlePointerDownEvent(const WebPointerEvent&); @@ -35,7 +37,9 @@ private: bool dispatchGestureEvent(Node& target, const WebGestureEvent& event); bool dispatchPointerEvent(Node& target, const WebPointerEvent&); bool dispatchClickEvent(Node& capturingTarget, const WebPointerEvent&); + bool dispatchKeyboardEvent(Node& target, const WebKeyboardEvent& event); + Node* targetForKeyboardEvent() const; Node* targetForHitTestResult(const HitTestResult& hitTestResult); HitTestResult performHitTest(const LayoutPoint&); void updateSelectionForPointerDown(const HitTestResult&, const WebPointerEvent&); @@ -44,6 +48,7 @@ private: LocalFrame& m_frame; PointerTargetMap m_targetForPointer; + bool m_suppressNextCharEvent; }; } diff --git a/engine/core/page/ChromeClient.h b/engine/core/page/ChromeClient.h index 6ee58a8fb6d..49d3ab1b323 100644 --- a/engine/core/page/ChromeClient.h +++ b/engine/core/page/ChromeClient.h @@ -104,10 +104,6 @@ public: virtual bool isChromeClientImpl() const { return false; } - // FIXME: Remove this method once we have input routing in the browser - // process. See http://crbug.com/339659. - virtual void forwardInputEvent(blink::Frame*, blink::Event*) { } - // Input mehtod editor related functions. virtual void willSetInputMethodState() { } virtual void didUpdateTextOfFocusedElementByNonUserInput() { } diff --git a/engine/core/page/EventHandler.cpp b/engine/core/page/EventHandler.cpp index 354f6bb014e..e269fb18f79 100644 --- a/engine/core/page/EventHandler.cpp +++ b/engine/core/page/EventHandler.cpp @@ -60,9 +60,8 @@ #include "sky/engine/core/rendering/RenderLayer.h" #include "sky/engine/core/rendering/RenderView.h" #include "sky/engine/core/rendering/style/RenderStyle.h" -#include "sky/engine/platform/PlatformKeyboardEvent.h" #include "sky/engine/platform/TraceEvent.h" -#include "sky/engine/platform/WindowsKeyboardCodes.h" +#include "sky/engine/platform/KeyboardCodes.h" #include "sky/engine/platform/geometry/FloatPoint.h" #include "sky/engine/platform/graphics/Image.h" #include "sky/engine/platform/heap/Handle.h" @@ -500,63 +499,6 @@ void EventHandler::notifyElementActivated() m_lastDeferredTapElement = nullptr; } -bool EventHandler::keyEvent(const PlatformKeyboardEvent& initialKeyEvent) -{ - RefPtr protector(m_frame->view()); - - if (initialKeyEvent.windowsVirtualKeyCode() == VK_CAPITAL) - capsLockStateMayHaveChanged(); - - // Check for cases where we are too early for events -- possible unmatched key up - // from pressing return in the location bar. - RefPtr node = eventTargetNodeForDocument(m_frame->document()); - if (!node) - return false; - - // FIXME: it would be fair to let an input method handle KeyUp events before DOM dispatch. - if (initialKeyEvent.type() == PlatformEvent::KeyUp || initialKeyEvent.type() == PlatformEvent::Char) - return !node->dispatchKeyEvent(initialKeyEvent); - - PlatformKeyboardEvent keyDownEvent = initialKeyEvent; - if (keyDownEvent.type() != PlatformEvent::RawKeyDown) - keyDownEvent.disambiguateKeyDownEvent(PlatformEvent::RawKeyDown); - RefPtr keydown = KeyboardEvent::create(keyDownEvent, m_frame->document()->domWindow()); - - keydown->setTarget(node); - - if (initialKeyEvent.type() == PlatformEvent::RawKeyDown) { - node->dispatchEvent(keydown, IGNORE_EXCEPTION); - // If frame changed as a result of keydown dispatch, then return true to avoid sending a subsequent keypress message to the new frame. - bool changedFocusedFrame = m_frame->page() && m_frame != m_frame->page()->focusController().focusedOrMainFrame(); - return keydown->defaultHandled() || keydown->defaultPrevented() || changedFocusedFrame; - } - - node->dispatchEvent(keydown, IGNORE_EXCEPTION); - // If frame changed as a result of keydown dispatch, then return early to avoid sending a subsequent keypress message to the new frame. - bool changedFocusedFrame = m_frame->page() && m_frame != m_frame->page()->focusController().focusedOrMainFrame(); - bool keydownResult = keydown->defaultHandled() || keydown->defaultPrevented() || changedFocusedFrame; - if (keydownResult) - return keydownResult; - - // Focus may have changed during keydown handling, so refetch node. - // But if we are dispatching a fake backward compatibility keypress, then we pretend that the keypress happened on the original node. - node = eventTargetNodeForDocument(m_frame->document()); - if (!node) - return false; - - PlatformKeyboardEvent keyPressEvent = initialKeyEvent; - keyPressEvent.disambiguateKeyDownEvent(PlatformEvent::Char); - if (keyPressEvent.text().isEmpty()) - return keydownResult; - RefPtr keypress = KeyboardEvent::create(keyPressEvent, m_frame->document()->domWindow()); - keypress->setTarget(node); - if (keydownResult) - keypress->setDefaultPrevented(true); - node->dispatchEvent(keypress, IGNORE_EXCEPTION); - - return keydownResult || keypress->defaultPrevented() || keypress->defaultHandled(); -} - void EventHandler::defaultKeyboardEventHandler(KeyboardEvent* event) { if (event->type() == EventTypeNames::keydown) { @@ -568,7 +510,7 @@ void EventHandler::defaultKeyboardEventHandler(KeyboardEvent* event) m_frame->editor().handleKeyboardEvent(event); if (event->defaultHandled()) return; - if (event->keyIdentifier() == "U+0009") + if (event->key() == VKEY_TAB) defaultTabEventHandler(event); } if (event->type() == EventTypeNames::keypress) { diff --git a/engine/core/page/EventHandler.h b/engine/core/page/EventHandler.h index cc4ff63c4fb..be093eadc90 100644 --- a/engine/core/page/EventHandler.h +++ b/engine/core/page/EventHandler.h @@ -59,7 +59,6 @@ class KeyboardEvent; class LocalFrame; class Node; class OptionalCursor; -class PlatformKeyboardEvent; class RenderLayer; class RenderLayerScrollableArea; class RenderObject; @@ -93,7 +92,6 @@ public: // If the view can't be scrolled either, recursively bubble to the parent frame. bool bubblingScroll(ScrollDirection, ScrollGranularity, Node* startingNode = 0); - bool keyEvent(const PlatformKeyboardEvent&); void defaultKeyboardEventHandler(KeyboardEvent*); bool handleTextInputEvent(const String& text, Event* underlyingEvent = 0, TextEventInputType = TextEventInputKeyboard); diff --git a/engine/platform/BUILD.gn b/engine/platform/BUILD.gn index bc75d1d7f0f..8746d17ba8d 100644 --- a/engine/platform/BUILD.gn +++ b/engine/platform/BUILD.gn @@ -132,7 +132,6 @@ source_set("platform") { "exported/WebHTTPBody.cpp", "exported/WebHTTPLoadInfo.cpp", "exported/WebImageSkia.cpp", - "exported/WebInputEvent.cpp", "exported/WebString.cpp", "exported/WebTransformKeyframe.cpp", "exported/WebURL.cpp", @@ -475,8 +474,6 @@ source_set("platform") { "Partitions.h", "PlatformEvent.h", "PlatformExport.h", - "PlatformKeyboardEvent.cpp", - "PlatformKeyboardEvent.h", "PlatformScreen.cpp", "PlatformScreen.h", "PlatformThreadData.cpp", diff --git a/engine/platform/PlatformEvent.h b/engine/platform/PlatformEvent.h index 2079a3e20a9..7d0f97b486d 100644 --- a/engine/platform/PlatformEvent.h +++ b/engine/platform/PlatformEvent.h @@ -32,12 +32,6 @@ class PlatformEvent { public: enum Type { NoType = 0, - - // PlatformKeyboardEvent - KeyDown, - KeyUp, - RawKeyDown, - Char, }; enum Modifiers { diff --git a/engine/platform/PlatformKeyboardEvent.cpp b/engine/platform/PlatformKeyboardEvent.cpp deleted file mode 100644 index ac7acd1fc42..00000000000 --- a/engine/platform/PlatformKeyboardEvent.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. - * Copyright (C) 2008, 2009 Google Inc. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "sky/engine/config.h" -#include "sky/engine/platform/PlatformKeyboardEvent.h" - -#include "sky/engine/platform/NotImplemented.h" - -namespace blink { - -void PlatformKeyboardEvent::disambiguateKeyDownEvent(Type type) -{ - // Can only change type from KeyDown to RawKeyDown or Char, as we lack information for other conversions. - ASSERT(m_type == PlatformEvent::KeyDown); - ASSERT(type == PlatformEvent::RawKeyDown || type == PlatformEvent::Char); - m_type = type; - - if (type == RawKeyDown) { - m_text = String(); - m_unmodifiedText = String(); - } else { - m_keyIdentifier = String(); - m_windowsVirtualKeyCode = 0; - } -} - -bool PlatformKeyboardEvent::currentCapsLockState() -{ - notImplemented(); - return false; -} - -void PlatformKeyboardEvent::getCurrentModifierState(bool& shiftKey, bool& ctrlKey, bool& altKey, bool& metaKey) -{ - shiftKey = false; - ctrlKey = false; - altKey = false; - metaKey = false; - notImplemented(); -} - -} // namespace blink diff --git a/engine/platform/PlatformKeyboardEvent.h b/engine/platform/PlatformKeyboardEvent.h deleted file mode 100644 index ffb24b12ece..00000000000 --- a/engine/platform/PlatformKeyboardEvent.h +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. All rights reserved. - * Copyright (C) 2008 Collabora, Ltd. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef SKY_ENGINE_PLATFORM_PLATFORMKEYBOARDEVENT_H_ -#define SKY_ENGINE_PLATFORM_PLATFORMKEYBOARDEVENT_H_ - -#include "sky/engine/platform/PlatformEvent.h" -#include "sky/engine/platform/PlatformExport.h" -#include "sky/engine/wtf/text/WTFString.h" - -namespace blink { - -class PlatformKeyboardEvent : public PlatformEvent { - WTF_MAKE_FAST_ALLOCATED; -public: - PlatformKeyboardEvent() - : PlatformEvent(PlatformEvent::KeyDown) - , m_windowsVirtualKeyCode(0) - , m_nativeVirtualKeyCode(0) - , m_autoRepeat(false) - , m_isKeypad(false) - , m_isSystemKey(false) - { - } - - PlatformKeyboardEvent(Type type, const String& text, const String& unmodifiedText, const String& keyIdentifier, int windowsVirtualKeyCode, int nativeVirtualKeyCode, bool isAutoRepeat, bool isKeypad, bool isSystemKey, Modifiers modifiers, double timestamp) - : PlatformEvent(type, modifiers, timestamp) - , m_text(text) - , m_unmodifiedText(unmodifiedText) - , m_keyIdentifier(keyIdentifier) - , m_windowsVirtualKeyCode(windowsVirtualKeyCode) - , m_nativeVirtualKeyCode(nativeVirtualKeyCode) - , m_autoRepeat(isAutoRepeat) - , m_isKeypad(isKeypad) - , m_isSystemKey(isSystemKey) - { - } - - PLATFORM_EXPORT void disambiguateKeyDownEvent(Type); - - // Text as as generated by processing a virtual key code with a keyboard layout - // (in most cases, just a character code, but the layout can emit several - // characters in a single keypress event on some platforms). - // This may bear no resemblance to the ultimately inserted text if an input method - // processes the input. - // Will be null for KeyUp and RawKeyDown events. - String text() const { return m_text; } - - // Text that would have been generated by the keyboard if no modifiers were pressed - // (except for Shift); useful for shortcut (accelerator) key handling. - // Otherwise, same as text(). - String unmodifiedText() const { return m_unmodifiedText; } - - String keyIdentifier() const { return m_keyIdentifier; } - - // Most compatible Windows virtual key code associated with the event. - // Zero for Char events. - int windowsVirtualKeyCode() const { return m_windowsVirtualKeyCode; } - - int nativeVirtualKeyCode() const { return m_nativeVirtualKeyCode; } - - bool isAutoRepeat() const { return m_autoRepeat; } - bool isKeypad() const { return m_isKeypad; } - bool isSystemKey() const { return m_isSystemKey; } - - PLATFORM_EXPORT static bool currentCapsLockState(); - PLATFORM_EXPORT static void getCurrentModifierState(bool& shiftKey, bool& ctrlKey, bool& altKey, bool& metaKey); - -protected: - String m_text; - String m_unmodifiedText; - String m_keyIdentifier; - int m_windowsVirtualKeyCode; - int m_nativeVirtualKeyCode; - bool m_autoRepeat; - bool m_isKeypad; - bool m_isSystemKey; -}; - -} // namespace blink - -#endif // SKY_ENGINE_PLATFORM_PLATFORMKEYBOARDEVENT_H_ diff --git a/engine/platform/exported/WebInputEvent.cpp b/engine/platform/exported/WebInputEvent.cpp deleted file mode 100644 index 020c89b0764..00000000000 --- a/engine/platform/exported/WebInputEvent.cpp +++ /dev/null @@ -1,221 +0,0 @@ -/* - * Copyright (C) 2009 Google Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "sky/engine/config.h" -#include "sky/engine/public/platform/WebInputEvent.h" - -#include -#include "sky/engine/platform/KeyboardCodes.h" -#include "sky/engine/wtf/Assertions.h" -#include "sky/engine/wtf/StringExtras.h" - -namespace blink { - -struct SameSizeAsWebInputEvent { - int inputData[5]; -}; - -struct SameSizeAsWebKeyboardEvent : public SameSizeAsWebInputEvent { - int keyboardData[12]; -}; - -struct SameSizeAsWebGestureEvent : public SameSizeAsWebInputEvent { - int gestureData[9]; -}; - -COMPILE_ASSERT(sizeof(WebInputEvent) == sizeof(SameSizeAsWebInputEvent), WebInputEvent_has_gaps); -COMPILE_ASSERT(sizeof(WebKeyboardEvent) == sizeof(SameSizeAsWebKeyboardEvent), WebKeyboardEvent_has_gaps); -COMPILE_ASSERT(sizeof(WebGestureEvent) == sizeof(SameSizeAsWebGestureEvent), WebGestureEvent_has_gaps); - -static const char* staticKeyIdentifiers(unsigned short keyCode) -{ - switch (keyCode) { - case VKEY_MENU: - return "Alt"; - case VKEY_CONTROL: - return "Control"; - case VKEY_SHIFT: - return "Shift"; - case VKEY_CAPITAL: - return "CapsLock"; - case VKEY_LWIN: - case VKEY_RWIN: - return "Win"; - case VKEY_CLEAR: - return "Clear"; - case VKEY_DOWN: - return "Down"; - case VKEY_END: - return "End"; - case VKEY_RETURN: - return "Enter"; - case VKEY_EXECUTE: - return "Execute"; - case VKEY_F1: - return "F1"; - case VKEY_F2: - return "F2"; - case VKEY_F3: - return "F3"; - case VKEY_F4: - return "F4"; - case VKEY_F5: - return "F5"; - case VKEY_F6: - return "F6"; - case VKEY_F7: - return "F7"; - case VKEY_F8: - return "F8"; - case VKEY_F9: - return "F9"; - case VKEY_F10: - return "F10"; - case VKEY_F11: - return "F11"; - case VKEY_F12: - return "F12"; - case VKEY_F13: - return "F13"; - case VKEY_F14: - return "F14"; - case VKEY_F15: - return "F15"; - case VKEY_F16: - return "F16"; - case VKEY_F17: - return "F17"; - case VKEY_F18: - return "F18"; - case VKEY_F19: - return "F19"; - case VKEY_F20: - return "F20"; - case VKEY_F21: - return "F21"; - case VKEY_F22: - return "F22"; - case VKEY_F23: - return "F23"; - case VKEY_F24: - return "F24"; - case VKEY_HELP: - return "Help"; - case VKEY_HOME: - return "Home"; - case VKEY_INSERT: - return "Insert"; - case VKEY_LEFT: - return "Left"; - case VKEY_NEXT: - return "PageDown"; - case VKEY_PRIOR: - return "PageUp"; - case VKEY_PAUSE: - return "Pause"; - case VKEY_SNAPSHOT: - return "PrintScreen"; - case VKEY_RIGHT: - return "Right"; - case VKEY_SCROLL: - return "Scroll"; - case VKEY_SELECT: - return "Select"; - case VKEY_UP: - return "Up"; - case VKEY_DELETE: - return "U+007F"; // Standard says that DEL becomes U+007F. - case VKEY_MEDIA_NEXT_TRACK: - return "MediaNextTrack"; - case VKEY_MEDIA_PREV_TRACK: - return "MediaPreviousTrack"; - case VKEY_MEDIA_STOP: - return "MediaStop"; - case VKEY_MEDIA_PLAY_PAUSE: - return "MediaPlayPause"; - case VKEY_VOLUME_MUTE: - return "VolumeMute"; - case VKEY_VOLUME_DOWN: - return "VolumeDown"; - case VKEY_VOLUME_UP: - return "VolumeUp"; - default: - return 0; - } -} - -void WebKeyboardEvent::setKeyIdentifierFromWindowsKeyCode() -{ - const char* id = staticKeyIdentifiers(windowsKeyCode); - if (id) { - strncpy(keyIdentifier, id, sizeof(keyIdentifier) - 1); - keyIdentifier[sizeof(keyIdentifier) - 1] = '\0'; - } else - snprintf(keyIdentifier, sizeof(keyIdentifier), "U+%04X", toupper(windowsKeyCode)); -} - -// static -int WebKeyboardEvent::windowsKeyCodeWithoutLocation(int keycode) -{ - switch (keycode) { - case VK_LCONTROL: - case VK_RCONTROL: - return VK_CONTROL; - case VK_LSHIFT: - case VK_RSHIFT: - return VK_SHIFT; - case VK_LMENU: - case VK_RMENU: - return VK_MENU; - default: - return keycode; - } -} - -// static -int WebKeyboardEvent::locationModifiersFromWindowsKeyCode(int keycode) -{ - switch (keycode) { - case VK_LCONTROL: - case VK_LSHIFT: - case VK_LMENU: - case VK_LWIN: - return IsLeft; - case VK_RCONTROL: - case VK_RSHIFT: - case VK_RMENU: - case VK_RWIN: - return IsRight; - default: - return 0; - } -} - -} // namespace blink diff --git a/engine/public/platform/WebInputEvent.h b/engine/public/platform/WebInputEvent.h index 5ed33045f6c..bd468004d46 100644 --- a/engine/public/platform/WebInputEvent.h +++ b/engine/public/platform/WebInputEvent.h @@ -94,9 +94,8 @@ public: PointerTypeLast = PointerCancel, // WebKeyboardEvent - RawKeyDown, - KeyboardTypeFirst = RawKeyDown, KeyDown, + KeyboardTypeFirst = KeyDown, KeyUp, Char, KeyboardTypeLast = Char, @@ -231,16 +230,7 @@ public: class WebKeyboardEvent : public WebInputEvent { public: - // Caps on string lengths so we can make them static arrays and keep - // them PODs. - static const size_t textLengthCap = 4; - - // http://www.w3.org/TR/DOM-Level-3-Events/keyset.html lists the - // identifiers. The longest is 18 characters, so we round up to the - // next multiple of 4. - static const size_t keyIdentifierLengthCap = 20; - - // |windowsKeyCode| is the Windows key code associated with this key + // |key| is the Windows key code associated with this key // event. Sometimes it's direct from the event (i.e. on Windows), // sometimes it's via a mapping function. If you want a list, see // WebCore/platform/chromium/KeyboardCodes* . Note that this should @@ -248,50 +238,21 @@ public: // what is returned by the Windows API. For example, it should // store VK_SHIFT instead of VK_RSHIFT. The location information // should be stored in |modifiers|. - int windowsKeyCode; + int key; - // The actual key code genenerated by the platform. The DOM spec runs - // on Windows-equivalent codes (thus |windowsKeyCode| above) but it - // doesn't hurt to have this one around. - int nativeKeyCode; - - // This identifies whether this event was tagged by the system as being - // a "system key" event (see - // http://msdn.microsoft.com/en-us/library/ms646286(VS.85).aspx for - // details). Other platforms don't have this concept, but it's just - // easier to leave it always false than ifdef. - // See comment at the top of the file for why an int is used here. - bool isSystemKey; - - // |text| is the text generated by this keystroke. |unmodifiedText| is - // |text|, but unmodified by an concurrently-held modifiers (except - // shift). This is useful for working out shortcut keys. Linux and - // Windows guarantee one character per event. The Mac does not, but in - // reality that's all it ever gives. We're generous, and cap it a bit - // longer. - WebUChar text[textLengthCap]; - WebUChar unmodifiedText[textLengthCap]; - - // This is a string identifying the key pressed. - char keyIdentifier[keyIdentifierLengthCap]; + // |charCode| is the text generated by this keystroke. |unmodifiedCharCode| + // is |charCode|, but unmodified by an concurrently-held modifiers (except + // shift). This is useful for working out shortcut keys. + WebUChar charCode; + WebUChar unmodifiedCharCode; WebKeyboardEvent() : WebInputEvent(sizeof(WebKeyboardEvent)) - , windowsKeyCode(0) - , nativeKeyCode(0) - , isSystemKey(false) + , key(0) + , charCode(0) + , unmodifiedCharCode(0) { - memset(&text, 0, sizeof(text)); - memset(&unmodifiedText, 0, sizeof(unmodifiedText)); - memset(&keyIdentifier, 0, sizeof(keyIdentifier)); } - - // Sets keyIdentifier based on the value of windowsKeyCode. This is - // handy for generating synthetic keyboard events. - BLINK_EXPORT void setKeyIdentifierFromWindowsKeyCode(); - - static int windowsKeyCodeWithoutLocation(int keycode); - static int locationModifiersFromWindowsKeyCode(int keycode); }; // WebGestureEvent -------------------------------------------------------------- diff --git a/engine/public/web/WebFrameClient.h b/engine/public/web/WebFrameClient.h index 1721bf05ec0..6f4f12b5ebb 100644 --- a/engine/public/web/WebFrameClient.h +++ b/engine/public/web/WebFrameClient.h @@ -238,10 +238,6 @@ public: // Extensions3D.h in WebCore/platform/graphics). virtual void didLoseWebGLContext(WebLocalFrame*, int) { } - // FIXME: Remove this method once we have input routing in the browser - // process. See http://crbug.com/339659. - virtual void forwardInputEvent(const WebInputEvent*) { } - protected: virtual ~WebFrameClient() { } }; diff --git a/engine/web/BUILD.gn b/engine/web/BUILD.gn index 98093fe907b..8bb7aa33925 100644 --- a/engine/web/BUILD.gn +++ b/engine/web/BUILD.gn @@ -59,8 +59,6 @@ component("web") { "WebFontImpl.h", "WebFrame.cpp", "WebHitTestResult.cpp", - "WebInputEventConversion.cpp", - "WebInputEventConversion.h", "Sky.cpp", "WebLeakDetector.cpp", "WebLocalFrameImpl.cpp", diff --git a/engine/web/ChromeClientImpl.cpp b/engine/web/ChromeClientImpl.cpp index 28c3319093f..92d024b6901 100644 --- a/engine/web/ChromeClientImpl.cpp +++ b/engine/web/ChromeClientImpl.cpp @@ -61,7 +61,6 @@ #include "sky/engine/public/web/WebTextDirection.h" #include "sky/engine/public/web/WebTouchAction.h" #include "sky/engine/public/web/WebViewClient.h" -#include "sky/engine/web/WebInputEventConversion.h" #include "sky/engine/web/WebLocalFrameImpl.h" #include "sky/engine/web/WebSettingsImpl.h" #include "sky/engine/web/WebViewImpl.h" @@ -288,20 +287,4 @@ void ChromeClientImpl::showImeIfNeeded() m_webView->client()->showImeIfNeeded(); } -// FIXME: Remove this code once we have input routing in the browser -// process. See http://crbug.com/339659. -void ChromeClientImpl::forwardInputEvent( - Frame* frame, Event* event) -{ - WebLocalFrameImpl* webFrame = WebLocalFrameImpl::fromFrame(toLocalFrame(frame)); - - // This is only called when we have out-of-process iframes, which - // need to forward input events across processes. - // FIXME: Add a check for out-of-process iframes enabled. - if (event->isKeyboardEvent()) { - WebKeyboardEventBuilder webEvent(*static_cast(event)); - webFrame->client()->forwardInputEvent(&webEvent); - } -} - } // namespace blink diff --git a/engine/web/ChromeClientImpl.h b/engine/web/ChromeClientImpl.h index 019e968bfa8..bf791f189d8 100644 --- a/engine/web/ChromeClientImpl.h +++ b/engine/web/ChromeClientImpl.h @@ -87,10 +87,6 @@ public: // ChromeClientImpl: void setNewWindowNavigationPolicy(WebNavigationPolicy); - // FIXME: Remove this method once we have input routing in the browser - // process. See http://crbug.com/339659. - virtual void forwardInputEvent(Frame*, Event*) override; - virtual void willSetInputMethodState() override; virtual void didUpdateTextOfFocusedElementByNonUserInput() override; virtual void showImeIfNeeded() override; diff --git a/engine/web/WebInputEventConversion.cpp b/engine/web/WebInputEventConversion.cpp deleted file mode 100644 index 100dd48714d..00000000000 --- a/engine/web/WebInputEventConversion.cpp +++ /dev/null @@ -1,238 +0,0 @@ -/* - * Copyright (C) 2009 Google Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "sky/engine/config.h" -#include "sky/engine/web/WebInputEventConversion.h" - -#include "sky/engine/core/events/KeyboardEvent.h" -#include "sky/engine/core/frame/FrameHost.h" -#include "sky/engine/core/frame/FrameView.h" -#include "sky/engine/core/page/Page.h" -#include "sky/engine/core/rendering/RenderObject.h" -#include "sky/engine/platform/KeyboardCodes.h" -#include "sky/engine/platform/Widget.h" - -namespace blink { - -static const double millisPerSecond = 1000.0; - -// MakePlatformKeyboardEvent -------------------------------------------------- - -inline PlatformEvent::Type toPlatformKeyboardEventType(WebInputEvent::Type type) -{ - switch (type) { - case WebInputEvent::KeyUp: - return PlatformEvent::KeyUp; - case WebInputEvent::KeyDown: - return PlatformEvent::KeyDown; - case WebInputEvent::RawKeyDown: - return PlatformEvent::RawKeyDown; - case WebInputEvent::Char: - return PlatformEvent::Char; - default: - ASSERT_NOT_REACHED(); - } - return PlatformEvent::KeyDown; -} - -PlatformKeyboardEventBuilder::PlatformKeyboardEventBuilder(const WebKeyboardEvent& e) -{ - m_type = toPlatformKeyboardEventType(e.type); - m_text = String(e.text); - m_unmodifiedText = String(e.unmodifiedText); - m_keyIdentifier = String(e.keyIdentifier); - m_autoRepeat = (e.modifiers & WebInputEvent::IsAutoRepeat); - m_nativeVirtualKeyCode = e.nativeKeyCode; - m_isKeypad = (e.modifiers & WebInputEvent::IsKeyPad); - m_isSystemKey = e.isSystemKey; - - m_modifiers = 0; - if (e.modifiers & WebInputEvent::ShiftKey) - m_modifiers |= PlatformEvent::ShiftKey; - if (e.modifiers & WebInputEvent::ControlKey) - m_modifiers |= PlatformEvent::CtrlKey; - if (e.modifiers & WebInputEvent::AltKey) - m_modifiers |= PlatformEvent::AltKey; - if (e.modifiers & WebInputEvent::MetaKey) - m_modifiers |= PlatformEvent::MetaKey; - - // FIXME: PlatformKeyboardEvents expect a locational version of the keycode (e.g. VK_LSHIFT - // instead of VK_SHIFT). This should be changed so the location/keycode are stored separately, - // as in other places in the code. - m_windowsVirtualKeyCode = e.windowsKeyCode; - if (e.windowsKeyCode == VK_SHIFT) { - if (e.modifiers & WebInputEvent::IsLeft) - m_windowsVirtualKeyCode = VK_LSHIFT; - else if (e.modifiers & WebInputEvent::IsRight) - m_windowsVirtualKeyCode = VK_RSHIFT; - } else if (e.windowsKeyCode == VK_CONTROL) { - if (e.modifiers & WebInputEvent::IsLeft) - m_windowsVirtualKeyCode = VK_LCONTROL; - else if (e.modifiers & WebInputEvent::IsRight) - m_windowsVirtualKeyCode = VK_RCONTROL; - } else if (e.windowsKeyCode == VK_MENU) { - if (e.modifiers & WebInputEvent::IsLeft) - m_windowsVirtualKeyCode = VK_LMENU; - else if (e.modifiers & WebInputEvent::IsRight) - m_windowsVirtualKeyCode = VK_RMENU; - } - -} - -void PlatformKeyboardEventBuilder::setKeyType(Type type) -{ - // According to the behavior of Webkit in Windows platform, - // we need to convert KeyDown to RawKeydown and Char events - // See WebKit/WebKit/Win/WebView.cpp - ASSERT(m_type == KeyDown); - ASSERT(type == RawKeyDown || type == Char); - m_type = type; - - if (type == RawKeyDown) { - m_text = String(); - m_unmodifiedText = String(); - } else { - m_keyIdentifier = String(); - m_windowsVirtualKeyCode = 0; - } -} - -// Please refer to bug http://b/issue?id=961192, which talks about Webkit -// keyboard event handling changes. It also mentions the list of keys -// which don't have associated character events. -bool PlatformKeyboardEventBuilder::isCharacterKey() const -{ - switch (windowsVirtualKeyCode()) { - case VKEY_BACK: - case VKEY_ESCAPE: - return false; - } - return true; -} - -static int getWebInputModifiers(const UIEventWithKeyState& event) -{ - int modifiers = 0; - if (event.ctrlKey()) - modifiers |= WebInputEvent::ControlKey; - if (event.shiftKey()) - modifiers |= WebInputEvent::ShiftKey; - if (event.altKey()) - modifiers |= WebInputEvent::AltKey; - if (event.metaKey()) - modifiers |= WebInputEvent::MetaKey; - return modifiers; -} - -WebKeyboardEventBuilder::WebKeyboardEventBuilder(const KeyboardEvent& event) -{ - if (event.type() == EventTypeNames::keydown) - type = KeyDown; - else if (event.type() == EventTypeNames::keyup) - type = WebInputEvent::KeyUp; - else if (event.type() == EventTypeNames::keypress) - type = WebInputEvent::Char; - else - return; // Skip all other keyboard events. - - modifiers = getWebInputModifiers(event); - if (event.location() == KeyboardEvent::DOM_KEY_LOCATION_NUMPAD) - modifiers |= WebInputEvent::IsKeyPad; - else if (event.location() == KeyboardEvent::DOM_KEY_LOCATION_LEFT) - modifiers |= WebInputEvent::IsLeft; - else if (event.location() == KeyboardEvent::DOM_KEY_LOCATION_RIGHT) - modifiers |= WebInputEvent::IsRight; - - timeStampSeconds = event.timeStamp() / millisPerSecond; - windowsKeyCode = event.keyCode(); - - // The platform keyevent does not exist if the event was created using - // initKeyboardEvent. - if (!event.keyEvent()) - return; - nativeKeyCode = event.keyEvent()->nativeVirtualKeyCode(); - unsigned numberOfCharacters = std::min(event.keyEvent()->text().length(), static_cast(textLengthCap)); - for (unsigned i = 0; i < numberOfCharacters; ++i) { - text[i] = event.keyEvent()->text()[i]; - unmodifiedText[i] = event.keyEvent()->unmodifiedText()[i]; - } - memcpy(keyIdentifier, event.keyIdentifier().ascii().data(), event.keyIdentifier().length()); -} - -WebInputEvent::Type toWebKeyboardEventType(PlatformEvent::Type type) -{ - switch (type) { - case PlatformEvent::KeyUp: - return WebInputEvent::KeyUp; - case PlatformEvent::KeyDown: - return WebInputEvent::KeyDown; - case PlatformEvent::RawKeyDown: - return WebInputEvent::RawKeyDown; - case PlatformEvent::Char: - return WebInputEvent::Char; - default: - return WebInputEvent::Undefined; - } -} - -int toWebKeyboardEventModifiers(int modifiers) -{ - int newModifiers = 0; - if (modifiers & PlatformEvent::ShiftKey) - newModifiers |= WebInputEvent::ShiftKey; - if (modifiers & PlatformEvent::CtrlKey) - newModifiers |= WebInputEvent::ControlKey; - if (modifiers & PlatformEvent::AltKey) - newModifiers |= WebInputEvent::AltKey; - if (modifiers & PlatformEvent::MetaKey) - newModifiers |= WebInputEvent::MetaKey; - return newModifiers; -} - -WebKeyboardEventBuilder::WebKeyboardEventBuilder(const PlatformKeyboardEvent& event) -{ - type = toWebKeyboardEventType(event.type()); - modifiers = toWebKeyboardEventModifiers(event.modifiers()); - if (event.isAutoRepeat()) - modifiers |= WebInputEvent::IsAutoRepeat; - if (event.isKeypad()) - modifiers |= WebInputEvent::IsKeyPad; - isSystemKey = event.isSystemKey(); - nativeKeyCode = event.nativeVirtualKeyCode(); - - windowsKeyCode = windowsKeyCodeWithoutLocation(event.windowsVirtualKeyCode()); - modifiers |= locationModifiersFromWindowsKeyCode(event.windowsVirtualKeyCode()); - - event.text().copyTo(text, 0, textLengthCap); - event.unmodifiedText().copyTo(unmodifiedText, 0, textLengthCap); - memcpy(keyIdentifier, event.keyIdentifier().ascii().data(), std::min(static_cast(keyIdentifierLengthCap), event.keyIdentifier().length())); -} - -} // namespace blink diff --git a/engine/web/WebInputEventConversion.h b/engine/web/WebInputEventConversion.h deleted file mode 100644 index 53572d217f5..00000000000 --- a/engine/web/WebInputEventConversion.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (C) 2009 Google Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef SKY_ENGINE_WEB_WEBINPUTEVENTCONVERSION_H_ -#define SKY_ENGINE_WEB_WEBINPUTEVENTCONVERSION_H_ - -#include "sky/engine/platform/PlatformKeyboardEvent.h" -#include "sky/engine/public/platform/WebInputEvent.h" - -namespace blink { - -class KeyboardEvent; -class RenderObject; -class WebKeyboardEvent; -class Widget; - -// These classes are used to convert from WebInputEvent subclasses to -// corresponding WebCore events. - -class PlatformKeyboardEventBuilder : public PlatformKeyboardEvent { -public: - PlatformKeyboardEventBuilder(const WebKeyboardEvent&); - void setKeyType(Type); - bool isCharacterKey() const; -}; - -// Converts a KeyboardEvent or PlatformKeyboardEvent to a -// corresponding WebKeyboardEvent. -// NOTE: For KeyboardEvent, this is only implemented for keydown, -// keyup, and keypress. If the event mapping fails, the event type will be set -// to Undefined. -class WebKeyboardEventBuilder : public WebKeyboardEvent { -public: - WebKeyboardEventBuilder(const KeyboardEvent&); - WebKeyboardEventBuilder(const PlatformKeyboardEvent&); -}; - -} // namespace blink - -#endif // SKY_ENGINE_WEB_WEBINPUTEVENTCONVERSION_H_ diff --git a/engine/web/WebViewImpl.cpp b/engine/web/WebViewImpl.cpp index df55b7abb53..6a836fd01c9 100644 --- a/engine/web/WebViewImpl.cpp +++ b/engine/web/WebViewImpl.cpp @@ -64,7 +64,6 @@ #include "sky/engine/platform/KeyboardCodes.h" #include "sky/engine/platform/Logging.h" #include "sky/engine/platform/NotImplemented.h" -#include "sky/engine/platform/PlatformKeyboardEvent.h" #include "sky/engine/platform/TraceEvent.h" #include "sky/engine/platform/fonts/FontCache.h" #include "sky/engine/platform/graphics/Color.h" @@ -86,7 +85,6 @@ #include "sky/engine/public/web/WebTextInputInfo.h" #include "sky/engine/public/web/WebViewClient.h" #include "sky/engine/web/CompositionUnderlineVectorBuilder.h" -#include "sky/engine/web/WebInputEventConversion.h" #include "sky/engine/web/WebLocalFrameImpl.h" #include "sky/engine/web/WebSettingsImpl.h" #include "sky/engine/wtf/CurrentTime.h" @@ -191,168 +189,6 @@ void WebViewImpl::acceptLanguagesChanged() page()->acceptLanguagesChanged(); } -bool WebViewImpl::handleKeyEvent(const WebKeyboardEvent& event) -{ - ASSERT((event.type == WebInputEvent::RawKeyDown) - || (event.type == WebInputEvent::KeyDown) - || (event.type == WebInputEvent::KeyUp)); - - // Please refer to the comments explaining the m_suppressNextKeypressEvent - // member. - // The m_suppressNextKeypressEvent is set if the KeyDown is handled by - // Webkit. A keyDown event is typically associated with a keyPress(char) - // event and a keyUp event. We reset this flag here as this is a new keyDown - // event. - m_suppressNextKeypressEvent = false; - - RefPtr focusedFrame = focusedCoreFrame(); - if (!focusedFrame) - return false; - - RefPtr frame = focusedFrame.get(); - - PlatformKeyboardEventBuilder evt(event); - - if (frame->eventHandler().keyEvent(evt)) { - if (WebInputEvent::RawKeyDown == event.type) { - // Suppress the next keypress event unless the focused node is a plug-in node. - // (Flash needs these keypress events to handle non-US keyboards.) - m_suppressNextKeypressEvent = true; - } - return true; - } - - return keyEventDefault(event); -} - -bool WebViewImpl::handleCharEvent(const WebKeyboardEvent& event) -{ - ASSERT(event.type == WebInputEvent::Char); - - // Please refer to the comments explaining the m_suppressNextKeypressEvent - // member. The m_suppressNextKeypressEvent is set if the KeyDown is - // handled by Webkit. A keyDown event is typically associated with a - // keyPress(char) event and a keyUp event. We reset this flag here as it - // only applies to the current keyPress event. - bool suppress = m_suppressNextKeypressEvent; - m_suppressNextKeypressEvent = false; - - LocalFrame* frame = focusedCoreFrame(); - if (!frame) - return suppress; - - EventHandler& handler = frame->eventHandler(); - - PlatformKeyboardEventBuilder evt(event); - if (!evt.isCharacterKey()) - return true; - - // Safari 3.1 does not pass off windows system key messages (WM_SYSCHAR) to - // the eventHandler::keyEvent. We mimic this behavior on all platforms since - // for now we are converting other platform's key events to windows key - // events. - if (evt.isSystemKey()) - return false; - - if (!suppress && !handler.keyEvent(evt)) - return keyEventDefault(event); - - return true; -} - -bool WebViewImpl::keyEventDefault(const WebKeyboardEvent& event) -{ - LocalFrame* frame = focusedCoreFrame(); - if (!frame) - return false; - - switch (event.type) { - case WebInputEvent::Char: - if (event.windowsKeyCode == VKEY_SPACE) { - int keyCode = ((event.modifiers & WebInputEvent::ShiftKey) ? VKEY_PRIOR : VKEY_NEXT); - return scrollViewWithKeyboard(keyCode, event.modifiers); - } - break; - case WebInputEvent::RawKeyDown: - if (event.modifiers == WebInputEvent::ControlKey) { - switch (event.windowsKeyCode) { - // Match FF behavior in the sense that Ctrl+home/end are the only Ctrl - // key combinations which affect scrolling. Safari is buggy in the - // sense that it scrolls the page for all Ctrl+scrolling key - // combinations. For e.g. Ctrl+pgup/pgdn/up/down, etc. - case VKEY_HOME: - case VKEY_END: - break; - default: - return false; - } - } - if (!event.isSystemKey && !(event.modifiers & WebInputEvent::ShiftKey)) - return scrollViewWithKeyboard(event.windowsKeyCode, event.modifiers); - break; - default: - break; - } - return false; -} - -bool WebViewImpl::scrollViewWithKeyboard(int keyCode, int modifiers) -{ - ScrollDirection scrollDirection; - ScrollGranularity scrollGranularity; - if (!mapKeyCodeForScroll(keyCode, &scrollDirection, &scrollGranularity)) - return false; - - if (LocalFrame* frame = focusedCoreFrame()) - return frame->eventHandler().bubblingScroll(scrollDirection, scrollGranularity); - return false; -} - -bool WebViewImpl::mapKeyCodeForScroll( - int keyCode, - ScrollDirection* scrollDirection, - ScrollGranularity* scrollGranularity) -{ - switch (keyCode) { - case VKEY_LEFT: - *scrollDirection = ScrollLeft; - *scrollGranularity = ScrollByLine; - break; - case VKEY_RIGHT: - *scrollDirection = ScrollRight; - *scrollGranularity = ScrollByLine; - break; - case VKEY_UP: - *scrollDirection = ScrollUp; - *scrollGranularity = ScrollByLine; - break; - case VKEY_DOWN: - *scrollDirection = ScrollDown; - *scrollGranularity = ScrollByLine; - break; - case VKEY_HOME: - *scrollDirection = ScrollUp; - *scrollGranularity = ScrollByDocument; - break; - case VKEY_END: - *scrollDirection = ScrollDown; - *scrollGranularity = ScrollByDocument; - break; - case VKEY_PRIOR: // page up - *scrollDirection = ScrollUp; - *scrollGranularity = ScrollByPage; - break; - case VKEY_NEXT: // page down - *scrollDirection = ScrollDown; - *scrollGranularity = ScrollByPage; - break; - default: - return false; - } - - return true; -} - LocalFrame* WebViewImpl::focusedCoreFrame() const { return m_page ? m_page->focusController().focusedOrMainFrame() : 0; @@ -501,16 +337,12 @@ bool WebViewImpl::handleInputEvent(const WebInputEvent& inputEvent) return m_page->mainFrame()->newEventHandler().handleGestureEvent(event); } - switch (inputEvent.type) { - case WebInputEvent::RawKeyDown: - case WebInputEvent::KeyDown: - case WebInputEvent::KeyUp: - return handleKeyEvent(static_cast(inputEvent)); - case WebInputEvent::Char: - return handleCharEvent(static_cast(inputEvent)); - default: - return false; + if (WebInputEvent::isKeyboardEventType(inputEvent.type)) { + const WebKeyboardEvent& event = static_cast(inputEvent); + return m_page->mainFrame()->newEventHandler().handleKeyboardEvent(event); } + + return false; } void WebViewImpl::setFocus(bool enable) diff --git a/engine/web/WebViewImpl.h b/engine/web/WebViewImpl.h index c949565c0aa..ba627f6307e 100644 --- a/engine/web/WebViewImpl.h +++ b/engine/web/WebViewImpl.h @@ -172,12 +172,6 @@ public: virtual void setVisibilityState(WebPageVisibilityState, bool) override; - // Returns true if the event leads to scrolling. - static bool mapKeyCodeForScroll( - int keyCode, - ScrollDirection*, - ScrollGranularity*); - // Exposed for the purpose of overriding device metrics. void sendResizeEventAndRepaint(); @@ -214,14 +208,8 @@ private: WebString inputModeOfFocusedElement(); - // Returns true if the event was actually processed. - bool keyEventDefault(const WebKeyboardEvent&); - bool confirmComposition(const WebString& text, ConfirmCompositionBehavior); - // Returns true if the view was scrolled. - bool scrollViewWithKeyboard(int keyCode, int modifiers); - // Converts |pos| from window coordinates to contents coordinates and gets // the HitTestResult for it. HitTestResult hitTestResultForWindowPos(const IntPoint&); @@ -229,10 +217,6 @@ private: void doComposite(); void reallocateRenderer(); - bool handleCharEvent(const WebKeyboardEvent&); - bool handleGestureEvent(const WebGestureEvent&); - bool handleKeyEvent(const WebKeyboardEvent&); - InputMethodContext* inputMethodContext(); WebViewClient* m_client; // Can be 0 (e.g. unittests, shared workers, etc.) diff --git a/framework/sky-input.sky b/framework/sky-input.sky index 9ebbaedbf60..5f1130bd047 100644 --- a/framework/sky-input.sky +++ b/framework/sky-input.sky @@ -57,7 +57,7 @@ module.exports = class extends SkyElement { } handleKeyDown(event) { // TODO(abarth): You can still get newlines if the user pastes them. - if (event.keyCode == 0xD) + if (event.key == 0xD) event.preventDefault(); } handleFocus(event) { diff --git a/tests/services/event-sender.sky b/tests/services/event-sender.sky index 99472060aaf..27965c98147 100644 --- a/tests/services/event-sender.sky +++ b/tests/services/event-sender.sky @@ -10,10 +10,10 @@ describe('Sky event sender', function() { it('should be able to send events', function(done) { var sky = document.querySelector('sky') - sky.focus(); sky.addEventListener('keypress', function(event) { assert.equal(event.type, 'keypress'); - assert.equal(event.keyCode, 0x41); + assert.equal(event.key, 0); + assert.equal(event.charCode, 0x41); done(); }); @@ -22,7 +22,7 @@ describe('Sky event sender', function() { testHarness.dispatchInputEvent(new events.Event({ action: constants.EventType.KEY_PRESSED, key_data: new events.KeyData({ - native_key_code: 0x41, + windows_key_code: 0x41, text: 0x41, unmodified_text: 0x41, is_char: true, diff --git a/viewer/converters/input_event_types.cc b/viewer/converters/input_event_types.cc index 91748f2ce81..d63d71b7049 100644 --- a/viewer/converters/input_event_types.cc +++ b/viewer/converters/input_event_types.cc @@ -182,7 +182,7 @@ scoped_ptr BuildWebKeyboardEvent( switch (event->action) { case mojo::EVENT_TYPE_KEY_PRESSED: web_event->type = event->key_data->is_char ? blink::WebInputEvent::Char : - blink::WebInputEvent::RawKeyDown; + blink::WebInputEvent::KeyDown; break; case mojo::EVENT_TYPE_KEY_RELEASED: web_event->type = blink::WebInputEvent::KeyUp; @@ -191,15 +191,10 @@ scoped_ptr BuildWebKeyboardEvent( NOTREACHED(); } - if (web_event->modifiers & blink::WebInputEvent::AltKey) - web_event->isSystemKey = true; + web_event->key = event->key_data->windows_key_code; + web_event->charCode = event->key_data->text; + web_event->unmodifiedCharCode = event->key_data->unmodified_text; - web_event->windowsKeyCode = event->key_data->windows_key_code; - web_event->nativeKeyCode = event->key_data->native_key_code; - web_event->text[0] = event->key_data->text; - web_event->unmodifiedText[0] = event->key_data->unmodified_text; - - web_event->setKeyIdentifierFromWindowsKeyCode(); return web_event.Pass(); }