Commit 2ecc34b0 authored by Ella Ge's avatar Ella Ge Committed by Commit Bot

make pointerevent offsetx/y double

pointerevent fractional coordinates was shipped from M64, but
offsetx/y were left behind.
This CL makes them aligned with other coordinates, expose fractions
for pointerevents and rounded version for mouseevents.

Intent to Ship: https://groups.google.com/a/chromium.org/d/msg/blink-dev/tl2sOodhtCs/oe0ZMNXPCAAJ

Bug: 867609
Change-Id: I31af4ce01fa820e3281932e0b0a7e8bd5a6c0042
Reviewed-on: https://chromium-review.googlesource.com/1151534
Commit-Queue: Ella Ge <eirage@chromium.org>
Reviewed-by: default avatarDave Tapuska <dtapuska@chromium.org>
Reviewed-by: default avatarNavid Zolghadr <nzolghadr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#583297}
parent 4d8df637
...@@ -137,7 +137,7 @@ ...@@ -137,7 +137,7 @@
event.offsetY == event.expectedOffsetY) event.offsetY == event.expectedOffsetY)
result = 'PASS: event hit ' + element.id + ' at offset (' + event.offsetX + ', ' + event.offsetY + ')'; result = 'PASS: event hit ' + element.id + ' at offset (' + event.offsetX + ', ' + event.offsetY + ')';
else else
result = 'FAIL: event at (' + event.clientX + ', ' + event.clientY + ') expected to hit ' + event.expectedElement + ' at (' + event.expectedOffsetX + ', ' + event.expectedOffsetY + ') but hit ' + element.id + ' at (' + event.offsetX + ', ' + event.offsetY + ')'; result = 'FAIL: event expected to hit ' + event.expectedElement + ' at (' + event.expectedOffsetX + ', ' + event.expectedOffsetY + ') but hit ' + element.id + ' at (' + event.offsetX + ', ' + event.offsetY + ')';
log(result); log(result);
} }
......
<script src="../../../resources/testharness.js"></script> <script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script> <script src="../../../resources/testharnessreport.js"></script>
<style> <style>
* {
margin: 0;
}
#pusher { #pusher {
width: 1000px; width: 1000px;
height: 1000px; height: 1000px;
...@@ -42,10 +45,12 @@ ...@@ -42,10 +45,12 @@
eventFired = false; eventFired = false;
await sendMouseDownAt(100, 100); await sendMouseDownAt(100, 100);
assert_true(eventFired); assert_true(eventFired);
assert_equals(lastEvent.clientX, 100); assert_equals(lastEvent.clientX, 100, "clientX");
assert_equals(lastEvent.clientY, 100); assert_equals(lastEvent.clientY, 100, "clientY");
assert_equals(lastEvent.pageX, 100); assert_equals(lastEvent.pageX, 100, "pageX");
assert_equals(lastEvent.pageY, 100); assert_equals(lastEvent.pageY, 100, "pageY");
assert_equals(lastEvent.offsetX, 100, "offsetX");
assert_equals(lastEvent.offsetY, 100, "offsetY");
}, 'Default'); }, 'Default');
promise_test(async () => { promise_test(async () => {
...@@ -53,22 +58,26 @@ ...@@ -53,22 +58,26 @@
eventSender.setPageZoomFactor(1.2); eventSender.setPageZoomFactor(1.2);
await sendMouseDownAt(100, 100); await sendMouseDownAt(100, 100);
assert_true(eventFired); assert_true(eventFired);
assert_approx_equals(lastEvent.clientX, 83.33333, floatPrecision); assert_approx_equals(lastEvent.clientX, 83.33333, floatPrecision, "clientX");
assert_approx_equals(lastEvent.clientY, 83.33333, floatPrecision); assert_approx_equals(lastEvent.clientY, 83.33333, floatPrecision, "clientY");
assert_approx_equals(lastEvent.pageX, 83.33333, floatPrecision); assert_approx_equals(lastEvent.pageX, 83.33333, floatPrecision, "pageX");
assert_approx_equals(lastEvent.pageY, 83.33333, floatPrecision); assert_approx_equals(lastEvent.pageY, 83.33333, floatPrecision, "pageY");
eventSender.setPageZoomFactor(1.0) assert_approx_equals(lastEvent.offsetX, 83.33333, floatPrecision, "offsetX");
assert_approx_equals(lastEvent.offsetY, 83.33333, floatPrecision, "offsetY");
}, 'Zoomed'); }, 'Zoomed');
promise_test(async () => { promise_test(async () => {
eventFired = false; eventFired = false;
window.scrollTo(50, 50); window.scrollTo(50, 50);
eventSender.setPageZoomFactor(1.0)
await sendMouseDownAt(100, 100); await sendMouseDownAt(100, 100);
assert_true(eventFired); assert_true(eventFired);
assert_equals(lastEvent.clientX, 100); assert_equals(lastEvent.clientX, 100, "clientX");
assert_equals(lastEvent.clientY, 100); assert_equals(lastEvent.clientY, 100, "clientY");
assert_equals(lastEvent.pageX, 150); assert_equals(lastEvent.pageX, 150, "pageX");
assert_equals(lastEvent.pageY, 150); assert_equals(lastEvent.pageY, 150, "pageY");
assert_equals(lastEvent.offsetX, 150, "offsetX");
assert_equals(lastEvent.offsetY, 150, "offsetY");
window.scrollTo(0, 0); window.scrollTo(0, 0);
}, 'Scrolled'); }, 'Scrolled');
...@@ -78,10 +87,12 @@ ...@@ -78,10 +87,12 @@
window.scrollTo(50, 50); window.scrollTo(50, 50);
await sendMouseDownAt(100, 100); await sendMouseDownAt(100, 100);
assert_true(eventFired); assert_true(eventFired);
assert_approx_equals(lastEvent.clientX, 83.33333, floatPrecision); assert_approx_equals(lastEvent.clientX, 83.33333, floatPrecision, "clientX");
assert_approx_equals(lastEvent.clientY, 83.33333, floatPrecision); assert_approx_equals(lastEvent.clientY, 83.33333, floatPrecision, "clientY");
assert_approx_equals(lastEvent.pageX, 133.33333, floatPrecision); assert_approx_equals(lastEvent.pageX, 133.33333, floatPrecision, "pageX");
assert_approx_equals(lastEvent.pageY, 133.33333, floatPrecision); assert_approx_equals(lastEvent.pageY, 133.33333, floatPrecision, "pageY");
assert_approx_equals(lastEvent.offsetX, 133.33333, floatPrecision, "offsetX");
assert_approx_equals(lastEvent.offsetY, 133.33333, floatPrecision, "offsetY");
eventSender.setPageZoomFactor(1.0) eventSender.setPageZoomFactor(1.0)
window.scrollTo(0, 0); window.scrollTo(0, 0);
}, 'Zoomed and scrolled'); }, 'Zoomed and scrolled');
......
<script src="../../../resources/testharness.js"></script> <script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script> <script src="../../../resources/testharnessreport.js"></script>
<style> <style>
* {
margin: 0;
}
#pusher { #pusher {
width: 1000px; width: 1000px;
height: 1000px; height: 1000px;
...@@ -42,10 +45,12 @@ ...@@ -42,10 +45,12 @@
eventFired = false; eventFired = false;
await sendMouseDownAt(100, 100); await sendMouseDownAt(100, 100);
assert_true(eventFired); assert_true(eventFired);
assert_equals(lastEvent.clientX, 100); assert_equals(lastEvent.clientX, 100, "clientX");
assert_equals(lastEvent.clientY, 100); assert_equals(lastEvent.clientY, 100, "clientY");
assert_equals(lastEvent.pageX, 100); assert_equals(lastEvent.pageX, 100, "pageX");
assert_equals(lastEvent.pageY, 100); assert_equals(lastEvent.pageY, 100, "pageY");
assert_equals(lastEvent.offsetX, 100, "offsetX");
assert_equals(lastEvent.offsetY, 100, "offsetY");
}, 'Default'); }, 'Default');
promise_test(async () => { promise_test(async () => {
...@@ -53,22 +58,26 @@ ...@@ -53,22 +58,26 @@
eventSender.setPageZoomFactor(1.2); eventSender.setPageZoomFactor(1.2);
await sendMouseDownAt(100, 100); await sendMouseDownAt(100, 100);
assert_true(eventFired); assert_true(eventFired);
assert_approx_equals(lastEvent.clientX, 83.33333, floatPrecision); assert_approx_equals(lastEvent.clientX, 83.33333, floatPrecision, "clientX");
assert_approx_equals(lastEvent.clientY, 83.33333, floatPrecision); assert_approx_equals(lastEvent.clientY, 83.33333, floatPrecision, "clientY");
assert_approx_equals(lastEvent.pageX, 83.33333, floatPrecision); assert_approx_equals(lastEvent.pageX, 83.33333, floatPrecision, "pageX");
assert_approx_equals(lastEvent.pageY, 83.33333, floatPrecision); assert_approx_equals(lastEvent.pageY, 83.33333, floatPrecision, "pageY");
eventSender.setPageZoomFactor(1.0) assert_approx_equals(lastEvent.offsetX, 83.33333, floatPrecision, "offsetX");
assert_approx_equals(lastEvent.offsetY, 83.33333, floatPrecision, "offsetY");
}, 'Zoomed'); }, 'Zoomed');
promise_test(async () => { promise_test(async () => {
eventFired = false; eventFired = false;
window.scrollTo(50, 50); window.scrollTo(50, 50);
eventSender.setPageZoomFactor(1.0)
await sendMouseDownAt(100, 100); await sendMouseDownAt(100, 100);
assert_true(eventFired); assert_true(eventFired);
assert_equals(lastEvent.clientX, 100); assert_equals(lastEvent.clientX, 100, "clientX");
assert_equals(lastEvent.clientY, 100); assert_equals(lastEvent.clientY, 100, "clientY");
assert_equals(lastEvent.pageX, 150); assert_equals(lastEvent.pageX, 150, "pageX");
assert_equals(lastEvent.pageY, 150); assert_equals(lastEvent.pageY, 150, "pageY");
assert_equals(lastEvent.offsetX, 150, "offsetX");
assert_equals(lastEvent.offsetY, 150, "offsetY");
window.scrollTo(0, 0); window.scrollTo(0, 0);
}, 'Scrolled'); }, 'Scrolled');
...@@ -78,10 +87,12 @@ ...@@ -78,10 +87,12 @@
window.scrollTo(50, 50); window.scrollTo(50, 50);
await sendMouseDownAt(100, 100); await sendMouseDownAt(100, 100);
assert_true(eventFired); assert_true(eventFired);
assert_approx_equals(lastEvent.clientX, 83.33333, floatPrecision); assert_approx_equals(lastEvent.clientX, 83.33333, floatPrecision, "clientX");
assert_approx_equals(lastEvent.clientY, 83.33333, floatPrecision); assert_approx_equals(lastEvent.clientY, 83.33333, floatPrecision, "clientY");
assert_approx_equals(lastEvent.pageX, 133.33333, floatPrecision); assert_approx_equals(lastEvent.pageX, 133.33333, floatPrecision, "pageX");
assert_approx_equals(lastEvent.pageY, 133.33333, floatPrecision); assert_approx_equals(lastEvent.pageY, 133.33333, floatPrecision, "pageY");
assert_approx_equals(lastEvent.offsetX, 133.33333, floatPrecision, "offsetX");
assert_approx_equals(lastEvent.offsetY, 133.33333, floatPrecision, "offsetY");
eventSender.setPageZoomFactor(1.0) eventSender.setPageZoomFactor(1.0)
window.scrollTo(0, 0); window.scrollTo(0, 0);
}, 'Zoomed and scrolled'); }, 'Zoomed and scrolled');
......
Absolute
Relative
Fixed
x x
Table Content
In Columns
Transformed
In RTL overflow
PASS: event at (109, 57) hit absolute at offset (19, 22)
PASS: event at (161, 13) hit relative at offset (21, 18)
PASS: event at (40, 297) hit table-content at offset (5, 8)
FAIL: event at (122, 407) expected to hit transformed at (8, 5) but hit transformed at (7.713230133056641, 5.262882232666016)
PASS: event at (573, 480) hit inside-overflow at offset (2, 9)
FAIL: event at (707, 174) expected to hit in-columns at (87, 13) but hit in-columns at (87.34375, 13)
PASS: event at (241, 67) hit fixed at offset (31, 7)
PASS: event at (244, 102) hit fixed at offset (34, 42)
PASS: event at (388, 88) hit fixed at offset (178, 28)
Absolute position
Relative position
Fixed position
First Second
This cell has borderTopExtra
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
In columns
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Div with transform
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
In RTL overflow
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
PASS: event hit abs-box at offset (17, 22)
PASS: event hit rel-box at offset (22, 24)
PASS: event hit fixed-box at offset (10, 10)
PASS: event hit with-bordertopextra at offset (4, 4)
FAIL: event expected to hit in-columns at (35, 5) but hit in-columns at (34.8125, 5)
PASS: event hit inside-overflow at offset (7, 6)
FAIL: event expected to hit transformed at (11, 16) but hit transformed at (10.535758972167969, 15.941521644592285)
...@@ -173,7 +173,6 @@ MouseEvent* MouseEvent::Create(const AtomicString& event_type, ...@@ -173,7 +173,6 @@ MouseEvent* MouseEvent::Create(const AtomicString& event_type,
MouseEvent::MouseEvent() MouseEvent::MouseEvent()
: position_type_(PositionType::kPosition), : position_type_(PositionType::kPosition),
has_cached_relative_position_(false),
button_(0), button_(0),
buttons_(0), buttons_(0),
related_target_(nullptr), related_target_(nullptr),
...@@ -527,6 +526,7 @@ int MouseEvent::layerX() { ...@@ -527,6 +526,7 @@ int MouseEvent::layerX() {
// TODO(mustaq): Remove the PointerEvent specific code when mouse has // TODO(mustaq): Remove the PointerEvent specific code when mouse has
// fractional coordinates. See crbug.com/655786. // fractional coordinates. See crbug.com/655786.
return IsPointerEvent() ? layer_location_.X() return IsPointerEvent() ? layer_location_.X()
: static_cast<int>(layer_location_.X()); : static_cast<int>(layer_location_.X());
} }
...@@ -537,24 +537,29 @@ int MouseEvent::layerY() { ...@@ -537,24 +537,29 @@ int MouseEvent::layerY() {
// TODO(mustaq): Remove the PointerEvent specific code when mouse has // TODO(mustaq): Remove the PointerEvent specific code when mouse has
// fractional coordinates. See crbug.com/655786. // fractional coordinates. See crbug.com/655786.
return IsPointerEvent() ? layer_location_.Y() return IsPointerEvent() ? layer_location_.Y()
: static_cast<int>(layer_location_.Y()); : static_cast<int>(layer_location_.Y());
} }
int MouseEvent::offsetX() { double MouseEvent::offsetX() {
if (!HasPosition()) if (!HasPosition())
return 0; return 0;
if (!has_cached_relative_position_) if (!has_cached_relative_position_)
ComputeRelativePosition(); ComputeRelativePosition();
return std::round(offset_location_.X()); return (RuntimeEnabledFeatures::FractionalMouseEventEnabled())
? offset_location_.X()
: std::round(offset_location_.X());
} }
int MouseEvent::offsetY() { double MouseEvent::offsetY() {
if (!HasPosition()) if (!HasPosition())
return 0; return 0;
if (!has_cached_relative_position_) if (!has_cached_relative_position_)
ComputeRelativePosition(); ComputeRelativePosition();
return std::round(offset_location_.Y()); return (RuntimeEnabledFeatures::FractionalMouseEventEnabled())
? offset_location_.Y()
: std::round(offset_location_.Y());
} }
} // namespace blink } // namespace blink
...@@ -159,8 +159,8 @@ class CORE_EXPORT MouseEvent : public UIEventWithKeyState { ...@@ -159,8 +159,8 @@ class CORE_EXPORT MouseEvent : public UIEventWithKeyState {
int layerX(); int layerX();
int layerY(); int layerY();
int offsetX(); virtual double offsetX();
int offsetY(); virtual double offsetY();
virtual double pageX() const { virtual double pageX() const {
return (RuntimeEnabledFeatures::FractionalMouseEventEnabled()) return (RuntimeEnabledFeatures::FractionalMouseEventEnabled())
...@@ -206,11 +206,16 @@ class CORE_EXPORT MouseEvent : public UIEventWithKeyState { ...@@ -206,11 +206,16 @@ class CORE_EXPORT MouseEvent : public UIEventWithKeyState {
void ReceivedTarget() override; void ReceivedTarget() override;
// TODO(eirage): Move these coordinates back to private when MouseEvent // TODO(eirage): Move these coordinates related field back to private
// fractional flag is removed. // when MouseEvent fractional flag is removed.
void ComputeRelativePosition();
DoublePoint screen_location_; DoublePoint screen_location_;
DoublePoint client_location_; DoublePoint client_location_;
DoublePoint page_location_; // zoomed CSS pixels DoublePoint page_location_; // zoomed CSS pixels
DoublePoint offset_location_; // zoomed CSS pixels
bool has_cached_relative_position_ = false;
private: private:
void InitMouseEventInternal(const AtomicString& type, void InitMouseEventInternal(const AtomicString& type,
...@@ -231,15 +236,12 @@ class CORE_EXPORT MouseEvent : public UIEventWithKeyState { ...@@ -231,15 +236,12 @@ class CORE_EXPORT MouseEvent : public UIEventWithKeyState {
void InitCoordinates(const double client_x, const double client_y); void InitCoordinates(const double client_x, const double client_y);
void ComputePageLocation(); void ComputePageLocation();
void ComputeRelativePosition();
DoublePoint movement_delta_; DoublePoint movement_delta_;
DoublePoint layer_location_; // zoomed CSS pixels DoublePoint layer_location_; // zoomed CSS pixels
DoublePoint offset_location_; // zoomed CSS pixels
DoublePoint absolute_location_; // (un-zoomed) FrameView content space DoublePoint absolute_location_; // (un-zoomed) FrameView content space
PositionType position_type_; PositionType position_type_;
bool has_cached_relative_position_;
short button_; short button_;
unsigned short buttons_; unsigned short buttons_;
Member<EventTarget> related_target_; Member<EventTarget> related_target_;
......
...@@ -99,6 +99,28 @@ double PointerEvent::pageY() const { ...@@ -99,6 +99,28 @@ double PointerEvent::pageY() const {
: page_location_.Y(); : page_location_.Y();
} }
double PointerEvent::offsetX() {
if (!HasPosition())
return 0;
if (!has_cached_relative_position_)
ComputeRelativePosition();
return (!RuntimeEnabledFeatures::FractionalMouseTypePointerEventEnabled() &&
pointer_type_ == "mouse")
? std::round(offset_location_.X())
: offset_location_.X();
}
double PointerEvent::offsetY() {
if (!HasPosition())
return 0;
if (!has_cached_relative_position_)
ComputeRelativePosition();
return (!RuntimeEnabledFeatures::FractionalMouseTypePointerEventEnabled() &&
pointer_type_ == "mouse")
? std::round(offset_location_.Y())
: offset_location_.Y();
}
void PointerEvent::ReceivedTarget() { void PointerEvent::ReceivedTarget() {
coalesced_events_targets_dirty_ = true; coalesced_events_targets_dirty_ = true;
MouseEvent::ReceivedTarget(); MouseEvent::ReceivedTarget();
......
...@@ -48,6 +48,9 @@ class CORE_EXPORT PointerEvent final : public MouseEvent { ...@@ -48,6 +48,9 @@ class CORE_EXPORT PointerEvent final : public MouseEvent {
double pageX() const override; double pageX() const override;
double pageY() const override; double pageY() const override;
double offsetX() override;
double offsetY() override;
void ReceivedTarget() override; void ReceivedTarget() override;
// Always return null for fromElement and toElement because these fields // Always return null for fromElement and toElement because these fields
......
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