| 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 "ui/base/accelerators/accelerator.h" | 7 #include "ui/base/accelerators/accelerator.h" |
| 8 #include "ui/views/controls/button/label_button.h" | 8 #include "ui/views/controls/button/label_button.h" |
| 9 #include "ui/views/layout/fill_layout.h" | 9 #include "ui/views/layout/fill_layout.h" |
| 10 #include "ui/views/test/views_test_base.h" | 10 #include "ui/views/test/views_test_base.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 LabelButton* second_child_button() const { | 28 LabelButton* second_child_button() const { |
| 29 return second_child_button_.get(); | 29 return second_child_button_.get(); |
| 30 } | 30 } |
| 31 LabelButton* third_child_button() const { return third_child_button_.get(); } | 31 LabelButton* third_child_button() const { return third_child_button_.get(); } |
| 32 LabelButton* not_child_button() const { return not_child_button_.get(); } | 32 LabelButton* not_child_button() const { return not_child_button_.get(); } |
| 33 | 33 |
| 34 View* GetDefaultFocusableChild() override; | 34 View* GetDefaultFocusableChild() override; |
| 35 | 35 |
| 36 private: | 36 private: |
| 37 void Init(); | 37 void Init(); |
| 38 LabelButton* CreateButton(bool add); |
| 38 | 39 |
| 39 scoped_ptr<LabelButton> child_button_; | 40 scoped_ptr<LabelButton> child_button_; |
| 40 scoped_ptr<LabelButton> second_child_button_; | 41 scoped_ptr<LabelButton> second_child_button_; |
| 41 scoped_ptr<LabelButton> third_child_button_; | 42 scoped_ptr<LabelButton> third_child_button_; |
| 42 scoped_ptr<LabelButton> not_child_button_; | 43 scoped_ptr<LabelButton> not_child_button_; |
| 43 | 44 |
| 44 DISALLOW_COPY_AND_ASSIGN(TestBarView); | 45 DISALLOW_COPY_AND_ASSIGN(TestBarView); |
| 45 }; | 46 }; |
| 46 | 47 |
| 47 TestBarView::TestBarView() { | 48 TestBarView::TestBarView() { |
| 48 Init(); | 49 Init(); |
| 49 set_allow_deactivate_on_esc(true); | 50 set_allow_deactivate_on_esc(true); |
| 50 } | 51 } |
| 51 | 52 |
| 52 TestBarView::~TestBarView() {} | 53 TestBarView::~TestBarView() {} |
| 53 | 54 |
| 54 void TestBarView::ButtonPressed(Button* sender, const ui::Event& event) { | 55 void TestBarView::ButtonPressed(Button* sender, const ui::Event& event) { |
| 55 } | 56 } |
| 56 | 57 |
| 57 void TestBarView::Init() { | 58 void TestBarView::Init() { |
| 58 SetLayoutManager(new FillLayout()); | 59 SetLayoutManager(new FillLayout()); |
| 59 base::string16 label; | 60 child_button_.reset(CreateButton(true)); |
| 60 child_button_.reset(new LabelButton(this, label)); | 61 second_child_button_.reset(CreateButton(true)); |
| 61 AddChildView(child_button_.get()); | 62 third_child_button_.reset(CreateButton(true)); |
| 62 second_child_button_.reset(new LabelButton(this, label)); | 63 not_child_button_.reset(CreateButton(false)); |
| 63 AddChildView(second_child_button_.get()); | 64 } |
| 64 third_child_button_.reset(new LabelButton(this, label)); | 65 |
| 65 AddChildView(third_child_button_.get()); | 66 LabelButton* TestBarView::CreateButton(bool add) { |
| 66 not_child_button_.reset(new LabelButton(this, label)); | 67 LabelButton* button = new LabelButton(this); |
| 68 button->InitAsTextbutton(base::string16()); |
| 69 if (add) |
| 70 AddChildView(button); |
| 71 return button; |
| 67 } | 72 } |
| 68 | 73 |
| 69 View* TestBarView::GetDefaultFocusableChild() { | 74 View* TestBarView::GetDefaultFocusableChild() { |
| 70 return child_button_.get(); | 75 return child_button_.get(); |
| 71 } | 76 } |
| 72 | 77 |
| 73 TEST_F(AccessiblePaneViewTest, SimpleSetPaneFocus) { | 78 TEST_F(AccessiblePaneViewTest, SimpleSetPaneFocus) { |
| 74 TestBarView* test_view = new TestBarView(); | 79 TestBarView* test_view = new TestBarView(); |
| 75 scoped_ptr<Widget> widget(new Widget()); | 80 scoped_ptr<Widget> widget(new Widget()); |
| 76 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); | 81 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 test_view->GetWidget()->GetFocusManager()->GetFocusedView()); | 219 test_view->GetWidget()->GetFocusManager()->GetFocusedView()); |
| 215 | 220 |
| 216 // ESC | 221 // ESC |
| 217 test_view->AcceleratorPressed(test_view->escape_key()); | 222 test_view->AcceleratorPressed(test_view->escape_key()); |
| 218 EXPECT_EQ(original_test_view->third_child_button(), | 223 EXPECT_EQ(original_test_view->third_child_button(), |
| 219 test_view->GetWidget()->GetFocusManager()->GetFocusedView()); | 224 test_view->GetWidget()->GetFocusManager()->GetFocusedView()); |
| 220 widget->CloseNow(); | 225 widget->CloseNow(); |
| 221 widget.reset(); | 226 widget.reset(); |
| 222 } | 227 } |
| 223 } // namespace views | 228 } // namespace views |
| OLD | NEW |