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

Side by Side Diff: views/widget/widget_win.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/widget/widget_win.h ('k') | no next file » | 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/widget/widget_win.h" 5 #include "views/widget/widget_win.h"
6 6
7 #include "app/keyboard_code_conversion_win.h" 7 #include "app/keyboard_code_conversion_win.h"
8 #include "app/l10n_util_win.h" 8 #include "app/l10n_util_win.h"
9 #include "app/system_monitor.h" 9 #include "app/system_monitor.h"
10 #include "app/view_prop.h"
10 #include "app/win_util.h" 11 #include "app/win_util.h"
11 #include "app/win/scoped_prop.h"
12 #include "base/string_util.h" 12 #include "base/string_util.h"
13 #include "base/win_util.h" 13 #include "base/win_util.h"
14 #include "gfx/canvas_skia.h" 14 #include "gfx/canvas_skia.h"
15 #include "gfx/native_theme_win.h" 15 #include "gfx/native_theme_win.h"
16 #include "gfx/path.h" 16 #include "gfx/path.h"
17 #include "views/accessibility/view_accessibility.h" 17 #include "views/accessibility/view_accessibility.h"
18 #include "views/controls/native_control_win.h" 18 #include "views/controls/native_control_win.h"
19 #include "views/focus/focus_util_win.h" 19 #include "views/focus/focus_util_win.h"
20 #include "views/views_delegate.h" 20 #include "views/views_delegate.h"
21 #include "views/widget/aero_tooltip_manager.h" 21 #include "views/widget/aero_tooltip_manager.h"
22 #include "views/widget/child_window_message_processor.h" 22 #include "views/widget/child_window_message_processor.h"
23 #include "views/widget/default_theme_provider.h" 23 #include "views/widget/default_theme_provider.h"
24 #include "views/widget/drop_target_win.h" 24 #include "views/widget/drop_target_win.h"
25 #include "views/widget/root_view.h" 25 #include "views/widget/root_view.h"
26 #include "views/widget/widget_delegate.h" 26 #include "views/widget/widget_delegate.h"
27 #include "views/window/window_win.h" 27 #include "views/window/window_win.h"
28 28
29 using app::ViewProp;
30
29 namespace views { 31 namespace views {
30 32
31 // Property used to link the HWND to its RootView. 33 // Property used to link the HWND to its RootView.
32 static const wchar_t* const kRootViewWindowProperty = L"__ROOT_VIEW__"; 34 static const char* const kRootViewWindowProperty = "__ROOT_VIEW__";
33 static const wchar_t* kWidgetKey = L"__VIEWS_WIDGET__"; 35
36 // Links the HWND to it's Widget (as a Widget, not a WidgetWin).
37 static const char* const kWidgetKey = "__VIEWS_WIDGET__";
34 38
35 bool WidgetWin::screen_reader_active_ = false; 39 bool WidgetWin::screen_reader_active_ = false;
36 40
37 // A custom MSAA object id used to determine if a screen reader is actively 41 // A custom MSAA object id used to determine if a screen reader is actively
38 // listening for MSAA events. 42 // listening for MSAA events.
39 #define OBJID_CUSTOM 1 43 #define OBJID_CUSTOM 1
40 44
41 RootView* GetRootViewForHWND(HWND hwnd) { 45 RootView* GetRootViewForHWND(HWND hwnd) {
42 return reinterpret_cast<RootView*>(::GetProp(hwnd, kRootViewWindowProperty)); 46 return reinterpret_cast<RootView*>(
47 ViewProp::GetValue(hwnd, kRootViewWindowProperty));
43 } 48 }
44 49
45 /////////////////////////////////////////////////////////////////////////////// 50 ///////////////////////////////////////////////////////////////////////////////
46 // WidgetWin, public 51 // WidgetWin, public
47 52
48 WidgetWin::WidgetWin() 53 WidgetWin::WidgetWin()
49 : close_widget_factory_(this), 54 : close_widget_factory_(this),
50 active_mouse_tracking_flags_(0), 55 active_mouse_tracking_flags_(0),
51 has_capture_(false), 56 has_capture_(false),
52 use_layered_buffer_(true), 57 use_layered_buffer_(true),
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 } 412 }
408 413
409 Window* WidgetWin::GetWindow() { 414 Window* WidgetWin::GetWindow() {
410 return GetWindowImpl(hwnd()); 415 return GetWindowImpl(hwnd());
411 } 416 }
412 417
413 const Window* WidgetWin::GetWindow() const { 418 const Window* WidgetWin::GetWindow() const {
414 return GetWindowImpl(hwnd()); 419 return GetWindowImpl(hwnd());
415 } 420 }
416 421
417 void WidgetWin::SetNativeWindowProperty(const std::wstring& name, void* value) { 422 void WidgetWin::SetNativeWindowProperty(const char* name, void* value) {
418 // Remove the existing property (if any). 423 // Remove the existing property (if any).
419 for (ScopedProps::iterator i = props_.begin(); i != props_.end(); ++i) { 424 for (ViewProps::iterator i = props_.begin(); i != props_.end(); ++i) {
420 if ((*i)->key() == name) { 425 if ((*i)->Key() == name) {
421 props_.erase(i); 426 props_.erase(i);
422 break; 427 break;
423 } 428 }
424 } 429 }
425 430
426 if (value) 431 if (value)
427 props_.push_back(new app::win::ScopedProp(hwnd(), name, value)); 432 props_.push_back(new ViewProp(hwnd(), name, value));
428 } 433 }
429 434
430 void* WidgetWin::GetNativeWindowProperty(const std::wstring& name) { 435 void* WidgetWin::GetNativeWindowProperty(const char* name) {
431 return GetProp(hwnd(), name.c_str()); 436 return ViewProp::GetValue(hwnd(), name);
432 } 437 }
433 438
434 ThemeProvider* WidgetWin::GetThemeProvider() const { 439 ThemeProvider* WidgetWin::GetThemeProvider() const {
435 Widget* widget = GetRootWidget(); 440 Widget* widget = GetRootWidget();
436 if (widget && widget != this) { 441 if (widget && widget != this) {
437 // Attempt to get the theme provider, and fall back to the default theme 442 // Attempt to get the theme provider, and fall back to the default theme
438 // provider if not found. 443 // provider if not found.
439 ThemeProvider* provider = widget->GetThemeProvider(); 444 ThemeProvider* provider = widget->GetThemeProvider();
440 if (provider) 445 if (provider)
441 return provider; 446 return provider;
(...skipping 849 matching lines...) Expand 10 before | Expand all | Expand 10 after
1291 ex_style |= WS_EX_LAYERED; 1296 ex_style |= WS_EX_LAYERED;
1292 if (accept_events != AcceptEvents) 1297 if (accept_events != AcceptEvents)
1293 ex_style |= WS_EX_TRANSPARENT; 1298 ex_style |= WS_EX_TRANSPARENT;
1294 popup->set_window_style(WS_POPUP); 1299 popup->set_window_style(WS_POPUP);
1295 popup->set_window_ex_style(ex_style); 1300 popup->set_window_ex_style(ex_style);
1296 popup->set_delete_on_destroy(delete_on_destroy == DeleteOnDestroy); 1301 popup->set_delete_on_destroy(delete_on_destroy == DeleteOnDestroy);
1297 return popup; 1302 return popup;
1298 } 1303 }
1299 1304
1300 static BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM l_param) { 1305 static BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM l_param) {
1301 RootView* root_view = 1306 RootView* root_view = GetRootViewForHWND(hwnd);
1302 reinterpret_cast<RootView*>(GetProp(hwnd, kRootViewWindowProperty));
1303 if (root_view) { 1307 if (root_view) {
1304 *reinterpret_cast<RootView**>(l_param) = root_view; 1308 *reinterpret_cast<RootView**>(l_param) = root_view;
1305 return FALSE; // Stop enumerating. 1309 return FALSE; // Stop enumerating.
1306 } 1310 }
1307 return TRUE; // Keep enumerating. 1311 return TRUE; // Keep enumerating.
1308 } 1312 }
1309 1313
1310 // static 1314 // static
1311 RootView* Widget::FindRootView(HWND hwnd) { 1315 RootView* Widget::FindRootView(HWND hwnd) {
1312 RootView* root_view = 1316 RootView* root_view = GetRootViewForHWND(hwnd);
1313 reinterpret_cast<RootView*>(GetProp(hwnd, kRootViewWindowProperty));
1314 if (root_view) 1317 if (root_view)
1315 return root_view; 1318 return root_view;
1316 1319
1317 // Enumerate all children and check if they have a RootView. 1320 // Enumerate all children and check if they have a RootView.
1318 EnumChildWindows(hwnd, EnumChildProc, reinterpret_cast<LPARAM>(&root_view)); 1321 EnumChildWindows(hwnd, EnumChildProc, reinterpret_cast<LPARAM>(&root_view));
1319 1322
1320 return root_view; 1323 return root_view;
1321 } 1324 }
1322 1325
1323 // Enumerate child windows as they could have RootView distinct from 1326 // Enumerate child windows as they could have RootView distinct from
1324 // the HWND's root view. 1327 // the HWND's root view.
1325 BOOL CALLBACK EnumAllRootViewsChildProc(HWND hwnd, LPARAM l_param) { 1328 BOOL CALLBACK EnumAllRootViewsChildProc(HWND hwnd, LPARAM l_param) {
1326 RootView* root_view = 1329 RootView* root_view = GetRootViewForHWND(hwnd);
1327 reinterpret_cast<RootView*>(GetProp(hwnd, kRootViewWindowProperty));
1328 if (root_view) { 1330 if (root_view) {
1329 std::set<RootView*>* root_views_set = 1331 std::set<RootView*>* root_views_set =
1330 reinterpret_cast<std::set<RootView*>*>(l_param); 1332 reinterpret_cast<std::set<RootView*>*>(l_param);
1331 root_views_set->insert(root_view); 1333 root_views_set->insert(root_view);
1332 } 1334 }
1333 return TRUE; // Keep enumerating. 1335 return TRUE; // Keep enumerating.
1334 } 1336 }
1335 1337
1336 void Widget::FindAllRootViews(HWND window, 1338 void Widget::FindAllRootViews(HWND window,
1337 std::vector<RootView*>* root_views) { 1339 std::vector<RootView*>* root_views) {
1338 RootView* root_view = 1340 RootView* root_view = GetRootViewForHWND(window);
1339 reinterpret_cast<RootView*>(GetProp(window, kRootViewWindowProperty));
1340 std::set<RootView*> root_views_set; 1341 std::set<RootView*> root_views_set;
1341 if (root_view) 1342 if (root_view)
1342 root_views_set.insert(root_view); 1343 root_views_set.insert(root_view);
1343 // Enumerate all children and check if they have a RootView. 1344 // Enumerate all children and check if they have a RootView.
1344 EnumChildWindows(window, EnumAllRootViewsChildProc, 1345 EnumChildWindows(window, EnumAllRootViewsChildProc,
1345 reinterpret_cast<LPARAM>(&root_views_set)); 1346 reinterpret_cast<LPARAM>(&root_views_set));
1346 root_views->clear(); 1347 root_views->clear();
1347 root_views->reserve(root_views_set.size()); 1348 root_views->reserve(root_views_set.size());
1348 for (std::set<RootView*>::iterator it = root_views_set.begin(); 1349 for (std::set<RootView*>::iterator it = root_views_set.begin();
1349 it != root_views_set.end(); 1350 it != root_views_set.end();
1350 ++it) 1351 ++it)
1351 root_views->push_back(*it); 1352 root_views->push_back(*it);
1352 } 1353 }
1353 1354
1354 //////////////////////////////////////////////////////////////////////////////// 1355 ////////////////////////////////////////////////////////////////////////////////
1355 // Widget, public: 1356 // Widget, public:
1356 1357
1357 // static 1358 // static
1358 Widget* Widget::GetWidgetFromNativeView(gfx::NativeView native_view) { 1359 Widget* Widget::GetWidgetFromNativeView(gfx::NativeView native_view) {
1359 if (IsWindow(native_view)) { 1360 return IsWindow(native_view) ?
1360 HANDLE raw_widget = GetProp(native_view, kWidgetKey); 1361 reinterpret_cast<Widget*>(ViewProp::GetValue(native_view, kWidgetKey)) :
1361 if (raw_widget) 1362 NULL;
1362 return reinterpret_cast<Widget*>(raw_widget);
1363 }
1364 return NULL;
1365 } 1363 }
1366 1364
1367 // static 1365 // static
1368 Widget* Widget::GetWidgetFromNativeWindow(gfx::NativeWindow native_window) { 1366 Widget* Widget::GetWidgetFromNativeWindow(gfx::NativeWindow native_window) {
1369 return Widget::GetWidgetFromNativeView(native_window); 1367 return Widget::GetWidgetFromNativeView(native_window);
1370 } 1368 }
1371 1369
1372 // static 1370 // static
1373 void Widget::NotifyLocaleChanged() { 1371 void Widget::NotifyLocaleChanged() {
1374 NOTIMPLEMENTED(); 1372 NOTIMPLEMENTED();
1375 } 1373 }
1376 1374
1377 } // namespace views 1375 } // namespace views
OLDNEW
« no previous file with comments | « views/widget/widget_win.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698