| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "ash/sticky_keys/sticky_keys_controller.h" | 5 #include "ash/sticky_keys/sticky_keys_controller.h" |
| 6 | 6 |
| 7 #include <X11/Xlib.h> | 7 #include <X11/Xlib.h> |
| 8 #undef None | 8 #undef None |
| 9 #undef Bool | 9 #undef Bool |
| 10 #undef RootWindow | 10 #undef RootWindow |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 | 257 |
| 258 void SendActivateStickyKeyPattern(StickyKeysHandler* handler, | 258 void SendActivateStickyKeyPattern(StickyKeysHandler* handler, |
| 259 ui::KeyboardCode key_code) { | 259 ui::KeyboardCode key_code) { |
| 260 scoped_ptr<ui::KeyEvent> ev; | 260 scoped_ptr<ui::KeyEvent> ev; |
| 261 ev.reset(GenerateKey(true, key_code)); | 261 ev.reset(GenerateKey(true, key_code)); |
| 262 handler->HandleKeyEvent(ev.get()); | 262 handler->HandleKeyEvent(ev.get()); |
| 263 ev.reset(GenerateKey(false, key_code)); | 263 ev.reset(GenerateKey(false, key_code)); |
| 264 handler->HandleKeyEvent(ev.get()); | 264 handler->HandleKeyEvent(ev.get()); |
| 265 } | 265 } |
| 266 | 266 |
| 267 void SendActivateStickyKeyPattern(aura::RootWindowHostDelegate* delegate, | 267 void SendActivateStickyKeyPattern(aura::WindowTreeHostDelegate* delegate, |
| 268 ui::KeyboardCode key_code) { | 268 ui::KeyboardCode key_code) { |
| 269 scoped_ptr<ui::KeyEvent> ev; | 269 scoped_ptr<ui::KeyEvent> ev; |
| 270 ev.reset(GenerateKey(true, key_code)); | 270 ev.reset(GenerateKey(true, key_code)); |
| 271 delegate->OnHostKeyEvent(ev.get()); | 271 delegate->OnHostKeyEvent(ev.get()); |
| 272 ev.reset(GenerateKey(false, key_code)); | 272 ev.reset(GenerateKey(false, key_code)); |
| 273 delegate->OnHostKeyEvent(ev.get()); | 273 delegate->OnHostKeyEvent(ev.get()); |
| 274 } | 274 } |
| 275 | 275 |
| 276 aura::Window* target() { return target_; } | 276 aura::Window* target() { return target_; } |
| 277 | 277 |
| (...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 785 mev.reset(GenerateSynthesizedMouseEvent(false)); | 785 mev.reset(GenerateSynthesizedMouseEvent(false)); |
| 786 sticky_key.HandleMouseEvent(mev.get()); | 786 sticky_key.HandleMouseEvent(mev.get()); |
| 787 EXPECT_TRUE(mev->flags() & ui::EF_CONTROL_DOWN); | 787 EXPECT_TRUE(mev->flags() & ui::EF_CONTROL_DOWN); |
| 788 EXPECT_EQ(StickyKeysHandler::DISABLED, sticky_key.current_state()); | 788 EXPECT_EQ(StickyKeysHandler::DISABLED, sticky_key.current_state()); |
| 789 } | 789 } |
| 790 | 790 |
| 791 TEST_F(StickyKeysTest, KeyEventDispatchImpl) { | 791 TEST_F(StickyKeysTest, KeyEventDispatchImpl) { |
| 792 // Test the actual key event dispatch implementation. | 792 // Test the actual key event dispatch implementation. |
| 793 EventBuffer buffer; | 793 EventBuffer buffer; |
| 794 ScopedVector<ui::Event> events; | 794 ScopedVector<ui::Event> events; |
| 795 aura::RootWindowHostDelegate* delegate = Shell::GetPrimaryRootWindow() | 795 aura::WindowTreeHostDelegate* delegate = Shell::GetPrimaryRootWindow() |
| 796 ->GetDispatcher()->AsRootWindowHostDelegate(); | 796 ->GetDispatcher()->AsWindowTreeHostDelegate(); |
| 797 Shell::GetInstance()->AddPreTargetHandler(&buffer); | 797 Shell::GetInstance()->AddPreTargetHandler(&buffer); |
| 798 Shell::GetInstance()->sticky_keys_controller()->Enable(true); | 798 Shell::GetInstance()->sticky_keys_controller()->Enable(true); |
| 799 | 799 |
| 800 SendActivateStickyKeyPattern(delegate, ui::VKEY_CONTROL); | 800 SendActivateStickyKeyPattern(delegate, ui::VKEY_CONTROL); |
| 801 scoped_ptr<ui::KeyEvent> ev; | 801 scoped_ptr<ui::KeyEvent> ev; |
| 802 buffer.PopEvents(&events); | 802 buffer.PopEvents(&events); |
| 803 | 803 |
| 804 // Test key press event is correctly modified and modifier release | 804 // Test key press event is correctly modified and modifier release |
| 805 // event is sent. | 805 // event is sent. |
| 806 ev.reset(GenerateKey(true, ui::VKEY_C)); | 806 ev.reset(GenerateKey(true, ui::VKEY_C)); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 824 static_cast<ui::KeyEvent*>(events[0])->key_code()); | 824 static_cast<ui::KeyEvent*>(events[0])->key_code()); |
| 825 EXPECT_FALSE(events[0]->flags() & ui::EF_CONTROL_DOWN); | 825 EXPECT_FALSE(events[0]->flags() & ui::EF_CONTROL_DOWN); |
| 826 | 826 |
| 827 Shell::GetInstance()->RemovePreTargetHandler(&buffer); | 827 Shell::GetInstance()->RemovePreTargetHandler(&buffer); |
| 828 } | 828 } |
| 829 | 829 |
| 830 TEST_F(StickyKeysTest, MouseEventDispatchImpl) { | 830 TEST_F(StickyKeysTest, MouseEventDispatchImpl) { |
| 831 // Test the actual sticky mouse event dispatch implementation. | 831 // Test the actual sticky mouse event dispatch implementation. |
| 832 EventBuffer buffer; | 832 EventBuffer buffer; |
| 833 ScopedVector<ui::Event> events; | 833 ScopedVector<ui::Event> events; |
| 834 aura::RootWindowHostDelegate* delegate = Shell::GetPrimaryRootWindow() | 834 aura::WindowTreeHostDelegate* delegate = Shell::GetPrimaryRootWindow() |
| 835 ->GetDispatcher()->AsRootWindowHostDelegate(); | 835 ->GetDispatcher()->AsWindowTreeHostDelegate(); |
| 836 Shell::GetInstance()->AddPreTargetHandler(&buffer); | 836 Shell::GetInstance()->AddPreTargetHandler(&buffer); |
| 837 Shell::GetInstance()->sticky_keys_controller()->Enable(true); | 837 Shell::GetInstance()->sticky_keys_controller()->Enable(true); |
| 838 | 838 |
| 839 scoped_ptr<ui::MouseEvent> ev; | 839 scoped_ptr<ui::MouseEvent> ev; |
| 840 SendActivateStickyKeyPattern(delegate, ui::VKEY_CONTROL); | 840 SendActivateStickyKeyPattern(delegate, ui::VKEY_CONTROL); |
| 841 buffer.PopEvents(&events); | 841 buffer.PopEvents(&events); |
| 842 | 842 |
| 843 // Test mouse press event is correctly modified. | 843 // Test mouse press event is correctly modified. |
| 844 ev.reset(GenerateMouseEvent(true)); | 844 ev.reset(GenerateMouseEvent(true)); |
| 845 delegate->OnHostMouseEvent(ev.get()); | 845 delegate->OnHostMouseEvent(ev.get()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 860 EXPECT_EQ(ui::VKEY_CONTROL, | 860 EXPECT_EQ(ui::VKEY_CONTROL, |
| 861 static_cast<ui::KeyEvent*>(events[1])->key_code()); | 861 static_cast<ui::KeyEvent*>(events[1])->key_code()); |
| 862 | 862 |
| 863 Shell::GetInstance()->RemovePreTargetHandler(&buffer); | 863 Shell::GetInstance()->RemovePreTargetHandler(&buffer); |
| 864 } | 864 } |
| 865 | 865 |
| 866 TEST_F(StickyKeysTest, MouseWheelEventDispatchImpl) { | 866 TEST_F(StickyKeysTest, MouseWheelEventDispatchImpl) { |
| 867 // Test the actual mouse wheel event dispatch implementation. | 867 // Test the actual mouse wheel event dispatch implementation. |
| 868 EventBuffer buffer; | 868 EventBuffer buffer; |
| 869 ScopedVector<ui::Event> events; | 869 ScopedVector<ui::Event> events; |
| 870 aura::RootWindowHostDelegate* delegate = Shell::GetPrimaryRootWindow() | 870 aura::WindowTreeHostDelegate* delegate = Shell::GetPrimaryRootWindow() |
| 871 ->GetDispatcher()->AsRootWindowHostDelegate(); | 871 ->GetDispatcher()->AsWindowTreeHostDelegate(); |
| 872 Shell::GetInstance()->AddPreTargetHandler(&buffer); | 872 Shell::GetInstance()->AddPreTargetHandler(&buffer); |
| 873 Shell::GetInstance()->sticky_keys_controller()->Enable(true); | 873 Shell::GetInstance()->sticky_keys_controller()->Enable(true); |
| 874 | 874 |
| 875 scoped_ptr<ui::MouseWheelEvent> ev; | 875 scoped_ptr<ui::MouseWheelEvent> ev; |
| 876 SendActivateStickyKeyPattern(delegate, ui::VKEY_CONTROL); | 876 SendActivateStickyKeyPattern(delegate, ui::VKEY_CONTROL); |
| 877 buffer.PopEvents(&events); | 877 buffer.PopEvents(&events); |
| 878 | 878 |
| 879 // Test positive mouse wheel event is correctly modified and modifier release | 879 // Test positive mouse wheel event is correctly modified and modifier release |
| 880 // event is sent. | 880 // event is sent. |
| 881 ev.reset(GenerateMouseWheelEvent(ui::MouseWheelEvent::kWheelDelta)); | 881 ev.reset(GenerateMouseWheelEvent(ui::MouseWheelEvent::kWheelDelta)); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 904 static_cast<ui::MouseWheelEvent*>(events[0])->y_offset()); | 904 static_cast<ui::MouseWheelEvent*>(events[0])->y_offset()); |
| 905 EXPECT_TRUE(events[0]->flags() & ui::EF_CONTROL_DOWN); | 905 EXPECT_TRUE(events[0]->flags() & ui::EF_CONTROL_DOWN); |
| 906 EXPECT_EQ(ui::ET_KEY_RELEASED, events[1]->type()); | 906 EXPECT_EQ(ui::ET_KEY_RELEASED, events[1]->type()); |
| 907 EXPECT_EQ(ui::VKEY_CONTROL, | 907 EXPECT_EQ(ui::VKEY_CONTROL, |
| 908 static_cast<ui::KeyEvent*>(events[1])->key_code()); | 908 static_cast<ui::KeyEvent*>(events[1])->key_code()); |
| 909 | 909 |
| 910 Shell::GetInstance()->RemovePreTargetHandler(&buffer); | 910 Shell::GetInstance()->RemovePreTargetHandler(&buffer); |
| 911 } | 911 } |
| 912 | 912 |
| 913 } // namespace ash | 913 } // namespace ash |
| OLD | NEW |