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

Side by Side Diff: ash/display/multi_display_manager.cc

Issue 10909043: Cancel drag if display configuration changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: win fix, adjust test screen size Created 8 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 | Annotate | Revision Log
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/display/multi_display_manager.h" 5 #include "ash/display/multi_display_manager.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "ash/display/display_controller.h" 10 #include "ash/display/display_controller.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 gfx::Display::kInvalidDisplayID); 46 gfx::Display::kInvalidDisplayID);
47 47
48 MultiDisplayManager::MultiDisplayManager() { 48 MultiDisplayManager::MultiDisplayManager() {
49 Init(); 49 Init();
50 } 50 }
51 51
52 MultiDisplayManager::~MultiDisplayManager() { 52 MultiDisplayManager::~MultiDisplayManager() {
53 } 53 }
54 54
55 // static 55 // static
56 void MultiDisplayManager::AddRemoveDisplay() {
57 MultiDisplayManager* manager = static_cast<MultiDisplayManager*>(
58 aura::Env::GetInstance()->display_manager());
59 manager->AddRemoveDisplayImpl();
60 }
61
62 void MultiDisplayManager::CycleDisplay() { 56 void MultiDisplayManager::CycleDisplay() {
63 MultiDisplayManager* manager = static_cast<MultiDisplayManager*>( 57 MultiDisplayManager* manager = static_cast<MultiDisplayManager*>(
64 aura::Env::GetInstance()->display_manager()); 58 aura::Env::GetInstance()->display_manager());
65 manager->CycleDisplayImpl(); 59 manager->CycleDisplayImpl();
66 } 60 }
67 61
62 // static
68 void MultiDisplayManager::ToggleDisplayScale() { 63 void MultiDisplayManager::ToggleDisplayScale() {
69 MultiDisplayManager* manager = static_cast<MultiDisplayManager*>( 64 MultiDisplayManager* manager = static_cast<MultiDisplayManager*>(
70 aura::Env::GetInstance()->display_manager()); 65 aura::Env::GetInstance()->display_manager());
71 manager->ScaleDisplayImpl(); 66 manager->ScaleDisplayImpl();
72 } 67 }
73 68
74 bool MultiDisplayManager::UpdateWorkAreaOfDisplayNearestWindow( 69 bool MultiDisplayManager::UpdateWorkAreaOfDisplayNearestWindow(
75 const aura::Window* window, 70 const aura::Window* window,
76 const gfx::Insets& insets) { 71 const gfx::Insets& insets) {
77 const RootWindow* root = window->GetRootWindow(); 72 const RootWindow* root = window->GetRootWindow();
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 } 210 }
216 #endif 211 #endif
217 212
218 return base::StringPrintf("Display %d", static_cast<int>(index + 1)); 213 return base::StringPrintf("Display %d", static_cast<int>(index + 1));
219 } 214 }
220 215
221 void MultiDisplayManager::OnRootWindowResized(const aura::RootWindow* root, 216 void MultiDisplayManager::OnRootWindowResized(const aura::RootWindow* root,
222 const gfx::Size& old_size) { 217 const gfx::Size& old_size) {
223 if (!use_fullscreen_host_window()) { 218 if (!use_fullscreen_host_window()) {
224 gfx::Display& display = FindDisplayForRootWindow(root); 219 gfx::Display& display = FindDisplayForRootWindow(root);
225 display.SetSize(root->GetHostSize()); 220 if (display.size() != root->GetHostSize()) {
226 NotifyBoundsChanged(display); 221 display.SetSize(root->GetHostSize());
222 NotifyBoundsChanged(display);
223 }
227 } 224 }
228 } 225 }
229 226
230 void MultiDisplayManager::Init() { 227 void MultiDisplayManager::Init() {
231 // TODO(oshima): Move this logic to DisplayChangeObserver. 228 // TODO(oshima): Move this logic to DisplayChangeObserver.
232 const string size_str = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 229 const string size_str = CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
233 switches::kAuraHostWindowSize); 230 switches::kAuraHostWindowSize);
234 vector<string> parts; 231 vector<string> parts;
235 base::SplitString(size_str, ',', &parts); 232 base::SplitString(size_str, ',', &parts);
236 for (vector<string>::const_iterator iter = parts.begin(); 233 for (vector<string>::const_iterator iter = parts.begin();
237 iter != parts.end(); ++iter) { 234 iter != parts.end(); ++iter) {
238 AddDisplayFromSpec(*iter); 235 AddDisplayFromSpec(*iter);
239 } 236 }
240 if (displays_.empty()) 237 if (displays_.empty())
241 AddDisplayFromSpec(std::string() /* default */); 238 AddDisplayFromSpec(std::string() /* default */);
242 } 239 }
243 240
244 void MultiDisplayManager::AddRemoveDisplayImpl() { 241 void MultiDisplayManager::CycleDisplayImpl() {
245 std::vector<gfx::Display> new_displays; 242 std::vector<gfx::Display> new_displays;
246 if (displays_.size() > 1) { 243 if (displays_.size() > 1) {
247 // Remove if there is more than one display. 244 // Remove if there is more than one display.
248 int count = displays_.size() - 1; 245 int count = displays_.size() - 1;
249 for (Displays::const_iterator iter = displays_.begin(); count-- > 0; ++iter) 246 for (Displays::const_iterator iter = displays_.begin(); count-- > 0; ++iter)
250 new_displays.push_back(*iter); 247 new_displays.push_back(*iter);
251 } else { 248 } else {
252 // Add if there is only one display. 249 // Add if there is only one display.
253 new_displays.push_back(displays_[0]); 250 new_displays.push_back(displays_[0]);
254 new_displays.push_back(CreateDisplayFromSpec("50+50-1280x768")); 251 new_displays.push_back(CreateDisplayFromSpec("100+200-500x400"));
255 } 252 }
256 if (new_displays.size()) 253 if (new_displays.size())
257 OnNativeDisplaysChanged(new_displays); 254 OnNativeDisplaysChanged(new_displays);
258 } 255 }
259 256
260 void MultiDisplayManager::CycleDisplayImpl() {
261 if (displays_.size() > 1) {
262 std::vector<gfx::Display> new_displays;
263 for (Displays::const_iterator iter = displays_.begin() + 1;
264 iter != displays_.end(); ++iter) {
265 gfx::Display display = *iter;
266 new_displays.push_back(display);
267 }
268 new_displays.push_back(displays_.front());
269 OnNativeDisplaysChanged(new_displays);
270 }
271 }
272
273 void MultiDisplayManager::ScaleDisplayImpl() { 257 void MultiDisplayManager::ScaleDisplayImpl() {
274 if (displays_.size() > 0) { 258 if (displays_.size() > 0) {
275 std::vector<gfx::Display> new_displays; 259 std::vector<gfx::Display> new_displays;
276 for (Displays::const_iterator iter = displays_.begin(); 260 for (Displays::const_iterator iter = displays_.begin();
277 iter != displays_.end(); ++iter) { 261 iter != displays_.end(); ++iter) {
278 gfx::Display display = *iter; 262 gfx::Display display = *iter;
279 float factor = display.device_scale_factor() == 1.0f ? 2.0f : 1.0f; 263 float factor = display.device_scale_factor() == 1.0f ? 2.0f : 1.0f;
280 display.SetScaleAndBounds( 264 display.SetScaleAndBounds(
281 factor, gfx::Rect(display.bounds_in_pixel().origin(), 265 factor, gfx::Rect(display.bounds_in_pixel().origin(),
282 display.size().Scale(factor))); 266 display.size().Scale(factor)));
283 new_displays.push_back(display); 267 new_displays.push_back(display);
284 } 268 }
285 OnNativeDisplaysChanged(new_displays); 269 OnNativeDisplaysChanged(new_displays);
286 } 270 }
287 } 271 }
288 272
289 gfx::Display& MultiDisplayManager::FindDisplayForRootWindow( 273 gfx::Display& MultiDisplayManager::FindDisplayForRootWindow(
290 const aura::RootWindow* root_window) { 274 const aura::RootWindow* root_window) {
291 int64 id = root_window->GetProperty(kDisplayIdKey); 275 int64 id = root_window->GetProperty(kDisplayIdKey);
276 // if id is |kInvaildDisplayID|, it's being deleted.
277 DCHECK(id != gfx::Display::kInvalidDisplayID);
292 for (Displays::iterator iter = displays_.begin(); 278 for (Displays::iterator iter = displays_.begin();
293 iter != displays_.end(); ++iter) { 279 iter != displays_.end(); ++iter) {
294 if ((*iter).id() == id) 280 if ((*iter).id() == id)
295 return *iter; 281 return *iter;
296 } 282 }
297 DLOG(FATAL) << "Could not find display by id:" << id; 283 DLOG(FATAL) << "Could not find display by id:" << id;
298 return GetInvalidDisplay(); 284 return GetInvalidDisplay();
299 } 285 }
300 286
301 void MultiDisplayManager::AddDisplayFromSpec(const std::string& spec) { 287 void MultiDisplayManager::AddDisplayFromSpec(const std::string& spec) {
302 gfx::Display display = CreateDisplayFromSpec(spec); 288 gfx::Display display = CreateDisplayFromSpec(spec);
303 289
304 const gfx::Insets insets = display.GetWorkAreaInsets(); 290 const gfx::Insets insets = display.GetWorkAreaInsets();
305 const gfx::Rect& native_bounds = display.bounds_in_pixel(); 291 const gfx::Rect& native_bounds = display.bounds_in_pixel();
306 display.SetScaleAndBounds(display.device_scale_factor(), native_bounds); 292 display.SetScaleAndBounds(display.device_scale_factor(), native_bounds);
307 display.UpdateWorkAreaFromInsets(insets); 293 display.UpdateWorkAreaFromInsets(insets);
308 displays_.push_back(display); 294 displays_.push_back(display);
309 } 295 }
310 296
311 } // namespace internal 297 } // namespace internal
312 } // namespace ash 298 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698