Index: ash/display/screen_ash.cc |
diff --git a/ash/display/screen_ash.cc b/ash/display/screen_ash.cc |
index 60089223bac1059192798b8089e8cffb8559919c..477c7106baa716823984f078f5b2fe2255f25058 100644 |
--- a/ash/display/screen_ash.cc |
+++ b/ash/display/screen_ash.cc |
@@ -17,6 +17,7 @@ |
#include "ui/aura/env.h" |
#include "ui/aura/window_event_dispatcher.h" |
#include "ui/gfx/display.h" |
+#include "ui/gfx/display_finder.h" |
#include "ui/gfx/screen.h" |
namespace ash { |
@@ -27,42 +28,6 @@ DisplayManager* GetDisplayManager() { |
return Shell::GetInstance()->display_manager(); |
} |
-gfx::Display FindDisplayNearestPoint(const std::vector<gfx::Display>& displays, |
- const gfx::Point& point) { |
- int min_distance = INT_MAX; |
- const gfx::Display* nearest_display = NULL; |
- for (std::vector<gfx::Display>::const_iterator iter = displays.begin(); |
- iter != displays.end(); ++iter) { |
- const gfx::Display& display = *iter; |
- int distance = display.bounds().ManhattanDistanceToPoint(point); |
- if (distance < min_distance) { |
- min_distance = distance; |
- nearest_display = &display; |
- } |
- } |
- // There should always be at least one display that is less than INT_MAX away. |
- DCHECK(nearest_display); |
- return *nearest_display; |
-} |
- |
-const gfx::Display* FindDisplayMatching( |
- const std::vector<gfx::Display>& displays, |
- const gfx::Rect& match_rect) { |
- int max_area = 0; |
- const gfx::Display* matching = NULL; |
- for (std::vector<gfx::Display>::const_iterator iter = displays.begin(); |
- iter != displays.end(); ++iter) { |
- const gfx::Display& display = *iter; |
- gfx::Rect intersect = gfx::IntersectRects(display.bounds(), match_rect); |
- int area = intersect.width() * intersect.height(); |
- if (area > max_area) { |
- max_area = area; |
- matching = &display; |
- } |
- } |
- return matching; |
-} |
- |
class ScreenForShutdown : public gfx::Screen { |
public: |
explicit ScreenForShutdown(ScreenAsh* screen_ash) |
@@ -84,11 +49,11 @@ class ScreenForShutdown : public gfx::Screen { |
return primary_display_; |
} |
gfx::Display GetDisplayNearestPoint(const gfx::Point& point) const override { |
- return FindDisplayNearestPoint(display_list_, point); |
+ return *gfx::FindDisplayNearestPoint(display_list_, point); |
} |
gfx::Display GetDisplayMatching(const gfx::Rect& match_rect) const override { |
const gfx::Display* matching = |
- FindDisplayMatching(display_list_, match_rect); |
+ gfx::FindDisplayWithBiggestIntersection(display_list_, match_rect); |
// Fallback to the primary display if there is no matching display. |
return matching ? *matching : GetPrimaryDisplay(); |
} |
@@ -187,14 +152,14 @@ gfx::Display ScreenAsh::GetDisplayNearestPoint(const gfx::Point& point) const { |
// Fallback to the display that has the shortest Manhattan distance from |
// the |point|. This is correct in the only areas that matter, namely in the |
// corners between the physical screens. |
- return FindDisplayNearestPoint(GetDisplayManager()->active_display_list(), |
- point); |
+ return *gfx::FindDisplayNearestPoint( |
+ GetDisplayManager()->active_display_list(), point); |
} |
gfx::Display ScreenAsh::GetDisplayMatching(const gfx::Rect& match_rect) const { |
if (match_rect.IsEmpty()) |
return GetDisplayNearestPoint(match_rect.origin()); |
- const gfx::Display* matching = FindDisplayMatching( |
+ const gfx::Display* matching = gfx::FindDisplayWithBiggestIntersection( |
GetDisplayManager()->active_display_list(), match_rect); |
// Fallback to the primary display if there is no matching display. |
return matching ? *matching : GetPrimaryDisplay(); |