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

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, 9 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 UINT32 pointer_id = GET_POINTERID_WPARAM(w_param);
1660 using GetPointerTypeFn = BOOL(WINAPI*)(UINT32, POINTER_INPUT_TYPE*);
1661
1662 POINTER_INPUT_TYPE pointer_type;
1663 static GetPointerTypeFn get_pointer_type = reinterpret_cast<GetPointerTypeFn>(
ananta 2017/03/14 22:58:32 Instead of these if's for function pointers, perha
1664 GetProcAddress(GetModuleHandleA("user32.dll"), "GetPointerType"));
1665 if (get_pointer_type && get_pointer_type(pointer_id, &pointer_type)) {
1666 // If the WM_POINTER messages are not sent from a stylus device, then we do
1667 // not handle them to make sure we do not change the current behavior of
1668 // touch and mouse inputs.
1669 if (pointer_type != PT_PEN) {
1670 SetMsgHandled(FALSE);
1671 return 0;
1672 }
1673
1674 using GetPointerPenInfoFn = BOOL(WINAPI*)(UINT32, POINTER_PEN_INFO*);
1675 using GetPointerInfoFn = BOOL(WINAPI*)(UINT32, POINTER_INFO*);
1676 POINTER_INFO pointer_info;
1677 static GetPointerInfoFn get_pointer_info =
1678 reinterpret_cast<GetPointerInfoFn>(
1679 GetProcAddress(GetModuleHandleA("user32.dll"), "GetPointerInfo"));
1680 POINTER_PEN_INFO pointer_pen_info;
1681 static GetPointerPenInfoFn get_pointer_pen_info =
1682 reinterpret_cast<GetPointerPenInfoFn>(GetProcAddress(
1683 GetModuleHandleA("user32.dll"), "GetPointerPenInfo"));
1684 if (get_pointer_pen_info &&
1685 get_pointer_pen_info(pointer_id, &pointer_pen_info)) {
1686 // We are now creating a fake mouse event with pointer type of pen from
1687 // the WM_POINTER message and then setting up an associated pointer
1688 // details in the MouseEvent which contains the pen's information.
1689 float pressure = (float)pointer_pen_info.pressure / 1024;
1690 float rotation = pointer_pen_info.rotation;
1691 int tiltX = pointer_pen_info.tiltX;
1692 int tiltY = pointer_pen_info.tiltY;
1693 gfx::Point point;
1694 if (get_pointer_info && get_pointer_info(pointer_id, &pointer_info)) {
1695 POINT client_point = pointer_info.ptPixelLocation;
1696 ScreenToClient(hwnd(), &client_point);
1697 point = gfx::Point(client_point.x, client_point.y);
1698 }
1699 ui::EventType event_type = ui::ET_MOUSE_MOVED;
1700 int flag = 0;
1701 switch (message) {
1702 case WM_POINTERDOWN:
1703 event_type = ui::ET_MOUSE_PRESSED;
1704 flag = ui::EF_LEFT_MOUSE_BUTTON;
1705 break;
1706 case WM_POINTERUP:
1707 event_type = ui::ET_MOUSE_RELEASED;
1708 flag = ui::EF_LEFT_MOUSE_BUTTON;
1709 break;
1710 case WM_POINTERUPDATE:
1711 event_type = ui::ET_MOUSE_MOVED;
1712 break;
1713 case WM_POINTERLEAVE:
1714 event_type = ui::ET_MOUSE_EXITED;
1715 break;
1716 default:
1717 break;
1718 }
1719 ui::MouseEvent event(event_type, point, point, base::TimeTicks::Now(), 0,
1720 0);
1721 event.set_flags(flag);
1722 ui::PointerDetails pointer_details(ui::EventPointerType::POINTER_TYPE_PEN,
1723 0.0f, 0.0f, pressure, tiltX, tiltY,
1724 0.0f, rotation, pointer_id);
1725 event.set_pointer_details(pointer_details);
1726
1727 // There are cases where the code handling the message destroys the
1728 // window, so use the weak ptr to check if destruction occured or not.
1729 base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr());
1730 bool handled = delegate_->HandleMouseEvent(event);
1731
1732 if (ref.get())
1733 SetMsgHandled(handled);
1734 }
1735 }
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 1126 matching lines...) Expand 10 before | Expand all | Expand 10 after
2781 MONITORINFO monitor_info = {sizeof(monitor_info)}; 2875 MONITORINFO monitor_info = {sizeof(monitor_info)};
2782 GetMonitorInfo(MonitorFromWindow(hwnd(), MONITOR_DEFAULTTOPRIMARY), 2876 GetMonitorInfo(MonitorFromWindow(hwnd(), MONITOR_DEFAULTTOPRIMARY),
2783 &monitor_info); 2877 &monitor_info);
2784 gfx::Rect shrunk_rect(monitor_info.rcMonitor); 2878 gfx::Rect shrunk_rect(monitor_info.rcMonitor);
2785 shrunk_rect.set_height(shrunk_rect.height() - 1); 2879 shrunk_rect.set_height(shrunk_rect.height() - 1);
2786 background_fullscreen_hack_ = true; 2880 background_fullscreen_hack_ = true;
2787 SetBoundsInternal(shrunk_rect, false); 2881 SetBoundsInternal(shrunk_rect, false);
2788 } 2882 }
2789 2883
2790 } // namespace views 2884 } // 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