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

Side by Side Diff: ui/views/win/hwnd_message_handler.cc

Issue 2648683003: Introduce WM_POINTER to Handle pointer events with pen type (Closed)
Patch Set: wm pointer Created 3 years, 8 months 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
« no previous file with comments | « ui/views/win/hwnd_message_handler.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) 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
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
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
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 // If the WM_POINTER messages are not sent from a stylus device, then we do
1671 // not handle them to make sure we do not change the current behavior of
1672 // touch and mouse inputs.
1673 if (!get_pointer_type || !get_pointer_type(pointer_id, &pointer_type) ||
1674 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 if (!get_pointer_pen_info ||
1685 !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 = static_cast<float>(pointer_pen_info.pressure) / 1024;
1694 float rotation = pointer_pen_info.rotation;
1695 int tilt_x = pointer_pen_info.tiltX;
1696 int tilt_y = pointer_pen_info.tiltY;
1697 POINT client_point = pointer_pen_info.pointerInfo.ptPixelLocationRaw;
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 int click_count = 0;
1703 switch (message) {
1704 case WM_POINTERDOWN:
1705 event_type = ui::ET_MOUSE_PRESSED;
1706 flag = ui::EF_LEFT_MOUSE_BUTTON;
1707 click_count = 1;
1708 break;
1709 case WM_POINTERUP:
1710 event_type = ui::ET_MOUSE_RELEASED;
1711 flag = ui::EF_LEFT_MOUSE_BUTTON;
1712 click_count = 1;
1713 break;
1714 case WM_POINTERUPDATE:
1715 event_type = ui::ET_MOUSE_MOVED;
1716 break;
1717 case WM_POINTERENTER:
1718 event_type = ui::ET_MOUSE_ENTERED;
1719 break;
1720 case WM_POINTERLEAVE:
1721 event_type = ui::ET_MOUSE_EXITED;
1722 break;
1723 default:
1724 break;
sky 2017/03/28 22:05:35 NOTREACHED?
1725 }
1726 ui::MouseEvent event(event_type, point, point, base::TimeTicks::Now(), flag,
1727 flag);
1728 ui::PointerDetails pointer_details(
1729 ui::EventPointerType::POINTER_TYPE_PEN, pointer_id,
1730 /* radius_x */ 0.0f, /* radius_y */ 0.0f, pressure, tilt_x, tilt_y,
1731 /* tangential_pressure */ 0.0f, rotation);
1732 event.set_pointer_details(pointer_details);
1733 event.SetClickCount(click_count);
1734
1735 // There are cases where the code handling the message destroys the
1736 // window, so use the weak ptr to check if destruction occured or not.
1737 base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr());
1738 bool handled = delegate_->HandleMouseEvent(event);
1739
1740 if (ref)
1741 SetMsgHandled(handled);
1742 return 0;
1743 }
1744
1645 void HWNDMessageHandler::OnMove(const gfx::Point& point) { 1745 void HWNDMessageHandler::OnMove(const gfx::Point& point) {
1646 delegate_->HandleMove(); 1746 delegate_->HandleMove();
1647 SetMsgHandled(FALSE); 1747 SetMsgHandled(FALSE);
1648 } 1748 }
1649 1749
1650 void HWNDMessageHandler::OnMoving(UINT param, const RECT* new_bounds) { 1750 void HWNDMessageHandler::OnMoving(UINT param, const RECT* new_bounds) {
1651 delegate_->HandleMove(); 1751 delegate_->HandleMove();
1652 } 1752 }
1653 1753
1654 LRESULT HWNDMessageHandler::OnNCActivate(UINT message, 1754 LRESULT HWNDMessageHandler::OnNCActivate(UINT message,
(...skipping 1128 matching lines...) Expand 10 before | Expand all | Expand 10 after
2783 MONITORINFO monitor_info = {sizeof(monitor_info)}; 2883 MONITORINFO monitor_info = {sizeof(monitor_info)};
2784 GetMonitorInfo(MonitorFromWindow(hwnd(), MONITOR_DEFAULTTOPRIMARY), 2884 GetMonitorInfo(MonitorFromWindow(hwnd(), MONITOR_DEFAULTTOPRIMARY),
2785 &monitor_info); 2885 &monitor_info);
2786 gfx::Rect shrunk_rect(monitor_info.rcMonitor); 2886 gfx::Rect shrunk_rect(monitor_info.rcMonitor);
2787 shrunk_rect.set_height(shrunk_rect.height() - 1); 2887 shrunk_rect.set_height(shrunk_rect.height() - 1);
2788 background_fullscreen_hack_ = true; 2888 background_fullscreen_hack_ = true;
2789 SetBoundsInternal(shrunk_rect, false); 2889 SetBoundsInternal(shrunk_rect, false);
2790 } 2890 }
2791 2891
2792 } // namespace views 2892 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/win/hwnd_message_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698