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/events/EventDispatchMediator.h"
28 #include "core/events/UIEventWithKeyState.h"
32 class EventDispatcher;
34 class PlatformKeyboardEvent;
36 struct KeyboardEventInit : public UIEventInit {
48 class KeyboardEvent FINAL : public UIEventWithKeyState {
50 enum KeyLocationCode {
51 DOM_KEY_LOCATION_STANDARD = 0x00,
52 DOM_KEY_LOCATION_LEFT = 0x01,
53 DOM_KEY_LOCATION_RIGHT = 0x02,
54 DOM_KEY_LOCATION_NUMPAD = 0x03
57 static PassRefPtrWillBeRawPtr<KeyboardEvent> create()
59 return adoptRefWillBeNoop(new KeyboardEvent);
62 static PassRefPtrWillBeRawPtr<KeyboardEvent> create(const PlatformKeyboardEvent& platformEvent, AbstractView* view)
64 return adoptRefWillBeNoop(new KeyboardEvent(platformEvent, view));
67 static PassRefPtrWillBeRawPtr<KeyboardEvent> create(const AtomicString& type, const KeyboardEventInit& initializer)
69 return adoptRefWillBeNoop(new KeyboardEvent(type, initializer));
72 static PassRefPtrWillBeRawPtr<KeyboardEvent> create(const AtomicString& type, bool canBubble, bool cancelable, AbstractView* view,
73 const String& keyIdentifier, unsigned location,
74 bool ctrlKey, bool altKey, bool shiftKey, bool metaKey)
76 return adoptRefWillBeNoop(new KeyboardEvent(type, canBubble, cancelable, view, keyIdentifier, location,
77 ctrlKey, altKey, shiftKey, metaKey));
80 virtual ~KeyboardEvent();
82 void initKeyboardEvent(const AtomicString& type, bool canBubble, bool cancelable, AbstractView*,
83 const String& keyIdentifier, unsigned location,
84 bool ctrlKey, bool altKey, bool shiftKey, bool metaKey);
86 const String& keyIdentifier() const { return m_keyIdentifier; }
87 unsigned location() const { return m_location; }
89 bool getModifierState(const String& keyIdentifier) const;
91 const PlatformKeyboardEvent* keyEvent() const { return m_keyEvent.get(); }
93 virtual int keyCode() const OVERRIDE; // key code for keydown and keyup, character for keypress
94 virtual int charCode() const OVERRIDE; // character code for keypress, 0 for keydown and keyup
95 bool repeat() const { return m_isAutoRepeat; }
97 virtual const AtomicString& interfaceName() const OVERRIDE;
98 virtual bool isKeyboardEvent() const OVERRIDE;
99 virtual int which() const OVERRIDE;
101 virtual void trace(Visitor*) OVERRIDE;
105 KeyboardEvent(const PlatformKeyboardEvent&, AbstractView*);
106 KeyboardEvent(const AtomicString&, const KeyboardEventInit&);
107 KeyboardEvent(const AtomicString& type, bool canBubble, bool cancelable, AbstractView*,
108 const String& keyIdentifier, unsigned location,
109 bool ctrlKey, bool altKey, bool shiftKey, bool metaKey);
111 OwnPtr<PlatformKeyboardEvent> m_keyEvent;
112 String m_keyIdentifier;
114 bool m_isAutoRepeat : 1;
117 class KeyboardEventDispatchMediator : public EventDispatchMediator {
119 static PassRefPtrWillBeRawPtr<KeyboardEventDispatchMediator> create(PassRefPtrWillBeRawPtr<KeyboardEvent>);
121 explicit KeyboardEventDispatchMediator(PassRefPtrWillBeRawPtr<KeyboardEvent>);
122 virtual bool dispatchEvent(EventDispatcher*) const OVERRIDE;
125 DEFINE_EVENT_TYPE_CASTS(KeyboardEvent);
129 #endif // KeyboardEvent_h