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 <utility> | 5 #include <utility> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "ui/base/accelerators/accelerator.h" | 9 #include "ui/base/accelerators/accelerator.h" |
10 #include "ui/base/keycodes/keyboard_codes.h" | 10 #include "ui/base/keycodes/keyboard_codes.h" |
11 #include "ui/views/controls/button/text_button.h" | 11 #include "ui/views/controls/button/text_button.h" |
12 #include "ui/views/controls/textfield/textfield.h" | 12 #include "ui/views/controls/textfield/textfield.h" |
13 #include "ui/views/focus/accelerator_handler.h" | 13 #include "ui/views/focus/accelerator_handler.h" |
14 #include "ui/views/focus/focus_manager_factory.h" | 14 #include "ui/views/focus/focus_manager_factory.h" |
15 #include "ui/views/focus/focus_manager_test.h" | 15 #include "ui/views/focus/focus_manager_test.h" |
16 #include "ui/views/focus/widget_focus_manager.h" | 16 #include "ui/views/focus/widget_focus_manager.h" |
17 #include "ui/views/widget/widget.h" | 17 #include "ui/views/widget/widget.h" |
18 | 18 |
19 #if defined(USE_AURA) | 19 #if defined(USE_AURA) |
20 #include "ui/aura/client/focus_client.h" | 20 #include "ui/aura/client/focus_client.h" |
21 #include "ui/aura/window.h" | 21 #include "ui/aura/window.h" |
| 22 #else |
| 23 #include "ui/views/controls/tabbed_pane/native_tabbed_pane_wrapper.h" |
| 24 #include "ui/views/controls/tabbed_pane/tabbed_pane.h" |
22 #endif | 25 #endif |
23 | 26 |
24 namespace views { | 27 namespace views { |
25 | 28 |
26 void FocusNativeView(gfx::NativeView view) { | 29 void FocusNativeView(gfx::NativeView view) { |
27 #if defined(USE_AURA) | 30 #if defined(USE_AURA) |
28 aura::client::GetFocusClient(view)->FocusWindow(view); | 31 aura::client::GetFocusClient(view)->FocusWindow(view); |
29 #elif defined(OS_WIN) | 32 #elif defined(OS_WIN) |
30 SetFocus(view); | 33 SetFocus(view); |
31 #else | 34 #else |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 | 168 |
166 #if !defined(USE_AURA) | 169 #if !defined(USE_AURA) |
167 class TestTextfield : public Textfield { | 170 class TestTextfield : public Textfield { |
168 public: | 171 public: |
169 TestTextfield() {} | 172 TestTextfield() {} |
170 virtual gfx::NativeView TestGetNativeControlView() { | 173 virtual gfx::NativeView TestGetNativeControlView() { |
171 return native_wrapper_->GetTestingHandle(); | 174 return native_wrapper_->GetTestingHandle(); |
172 } | 175 } |
173 }; | 176 }; |
174 | 177 |
| 178 class TestTabbedPane : public TabbedPane { |
| 179 public: |
| 180 TestTabbedPane() {} |
| 181 virtual gfx::NativeView TestGetNativeControlView() { |
| 182 return native_tabbed_pane_->GetTestingHandle(); |
| 183 } |
| 184 }; |
| 185 |
175 // Tests that NativeControls do set the focused View appropriately on the | 186 // Tests that NativeControls do set the focused View appropriately on the |
176 // FocusManager. | 187 // FocusManager. |
177 TEST_F(FocusManagerTest, DISABLED_FocusNativeControls) { | 188 TEST_F(FocusManagerTest, DISABLED_FocusNativeControls) { |
178 TestTextfield* textfield = new TestTextfield(); | 189 TestTextfield* textfield = new TestTextfield(); |
| 190 TestTabbedPane* tabbed_pane = new TestTabbedPane(); |
| 191 tabbed_pane->set_use_native_win_control(true); |
| 192 TestTextfield* textfield2 = new TestTextfield(); |
| 193 |
179 GetContentsView()->AddChildView(textfield); | 194 GetContentsView()->AddChildView(textfield); |
| 195 GetContentsView()->AddChildView(tabbed_pane); |
| 196 |
| 197 tabbed_pane->AddTab(ASCIIToUTF16("Awesome textfield"), textfield2); |
| 198 |
180 // Simulate the native view getting the native focus (such as by user click). | 199 // Simulate the native view getting the native focus (such as by user click). |
181 FocusNativeView(textfield->TestGetNativeControlView()); | 200 FocusNativeView(textfield->TestGetNativeControlView()); |
182 EXPECT_EQ(textfield, GetFocusManager()->GetFocusedView()); | 201 EXPECT_EQ(textfield, GetFocusManager()->GetFocusedView()); |
| 202 |
| 203 FocusNativeView(tabbed_pane->TestGetNativeControlView()); |
| 204 EXPECT_EQ(tabbed_pane, GetFocusManager()->GetFocusedView()); |
| 205 |
| 206 FocusNativeView(textfield2->TestGetNativeControlView()); |
| 207 EXPECT_EQ(textfield2, GetFocusManager()->GetFocusedView()); |
| 208 } |
| 209 #endif |
| 210 |
| 211 // There is no tabbed pane in Aura. |
| 212 #if !defined(USE_AURA) |
| 213 TEST_F(FocusManagerTest, ContainsView) { |
| 214 View* view = new View(); |
| 215 scoped_ptr<View> detached_view(new View()); |
| 216 TabbedPane* tabbed_pane = new TabbedPane(); |
| 217 tabbed_pane->set_use_native_win_control(true); |
| 218 TabbedPane* nested_tabbed_pane = new TabbedPane(); |
| 219 nested_tabbed_pane->set_use_native_win_control(true); |
| 220 NativeTextButton* tab_button = new NativeTextButton( |
| 221 NULL, ASCIIToUTF16("tab button")); |
| 222 |
| 223 GetContentsView()->AddChildView(view); |
| 224 GetContentsView()->AddChildView(tabbed_pane); |
| 225 // Adding a View inside a TabbedPane to test the case of nested root view. |
| 226 |
| 227 tabbed_pane->AddTab(ASCIIToUTF16("Awesome tab"), nested_tabbed_pane); |
| 228 nested_tabbed_pane->AddTab(ASCIIToUTF16("Awesomer tab"), tab_button); |
| 229 |
| 230 EXPECT_TRUE(GetFocusManager()->ContainsView(view)); |
| 231 EXPECT_TRUE(GetFocusManager()->ContainsView(tabbed_pane)); |
| 232 EXPECT_TRUE(GetFocusManager()->ContainsView(nested_tabbed_pane)); |
| 233 EXPECT_TRUE(GetFocusManager()->ContainsView(tab_button)); |
| 234 EXPECT_FALSE(GetFocusManager()->ContainsView(detached_view.get())); |
183 } | 235 } |
184 #endif | 236 #endif |
185 | 237 |
186 // Counts accelerator calls. | 238 // Counts accelerator calls. |
187 class TestAcceleratorTarget : public ui::AcceleratorTarget { | 239 class TestAcceleratorTarget : public ui::AcceleratorTarget { |
188 public: | 240 public: |
189 explicit TestAcceleratorTarget(bool process_accelerator) | 241 explicit TestAcceleratorTarget(bool process_accelerator) |
190 : accelerator_count_(0), | 242 : accelerator_count_(0), |
191 process_accelerator_(process_accelerator), | 243 process_accelerator_(process_accelerator), |
192 can_handle_accelerators_(true) {} | 244 can_handle_accelerators_(true) {} |
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
580 ViewsTestBase::TearDown(); | 632 ViewsTestBase::TearDown(); |
581 } | 633 } |
582 | 634 |
583 FocusManager* tracked_focus_manager_; | 635 FocusManager* tracked_focus_manager_; |
584 DtorTrackVector dtor_tracker_; | 636 DtorTrackVector dtor_tracker_; |
585 }; | 637 }; |
586 | 638 |
587 #if !defined(USE_AURA) | 639 #if !defined(USE_AURA) |
588 TEST_F(FocusManagerDtorTest, FocusManagerDestructedLast) { | 640 TEST_F(FocusManagerDtorTest, FocusManagerDestructedLast) { |
589 // Setup views hierarchy. | 641 // Setup views hierarchy. |
590 GetContentsView()->AddChildView(new TestTextfield()); | 642 TabbedPane* tabbed_pane = new TabbedPane(); |
591 GetContentsView()->AddChildView(new NativeButtonDtorTracked( | 643 tabbed_pane->set_use_native_win_control(true); |
592 ASCIIToUTF16("button"), &dtor_tracker_)); | 644 GetContentsView()->AddChildView(tabbed_pane); |
| 645 |
| 646 NativeButtonDtorTracked* button = new NativeButtonDtorTracked( |
| 647 ASCIIToUTF16("button"), &dtor_tracker_); |
| 648 tabbed_pane->AddTab(ASCIIToUTF16("Awesome tab"), button); |
593 | 649 |
594 // Close the window. | 650 // Close the window. |
595 GetWidget()->Close(); | 651 GetWidget()->Close(); |
596 RunPendingMessages(); | 652 RunPendingMessages(); |
597 | 653 |
598 // Test window, button and focus manager should all be destructed. | 654 // Test window, button and focus manager should all be destructed. |
599 ASSERT_EQ(3, static_cast<int>(dtor_tracker_.size())); | 655 ASSERT_EQ(3, static_cast<int>(dtor_tracker_.size())); |
600 | 656 |
601 // Focus manager should be the last one to destruct. | 657 // Focus manager should be the last one to destruct. |
602 ASSERT_STREQ("FocusManagerDtorTracked", dtor_tracker_[2].c_str()); | 658 ASSERT_STREQ("FocusManagerDtorTracked", dtor_tracker_[2].c_str()); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
640 views::View* v3 = new View; | 696 views::View* v3 = new View; |
641 v3->set_focusable(true); | 697 v3->set_focusable(true); |
642 GetContentsView()->AddChildView(v3); | 698 GetContentsView()->AddChildView(v3); |
643 | 699 |
644 v3->RequestFocus(); | 700 v3->RequestFocus(); |
645 GetWidget()->GetFocusManager()->AdvanceFocus(true); | 701 GetWidget()->GetFocusManager()->AdvanceFocus(true); |
646 EXPECT_TRUE(v1->HasFocus()); | 702 EXPECT_TRUE(v1->HasFocus()); |
647 } | 703 } |
648 | 704 |
649 } // namespace views | 705 } // namespace views |
OLD | NEW |