Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2001 Peter Kelly (pmk@post.com) |
| 3 | * Copyright (C) 2001 Tobias Anton (anton@stud.fbi.fh-darmstadt.de) |
| 4 | * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) |
| 5 | * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. |
| 6 | * |
| 7 | * This library is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU Library General Public |
| 9 | * License as published by the Free Software Foundation; either |
| 10 | * version 2 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * This library is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * Library General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Library General Public License |
| 18 | * along with this library; see the file COPYING.LIB. If not, write to |
| 19 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 20 | * Boston, MA 02110-1301, USA. |
| 21 | * |
| 22 | */ |
| 23 | |
| 24 | #ifndef KeyboardEvent_h |
| 25 | #define KeyboardEvent_h |
| 26 | |
| 27 | #include "core/dom/EventDispatchMediator.h" |
| 28 | #include "core/dom/UIEventWithKeyState.h" |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 29 | |
| 30 | namespace WebCore { |
| 31 | |
| 32 | class EventDispatcher; |
| 33 | class Node; |
| 34 | class PlatformKeyboardEvent; |
| 35 | |
| 36 | struct KeyboardEventInit : public UIEventInit { |
| 37 | KeyboardEventInit(); |
| 38 | |
| 39 | String keyIdentifier; |
Torne (Richard Coles) | f5e4ad5 | 2013-08-05 13:57:57 +0100 | [diff] [blame] | 40 | unsigned location; |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 41 | bool ctrlKey; |
| 42 | bool altKey; |
| 43 | bool shiftKey; |
| 44 | bool metaKey; |
| 45 | }; |
| 46 | |
| 47 | class KeyboardEvent : public UIEventWithKeyState { |
| 48 | public: |
| 49 | enum KeyLocationCode { |
Torne (Richard Coles) | f5e4ad5 | 2013-08-05 13:57:57 +0100 | [diff] [blame] | 50 | DOM_KEY_LOCATION_STANDARD = 0x00, |
| 51 | DOM_KEY_LOCATION_LEFT = 0x01, |
| 52 | DOM_KEY_LOCATION_RIGHT = 0x02, |
| 53 | DOM_KEY_LOCATION_NUMPAD = 0x03 |
| 54 | // FIXME: The following values are not supported yet (crbug.com/265446) |
| 55 | // DOM_KEY_LOCATION_MOBILE = 0x04, |
| 56 | // DOM_KEY_LOCATION_JOYSTICK = 0x05 |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 57 | }; |
Ben Murdoch | 02772c6 | 2013-07-26 10:21:05 +0100 | [diff] [blame] | 58 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 59 | static PassRefPtr<KeyboardEvent> create() |
| 60 | { |
| 61 | return adoptRef(new KeyboardEvent); |
| 62 | } |
| 63 | |
| 64 | static PassRefPtr<KeyboardEvent> create(const PlatformKeyboardEvent& platformEvent, AbstractView* view) |
| 65 | { |
| 66 | return adoptRef(new KeyboardEvent(platformEvent, view)); |
| 67 | } |
| 68 | |
| 69 | static PassRefPtr<KeyboardEvent> create(const AtomicString& type, const KeyboardEventInit& initializer) |
| 70 | { |
| 71 | return adoptRef(new KeyboardEvent(type, initializer)); |
| 72 | } |
| 73 | |
| 74 | static PassRefPtr<KeyboardEvent> create(const AtomicString& type, bool canBubble, bool cancelable, AbstractView* view, |
Torne (Richard Coles) | f5e4ad5 | 2013-08-05 13:57:57 +0100 | [diff] [blame] | 75 | const String& keyIdentifier, unsigned location, |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 76 | bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, bool altGraphKey) |
| 77 | { |
Torne (Richard Coles) | f5e4ad5 | 2013-08-05 13:57:57 +0100 | [diff] [blame] | 78 | return adoptRef(new KeyboardEvent(type, canBubble, cancelable, view, keyIdentifier, location, |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 79 | ctrlKey, altKey, shiftKey, metaKey, altGraphKey)); |
| 80 | } |
| 81 | |
| 82 | virtual ~KeyboardEvent(); |
Ben Murdoch | 02772c6 | 2013-07-26 10:21:05 +0100 | [diff] [blame] | 83 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 84 | void initKeyboardEvent(const AtomicString& type, bool canBubble, bool cancelable, AbstractView*, |
Torne (Richard Coles) | f5e4ad5 | 2013-08-05 13:57:57 +0100 | [diff] [blame] | 85 | const String& keyIdentifier, unsigned location, |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 86 | bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, bool altGraphKey = false); |
Ben Murdoch | 02772c6 | 2013-07-26 10:21:05 +0100 | [diff] [blame] | 87 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 88 | const String& keyIdentifier() const { return m_keyIdentifier; } |
Torne (Richard Coles) | f5e4ad5 | 2013-08-05 13:57:57 +0100 | [diff] [blame] | 89 | unsigned location() const { return m_location; } |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 90 | |
| 91 | bool getModifierState(const String& keyIdentifier) const; |
| 92 | |
| 93 | bool altGraphKey() const { return m_altGraphKey; } |
Ben Murdoch | 02772c6 | 2013-07-26 10:21:05 +0100 | [diff] [blame] | 94 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 95 | const PlatformKeyboardEvent* keyEvent() const { return m_keyEvent.get(); } |
| 96 | |
| 97 | int keyCode() const; // key code for keydown and keyup, character for keypress |
| 98 | int charCode() const; // character code for keypress, 0 for keydown and keyup |
| 99 | |
| 100 | virtual const AtomicString& interfaceName() const; |
| 101 | virtual bool isKeyboardEvent() const; |
| 102 | virtual int which() const; |
| 103 | |
| 104 | private: |
| 105 | KeyboardEvent(); |
| 106 | KeyboardEvent(const PlatformKeyboardEvent&, AbstractView*); |
| 107 | KeyboardEvent(const AtomicString&, const KeyboardEventInit&); |
| 108 | KeyboardEvent(const AtomicString& type, bool canBubble, bool cancelable, AbstractView*, |
Torne (Richard Coles) | f5e4ad5 | 2013-08-05 13:57:57 +0100 | [diff] [blame] | 109 | const String& keyIdentifier, unsigned location, |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 110 | bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, bool altGraphKey); |
| 111 | |
| 112 | OwnPtr<PlatformKeyboardEvent> m_keyEvent; |
| 113 | String m_keyIdentifier; |
Torne (Richard Coles) | f5e4ad5 | 2013-08-05 13:57:57 +0100 | [diff] [blame] | 114 | unsigned m_location; |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 115 | bool m_altGraphKey : 1; |
| 116 | }; |
| 117 | |
| 118 | KeyboardEvent* findKeyboardEvent(Event*); |
| 119 | |
| 120 | class KeyboardEventDispatchMediator : public EventDispatchMediator { |
| 121 | public: |
| 122 | static PassRefPtr<KeyboardEventDispatchMediator> create(PassRefPtr<KeyboardEvent>); |
| 123 | private: |
| 124 | explicit KeyboardEventDispatchMediator(PassRefPtr<KeyboardEvent>); |
| 125 | virtual bool dispatchEvent(EventDispatcher*) const OVERRIDE; |
| 126 | }; |
| 127 | |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 128 | inline KeyboardEvent* toKeyboardEvent(Event* event) |
| 129 | { |
| 130 | ASSERT_WITH_SECURITY_IMPLICATION(!event || event->isKeyboardEvent()); |
| 131 | return static_cast<KeyboardEvent*>(event); |
| 132 | } |
| 133 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 134 | } // namespace WebCore |
| 135 | |
| 136 | #endif // KeyboardEvent_h |