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 |
| 8 #include "ui/base/win/window_impl.h" |
| 9 #include "base/logging.h" |
| 10 #include "base/message_loop.h" |
| 11 #include "base/scoped_ptr.h" |
| 12 #include "base/scoped_vector.h" |
| 13 #include "ui/views/widget/native_widget.h" |
| 14 |
| 15 namespace gfx { |
| 16 class CanvasSkia; |
| 17 } |
| 18 |
| 19 namespace ui { |
| 20 class ViewProp; |
| 21 namespace internal { |
| 22 |
| 23 // A Windows message reflected from other windows. This message is sent with the |
| 24 // following arguments: |
| 25 // HWND - Target window |
| 26 // MSG - kReflectedMessage |
| 27 // WPARAM - Should be 0 |
| 28 // LPARAM - Pointer to MSG struct containing the original message. |
| 29 const int kReflectedMessage = WM_APP + 3; |
| 30 |
| 31 // These two messages aren't defined in winuser.h, but they are sent to windows |
| 32 // with captions. They appear to paint the window caption and frame. |
| 33 // Unfortunately if you override the standard non-client rendering as we do |
| 34 // with CustomFrameWindow, sometimes Windows (not deterministically |
| 35 // reproducibly but definitely frequently) will send these messages to the |
| 36 // window and paint the standard caption/title over the top of the custom one. |
| 37 // So we need to handle these messages in CustomFrameWindow to prevent this |
| 38 // from happening. |
| 39 const int WM_NCUAHDRAWCAPTION = 0xAE; |
| 40 const int WM_NCUAHDRAWFRAME = 0xAF; |
| 41 |
| 42 class NativeWidgetListener; |
| 43 |
| 44 //////////////////////////////////////////////////////////////////////////////// |
| 45 // NativeWidgetWin class |
| 46 // |
| 47 // A NativeWidget implementation that wraps a Win32 HWND. |
| 48 // |
| 49 class NativeWidgetWin : public NativeWidget, |
| 50 public ui::WindowImpl, |
| 51 public MessageLoopForUI::Observer { |
| 52 public: |
| 53 explicit NativeWidgetWin(NativeWidgetListener* listener); |
| 54 virtual ~NativeWidgetWin(); |
| 55 |
| 56 private: |
| 57 typedef ScopedVector<ViewProp> ViewProps; |
| 58 |
| 59 // Overridden from NativeWidget: |
| 60 virtual void InitWithNativeViewParent(gfx::NativeView parent, |
| 61 const gfx::Rect& bounds); |
| 62 virtual void InitWithWidgetParent(Widget* parent, |
| 63 const gfx::Rect& bounds); |
| 64 virtual void InitWithViewParent(View* parent, const gfx::Rect& bounds); |
| 65 virtual void SetNativeWindowProperty(const char* name, void* value); |
| 66 virtual void* GetNativeWindowProperty(const char* name) const; |
| 67 virtual gfx::Rect GetWindowScreenBounds() const; |
| 68 virtual gfx::Rect GetClientAreaScreenBounds() const; |
| 69 virtual void SetBounds(const gfx::Rect& bounds); |
| 70 virtual void SetShape(const gfx::Path& shape); |
| 71 virtual gfx::NativeView GetNativeView() const; |
| 72 virtual void Show(); |
| 73 virtual void Hide(); |
| 74 virtual void Close(); |
| 75 virtual void MoveAbove(NativeWidget* other); |
| 76 virtual void SetAlwaysOnTop(bool always_on_top); |
| 77 virtual void Invalidate(); |
| 78 virtual void InvalidateRect(const gfx::Rect& invalid_rect); |
| 79 virtual void Paint(); |
| 80 virtual bool IsVisible() const; |
| 81 virtual bool IsActive() const; |
| 82 virtual void SetMouseCapture(); |
| 83 virtual void ReleaseMouseCapture(); |
| 84 virtual bool HasMouseCapture() const; |
| 85 virtual bool ShouldReleaseCaptureOnMouseReleased() const; |
| 86 |
| 87 // Overridden from MessageLoop::Observer: |
| 88 void WillProcessMessage(const MSG& msg); |
| 89 virtual void DidProcessMessage(const MSG& msg); |
| 90 |
| 91 // Message handlers |
| 92 BEGIN_MSG_MAP_EX(NativeWidgetWin) |
| 93 // Range handlers must go first! |
| 94 MESSAGE_RANGE_HANDLER_EX(WM_MOUSEFIRST, WM_MOUSELAST, OnMouseRange) |
| 95 MESSAGE_RANGE_HANDLER_EX(WM_NCMOUSEMOVE, WM_NCMBUTTONDBLCLK, OnNCMouseRange) |
| 96 |
| 97 // Reflected message handler |
| 98 MESSAGE_HANDLER_EX(kReflectedMessage, OnReflectedMessage) |
| 99 |
| 100 // CustomFrameWindow hacks |
| 101 MESSAGE_HANDLER_EX(WM_NCUAHDRAWCAPTION, OnNCUAHDrawCaption) |
| 102 MESSAGE_HANDLER_EX(WM_NCUAHDRAWFRAME, OnNCUAHDrawFrame) |
| 103 |
| 104 // Vista and newer |
| 105 MESSAGE_HANDLER_EX(WM_DWMCOMPOSITIONCHANGED, OnDwmCompositionChanged) |
| 106 |
| 107 // Non-atlcrack.h handlers |
| 108 MESSAGE_HANDLER_EX(WM_GETOBJECT, OnGetObject) |
| 109 MESSAGE_HANDLER_EX(WM_NCMOUSELEAVE, OnMouseLeave) |
| 110 MESSAGE_HANDLER_EX(WM_MOUSELEAVE, OnMouseLeave) |
| 111 |
| 112 // Key events. |
| 113 MESSAGE_HANDLER_EX(WM_KEYDOWN, OnKeyDown) |
| 114 MESSAGE_HANDLER_EX(WM_KEYUP, OnKeyUp) |
| 115 MESSAGE_HANDLER_EX(WM_SYSKEYDOWN, OnKeyDown); |
| 116 MESSAGE_HANDLER_EX(WM_SYSKEYUP, OnKeyUp); |
| 117 |
| 118 // This list is in _ALPHABETICAL_ order! OR I WILL HURT YOU. |
| 119 MSG_WM_ACTIVATE(OnActivate) |
| 120 MSG_WM_ACTIVATEAPP(OnActivateApp) |
| 121 MSG_WM_APPCOMMAND(OnAppCommand) |
| 122 MSG_WM_CANCELMODE(OnCancelMode) |
| 123 MSG_WM_CAPTURECHANGED(OnCaptureChanged) |
| 124 MSG_WM_CLOSE(OnClose) |
| 125 MSG_WM_COMMAND(OnCommand) |
| 126 MSG_WM_CREATE(OnCreate) |
| 127 MSG_WM_DESTROY(OnDestroy) |
| 128 MSG_WM_DISPLAYCHANGE(OnDisplayChange) |
| 129 MSG_WM_ERASEBKGND(OnEraseBkgnd) |
| 130 MSG_WM_ENDSESSION(OnEndSession) |
| 131 MSG_WM_ENTERSIZEMOVE(OnEnterSizeMove) |
| 132 MSG_WM_EXITMENULOOP(OnExitMenuLoop) |
| 133 MSG_WM_EXITSIZEMOVE(OnExitSizeMove) |
| 134 MSG_WM_GETMINMAXINFO(OnGetMinMaxInfo) |
| 135 MSG_WM_HSCROLL(OnHScroll) |
| 136 MSG_WM_INITMENU(OnInitMenu) |
| 137 MSG_WM_INITMENUPOPUP(OnInitMenuPopup) |
| 138 MSG_WM_KILLFOCUS(OnKillFocus) |
| 139 MSG_WM_MOUSEACTIVATE(OnMouseActivate) |
| 140 MSG_WM_MOVE(OnMove) |
| 141 MSG_WM_MOVING(OnMoving) |
| 142 MSG_WM_NCACTIVATE(OnNCActivate) |
| 143 MSG_WM_NCCALCSIZE(OnNCCalcSize) |
| 144 MESSAGE_HANDLER_EX(WM_NCHITTEST, OnNCHitTest) |
| 145 MSG_WM_NCPAINT(OnNCPaint) |
| 146 MSG_WM_NOTIFY(OnNotify) |
| 147 MSG_WM_PAINT(OnPaint) |
| 148 MSG_WM_POWERBROADCAST(OnPowerBroadcast) |
| 149 MSG_WM_SETFOCUS(OnSetFocus) |
| 150 MSG_WM_SETICON(OnSetIcon) |
| 151 MSG_WM_SETTEXT(OnSetText) |
| 152 MSG_WM_SETTINGCHANGE(OnSettingChange) |
| 153 MSG_WM_SIZE(OnSize) |
| 154 MSG_WM_SYSCOMMAND(OnSysCommand) |
| 155 MSG_WM_THEMECHANGED(OnThemeChanged) |
| 156 MSG_WM_VSCROLL(OnVScroll) |
| 157 MSG_WM_WINDOWPOSCHANGING(OnWindowPosChanging) |
| 158 MSG_WM_WINDOWPOSCHANGED(OnWindowPosChanged) |
| 159 END_MSG_MAP() |
| 160 |
| 161 virtual void OnActivate(UINT action, BOOL minimized, HWND window); |
| 162 virtual void OnActivateApp(BOOL active, DWORD thread_id); |
| 163 virtual LRESULT OnAppCommand(HWND window, short app_command, WORD device, |
| 164 int keystate); |
| 165 virtual void OnCancelMode(); |
| 166 virtual void OnCaptureChanged(HWND hwnd); |
| 167 virtual void OnClose(); |
| 168 virtual void OnCommand(UINT notification_code, int command_id, HWND window); |
| 169 virtual LRESULT OnCreate(CREATESTRUCT* create_struct); |
| 170 // WARNING: If you override this be sure and invoke super, otherwise we'll |
| 171 // leak a few things. |
| 172 virtual void OnDestroy(); |
| 173 virtual void OnDisplayChange(UINT bits_per_pixel, CSize screen_size); |
| 174 virtual LRESULT OnDwmCompositionChanged(UINT message, |
| 175 WPARAM w_param, |
| 176 LPARAM l_param); |
| 177 virtual void OnEndSession(BOOL ending, UINT logoff); |
| 178 virtual void OnEnterSizeMove(); |
| 179 virtual LRESULT OnEraseBkgnd(HDC dc); |
| 180 virtual void OnExitMenuLoop(BOOL is_track_popup_menu); |
| 181 virtual void OnExitSizeMove(); |
| 182 virtual LRESULT OnGetObject(UINT message, WPARAM w_param, LPARAM l_param); |
| 183 virtual void OnGetMinMaxInfo(MINMAXINFO* minmax_info); |
| 184 virtual void OnHScroll(int scroll_type, short position, HWND scrollbar); |
| 185 virtual void OnInitMenu(HMENU menu); |
| 186 virtual void OnInitMenuPopup(HMENU menu, UINT position, BOOL is_system_menu); |
| 187 virtual LRESULT OnKeyDown(UINT message, WPARAM w_param, LPARAM l_param); |
| 188 virtual LRESULT OnKeyUp(UINT message, WPARAM w_param, LPARAM l_param); |
| 189 virtual void OnKillFocus(HWND focused_window); |
| 190 virtual LRESULT OnMouseActivate(HWND window, UINT hittest_code, UINT message); |
| 191 virtual LRESULT OnMouseLeave(UINT message, WPARAM w_param, LPARAM l_param); |
| 192 virtual void OnMove(const CPoint& point); |
| 193 virtual void OnMoving(UINT param, LPRECT new_bounds); |
| 194 virtual LRESULT OnMouseRange(UINT message, WPARAM w_param, LPARAM l_param); |
| 195 virtual LRESULT OnNCActivate(BOOL active); |
| 196 virtual LRESULT OnNCCalcSize(BOOL w_param, LPARAM l_param); |
| 197 virtual LRESULT OnNCHitTest(UINT message, WPARAM w_param, LPARAM l_param); |
| 198 virtual LRESULT OnNCMouseRange(UINT message, WPARAM w_param, LPARAM l_param); |
| 199 virtual void OnNCPaint(HRGN rgn); |
| 200 virtual LRESULT OnNCUAHDrawCaption(UINT message, |
| 201 WPARAM w_param, |
| 202 LPARAM l_param); |
| 203 virtual LRESULT OnNCUAHDrawFrame(UINT message, WPARAM w_param, |
| 204 LPARAM l_param); |
| 205 virtual LRESULT OnNotify(int w_param, NMHDR* l_param); |
| 206 virtual void OnPaint(HDC dc); |
| 207 virtual LRESULT OnPowerBroadcast(DWORD power_event, DWORD data); |
| 208 virtual LRESULT OnReflectedMessage(UINT message, WPARAM w_param, |
| 209 LPARAM l_param); |
| 210 virtual void OnSetFocus(HWND focused_window); |
| 211 virtual LRESULT OnSetIcon(UINT size_type, HICON new_icon); |
| 212 virtual LRESULT OnSetText(const wchar_t* text); |
| 213 virtual void OnSettingChange(UINT flags, const wchar_t* section); |
| 214 virtual void OnSize(UINT param, const CSize& size); |
| 215 virtual void OnSysCommand(UINT notification_code, CPoint click); |
| 216 virtual void OnThemeChanged(); |
| 217 virtual void OnVScroll(int scroll_type, short position, HWND scrollbar); |
| 218 virtual void OnWindowPosChanging(WINDOWPOS* window_pos); |
| 219 virtual void OnWindowPosChanged(WINDOWPOS* window_pos); |
| 220 |
| 221 // Deletes this window as it is destroyed, override to provide different |
| 222 // behavior. |
| 223 virtual void OnFinalMessage(HWND window); |
| 224 |
| 225 // Overridden from WindowImpl: |
| 226 virtual HICON GetDefaultWindowIcon() const; |
| 227 virtual LRESULT OnWndProc(UINT message, WPARAM w_param, LPARAM l_param); |
| 228 |
| 229 // Start tracking all mouse events so that this window gets sent mouse leave |
| 230 // messages too. |
| 231 void TrackMouseEvents(DWORD mouse_tracking_flags); |
| 232 |
| 233 bool ProcessMouseRange(UINT message, WPARAM w_param, LPARAM l_param, |
| 234 bool non_client); |
| 235 void ProcessMouseMoved(const CPoint& point, UINT flags, bool is_nonclient); |
| 236 void ProcessMouseExited(); |
| 237 |
| 238 // Fills out a MSG struct with the supplied values. |
| 239 void MakeMSG(MSG* msg, UINT message, WPARAM w_param, LPARAM l_param) const; |
| 240 |
| 241 void CloseNow(); |
| 242 |
| 243 bool IsLayeredWindow() const; |
| 244 |
| 245 // A listener implementation that handles events received here. |
| 246 NativeWidgetListener* listener_; |
| 247 |
| 248 // The flags currently being used with TrackMouseEvent to track mouse |
| 249 // messages. 0 if there is no active tracking. The value of this member is |
| 250 // used when tracking is canceled. |
| 251 DWORD active_mouse_tracking_flags_; |
| 252 |
| 253 // True when the HWND has event capture. |
| 254 bool has_capture_; |
| 255 |
| 256 // A canvas that contains the window contents in the case of a layered |
| 257 // window. |
| 258 scoped_ptr<gfx::CanvasSkia> window_contents_; |
| 259 |
| 260 // Properties associated with this NativeWidget implementation. |
| 261 // TODO(beng): move to Widget. |
| 262 ViewProps props_; |
| 263 |
| 264 DISALLOW_COPY_AND_ASSIGN(NativeWidgetWin); |
| 265 }; |
| 266 |
| 267 } // namespace internal |
| 268 } // namespace ui |
| 269 |
| 270 #endif // UI_VIEWS_WIDGET_NATIVE_WIDGET_WIN_H_ |
| 271 |
OLD | NEW |