Commit 499bc4f5 authored by lanwei's avatar lanwei Committed by Commit bot

Introduce WM_POINTER to Handle pointer events with pen type

BUG=367113

Review-Url: https://codereview.chromium.org/2648683003
Cr-Commit-Position: refs/heads/master@{#460522}
parent eded34c4
...@@ -312,6 +312,19 @@ LRESULT LegacyRenderWidgetHostHWND::OnMouseActivate(UINT message, ...@@ -312,6 +312,19 @@ LRESULT LegacyRenderWidgetHostHWND::OnMouseActivate(UINT message,
return MA_ACTIVATE; return MA_ACTIVATE;
} }
LRESULT LegacyRenderWidgetHostHWND::OnPointer(UINT message,
WPARAM w_param,
LPARAM l_param) {
LRESULT ret = 0;
if (GetWindowEventTarget(GetParent())) {
bool msg_handled = false;
ret = GetWindowEventTarget(GetParent())
->HandlePointerMessage(message, w_param, l_param, &msg_handled);
SetMsgHandled(msg_handled);
}
return ret;
}
LRESULT LegacyRenderWidgetHostHWND::OnTouch(UINT message, LRESULT LegacyRenderWidgetHostHWND::OnTouch(UINT message,
WPARAM w_param, WPARAM w_param,
LPARAM l_param) { LPARAM l_param) {
......
...@@ -83,6 +83,11 @@ class CONTENT_EXPORT LegacyRenderWidgetHostHWND ...@@ -83,6 +83,11 @@ class CONTENT_EXPORT LegacyRenderWidgetHostHWND
MESSAGE_HANDLER_EX(WM_MOUSEACTIVATE, OnMouseActivate) MESSAGE_HANDLER_EX(WM_MOUSEACTIVATE, OnMouseActivate)
MESSAGE_HANDLER_EX(WM_SETCURSOR, OnSetCursor) MESSAGE_HANDLER_EX(WM_SETCURSOR, OnSetCursor)
MESSAGE_HANDLER_EX(WM_TOUCH, OnTouch) MESSAGE_HANDLER_EX(WM_TOUCH, OnTouch)
MESSAGE_HANDLER_EX(WM_POINTERDOWN, OnPointer)
MESSAGE_HANDLER_EX(WM_POINTERUPDATE, OnPointer)
MESSAGE_HANDLER_EX(WM_POINTERUP, OnPointer)
MESSAGE_HANDLER_EX(WM_POINTERENTER, OnPointer)
MESSAGE_HANDLER_EX(WM_POINTERLEAVE, OnPointer)
MESSAGE_HANDLER_EX(WM_HSCROLL, OnScroll) MESSAGE_HANDLER_EX(WM_HSCROLL, OnScroll)
MESSAGE_HANDLER_EX(WM_VSCROLL, OnScroll) MESSAGE_HANDLER_EX(WM_VSCROLL, OnScroll)
MESSAGE_HANDLER_EX(WM_NCHITTEST, OnNCHitTest) MESSAGE_HANDLER_EX(WM_NCHITTEST, OnNCHitTest)
...@@ -135,6 +140,7 @@ class CONTENT_EXPORT LegacyRenderWidgetHostHWND ...@@ -135,6 +140,7 @@ class CONTENT_EXPORT LegacyRenderWidgetHostHWND
LRESULT OnMouseRange(UINT message, WPARAM w_param, LPARAM l_param, LRESULT OnMouseRange(UINT message, WPARAM w_param, LPARAM l_param,
BOOL& handled); BOOL& handled);
LRESULT OnMouseActivate(UINT message, WPARAM w_param, LPARAM l_param); LRESULT OnMouseActivate(UINT message, WPARAM w_param, LPARAM l_param);
LRESULT OnPointer(UINT message, WPARAM w_param, LPARAM l_param);
LRESULT OnTouch(UINT message, WPARAM w_param, LPARAM l_param); LRESULT OnTouch(UINT message, WPARAM w_param, LPARAM l_param);
LRESULT OnScroll(UINT message, WPARAM w_param, LPARAM l_param); LRESULT OnScroll(UINT message, WPARAM w_param, LPARAM l_param);
LRESULT OnNCHitTest(UINT message, WPARAM w_param, LPARAM l_param); LRESULT OnNCHitTest(UINT message, WPARAM w_param, LPARAM l_param);
......
...@@ -30,6 +30,18 @@ class UI_BASE_EXPORT WindowEventTarget { ...@@ -30,6 +30,18 @@ class UI_BASE_EXPORT WindowEventTarget {
LPARAM l_param, LPARAM l_param,
bool* handled) = 0; bool* handled) = 0;
// Handles pointer events like WM_POINTERUP, WM_POINTERDOWN, WM_POINTERUPDATE
// events.
// The |message| parameter identifies the message.
// The |w_param| and |l_param| values are as per MSDN docs.
// The |handled| parameter is an output parameter which when set to false
// indicates that the message should be DefProc'ed.
// Returns the result of processing the message.
virtual LRESULT HandlePointerMessage(unsigned int message,
WPARAM w_param,
LPARAM l_param,
bool* handled) = 0;
// Handles keyboard events like WM_KEYDOWN/WM_KEYUP, etc. // Handles keyboard events like WM_KEYDOWN/WM_KEYUP, etc.
// The |message| parameter identifies the message. // The |message| parameter identifies the message.
// The |w_param| and |l_param| values are dependent on the type of the // The |w_param| and |l_param| values are dependent on the type of the
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include "ui/display/win/dpi.h" #include "ui/display/win/dpi.h"
#include "ui/display/win/screen_win.h" #include "ui/display/win/screen_win.h"
#include "ui/events/event.h" #include "ui/events/event.h"
#include "ui/events/event_constants.h"
#include "ui/events/event_utils.h" #include "ui/events/event_utils.h"
#include "ui/events/keycodes/keyboard_code_conversion_win.h" #include "ui/events/keycodes/keyboard_code_conversion_win.h"
#include "ui/events/win/system_event_state_lookup.h" #include "ui/events/win/system_event_state_lookup.h"
...@@ -974,6 +975,16 @@ LRESULT HWNDMessageHandler::HandleTouchMessage(unsigned int message, ...@@ -974,6 +975,16 @@ LRESULT HWNDMessageHandler::HandleTouchMessage(unsigned int message,
return ret; return ret;
} }
LRESULT HWNDMessageHandler::HandlePointerMessage(unsigned int message,
WPARAM w_param,
LPARAM l_param,
bool* handled) {
base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr());
LRESULT ret = OnPointerEvent(message, w_param, l_param);
*handled = IsMsgHandled();
return ret;
}
LRESULT HWNDMessageHandler::HandleScrollMessage(unsigned int message, LRESULT HWNDMessageHandler::HandleScrollMessage(unsigned int message,
WPARAM w_param, WPARAM w_param,
LPARAM l_param, LPARAM l_param,
...@@ -1642,6 +1653,95 @@ LRESULT HWNDMessageHandler::OnPointerActivate(UINT message, ...@@ -1642,6 +1653,95 @@ LRESULT HWNDMessageHandler::OnPointerActivate(UINT message,
return -1; return -1;
} }
LRESULT HWNDMessageHandler::OnPointerEvent(UINT message,
WPARAM w_param,
LPARAM l_param) {
// WM_POINTER is not supported on Windows 7 or lower.
if (base::win::GetVersion() <= base::win::VERSION_WIN7) {
SetMsgHandled(FALSE);
return -1;
}
UINT32 pointer_id = GET_POINTERID_WPARAM(w_param);
using GetPointerTypeFn = BOOL(WINAPI*)(UINT32, POINTER_INPUT_TYPE*);
POINTER_INPUT_TYPE pointer_type;
static GetPointerTypeFn get_pointer_type = reinterpret_cast<GetPointerTypeFn>(
GetProcAddress(GetModuleHandleA("user32.dll"), "GetPointerType"));
// If the WM_POINTER messages are not sent from a stylus device, then we do
// not handle them to make sure we do not change the current behavior of
// touch and mouse inputs.
if (!get_pointer_type || !get_pointer_type(pointer_id, &pointer_type) ||
pointer_type != PT_PEN) {
SetMsgHandled(FALSE);
return -1;
}
using GetPointerPenInfoFn = BOOL(WINAPI*)(UINT32, POINTER_PEN_INFO*);
POINTER_PEN_INFO pointer_pen_info;
static GetPointerPenInfoFn get_pointer_pen_info =
reinterpret_cast<GetPointerPenInfoFn>(
GetProcAddress(GetModuleHandleA("user32.dll"), "GetPointerPenInfo"));
if (!get_pointer_pen_info ||
!get_pointer_pen_info(pointer_id, &pointer_pen_info)) {
SetMsgHandled(FALSE);
return -1;
}
// We are now creating a fake mouse event with pointer type of pen from
// the WM_POINTER message and then setting up an associated pointer
// details in the MouseEvent which contains the pen's information.
float pressure = static_cast<float>(pointer_pen_info.pressure) / 1024;
float rotation = pointer_pen_info.rotation;
int tilt_x = pointer_pen_info.tiltX;
int tilt_y = pointer_pen_info.tiltY;
POINT client_point = pointer_pen_info.pointerInfo.ptPixelLocationRaw;
ScreenToClient(hwnd(), &client_point);
gfx::Point point = gfx::Point(client_point.x, client_point.y);
ui::EventType event_type = ui::ET_MOUSE_MOVED;
int flag = -1;
int click_count = 0;
switch (message) {
case WM_POINTERDOWN:
event_type = ui::ET_MOUSE_PRESSED;
flag = ui::EF_LEFT_MOUSE_BUTTON;
click_count = 1;
break;
case WM_POINTERUP:
event_type = ui::ET_MOUSE_RELEASED;
flag = ui::EF_LEFT_MOUSE_BUTTON;
click_count = 1;
break;
case WM_POINTERUPDATE:
event_type = ui::ET_MOUSE_MOVED;
break;
case WM_POINTERENTER:
event_type = ui::ET_MOUSE_ENTERED;
break;
case WM_POINTERLEAVE:
event_type = ui::ET_MOUSE_EXITED;
break;
default:
NOTREACHED();
}
ui::MouseEvent event(event_type, point, point, base::TimeTicks::Now(), flag,
flag);
ui::PointerDetails pointer_details(
ui::EventPointerType::POINTER_TYPE_PEN, pointer_id,
/* radius_x */ 0.0f, /* radius_y */ 0.0f, pressure, tilt_x, tilt_y,
/* tangential_pressure */ 0.0f, rotation);
event.set_pointer_details(pointer_details);
event.SetClickCount(click_count);
// There are cases where the code handling the message destroys the
// window, so use the weak ptr to check if destruction occured or not.
base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr());
bool handled = delegate_->HandleMouseEvent(event);
if (ref)
SetMsgHandled(handled);
return 0;
}
void HWNDMessageHandler::OnMove(const gfx::Point& point) { void HWNDMessageHandler::OnMove(const gfx::Point& point) {
delegate_->HandleMove(); delegate_->HandleMove();
SetMsgHandled(FALSE); SetMsgHandled(FALSE);
......
...@@ -235,7 +235,10 @@ class VIEWS_EXPORT HWNDMessageHandler : ...@@ -235,7 +235,10 @@ class VIEWS_EXPORT HWNDMessageHandler :
WPARAM w_param, WPARAM w_param,
LPARAM l_param, LPARAM l_param,
bool* handled) override; bool* handled) override;
LRESULT HandlePointerMessage(unsigned int message,
WPARAM w_param,
LPARAM l_param,
bool* handled) override;
LRESULT HandleScrollMessage(unsigned int message, LRESULT HandleScrollMessage(unsigned int message,
WPARAM w_param, WPARAM w_param,
LPARAM l_param, LPARAM l_param,
...@@ -358,6 +361,11 @@ class VIEWS_EXPORT HWNDMessageHandler : ...@@ -358,6 +361,11 @@ class VIEWS_EXPORT HWNDMessageHandler :
// Pointer events. // Pointer events.
CR_MESSAGE_HANDLER_EX(WM_POINTERACTIVATE, OnPointerActivate) CR_MESSAGE_HANDLER_EX(WM_POINTERACTIVATE, OnPointerActivate)
CR_MESSAGE_HANDLER_EX(WM_POINTERDOWN, OnPointerEvent)
CR_MESSAGE_HANDLER_EX(WM_POINTERUP, OnPointerEvent)
CR_MESSAGE_HANDLER_EX(WM_POINTERUPDATE, OnPointerEvent)
CR_MESSAGE_HANDLER_EX(WM_POINTERENTER, OnPointerEvent)
CR_MESSAGE_HANDLER_EX(WM_POINTERLEAVE, OnPointerEvent)
// Key events. // Key events.
CR_MESSAGE_HANDLER_EX(WM_KEYDOWN, OnKeyEvent) CR_MESSAGE_HANDLER_EX(WM_KEYDOWN, OnKeyEvent)
...@@ -460,6 +468,7 @@ class VIEWS_EXPORT HWNDMessageHandler : ...@@ -460,6 +468,7 @@ class VIEWS_EXPORT HWNDMessageHandler :
LRESULT OnMouseActivate(UINT message, WPARAM w_param, LPARAM l_param); LRESULT OnMouseActivate(UINT message, WPARAM w_param, LPARAM l_param);
LRESULT OnMouseRange(UINT message, WPARAM w_param, LPARAM l_param); LRESULT OnMouseRange(UINT message, WPARAM w_param, LPARAM l_param);
LRESULT OnPointerActivate(UINT message, WPARAM w_param, LPARAM l_param); LRESULT OnPointerActivate(UINT message, WPARAM w_param, LPARAM l_param);
LRESULT OnPointerEvent(UINT message, WPARAM w_param, LPARAM l_param);
void OnMove(const gfx::Point& point); void OnMove(const gfx::Point& point);
void OnMoving(UINT param, const RECT* new_bounds); void OnMoving(UINT param, const RECT* new_bounds);
LRESULT OnNCActivate(UINT message, WPARAM w_param, LPARAM l_param); LRESULT OnNCActivate(UINT message, WPARAM w_param, LPARAM l_param);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment