Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Side by Side Diff: ui/views/win/hwnd_message_handler.h

Issue 1107353003: win: Move HWNDMessageHandler's WeakPtrFactory member to the end. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | ui/views/win/hwnd_message_handler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <windows.h> 8 #include <windows.h>
9 9
10 #include <set> 10 #include <set>
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 // Unfortunately if you override the standard non-client rendering as we do 48 // Unfortunately if you override the standard non-client rendering as we do
49 // with CustomFrameWindow, sometimes Windows (not deterministically 49 // with CustomFrameWindow, sometimes Windows (not deterministically
50 // reproducibly but definitely frequently) will send these messages to the 50 // reproducibly but definitely frequently) will send these messages to the
51 // window and paint the standard caption/title over the top of the custom one. 51 // window and paint the standard caption/title over the top of the custom one.
52 // So we need to handle these messages in CustomFrameWindow to prevent this 52 // So we need to handle these messages in CustomFrameWindow to prevent this
53 // from happening. 53 // from happening.
54 const int WM_NCUAHDRAWCAPTION = 0xAE; 54 const int WM_NCUAHDRAWCAPTION = 0xAE;
55 const int WM_NCUAHDRAWFRAME = 0xAF; 55 const int WM_NCUAHDRAWFRAME = 0xAF;
56 56
57 // IsMsgHandled() and BEGIN_SAFE_MSG_MAP_EX are a modified version of 57 // IsMsgHandled() and BEGIN_SAFE_MSG_MAP_EX are a modified version of
58 // BEGIN_MSG_MAP_EX. The main difference is it adds a WeakPtrFactory member 58 // BEGIN_MSG_MAP_EX. The main difference is it uses a WeakPtrFactory member
59 // (|weak_factory_|) that is used in _ProcessWindowMessage() and changing 59 // (|weak_factory|) that is used in _ProcessWindowMessage() and changing
60 // IsMsgHandled() from a member function to a define that checks if the weak 60 // IsMsgHandled() from a member function to a define that checks if the weak
61 // factory is still valid in addition to the member. Together these allow for 61 // factory is still valid in addition to the member. Together these allow for
62 // |this| to be deleted during dispatch. 62 // |this| to be deleted during dispatch.
63 #define IsMsgHandled() !ref.get() || msg_handled_ 63 #define IsMsgHandled() !ref.get() || msg_handled_
64 64
65 #define BEGIN_SAFE_MSG_MAP_EX(the_class) \ 65 #define BEGIN_SAFE_MSG_MAP_EX(weak_factory) \
66 private: \ 66 private: \
67 base::WeakPtrFactory<the_class> weak_factory_; \
68 BOOL msg_handled_; \ 67 BOOL msg_handled_; \
69 \ 68 \
70 public: \ 69 public: \
71 /* "handled" management for cracked handlers */ \ 70 /* "handled" management for cracked handlers */ \
72 void SetMsgHandled(BOOL handled) { \ 71 void SetMsgHandled(BOOL handled) { \
73 msg_handled_ = handled; \ 72 msg_handled_ = handled; \
74 } \ 73 } \
75 BOOL ProcessWindowMessage(HWND hwnd, \ 74 BOOL ProcessWindowMessage(HWND hwnd, \
76 UINT msg, \ 75 UINT msg, \
77 WPARAM w_param, \ 76 WPARAM w_param, \
78 LPARAM l_param, \ 77 LPARAM l_param, \
79 LRESULT& l_result, \ 78 LRESULT& l_result, \
80 DWORD msg_map_id = 0) { \ 79 DWORD msg_map_id = 0) { \
81 base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr()); \ 80 base::WeakPtr<HWNDMessageHandler> ref(weak_factory.GetWeakPtr()); \
82 BOOL old_msg_handled = msg_handled_; \ 81 BOOL old_msg_handled = msg_handled_; \
83 BOOL ret = _ProcessWindowMessage(hwnd, msg, w_param, l_param, l_result, \ 82 BOOL ret = _ProcessWindowMessage(hwnd, msg, w_param, l_param, l_result, \
84 msg_map_id); \ 83 msg_map_id); \
85 if (ref.get()) \ 84 if (ref.get()) \
86 msg_handled_ = old_msg_handled; \ 85 msg_handled_ = old_msg_handled; \
87 return ret; \ 86 return ret; \
88 } \ 87 } \
89 BOOL _ProcessWindowMessage(HWND hWnd, \ 88 BOOL _ProcessWindowMessage(HWND hWnd, \
90 UINT uMsg, \ 89 UINT uMsg, \
91 WPARAM wParam, \ 90 WPARAM wParam, \
92 LPARAM lParam, \ 91 LPARAM lParam, \
93 LRESULT& lResult, \ 92 LRESULT& lResult, \
94 DWORD dwMsgMapID) { \ 93 DWORD dwMsgMapID) { \
95 base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr()); \ 94 base::WeakPtr<HWNDMessageHandler> ref(weak_factory.GetWeakPtr()); \
96 BOOL bHandled = TRUE; \ 95 BOOL bHandled = TRUE; \
97 hWnd; \ 96 hWnd; \
98 uMsg; \ 97 uMsg; \
99 wParam; \ 98 wParam; \
100 lParam; \ 99 lParam; \
101 lResult; \ 100 lResult; \
102 bHandled; \ 101 bHandled; \
103 switch(dwMsgMapID) { \ 102 switch(dwMsgMapID) { \
104 case 0: 103 case 0:
105 104
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 // Synchronously updates the invalid contents of the Widget. Valid for 307 // Synchronously updates the invalid contents of the Widget. Valid for
309 // layered windows only. 308 // layered windows only.
310 void RedrawLayeredWindowContents(); 309 void RedrawLayeredWindowContents();
311 310
312 // Attempts to force the window to be redrawn, ensuring that it gets 311 // Attempts to force the window to be redrawn, ensuring that it gets
313 // onscreen. 312 // onscreen.
314 void ForceRedrawWindow(int attempts); 313 void ForceRedrawWindow(int attempts);
315 314
316 // Message Handlers ---------------------------------------------------------- 315 // Message Handlers ----------------------------------------------------------
317 316
318 BEGIN_SAFE_MSG_MAP_EX(HWNDMessageHandler) 317 BEGIN_SAFE_MSG_MAP_EX(weak_factory_)
319 // Range handlers must go first! 318 // Range handlers must go first!
320 CR_MESSAGE_RANGE_HANDLER_EX(WM_MOUSEFIRST, WM_MOUSELAST, OnMouseRange) 319 CR_MESSAGE_RANGE_HANDLER_EX(WM_MOUSEFIRST, WM_MOUSELAST, OnMouseRange)
321 CR_MESSAGE_RANGE_HANDLER_EX(WM_NCMOUSEMOVE, 320 CR_MESSAGE_RANGE_HANDLER_EX(WM_NCMOUSEMOVE,
322 WM_NCXBUTTONDBLCLK, 321 WM_NCXBUTTONDBLCLK,
323 OnMouseRange) 322 OnMouseRange)
324 323
325 // CustomFrameWindow hacks 324 // CustomFrameWindow hacks
326 CR_MESSAGE_HANDLER_EX(WM_NCUAHDRAWCAPTION, OnNCUAHDrawCaption) 325 CR_MESSAGE_HANDLER_EX(WM_NCUAHDRAWCAPTION, OnNCUAHDrawCaption)
327 CR_MESSAGE_HANDLER_EX(WM_NCUAHDRAWFRAME, OnNCUAHDrawFrame) 326 CR_MESSAGE_HANDLER_EX(WM_NCUAHDRAWFRAME, OnNCUAHDrawFrame)
328 327
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 long last_mouse_hwheel_time_; 619 long last_mouse_hwheel_time_;
621 620
622 // On Windows Vista and beyond, if we are transitioning from custom frame 621 // On Windows Vista and beyond, if we are transitioning from custom frame
623 // to Aero(glass) we delay setting the DWM related properties in full 622 // to Aero(glass) we delay setting the DWM related properties in full
624 // screen mode as DWM is not supported in full screen windows. We perform 623 // screen mode as DWM is not supported in full screen windows. We perform
625 // the DWM related operations when the window comes out of fullscreen mode. 624 // the DWM related operations when the window comes out of fullscreen mode.
626 // This member variable is set to true if the window is transitioning to 625 // This member variable is set to true if the window is transitioning to
627 // glass. Defaults to false. 626 // glass. Defaults to false.
628 bool dwm_transition_desired_; 627 bool dwm_transition_desired_;
629 628
629 base::WeakPtrFactory<HWNDMessageHandler> weak_factory_;
630
630 DISALLOW_COPY_AND_ASSIGN(HWNDMessageHandler); 631 DISALLOW_COPY_AND_ASSIGN(HWNDMessageHandler);
631 }; 632 };
632 633
633 } // namespace views 634 } // namespace views
634 635
635 #endif // UI_VIEWS_WIN_HWND_MESSAGE_HANDLER_H_ 636 #endif // UI_VIEWS_WIN_HWND_MESSAGE_HANDLER_H_
OLDNEW
« no previous file with comments | « no previous file | ui/views/win/hwnd_message_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698