Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(97)

Side by Side Diff: ash/wm/workspace/workspace_layout_manager_unittest.cc

Issue 2180603002: Virtual keyboard - do not change work area of screen if in non-sticky mode. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Virtual keyboard - do not change work area of screen if in non-sticky mode Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 1039 matching lines...) Expand 10 before | Expand all | Expand 10 after
1089 1094
1090 // Initializes the keyboard bounds using the bottom half of the work area. 1095 // Initializes the keyboard bounds using the bottom half of the work area.
1091 void InitKeyboardBounds() { 1096 void InitKeyboardBounds() {
1092 gfx::Rect work_area( 1097 gfx::Rect work_area(
1093 display::Screen::GetScreen()->GetPrimaryDisplay().work_area()); 1098 display::Screen::GetScreen()->GetPrimaryDisplay().work_area());
1094 keyboard_bounds_.SetRect(work_area.x(), 1099 keyboard_bounds_.SetRect(work_area.x(),
1095 work_area.y() + work_area.height() / 2, 1100 work_area.y() + work_area.height() / 2,
1096 work_area.width(), work_area.height() / 2); 1101 work_area.width(), work_area.height() / 2);
1097 } 1102 }
1098 1103
1104 void EnableNewVKMode() {
1105 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
1106 if (!command_line->HasSwitch(switches::kAshUseNewVKWindowBehavior)) {
1107 command_line->AppendSwitch(switches::kAshUseNewVKWindowBehavior);
1108 }
1109 }
1110
1099 const gfx::Rect& keyboard_bounds() const { return keyboard_bounds_; } 1111 const gfx::Rect& keyboard_bounds() const { return keyboard_bounds_; }
1100 1112
1101 private: 1113 private:
1102 gfx::Insets restore_work_area_insets_; 1114 gfx::Insets restore_work_area_insets_;
1103 gfx::Rect keyboard_bounds_; 1115 gfx::Rect keyboard_bounds_;
1104 WorkspaceLayoutManager* layout_manager_; 1116 WorkspaceLayoutManager* layout_manager_;
1105 1117
1106 DISALLOW_COPY_AND_ASSIGN(WorkspaceLayoutManagerKeyboardTest); 1118 DISALLOW_COPY_AND_ASSIGN(WorkspaceLayoutManagerKeyboardTest);
1107 }; 1119 };
1108 1120
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1196 std::unique_ptr<aura::Window> window( 1208 std::unique_ptr<aura::Window> window(
1197 CreateTestWindowInShellWithDelegate(&delegate2, -1, keyboard_bounds())); 1209 CreateTestWindowInShellWithDelegate(&delegate2, -1, keyboard_bounds()));
1198 wm::GetWindowState(window.get())->set_ignore_keyboard_bounds_change(true); 1210 wm::GetWindowState(window.get())->set_ignore_keyboard_bounds_change(true);
1199 wm::ActivateWindow(window.get()); 1211 wm::ActivateWindow(window.get());
1200 1212
1201 EXPECT_EQ(keyboard_bounds(), window->bounds()); 1213 EXPECT_EQ(keyboard_bounds(), window->bounds());
1202 ShowKeyboard(); 1214 ShowKeyboard();
1203 EXPECT_EQ(keyboard_bounds(), window->bounds()); 1215 EXPECT_EQ(keyboard_bounds(), window->bounds());
1204 } 1216 }
1205 1217
1218 TEST_F(WorkspaceLayoutManagerKeyboardTest, ChangeWorkAreaInNonStickyMode) {
1219 keyboard::SetAccessibilityKeyboardEnabled(true);
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 std::unique_ptr<aura::Window> window(
1232 CreateTestWindowInShellWithDelegate(&delegate, -1, orig_window_bounds));
1233
1234 wm::ActivateWindow(window.get());
1235 EXPECT_EQ(orig_window_bounds.ToString(), window->bounds().ToString());
oshima 2016/07/28 15:53:47 comparing with ToString() is old style. Can you ju
hariank 2016/07/28 17:24:10 Done.
1236
1237 // Open keyboard in non-sticky mode.
1238 kb_controller->ShowKeyboard(false);
1239 kb_controller->ui()->GetKeyboardWindow()->SetBounds(
1240 keyboard::FullWidthKeyboardBoundsFromRootBounds(
1241 Shell::GetPrimaryRootWindow()->bounds(), 100));
oshima 2016/07/28 15:53:47 Did you copy this from https://cs.chromium.org/chr
hariank 2016/07/28 17:24:10 Done.
1242
1243 int shift =
1244 work_area.height() - kb_controller->GetContainerWindow()->bounds().y();
1245 gfx::Rect changed_window_bounds(0, 100 - shift, work_area.width(),
1246 work_area.height() - 100);
oshima 2016/07/28 15:53:47 compure this from orig_window_bounds and Offset.
hariank 2016/07/28 17:24:10 Done.
oshima 2016/07/28 17:33:48 Sorry I wasn't clear. Here is what I meant gfx::R
hariank 2016/07/28 17:45:12 Done.
1247 // Window should be shifted up.
1248 EXPECT_EQ(changed_window_bounds.ToString(), window->bounds().ToString());
1249
1250 kb_controller->HideKeyboard(
1251 keyboard::KeyboardController::HIDE_REASON_AUTOMATIC);
1252 EXPECT_EQ(orig_window_bounds.ToString(), window->bounds().ToString());
1253
1254 // Open keyboard in sticky mode.
1255 kb_controller->ShowKeyboard(true);
1256 kb_controller->ui()->GetKeyboardWindow()->SetBounds(
1257 keyboard::FullWidthKeyboardBoundsFromRootBounds(
1258 Shell::GetPrimaryRootWindow()->bounds(), 100));
1259 // Window should be shifted up.
1260 EXPECT_EQ(changed_window_bounds.ToString(), window->bounds().ToString());
1261
1262 kb_controller->HideKeyboard(
1263 keyboard::KeyboardController::HIDE_REASON_AUTOMATIC);
1264 EXPECT_EQ(orig_window_bounds.ToString(), window->bounds().ToString());
1265 }
1266
1267 // When kAshUseNewVKWindowBehavior flag enabled, do not change accessibility
1268 // keyboard work area in non-sticky mode.
1269 TEST_F(WorkspaceLayoutManagerKeyboardTest,
1270 IgnoreWorkAreaChangeinNonStickyMode) {
1271 // Append flag to ignore work area change in non-sticky mode.
1272 EnableNewVKMode();
1273
1274 keyboard::SetAccessibilityKeyboardEnabled(true);
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 std::unique_ptr<aura::Window> window(
1287 CreateTestWindowInShellWithDelegate(&delegate, -1, orig_window_bounds));
1288
1289 wm::ActivateWindow(window.get());
1290 EXPECT_EQ(orig_window_bounds.ToString(), window->bounds().ToString());
1291
1292 // Open keyboard in non-sticky mode.
1293 kb_controller->ShowKeyboard(false);
1294 kb_controller->ui()->GetKeyboardWindow()->SetBounds(
1295 keyboard::FullWidthKeyboardBoundsFromRootBounds(
1296 Shell::GetPrimaryRootWindow()->bounds(), 100));
1297
1298 int shift =
1299 work_area.height() - kb_controller->GetContainerWindow()->bounds().y();
1300 gfx::Rect changed_window_bounds(0, 100 - shift, work_area.width(),
1301 work_area.height() - 100);
oshima 2016/07/28 15:53:47 same here, and move this to here it is used.
hariank 2016/07/28 17:24:10 Done.
1302 // Window should not be shifted up.
1303 EXPECT_EQ(orig_window_bounds.ToString(), window->bounds().ToString());
1304
1305 kb_controller->HideKeyboard(
1306 keyboard::KeyboardController::HIDE_REASON_AUTOMATIC);
1307 EXPECT_EQ(orig_window_bounds.ToString(), window->bounds().ToString());
1308
1309 // Open keyboard in sticky mode.
1310 kb_controller->ShowKeyboard(true);
1311 kb_controller->ui()->GetKeyboardWindow()->SetBounds(
1312 keyboard::FullWidthKeyboardBoundsFromRootBounds(
1313 Shell::GetPrimaryRootWindow()->bounds(), 100));
1314 // Window should be shifted up.
1315 EXPECT_EQ(changed_window_bounds.ToString(), window->bounds().ToString());
1316
1317 kb_controller->HideKeyboard(
1318 keyboard::KeyboardController::HIDE_REASON_AUTOMATIC);
1319 EXPECT_EQ(orig_window_bounds.ToString(), window->bounds().ToString());
1320 }
1321
1206 } // namespace ash 1322 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/wm/workspace/workspace_layout_manager.cc ('k') | chrome/browser/chromeos/login/chrome_restart_request.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698