| 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 "chrome/browser/ui/ash/event_rewriter.h" | 5 #include "chrome/browser/ui/ash/event_rewriter.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/prefs/pref_member.h" | 9 #include "base/prefs/pref_member.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "ash/wm/window_state.h" | 22 #include "ash/wm/window_state.h" |
| 23 #include "chrome/browser/chromeos/input_method/input_method_configuration.h" | 23 #include "chrome/browser/chromeos/input_method/input_method_configuration.h" |
| 24 #include "chrome/browser/chromeos/input_method/mock_input_method_manager.h" | 24 #include "chrome/browser/chromeos/input_method/mock_input_method_manager.h" |
| 25 #include "chrome/browser/chromeos/login/mock_user_manager.h" | 25 #include "chrome/browser/chromeos/login/mock_user_manager.h" |
| 26 #include "chrome/browser/chromeos/login/user_manager.h" | 26 #include "chrome/browser/chromeos/login/user_manager.h" |
| 27 #include "chrome/browser/chromeos/preferences.h" | 27 #include "chrome/browser/chromeos/preferences.h" |
| 28 #include "chromeos/chromeos_switches.h" | 28 #include "chromeos/chromeos_switches.h" |
| 29 #include "chromeos/ime/mock_xkeyboard.h" | 29 #include "chromeos/ime/mock_xkeyboard.h" |
| 30 #include "ui/aura/window.h" | 30 #include "ui/aura/window.h" |
| 31 #include "ui/events/test/events_test_utils_x11.h" | 31 #include "ui/events/test/events_test_utils_x11.h" |
| 32 #include "ui/events/x/touch_factory_x11.h" |
| 32 #include "ui/gfx/x/x11_types.h" | 33 #include "ui/gfx/x/x11_types.h" |
| 33 | 34 |
| 34 namespace { | 35 namespace { |
| 35 | 36 |
| 36 std::string GetRewrittenEventAsString(EventRewriter* rewriter, | 37 std::string GetRewrittenEventAsString(EventRewriter* rewriter, |
| 37 ui::KeyboardCode ui_keycode, | 38 ui::KeyboardCode ui_keycode, |
| 38 int ui_flags, | 39 int ui_flags, |
| 39 ui::EventType ui_type, | 40 ui::EventType ui_type, |
| 40 KeyCode x_keycode, | 41 KeyCode x_keycode, |
| 41 unsigned int x_state) { | 42 unsigned int x_state) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 56 int ui_flags, | 57 int ui_flags, |
| 57 ui::EventType ui_type, | 58 ui::EventType ui_type, |
| 58 KeyCode x_keycode, | 59 KeyCode x_keycode, |
| 59 unsigned int x_state, | 60 unsigned int x_state, |
| 60 int x_type) { | 61 int x_type) { |
| 61 return base::StringPrintf( | 62 return base::StringPrintf( |
| 62 "ui_keycode=%d ui_flags=%d ui_type=%d x_keycode=%u x_state=%u x_type=%d", | 63 "ui_keycode=%d ui_flags=%d ui_type=%d x_keycode=%u x_state=%u x_type=%d", |
| 63 ui_keycode, ui_flags, ui_type, x_keycode, x_state, x_type); | 64 ui_keycode, ui_flags, ui_type, x_keycode, x_state, x_type); |
| 64 } | 65 } |
| 65 | 66 |
| 67 } // namespace |
| 68 |
| 66 class EventRewriterTest : public testing::Test { | 69 class EventRewriterTest : public testing::Test { |
| 67 public: | 70 public: |
| 68 EventRewriterTest() | 71 EventRewriterTest() |
| 69 : display_(gfx::GetXDisplay()), | 72 : display_(gfx::GetXDisplay()), |
| 70 keycode_a_(XKeysymToKeycode(display_, XK_a)), | 73 keycode_a_(XKeysymToKeycode(display_, XK_a)), |
| 71 keycode_alt_l_(XKeysymToKeycode(display_, XK_Alt_L)), | 74 keycode_alt_l_(XKeysymToKeycode(display_, XK_Alt_L)), |
| 72 keycode_alt_r_(XKeysymToKeycode(display_, XK_Alt_R)), | 75 keycode_alt_r_(XKeysymToKeycode(display_, XK_Alt_R)), |
| 73 keycode_b_(XKeysymToKeycode(display_, XK_B)), | 76 keycode_b_(XKeysymToKeycode(display_, XK_B)), |
| 74 keycode_caps_lock_(XKeysymToKeycode(display_, XK_Caps_Lock)), | 77 keycode_caps_lock_(XKeysymToKeycode(display_, XK_Caps_Lock)), |
| 75 keycode_control_l_(XKeysymToKeycode(display_, XK_Control_L)), | 78 keycode_control_l_(XKeysymToKeycode(display_, XK_Control_L)), |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 | 176 |
| 174 virtual void TearDown() { | 177 virtual void TearDown() { |
| 175 // Shutdown() deletes the IME mock object. | 178 // Shutdown() deletes the IME mock object. |
| 176 chromeos::input_method::Shutdown(); | 179 chromeos::input_method::Shutdown(); |
| 177 } | 180 } |
| 178 | 181 |
| 179 protected: | 182 protected: |
| 180 void TestRewriteNumPadKeys(); | 183 void TestRewriteNumPadKeys(); |
| 181 void TestRewriteNumPadKeysOnAppleKeyboard(); | 184 void TestRewriteNumPadKeysOnAppleKeyboard(); |
| 182 | 185 |
| 186 void RewriteLocatedEvent(EventRewriter* rewriter, |
| 187 ui::LocatedEvent* event) { |
| 188 rewriter->RewriteLocatedEvent(event); |
| 189 } |
| 190 |
| 183 Display* display_; | 191 Display* display_; |
| 184 const KeyCode keycode_a_; | 192 const KeyCode keycode_a_; |
| 185 const KeyCode keycode_alt_l_; | 193 const KeyCode keycode_alt_l_; |
| 186 const KeyCode keycode_alt_r_; | 194 const KeyCode keycode_alt_r_; |
| 187 const KeyCode keycode_b_; | 195 const KeyCode keycode_b_; |
| 188 const KeyCode keycode_caps_lock_; | 196 const KeyCode keycode_caps_lock_; |
| 189 const KeyCode keycode_control_l_; | 197 const KeyCode keycode_control_l_; |
| 190 const KeyCode keycode_control_r_; | 198 const KeyCode keycode_control_r_; |
| 191 const KeyCode keycode_meta_l_; | 199 const KeyCode keycode_meta_l_; |
| 192 const KeyCode keycode_meta_r_; | 200 const KeyCode keycode_meta_r_; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 const KeyCode keycode_0_; | 271 const KeyCode keycode_0_; |
| 264 const KeyCode keycode_minus_; | 272 const KeyCode keycode_minus_; |
| 265 const KeyCode keycode_equal_; | 273 const KeyCode keycode_equal_; |
| 266 const KeyCode keycode_period_; | 274 const KeyCode keycode_period_; |
| 267 const KeyCode keycode_insert_; | 275 const KeyCode keycode_insert_; |
| 268 chromeos::MockUserManager* mock_user_manager_; // Not owned. | 276 chromeos::MockUserManager* mock_user_manager_; // Not owned. |
| 269 chromeos::ScopedUserManagerEnabler user_manager_enabler_; | 277 chromeos::ScopedUserManagerEnabler user_manager_enabler_; |
| 270 chromeos::input_method::MockInputMethodManager* input_method_manager_mock_; | 278 chromeos::input_method::MockInputMethodManager* input_method_manager_mock_; |
| 271 }; | 279 }; |
| 272 | 280 |
| 273 } // namespace | |
| 274 #else | 281 #else |
| 275 class EventRewriterTest : public testing::Test { | 282 class EventRewriterTest : public testing::Test { |
| 276 public: | 283 public: |
| 277 EventRewriterTest() {} | 284 EventRewriterTest() {} |
| 278 virtual ~EventRewriterTest() {} | 285 virtual ~EventRewriterTest() {} |
| 279 }; | 286 }; |
| 280 #endif | 287 #endif |
| 281 | 288 |
| 282 TEST_F(EventRewriterTest, TestGetDeviceType) { | 289 TEST_F(EventRewriterTest, TestGetDeviceType) { |
| 283 // This is the typical string which an Apple keyboard sends. | 290 // This is the typical string which an Apple keyboard sends. |
| (...skipping 2089 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2373 ASSERT_FALSE(RewriteFunctionKeys(&press_f1)); | 2380 ASSERT_FALSE(RewriteFunctionKeys(&press_f1)); |
| 2374 ASSERT_EQ(ui::VKEY_F1, press_f1.key_code()); | 2381 ASSERT_EQ(ui::VKEY_F1, press_f1.key_code()); |
| 2375 | 2382 |
| 2376 // If the pref isn't set when an event is sent to a regular window, F1 is | 2383 // If the pref isn't set when an event is sent to a regular window, F1 is |
| 2377 // rewritten to the back key. | 2384 // rewritten to the back key. |
| 2378 send_function_keys_pref.SetValue(false); | 2385 send_function_keys_pref.SetValue(false); |
| 2379 ASSERT_TRUE(RewriteFunctionKeys(&press_f1)); | 2386 ASSERT_TRUE(RewriteFunctionKeys(&press_f1)); |
| 2380 ASSERT_EQ(ui::VKEY_BROWSER_BACK, press_f1.key_code()); | 2387 ASSERT_EQ(ui::VKEY_BROWSER_BACK, press_f1.key_code()); |
| 2381 } | 2388 } |
| 2382 | 2389 |
| 2390 TEST_F(EventRewriterTest, DontRewriteIfNotRewritten) { |
| 2391 std::vector<unsigned int> device_list; |
| 2392 device_list.push_back(10); |
| 2393 device_list.push_back(11); |
| 2394 ui::TouchFactory::GetInstance()->SetPointerDeviceForTest(device_list); |
| 2395 TestingPrefServiceSyncable prefs; |
| 2396 EventRewriter rewriter; |
| 2397 rewriter.set_pref_service_for_testing(&prefs); |
| 2398 const int kLeftAndAltFlag = ui::EF_LEFT_MOUSE_BUTTON | ui::EF_ALT_DOWN; |
| 2399 { |
| 2400 ui::ScopedXI2Event xev; |
| 2401 xev.InitGenericButtonEvent(10, ui::ET_MOUSE_PRESSED, kLeftAndAltFlag); |
| 2402 ui::MouseEvent press(xev); |
| 2403 // Sanity check. |
| 2404 EXPECT_EQ(ui::ET_MOUSE_PRESSED, press.type()); |
| 2405 EXPECT_EQ(kLeftAndAltFlag, press.flags()); |
| 2406 |
| 2407 RewriteLocatedEvent(&rewriter, &press); |
| 2408 |
| 2409 EXPECT_TRUE(ui::EF_RIGHT_MOUSE_BUTTON & press.flags()); |
| 2410 } |
| 2411 { |
| 2412 ui::ScopedXI2Event xev; |
| 2413 xev.InitGenericButtonEvent(10, ui::ET_MOUSE_RELEASED, kLeftAndAltFlag); |
| 2414 ui::MouseEvent release(xev); |
| 2415 RewriteLocatedEvent(&rewriter, &release); |
| 2416 EXPECT_TRUE(ui::EF_RIGHT_MOUSE_BUTTON & release.flags()); |
| 2417 } |
| 2418 |
| 2419 // No ALT in frst click. |
| 2420 { |
| 2421 ui::ScopedXI2Event xev; |
| 2422 xev.InitGenericButtonEvent( |
| 2423 10, ui::ET_MOUSE_PRESSED, ui::EF_LEFT_MOUSE_BUTTON); |
| 2424 ui::MouseEvent press(xev); |
| 2425 RewriteLocatedEvent(&rewriter, &press); |
| 2426 EXPECT_TRUE(ui::EF_LEFT_MOUSE_BUTTON & press.flags()); |
| 2427 } |
| 2428 { |
| 2429 ui::ScopedXI2Event xev; |
| 2430 xev.InitGenericButtonEvent(10, ui::ET_MOUSE_RELEASED, kLeftAndAltFlag); |
| 2431 ui::MouseEvent release(xev); |
| 2432 RewriteLocatedEvent(&rewriter, &release); |
| 2433 EXPECT_TRUE((ui::EF_LEFT_MOUSE_BUTTON | ui::EF_ALT_DOWN) & |
| 2434 release.flags()); |
| 2435 } |
| 2436 |
| 2437 // ALT on different device. |
| 2438 { |
| 2439 ui::ScopedXI2Event xev; |
| 2440 xev.InitGenericButtonEvent(11, ui::ET_MOUSE_PRESSED, kLeftAndAltFlag); |
| 2441 ui::MouseEvent press(xev); |
| 2442 RewriteLocatedEvent(&rewriter, &press); |
| 2443 EXPECT_TRUE(ui::EF_RIGHT_MOUSE_BUTTON & press.flags()); |
| 2444 } |
| 2445 { |
| 2446 ui::ScopedXI2Event xev; |
| 2447 xev.InitGenericButtonEvent(10, ui::ET_MOUSE_RELEASED, kLeftAndAltFlag); |
| 2448 ui::MouseEvent release(xev); |
| 2449 RewriteLocatedEvent(&rewriter, &release); |
| 2450 EXPECT_TRUE((ui::EF_LEFT_MOUSE_BUTTON | ui::EF_ALT_DOWN) & |
| 2451 release.flags()); |
| 2452 } |
| 2453 { |
| 2454 ui::ScopedXI2Event xev; |
| 2455 xev.InitGenericButtonEvent(11, ui::ET_MOUSE_RELEASED, kLeftAndAltFlag); |
| 2456 ui::MouseEvent release(xev); |
| 2457 RewriteLocatedEvent(&rewriter, &release); |
| 2458 EXPECT_TRUE(ui::EF_RIGHT_MOUSE_BUTTON & release.flags()); |
| 2459 } |
| 2460 } |
| 2461 |
| 2383 #endif // OS_CHROMEOS | 2462 #endif // OS_CHROMEOS |
| OLD | NEW |