Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 #ifndef UI_VIEWS_WIDGET_DESKTOP_AURA_DESKTOP_SCREEN_X11_H_ | 5 #ifndef UI_VIEWS_WIDGET_DESKTOP_AURA_DESKTOP_SCREEN_X11_H_ |
| 6 #define UI_VIEWS_WIDGET_DESKTOP_AURA_DESKTOP_SCREEN_X11_H_ | 6 #define UI_VIEWS_WIDGET_DESKTOP_AURA_DESKTOP_SCREEN_X11_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 | 11 |
| 12 #include "base/cancelable_callback.h" | |
| 12 #include "base/macros.h" | 13 #include "base/macros.h" |
| 13 #include "base/timer/timer.h" | |
| 14 #include "ui/display/display_change_notifier.h" | 14 #include "ui/display/display_change_notifier.h" |
| 15 #include "ui/display/screen.h" | 15 #include "ui/display/screen.h" |
| 16 #include "ui/events/platform/platform_event_dispatcher.h" | 16 #include "ui/events/platform/platform_event_dispatcher.h" |
| 17 #include "ui/views/linux_ui/device_scale_factor_observer.h" | |
| 17 #include "ui/views/views_export.h" | 18 #include "ui/views/views_export.h" |
| 18 | 19 |
| 19 typedef unsigned long XID; | 20 typedef unsigned long XID; |
| 20 typedef XID Window; | 21 typedef XID Window; |
| 21 typedef struct _XDisplay Display; | 22 typedef struct _XDisplay Display; |
| 22 | 23 |
| 23 namespace views { | 24 namespace views { |
| 24 class DesktopScreenX11Test; | 25 class DesktopScreenX11Test; |
| 25 | 26 |
| 26 namespace test { | 27 namespace test { |
| 27 class DesktopScreenX11TestApi; | 28 class DesktopScreenX11TestApi; |
| 28 } | 29 } |
| 29 | 30 |
| 30 // Our singleton screen implementation that talks to xrandr. | 31 // Our singleton screen implementation that talks to xrandr. |
| 31 class VIEWS_EXPORT DesktopScreenX11 : public display::Screen, | 32 class VIEWS_EXPORT DesktopScreenX11 : public display::Screen, |
| 32 public ui::PlatformEventDispatcher { | 33 public ui::PlatformEventDispatcher, |
| 34 public views::DeviceScaleFactorObserver { | |
| 33 public: | 35 public: |
| 34 DesktopScreenX11(); | 36 DesktopScreenX11(); |
| 35 | 37 |
| 36 ~DesktopScreenX11() override; | 38 ~DesktopScreenX11() override; |
| 37 | 39 |
| 38 // Overridden from display::Screen: | 40 // Overridden from display::Screen: |
| 39 gfx::Point GetCursorScreenPoint() override; | 41 gfx::Point GetCursorScreenPoint() override; |
| 40 bool IsWindowUnderCursor(gfx::NativeWindow window) override; | 42 bool IsWindowUnderCursor(gfx::NativeWindow window) override; |
| 41 gfx::NativeWindow GetWindowAtScreenPoint(const gfx::Point& point) override; | 43 gfx::NativeWindow GetWindowAtScreenPoint(const gfx::Point& point) override; |
| 42 int GetNumDisplays() const override; | 44 int GetNumDisplays() const override; |
| 43 const std::vector<display::Display>& GetAllDisplays() const override; | 45 const std::vector<display::Display>& GetAllDisplays() const override; |
| 44 display::Display GetDisplayNearestWindow( | 46 display::Display GetDisplayNearestWindow( |
| 45 gfx::NativeView window) const override; | 47 gfx::NativeView window) const override; |
| 46 display::Display GetDisplayNearestPoint( | 48 display::Display GetDisplayNearestPoint( |
| 47 const gfx::Point& point) const override; | 49 const gfx::Point& point) const override; |
| 48 display::Display GetDisplayMatching( | 50 display::Display GetDisplayMatching( |
| 49 const gfx::Rect& match_rect) const override; | 51 const gfx::Rect& match_rect) const override; |
| 50 display::Display GetPrimaryDisplay() const override; | 52 display::Display GetPrimaryDisplay() const override; |
| 51 void AddObserver(display::DisplayObserver* observer) override; | 53 void AddObserver(display::DisplayObserver* observer) override; |
| 52 void RemoveObserver(display::DisplayObserver* observer) override; | 54 void RemoveObserver(display::DisplayObserver* observer) override; |
| 53 | 55 |
| 54 // ui::PlatformEventDispatcher: | 56 // ui::PlatformEventDispatcher: |
| 55 bool CanDispatchEvent(const ui::PlatformEvent& event) override; | 57 bool CanDispatchEvent(const ui::PlatformEvent& event) override; |
| 56 uint32_t DispatchEvent(const ui::PlatformEvent& event) override; | 58 uint32_t DispatchEvent(const ui::PlatformEvent& event) override; |
| 57 | 59 |
| 60 // views::DeviceScaleFactorObserver: | |
| 61 void OnDeviceScaleFactorChanged() override; | |
| 62 | |
| 58 static void UpdateDeviceScaleFactorForTest(); | 63 static void UpdateDeviceScaleFactorForTest(); |
| 59 | 64 |
| 60 private: | 65 private: |
| 61 friend class DesktopScreenX11Test; | 66 friend class DesktopScreenX11Test; |
| 62 friend class test::DesktopScreenX11TestApi; | 67 friend class test::DesktopScreenX11TestApi; |
| 63 | 68 |
| 64 // Constructor used in tests. | 69 // Constructor used in tests. |
| 65 DesktopScreenX11(const std::vector<display::Display>& test_displays); | 70 DesktopScreenX11(const std::vector<display::Display>& test_displays); |
| 66 | 71 |
| 67 // Builds a list of displays from the current screen information offered by | 72 // Builds a list of displays from the current screen information offered by |
| 68 // the X server. | 73 // the X server. |
| 69 std::vector<display::Display> BuildDisplaysFromXRandRInfo(); | 74 std::vector<display::Display> BuildDisplaysFromXRandRInfo(); |
| 70 | 75 |
| 71 // We delay updating the display so we can coalesce events. | 76 void RestartDelayedConfigureTask(); |
| 72 void ConfigureTimerFired(); | 77 |
| 78 void UpdateDisplayConfiguration(); | |
|
Elliot Glaysher
2017/06/29 17:22:36
docs please.
Tom Anderson
2017/06/29 18:38:59
Done.
| |
| 73 | 79 |
| 74 // Updates |displays_| and sets FontRenderParams's scale factor. | 80 // Updates |displays_| and sets FontRenderParams's scale factor. |
| 75 void SetDisplaysInternal(const std::vector<display::Display>& displays); | 81 void SetDisplaysInternal(const std::vector<display::Display>& displays); |
| 76 | 82 |
| 77 Display* xdisplay_; | 83 Display* xdisplay_; |
| 78 ::Window x_root_window_; | 84 ::Window x_root_window_; |
| 79 | 85 |
| 80 // Whether the x server supports the XRandR extension. | 86 // Whether the x server supports the XRandR extension. |
| 81 bool has_xrandr_; | 87 bool has_xrandr_; |
| 82 | 88 |
| 83 // The base of the event numbers used to represent XRandr events used in | 89 // The base of the event numbers used to represent XRandr events used in |
| 84 // decoding events regarding output add/remove. | 90 // decoding events regarding output add/remove. |
| 85 int xrandr_event_base_; | 91 int xrandr_event_base_; |
| 86 | 92 |
| 87 // The display objects we present to chrome. | 93 // The display objects we present to chrome. |
| 88 std::vector<display::Display> displays_; | 94 std::vector<display::Display> displays_; |
| 89 | 95 |
| 90 // The index into displays_ that represents the primary display. | 96 // The index into displays_ that represents the primary display. |
| 91 size_t primary_display_index_; | 97 size_t primary_display_index_; |
| 92 | 98 |
| 93 // The timer to delay configuring outputs. See also the comments in | 99 // The task to delay configuring outputs. We delay updating the |
| 94 // Dispatch(). | 100 // display so we can coalesce events. |
| 95 std::unique_ptr<base::OneShotTimer> configure_timer_; | 101 base::CancelableCallback<void()> delayed_configuration_task_; |
| 96 | 102 |
| 97 display::DisplayChangeNotifier change_notifier_; | 103 display::DisplayChangeNotifier change_notifier_; |
| 98 | 104 |
| 105 base::WeakPtrFactory<DesktopScreenX11> weak_factory_; | |
| 106 | |
| 99 DISALLOW_COPY_AND_ASSIGN(DesktopScreenX11); | 107 DISALLOW_COPY_AND_ASSIGN(DesktopScreenX11); |
| 100 }; | 108 }; |
| 101 | 109 |
| 102 } // namespace views | 110 } // namespace views |
| 103 | 111 |
| 104 #endif // UI_VIEWS_WIDGET_DESKTOP_AURA_DESKTOP_SCREEN_X11_H_ | 112 #endif // UI_VIEWS_WIDGET_DESKTOP_AURA_DESKTOP_SCREEN_X11_H_ |
| OLD | NEW |