msw | 5e048a7 | 2016-09-07 18:55:30 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
msw | 5e048a7 | 2016-09-07 18:55:30 | [diff] [blame] | 5 | #include "ui/display/screen_base.h" |
| 6 | |
| 7 | #include "ui/display/display_finder.h" |
| 8 | |
| 9 | namespace display { |
| 10 | |
riajiang | bcbb8c4 | 2016-11-07 17:57:41 | [diff] [blame] | 11 | ScreenBase::ScreenBase() {} |
msw | 5e048a7 | 2016-09-07 18:55:30 | [diff] [blame] | 12 | |
riajiang | bcbb8c4 | 2016-11-07 17:57:41 | [diff] [blame] | 13 | ScreenBase::~ScreenBase() {} |
msw | 5e048a7 | 2016-09-07 18:55:30 | [diff] [blame] | 14 | |
| 15 | gfx::Point ScreenBase::GetCursorScreenPoint() { |
Daniel Bratell | ff54119 | 2017-11-02 14:22:28 | [diff] [blame] | 16 | NOTIMPLEMENTED_LOG_ONCE(); |
msw | 5e048a7 | 2016-09-07 18:55:30 | [diff] [blame] | 17 | return gfx::Point(); |
| 18 | } |
| 19 | |
| 20 | bool ScreenBase::IsWindowUnderCursor(gfx::NativeWindow window) { |
Daniel Bratell | ff54119 | 2017-11-02 14:22:28 | [diff] [blame] | 21 | NOTIMPLEMENTED_LOG_ONCE(); |
msw | 5e048a7 | 2016-09-07 18:55:30 | [diff] [blame] | 22 | return false; |
| 23 | } |
| 24 | |
| 25 | gfx::NativeWindow ScreenBase::GetWindowAtScreenPoint(const gfx::Point& point) { |
Daniel Bratell | ff54119 | 2017-11-02 14:22:28 | [diff] [blame] | 26 | NOTIMPLEMENTED_LOG_ONCE(); |
msw | 5e048a7 | 2016-09-07 18:55:30 | [diff] [blame] | 27 | return nullptr; |
| 28 | } |
| 29 | |
kylechar | 9825bba | 2016-11-02 14:10:16 | [diff] [blame] | 30 | Display ScreenBase::GetPrimaryDisplay() const { |
| 31 | auto iter = display_list_.GetPrimaryDisplayIterator(); |
| 32 | if (iter == display_list_.displays().end()) |
| 33 | return Display(); // Invalid display since we have no primary display. |
| 34 | return *iter; |
msw | 5e048a7 | 2016-09-07 18:55:30 | [diff] [blame] | 35 | } |
| 36 | |
jinsukkim | 2dd85f3 | 2017-03-17 01:54:28 | [diff] [blame] | 37 | Display ScreenBase::GetDisplayNearestWindow(gfx::NativeWindow window) const { |
riajiang | e5d57c4 | 2016-12-17 04:42:05 | [diff] [blame] | 38 | // TODO(riajiang): Implement this for multi-displays either here or in |
| 39 | // ScreenMus. |
Daniel Bratell | ff54119 | 2017-11-02 14:22:28 | [diff] [blame] | 40 | NOTIMPLEMENTED_LOG_ONCE(); |
kylechar | 9825bba | 2016-11-02 14:10:16 | [diff] [blame] | 41 | return GetPrimaryDisplay(); |
msw | 5e048a7 | 2016-09-07 18:55:30 | [diff] [blame] | 42 | } |
| 43 | |
kylechar | 9825bba | 2016-11-02 14:10:16 | [diff] [blame] | 44 | Display ScreenBase::GetDisplayNearestPoint(const gfx::Point& point) const { |
| 45 | return *FindDisplayNearestPoint(display_list_.displays(), point); |
msw | 5e048a7 | 2016-09-07 18:55:30 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | int ScreenBase::GetNumDisplays() const { |
| 49 | return static_cast<int>(display_list_.displays().size()); |
| 50 | } |
| 51 | |
riajiang | 107f22dd | 2016-11-18 18:38:11 | [diff] [blame] | 52 | const std::vector<Display>& ScreenBase::GetAllDisplays() const { |
msw | 5e048a7 | 2016-09-07 18:55:30 | [diff] [blame] | 53 | return display_list_.displays(); |
| 54 | } |
| 55 | |
kylechar | 9825bba | 2016-11-02 14:10:16 | [diff] [blame] | 56 | Display ScreenBase::GetDisplayMatching(const gfx::Rect& match_rect) const { |
sky | cdafce6 | 2017-03-06 19:22:33 | [diff] [blame] | 57 | if (match_rect.IsEmpty()) |
| 58 | return GetDisplayNearestPoint(match_rect.origin()); |
| 59 | |
kylechar | 9825bba | 2016-11-02 14:10:16 | [diff] [blame] | 60 | const Display* match = |
| 61 | FindDisplayWithBiggestIntersection(display_list_.displays(), match_rect); |
msw | 5e048a7 | 2016-09-07 18:55:30 | [diff] [blame] | 62 | return match ? *match : GetPrimaryDisplay(); |
| 63 | } |
| 64 | |
kylechar | 9825bba | 2016-11-02 14:10:16 | [diff] [blame] | 65 | void ScreenBase::AddObserver(DisplayObserver* observer) { |
msw | 5e048a7 | 2016-09-07 18:55:30 | [diff] [blame] | 66 | display_list_.AddObserver(observer); |
| 67 | } |
| 68 | |
kylechar | 9825bba | 2016-11-02 14:10:16 | [diff] [blame] | 69 | void ScreenBase::RemoveObserver(DisplayObserver* observer) { |
msw | 5e048a7 | 2016-09-07 18:55:30 | [diff] [blame] | 70 | display_list_.RemoveObserver(observer); |
| 71 | } |
| 72 | |
riajiang | bcbb8c4 | 2016-11-07 17:57:41 | [diff] [blame] | 73 | void ScreenBase::ProcessDisplayChanged(const Display& changed_display, |
| 74 | bool is_primary) { |
| 75 | if (display_list_.FindDisplayById(changed_display.id()) == |
| 76 | display_list_.displays().end()) { |
| 77 | display_list_.AddDisplay(changed_display, |
| 78 | is_primary ? DisplayList::Type::PRIMARY |
| 79 | : DisplayList::Type::NOT_PRIMARY); |
| 80 | return; |
| 81 | } |
| 82 | display_list_.UpdateDisplay( |
| 83 | changed_display, |
| 84 | is_primary ? DisplayList::Type::PRIMARY : DisplayList::Type::NOT_PRIMARY); |
| 85 | } |
| 86 | |
msw | 5e048a7 | 2016-09-07 18:55:30 | [diff] [blame] | 87 | } // namespace display |