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/widget/native_widget_aura.h" | 5 #include "ui/views/widget/native_widget_aura.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 #include "ui/aura/client/aura_constants.h" | 13 #include "ui/aura/client/aura_constants.h" |
14 #include "ui/aura/env.h" | 14 #include "ui/aura/env.h" |
15 #include "ui/aura/layout_manager.h" | 15 #include "ui/aura/layout_manager.h" |
16 #include "ui/aura/test/aura_test_base.h" | 16 #include "ui/aura/test/aura_test_base.h" |
17 #include "ui/aura/window.h" | 17 #include "ui/aura/window.h" |
18 #include "ui/aura/window_observer.h" | 18 #include "ui/aura/window_observer.h" |
19 #include "ui/aura/window_tree_host.h" | 19 #include "ui/aura/window_tree_host.h" |
20 #include "ui/events/event.h" | 20 #include "ui/events/event.h" |
21 #include "ui/events/event_utils.h" | 21 #include "ui/events/event_utils.h" |
| 22 #include "ui/views/controls/textfield/textfield.h" |
22 #include "ui/views/layout/fill_layout.h" | 23 #include "ui/views/layout/fill_layout.h" |
23 #include "ui/views/test/widget_test.h" | 24 #include "ui/views/test/widget_test.h" |
24 #include "ui/views/widget/root_view.h" | 25 #include "ui/views/widget/root_view.h" |
25 #include "ui/views/widget/widget_delegate.h" | 26 #include "ui/views/widget/widget_delegate.h" |
26 #include "ui/wm/core/base_focus_rules.h" | 27 #include "ui/wm/core/base_focus_rules.h" |
27 #include "ui/wm/core/default_activation_client.h" | 28 #include "ui/wm/core/default_activation_client.h" |
28 #include "ui/wm/core/focus_controller.h" | 29 #include "ui/wm/core/focus_controller.h" |
29 | 30 |
30 namespace views { | 31 namespace views { |
31 namespace { | 32 namespace { |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 params.show_state = ui::SHOW_STATE_MINIMIZED; | 144 params.show_state = ui::SHOW_STATE_MINIMIZED; |
144 params.bounds.SetRect(0, 0, 1024, 800); | 145 params.bounds.SetRect(0, 0, 1024, 800); |
145 std::unique_ptr<Widget> widget(new Widget()); | 146 std::unique_ptr<Widget> widget(new Widget()); |
146 widget->Init(params); | 147 widget->Init(params); |
147 widget->Show(); | 148 widget->Show(); |
148 | 149 |
149 EXPECT_TRUE(widget->IsMinimized()); | 150 EXPECT_TRUE(widget->IsMinimized()); |
150 widget->CloseNow(); | 151 widget->CloseNow(); |
151 } | 152 } |
152 | 153 |
| 154 TEST_F(NativeWidgetAuraTest, NonActiveWindowRequestImeFocus) { |
| 155 Widget::InitParams params(Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| 156 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 157 params.parent = nullptr; |
| 158 params.context = root_window(); |
| 159 |
| 160 // |widget1| sets to non-activatable. |
| 161 std::unique_ptr<Widget> widget1(new Widget()); |
| 162 widget1->Init(params); |
| 163 widget1->widget_delegate()->set_can_activate(false); |
| 164 Textfield* textfield0 = new Textfield(); |
| 165 widget1->GetRootView()->AddChildView(textfield0); |
| 166 Textfield* textfield1 = new Textfield(); |
| 167 widget1->GetRootView()->AddChildView(textfield1); |
| 168 |
| 169 std::unique_ptr<Widget> widget2(new Widget()); |
| 170 widget2->Init(params); |
| 171 Textfield* textfield2 = new Textfield(); |
| 172 widget2->GetRootView()->AddChildView(textfield2); |
| 173 |
| 174 textfield2->RequestFocus(); |
| 175 EXPECT_TRUE(textfield2->HasFocus()); |
| 176 EXPECT_FALSE(textfield0->HasFocus()); |
| 177 EXPECT_FALSE(textfield1->HasFocus()); |
| 178 textfield0->RequestFocus(); |
| 179 EXPECT_TRUE(textfield2->HasFocus()); |
| 180 EXPECT_FALSE(textfield0->HasFocus()); |
| 181 EXPECT_FALSE(textfield1->HasFocus()); |
| 182 |
| 183 // |widget1| sets to activatable. If now there is an Activate() call, focus |
| 184 // should restore to |textfield0| properly. |
| 185 widget1->widget_delegate()->set_can_activate(true); |
| 186 widget1->Activate(); |
| 187 EXPECT_TRUE(textfield0->HasFocus()); |
| 188 EXPECT_FALSE(textfield1->HasFocus()); |
| 189 EXPECT_FALSE(textfield2->HasFocus()); |
| 190 } |
| 191 |
153 // A WindowObserver that counts kShowStateKey property changes. | 192 // A WindowObserver that counts kShowStateKey property changes. |
154 class TestWindowObserver : public aura::WindowObserver { | 193 class TestWindowObserver : public aura::WindowObserver { |
155 public: | 194 public: |
156 explicit TestWindowObserver(gfx::NativeWindow window) : window_(window) { | 195 explicit TestWindowObserver(gfx::NativeWindow window) : window_(window) { |
157 window_->AddObserver(this); | 196 window_->AddObserver(this); |
158 } | 197 } |
159 ~TestWindowObserver() override { | 198 ~TestWindowObserver() override { |
160 window_->RemoveObserver(this); | 199 window_->RemoveObserver(this); |
161 } | 200 } |
162 | 201 |
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
596 EXPECT_FALSE(delegate.view()->HasFocus()); | 635 EXPECT_FALSE(delegate.view()->HasFocus()); |
597 | 636 |
598 test_focus_rules()->set_can_activate(true); | 637 test_focus_rules()->set_can_activate(true); |
599 views::test::TestInitialFocusWidgetDelegate delegate2(root_window()); | 638 views::test::TestInitialFocusWidgetDelegate delegate2(root_window()); |
600 delegate2.GetWidget()->Show(); | 639 delegate2.GetWidget()->Show(); |
601 EXPECT_TRUE(delegate2.view()->HasFocus()); | 640 EXPECT_TRUE(delegate2.view()->HasFocus()); |
602 } | 641 } |
603 | 642 |
604 } // namespace | 643 } // namespace |
605 } // namespace views | 644 } // namespace views |
OLD | NEW |