| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/mus/test/wm_test_base.h" | 5 #include "ash/mus/test/wm_test_base.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "ash/mus/root_window_controller.h" | 10 #include "ash/mus/root_window_controller.h" |
| 11 #include "ash/mus/test/wm_test_helper.h" | 11 #include "ash/mus/test/wm_test_helper.h" |
| 12 #include "ash/mus/test/wm_test_screen.h" | 12 #include "ash/mus/test/wm_test_screen.h" |
| 13 #include "ash/mus/window_manager.h" | 13 #include "ash/mus/window_manager.h" |
| 14 #include "ash/mus/window_manager_application.h" | 14 #include "ash/mus/window_manager_application.h" |
| 15 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 16 #include "base/strings/string_split.h" | 16 #include "base/strings/string_split.h" |
| 17 #include "services/ui/public/cpp/property_type_converters.h" | 17 #include "services/ui/public/cpp/property_type_converters.h" |
| 18 #include "services/ui/public/cpp/window_tree_client.h" | 18 #include "services/ui/public/cpp/window_tree_client.h" |
| 19 #include "ui/display/display.h" | 19 #include "ui/display/display.h" |
| 20 | 20 |
| 21 namespace ash { | 21 namespace ash { |
| 22 namespace mus { | 22 namespace mus { |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 ::ui::mojom::WindowType MusWindowTypeFromWmWindowType( | 25 ui::mojom::WindowType MusWindowTypeFromWmWindowType( |
| 26 ui::wm::WindowType wm_window_type) { | 26 ui::wm::WindowType wm_window_type) { |
| 27 switch (wm_window_type) { | 27 switch (wm_window_type) { |
| 28 case ui::wm::WINDOW_TYPE_UNKNOWN: | 28 case ui::wm::WINDOW_TYPE_UNKNOWN: |
| 29 break; | 29 break; |
| 30 | 30 |
| 31 case ui::wm::WINDOW_TYPE_NORMAL: | 31 case ui::wm::WINDOW_TYPE_NORMAL: |
| 32 return ::ui::mojom::WindowType::WINDOW; | 32 return ui::mojom::WindowType::WINDOW; |
| 33 | 33 |
| 34 case ui::wm::WINDOW_TYPE_POPUP: | 34 case ui::wm::WINDOW_TYPE_POPUP: |
| 35 return ::ui::mojom::WindowType::POPUP; | 35 return ui::mojom::WindowType::POPUP; |
| 36 | 36 |
| 37 case ui::wm::WINDOW_TYPE_CONTROL: | 37 case ui::wm::WINDOW_TYPE_CONTROL: |
| 38 return ::ui::mojom::WindowType::CONTROL; | 38 return ui::mojom::WindowType::CONTROL; |
| 39 | 39 |
| 40 case ui::wm::WINDOW_TYPE_PANEL: | 40 case ui::wm::WINDOW_TYPE_PANEL: |
| 41 return ::ui::mojom::WindowType::PANEL; | 41 return ui::mojom::WindowType::PANEL; |
| 42 | 42 |
| 43 case ui::wm::WINDOW_TYPE_MENU: | 43 case ui::wm::WINDOW_TYPE_MENU: |
| 44 return ::ui::mojom::WindowType::MENU; | 44 return ui::mojom::WindowType::MENU; |
| 45 | 45 |
| 46 case ui::wm::WINDOW_TYPE_TOOLTIP: | 46 case ui::wm::WINDOW_TYPE_TOOLTIP: |
| 47 return ::ui::mojom::WindowType::TOOLTIP; | 47 return ui::mojom::WindowType::TOOLTIP; |
| 48 } | 48 } |
| 49 | 49 |
| 50 NOTREACHED(); | 50 NOTREACHED(); |
| 51 return ::ui::mojom::WindowType::CONTROL; | 51 return ui::mojom::WindowType::CONTROL; |
| 52 } | 52 } |
| 53 | 53 |
| 54 bool CompareByDisplayId(const RootWindowController* root1, | 54 bool CompareByDisplayId(const RootWindowController* root1, |
| 55 const RootWindowController* root2) { | 55 const RootWindowController* root2) { |
| 56 return root1->display().id() < root2->display().id(); | 56 return root1->display().id() < root2->display().id(); |
| 57 } | 57 } |
| 58 | 58 |
| 59 // TODO(sky): at some point this needs to support everything in DisplayInfo, | 59 // TODO(sky): at some point this needs to support everything in DisplayInfo, |
| 60 // for now just the bare minimum, which is [x+y-]wxh. | 60 // for now just the bare minimum, which is [x+y-]wxh. |
| 61 gfx::Rect ParseDisplayBounds(const std::string& spec) { | 61 gfx::Rect ParseDisplayBounds(const std::string& spec) { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 gfx::Rect work_area(bounds); | 113 gfx::Rect work_area(bounds); |
| 114 // Offset the height slightly to give a different work area. -2 is arbitrary, | 114 // Offset the height slightly to give a different work area. -2 is arbitrary, |
| 115 // it could be anything. | 115 // it could be anything. |
| 116 work_area.set_height(std::max(0, work_area.height() - 2)); | 116 work_area.set_height(std::max(0, work_area.height() - 2)); |
| 117 roots[0]->display_.set_work_area(work_area); | 117 roots[0]->display_.set_work_area(work_area); |
| 118 roots[0]->root()->SetBounds(gfx::Rect(bounds.size())); | 118 roots[0]->root()->SetBounds(gfx::Rect(bounds.size())); |
| 119 test_helper_->screen()->display_list()->UpdateDisplay( | 119 test_helper_->screen()->display_list()->UpdateDisplay( |
| 120 roots[0]->display(), views::DisplayList::Type::PRIMARY); | 120 roots[0]->display(), views::DisplayList::Type::PRIMARY); |
| 121 } | 121 } |
| 122 | 122 |
| 123 ::ui::Window* WmTestBase::GetPrimaryRootWindow() { | 123 ui::Window* WmTestBase::GetPrimaryRootWindow() { |
| 124 std::vector<RootWindowController*> roots = | 124 std::vector<RootWindowController*> roots = |
| 125 WmTestBase::GetRootsOrderedByDisplayId(); | 125 WmTestBase::GetRootsOrderedByDisplayId(); |
| 126 DCHECK(!roots.empty()); | 126 DCHECK(!roots.empty()); |
| 127 return roots[0]->root(); | 127 return roots[0]->root(); |
| 128 } | 128 } |
| 129 | 129 |
| 130 ::ui::Window* WmTestBase::GetSecondaryRootWindow() { | 130 ui::Window* WmTestBase::GetSecondaryRootWindow() { |
| 131 std::vector<RootWindowController*> roots = | 131 std::vector<RootWindowController*> roots = |
| 132 WmTestBase::GetRootsOrderedByDisplayId(); | 132 WmTestBase::GetRootsOrderedByDisplayId(); |
| 133 return roots.size() < 2 ? nullptr : roots[1]->root(); | 133 return roots.size() < 2 ? nullptr : roots[1]->root(); |
| 134 } | 134 } |
| 135 | 135 |
| 136 display::Display WmTestBase::GetPrimaryDisplay() { | 136 display::Display WmTestBase::GetPrimaryDisplay() { |
| 137 std::vector<RootWindowController*> roots = | 137 std::vector<RootWindowController*> roots = |
| 138 WmTestBase::GetRootsOrderedByDisplayId(); | 138 WmTestBase::GetRootsOrderedByDisplayId(); |
| 139 DCHECK(!roots.empty()); | 139 DCHECK(!roots.empty()); |
| 140 return roots[0]->display(); | 140 return roots[0]->display(); |
| 141 } | 141 } |
| 142 | 142 |
| 143 display::Display WmTestBase::GetSecondaryDisplay() { | 143 display::Display WmTestBase::GetSecondaryDisplay() { |
| 144 std::vector<RootWindowController*> roots = | 144 std::vector<RootWindowController*> roots = |
| 145 WmTestBase::GetRootsOrderedByDisplayId(); | 145 WmTestBase::GetRootsOrderedByDisplayId(); |
| 146 return roots.size() < 2 ? display::Display() : roots[1]->display(); | 146 return roots.size() < 2 ? display::Display() : roots[1]->display(); |
| 147 } | 147 } |
| 148 | 148 |
| 149 ::ui::Window* WmTestBase::CreateTestWindow(const gfx::Rect& bounds) { | 149 ui::Window* WmTestBase::CreateTestWindow(const gfx::Rect& bounds) { |
| 150 return CreateTestWindow(bounds, ui::wm::WINDOW_TYPE_NORMAL); | 150 return CreateTestWindow(bounds, ui::wm::WINDOW_TYPE_NORMAL); |
| 151 } | 151 } |
| 152 | 152 |
| 153 ::ui::Window* WmTestBase::CreateTestWindow(const gfx::Rect& bounds, | 153 ui::Window* WmTestBase::CreateTestWindow(const gfx::Rect& bounds, |
| 154 ui::wm::WindowType window_type) { | 154 ui::wm::WindowType window_type) { |
| 155 std::map<std::string, std::vector<uint8_t>> properties; | 155 std::map<std::string, std::vector<uint8_t>> properties; |
| 156 properties[::ui::mojom::WindowManager::kWindowType_Property] = | 156 properties[ui::mojom::WindowManager::kWindowType_Property] = |
| 157 mojo::ConvertTo<std::vector<uint8_t>>( | 157 mojo::ConvertTo<std::vector<uint8_t>>( |
| 158 static_cast<int32_t>(MusWindowTypeFromWmWindowType(window_type))); | 158 static_cast<int32_t>(MusWindowTypeFromWmWindowType(window_type))); |
| 159 if (!bounds.IsEmpty()) { | 159 if (!bounds.IsEmpty()) { |
| 160 properties[::ui::mojom::WindowManager::kInitialBounds_Property] = | 160 properties[ui::mojom::WindowManager::kInitialBounds_Property] = |
| 161 mojo::ConvertTo<std::vector<uint8_t>>(bounds); | 161 mojo::ConvertTo<std::vector<uint8_t>>(bounds); |
| 162 } | 162 } |
| 163 properties[::ui::mojom::WindowManager::kResizeBehavior_Property] = | 163 properties[ui::mojom::WindowManager::kResizeBehavior_Property] = |
| 164 mojo::ConvertTo<std::vector<uint8_t>>( | 164 mojo::ConvertTo<std::vector<uint8_t>>( |
| 165 ::ui::mojom::kResizeBehaviorCanResize | | 165 ui::mojom::kResizeBehaviorCanResize | |
| 166 ::ui::mojom::kResizeBehaviorCanMaximize | | 166 ui::mojom::kResizeBehaviorCanMaximize | |
| 167 ::ui::mojom::kResizeBehaviorCanMinimize); | 167 ui::mojom::kResizeBehaviorCanMinimize); |
| 168 | 168 |
| 169 ::ui::Window* window = | 169 ui::Window* window = |
| 170 GetRootsOrderedByDisplayId()[0]->window_manager()->NewTopLevelWindow( | 170 GetRootsOrderedByDisplayId()[0]->window_manager()->NewTopLevelWindow( |
| 171 &properties); | 171 &properties); |
| 172 window->SetVisible(true); | 172 window->SetVisible(true); |
| 173 return window; | 173 return window; |
| 174 } | 174 } |
| 175 | 175 |
| 176 ::ui::Window* WmTestBase::CreateFullscreenTestWindow() { | 176 ui::Window* WmTestBase::CreateFullscreenTestWindow() { |
| 177 std::map<std::string, std::vector<uint8_t>> properties; | 177 std::map<std::string, std::vector<uint8_t>> properties; |
| 178 properties[::ui::mojom::WindowManager::kShowState_Property] = | 178 properties[ui::mojom::WindowManager::kShowState_Property] = |
| 179 mojo::ConvertTo<std::vector<uint8_t>>( | 179 mojo::ConvertTo<std::vector<uint8_t>>( |
| 180 static_cast<int32_t>(ui::mojom::ShowState::FULLSCREEN)); | 180 static_cast<int32_t>(ui::mojom::ShowState::FULLSCREEN)); |
| 181 ::ui::Window* window = | 181 ui::Window* window = |
| 182 GetRootsOrderedByDisplayId()[0]->window_manager()->NewTopLevelWindow( | 182 GetRootsOrderedByDisplayId()[0]->window_manager()->NewTopLevelWindow( |
| 183 &properties); | 183 &properties); |
| 184 window->SetVisible(true); | 184 window->SetVisible(true); |
| 185 return window; | 185 return window; |
| 186 } | 186 } |
| 187 | 187 |
| 188 ::ui::Window* WmTestBase::CreateChildTestWindow(::ui::Window* parent, | 188 ui::Window* WmTestBase::CreateChildTestWindow(ui::Window* parent, |
| 189 const gfx::Rect& bounds) { | 189 const gfx::Rect& bounds) { |
| 190 std::map<std::string, std::vector<uint8_t>> properties; | 190 std::map<std::string, std::vector<uint8_t>> properties; |
| 191 properties[::ui::mojom::WindowManager::kWindowType_Property] = | 191 properties[ui::mojom::WindowManager::kWindowType_Property] = |
| 192 mojo::ConvertTo<std::vector<uint8_t>>(static_cast<int32_t>( | 192 mojo::ConvertTo<std::vector<uint8_t>>(static_cast<int32_t>( |
| 193 MusWindowTypeFromWmWindowType(ui::wm::WINDOW_TYPE_NORMAL))); | 193 MusWindowTypeFromWmWindowType(ui::wm::WINDOW_TYPE_NORMAL))); |
| 194 ::ui::Window* window = | 194 ui::Window* window = |
| 195 GetRootsOrderedByDisplayId()[0]->root()->window_tree()->NewWindow( | 195 GetRootsOrderedByDisplayId()[0]->root()->window_tree()->NewWindow( |
| 196 &properties); | 196 &properties); |
| 197 window->SetBounds(bounds); | 197 window->SetBounds(bounds); |
| 198 window->SetVisible(true); | 198 window->SetVisible(true); |
| 199 parent->AddChild(window); | 199 parent->AddChild(window); |
| 200 return window; | 200 return window; |
| 201 } | 201 } |
| 202 | 202 |
| 203 void WmTestBase::SetUp() { | 203 void WmTestBase::SetUp() { |
| 204 setup_called_ = true; | 204 setup_called_ = true; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 216 ->window_manager() | 216 ->window_manager() |
| 217 ->GetRootWindowControllers(); | 217 ->GetRootWindowControllers(); |
| 218 std::vector<RootWindowController*> ordered_roots; | 218 std::vector<RootWindowController*> ordered_roots; |
| 219 ordered_roots.insert(ordered_roots.begin(), roots.begin(), roots.end()); | 219 ordered_roots.insert(ordered_roots.begin(), roots.begin(), roots.end()); |
| 220 std::sort(ordered_roots.begin(), ordered_roots.end(), &CompareByDisplayId); | 220 std::sort(ordered_roots.begin(), ordered_roots.end(), &CompareByDisplayId); |
| 221 return ordered_roots; | 221 return ordered_roots; |
| 222 } | 222 } |
| 223 | 223 |
| 224 } // namespace mus | 224 } // namespace mus |
| 225 } // namespace ash | 225 } // namespace ash |
| OLD | NEW |