From 9f18dcfb2a55e9bc6698bfbb23fa28a624e1c880 Mon Sep 17 00:00:00 2001 From: jaril Date: Mon, 4 Nov 2019 04:52:05 +0000 Subject: [PATCH] Bug 1593302 - Fix frame timeline scrubbing so it doesn't highlight other elements r=jlast Differential Revision: https://phabricator.services.mozilla.com/D51424 --HG-- extra : moz-landing-system : lando --- .../SecondaryPanes/FrameTimeline.css | 4 ++ .../SecondaryPanes/FrameTimeline.js | 48 +++++++++---------- 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/devtools/client/debugger/src/components/SecondaryPanes/FrameTimeline.css b/devtools/client/debugger/src/components/SecondaryPanes/FrameTimeline.css index 4533d851bc60..cc509012485c 100644 --- a/devtools/client/debugger/src/components/SecondaryPanes/FrameTimeline.css +++ b/devtools/client/debugger/src/components/SecondaryPanes/FrameTimeline.css @@ -10,6 +10,10 @@ --replay-head-background: var(--theme-highlight-purple); } +body.scrubbing { + user-select: none; +} + .frame-timeline-container { border-bottom: 1px solid var(--theme-splitter-color); background-color: var(--accordion-header-background); diff --git a/devtools/client/debugger/src/components/SecondaryPanes/FrameTimeline.js b/devtools/client/debugger/src/components/SecondaryPanes/FrameTimeline.js index 0f0c818f7589..c7358e6b92a9 100644 --- a/devtools/client/debugger/src/components/SecondaryPanes/FrameTimeline.js +++ b/devtools/client/debugger/src/components/SecondaryPanes/FrameTimeline.js @@ -76,6 +76,26 @@ class FrameTimeline extends Component { displayedFrame: {}, }; + componentDidUpdate(prevProps: Props, prevState: State) { + if (!document.body) { + return; + } + + // To please Flow. + const bodyClassList = document.body.classList; + + if (this.state.scrubbing && !prevState.scrubbing) { + document.addEventListener("mousemove", this.onMouseMove); + document.addEventListener("mouseup", this.onMouseUp); + bodyClassList.add("scrubbing"); + } + if (!this.state.scrubbing && prevState.scrubbing) { + document.removeEventListener("mousemove", this.onMouseMove); + document.removeEventListener("mouseup", this.onMouseUp); + bodyClassList.remove("scrubbing"); + } + } + getProgress(clientX: number) { const { width, left } = getBoundingClientRect(this._timeline); const progress = ((clientX - left) / width) * 100; @@ -124,13 +144,8 @@ class FrameTimeline extends Component { this.setState({ scrubbing: true, percentage: progress }); }; - onMouseUp = (event: SyntheticMouseEvent<>) => { + onMouseUp = (event: MouseEvent) => { const { seekToPosition, selectedLocation } = this.props; - const { scrubbing } = this.state; - - if (!scrubbing) { - return; - } const progress = this.getProgress(event.clientX); const position = this.getPosition(progress); @@ -145,19 +160,8 @@ class FrameTimeline extends Component { } }; - onMouseMove = (event: SyntheticMouseEvent<>) => { - const { scrubbing } = this.state; - - if (!scrubbing) { - return; - } - - const { width, left } = getBoundingClientRect(this._timeline); - const percentage = ((event.clientX - left) / width) * 100; - - if (percentage < 0 || percentage > 100) { - return; - } + onMouseMove = (event: MouseEvent) => { + const percentage = this.getProgress(event.clientX); this.displayPreview(percentage); this.setState({ percentage }); @@ -260,11 +264,7 @@ class FrameTimeline extends Component { } return ( -
+
{this.renderTimeline()}
);