Commit e08cca3a authored by Ella Ge's avatar Ella Ge Committed by Commit Bot

Make touch adjustment range upperbound respect zoom_factor

We used to have the touch adjustment range as 32dip in diameter (16dip
in radius) for Android. After the zoom-for-dsf change, the pointerevent
width & height became in physical pixel. It makes the actually range in
dip much smaller on Android.

This CL changes the adjustment range to be 32 CSS pixel, and apply the
zoom_factor before compare with the pointerevent width&height.

On Android, there is no ctrl +/- page zoom, so CSS pixel is dip. There
is no change in behavior.
On Desktop (aura), the adjustment upperbound is affected as it wasn't
consider zooming before but now it does. Therefore, the bound will be
affected by zoom_factor.
On aura, there wasn't an upper bound for adjustment range before the
unified touch adjustment change, which means the adjustment range is
always the pointerevent width & height (physical pixel not changed).
When we zoom in, the upper bound is increased, but the adjustment range
will follow the finger size. So I think it's ok to make the bound
changing with zooming as well on aura.

Bug: 894961
Change-Id: I466d6b187359f13c82c62860086cb9eeef8cb2a5
Reviewed-on: https://chromium-review.googlesource.com/c/1279204
Commit-Queue: Ella Ge <eirage@chromium.org>
Reviewed-by: default avatarRick Byers <rbyers@chromium.org>
Reviewed-by: default avatarNavid Zolghadr <nzolghadr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#600126}
parent 77787bcb
<!DOCTYPE html>
<meta charset="utf-8">
<title>Touch-generated events should have the same target</title>
<script src="../../../../resources/testharness.js"></script>
<script src="../../../../resources/testharnessreport.js"></script>
<body onload="inject_input()">
<p>Touch letter 'O' below to run the test. If a "PASS" result appears the test passes, otherwise it fails</p>
<p><a href="#" id="link" style="margin:3px">Link</a> <span id="target">O</span></p>
<div id="log"></div>
</body>
<script>
const target = document.getElementById('target');
const xPosition = target.offsetLeft + 2;
const yPosition = target.offsetTop + 2;
async_test(t => {
const link = document.getElementById('link');
const expectedEventLog = ['pointerdown-link', 'touchstart-link', 'pointerup-link', 'touchend-link', 'click-link'];
const eventLogRecorder = [];
const eventNames = ['touchstart', 'touchmove', 'touchend', 'pointerdown', 'pointermove', 'pointerup', 'click'];
for (eventName of eventNames) {
document.addEventListener(eventName, t.step_func(event => {
// TouchEvent and PointerEvent should have the same un-adjusted coordinates.
// click event should have coordinates adjusted to link element.
const eventClientX = event.clientX || (event.touches.length > 0 ? event.touches[0].clientX : 0);
const eventClientY = event.clientY || (event.touches.length > 0 ? event.touches[0].clientY : 0);
if (event.type === 'click') {
assert_equals(document.elementFromPoint(eventClientX, eventClientY), link,
'click should have clientX/Y adjusted to link.');
} else if (event.type != 'touchend') {
assert_equals(eventClientX, xPosition,
`${event.type} should have un-adjusted x coordinates.`);
assert_equals(eventClientY, yPosition,
`${event.type} should have un-adjusted y coordinates.`);
}
// All events should have target adjusted to link.
const targetName = event.target.id || event.target.nodeName || '[null]';
eventLogRecorder.push(`${event.type}-${targetName}`);
if (event.type === 'click') {
assert_array_equals(eventLogRecorder, expectedEventLog);
t.done();
}
}));
}
});
</script>
<script>
function inject_input() {
return new Promise(function(resolve, reject) {
if (window.chrome && chrome.gpuBenchmarking) {
chrome.gpuBenchmarking.pointerActionSequence( [
{source: 'touch',
actions: [
{ name: 'pointerDown', x: xPosition, y: yPosition },
{ name: 'pointerUp' }
]}], resolve);
} else {
reject();
}
});
}
</script>
\ No newline at end of file
...@@ -1752,7 +1752,8 @@ GestureEventWithHitTestResults EventHandler::HitTestResultForGestureEvent( ...@@ -1752,7 +1752,8 @@ GestureEventWithHitTestResults EventHandler::HitTestResultForGestureEvent(
touch_adjustment_result_.adjusted_point); touch_adjustment_result_.adjusted_point);
} else { } else {
hit_rect_size = GetHitTestRectForAdjustment( hit_rect_size = GetHitTestRectForAdjustment(
LayoutSize(adjusted_event.TapAreaInRootFrame())); LayoutSize(adjusted_event.TapAreaInRootFrame()),
frame_->PageZoomFactor());
if (!hit_rect_size.IsEmpty()) if (!hit_rect_size.IsEmpty())
hit_type |= HitTestRequest::kListBased; hit_type |= HitTestRequest::kListBased;
} }
......
...@@ -326,7 +326,8 @@ void PointerEventManager::AdjustTouchPointerEvent( ...@@ -326,7 +326,8 @@ void PointerEventManager::AdjustTouchPointerEvent(
WebPointerProperties::PointerType::kTouch); WebPointerProperties::PointerType::kTouch);
LayoutSize hit_rect_size = GetHitTestRectForAdjustment( LayoutSize hit_rect_size = GetHitTestRectForAdjustment(
LayoutSize(pointer_event.width, pointer_event.height)); LayoutSize(pointer_event.width, pointer_event.height),
frame_->PageZoomFactor());
if (hit_rect_size.IsEmpty()) if (hit_rect_size.IsEmpty())
return; return;
......
...@@ -44,7 +44,8 @@ namespace blink { ...@@ -44,7 +44,8 @@ namespace blink {
namespace touch_adjustment { namespace touch_adjustment {
const float kZeroTolerance = 1e-6f; const float kZeroTolerance = 1e-6f;
constexpr float kMaxAdjustmentSizeDips = 32.f; // The maximum adjustment range (diameters) in css pixel.
constexpr float kMaxAdjustmentSize = 32.f;
// Class for remembering absolute quads of a target node and what node they // Class for remembering absolute quads of a target node and what node they
// represent. // represent.
...@@ -513,10 +514,11 @@ bool FindBestContextMenuCandidate(Node*& target_node, ...@@ -513,10 +514,11 @@ bool FindBestContextMenuCandidate(Node*& target_node,
subtargets, touch_adjustment::HybridDistanceFunction); subtargets, touch_adjustment::HybridDistanceFunction);
} }
LayoutSize GetHitTestRectForAdjustment(const LayoutSize& touch_area) { LayoutSize GetHitTestRectForAdjustment(const LayoutSize& touch_area,
const LayoutSize max_size(touch_adjustment::kMaxAdjustmentSizeDips, float zoom_factor) {
touch_adjustment::kMaxAdjustmentSizeDips); const LayoutSize max_size(touch_adjustment::kMaxAdjustmentSize,
return touch_area.ShrunkTo(max_size); touch_adjustment::kMaxAdjustmentSize);
return touch_area.ShrunkTo(max_size * zoom_factor);
} }
} // namespace blink } // namespace blink
...@@ -43,7 +43,11 @@ bool FindBestContextMenuCandidate(Node*& target_node, ...@@ -43,7 +43,11 @@ bool FindBestContextMenuCandidate(Node*& target_node,
const IntRect& touch_area, const IntRect& touch_area,
const HeapVector<Member<Node>>&); const HeapVector<Member<Node>>&);
LayoutSize GetHitTestRectForAdjustment(const LayoutSize& touch_area); // Applies an upper bound to the touch area as the adjustment rect. The
// touch_area is in root frame coordinates, which is in physical pixel when
// zoom-for-dsf is enabled, otherwise in dip (when page scale is 1).
LayoutSize GetHitTestRectForAdjustment(const LayoutSize& touch_area,
float zoom_factor);
struct TouchAdjustmentResult { struct TouchAdjustmentResult {
uint32_t unique_event_id; uint32_t unique_event_id;
......
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