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/focus/focus_manager.h" | 5 #include "ui/views/focus/focus_manager.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 }; | 41 }; |
42 | 42 |
43 class SimpleTestView : public View { | 43 class SimpleTestView : public View { |
44 public: | 44 public: |
45 SimpleTestView(std::vector<FocusTestEvent>* event_list, int view_id) | 45 SimpleTestView(std::vector<FocusTestEvent>* event_list, int view_id) |
46 : event_list_(event_list) { | 46 : event_list_(event_list) { |
47 SetFocusable(true); | 47 SetFocusable(true); |
48 set_id(view_id); | 48 set_id(view_id); |
49 } | 49 } |
50 | 50 |
51 virtual void OnFocus() OVERRIDE { | 51 virtual void OnFocus() override { |
52 event_list_->push_back(FocusTestEvent(ON_FOCUS, id())); | 52 event_list_->push_back(FocusTestEvent(ON_FOCUS, id())); |
53 } | 53 } |
54 | 54 |
55 virtual void OnBlur() OVERRIDE { | 55 virtual void OnBlur() override { |
56 event_list_->push_back(FocusTestEvent(ON_BLUR, id())); | 56 event_list_->push_back(FocusTestEvent(ON_BLUR, id())); |
57 } | 57 } |
58 | 58 |
59 private: | 59 private: |
60 std::vector<FocusTestEvent>* event_list_; | 60 std::vector<FocusTestEvent>* event_list_; |
61 | 61 |
62 DISALLOW_COPY_AND_ASSIGN(SimpleTestView); | 62 DISALLOW_COPY_AND_ASSIGN(SimpleTestView); |
63 }; | 63 }; |
64 | 64 |
65 // Tests that the appropriate Focus related methods are called when a View | 65 // Tests that the appropriate Focus related methods are called when a View |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 } | 158 } |
159 | 159 |
160 // Counts accelerator calls. | 160 // Counts accelerator calls. |
161 class TestAcceleratorTarget : public ui::AcceleratorTarget { | 161 class TestAcceleratorTarget : public ui::AcceleratorTarget { |
162 public: | 162 public: |
163 explicit TestAcceleratorTarget(bool process_accelerator) | 163 explicit TestAcceleratorTarget(bool process_accelerator) |
164 : accelerator_count_(0), | 164 : accelerator_count_(0), |
165 process_accelerator_(process_accelerator), | 165 process_accelerator_(process_accelerator), |
166 can_handle_accelerators_(true) {} | 166 can_handle_accelerators_(true) {} |
167 | 167 |
168 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE { | 168 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) override { |
169 ++accelerator_count_; | 169 ++accelerator_count_; |
170 return process_accelerator_; | 170 return process_accelerator_; |
171 } | 171 } |
172 | 172 |
173 virtual bool CanHandleAccelerators() const OVERRIDE { | 173 virtual bool CanHandleAccelerators() const override { |
174 return can_handle_accelerators_; | 174 return can_handle_accelerators_; |
175 } | 175 } |
176 | 176 |
177 int accelerator_count() const { return accelerator_count_; } | 177 int accelerator_count() const { return accelerator_count_; } |
178 | 178 |
179 void set_can_handle_accelerators(bool can_handle_accelerators) { | 179 void set_can_handle_accelerators(bool can_handle_accelerators) { |
180 can_handle_accelerators_ = can_handle_accelerators; | 180 can_handle_accelerators_ = can_handle_accelerators; |
181 } | 181 } |
182 | 182 |
183 private: | 183 private: |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 // Unregisters itself when its accelerator is invoked. | 418 // Unregisters itself when its accelerator is invoked. |
419 class SelfUnregisteringAcceleratorTarget : public ui::AcceleratorTarget { | 419 class SelfUnregisteringAcceleratorTarget : public ui::AcceleratorTarget { |
420 public: | 420 public: |
421 SelfUnregisteringAcceleratorTarget(ui::Accelerator accelerator, | 421 SelfUnregisteringAcceleratorTarget(ui::Accelerator accelerator, |
422 FocusManager* focus_manager) | 422 FocusManager* focus_manager) |
423 : accelerator_(accelerator), | 423 : accelerator_(accelerator), |
424 focus_manager_(focus_manager), | 424 focus_manager_(focus_manager), |
425 accelerator_count_(0) { | 425 accelerator_count_(0) { |
426 } | 426 } |
427 | 427 |
428 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE { | 428 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) override { |
429 ++accelerator_count_; | 429 ++accelerator_count_; |
430 focus_manager_->UnregisterAccelerator(accelerator, this); | 430 focus_manager_->UnregisterAccelerator(accelerator, this); |
431 return true; | 431 return true; |
432 } | 432 } |
433 | 433 |
434 virtual bool CanHandleAccelerators() const OVERRIDE { | 434 virtual bool CanHandleAccelerators() const override { |
435 return true; | 435 return true; |
436 } | 436 } |
437 | 437 |
438 int accelerator_count() const { return accelerator_count_; } | 438 int accelerator_count() const { return accelerator_count_; } |
439 | 439 |
440 private: | 440 private: |
441 ui::Accelerator accelerator_; | 441 ui::Accelerator accelerator_; |
442 FocusManager* focus_manager_; | 442 FocusManager* focus_manager_; |
443 int accelerator_count_; | 443 int accelerator_count_; |
444 | 444 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 DISALLOW_COPY_AND_ASSIGN(FocusManagerDtorTracked); | 492 DISALLOW_COPY_AND_ASSIGN(FocusManagerDtorTracked); |
493 }; | 493 }; |
494 | 494 |
495 class TestFocusManagerFactory : public FocusManagerFactory { | 495 class TestFocusManagerFactory : public FocusManagerFactory { |
496 public: | 496 public: |
497 explicit TestFocusManagerFactory(DtorTrackVector* dtor_tracker) | 497 explicit TestFocusManagerFactory(DtorTrackVector* dtor_tracker) |
498 : dtor_tracker_(dtor_tracker) { | 498 : dtor_tracker_(dtor_tracker) { |
499 } | 499 } |
500 | 500 |
501 virtual FocusManager* CreateFocusManager(Widget* widget, | 501 virtual FocusManager* CreateFocusManager(Widget* widget, |
502 bool desktop_widget) OVERRIDE { | 502 bool desktop_widget) override { |
503 return new FocusManagerDtorTracked(widget, dtor_tracker_); | 503 return new FocusManagerDtorTracked(widget, dtor_tracker_); |
504 } | 504 } |
505 | 505 |
506 private: | 506 private: |
507 DtorTrackVector* dtor_tracker_; | 507 DtorTrackVector* dtor_tracker_; |
508 DISALLOW_COPY_AND_ASSIGN(TestFocusManagerFactory); | 508 DISALLOW_COPY_AND_ASSIGN(TestFocusManagerFactory); |
509 }; | 509 }; |
510 | 510 |
511 class LabelButtonDtorTracked : public LabelButton { | 511 class LabelButtonDtorTracked : public LabelButton { |
512 public: | 512 public: |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
561 }; | 561 }; |
562 | 562 |
563 namespace { | 563 namespace { |
564 | 564 |
565 class FocusInAboutToRequestFocusFromTabTraversalView : public View { | 565 class FocusInAboutToRequestFocusFromTabTraversalView : public View { |
566 public: | 566 public: |
567 FocusInAboutToRequestFocusFromTabTraversalView() : view_to_focus_(NULL) {} | 567 FocusInAboutToRequestFocusFromTabTraversalView() : view_to_focus_(NULL) {} |
568 | 568 |
569 void set_view_to_focus(View* view) { view_to_focus_ = view; } | 569 void set_view_to_focus(View* view) { view_to_focus_ = view; } |
570 | 570 |
571 virtual void AboutToRequestFocusFromTabTraversal(bool reverse) OVERRIDE { | 571 virtual void AboutToRequestFocusFromTabTraversal(bool reverse) override { |
572 view_to_focus_->RequestFocus(); | 572 view_to_focus_->RequestFocus(); |
573 } | 573 } |
574 | 574 |
575 private: | 575 private: |
576 views::View* view_to_focus_; | 576 views::View* view_to_focus_; |
577 | 577 |
578 DISALLOW_COPY_AND_ASSIGN(FocusInAboutToRequestFocusFromTabTraversalView); | 578 DISALLOW_COPY_AND_ASSIGN(FocusInAboutToRequestFocusFromTabTraversalView); |
579 }; | 579 }; |
580 } // namespace | 580 } // namespace |
581 | 581 |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
699 namespace { | 699 namespace { |
700 | 700 |
701 class FocusManagerArrowKeyTraversalTest : public FocusManagerTest { | 701 class FocusManagerArrowKeyTraversalTest : public FocusManagerTest { |
702 public: | 702 public: |
703 FocusManagerArrowKeyTraversalTest() | 703 FocusManagerArrowKeyTraversalTest() |
704 : previous_arrow_key_traversal_enabled_(false) { | 704 : previous_arrow_key_traversal_enabled_(false) { |
705 } | 705 } |
706 virtual ~FocusManagerArrowKeyTraversalTest() {} | 706 virtual ~FocusManagerArrowKeyTraversalTest() {} |
707 | 707 |
708 // FocusManagerTest overrides: | 708 // FocusManagerTest overrides: |
709 virtual void SetUp() OVERRIDE { | 709 virtual void SetUp() override { |
710 FocusManagerTest::SetUp(); | 710 FocusManagerTest::SetUp(); |
711 | 711 |
712 previous_arrow_key_traversal_enabled_ = | 712 previous_arrow_key_traversal_enabled_ = |
713 FocusManager::arrow_key_traversal_enabled(); | 713 FocusManager::arrow_key_traversal_enabled(); |
714 } | 714 } |
715 virtual void TearDown() OVERRIDE { | 715 virtual void TearDown() override { |
716 FocusManager::set_arrow_key_traversal_enabled( | 716 FocusManager::set_arrow_key_traversal_enabled( |
717 previous_arrow_key_traversal_enabled_); | 717 previous_arrow_key_traversal_enabled_); |
718 FocusManagerTest::TearDown(); | 718 FocusManagerTest::TearDown(); |
719 } | 719 } |
720 | 720 |
721 private: | 721 private: |
722 bool previous_arrow_key_traversal_enabled_; | 722 bool previous_arrow_key_traversal_enabled_; |
723 | 723 |
724 DISALLOW_COPY_AND_ASSIGN(FocusManagerArrowKeyTraversalTest); | 724 DISALLOW_COPY_AND_ASSIGN(FocusManagerArrowKeyTraversalTest); |
725 }; | 725 }; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
779 GetFocusManager()->StoreFocusedView(true); | 779 GetFocusManager()->StoreFocusedView(true); |
780 EXPECT_EQ(NULL, GetFocusManager()->GetFocusedView()); | 780 EXPECT_EQ(NULL, GetFocusManager()->GetFocusedView()); |
781 EXPECT_TRUE(GetFocusManager()->RestoreFocusedView()); | 781 EXPECT_TRUE(GetFocusManager()->RestoreFocusedView()); |
782 EXPECT_EQ(&view, GetFocusManager()->GetStoredFocusView()); | 782 EXPECT_EQ(&view, GetFocusManager()->GetStoredFocusView()); |
783 } | 783 } |
784 | 784 |
785 class TextInputTestView : public View { | 785 class TextInputTestView : public View { |
786 public: | 786 public: |
787 TextInputTestView() {} | 787 TextInputTestView() {} |
788 | 788 |
789 virtual ui::TextInputClient* GetTextInputClient() OVERRIDE { | 789 virtual ui::TextInputClient* GetTextInputClient() override { |
790 return &text_input_client_; | 790 return &text_input_client_; |
791 } | 791 } |
792 | 792 |
793 private: | 793 private: |
794 ui::DummyTextInputClient text_input_client_; | 794 ui::DummyTextInputClient text_input_client_; |
795 | 795 |
796 DISALLOW_COPY_AND_ASSIGN(TextInputTestView); | 796 DISALLOW_COPY_AND_ASSIGN(TextInputTestView); |
797 }; | 797 }; |
798 | 798 |
799 TEST_F(FocusManagerTest, TextInputClient) { | 799 TEST_F(FocusManagerTest, TextInputClient) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
845 explicit AdvanceFocusWidgetDelegate(Widget* widget) | 845 explicit AdvanceFocusWidgetDelegate(Widget* widget) |
846 : widget_(widget), | 846 : widget_(widget), |
847 should_advance_focus_to_parent_(false) {} | 847 should_advance_focus_to_parent_(false) {} |
848 virtual ~AdvanceFocusWidgetDelegate() {} | 848 virtual ~AdvanceFocusWidgetDelegate() {} |
849 | 849 |
850 void set_should_advance_focus_to_parent(bool value) { | 850 void set_should_advance_focus_to_parent(bool value) { |
851 should_advance_focus_to_parent_ = value; | 851 should_advance_focus_to_parent_ = value; |
852 } | 852 } |
853 | 853 |
854 // WidgetDelegate overrides: | 854 // WidgetDelegate overrides: |
855 virtual bool ShouldAdvanceFocusToTopLevelWidget() const OVERRIDE { | 855 virtual bool ShouldAdvanceFocusToTopLevelWidget() const override { |
856 return should_advance_focus_to_parent_; | 856 return should_advance_focus_to_parent_; |
857 } | 857 } |
858 virtual Widget* GetWidget() OVERRIDE { return widget_; } | 858 virtual Widget* GetWidget() override { return widget_; } |
859 virtual const Widget* GetWidget() const OVERRIDE { return widget_; } | 859 virtual const Widget* GetWidget() const override { return widget_; } |
860 | 860 |
861 private: | 861 private: |
862 Widget* widget_; | 862 Widget* widget_; |
863 bool should_advance_focus_to_parent_; | 863 bool should_advance_focus_to_parent_; |
864 | 864 |
865 DISALLOW_COPY_AND_ASSIGN(AdvanceFocusWidgetDelegate); | 865 DISALLOW_COPY_AND_ASSIGN(AdvanceFocusWidgetDelegate); |
866 }; | 866 }; |
867 | 867 |
868 } // namespace | 868 } // namespace |
869 | 869 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
911 EXPECT_EQ(view1, GetFocusManager()->GetFocusedView()); | 911 EXPECT_EQ(view1, GetFocusManager()->GetFocusedView()); |
912 | 912 |
913 // Allow focus to go to the parent, and focus backwards which should now move | 913 // Allow focus to go to the parent, and focus backwards which should now move |
914 // up |widget_view| (in the parent). | 914 // up |widget_view| (in the parent). |
915 delegate->set_should_advance_focus_to_parent(true); | 915 delegate->set_should_advance_focus_to_parent(true); |
916 GetFocusManager()->AdvanceFocus(true); | 916 GetFocusManager()->AdvanceFocus(true); |
917 EXPECT_EQ(widget_view, GetFocusManager()->GetFocusedView()); | 917 EXPECT_EQ(widget_view, GetFocusManager()->GetFocusedView()); |
918 } | 918 } |
919 | 919 |
920 } // namespace views | 920 } // namespace views |
OLD | NEW |