1 // Copyright 2018 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_PLATFORM_H_ 6 #define UI_VIEWS_WIDGET_DESKTOP_AURA_DESKTOP_WINDOW_TREE_HOST_PLATFORM_H_ 7 8 #include <memory> 9 #include <set> 10 #include <string> 11 #include <vector> 12 13 #include "base/memory/weak_ptr.h" 14 #include "build/build_config.h" 15 #include "ui/aura/window_tree_host_platform.h" 16 #include "ui/platform_window/extensions/workspace_extension_delegate.h" 17 #include "ui/views/views_export.h" 18 #include "ui/views/widget/desktop_aura/desktop_window_tree_host.h" 19 #include "ui/views/widget/desktop_aura/window_move_client_platform.h" 20 21 namespace views { 22 23 class VIEWS_EXPORT DesktopWindowTreeHostPlatform 24 : public aura::WindowTreeHostPlatform, 25 public DesktopWindowTreeHost, 26 public ui::WorkspaceExtensionDelegate { 27 public: 28 DesktopWindowTreeHostPlatform( 29 internal::NativeWidgetDelegate* native_widget_delegate, 30 DesktopNativeWidgetAura* desktop_native_widget_aura); 31 ~DesktopWindowTreeHostPlatform() override; 32 33 // A way of converting a |widget| into the content_window() 34 // of the associated DesktopNativeWidgetAura. 35 static aura::Window* GetContentWindowForWidget(gfx::AcceleratedWidget widget); 36 37 // A way of converting a |widget| into this object. 38 static DesktopWindowTreeHostPlatform* GetHostForWidget( 39 gfx::AcceleratedWidget widget); 40 41 // Accessor for DesktopNativeWidgetAura::content_window(). 42 aura::Window* GetContentWindow(); 43 const aura::Window* GetContentWindow() const; 44 45 // DesktopWindowTreeHost: 46 void Init(const Widget::InitParams& params) override; 47 void OnNativeWidgetCreated(const Widget::InitParams& params) override; 48 void OnWidgetInitDone() override; 49 void OnActiveWindowChanged(bool active) override; 50 std::unique_ptr<corewm::Tooltip> CreateTooltip() override; 51 std::unique_ptr<aura::client::DragDropClient> CreateDragDropClient( 52 DesktopNativeCursorManager* cursor_manager) override; 53 void Close() override; 54 void CloseNow() override; 55 aura::WindowTreeHost* AsWindowTreeHost() override; 56 void Show(ui::WindowShowState show_state, 57 const gfx::Rect& restore_bounds) override; 58 bool IsVisible() const override; 59 void SetSize(const gfx::Size& size) override; 60 void StackAbove(aura::Window* window) override; 61 void StackAtTop() override; 62 void CenterWindow(const gfx::Size& size) override; 63 void GetWindowPlacement(gfx::Rect* bounds, 64 ui::WindowShowState* show_state) const override; 65 gfx::Rect GetWindowBoundsInScreen() const override; 66 gfx::Rect GetClientAreaBoundsInScreen() const override; 67 gfx::Rect GetRestoredBounds() const override; 68 std::string GetWorkspace() const override; 69 gfx::Rect GetWorkAreaBoundsInScreen() const override; 70 void SetShape(std::unique_ptr<Widget::ShapeRects> native_shape) override; 71 void Activate() override; 72 void Deactivate() override; 73 bool IsActive() const override; 74 void Maximize() override; 75 void Minimize() override; 76 void Restore() override; 77 bool IsMaximized() const override; 78 bool IsMinimized() const override; 79 bool HasCapture() const override; 80 void SetZOrderLevel(ui::ZOrderLevel order) override; 81 ui::ZOrderLevel GetZOrderLevel() const override; 82 void SetVisibleOnAllWorkspaces(bool always_visible) override; 83 bool IsVisibleOnAllWorkspaces() const override; 84 bool SetWindowTitle(const base::string16& title) override; 85 void ClearNativeFocus() override; 86 Widget::MoveLoopResult RunMoveLoop( 87 const gfx::Vector2d& drag_offset, 88 Widget::MoveLoopSource source, 89 Widget::MoveLoopEscapeBehavior escape_behavior) override; 90 void EndMoveLoop() override; 91 void SetVisibilityChangedAnimationsEnabled(bool value) override; 92 std::unique_ptr<NonClientFrameView> CreateNonClientFrameView() override; 93 bool ShouldUseNativeFrame() const override; 94 bool ShouldWindowContentsBeTransparent() const override; 95 void FrameTypeChanged() override; 96 void SetFullscreen(bool fullscreen) override; 97 bool IsFullscreen() const override; 98 void SetOpacity(float opacity) override; 99 void SetAspectRatio(const gfx::SizeF& aspect_ratio) override; 100 void SetWindowIcons(const gfx::ImageSkia& window_icon, 101 const gfx::ImageSkia& app_icon) override; 102 void InitModalType(ui::ModalType modal_type) override; 103 void FlashFrame(bool flash_frame) override; 104 bool IsAnimatingClosed() const override; 105 bool IsTranslucentWindowOpacitySupported() const override; 106 void SizeConstraintsChanged() override; 107 bool ShouldUpdateWindowTransparency() const override; 108 bool ShouldUseDesktopNativeCursorManager() const override; 109 bool ShouldCreateVisibilityController() const override; 110 111 // WindowTreeHost: 112 gfx::Transform GetRootTransform() const override; 113 void ShowImpl() override; 114 void HideImpl() override; 115 116 // PlatformWindowDelegate: 117 void OnClosed() override; 118 void OnWindowStateChanged(ui::PlatformWindowState new_state) override; 119 void OnCloseRequest() override; 120 void OnWillDestroyAcceleratedWidget() override; 121 void OnActivationChanged(bool active) override; 122 base::Optional<gfx::Size> GetMinimumSizeForWindow() override; 123 base::Optional<gfx::Size> GetMaximumSizeForWindow() override; 124 125 // ui::WorkspaceExtensionDelegate: 126 void OnWorkspaceChanged() override; 127 128 protected: 129 // TODO(https://crbug.com/990756): move these methods back to private 130 // once DWTHX11 stops using them. native_widget_delegate()131 internal::NativeWidgetDelegate* native_widget_delegate() { 132 return native_widget_delegate_; 133 } desktop_native_widget_aura()134 DesktopNativeWidgetAura* desktop_native_widget_aura() { 135 return desktop_native_widget_aura_; 136 } 137 138 // These are not general purpose methods and must be used with care. Please 139 // make sure you understand the rounding direction before using. 140 gfx::Rect ToDIPRect(const gfx::Rect& rect_in_pixels) const; 141 gfx::Rect ToPixelRect(const gfx::Rect& rect_in_dip) const; 142 143 private: 144 void ScheduleRelayout(); 145 146 Widget* GetWidget(); 147 const Widget* GetWidget() const; 148 149 // Set visibility and fire OnNativeWidgetVisibilityChanged() if it changed. 150 void SetVisible(bool visible); 151 152 // There are platform specific properties that Linux may want to add. 153 virtual void AddAdditionalInitProperties( 154 const Widget::InitParams& params, 155 ui::PlatformWindowInitProperties* properties); 156 157 internal::NativeWidgetDelegate* const native_widget_delegate_; 158 DesktopNativeWidgetAura* const desktop_native_widget_aura_; 159 160 bool is_active_ = false; 161 162 base::string16 window_title_; 163 164 // We can optionally have a parent which can order us to close, or own 165 // children who we're responsible for closing when we CloseNow(). 166 DesktopWindowTreeHostPlatform* window_parent_ = nullptr; 167 std::set<DesktopWindowTreeHostPlatform*> window_children_; 168 169 // Keep track of PlatformWindow state so that we would react correctly and set 170 // visibility only if the window was minimized or was unminimized from the 171 // normal state. 172 ui::PlatformWindowState old_state_ = ui::PlatformWindowState::kUnknown; 173 174 // Used for tab dragging in move loop requests. 175 WindowMoveClientPlatform window_move_client_; 176 177 base::WeakPtrFactory<DesktopWindowTreeHostPlatform> close_widget_factory_{ 178 this}; 179 180 DISALLOW_COPY_AND_ASSIGN(DesktopWindowTreeHostPlatform); 181 }; 182 183 } // namespace views 184 185 #endif // UI_VIEWS_WIDGET_DESKTOP_AURA_DESKTOP_WINDOW_TREE_HOST_PLATFORM_H_ 186