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/wm/workspace/workspace_layout_manager.h" | 5 #include "ash/wm/workspace/workspace_layout_manager.h" |
6 | 6 |
7 #include "ash/display/display_layout.h" | 7 #include "ash/display/display_layout.h" |
8 #include "ash/display/display_manager.h" | 8 #include "ash/display/display_manager.h" |
9 #include "ash/root_window_controller.h" | 9 #include "ash/root_window_controller.h" |
10 #include "ash/screen_util.h" | 10 #include "ash/screen_util.h" |
11 #include "ash/session/session_state_delegate.h" | 11 #include "ash/session/session_state_delegate.h" |
12 #include "ash/shelf/shelf_layout_manager.h" | 12 #include "ash/shelf/shelf_layout_manager.h" |
13 #include "ash/shell.h" | 13 #include "ash/shell.h" |
14 #include "ash/shell_observer.h" | 14 #include "ash/shell_observer.h" |
15 #include "ash/shell_window_ids.h" | 15 #include "ash/shell_window_ids.h" |
16 #include "ash/test/ash_test_base.h" | 16 #include "ash/test/ash_test_base.h" |
17 #include "ash/wm/maximize_mode/workspace_backdrop_delegate.h" | 17 #include "ash/wm/maximize_mode/workspace_backdrop_delegate.h" |
18 #include "ash/wm/window_state.h" | 18 #include "ash/wm/window_state.h" |
19 #include "ash/wm/window_util.h" | 19 #include "ash/wm/window_util.h" |
20 #include "ash/wm/wm_event.h" | 20 #include "ash/wm/wm_event.h" |
21 #include "ash/wm/workspace/workspace_window_resizer.h" | 21 #include "ash/wm/workspace/workspace_window_resizer.h" |
22 #include "base/basictypes.h" | 22 #include "base/basictypes.h" |
23 #include "base/compiler_specific.h" | 23 #include "base/compiler_specific.h" |
24 #include "ui/aura/client/aura_constants.h" | 24 #include "ui/aura/client/aura_constants.h" |
25 #include "ui/aura/test/test_windows.h" | 25 #include "ui/aura/test/test_windows.h" |
26 #include "ui/aura/window.h" | 26 #include "ui/aura/window.h" |
27 #include "ui/aura/window_event_dispatcher.h" | 27 #include "ui/aura/window_event_dispatcher.h" |
28 #include "ui/base/ime/dummy_text_input_client.h" | |
29 #include "ui/base/ime/input_method.h" | |
28 #include "ui/base/ui_base_types.h" | 30 #include "ui/base/ui_base_types.h" |
29 #include "ui/gfx/insets.h" | 31 #include "ui/gfx/insets.h" |
30 #include "ui/gfx/screen.h" | 32 #include "ui/gfx/screen.h" |
31 #include "ui/views/widget/widget.h" | 33 #include "ui/views/widget/widget.h" |
32 #include "ui/views/widget/widget_delegate.h" | 34 #include "ui/views/widget/widget_delegate.h" |
33 #include "ui/wm/core/window_util.h" | 35 #include "ui/wm/core/window_util.h" |
34 | 36 |
35 namespace ash { | 37 namespace ash { |
36 namespace { | 38 namespace { |
37 | 39 |
(...skipping 895 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
933 window3.reset(); | 935 window3.reset(); |
934 EXPECT_EQ("b,x", | 936 EXPECT_EQ("b,x", |
935 GetWindowOrderAsString(backdrop, window1.get(), window2.get(), | 937 GetWindowOrderAsString(backdrop, window1.get(), window2.get(), |
936 window3.get())); | 938 window3.get())); |
937 ShowTopWindowBackdrop(false); | 939 ShowTopWindowBackdrop(false); |
938 EXPECT_EQ("b", | 940 EXPECT_EQ("b", |
939 GetWindowOrderAsString(NULL, window1.get(), window2.get(), | 941 GetWindowOrderAsString(NULL, window1.get(), window2.get(), |
940 window3.get())); | 942 window3.get())); |
941 } | 943 } |
942 | 944 |
945 class WorkspaceLayoutManagerKeyboardTest : public test::AshTestBase { | |
946 public: | |
947 WorkspaceLayoutManagerKeyboardTest() {} | |
948 virtual ~WorkspaceLayoutManagerKeyboardTest() {} | |
949 | |
950 virtual void SetUp() OVERRIDE { | |
951 test::AshTestBase::SetUp(); | |
952 UpdateDisplay("800x600"); | |
953 aura::Window* default_container = Shell::GetContainer( | |
954 Shell::GetPrimaryRootWindow(), kShellWindowId_DefaultContainer); | |
955 layout_manager_ = new WorkspaceLayoutManager(Shell::GetPrimaryRootWindow()); | |
956 default_container->SetLayoutManager(layout_manager_); | |
957 } | |
958 | |
959 aura::Window* CreateTestWindow(const gfx::Rect& bounds) { | |
960 return CreateTestWindowInShellWithBounds(bounds); | |
961 } | |
962 | |
963 void ShowKeyboard() { | |
964 restore_work_area_insets_ = Shell::GetScreen()->GetPrimaryDisplay(). | |
965 GetWorkAreaInsets(); | |
966 Shell::GetInstance()->SetDisplayWorkAreaInsets( | |
967 Shell::GetPrimaryRootWindow(), | |
968 gfx::Insets(0, 0, keyboard_bounds_.height(), 0)); | |
969 layout_manager_->OnKeyboardBoundsChanging(keyboard_bounds_); | |
970 } | |
971 | |
972 void HideKeyboard() { | |
973 Shell::GetInstance()->SetDisplayWorkAreaInsets( | |
974 Shell::GetPrimaryRootWindow(), | |
975 restore_work_area_insets_); | |
976 layout_manager_->OnKeyboardBoundsChanging(gfx::Rect()); | |
977 } | |
978 | |
979 void SetKeyboardBounds(const gfx::Rect& bounds) { | |
980 keyboard_bounds_ = bounds; | |
981 } | |
982 | |
983 private: | |
984 gfx::Insets restore_work_area_insets_; | |
985 gfx::Rect keyboard_bounds_; | |
986 WorkspaceLayoutManager *layout_manager_; | |
987 | |
988 DISALLOW_COPY_AND_ASSIGN(WorkspaceLayoutManagerKeyboardTest); | |
989 }; | |
990 | |
991 class FakeTextInputClient : public ui::DummyTextInputClient { | |
992 | |
flackr
2014/06/03 13:36:30
nit: no newline before public:
kevers
2014/06/03 15:32:44
Done.
| |
993 public: | |
994 FakeTextInputClient(gfx::NativeWindow window) { | |
995 window_ = window; | |
flackr
2014/06/03 13:36:30
nit: Use initializer list to assign members.
kevers
2014/06/03 15:32:44
Done.
| |
996 } | |
flackr
2014/06/03 13:36:30
nit: Add virtual dtor.
kevers
2014/06/03 15:32:44
Done.
| |
997 | |
998 virtual gfx::NativeWindow GetAttachedWindow() const OVERRIDE { | |
999 return window_; | |
1000 } | |
1001 | |
1002 private: | |
1003 gfx::NativeWindow window_; | |
1004 | |
1005 DISALLOW_COPY_AND_ASSIGN(FakeTextInputClient); | |
1006 }; | |
1007 | |
1008 TEST_F(WorkspaceLayoutManagerKeyboardTest, AdjustWindowForA11yKeyboard) { | |
1009 gfx::Rect work_area( | |
1010 Shell::GetScreen()->GetPrimaryDisplay().work_area()); | |
1011 gfx::Rect keyboard_bounds(work_area.x(), | |
1012 work_area.y() + work_area.height() / 2, | |
1013 work_area.width(), | |
1014 work_area.height() / 2); | |
1015 | |
1016 SetKeyboardBounds(keyboard_bounds); | |
1017 scoped_ptr<aura::Window> window( | |
1018 CreateTestWindowInShellWithBounds(work_area)); | |
1019 | |
1020 aura::Window* root_window = ash::Shell::GetInstance()->GetPrimaryRootWindow(); | |
1021 FakeTextInputClient text_input_client(window.get()); | |
1022 ui::InputMethod* input_method = | |
1023 root_window->GetProperty(aura::client::kRootWindowInputMethodKey); | |
1024 input_method->SetFocusedTextInputClient(&text_input_client); | |
1025 | |
1026 int available_height = | |
1027 Shell::GetScreen()->GetPrimaryDisplay().bounds().height() - | |
1028 keyboard_bounds.height(); | |
1029 | |
1030 EXPECT_EQ(gfx::Rect(work_area).ToString(), | |
1031 window->bounds().ToString()); | |
1032 ShowKeyboard(); | |
1033 EXPECT_EQ(gfx::Rect(work_area.origin(), | |
1034 gfx::Size(work_area.width(), available_height)).ToString(), | |
1035 window->bounds().ToString()); | |
1036 HideKeyboard(); | |
1037 | |
1038 window->SetBounds(gfx::Rect(50, 50, 100, 500)); | |
1039 EXPECT_EQ("50,50 100x500", window->bounds().ToString()); | |
1040 ShowKeyboard(); | |
1041 EXPECT_EQ(gfx::Rect(50, 0, 100, available_height).ToString(), | |
1042 window->bounds().ToString()); | |
1043 HideKeyboard(); | |
1044 input_method->SetFocusedTextInputClient(NULL); | |
1045 } | |
1046 | |
943 } // namespace ash | 1047 } // namespace ash |
OLD | NEW |