| 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 std::unique_ptr<Widget> widget1(new Widget()); |
| 161 widget1->Init(params); |
| 162 Textfield* textfield1 = new Textfield(); |
| 163 widget1->GetRootView()->AddChildView(textfield1); |
| 164 Textfield* textfield2 = new Textfield(); |
| 165 widget1->GetRootView()->AddChildView(textfield2); |
| 166 |
| 167 std::unique_ptr<Widget> widget2(new Widget()); |
| 168 widget2->Init(params); |
| 169 Textfield* textfield3 = new Textfield(); |
| 170 widget2->GetRootView()->AddChildView(textfield3); |
| 171 |
| 172 // |widget1| non-active, |widget2| active. |widget1|'s child view |
| 173 // should not be able to get IME focus. |
| 174 widget2->Activate(); |
| 175 EXPECT_FALSE(widget1->IsActive()); |
| 176 EXPECT_TRUE(widget2->IsActive()); |
| 177 textfield3->RequestFocus(); |
| 178 EXPECT_TRUE(textfield3->HasFocus()); |
| 179 EXPECT_FALSE(textfield1->HasFocus()); |
| 180 EXPECT_FALSE(textfield2->HasFocus()); |
| 181 textfield1->RequestFocus(); |
| 182 EXPECT_TRUE(textfield3->HasFocus()); |
| 183 EXPECT_FALSE(textfield1->HasFocus()); |
| 184 EXPECT_FALSE(textfield2->HasFocus()); |
| 185 |
| 186 // |widget1| becomes active. Since |textfield1| requests focus when |widget1| |
| 187 // is non-active, the focus is stored and will be set when |widget1| |
| 188 // is activated. |
| 189 widget1->Activate(); |
| 190 EXPECT_TRUE(widget1->IsActive()); |
| 191 EXPECT_FALSE(widget2->IsActive()); |
| 192 EXPECT_TRUE(textfield1->HasFocus()); |
| 193 EXPECT_FALSE(textfield2->HasFocus()); |
| 194 EXPECT_FALSE(textfield3->HasFocus()); |
| 195 } |
| 196 |
| 153 // A WindowObserver that counts kShowStateKey property changes. | 197 // A WindowObserver that counts kShowStateKey property changes. |
| 154 class TestWindowObserver : public aura::WindowObserver { | 198 class TestWindowObserver : public aura::WindowObserver { |
| 155 public: | 199 public: |
| 156 explicit TestWindowObserver(gfx::NativeWindow window) : window_(window) { | 200 explicit TestWindowObserver(gfx::NativeWindow window) : window_(window) { |
| 157 window_->AddObserver(this); | 201 window_->AddObserver(this); |
| 158 } | 202 } |
| 159 ~TestWindowObserver() override { | 203 ~TestWindowObserver() override { |
| 160 window_->RemoveObserver(this); | 204 window_->RemoveObserver(this); |
| 161 } | 205 } |
| 162 | 206 |
| (...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 596 EXPECT_FALSE(delegate.view()->HasFocus()); | 640 EXPECT_FALSE(delegate.view()->HasFocus()); |
| 597 | 641 |
| 598 test_focus_rules()->set_can_activate(true); | 642 test_focus_rules()->set_can_activate(true); |
| 599 views::test::TestInitialFocusWidgetDelegate delegate2(root_window()); | 643 views::test::TestInitialFocusWidgetDelegate delegate2(root_window()); |
| 600 delegate2.GetWidget()->Show(); | 644 delegate2.GetWidget()->Show(); |
| 601 EXPECT_TRUE(delegate2.view()->HasFocus()); | 645 EXPECT_TRUE(delegate2.view()->HasFocus()); |
| 602 } | 646 } |
| 603 | 647 |
| 604 } // namespace | 648 } // namespace |
| 605 } // namespace views | 649 } // namespace views |
| OLD | NEW |