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

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: rebased & removed views::View::GetTextInputClient & removed GetFocusedTextInputClient. 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/ui_base_types.h" 30 #include "ui/base/ui_base_types.h"
33 #include "ui/gfx/geometry/insets.h" 31 #include "ui/gfx/geometry/insets.h"
34 #include "ui/gfx/screen.h" 32 #include "ui/gfx/screen.h"
35 #include "ui/views/widget/widget.h" 33 #include "ui/views/widget/widget.h"
36 #include "ui/views/widget/widget_delegate.h" 34 #include "ui/views/widget/widget_delegate.h"
37 #include "ui/wm/core/window_util.h" 35 #include "ui/wm/core/window_util.h"
38 36
39 namespace ash { 37 namespace ash {
40 namespace { 38 namespace {
41 39
(...skipping 962 matching lines...) Expand 10 before | Expand all | Expand 10 after
1004 Shell::GetInstance()->SetDisplayWorkAreaInsets( 1002 Shell::GetInstance()->SetDisplayWorkAreaInsets(
1005 Shell::GetPrimaryRootWindow(), 1003 Shell::GetPrimaryRootWindow(),
1006 restore_work_area_insets_); 1004 restore_work_area_insets_);
1007 layout_manager_->OnKeyboardBoundsChanging(gfx::Rect()); 1005 layout_manager_->OnKeyboardBoundsChanging(gfx::Rect());
1008 } 1006 }
1009 1007
1010 void SetKeyboardBounds(const gfx::Rect& bounds) { 1008 void SetKeyboardBounds(const gfx::Rect& bounds) {
1011 keyboard_bounds_ = bounds; 1009 keyboard_bounds_ = bounds;
1012 } 1010 }
1013 1011
1014 void Focus(ui::TextInputClient* text_input_client) {
1015 aura::Window* root_window =
1016 ash::Shell::GetInstance()->GetPrimaryRootWindow();
1017 ui::InputMethod* input_method = root_window->GetHost()->GetInputMethod();
1018 input_method->SetFocusedTextInputClient(text_input_client);
1019 }
1020
1021 void Blur(ui::TextInputClient* text_input_client) {
1022 aura::Window* root_window =
1023 ash::Shell::GetInstance()->GetPrimaryRootWindow();
1024 ui::InputMethod* input_method = root_window->GetHost()->GetInputMethod();
1025 input_method->SetFocusedTextInputClient(NULL);
1026 }
1027
1028 private: 1012 private:
1029 gfx::Insets restore_work_area_insets_; 1013 gfx::Insets restore_work_area_insets_;
1030 gfx::Rect keyboard_bounds_; 1014 gfx::Rect keyboard_bounds_;
1031 WorkspaceLayoutManager* layout_manager_; 1015 WorkspaceLayoutManager* layout_manager_;
1032 1016
1033 DISALLOW_COPY_AND_ASSIGN(WorkspaceLayoutManagerKeyboardTest); 1017 DISALLOW_COPY_AND_ASSIGN(WorkspaceLayoutManagerKeyboardTest);
1034 }; 1018 };
1035 1019
1036 class FakeTextInputClient : public ui::DummyTextInputClient {
1037 public:
1038 explicit FakeTextInputClient(gfx::NativeWindow window) : window_(window) {}
1039 ~FakeTextInputClient() override {}
1040
1041 gfx::NativeWindow GetAttachedWindow() const override { return window_; }
1042
1043 private:
1044 gfx::NativeWindow window_;
1045
1046 DISALLOW_COPY_AND_ASSIGN(FakeTextInputClient);
1047 };
1048
1049 // Tests that when a child window gains focus the top level window containing it 1020 // Tests that when a child window gains focus the top level window containing it
1050 // is resized to fit the remaining workspace area. 1021 // is resized to fit the remaining workspace area.
1051 TEST_F(WorkspaceLayoutManagerKeyboardTest, ChildWindowFocused) { 1022 TEST_F(WorkspaceLayoutManagerKeyboardTest, ChildWindowFocused) {
1052 gfx::Rect work_area( 1023 gfx::Rect work_area(
1053 Shell::GetScreen()->GetPrimaryDisplay().work_area()); 1024 Shell::GetScreen()->GetPrimaryDisplay().work_area());
1054 gfx::Rect keyboard_bounds(work_area.x(), 1025 gfx::Rect keyboard_bounds(work_area.x(),
1055 work_area.y() + work_area.height() / 2, 1026 work_area.y() + work_area.height() / 2,
1056 work_area.width(), 1027 work_area.width(),
1057 work_area.height() / 2); 1028 work_area.height() / 2);
1058 1029
1059 SetKeyboardBounds(keyboard_bounds); 1030 SetKeyboardBounds(keyboard_bounds);
1060 1031
1061 aura::test::TestWindowDelegate delegate1; 1032 aura::test::TestWindowDelegate delegate1;
1062 scoped_ptr<aura::Window> parent_window(CreateTestWindowInShellWithDelegate( 1033 scoped_ptr<aura::Window> parent_window(CreateTestWindowInShellWithDelegate(
1063 &delegate1, -1, work_area)); 1034 &delegate1, -1, work_area));
1064 aura::test::TestWindowDelegate delegate2; 1035 aura::test::TestWindowDelegate delegate2;
1065 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate( 1036 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate(
1066 &delegate2, -1, work_area)); 1037 &delegate2, -1, work_area));
1067 parent_window->AddChild(window.get()); 1038 parent_window->AddChild(window.get());
1068 1039
1069 FakeTextInputClient text_input_client(window.get()); 1040 wm::ActivateWindow(window.get());
1070 Focus(&text_input_client);
1071 1041
1072 int available_height = 1042 int available_height =
1073 Shell::GetScreen()->GetPrimaryDisplay().bounds().height() - 1043 Shell::GetScreen()->GetPrimaryDisplay().bounds().height() -
1074 keyboard_bounds.height(); 1044 keyboard_bounds.height();
1075 1045
1076 gfx::Rect initial_window_bounds(50, 50, 100, 500); 1046 gfx::Rect initial_window_bounds(50, 50, 100, 500);
1077 parent_window->SetBounds(initial_window_bounds); 1047 parent_window->SetBounds(initial_window_bounds);
1078 EXPECT_EQ(initial_window_bounds.ToString(), 1048 EXPECT_EQ(initial_window_bounds.ToString(),
1079 parent_window->bounds().ToString()); 1049 parent_window->bounds().ToString());
1080 ShowKeyboard(); 1050 ShowKeyboard();
1081 EXPECT_EQ(gfx::Rect(50, 0, 100, available_height).ToString(), 1051 EXPECT_EQ(gfx::Rect(50, 0, 100, available_height).ToString(),
1082 parent_window->bounds().ToString()); 1052 parent_window->bounds().ToString());
1083 HideKeyboard(); 1053 HideKeyboard();
1084 EXPECT_EQ(initial_window_bounds.ToString(), 1054 EXPECT_EQ(initial_window_bounds.ToString(),
1085 parent_window->bounds().ToString()); 1055 parent_window->bounds().ToString());
1086
1087 Blur(&text_input_client);
1088 } 1056 }
1089 1057
1090 TEST_F(WorkspaceLayoutManagerKeyboardTest, AdjustWindowForA11yKeyboard) { 1058 TEST_F(WorkspaceLayoutManagerKeyboardTest, AdjustWindowForA11yKeyboard) {
1091 gfx::Rect work_area( 1059 gfx::Rect work_area(
1092 Shell::GetScreen()->GetPrimaryDisplay().work_area()); 1060 Shell::GetScreen()->GetPrimaryDisplay().work_area());
1093 gfx::Rect keyboard_bounds(work_area.x(), 1061 gfx::Rect keyboard_bounds(work_area.x(),
1094 work_area.y() + work_area.height() / 2, 1062 work_area.y() + work_area.height() / 2,
1095 work_area.width(), 1063 work_area.width(),
1096 work_area.height() / 2); 1064 work_area.height() / 2);
1097 1065
1098 SetKeyboardBounds(keyboard_bounds); 1066 SetKeyboardBounds(keyboard_bounds);
1099 1067
1100 aura::test::TestWindowDelegate delegate; 1068 aura::test::TestWindowDelegate delegate;
1101 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate( 1069 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate(
1102 &delegate, -1, work_area)); 1070 &delegate, -1, work_area));
1103 1071
1104 FakeTextInputClient text_input_client(window.get());
1105 Focus(&text_input_client);
1106
1107 int available_height = 1072 int available_height =
1108 Shell::GetScreen()->GetPrimaryDisplay().bounds().height() - 1073 Shell::GetScreen()->GetPrimaryDisplay().bounds().height() -
1109 keyboard_bounds.height(); 1074 keyboard_bounds.height();
1110 1075
1076 wm::ActivateWindow(window.get());
1077
1111 EXPECT_EQ(gfx::Rect(work_area).ToString(), window->bounds().ToString()); 1078 EXPECT_EQ(gfx::Rect(work_area).ToString(), window->bounds().ToString());
1112 ShowKeyboard(); 1079 ShowKeyboard();
1113 EXPECT_EQ(gfx::Rect(work_area.origin(), 1080 EXPECT_EQ(gfx::Rect(work_area.origin(),
1114 gfx::Size(work_area.width(), available_height)).ToString(), 1081 gfx::Size(work_area.width(), available_height)).ToString(),
1115 window->bounds().ToString()); 1082 window->bounds().ToString());
1116 HideKeyboard(); 1083 HideKeyboard();
1117 EXPECT_EQ(gfx::Rect(work_area).ToString(), window->bounds().ToString()); 1084 EXPECT_EQ(gfx::Rect(work_area).ToString(), window->bounds().ToString());
1118 1085
1119 gfx::Rect small_window_bound(50, 50, 100, 500); 1086 gfx::Rect small_window_bound(50, 50, 100, 500);
1120 window->SetBounds(small_window_bound); 1087 window->SetBounds(small_window_bound);
(...skipping 11 matching lines...) Expand all
1132 EXPECT_EQ(occluded_window_bounds.ToString(), 1099 EXPECT_EQ(occluded_window_bounds.ToString(),
1133 occluded_window_bounds.ToString()); 1100 occluded_window_bounds.ToString());
1134 ShowKeyboard(); 1101 ShowKeyboard();
1135 EXPECT_EQ(gfx::Rect(50, 1102 EXPECT_EQ(gfx::Rect(50,
1136 keyboard_bounds.y() - keyboard_bounds.height()/2, 1103 keyboard_bounds.y() - keyboard_bounds.height()/2,
1137 occluded_window_bounds.width(), 1104 occluded_window_bounds.width(),
1138 occluded_window_bounds.height()).ToString(), 1105 occluded_window_bounds.height()).ToString(),
1139 window->bounds().ToString()); 1106 window->bounds().ToString());
1140 HideKeyboard(); 1107 HideKeyboard();
1141 EXPECT_EQ(occluded_window_bounds.ToString(), window->bounds().ToString()); 1108 EXPECT_EQ(occluded_window_bounds.ToString(), window->bounds().ToString());
1142
1143 Blur(&text_input_client);
1144 } 1109 }
1145 1110
1146 } // namespace ash 1111 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698