| 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 "ash/root_window_controller.h" | 5 #include "ash/root_window_controller.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "ash/aura/wm_window_aura.h" | 9 #include "ash/aura/wm_window_aura.h" |
| 10 #include "ash/common/material_design/material_design_controller.h" | 10 #include "ash/common/material_design/material_design_controller.h" |
| (...skipping 705 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 716 } | 716 } |
| 717 | 717 |
| 718 private: | 718 private: |
| 719 DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardRootWindowControllerTest); | 719 DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardRootWindowControllerTest); |
| 720 }; | 720 }; |
| 721 | 721 |
| 722 class MockTextInputClient : public ui::DummyTextInputClient { | 722 class MockTextInputClient : public ui::DummyTextInputClient { |
| 723 public: | 723 public: |
| 724 MockTextInputClient() : ui::DummyTextInputClient(ui::TEXT_INPUT_TYPE_TEXT) {} | 724 MockTextInputClient() : ui::DummyTextInputClient(ui::TEXT_INPUT_TYPE_TEXT) {} |
| 725 | 725 |
| 726 void EnsureCaretInRect(const gfx::Rect& rect) override { | 726 void EnsureCaretNotInRect(const gfx::Rect& rect) override { |
| 727 visible_rect_ = rect; | 727 caret_exclude_rect_ = rect; |
| 728 } | 728 } |
| 729 | 729 |
| 730 const gfx::Rect& visible_rect() const { return visible_rect_; } | 730 const gfx::Rect& caret_exclude_rect() const { return caret_exclude_rect_; } |
| 731 | 731 |
| 732 private: | 732 private: |
| 733 gfx::Rect visible_rect_; | 733 gfx::Rect caret_exclude_rect_; |
| 734 | 734 |
| 735 DISALLOW_COPY_AND_ASSIGN(MockTextInputClient); | 735 DISALLOW_COPY_AND_ASSIGN(MockTextInputClient); |
| 736 }; | 736 }; |
| 737 | 737 |
| 738 class TargetHitTestEventHandler : public ui::test::TestEventHandler { | 738 class TargetHitTestEventHandler : public ui::test::TestEventHandler { |
| 739 public: | 739 public: |
| 740 TargetHitTestEventHandler() {} | 740 TargetHitTestEventHandler() {} |
| 741 | 741 |
| 742 // ui::test::TestEventHandler overrides. | 742 // ui::test::TestEventHandler overrides. |
| 743 void OnMouseEvent(ui::MouseEvent* event) override { | 743 void OnMouseEvent(ui::MouseEvent* event) override { |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1076 | 1076 |
| 1077 const int keyboard_height = 100; | 1077 const int keyboard_height = 100; |
| 1078 aura::Window* keyboard_window = ui->GetKeyboardWindow(); | 1078 aura::Window* keyboard_window = ui->GetKeyboardWindow(); |
| 1079 keyboard_container->AddChild(keyboard_window); | 1079 keyboard_container->AddChild(keyboard_window); |
| 1080 keyboard_window->set_owned_by_parent(false); | 1080 keyboard_window->set_owned_by_parent(false); |
| 1081 keyboard_window->SetBounds(keyboard::FullWidthKeyboardBoundsFromRootBounds( | 1081 keyboard_window->SetBounds(keyboard::FullWidthKeyboardBoundsFromRootBounds( |
| 1082 root_window->bounds(), keyboard_height)); | 1082 root_window->bounds(), keyboard_height)); |
| 1083 | 1083 |
| 1084 ui->EnsureCaretInWorkArea(); | 1084 ui->EnsureCaretInWorkArea(); |
| 1085 ASSERT_EQ(root_window->bounds().width(), | 1085 ASSERT_EQ(root_window->bounds().width(), |
| 1086 text_input_client.visible_rect().width()); | 1086 text_input_client.caret_exclude_rect().width()); |
| 1087 ASSERT_EQ(root_window->bounds().height() - keyboard_height, | 1087 ASSERT_EQ(keyboard_height, text_input_client.caret_exclude_rect().height()); |
| 1088 text_input_client.visible_rect().height()); | |
| 1089 | 1088 |
| 1090 input_method->SetFocusedTextInputClient(NULL); | 1089 input_method->SetFocusedTextInputClient(NULL); |
| 1091 } | 1090 } |
| 1092 | 1091 |
| 1092 TEST_F(VirtualKeyboardRootWindowControllerTest, |
| 1093 EnsureCaretInWorkAreaWithMultipleDisplays) { |
| 1094 if (!SupportsMultipleDisplays()) |
| 1095 return; |
| 1096 |
| 1097 UpdateDisplay("500x500,600x600"); |
| 1098 const int64_t primary_display_id = |
| 1099 display::Screen::GetScreen()->GetPrimaryDisplay().id(); |
| 1100 const int64_t secondary_display_id = |
| 1101 Shell::GetInstance()->display_manager()->GetSecondaryDisplay().id(); |
| 1102 ASSERT_NE(primary_display_id, secondary_display_id); |
| 1103 |
| 1104 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
| 1105 ASSERT_EQ(static_cast<size_t>(2), root_windows.size()); |
| 1106 aura::Window* primary_root_window = root_windows[0]; |
| 1107 aura::Window* secondary_root_window = root_windows[1]; |
| 1108 |
| 1109 keyboard::KeyboardController* keyboard_controller = |
| 1110 keyboard::KeyboardController::GetInstance(); |
| 1111 keyboard::KeyboardUI* ui = keyboard_controller->ui(); |
| 1112 |
| 1113 MockTextInputClient text_input_client; |
| 1114 ui::InputMethod* input_method = ui->GetInputMethod(); |
| 1115 ASSERT_TRUE(input_method); |
| 1116 input_method->SetFocusedTextInputClient(&text_input_client); |
| 1117 |
| 1118 const int keyboard_height = 100; |
| 1119 // Check that the keyboard on the primary screen doesn't cover the window on |
| 1120 // the secondary screen. |
| 1121 aura::Window* keyboard_container = Shell::GetContainer( |
| 1122 primary_root_window, kShellWindowId_VirtualKeyboardContainer); |
| 1123 ASSERT_TRUE(keyboard_container); |
| 1124 keyboard_container->Show(); |
| 1125 aura::Window* keyboard_window = ui->GetKeyboardWindow(); |
| 1126 keyboard_container->AddChild(keyboard_window); |
| 1127 keyboard_window->set_owned_by_parent(false); |
| 1128 keyboard_window->SetBounds(keyboard::FullWidthKeyboardBoundsFromRootBounds( |
| 1129 primary_root_window->bounds(), keyboard_height)); |
| 1130 |
| 1131 EXPECT_TRUE(primary_root_window->GetBoundsInScreen().Contains( |
| 1132 text_input_client.caret_exclude_rect())); |
| 1133 EXPECT_FALSE(secondary_root_window->GetBoundsInScreen().Contains( |
| 1134 text_input_client.caret_exclude_rect())); |
| 1135 |
| 1136 // Move the keyboard into the secondary display and check that the keyboard |
| 1137 // doesn't cover the window on the primary screen. |
| 1138 keyboard_controller->ShowKeyboardInDisplay(secondary_display_id); |
| 1139 keyboard_window->SetBounds(keyboard::FullWidthKeyboardBoundsFromRootBounds( |
| 1140 secondary_root_window->bounds(), keyboard_height)); |
| 1141 |
| 1142 ui->EnsureCaretInWorkArea(); |
| 1143 EXPECT_FALSE(primary_root_window->GetBoundsInScreen().Contains( |
| 1144 text_input_client.caret_exclude_rect())); |
| 1145 EXPECT_TRUE(secondary_root_window->GetBoundsInScreen().Contains( |
| 1146 text_input_client.caret_exclude_rect())); |
| 1147 |
| 1148 input_method->SetFocusedTextInputClient(nullptr); |
| 1149 } |
| 1150 |
| 1093 // Tests that the virtual keyboard does not block context menus. The virtual | 1151 // Tests that the virtual keyboard does not block context menus. The virtual |
| 1094 // keyboard should appear in front of most content, but not context menus. See | 1152 // keyboard should appear in front of most content, but not context menus. See |
| 1095 // crbug/377180. | 1153 // crbug/377180. |
| 1096 TEST_F(VirtualKeyboardRootWindowControllerTest, ZOrderTest) { | 1154 TEST_F(VirtualKeyboardRootWindowControllerTest, ZOrderTest) { |
| 1097 UpdateDisplay("800x600"); | 1155 UpdateDisplay("800x600"); |
| 1098 keyboard::KeyboardController* keyboard_controller = | 1156 keyboard::KeyboardController* keyboard_controller = |
| 1099 keyboard::KeyboardController::GetInstance(); | 1157 keyboard::KeyboardController::GetInstance(); |
| 1100 keyboard::KeyboardUI* ui = keyboard_controller->ui(); | 1158 keyboard::KeyboardUI* ui = keyboard_controller->ui(); |
| 1101 | 1159 |
| 1102 aura::Window* root_window = Shell::GetPrimaryRootWindow(); | 1160 aura::Window* root_window = Shell::GetPrimaryRootWindow(); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1195 keyboard_controller->ui()->GetKeyboardWindow()->SetBounds( | 1253 keyboard_controller->ui()->GetKeyboardWindow()->SetBounds( |
| 1196 gfx::Rect(0, 400, 800, 200)); | 1254 gfx::Rect(0, 400, 800, 200)); |
| 1197 EXPECT_EQ("0,400 800x200", keyboard_container->bounds().ToString()); | 1255 EXPECT_EQ("0,400 800x200", keyboard_container->bounds().ToString()); |
| 1198 | 1256 |
| 1199 UpdateDisplay("600x800"); | 1257 UpdateDisplay("600x800"); |
| 1200 EXPECT_EQ("0,600 600x200", keyboard_container->bounds().ToString()); | 1258 EXPECT_EQ("0,600 600x200", keyboard_container->bounds().ToString()); |
| 1201 } | 1259 } |
| 1202 | 1260 |
| 1203 } // namespace test | 1261 } // namespace test |
| 1204 } // namespace ash | 1262 } // namespace ash |
| OLD | NEW |