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_helper.h" | 5 #include "ash/mus/test/wm_test_helper.h" |
6 | 6 |
7 #include "ash/common/material_design/material_design_controller.h" | 7 #include "ash/common/material_design/material_design_controller.h" |
8 #include "ash/common/test/material_design_controller_test_api.h" | 8 #include "ash/common/test/material_design_controller_test_api.h" |
9 #include "ash/mus/root_window_controller.h" | 9 #include "ash/mus/root_window_controller.h" |
10 #include "ash/mus/window_manager.h" | 10 #include "ash/mus/window_manager.h" |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 window_manager_app_->window_manager_.get(), | 97 window_manager_app_->window_manager_.get(), |
98 window_manager_app_->window_manager_.get()); | 98 window_manager_app_->window_manager_.get()); |
99 window_manager_app_->InitWindowManager( | 99 window_manager_app_->InitWindowManager( |
100 window_tree_client_setup_.OwnWindowTreeClient(), | 100 window_tree_client_setup_.OwnWindowTreeClient(), |
101 blocking_pool_owner_->pool()); | 101 blocking_pool_owner_->pool()); |
102 | 102 |
103 ui::WindowTreeClient* window_tree_client = | 103 ui::WindowTreeClient* window_tree_client = |
104 window_manager_app_->window_manager()->window_tree_client(); | 104 window_manager_app_->window_manager()->window_tree_client(); |
105 window_tree_client_private_ = | 105 window_tree_client_private_ = |
106 base::MakeUnique<ui::WindowTreeClientPrivate>(window_tree_client); | 106 base::MakeUnique<ui::WindowTreeClientPrivate>(window_tree_client); |
107 CreateRootWindowController("800x600"); | 107 int next_x = 0; |
| 108 CreateRootWindowController("800x600", &next_x); |
108 } | 109 } |
109 | 110 |
110 std::vector<RootWindowController*> WmTestHelper::GetRootsOrderedByDisplayId() { | 111 std::vector<RootWindowController*> WmTestHelper::GetRootsOrderedByDisplayId() { |
111 std::set<RootWindowController*> roots = | 112 std::set<RootWindowController*> roots = |
112 window_manager_app_->window_manager()->GetRootWindowControllers(); | 113 window_manager_app_->window_manager()->GetRootWindowControllers(); |
113 std::vector<RootWindowController*> ordered_roots; | 114 std::vector<RootWindowController*> ordered_roots; |
114 ordered_roots.insert(ordered_roots.begin(), roots.begin(), roots.end()); | 115 ordered_roots.insert(ordered_roots.begin(), roots.begin(), roots.end()); |
115 std::sort(ordered_roots.begin(), ordered_roots.end(), &CompareByDisplayId); | 116 std::sort(ordered_roots.begin(), ordered_roots.end(), &CompareByDisplayId); |
116 return ordered_roots; | 117 return ordered_roots; |
117 } | 118 } |
118 | 119 |
119 void WmTestHelper::UpdateDisplay(const std::string& display_spec) { | 120 void WmTestHelper::UpdateDisplay(const std::string& display_spec) { |
120 const std::vector<std::string> parts = base::SplitString( | 121 const std::vector<std::string> parts = base::SplitString( |
121 display_spec, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 122 display_spec, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
122 std::vector<RootWindowController*> root_window_controllers = | 123 std::vector<RootWindowController*> root_window_controllers = |
123 GetRootsOrderedByDisplayId(); | 124 GetRootsOrderedByDisplayId(); |
| 125 int next_x = 0; |
124 for (size_t i = 0, | 126 for (size_t i = 0, |
125 end = std::min(parts.size(), root_window_controllers.size()); | 127 end = std::min(parts.size(), root_window_controllers.size()); |
126 i < end; ++i) { | 128 i < end; ++i) { |
127 UpdateDisplay(root_window_controllers[i], parts[i]); | 129 UpdateDisplay(root_window_controllers[i], parts[i], &next_x); |
128 } | 130 } |
129 for (size_t i = root_window_controllers.size(); i < parts.size(); ++i) | 131 for (size_t i = root_window_controllers.size(); i < parts.size(); ++i) { |
130 root_window_controllers.push_back(CreateRootWindowController(parts[i])); | 132 root_window_controllers.push_back( |
| 133 CreateRootWindowController(parts[i], &next_x)); |
| 134 } |
131 while (root_window_controllers.size() > parts.size()) { | 135 while (root_window_controllers.size() > parts.size()) { |
132 window_manager_app_->window_manager()->DestroyRootWindowController( | 136 window_manager_app_->window_manager()->DestroyRootWindowController( |
133 root_window_controllers.back()); | 137 root_window_controllers.back()); |
134 root_window_controllers.pop_back(); | 138 root_window_controllers.pop_back(); |
135 } | 139 } |
136 } | 140 } |
137 | 141 |
138 RootWindowController* WmTestHelper::CreateRootWindowController( | 142 RootWindowController* WmTestHelper::CreateRootWindowController( |
139 const std::string& display_spec) { | 143 const std::string& display_spec, |
140 display::Display display(next_display_id_++, | 144 int* next_x) { |
141 ParseDisplayBounds(display_spec)); | 145 gfx::Rect bounds = ParseDisplayBounds(display_spec); |
| 146 bounds.set_x(*next_x); |
| 147 *next_x += bounds.size().width(); |
| 148 display::Display display(next_display_id_++, bounds); |
142 gfx::Rect work_area(display.bounds()); | 149 gfx::Rect work_area(display.bounds()); |
143 // Offset the height slightly to give a different work area. -20 is arbitrary, | 150 // Offset the height slightly to give a different work area. -20 is arbitrary, |
144 // it could be anything. | 151 // it could be anything. |
145 work_area.set_height(std::max(0, work_area.height() - 20)); | 152 work_area.set_height(std::max(0, work_area.height() - 20)); |
146 display.set_work_area(work_area); | 153 display.set_work_area(work_area); |
147 window_tree_client_private_->CallWmNewDisplayAdded(display); | 154 window_tree_client_private_->CallWmNewDisplayAdded(display); |
148 return GetRootsOrderedByDisplayId().back(); | 155 return GetRootsOrderedByDisplayId().back(); |
149 } | 156 } |
150 | 157 |
151 void WmTestHelper::UpdateDisplay(RootWindowController* root_window_controller, | 158 void WmTestHelper::UpdateDisplay(RootWindowController* root_window_controller, |
152 const std::string& display_spec) { | 159 const std::string& display_spec, |
| 160 int* next_x) { |
153 gfx::Rect bounds = ParseDisplayBounds(display_spec); | 161 gfx::Rect bounds = ParseDisplayBounds(display_spec); |
| 162 bounds.set_x(*next_x); |
| 163 *next_x += bounds.size().width(); |
154 root_window_controller->display_.set_bounds(bounds); | 164 root_window_controller->display_.set_bounds(bounds); |
155 gfx::Rect work_area(bounds); | 165 gfx::Rect work_area(bounds); |
156 // Offset the height slightly to give a different work area. -20 is arbitrary, | 166 // Offset the height slightly to give a different work area. -20 is arbitrary, |
157 // it could be anything. | 167 // it could be anything. |
158 work_area.set_height(std::max(0, work_area.height() - 20)); | 168 work_area.set_height(std::max(0, work_area.height() - 20)); |
159 root_window_controller->display_.set_work_area(work_area); | 169 root_window_controller->display_.set_work_area(work_area); |
160 root_window_controller->root()->SetBounds(gfx::Rect(bounds.size())); | 170 root_window_controller->root()->SetBounds(gfx::Rect(bounds.size())); |
161 display::ScreenBase* screen = | 171 display::ScreenBase* screen = |
162 window_manager_app_->window_manager()->screen_.get(); | 172 window_manager_app_->window_manager()->screen_.get(); |
163 const bool is_primary = screen->display_list()->FindDisplayById( | 173 const bool is_primary = screen->display_list()->FindDisplayById( |
164 root_window_controller->display().id()) == | 174 root_window_controller->display().id()) == |
165 screen->display_list()->GetPrimaryDisplayIterator(); | 175 screen->display_list()->GetPrimaryDisplayIterator(); |
166 screen->display_list()->UpdateDisplay( | 176 screen->display_list()->UpdateDisplay( |
167 root_window_controller->display(), | 177 root_window_controller->display(), |
168 is_primary ? display::DisplayList::Type::PRIMARY | 178 is_primary ? display::DisplayList::Type::PRIMARY |
169 : display::DisplayList::Type::NOT_PRIMARY); | 179 : display::DisplayList::Type::NOT_PRIMARY); |
170 } | 180 } |
171 | 181 |
172 } // namespace mus | 182 } // namespace mus |
173 } // namespace ash | 183 } // namespace ash |
OLD | NEW |