| 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 #include "views/widget/native_widget_win.h" | 5 #include "views/widget/native_widget_win.h" |
| 6 | 6 |
| 7 #include <dwmapi.h> | 7 #include <dwmapi.h> |
| 8 #include <shellapi.h> | 8 #include <shellapi.h> |
| 9 | 9 |
| 10 #include <algorithm> |
| 11 |
| 10 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 11 #include "base/system_monitor/system_monitor.h" | 13 #include "base/system_monitor/system_monitor.h" |
| 12 #include "base/win/scoped_gdi_object.h" | 14 #include "base/win/scoped_gdi_object.h" |
| 13 #include "base/win/win_util.h" | 15 #include "base/win/win_util.h" |
| 14 #include "base/win/windows_version.h" | 16 #include "base/win/windows_version.h" |
| 15 #include "ui/base/dragdrop/drag_drop_types.h" | 17 #include "ui/base/dragdrop/drag_drop_types.h" |
| 16 #include "ui/base/dragdrop/drag_source.h" | 18 #include "ui/base/dragdrop/drag_source.h" |
| 17 #include "ui/base/dragdrop/os_exchange_data.h" | 19 #include "ui/base/dragdrop/os_exchange_data.h" |
| 18 #include "ui/base/dragdrop/os_exchange_data_provider_win.h" | 20 #include "ui/base/dragdrop/os_exchange_data_provider_win.h" |
| 19 #include "ui/base/keycodes/keyboard_code_conversion_win.h" | 21 #include "ui/base/keycodes/keyboard_code_conversion_win.h" |
| (...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 684 reinterpret_cast<LPARAM>(windows_icon))); | 686 reinterpret_cast<LPARAM>(windows_icon))); |
| 685 if (old_icon) | 687 if (old_icon) |
| 686 DestroyIcon(old_icon); | 688 DestroyIcon(old_icon); |
| 687 } | 689 } |
| 688 } | 690 } |
| 689 | 691 |
| 690 void NativeWidgetWin::SetAccessibleName(const std::wstring& name) { | 692 void NativeWidgetWin::SetAccessibleName(const std::wstring& name) { |
| 691 base::win::ScopedComPtr<IAccPropServices> pAccPropServices; | 693 base::win::ScopedComPtr<IAccPropServices> pAccPropServices; |
| 692 HRESULT hr = CoCreateInstance(CLSID_AccPropServices, NULL, CLSCTX_SERVER, | 694 HRESULT hr = CoCreateInstance(CLSID_AccPropServices, NULL, CLSCTX_SERVER, |
| 693 IID_IAccPropServices, reinterpret_cast<void**>(&pAccPropServices)); | 695 IID_IAccPropServices, reinterpret_cast<void**>(&pAccPropServices)); |
| 694 if (SUCCEEDED(hr)) { | 696 if (SUCCEEDED(hr)) |
| 695 VARIANT var; | 697 hr = pAccPropServices->SetHwndPropStr(GetNativeView(), OBJID_CLIENT, |
| 696 var.vt = VT_BSTR; | 698 CHILDID_SELF, PROPID_ACC_NAME, |
| 697 var.bstrVal = SysAllocString(name.c_str()); | 699 name.c_str()); |
| 698 hr = pAccPropServices->SetHwndProp(GetNativeView(), OBJID_CLIENT, | |
| 699 CHILDID_SELF, PROPID_ACC_NAME, var); | |
| 700 } | |
| 701 } | 700 } |
| 702 | 701 |
| 703 void NativeWidgetWin::SetAccessibleRole(ui::AccessibilityTypes::Role role) { | 702 void NativeWidgetWin::SetAccessibleRole(ui::AccessibilityTypes::Role role) { |
| 704 base::win::ScopedComPtr<IAccPropServices> pAccPropServices; | 703 base::win::ScopedComPtr<IAccPropServices> pAccPropServices; |
| 705 HRESULT hr = CoCreateInstance(CLSID_AccPropServices, NULL, CLSCTX_SERVER, | 704 HRESULT hr = CoCreateInstance(CLSID_AccPropServices, NULL, CLSCTX_SERVER, |
| 706 IID_IAccPropServices, reinterpret_cast<void**>(&pAccPropServices)); | 705 IID_IAccPropServices, reinterpret_cast<void**>(&pAccPropServices)); |
| 707 if (SUCCEEDED(hr)) { | 706 if (SUCCEEDED(hr)) { |
| 708 VARIANT var; | 707 VARIANT var; |
| 709 if (role) { | 708 if (role) { |
| 710 var.vt = VT_I4; | 709 var.vt = VT_I4; |
| 711 var.lVal = NativeViewAccessibilityWin::MSAARole(role); | 710 var.lVal = NativeViewAccessibilityWin::MSAARole(role); |
| 712 hr = pAccPropServices->SetHwndProp(GetNativeView(), OBJID_CLIENT, | 711 hr = pAccPropServices->SetHwndProp(GetNativeView(), OBJID_CLIENT, |
| 713 CHILDID_SELF, PROPID_ACC_ROLE, var); | 712 CHILDID_SELF, PROPID_ACC_ROLE, var); |
| 714 } | 713 } |
| 715 } | 714 } |
| 716 } | 715 } |
| 717 | 716 |
| 718 void NativeWidgetWin::SetAccessibleState(ui::AccessibilityTypes::State state) { | 717 void NativeWidgetWin::SetAccessibleState(ui::AccessibilityTypes::State state) { |
| 719 base::win::ScopedComPtr<IAccPropServices> pAccPropServices; | 718 base::win::ScopedComPtr<IAccPropServices> pAccPropServices; |
| 720 HRESULT hr = CoCreateInstance(CLSID_AccPropServices, NULL, CLSCTX_SERVER, | 719 HRESULT hr = CoCreateInstance(CLSID_AccPropServices, NULL, CLSCTX_SERVER, |
| 721 IID_IAccPropServices, reinterpret_cast<void**>(&pAccPropServices)); | 720 IID_IAccPropServices, reinterpret_cast<void**>(&pAccPropServices)); |
| 722 if (SUCCEEDED(hr)) { | 721 if (SUCCEEDED(hr)) { |
| 723 VARIANT var; | 722 VARIANT var; |
| 724 if (state) { | 723 if (state) { |
| 724 var.vt = VT_I4; |
| 725 var.lVal = NativeViewAccessibilityWin::MSAAState(state); | 725 var.lVal = NativeViewAccessibilityWin::MSAAState(state); |
| 726 hr = pAccPropServices->SetHwndProp(GetNativeView(), OBJID_CLIENT, | 726 hr = pAccPropServices->SetHwndProp(GetNativeView(), OBJID_CLIENT, |
| 727 CHILDID_SELF, PROPID_ACC_STATE, var); | 727 CHILDID_SELF, PROPID_ACC_STATE, var); |
| 728 } | 728 } |
| 729 } | 729 } |
| 730 } | 730 } |
| 731 | 731 |
| 732 void NativeWidgetWin::BecomeModal() { | 732 void NativeWidgetWin::BecomeModal() { |
| 733 // We implement modality by crawling up the hierarchy of windows starting | 733 // We implement modality by crawling up the hierarchy of windows starting |
| 734 // at the owner, disabling all of them so that they don't receive input | 734 // at the owner, disabling all of them so that they don't receive input |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1054 &NativeWidgetWin::RedrawLayeredWindowContents)); | 1054 &NativeWidgetWin::RedrawLayeredWindowContents)); |
| 1055 } | 1055 } |
| 1056 } else { | 1056 } else { |
| 1057 // InvalidateRect() expects client coordinates. | 1057 // InvalidateRect() expects client coordinates. |
| 1058 RECT r = rect.ToRECT(); | 1058 RECT r = rect.ToRECT(); |
| 1059 InvalidateRect(hwnd(), &r, FALSE); | 1059 InvalidateRect(hwnd(), &r, FALSE); |
| 1060 } | 1060 } |
| 1061 } | 1061 } |
| 1062 | 1062 |
| 1063 void NativeWidgetWin::SetCursor(gfx::NativeCursor cursor) { | 1063 void NativeWidgetWin::SetCursor(gfx::NativeCursor cursor) { |
| 1064 if(cursor) { | 1064 if (cursor) { |
| 1065 previous_cursor_ = ::SetCursor(cursor); | 1065 previous_cursor_ = ::SetCursor(cursor); |
| 1066 } else if (previous_cursor_) { | 1066 } else if (previous_cursor_) { |
| 1067 ::SetCursor(previous_cursor_); | 1067 ::SetCursor(previous_cursor_); |
| 1068 previous_cursor_ = NULL; | 1068 previous_cursor_ = NULL; |
| 1069 } | 1069 } |
| 1070 } | 1070 } |
| 1071 | 1071 |
| 1072 void NativeWidgetWin::ClearNativeFocus() { | 1072 void NativeWidgetWin::ClearNativeFocus() { |
| 1073 ::SetFocus(GetNativeView()); | 1073 ::SetFocus(GetNativeView()); |
| 1074 } | 1074 } |
| (...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1602 // We only override the default handling if we need to specify a custom | 1602 // We only override the default handling if we need to specify a custom |
| 1603 // non-client edge width. Note that in most cases "no insets" means no | 1603 // non-client edge width. Note that in most cases "no insets" means no |
| 1604 // custom width, but in fullscreen mode we want a custom width of 0. | 1604 // custom width, but in fullscreen mode we want a custom width of 0. |
| 1605 gfx::Insets insets = GetClientAreaInsets(); | 1605 gfx::Insets insets = GetClientAreaInsets(); |
| 1606 if (insets.empty() && !IsFullscreen()) { | 1606 if (insets.empty() && !IsFullscreen()) { |
| 1607 SetMsgHandled(FALSE); | 1607 SetMsgHandled(FALSE); |
| 1608 return 0; | 1608 return 0; |
| 1609 } | 1609 } |
| 1610 | 1610 |
| 1611 RECT* client_rect = mode ? | 1611 RECT* client_rect = mode ? |
| 1612 &reinterpret_cast<NCCALCSIZE_PARAMS*>(l_param)->rgrc[0] : | 1612 &(reinterpret_cast<NCCALCSIZE_PARAMS*>(l_param)->rgrc[0]) : |
| 1613 reinterpret_cast<RECT*>(l_param); | 1613 reinterpret_cast<RECT*>(l_param); |
| 1614 client_rect->left += insets.left(); | 1614 client_rect->left += insets.left(); |
| 1615 client_rect->top += insets.top(); | 1615 client_rect->top += insets.top(); |
| 1616 client_rect->bottom -= insets.bottom(); | 1616 client_rect->bottom -= insets.bottom(); |
| 1617 client_rect->right -= insets.right(); | 1617 client_rect->right -= insets.right(); |
| 1618 if (IsMaximized()) { | 1618 if (IsMaximized()) { |
| 1619 // Find all auto-hide taskbars along the screen edges and adjust in by the | 1619 // Find all auto-hide taskbars along the screen edges and adjust in by the |
| 1620 // thickness of the auto-hide taskbar on each such edge, so the window isn't | 1620 // thickness of the auto-hide taskbar on each such edge, so the window isn't |
| 1621 // treated as a "fullscreen app", which would cause the taskbars to | 1621 // treated as a "fullscreen app", which would cause the taskbars to |
| 1622 // disappear. | 1622 // disappear. |
| (...skipping 910 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2533 return (GetKeyState(VK_LBUTTON) & 0x80) || | 2533 return (GetKeyState(VK_LBUTTON) & 0x80) || |
| 2534 (GetKeyState(VK_RBUTTON) & 0x80) || | 2534 (GetKeyState(VK_RBUTTON) & 0x80) || |
| 2535 (GetKeyState(VK_MBUTTON) & 0x80) || | 2535 (GetKeyState(VK_MBUTTON) & 0x80) || |
| 2536 (GetKeyState(VK_XBUTTON1) & 0x80) || | 2536 (GetKeyState(VK_XBUTTON1) & 0x80) || |
| 2537 (GetKeyState(VK_XBUTTON2) & 0x80); | 2537 (GetKeyState(VK_XBUTTON2) & 0x80); |
| 2538 } | 2538 } |
| 2539 | 2539 |
| 2540 } // namespace internal | 2540 } // namespace internal |
| 2541 | 2541 |
| 2542 } // namespace views | 2542 } // namespace views |
| OLD | NEW |