| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/bind.h" | 6 #include "base/bind.h" |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/memory/shared_memory.h" | 8 #include "base/memory/shared_memory.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 #include "ui/gfx/range/range.h" | 58 #include "ui/gfx/range/range.h" |
| 59 | 59 |
| 60 #if defined(USE_AURA) | 60 #if defined(USE_AURA) |
| 61 #include "ui/events/event.h" | 61 #include "ui/events/event.h" |
| 62 #endif | 62 #endif |
| 63 | 63 |
| 64 #if defined(USE_AURA) && defined(USE_X11) | 64 #if defined(USE_AURA) && defined(USE_X11) |
| 65 #include <X11/Xlib.h> | 65 #include <X11/Xlib.h> |
| 66 #include "ui/events/event_constants.h" | 66 #include "ui/events/event_constants.h" |
| 67 #include "ui/events/keycodes/keyboard_code_conversion.h" | 67 #include "ui/events/keycodes/keyboard_code_conversion.h" |
| 68 #include "ui/events/test/events_test_utils.h" |
| 68 #include "ui/events/test/events_test_utils_x11.h" | 69 #include "ui/events/test/events_test_utils_x11.h" |
| 69 #endif | 70 #endif |
| 70 | 71 |
| 71 #if defined(USE_OZONE) | 72 #if defined(USE_OZONE) |
| 72 #include "ui/events/keycodes/keyboard_code_conversion.h" | 73 #include "ui/events/keycodes/keyboard_code_conversion.h" |
| 73 #endif | 74 #endif |
| 74 | 75 |
| 75 using blink::WebFrame; | 76 using blink::WebFrame; |
| 76 using blink::WebInputEvent; | 77 using blink::WebInputEvent; |
| 77 using blink::WebLocalFrame; | 78 using blink::WebLocalFrame; |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 return -1; | 182 return -1; |
| 182 | 183 |
| 183 // Create IPC messages from Windows messages and send them to our | 184 // Create IPC messages from Windows messages and send them to our |
| 184 // back-end. | 185 // back-end. |
| 185 // A keyboard event of Windows consists of three Windows messages: | 186 // A keyboard event of Windows consists of three Windows messages: |
| 186 // WM_KEYDOWN, WM_CHAR, and WM_KEYUP. | 187 // WM_KEYDOWN, WM_CHAR, and WM_KEYUP. |
| 187 // WM_KEYDOWN and WM_KEYUP sends virtual-key codes. On the other hand, | 188 // WM_KEYDOWN and WM_KEYUP sends virtual-key codes. On the other hand, |
| 188 // WM_CHAR sends a composed Unicode character. | 189 // WM_CHAR sends a composed Unicode character. |
| 189 MSG msg1 = { NULL, WM_KEYDOWN, key_code, 0 }; | 190 MSG msg1 = { NULL, WM_KEYDOWN, key_code, 0 }; |
| 190 #if defined(USE_AURA) | 191 #if defined(USE_AURA) |
| 191 ui::KeyEvent evt1(msg1, false); | 192 ui::KeyEvent evt1(msg1); |
| 192 NativeWebKeyboardEvent keydown_event(&evt1); | 193 NativeWebKeyboardEvent keydown_event(&evt1); |
| 193 #else | 194 #else |
| 194 NativeWebKeyboardEvent keydown_event(msg1); | 195 NativeWebKeyboardEvent keydown_event(msg1); |
| 195 #endif | 196 #endif |
| 196 SendNativeKeyEvent(keydown_event); | 197 SendNativeKeyEvent(keydown_event); |
| 197 | 198 |
| 198 MSG msg2 = { NULL, WM_CHAR, (*output)[0], 0 }; | 199 MSG msg2 = { NULL, WM_CHAR, (*output)[0], 0 }; |
| 199 #if defined(USE_AURA) | 200 #if defined(USE_AURA) |
| 200 ui::KeyEvent evt2(msg2, true); | 201 ui::KeyEvent evt2(msg2); |
| 201 NativeWebKeyboardEvent char_event(&evt2); | 202 NativeWebKeyboardEvent char_event(&evt2); |
| 202 #else | 203 #else |
| 203 NativeWebKeyboardEvent char_event(msg2); | 204 NativeWebKeyboardEvent char_event(msg2); |
| 204 #endif | 205 #endif |
| 205 SendNativeKeyEvent(char_event); | 206 SendNativeKeyEvent(char_event); |
| 206 | 207 |
| 207 MSG msg3 = { NULL, WM_KEYUP, key_code, 0 }; | 208 MSG msg3 = { NULL, WM_KEYUP, key_code, 0 }; |
| 208 #if defined(USE_AURA) | 209 #if defined(USE_AURA) |
| 209 ui::KeyEvent evt3(msg3, false); | 210 ui::KeyEvent evt3(msg3); |
| 210 NativeWebKeyboardEvent keyup_event(&evt3); | 211 NativeWebKeyboardEvent keyup_event(&evt3); |
| 211 #else | 212 #else |
| 212 NativeWebKeyboardEvent keyup_event(msg3); | 213 NativeWebKeyboardEvent keyup_event(msg3); |
| 213 #endif | 214 #endif |
| 214 SendNativeKeyEvent(keyup_event); | 215 SendNativeKeyEvent(keyup_event); |
| 215 | 216 |
| 216 return length; | 217 return length; |
| 217 #elif defined(USE_AURA) && defined(USE_X11) | 218 #elif defined(USE_AURA) && defined(USE_X11) |
| 218 // We ignore |layout|, which means we are only testing the layout of the | 219 // We ignore |layout|, which means we are only testing the layout of the |
| 219 // current locale. TODO(mazda): fix this to respect |layout|. | 220 // current locale. TODO(mazda): fix this to respect |layout|. |
| 220 CHECK(output); | 221 CHECK(output); |
| 221 const int flags = ConvertMockKeyboardModifier(modifiers); | 222 const int flags = ConvertMockKeyboardModifier(modifiers); |
| 222 | 223 |
| 223 ui::ScopedXI2Event xevent; | 224 ui::ScopedXI2Event xevent; |
| 224 xevent.InitKeyEvent(ui::ET_KEY_PRESSED, | 225 xevent.InitKeyEvent(ui::ET_KEY_PRESSED, |
| 225 static_cast<ui::KeyboardCode>(key_code), | 226 static_cast<ui::KeyboardCode>(key_code), |
| 226 flags); | 227 flags); |
| 227 ui::KeyEvent event1(xevent, false); | 228 ui::KeyEvent event1(xevent); |
| 228 NativeWebKeyboardEvent keydown_event(&event1); | 229 NativeWebKeyboardEvent keydown_event(&event1); |
| 229 SendNativeKeyEvent(keydown_event); | 230 SendNativeKeyEvent(keydown_event); |
| 230 | 231 |
| 232 // X11 doesn't actually have native character events, but give the test |
| 233 // what it wants. |
| 231 xevent.InitKeyEvent(ui::ET_KEY_PRESSED, | 234 xevent.InitKeyEvent(ui::ET_KEY_PRESSED, |
| 232 static_cast<ui::KeyboardCode>(key_code), | 235 static_cast<ui::KeyboardCode>(key_code), |
| 233 flags); | 236 flags); |
| 234 ui::KeyEvent event2(xevent, true); | 237 ui::KeyEvent event2(xevent); |
| 238 ui::KeyEventTestApi test_event2(&event2); |
| 239 test_event2.set_is_char(true); |
| 235 NativeWebKeyboardEvent char_event(&event2); | 240 NativeWebKeyboardEvent char_event(&event2); |
| 236 SendNativeKeyEvent(char_event); | 241 SendNativeKeyEvent(char_event); |
| 237 | 242 |
| 238 xevent.InitKeyEvent(ui::ET_KEY_RELEASED, | 243 xevent.InitKeyEvent(ui::ET_KEY_RELEASED, |
| 239 static_cast<ui::KeyboardCode>(key_code), | 244 static_cast<ui::KeyboardCode>(key_code), |
| 240 flags); | 245 flags); |
| 241 ui::KeyEvent event3(xevent, false); | 246 ui::KeyEvent event3(xevent); |
| 242 NativeWebKeyboardEvent keyup_event(&event3); | 247 NativeWebKeyboardEvent keyup_event(&event3); |
| 243 SendNativeKeyEvent(keyup_event); | 248 SendNativeKeyEvent(keyup_event); |
| 244 | 249 |
| 245 long c = GetCharacterFromKeyCode(static_cast<ui::KeyboardCode>(key_code), | 250 long c = GetCharacterFromKeyCode(static_cast<ui::KeyboardCode>(key_code), |
| 246 flags); | 251 flags); |
| 247 output->assign(1, static_cast<base::char16>(c)); | 252 output->assign(1, static_cast<base::char16>(c)); |
| 248 return 1; | 253 return 1; |
| 249 #elif defined(USE_OZONE) | 254 #elif defined(USE_OZONE) |
| 250 const int flags = ConvertMockKeyboardModifier(modifiers); | 255 const int flags = ConvertMockKeyboardModifier(modifiers); |
| 251 | 256 |
| 252 // Ozone's native events are ui::Events. So first create the "native" event, | 257 // Ozone's native events are ui::Events. So first create the "native" event, |
| 253 // then create the actual ui::KeyEvent with the native event. | 258 // then create the actual ui::KeyEvent with the native event. |
| 254 ui::KeyEvent keydown_native_event(ui::ET_KEY_PRESSED, | 259 ui::KeyEvent keydown_native_event(ui::ET_KEY_PRESSED, |
| 255 static_cast<ui::KeyboardCode>(key_code), | 260 static_cast<ui::KeyboardCode>(key_code), |
| 256 flags, | 261 flags); |
| 257 true); | 262 ui::KeyEvent keydown_event(&keydown_native_event); |
| 258 ui::KeyEvent keydown_event(&keydown_native_event, false); | |
| 259 NativeWebKeyboardEvent keydown_web_event(&keydown_event); | 263 NativeWebKeyboardEvent keydown_web_event(&keydown_event); |
| 260 SendNativeKeyEvent(keydown_web_event); | 264 SendNativeKeyEvent(keydown_web_event); |
| 261 | 265 |
| 262 ui::KeyEvent char_native_event(ui::ET_KEY_PRESSED, | 266 ui::KeyEvent char_native_event(static_cast<base::char16>(key_code), |
| 263 static_cast<ui::KeyboardCode>(key_code), | 267 static_cast<ui::KeyboardCode>(key_code), |
| 264 flags, | 268 flags); |
| 265 true); | 269 ui::KeyEvent char_event(&char_native_event); |
| 266 ui::KeyEvent char_event(&char_native_event, true); | |
| 267 NativeWebKeyboardEvent char_web_event(&char_event); | 270 NativeWebKeyboardEvent char_web_event(&char_event); |
| 268 SendNativeKeyEvent(char_web_event); | 271 SendNativeKeyEvent(char_web_event); |
| 269 | 272 |
| 270 ui::KeyEvent keyup_native_event(ui::ET_KEY_RELEASED, | 273 ui::KeyEvent keyup_native_event(ui::ET_KEY_RELEASED, |
| 271 static_cast<ui::KeyboardCode>(key_code), | 274 static_cast<ui::KeyboardCode>(key_code), |
| 272 flags, | 275 flags); |
| 273 true); | 276 ui::KeyEvent keyup_event(&keyup_native_event); |
| 274 ui::KeyEvent keyup_event(&keyup_native_event, false); | |
| 275 NativeWebKeyboardEvent keyup_web_event(&keyup_event); | 277 NativeWebKeyboardEvent keyup_web_event(&keyup_event); |
| 276 SendNativeKeyEvent(keyup_web_event); | 278 SendNativeKeyEvent(keyup_web_event); |
| 277 | 279 |
| 278 long c = GetCharacterFromKeyCode(static_cast<ui::KeyboardCode>(key_code), | 280 long c = GetCharacterFromKeyCode(static_cast<ui::KeyboardCode>(key_code), |
| 279 flags); | 281 flags); |
| 280 output->assign(1, static_cast<base::char16>(c)); | 282 output->assign(1, static_cast<base::char16>(c)); |
| 281 return 1; | 283 return 1; |
| 282 #else | 284 #else |
| 283 NOTIMPLEMENTED(); | 285 NOTIMPLEMENTED(); |
| 284 return L'\0'; | 286 return L'\0'; |
| (...skipping 2145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2430 ProcessPendingMessages(); | 2432 ProcessPendingMessages(); |
| 2431 base::Time after_navigation = | 2433 base::Time after_navigation = |
| 2432 base::Time::Now() + base::TimeDelta::FromDays(1); | 2434 base::Time::Now() + base::TimeDelta::FromDays(1); |
| 2433 | 2435 |
| 2434 base::Time late_nav_reported_start = | 2436 base::Time late_nav_reported_start = |
| 2435 base::Time::FromDoubleT(GetMainFrame()->performance().navigationStart()); | 2437 base::Time::FromDoubleT(GetMainFrame()->performance().navigationStart()); |
| 2436 EXPECT_LE(late_nav_reported_start, after_navigation); | 2438 EXPECT_LE(late_nav_reported_start, after_navigation); |
| 2437 } | 2439 } |
| 2438 | 2440 |
| 2439 } // namespace content | 2441 } // namespace content |
| OLD | NEW |