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