| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/mojo/init/screen_mojo.h" | 5 #include "ui/mojo/init/screen_mojo.h" |
| 6 | 6 |
| 7 namespace ui { | 7 namespace ui { |
| 8 namespace mojo { | 8 namespace mojo { |
| 9 | 9 |
| 10 ScreenMojo::ScreenMojo(const gfx::Size& screen_size_in_pixels, | 10 ScreenMojo::ScreenMojo(const std::vector<gfx::Display>& displays) |
| 11 float device_pixel_ratio) | 11 : displays_(displays) {} |
| 12 : screen_size_in_pixels_(screen_size_in_pixels), | 12 |
| 13 device_pixel_ratio_(device_pixel_ratio) { | 13 ScreenMojo::~ScreenMojo() {} |
| 14 static int64 synthesized_display_id = 2000; | |
| 15 display_.set_id(synthesized_display_id++); | |
| 16 display_.SetScaleAndBounds(device_pixel_ratio, | |
| 17 gfx::Rect(screen_size_in_pixels)); | |
| 18 } | |
| 19 | 14 |
| 20 gfx::Point ScreenMojo::GetCursorScreenPoint() { | 15 gfx::Point ScreenMojo::GetCursorScreenPoint() { |
| 16 NOTIMPLEMENTED(); |
| 21 return gfx::Point(); | 17 return gfx::Point(); |
| 22 } | 18 } |
| 23 | 19 |
| 24 gfx::NativeWindow ScreenMojo::GetWindowUnderCursor() { | 20 gfx::NativeWindow ScreenMojo::GetWindowUnderCursor() { |
| 25 NOTIMPLEMENTED(); | 21 NOTIMPLEMENTED(); |
| 26 return nullptr; | 22 return nullptr; |
| 27 } | 23 } |
| 28 | 24 |
| 29 gfx::NativeWindow ScreenMojo::GetWindowAtScreenPoint(const gfx::Point& point) { | 25 gfx::NativeWindow ScreenMojo::GetWindowAtScreenPoint(const gfx::Point& point) { |
| 30 NOTIMPLEMENTED(); | 26 NOTIMPLEMENTED(); |
| 31 return nullptr; | 27 return nullptr; |
| 32 } | 28 } |
| 33 | 29 |
| 34 gfx::Display ScreenMojo::GetPrimaryDisplay() const { | 30 gfx::Display ScreenMojo::GetPrimaryDisplay() const { |
| 35 return display_; | 31 return displays_[0]; |
| 36 } | 32 } |
| 37 | 33 |
| 38 gfx::Display ScreenMojo::GetDisplayNearestWindow(gfx::NativeView view) const { | 34 gfx::Display ScreenMojo::GetDisplayNearestWindow(gfx::NativeView view) const { |
| 39 return GetPrimaryDisplay(); | 35 return GetPrimaryDisplay(); |
| 40 } | 36 } |
| 41 | 37 |
| 42 gfx::Display ScreenMojo::GetDisplayNearestPoint(const gfx::Point& point) const { | 38 gfx::Display ScreenMojo::GetDisplayNearestPoint(const gfx::Point& point) const { |
| 43 return GetPrimaryDisplay(); | 39 return GetPrimaryDisplay(); |
| 44 } | 40 } |
| 45 | 41 |
| 46 int ScreenMojo::GetNumDisplays() const { | 42 int ScreenMojo::GetNumDisplays() const { |
| 47 return 1; | 43 return static_cast<int>(displays_.size()); |
| 48 } | 44 } |
| 49 | 45 |
| 50 std::vector<gfx::Display> ScreenMojo::GetAllDisplays() const { | 46 std::vector<gfx::Display> ScreenMojo::GetAllDisplays() const { |
| 51 return std::vector<gfx::Display>(1, GetPrimaryDisplay()); | 47 return displays_; |
| 52 } | 48 } |
| 53 | 49 |
| 54 gfx::Display ScreenMojo::GetDisplayMatching(const gfx::Rect& match_rect) const { | 50 gfx::Display ScreenMojo::GetDisplayMatching(const gfx::Rect& match_rect) const { |
| 55 return GetPrimaryDisplay(); | 51 int biggest_area = 0; |
| 52 gfx::Display result; |
| 53 const gfx::Display matching_display; |
| 54 for (const gfx::Display& display : displays_) { |
| 55 gfx::Rect display_union(match_rect); |
| 56 display_union.Union(display.bounds()); |
| 57 if (!display_union.IsEmpty()) { |
| 58 const int area = display_union.width() * display_union.height(); |
| 59 if (area > biggest_area) { |
| 60 biggest_area = area; |
| 61 result = display; |
| 62 } |
| 63 } |
| 64 } |
| 65 return biggest_area == 0 ? displays_[0] : result; |
| 56 } | 66 } |
| 57 | 67 |
| 58 void ScreenMojo::AddObserver(gfx::DisplayObserver* observer) { | 68 void ScreenMojo::AddObserver(gfx::DisplayObserver* observer) { |
| 59 // TODO: add support for display changes. | 69 // TODO: add support for display changes. |
| 60 } | 70 } |
| 61 | 71 |
| 62 void ScreenMojo::RemoveObserver(gfx::DisplayObserver* observer) { | 72 void ScreenMojo::RemoveObserver(gfx::DisplayObserver* observer) { |
| 63 // TODO: add support for display changes. | 73 // TODO: add support for display changes. |
| 64 } | 74 } |
| 65 | 75 |
| 66 } // namespace mojo | 76 } // namespace mojo |
| 67 } // namespace ui | 77 } // namespace ui |
| OLD | NEW |