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

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

Issue 5144005: Converts usage of SetProp/GetProp to a map. Even after making sure we (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/chrome
Patch Set: Fix build Created 10 years, 1 month 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/accessibility/view_accessibility.cc ('k') | views/controls/native_control_win.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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 #include "views/controls/native_control.h" 5 #include "views/controls/native_control.h"
6 6
7 #include <atlbase.h> 7 #include <atlbase.h>
8 #include <atlapp.h> 8 #include <atlapp.h>
9 #include <atlcrack.h> 9 #include <atlcrack.h>
10 #include <atlframe.h> 10 #include <atlframe.h>
11 #include <atlmisc.h> 11 #include <atlmisc.h>
12 12
13 #include "app/keyboard_code_conversion_win.h" 13 #include "app/keyboard_code_conversion_win.h"
14 #include "app/keyboard_codes.h" 14 #include "app/keyboard_codes.h"
15 #include "app/l10n_util_win.h" 15 #include "app/l10n_util_win.h"
16 #include "app/win/scoped_prop.h" 16 #include "app/view_prop.h"
17 #include "base/logging.h" 17 #include "base/logging.h"
18 #include "base/scoped_ptr.h" 18 #include "base/scoped_ptr.h"
19 #include "base/win_util.h" 19 #include "base/win_util.h"
20 #include "gfx/native_theme_win.h" 20 #include "gfx/native_theme_win.h"
21 #include "views/background.h" 21 #include "views/background.h"
22 #include "views/border.h" 22 #include "views/border.h"
23 #include "views/controls/native/native_view_host.h" 23 #include "views/controls/native/native_view_host.h"
24 #include "views/focus/focus_manager.h" 24 #include "views/focus/focus_manager.h"
25 #include "views/widget/widget.h" 25 #include "views/widget/widget.h"
26 26
27 using app::ViewProp;
28
27 namespace views { 29 namespace views {
28 30
29 // Maps to the NativeControl. 31 // Maps to the NativeControl.
30 static const wchar_t* const kNativeControlKey = L"__NATIVE_CONTROL__"; 32 static const char* const kNativeControlKey = "__NATIVE_CONTROL__";
31 33
32 class NativeControlContainer : public CWindowImpl<NativeControlContainer, 34 class NativeControlContainer : public CWindowImpl<NativeControlContainer,
33 CWindow, 35 CWindow,
34 CWinTraits<WS_CHILD | WS_CLIPSIBLINGS | 36 CWinTraits<WS_CHILD | WS_CLIPSIBLINGS |
35 WS_CLIPCHILDREN>> { 37 WS_CLIPCHILDREN>> {
36 public: 38 public:
37 explicit NativeControlContainer(NativeControl* parent) 39 explicit NativeControlContainer(NativeControl* parent)
38 : parent_(parent), 40 : parent_(parent),
39 control_(NULL), 41 control_(NULL),
40 original_handler_(NULL) { 42 original_handler_(NULL) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 84
83 private: 85 private:
84 friend class NativeControl; 86 friend class NativeControl;
85 87
86 LRESULT OnCreate(LPCREATESTRUCT create_struct) { 88 LRESULT OnCreate(LPCREATESTRUCT create_struct) {
87 control_ = parent_->CreateNativeControl(m_hWnd); 89 control_ = parent_->CreateNativeControl(m_hWnd);
88 90
89 // We subclass the control hwnd so we get the WM_KEYDOWN messages. 91 // We subclass the control hwnd so we get the WM_KEYDOWN messages.
90 original_handler_ = win_util::SetWindowProc( 92 original_handler_ = win_util::SetWindowProc(
91 control_, &NativeControl::NativeControlWndProc); 93 control_, &NativeControl::NativeControlWndProc);
92 prop_.reset( 94 prop_.reset(new ViewProp(control_, kNativeControlKey , parent_));
93 new app::win::ScopedProp(control_, kNativeControlKey , parent_));
94 95
95 ::ShowWindow(control_, SW_SHOW); 96 ::ShowWindow(control_, SW_SHOW);
96 return 1; 97 return 1;
97 } 98 }
98 99
99 LRESULT OnEraseBkgnd(HDC dc) { 100 LRESULT OnEraseBkgnd(HDC dc) {
100 return 1; 101 return 1;
101 } 102 }
102 103
103 void OnPaint(HDC ignore) { 104 void OnPaint(HDC ignore) {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 LRESULT OnCtlColorStatic(HDC dc, HWND control) { 160 LRESULT OnCtlColorStatic(HDC dc, HWND control) {
160 return OnCtlColor(WM_CTLCOLORSTATIC, dc, control); 161 return OnCtlColor(WM_CTLCOLORSTATIC, dc, control);
161 } 162 }
162 163
163 NativeControl* parent_; 164 NativeControl* parent_;
164 HWND control_; 165 HWND control_;
165 166
166 // Message handler that was set before we reset it. 167 // Message handler that was set before we reset it.
167 WNDPROC original_handler_; 168 WNDPROC original_handler_;
168 169
169 scoped_ptr<app::win::ScopedProp> prop_; 170 scoped_ptr<ViewProp> prop_;
170 171
171 DISALLOW_COPY_AND_ASSIGN(NativeControlContainer); 172 DISALLOW_COPY_AND_ASSIGN(NativeControlContainer);
172 }; 173 };
173 174
174 NativeControl::NativeControl() : hwnd_view_(NULL), 175 NativeControl::NativeControl() : hwnd_view_(NULL),
175 container_(NULL), 176 container_(NULL),
176 fixed_width_(-1), 177 fixed_width_(-1),
177 horizontal_alignment_(CENTER), 178 horizontal_alignment_(CENTER),
178 fixed_height_(-1), 179 fixed_height_(-1),
179 vertical_alignment_(CENTER) { 180 vertical_alignment_(CENTER) {
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 ex_style |= l10n_util::GetExtendedTooltipStyles(); 357 ex_style |= l10n_util::GetExtendedTooltipStyles();
357 358
358 return ex_style; 359 return ex_style;
359 } 360 }
360 361
361 // static 362 // static
362 LRESULT CALLBACK NativeControl::NativeControlWndProc(HWND window, 363 LRESULT CALLBACK NativeControl::NativeControlWndProc(HWND window,
363 UINT message, 364 UINT message,
364 WPARAM w_param, 365 WPARAM w_param,
365 LPARAM l_param) { 366 LPARAM l_param) {
366 NativeControl* native_control = 367 NativeControl* native_control = static_cast<NativeControl*>(
367 static_cast<NativeControl*>(GetProp(window, kNativeControlKey)); 368 ViewProp::GetValue(window, kNativeControlKey));
368 DCHECK(native_control); 369 DCHECK(native_control);
369 WNDPROC original_handler = native_control->container_->original_handler_; 370 WNDPROC original_handler = native_control->container_->original_handler_;
370 DCHECK(original_handler); 371 DCHECK(original_handler);
371 372
372 if (message == WM_KEYDOWN && 373 if (message == WM_KEYDOWN &&
373 native_control->OnKeyDown(app::KeyboardCodeForWindowsKeyCode(w_param))) { 374 native_control->OnKeyDown(app::KeyboardCodeForWindowsKeyCode(w_param))) {
374 return 0; 375 return 0;
375 } else if (message == WM_SETFOCUS) { 376 } else if (message == WM_SETFOCUS) {
376 // Let the focus manager know that the focus changed. 377 // Let the focus manager know that the focus changed.
377 FocusManager* focus_manager = native_control->GetFocusManager(); 378 FocusManager* focus_manager = native_control->GetFocusManager();
378 if (focus_manager) { 379 if (focus_manager) {
379 focus_manager->SetFocusedView(native_control); 380 focus_manager->SetFocusedView(native_control);
380 } else { 381 } else {
381 NOTREACHED(); 382 NOTREACHED();
382 } 383 }
383 } else if (message == WM_DESTROY) { 384 } else if (message == WM_DESTROY) {
384 win_util::SetWindowProc(window, 385 win_util::SetWindowProc(window,
385 reinterpret_cast<WNDPROC>(original_handler)); 386 reinterpret_cast<WNDPROC>(original_handler));
386 native_control->container_->prop_.reset(); 387 native_control->container_->prop_.reset();
387 } 388 }
388 389
389 return CallWindowProc(reinterpret_cast<WNDPROC>(original_handler), window, 390 return CallWindowProc(reinterpret_cast<WNDPROC>(original_handler), window,
390 message, w_param, l_param); 391 message, w_param, l_param);
391 } 392 }
392 393
393 } // namespace views 394 } // namespace views
OLDNEW
« no previous file with comments | « views/accessibility/view_accessibility.cc ('k') | views/controls/native_control_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698