Avi Drissman | 8ba1bad | 2022-09-13 19:22:36 | [diff] [blame] | 1 | // Copyright 2018 The Chromium Authors |
Shawn Gallea | 787ef55 | 2018-11-27 23:29:24 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef COMPONENTS_EXO_WAYLAND_ZAURA_SHELL_H_ |
| 6 | #define COMPONENTS_EXO_WAYLAND_ZAURA_SHELL_H_ |
| 7 | |
| 8 | #include <stdint.h> |
| 9 | |
Mitsuru Oshima | b86c8e2 | 2022-11-16 18:43:43 | [diff] [blame] | 10 | #include "ash/shell_observer.h" |
Mitsuru Oshima | 022987f | 2022-03-10 18:22:30 | [diff] [blame] | 11 | #include "chromeos/ui/base/window_state_type.h" |
Eliot Courtney | 99f3e9fc | 2019-04-03 09:07:20 | [diff] [blame] | 12 | #include "components/exo/surface.h" |
| 13 | #include "components/exo/surface_observer.h" |
Addison Luh | 60d521d | 2022-06-02 00:37:56 | [diff] [blame] | 14 | #include "components/exo/wayland/wayland_display_observer.h" |
| 15 | #include "ui/gfx/geometry/insets.h" |
chinsenj | 46a9766 | 2021-07-01 21:37:41 | [diff] [blame] | 16 | #include "ui/gfx/geometry/size_f.h" |
Eliot Courtney | 99f3e9fc | 2019-04-03 09:07:20 | [diff] [blame] | 17 | #include "ui/wm/public/activation_change_observer.h" |
| 18 | |
Shawn Gallea | 787ef55 | 2018-11-27 23:29:24 | [diff] [blame] | 19 | struct wl_client; |
Eliot Courtney | 99f3e9fc | 2019-04-03 09:07:20 | [diff] [blame] | 20 | struct wl_resource; |
Shawn Gallea | 787ef55 | 2018-11-27 23:29:24 | [diff] [blame] | 21 | |
Eriko Kurimoto | f66bb1f | 2022-11-30 17:07:37 | [diff] [blame] | 22 | namespace base { |
| 23 | class TimeDelta; |
| 24 | } |
| 25 | |
Shawn Gallea | 787ef55 | 2018-11-27 23:29:24 | [diff] [blame] | 26 | namespace exo { |
jonahwilliams | 9fdb3fed | 2021-10-13 18:24:44 | [diff] [blame] | 27 | |
Mitsuru Oshima | 022987f | 2022-03-10 18:22:30 | [diff] [blame] | 28 | class ShellSurface; |
jonahwilliams | 9fdb3fed | 2021-10-13 18:24:44 | [diff] [blame] | 29 | class ShellSurfaceBase; |
| 30 | |
Shawn Gallea | 787ef55 | 2018-11-27 23:29:24 | [diff] [blame] | 31 | namespace wayland { |
Mitsuru Oshima | 022987f | 2022-03-10 18:22:30 | [diff] [blame] | 32 | class SerialTracker; |
Shawn Gallea | 787ef55 | 2018-11-27 23:29:24 | [diff] [blame] | 33 | |
Eriko Kurimoto | f66bb1f | 2022-11-30 17:07:37 | [diff] [blame] | 34 | constexpr uint32_t kZAuraShellVersion = 47; |
Shawn Gallea | 787ef55 | 2018-11-27 23:29:24 | [diff] [blame] | 35 | |
Daniel Nicoara | e3befc0 | 2019-06-27 19:46:10 | [diff] [blame] | 36 | // Adds bindings to the Aura Shell. Normally this implies Ash on ChromeOS |
| 37 | // builds. On non-ChromeOS builds the protocol provides access to Aura windowing |
| 38 | // system. |
Shawn Gallea | 787ef55 | 2018-11-27 23:29:24 | [diff] [blame] | 39 | void bind_aura_shell(wl_client* client, |
| 40 | void* data, |
| 41 | uint32_t version, |
| 42 | uint32_t id); |
| 43 | |
Eliot Courtney | 99f3e9fc | 2019-04-03 09:07:20 | [diff] [blame] | 44 | class AuraSurface : public SurfaceObserver, |
| 45 | public ::wm::ActivationChangeObserver { |
| 46 | public: |
| 47 | AuraSurface(Surface* surface, wl_resource* resource); |
Peter Boström | 09c0182 | 2021-09-20 22:43:27 | [diff] [blame] | 48 | |
| 49 | AuraSurface(const AuraSurface&) = delete; |
| 50 | AuraSurface& operator=(const AuraSurface&) = delete; |
| 51 | |
Eliot Courtney | 99f3e9fc | 2019-04-03 09:07:20 | [diff] [blame] | 52 | ~AuraSurface() override; |
| 53 | |
| 54 | void SetFrame(SurfaceFrameType type); |
Mitsuru Oshima | c061d9e | 2021-01-29 18:52:07 | [diff] [blame] | 55 | void SetServerStartResize(); |
Eliot Courtney | 99f3e9fc | 2019-04-03 09:07:20 | [diff] [blame] | 56 | void SetFrameColors(SkColor active_frame_color, SkColor inactive_frame_color); |
| 57 | void SetParent(AuraSurface* parent, const gfx::Point& position); |
| 58 | void SetStartupId(const char* startup_id); |
| 59 | void SetApplicationId(const char* application_id); |
Lloyd Pique | d507c5f | 2020-11-11 22:47:05 | [diff] [blame] | 60 | void SetClientSurfaceId(const char* client_surface_id); |
Eliot Courtney | 99f3e9fc | 2019-04-03 09:07:20 | [diff] [blame] | 61 | void SetOcclusionTracking(bool tracking); |
Nicholas Hollingum | de1f81b5 | 2019-10-09 02:57:18 | [diff] [blame] | 62 | void Activate(); |
| 63 | void DrawAttention(); |
Chloe Pelling | 8a8acdeb | 2020-07-07 10:45:20 | [diff] [blame] | 64 | void SetFullscreenMode(uint32_t mode); |
Antonio Gomes | d7fcbe6 | 2021-02-24 18:30:49 | [diff] [blame] | 65 | void IntentToSnap(uint32_t snap_direction); |
Cattalyya Nuengsigkapian | ffc3961 | 2021-10-02 00:14:23 | [diff] [blame] | 66 | void SetSnapPrimary(); |
| 67 | void SetSnapSecondary(); |
Antonio Gomes | d7fcbe6 | 2021-02-24 18:30:49 | [diff] [blame] | 68 | void UnsetSnap(); |
Shengsong Tan | 394e260 | 2021-04-07 00:25:27 | [diff] [blame] | 69 | void SetWindowSessionId(int32_t window_session_id); |
Antonio Gomes | 22056e2 | 2021-04-16 16:56:19 | [diff] [blame] | 70 | void SetCanGoBack(); |
| 71 | void UnsetCanGoBack(); |
chinsenj | 46a9766 | 2021-07-01 21:37:41 | [diff] [blame] | 72 | void SetPip(); |
| 73 | void UnsetPip(); |
| 74 | void SetAspectRatio(const gfx::SizeF& aspect_ratio); |
Minju Kim | 98aa08c4f | 2021-08-10 02:01:45 | [diff] [blame] | 75 | void MoveToDesk(int desk_index); |
Minju Kim | 3c300e50 | 2021-09-02 09:08:47 | [diff] [blame] | 76 | void SetInitialWorkspace(const char* initial_workspace); |
Stefan Kuhne | dcbdde0 | 2021-09-24 19:54:14 | [diff] [blame] | 77 | void Pin(bool trusted); |
| 78 | void Unpin(); |
jonahwilliams | 9fdb3fed | 2021-10-13 18:24:44 | [diff] [blame] | 79 | void SetOrientationLock(uint32_t orientation_lock); |
Eriko Kurimoto | f66bb1f | 2022-11-30 17:07:37 | [diff] [blame] | 80 | void ShowTooltip(const char* text, |
| 81 | const gfx::Point& position, |
| 82 | uint32_t trigger, |
| 83 | const base::TimeDelta& show_delay, |
| 84 | const base::TimeDelta& hide_delay); |
| 85 | void HideTooltip(); |
Eliot Courtney | 99f3e9fc | 2019-04-03 09:07:20 | [diff] [blame] | 86 | |
| 87 | // Overridden from SurfaceObserver: |
| 88 | void OnSurfaceDestroying(Surface* surface) override; |
| 89 | void OnWindowOcclusionChanged(Surface* surface) override; |
Abhijeet Kandalkar | d354a70 | 2021-03-23 21:52:46 | [diff] [blame] | 90 | void OnFrameLockingChanged(Surface* surface, bool lock) override; |
Minju Kim | 98aa08c4f | 2021-08-10 02:01:45 | [diff] [blame] | 91 | void OnDeskChanged(Surface* surface, int state) override; |
yjliu | 9edcefd | 2022-01-25 02:00:33 | [diff] [blame] | 92 | void ThrottleFrameRate(bool on) override; |
Eriko Kurimoto | f66bb1f | 2022-11-30 17:07:37 | [diff] [blame] | 93 | void OnTooltipShown(Surface* surface, |
| 94 | const std::u16string& text, |
| 95 | const gfx::Rect& bounds) override; |
| 96 | void OnTooltipHidden(Surface* surface) override; |
Eliot Courtney | 99f3e9fc | 2019-04-03 09:07:20 | [diff] [blame] | 97 | |
| 98 | // Overridden from ActivationChangeObserver: |
| 99 | void OnWindowActivating(ActivationReason reason, |
| 100 | aura::Window* gaining_active, |
| 101 | aura::Window* losing_active) override; |
| 102 | void OnWindowActivated(ActivationReason reason, |
| 103 | aura::Window* gained_active, |
| 104 | aura::Window* lost_active) override {} |
| 105 | |
| 106 | protected: |
| 107 | virtual void SendOcclusionFraction(float occlusion_fraction); |
Eliot Courtney | 62eec49 | 2021-07-15 08:11:51 | [diff] [blame] | 108 | virtual void SendOcclusionState( |
| 109 | const aura::Window::OcclusionState occlusion_state); |
Eliot Courtney | 99f3e9fc | 2019-04-03 09:07:20 | [diff] [blame] | 110 | |
| 111 | private: |
| 112 | Surface* surface_; |
| 113 | wl_resource* const resource_; |
| 114 | |
Eriko Kurimoto | f66bb1f | 2022-11-30 17:07:37 | [diff] [blame] | 115 | // Tooltip text sent from Lacros. |
| 116 | // This is kept here since it should out-live ShowTooltip() scope. |
| 117 | std::u16string tooltip_text_; |
| 118 | |
Eliot Courtney | 62eec49 | 2021-07-15 08:11:51 | [diff] [blame] | 119 | void ComputeAndSendOcclusion( |
Eliot Courtney | 99f3e9fc | 2019-04-03 09:07:20 | [diff] [blame] | 120 | const aura::Window::OcclusionState occlusion_state, |
| 121 | const SkRegion& occluded_region); |
Eliot Courtney | 99f3e9fc | 2019-04-03 09:07:20 | [diff] [blame] | 122 | }; |
| 123 | |
jonahwilliams | 9fdb3fed | 2021-10-13 18:24:44 | [diff] [blame] | 124 | // Provides an implementation for top level operations on the shell. |
| 125 | class AuraToplevel { |
| 126 | public: |
Mitsuru Oshima | 022987f | 2022-03-10 18:22:30 | [diff] [blame] | 127 | AuraToplevel(ShellSurface* shell_surface, |
| 128 | SerialTracker* const serial_tracker, |
| 129 | wl_resource* aura_toplevel_resource, |
| 130 | wl_resource* xdg_toplevel_resource); |
| 131 | |
jonahwilliams | 9fdb3fed | 2021-10-13 18:24:44 | [diff] [blame] | 132 | AuraToplevel(const AuraToplevel&) = delete; |
| 133 | AuraToplevel& operator=(const AuraToplevel&) = delete; |
Mitsuru Oshima | 022987f | 2022-03-10 18:22:30 | [diff] [blame] | 134 | |
| 135 | virtual ~AuraToplevel(); |
jonahwilliams | 9fdb3fed | 2021-10-13 18:24:44 | [diff] [blame] | 136 | |
| 137 | void SetOrientationLock(uint32_t lock_type); |
yjliu | 7d45608 | 2021-11-02 18:39:37 | [diff] [blame] | 138 | void SetClientSubmitsSurfacesInPixelCoordinates(bool enable); |
Mitsuru Oshima | 022987f | 2022-03-10 18:22:30 | [diff] [blame] | 139 | void SetClientUsesScreenCoordinates(); |
| 140 | void SetWindowBounds(int32_t x, int32_t y, int32_t width, int32_t height); |
Sophie Wen | 55b7bcae | 2022-04-18 23:37:09 | [diff] [blame] | 141 | void SetRestoreInfo(int32_t restore_session_id, int32_t restore_window_id); |
Sophie Wen | 4d1dab62 | 2022-05-31 19:08:42 | [diff] [blame] | 142 | void SetRestoreInfoWithWindowIdSource( |
| 143 | int32_t restore_session_id, |
| 144 | const std::string& restore_window_id_source); |
Alvin Lee | b981e91 | 2022-05-05 12:06:45 | [diff] [blame] | 145 | void SetSystemModal(bool modal); |
Sammie Quon | 5c0d0ac | 2022-08-16 02:59:00 | [diff] [blame] | 146 | void SetFloat(); |
| 147 | void UnsetFloat(); |
yjliu | 7d45608 | 2021-11-02 18:39:37 | [diff] [blame] | 148 | |
Mitsuru Oshima | 022987f | 2022-03-10 18:22:30 | [diff] [blame] | 149 | void OnConfigure(const gfx::Rect& bounds, |
| 150 | chromeos::WindowStateType state_type, |
| 151 | bool resizing, |
| 152 | bool activated); |
| 153 | virtual void OnOriginChange(const gfx::Point& origin); |
Erik Chen | 8ccd9db | 2022-06-23 19:50:11 | [diff] [blame] | 154 | void SetDecoration(SurfaceFrameType type); |
Ben Becker | aa6d5af | 2022-08-17 22:34:51 | [diff] [blame] | 155 | void SetZOrder(ui::ZOrderLevel z_order); |
Erik Chen | 08a5e41 | 2022-09-29 22:06:48 | [diff] [blame] | 156 | void Activate(); |
| 157 | void Deactivate(); |
Fred Shih | 6d4d5d2 | 2022-11-14 22:28:03 | [diff] [blame] | 158 | void SetFullscreenMode(uint32_t mode); |
Erik Chen | ceeed8f | 2022-11-24 00:03:50 | [diff] [blame] | 159 | void SetScaleFactor(float scale_factor); |
Mitsuru Oshima | 022987f | 2022-03-10 18:22:30 | [diff] [blame] | 160 | |
| 161 | ShellSurface* shell_surface_; |
| 162 | SerialTracker* const serial_tracker_; |
| 163 | wl_resource* xdg_toplevel_resource_; |
| 164 | wl_resource* aura_toplevel_resource_; |
| 165 | bool supports_window_bounds_ = false; |
| 166 | |
| 167 | base::WeakPtrFactory<AuraToplevel> weak_ptr_factory_{this}; |
yjliu | 7d45608 | 2021-11-02 18:39:37 | [diff] [blame] | 168 | }; |
| 169 | |
| 170 | class AuraPopup { |
| 171 | public: |
| 172 | AuraPopup(ShellSurfaceBase* shell_surface); |
| 173 | AuraPopup(const AuraPopup&) = delete; |
| 174 | AuraPopup& operator=(const AuraPopup&) = delete; |
| 175 | ~AuraPopup(); |
| 176 | |
| 177 | void SetClientSubmitsSurfacesInPixelCoordinates(bool enable); |
Erik Chen | 8ccd9db | 2022-06-23 19:50:11 | [diff] [blame] | 178 | void SetDecoration(SurfaceFrameType type); |
Eriko Kurimoto | fc5c8e1 | 2022-07-19 05:40:35 | [diff] [blame] | 179 | void SetMenu(); |
Erik Chen | ceeed8f | 2022-11-24 00:03:50 | [diff] [blame] | 180 | void SetScaleFactor(float scale_factor); |
jonahwilliams | 9fdb3fed | 2021-10-13 18:24:44 | [diff] [blame] | 181 | |
| 182 | private: |
| 183 | ShellSurfaceBase* shell_surface_; |
| 184 | }; |
| 185 | |
Addison Luh | 60d521d | 2022-06-02 00:37:56 | [diff] [blame] | 186 | class AuraOutput : public WaylandDisplayObserver { |
| 187 | public: |
Mitsuru Oshima | dcb9100bc | 2022-08-18 16:30:48 | [diff] [blame] | 188 | AuraOutput(wl_resource* resource, WaylandDisplayHandler* display_handler); |
Addison Luh | 60d521d | 2022-06-02 00:37:56 | [diff] [blame] | 189 | |
| 190 | AuraOutput(const AuraOutput&) = delete; |
| 191 | AuraOutput& operator=(const AuraOutput&) = delete; |
| 192 | |
| 193 | ~AuraOutput() override; |
| 194 | |
| 195 | // Overridden from WaylandDisplayObserver: |
| 196 | bool SendDisplayMetrics(const display::Display& display, |
| 197 | uint32_t changed_metrics) override; |
Mitsuru Oshima | b86c8e2 | 2022-11-16 18:43:43 | [diff] [blame] | 198 | void SendActiveDisplay() override; |
Mitsuru Oshima | dcb9100bc | 2022-08-18 16:30:48 | [diff] [blame] | 199 | void OnOutputDestroyed() override; |
| 200 | |
| 201 | bool HasDisplayHandlerForTesting() const; |
Addison Luh | 60d521d | 2022-06-02 00:37:56 | [diff] [blame] | 202 | |
| 203 | protected: |
| 204 | virtual void SendInsets(const gfx::Insets& insets); |
Addison Luh | b0a4ff62 | 2022-06-02 00:46:36 | [diff] [blame] | 205 | virtual void SendLogicalTransform(int32_t transform); |
Addison Luh | 60d521d | 2022-06-02 00:37:56 | [diff] [blame] | 206 | |
| 207 | private: |
| 208 | wl_resource* const resource_; |
Mitsuru Oshima | dcb9100bc | 2022-08-18 16:30:48 | [diff] [blame] | 209 | WaylandDisplayHandler* display_handler_; |
Addison Luh | 60d521d | 2022-06-02 00:37:56 | [diff] [blame] | 210 | }; |
| 211 | |
Shawn Gallea | 787ef55 | 2018-11-27 23:29:24 | [diff] [blame] | 212 | } // namespace wayland |
| 213 | } // namespace exo |
| 214 | |
Eliot Courtney | 99f3e9fc | 2019-04-03 09:07:20 | [diff] [blame] | 215 | #endif // COMPONENTS_EXO_WAYLAND_ZAURA_SHELL_H_ |