OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 CHROME_FRAME_INFOBARS_INTERNAL_SUBCLASSING_WINDOW_WITH_DELEGATE_H_ | 5 #ifndef CHROME_FRAME_INFOBARS_INTERNAL_SUBCLASSING_WINDOW_WITH_DELEGATE_H_ |
6 #define CHROME_FRAME_INFOBARS_INTERNAL_SUBCLASSING_WINDOW_WITH_DELEGATE_H_ | 6 #define CHROME_FRAME_INFOBARS_INTERNAL_SUBCLASSING_WINDOW_WITH_DELEGATE_H_ |
7 | 7 |
8 #include <atlbase.h> | 8 #include <atlbase.h> |
9 #include <atlcrack.h> | 9 #include <atlcrack.h> |
10 #include <atlwin.h> | 10 #include <atlwin.h> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "chrome_frame/utils.h" | 15 #include "chrome_frame/pin_module.h" |
16 | 16 |
17 // Implements behavior common to HostWindowManager and DisplacedWindowManager. | 17 // Implements behavior common to HostWindowManager and DisplacedWindowManager. |
18 template<typename T> class SubclassingWindowWithDelegate | 18 template<typename T> class SubclassingWindowWithDelegate |
19 : public CWindowImpl<T> { | 19 : public CWindowImpl<T> { |
20 public: | 20 public: |
21 // Allows clients to modify the dimensions of the displaced window. | 21 // Allows clients to modify the dimensions of the displaced window. |
22 // Through its destructor, allows clients to know when the subclassed window | 22 // Through its destructor, allows clients to know when the subclassed window |
23 // is destroyed. | 23 // is destroyed. |
24 class Delegate { | 24 class Delegate { |
25 public: | 25 public: |
(...skipping 20 matching lines...) Expand all Loading... |
46 DCHECK(delegate_ == NULL); | 46 DCHECK(delegate_ == NULL); |
47 scoped_ptr<Delegate> new_delegate(delegate); | 47 scoped_ptr<Delegate> new_delegate(delegate); |
48 | 48 |
49 if (!::IsWindow(hwnd) || !SubclassWindow(hwnd)) { | 49 if (!::IsWindow(hwnd) || !SubclassWindow(hwnd)) { |
50 PLOG(ERROR) << "Failed to subclass an HWND"; | 50 PLOG(ERROR) << "Failed to subclass an HWND"; |
51 return false; | 51 return false; |
52 } | 52 } |
53 | 53 |
54 // Ensure we won't be unloaded while our window proc is attached to the tab | 54 // Ensure we won't be unloaded while our window proc is attached to the tab |
55 // window. | 55 // window. |
56 PinModule(); | 56 chrome_frame::PinModule(); |
57 | 57 |
58 delegate_.swap(new_delegate); | 58 delegate_.swap(new_delegate); |
59 | 59 |
60 return true; | 60 return true; |
61 } | 61 } |
62 | 62 |
63 // Returns the delegate associated with the specified window, if any. | 63 // Returns the delegate associated with the specified window, if any. |
64 static Delegate* GetDelegateForHwnd(HWND hwnd) { | 64 static Delegate* GetDelegateForHwnd(HWND hwnd) { |
65 return reinterpret_cast<Delegate*>( | 65 return reinterpret_cast<Delegate*>( |
66 ::SendMessage(hwnd, RegisterGetDelegateMessage(), NULL, NULL)); | 66 ::SendMessage(hwnd, RegisterGetDelegateMessage(), NULL, NULL)); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 LPARAM lparam, | 98 LPARAM lparam, |
99 BOOL& handled) { | 99 BOOL& handled) { |
100 return reinterpret_cast<LRESULT>(delegate_.get()); | 100 return reinterpret_cast<LRESULT>(delegate_.get()); |
101 } | 101 } |
102 | 102 |
103 scoped_ptr<Delegate> delegate_; | 103 scoped_ptr<Delegate> delegate_; |
104 DISALLOW_COPY_AND_ASSIGN(SubclassingWindowWithDelegate); | 104 DISALLOW_COPY_AND_ASSIGN(SubclassingWindowWithDelegate); |
105 }; // class SubclassingWindowWithDelegate | 105 }; // class SubclassingWindowWithDelegate |
106 | 106 |
107 #endif // CHROME_FRAME_INFOBARS_INTERNAL_SUBCLASSING_WINDOW_WITH_DELEGATE_H_ | 107 #endif // CHROME_FRAME_INFOBARS_INTERNAL_SUBCLASSING_WINDOW_WITH_DELEGATE_H_ |
OLD | NEW |