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