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

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

Issue 1177503003: Remove the 2-level input method system & InputMethodBridge. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: reverted changes for MockInputMethod. Created 5 years, 6 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/wm/workspace/workspace_layout_manager.h" 5 #include "ash/wm/workspace/workspace_layout_manager.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "ash/display/display_layout.h" 9 #include "ash/display/display_layout.h"
10 #include "ash/display/display_manager.h" 10 #include "ash/display/display_manager.h"
11 #include "ash/root_window_controller.h" 11 #include "ash/root_window_controller.h"
12 #include "ash/screen_util.h" 12 #include "ash/screen_util.h"
13 #include "ash/session/session_state_delegate.h" 13 #include "ash/session/session_state_delegate.h"
14 #include "ash/shelf/shelf_layout_manager.h" 14 #include "ash/shelf/shelf_layout_manager.h"
15 #include "ash/shell.h" 15 #include "ash/shell.h"
16 #include "ash/shell_observer.h" 16 #include "ash/shell_observer.h"
17 #include "ash/shell_window_ids.h" 17 #include "ash/shell_window_ids.h"
18 #include "ash/test/ash_test_base.h" 18 #include "ash/test/ash_test_base.h"
19 #include "ash/wm/maximize_mode/workspace_backdrop_delegate.h" 19 #include "ash/wm/maximize_mode/workspace_backdrop_delegate.h"
20 #include "ash/wm/window_state.h" 20 #include "ash/wm/window_state.h"
21 #include "ash/wm/window_util.h" 21 #include "ash/wm/window_util.h"
22 #include "ash/wm/wm_event.h" 22 #include "ash/wm/wm_event.h"
23 #include "ash/wm/workspace/workspace_window_resizer.h" 23 #include "ash/wm/workspace/workspace_window_resizer.h"
24 #include "base/basictypes.h" 24 #include "base/basictypes.h"
25 #include "base/compiler_specific.h" 25 #include "base/compiler_specific.h"
26 #include "ui/aura/client/aura_constants.h" 26 #include "ui/aura/client/aura_constants.h"
27 #include "ui/aura/test/test_windows.h" 27 #include "ui/aura/test/test_windows.h"
28 #include "ui/aura/window.h" 28 #include "ui/aura/window.h"
29 #include "ui/aura/window_event_dispatcher.h" 29 #include "ui/aura/window_event_dispatcher.h"
30 #include "ui/base/ime/dummy_text_input_client.h"
31 #include "ui/base/ime/input_method.h"
32 #include "ui/base/ime/text_input_focus_manager.h"
33 #include "ui/base/ui_base_switches_util.h" 30 #include "ui/base/ui_base_switches_util.h"
34 #include "ui/base/ui_base_types.h" 31 #include "ui/base/ui_base_types.h"
35 #include "ui/gfx/geometry/insets.h" 32 #include "ui/gfx/geometry/insets.h"
36 #include "ui/gfx/screen.h" 33 #include "ui/gfx/screen.h"
37 #include "ui/views/widget/widget.h" 34 #include "ui/views/widget/widget.h"
38 #include "ui/views/widget/widget_delegate.h" 35 #include "ui/views/widget/widget_delegate.h"
39 #include "ui/wm/core/window_util.h" 36 #include "ui/wm/core/window_util.h"
40 37
41 namespace ash { 38 namespace ash {
42 namespace { 39 namespace {
(...skipping 963 matching lines...) Expand 10 before | Expand all | Expand 10 after
1006 Shell::GetInstance()->SetDisplayWorkAreaInsets( 1003 Shell::GetInstance()->SetDisplayWorkAreaInsets(
1007 Shell::GetPrimaryRootWindow(), 1004 Shell::GetPrimaryRootWindow(),
1008 restore_work_area_insets_); 1005 restore_work_area_insets_);
1009 layout_manager_->OnKeyboardBoundsChanging(gfx::Rect()); 1006 layout_manager_->OnKeyboardBoundsChanging(gfx::Rect());
1010 } 1007 }
1011 1008
1012 void SetKeyboardBounds(const gfx::Rect& bounds) { 1009 void SetKeyboardBounds(const gfx::Rect& bounds) {
1013 keyboard_bounds_ = bounds; 1010 keyboard_bounds_ = bounds;
1014 } 1011 }
1015 1012
1016 void Focus(ui::TextInputClient* text_input_client) {
1017 if (switches::IsTextInputFocusManagerEnabled()) {
1018 ui::TextInputFocusManager::GetInstance()->FocusTextInputClient(
1019 text_input_client);
1020 } else {
1021 aura::Window* root_window =
1022 ash::Shell::GetInstance()->GetPrimaryRootWindow();
1023 ui::InputMethod* input_method = root_window->GetHost()->GetInputMethod();
1024 input_method->SetFocusedTextInputClient(text_input_client);
1025 }
1026 }
1027
1028 void Blur(ui::TextInputClient* text_input_client) {
1029 if (switches::IsTextInputFocusManagerEnabled()) {
1030 ui::TextInputFocusManager::GetInstance()->BlurTextInputClient(
1031 text_input_client);
1032 } else {
1033 aura::Window* root_window =
1034 ash::Shell::GetInstance()->GetPrimaryRootWindow();
1035 ui::InputMethod* input_method = root_window->GetHost()->GetInputMethod();
1036 input_method->SetFocusedTextInputClient(NULL);
1037 }
1038 }
1039
1040 private: 1013 private:
1041 gfx::Insets restore_work_area_insets_; 1014 gfx::Insets restore_work_area_insets_;
1042 gfx::Rect keyboard_bounds_; 1015 gfx::Rect keyboard_bounds_;
1043 WorkspaceLayoutManager* layout_manager_; 1016 WorkspaceLayoutManager* layout_manager_;
1044 1017
1045 DISALLOW_COPY_AND_ASSIGN(WorkspaceLayoutManagerKeyboardTest); 1018 DISALLOW_COPY_AND_ASSIGN(WorkspaceLayoutManagerKeyboardTest);
1046 }; 1019 };
1047 1020
1048 class FakeTextInputClient : public ui::DummyTextInputClient {
1049 public:
1050 explicit FakeTextInputClient(gfx::NativeWindow window) : window_(window) {}
1051 ~FakeTextInputClient() override {}
1052
1053 gfx::NativeWindow GetAttachedWindow() const override { return window_; }
1054
1055 private:
1056 gfx::NativeWindow window_;
1057
1058 DISALLOW_COPY_AND_ASSIGN(FakeTextInputClient);
1059 };
1060
1061 // Tests that when a child window gains focus the top level window containing it 1021 // Tests that when a child window gains focus the top level window containing it
1062 // is resized to fit the remaining workspace area. 1022 // is resized to fit the remaining workspace area.
1063 TEST_F(WorkspaceLayoutManagerKeyboardTest, ChildWindowFocused) { 1023 TEST_F(WorkspaceLayoutManagerKeyboardTest, ChildWindowFocused) {
1064 gfx::Rect work_area( 1024 gfx::Rect work_area(
1065 Shell::GetScreen()->GetPrimaryDisplay().work_area()); 1025 Shell::GetScreen()->GetPrimaryDisplay().work_area());
1066 gfx::Rect keyboard_bounds(work_area.x(), 1026 gfx::Rect keyboard_bounds(work_area.x(),
1067 work_area.y() + work_area.height() / 2, 1027 work_area.y() + work_area.height() / 2,
1068 work_area.width(), 1028 work_area.width(),
1069 work_area.height() / 2); 1029 work_area.height() / 2);
1070 1030
1071 SetKeyboardBounds(keyboard_bounds); 1031 SetKeyboardBounds(keyboard_bounds);
1072 1032
1073 aura::test::TestWindowDelegate delegate1; 1033 aura::test::TestWindowDelegate delegate1;
1074 scoped_ptr<aura::Window> parent_window(CreateTestWindowInShellWithDelegate( 1034 scoped_ptr<aura::Window> parent_window(CreateTestWindowInShellWithDelegate(
1075 &delegate1, -1, work_area)); 1035 &delegate1, -1, work_area));
1076 aura::test::TestWindowDelegate delegate2; 1036 aura::test::TestWindowDelegate delegate2;
1077 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate( 1037 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate(
1078 &delegate2, -1, work_area)); 1038 &delegate2, -1, work_area));
1079 parent_window->AddChild(window.get()); 1039 parent_window->AddChild(window.get());
1080 1040
1081 FakeTextInputClient text_input_client(window.get()); 1041 wm::ActivateWindow(window.get());
1082 Focus(&text_input_client);
1083 1042
1084 int available_height = 1043 int available_height =
1085 Shell::GetScreen()->GetPrimaryDisplay().bounds().height() - 1044 Shell::GetScreen()->GetPrimaryDisplay().bounds().height() -
1086 keyboard_bounds.height(); 1045 keyboard_bounds.height();
1087 1046
1088 gfx::Rect initial_window_bounds(50, 50, 100, 500); 1047 gfx::Rect initial_window_bounds(50, 50, 100, 500);
1089 parent_window->SetBounds(initial_window_bounds); 1048 parent_window->SetBounds(initial_window_bounds);
1090 EXPECT_EQ(initial_window_bounds.ToString(), 1049 EXPECT_EQ(initial_window_bounds.ToString(),
1091 parent_window->bounds().ToString()); 1050 parent_window->bounds().ToString());
1092 ShowKeyboard(); 1051 ShowKeyboard();
1093 EXPECT_EQ(gfx::Rect(50, 0, 100, available_height).ToString(), 1052 EXPECT_EQ(gfx::Rect(50, 0, 100, available_height).ToString(),
1094 parent_window->bounds().ToString()); 1053 parent_window->bounds().ToString());
1095 HideKeyboard(); 1054 HideKeyboard();
1096 EXPECT_EQ(initial_window_bounds.ToString(), 1055 EXPECT_EQ(initial_window_bounds.ToString(),
1097 parent_window->bounds().ToString()); 1056 parent_window->bounds().ToString());
1098
1099 Blur(&text_input_client);
1100 } 1057 }
1101 1058
1102 TEST_F(WorkspaceLayoutManagerKeyboardTest, AdjustWindowForA11yKeyboard) { 1059 TEST_F(WorkspaceLayoutManagerKeyboardTest, AdjustWindowForA11yKeyboard) {
1103 gfx::Rect work_area( 1060 gfx::Rect work_area(
1104 Shell::GetScreen()->GetPrimaryDisplay().work_area()); 1061 Shell::GetScreen()->GetPrimaryDisplay().work_area());
1105 gfx::Rect keyboard_bounds(work_area.x(), 1062 gfx::Rect keyboard_bounds(work_area.x(),
1106 work_area.y() + work_area.height() / 2, 1063 work_area.y() + work_area.height() / 2,
1107 work_area.width(), 1064 work_area.width(),
1108 work_area.height() / 2); 1065 work_area.height() / 2);
1109 1066
1110 SetKeyboardBounds(keyboard_bounds); 1067 SetKeyboardBounds(keyboard_bounds);
1111 1068
1112 aura::test::TestWindowDelegate delegate; 1069 aura::test::TestWindowDelegate delegate;
1113 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate( 1070 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate(
1114 &delegate, -1, work_area)); 1071 &delegate, -1, work_area));
1115 1072
1116 FakeTextInputClient text_input_client(window.get());
1117 Focus(&text_input_client);
1118
1119 int available_height = 1073 int available_height =
1120 Shell::GetScreen()->GetPrimaryDisplay().bounds().height() - 1074 Shell::GetScreen()->GetPrimaryDisplay().bounds().height() -
1121 keyboard_bounds.height(); 1075 keyboard_bounds.height();
1122 1076
1077 wm::ActivateWindow(window.get());
1078
1123 EXPECT_EQ(gfx::Rect(work_area).ToString(), window->bounds().ToString()); 1079 EXPECT_EQ(gfx::Rect(work_area).ToString(), window->bounds().ToString());
1124 ShowKeyboard(); 1080 ShowKeyboard();
1125 EXPECT_EQ(gfx::Rect(work_area.origin(), 1081 EXPECT_EQ(gfx::Rect(work_area.origin(),
1126 gfx::Size(work_area.width(), available_height)).ToString(), 1082 gfx::Size(work_area.width(), available_height)).ToString(),
1127 window->bounds().ToString()); 1083 window->bounds().ToString());
1128 HideKeyboard(); 1084 HideKeyboard();
1129 EXPECT_EQ(gfx::Rect(work_area).ToString(), window->bounds().ToString()); 1085 EXPECT_EQ(gfx::Rect(work_area).ToString(), window->bounds().ToString());
1130 1086
1131 gfx::Rect small_window_bound(50, 50, 100, 500); 1087 gfx::Rect small_window_bound(50, 50, 100, 500);
1132 window->SetBounds(small_window_bound); 1088 window->SetBounds(small_window_bound);
(...skipping 11 matching lines...) Expand all
1144 EXPECT_EQ(occluded_window_bounds.ToString(), 1100 EXPECT_EQ(occluded_window_bounds.ToString(),
1145 occluded_window_bounds.ToString()); 1101 occluded_window_bounds.ToString());
1146 ShowKeyboard(); 1102 ShowKeyboard();
1147 EXPECT_EQ(gfx::Rect(50, 1103 EXPECT_EQ(gfx::Rect(50,
1148 keyboard_bounds.y() - keyboard_bounds.height()/2, 1104 keyboard_bounds.y() - keyboard_bounds.height()/2,
1149 occluded_window_bounds.width(), 1105 occluded_window_bounds.width(),
1150 occluded_window_bounds.height()).ToString(), 1106 occluded_window_bounds.height()).ToString(),
1151 window->bounds().ToString()); 1107 window->bounds().ToString());
1152 HideKeyboard(); 1108 HideKeyboard();
1153 EXPECT_EQ(occluded_window_bounds.ToString(), window->bounds().ToString()); 1109 EXPECT_EQ(occluded_window_bounds.ToString(), window->bounds().ToString());
1154
1155 Blur(&text_input_client);
1156 } 1110 }
1157 1111
1158 } // namespace ash 1112 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698