| OLD | NEW |
| 1 // Copyright (c) 2011 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 // This functionality currently works on Windows and on Linux when | 5 // This functionality currently works on Windows and on Linux when |
| 6 // toolkit_views is defined (i.e. for Chrome OS). It's not needed | 6 // toolkit_views is defined (i.e. for Chrome OS). It's not needed |
| 7 // on the Mac, and it's not yet implemented on Linux. | 7 // on the Mac, and it's not yet implemented on Linux. |
| 8 #if defined(TOOLKIT_VIEWS) | 8 #if defined(TOOLKIT_VIEWS) |
| 9 | 9 |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 23 #include "ui/views/focus/focus_manager.h" | 23 #include "ui/views/focus/focus_manager.h" |
| 24 #include "ui/views/view.h" | 24 #include "ui/views/view.h" |
| 25 #include "ui/views/widget/widget.h" | 25 #include "ui/views/widget/widget.h" |
| 26 | 26 |
| 27 namespace { | 27 namespace { |
| 28 | 28 |
| 29 // An async version of SendKeyPressSync since we don't get notified when a | 29 // An async version of SendKeyPressSync since we don't get notified when a |
| 30 // menu is showing. | 30 // menu is showing. |
| 31 void SendKeyPress(Browser* browser, ui::KeyboardCode key) { | 31 void SendKeyPress(Browser* browser, ui::KeyboardCode key) { |
| 32 ASSERT_TRUE(ui_controls::SendKeyPress( | 32 ASSERT_TRUE(ui_controls::SendKeyPress( |
| 33 browser->window()->GetNativeHandle(), key, false, false, false, false)); | 33 browser->window()->GetNativeWindow(), key, false, false, false, false)); |
| 34 } | 34 } |
| 35 | 35 |
| 36 // Helper class that waits until the focus has changed to a view other | 36 // Helper class that waits until the focus has changed to a view other |
| 37 // than the one with the provided view id. | 37 // than the one with the provided view id. |
| 38 class ViewFocusChangeWaiter : public views::FocusChangeListener { | 38 class ViewFocusChangeWaiter : public views::FocusChangeListener { |
| 39 public: | 39 public: |
| 40 ViewFocusChangeWaiter(views::FocusManager* focus_manager, | 40 ViewFocusChangeWaiter(views::FocusManager* focus_manager, |
| 41 int previous_view_id) | 41 int previous_view_id) |
| 42 : focus_manager_(focus_manager), | 42 : focus_manager_(focus_manager), |
| 43 previous_view_id_(previous_view_id), | 43 previous_view_id_(previous_view_id), |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 // Use the keyboard to select "New Tab" from the app menu. | 109 // Use the keyboard to select "New Tab" from the app menu. |
| 110 // This test depends on the fact that there is one menu and that | 110 // This test depends on the fact that there is one menu and that |
| 111 // New Tab is the first item in the menu. If the menus change, | 111 // New Tab is the first item in the menu. If the menus change, |
| 112 // this test will need to be changed to reflect that. | 112 // this test will need to be changed to reflect that. |
| 113 // | 113 // |
| 114 // If alternate_key_sequence is true, use "Alt" instead of "F10" to | 114 // If alternate_key_sequence is true, use "Alt" instead of "F10" to |
| 115 // open the menu bar, and "Down" instead of "Enter" to open a menu. | 115 // open the menu bar, and "Down" instead of "Enter" to open a menu. |
| 116 void TestMenuKeyboardAccess(bool alternate_key_sequence, bool shift); | 116 void TestMenuKeyboardAccess(bool alternate_key_sequence, bool shift); |
| 117 | 117 |
| 118 int GetFocusedViewID() { | 118 int GetFocusedViewID() { |
| 119 gfx::NativeWindow window = browser()->window()->GetNativeHandle(); | 119 gfx::NativeWindow window = browser()->window()->GetNativeWindow(); |
| 120 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window); | 120 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window); |
| 121 const views::FocusManager* focus_manager = widget->GetFocusManager(); | 121 const views::FocusManager* focus_manager = widget->GetFocusManager(); |
| 122 const views::View* focused_view = focus_manager->GetFocusedView(); | 122 const views::View* focused_view = focus_manager->GetFocusedView(); |
| 123 return focused_view ? focused_view->id() : -1; | 123 return focused_view ? focused_view->id() : -1; |
| 124 } | 124 } |
| 125 | 125 |
| 126 void WaitForFocusedViewIDToChange(int original_view_id) { | 126 void WaitForFocusedViewIDToChange(int original_view_id) { |
| 127 if (GetFocusedViewID() != original_view_id) | 127 if (GetFocusedViewID() != original_view_id) |
| 128 return; | 128 return; |
| 129 gfx::NativeWindow window = browser()->window()->GetNativeHandle(); | 129 gfx::NativeWindow window = browser()->window()->GetNativeWindow(); |
| 130 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window); | 130 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window); |
| 131 views::FocusManager* focus_manager = widget->GetFocusManager(); | 131 views::FocusManager* focus_manager = widget->GetFocusManager(); |
| 132 ViewFocusChangeWaiter waiter(focus_manager, original_view_id); | 132 ViewFocusChangeWaiter waiter(focus_manager, original_view_id); |
| 133 waiter.Wait(); | 133 waiter.Wait(); |
| 134 } | 134 } |
| 135 | 135 |
| 136 DISALLOW_COPY_AND_ASSIGN(KeyboardAccessTest); | 136 DISALLOW_COPY_AND_ASSIGN(KeyboardAccessTest); |
| 137 }; | 137 }; |
| 138 | 138 |
| 139 void KeyboardAccessTest::TestMenuKeyboardAccess(bool alternate_key_sequence, | 139 void KeyboardAccessTest::TestMenuKeyboardAccess(bool alternate_key_sequence, |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 ASSERT_EQ(2, browser()->active_index()); | 248 ASSERT_EQ(2, browser()->active_index()); |
| 249 | 249 |
| 250 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | 250 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
| 251 browser(), ui::VKEY_W, true, false, false, false)); | 251 browser(), ui::VKEY_W, true, false, false, false)); |
| 252 ASSERT_EQ(0, browser()->active_index()); | 252 ASSERT_EQ(0, browser()->active_index()); |
| 253 } | 253 } |
| 254 | 254 |
| 255 } // namespace | 255 } // namespace |
| 256 | 256 |
| 257 #endif // defined(TOOLKIT_VIEWS) | 257 #endif // defined(TOOLKIT_VIEWS) |
| OLD | NEW |