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 // 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 | 8 |
9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 int previous_view_id) | 44 int previous_view_id) |
45 : focus_manager_(focus_manager), | 45 : focus_manager_(focus_manager), |
46 previous_view_id_(previous_view_id), | 46 previous_view_id_(previous_view_id), |
47 weak_factory_(this) { | 47 weak_factory_(this) { |
48 focus_manager_->AddFocusChangeListener(this); | 48 focus_manager_->AddFocusChangeListener(this); |
49 // Call the focus change notification once in case the focus has | 49 // Call the focus change notification once in case the focus has |
50 // already changed. | 50 // already changed. |
51 OnWillChangeFocus(NULL, focus_manager_->GetFocusedView()); | 51 OnWillChangeFocus(NULL, focus_manager_->GetFocusedView()); |
52 } | 52 } |
53 | 53 |
54 virtual ~ViewFocusChangeWaiter() { | 54 ~ViewFocusChangeWaiter() override { |
55 focus_manager_->RemoveFocusChangeListener(this); | 55 focus_manager_->RemoveFocusChangeListener(this); |
56 } | 56 } |
57 | 57 |
58 void Wait() { | 58 void Wait() { |
59 content::RunMessageLoop(); | 59 content::RunMessageLoop(); |
60 } | 60 } |
61 | 61 |
62 private: | 62 private: |
63 // Inherited from FocusChangeListener | 63 // Inherited from FocusChangeListener |
64 virtual void OnWillChangeFocus(views::View* focused_before, | 64 void OnWillChangeFocus(views::View* focused_before, |
65 views::View* focused_now) override { | 65 views::View* focused_now) override {} |
66 } | |
67 | 66 |
68 virtual void OnDidChangeFocus(views::View* focused_before, | 67 void OnDidChangeFocus(views::View* focused_before, |
69 views::View* focused_now) override { | 68 views::View* focused_now) override { |
70 if (focused_now && focused_now->id() != previous_view_id_) { | 69 if (focused_now && focused_now->id() != previous_view_id_) { |
71 base::MessageLoop::current()->PostTask(FROM_HERE, | 70 base::MessageLoop::current()->PostTask(FROM_HERE, |
72 base::MessageLoop::QuitClosure()); | 71 base::MessageLoop::QuitClosure()); |
73 } | 72 } |
74 } | 73 } |
75 | 74 |
76 views::FocusManager* focus_manager_; | 75 views::FocusManager* focus_manager_; |
77 int previous_view_id_; | 76 int previous_view_id_; |
78 base::WeakPtrFactory<ViewFocusChangeWaiter> weak_factory_; | 77 base::WeakPtrFactory<ViewFocusChangeWaiter> weak_factory_; |
79 | 78 |
80 DISALLOW_COPY_AND_ASSIGN(ViewFocusChangeWaiter); | 79 DISALLOW_COPY_AND_ASSIGN(ViewFocusChangeWaiter); |
81 }; | 80 }; |
82 | 81 |
83 class SendKeysMenuListener : public views::MenuListener { | 82 class SendKeysMenuListener : public views::MenuListener { |
84 public: | 83 public: |
85 SendKeysMenuListener(ToolbarView* toolbar_view, | 84 SendKeysMenuListener(ToolbarView* toolbar_view, |
86 Browser* browser, | 85 Browser* browser, |
87 bool test_dismiss_menu) | 86 bool test_dismiss_menu) |
88 : toolbar_view_(toolbar_view), browser_(browser), menu_open_count_(0), | 87 : toolbar_view_(toolbar_view), browser_(browser), menu_open_count_(0), |
89 test_dismiss_menu_(test_dismiss_menu) { | 88 test_dismiss_menu_(test_dismiss_menu) { |
90 toolbar_view_->AddMenuListener(this); | 89 toolbar_view_->AddMenuListener(this); |
91 } | 90 } |
92 | 91 |
93 virtual ~SendKeysMenuListener() { | 92 ~SendKeysMenuListener() override { |
94 if (test_dismiss_menu_) | 93 if (test_dismiss_menu_) |
95 toolbar_view_->RemoveMenuListener(this); | 94 toolbar_view_->RemoveMenuListener(this); |
96 } | 95 } |
97 | 96 |
98 int menu_open_count() const { | 97 int menu_open_count() const { |
99 return menu_open_count_; | 98 return menu_open_count_; |
100 } | 99 } |
101 | 100 |
102 private: | 101 private: |
103 // Overridden from views::MenuListener: | 102 // Overridden from views::MenuListener: |
104 virtual void OnMenuOpened() override { | 103 void OnMenuOpened() override { |
105 menu_open_count_++; | 104 menu_open_count_++; |
106 if (!test_dismiss_menu_) { | 105 if (!test_dismiss_menu_) { |
107 toolbar_view_->RemoveMenuListener(this); | 106 toolbar_view_->RemoveMenuListener(this); |
108 // Press DOWN to select the first item, then RETURN to select it. | 107 // Press DOWN to select the first item, then RETURN to select it. |
109 SendKeyPress(browser_, ui::VKEY_DOWN); | 108 SendKeyPress(browser_, ui::VKEY_DOWN); |
110 SendKeyPress(browser_, ui::VKEY_RETURN); | 109 SendKeyPress(browser_, ui::VKEY_RETURN); |
111 } else { | 110 } else { |
112 SendKeyPress(browser_, ui::VKEY_ESCAPE); | 111 SendKeyPress(browser_, ui::VKEY_ESCAPE); |
113 base::MessageLoop::current()->PostDelayedTask( | 112 base::MessageLoop::current()->PostDelayedTask( |
114 FROM_HERE, | 113 FROM_HERE, |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 browser(), ui::VKEY_BROWSER_FORWARD, false, false, false, false)); | 432 browser(), ui::VKEY_BROWSER_FORWARD, false, false, false, false)); |
434 | 433 |
435 base::string16 after_forward; | 434 base::string16 after_forward; |
436 ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), &after_forward)); | 435 ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), &after_forward)); |
437 | 436 |
438 EXPECT_EQ(before_back, after_forward); | 437 EXPECT_EQ(before_back, after_forward); |
439 } | 438 } |
440 #endif | 439 #endif |
441 | 440 |
442 } // namespace | 441 } // namespace |
OLD | NEW |