Chromium Code Reviews| 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 // This has to be before any other includes, else default is picked up. | 5 // This has to be before any other includes, else default is picked up. |
| 6 // See base/logging for details on this. | 6 // See base/logging for details on this. |
| 7 #define NOTIMPLEMENTED_POLICY 5 | 7 #define NOTIMPLEMENTED_POLICY 5 |
| 8 | 8 |
| 9 #include "ui/display/screen_base.h" | 9 #include "ui/display/screen_base.h" |
| 10 | 10 |
| 11 #include "ui/display/display_finder.h" | 11 #include "ui/display/display_finder.h" |
| 12 | 12 |
| 13 namespace display { | 13 namespace display { |
| 14 | 14 |
| 15 ScreenBase::ScreenBase() { | 15 ScreenBase::ScreenBase() { |
| 16 display::Screen::SetScreenInstance(this); | 16 Screen::SetScreenInstance(this); |
| 17 } | 17 } |
| 18 | 18 |
| 19 ScreenBase::~ScreenBase() { | 19 ScreenBase::~ScreenBase() { |
| 20 DCHECK_EQ(this, display::Screen::GetScreen()); | 20 DCHECK_EQ(this, Screen::GetScreen()); |
| 21 display::Screen::SetScreenInstance(nullptr); | 21 Screen::SetScreenInstance(nullptr); |
| 22 } | 22 } |
| 23 | 23 |
| 24 void ScreenBase::ProcessDisplayChanged(const display::Display& changed_display, | 24 void ScreenBase::ProcessDisplayChanged(const Display& changed_display, |
| 25 bool is_primary) { | 25 bool is_primary) { |
| 26 if (display_list_.FindDisplayById(changed_display.id()) == | 26 if (display_list_.FindDisplayById(changed_display.id()) == |
| 27 display_list_.displays().end()) { | 27 display_list_.displays().end()) { |
| 28 display_list_.AddDisplay( | 28 display_list_.AddDisplay(changed_display, |
| 29 changed_display, is_primary ? display::DisplayList::Type::PRIMARY | 29 is_primary ? DisplayList::Type::PRIMARY |
| 30 : display::DisplayList::Type::NOT_PRIMARY); | 30 : DisplayList::Type::NOT_PRIMARY); |
| 31 return; | 31 return; |
| 32 } | 32 } |
| 33 display_list_.UpdateDisplay( | 33 display_list_.UpdateDisplay( |
| 34 changed_display, is_primary ? display::DisplayList::Type::PRIMARY | 34 changed_display, |
| 35 : display::DisplayList::Type::NOT_PRIMARY); | 35 is_primary ? DisplayList::Type::PRIMARY : DisplayList::Type::NOT_PRIMARY); |
| 36 } | 36 } |
| 37 | 37 |
| 38 gfx::Point ScreenBase::GetCursorScreenPoint() { | 38 gfx::Point ScreenBase::GetCursorScreenPoint() { |
| 39 NOTIMPLEMENTED(); | 39 NOTIMPLEMENTED(); |
| 40 return gfx::Point(); | 40 return gfx::Point(); |
| 41 } | 41 } |
| 42 | 42 |
| 43 bool ScreenBase::IsWindowUnderCursor(gfx::NativeWindow window) { | 43 bool ScreenBase::IsWindowUnderCursor(gfx::NativeWindow window) { |
| 44 NOTIMPLEMENTED(); | 44 NOTIMPLEMENTED(); |
| 45 return false; | 45 return false; |
| 46 } | 46 } |
| 47 | 47 |
| 48 gfx::NativeWindow ScreenBase::GetWindowAtScreenPoint(const gfx::Point& point) { | 48 gfx::NativeWindow ScreenBase::GetWindowAtScreenPoint(const gfx::Point& point) { |
| 49 NOTIMPLEMENTED(); | 49 NOTIMPLEMENTED(); |
| 50 return nullptr; | 50 return nullptr; |
| 51 } | 51 } |
| 52 | 52 |
| 53 display::Display ScreenBase::GetPrimaryDisplay() const { | 53 Display ScreenBase::GetPrimaryDisplay() const { |
|
sky
2016/11/01 22:03:37
Can this function really be called when there are
kylechar
2016/11/01 22:07:13
Yep :( Other instances of Screen implement (eg. Sc
kylechar
2016/11/01 22:18:30
On second though, I could add a NOTREACHED() to ca
| |
| 54 return *display_list_.GetPrimaryDisplayIterator(); | 54 auto iter = display_list_.GetPrimaryDisplayIterator(); |
| 55 if (iter == display_list_.displays().end()) | |
| 56 return Display(); // Invalid display since we have no primary display. | |
| 57 return *iter; | |
| 55 } | 58 } |
| 56 | 59 |
| 57 display::Display ScreenBase::GetDisplayNearestWindow( | 60 Display ScreenBase::GetDisplayNearestWindow(gfx::NativeView view) const { |
| 58 gfx::NativeView view) const { | |
| 59 NOTIMPLEMENTED(); | 61 NOTIMPLEMENTED(); |
| 60 return *display_list_.GetPrimaryDisplayIterator(); | 62 return GetPrimaryDisplay(); |
| 61 } | 63 } |
| 62 | 64 |
| 63 display::Display ScreenBase::GetDisplayNearestPoint( | 65 Display ScreenBase::GetDisplayNearestPoint(const gfx::Point& point) const { |
| 64 const gfx::Point& point) const { | 66 return *FindDisplayNearestPoint(display_list_.displays(), point); |
| 65 return *display::FindDisplayNearestPoint(display_list_.displays(), point); | |
| 66 } | 67 } |
| 67 | 68 |
| 68 int ScreenBase::GetNumDisplays() const { | 69 int ScreenBase::GetNumDisplays() const { |
| 69 return static_cast<int>(display_list_.displays().size()); | 70 return static_cast<int>(display_list_.displays().size()); |
| 70 } | 71 } |
| 71 | 72 |
| 72 std::vector<display::Display> ScreenBase::GetAllDisplays() const { | 73 std::vector<Display> ScreenBase::GetAllDisplays() const { |
| 73 return display_list_.displays(); | 74 return display_list_.displays(); |
| 74 } | 75 } |
| 75 | 76 |
| 76 display::Display ScreenBase::GetDisplayMatching( | 77 Display ScreenBase::GetDisplayMatching(const gfx::Rect& match_rect) const { |
| 77 const gfx::Rect& match_rect) const { | 78 const Display* match = |
| 78 const display::Display* match = display::FindDisplayWithBiggestIntersection( | 79 FindDisplayWithBiggestIntersection(display_list_.displays(), match_rect); |
| 79 display_list_.displays(), match_rect); | |
| 80 return match ? *match : GetPrimaryDisplay(); | 80 return match ? *match : GetPrimaryDisplay(); |
| 81 } | 81 } |
| 82 | 82 |
| 83 void ScreenBase::AddObserver(display::DisplayObserver* observer) { | 83 void ScreenBase::AddObserver(DisplayObserver* observer) { |
| 84 display_list_.AddObserver(observer); | 84 display_list_.AddObserver(observer); |
| 85 } | 85 } |
| 86 | 86 |
| 87 void ScreenBase::RemoveObserver(display::DisplayObserver* observer) { | 87 void ScreenBase::RemoveObserver(DisplayObserver* observer) { |
| 88 display_list_.RemoveObserver(observer); | 88 display_list_.RemoveObserver(observer); |
| 89 } | 89 } |
| 90 | 90 |
| 91 } // namespace display | 91 } // namespace display |
| OLD | NEW |