| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "ui/gfx/display_finder.h" | 5 #include "ui/display/display_finder.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "ui/gfx/display.h" | 10 #include "ui/gfx/display.h" |
| 11 #include "ui/gfx/geometry/point.h" | 11 #include "ui/gfx/geometry/point.h" |
| 12 #include "ui/gfx/geometry/rect.h" | 12 #include "ui/gfx/geometry/rect.h" |
| 13 | 13 |
| 14 namespace gfx { | 14 namespace display { |
| 15 | 15 |
| 16 const Display* FindDisplayNearestPoint(const std::vector<Display>& displays, | 16 const Display* FindDisplayNearestPoint(const std::vector<Display>& displays, |
| 17 const Point& point) { | 17 const gfx::Point& point) { |
| 18 DCHECK(!displays.empty()); | 18 DCHECK(!displays.empty()); |
| 19 int min_distance = std::numeric_limits<int>::max(); | 19 int min_distance = std::numeric_limits<int>::max(); |
| 20 const Display* nearest_display = nullptr; | 20 const Display* nearest_display = nullptr; |
| 21 for (const auto& display : displays) { | 21 for (const auto& display : displays) { |
| 22 const int distance = display.bounds().ManhattanDistanceToPoint(point); | 22 const int distance = display.bounds().ManhattanDistanceToPoint(point); |
| 23 if (distance < min_distance) { | 23 if (distance < min_distance) { |
| 24 min_distance = distance; | 24 min_distance = distance; |
| 25 nearest_display = &display; | 25 nearest_display = &display; |
| 26 } | 26 } |
| 27 } | 27 } |
| 28 // There should always be at least one display that is less than INT_MAX away. | 28 // There should always be at least one display that is less than INT_MAX away. |
| 29 DCHECK(nearest_display); | 29 DCHECK(nearest_display); |
| 30 return nearest_display; | 30 return nearest_display; |
| 31 } | 31 } |
| 32 | 32 |
| 33 const Display* FindDisplayWithBiggestIntersection( | 33 const Display* FindDisplayWithBiggestIntersection( |
| 34 const std::vector<Display>& displays, | 34 const std::vector<Display>& displays, |
| 35 const Rect& rect) { | 35 const gfx::Rect& rect) { |
| 36 DCHECK(!displays.empty()); | 36 DCHECK(!displays.empty()); |
| 37 int max_area = 0; | 37 int max_area = 0; |
| 38 const Display* matching = nullptr; | 38 const Display* matching = nullptr; |
| 39 for (const auto& display : displays) { | 39 for (const auto& display : displays) { |
| 40 const Rect intersect = IntersectRects(display.bounds(), rect); | 40 const gfx::Rect intersect = IntersectRects(display.bounds(), rect); |
| 41 const int area = intersect.width() * intersect.height(); | 41 const int area = intersect.width() * intersect.height(); |
| 42 if (area > max_area) { | 42 if (area > max_area) { |
| 43 max_area = area; | 43 max_area = area; |
| 44 matching = &display; | 44 matching = &display; |
| 45 } | 45 } |
| 46 } | 46 } |
| 47 return matching; | 47 return matching; |
| 48 } | 48 } |
| 49 | 49 |
| 50 } // namespace gfx | 50 } // namespace display |
| OLD | NEW |