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

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

Issue 504793003: Resize BrowserFrameAsh and not RenderWidgetHostViewAura when keyboard bounds change. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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
« no previous file with comments | « ash/wm/workspace/workspace_layout_manager.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 993 matching lines...) Expand 10 before | Expand all | Expand 10 after
1004 Shell::GetInstance()->SetDisplayWorkAreaInsets( 1004 Shell::GetInstance()->SetDisplayWorkAreaInsets(
1005 Shell::GetPrimaryRootWindow(), 1005 Shell::GetPrimaryRootWindow(),
1006 restore_work_area_insets_); 1006 restore_work_area_insets_);
1007 layout_manager_->OnKeyboardBoundsChanging(gfx::Rect()); 1007 layout_manager_->OnKeyboardBoundsChanging(gfx::Rect());
1008 } 1008 }
1009 1009
1010 void SetKeyboardBounds(const gfx::Rect& bounds) { 1010 void SetKeyboardBounds(const gfx::Rect& bounds) {
1011 keyboard_bounds_ = bounds; 1011 keyboard_bounds_ = bounds;
1012 } 1012 }
1013 1013
1014 void Focus(ui::TextInputClient* text_input_client) {
1015 if (switches::IsTextInputFocusManagerEnabled()) {
1016 ui::TextInputFocusManager::GetInstance()->FocusTextInputClient(
1017 text_input_client);
1018 } else {
1019 aura::Window* root_window =
1020 ash::Shell::GetInstance()->GetPrimaryRootWindow();
1021 ui::InputMethod* input_method =
1022 root_window->GetProperty(aura::client::kRootWindowInputMethodKey);
1023 input_method->SetFocusedTextInputClient(text_input_client);
1024 }
1025 }
1026
1027 void Blur(ui::TextInputClient* text_input_client) {
1028 if (switches::IsTextInputFocusManagerEnabled()) {
1029 ui::TextInputFocusManager::GetInstance()->BlurTextInputClient(
1030 text_input_client);
1031 } else {
1032 aura::Window* root_window =
1033 ash::Shell::GetInstance()->GetPrimaryRootWindow();
1034 ui::InputMethod* input_method =
1035 root_window->GetProperty(aura::client::kRootWindowInputMethodKey);
1036 input_method->SetFocusedTextInputClient(NULL);
1037 }
1038 }
1039
1014 private: 1040 private:
1015 gfx::Insets restore_work_area_insets_; 1041 gfx::Insets restore_work_area_insets_;
1016 gfx::Rect keyboard_bounds_; 1042 gfx::Rect keyboard_bounds_;
1017 WorkspaceLayoutManager* layout_manager_; 1043 WorkspaceLayoutManager* layout_manager_;
1018 1044
1019 DISALLOW_COPY_AND_ASSIGN(WorkspaceLayoutManagerKeyboardTest); 1045 DISALLOW_COPY_AND_ASSIGN(WorkspaceLayoutManagerKeyboardTest);
1020 }; 1046 };
1021 1047
1022 class FakeTextInputClient : public ui::DummyTextInputClient { 1048 class FakeTextInputClient : public ui::DummyTextInputClient {
1023 public: 1049 public:
1024 explicit FakeTextInputClient(gfx::NativeWindow window) : window_(window) {} 1050 explicit FakeTextInputClient(gfx::NativeWindow window) : window_(window) {}
1025 virtual ~FakeTextInputClient() {} 1051 virtual ~FakeTextInputClient() {}
1026 1052
1027 virtual gfx::NativeWindow GetAttachedWindow() const OVERRIDE { 1053 virtual gfx::NativeWindow GetAttachedWindow() const OVERRIDE {
1028 return window_; 1054 return window_;
1029 } 1055 }
1030 1056
1031 private: 1057 private:
1032 gfx::NativeWindow window_; 1058 gfx::NativeWindow window_;
1033 1059
1034 DISALLOW_COPY_AND_ASSIGN(FakeTextInputClient); 1060 DISALLOW_COPY_AND_ASSIGN(FakeTextInputClient);
1035 }; 1061 };
1036 1062
1063 // Tests that when a child window gains focus the top level window containing it
1064 // is resized to fit the remaining workspace area.
1065 TEST_F(WorkspaceLayoutManagerKeyboardTest, ChildWindowFocused) {
1066 gfx::Rect work_area(
1067 Shell::GetScreen()->GetPrimaryDisplay().work_area());
1068 gfx::Rect keyboard_bounds(work_area.x(),
1069 work_area.y() + work_area.height() / 2,
1070 work_area.width(),
1071 work_area.height() / 2);
1072
1073 SetKeyboardBounds(keyboard_bounds);
1074
1075 aura::test::TestWindowDelegate delegate1;
1076 scoped_ptr<aura::Window> parent_window(CreateTestWindowInShellWithDelegate(
1077 &delegate1, -1, work_area));
1078 aura::test::TestWindowDelegate delegate2;
1079 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate(
1080 &delegate2, -1, work_area));
1081 parent_window->AddChild(window.get());
1082
1083 FakeTextInputClient text_input_client(window.get());
1084 Focus(&text_input_client);
1085
1086 int available_height =
1087 Shell::GetScreen()->GetPrimaryDisplay().bounds().height() -
1088 keyboard_bounds.height();
1089
1090 gfx::Rect initial_window_bounds(50, 50, 100, 500);
1091 parent_window->SetBounds(initial_window_bounds);
1092 EXPECT_EQ(initial_window_bounds.ToString(),
1093 parent_window->bounds().ToString());
1094 ShowKeyboard();
1095 EXPECT_EQ(gfx::Rect(50, 0, 100, available_height).ToString(),
1096 parent_window->bounds().ToString());
1097 HideKeyboard();
1098 EXPECT_EQ(initial_window_bounds.ToString(),
1099 parent_window->bounds().ToString());
1100
1101 Blur(&text_input_client);
1102 }
1103
1037 TEST_F(WorkspaceLayoutManagerKeyboardTest, AdjustWindowForA11yKeyboard) { 1104 TEST_F(WorkspaceLayoutManagerKeyboardTest, AdjustWindowForA11yKeyboard) {
1038 gfx::Rect work_area( 1105 gfx::Rect work_area(
1039 Shell::GetScreen()->GetPrimaryDisplay().work_area()); 1106 Shell::GetScreen()->GetPrimaryDisplay().work_area());
1040 gfx::Rect keyboard_bounds(work_area.x(), 1107 gfx::Rect keyboard_bounds(work_area.x(),
1041 work_area.y() + work_area.height() / 2, 1108 work_area.y() + work_area.height() / 2,
1042 work_area.width(), 1109 work_area.width(),
1043 work_area.height() / 2); 1110 work_area.height() / 2);
1044 1111
1045 SetKeyboardBounds(keyboard_bounds); 1112 SetKeyboardBounds(keyboard_bounds);
1046 1113
1047 aura::test::TestWindowDelegate delegate; 1114 aura::test::TestWindowDelegate delegate;
1048 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate( 1115 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate(
1049 &delegate, -1, work_area)); 1116 &delegate, -1, work_area));
1050 1117
1051 aura::Window* root_window = ash::Shell::GetInstance()->GetPrimaryRootWindow();
1052 FakeTextInputClient text_input_client(window.get()); 1118 FakeTextInputClient text_input_client(window.get());
1053 ui::InputMethod* input_method = 1119 Focus(&text_input_client);
1054 root_window->GetProperty(aura::client::kRootWindowInputMethodKey);
1055 if (switches::IsTextInputFocusManagerEnabled()) {
1056 ui::TextInputFocusManager::GetInstance()->FocusTextInputClient(
1057 &text_input_client);
1058 } else {
1059 input_method->SetFocusedTextInputClient(&text_input_client);
1060 }
1061 1120
1062 int available_height = 1121 int available_height =
1063 Shell::GetScreen()->GetPrimaryDisplay().bounds().height() - 1122 Shell::GetScreen()->GetPrimaryDisplay().bounds().height() -
1064 keyboard_bounds.height(); 1123 keyboard_bounds.height();
1065 1124
1066 EXPECT_EQ(gfx::Rect(work_area).ToString(), window->bounds().ToString()); 1125 EXPECT_EQ(gfx::Rect(work_area).ToString(), window->bounds().ToString());
1067 ShowKeyboard(); 1126 ShowKeyboard();
1068 EXPECT_EQ(gfx::Rect(work_area.origin(), 1127 EXPECT_EQ(gfx::Rect(work_area.origin(),
1069 gfx::Size(work_area.width(), available_height)).ToString(), 1128 gfx::Size(work_area.width(), available_height)).ToString(),
1070 window->bounds().ToString()); 1129 window->bounds().ToString());
1071 HideKeyboard(); 1130 HideKeyboard();
1072 EXPECT_EQ(gfx::Rect(work_area).ToString(), window->bounds().ToString()); 1131 EXPECT_EQ(gfx::Rect(work_area).ToString(), window->bounds().ToString());
1073 1132
1074 gfx::Rect small_window_bound(50, 50, 100, 500); 1133 gfx::Rect small_window_bound(50, 50, 100, 500);
1075 window->SetBounds(small_window_bound); 1134 window->SetBounds(small_window_bound);
1076 EXPECT_EQ(small_window_bound.ToString(), window->bounds().ToString()); 1135 EXPECT_EQ(small_window_bound.ToString(), window->bounds().ToString());
1077 ShowKeyboard(); 1136 ShowKeyboard();
1078 EXPECT_EQ(gfx::Rect(50, 0, 100, available_height).ToString(), 1137 EXPECT_EQ(gfx::Rect(50, 0, 100, available_height).ToString(),
1079 window->bounds().ToString()); 1138 window->bounds().ToString());
1080 HideKeyboard(); 1139 HideKeyboard();
1081 EXPECT_EQ(small_window_bound.ToString(), window->bounds().ToString()); 1140 EXPECT_EQ(small_window_bound.ToString(), window->bounds().ToString());
1082 1141
1083 if (switches::IsTextInputFocusManagerEnabled()) { 1142 Blur(&text_input_client);
1084 ui::TextInputFocusManager::GetInstance()->BlurTextInputClient(
1085 &text_input_client);
1086 } else {
1087 input_method->SetFocusedTextInputClient(NULL);
1088 }
1089 } 1143 }
1090 1144
1091 } // namespace ash 1145 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/workspace/workspace_layout_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698