Skip to content

armgit / cra

Public Imported from GitHub
0

The open-source Arc replacement for macOS. Spaces, pinned tabs, split view, Little Windows and Arc's shortcuts on Chromium, with your Arc sidebar imported in one go.

Lay out fresh background tabs at the visible pane size (#126)

Quinn Battersbyc3dab4ee58f1
diff --git a/Sources/Cra/UI/Windows/MainWindowController.swift b/Sources/Cra/UI/Windows/MainWindowController.swift
index 3df6808..495b27e 100644
--- a/Sources/Cra/UI/Windows/MainWindowController.swift
+++ b/Sources/Cra/UI/Windows/MainWindowController.swift
@@ -727,7 +727,15 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserM
if EmbeddedPages.isHost(w), let views = EmbeddedPages.pageViews(of: w) {
for v in views where v.superview !== w.contentView { v.removeFromSuperview() }
}
- if w.isVisible { w.orderOut(nil) }
+ if w.isVisible {
+ w.orderOut(nil)
+ // A new background page starts in CEF's 10 pt window. Let it lay out at
+ // the pane size before autofocus can scroll its player off the top.
+ let pane = shell.webContainer
+ if w.parent == nil, !pane.bounds.isEmpty {
+ w.setFrame(window.convertToScreen(pane.convert(pane.bounds, to: nil)), display: false)
+ }
+ }
continue
}
if w.parent !== window {
diff --git a/Tests/Fixtures/Pages/player-focus.html b/Tests/Fixtures/Pages/player-focus.html
new file mode 100644
index 0000000..b10b639
--- /dev/null
+++ b/Tests/Fixtures/Pages/player-focus.html
@@ -0,0 +1,16 @@
+<!doctype html>
+<meta charset="utf-8">
+<title>Watch fixture</title>
+<style>
+ body { margin: 0; font: 16px system-ui; }
+ header { height: 60px; }
+ #player { min-height: 150px; height: 65vh; background: #222; color: white; }
+ main { min-height: 200vh; }
+</style>
+<header>Watch</header>
+<div id="player" tabindex="0">Video player</div>
+<main>Comments</main>
+<script>
+ // Watch pages focus the player at load so the playback keys work.
+ document.getElementById('player').focus();
+</script>
diff --git a/Tests/Scenarios/background-player-scroll.scenario b/Tests/Scenarios/background-player-scroll.scenario
new file mode 100644
index 0000000..618c36b
--- /dev/null
+++ b/Tests/Scenarios/background-player-scroll.scenario
@@ -0,0 +1,18 @@
+# A watch page focuses its player while loading in a fresh background tab.
+# Wait for that load before selecting it for the first time.
+cra://open?url=${PAGE}
+expect-log loaded 127.0.0.1
+cra://open?url=file://${FIXTURES}/Pages/player-focus.html&background=1
+expect-log loaded file:
+cra://action/nextTab
+cra://debug?cdp=Runtime.evaluate&params={"expression":"document.title.concat(':',scrollY)"}
+expect-log Cra cdp Runtime.evaluate .*"value":"Watch fixture:0"
+
+# A later switch back to the comments must keep the reader's place.
+cra://debug?pageJS=window.scrollTo(0,400)
+cra://action/nextTab
+cra://debug?cdp=Runtime.evaluate&params={"expression":"document.title"}
+expect-log Cra cdp Runtime.evaluate .*"value":"Fixture 0"
+cra://action/nextTab
+cra://debug?cdp=Runtime.evaluate&params={"expression":"document.title.concat(':',scrollY)"}
+expect-log Cra cdp Runtime.evaluate .*"value":"Watch fixture:400"