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

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: RenderText fixup 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 493 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 *internal_display_ = displays_[0]; 504 *internal_display_ = displays_[0];
505 return internal_display_id_; 505 return internal_display_id_;
506 } 506 }
507 507
508 void MultiDisplayManager::EnsurePointerInDisplays() { 508 void MultiDisplayManager::EnsurePointerInDisplays() {
509 // Don't try to move the pointer during the boot/startup. 509 // Don't try to move the pointer during the boot/startup.
510 if (!Shell::HasInstance()) 510 if (!Shell::HasInstance())
511 return; 511 return;
512 gfx::Point location_in_screen = Shell::GetScreen()->GetCursorScreenPoint(); 512 gfx::Point location_in_screen = Shell::GetScreen()->GetCursorScreenPoint();
513 gfx::Point target_location; 513 gfx::Point target_location;
514 int64 closest_distance = -1; 514 int64 closest_distance_squared = -1;
515 515
516 for (DisplayList::const_iterator iter = displays_.begin(); 516 for (DisplayList::const_iterator iter = displays_.begin();
517 iter != displays_.end(); ++iter) { 517 iter != displays_.end(); ++iter) {
518 const gfx::Rect& display_bounds = iter->bounds(); 518 const gfx::Rect& display_bounds = iter->bounds();
519 519
520 if (display_bounds.Contains(location_in_screen)) { 520 if (display_bounds.Contains(location_in_screen)) {
521 target_location = location_in_screen; 521 target_location = location_in_screen;
522 break; 522 break;
523 } 523 }
524 gfx::Point center = display_bounds.CenterPoint(); 524 gfx::Point center = display_bounds.CenterPoint();
525 gfx::Point diff = center.Subtract(location_in_screen); 525 // Use the distance squared from the center of the dislay. This is not
526 // Use the distance from the center of the dislay. This is not
527 // exactly "closest" display, but good enough to pick one 526 // exactly "closest" display, but good enough to pick one
528 // appropriate (and there are at most two displays). 527 // appropriate (and there are at most two displays).
529 int64 distance = diff.x() * diff.x() + diff.y() * diff.y(); 528 // We don't care about actual distance, only relative to other displays, so
530 if (closest_distance < 0 || closest_distance > distance) { 529 // using the LengthSquared() is cheaper than Length().
530 int64 distance_squared = (center - location_in_screen).LengthSquared();
531 if (closest_distance_squared < 0 ||
532 closest_distance_squared > distance_squared) {
531 target_location = center; 533 target_location = center;
532 closest_distance = distance; 534 closest_distance_squared = distance_squared;
533 } 535 }
534 } 536 }
535 537
536 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow(); 538 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow();
537 aura::client::ScreenPositionClient* client = 539 aura::client::ScreenPositionClient* client =
538 aura::client::GetScreenPositionClient(root_window); 540 aura::client::GetScreenPositionClient(root_window);
539 client->ConvertPointFromScreen(root_window, &target_location); 541 client->ConvertPointFromScreen(root_window, &target_location);
540 542
541 root_window->MoveCursorTo(target_location); 543 root_window->MoveCursorTo(target_location);
542 } 544 }
543 545
544 void MultiDisplayManager::SetDisplayIdsForTest(DisplayList* to_update) const { 546 void MultiDisplayManager::SetDisplayIdsForTest(DisplayList* to_update) const {
545 DisplayList::iterator iter_to_update = to_update->begin(); 547 DisplayList::iterator iter_to_update = to_update->begin();
546 DisplayList::const_iterator iter = displays_.begin(); 548 DisplayList::const_iterator iter = displays_.begin();
547 for (; iter != displays_.end() && iter_to_update != to_update->end(); 549 for (; iter != displays_.end() && iter_to_update != to_update->end();
548 ++iter, ++iter_to_update) { 550 ++iter, ++iter_to_update) {
549 (*iter_to_update).set_id((*iter).id()); 551 (*iter_to_update).set_id((*iter).id());
550 } 552 }
551 } 553 }
552 554
553 } // namespace internal 555 } // namespace internal
554 } // namespace ash 556 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698