Skip to content

Commit

Permalink
Do not increase the pointer id when type is eraser
Browse files Browse the repository at this point in the history
We are setting the pointer type to eraser when using an eraser button. We
should not increase the pointer id in this case, because it should be
considered as a pen type.

BUG=685252

Review-Url: https://codereview.chromium.org/2867093003
Cr-Commit-Position: refs/heads/master@{#471391}
  • Loading branch information
LanWei22 authored and Commit bot committed May 12, 2017
1 parent 1720aab commit 0474c2a
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 27 deletions.
37 changes: 27 additions & 10 deletions content/shell/test_runner/event_sender.cc
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ class EventSenderBindings : public gin::Wrappable<EventSenderBindings> {
void GestureTwoFingerTap(gin::Arguments* args);
void ContinuousMouseScrollBy(gin::Arguments* args);
void MouseMoveTo(gin::Arguments* args);
void MouseLeave();
void MouseLeave(gin::Arguments* args);
void MouseScrollBy(gin::Arguments* args);
void ScheduleAsynchronousClick(gin::Arguments* args);
void ScheduleAsynchronousKeyDown(gin::Arguments* args);
Expand Down Expand Up @@ -1015,9 +1015,24 @@ void EventSenderBindings::MouseMoveTo(gin::Arguments* args) {
sender_->MouseMoveTo(args);
}

void EventSenderBindings::MouseLeave() {
if (sender_)
sender_->MouseLeave();
void EventSenderBindings::MouseLeave(gin::Arguments* args) {
if (!sender_)
return;

WebPointerProperties::PointerType pointerType =
WebPointerProperties::PointerType::kMouse;
int pointerId = kRawMousePointerId;

// Only allow pen or mouse through this API.
if (!getPointerType(args, false, pointerType))
return;
if (!args->PeekNext().IsEmpty()) {
if (!args->GetNext(&pointerId)) {
args->ThrowError();
return;
}
}
sender_->MouseLeave(pointerType, pointerId);
}

void EventSenderBindings::MouseScrollBy(gin::Arguments* args) {
Expand Down Expand Up @@ -2211,16 +2226,18 @@ void EventSender::MouseMoveTo(gin::Arguments* args) {
}
}

void EventSender::MouseLeave() {
void EventSender::MouseLeave(
blink::WebPointerProperties::PointerType pointerType,
int pointerId) {
if (force_layout_on_events_)
widget()->UpdateAllLifecyclePhases();

WebMouseEvent event(WebInputEvent::kMouseLeave,
ModifiersForPointer(kRawMousePointerId),
GetCurrentEventTimeSec());
InitMouseEvent(WebMouseEvent::Button::kNoButton, 0,
current_pointer_state_[kRawMousePointerId].last_pos_,
click_count_, &event);
ModifiersForPointer(pointerId), GetCurrentEventTimeSec());
InitMouseEventGeneric(WebMouseEvent::Button::kNoButton, 0,
current_pointer_state_[kRawMousePointerId].last_pos_,
click_count_, pointerType, pointerId, 0.0, 0, 0,
&event);
HandleInputEventOnViewOrPopup(event);
}

Expand Down
2 changes: 1 addition & 1 deletion content/shell/test_runner/event_sender.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class EventSender {

void MouseScrollBy(gin::Arguments* args, MouseScrollType scroll_type);
void MouseMoveTo(gin::Arguments* args);
void MouseLeave();
void MouseLeave(blink::WebPointerProperties::PointerType, int pointerId);
void ScheduleAsynchronousClick(int button_number, int modifiers);
void ScheduleAsynchronousKeyDown(const std::string& code_str,
int modifiers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@

debug("--- move pen out of target ---");
eventSender.mouseMoveTo(x - 5, y - 5, [], inputPointerType, penId, penPressure, penTiltX, penTiltY);

eventSender.mouseLeave(inputPointerType, penId);
debug("");
}

Expand Down
27 changes: 15 additions & 12 deletions third_party/WebKit/Source/core/events/PointerEventFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@ inline int ToInt(WebPointerProperties::PointerType t) {

const char* PointerTypeNameForWebPointPointerType(
WebPointerProperties::PointerType type) {
// TODO(mustaq): Fix when the spec starts supporting hovering erasers.
switch (type) {
case WebPointerProperties::PointerType::kUnknown:
return "";
case WebPointerProperties::PointerType::kTouch:
return "touch";
case WebPointerProperties::PointerType::kPen:
case WebPointerProperties::PointerType::kEraser:
// TODO(mustaq): Fix when the spec starts supporting hovering erasers.
return "pen";
case WebPointerProperties::PointerType::kMouse:
return "mouse";
default:
NOTREACHED();
return "";
}
NOTREACHED();
return "";
}

const AtomicString& PointerEventNameForMouseEventName(
Expand Down Expand Up @@ -188,21 +188,22 @@ void PointerEventFactory::SetIdTypeButtons(
PointerEventInit& pointer_event_init,
const WebPointerProperties& pointer_properties,
unsigned buttons) {
const WebPointerProperties::PointerType pointer_type =
WebPointerProperties::PointerType pointer_type =
pointer_properties.pointer_type;
const IncomingId incoming_id(pointer_type, pointer_properties.id);
int pointer_id = AddIdAndActiveButtons(incoming_id, buttons != 0);

// Tweak the |buttons| to reflect pen eraser mode only if the pen is in
// active buttons state w/o even considering the eraser button.
// TODO(mustaq): Fix when the spec starts supporting hovering erasers.
if (pointer_type == WebPointerProperties::PointerType::kEraser &&
buttons != 0) {
buttons |= static_cast<unsigned>(WebPointerProperties::Buttons::kEraser);
buttons &= ~static_cast<unsigned>(WebPointerProperties::Buttons::kLeft);
if (pointer_type == WebPointerProperties::PointerType::kEraser) {
if (buttons != 0) {
buttons |= static_cast<unsigned>(WebPointerProperties::Buttons::kEraser);
buttons &= ~static_cast<unsigned>(WebPointerProperties::Buttons::kLeft);
}
pointer_type = WebPointerProperties::PointerType::kPen;
}
pointer_event_init.setButtons(buttons);

const IncomingId incoming_id(pointer_type, pointer_properties.id);
int pointer_id = AddIdAndActiveButtons(incoming_id, buttons != 0);
pointer_event_init.setPointerId(pointer_id);
pointer_event_init.setPointerType(
PointerTypeNameForWebPointPointerType(pointer_type));
Expand Down Expand Up @@ -515,6 +516,8 @@ bool PointerEventFactory::Remove(const int mapped_id) {
return true;
}

// This function does not work with pointer type of eraser, because we save
// them as pen type in the pointer id map.
Vector<int> PointerEventFactory::GetPointerIdsOfType(
WebPointerProperties::PointerType pointer_type) const {
Vector<int> mapped_ids;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ const char* PointerTypeNameForWebPointPointerType(
case WebPointerProperties::PointerType::kTouch:
return "touch";
case WebPointerProperties::PointerType::kPen:
case WebPointerProperties::PointerType::kEraser:
return "pen";
case WebPointerProperties::PointerType::kMouse:
return "mouse";
default:
NOTREACHED();
return "";
}
NOTREACHED();
return "";
}
}

Expand Down

0 comments on commit 0474c2a

Please sign in to comment.