Chromium Code Reviews| 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" | |
| 6 | |
| 5 #include <utility> | 7 #include <utility> |
| 6 #include <vector> | 8 #include <vector> |
| 7 | 9 |
| 10 #include "base/command_line.h" | |
| 8 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 9 #include "ui/aura/client/focus_client.h" | 12 #include "ui/aura/client/focus_client.h" |
| 10 #include "ui/aura/window.h" | 13 #include "ui/aura/window.h" |
| 11 #include "ui/base/accelerators/accelerator.h" | 14 #include "ui/base/accelerators/accelerator.h" |
| 15 #include "ui/base/ime/dummy_text_input_client.h" | |
| 16 #include "ui/base/ime/text_input_focus_manager.h" | |
| 17 #include "ui/base/ui_base_switches.h" | |
| 12 #include "ui/events/keycodes/keyboard_codes.h" | 18 #include "ui/events/keycodes/keyboard_codes.h" |
| 13 #include "ui/views/accessible_pane_view.h" | 19 #include "ui/views/accessible_pane_view.h" |
| 14 #include "ui/views/controls/button/label_button.h" | 20 #include "ui/views/controls/button/label_button.h" |
| 15 #include "ui/views/controls/textfield/textfield.h" | |
| 16 #include "ui/views/focus/focus_manager_factory.h" | 21 #include "ui/views/focus/focus_manager_factory.h" |
| 17 #include "ui/views/focus/focus_manager_test.h" | 22 #include "ui/views/focus/focus_manager_test.h" |
| 18 #include "ui/views/focus/widget_focus_manager.h" | 23 #include "ui/views/focus/widget_focus_manager.h" |
| 19 #include "ui/views/widget/widget.h" | 24 #include "ui/views/widget/widget.h" |
| 20 | 25 |
| 21 namespace views { | 26 namespace views { |
| 22 | 27 |
| 23 enum FocusTestEventType { | 28 enum FocusTestEventType { |
| 24 ON_FOCUS = 0, | 29 ON_FOCUS = 0, |
| 25 ON_BLUR | 30 ON_BLUR |
| (...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 756 focus_manager->OnKeyEvent(right_key); | 761 focus_manager->OnKeyEvent(right_key); |
| 757 EXPECT_EQ(v[1], focus_manager->GetFocusedView()); | 762 EXPECT_EQ(v[1], focus_manager->GetFocusedView()); |
| 758 focus_manager->OnKeyEvent(left_key); | 763 focus_manager->OnKeyEvent(left_key); |
| 759 EXPECT_EQ(v[0], focus_manager->GetFocusedView()); | 764 EXPECT_EQ(v[0], focus_manager->GetFocusedView()); |
| 760 focus_manager->OnKeyEvent(down_key); | 765 focus_manager->OnKeyEvent(down_key); |
| 761 EXPECT_EQ(v[1], focus_manager->GetFocusedView()); | 766 EXPECT_EQ(v[1], focus_manager->GetFocusedView()); |
| 762 focus_manager->OnKeyEvent(up_key); | 767 focus_manager->OnKeyEvent(up_key); |
| 763 EXPECT_EQ(v[0], focus_manager->GetFocusedView()); | 768 EXPECT_EQ(v[0], focus_manager->GetFocusedView()); |
| 764 } | 769 } |
| 765 | 770 |
| 771 class TextInputTestView : public View { | |
| 772 public: | |
| 773 virtual ui::TextInputClient* GetTextInputClient() OVERRIDE { | |
| 774 return &text_input_client_; | |
| 775 } | |
| 776 | |
| 777 private: | |
| 778 ui::DummyTextInputClient text_input_client_; | |
| 779 }; | |
|
sky
2014/05/30 16:30:15
DISALLOW_...
Yuki
2014/06/02 07:38:55
Done.
| |
| 780 | |
| 766 TEST_F(FocusManagerTest, StoreFocusedView) { | 781 TEST_F(FocusManagerTest, StoreFocusedView) { |
| 767 View view; | 782 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); |
| 768 GetFocusManager()->SetFocusedView(&view); | 783 cmd_line->AppendSwitch(switches::kEnableTextInputFocusManager); |
| 784 | |
| 785 View* view = new TextInputTestView; | |
| 786 ui::TextInputClient* text_input_client = view->GetTextInputClient(); | |
| 787 view->SetFocusable(true); | |
| 788 GetContentsView()->AddChildView(view); | |
| 789 ui::TextInputFocusManager* text_input_focus_manager = | |
| 790 ui::TextInputFocusManager::GetInstance(); | |
| 791 | |
| 792 GetFocusManager()->SetFocusedView(view); | |
| 793 EXPECT_EQ(view, GetFocusManager()->GetFocusedView()); | |
| 794 EXPECT_EQ(text_input_client, | |
| 795 text_input_focus_manager->GetFocusedTextInputClient()); | |
| 769 GetFocusManager()->StoreFocusedView(false); | 796 GetFocusManager()->StoreFocusedView(false); |
| 770 EXPECT_TRUE(GetFocusManager()->RestoreFocusedView()); | 797 EXPECT_TRUE(GetFocusManager()->RestoreFocusedView()); |
| 771 EXPECT_EQ(&view, GetFocusManager()->GetStoredFocusView()); | 798 EXPECT_EQ(view, GetFocusManager()->GetStoredFocusView()); |
| 799 EXPECT_EQ(view, GetFocusManager()->GetFocusedView()); | |
| 800 EXPECT_EQ(text_input_client, | |
| 801 text_input_focus_manager->GetFocusedTextInputClient()); | |
| 772 | 802 |
| 773 // Repeat with |true|. | 803 // Repeat with |true|. |
| 774 GetFocusManager()->SetFocusedView(&view); | 804 GetFocusManager()->SetFocusedView(view); |
| 805 EXPECT_EQ(view, GetFocusManager()->GetFocusedView()); | |
| 806 EXPECT_EQ(text_input_client, | |
| 807 text_input_focus_manager->GetFocusedTextInputClient()); | |
| 775 GetFocusManager()->StoreFocusedView(true); | 808 GetFocusManager()->StoreFocusedView(true); |
| 776 EXPECT_TRUE(GetFocusManager()->RestoreFocusedView()); | 809 EXPECT_TRUE(GetFocusManager()->RestoreFocusedView()); |
| 777 EXPECT_EQ(&view, GetFocusManager()->GetStoredFocusView()); | 810 EXPECT_EQ(view, GetFocusManager()->GetStoredFocusView()); |
| 811 EXPECT_EQ(view, GetFocusManager()->GetFocusedView()); | |
| 812 EXPECT_EQ(text_input_client, | |
| 813 text_input_focus_manager->GetFocusedTextInputClient()); | |
| 814 | |
| 815 // Focus the view twice in a row. | |
| 816 GetFocusManager()->SetFocusedView(view); | |
| 817 EXPECT_EQ(text_input_client, | |
| 818 text_input_focus_manager->GetFocusedTextInputClient()); | |
| 819 ui::TextInputFocusManager::GetInstance()->FocusTextInputClient(NULL); | |
| 820 GetFocusManager()->SetFocusedView(view); | |
| 821 EXPECT_EQ(text_input_client, | |
| 822 text_input_focus_manager->GetFocusedTextInputClient()); | |
| 778 } | 823 } |
| 779 | 824 |
| 780 namespace { | 825 namespace { |
| 781 | 826 |
| 782 // Trivial WidgetDelegate implementation that allows setting return value of | 827 // Trivial WidgetDelegate implementation that allows setting return value of |
| 783 // ShouldAdvanceFocusToTopLevelWidget(). | 828 // ShouldAdvanceFocusToTopLevelWidget(). |
| 784 class AdvanceFocusWidgetDelegate : public WidgetDelegate { | 829 class AdvanceFocusWidgetDelegate : public WidgetDelegate { |
| 785 public: | 830 public: |
| 786 explicit AdvanceFocusWidgetDelegate(Widget* widget) | 831 explicit AdvanceFocusWidgetDelegate(Widget* widget) |
| 787 : widget_(widget), | 832 : widget_(widget), |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 852 EXPECT_EQ(view1, GetFocusManager()->GetFocusedView()); | 897 EXPECT_EQ(view1, GetFocusManager()->GetFocusedView()); |
| 853 | 898 |
| 854 // Allow focus to go to the parent, and focus backwards which should now move | 899 // Allow focus to go to the parent, and focus backwards which should now move |
| 855 // up |widget_view| (in the parent). | 900 // up |widget_view| (in the parent). |
| 856 delegate->set_should_advance_focus_to_parent(true); | 901 delegate->set_should_advance_focus_to_parent(true); |
| 857 GetFocusManager()->AdvanceFocus(true); | 902 GetFocusManager()->AdvanceFocus(true); |
| 858 EXPECT_EQ(widget_view, GetFocusManager()->GetFocusedView()); | 903 EXPECT_EQ(widget_view, GetFocusManager()->GetFocusedView()); |
| 859 } | 904 } |
| 860 | 905 |
| 861 } // namespace views | 906 } // namespace views |
| OLD | NEW |