1 // Copyright 2014 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 #ifndef UI_PLATFORM_WINDOW_PLATFORM_WINDOW_H_
6 #define UI_PLATFORM_WINDOW_PLATFORM_WINDOW_H_
7
8 #include <memory>
9 #include <string>
10
11 #include "base/component_export.h"
12 #include "base/strings/string16.h"
13 #include "ui/base/class_property.h"
14 #include "ui/base/cursor/cursor.h"
15 #include "ui/base/ui_base_types.h"
16 #include "ui/gfx/native_widget_types.h"
17 #include "ui/platform_window/platform_window_delegate.h"
18
19 namespace gfx {
20 class ImageSkia;
21 class Point;
22 class Rect;
23 class SizeF;
24 class Transform;
25 } // namespace gfx
26
27 namespace ui {
28
29 // Generic PlatformWindow interface.
COMPONENT_EXPORT(PLATFORM_WINDOW)30 class COMPONENT_EXPORT(PLATFORM_WINDOW) PlatformWindow
31 : public PropertyHandler {
32 public:
33 PlatformWindow();
34 ~PlatformWindow() override;
35
36 // PlatformWindow may be called with the |inactive| set to true in some cases.
37 // That means that the Window Manager must not activate the window when it is
38 // shown. Most of PlatformWindow may ignore this value if not supported.
39 virtual void Show(bool inactive = false) = 0;
40 virtual void Hide() = 0;
41 virtual void Close() = 0;
42
43 virtual bool IsVisible() const = 0;
44
45 // Informs the window it is going to be destroyed sometime soon. This is only
46 // called for specific code paths, for example by Ash, so it shouldn't be
47 // assumed this will get called before destruction.
48 virtual void PrepareForShutdown() = 0;
49
50 // Sets and gets the bounds of the platform-window. Note that the bounds is in
51 // physical pixel coordinates.
52 virtual void SetBounds(const gfx::Rect& bounds) = 0;
53 virtual gfx::Rect GetBounds() const = 0;
54
55 virtual void SetTitle(const base::string16& title) = 0;
56
57 virtual void SetCapture() = 0;
58 virtual void ReleaseCapture() = 0;
59 virtual bool HasCapture() const = 0;
60
61 virtual void ToggleFullscreen() = 0;
62 virtual void Maximize() = 0;
63 virtual void Minimize() = 0;
64 virtual void Restore() = 0;
65 virtual PlatformWindowState GetPlatformWindowState() const = 0;
66
67 virtual void Activate() = 0;
68 virtual void Deactivate() = 0;
69
70 // Sets whether the window should have the standard title bar provided by the
71 // underlying windowing system. For the main browser window, this may be
72 // changed by the user at any time via 'Show system title bar' option in the
73 // tab strip menu.
74 virtual void SetUseNativeFrame(bool use_native_frame) = 0;
75 virtual bool ShouldUseNativeFrame() const = 0;
76
77 virtual void SetCursor(PlatformCursor cursor) = 0;
78
79 // Moves the cursor to |location|. Location is in platform window coordinates.
80 virtual void MoveCursorTo(const gfx::Point& location) = 0;
81
82 // Confines the cursor to |bounds| when it is in the platform window. |bounds|
83 // is in platform window coordinates.
84 virtual void ConfineCursorToBounds(const gfx::Rect& bounds) = 0;
85
86 // Sets and gets the restored bounds of the platform-window.
87 virtual void SetRestoredBoundsInPixels(const gfx::Rect& bounds) = 0;
88 virtual gfx::Rect GetRestoredBoundsInPixels() const = 0;
89
90 // Sets the Window icons. |window_icon| is a 16x16 icon suitable for use in
91 // a title bar. |app_icon| is a larger size for use in the host environment
92 // app switching UI.
93 virtual void SetWindowIcons(const gfx::ImageSkia& window_icon,
94 const gfx::ImageSkia& app_icon) = 0;
95
96 // Notifies that size constraints of the host have been changed and the
97 // PlatformWindow must react on them accordingly.
98 virtual void SizeConstraintsChanged() = 0;
99
100 // Tells if the content of the platform window should be transparent. By
101 // default returns false.
102 virtual bool ShouldWindowContentsBeTransparent() const;
103
104 // Sets and gets ZOrderLevel of the PlatformWindow. Such platforms that do not
105 // support ordering, should not implement these methods as the default
106 // implementation always returns ZOrderLevel::kNormal value.
107 virtual void SetZOrderLevel(ZOrderLevel order);
108 virtual ZOrderLevel GetZOrderLevel() const;
109
110 // Asks the PlatformWindow to stack itself on top of |widget|.
111 virtual void StackAbove(gfx::AcceleratedWidget widget);
112 virtual void StackAtTop();
113
114 // Flashes the frame of the window to draw attention to it. If |flash_frame|
115 // is set, the PlatformWindow must draw attention to it. If |flash_frame| is
116 // not set, flashing must be stopped.
117 virtual void FlashFrame(bool flash_frame);
118
119 using ShapeRects = std::vector<gfx::Rect>;
120 // Sets shape of the PlatformWindow. ShapeRects corresponds to the
121 // Widget::ShapeRects that is a vector of gfx::Rects that describe the shape.
122 virtual void SetShape(std::unique_ptr<ShapeRects> native_shape,
123 const gfx::Transform& transform);
124
125 // Sets the aspect ratio of the Platform Window, which will be
126 // maintained during interactive resizing. This size disregards title bar and
127 // borders. Once set, some platforms ensure the content will only size to
128 // integer multiples of |aspect_ratio|.
129 virtual void SetAspectRatio(const gfx::SizeF& aspect_ratio);
130
131 // Returns true if the window was closed but is still showing because of
132 // animations.
133 virtual bool IsAnimatingClosed() const;
134
135 // Returns true if the window supports translucency.
136 virtual bool IsTranslucentWindowOpacitySupported() const;
137
138 // Sets opacity of the platform window.
139 virtual void SetOpacity(float opacity);
140
141 // Enables or disables platform provided animations of the PlatformWindow.
142 // If |enabled| is set to false, animations are disabled.
143 virtual void SetVisibilityChangedAnimationsEnabled(bool enabled);
144
145 // Returns a unique ID for the window. The interpretation of the ID is
146 // platform specific. Overriding this method is optional.
147 virtual std::string GetWindowUniqueId() const;
148 };
149
150 } // namespace ui
151
152 #endif // UI_PLATFORM_WINDOW_PLATFORM_WINDOW_H_
153