1 // Copyright (c) 2012 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_VIEWS_WIDGET_DESKTOP_AURA_DESKTOP_WINDOW_TREE_HOST_H_ 6 #define UI_VIEWS_WIDGET_DESKTOP_AURA_DESKTOP_WINDOW_TREE_HOST_H_ 7 8 #include <memory> 9 #include <string> 10 11 #include "ui/aura/window_event_dispatcher.h" 12 #include "ui/base/ui_base_types.h" 13 #include "ui/views/views_export.h" 14 #include "ui/views/widget/widget.h" 15 16 namespace aura { 17 class WindowTreeHost; 18 class Window; 19 20 namespace client { 21 class DragDropClient; 22 class ScreenPositionClient; 23 } // namespace client 24 } // namespace aura 25 26 namespace gfx { 27 class ImageSkia; 28 class Rect; 29 } // namespace gfx 30 31 namespace views { 32 namespace corewm { 33 class Tooltip; 34 } 35 36 namespace internal { 37 class NativeWidgetDelegate; 38 } 39 40 class DesktopNativeCursorManager; 41 class DesktopNativeWidgetAura; 42 43 class VIEWS_EXPORT DesktopWindowTreeHost { 44 public: 45 virtual ~DesktopWindowTreeHost() = default; 46 47 static DesktopWindowTreeHost* Create( 48 internal::NativeWidgetDelegate* native_widget_delegate, 49 DesktopNativeWidgetAura* desktop_native_widget_aura); 50 51 // Sets up resources needed before the WindowEventDispatcher has been created. 52 // It is expected this calls InitHost() on the WindowTreeHost. 53 virtual void Init(const Widget::InitParams& params) = 0; 54 55 // Invoked once the DesktopNativeWidgetAura has been created. 56 virtual void OnNativeWidgetCreated(const Widget::InitParams& params) = 0; 57 58 // Called from DesktopNativeWidgetAura::OnWidgetInitDone(). 59 virtual void OnWidgetInitDone() = 0; 60 61 // Called from DesktopNativeWidgetAura::OnWindowActivated(). 62 virtual void OnActiveWindowChanged(bool active) = 0; 63 64 // Creates and returns the Tooltip implementation to use. Return value is 65 // owned by DesktopNativeWidgetAura and lives as long as 66 // DesktopWindowTreeHost. 67 virtual std::unique_ptr<corewm::Tooltip> CreateTooltip() = 0; 68 69 // Creates and returns the DragDropClient implementation to use. Return value 70 // is owned by DesktopNativeWidgetAura and lives as long as 71 // DesktopWindowTreeHost. 72 virtual std::unique_ptr<aura::client::DragDropClient> CreateDragDropClient( 73 DesktopNativeCursorManager* cursor_manager) = 0; 74 75 // Creates the ScreenPositionClient to use for the WindowTreeHost. Default 76 // implementation creates DesktopScreenPositionClient. 77 virtual std::unique_ptr<aura::client::ScreenPositionClient> 78 CreateScreenPositionClient(); 79 80 virtual void Close() = 0; 81 virtual void CloseNow() = 0; 82 83 virtual aura::WindowTreeHost* AsWindowTreeHost() = 0; 84 85 // There are two distinct ways for DesktopWindowTreeHosts's to be shown: 86 // 1. This function is called. As this function is specific to 87 // DesktopWindowTreeHost, it is only called from DesktopNativeWidgetAura. 88 // 2. Calling Show() directly on the WindowTreeHost associated with this 89 // DesktopWindowTreeHost. This is very rare. In general, calls go through 90 // Widget, which ends up in (1). 91 // 92 // Implementations must deal with these two code paths. In general, this is 93 // done by having the WindowTreeHost subclass override ShowImpl() to call this 94 // function: Show(ui::SHOW_STATE_NORMAL, gfx::Rect()). A subtle 95 // ramification is the implementation of this function can *not* call 96 // WindowTreeHost::Show(), and the implementation of this must perform the 97 // same work as WindowTreeHost::Show(). This means setting the visibility of 98 // the compositor, window() and DesktopNativeWidgetAura::content_window() 99 // appropriately. Some subclasses set the visibility of window() in the 100 // constructor and assume it's always true. 101 virtual void Show(ui::WindowShowState show_state, 102 const gfx::Rect& restore_bounds) = 0; 103 104 virtual bool IsVisible() const = 0; 105 106 virtual void SetSize(const gfx::Size& size) = 0; 107 virtual void StackAbove(aura::Window* window) = 0; 108 virtual void StackAtTop() = 0; 109 virtual void CenterWindow(const gfx::Size& size) = 0; 110 virtual void GetWindowPlacement(gfx::Rect* bounds, 111 ui::WindowShowState* show_state) const = 0; 112 virtual gfx::Rect GetWindowBoundsInScreen() const = 0; 113 virtual gfx::Rect GetClientAreaBoundsInScreen() const = 0; 114 virtual gfx::Rect GetRestoredBounds() const = 0; 115 virtual std::string GetWorkspace() const = 0; 116 117 virtual gfx::Rect GetWorkAreaBoundsInScreen() const = 0; 118 119 // Sets the shape of the root window. If |native_shape| is nullptr then the 120 // window reverts to rectangular. 121 virtual void SetShape(std::unique_ptr<Widget::ShapeRects> native_shape) = 0; 122 123 virtual void Activate() = 0; 124 virtual void Deactivate() = 0; 125 virtual bool IsActive() const = 0; 126 virtual void Maximize() = 0; 127 virtual void Minimize() = 0; 128 virtual void Restore() = 0; 129 virtual bool IsMaximized() const = 0; 130 virtual bool IsMinimized() const = 0; 131 132 virtual bool HasCapture() const = 0; 133 134 virtual void SetZOrderLevel(ui::ZOrderLevel order) = 0; 135 virtual ui::ZOrderLevel GetZOrderLevel() const = 0; 136 137 virtual void SetVisibleOnAllWorkspaces(bool always_visible) = 0; 138 virtual bool IsVisibleOnAllWorkspaces() const = 0; 139 140 // Returns true if the title changed. 141 virtual bool SetWindowTitle(const base::string16& title) = 0; 142 143 virtual void ClearNativeFocus() = 0; 144 145 virtual Widget::MoveLoopResult RunMoveLoop( 146 const gfx::Vector2d& drag_offset, 147 Widget::MoveLoopSource source, 148 Widget::MoveLoopEscapeBehavior escape_behavior) = 0; 149 virtual void EndMoveLoop() = 0; 150 151 virtual void SetVisibilityChangedAnimationsEnabled(bool value) = 0; 152 153 virtual std::unique_ptr<NonClientFrameView> CreateNonClientFrameView() = 0; 154 155 // Determines whether the window should use native title bar and borders. 156 virtual bool ShouldUseNativeFrame() const = 0; 157 // Determines whether the window contents should be rendered transparently 158 // (for example, so that they can overhang onto the window title bar). 159 virtual bool ShouldWindowContentsBeTransparent() const = 0; 160 virtual void FrameTypeChanged() = 0; 161 162 virtual void SetFullscreen(bool fullscreen) = 0; 163 virtual bool IsFullscreen() const = 0; 164 165 virtual void SetOpacity(float opacity) = 0; 166 167 virtual void SetAspectRatio(const gfx::SizeF& aspect_ratio) = 0; 168 169 virtual void SetWindowIcons(const gfx::ImageSkia& window_icon, 170 const gfx::ImageSkia& app_icon) = 0; 171 172 virtual void InitModalType(ui::ModalType modal_type) = 0; 173 174 virtual void FlashFrame(bool flash_frame) = 0; 175 176 // Returns true if the Widget was closed but is still showing because of 177 // animations. 178 virtual bool IsAnimatingClosed() const = 0; 179 180 // Returns true if the Widget supports translucency. 181 virtual bool IsTranslucentWindowOpacitySupported() const = 0; 182 183 // Called when the window's size constraints change. 184 virtual void SizeConstraintsChanged() = 0; 185 186 // Returns true if the transparency of the DesktopNativeWidgetAura's 187 // |content_window_| should change. 188 virtual bool ShouldUpdateWindowTransparency() const = 0; 189 190 // A return value of true indicates DesktopNativeCursorManager should be 191 // used, a return value of false indicates the DesktopWindowTreeHost manages 192 // cursors itself. 193 virtual bool ShouldUseDesktopNativeCursorManager() const = 0; 194 195 // Returns whether a VisibilityController should be created. 196 virtual bool ShouldCreateVisibilityController() const = 0; 197 198 // Sets the bounds in screen coordinate DIPs (WindowTreeHost generally 199 // operates in pixels). This function is implemented in terms of Screen. 200 virtual void SetBoundsInDIP(const gfx::Rect& bounds); 201 }; 202 203 } // namespace views 204 205 #endif // UI_VIEWS_WIDGET_DESKTOP_AURA_DESKTOP_WINDOW_TREE_HOST_H_ 206