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

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

Issue 10961021: Return primary display if out of bounds point or NULL ponter is passed to gfx::Screen::GeDisplayNea (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix a few other tests that were using native coordinate. it shoud use screen coordinate now. 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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 bool MultiDisplayManager::UpdateWorkAreaOfDisplayNearestWindow( 112 bool MultiDisplayManager::UpdateWorkAreaOfDisplayNearestWindow(
113 const aura::Window* window, 113 const aura::Window* window,
114 const gfx::Insets& insets) { 114 const gfx::Insets& insets) {
115 const RootWindow* root = window->GetRootWindow(); 115 const RootWindow* root = window->GetRootWindow();
116 gfx::Display& display = FindDisplayForRootWindow(root); 116 gfx::Display& display = FindDisplayForRootWindow(root);
117 gfx::Rect old_work_area = display.work_area(); 117 gfx::Rect old_work_area = display.work_area();
118 display.UpdateWorkAreaFromInsets(insets); 118 display.UpdateWorkAreaFromInsets(insets);
119 return old_work_area != display.work_area(); 119 return old_work_area != display.work_area();
120 } 120 }
121 121
122 const gfx::Display& MultiDisplayManager::GetDisplayForId(int64 id) const {
123 for (DisplayList::const_iterator iter = displays_.begin();
124 iter != displays_.end(); ++iter) {
125 if ((*iter).id() == id)
126 return *iter;
127 }
128 VLOG(1) << "display not found for id:" << id;
129 return GetInvalidDisplay();
130 }
131
122 const gfx::Display& MultiDisplayManager::FindDisplayContainingPoint( 132 const gfx::Display& MultiDisplayManager::FindDisplayContainingPoint(
123 const gfx::Point& point_in_screen) const { 133 const gfx::Point& point_in_screen) const {
124 for (DisplayList::const_iterator iter = displays_.begin(); 134 for (DisplayList::const_iterator iter = displays_.begin();
125 iter != displays_.end(); ++iter) { 135 iter != displays_.end(); ++iter) {
126 const gfx::Display& display = *iter; 136 const gfx::Display& display = *iter;
127 if (display.bounds().Contains(point_in_screen)) 137 if (display.bounds().Contains(point_in_screen))
128 return display; 138 return display;
129 } 139 }
130 return GetInvalidDisplay(); 140 return GetInvalidDisplay();
131 } 141 }
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 return index < displays_.size() ? &displays_[index] : NULL; 267 return index < displays_.size() ? &displays_[index] : NULL;
258 } 268 }
259 269
260 size_t MultiDisplayManager::GetNumDisplays() const { 270 size_t MultiDisplayManager::GetNumDisplays() const {
261 return displays_.size(); 271 return displays_.size();
262 } 272 }
263 273
264 const gfx::Display& MultiDisplayManager::GetDisplayNearestWindow( 274 const gfx::Display& MultiDisplayManager::GetDisplayNearestWindow(
265 const Window* window) const { 275 const Window* window) const {
266 if (!window) 276 if (!window)
267 return displays_[0]; 277 return DisplayController::GetPrimaryDisplay();
268 const RootWindow* root = window->GetRootWindow(); 278 const RootWindow* root = window->GetRootWindow();
269 MultiDisplayManager* manager = const_cast<MultiDisplayManager*>(this); 279 MultiDisplayManager* manager = const_cast<MultiDisplayManager*>(this);
270 return root ? manager->FindDisplayForRootWindow(root) : GetInvalidDisplay(); 280 return root ? manager->FindDisplayForRootWindow(root) : GetInvalidDisplay();
271 } 281 }
272 282
273 const gfx::Display& MultiDisplayManager::GetDisplayNearestPoint( 283 const gfx::Display& MultiDisplayManager::GetDisplayNearestPoint(
274 const gfx::Point& point) const { 284 const gfx::Point& point) const {
275 // Fallback to the primary display if there is no root display containing 285 // Fallback to the primary display if there is no root display containing
276 // the |point|. 286 // the |point|.
277 const gfx::Display& display = FindDisplayContainingPoint(point); 287 const gfx::Display& display = FindDisplayContainingPoint(point);
278 return display.is_valid() ? display : displays_[0]; 288 return display.is_valid() ? display : DisplayController::GetPrimaryDisplay();
279 } 289 }
280 290
281 const gfx::Display& MultiDisplayManager::GetDisplayMatching( 291 const gfx::Display& MultiDisplayManager::GetDisplayMatching(
282 const gfx::Rect& rect) const { 292 const gfx::Rect& rect) const {
283 if (rect.IsEmpty()) 293 if (rect.IsEmpty())
284 return GetDisplayNearestPoint(rect.origin()); 294 return GetDisplayNearestPoint(rect.origin());
285 295
286 int max = 0; 296 int max = 0;
287 const gfx::Display* matching = 0; 297 const gfx::Display* matching = 0;
288 for (std::vector<gfx::Display>::const_iterator iter = displays_.begin(); 298 for (std::vector<gfx::Display>::const_iterator iter = displays_.begin();
289 iter != displays_.end(); ++iter) { 299 iter != displays_.end(); ++iter) {
290 const gfx::Display& display = *iter; 300 const gfx::Display& display = *iter;
291 gfx::Rect intersect = display.bounds().Intersect(rect); 301 gfx::Rect intersect = display.bounds().Intersect(rect);
292 int area = intersect.width() * intersect.height(); 302 int area = intersect.width() * intersect.height();
293 if (area > max) { 303 if (area > max) {
294 max = area; 304 max = area;
295 matching = &(*iter); 305 matching = &(*iter);
296 } 306 }
297 } 307 }
298 // Fallback to the primary display if there is no matching display. 308 // Fallback to the primary display if there is no matching display.
299 return matching ? *matching : displays_[0]; 309 return matching ? *matching : DisplayController::GetPrimaryDisplay();
300 } 310 }
301 311
302 std::string MultiDisplayManager::GetDisplayNameFor( 312 std::string MultiDisplayManager::GetDisplayNameFor(
303 const gfx::Display& display) { 313 const gfx::Display& display) {
304 #if defined(USE_X11) 314 #if defined(USE_X11)
305 std::vector<XID> outputs; 315 std::vector<XID> outputs;
306 if (display.id() != gfx::Display::kInvalidDisplayID && 316 if (display.id() != gfx::Display::kInvalidDisplayID &&
307 ui::GetOutputDeviceHandles(&outputs)) { 317 ui::GetOutputDeviceHandles(&outputs)) {
308 for (size_t i = 0; i < outputs.size(); ++i) { 318 for (size_t i = 0; i < outputs.size(); ++i) {
309 uint16 manufacturer_id = 0; 319 uint16 manufacturer_id = 0;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 base::SplitString(size_str, ',', &parts); 365 base::SplitString(size_str, ',', &parts);
356 for (vector<string>::const_iterator iter = parts.begin(); 366 for (vector<string>::const_iterator iter = parts.begin();
357 iter != parts.end(); ++iter) { 367 iter != parts.end(); ++iter) {
358 AddDisplayFromSpec(*iter); 368 AddDisplayFromSpec(*iter);
359 } 369 }
360 if (displays_.empty()) 370 if (displays_.empty())
361 AddDisplayFromSpec(std::string() /* default */); 371 AddDisplayFromSpec(std::string() /* default */);
362 } 372 }
363 373
364 void MultiDisplayManager::CycleDisplayImpl() { 374 void MultiDisplayManager::CycleDisplayImpl() {
375 DCHECK(!displays_.empty());
365 std::vector<gfx::Display> new_displays; 376 std::vector<gfx::Display> new_displays;
366 if (displays_.size() > 1) { 377 new_displays.push_back(DisplayController::GetPrimaryDisplay());
367 // Remove if there is more than one display. 378 // Add if there is only one display.
368 int count = displays_.size() - 1; 379 if (displays_.size() == 1)
369 for (DisplayList::const_iterator iter = displays_.begin();
370 count-- > 0; ++iter) {
371 new_displays.push_back(*iter);
372 }
373 } else {
374 // Add if there is only one display.
375 new_displays.push_back(displays_[0]);
376 new_displays.push_back(CreateDisplayFromSpec("100+200-500x400")); 380 new_displays.push_back(CreateDisplayFromSpec("100+200-500x400"));
377 } 381 OnNativeDisplaysChanged(new_displays);
378 if (new_displays.size())
379 OnNativeDisplaysChanged(new_displays);
380 } 382 }
381 383
382 void MultiDisplayManager::ScaleDisplayImpl() { 384 void MultiDisplayManager::ScaleDisplayImpl() {
383 if (displays_.size() > 0) { 385 DCHECK(!displays_.empty());
384 std::vector<gfx::Display> new_displays; 386 std::vector<gfx::Display> new_displays;
385 for (DisplayList::const_iterator iter = displays_.begin(); 387 for (DisplayList::const_iterator iter = displays_.begin();
386 iter != displays_.end(); ++iter) { 388 iter != displays_.end(); ++iter) {
387 gfx::Display display = *iter; 389 gfx::Display display = *iter;
388 float factor = display.device_scale_factor() == 1.0f ? 2.0f : 1.0f; 390 float factor = display.device_scale_factor() == 1.0f ? 2.0f : 1.0f;
389 display.SetScaleAndBounds( 391 display.SetScaleAndBounds(
390 factor, gfx::Rect(display.bounds_in_pixel().origin(), 392 factor, gfx::Rect(display.bounds_in_pixel().origin(),
391 display.size().Scale(factor))); 393 display.size().Scale(factor)));
392 new_displays.push_back(display); 394 new_displays.push_back(display);
393 }
394 OnNativeDisplaysChanged(new_displays);
395 } 395 }
396 OnNativeDisplaysChanged(new_displays);
396 } 397 }
397 398
398 gfx::Display& MultiDisplayManager::FindDisplayForRootWindow( 399 gfx::Display& MultiDisplayManager::FindDisplayForRootWindow(
399 const aura::RootWindow* root_window) { 400 const aura::RootWindow* root_window) {
400 int64 id = root_window->GetProperty(kDisplayIdKey); 401 int64 id = root_window->GetProperty(kDisplayIdKey);
401 // if id is |kInvaildDisplayID|, it's being deleted. 402 // if id is |kInvaildDisplayID|, it's being deleted.
402 DCHECK(id != gfx::Display::kInvalidDisplayID); 403 DCHECK(id != gfx::Display::kInvalidDisplayID);
403 return FindDisplayForId(id); 404 return FindDisplayForId(id);
404 } 405 }
405 406
(...skipping 28 matching lines...) Expand all
434 DisplayList::iterator iter_to_update = to_update->begin(); 435 DisplayList::iterator iter_to_update = to_update->begin();
435 DisplayList::const_iterator iter = displays_.begin(); 436 DisplayList::const_iterator iter = displays_.begin();
436 for (; iter != displays_.end() && iter_to_update != to_update->end(); 437 for (; iter != displays_.end() && iter_to_update != to_update->end();
437 ++iter, ++iter_to_update) { 438 ++iter, ++iter_to_update) {
438 (*iter_to_update).set_id((*iter).id()); 439 (*iter_to_update).set_id((*iter).id());
439 } 440 }
440 } 441 }
441 442
442 } // namespace internal 443 } // namespace internal
443 } // namespace ash 444 } // namespace ash
OLDNEW
« no previous file with comments | « ash/display/multi_display_manager.h ('k') | ash/wm/workspace/workspace_window_resizer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698