]> git.saurik.com Git - iphone-api.git/blob - WebCore/KeyboardEvent.h
Adding the WebCore headers (for Cydget).
[iphone-api.git] / WebCore / KeyboardEvent.h
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 "UIEventWithKeyState.h"
28 #include <wtf/Vector.h>
29
30 namespace WebCore {
31
32 class PlatformKeyboardEvent;
33
34 #if PLATFORM(MAC)
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:"); }
38
39 String commandName;
40 String text;
41 };
42 #endif
43
44 // Introduced in DOM Level 3
45 class KeyboardEvent : public UIEventWithKeyState {
46 public:
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
52 };
53
54 static PassRefPtr<KeyboardEvent> create()
55 {
56 return adoptRef(new KeyboardEvent);
57 }
58 static PassRefPtr<KeyboardEvent> create(const PlatformKeyboardEvent& platformEvent, AbstractView* view)
59 {
60 return adoptRef(new KeyboardEvent(platformEvent, view));
61 }
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)
65 {
66 return adoptRef(new KeyboardEvent(type, canBubble, cancelable, view, keyIdentifier, keyLocation,
67 ctrlKey, altKey, shiftKey, metaKey, altGraphKey));
68 }
69 virtual ~KeyboardEvent();
70
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);
74
75 String keyIdentifier() const { return m_keyIdentifier; }
76 unsigned keyLocation() const { return m_keyLocation; }
77
78 bool getModifierState(const String& keyIdentifier) const;
79
80 bool altGraphKey() const { return m_altGraphKey; }
81
82 const PlatformKeyboardEvent* keyEvent() const { return m_keyEvent; }
83
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
86
87 virtual bool isKeyboardEvent() const;
88 virtual int which() const;
89
90 #if PLATFORM(MAC)
91 // We only have this need to store keypress command info on the Mac.
92 Vector<KeypressCommand>& keypressCommands() { return m_keypressCommands; }
93 #endif
94
95 private:
96 KeyboardEvent();
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);
101
102 PlatformKeyboardEvent* m_keyEvent;
103 String m_keyIdentifier;
104 unsigned m_keyLocation;
105 bool m_altGraphKey : 1;
106
107 #if PLATFORM(MAC)
108 Vector<KeypressCommand> m_keypressCommands;
109 #endif
110 };
111
112 KeyboardEvent* findKeyboardEvent(Event*);
113
114 } // namespace WebCore
115
116 #endif // KeyboardEvent_h