| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 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_NATIVE_WIDGET_WIN_H_ | |
| 6 #define UI_VIEWS_WIDGET_NATIVE_WIDGET_WIN_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include <atlbase.h> | |
| 10 #include <atlapp.h> | |
| 11 #include <atlcrack.h> | |
| 12 #include <atlmisc.h> | |
| 13 | |
| 14 #include <string> | |
| 15 #include <vector> | |
| 16 | |
| 17 #include "base/memory/ref_counted.h" | |
| 18 #include "base/memory/scoped_ptr.h" | |
| 19 #include "base/memory/scoped_vector.h" | |
| 20 #include "base/memory/weak_ptr.h" | |
| 21 #include "base/message_loop.h" | |
| 22 #include "base/win/scoped_comptr.h" | |
| 23 #include "base/win/win_util.h" | |
| 24 #include "ui/base/win/window_impl.h" | |
| 25 #include "ui/gfx/compositor/compositor.h" | |
| 26 #include "ui/views/focus/focus_manager.h" | |
| 27 #include "ui/views/layout/layout_manager.h" | |
| 28 #include "ui/views/widget/native_widget_private.h" | |
| 29 | |
| 30 namespace ui { | |
| 31 class Compositor; | |
| 32 class ViewProp; | |
| 33 } | |
| 34 | |
| 35 namespace gfx { | |
| 36 class CanvasSkia; | |
| 37 class Font; | |
| 38 class Rect; | |
| 39 } | |
| 40 | |
| 41 namespace views { | |
| 42 | |
| 43 class DropTargetWin; | |
| 44 class RootView; | |
| 45 class TooltipManagerWin; | |
| 46 | |
| 47 // These two messages aren't defined in winuser.h, but they are sent to windows | |
| 48 // with captions. They appear to paint the window caption and frame. | |
| 49 // Unfortunately if you override the standard non-client rendering as we do | |
| 50 // with CustomFrameWindow, sometimes Windows (not deterministically | |
| 51 // reproducibly but definitely frequently) will send these messages to the | |
| 52 // window and paint the standard caption/title over the top of the custom one. | |
| 53 // So we need to handle these messages in CustomFrameWindow to prevent this | |
| 54 // from happening. | |
| 55 const int WM_NCUAHDRAWCAPTION = 0xAE; | |
| 56 const int WM_NCUAHDRAWFRAME = 0xAF; | |
| 57 | |
| 58 /////////////////////////////////////////////////////////////////////////////// | |
| 59 // | |
| 60 // NativeWidgetWin | |
| 61 // A Widget for a views hierarchy used to represent anything that can be | |
| 62 // contained within an HWND, e.g. a control, a window, etc. Specializations | |
| 63 // suitable for specific tasks, e.g. top level window, are derived from this. | |
| 64 // | |
| 65 // This Widget contains a RootView which owns the hierarchy of views within it. | |
| 66 // As long as views are part of this tree, they will be deleted automatically | |
| 67 // when the RootView is destroyed. If you remove a view from the tree, you are | |
| 68 // then responsible for cleaning up after it. | |
| 69 // | |
| 70 /////////////////////////////////////////////////////////////////////////////// | |
| 71 class VIEWS_EXPORT NativeWidgetWin : public ui::WindowImpl, | |
| 72 public MessageLoopForUI::Observer, | |
| 73 public ui::CompositorDelegate, | |
| 74 public internal::NativeWidgetPrivate { | |
| 75 public: | |
| 76 explicit NativeWidgetWin(internal::NativeWidgetDelegate* delegate); | |
| 77 virtual ~NativeWidgetWin(); | |
| 78 | |
| 79 // Returns true if we are on Windows Vista or greater and composition is | |
| 80 // enabled. | |
| 81 static bool IsAeroGlassEnabled(); | |
| 82 | |
| 83 // Returns the system set window title font. | |
| 84 static gfx::Font GetWindowTitleFont(); | |
| 85 | |
| 86 // Show the window with the specified show command. | |
| 87 void Show(int show_state); | |
| 88 | |
| 89 // Disable Layered Window updates by setting to false. | |
| 90 void set_can_update_layered_window(bool can_update_layered_window) { | |
| 91 can_update_layered_window_ = can_update_layered_window; | |
| 92 } | |
| 93 | |
| 94 // Obtain the view event with the given MSAA child id. Used in | |
| 95 // NativeViewAccessibilityWin::get_accChild to support requests for | |
| 96 // children of windowless controls. May return NULL | |
| 97 // (see ViewHierarchyChanged). | |
| 98 View* GetAccessibilityViewEventAt(int id); | |
| 99 | |
| 100 // Add a view that has recently fired an accessibility event. Returns a MSAA | |
| 101 // child id which is generated by: -(index of view in vector + 1) which | |
| 102 // guarantees a negative child id. This distinguishes the view from | |
| 103 // positive MSAA child id's which are direct leaf children of views that have | |
| 104 // associated hWnd's (e.g. NativeWidgetWin). | |
| 105 int AddAccessibilityViewEvent(View* view); | |
| 106 | |
| 107 // Clear a view that has recently been removed on a hierarchy change. | |
| 108 void ClearAccessibilityViewEvent(View* view); | |
| 109 | |
| 110 // Hides the window if it hasn't already been force-hidden. The force hidden | |
| 111 // count is tracked, so calling multiple times is allowed, you just have to | |
| 112 // be sure to call PopForceHidden the same number of times. | |
| 113 void PushForceHidden(); | |
| 114 | |
| 115 // Decrements the force hidden count, showing the window if we have reached | |
| 116 // the top of the stack. See PushForceHidden. | |
| 117 void PopForceHidden(); | |
| 118 | |
| 119 BOOL IsWindow() const { | |
| 120 return ::IsWindow(GetNativeView()); | |
| 121 } | |
| 122 | |
| 123 BOOL ShowWindow(int command) { | |
| 124 DCHECK(::IsWindow(GetNativeView())); | |
| 125 return ::ShowWindow(GetNativeView(), command); | |
| 126 } | |
| 127 | |
| 128 HWND GetParent() const { | |
| 129 return ::GetParent(GetNativeView()); | |
| 130 } | |
| 131 | |
| 132 LONG GetWindowLong(int index) { | |
| 133 DCHECK(::IsWindow(GetNativeView())); | |
| 134 return ::GetWindowLong(GetNativeView(), index); | |
| 135 } | |
| 136 | |
| 137 BOOL GetWindowRect(RECT* rect) const { | |
| 138 return ::GetWindowRect(GetNativeView(), rect); | |
| 139 } | |
| 140 | |
| 141 LONG SetWindowLong(int index, LONG new_long) { | |
| 142 DCHECK(::IsWindow(GetNativeView())); | |
| 143 return ::SetWindowLong(GetNativeView(), index, new_long); | |
| 144 } | |
| 145 | |
| 146 BOOL SetWindowPos(HWND hwnd_after, int x, int y, int cx, int cy, UINT flags) { | |
| 147 DCHECK(::IsWindow(GetNativeView())); | |
| 148 return ::SetWindowPos(GetNativeView(), hwnd_after, x, y, cx, cy, flags); | |
| 149 } | |
| 150 | |
| 151 BOOL IsZoomed() const { | |
| 152 DCHECK(::IsWindow(GetNativeView())); | |
| 153 return ::IsZoomed(GetNativeView()); | |
| 154 } | |
| 155 | |
| 156 BOOL MoveWindow(int x, int y, int width, int height) { | |
| 157 return MoveWindow(x, y, width, height, TRUE); | |
| 158 } | |
| 159 | |
| 160 BOOL MoveWindow(int x, int y, int width, int height, BOOL repaint) { | |
| 161 DCHECK(::IsWindow(GetNativeView())); | |
| 162 return ::MoveWindow(GetNativeView(), x, y, width, height, repaint); | |
| 163 } | |
| 164 | |
| 165 int SetWindowRgn(HRGN region, BOOL redraw) { | |
| 166 DCHECK(::IsWindow(GetNativeView())); | |
| 167 return ::SetWindowRgn(GetNativeView(), region, redraw); | |
| 168 } | |
| 169 | |
| 170 BOOL GetClientRect(RECT* rect) const { | |
| 171 DCHECK(::IsWindow(GetNativeView())); | |
| 172 return ::GetClientRect(GetNativeView(), rect); | |
| 173 } | |
| 174 | |
| 175 // Overridden from ui::CompositorDelegate: | |
| 176 virtual void ScheduleDraw(); | |
| 177 | |
| 178 // Overridden from internal::NativeWidgetPrivate: | |
| 179 virtual void InitNativeWidget(const Widget::InitParams& params) OVERRIDE; | |
| 180 virtual NonClientFrameView* CreateNonClientFrameView() OVERRIDE; | |
| 181 virtual void UpdateFrameAfterFrameChange() OVERRIDE; | |
| 182 virtual bool ShouldUseNativeFrame() const OVERRIDE; | |
| 183 virtual void FrameTypeChanged() OVERRIDE; | |
| 184 virtual Widget* GetWidget() OVERRIDE; | |
| 185 virtual const Widget* GetWidget() const OVERRIDE; | |
| 186 virtual gfx::NativeView GetNativeView() const OVERRIDE; | |
| 187 virtual gfx::NativeWindow GetNativeWindow() const OVERRIDE; | |
| 188 virtual Widget* GetTopLevelWidget() OVERRIDE; | |
| 189 virtual const ui::Compositor* GetCompositor() const OVERRIDE; | |
| 190 virtual ui::Compositor* GetCompositor() OVERRIDE; | |
| 191 virtual void CalculateOffsetToAncestorWithLayer( | |
| 192 gfx::Point* offset, | |
| 193 ui::Layer** layer_parent) OVERRIDE; | |
| 194 virtual void ReorderLayers() OVERRIDE; | |
| 195 virtual void ViewRemoved(View* view) OVERRIDE; | |
| 196 virtual void SetNativeWindowProperty(const char* name, void* value) OVERRIDE; | |
| 197 virtual void* GetNativeWindowProperty(const char* name) const OVERRIDE; | |
| 198 virtual TooltipManager* GetTooltipManager() const OVERRIDE; | |
| 199 virtual bool IsScreenReaderActive() const OVERRIDE; | |
| 200 virtual void SendNativeAccessibilityEvent( | |
| 201 View* view, | |
| 202 ui::AccessibilityTypes::Event event_type) OVERRIDE; | |
| 203 virtual void SetMouseCapture() OVERRIDE; | |
| 204 virtual void ReleaseMouseCapture() OVERRIDE; | |
| 205 virtual bool HasMouseCapture() const OVERRIDE; | |
| 206 virtual InputMethod* CreateInputMethod() OVERRIDE; | |
| 207 virtual void CenterWindow(const gfx::Size& size) OVERRIDE; | |
| 208 virtual void GetWindowPlacement( | |
| 209 gfx::Rect* bounds, | |
| 210 ui::WindowShowState* show_state) const OVERRIDE; | |
| 211 virtual void SetWindowTitle(const string16& title) OVERRIDE; | |
| 212 virtual void SetWindowIcons(const SkBitmap& window_icon, | |
| 213 const SkBitmap& app_icon) OVERRIDE; | |
| 214 virtual void SetAccessibleName(const string16& name) OVERRIDE; | |
| 215 virtual void SetAccessibleRole(ui::AccessibilityTypes::Role role) OVERRIDE; | |
| 216 virtual void SetAccessibleState(ui::AccessibilityTypes::State state) OVERRIDE; | |
| 217 virtual void BecomeModal() OVERRIDE; | |
| 218 virtual gfx::Rect GetWindowScreenBounds() const OVERRIDE; | |
| 219 virtual gfx::Rect GetClientAreaScreenBounds() const OVERRIDE; | |
| 220 virtual gfx::Rect GetRestoredBounds() const OVERRIDE; | |
| 221 virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE; | |
| 222 virtual void SetSize(const gfx::Size& size) OVERRIDE; | |
| 223 virtual void MoveAbove(gfx::NativeView native_view) OVERRIDE; | |
| 224 virtual void MoveToTop() OVERRIDE; | |
| 225 virtual void SetShape(gfx::NativeRegion shape) OVERRIDE; | |
| 226 virtual void Close() OVERRIDE; | |
| 227 virtual void CloseNow() OVERRIDE; | |
| 228 virtual void EnableClose(bool enable) OVERRIDE; | |
| 229 virtual void Show() OVERRIDE; | |
| 230 virtual void Hide() OVERRIDE; | |
| 231 virtual void ShowMaximizedWithBounds( | |
| 232 const gfx::Rect& restored_bounds) OVERRIDE; | |
| 233 virtual void ShowWithWindowState(ui::WindowShowState show_state) OVERRIDE; | |
| 234 virtual bool IsVisible() const OVERRIDE; | |
| 235 virtual void Activate() OVERRIDE; | |
| 236 virtual void Deactivate() OVERRIDE; | |
| 237 virtual bool IsActive() const OVERRIDE; | |
| 238 virtual void SetAlwaysOnTop(bool always_on_top) OVERRIDE; | |
| 239 virtual void Maximize() OVERRIDE; | |
| 240 virtual void Minimize() OVERRIDE; | |
| 241 virtual bool IsMaximized() const OVERRIDE; | |
| 242 virtual bool IsMinimized() const OVERRIDE; | |
| 243 virtual void Restore() OVERRIDE; | |
| 244 virtual void SetFullscreen(bool fullscreen) OVERRIDE; | |
| 245 virtual bool IsFullscreen() const OVERRIDE; | |
| 246 virtual void SetOpacity(unsigned char opacity) OVERRIDE; | |
| 247 virtual void SetUseDragFrame(bool use_drag_frame) OVERRIDE; | |
| 248 virtual bool IsAccessibleWidget() const OVERRIDE; | |
| 249 virtual void RunShellDrag(View* view, | |
| 250 const ui::OSExchangeData& data, | |
| 251 int operation) OVERRIDE; | |
| 252 virtual void SchedulePaintInRect(const gfx::Rect& rect) OVERRIDE; | |
| 253 virtual void SetCursor(gfx::NativeCursor cursor) OVERRIDE; | |
| 254 virtual void ClearNativeFocus() OVERRIDE; | |
| 255 virtual void FocusNativeView(gfx::NativeView native_view) OVERRIDE; | |
| 256 virtual bool ConvertPointFromAncestor( | |
| 257 const Widget* ancestor, gfx::Point* point) const OVERRIDE; | |
| 258 virtual gfx::Rect GetWorkAreaBoundsInScreen() const OVERRIDE; | |
| 259 virtual void SetInactiveRenderingDisabled(bool value) OVERRIDE; | |
| 260 | |
| 261 protected: | |
| 262 // Information saved before going into fullscreen mode, used to restore the | |
| 263 // window afterwards. | |
| 264 struct SavedWindowInfo { | |
| 265 bool maximized; | |
| 266 LONG style; | |
| 267 LONG ex_style; | |
| 268 RECT window_rect; | |
| 269 }; | |
| 270 | |
| 271 // Overridden from MessageLoop::Observer: | |
| 272 virtual base::EventStatus WillProcessEvent( | |
| 273 const base::NativeEvent& event) OVERRIDE; | |
| 274 virtual void DidProcessEvent(const base::NativeEvent& event) OVERRIDE; | |
| 275 | |
| 276 // Overridden from WindowImpl: | |
| 277 virtual HICON GetDefaultWindowIcon() const OVERRIDE; | |
| 278 virtual LRESULT OnWndProc(UINT message, | |
| 279 WPARAM w_param, | |
| 280 LPARAM l_param) OVERRIDE; | |
| 281 | |
| 282 // Message Handlers ---------------------------------------------------------- | |
| 283 | |
| 284 BEGIN_MSG_MAP_EX(NativeWidgetWin) | |
| 285 // Range handlers must go first! | |
| 286 MESSAGE_RANGE_HANDLER_EX(WM_MOUSEFIRST, WM_MOUSELAST, OnMouseRange) | |
| 287 MESSAGE_RANGE_HANDLER_EX(WM_NCMOUSEMOVE, WM_NCXBUTTONDBLCLK, OnMouseRange) | |
| 288 | |
| 289 // Reflected message handler | |
| 290 MESSAGE_HANDLER_EX(base::win::kReflectedMessage, OnReflectedMessage) | |
| 291 | |
| 292 // CustomFrameWindow hacks | |
| 293 MESSAGE_HANDLER_EX(WM_NCUAHDRAWCAPTION, OnNCUAHDrawCaption) | |
| 294 MESSAGE_HANDLER_EX(WM_NCUAHDRAWFRAME, OnNCUAHDrawFrame) | |
| 295 | |
| 296 // Vista and newer | |
| 297 MESSAGE_HANDLER_EX(WM_DWMCOMPOSITIONCHANGED, OnDwmCompositionChanged) | |
| 298 | |
| 299 // Non-atlcrack.h handlers | |
| 300 MESSAGE_HANDLER_EX(WM_GETOBJECT, OnGetObject) | |
| 301 | |
| 302 // Mouse events. | |
| 303 MESSAGE_HANDLER_EX(WM_MOUSEACTIVATE, OnMouseActivate) | |
| 304 MESSAGE_HANDLER_EX(WM_MOUSELEAVE, OnMouseRange) | |
| 305 MESSAGE_HANDLER_EX(WM_NCMOUSELEAVE, OnMouseRange) | |
| 306 MESSAGE_HANDLER_EX(WM_SETCURSOR, OnSetCursor); | |
| 307 | |
| 308 // Key events. | |
| 309 MESSAGE_HANDLER_EX(WM_KEYDOWN, OnKeyEvent) | |
| 310 MESSAGE_HANDLER_EX(WM_KEYUP, OnKeyEvent) | |
| 311 MESSAGE_HANDLER_EX(WM_SYSKEYDOWN, OnKeyEvent) | |
| 312 MESSAGE_HANDLER_EX(WM_SYSKEYUP, OnKeyEvent) | |
| 313 | |
| 314 // IME Events. | |
| 315 MESSAGE_HANDLER_EX(WM_IME_SETCONTEXT, OnImeMessages) | |
| 316 MESSAGE_HANDLER_EX(WM_IME_STARTCOMPOSITION, OnImeMessages) | |
| 317 MESSAGE_HANDLER_EX(WM_IME_COMPOSITION, OnImeMessages) | |
| 318 MESSAGE_HANDLER_EX(WM_IME_ENDCOMPOSITION, OnImeMessages) | |
| 319 MESSAGE_HANDLER_EX(WM_IME_REQUEST, OnImeMessages) | |
| 320 MESSAGE_HANDLER_EX(WM_CHAR, OnImeMessages) | |
| 321 MESSAGE_HANDLER_EX(WM_SYSCHAR, OnImeMessages) | |
| 322 MESSAGE_HANDLER_EX(WM_DEADCHAR, OnImeMessages) | |
| 323 MESSAGE_HANDLER_EX(WM_SYSDEADCHAR, OnImeMessages) | |
| 324 | |
| 325 // This list is in _ALPHABETICAL_ order! OR I WILL HURT YOU. | |
| 326 MSG_WM_ACTIVATE(OnActivate) | |
| 327 MSG_WM_ACTIVATEAPP(OnActivateApp) | |
| 328 MSG_WM_APPCOMMAND(OnAppCommand) | |
| 329 MSG_WM_CANCELMODE(OnCancelMode) | |
| 330 MSG_WM_CAPTURECHANGED(OnCaptureChanged) | |
| 331 MSG_WM_CLOSE(OnClose) | |
| 332 MSG_WM_COMMAND(OnCommand) | |
| 333 MSG_WM_CREATE(OnCreate) | |
| 334 MSG_WM_DESTROY(OnDestroy) | |
| 335 MSG_WM_DISPLAYCHANGE(OnDisplayChange) | |
| 336 MSG_WM_ERASEBKGND(OnEraseBkgnd) | |
| 337 MSG_WM_ENDSESSION(OnEndSession) | |
| 338 MSG_WM_ENTERSIZEMOVE(OnEnterSizeMove) | |
| 339 MSG_WM_EXITMENULOOP(OnExitMenuLoop) | |
| 340 MSG_WM_EXITSIZEMOVE(OnExitSizeMove) | |
| 341 MSG_WM_GETMINMAXINFO(OnGetMinMaxInfo) | |
| 342 MSG_WM_HSCROLL(OnHScroll) | |
| 343 MSG_WM_INITMENU(OnInitMenu) | |
| 344 MSG_WM_INITMENUPOPUP(OnInitMenuPopup) | |
| 345 MSG_WM_INPUTLANGCHANGE(OnInputLangChange) | |
| 346 MSG_WM_KILLFOCUS(OnKillFocus) | |
| 347 MSG_WM_MOVE(OnMove) | |
| 348 MSG_WM_MOVING(OnMoving) | |
| 349 MSG_WM_NCACTIVATE(OnNCActivate) | |
| 350 MSG_WM_NCCALCSIZE(OnNCCalcSize) | |
| 351 MSG_WM_NCHITTEST(OnNCHitTest) | |
| 352 MSG_WM_NCPAINT(OnNCPaint) | |
| 353 MSG_WM_NOTIFY(OnNotify) | |
| 354 MSG_WM_PAINT(OnPaint) | |
| 355 MSG_WM_POWERBROADCAST(OnPowerBroadcast) | |
| 356 MSG_WM_SETFOCUS(OnSetFocus) | |
| 357 MSG_WM_SETICON(OnSetIcon) | |
| 358 MSG_WM_SETTEXT(OnSetText) | |
| 359 MSG_WM_SETTINGCHANGE(OnSettingChange) | |
| 360 MSG_WM_SIZE(OnSize) | |
| 361 MSG_WM_SYSCOMMAND(OnSysCommand) | |
| 362 MSG_WM_THEMECHANGED(OnThemeChanged) | |
| 363 MSG_WM_VSCROLL(OnVScroll) | |
| 364 MSG_WM_WINDOWPOSCHANGING(OnWindowPosChanging) | |
| 365 MSG_WM_WINDOWPOSCHANGED(OnWindowPosChanged) | |
| 366 END_MSG_MAP() | |
| 367 | |
| 368 // These are all virtual so that specialized Widgets can modify or augment | |
| 369 // processing. | |
| 370 // This list is in _ALPHABETICAL_ order! | |
| 371 // Note: in the base class these functions must do nothing but convert point | |
| 372 // coordinates to client coordinates (if necessary) and forward the | |
| 373 // handling to the appropriate Process* function. This is so that | |
| 374 // subclasses can easily override these methods to do different things | |
| 375 // and have a convenient function to call to get the default behavior. | |
| 376 virtual void OnActivate(UINT action, BOOL minimized, HWND window); | |
| 377 virtual void OnActivateApp(BOOL active, DWORD thread_id); | |
| 378 virtual LRESULT OnAppCommand(HWND window, short app_command, WORD device, | |
| 379 int keystate); | |
| 380 virtual void OnCancelMode(); | |
| 381 virtual void OnCaptureChanged(HWND hwnd); | |
| 382 virtual void OnClose(); | |
| 383 virtual void OnCommand(UINT notification_code, int command_id, HWND window); | |
| 384 virtual LRESULT OnCreate(CREATESTRUCT* create_struct); | |
| 385 // WARNING: If you override this be sure and invoke super, otherwise we'll | |
| 386 // leak a few things. | |
| 387 virtual void OnDestroy(); | |
| 388 virtual void OnDisplayChange(UINT bits_per_pixel, CSize screen_size); | |
| 389 virtual LRESULT OnDwmCompositionChanged(UINT msg, | |
| 390 WPARAM w_param, | |
| 391 LPARAM l_param); | |
| 392 virtual void OnEndSession(BOOL ending, UINT logoff); | |
| 393 virtual void OnEnterSizeMove(); | |
| 394 virtual LRESULT OnEraseBkgnd(HDC dc); | |
| 395 virtual void OnExitMenuLoop(BOOL is_track_popup_menu); | |
| 396 virtual void OnExitSizeMove(); | |
| 397 virtual LRESULT OnGetObject(UINT uMsg, WPARAM w_param, LPARAM l_param); | |
| 398 virtual void OnGetMinMaxInfo(MINMAXINFO* minmax_info); | |
| 399 virtual void OnHScroll(int scroll_type, short position, HWND scrollbar); | |
| 400 virtual LRESULT OnImeMessages(UINT message, WPARAM w_param, LPARAM l_param); | |
| 401 virtual void OnInitMenu(HMENU menu); | |
| 402 virtual void OnInitMenuPopup(HMENU menu, UINT position, BOOL is_system_menu); | |
| 403 virtual void OnInputLangChange(DWORD character_set, HKL input_language_id); | |
| 404 virtual LRESULT OnKeyEvent(UINT message, WPARAM w_param, LPARAM l_param); | |
| 405 virtual void OnKillFocus(HWND focused_window); | |
| 406 virtual LRESULT OnMouseActivate(UINT message, WPARAM w_param, LPARAM l_param); | |
| 407 virtual LRESULT OnMouseRange(UINT message, WPARAM w_param, LPARAM l_param); | |
| 408 virtual void OnMove(const CPoint& point); | |
| 409 virtual void OnMoving(UINT param, LPRECT new_bounds); | |
| 410 virtual LRESULT OnNCActivate(BOOL active); | |
| 411 virtual LRESULT OnNCCalcSize(BOOL w_param, LPARAM l_param); | |
| 412 virtual LRESULT OnNCHitTest(const CPoint& pt); | |
| 413 virtual void OnNCPaint(HRGN rgn); | |
| 414 virtual LRESULT OnNCUAHDrawCaption(UINT msg, | |
| 415 WPARAM w_param, | |
| 416 LPARAM l_param); | |
| 417 virtual LRESULT OnNCUAHDrawFrame(UINT msg, WPARAM w_param, LPARAM l_param); | |
| 418 virtual LRESULT OnNotify(int w_param, NMHDR* l_param); | |
| 419 virtual void OnPaint(HDC dc); | |
| 420 virtual LRESULT OnPowerBroadcast(DWORD power_event, DWORD data); | |
| 421 virtual LRESULT OnReflectedMessage(UINT msg, WPARAM w_param, LPARAM l_param); | |
| 422 virtual LRESULT OnSetCursor(UINT message, WPARAM w_param, LPARAM l_param); | |
| 423 virtual void OnSetFocus(HWND focused_window); | |
| 424 virtual LRESULT OnSetIcon(UINT size_type, HICON new_icon); | |
| 425 virtual LRESULT OnSetText(const wchar_t* text); | |
| 426 virtual void OnSettingChange(UINT flags, const wchar_t* section); | |
| 427 virtual void OnSize(UINT param, const CSize& size); | |
| 428 virtual void OnSysCommand(UINT notification_code, CPoint click); | |
| 429 virtual void OnThemeChanged(); | |
| 430 virtual void OnVScroll(int scroll_type, short position, HWND scrollbar); | |
| 431 virtual void OnWindowPosChanging(WINDOWPOS* window_pos); | |
| 432 virtual void OnWindowPosChanged(WINDOWPOS* window_pos); | |
| 433 | |
| 434 // Deletes this window as it is destroyed, override to provide different | |
| 435 // behavior. | |
| 436 virtual void OnFinalMessage(HWND window); | |
| 437 | |
| 438 // Retrieve the show state of the window. This is one of the SW_SHOW* flags | |
| 439 // passed into Windows' ShowWindow method. For normal windows this defaults | |
| 440 // to SW_SHOWNORMAL, however windows (e.g. the main window) can override this | |
| 441 // method to provide different values (e.g. retrieve the user's specified | |
| 442 // show state from the shortcut starutp info). | |
| 443 virtual int GetShowState() const; | |
| 444 | |
| 445 // Returns the insets of the client area relative to the non-client area of | |
| 446 // the window. Override this function instead of OnNCCalcSize, which is | |
| 447 // crazily complicated. | |
| 448 virtual gfx::Insets GetClientAreaInsets() const; | |
| 449 | |
| 450 // Start tracking all mouse events so that this window gets sent mouse leave | |
| 451 // messages too. | |
| 452 void TrackMouseEvents(DWORD mouse_tracking_flags); | |
| 453 | |
| 454 // Called when a MSAA screen reader client is detected. | |
| 455 virtual void OnScreenReaderDetected(); | |
| 456 | |
| 457 // Executes the specified SC_command. | |
| 458 void ExecuteSystemMenuCommand(int command); | |
| 459 | |
| 460 // The TooltipManager. This is NULL if there is a problem creating the | |
| 461 // underlying tooltip window. | |
| 462 // WARNING: RootView's destructor calls into the TooltipManager. As such, this | |
| 463 // must be destroyed AFTER root_view_. | |
| 464 scoped_ptr<TooltipManagerWin> tooltip_manager_; | |
| 465 | |
| 466 scoped_refptr<DropTargetWin> drop_target_; | |
| 467 | |
| 468 const gfx::Rect& invalid_rect() const { return invalid_rect_; } | |
| 469 | |
| 470 // Saved window information from before entering fullscreen mode. | |
| 471 // TODO(beng): move to private once GetRestoredBounds() moves onto Widget. | |
| 472 SavedWindowInfo saved_window_info_; | |
| 473 | |
| 474 private: | |
| 475 typedef ScopedVector<ui::ViewProp> ViewProps; | |
| 476 | |
| 477 // Called after the WM_ACTIVATE message has been processed by the default | |
| 478 // windows procedure. | |
| 479 static void PostProcessActivateMessage(NativeWidgetWin* widget, | |
| 480 int activation_state); | |
| 481 | |
| 482 void SetInitParams(const Widget::InitParams& params); | |
| 483 | |
| 484 // Synchronously paints the invalid contents of the Widget. | |
| 485 void RedrawInvalidRect(); | |
| 486 | |
| 487 // Synchronously updates the invalid contents of the Widget. Valid for | |
| 488 // layered windows only. | |
| 489 void RedrawLayeredWindowContents(); | |
| 490 | |
| 491 // Lock or unlock the window from being able to redraw itself in response to | |
| 492 // updates to its invalid region. | |
| 493 class ScopedRedrawLock; | |
| 494 void LockUpdates(); | |
| 495 void UnlockUpdates(); | |
| 496 | |
| 497 // Determines whether the delegate expects the client size or the window size. | |
| 498 bool WidgetSizeIsClientSize() const; | |
| 499 | |
| 500 // Responds to the client area changing size, either at window creation time | |
| 501 // or subsequently. | |
| 502 void ClientAreaSizeChanged(); | |
| 503 | |
| 504 // Resets the window region for the current widget bounds if necessary. | |
| 505 // If |force| is true, the window region is reset to NULL even for native | |
| 506 // frame windows. | |
| 507 void ResetWindowRegion(bool force); | |
| 508 | |
| 509 // Calls DefWindowProc, safely wrapping the call in a ScopedRedrawLock to | |
| 510 // prevent frame flicker. DefWindowProc handling can otherwise render the | |
| 511 // classic-look window title bar directly. | |
| 512 LRESULT DefWindowProcWithRedrawLock(UINT message, | |
| 513 WPARAM w_param, | |
| 514 LPARAM l_param); | |
| 515 | |
| 516 // Stops ignoring SetWindowPos() requests (see below). | |
| 517 void StopIgnoringPosChanges() { ignore_window_pos_changes_ = false; } | |
| 518 | |
| 519 void RestoreEnabledIfNecessary(); | |
| 520 | |
| 521 void SetInitialFocus(); | |
| 522 | |
| 523 // Overridden from internal::InputMethodDelegate | |
| 524 virtual void DispatchKeyEventPostIME(const KeyEvent& key) OVERRIDE; | |
| 525 | |
| 526 // A delegate implementation that handles events received here. | |
| 527 // See class documentation for Widget in widget.h for a note about ownership. | |
| 528 internal::NativeWidgetDelegate* delegate_; | |
| 529 | |
| 530 // The following factory is used for calls to close the NativeWidgetWin | |
| 531 // instance. | |
| 532 base::WeakPtrFactory<NativeWidgetWin> close_widget_factory_; | |
| 533 | |
| 534 // The flags currently being used with TrackMouseEvent to track mouse | |
| 535 // messages. 0 if there is no active tracking. The value of this member is | |
| 536 // used when tracking is canceled. | |
| 537 DWORD active_mouse_tracking_flags_; | |
| 538 | |
| 539 // Should we keep an off-screen buffer? This is false by default, set to true | |
| 540 // when WS_EX_LAYERED is specified before the native window is created. | |
| 541 // | |
| 542 // NOTE: this is intended to be used with a layered window (a window with an | |
| 543 // extended window style of WS_EX_LAYERED). If you are using a layered window | |
| 544 // and NOT changing the layered alpha or anything else, then leave this value | |
| 545 // alone. OTOH if you are invoking SetLayeredWindowAttributes then you'll | |
| 546 // most likely want to set this to false, or after changing the alpha toggle | |
| 547 // the extended style bit to false than back to true. See MSDN for more | |
| 548 // details. | |
| 549 bool use_layered_buffer_; | |
| 550 | |
| 551 // The default alpha to be applied to the layered window. | |
| 552 BYTE layered_alpha_; | |
| 553 | |
| 554 // A canvas that contains the window contents in the case of a layered | |
| 555 // window. | |
| 556 scoped_ptr<gfx::CanvasSkia> layered_window_contents_; | |
| 557 | |
| 558 // We must track the invalid rect ourselves, for two reasons: | |
| 559 // For layered windows, Windows will not do this properly with | |
| 560 // InvalidateRect()/GetUpdateRect(). (In fact, it'll return misleading | |
| 561 // information from GetUpdateRect()). | |
| 562 // We also need to keep track of the invalid rectangle for the RootView should | |
| 563 // we need to paint the non-client area. The data supplied to WM_NCPAINT seems | |
| 564 // to be insufficient. | |
| 565 gfx::Rect invalid_rect_; | |
| 566 | |
| 567 // A factory that allows us to schedule a redraw for layered windows. | |
| 568 base::WeakPtrFactory<NativeWidgetWin> paint_layered_window_factory_; | |
| 569 | |
| 570 // See class documentation for Widget in widget.h for a note about ownership. | |
| 571 Widget::InitParams::Ownership ownership_; | |
| 572 | |
| 573 // True if we are allowed to update the layered window from the DIB backing | |
| 574 // store if necessary. | |
| 575 bool can_update_layered_window_; | |
| 576 | |
| 577 // Whether the focus should be restored next time we get enabled. Needed to | |
| 578 // restore focus correctly when Windows modal dialogs are displayed. | |
| 579 bool restore_focus_when_enabled_; | |
| 580 | |
| 581 // Instance of accessibility information and handling for MSAA root | |
| 582 base::win::ScopedComPtr<IAccessible> accessibility_root_; | |
| 583 | |
| 584 // Value determines whether the Widget is customized for accessibility. | |
| 585 static bool screen_reader_active_; | |
| 586 | |
| 587 // The maximum number of view events in our vector below. | |
| 588 static const int kMaxAccessibilityViewEvents = 20; | |
| 589 | |
| 590 // A vector used to access views for which we have sent notifications to | |
| 591 // accessibility clients. It is used as a circular queue. | |
| 592 std::vector<View*> accessibility_view_events_; | |
| 593 | |
| 594 // The current position of the view events vector. When incrementing, | |
| 595 // we always mod this value with the max view events above . | |
| 596 int accessibility_view_events_index_; | |
| 597 | |
| 598 // The last cursor that was active before the current one was selected. Saved | |
| 599 // so that we can restore it. | |
| 600 gfx::NativeCursor previous_cursor_; | |
| 601 | |
| 602 ViewProps props_; | |
| 603 | |
| 604 // True if we're in fullscreen mode. | |
| 605 bool fullscreen_; | |
| 606 | |
| 607 // If this is greater than zero, we should prevent attempts to make the window | |
| 608 // visible when we handle WM_WINDOWPOSCHANGING. Some calls like | |
| 609 // ShowWindow(SW_RESTORE) make the window visible in addition to restoring it, | |
| 610 // when all we want to do is restore it. | |
| 611 int force_hidden_count_; | |
| 612 | |
| 613 // The window styles before we modified them for the drag frame appearance. | |
| 614 DWORD drag_frame_saved_window_style_; | |
| 615 DWORD drag_frame_saved_window_ex_style_; | |
| 616 | |
| 617 // Represents the number of ScopedRedrawLocks active against this widget. | |
| 618 // If this is greater than zero, the widget should be locked against updates. | |
| 619 int lock_updates_count_; | |
| 620 | |
| 621 // The window styles of the window before updates were locked. | |
| 622 DWORD saved_window_style_; | |
| 623 | |
| 624 // When true, this flag makes us discard incoming SetWindowPos() requests that | |
| 625 // only change our position/size. (We still allow changes to Z-order, | |
| 626 // activation, etc.) | |
| 627 bool ignore_window_pos_changes_; | |
| 628 | |
| 629 // The following factory is used to ignore SetWindowPos() calls for short time | |
| 630 // periods. | |
| 631 base::WeakPtrFactory<NativeWidgetWin> ignore_pos_changes_factory_; | |
| 632 | |
| 633 // The last-seen monitor containing us, and its rect and work area. These are | |
| 634 // used to catch updates to the rect and work area and react accordingly. | |
| 635 HMONITOR last_monitor_; | |
| 636 gfx::Rect last_monitor_rect_, last_work_area_; | |
| 637 | |
| 638 // Set to true when the user presses the right mouse button on the caption | |
| 639 // area. We need this so we can correctly show the context menu on mouse-up. | |
| 640 bool is_right_mouse_pressed_on_caption_; | |
| 641 | |
| 642 // Whether all ancestors have been enabled. This is only used if is_modal_ is | |
| 643 // true. | |
| 644 bool restored_enabled_; | |
| 645 | |
| 646 // The compositor for accelerated drawing. | |
| 647 scoped_refptr<ui::Compositor> compositor_; | |
| 648 | |
| 649 // This flag can be initialized and checked after certain operations (such as | |
| 650 // DefWindowProc) to avoid stack-controlled NativeWidgetWin operations (such | |
| 651 // as unlocking the Window with a ScopedRedrawLock) after Widget destruction. | |
| 652 bool* destroyed_; | |
| 653 | |
| 654 // True if the widget is going to have a non_client_view. We cache this value | |
| 655 // rather than asking the Widget for the non_client_view so that we know at | |
| 656 // Init time, before the Widget has created the NonClientView. | |
| 657 bool has_non_client_view_; | |
| 658 | |
| 659 DISALLOW_COPY_AND_ASSIGN(NativeWidgetWin); | |
| 660 }; | |
| 661 | |
| 662 } // namespace views | |
| 663 | |
| 664 #endif // UI_VIEWS_WIDGET_NATIVE_WIDGET_WIN_H_ | |
| OLD | NEW |