blob: 54236fad97f885f020336f51a973246a79474ce4 [file] [log] [blame]
Avi Drissman8ba1bad2022-09-13 19:22:361// Copyright 2018 The Chromium Authors
Shawn Gallea787ef552018-11-27 23:29:242// 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 Oshimab86c8e22022-11-16 18:43:4310#include "ash/shell_observer.h"
Mitsuru Oshima022987f2022-03-10 18:22:3011#include "chromeos/ui/base/window_state_type.h"
Eliot Courtney99f3e9fc2019-04-03 09:07:2012#include "components/exo/surface.h"
13#include "components/exo/surface_observer.h"
Addison Luh60d521d2022-06-02 00:37:5614#include "components/exo/wayland/wayland_display_observer.h"
15#include "ui/gfx/geometry/insets.h"
chinsenj46a97662021-07-01 21:37:4116#include "ui/gfx/geometry/size_f.h"
Eliot Courtney99f3e9fc2019-04-03 09:07:2017#include "ui/wm/public/activation_change_observer.h"
18
Shawn Gallea787ef552018-11-27 23:29:2419struct wl_client;
Eliot Courtney99f3e9fc2019-04-03 09:07:2020struct wl_resource;
Shawn Gallea787ef552018-11-27 23:29:2421
Eriko Kurimotof66bb1f2022-11-30 17:07:3722namespace base {
23class TimeDelta;
24}
25
Shawn Gallea787ef552018-11-27 23:29:2426namespace exo {
jonahwilliams9fdb3fed2021-10-13 18:24:4427
Mitsuru Oshima022987f2022-03-10 18:22:3028class ShellSurface;
jonahwilliams9fdb3fed2021-10-13 18:24:4429class ShellSurfaceBase;
30
Shawn Gallea787ef552018-11-27 23:29:2431namespace wayland {
Mitsuru Oshima022987f2022-03-10 18:22:3032class SerialTracker;
Shawn Gallea787ef552018-11-27 23:29:2433
Eriko Kurimotof66bb1f2022-11-30 17:07:3734constexpr uint32_t kZAuraShellVersion = 47;
Shawn Gallea787ef552018-11-27 23:29:2435
Daniel Nicoarae3befc02019-06-27 19:46:1036// 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 Gallea787ef552018-11-27 23:29:2439void bind_aura_shell(wl_client* client,
40 void* data,
41 uint32_t version,
42 uint32_t id);
43
Eliot Courtney99f3e9fc2019-04-03 09:07:2044class AuraSurface : public SurfaceObserver,
45 public ::wm::ActivationChangeObserver {
46 public:
47 AuraSurface(Surface* surface, wl_resource* resource);
Peter Boström09c01822021-09-20 22:43:2748
49 AuraSurface(const AuraSurface&) = delete;
50 AuraSurface& operator=(const AuraSurface&) = delete;
51
Eliot Courtney99f3e9fc2019-04-03 09:07:2052 ~AuraSurface() override;
53
54 void SetFrame(SurfaceFrameType type);
Mitsuru Oshimac061d9e2021-01-29 18:52:0755 void SetServerStartResize();
Eliot Courtney99f3e9fc2019-04-03 09:07:2056 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 Piqued507c5f2020-11-11 22:47:0560 void SetClientSurfaceId(const char* client_surface_id);
Eliot Courtney99f3e9fc2019-04-03 09:07:2061 void SetOcclusionTracking(bool tracking);
Nicholas Hollingumde1f81b52019-10-09 02:57:1862 void Activate();
63 void DrawAttention();
Chloe Pelling8a8acdeb2020-07-07 10:45:2064 void SetFullscreenMode(uint32_t mode);
Antonio Gomesd7fcbe62021-02-24 18:30:4965 void IntentToSnap(uint32_t snap_direction);
Cattalyya Nuengsigkapianffc39612021-10-02 00:14:2366 void SetSnapPrimary();
67 void SetSnapSecondary();
Antonio Gomesd7fcbe62021-02-24 18:30:4968 void UnsetSnap();
Shengsong Tan394e2602021-04-07 00:25:2769 void SetWindowSessionId(int32_t window_session_id);
Antonio Gomes22056e22021-04-16 16:56:1970 void SetCanGoBack();
71 void UnsetCanGoBack();
chinsenj46a97662021-07-01 21:37:4172 void SetPip();
73 void UnsetPip();
74 void SetAspectRatio(const gfx::SizeF& aspect_ratio);
Minju Kim98aa08c4f2021-08-10 02:01:4575 void MoveToDesk(int desk_index);
Minju Kim3c300e502021-09-02 09:08:4776 void SetInitialWorkspace(const char* initial_workspace);
Stefan Kuhnedcbdde02021-09-24 19:54:1477 void Pin(bool trusted);
78 void Unpin();
jonahwilliams9fdb3fed2021-10-13 18:24:4479 void SetOrientationLock(uint32_t orientation_lock);
Eriko Kurimotof66bb1f2022-11-30 17:07:3780 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 Courtney99f3e9fc2019-04-03 09:07:2086
87 // Overridden from SurfaceObserver:
88 void OnSurfaceDestroying(Surface* surface) override;
89 void OnWindowOcclusionChanged(Surface* surface) override;
Abhijeet Kandalkard354a702021-03-23 21:52:4690 void OnFrameLockingChanged(Surface* surface, bool lock) override;
Minju Kim98aa08c4f2021-08-10 02:01:4591 void OnDeskChanged(Surface* surface, int state) override;
yjliu9edcefd2022-01-25 02:00:3392 void ThrottleFrameRate(bool on) override;
Eriko Kurimotof66bb1f2022-11-30 17:07:3793 void OnTooltipShown(Surface* surface,
94 const std::u16string& text,
95 const gfx::Rect& bounds) override;
96 void OnTooltipHidden(Surface* surface) override;
Eliot Courtney99f3e9fc2019-04-03 09:07:2097
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 Courtney62eec492021-07-15 08:11:51108 virtual void SendOcclusionState(
109 const aura::Window::OcclusionState occlusion_state);
Eliot Courtney99f3e9fc2019-04-03 09:07:20110
111 private:
112 Surface* surface_;
113 wl_resource* const resource_;
114
Eriko Kurimotof66bb1f2022-11-30 17:07:37115 // Tooltip text sent from Lacros.
116 // This is kept here since it should out-live ShowTooltip() scope.
117 std::u16string tooltip_text_;
118
Eliot Courtney62eec492021-07-15 08:11:51119 void ComputeAndSendOcclusion(
Eliot Courtney99f3e9fc2019-04-03 09:07:20120 const aura::Window::OcclusionState occlusion_state,
121 const SkRegion& occluded_region);
Eliot Courtney99f3e9fc2019-04-03 09:07:20122};
123
jonahwilliams9fdb3fed2021-10-13 18:24:44124// Provides an implementation for top level operations on the shell.
125class AuraToplevel {
126 public:
Mitsuru Oshima022987f2022-03-10 18:22:30127 AuraToplevel(ShellSurface* shell_surface,
128 SerialTracker* const serial_tracker,
129 wl_resource* aura_toplevel_resource,
130 wl_resource* xdg_toplevel_resource);
131
jonahwilliams9fdb3fed2021-10-13 18:24:44132 AuraToplevel(const AuraToplevel&) = delete;
133 AuraToplevel& operator=(const AuraToplevel&) = delete;
Mitsuru Oshima022987f2022-03-10 18:22:30134
135 virtual ~AuraToplevel();
jonahwilliams9fdb3fed2021-10-13 18:24:44136
137 void SetOrientationLock(uint32_t lock_type);
yjliu7d456082021-11-02 18:39:37138 void SetClientSubmitsSurfacesInPixelCoordinates(bool enable);
Mitsuru Oshima022987f2022-03-10 18:22:30139 void SetClientUsesScreenCoordinates();
140 void SetWindowBounds(int32_t x, int32_t y, int32_t width, int32_t height);
Sophie Wen55b7bcae2022-04-18 23:37:09141 void SetRestoreInfo(int32_t restore_session_id, int32_t restore_window_id);
Sophie Wen4d1dab622022-05-31 19:08:42142 void SetRestoreInfoWithWindowIdSource(
143 int32_t restore_session_id,
144 const std::string& restore_window_id_source);
Alvin Leeb981e912022-05-05 12:06:45145 void SetSystemModal(bool modal);
Sammie Quon5c0d0ac2022-08-16 02:59:00146 void SetFloat();
147 void UnsetFloat();
yjliu7d456082021-11-02 18:39:37148
Mitsuru Oshima022987f2022-03-10 18:22:30149 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 Chen8ccd9db2022-06-23 19:50:11154 void SetDecoration(SurfaceFrameType type);
Ben Beckeraa6d5af2022-08-17 22:34:51155 void SetZOrder(ui::ZOrderLevel z_order);
Erik Chen08a5e412022-09-29 22:06:48156 void Activate();
157 void Deactivate();
Fred Shih6d4d5d22022-11-14 22:28:03158 void SetFullscreenMode(uint32_t mode);
Erik Chenceeed8f2022-11-24 00:03:50159 void SetScaleFactor(float scale_factor);
Mitsuru Oshima022987f2022-03-10 18:22:30160
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};
yjliu7d456082021-11-02 18:39:37168};
169
170class 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 Chen8ccd9db2022-06-23 19:50:11178 void SetDecoration(SurfaceFrameType type);
Eriko Kurimotofc5c8e12022-07-19 05:40:35179 void SetMenu();
Erik Chenceeed8f2022-11-24 00:03:50180 void SetScaleFactor(float scale_factor);
jonahwilliams9fdb3fed2021-10-13 18:24:44181
182 private:
183 ShellSurfaceBase* shell_surface_;
184};
185
Addison Luh60d521d2022-06-02 00:37:56186class AuraOutput : public WaylandDisplayObserver {
187 public:
Mitsuru Oshimadcb9100bc2022-08-18 16:30:48188 AuraOutput(wl_resource* resource, WaylandDisplayHandler* display_handler);
Addison Luh60d521d2022-06-02 00:37:56189
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 Oshimab86c8e22022-11-16 18:43:43198 void SendActiveDisplay() override;
Mitsuru Oshimadcb9100bc2022-08-18 16:30:48199 void OnOutputDestroyed() override;
200
201 bool HasDisplayHandlerForTesting() const;
Addison Luh60d521d2022-06-02 00:37:56202
203 protected:
204 virtual void SendInsets(const gfx::Insets& insets);
Addison Luhb0a4ff622022-06-02 00:46:36205 virtual void SendLogicalTransform(int32_t transform);
Addison Luh60d521d2022-06-02 00:37:56206
207 private:
208 wl_resource* const resource_;
Mitsuru Oshimadcb9100bc2022-08-18 16:30:48209 WaylandDisplayHandler* display_handler_;
Addison Luh60d521d2022-06-02 00:37:56210};
211
Shawn Gallea787ef552018-11-27 23:29:24212} // namespace wayland
213} // namespace exo
214
Eliot Courtney99f3e9fc2019-04-03 09:07:20215#endif // COMPONENTS_EXO_WAYLAND_ZAURA_SHELL_H_