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 "ash/common/wm/workspace/workspace_layout_manager.h" | 5 #include "ash/common/wm/workspace/workspace_layout_manager.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "ash/aura/wm_window_aura.h" | 10 #include "ash/aura/wm_window_aura.h" |
| 11 #include "ash/common/ash_switches.h" | |
| 11 #include "ash/common/session/session_state_delegate.h" | 12 #include "ash/common/session/session_state_delegate.h" |
| 12 #include "ash/common/shelf/shelf_constants.h" | 13 #include "ash/common/shelf/shelf_constants.h" |
| 13 #include "ash/common/shell_observer.h" | 14 #include "ash/common/shell_observer.h" |
| 14 #include "ash/common/shell_window_ids.h" | 15 #include "ash/common/shell_window_ids.h" |
| 15 #include "ash/common/wm/maximize_mode/workspace_backdrop_delegate.h" | 16 #include "ash/common/wm/maximize_mode/workspace_backdrop_delegate.h" |
| 16 #include "ash/common/wm/window_state.h" | 17 #include "ash/common/wm/window_state.h" |
| 17 #include "ash/common/wm/wm_event.h" | 18 #include "ash/common/wm/wm_event.h" |
| 18 #include "ash/common/wm/workspace/workspace_window_resizer.h" | 19 #include "ash/common/wm/workspace/workspace_window_resizer.h" |
| 19 #include "ash/common/wm_shell.h" | 20 #include "ash/common/wm_shell.h" |
| 20 #include "ash/display/display_manager.h" | 21 #include "ash/display/display_manager.h" |
| 21 #include "ash/root_window_controller.h" | 22 #include "ash/root_window_controller.h" |
| 22 #include "ash/screen_util.h" | 23 #include "ash/screen_util.h" |
| 23 #include "ash/shelf/shelf.h" | 24 #include "ash/shelf/shelf.h" |
| 24 #include "ash/shelf/shelf_layout_manager.h" | 25 #include "ash/shelf/shelf_layout_manager.h" |
| 25 #include "ash/shell.h" | 26 #include "ash/shell.h" |
| 26 #include "ash/test/ash_test_base.h" | 27 #include "ash/test/ash_test_base.h" |
| 27 #include "ash/test/display_manager_test_api.h" | 28 #include "ash/test/display_manager_test_api.h" |
| 28 #include "ash/wm/window_state_aura.h" | 29 #include "ash/wm/window_state_aura.h" |
| 29 #include "ash/wm/window_util.h" | 30 #include "ash/wm/window_util.h" |
| 31 #include "base/command_line.h" | |
| 30 #include "base/compiler_specific.h" | 32 #include "base/compiler_specific.h" |
| 31 #include "base/run_loop.h" | 33 #include "base/run_loop.h" |
| 32 #include "ui/aura/client/aura_constants.h" | 34 #include "ui/aura/client/aura_constants.h" |
| 33 #include "ui/aura/test/test_windows.h" | 35 #include "ui/aura/test/test_windows.h" |
| 34 #include "ui/aura/window.h" | 36 #include "ui/aura/window.h" |
| 35 #include "ui/aura/window_event_dispatcher.h" | 37 #include "ui/aura/window_event_dispatcher.h" |
| 36 #include "ui/base/ui_base_types.h" | 38 #include "ui/base/ui_base_types.h" |
| 37 #include "ui/display/manager/display_layout.h" | 39 #include "ui/display/manager/display_layout.h" |
| 38 #include "ui/display/screen.h" | 40 #include "ui/display/screen.h" |
| 39 #include "ui/gfx/geometry/insets.h" | 41 #include "ui/gfx/geometry/insets.h" |
| 42 #include "ui/keyboard/keyboard_controller.h" | |
| 43 #include "ui/keyboard/keyboard_ui.h" | |
| 44 #include "ui/keyboard/keyboard_util.h" | |
| 40 #include "ui/views/widget/widget.h" | 45 #include "ui/views/widget/widget.h" |
| 41 #include "ui/views/widget/widget_delegate.h" | 46 #include "ui/views/widget/widget_delegate.h" |
| 42 #include "ui/wm/core/window_util.h" | 47 #include "ui/wm/core/window_util.h" |
| 43 | 48 |
| 44 namespace ash { | 49 namespace ash { |
| 45 namespace { | 50 namespace { |
| 46 | 51 |
| 47 class MaximizeDelegateView : public views::WidgetDelegateView { | 52 class MaximizeDelegateView : public views::WidgetDelegateView { |
| 48 public: | 53 public: |
| 49 explicit MaximizeDelegateView(const gfx::Rect& initial_bounds) | 54 explicit MaximizeDelegateView(const gfx::Rect& initial_bounds) |
| (...skipping 1009 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1059 public: | 1064 public: |
| 1060 WorkspaceLayoutManagerKeyboardTest() : layout_manager_(nullptr) {} | 1065 WorkspaceLayoutManagerKeyboardTest() : layout_manager_(nullptr) {} |
| 1061 ~WorkspaceLayoutManagerKeyboardTest() override {} | 1066 ~WorkspaceLayoutManagerKeyboardTest() override {} |
| 1062 | 1067 |
| 1063 void SetUp() override { | 1068 void SetUp() override { |
| 1064 test::AshTestBase::SetUp(); | 1069 test::AshTestBase::SetUp(); |
| 1065 UpdateDisplay("800x600"); | 1070 UpdateDisplay("800x600"); |
| 1066 aura::Window* default_container = Shell::GetContainer( | 1071 aura::Window* default_container = Shell::GetContainer( |
| 1067 Shell::GetPrimaryRootWindow(), kShellWindowId_DefaultContainer); | 1072 Shell::GetPrimaryRootWindow(), kShellWindowId_DefaultContainer); |
| 1068 layout_manager_ = GetWorkspaceLayoutManager(default_container); | 1073 layout_manager_ = GetWorkspaceLayoutManager(default_container); |
| 1074 keyboard::SetAccessibilityKeyboardEnabled(true); | |
|
oshima
2016/07/27 21:40:23
Why this change here? Won't this change what other
hariank
2016/07/27 23:00:39
Done.
| |
| 1069 } | 1075 } |
| 1070 | 1076 |
| 1071 aura::Window* CreateTestWindow(const gfx::Rect& bounds) { | 1077 aura::Window* CreateTestWindow(const gfx::Rect& bounds) { |
| 1072 return CreateTestWindowInShellWithBounds(bounds); | 1078 return CreateTestWindowInShellWithBounds(bounds); |
| 1073 } | 1079 } |
| 1074 | 1080 |
| 1075 void ShowKeyboard() { | 1081 void ShowKeyboard() { |
| 1076 layout_manager_->OnKeyboardBoundsChanging(keyboard_bounds_); | 1082 layout_manager_->OnKeyboardBoundsChanging(keyboard_bounds_); |
| 1077 restore_work_area_insets_ = | 1083 restore_work_area_insets_ = |
| 1078 display::Screen::GetScreen()->GetPrimaryDisplay().GetWorkAreaInsets(); | 1084 display::Screen::GetScreen()->GetPrimaryDisplay().GetWorkAreaInsets(); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 1089 | 1095 |
| 1090 // Initializes the keyboard bounds using the bottom half of the work area. | 1096 // Initializes the keyboard bounds using the bottom half of the work area. |
| 1091 void InitKeyboardBounds() { | 1097 void InitKeyboardBounds() { |
| 1092 gfx::Rect work_area( | 1098 gfx::Rect work_area( |
| 1093 display::Screen::GetScreen()->GetPrimaryDisplay().work_area()); | 1099 display::Screen::GetScreen()->GetPrimaryDisplay().work_area()); |
| 1094 keyboard_bounds_.SetRect(work_area.x(), | 1100 keyboard_bounds_.SetRect(work_area.x(), |
| 1095 work_area.y() + work_area.height() / 2, | 1101 work_area.y() + work_area.height() / 2, |
| 1096 work_area.width(), work_area.height() / 2); | 1102 work_area.width(), work_area.height() / 2); |
| 1097 } | 1103 } |
| 1098 | 1104 |
| 1105 void SetVKFlag() { | |
|
oshima
2016/07/27 21:40:23
EnableNewVKMode()
would be better.
hariank
2016/07/27 23:00:39
Done.
| |
| 1106 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
| 1107 if (!command_line->HasSwitch(switches::kAshUseNewVKWindowBehavior)) { | |
| 1108 command_line->AppendSwitch(switches::kAshUseNewVKWindowBehavior); | |
| 1109 } | |
| 1110 } | |
| 1111 | |
| 1099 const gfx::Rect& keyboard_bounds() const { return keyboard_bounds_; } | 1112 const gfx::Rect& keyboard_bounds() const { return keyboard_bounds_; } |
| 1100 | 1113 |
| 1101 private: | 1114 private: |
| 1102 gfx::Insets restore_work_area_insets_; | 1115 gfx::Insets restore_work_area_insets_; |
| 1103 gfx::Rect keyboard_bounds_; | 1116 gfx::Rect keyboard_bounds_; |
| 1104 WorkspaceLayoutManager* layout_manager_; | 1117 WorkspaceLayoutManager* layout_manager_; |
| 1105 | 1118 |
| 1106 DISALLOW_COPY_AND_ASSIGN(WorkspaceLayoutManagerKeyboardTest); | 1119 DISALLOW_COPY_AND_ASSIGN(WorkspaceLayoutManagerKeyboardTest); |
| 1107 }; | 1120 }; |
| 1108 | 1121 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1196 std::unique_ptr<aura::Window> window( | 1209 std::unique_ptr<aura::Window> window( |
| 1197 CreateTestWindowInShellWithDelegate(&delegate2, -1, keyboard_bounds())); | 1210 CreateTestWindowInShellWithDelegate(&delegate2, -1, keyboard_bounds())); |
| 1198 wm::GetWindowState(window.get())->set_ignore_keyboard_bounds_change(true); | 1211 wm::GetWindowState(window.get())->set_ignore_keyboard_bounds_change(true); |
| 1199 wm::ActivateWindow(window.get()); | 1212 wm::ActivateWindow(window.get()); |
| 1200 | 1213 |
| 1201 EXPECT_EQ(keyboard_bounds(), window->bounds()); | 1214 EXPECT_EQ(keyboard_bounds(), window->bounds()); |
| 1202 ShowKeyboard(); | 1215 ShowKeyboard(); |
| 1203 EXPECT_EQ(keyboard_bounds(), window->bounds()); | 1216 EXPECT_EQ(keyboard_bounds(), window->bounds()); |
| 1204 } | 1217 } |
| 1205 | 1218 |
| 1219 TEST_F(WorkspaceLayoutManagerKeyboardTest, ChangeWorkAreaInNonStickyMode) { | |
| 1220 InitKeyboardBounds(); | |
| 1221 Shell::GetInstance()->CreateKeyboard(); | |
| 1222 keyboard::KeyboardController* kb_controller = | |
| 1223 keyboard::KeyboardController::GetInstance(); | |
| 1224 | |
| 1225 gfx::Rect work_area( | |
| 1226 display::Screen::GetScreen()->GetPrimaryDisplay().work_area()); | |
| 1227 | |
| 1228 aura::test::TestWindowDelegate delegate; | |
| 1229 gfx::Rect orig_window_bounds(0, 100, work_area.width(), | |
| 1230 work_area.height() - 100); | |
| 1231 gfx::Rect changed_window_bounds(0, 47, work_area.width(), | |
| 1232 work_area.height() - 100); | |
|
oshima
2016/07/27 21:40:23
can you compute this from keyboard bounds?
hariank
2016/07/27 23:00:38
Done.
| |
| 1233 std::unique_ptr<aura::Window> window( | |
| 1234 CreateTestWindowInShellWithDelegate(&delegate, -1, orig_window_bounds)); | |
| 1235 | |
| 1236 wm::ActivateWindow(window.get()); | |
| 1237 EXPECT_EQ(orig_window_bounds.ToString(), window->bounds().ToString()); | |
| 1238 | |
| 1239 // Open keyboard in non-sticky mode. | |
| 1240 kb_controller->ShowKeyboard(false); | |
| 1241 if (kb_controller->ui()->GetKeyboardWindow()->bounds().height() == 0) { | |
|
oshima
2016/07/27 21:40:23
no conditional branch in unit test. Why do you nee
hariank
2016/07/27 23:00:39
Done.
| |
| 1242 kb_controller->ui()->GetKeyboardWindow()->SetBounds( | |
| 1243 keyboard::FullWidthKeyboardBoundsFromRootBounds( | |
| 1244 Shell::GetPrimaryRootWindow()->bounds(), 100)); | |
| 1245 } | |
| 1246 // Window should be shifted up. | |
| 1247 EXPECT_EQ(changed_window_bounds.ToString(), window->bounds().ToString()); | |
| 1248 | |
| 1249 kb_controller->HideKeyboard( | |
| 1250 keyboard::KeyboardController::HIDE_REASON_AUTOMATIC); | |
| 1251 EXPECT_EQ(orig_window_bounds.ToString(), window->bounds().ToString()); | |
| 1252 | |
| 1253 // Open keyboard in sticky mode. | |
| 1254 kb_controller->ShowKeyboard(true); | |
| 1255 if (kb_controller->ui()->GetKeyboardWindow()->bounds().height() == 0) { | |
|
oshima
2016/07/27 21:40:23
same here.
hariank
2016/07/27 23:00:38
Done.
| |
| 1256 kb_controller->ui()->GetKeyboardWindow()->SetBounds( | |
| 1257 keyboard::FullWidthKeyboardBoundsFromRootBounds( | |
| 1258 Shell::GetPrimaryRootWindow()->bounds(), 100)); | |
| 1259 } | |
| 1260 // Window should be shifted up. | |
| 1261 EXPECT_EQ(changed_window_bounds.ToString(), window->bounds().ToString()); | |
| 1262 | |
| 1263 kb_controller->HideKeyboard( | |
| 1264 keyboard::KeyboardController::HIDE_REASON_AUTOMATIC); | |
| 1265 EXPECT_EQ(orig_window_bounds.ToString(), window->bounds().ToString()); | |
| 1266 } | |
| 1267 | |
| 1268 // When kAshUseNewVKWindowBehavior flag enabled, do not change accessibility | |
| 1269 // keyboard work area in non-sticky mode. | |
| 1270 TEST_F(WorkspaceLayoutManagerKeyboardTest, | |
| 1271 IgnoreWorkAreaChangeinNonStickyMode) { | |
| 1272 // Append flag to ignore work area change in non-sticky mode. | |
| 1273 SetVKFlag(); | |
| 1274 | |
| 1275 InitKeyboardBounds(); | |
| 1276 Shell::GetInstance()->CreateKeyboard(); | |
| 1277 keyboard::KeyboardController* kb_controller = | |
| 1278 keyboard::KeyboardController::GetInstance(); | |
| 1279 | |
| 1280 gfx::Rect work_area( | |
| 1281 display::Screen::GetScreen()->GetPrimaryDisplay().work_area()); | |
| 1282 | |
| 1283 aura::test::TestWindowDelegate delegate; | |
| 1284 gfx::Rect orig_window_bounds(0, 100, work_area.width(), | |
| 1285 work_area.height() - 100); | |
| 1286 gfx::Rect changed_window_bounds(0, 47, work_area.width(), | |
| 1287 work_area.height() - 100); | |
| 1288 std::unique_ptr<aura::Window> window( | |
| 1289 CreateTestWindowInShellWithDelegate(&delegate, -1, orig_window_bounds)); | |
| 1290 | |
| 1291 wm::ActivateWindow(window.get()); | |
| 1292 EXPECT_EQ(orig_window_bounds.ToString(), window->bounds().ToString()); | |
| 1293 | |
| 1294 // Open keyboard in non-sticky mode. | |
| 1295 kb_controller->ShowKeyboard(false); | |
| 1296 if (kb_controller->ui()->GetKeyboardWindow()->bounds().height() == 0) { | |
| 1297 kb_controller->ui()->GetKeyboardWindow()->SetBounds( | |
| 1298 keyboard::FullWidthKeyboardBoundsFromRootBounds( | |
| 1299 Shell::GetPrimaryRootWindow()->bounds(), 100)); | |
| 1300 } | |
| 1301 // Window should not be shifted up. | |
| 1302 EXPECT_EQ(orig_window_bounds.ToString(), window->bounds().ToString()); | |
| 1303 | |
| 1304 kb_controller->HideKeyboard( | |
| 1305 keyboard::KeyboardController::HIDE_REASON_AUTOMATIC); | |
| 1306 EXPECT_EQ(orig_window_bounds.ToString(), window->bounds().ToString()); | |
| 1307 | |
| 1308 // Open keyboard in sticky mode. | |
| 1309 kb_controller->ShowKeyboard(true); | |
| 1310 if (kb_controller->ui()->GetKeyboardWindow()->bounds().height() == 0) { | |
| 1311 kb_controller->ui()->GetKeyboardWindow()->SetBounds( | |
| 1312 keyboard::FullWidthKeyboardBoundsFromRootBounds( | |
| 1313 Shell::GetPrimaryRootWindow()->bounds(), 100)); | |
| 1314 } | |
| 1315 // Window should be shifted up. | |
| 1316 EXPECT_EQ(changed_window_bounds.ToString(), window->bounds().ToString()); | |
| 1317 | |
| 1318 kb_controller->HideKeyboard( | |
| 1319 keyboard::KeyboardController::HIDE_REASON_AUTOMATIC); | |
| 1320 EXPECT_EQ(orig_window_bounds.ToString(), window->bounds().ToString()); | |
| 1321 } | |
| 1322 | |
| 1206 } // namespace ash | 1323 } // namespace ash |
| OLD | NEW |