Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions core/browser_events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ const LINE_MODE_MULTIPLIER = 40;
*/
const PAGE_MODE_MULTIPLIER = 125;

/**
* Options to control the behavior of bound event listeners. Based on
* https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#options
* and should be kept consistent with web standards as they evolve.
*/
export type BindOptions = {
capture?: boolean;
once?: boolean;
passive?: boolean;
signal?: AbortSignal;
};

/**
* Bind an event handler that can be ignored if it is not part of the active
* touch stream.
Expand All @@ -46,6 +58,9 @@ const PAGE_MODE_MULTIPLIER = 125;
* @param opt_noCaptureIdentifier True if triggering on this event should not
* block execution of other event handlers on this touch or other
* simultaneous touches. False by default.
* @param options An object with options controlling the behavior of the event
* listener. Passed through directly as the third argument to
* `addEventListener`.
* @returns Opaque data that can be passed to unbindEvent_.
*/
export function conditionalBind(
Expand All @@ -54,6 +69,7 @@ export function conditionalBind(
thisObject: object | null,
func: Function,
opt_noCaptureIdentifier?: boolean,
options?: BindOptions,
): Data {
/**
*
Expand All @@ -75,11 +91,11 @@ export function conditionalBind(
if (name in Touch.TOUCH_MAP) {
for (let i = 0; i < Touch.TOUCH_MAP[name].length; i++) {
const type = Touch.TOUCH_MAP[name][i];
node.addEventListener(type, wrapFunc, false);
node.addEventListener(type, wrapFunc, {capture: false, ...options});
bindData.push([node, type, wrapFunc]);
}
} else {
node.addEventListener(name, wrapFunc, false);
node.addEventListener(name, wrapFunc, {capture: false, ...options});
bindData.push([node, name, wrapFunc]);
}
return bindData;
Expand All @@ -95,13 +111,17 @@ export function conditionalBind(
* @param name Event name to listen to (e.g. 'mousedown').
* @param thisObject The value of 'this' in the function.
* @param func Function to call when event is triggered.
* @param options An object with options controlling the behavior of the event
* listener. Passed through directly as the third argument to
* `addEventListener`.
* @returns Opaque data that can be passed to unbindEvent_.
*/
export function bind(
node: EventTarget,
name: string,
thisObject: object | null,
func: Function,
options?: BindOptions,
): Data {
/**
*
Expand All @@ -119,11 +139,11 @@ export function bind(
if (name in Touch.TOUCH_MAP) {
for (let i = 0; i < Touch.TOUCH_MAP[name].length; i++) {
const type = Touch.TOUCH_MAP[name][i];
node.addEventListener(type, wrapFunc, false);
node.addEventListener(type, wrapFunc, {capture: false, ...options});
bindData.push([node, type, wrapFunc]);
}
} else {
node.addEventListener(name, wrapFunc, false);
node.addEventListener(name, wrapFunc, {capture: false, ...options});
bindData.push([node, name, wrapFunc]);
}
return bindData;
Expand Down
13 changes: 10 additions & 3 deletions core/comments/comment_editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,16 @@ export class CommentEditor implements IFocusableNode {
);

// Don't zoom with mousewheel; let it scroll instead.
browserEvents.conditionalBind(this.textArea, 'wheel', this, (e: Event) => {
e.stopPropagation();
});
browserEvents.conditionalBind(
this.textArea,
'wheel',
this,
(e: Event) => {
e.stopPropagation();
},
false,
{passive: true},
);

// Register listener for keydown events that would finish editing.
browserEvents.conditionalBind(
Expand Down
2 changes: 2 additions & 0 deletions core/flyout_base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,8 @@ export abstract class Flyout
'wheel',
this,
this.wheel_,
false,
{passive: false},
),
);

Expand Down
1 change: 1 addition & 0 deletions core/inject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ function loadSounds(pathToMedia: string, workspace: WorkspaceSvg) {
null,
unbindSounds,
true,
{passive: true},
),
);
}
6 changes: 5 additions & 1 deletion core/workspace_svg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -809,12 +809,16 @@ export class WorkspaceSvg
// which otherwise prevents zoom/scroll events from being observed in
// Safari. Once that bug is fixed it should be removed.
this.dummyWheelListener = () => {};
document.body.addEventListener('wheel', this.dummyWheelListener);
document.body.addEventListener('wheel', this.dummyWheelListener, {
passive: true,
});
browserEvents.conditionalBind(
this.svgGroup_,
'wheel',
this,
this.onMouseWheel,
false,
{passive: false},
);
}

Expand Down
Loading