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_NATIVE_WIDGET_WIN_H_
6 #define UI_VIEWS_WIDGET_NATIVE_WIDGET_WIN_H_
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/scoped_vector.h"
12 #include "base/win/scoped_comptr.h"
13 #include "base/win/win_util.h"
14 #include "ui/gfx/win/window_impl.h"
15 #include "ui/views/widget/native_widget_private.h"
16 #include "ui/views/win/hwnd_message_handler_delegate.h"
32 class HWNDMessageHandler
;
33 class InputMethodDelegate
;
35 class TooltipManagerWin
;
37 ///////////////////////////////////////////////////////////////////////////////
40 // A Widget for a views hierarchy used to represent anything that can be
41 // contained within an HWND, e.g. a control, a window, etc. Specializations
42 // suitable for specific tasks, e.g. top level window, are derived from this.
44 // This Widget contains a RootView which owns the hierarchy of views within it.
45 // As long as views are part of this tree, they will be deleted automatically
46 // when the RootView is destroyed. If you remove a view from the tree, you are
47 // then responsible for cleaning up after it.
49 ///////////////////////////////////////////////////////////////////////////////
50 class VIEWS_EXPORT NativeWidgetWin
: public internal::NativeWidgetPrivate
,
51 public HWNDMessageHandlerDelegate
{
53 explicit NativeWidgetWin(internal::NativeWidgetDelegate
* delegate
);
54 virtual ~NativeWidgetWin();
56 // Returns the system set window title font.
57 static gfx::Font
GetWindowTitleFont();
59 // Show the window with the specified show command.
60 void Show(int show_state
);
62 // Places the window in a pseudo-fullscreen mode where it looks and acts as
63 // like a fullscreen window except that it remains within the boundaries
64 // of the metro snap divider.
65 void SetMetroSnapFullscreen(bool metro_snap
);
66 bool IsInMetroSnapMode() const;
68 void SetCanUpdateLayeredWindow(bool can_update
);
70 // Overridden from internal::NativeWidgetPrivate:
71 virtual void InitNativeWidget(const Widget::InitParams
& params
) OVERRIDE
;
72 virtual NonClientFrameView
* CreateNonClientFrameView() OVERRIDE
;
73 virtual bool ShouldUseNativeFrame() const OVERRIDE
;
74 virtual void FrameTypeChanged() OVERRIDE
;
75 virtual Widget
* GetWidget() OVERRIDE
;
76 virtual const Widget
* GetWidget() const OVERRIDE
;
77 virtual gfx::NativeView
GetNativeView() const OVERRIDE
;
78 virtual gfx::NativeWindow
GetNativeWindow() const OVERRIDE
;
79 virtual Widget
* GetTopLevelWidget() OVERRIDE
;
80 virtual const ui::Compositor
* GetCompositor() const OVERRIDE
;
81 virtual ui::Compositor
* GetCompositor() OVERRIDE
;
82 virtual ui::Layer
* GetLayer() OVERRIDE
;
83 virtual void ReorderNativeViews() OVERRIDE
;
84 virtual void ViewRemoved(View
* view
) OVERRIDE
;
85 virtual void SetNativeWindowProperty(const char* name
, void* value
) OVERRIDE
;
86 virtual void* GetNativeWindowProperty(const char* name
) const OVERRIDE
;
87 virtual TooltipManager
* GetTooltipManager() const OVERRIDE
;
88 virtual void SetCapture() OVERRIDE
;
89 virtual void ReleaseCapture() OVERRIDE
;
90 virtual bool HasCapture() const OVERRIDE
;
91 virtual InputMethod
* CreateInputMethod() OVERRIDE
;
92 virtual internal::InputMethodDelegate
* GetInputMethodDelegate() OVERRIDE
;
93 virtual void CenterWindow(const gfx::Size
& size
) OVERRIDE
;
94 virtual void GetWindowPlacement(
96 ui::WindowShowState
* show_state
) const OVERRIDE
;
97 virtual void SetWindowTitle(const string16
& title
) OVERRIDE
;
98 virtual void SetWindowIcons(const gfx::ImageSkia
& window_icon
,
99 const gfx::ImageSkia
& app_icon
) OVERRIDE
;
100 virtual void InitModalType(ui::ModalType modal_type
) OVERRIDE
;
101 virtual gfx::Rect
GetWindowBoundsInScreen() const OVERRIDE
;
102 virtual gfx::Rect
GetClientAreaBoundsInScreen() const OVERRIDE
;
103 virtual gfx::Rect
GetRestoredBounds() const OVERRIDE
;
104 virtual void SetBounds(const gfx::Rect
& bounds
) OVERRIDE
;
105 virtual void SetSize(const gfx::Size
& size
) OVERRIDE
;
106 virtual void StackAbove(gfx::NativeView native_view
) OVERRIDE
;
107 virtual void StackAtTop() OVERRIDE
;
108 virtual void StackBelow(gfx::NativeView native_view
) OVERRIDE
;
109 virtual void SetShape(gfx::NativeRegion shape
) OVERRIDE
;
110 virtual void Close() OVERRIDE
;
111 virtual void CloseNow() OVERRIDE
;
112 virtual void Show() OVERRIDE
;
113 virtual void Hide() OVERRIDE
;
114 virtual void ShowMaximizedWithBounds(
115 const gfx::Rect
& restored_bounds
) OVERRIDE
;
116 virtual void ShowWithWindowState(ui::WindowShowState show_state
) OVERRIDE
;
117 virtual bool IsVisible() const OVERRIDE
;
118 virtual void Activate() OVERRIDE
;
119 virtual void Deactivate() OVERRIDE
;
120 virtual bool IsActive() const OVERRIDE
;
121 virtual void SetAlwaysOnTop(bool always_on_top
) OVERRIDE
;
122 virtual bool IsAlwaysOnTop() const OVERRIDE
;
123 virtual void Maximize() OVERRIDE
;
124 virtual void Minimize() OVERRIDE
;
125 virtual bool IsMaximized() const OVERRIDE
;
126 virtual bool IsMinimized() const OVERRIDE
;
127 virtual void Restore() OVERRIDE
;
128 virtual void SetFullscreen(bool fullscreen
) OVERRIDE
;
129 virtual bool IsFullscreen() const OVERRIDE
;
130 virtual void SetOpacity(unsigned char opacity
) OVERRIDE
;
131 virtual void SetUseDragFrame(bool use_drag_frame
) OVERRIDE
;
132 virtual void FlashFrame(bool flash
) OVERRIDE
;
133 virtual void RunShellDrag(View
* view
,
134 const ui::OSExchangeData
& data
,
135 const gfx::Point
& location
,
137 ui::DragDropTypes::DragEventSource source
) OVERRIDE
;
138 virtual void SchedulePaintInRect(const gfx::Rect
& rect
) OVERRIDE
;
139 virtual void SetCursor(gfx::NativeCursor cursor
) OVERRIDE
;
140 virtual bool IsMouseEventsEnabled() const OVERRIDE
;
141 virtual void ClearNativeFocus() OVERRIDE
;
142 virtual gfx::Rect
GetWorkAreaBoundsInScreen() const OVERRIDE
;
143 virtual Widget::MoveLoopResult
RunMoveLoop(
144 const gfx::Vector2d
& drag_offset
,
145 Widget::MoveLoopSource source
,
146 Widget::MoveLoopEscapeBehavior escape_behavior
) OVERRIDE
;
147 virtual void EndMoveLoop() OVERRIDE
;
148 virtual void SetVisibilityChangedAnimationsEnabled(bool value
) OVERRIDE
;
149 virtual ui::NativeTheme
* GetNativeTheme() const OVERRIDE
;
150 virtual void OnRootViewLayout() const OVERRIDE
;
152 // Overridden from NativeWidget:
153 virtual ui::EventHandler
* GetEventHandler() OVERRIDE
;
156 // Deletes this window as it is destroyed, override to provide different
158 virtual void OnFinalMessage(HWND window
);
160 HWNDMessageHandler
* GetMessageHandler();
162 // Overridden from HWNDMessageHandlerDelegate:
163 virtual bool IsWidgetWindow() const OVERRIDE
;
164 virtual bool IsUsingCustomFrame() const OVERRIDE
;
165 virtual void SchedulePaint() OVERRIDE
;
166 virtual void EnableInactiveRendering() OVERRIDE
;
167 virtual bool IsInactiveRenderingDisabled() OVERRIDE
;
168 virtual bool CanResize() const OVERRIDE
;
169 virtual bool CanMaximize() const OVERRIDE
;
170 virtual bool CanActivate() const OVERRIDE
;
171 virtual bool WidgetSizeIsClientSize() const OVERRIDE
;
172 virtual bool CanSaveFocus() const OVERRIDE
;
173 virtual void SaveFocusOnDeactivate() OVERRIDE
;
174 virtual void RestoreFocusOnActivate() OVERRIDE
;
175 virtual void RestoreFocusOnEnable() OVERRIDE
;
176 virtual bool IsModal() const OVERRIDE
;
177 virtual int GetInitialShowState() const OVERRIDE
;
178 virtual bool WillProcessWorkAreaChange() const OVERRIDE
;
179 virtual int GetNonClientComponent(const gfx::Point
& point
) const OVERRIDE
;
180 virtual void GetWindowMask(const gfx::Size
& size
, gfx::Path
* path
) OVERRIDE
;
181 virtual bool GetClientAreaInsets(gfx::Insets
* insets
) const OVERRIDE
;
182 virtual void GetMinMaxSize(gfx::Size
* min_size
,
183 gfx::Size
* max_size
) const OVERRIDE
;
184 virtual gfx::Size
GetRootViewSize() const OVERRIDE
;
185 virtual void ResetWindowControls() OVERRIDE
;
186 virtual void PaintLayeredWindow(gfx::Canvas
* canvas
) OVERRIDE
;
187 virtual InputMethod
* GetInputMethod() OVERRIDE
;
188 virtual gfx::NativeViewAccessible
GetNativeViewAccessible() OVERRIDE
;
189 virtual bool ShouldHandleSystemCommands() const OVERRIDE
;
190 virtual void HandleAppDeactivated() OVERRIDE
;
191 virtual void HandleActivationChanged(bool active
) OVERRIDE
;
192 virtual bool HandleAppCommand(short command
) OVERRIDE
;
193 virtual void HandleCancelMode() OVERRIDE
;
194 virtual void HandleCaptureLost() OVERRIDE
;
195 virtual void HandleClose() OVERRIDE
;
196 virtual bool HandleCommand(int command
) OVERRIDE
;
197 virtual void HandleAccelerator(const ui::Accelerator
& accelerator
) OVERRIDE
;
198 virtual void HandleCreate() OVERRIDE
;
199 virtual void HandleDestroying() OVERRIDE
;
200 virtual void HandleDestroyed() OVERRIDE
;
201 virtual bool HandleInitialFocus() OVERRIDE
;
202 virtual void HandleDisplayChange() OVERRIDE
;
203 virtual void HandleBeginWMSizeMove() OVERRIDE
;
204 virtual void HandleEndWMSizeMove() OVERRIDE
;
205 virtual void HandleMove() OVERRIDE
;
206 virtual void HandleWorkAreaChanged() OVERRIDE
;
207 virtual void HandleVisibilityChanging(bool visible
) OVERRIDE
;
208 virtual void HandleVisibilityChanged(bool visible
) OVERRIDE
;
209 virtual void HandleClientSizeChanged(const gfx::Size
& new_size
) OVERRIDE
;
210 virtual void HandleFrameChanged() OVERRIDE
;
211 virtual void HandleNativeFocus(HWND last_focused_window
) OVERRIDE
;
212 virtual void HandleNativeBlur(HWND focused_window
) OVERRIDE
;
213 virtual bool HandleMouseEvent(const ui::MouseEvent
& event
) OVERRIDE
;
214 virtual bool HandleKeyEvent(const ui::KeyEvent
& event
) OVERRIDE
;
215 virtual bool HandleUntranslatedKeyEvent(const ui::KeyEvent
& event
) OVERRIDE
;
216 virtual void HandleTouchEvent(const ui::TouchEvent
& event
) OVERRIDE
;
217 virtual bool HandleIMEMessage(UINT message
,
220 LRESULT
* result
) OVERRIDE
;
221 virtual void HandleInputLanguageChange(DWORD character_set
,
222 HKL input_language_id
) OVERRIDE
;
223 virtual bool HandlePaintAccelerated(const gfx::Rect
& invalid_rect
) OVERRIDE
;
224 virtual void HandlePaint(gfx::Canvas
* canvas
) OVERRIDE
;
225 virtual bool HandleTooltipNotify(int w_param
,
227 LRESULT
* l_result
) OVERRIDE
;
228 virtual void HandleTooltipMouseMove(UINT message
,
230 LPARAM l_param
) OVERRIDE
;
231 virtual bool PreHandleMSG(UINT message
,
234 LRESULT
* result
) OVERRIDE
;
235 virtual void PostHandleMSG(UINT message
,
237 LPARAM l_param
) OVERRIDE
;
239 // The TooltipManager. This is NULL if there is a problem creating the
240 // underlying tooltip window.
241 // WARNING: RootView's destructor calls into the TooltipManager. As such, this
242 // must be destroyed AFTER root_view_.
243 scoped_ptr
<TooltipManagerWin
> tooltip_manager_
;
245 scoped_refptr
<DropTargetWin
> drop_target_
;
248 typedef ScopedVector
<ui::ViewProp
> ViewProps
;
250 void SetInitParams(const Widget::InitParams
& params
);
252 // A delegate implementation that handles events received here.
253 // See class documentation for Widget in widget.h for a note about ownership.
254 internal::NativeWidgetDelegate
* delegate_
;
256 // See class documentation for Widget in widget.h for a note about ownership.
257 Widget::InitParams::Ownership ownership_
;
261 // The window styles before we modified them for the drag frame appearance.
262 DWORD drag_frame_saved_window_style_
;
263 DWORD drag_frame_saved_window_ex_style_
;
265 // True if the widget is going to have a non_client_view. We cache this value
266 // rather than asking the Widget for the non_client_view so that we know at
267 // Init time, before the Widget has created the NonClientView.
268 bool has_non_client_view_
;
270 scoped_ptr
<HWNDMessageHandler
> message_handler_
;
272 DISALLOW_COPY_AND_ASSIGN(NativeWidgetWin
);
277 #endif // UI_VIEWS_WIDGET_NATIVE_WIDGET_WIN_H_