| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef UI_VIEWS_WIN_HWND_MESSAGE_HANDLER_H_ | 5 #ifndef UI_VIEWS_WIN_HWND_MESSAGE_HANDLER_H_ |
| 6 #define UI_VIEWS_WIN_HWND_MESSAGE_HANDLER_H_ | 6 #define UI_VIEWS_WIN_HWND_MESSAGE_HANDLER_H_ |
| 7 | 7 |
| 8 #include <atlbase.h> | 8 #include <atlbase.h> |
| 9 #include <atlapp.h> | 9 #include <atlapp.h> |
| 10 #include <atlmisc.h> | 10 #include <atlmisc.h> |
| 11 #include <windows.h> | 11 #include <windows.h> |
| 12 | 12 |
| 13 #include <set> | 13 #include <set> |
| 14 | 14 |
| 15 #include "base/basictypes.h" | 15 #include "base/basictypes.h" |
| 16 #include "base/compiler_specific.h" | 16 #include "base/compiler_specific.h" |
| 17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
| 18 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
| 19 #include "base/message_loop.h" | 19 #include "base/message_loop.h" |
| 20 #include "base/string16.h" | 20 #include "base/string16.h" |
| 21 #include "base/win/win_util.h" |
| 21 #include "ui/base/accessibility/accessibility_types.h" | 22 #include "ui/base/accessibility/accessibility_types.h" |
| 22 #include "ui/base/ui_base_types.h" | 23 #include "ui/base/ui_base_types.h" |
| 24 #include "ui/base/win/window_impl.h" |
| 23 #include "ui/gfx/rect.h" | 25 #include "ui/gfx/rect.h" |
| 24 #include "ui/views/ime/input_method_delegate.h" | 26 #include "ui/views/ime/input_method_delegate.h" |
| 25 #include "ui/views/views_export.h" | 27 #include "ui/views/views_export.h" |
| 26 | 28 |
| 27 namespace gfx { | 29 namespace gfx { |
| 28 class Canvas; | 30 class Canvas; |
| 29 class ImageSkia; | 31 class ImageSkia; |
| 30 class Insets; | 32 class Insets; |
| 31 } | 33 } |
| 32 | 34 |
| 33 namespace views { | 35 namespace views { |
| 34 | 36 |
| 35 class FullscreenHandler; | 37 class FullscreenHandler; |
| 36 class HWNDMessageHandlerDelegate; | 38 class HWNDMessageHandlerDelegate; |
| 37 class InputMethod; | 39 class InputMethod; |
| 38 | 40 |
| 39 VIEWS_EXPORT bool IsAeroGlassEnabled(); | 41 VIEWS_EXPORT bool IsAeroGlassEnabled(); |
| 40 | 42 |
| 43 // These two messages aren't defined in winuser.h, but they are sent to windows |
| 44 // with captions. They appear to paint the window caption and frame. |
| 45 // Unfortunately if you override the standard non-client rendering as we do |
| 46 // with CustomFrameWindow, sometimes Windows (not deterministically |
| 47 // reproducibly but definitely frequently) will send these messages to the |
| 48 // window and paint the standard caption/title over the top of the custom one. |
| 49 // So we need to handle these messages in CustomFrameWindow to prevent this |
| 50 // from happening. |
| 51 const int WM_NCUAHDRAWCAPTION = 0xAE; |
| 52 const int WM_NCUAHDRAWFRAME = 0xAF; |
| 53 |
| 41 // An object that handles messages for a HWND that implements the views | 54 // An object that handles messages for a HWND that implements the views |
| 42 // "Custom Frame" look. The purpose of this class is to isolate the windows- | 55 // "Custom Frame" look. The purpose of this class is to isolate the windows- |
| 43 // specific message handling from the code that wraps it. It is intended to be | 56 // specific message handling from the code that wraps it. It is intended to be |
| 44 // used by both a views::NativeWidget and an aura::RootWindowHost | 57 // used by both a views::NativeWidget and an aura::RootWindowHost |
| 45 // implementation. | 58 // implementation. |
| 46 // TODO(beng): This object should eventually *become* the WindowImpl. | 59 // TODO(beng): This object should eventually *become* the WindowImpl. |
| 47 class VIEWS_EXPORT HWNDMessageHandler : public internal::InputMethodDelegate, | 60 class VIEWS_EXPORT HWNDMessageHandler : public ui::WindowImpl, |
| 61 public internal::InputMethodDelegate, |
| 48 public MessageLoopForUI::Observer { | 62 public MessageLoopForUI::Observer { |
| 49 public: | 63 public: |
| 50 explicit HWNDMessageHandler(HWNDMessageHandlerDelegate* delegate); | 64 explicit HWNDMessageHandler(HWNDMessageHandlerDelegate* delegate); |
| 51 ~HWNDMessageHandler(); | 65 ~HWNDMessageHandler(); |
| 52 | 66 |
| 53 void Init(const gfx::Rect& bounds); | 67 void Init(HWND parent, const gfx::Rect& bounds); |
| 54 void InitModalType(ui::ModalType modal_type); | 68 void InitModalType(ui::ModalType modal_type); |
| 55 | 69 |
| 56 void Close(); | 70 void Close(); |
| 57 void CloseNow(); | 71 void CloseNow(); |
| 58 | 72 |
| 59 gfx::Rect GetWindowBoundsInScreen() const; | 73 gfx::Rect GetWindowBoundsInScreen() const; |
| 60 gfx::Rect GetClientAreaBoundsInScreen() const; | 74 gfx::Rect GetClientAreaBoundsInScreen() const; |
| 61 gfx::Rect GetRestoredBounds() const; | 75 gfx::Rect GetRestoredBounds() const; |
| 62 void GetWindowPlacement(gfx::Rect* bounds, | 76 void GetWindowPlacement(gfx::Rect* bounds, |
| 63 ui::WindowShowState* show_state) const; | 77 ui::WindowShowState* show_state) const; |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 void OnEndSession(BOOL ending, UINT logoff); | 170 void OnEndSession(BOOL ending, UINT logoff); |
| 157 void OnEnterSizeMove(); | 171 void OnEnterSizeMove(); |
| 158 LRESULT OnEraseBkgnd(HDC dc); | 172 LRESULT OnEraseBkgnd(HDC dc); |
| 159 void OnExitMenuLoop(BOOL is_track_popup_menu); | 173 void OnExitMenuLoop(BOOL is_track_popup_menu); |
| 160 void OnExitSizeMove(); | 174 void OnExitSizeMove(); |
| 161 void OnHScroll(int scroll_type, short position, HWND scrollbar); | 175 void OnHScroll(int scroll_type, short position, HWND scrollbar); |
| 162 void OnGetMinMaxInfo(MINMAXINFO* minmax_info); | 176 void OnGetMinMaxInfo(MINMAXINFO* minmax_info); |
| 163 LRESULT OnGetObject(UINT message, WPARAM w_param, LPARAM l_param); | 177 LRESULT OnGetObject(UINT message, WPARAM w_param, LPARAM l_param); |
| 164 LRESULT OnImeMessages(UINT message, WPARAM w_param, LPARAM l_param); | 178 LRESULT OnImeMessages(UINT message, WPARAM w_param, LPARAM l_param); |
| 165 void OnInitMenu(HMENU menu); | 179 void OnInitMenu(HMENU menu); |
| 166 void OnInitMenuPopup(); | 180 void OnInitMenuPopup(HMENU menu, UINT position, BOOL is_system_menu); |
| 167 void OnInputLangChange(DWORD character_set, HKL input_language_id); | 181 void OnInputLangChange(DWORD character_set, HKL input_language_id); |
| 168 LRESULT OnKeyEvent(UINT message, WPARAM w_param, LPARAM l_param); | 182 LRESULT OnKeyEvent(UINT message, WPARAM w_param, LPARAM l_param); |
| 169 void OnKillFocus(HWND focused_window); | 183 void OnKillFocus(HWND focused_window); |
| 170 LRESULT OnMouseActivate(UINT message, WPARAM w_param, LPARAM l_param); | 184 LRESULT OnMouseActivate(UINT message, WPARAM w_param, LPARAM l_param); |
| 171 LRESULT OnMouseRange(UINT message, WPARAM w_param, LPARAM l_param); | 185 LRESULT OnMouseRange(UINT message, WPARAM w_param, LPARAM l_param); |
| 172 void OnMove(const CPoint& point); | 186 void OnMove(const CPoint& point); |
| 173 void OnMoving(UINT param, const RECT* new_bounds); | 187 void OnMoving(UINT param, const RECT* new_bounds); |
| 174 LRESULT OnNCActivate(BOOL active); | 188 LRESULT OnNCActivate(BOOL active); |
| 175 LRESULT OnNCCalcSize(BOOL mode, LPARAM l_param); | 189 LRESULT OnNCCalcSize(BOOL mode, LPARAM l_param); |
| 176 LRESULT OnNCHitTest(const CPoint& point); | 190 LRESULT OnNCHitTest(const CPoint& point); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 187 LRESULT OnSetText(const wchar_t* text); | 201 LRESULT OnSetText(const wchar_t* text); |
| 188 void OnSettingChange(UINT flags, const wchar_t* section); | 202 void OnSettingChange(UINT flags, const wchar_t* section); |
| 189 void OnSize(UINT param, const CSize& size); | 203 void OnSize(UINT param, const CSize& size); |
| 190 void OnSysCommand(UINT notification_code, const CPoint& point); | 204 void OnSysCommand(UINT notification_code, const CPoint& point); |
| 191 void OnThemeChanged(); | 205 void OnThemeChanged(); |
| 192 LRESULT OnTouchEvent(UINT message, WPARAM w_param, LPARAM l_param); | 206 LRESULT OnTouchEvent(UINT message, WPARAM w_param, LPARAM l_param); |
| 193 void OnVScroll(int scroll_type, short position, HWND scrollbar); | 207 void OnVScroll(int scroll_type, short position, HWND scrollbar); |
| 194 void OnWindowPosChanging(WINDOWPOS* window_pos); | 208 void OnWindowPosChanging(WINDOWPOS* window_pos); |
| 195 void OnWindowPosChanged(WINDOWPOS* window_pos); | 209 void OnWindowPosChanged(WINDOWPOS* window_pos); |
| 196 | 210 |
| 197 // TODO(beng): Can be removed once this object becomes the WindowImpl. | |
| 198 bool remove_standard_frame() const { return remove_standard_frame_; } | |
| 199 void set_remove_standard_frame(bool remove_standard_frame) { | 211 void set_remove_standard_frame(bool remove_standard_frame) { |
| 200 remove_standard_frame_ = remove_standard_frame; | 212 remove_standard_frame_ = remove_standard_frame; |
| 201 } | 213 } |
| 202 | 214 |
| 203 // Resets the window region for the current widget bounds if necessary. | 215 // Resets the window region for the current widget bounds if necessary. |
| 204 // If |force| is true, the window region is reset to NULL even for native | 216 // If |force| is true, the window region is reset to NULL even for native |
| 205 // frame windows. | 217 // frame windows. |
| 206 void ResetWindowRegion(bool force); | 218 void ResetWindowRegion(bool force); |
| 207 | 219 |
| 208 // TODO(beng): This won't be a style violation once this object becomes the | |
| 209 // WindowImpl. | |
| 210 HWND hwnd(); | |
| 211 HWND hwnd() const; | |
| 212 | |
| 213 private: | 220 private: |
| 214 typedef std::set<DWORD> TouchIDs; | 221 typedef std::set<DWORD> TouchIDs; |
| 215 | 222 |
| 216 // TODO(beng): remove once this is the WindowImpl. | |
| 217 friend class NativeWidgetWin; | |
| 218 | |
| 219 // Overridden from internal::InputMethodDelegate: | 223 // Overridden from internal::InputMethodDelegate: |
| 220 virtual void DispatchKeyEventPostIME(const ui::KeyEvent& key) OVERRIDE; | 224 virtual void DispatchKeyEventPostIME(const ui::KeyEvent& key) OVERRIDE; |
| 221 | 225 |
| 222 // Overridden from WindowImpl: | 226 // Overridden from WindowImpl: |
| 223 virtual HICON GetDefaultWindowIcon() const; | 227 virtual HICON GetDefaultWindowIcon() const OVERRIDE; |
| 224 virtual LRESULT OnWndProc(UINT message, WPARAM w_param, LPARAM l_param); | 228 virtual LRESULT OnWndProc(UINT message, |
| 229 WPARAM w_param, |
| 230 LPARAM l_param) OVERRIDE; |
| 225 | 231 |
| 226 // Overridden from MessageLoopForUI::Observer: | 232 // Overridden from MessageLoopForUI::Observer: |
| 227 virtual base::EventStatus WillProcessEvent( | 233 virtual base::EventStatus WillProcessEvent( |
| 228 const base::NativeEvent& event) OVERRIDE; | 234 const base::NativeEvent& event) OVERRIDE; |
| 229 virtual void DidProcessEvent(const base::NativeEvent& event) OVERRIDE; | 235 virtual void DidProcessEvent(const base::NativeEvent& event) OVERRIDE; |
| 230 | 236 |
| 231 // Can be called after the delegate has had the opportunity to set focus and | 237 // Can be called after the delegate has had the opportunity to set focus and |
| 232 // did not do so. | 238 // did not do so. |
| 233 void SetInitialFocus(); | 239 void SetInitialFocus(); |
| 234 | 240 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 // Stops ignoring SetWindowPos() requests (see below). | 280 // Stops ignoring SetWindowPos() requests (see below). |
| 275 void StopIgnoringPosChanges() { ignore_window_pos_changes_ = false; } | 281 void StopIgnoringPosChanges() { ignore_window_pos_changes_ = false; } |
| 276 | 282 |
| 277 // Synchronously paints the invalid contents of the Widget. | 283 // Synchronously paints the invalid contents of the Widget. |
| 278 void RedrawInvalidRect(); | 284 void RedrawInvalidRect(); |
| 279 | 285 |
| 280 // Synchronously updates the invalid contents of the Widget. Valid for | 286 // Synchronously updates the invalid contents of the Widget. Valid for |
| 281 // layered windows only. | 287 // layered windows only. |
| 282 void RedrawLayeredWindowContents(); | 288 void RedrawLayeredWindowContents(); |
| 283 | 289 |
| 284 // TODO(beng): Remove once this class becomes the WindowImpl. | 290 |
| 285 void SetMsgHandled(BOOL handled); | 291 // Message Handlers ---------------------------------------------------------- |
| 292 |
| 293 BEGIN_MSG_MAP_EX(NativeWidgetWin) |
| 294 // Range handlers must go first! |
| 295 MESSAGE_RANGE_HANDLER_EX(WM_MOUSEFIRST, WM_MOUSELAST, OnMouseRange) |
| 296 MESSAGE_RANGE_HANDLER_EX(WM_NCMOUSEMOVE, WM_NCXBUTTONDBLCLK, OnMouseRange) |
| 297 |
| 298 // Reflected message handler |
| 299 MESSAGE_HANDLER_EX(base::win::kReflectedMessage, OnReflectedMessage) |
| 300 |
| 301 // CustomFrameWindow hacks |
| 302 MESSAGE_HANDLER_EX(WM_NCUAHDRAWCAPTION, OnNCUAHDrawCaption) |
| 303 MESSAGE_HANDLER_EX(WM_NCUAHDRAWFRAME, OnNCUAHDrawFrame) |
| 304 |
| 305 // Vista and newer |
| 306 MESSAGE_HANDLER_EX(WM_DWMCOMPOSITIONCHANGED, OnDwmCompositionChanged) |
| 307 |
| 308 // Non-atlcrack.h handlers |
| 309 MESSAGE_HANDLER_EX(WM_GETOBJECT, OnGetObject) |
| 310 |
| 311 // Mouse events. |
| 312 MESSAGE_HANDLER_EX(WM_MOUSEACTIVATE, OnMouseActivate) |
| 313 MESSAGE_HANDLER_EX(WM_MOUSELEAVE, OnMouseRange) |
| 314 MESSAGE_HANDLER_EX(WM_NCMOUSELEAVE, OnMouseRange) |
| 315 MESSAGE_HANDLER_EX(WM_SETCURSOR, OnSetCursor); |
| 316 |
| 317 // Key events. |
| 318 MESSAGE_HANDLER_EX(WM_KEYDOWN, OnKeyEvent) |
| 319 MESSAGE_HANDLER_EX(WM_KEYUP, OnKeyEvent) |
| 320 MESSAGE_HANDLER_EX(WM_SYSKEYDOWN, OnKeyEvent) |
| 321 MESSAGE_HANDLER_EX(WM_SYSKEYUP, OnKeyEvent) |
| 322 |
| 323 // IME Events. |
| 324 MESSAGE_HANDLER_EX(WM_IME_SETCONTEXT, OnImeMessages) |
| 325 MESSAGE_HANDLER_EX(WM_IME_STARTCOMPOSITION, OnImeMessages) |
| 326 MESSAGE_HANDLER_EX(WM_IME_COMPOSITION, OnImeMessages) |
| 327 MESSAGE_HANDLER_EX(WM_IME_ENDCOMPOSITION, OnImeMessages) |
| 328 MESSAGE_HANDLER_EX(WM_IME_REQUEST, OnImeMessages) |
| 329 MESSAGE_HANDLER_EX(WM_CHAR, OnImeMessages) |
| 330 MESSAGE_HANDLER_EX(WM_SYSCHAR, OnImeMessages) |
| 331 MESSAGE_HANDLER_EX(WM_DEADCHAR, OnImeMessages) |
| 332 MESSAGE_HANDLER_EX(WM_SYSDEADCHAR, OnImeMessages) |
| 333 |
| 334 // Touch Events. |
| 335 MESSAGE_HANDLER_EX(WM_TOUCH, OnTouchEvent) |
| 336 |
| 337 // This list is in _ALPHABETICAL_ order! OR I WILL HURT YOU. |
| 338 MSG_WM_ACTIVATE(OnActivate) |
| 339 MSG_WM_ACTIVATEAPP(OnActivateApp) |
| 340 MSG_WM_APPCOMMAND(OnAppCommand) |
| 341 MSG_WM_CANCELMODE(OnCancelMode) |
| 342 MSG_WM_CAPTURECHANGED(OnCaptureChanged) |
| 343 MSG_WM_CLOSE(OnClose) |
| 344 MSG_WM_COMMAND(OnCommand) |
| 345 MSG_WM_CREATE(OnCreate) |
| 346 MSG_WM_DESTROY(OnDestroy) |
| 347 MSG_WM_DISPLAYCHANGE(OnDisplayChange) |
| 348 MSG_WM_ERASEBKGND(OnEraseBkgnd) |
| 349 MSG_WM_ENDSESSION(OnEndSession) |
| 350 MSG_WM_ENTERSIZEMOVE(OnEnterSizeMove) |
| 351 MSG_WM_EXITMENULOOP(OnExitMenuLoop) |
| 352 MSG_WM_EXITSIZEMOVE(OnExitSizeMove) |
| 353 MSG_WM_GETMINMAXINFO(OnGetMinMaxInfo) |
| 354 MSG_WM_HSCROLL(OnHScroll) |
| 355 MSG_WM_INITMENU(OnInitMenu) |
| 356 MSG_WM_INITMENUPOPUP(OnInitMenuPopup) |
| 357 MSG_WM_INPUTLANGCHANGE(OnInputLangChange) |
| 358 MSG_WM_KILLFOCUS(OnKillFocus) |
| 359 MSG_WM_MOVE(OnMove) |
| 360 MSG_WM_MOVING(OnMoving) |
| 361 MSG_WM_NCACTIVATE(OnNCActivate) |
| 362 MSG_WM_NCCALCSIZE(OnNCCalcSize) |
| 363 MSG_WM_NCHITTEST(OnNCHitTest) |
| 364 MSG_WM_NCPAINT(OnNCPaint) |
| 365 MSG_WM_NOTIFY(OnNotify) |
| 366 MSG_WM_PAINT(OnPaint) |
| 367 MSG_WM_POWERBROADCAST(OnPowerBroadcast) |
| 368 MSG_WM_SETFOCUS(OnSetFocus) |
| 369 MSG_WM_SETICON(OnSetIcon) |
| 370 MSG_WM_SETTEXT(OnSetText) |
| 371 MSG_WM_SETTINGCHANGE(OnSettingChange) |
| 372 MSG_WM_SIZE(OnSize) |
| 373 MSG_WM_SYSCOMMAND(OnSysCommand) |
| 374 MSG_WM_THEMECHANGED(OnThemeChanged) |
| 375 MSG_WM_VSCROLL(OnVScroll) |
| 376 MSG_WM_WINDOWPOSCHANGING(OnWindowPosChanging) |
| 377 MSG_WM_WINDOWPOSCHANGED(OnWindowPosChanged) |
| 378 END_MSG_MAP() |
| 286 | 379 |
| 287 HWNDMessageHandlerDelegate* delegate_; | 380 HWNDMessageHandlerDelegate* delegate_; |
| 288 | 381 |
| 289 scoped_ptr<FullscreenHandler> fullscreen_handler_; | 382 scoped_ptr<FullscreenHandler> fullscreen_handler_; |
| 290 | 383 |
| 291 // The following factory is used for calls to close the NativeWidgetWin | |
| 292 // instance. | |
| 293 base::WeakPtrFactory<HWNDMessageHandler> close_widget_factory_; | 384 base::WeakPtrFactory<HWNDMessageHandler> close_widget_factory_; |
| 294 | 385 |
| 295 bool remove_standard_frame_; | 386 bool remove_standard_frame_; |
| 296 | 387 |
| 297 // Whether the focus should be restored next time we get enabled. Needed to | 388 // Whether the focus should be restored next time we get enabled. Needed to |
| 298 // restore focus correctly when Windows modal dialogs are displayed. | 389 // restore focus correctly when Windows modal dialogs are displayed. |
| 299 bool restore_focus_when_enabled_; | 390 bool restore_focus_when_enabled_; |
| 300 | 391 |
| 301 // Whether all ancestors have been enabled. This is only used if is_modal_ is | 392 // Whether all ancestors have been enabled. This is only used if is_modal_ is |
| 302 // true. | 393 // true. |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 // True if we are allowed to update the layered window from the DIB backing | 474 // True if we are allowed to update the layered window from the DIB backing |
| 384 // store if necessary. | 475 // store if necessary. |
| 385 bool can_update_layered_window_; | 476 bool can_update_layered_window_; |
| 386 | 477 |
| 387 DISALLOW_COPY_AND_ASSIGN(HWNDMessageHandler); | 478 DISALLOW_COPY_AND_ASSIGN(HWNDMessageHandler); |
| 388 }; | 479 }; |
| 389 | 480 |
| 390 } // namespace views | 481 } // namespace views |
| 391 | 482 |
| 392 #endif // UI_VIEWS_WIN_HWND_MESSAGE_HANDLER_H_ | 483 #endif // UI_VIEWS_WIN_HWND_MESSAGE_HANDLER_H_ |
| OLD | NEW |