OLD | NEW |
(Empty) | |
| 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 |
| 5 #include "ui/views/widget/desktop_aura/desktop_screen_wayland.h" |
| 6 |
| 7 #include "ui/aura/window.h" |
| 8 #include "ui/ozone/public/ozone_platform.h" |
| 9 #include "ui/views/widget/desktop_aura/desktop_screen.h" |
| 10 |
| 11 namespace views { |
| 12 |
| 13 //////////////////////////////////////////////////////////////////////////////// |
| 14 // DesktopScreenWayland, public: |
| 15 DesktopScreenWayland::DesktopScreenWayland() |
| 16 : display::Screen(), |
| 17 displays_() { |
| 18 // Add a dummy Display. |
| 19 // Without this, content_shell crashes in WindowTreeHost::InitCompositor() |
| 20 // whiling calling GetDeviceScaleFactorFromDisplay() because the wl_output |
| 21 // messages arrives later from Wayland Server. |
| 22 displays_.push_back(display::Display(0, gfx::Rect(0, 0, 800, 600))); |
| 23 ui::OzonePlatform::GetInstance()->SetScreenOutputObserver(this); |
| 24 } |
| 25 |
| 26 DesktopScreenWayland::~DesktopScreenWayland() { |
| 27 } |
| 28 |
| 29 // Overridden from display::Screen: |
| 30 gfx::Point DesktopScreenWayland::GetCursorScreenPoint() { |
| 31 return gfx::Point(); |
| 32 } |
| 33 |
| 34 bool DesktopScreenWayland::IsWindowUnderCursor(gfx::NativeWindow window) { |
| 35 return true; |
| 36 } |
| 37 |
| 38 gfx::NativeWindow DesktopScreenWayland::GetWindowAtScreenPoint( |
| 39 const gfx::Point& point) { |
| 40 return nullptr; |
| 41 } |
| 42 |
| 43 int DesktopScreenWayland::GetNumDisplays() const { |
| 44 return displays_.size(); |
| 45 } |
| 46 |
| 47 std::vector<display::Display> DesktopScreenWayland::GetAllDisplays() const { |
| 48 return displays_; |
| 49 } |
| 50 |
| 51 display::Display DesktopScreenWayland::GetDisplayNearestWindow( |
| 52 gfx::NativeView window) const { |
| 53 return GetPrimaryDisplay(); |
| 54 } |
| 55 |
| 56 display::Display DesktopScreenWayland::GetDisplayNearestPoint( |
| 57 const gfx::Point& point) const { |
| 58 return GetPrimaryDisplay(); |
| 59 } |
| 60 |
| 61 display::Display DesktopScreenWayland::GetDisplayMatching( |
| 62 const gfx::Rect& match_rect) const { |
| 63 return GetPrimaryDisplay(); |
| 64 } |
| 65 |
| 66 display::Display DesktopScreenWayland::GetPrimaryDisplay() const { |
| 67 DCHECK(!displays_.empty()); |
| 68 return displays_.front(); |
| 69 } |
| 70 |
| 71 void DesktopScreenWayland::AddObserver(display::DisplayObserver* observer) { |
| 72 change_notifier_.AddObserver(observer); |
| 73 } |
| 74 |
| 75 void DesktopScreenWayland::RemoveObserver(display::DisplayObserver* observer) { |
| 76 change_notifier_.RemoveObserver(observer); |
| 77 } |
| 78 |
| 79 void DesktopScreenWayland::OnOutputGeometryChanged(int32_t name, |
| 80 const gfx::Rect& rect) { |
| 81 // Remove the dummy Display. |
| 82 if (GetPrimaryDisplay().id() == 0 && displays_.size() == 1) |
| 83 displays_.clear(); |
| 84 |
| 85 display::Display* matching = nullptr; |
| 86 for (std::vector<display::Display>::iterator it = displays_.begin(); |
| 87 it != displays_.end(); ++it) { |
| 88 if (name == it->id()) |
| 89 matching = &*it; |
| 90 } |
| 91 |
| 92 std::vector<display::Display> old_displays = displays_; |
| 93 |
| 94 if (!matching) |
| 95 displays_.push_back(display::Display(name, rect)); |
| 96 else |
| 97 matching->set_bounds(rect); |
| 98 |
| 99 change_notifier_.NotifyDisplaysChanged(old_displays, displays_); |
| 100 } |
| 101 |
| 102 } // namespace views |
OLD | NEW |