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/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "ui/aura/client/focus_client.h" | |
10 #include "ui/aura/window.h" | |
9 #include "ui/base/accelerators/accelerator.h" | 11 #include "ui/base/accelerators/accelerator.h" |
10 #include "ui/events/keycodes/keyboard_codes.h" | 12 #include "ui/events/keycodes/keyboard_codes.h" |
11 #include "ui/views/accessible_pane_view.h" | 13 #include "ui/views/accessible_pane_view.h" |
12 #include "ui/views/controls/button/label_button.h" | 14 #include "ui/views/controls/button/label_button.h" |
13 #include "ui/views/controls/textfield/textfield.h" | 15 #include "ui/views/controls/textfield/textfield.h" |
14 #include "ui/views/focus/focus_manager_factory.h" | 16 #include "ui/views/focus/focus_manager_factory.h" |
15 #include "ui/views/focus/focus_manager_test.h" | 17 #include "ui/views/focus/focus_manager_test.h" |
16 #include "ui/views/focus/widget_focus_manager.h" | 18 #include "ui/views/focus/widget_focus_manager.h" |
17 #include "ui/views/widget/widget.h" | 19 #include "ui/views/widget/widget.h" |
18 | 20 |
19 #if defined(USE_AURA) | |
20 #include "ui/aura/client/focus_client.h" | |
21 #include "ui/aura/window.h" | |
22 #endif | |
23 | |
24 namespace views { | 21 namespace views { |
25 | 22 |
26 void FocusNativeView(gfx::NativeView view) { | 23 void FocusNativeView(gfx::NativeView view) { |
msw
2014/03/08 01:04:50
nit: this could be inlined for its two users.
sky
2014/03/08 01:30:28
Done.
| |
27 #if defined(USE_AURA) | |
28 aura::client::GetFocusClient(view)->FocusWindow(view); | 24 aura::client::GetFocusClient(view)->FocusWindow(view); |
29 #elif defined(OS_WIN) | |
30 SetFocus(view); | |
31 #else | |
32 #error | |
33 #endif | |
34 } | 25 } |
35 | 26 |
36 enum FocusTestEventType { | 27 enum FocusTestEventType { |
37 ON_FOCUS = 0, | 28 ON_FOCUS = 0, |
38 ON_BLUR | 29 ON_BLUR |
39 }; | 30 }; |
40 | 31 |
41 struct FocusTestEvent { | 32 struct FocusTestEvent { |
42 FocusTestEvent(FocusTestEventType type, int view_id) | 33 FocusTestEvent(FocusTestEventType type, int view_id) |
43 : type(type), | 34 : type(type), |
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
559 | 550 |
560 virtual void TearDown() { | 551 virtual void TearDown() { |
561 FocusManagerFactory::Install(NULL); | 552 FocusManagerFactory::Install(NULL); |
562 ViewsTestBase::TearDown(); | 553 ViewsTestBase::TearDown(); |
563 } | 554 } |
564 | 555 |
565 FocusManager* tracked_focus_manager_; | 556 FocusManager* tracked_focus_manager_; |
566 DtorTrackVector dtor_tracker_; | 557 DtorTrackVector dtor_tracker_; |
567 }; | 558 }; |
568 | 559 |
569 #if !defined(USE_AURA) | |
570 TEST_F(FocusManagerDtorTest, FocusManagerDestructedLast) { | |
571 // Setup views hierarchy. | |
572 GetContentsView()->AddChildView(new Textfield()); | |
573 GetContentsView()->AddChildView(new LabelButtonDtorTracked( | |
574 base::ASCIIToUTF16("button"), &dtor_tracker_)); | |
575 | |
576 // Close the window. | |
577 GetWidget()->Close(); | |
578 RunPendingMessages(); | |
579 | |
580 // Test window, button and focus manager should all be destructed. | |
581 ASSERT_EQ(3, static_cast<int>(dtor_tracker_.size())); | |
582 | |
583 // Focus manager should be the last one to destruct. | |
584 ASSERT_STREQ("FocusManagerDtorTracked", dtor_tracker_[2].c_str()); | |
585 } | |
586 #endif | |
587 | |
588 namespace { | 560 namespace { |
589 | 561 |
590 class FocusInAboutToRequestFocusFromTabTraversalView : public View { | 562 class FocusInAboutToRequestFocusFromTabTraversalView : public View { |
591 public: | 563 public: |
592 FocusInAboutToRequestFocusFromTabTraversalView() : view_to_focus_(NULL) {} | 564 FocusInAboutToRequestFocusFromTabTraversalView() : view_to_focus_(NULL) {} |
593 | 565 |
594 void set_view_to_focus(View* view) { view_to_focus_ = view; } | 566 void set_view_to_focus(View* view) { view_to_focus_ = view; } |
595 | 567 |
596 virtual void AboutToRequestFocusFromTabTraversal(bool reverse) OVERRIDE { | 568 virtual void AboutToRequestFocusFromTabTraversal(bool reverse) OVERRIDE { |
597 view_to_focus_->RequestFocus(); | 569 view_to_focus_->RequestFocus(); |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
884 EXPECT_EQ(view1, GetFocusManager()->GetFocusedView()); | 856 EXPECT_EQ(view1, GetFocusManager()->GetFocusedView()); |
885 | 857 |
886 // Allow focus to go to the parent, and focus backwards which should now move | 858 // Allow focus to go to the parent, and focus backwards which should now move |
887 // up |widget_view| (in the parent). | 859 // up |widget_view| (in the parent). |
888 delegate->set_should_advance_focus_to_parent(true); | 860 delegate->set_should_advance_focus_to_parent(true); |
889 GetFocusManager()->AdvanceFocus(true); | 861 GetFocusManager()->AdvanceFocus(true); |
890 EXPECT_EQ(widget_view, GetFocusManager()->GetFocusedView()); | 862 EXPECT_EQ(widget_view, GetFocusManager()->GetFocusedView()); |
891 } | 863 } |
892 | 864 |
893 } // namespace views | 865 } // namespace views |
OLD | NEW |