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

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

Issue 11269022: Add Vector2d classes that represent offsets, instead of using Point. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 1 month 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 496 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 507
508 for (DisplayList::const_iterator iter = displays_.begin(); 508 for (DisplayList::const_iterator iter = displays_.begin();
509 iter != displays_.end(); ++iter) { 509 iter != displays_.end(); ++iter) {
510 const gfx::Rect& display_bounds = iter->bounds(); 510 const gfx::Rect& display_bounds = iter->bounds();
511 511
512 if (display_bounds.Contains(location_in_screen)) { 512 if (display_bounds.Contains(location_in_screen)) {
513 target_location = location_in_screen; 513 target_location = location_in_screen;
514 break; 514 break;
515 } 515 }
516 gfx::Point center = display_bounds.CenterPoint(); 516 gfx::Point center = display_bounds.CenterPoint();
517 gfx::Point diff = center.Subtract(location_in_screen); 517 gfx::Vector2d diff = center.Subtract(location_in_screen);
Peter Kasting 2012/10/27 01:01:39 Nit: Inline into next statement
danakj 2012/10/29 19:17:20 Done.
518 // Use the distance from the center of the dislay. This is not 518 // Use the distance from the center of the dislay. This is not
519 // exactly "closest" display, but good enough to pick one 519 // exactly "closest" display, but good enough to pick one
520 // appropriate (and there are at most two displays). 520 // appropriate (and there are at most two displays).
521 int64 distance = diff.x() * diff.x() + diff.y() * diff.y(); 521 int64 distance = diff.LengthSquared();
danakj 2012/10/27 00:35:33 Was able to make use of LengthSquared() here.
522 if (closest_distance < 0 || closest_distance > distance) { 522 if (closest_distance < 0 || closest_distance > distance) {
523 target_location = center; 523 target_location = center;
524 closest_distance = distance; 524 closest_distance = distance;
525 } 525 }
526 } 526 }
527 527
528 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow(); 528 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow();
529 aura::client::ScreenPositionClient* client = 529 aura::client::ScreenPositionClient* client =
530 aura::client::GetScreenPositionClient(root_window); 530 aura::client::GetScreenPositionClient(root_window);
531 client->ConvertPointFromScreen(root_window, &target_location); 531 client->ConvertPointFromScreen(root_window, &target_location);
532 532
533 root_window->MoveCursorTo(target_location); 533 root_window->MoveCursorTo(target_location);
534 } 534 }
535 535
536 void MultiDisplayManager::SetDisplayIdsForTest(DisplayList* to_update) const { 536 void MultiDisplayManager::SetDisplayIdsForTest(DisplayList* to_update) const {
537 DisplayList::iterator iter_to_update = to_update->begin(); 537 DisplayList::iterator iter_to_update = to_update->begin();
538 DisplayList::const_iterator iter = displays_.begin(); 538 DisplayList::const_iterator iter = displays_.begin();
539 for (; iter != displays_.end() && iter_to_update != to_update->end(); 539 for (; iter != displays_.end() && iter_to_update != to_update->end();
540 ++iter, ++iter_to_update) { 540 ++iter, ++iter_to_update) {
541 (*iter_to_update).set_id((*iter).id()); 541 (*iter_to_update).set_id((*iter).id());
542 } 542 }
543 } 543 }
544 544
545 } // namespace internal 545 } // namespace internal
546 } // namespace ash 546 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698