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

Side by Side Diff: views/controls/native_control_win.cc

Issue 114059: Refactors HWNDView, NativeViewHostGtk and NativeViewHost so that they match t... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « views/controls/native_control_win.h ('k') | views/controls/native_view_host.h » ('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) 2009 The Chromium Authors. All rights reserved. Use of this 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this
2 // source code is governed by a BSD-style license that can be found in the 2 // source code is governed by a BSD-style license that can be found in the
3 // LICENSE file. 3 // LICENSE file.
4 4
5 #include "views/controls/native_control_win.h" 5 #include "views/controls/native_control_win.h"
6 6
7 #include "app/l10n_util_win.h" 7 #include "app/l10n_util_win.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/win_util.h" 9 #include "base/win_util.h"
10 10
11 namespace views { 11 namespace views {
12 12
13 // static 13 // static
14 const wchar_t* NativeControlWin::kNativeControlWinKey = 14 const wchar_t* NativeControlWin::kNativeControlWinKey =
15 L"__NATIVE_CONTROL_WIN__"; 15 L"__NATIVE_CONTROL_WIN__";
16 16
17 static const wchar_t* kNativeControlOriginalWndProcKey = 17 static const wchar_t* kNativeControlOriginalWndProcKey =
18 L"__NATIVE_CONTROL_ORIGINAL_WNDPROC__"; 18 L"__NATIVE_CONTROL_ORIGINAL_WNDPROC__";
19 19
20 // static 20 // static
21 WNDPROC NativeControlWin::original_wndproc_ = NULL; 21 WNDPROC NativeControlWin::original_wndproc_ = NULL;
22 22
23 //////////////////////////////////////////////////////////////////////////////// 23 ////////////////////////////////////////////////////////////////////////////////
24 // NativeControlWin, public: 24 // NativeControlWin, public:
25 25
26 NativeControlWin::NativeControlWin() : HWNDView() { 26 NativeControlWin::NativeControlWin() {
27 } 27 }
28 28
29 NativeControlWin::~NativeControlWin() { 29 NativeControlWin::~NativeControlWin() {
30 HWND hwnd = GetHWND(); 30 HWND hwnd = native_view();
31 if (hwnd) { 31 if (hwnd) {
32 // Destroy the hwnd if it still exists. Otherwise we won't have shut things 32 // Destroy the hwnd if it still exists. Otherwise we won't have shut things
33 // down correctly, leading to leaking and crashing if another message 33 // down correctly, leading to leaking and crashing if another message
34 // comes in for the hwnd. 34 // comes in for the hwnd.
35 Detach(); 35 Detach();
36 DestroyWindow(hwnd); 36 DestroyWindow(hwnd);
37 } 37 }
38 } 38 }
39 39
40 bool NativeControlWin::ProcessMessage(UINT message, WPARAM w_param, 40 bool NativeControlWin::ProcessMessage(UINT message, WPARAM w_param,
41 LPARAM l_param, LRESULT* result) { 41 LPARAM l_param, LRESULT* result) {
42 switch (message) { 42 switch (message) {
43 case WM_CONTEXTMENU: 43 case WM_CONTEXTMENU:
44 ShowContextMenu(gfx::Point(LOWORD(l_param), HIWORD(l_param))); 44 ShowContextMenu(gfx::Point(LOWORD(l_param), HIWORD(l_param)));
45 *result = 0; 45 *result = 0;
46 return true; 46 return true;
47 case WM_CTLCOLORBTN: 47 case WM_CTLCOLORBTN:
48 case WM_CTLCOLORSTATIC: 48 case WM_CTLCOLORSTATIC:
49 *result = GetControlColor(message, reinterpret_cast<HDC>(w_param), 49 *result = GetControlColor(message, reinterpret_cast<HDC>(w_param),
50 GetHWND()); 50 native_view());
51 return true; 51 return true;
52 } 52 }
53 return false; 53 return false;
54 } 54 }
55 55
56 //////////////////////////////////////////////////////////////////////////////// 56 ////////////////////////////////////////////////////////////////////////////////
57 // NativeControlWin, View overrides: 57 // NativeControlWin, View overrides:
58 58
59 void NativeControlWin::SetEnabled(bool enabled) { 59 void NativeControlWin::SetEnabled(bool enabled) {
60 if (IsEnabled() != enabled) { 60 if (IsEnabled() != enabled) {
61 View::SetEnabled(enabled); 61 View::SetEnabled(enabled);
62 if (GetHWND()) 62 if (native_view())
63 EnableWindow(GetHWND(), IsEnabled()); 63 EnableWindow(native_view(), IsEnabled());
64 } 64 }
65 } 65 }
66 66
67 void NativeControlWin::ViewHierarchyChanged(bool is_add, View* parent, 67 void NativeControlWin::ViewHierarchyChanged(bool is_add, View* parent,
68 View* child) { 68 View* child) {
69 // Call the base class to hide the view if we're being removed.
70 NativeViewHost::ViewHierarchyChanged(is_add, parent, child);
71
69 // Create the HWND when we're added to a valid Widget. Many controls need a 72 // Create the HWND when we're added to a valid Widget. Many controls need a
70 // parent HWND to function properly. 73 // parent HWND to function properly.
71 if (is_add && GetWidget() && !GetHWND()) 74 if (is_add && GetWidget() && !native_view())
72 CreateNativeControl(); 75 CreateNativeControl();
73
74 // Call the base class to hide the view if we're being removed.
75 HWNDView::ViewHierarchyChanged(is_add, parent, child);
76 } 76 }
77 77
78 void NativeControlWin::VisibilityChanged(View* starting_from, bool is_visible) { 78 void NativeControlWin::VisibilityChanged(View* starting_from, bool is_visible) {
79 if (!is_visible) { 79 if (!is_visible) {
80 // We destroy the child control HWND when we become invisible because of the 80 // We destroy the child control HWND when we become invisible because of the
81 // performance cost of maintaining many HWNDs. 81 // performance cost of maintaining many HWNDs.
82 HWND hwnd = GetHWND(); 82 HWND hwnd = native_view();
83 Detach(); 83 Detach();
84 DestroyWindow(hwnd); 84 DestroyWindow(hwnd);
85 } else if (!GetHWND()) { 85 } else if (!native_view()) {
86 CreateNativeControl(); 86 CreateNativeControl();
87 } 87 }
88 } 88 }
89 89
90 void NativeControlWin::Focus() { 90 void NativeControlWin::Focus() {
91 DCHECK(GetHWND()); 91 DCHECK(native_view());
92 SetFocus(GetHWND()); 92 SetFocus(native_view());
93 } 93 }
94 94
95 //////////////////////////////////////////////////////////////////////////////// 95 ////////////////////////////////////////////////////////////////////////////////
96 // NativeControlWin, protected: 96 // NativeControlWin, protected:
97 97
98 void NativeControlWin::ShowContextMenu(const gfx::Point& location) { 98 void NativeControlWin::ShowContextMenu(const gfx::Point& location) {
99 if (!GetContextMenuController()) 99 if (!GetContextMenuController())
100 return; 100 return;
101 101
102 int x = location.x(); 102 int x = location.x();
(...skipping 13 matching lines...) Expand all
116 // this object when it receives messages from it. 116 // this object when it receives messages from it.
117 SetProp(native_control, kNativeControlWinKey, this); 117 SetProp(native_control, kNativeControlWinKey, this);
118 118
119 // Subclass the window so we can monitor for key presses. 119 // Subclass the window so we can monitor for key presses.
120 original_wndproc_ = 120 original_wndproc_ =
121 win_util::SetWindowProc(native_control, 121 win_util::SetWindowProc(native_control,
122 &NativeControlWin::NativeControlWndProc); 122 &NativeControlWin::NativeControlWndProc);
123 SetProp(native_control, kNativeControlOriginalWndProcKey, original_wndproc_); 123 SetProp(native_control, kNativeControlOriginalWndProcKey, original_wndproc_);
124 124
125 Attach(native_control); 125 Attach(native_control);
126 // GetHWND() is now valid. 126 // native_view() is now valid.
127 127
128 // Update the newly created HWND with any resident enabled state. 128 // Update the newly created HWND with any resident enabled state.
129 EnableWindow(GetHWND(), IsEnabled()); 129 EnableWindow(native_view(), IsEnabled());
130 130
131 // This message ensures that the focus border is shown. 131 // This message ensures that the focus border is shown.
132 SendMessage(GetHWND(), WM_CHANGEUISTATE, 132 SendMessage(native_view(), WM_CHANGEUISTATE,
133 MAKEWPARAM(UIS_CLEAR, UISF_HIDEFOCUS), 0); 133 MAKEWPARAM(UIS_CLEAR, UISF_HIDEFOCUS), 0);
134 } 134 }
135 135
136 DWORD NativeControlWin::GetAdditionalExStyle() const { 136 DWORD NativeControlWin::GetAdditionalExStyle() const {
137 // If the UI for the view is mirrored, we should make sure we add the 137 // If the UI for the view is mirrored, we should make sure we add the
138 // extended window style for a right-to-left layout so the subclass creates 138 // extended window style for a right-to-left layout so the subclass creates
139 // a mirrored HWND for the underlying control. 139 // a mirrored HWND for the underlying control.
140 DWORD ex_style = 0; 140 DWORD ex_style = 0;
141 if (UILayoutIsRightToLeft()) 141 if (UILayoutIsRightToLeft())
142 ex_style |= l10n_util::GetExtendedStyles(); 142 ex_style |= l10n_util::GetExtendedStyles();
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 } else if (message == WM_DESTROY) { 189 } else if (message == WM_DESTROY) {
190 win_util::SetWindowProc(window, native_control->original_wndproc_); 190 win_util::SetWindowProc(window, native_control->original_wndproc_);
191 RemoveProp(window, kNativeControlWinKey); 191 RemoveProp(window, kNativeControlWinKey);
192 } 192 }
193 193
194 return CallWindowProc(native_control->original_wndproc_, window, message, 194 return CallWindowProc(native_control->original_wndproc_, window, message,
195 w_param, l_param); 195 w_param, l_param);
196 } 196 }
197 197
198 } // namespace views 198 } // namespace views
OLDNEW
« no previous file with comments | « views/controls/native_control_win.h ('k') | views/controls/native_view_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698