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