Skip to content

Commit 1534fcf

Browse files
AlinaVarkkiDevtools-frontend LUCI CQ
authored andcommitted
[RPP] Refactor onMouseWheel method and add the 'Modern' method scroll behaviours
Bug: 313757601 Change-Id: Ib35f12e1bfb3a4e4f68f8c017b476779998f840f Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6063482 Commit-Queue: Alina Varkki <[email protected]> Reviewed-by: Jack Franklin <[email protected]> Auto-Submit: Alina Varkki <[email protected]>
1 parent 0446077 commit 1534fcf

File tree

2 files changed

+36
-16
lines changed

2 files changed

+36
-16
lines changed

front_end/ui/components/dialogs/shortcutDialog.css

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@
7070
.nav-radio-buttons {
7171
display: flex;
7272
flex-direction: column;
73-
padding: 0 var(--sys-size-8) var(--sys-size-4) var(--sys-size-8);
74-
gap: var(--sys-size-3);
7573
border-bottom: var(--sys-size-1) solid var(--sys-color-divider);
7674
}
7775

front_end/ui/legacy/components/perf_ui/ChartViewport.ts

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -206,23 +206,45 @@ export class ChartViewport extends UI.Widget.VBox {
206206
this.totalTime = totalTime;
207207
}
208208

209-
private onMouseWheel(e: Event): void {
210-
const wheelEvent = (e as WheelEvent);
211-
const doZoomInstead = wheelEvent.shiftKey !==
212-
(Common.Settings.Settings.instance().moduleSetting('flamechart-selected-navigation').get() === 'classic');
213-
const panVertically = !doZoomInstead && (wheelEvent.deltaY || Math.abs(wheelEvent.deltaX) === 53);
214-
const panHorizontally = doZoomInstead && Math.abs(wheelEvent.deltaX) > Math.abs(wheelEvent.deltaY);
215-
if (panVertically) {
216-
this.vScrollElement.scrollTop += (wheelEvent.deltaY || wheelEvent.deltaX) / 53 * this.offsetHeight / 8;
217-
} else if (panHorizontally) {
218-
this.handlePanGesture(wheelEvent.deltaX, /* animate */ true);
219-
} else { // Zoom.
220-
const wheelZoomSpeed = 1 / 53;
221-
this.handleZoomGesture(Math.pow(1.2, (wheelEvent.deltaY || wheelEvent.deltaX) * wheelZoomSpeed) - 1);
209+
/**
210+
* The mouse wheel can results in flamechart zoom, scroll and pan actions, depending on the scroll deltas and the selected navigation:
211+
*
212+
* Classic navigation:
213+
* 1. Mouse Wheel --> Zoom
214+
* 2. Mouse Wheel + Shift --> Scroll
215+
* 3. Trackpad: Mouse Wheel AND horizontal scroll (deltaX > deltaY): --> Pan left/right
216+
*
217+
* Modern navigation:
218+
* 1. Mouse Wheel -> Scroll
219+
* 2. Mouse Wheel + Shift -> Pan left/right
220+
* 3. Mouse Wheel + Ctrl/Cmd -> Zoom
221+
* 4. Trackpad: Mouse Wheel AND horizontal scroll (deltaX > deltaY): --> Zoom
222+
*/
223+
private onMouseWheel(wheelEvent: WheelEvent): void {
224+
const navigation = Common.Settings.Settings.instance().moduleSetting('flamechart-selected-navigation').get();
225+
const scrollDelta = (wheelEvent.deltaY || wheelEvent.deltaX) / 53 * this.offsetHeight / 8;
226+
const zoomDelta = Math.pow(1.2, (wheelEvent.deltaY || wheelEvent.deltaX) * 1 / 53) - 1;
227+
228+
if (navigation === 'classic') {
229+
if (wheelEvent.shiftKey) { // Scroll
230+
this.vScrollElement.scrollTop += scrollDelta;
231+
} else if (Math.abs(wheelEvent.deltaX) > Math.abs(wheelEvent.deltaY)) { // Pan left/right
232+
this.handlePanGesture(wheelEvent.deltaX, /* animate */ true);
233+
} else { // Zoom
234+
this.handleZoomGesture(zoomDelta);
235+
}
236+
} else if (navigation === 'modern') {
237+
if (wheelEvent.shiftKey) { // Pan left/right
238+
this.handlePanGesture(wheelEvent.deltaY, /* animate */ true);
239+
} else if (wheelEvent.ctrlKey || Math.abs(wheelEvent.deltaX) > Math.abs(wheelEvent.deltaY)) { // Zoom
240+
this.handleZoomGesture(zoomDelta);
241+
} else { // Scroll
242+
this.vScrollElement.scrollTop += scrollDelta;
243+
}
222244
}
223245

224246
// Block swipe gesture.
225-
e.consume(true);
247+
wheelEvent.consume(true);
226248
}
227249

228250
private startDragging(event: MouseEvent): boolean {

0 commit comments

Comments
 (0)