OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/views/win/hwnd_message_handler.h" | 5 #include "ui/views/win/hwnd_message_handler.h" |
6 | 6 |
7 #include <dwmapi.h> | 7 #include <dwmapi.h> |
8 #include <oleacc.h> | 8 #include <oleacc.h> |
9 #include <shellapi.h> | 9 #include <shellapi.h> |
10 #include <tchar.h> | 10 #include <tchar.h> |
(...skipping 13 matching lines...) Expand all Loading... | |
24 #include "base/win/windows_version.h" | 24 #include "base/win/windows_version.h" |
25 #include "ui/base/view_prop.h" | 25 #include "ui/base/view_prop.h" |
26 #include "ui/base/win/internal_constants.h" | 26 #include "ui/base/win/internal_constants.h" |
27 #include "ui/base/win/lock_state.h" | 27 #include "ui/base/win/lock_state.h" |
28 #include "ui/base/win/mouse_wheel_util.h" | 28 #include "ui/base/win/mouse_wheel_util.h" |
29 #include "ui/base/win/shell.h" | 29 #include "ui/base/win/shell.h" |
30 #include "ui/base/win/touch_input.h" | 30 #include "ui/base/win/touch_input.h" |
31 #include "ui/display/win/dpi.h" | 31 #include "ui/display/win/dpi.h" |
32 #include "ui/display/win/screen_win.h" | 32 #include "ui/display/win/screen_win.h" |
33 #include "ui/events/event.h" | 33 #include "ui/events/event.h" |
34 #include "ui/events/event_constants.h" | |
34 #include "ui/events/event_utils.h" | 35 #include "ui/events/event_utils.h" |
35 #include "ui/events/keycodes/keyboard_code_conversion_win.h" | 36 #include "ui/events/keycodes/keyboard_code_conversion_win.h" |
36 #include "ui/events/win/system_event_state_lookup.h" | 37 #include "ui/events/win/system_event_state_lookup.h" |
37 #include "ui/gfx/canvas.h" | 38 #include "ui/gfx/canvas.h" |
38 #include "ui/gfx/geometry/insets.h" | 39 #include "ui/gfx/geometry/insets.h" |
39 #include "ui/gfx/icon_util.h" | 40 #include "ui/gfx/icon_util.h" |
40 #include "ui/gfx/path.h" | 41 #include "ui/gfx/path.h" |
41 #include "ui/gfx/path_win.h" | 42 #include "ui/gfx/path_win.h" |
42 #include "ui/gfx/win/direct_manipulation.h" | 43 #include "ui/gfx/win/direct_manipulation.h" |
43 #include "ui/gfx/win/hwnd_util.h" | 44 #include "ui/gfx/win/hwnd_util.h" |
(...skipping 923 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
967 LRESULT HWNDMessageHandler::HandleTouchMessage(unsigned int message, | 968 LRESULT HWNDMessageHandler::HandleTouchMessage(unsigned int message, |
968 WPARAM w_param, | 969 WPARAM w_param, |
969 LPARAM l_param, | 970 LPARAM l_param, |
970 bool* handled) { | 971 bool* handled) { |
971 base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr()); | 972 base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr()); |
972 LRESULT ret = OnTouchEvent(message, w_param, l_param); | 973 LRESULT ret = OnTouchEvent(message, w_param, l_param); |
973 *handled = IsMsgHandled(); | 974 *handled = IsMsgHandled(); |
974 return ret; | 975 return ret; |
975 } | 976 } |
976 | 977 |
978 LRESULT HWNDMessageHandler::HandlePointerMessage(unsigned int message, | |
979 WPARAM w_param, | |
980 LPARAM l_param, | |
981 bool* handled) { | |
982 base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr()); | |
983 LRESULT ret = OnPointerEvent(message, w_param, l_param); | |
984 *handled = IsMsgHandled(); | |
985 return ret; | |
986 } | |
987 | |
977 LRESULT HWNDMessageHandler::HandleScrollMessage(unsigned int message, | 988 LRESULT HWNDMessageHandler::HandleScrollMessage(unsigned int message, |
978 WPARAM w_param, | 989 WPARAM w_param, |
979 LPARAM l_param, | 990 LPARAM l_param, |
980 bool* handled) { | 991 bool* handled) { |
981 base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr()); | 992 base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr()); |
982 LRESULT ret = OnScrollMessage(message, w_param, l_param); | 993 LRESULT ret = OnScrollMessage(message, w_param, l_param); |
983 *handled = IsMsgHandled(); | 994 *handled = IsMsgHandled(); |
984 return ret; | 995 return ret; |
985 } | 996 } |
986 | 997 |
(...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1635 POINTER_INPUT_TYPE pointer_type; | 1646 POINTER_INPUT_TYPE pointer_type; |
1636 static GetPointerTypeFn get_pointer_type = reinterpret_cast<GetPointerTypeFn>( | 1647 static GetPointerTypeFn get_pointer_type = reinterpret_cast<GetPointerTypeFn>( |
1637 GetProcAddress(GetModuleHandleA("user32.dll"), "GetPointerType")); | 1648 GetProcAddress(GetModuleHandleA("user32.dll"), "GetPointerType")); |
1638 if (get_pointer_type && get_pointer_type(pointer_id, &pointer_type) && | 1649 if (get_pointer_type && get_pointer_type(pointer_id, &pointer_type) && |
1639 pointer_type == PT_TOUCHPAD) | 1650 pointer_type == PT_TOUCHPAD) |
1640 return PA_NOACTIVATE; | 1651 return PA_NOACTIVATE; |
1641 SetMsgHandled(FALSE); | 1652 SetMsgHandled(FALSE); |
1642 return -1; | 1653 return -1; |
1643 } | 1654 } |
1644 | 1655 |
1656 LRESULT HWNDMessageHandler::OnPointerEvent(UINT message, | |
1657 WPARAM w_param, | |
1658 LPARAM l_param) { | |
1659 // WM_POINTER is not supported on Windows 7 or lower. | |
1660 if (base::win::GetVersion() <= base::win::VERSION_WIN7) { | |
1661 SetMsgHandled(FALSE); | |
1662 return -1; | |
1663 } | |
1664 | |
1665 UINT32 pointer_id = GET_POINTERID_WPARAM(w_param); | |
1666 using GetPointerTypeFn = BOOL(WINAPI*)(UINT32, POINTER_INPUT_TYPE*); | |
1667 POINTER_INPUT_TYPE pointer_type; | |
1668 static GetPointerTypeFn get_pointer_type = reinterpret_cast<GetPointerTypeFn>( | |
1669 GetProcAddress(GetModuleHandleA("user32.dll"), "GetPointerType")); | |
1670 CHECK(get_pointer_type); | |
1671 // If the WM_POINTER messages are not sent from a stylus device, then we do | |
1672 // not handle them to make sure we do not change the current behavior of | |
1673 // touch and mouse inputs. | |
1674 if (!get_pointer_type(pointer_id, &pointer_type) || pointer_type != PT_PEN) { | |
1675 SetMsgHandled(FALSE); | |
1676 return -1; | |
1677 } | |
1678 | |
1679 using GetPointerPenInfoFn = BOOL(WINAPI*)(UINT32, POINTER_PEN_INFO*); | |
1680 POINTER_PEN_INFO pointer_pen_info; | |
1681 static GetPointerPenInfoFn get_pointer_pen_info = | |
1682 reinterpret_cast<GetPointerPenInfoFn>( | |
1683 GetProcAddress(GetModuleHandleA("user32.dll"), "GetPointerPenInfo")); | |
1684 CHECK(get_pointer_pen_info); | |
1685 if (!get_pointer_pen_info(pointer_id, &pointer_pen_info)) { | |
1686 SetMsgHandled(FALSE); | |
1687 return -1; | |
1688 } | |
1689 | |
1690 // We are now creating a fake mouse event with pointer type of pen from | |
1691 // the WM_POINTER message and then setting up an associated pointer | |
1692 // details in the MouseEvent which contains the pen's information. | |
1693 float pressure = (float)pointer_pen_info.pressure / 1024; | |
ananta
2017/03/22 19:03:26
static_cast<float> here/
lanwei
2017/03/22 22:38:40
Done.
| |
1694 float rotation = pointer_pen_info.rotation; | |
1695 int tiltX = pointer_pen_info.tiltX; | |
1696 int tiltY = pointer_pen_info.tiltY; | |
1697 POINT client_point = pointer_pen_info.pointerInfo.ptPixelLocation; | |
mustaq
2017/03/20 14:31:16
I think ptPixelLocationRaw is more appropriate her
lanwei
2017/03/22 22:38:40
Acknowledged.
| |
1698 ScreenToClient(hwnd(), &client_point); | |
1699 gfx::Point point = gfx::Point(client_point.x, client_point.y); | |
1700 ui::EventType event_type = ui::ET_MOUSE_MOVED; | |
1701 int flag = -1; | |
1702 switch (message) { | |
1703 case WM_POINTERDOWN: | |
1704 event_type = ui::ET_MOUSE_PRESSED; | |
1705 flag = ui::EF_LEFT_MOUSE_BUTTON; | |
1706 break; | |
1707 case WM_POINTERUP: | |
1708 event_type = ui::ET_MOUSE_RELEASED; | |
1709 flag = ui::EF_LEFT_MOUSE_BUTTON; | |
1710 break; | |
1711 case WM_POINTERUPDATE: | |
1712 event_type = ui::ET_MOUSE_MOVED; | |
1713 break; | |
1714 case WM_POINTERLEAVE: | |
1715 event_type = ui::ET_MOUSE_EXITED; | |
1716 break; | |
1717 default: | |
1718 break; | |
1719 } | |
1720 ui::MouseEvent event(event_type, point, point, base::TimeTicks::Now(), flag, | |
1721 flag); | |
1722 ui::PointerDetails pointer_details( | |
1723 ui::EventPointerType::POINTER_TYPE_PEN, pointer_id, | |
1724 /* radius_x */ 0.0f, | |
1725 /* radius_y */ 0.0f, pressure, tiltX, tiltY, | |
1726 /* radius_y */ 0.0f, rotation); | |
1727 event.set_pointer_details(pointer_details); | |
1728 | |
1729 // There are cases where the code handling the message destroys the | |
1730 // window, so use the weak ptr to check if destruction occured or not. | |
1731 base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr()); | |
1732 bool handled = delegate_->HandleMouseEvent(event); | |
1733 | |
1734 if (ref.get()) | |
1735 SetMsgHandled(handled); | |
1736 return 0; | |
1737 } | |
1738 | |
1645 void HWNDMessageHandler::OnMove(const gfx::Point& point) { | 1739 void HWNDMessageHandler::OnMove(const gfx::Point& point) { |
1646 delegate_->HandleMove(); | 1740 delegate_->HandleMove(); |
1647 SetMsgHandled(FALSE); | 1741 SetMsgHandled(FALSE); |
1648 } | 1742 } |
1649 | 1743 |
1650 void HWNDMessageHandler::OnMoving(UINT param, const RECT* new_bounds) { | 1744 void HWNDMessageHandler::OnMoving(UINT param, const RECT* new_bounds) { |
1651 delegate_->HandleMove(); | 1745 delegate_->HandleMove(); |
1652 } | 1746 } |
1653 | 1747 |
1654 LRESULT HWNDMessageHandler::OnNCActivate(UINT message, | 1748 LRESULT HWNDMessageHandler::OnNCActivate(UINT message, |
(...skipping 1128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2783 MONITORINFO monitor_info = {sizeof(monitor_info)}; | 2877 MONITORINFO monitor_info = {sizeof(monitor_info)}; |
2784 GetMonitorInfo(MonitorFromWindow(hwnd(), MONITOR_DEFAULTTOPRIMARY), | 2878 GetMonitorInfo(MonitorFromWindow(hwnd(), MONITOR_DEFAULTTOPRIMARY), |
2785 &monitor_info); | 2879 &monitor_info); |
2786 gfx::Rect shrunk_rect(monitor_info.rcMonitor); | 2880 gfx::Rect shrunk_rect(monitor_info.rcMonitor); |
2787 shrunk_rect.set_height(shrunk_rect.height() - 1); | 2881 shrunk_rect.set_height(shrunk_rect.height() - 1); |
2788 background_fullscreen_hack_ = true; | 2882 background_fullscreen_hack_ = true; |
2789 SetBoundsInternal(shrunk_rect, false); | 2883 SetBoundsInternal(shrunk_rect, false); |
2790 } | 2884 } |
2791 | 2885 |
2792 } // namespace views | 2886 } // namespace views |
OLD | NEW |