| 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" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "ui/aura/client/focus_client.h" | 12 #include "ui/aura/client/focus_client.h" |
| 13 #include "ui/aura/window.h" | 13 #include "ui/aura/window.h" |
| 14 #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" | |
| 18 #include "ui/events/keycodes/keyboard_codes.h" | 15 #include "ui/events/keycodes/keyboard_codes.h" |
| 19 #include "ui/views/accessible_pane_view.h" | 16 #include "ui/views/accessible_pane_view.h" |
| 20 #include "ui/views/controls/button/label_button.h" | 17 #include "ui/views/controls/button/label_button.h" |
| 21 #include "ui/views/focus/focus_manager_factory.h" | 18 #include "ui/views/focus/focus_manager_factory.h" |
| 22 #include "ui/views/focus/widget_focus_manager.h" | 19 #include "ui/views/focus/widget_focus_manager.h" |
| 23 #include "ui/views/test/focus_manager_test.h" | 20 #include "ui/views/test/focus_manager_test.h" |
| 24 #include "ui/views/widget/widget.h" | 21 #include "ui/views/widget/widget.h" |
| 25 | 22 |
| 26 namespace views { | 23 namespace views { |
| 27 | 24 |
| (...skipping 761 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 789 EXPECT_EQ(&view, GetFocusManager()->GetStoredFocusView()); | 786 EXPECT_EQ(&view, GetFocusManager()->GetStoredFocusView()); |
| 790 | 787 |
| 791 // Repeat with |true|. | 788 // Repeat with |true|. |
| 792 GetFocusManager()->SetFocusedView(&view); | 789 GetFocusManager()->SetFocusedView(&view); |
| 793 GetFocusManager()->StoreFocusedView(true); | 790 GetFocusManager()->StoreFocusedView(true); |
| 794 EXPECT_EQ(NULL, GetFocusManager()->GetFocusedView()); | 791 EXPECT_EQ(NULL, GetFocusManager()->GetFocusedView()); |
| 795 EXPECT_TRUE(GetFocusManager()->RestoreFocusedView()); | 792 EXPECT_TRUE(GetFocusManager()->RestoreFocusedView()); |
| 796 EXPECT_EQ(&view, GetFocusManager()->GetStoredFocusView()); | 793 EXPECT_EQ(&view, GetFocusManager()->GetStoredFocusView()); |
| 797 } | 794 } |
| 798 | 795 |
| 799 class TextInputTestView : public View { | |
| 800 public: | |
| 801 TextInputTestView() {} | |
| 802 | |
| 803 ui::TextInputClient* GetTextInputClient() override { | |
| 804 return &text_input_client_; | |
| 805 } | |
| 806 | |
| 807 private: | |
| 808 ui::DummyTextInputClient text_input_client_; | |
| 809 | |
| 810 DISALLOW_COPY_AND_ASSIGN(TextInputTestView); | |
| 811 }; | |
| 812 | |
| 813 TEST_F(FocusManagerTest, TextInputClient) { | |
| 814 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); | |
| 815 cmd_line->AppendSwitch(switches::kEnableTextInputFocusManager); | |
| 816 | |
| 817 View* view = new TextInputTestView; | |
| 818 ui::TextInputClient* text_input_client = view->GetTextInputClient(); | |
| 819 view->SetFocusable(true); | |
| 820 GetContentsView()->AddChildView(view); | |
| 821 ui::TextInputFocusManager* text_input_focus_manager = | |
| 822 ui::TextInputFocusManager::GetInstance(); | |
| 823 | |
| 824 GetFocusManager()->SetFocusedView(view); | |
| 825 EXPECT_EQ(view, GetFocusManager()->GetFocusedView()); | |
| 826 EXPECT_EQ(text_input_client, | |
| 827 text_input_focus_manager->GetFocusedTextInputClient()); | |
| 828 GetFocusManager()->StoreFocusedView(false); | |
| 829 EXPECT_TRUE(GetFocusManager()->RestoreFocusedView()); | |
| 830 EXPECT_EQ(text_input_client, | |
| 831 text_input_focus_manager->GetFocusedTextInputClient()); | |
| 832 | |
| 833 // Repeat with |true|. | |
| 834 GetFocusManager()->SetFocusedView(view); | |
| 835 EXPECT_EQ(view, GetFocusManager()->GetFocusedView()); | |
| 836 EXPECT_EQ(text_input_client, | |
| 837 text_input_focus_manager->GetFocusedTextInputClient()); | |
| 838 GetFocusManager()->StoreFocusedView(true); | |
| 839 EXPECT_TRUE(GetFocusManager()->RestoreFocusedView()); | |
| 840 EXPECT_EQ(text_input_client, | |
| 841 text_input_focus_manager->GetFocusedTextInputClient()); | |
| 842 | |
| 843 // Focus the view twice in a row. | |
| 844 GetFocusManager()->SetFocusedView(view); | |
| 845 EXPECT_EQ(text_input_client, | |
| 846 text_input_focus_manager->GetFocusedTextInputClient()); | |
| 847 ui::TextInputFocusManager::GetInstance()->FocusTextInputClient(NULL); | |
| 848 GetFocusManager()->SetFocusedView(view); | |
| 849 EXPECT_EQ(text_input_client, | |
| 850 text_input_focus_manager->GetFocusedTextInputClient()); | |
| 851 } | |
| 852 | |
| 853 namespace { | 796 namespace { |
| 854 | 797 |
| 855 // Trivial WidgetDelegate implementation that allows setting return value of | 798 // Trivial WidgetDelegate implementation that allows setting return value of |
| 856 // ShouldAdvanceFocusToTopLevelWidget(). | 799 // ShouldAdvanceFocusToTopLevelWidget(). |
| 857 class AdvanceFocusWidgetDelegate : public WidgetDelegate { | 800 class AdvanceFocusWidgetDelegate : public WidgetDelegate { |
| 858 public: | 801 public: |
| 859 explicit AdvanceFocusWidgetDelegate(Widget* widget) | 802 explicit AdvanceFocusWidgetDelegate(Widget* widget) |
| 860 : widget_(widget), | 803 : widget_(widget), |
| 861 should_advance_focus_to_parent_(false) {} | 804 should_advance_focus_to_parent_(false) {} |
| 862 ~AdvanceFocusWidgetDelegate() override {} | 805 ~AdvanceFocusWidgetDelegate() override {} |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 925 EXPECT_EQ(view1, GetFocusManager()->GetFocusedView()); | 868 EXPECT_EQ(view1, GetFocusManager()->GetFocusedView()); |
| 926 | 869 |
| 927 // Allow focus to go to the parent, and focus backwards which should now move | 870 // Allow focus to go to the parent, and focus backwards which should now move |
| 928 // up |widget_view| (in the parent). | 871 // up |widget_view| (in the parent). |
| 929 delegate->set_should_advance_focus_to_parent(true); | 872 delegate->set_should_advance_focus_to_parent(true); |
| 930 GetFocusManager()->AdvanceFocus(true); | 873 GetFocusManager()->AdvanceFocus(true); |
| 931 EXPECT_EQ(widget_view, GetFocusManager()->GetFocusedView()); | 874 EXPECT_EQ(widget_view, GetFocusManager()->GetFocusedView()); |
| 932 } | 875 } |
| 933 | 876 |
| 934 } // namespace views | 877 } // namespace views |
| OLD | NEW |