Skip to content
Merged
18 changes: 11 additions & 7 deletions images/chromium-headful/client/src/components/video.vue
Original file line number Diff line number Diff line change
Expand Up @@ -712,11 +712,8 @@
let x = e.deltaX
let y = e.deltaY

// Pixel units unless it's non-zero.
// Note that if deltamode is line or page won't matter since we aren't
// sending the mouse wheel delta to the server anyway.
// The difference between pixel and line can be important however since
// we have a threshold that can be smaller than the line height.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this comment seems useful? and maybe should be expanded with the change in this pr

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch — restored the comment and expanded it to explain the PIXELS_PER_TICK divisor, the 1:1 mapping to XTestFakeButtonEvents, and how the scroll setting clamps fast swipes.

// Normalize to pixel units. deltaMode 1 = lines, 2 = pages; convert
// both to approximate pixel values so the divisor below works uniformly.
if (e.deltaMode !== 0) {
x *= WHEEL_LINE_HEIGHT
y *= WHEEL_LINE_HEIGHT
Expand All @@ -727,8 +724,15 @@
y = y * -1
}

x = Math.min(Math.max(x, -this.scroll), this.scroll)
y = Math.min(Math.max(y, -this.scroll), this.scroll)
// The server sends one XTestFakeButtonEvent per unit we pass here,
// and each event scrolls Chromium by ~120 px. Raw pixel deltas from
// trackpads are already in pixels (~120 per notch), so dividing by
// PIXELS_PER_TICK converts them to discrete scroll "ticks". The
// result is clamped to [-scroll, scroll] (the user-facing sensitivity
// setting) so fast swipes don't over-scroll.
const PIXELS_PER_TICK = 120
x = x === 0 ? 0 : Math.min(Math.max(Math.round(x / PIXELS_PER_TICK) || Math.sign(x), -this.scroll), this.scroll)
y = y === 0 ? 0 : Math.min(Math.max(Math.round(y / PIXELS_PER_TICK) || Math.sign(y), -this.scroll), this.scroll)

this.sendMousePos(e)

Expand Down
Loading