Revert of Implement timers by posting delayed tasks (patchset #21 id:400001 of https...
[chromium-blink-merge.git] / third_party / WebKit / Source / core / events / KeyboardEvent.h
blobbbe262322d4756d6b72b0c6b740063ecc9ffa7df
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.
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.
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.
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.
24 #ifndef KeyboardEvent_h
25 #define KeyboardEvent_h
27 #include "core/CoreExport.h"
28 #include "core/events/EventDispatchMediator.h"
29 #include "core/events/KeyboardEventInit.h"
30 #include "core/events/UIEventWithKeyState.h"
32 namespace blink {
34 class EventDispatcher;
35 class PlatformKeyboardEvent;
37 class CORE_EXPORT KeyboardEvent final : public UIEventWithKeyState {
38 DEFINE_WRAPPERTYPEINFO();
39 public:
40 enum KeyLocationCode {
41 DOM_KEY_LOCATION_STANDARD = 0x00,
42 DOM_KEY_LOCATION_LEFT = 0x01,
43 DOM_KEY_LOCATION_RIGHT = 0x02,
44 DOM_KEY_LOCATION_NUMPAD = 0x03
47 static PassRefPtrWillBeRawPtr<KeyboardEvent> create()
49 return adoptRefWillBeNoop(new KeyboardEvent);
52 static PassRefPtrWillBeRawPtr<KeyboardEvent> create(const PlatformKeyboardEvent& platformEvent, AbstractView* view)
54 return adoptRefWillBeNoop(new KeyboardEvent(platformEvent, view));
57 static PassRefPtrWillBeRawPtr<KeyboardEvent> create(ScriptState*, const AtomicString& type, const KeyboardEventInit&);
59 static PassRefPtrWillBeRawPtr<KeyboardEvent> create(const AtomicString& type, bool canBubble, bool cancelable, AbstractView* view,
60 const String& keyIdentifier, const String& code, const String& key, unsigned location,
61 bool ctrlKey, bool altKey, bool shiftKey, bool metaKey)
63 return adoptRefWillBeNoop(new KeyboardEvent(type, canBubble, cancelable, view, keyIdentifier, code, key, location,
64 ctrlKey, altKey, shiftKey, metaKey));
67 virtual ~KeyboardEvent();
69 void initKeyboardEvent(ScriptState*, const AtomicString& type, bool canBubble, bool cancelable, AbstractView*,
70 const String& keyIdentifier, unsigned location,
71 bool ctrlKey, bool altKey, bool shiftKey, bool metaKey);
73 const String& keyIdentifier() const { return m_keyIdentifier; }
74 const String& code() const { return m_code; }
75 const String& key() const { return m_key; }
77 unsigned location() const { return m_location; }
79 bool getModifierState(const String& keyIdentifier) const;
81 const PlatformKeyboardEvent* keyEvent() const { return m_keyEvent.get(); }
83 virtual int keyCode() const override; // key code for keydown and keyup, character for keypress
84 virtual int charCode() const override; // character code for keypress, 0 for keydown and keyup
85 bool repeat() const { return m_isAutoRepeat; }
87 virtual const AtomicString& interfaceName() const override;
88 virtual bool isKeyboardEvent() const override;
89 virtual int which() const override;
91 DECLARE_VIRTUAL_TRACE();
93 private:
94 KeyboardEvent();
95 KeyboardEvent(const PlatformKeyboardEvent&, AbstractView*);
96 KeyboardEvent(const AtomicString&, const KeyboardEventInit&);
97 KeyboardEvent(const AtomicString& type, bool canBubble, bool cancelable, AbstractView*,
98 const String& keyIdentifier, const String& code, const String& key, unsigned location,
99 bool ctrlKey, bool altKey, bool shiftKey, bool metaKey);
101 OwnPtr<PlatformKeyboardEvent> m_keyEvent;
102 String m_keyIdentifier;
103 String m_code;
104 String m_key;
105 unsigned m_location;
106 bool m_isAutoRepeat : 1;
109 class KeyboardEventDispatchMediator : public EventDispatchMediator {
110 public:
111 static PassRefPtrWillBeRawPtr<KeyboardEventDispatchMediator> create(PassRefPtrWillBeRawPtr<KeyboardEvent>);
112 private:
113 explicit KeyboardEventDispatchMediator(PassRefPtrWillBeRawPtr<KeyboardEvent>);
114 virtual bool dispatchEvent(EventDispatcher&) const override;
117 DEFINE_EVENT_TYPE_CASTS(KeyboardEvent);
119 } // namespace blink
121 #endif // KeyboardEvent_h