OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "config.h" | 5 #include "config.h" |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 | 8 |
9 #include "KeyboardCodes.h" | 9 #include "KeyboardCodes.h" |
10 #include "StringImpl.h" // This is so that the KJS build works | 10 #include "StringImpl.h" // This is so that the KJS build works |
11 | 11 |
12 MSVC_PUSH_WARNING_LEVEL(0); | 12 MSVC_PUSH_WARNING_LEVEL(0); |
13 #include "PlatformKeyboardEvent.h" | 13 #include "PlatformKeyboardEvent.h" |
14 #include "PlatformMouseEvent.h" | 14 #include "PlatformMouseEvent.h" |
15 #include "PlatformWheelEvent.h" | 15 #include "PlatformWheelEvent.h" |
16 #include "Widget.h" | 16 #include "Widget.h" |
17 MSVC_POP_WARNING(); | 17 MSVC_POP_WARNING(); |
18 | 18 |
19 #include "WebKit.h" | 19 #include "WebKit.h" |
20 | 20 |
21 #undef LOG | 21 #undef LOG |
22 #include "base/gfx/point.h" | 22 #include "base/gfx/point.h" |
23 #include "base/logging.h" | 23 #include "base/logging.h" |
24 #include "webkit/glue/event_conversion.h" | 24 #include "webkit/glue/event_conversion.h" |
| 25 #include "webkit/glue/glue_util.h" |
25 #include "webkit/glue/webinputevent.h" | 26 #include "webkit/glue/webinputevent.h" |
26 #include "webkit/glue/webkit_glue.h" | 27 #include "webkit/glue/webkit_glue.h" |
27 | 28 |
28 using namespace WebCore; | 29 using namespace WebCore; |
29 | 30 |
30 // MakePlatformMouseEvent ----------------------------------------------------- | 31 // MakePlatformMouseEvent ----------------------------------------------------- |
31 | 32 |
32 int MakePlatformMouseEvent::last_click_count_ = 0; | 33 int MakePlatformMouseEvent::last_click_count_ = 0; |
33 uint32 MakePlatformMouseEvent::last_click_time_ = 0; | 34 uint32 MakePlatformMouseEvent::last_click_time_ = 0; |
34 | 35 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 | 135 |
135 // MakePlatformKeyboardEvent -------------------------------------------------- | 136 // MakePlatformKeyboardEvent -------------------------------------------------- |
136 | 137 |
137 static inline const PlatformKeyboardEvent::Type ToPlatformKeyboardEventType( | 138 static inline const PlatformKeyboardEvent::Type ToPlatformKeyboardEventType( |
138 WebInputEvent::Type type) { | 139 WebInputEvent::Type type) { |
139 switch (type) { | 140 switch (type) { |
140 case WebInputEvent::KEY_UP: | 141 case WebInputEvent::KEY_UP: |
141 return PlatformKeyboardEvent::KeyUp; | 142 return PlatformKeyboardEvent::KeyUp; |
142 case WebInputEvent::KEY_DOWN: | 143 case WebInputEvent::KEY_DOWN: |
143 return PlatformKeyboardEvent::KeyDown; | 144 return PlatformKeyboardEvent::KeyDown; |
| 145 case WebInputEvent::RAW_KEY_DOWN: |
| 146 return PlatformKeyboardEvent::RawKeyDown; |
144 case WebInputEvent::CHAR: | 147 case WebInputEvent::CHAR: |
145 return PlatformKeyboardEvent::Char; | 148 return PlatformKeyboardEvent::Char; |
146 default: | 149 default: |
147 ASSERT_NOT_REACHED(); | 150 ASSERT_NOT_REACHED(); |
148 } | 151 } |
149 return PlatformKeyboardEvent::KeyDown; | 152 return PlatformKeyboardEvent::KeyDown; |
150 } | 153 } |
151 | 154 |
152 static inline String ToSingleCharacterString(UChar c) { | 155 MakePlatformKeyboardEvent::MakePlatformKeyboardEvent( |
153 return String(&c, 1); | 156 const WebKeyboardEvent& e) { |
154 } | |
155 | |
156 #if !defined(OS_MACOSX) | |
157 // This function is not used on Mac OS X, and gcc complains. | |
158 static String GetKeyIdentifierForWindowsKeyCode(unsigned short keyCode) { | |
159 switch (keyCode) { | |
160 case VKEY_MENU: | |
161 return "Alt"; | |
162 case VKEY_CONTROL: | |
163 return "Control"; | |
164 case VKEY_SHIFT: | |
165 return "Shift"; | |
166 case VKEY_CAPITAL: | |
167 return "CapsLock"; | |
168 case VKEY_LWIN: | |
169 case VKEY_RWIN: | |
170 return "Win"; | |
171 case VKEY_CLEAR: | |
172 return "Clear"; | |
173 case VKEY_DOWN: | |
174 return "Down"; | |
175 // "End" | |
176 case VKEY_END: | |
177 return "End"; | |
178 // "Enter" | |
179 case VKEY_RETURN: | |
180 return "Enter"; | |
181 case VKEY_EXECUTE: | |
182 return "Execute"; | |
183 case VKEY_F1: | |
184 return "F1"; | |
185 case VKEY_F2: | |
186 return "F2"; | |
187 case VKEY_F3: | |
188 return "F3"; | |
189 case VKEY_F4: | |
190 return "F4"; | |
191 case VKEY_F5: | |
192 return "F5"; | |
193 case VKEY_F6: | |
194 return "F6"; | |
195 case VKEY_F7: | |
196 return "F7"; | |
197 case VKEY_F8: | |
198 return "F8"; | |
199 case VKEY_F9: | |
200 return "F9"; | |
201 case VKEY_F10: | |
202 return "F11"; | |
203 case VKEY_F12: | |
204 return "F12"; | |
205 case VKEY_F13: | |
206 return "F13"; | |
207 case VKEY_F14: | |
208 return "F14"; | |
209 case VKEY_F15: | |
210 return "F15"; | |
211 case VKEY_F16: | |
212 return "F16"; | |
213 case VKEY_F17: | |
214 return "F17"; | |
215 case VKEY_F18: | |
216 return "F18"; | |
217 case VKEY_F19: | |
218 return "F19"; | |
219 case VKEY_F20: | |
220 return "F20"; | |
221 case VKEY_F21: | |
222 return "F21"; | |
223 case VKEY_F22: | |
224 return "F22"; | |
225 case VKEY_F23: | |
226 return "F23"; | |
227 case VKEY_F24: | |
228 return "F24"; | |
229 case VKEY_HELP: | |
230 return "Help"; | |
231 case VKEY_HOME: | |
232 return "Home"; | |
233 case VKEY_INSERT: | |
234 return "Insert"; | |
235 case VKEY_LEFT: | |
236 return "Left"; | |
237 case VKEY_NEXT: | |
238 return "PageDown"; | |
239 case VKEY_PRIOR: | |
240 return "PageUp"; | |
241 case VKEY_PAUSE: | |
242 return "Pause"; | |
243 case VKEY_SNAPSHOT: | |
244 return "PrintScreen"; | |
245 case VKEY_RIGHT: | |
246 return "Right"; | |
247 case VKEY_SCROLL: | |
248 return "Scroll"; | |
249 case VKEY_SELECT: | |
250 return "Select"; | |
251 case VKEY_UP: | |
252 return "Up"; | |
253 // Standard says that DEL becomes U+007F. | |
254 case VKEY_DELETE: | |
255 return "U+007F"; | |
256 default: | |
257 return String::format("U+%04X", toupper(keyCode)); | |
258 } | |
259 } | |
260 #endif // !defined(OS_MACOSX) | |
261 | |
262 MakePlatformKeyboardEvent::MakePlatformKeyboardEvent(const WebKeyboardEvent& e) | |
263 { | |
264 m_type = ToPlatformKeyboardEventType(e.type); | 157 m_type = ToPlatformKeyboardEventType(e.type); |
265 if (m_type == Char || m_type == KeyDown) { | 158 m_text = WebCore::String(e.text); |
266 #if defined(OS_MACOSX) | 159 m_unmodifiedText = WebCore::String(e.unmodified_text); |
267 m_text = &e.text[0]; | 160 m_keyIdentifier = WebCore::String(e.key_identifier); |
268 m_unmodifiedText = &e.unmodified_text[0]; | |
269 m_keyIdentifier = &e.key_identifier[0]; | |
270 | |
271 // Always use 13 for Enter/Return -- we don't want to use AppKit's | |
272 // different character for Enter. | |
273 if (m_windowsVirtualKeyCode == '\r') { | |
274 m_text = "\r"; | |
275 m_unmodifiedText = "\r"; | |
276 } | |
277 | |
278 // The adjustments below are only needed in backward compatibility mode, | |
279 // but we cannot tell what mode we are in from here. | |
280 | |
281 // Turn 0x7F into 8, because backspace needs to always be 8. | |
282 if (m_text == "\x7F") | |
283 m_text = "\x8"; | |
284 if (m_unmodifiedText == "\x7F") | |
285 m_unmodifiedText = "\x8"; | |
286 // Always use 9 for tab -- we don't want to use AppKit's different character
for shift-tab. | |
287 if (m_windowsVirtualKeyCode == 9) { | |
288 m_text = "\x9"; | |
289 m_unmodifiedText = "\x9"; | |
290 } | |
291 #elif defined(OS_WIN) | |
292 m_text = m_unmodifiedText = ToSingleCharacterString(e.key_code); | |
293 #elif defined(OS_LINUX) | |
294 m_text = m_unmodifiedText = ToSingleCharacterString(e.text); | |
295 #endif | |
296 } | |
297 #if defined(OS_WIN) || defined(OS_LINUX) | |
298 if (m_type != Char) | |
299 m_keyIdentifier = GetKeyIdentifierForWindowsKeyCode(e.key_code); | |
300 #endif | |
301 if (m_type == Char || m_type == KeyDown || m_type == KeyUp || | |
302 m_type == RawKeyDown) { | |
303 m_windowsVirtualKeyCode = e.key_code; | |
304 } else { | |
305 m_windowsVirtualKeyCode = 0; | |
306 } | |
307 m_autoRepeat = (e.modifiers & WebInputEvent::IS_AUTO_REPEAT) != 0; | 161 m_autoRepeat = (e.modifiers & WebInputEvent::IS_AUTO_REPEAT) != 0; |
| 162 m_windowsVirtualKeyCode = e.windows_key_code; |
| 163 m_nativeVirtualKeyCode = e.native_key_code; |
308 m_isKeypad = (e.modifiers & WebInputEvent::IS_KEYPAD) != 0; | 164 m_isKeypad = (e.modifiers & WebInputEvent::IS_KEYPAD) != 0; |
309 m_shiftKey = (e.modifiers & WebInputEvent::SHIFT_KEY) != 0; | 165 m_shiftKey = (e.modifiers & WebInputEvent::SHIFT_KEY) != 0; |
310 m_ctrlKey = (e.modifiers & WebInputEvent::CTRL_KEY) != 0; | 166 m_ctrlKey = (e.modifiers & WebInputEvent::CTRL_KEY) != 0; |
311 m_altKey = (e.modifiers & WebInputEvent::ALT_KEY) != 0; | 167 m_altKey = (e.modifiers & WebInputEvent::ALT_KEY) != 0; |
312 m_metaKey = (e.modifiers & WebInputEvent::META_KEY) != 0; | 168 m_metaKey = (e.modifiers & WebInputEvent::META_KEY) != 0; |
313 #if defined(OS_WIN) | |
314 m_isSystemKey = e.system_key; | 169 m_isSystemKey = e.system_key; |
315 // TODO(port): set this field properly for linux and mac. | |
316 #elif defined(OS_LINUX) | |
317 m_isSystemKey = m_altKey; | |
318 #else | |
319 m_isSystemKey = false; | |
320 #endif | |
321 } | 170 } |
322 | 171 |
323 void MakePlatformKeyboardEvent::SetKeyType(Type type) { | 172 void MakePlatformKeyboardEvent::SetKeyType(Type type) { |
324 // According to the behavior of Webkit in Windows platform, | 173 // According to the behavior of Webkit in Windows platform, |
325 // we need to convert KeyDown to RawKeydown and Char events | 174 // we need to convert KeyDown to RawKeydown and Char events |
326 // See WebKit/WebKit/Win/WebView.cpp | 175 // See WebKit/WebKit/Win/WebView.cpp |
327 ASSERT(m_type == KeyDown); | 176 ASSERT(m_type == KeyDown); |
328 ASSERT(type == RawKeyDown || type == Char); | 177 ASSERT(type == RawKeyDown || type == Char); |
329 m_type = type; | 178 m_type = type; |
330 | 179 |
(...skipping 13 matching lines...) Expand all Loading... |
344 switch (windowsVirtualKeyCode()) { | 193 switch (windowsVirtualKeyCode()) { |
345 case VKEY_BACK: | 194 case VKEY_BACK: |
346 case VKEY_ESCAPE: | 195 case VKEY_ESCAPE: |
347 return false; | 196 return false; |
348 | 197 |
349 default: | 198 default: |
350 break; | 199 break; |
351 } | 200 } |
352 return true; | 201 return true; |
353 } | 202 } |
OLD | NEW |