Skip to content

Commit 97d01c7

Browse files
committed
real BL-15721 wip
1 parent 8e613af commit 97d01c7

4 files changed

Lines changed: 48 additions & 22 deletions

File tree

src/BloomBrowserUI/bookEdit/css/editMode.less

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1642,21 +1642,34 @@ svg.bloom-videoControl {
16421642
}
16431643
}
16441644

1645+
// Detector above the canvas so we can detect hover and clicks of playback controls
1646+
.bloom-videoMouseDetector {
1647+
height: 100%;
1648+
width: 100%;
1649+
position: absolute;
1650+
top: 0;
1651+
z-index: @canvasElementCanvasZIndex + 1;
1652+
}
1653+
16451654
// Show pause and replay when playing and hovered.
1646-
.bloom-videoContainer.playing:hover {
1647-
.bloom-videoControlContainer {
1648-
&.bloom-videoPauseIcon,
1649-
&.bloom-videoReplayIcon {
1650-
display: flex;
1655+
.bloom-videoContainer.playing {
1656+
.bloom-videoMouseDetector:hover {
1657+
.bloom-videoControlContainer {
1658+
&.bloom-videoPauseIcon,
1659+
&.bloom-videoReplayIcon {
1660+
display: flex;
1661+
}
16511662
}
16521663
}
16531664
}
16541665

16551666
// Show play, centered, when hovering a video that is not paused or playing
1656-
.bloom-videoContainer:not(.paused):not(.playing):hover {
1657-
.bloom-videoPlayIcon {
1658-
display: flex;
1659-
left: calc(50% - @videoIconSize / 2);
1667+
.bloom-videoContainer:not(.paused):not(.playing) {
1668+
.bloom-videoMouseDetector:hover {
1669+
.bloom-videoPlayIcon {
1670+
display: flex;
1671+
left: calc(50% - @videoIconSize / 2);
1672+
}
16601673
}
16611674
}
16621675

@@ -1674,6 +1687,13 @@ svg.bloom-videoControl {
16741687
}
16751688
}
16761689

1690+
// TODO copilot did this and it works but I'm not sure it's the right fix. Let's see if HandlePlayClick gets fixed in BL-15936
1691+
// For draggable videos in Play Mode, disable pointer events on the mouse detector
1692+
// so clicks can pass through to the drag system which handles playback
1693+
.drag-activity-play [data-draggable-id] .bloom-videoMouseDetector {
1694+
pointer-events: none;
1695+
}
1696+
16771697
// If the background image hasn't been set in a game, we don't want to show the placeholder image.
16781698
.bloom-page[data-tool-id="game"]:not([data-activity="simple-dom-choice"]) {
16791699
.bloom-canvas

src/BloomBrowserUI/bookEdit/js/CanvasElementManager.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6535,7 +6535,8 @@ export class CanvasElementManager {
65356535
.find(".bloom-ui")
65366536
.filter(
65376537
(_, x) =>
6538-
!x.classList.contains("bloom-videoControlContainer"),
6538+
!x.classList.contains("bloom-videoControlContainer") &&
6539+
!x.classList.contains("bloom-videoMouseDetector"),
65396540
)
65406541
.remove();
65416542
thisCanvasElement.find(".bloom-dragHandleTOP").remove(); // BL-7903 remove any left over drag handles (this was the class used in 4.7 alpha)

src/BloomBrowserUI/bookEdit/js/bloomVideo.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,14 @@ export function SetupVideoEditing(container) {
3131
// debugging, and just might prevent a problem in normal operation.
3232
videoElement.parentElement?.classList.remove("playing");
3333
videoElement.parentElement?.classList.remove("paused");
34-
videoElement.addEventListener("click", handleVideoClick);
34+
const mouseDetector =
35+
videoElement.ownerDocument.createElement("div");
36+
mouseDetector.classList.add("bloom-videoMouseDetector");
37+
mouseDetector.classList.add("bloom-ui"); // don't save as part of document
38+
mouseDetector.addEventListener("click", handleVideoClick);
39+
videoElement.parentElement?.appendChild(mouseDetector);
3540
const playButton = wrapVideoIcon(
36-
videoElement,
41+
mouseDetector,
3742
// Alternatively, we could import the Material UI icon, make this file a TSX, and use
3843
// ReactDom.render to render the icon into the div. But just creating the SVG
3944
// ourselves (as these methods do) seems more natural to me. We would not be using
@@ -44,13 +49,13 @@ export function SetupVideoEditing(container) {
4449
);
4550
playButton.addEventListener("click", handlePlayClick);
4651
const pauseButton = wrapVideoIcon(
47-
videoElement,
52+
mouseDetector,
4853
getPauseIcon("#ffffff", videoElement),
4954
"bloom-videoPauseIcon",
5055
);
5156
pauseButton.addEventListener("click", handlePauseClick);
5257
const replayButton = wrapVideoIcon(
53-
videoElement,
58+
mouseDetector,
5459
getReplayIcon("#ffffff", videoElement),
5560
"bloom-videoReplayIcon",
5661
);
@@ -302,17 +307,17 @@ export function updateVideoInContainer(container: Element, url: string): void {
302307
// configure one of the icons we display over videos. We put a div around it and apply
303308
// various classes and append it to the parent of the video.
304309
function wrapVideoIcon(
305-
videoElement: HTMLVideoElement,
310+
parent: HTMLElement,
306311
icon: HTMLElement,
307312
iconClass: string,
308313
): HTMLElement {
309-
const wrapper = videoElement.ownerDocument.createElement("div");
314+
const wrapper = parent.ownerDocument.createElement("div");
310315
wrapper.classList.add("bloom-videoControlContainer");
311316
wrapper.classList.add("bloom-ui"); // don't save as part of document
312317
wrapper.appendChild(icon);
313318
wrapper.classList.add(iconClass);
314319
icon.classList.add("bloom-videoControl");
315-
videoElement.parentElement?.appendChild(wrapper);
320+
parent.appendChild(wrapper);
316321
return icon;
317322
}
318323

@@ -336,6 +341,7 @@ export function handlePlayClick(ev: MouseEvent, forcePlay?: boolean) {
336341
// becuse the click might be a drag on the canvas element. We'll let CanvasElementManager
337342
// decide and call playVideo if appropriate. That is, if we're not in Play mode,
338343
// where dragging is not applicable, or being called FROM the CanvasElementManager.
344+
// TODO The above comment is out of date; there
339345
if (
340346
!forcePlay &&
341347
video.closest(kCanvasElementSelector) &&
@@ -391,12 +397,14 @@ function handlePauseClick(ev: MouseEvent) {
391397
// be a natural bit of code to put in dragActivityRuntime.ts, except we don't need
392398
// it there, because BloomPlayer has this behavior for all videos, not just in Games.)
393399
const handleVideoClick = (ev: MouseEvent) => {
394-
const video = ev.currentTarget as HTMLVideoElement;
400+
const video = (ev.currentTarget as HTMLElement)
401+
?.closest(".bloom-videoContainer")
402+
?.getElementsByTagName("video")[0];
395403

396404
// If we're not in Play mode, we don't need these behaviors.
397405
// At least I don't think so. Outside Play mode, clicking on canvas elements is mainly about moving
398406
// them, but we have a visible Play button in case you want to play one. In BP (and Play mode), you
399-
// can't move them (unless one day we make them something you can drag to a target), so it
407+
// can't move them if they aren't draggable, so it
400408
// makes sense that a click anywhere on the video would play it; there's nothing else useful
401409
// to do in response.
402410
if (!video.closest(".drag-activity-play")) {

src/content/bookLayout/basePage.less

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,9 +336,6 @@ books may contain divs with box-header-off, so we need a rule to hide them.*/
336336
background-size: contain;
337337
}
338338

339-
// above canvas so we can click playback controls
340-
z-index: @canvasElementCanvasZIndex + 1;
341-
342339
video {
343340
// I don't know exactly why this works, but it makes the video shrink to fit,
344341
// keep its aspect ratio, and center in whatever direction is not filled.

0 commit comments

Comments
 (0)