Skip to content

Commit

Permalink
Pass MotionEvent tool type to Blink.
Browse files Browse the repository at this point in the history
This maps MotionEvent tool type to PointerEvent pointerType and passes
that to WebTouchPoints.

This CL is a part of a patch series:
 1. https://codereview.chromium.org/1253183005/
    for new WebPointerProperties fields
 2. https://codereview.chromium.org/1260693003/
    for eventSender web pointer property support
 3. https://codereview.chromium.org/1192463008/
    for handling pointer type in Blink event handlers
 4. https://codereview.chromium.org/1190013002/ (this)

BUG=514360

Review URL: https://codereview.chromium.org/1190013002

Cr-Commit-Position: refs/heads/master@{#342992}
  • Loading branch information
e.hakkinen authored and Commit bot committed Aug 12, 2015
1 parent b285dfd commit 3c4c729
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
19 changes: 17 additions & 2 deletions content/browser/renderer_host/input/motion_event_web.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "content/common/input/web_touch_event_traits.h"

using blink::WebInputEvent;
using blink::WebPointerProperties;
using blink::WebTouchEvent;
using blink::WebTouchPoint;

Expand Down Expand Up @@ -157,9 +158,23 @@ base::TimeTicks MotionEventWeb::GetEventTime() const {

ui::MotionEvent::ToolType MotionEventWeb::GetToolType(
size_t pointer_index) const {
// TODO(jdduke): Plumb tool type from the platform event, crbug.com/404128.
DCHECK_LT(pointer_index, GetPointerCount());
return TOOL_TYPE_UNKNOWN;

const WebPointerProperties& pointer = event_.touches[pointer_index];

switch (pointer.pointerType) {
case WebPointerProperties::PointerTypeUnknown:
return TOOL_TYPE_UNKNOWN;
case WebPointerProperties::PointerTypeMouse:
return TOOL_TYPE_MOUSE;
case WebPointerProperties::PointerTypePen:
return TOOL_TYPE_STYLUS;
case WebPointerProperties::PointerTypeTouch:
return TOOL_TYPE_FINGER;
default:
NOTREACHED() << "Unhandled pointer type " << pointer.pointerType;
return TOOL_TYPE_UNKNOWN;
}
}

int MotionEventWeb::GetButtonState() const {
Expand Down
20 changes: 20 additions & 0 deletions ui/events/blink/blink_event_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,30 @@ WebTouchPoint::State ToWebTouchPointState(const MotionEvent& event,
return WebTouchPoint::StateUndefined;
}

WebTouchPoint::PointerType ToWebTouchPointPointerType(const MotionEvent& event,
size_t pointer_index) {
switch (event.GetToolType(pointer_index)) {
case MotionEvent::TOOL_TYPE_UNKNOWN:
return WebTouchPoint::PointerTypeUnknown;
case MotionEvent::TOOL_TYPE_FINGER:
return WebTouchPoint::PointerTypeTouch;
case MotionEvent::TOOL_TYPE_STYLUS:
return WebTouchPoint::PointerTypePen;
case MotionEvent::TOOL_TYPE_MOUSE:
return WebTouchPoint::PointerTypeMouse;
case MotionEvent::TOOL_TYPE_ERASER:
return WebTouchPoint::PointerTypeUnknown;
}
NOTREACHED() << "Invalid MotionEvent::ToolType = "
<< event.GetToolType(pointer_index);
return WebTouchPoint::PointerTypeUnknown;
}

WebTouchPoint CreateWebTouchPoint(const MotionEvent& event,
size_t pointer_index) {
WebTouchPoint touch;
touch.id = event.GetPointerId(pointer_index);
touch.pointerType = ToWebTouchPointPointerType(event, pointer_index);
touch.state = ToWebTouchPointState(event, pointer_index);
touch.position.x = event.GetX(pointer_index);
touch.position.y = event.GetY(pointer_index);
Expand Down

0 comments on commit 3c4c729

Please sign in to comment.