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 "UIEventWithKeyState.h"
28 #include <wtf/Vector.h>
32 class PlatformKeyboardEvent
;
35 struct KeypressCommand
{
36 KeypressCommand(const String
& commandName
) : commandName(commandName
) {}
37 KeypressCommand(const String
& commandName
, const String
& text
) : commandName(commandName
), text(text
) { ASSERT(commandName
== "insertText:"); }
44 // Introduced in DOM Level 3
45 class KeyboardEvent
: public UIEventWithKeyState
{
47 enum KeyLocationCode
{
48 DOM_KEY_LOCATION_STANDARD
= 0x00,
49 DOM_KEY_LOCATION_LEFT
= 0x01,
50 DOM_KEY_LOCATION_RIGHT
= 0x02,
51 DOM_KEY_LOCATION_NUMPAD
= 0x03
54 static PassRefPtr
<KeyboardEvent
> create()
56 return adoptRef(new KeyboardEvent
);
58 static PassRefPtr
<KeyboardEvent
> create(const PlatformKeyboardEvent
& platformEvent
, AbstractView
* view
)
60 return adoptRef(new KeyboardEvent(platformEvent
, view
));
62 static PassRefPtr
<KeyboardEvent
> create(const AtomicString
& type
, bool canBubble
, bool cancelable
, AbstractView
* view
,
63 const String
& keyIdentifier
, unsigned keyLocation
,
64 bool ctrlKey
, bool altKey
, bool shiftKey
, bool metaKey
, bool altGraphKey
)
66 return adoptRef(new KeyboardEvent(type
, canBubble
, cancelable
, view
, keyIdentifier
, keyLocation
,
67 ctrlKey
, altKey
, shiftKey
, metaKey
, altGraphKey
));
69 virtual ~KeyboardEvent();
71 void initKeyboardEvent(const AtomicString
& type
, bool canBubble
, bool cancelable
, AbstractView
*,
72 const String
& keyIdentifier
, unsigned keyLocation
,
73 bool ctrlKey
, bool altKey
, bool shiftKey
, bool metaKey
, bool altGraphKey
= false);
75 String
keyIdentifier() const { return m_keyIdentifier
; }
76 unsigned keyLocation() const { return m_keyLocation
; }
78 bool getModifierState(const String
& keyIdentifier
) const;
80 bool altGraphKey() const { return m_altGraphKey
; }
82 const PlatformKeyboardEvent
* keyEvent() const { return m_keyEvent
; }
84 int keyCode() const; // key code for keydown and keyup, character for keypress
85 int charCode() const; // character code for keypress, 0 for keydown and keyup
87 virtual bool isKeyboardEvent() const;
88 virtual int which() const;
91 // We only have this need to store keypress command info on the Mac.
92 Vector
<KeypressCommand
>& keypressCommands() { return m_keypressCommands
; }
97 KeyboardEvent(const PlatformKeyboardEvent
&, AbstractView
*);
98 KeyboardEvent(const AtomicString
& type
, bool canBubble
, bool cancelable
, AbstractView
*,
99 const String
& keyIdentifier
, unsigned keyLocation
,
100 bool ctrlKey
, bool altKey
, bool shiftKey
, bool metaKey
, bool altGraphKey
);
102 PlatformKeyboardEvent
* m_keyEvent
;
103 String m_keyIdentifier
;
104 unsigned m_keyLocation
;
105 bool m_altGraphKey
: 1;
108 Vector
<KeypressCommand
> m_keypressCommands
;
112 KeyboardEvent
* findKeyboardEvent(Event
*);
114 } // namespace WebCore
116 #endif // KeyboardEvent_h