[M120 Migration][VD] Fix some focus issues for offscreen mode
[platform/framework/web/chromium-efl.git] / ui / platform_window / platform_window.h
1 // Copyright 2014 The Chromium Authors
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 UI_PLATFORM_WINDOW_PLATFORM_WINDOW_H_
6 #define UI_PLATFORM_WINDOW_PLATFORM_WINDOW_H_
7
8 #include <memory>
9 #include <string>
10 #include <vector>
11
12 #include "base/component_export.h"
13 #include "ui/base/class_property.h"
14 #include "ui/base/ui_base_types.h"
15 #include "ui/gfx/native_widget_types.h"
16 #include "ui/platform_window/platform_window_delegate.h"
17
18 #if BUILDFLAG(IS_EFL)
19 #include <Evas.h>
20 #endif
21
22 template <class T>
23 class scoped_refptr;
24
25 namespace gfx {
26 class ImageSkia;
27 class Insets;
28 class Point;
29 class Rect;
30 class SizeF;
31 class Transform;
32 }  // namespace gfx
33
34 namespace ui {
35 class PlatformCursor;
36
37 #if BUILDFLAG(IS_EFL)
38 class EflEventHandler;
39 #endif
40
41 // Generic PlatformWindow interface.
42 class COMPONENT_EXPORT(PLATFORM_WINDOW) PlatformWindow
43     : public PropertyHandler {
44  public:
45   PlatformWindow();
46   ~PlatformWindow() override;
47
48   // PlatformWindow may be called with the |inactive| set to true in some cases.
49   // That means that the Window Manager must not activate the window when it is
50   // shown.  Most of PlatformWindow may ignore this value if not supported.
51   virtual void Show(bool inactive = false) = 0;
52   virtual void Hide() = 0;
53   virtual void Close() = 0;
54
55   virtual bool IsVisible() const = 0;
56
57   // Informs the window it is going to be destroyed sometime soon. This is only
58   // called for specific code paths, for example by Ash, so it shouldn't be
59   // assumed this will get called before destruction.
60   virtual void PrepareForShutdown() = 0;
61
62   // Sets and gets the bounds of the platform-window. Note that the bounds is in
63   // physical pixel coordinates. The implementation should use
64   // `PlatformWindowDelegate::ConvertRectToPixels|DIP` if conversion is
65   // necessary.
66   virtual void SetBoundsInPixels(const gfx::Rect& bounds) = 0;
67   virtual gfx::Rect GetBoundsInPixels() const = 0;
68
69   // Sets and gets the bounds of the platform-window. Note that the bounds is in
70   // device-independent-pixel (dip) coordinates. The implementation should use
71   // `PlatformWindowDelegate::ConvertRectToPixels|DIP` if conversion is
72   // necessary.
73   virtual void SetBoundsInDIP(const gfx::Rect& bounds) = 0;
74   virtual gfx::Rect GetBoundsInDIP() const = 0;
75
76   virtual void SetTitle(const std::u16string& title) = 0;
77
78   virtual void SetCapture() = 0;
79   virtual void ReleaseCapture() = 0;
80   virtual bool HasCapture() const = 0;
81
82   // Enters or exits fullscreen when `fullscreen` is true or false respectively.
83   // This operation may have no effect if the window is already in the specified
84   // state. `target_display_id` indicates the display where the window should be
85   // shown fullscreen when entering into fullscreen; display::kInvalidDisplayId
86   // indicates that no display was specified, so the current display may be
87   // used.
88   virtual void SetFullscreen(bool fullscreen, int64_t target_display_id) = 0;
89   virtual void Maximize() = 0;
90   virtual void Minimize() = 0;
91   virtual void Restore() = 0;
92   virtual PlatformWindowState GetPlatformWindowState() const = 0;
93
94   virtual void Activate() = 0;
95   virtual void Deactivate() = 0;
96
97   // Sets whether the window should have the standard title bar provided by the
98   // underlying windowing system.  For the main browser window, this may be
99   // changed by the user at any time via 'Show system title bar' option in the
100   // tab strip menu.
101   virtual void SetUseNativeFrame(bool use_native_frame) = 0;
102   virtual bool ShouldUseNativeFrame() const = 0;
103
104   // This method sets the current cursor to `cursor`. Note that the platform
105   // window should keep a copy of `cursor` and also avoid replacing it until the
106   // new value has been set if any kind of platform-specific resources are
107   // managed by the platform cursor, e.g. HCURSOR on Windows, which are
108   // destroyed once the last copy of the platform cursor goes out of scope.
109   virtual void SetCursor(scoped_refptr<PlatformCursor> cursor) = 0;
110
111   // Moves the cursor to |location|. Location is in platform window coordinates.
112   virtual void MoveCursorTo(const gfx::Point& location) = 0;
113
114   // Confines the cursor to |bounds| when it is in the platform window. |bounds|
115   // is in platform window coordinates.
116   virtual void ConfineCursorToBounds(const gfx::Rect& bounds) = 0;
117
118   // Sets and gets the restored bounds of the platform-window.
119   virtual void SetRestoredBoundsInDIP(const gfx::Rect& bounds) = 0;
120   virtual gfx::Rect GetRestoredBoundsInDIP() const = 0;
121
122   // Sets the Window icons. |window_icon| is a 16x16 icon suitable for use in
123   // a title bar. |app_icon| is a larger size for use in the host environment
124   // app switching UI.
125   virtual void SetWindowIcons(const gfx::ImageSkia& window_icon,
126                               const gfx::ImageSkia& app_icon) = 0;
127
128   // Notifies that size constraints of the host have been changed and the
129   // PlatformWindow must react on them accordingly.
130   virtual void SizeConstraintsChanged() = 0;
131
132   // Tells if the content of the platform window should be transparent. By
133   // default returns false.
134   virtual bool ShouldWindowContentsBeTransparent() const;
135
136   // Sets and gets ZOrderLevel of the PlatformWindow. Such platforms that do not
137   // support ordering, should not implement these methods as the default
138   // implementation always returns ZOrderLevel::kNormal value.
139   virtual void SetZOrderLevel(ZOrderLevel order);
140   virtual ZOrderLevel GetZOrderLevel() const;
141
142   // Asks the PlatformWindow to stack itself on top of |widget|.
143   virtual void StackAbove(gfx::AcceleratedWidget widget);
144   virtual void StackAtTop();
145
146   // Flashes the frame of the window to draw attention to it. If |flash_frame|
147   // is set, the PlatformWindow must draw attention to it. If |flash_frame| is
148   // not set, flashing must be stopped.
149   virtual void FlashFrame(bool flash_frame);
150
151   using ShapeRects = std::vector<gfx::Rect>;
152   // Sets shape of the PlatformWindow. ShapeRects corresponds to the
153   // Widget::ShapeRects that is a vector of gfx::Rects that describe the shape.
154   virtual void SetShape(std::unique_ptr<ShapeRects> native_shape,
155                         const gfx::Transform& transform);
156
157   // Sets the aspect ratio of the Platform Window, which will be
158   // maintained during interactive resizing. This size disregards title bar and
159   // borders. Once set, some platforms ensure the content will only size to
160   // integer multiples of |aspect_ratio|.
161   virtual void SetAspectRatio(const gfx::SizeF& aspect_ratio);
162
163   // Returns true if the window was closed but is still showing because of
164   // animations.
165   virtual bool IsAnimatingClosed() const;
166
167   // Returns true if the window supports translucency.
168   virtual bool IsTranslucentWindowOpacitySupported() const;
169
170   // Sets opacity of the platform window.
171   virtual void SetOpacity(float opacity);
172
173   // Enables or disables platform provided animations of the PlatformWindow.
174   // If |enabled| is set to false, animations are disabled.
175   virtual void SetVisibilityChangedAnimationsEnabled(bool enabled);
176
177   // Returns a unique ID for the window. The interpretation of the ID is
178   // platform specific. Overriding this method is optional.
179   virtual std::string GetWindowUniqueId() const;
180
181   // Returns true if window shape should be updated in host,
182   // otherwise false when platform window or specific frame views updates the
183   // window shape.
184   virtual bool ShouldUpdateWindowShape() const;
185
186   // Returns true if the WM supports setting the frame extents for client side
187   // decorations.  This typically requires a compositor and an extension for
188   // specifying the decoration insets.
189   virtual bool CanSetDecorationInsets() const;
190
191   // Lets the WM know which portion of the window is the frame decoration.  The
192   // WM may use this to eg. snap windows to each other starting where the window
193   // begins rather than starting where the shadow begins.  If |insets_px| is
194   // nullptr, then any existing insets will be reset.
195   virtual void SetDecorationInsets(const gfx::Insets* insets_px);
196
197   // Sets a hint for the compositor so it can avoid unnecessarily redrawing
198   // occluded portions of windows.  If |region_px| is nullopt or empty, then any
199   // existing region will be reset.
200   virtual void SetOpaqueRegion(
201       absl::optional<std::vector<gfx::Rect>> region_px);
202
203   // Sets the clickable region of a window.  This is useful for trimming down a
204   // potentially large (24px) hit area for window resizing on the window shadow
205   // to a more reasonable (10px) area.  If |region_px| is nullopt, then any
206   // existing region will be reset.
207   virtual void SetInputRegion(absl::optional<gfx::Rect> region_px);
208
209   // Whether the platform supports client-controlled window movement. Under
210   // Wayland, for example, this returns false, unless the required protocol
211   // extension is supported by the compositor.
212   virtual bool IsClientControlledWindowMovementSupported() const;
213
214   // Notifies the DE that the app is done loading, so that it can dismiss any
215   // loading animations.
216   virtual void NotifyStartupComplete(const std::string& startup_id);
217
218   // Shows tooltip with this platform window as a parent window.
219   // `position` is relative to this platform window.
220   // `show_delay` and `hide_delay` specify the delay before showing or hiding
221   // tooltip on server side. `show_delay` may be set to zero only for testing.
222   // If `hide_delay` is zero, the tooltip will not be hidden by timer on server
223   // side.
224   virtual void ShowTooltip(const std::u16string& text,
225                            const gfx::Point& position,
226                            const PlatformWindowTooltipTrigger trigger,
227                            const base::TimeDelta show_delay,
228                            const base::TimeDelta hide_delay) {}
229
230   // Hides tooltip.
231   virtual void HideTooltip() {}
232
233 #if BUILDFLAG(IS_EFL)
234   // Sets view created in RWHVAura as events overlay for offscreen rendering.
235   virtual void SetEventsOverlayForOffscreen(Evas_Object* events_overlay) {}
236   virtual void UpdateFocus(bool focused) {}
237
238   virtual EflEventHandler* GetEventHandler() { return nullptr; }
239 #endif
240 };
241
242 }  // namespace ui
243
244 #endif  // UI_PLATFORM_WINDOW_PLATFORM_WINDOW_H_