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.
5 #ifndef UI_VIEWS_WIDGET_DESKTOP_AURA_DESKTOP_WINDOW_TREE_HOST_WIN_H_
6 #define UI_VIEWS_WIDGET_DESKTOP_AURA_DESKTOP_WINDOW_TREE_HOST_WIN_H_
8 #include "ui/aura/window_tree_host.h"
9 #include "ui/views/views_export.h"
10 #include "ui/views/widget/desktop_aura/desktop_window_tree_host.h"
11 #include "ui/views/win/hwnd_message_handler_delegate.h"
12 #include "ui/wm/public/animation_host.h"
18 class ScopedTooltipDisabler
;
23 class DesktopCursorClient
;
24 class DesktopDragDropClientWin
;
25 class HWNDMessageHandler
;
31 class VIEWS_EXPORT DesktopWindowTreeHostWin
32 : public DesktopWindowTreeHost
,
33 public aura::client::AnimationHost
,
34 public aura::WindowTreeHost
,
35 public HWNDMessageHandlerDelegate
{
37 DesktopWindowTreeHostWin(
38 internal::NativeWidgetDelegate
* native_widget_delegate
,
39 DesktopNativeWidgetAura
* desktop_native_widget_aura
);
40 ~DesktopWindowTreeHostWin() override
;
42 // A way of converting an HWND into a content window.
43 static aura::Window
* GetContentWindowForHWND(HWND hwnd
);
46 // Overridden from DesktopWindowTreeHost:
47 void Init(aura::Window
* content_window
,
48 const Widget::InitParams
& params
) override
;
49 void OnNativeWidgetCreated(const Widget::InitParams
& params
) override
;
50 scoped_ptr
<corewm::Tooltip
> CreateTooltip() override
;
51 scoped_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 ShowWindowWithState(ui::WindowShowState show_state
) override
;
57 void ShowMaximizedWithBounds(const gfx::Rect
& restored_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 gfx::Rect
GetWorkAreaBoundsInScreen() const override
;
69 void SetShape(SkRegion
* native_region
) override
;
70 void Activate() override
;
71 void Deactivate() override
;
72 bool IsActive() const override
;
73 void Maximize() override
;
74 void Minimize() override
;
75 void Restore() override
;
76 bool IsMaximized() const override
;
77 bool IsMinimized() const override
;
78 bool HasCapture() const override
;
79 void SetAlwaysOnTop(bool always_on_top
) override
;
80 bool IsAlwaysOnTop() const override
;
81 void SetVisibleOnAllWorkspaces(bool always_visible
) override
;
82 bool SetWindowTitle(const base::string16
& title
) override
;
83 void ClearNativeFocus() override
;
84 Widget::MoveLoopResult
RunMoveLoop(
85 const gfx::Vector2d
& drag_offset
,
86 Widget::MoveLoopSource source
,
87 Widget::MoveLoopEscapeBehavior escape_behavior
) override
;
88 void EndMoveLoop() override
;
89 void SetVisibilityChangedAnimationsEnabled(bool value
) override
;
90 bool ShouldUseNativeFrame() const override
;
91 bool ShouldWindowContentsBeTransparent() const override
;
92 void FrameTypeChanged() override
;
93 void SetFullscreen(bool fullscreen
) override
;
94 bool IsFullscreen() const override
;
95 void SetOpacity(unsigned char opacity
) override
;
96 void SetWindowIcons(const gfx::ImageSkia
& window_icon
,
97 const gfx::ImageSkia
& app_icon
) override
;
98 void InitModalType(ui::ModalType modal_type
) override
;
99 void FlashFrame(bool flash_frame
) override
;
100 void OnRootViewLayout() override
;
101 void OnNativeWidgetFocus() override
;
102 void OnNativeWidgetBlur() override
;
103 bool IsAnimatingClosed() const override
;
104 bool IsTranslucentWindowOpacitySupported() const override
;
105 void SizeConstraintsChanged() override
;
107 // Overridden from aura::WindowTreeHost:
108 ui::EventSource
* GetEventSource() override
;
109 gfx::AcceleratedWidget
GetAcceleratedWidget() override
;
110 void ShowImpl() override
;
111 void HideImpl() override
;
112 gfx::Rect
GetBounds() const override
;
113 void SetBounds(const gfx::Rect
& bounds
) override
;
114 gfx::Point
GetLocationOnNativeScreen() const override
;
115 void SetCapture() override
;
116 void ReleaseCapture() override
;
117 void SetCursorNative(gfx::NativeCursor cursor
) override
;
118 void OnCursorVisibilityChangedNative(bool show
) override
;
119 void MoveCursorToNative(const gfx::Point
& location
) override
;
121 // Overridden from aura::client::AnimationHost
122 void SetHostTransitionOffsets(
123 const gfx::Vector2d
& top_left_delta
,
124 const gfx::Vector2d
& bottom_right_delta
) override
;
125 void OnWindowHidingAnimationCompleted() override
;
127 // Overridden from HWNDMessageHandlerDelegate:
128 bool IsWidgetWindow() const override
;
129 bool IsUsingCustomFrame() const override
;
130 void SchedulePaint() override
;
131 void EnableInactiveRendering() override
;
132 bool IsInactiveRenderingDisabled() override
;
133 bool CanResize() const override
;
134 bool CanMaximize() const override
;
135 bool CanMinimize() const override
;
136 bool CanActivate() const override
;
137 bool WidgetSizeIsClientSize() const override
;
138 bool IsModal() const override
;
139 int GetInitialShowState() const override
;
140 bool WillProcessWorkAreaChange() const override
;
141 int GetNonClientComponent(const gfx::Point
& point
) const override
;
142 void GetWindowMask(const gfx::Size
& size
, gfx::Path
* path
) override
;
143 bool GetClientAreaInsets(gfx::Insets
* insets
) const override
;
144 void GetMinMaxSize(gfx::Size
* min_size
, gfx::Size
* max_size
) const override
;
145 gfx::Size
GetRootViewSize() const override
;
146 void ResetWindowControls() override
;
147 gfx::NativeViewAccessible
GetNativeViewAccessible() override
;
148 bool ShouldHandleSystemCommands() const override
;
149 void HandleAppDeactivated() override
;
150 void HandleActivationChanged(bool active
) override
;
151 bool HandleAppCommand(short command
) override
;
152 void HandleCancelMode() override
;
153 void HandleCaptureLost() override
;
154 void HandleClose() override
;
155 bool HandleCommand(int command
) override
;
156 void HandleAccelerator(const ui::Accelerator
& accelerator
) override
;
157 void HandleCreate() override
;
158 void HandleDestroying() override
;
159 void HandleDestroyed() override
;
160 bool HandleInitialFocus(ui::WindowShowState show_state
) override
;
161 void HandleDisplayChange() override
;
162 void HandleBeginWMSizeMove() override
;
163 void HandleEndWMSizeMove() override
;
164 void HandleMove() override
;
165 void HandleWorkAreaChanged() override
;
166 void HandleVisibilityChanging(bool visible
) override
;
167 void HandleVisibilityChanged(bool visible
) override
;
168 void HandleClientSizeChanged(const gfx::Size
& new_size
) override
;
169 void HandleFrameChanged() override
;
170 void HandleNativeFocus(HWND last_focused_window
) override
;
171 void HandleNativeBlur(HWND focused_window
) override
;
172 bool HandleMouseEvent(const ui::MouseEvent
& event
) override
;
173 void HandleKeyEvent(ui::KeyEvent
* event
) override
;
174 void HandleTouchEvent(const ui::TouchEvent
& event
) override
;
175 bool HandleIMEMessage(UINT message
,
178 LRESULT
* result
) override
;
179 void HandleInputLanguageChange(DWORD character_set
,
180 HKL input_language_id
) override
;
181 void HandlePaintAccelerated(const gfx::Rect
& invalid_rect
) override
;
182 bool HandleTooltipNotify(int w_param
,
184 LRESULT
* l_result
) override
;
185 void HandleMenuLoop(bool in_menu_loop
) override
;
186 bool PreHandleMSG(UINT message
,
189 LRESULT
* result
) override
;
190 void PostHandleMSG(UINT message
, WPARAM w_param
, LPARAM l_param
) override
;
191 bool HandleScrollEvent(const ui::ScrollEvent
& event
) override
;
192 void HandleWindowSizeChanging() override
;
195 const Widget
* GetWidget() const;
196 HWND
GetHWND() const;
199 void SetWindowTransparency();
201 // Returns true if a modal window is active in the current root window chain.
202 bool IsModalWindowActive() const;
204 scoped_ptr
<HWNDMessageHandler
> message_handler_
;
205 scoped_ptr
<aura::client::FocusClient
> focus_client_
;
207 // TODO(beng): Consider providing an interface to DesktopNativeWidgetAura
208 // instead of providing this route back to Widget.
209 internal::NativeWidgetDelegate
* native_widget_delegate_
;
211 DesktopNativeWidgetAura
* desktop_native_widget_aura_
;
213 aura::Window
* content_window_
;
215 // Owned by DesktopNativeWidgetAura.
216 DesktopDragDropClientWin
* drag_drop_client_
;
218 // When certain windows are being shown, we augment the window size
219 // temporarily for animation. The following two members contain the top left
220 // and bottom right offsets which are used to enlarge the window.
221 gfx::Vector2d window_expansion_top_left_delta_
;
222 gfx::Vector2d window_expansion_bottom_right_delta_
;
224 // Windows are enlarged to be at least 64x64 pixels, so keep track of the
226 gfx::Vector2d window_enlargement_
;
228 // Whether the window close should be converted to a hide, and then actually
229 // closed on the completion of the hide animation. This is cached because
230 // the property is set on the contained window which has a shorter lifetime.
231 bool should_animate_window_close_
;
233 // When Close()d and animations are being applied to this window, the close
234 // of the window needs to be deferred to when the close animation is
235 // completed. This variable indicates that a Close was converted to a Hide,
236 // so that when the Hide is completed the host window should be closed.
239 // True if the widget is going to have a non_client_view. We cache this value
240 // rather than asking the Widget for the non_client_view so that we know at
241 // Init time, before the Widget has created the NonClientView.
242 bool has_non_client_view_
;
244 // Owned by TooltipController, but we need to forward events to it so we keep
246 corewm::TooltipWin
* tooltip_
;
248 // Visibility of the cursor. On Windows we can have multiple root windows and
249 // the implementation of ::ShowCursor() is based on a counter, so making this
250 // member static ensures that ::ShowCursor() is always called exactly once
251 // whenever the cursor visibility state changes.
252 static bool is_cursor_visible_
;
254 scoped_ptr
<aura::client::ScopedTooltipDisabler
> tooltip_disabler_
;
256 DISALLOW_COPY_AND_ASSIGN(DesktopWindowTreeHostWin
);
261 #endif // UI_VIEWS_WIDGET_DESKTOP_AURA_DESKTOP_WINDOW_TREE_HOST_WIN_H_