| 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 "ui/views/accessible_pane_view.h" | 5 #include "ui/views/accessible_pane_view.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
| 9 #include "ui/base/accelerators/accelerator.h" | 9 #include "ui/base/accelerators/accelerator.h" |
| 10 #include "ui/views/controls/button/label_button.h" | 10 #include "ui/views/controls/button/label_button.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 return second_child_button_.get(); | 31 return second_child_button_.get(); |
| 32 } | 32 } |
| 33 LabelButton* third_child_button() const { return third_child_button_.get(); } | 33 LabelButton* third_child_button() const { return third_child_button_.get(); } |
| 34 LabelButton* not_child_button() const { return not_child_button_.get(); } | 34 LabelButton* not_child_button() const { return not_child_button_.get(); } |
| 35 | 35 |
| 36 View* GetDefaultFocusableChild() override; | 36 View* GetDefaultFocusableChild() override; |
| 37 | 37 |
| 38 private: | 38 private: |
| 39 void Init(); | 39 void Init(); |
| 40 | 40 |
| 41 scoped_ptr<LabelButton> child_button_; | 41 std::unique_ptr<LabelButton> child_button_; |
| 42 scoped_ptr<LabelButton> second_child_button_; | 42 std::unique_ptr<LabelButton> second_child_button_; |
| 43 scoped_ptr<LabelButton> third_child_button_; | 43 std::unique_ptr<LabelButton> third_child_button_; |
| 44 scoped_ptr<LabelButton> not_child_button_; | 44 std::unique_ptr<LabelButton> not_child_button_; |
| 45 | 45 |
| 46 DISALLOW_COPY_AND_ASSIGN(TestBarView); | 46 DISALLOW_COPY_AND_ASSIGN(TestBarView); |
| 47 }; | 47 }; |
| 48 | 48 |
| 49 TestBarView::TestBarView() { | 49 TestBarView::TestBarView() { |
| 50 Init(); | 50 Init(); |
| 51 set_allow_deactivate_on_esc(true); | 51 set_allow_deactivate_on_esc(true); |
| 52 } | 52 } |
| 53 | 53 |
| 54 TestBarView::~TestBarView() {} | 54 TestBarView::~TestBarView() {} |
| (...skipping 12 matching lines...) Expand all Loading... |
| 67 AddChildView(third_child_button_.get()); | 67 AddChildView(third_child_button_.get()); |
| 68 not_child_button_.reset(new LabelButton(this, label)); | 68 not_child_button_.reset(new LabelButton(this, label)); |
| 69 } | 69 } |
| 70 | 70 |
| 71 View* TestBarView::GetDefaultFocusableChild() { | 71 View* TestBarView::GetDefaultFocusableChild() { |
| 72 return child_button_.get(); | 72 return child_button_.get(); |
| 73 } | 73 } |
| 74 | 74 |
| 75 TEST_F(AccessiblePaneViewTest, SimpleSetPaneFocus) { | 75 TEST_F(AccessiblePaneViewTest, SimpleSetPaneFocus) { |
| 76 TestBarView* test_view = new TestBarView(); | 76 TestBarView* test_view = new TestBarView(); |
| 77 scoped_ptr<Widget> widget(new Widget()); | 77 std::unique_ptr<Widget> widget(new Widget()); |
| 78 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); | 78 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); |
| 79 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 79 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 80 params.bounds = gfx::Rect(50, 50, 650, 650); | 80 params.bounds = gfx::Rect(50, 50, 650, 650); |
| 81 widget->Init(params); | 81 widget->Init(params); |
| 82 View* root = widget->GetRootView(); | 82 View* root = widget->GetRootView(); |
| 83 root->AddChildView(test_view); | 83 root->AddChildView(test_view); |
| 84 widget->Show(); | 84 widget->Show(); |
| 85 widget->Activate(); | 85 widget->Activate(); |
| 86 | 86 |
| 87 // Set pane focus succeeds, focus on child. | 87 // Set pane focus succeeds, focus on child. |
| 88 EXPECT_TRUE(test_view->SetPaneFocusAndFocusDefault()); | 88 EXPECT_TRUE(test_view->SetPaneFocusAndFocusDefault()); |
| 89 EXPECT_EQ(test_view, test_view->GetPaneFocusTraversable()); | 89 EXPECT_EQ(test_view, test_view->GetPaneFocusTraversable()); |
| 90 EXPECT_EQ(test_view->child_button(), | 90 EXPECT_EQ(test_view->child_button(), |
| 91 test_view->GetWidget()->GetFocusManager()->GetFocusedView()); | 91 test_view->GetWidget()->GetFocusManager()->GetFocusedView()); |
| 92 | 92 |
| 93 // Set focus on non child view, focus failed, stays on pane. | 93 // Set focus on non child view, focus failed, stays on pane. |
| 94 EXPECT_TRUE(test_view->SetPaneFocus(test_view->not_child_button())); | 94 EXPECT_TRUE(test_view->SetPaneFocus(test_view->not_child_button())); |
| 95 EXPECT_FALSE(test_view->not_child_button() == | 95 EXPECT_FALSE(test_view->not_child_button() == |
| 96 test_view->GetWidget()->GetFocusManager()->GetFocusedView()); | 96 test_view->GetWidget()->GetFocusManager()->GetFocusedView()); |
| 97 EXPECT_EQ(test_view->child_button(), | 97 EXPECT_EQ(test_view->child_button(), |
| 98 test_view->GetWidget()->GetFocusManager()->GetFocusedView()); | 98 test_view->GetWidget()->GetFocusManager()->GetFocusedView()); |
| 99 widget->CloseNow(); | 99 widget->CloseNow(); |
| 100 widget.reset(); | 100 widget.reset(); |
| 101 } | 101 } |
| 102 | 102 |
| 103 TEST_F(AccessiblePaneViewTest, SetPaneFocusAndRestore) { | 103 TEST_F(AccessiblePaneViewTest, SetPaneFocusAndRestore) { |
| 104 View* test_view_main = new View(); | 104 View* test_view_main = new View(); |
| 105 scoped_ptr<Widget> widget_main(new Widget()); | 105 std::unique_ptr<Widget> widget_main(new Widget()); |
| 106 Widget::InitParams params_main = CreateParams(Widget::InitParams::TYPE_POPUP); | 106 Widget::InitParams params_main = CreateParams(Widget::InitParams::TYPE_POPUP); |
| 107 params_main.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 107 params_main.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 108 // By default, TYPE_POPUP is not activatable. | 108 // By default, TYPE_POPUP is not activatable. |
| 109 params_main.activatable = Widget::InitParams::ACTIVATABLE_YES; | 109 params_main.activatable = Widget::InitParams::ACTIVATABLE_YES; |
| 110 params_main.bounds = gfx::Rect(0, 0, 20, 20); | 110 params_main.bounds = gfx::Rect(0, 0, 20, 20); |
| 111 widget_main->Init(params_main); | 111 widget_main->Init(params_main); |
| 112 View* root_main = widget_main->GetRootView(); | 112 View* root_main = widget_main->GetRootView(); |
| 113 root_main->AddChildView(test_view_main); | 113 root_main->AddChildView(test_view_main); |
| 114 widget_main->Activate(); | 114 widget_main->Activate(); |
| 115 test_view_main->GetFocusManager()->SetFocusedView(test_view_main); | 115 test_view_main->GetFocusManager()->SetFocusedView(test_view_main); |
| 116 EXPECT_TRUE(widget_main->IsActive()); | 116 EXPECT_TRUE(widget_main->IsActive()); |
| 117 EXPECT_TRUE(test_view_main->HasFocus()); | 117 EXPECT_TRUE(test_view_main->HasFocus()); |
| 118 | 118 |
| 119 TestBarView* test_view_bar = new TestBarView(); | 119 TestBarView* test_view_bar = new TestBarView(); |
| 120 scoped_ptr<Widget> widget_bar(new Widget()); | 120 std::unique_ptr<Widget> widget_bar(new Widget()); |
| 121 Widget::InitParams params_bar = CreateParams(Widget::InitParams::TYPE_POPUP); | 121 Widget::InitParams params_bar = CreateParams(Widget::InitParams::TYPE_POPUP); |
| 122 params_bar.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 122 params_bar.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 123 params_bar.activatable = Widget::InitParams::ACTIVATABLE_YES; | 123 params_bar.activatable = Widget::InitParams::ACTIVATABLE_YES; |
| 124 params_bar.bounds = gfx::Rect(50, 50, 650, 650); | 124 params_bar.bounds = gfx::Rect(50, 50, 650, 650); |
| 125 widget_bar->Init(params_bar); | 125 widget_bar->Init(params_bar); |
| 126 View* root_bar = widget_bar->GetRootView(); | 126 View* root_bar = widget_bar->GetRootView(); |
| 127 root_bar->AddChildView(test_view_bar); | 127 root_bar->AddChildView(test_view_bar); |
| 128 widget_bar->Show(); | 128 widget_bar->Show(); |
| 129 widget_bar->Activate(); | 129 widget_bar->Activate(); |
| 130 | 130 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 150 widget_bar->CloseNow(); | 150 widget_bar->CloseNow(); |
| 151 widget_bar.reset(); | 151 widget_bar.reset(); |
| 152 | 152 |
| 153 widget_main->CloseNow(); | 153 widget_main->CloseNow(); |
| 154 widget_main.reset(); | 154 widget_main.reset(); |
| 155 } | 155 } |
| 156 | 156 |
| 157 TEST_F(AccessiblePaneViewTest, TwoSetPaneFocus) { | 157 TEST_F(AccessiblePaneViewTest, TwoSetPaneFocus) { |
| 158 TestBarView* test_view = new TestBarView(); | 158 TestBarView* test_view = new TestBarView(); |
| 159 TestBarView* test_view_2 = new TestBarView(); | 159 TestBarView* test_view_2 = new TestBarView(); |
| 160 scoped_ptr<Widget> widget(new Widget()); | 160 std::unique_ptr<Widget> widget(new Widget()); |
| 161 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); | 161 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); |
| 162 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 162 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 163 params.bounds = gfx::Rect(50, 50, 650, 650); | 163 params.bounds = gfx::Rect(50, 50, 650, 650); |
| 164 widget->Init(params); | 164 widget->Init(params); |
| 165 View* root = widget->GetRootView(); | 165 View* root = widget->GetRootView(); |
| 166 root->AddChildView(test_view); | 166 root->AddChildView(test_view); |
| 167 root->AddChildView(test_view_2); | 167 root->AddChildView(test_view_2); |
| 168 widget->Show(); | 168 widget->Show(); |
| 169 widget->Activate(); | 169 widget->Activate(); |
| 170 | 170 |
| 171 // Set pane focus succeeds, focus on child. | 171 // Set pane focus succeeds, focus on child. |
| 172 EXPECT_TRUE(test_view->SetPaneFocusAndFocusDefault()); | 172 EXPECT_TRUE(test_view->SetPaneFocusAndFocusDefault()); |
| 173 EXPECT_EQ(test_view, test_view->GetPaneFocusTraversable()); | 173 EXPECT_EQ(test_view, test_view->GetPaneFocusTraversable()); |
| 174 EXPECT_EQ(test_view->child_button(), | 174 EXPECT_EQ(test_view->child_button(), |
| 175 test_view->GetWidget()->GetFocusManager()->GetFocusedView()); | 175 test_view->GetWidget()->GetFocusManager()->GetFocusedView()); |
| 176 | 176 |
| 177 // Set focus on another test_view, focus move to that pane. | 177 // Set focus on another test_view, focus move to that pane. |
| 178 EXPECT_TRUE(test_view_2->SetPaneFocus(test_view_2->second_child_button())); | 178 EXPECT_TRUE(test_view_2->SetPaneFocus(test_view_2->second_child_button())); |
| 179 EXPECT_FALSE(test_view->child_button() == | 179 EXPECT_FALSE(test_view->child_button() == |
| 180 test_view->GetWidget()->GetFocusManager()->GetFocusedView()); | 180 test_view->GetWidget()->GetFocusManager()->GetFocusedView()); |
| 181 EXPECT_EQ(test_view_2->second_child_button(), | 181 EXPECT_EQ(test_view_2->second_child_button(), |
| 182 test_view->GetWidget()->GetFocusManager()->GetFocusedView()); | 182 test_view->GetWidget()->GetFocusManager()->GetFocusedView()); |
| 183 widget->CloseNow(); | 183 widget->CloseNow(); |
| 184 widget.reset(); | 184 widget.reset(); |
| 185 } | 185 } |
| 186 | 186 |
| 187 TEST_F(AccessiblePaneViewTest, PaneFocusTraversal) { | 187 TEST_F(AccessiblePaneViewTest, PaneFocusTraversal) { |
| 188 TestBarView* test_view = new TestBarView(); | 188 TestBarView* test_view = new TestBarView(); |
| 189 TestBarView* original_test_view = new TestBarView(); | 189 TestBarView* original_test_view = new TestBarView(); |
| 190 scoped_ptr<Widget> widget(new Widget()); | 190 std::unique_ptr<Widget> widget(new Widget()); |
| 191 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); | 191 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); |
| 192 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 192 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 193 params.bounds = gfx::Rect(50, 50, 650, 650); | 193 params.bounds = gfx::Rect(50, 50, 650, 650); |
| 194 widget->Init(params); | 194 widget->Init(params); |
| 195 View* root = widget->GetRootView(); | 195 View* root = widget->GetRootView(); |
| 196 root->AddChildView(original_test_view); | 196 root->AddChildView(original_test_view); |
| 197 root->AddChildView(test_view); | 197 root->AddChildView(test_view); |
| 198 widget->Show(); | 198 widget->Show(); |
| 199 widget->Activate(); | 199 widget->Activate(); |
| 200 | 200 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 224 test_view->GetWidget()->GetFocusManager()->GetFocusedView()); | 224 test_view->GetWidget()->GetFocusManager()->GetFocusedView()); |
| 225 | 225 |
| 226 // ESC | 226 // ESC |
| 227 test_view->AcceleratorPressed(test_view->escape_key()); | 227 test_view->AcceleratorPressed(test_view->escape_key()); |
| 228 EXPECT_EQ(original_test_view->third_child_button(), | 228 EXPECT_EQ(original_test_view->third_child_button(), |
| 229 test_view->GetWidget()->GetFocusManager()->GetFocusedView()); | 229 test_view->GetWidget()->GetFocusManager()->GetFocusedView()); |
| 230 widget->CloseNow(); | 230 widget->CloseNow(); |
| 231 widget.reset(); | 231 widget.reset(); |
| 232 } | 232 } |
| 233 } // namespace views | 233 } // namespace views |
| OLD | NEW |