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.
Picture in Picture: Chrome's strip never shows, Arc's top bar, scrim and size limits (#246)
Victor529bff613153
diff --git a/Packages/CraCore/Sources/CraCore/PictureInPictureLayout.swift b/Packages/CraCore/Sources/CraCore/PictureInPictureLayout.swiftnew file mode 100644index 0000000..f2438c0--- /dev/null+++ b/Packages/CraCore/Sources/CraCore/PictureInPictureLayout.swift@@ -0,0 +1,93 @@+import CoreGraphics+import Foundation++/// Where Arc's Picture in Picture window opens, and how its hover controls are laid out.+public enum PictureInPictureLayout {+ /// The even layer over the whole frame while the controls show: Arc's+ /// `Color.black.opacity(0.33)`, in and out with `.easeInOut(duration: 0.2)` (Arc 1.172 binary).+ public static let scrimAlpha: CGFloat = 0.33+ public static let fadeDuration: Double = 0.2+ public static let addressFontSize: CGFloat = 11+ /// The address keeps this far from a button, and isn't shown in less room than this.+ static let addressGap: CGFloat = 8+ static let addressMinWidth: CGFloat = 24++ /// Arc's size classes, by window width: tiny under 280 pt, small under 400, then normal.+ /// Its controls sit 12 pt in when tiny and 16 pt otherwise, inside 8 pt of button padding+ /// (10 from 400 pt) around a 12 pt glyph: a button's centre is 26, 30 or 32 pt from the+ /// edges. The reporter measured 26 on a tiny window (#246).+ public static func buttonCentreInset(width: CGFloat) -> CGFloat {+ width < 280 ? 12 + 8 + 6 : width < 400 ? 16 + 8 + 6 : 16 + 10 + 6+ }++ /// Back to Tab grows its words from 400 pt wide; Minimize and Close stay glyphs.+ public static func labelsBackToTab(width: CGFloat) -> Bool { width >= 400 }++ /// The top bar in a window `width` wide, y going down from the top edge: back to tab on the+ /// left (`backWidth` wide: a glyph, or the glyph and its words), close on the right, the+ /// address centred on the window between them (truncated in the middle when it doesn't fit;+ /// nil when there's no room at all).+ public struct TopBar: Equatable, Sendable {+ public var back: CGRect+ public var close: CGRect+ public var address: CGRect?+ }++ public static func topBar(width: CGFloat, buttonSize b: CGFloat, backWidth: CGFloat? = nil, addressWidth: CGFloat) -> TopBar {+ let c = buttonCentreInset(width: width)+ let y = c - b / 2+ let back = CGRect(x: c - b / 2, y: y, width: backWidth ?? b, height: b)+ let close = CGRect(x: width - c - b / 2, y: y, width: b, height: b)+ let room = 2 * (min(width / 2 - back.maxX, close.minX - width / 2) - addressGap)+ let w = min(addressWidth, room)+ let address = addressWidth > 0 && w >= addressMinWidth+ ? CGRect(x: width / 2 - w / 2, y: c - addressFontSize, width: w, height: 2 * addressFontSize) : nil+ return TopBar(back: back, close: close, address: address)+ }++ /// Arc's limits on the window's size (Arc 1.172 binary): at least 224 × 126 pt for the+ /// video's shape (a 16:9 video can't be made smaller than that), at most 61.7 % of the+ /// screen's width and the visible frame's height less 20 pt. The window keeps the video's+ /// aspect ratio inside them.+ public static func sizeLimits(aspect a: CGFloat, screen: CGRect, visible: CGRect) -> (min: CGSize, max: CGSize) {+ let minW = max(224, 126 * a)+ let maxW = max(224, (0.617 * screen.width).rounded(.down)), maxH = max(126, visible.height - 20)+ return (CGSize(width: minW, height: (minW / a).rounded()), CGSize(width: maxW, height: maxH))+ }++ /// The largest size of the video's shape within the limits, no bigger than `size`'s width.+ static func clamp(width: CGFloat, aspect a: CGFloat, limits: (min: CGSize, max: CGSize)) -> CGSize {+ let w = min(max(width, limits.min.width), limits.max.width, limits.max.height * a).rounded()+ return CGSize(width: w, height: (w / a).rounded())+ }++ /// 10 pt from the top and right edges of the visible frame when it first opens.+ public static let edgeMargin: CGFloat = 10+ /// Arc on a 1728×1117 display (24 Oct): 782×440 for a 16:9 video. Arc's code has no fixed+ /// default (it keeps the size the window starts with, inside its limits), and a 223×125 Arc+ /// window is its minimum, not a fresh one (#246).+ public static let defaultHeightFraction: CGFloat = 440.0 / 1084.0++ /// Where the window opens: the frame the user last left it at (Arc's "absolute" placement),+ /// keeping its width and following this video's aspect ratio, or else Arc's default in the+ /// top-right corner of the visible frame; inside Arc's size limits either way. AppKit screen+ /// coordinates (y up).+ public static func initialFrame(aspect: CGFloat, screen: CGRect, visible: CGRect, remembered: CGRect?) -> CGRect {+ let limits = sizeLimits(aspect: aspect, screen: screen, visible: visible)+ if let r = remembered, !r.isEmpty, visible.intersects(r) {+ let size = clamp(width: r.width, aspect: aspect, limits: limits)+ return CGRect(x: r.minX, y: r.maxY - size.height, width: size.width, height: size.height)+ }+ let size = clamp(width: (visible.height * defaultHeightFraction * aspect).rounded(), aspect: aspect, limits: limits)+ return CGRect(x: visible.maxX - edgeMargin - size.width, y: visible.maxY - edgeMargin - size.height,+ width: size.width, height: size.height)+ }++ /// The address in the top bar: the page's host as Arc writes it ("www.youtube.com"), and+ /// Chrome's words for a file on this Mac.+ public static func address(of url: String) -> String {+ guard let u = URL(string: url) else { return "" }+ if u.isFileURL { return "File on your device" }+ return u.host ?? ""+ }+}diff --git a/Packages/CraCore/Tests/CraCoreTests/PictureInPictureLayoutTests.swift b/Packages/CraCore/Tests/CraCoreTests/PictureInPictureLayoutTests.swiftnew file mode 100644index 0000000..1bced4f--- /dev/null+++ b/Packages/CraCore/Tests/CraCoreTests/PictureInPictureLayoutTests.swift@@ -0,0 +1,71 @@+import CoreGraphics+import CraCore+import Foundation+import Testing++/// Arc's Picture in Picture window: where it opens and what its top bar shows (#246).+struct PictureInPictureLayoutTests {+ @Test(arguments: [("https://www.youtube.com/watch?v=x", "www.youtube.com"), ("http://127.0.0.1:8080/video.html", "127.0.0.1"),+ ("file:///Users/me/clip.mp4", "File on your device"), ("about:blank", "")])+ func addressIsTheHost(url: String, address: String) {+ #expect(PictureInPictureLayout.address(of: url) == address)+ }++ /// Back to tab on the left, close on the right (Cra had them the other way round), the+ /// address centred on the window between them and clear of both.+ @Test(.bug("https://github.com/VictorKildahl/cra/issues/246"))+ func topBarIsArcs() {+ let bar = PictureInPictureLayout.topBar(width: 223, buttonSize: 26, addressWidth: 85)+ #expect(bar.back == CGRect(x: 13, y: 13, width: 26, height: 26))+ #expect(bar.close == CGRect(x: 184, y: 13, width: 26, height: 26))+ let a = try! #require(bar.address)+ #expect(a.midX == 111.5 && a.midY == 26 && a.width == 85)+ #expect(a.minX >= bar.back.maxX + 8 && a.maxX <= bar.close.minX - 8)+ }++ @Test func longAddressIsCutToTheRoomAndDroppedWithoutRoom() {+ let bar = PictureInPictureLayout.topBar(width: 223, buttonSize: 26, addressWidth: 400)+ #expect(bar.address?.width == 2 * (111.5 - 39 - 8))+ #expect(PictureInPictureLayout.topBar(width: 110, buttonSize: 26, addressWidth: 85).address == nil)+ #expect(PictureInPictureLayout.topBar(width: 223, buttonSize: 26, addressWidth: 0).address == nil)+ }++ /// Arc's size classes: buttons 12 pt + 8 pt padding in below 280 pt, 16 + 8 below 400, 16 + 10+ /// from there, where Back to Tab also shows its words.+ @Test func controlsMoveInWithTheWindowsSize() {+ #expect([223, 279, 280, 399, 400, 801].map { PictureInPictureLayout.buttonCentreInset(width: $0) } == [26, 26, 30, 30, 32, 32])+ #expect(!PictureInPictureLayout.labelsBackToTab(width: 399) && PictureInPictureLayout.labelsBackToTab(width: 400))+ let bar = PictureInPictureLayout.topBar(width: 801, buttonSize: 26, backWidth: 110, addressWidth: 85)+ #expect(bar.back == CGRect(x: 19, y: 19, width: 110, height: 26))+ #expect(bar.close == CGRect(x: 756, y: 19, width: 26, height: 26))+ #expect(bar.address?.midX == 400.5)+ }++ let screen = CGRect(x: 0, y: 0, width: 1920, height: 1080)+ let visible = CGRect(x: 0, y: 80, width: 1920, height: 975)++ /// Arc's limits: never below 224 × 126 for 16:9 (the 223 × 125.5 window in #246 was Arc's+ /// minimum), at most 61.7 % of the screen's width and the visible height less 20.+ @Test(.bug("https://github.com/VictorKildahl/cra/issues/246"))+ func sizeStaysInArcsLimits() {+ let l = PictureInPictureLayout.sizeLimits(aspect: 16.0 / 9, screen: screen, visible: visible)+ #expect(l.min == CGSize(width: 224, height: 126))+ #expect(l.max == CGSize(width: 1184, height: 955))+ // Portrait: 224 wide at least, not 126 tall.+ #expect(PictureInPictureLayout.sizeLimits(aspect: 9.0 / 16, screen: screen, visible: visible).min == CGSize(width: 224, height: 398))+ // A remembered frame below the minimum (Cra allowed 160 × 90) opens at Arc's minimum.+ let small = PictureInPictureLayout.initialFrame(aspect: 16.0 / 9, screen: screen, visible: visible,+ remembered: CGRect(x: 100, y: 500, width: 160, height: 90))+ #expect(small == CGRect(x: 100, y: 464, width: 224, height: 126))+ // One wider than the screen allows opens at the widest Arc allows.+ let wide = PictureInPictureLayout.initialFrame(aspect: 16.0 / 9, screen: screen, visible: visible,+ remembered: CGRect(x: 0, y: 100, width: 1600, height: 900))+ #expect(wide.size == CGSize(width: 1184, height: 666))+ }++ @Test func firstOpensTopRightTenPointsIn() {+ let f = PictureInPictureLayout.initialFrame(aspect: 16.0 / 9, screen: CGRect(x: 0, y: 0, width: 1728, height: 1117),+ visible: CGRect(x: 0, y: 0, width: 1728, height: 1084), remembered: nil)+ #expect(f == CGRect(x: 1728 - 10 - 782, y: 1084 - 10 - 440, width: 782, height: 440))+ }+}diff --git a/Sources/Cra/Services/BrowserManager.swift b/Sources/Cra/Services/BrowserManager.swiftindex 1662c28..a1c51ec 100644--- a/Sources/Cra/Services/BrowserManager.swift+++ b/Sources/Cra/Services/BrowserManager.swift@@ -857,6 +857,7 @@ final class BrowserManager: NSObject, @preconcurrency CraBrowserDelegate {skip: { [weak browser] s in browser?.skipPictureInPicture(by: s) },close: { [weak browser] in browser?.closePictureInPicture() })PictureInPictureChrome.shared.isPlaying = browser.isPictureInPicturePlaying+ PictureInPictureChrome.shared.address = PictureInPictureLayout.address(of: browser.currentURL)PictureInPictureChrome.shared.videoEntered()} else {PictureInPictureChrome.shared.videoLeft()diff --git a/Sources/Cra/UI/PictureInPicture/PictureInPictureChrome.swift b/Sources/Cra/UI/PictureInPicture/PictureInPictureChrome.swiftindex 1b481a3..018a2b5 100644--- a/Sources/Cra/UI/PictureInPicture/PictureInPictureChrome.swift+++ b/Sources/Cra/UI/PictureInPicture/PictureInPictureChrome.swift@@ -18,8 +18,8 @@ struct PictureInPictureActions {/// the top-right corner, remembered where the user leaves it (measured on Arc/// 1.168, see docs/arc-reverse-engineering.md). A transparent child window/// over it keeps the pointer away from Chrome's controls and draws Arc's-/// instead on hover: close and back-to-tab at the top, play/pause with-/// ±15 s skips in the middle (Arc's tooltips: "closes the pip window",+/// instead on hover: back-to-tab, the page's address and close at the top,+/// play/pause with ±15 s skips in the middle (Arc's tooltips: "closes the pip window",/// "returns to the original tab", "Skip back/ahead 15 seconds"). The overlay/// also owns dragging and aspect-locked edge resizing.@MainActor@@ -30,12 +30,13 @@ final class PictureInPictureChrome {var isPlaying = false {didSet { for o in overlays.values { o.controls.isPlaying = isPlaying } }}+ /// The page's host, centred in the top bar (Arc's; Chrome's own strip stays hidden, #246).+ var address = "" {+ didSet { for o in overlays.values { o.controls.address = address } }+ }- /// Arc on a 1728×1117 display: 782×440 for a 16:9 video, 10 pt from the- /// top and right edges of the visible frame.static let cornerRadius: CGFloat = 6- static let edgeMargin: CGFloat = 10- static let defaultHeightFraction: CGFloat = 440.0 / 1084.0+ static let edgeMargin = PictureInPictureLayout.edgeMarginprivate static let frameKey = "CraPictureInPictureFrame"private var overlays: [ObjectIdentifier: PictureInPictureOverlay] = [:]@@ -60,6 +61,7 @@ final class PictureInPictureChrome {let overlay = PictureInPictureOverlay(over: window)overlays[ObjectIdentifier(window)] = overlayoverlay.controls.isPlaying = isPlaying+ overlay.controls.address = addresswindow.addChildWindow(overlay, ordered: .above)overlay.orderFront(nil)observers.append(NotificationCenter.default.addObserver(forName: NSWindow.willCloseNotification, object: window, queue: .main) { [weak self] _ in@@ -109,27 +111,18 @@ final class PictureInPictureChrome {let aspect = window.frame.width / max(window.frame.height, 1)window.setFrame(initialFrame(aspect: aspect, screen: window.screen ?? NSScreen.main), display: true)window.invalidateShadow()- // Chrome still paints its title strip ("File on your device") for the- // first seconds after the window appears; that lives inside Chromium's- // compositor layer and is not reachable from here (neither resizing- // nor focus changes affect it). After that the window is Arc's.+ // Chrome's own title strip (favicon, host, top scrim) stays hidden because CraCEF starts+ // Chromium with every video PiP trusted (VideoPipForceTrustedForMediaPlaybackForTesting,+ // #246); without that it stayed until a click reached this window, which never happens.}- /// Last frame the user left the window at (Arc's "absolute" placement),- /// else Arc's default: top-right corner of the visible frame.+ /// Last frame the user left the window at, else Arc's default (PictureInPictureLayout).func initialFrame(aspect: CGFloat, screen: NSScreen?) -> NSRect {let visible = screen?.visibleFrame ?? NSRect(x: 0, y: 0, width: 1728, height: 1084)- if let s = UserDefaults.standard.string(forKey: Self.frameKey) {- let r = NSRectFromString(s)- if !r.isEmpty, visible.intersects(r) {- // Keep the remembered width, follow the video's aspect ratio.- let h = (r.width / aspect).rounded()- return NSRect(x: r.minX, y: r.maxY - h, width: r.width, height: h)- }- }- let h = (visible.height * Self.defaultHeightFraction).rounded()- let w = (h * aspect).rounded()- return NSRect(x: visible.maxX - Self.edgeMargin - w, y: visible.maxY - Self.edgeMargin - h, width: w, height: h)+ let remembered = UserDefaults.standard.string(forKey: Self.frameKey).map(NSRectFromString)+ let frame = PictureInPictureLayout.initialFrame(aspect: aspect, screen: screen?.frame ?? visible, visible: visible, remembered: remembered)+ CraLog.note("pip: opens at \(Int(frame.width))×\(Int(frame.height))\(remembered == nil ? "" : " (remembered)")")+ return frame}func remember(_ frame: NSRect) {@@ -259,11 +252,15 @@ final class PictureInPictureOverlayView: NSView {guard let target, var g = gesture else { return }// The button was let go without a mouse-up reaching this window.if NSEvent.pressedMouseButtons & 1 == 0 { finish(event); return }+ // Arc's limits (#246): 224 × 126 for a 16:9 video at least, 61.7 % of the screen's width and+ // the visible height less 20 at most.+ let screen = target.screen ?? NSScreen.main+ let visible = screen?.visibleFrame ?? target.frame+ let limits = PictureInPictureLayout.sizeLimits(aspect: g.startFrame.width / max(g.startFrame.height, 1),+ screen: screen?.frame ?? visible, visible: visible)let constraints = target.contentMaxSize- let visible = target.screen?.visibleFrame.size ?? constraints- let maxSize = NSSize(width: min(constraints.width, visible.width - 2 * PictureInPictureChrome.edgeMargin),- height: min(constraints.height, visible.height - 2 * PictureInPictureChrome.edgeMargin))- let minSize = NSSize(width: max(target.contentMinSize.width, 160), height: max(target.contentMinSize.height, 90))+ let maxSize = NSSize(width: min(constraints.width, limits.max.width), height: min(constraints.height, limits.max.height))+ let minSize = NSSize(width: max(target.contentMinSize.width, limits.min.width), height: max(target.contentMinSize.height, limits.min.height))let wasDragging = g.isDragginglet frame = g.frame(mouse: Self.screenLocation(of: event), minSize: minSize, maxSize: maxSize)gesture = gdiff --git a/Sources/Cra/UI/PictureInPicture/PictureInPictureControls.swift b/Sources/Cra/UI/PictureInPicture/PictureInPictureControls.swiftindex 95ca03b..4214a18 100644--- a/Sources/Cra/UI/PictureInPicture/PictureInPictureControls.swift+++ b/Sources/Cra/UI/PictureInPicture/PictureInPictureControls.swift@@ -2,22 +2,27 @@ import AppKit/// Arc's Picture in Picture hover controls, drawn over the video.///-/// Invisible until the pointer enters the window, then fades in a dark scrim-/// with the buttons: close (top-left) and back-to-tab (top-right), play/pause-/// in the middle between ±15 s skips. Fades out when the pointer leaves or-/// rests for a while. Only the buttons take clicks; everything else passes+/// Invisible until the pointer enters the window, then fades in one even dark+/// layer with the controls: back-to-tab (top-left), the page's address (centred)+/// and close (top-right), play/pause in the middle between ±15 s skips, as in Arc+/// (#246). Fades out when the pointer leaves or rests for a while, and the window+/// is the bare video again. Only the buttons take clicks; everything else passes/// through to the overlay, which drags and resizes the window.@MainActorfinal class PictureInPictureControlsView: NSView {var isPlaying = false { didSet { playButton.symbol = isPlaying ? "pause.fill" : "play.fill"; playButton.tip = isPlaying ? "Pause" : "Play" } }- private let scrim = CAGradientLayer()- private let closeButton = PictureInPictureButton(symbol: "xmark", pointSize: 12, diameter: 26, tip: "Close")- private let backButton = PictureInPictureButton(symbol: "pip.exit", pointSize: 13, diameter: 26, tip: "Back to Tab")+ var address = "" { didSet { addressLabel.stringValue = address; needsLayout = true } }++ private let scrim = CALayer()+ private let addressLabel = NSTextField(labelWithString: "")+ private static let topButtonSize: CGFloat = 26+ private let closeButton = PictureInPictureButton(symbol: "xmark", pointSize: 12, diameter: topButtonSize, tip: "Close")+ private let backButton = PictureInPictureButton(symbol: "pip.exit", pointSize: 13, diameter: topButtonSize, tip: "Back to Tab")private let playButton = PictureInPictureButton(symbol: "play.fill", pointSize: 22, diameter: 48, tip: "Play")private let skipBackButton = PictureInPictureButton(symbol: "gobackward.15", pointSize: 17, diameter: 38, tip: "Skip back 15 seconds")private let skipAheadButton = PictureInPictureButton(symbol: "goforward.15", pointSize: 17, diameter: 38, tip: "Skip ahead 15 seconds")- private var buttons: [PictureInPictureButton] { [closeButton, backButton, playButton, skipBackButton, skipAheadButton] }+ private var buttons: [PictureInPictureButton] { [backButton, closeButton, playButton, skipBackButton, skipAheadButton] }private var hideTimer: Timer?private var shown = false@@ -25,12 +30,16 @@ final class PictureInPictureControlsView: NSView {super.init(frame: frame)wantsLayer = truelayer?.opacity = 0- scrim.colors = [NSColor.black.withAlphaComponent(0.45).cgColor,- NSColor.black.withAlphaComponent(0.15).cgColor,- NSColor.black.withAlphaComponent(0.15).cgColor,- NSColor.black.withAlphaComponent(0.45).cgColor]- scrim.locations = [0, 0.3, 0.7, 1]+ // Arc dims the whole frame evenly, from the top bar to the bottom edge; Cra's gradient+ // darkened the top and bottom and left the middle almost clear (#246).+ scrim.backgroundColor = NSColor.black.withAlphaComponent(PictureInPictureLayout.scrimAlpha).cgColorlayer?.addSublayer(scrim)+ addressLabel.font = .systemFont(ofSize: PictureInPictureLayout.addressFontSize, weight: .medium)+ addressLabel.textColor = .white+ addressLabel.alignment = .center+ addressLabel.lineBreakMode = .byTruncatingMiddle+ addressLabel.maximumNumberOfLines = 1+ addSubview(addressLabel)for b in buttons {addSubview(b)b.onPress = { [weak self] in self?.show() }@@ -54,9 +63,17 @@ final class PictureInPictureControlsView: NSView {CATransaction.begin(); CATransaction.setDisableActions(true)scrim.frame = boundsCATransaction.commit()- let inset: CGFloat = 10- closeButton.setFrameOrigin(NSPoint(x: inset, y: inset))- backButton.setFrameOrigin(NSPoint(x: bounds.maxX - inset - backButton.frame.width, y: inset))+ // Back to Tab shows its words from 400 pt wide, as in Arc.+ backButton.label = PictureInPictureLayout.labelsBackToTab(width: bounds.width) ? "Back to Tab" : nil+ let bar = PictureInPictureLayout.topBar(width: bounds.width, buttonSize: Self.topButtonSize, backWidth: backButton.fittingWidth,+ addressWidth: addressLabel.stringValue.isEmpty ? 0 : PictureInPictureButton.textWidth(addressLabel))+ backButton.frame = bar.back+ closeButton.frame = bar.close+ addressLabel.isHidden = bar.address == nil+ if let a = bar.address {+ let h = ceil(addressLabel.intrinsicContentSize.height)+ addressLabel.frame = NSRect(x: a.minX, y: a.midY - h / 2, width: a.width, height: h)+ }let c = NSPoint(x: bounds.midX, y: bounds.midY)let gap: CGFloat = bounds.width < 360 ? 18 : 30playButton.setFrameOrigin(NSPoint(x: c.x - playButton.frame.width / 2, y: c.y - playButton.frame.height / 2))@@ -86,7 +103,7 @@ final class PictureInPictureControlsView: NSView {private func show() {if !shown {shown = true- fade(to: 1, duration: 0.15)+ fade(to: 1, duration: PictureInPictureLayout.fadeDuration)}hide(after: 2.5)}@@ -102,7 +119,7 @@ final class PictureInPictureControlsView: NSView {// Keep the controls while the pointer rests on a button.if pointerInside(), self.buttons.contains(where: { $0.isHovered }) { self.hide(after: 2.5); return }self.shown = false- self.fade(to: 0, duration: 0.25)+ self.fade(to: 0, duration: PictureInPictureLayout.fadeDuration)}if delay == 0 { action(); return }hideTimer = Timer.scheduledTimer(withTimeInterval: delay, repeats: false) { _ in Task { @MainActor in action() } }@@ -114,7 +131,7 @@ final class PictureInPictureControlsView: NSView {anim.fromValue = layer.presentation()?.opacity ?? layer.opacityanim.toValue = opacityanim.duration = duration- anim.timingFunction = CAMediaTimingFunction(name: .easeOut)+ anim.timingFunction = CAMediaTimingFunction(name: .easeInEaseOut) // Arc: .easeInOut(duration: 0.2)layer.opacity = opacitylayer.add(anim, forKey: "fade")}@@ -130,7 +147,25 @@ final class PictureInPictureButton: NSView {private(set) var isHovered = false { didSet { updateBackground() } }private var isPressed = false { didSet { updateBackground() } }private let pointSize: CGFloat+ private let diameter: CGFloatprivate let image = NSImageView()+ private let text = NSTextField(labelWithString: "")+ /// Words after the glyph: the button becomes a pill (Arc's Back to Tab on a wide window,+ /// 12 pt medium, 6 pt continuous corners, 10 pt padding).+ var label: String? {+ didSet {+ guard label != oldValue else { return }+ text.stringValue = label ?? ""+ text.isHidden = label == nil+ layer?.cornerRadius = label == nil ? diameter / 2 : 6+ needsLayout = true+ }+ }+ /// The width the button wants: its disc, or the glyph and its words.+ var fittingWidth: CGFloat {+ guard label != nil else { return diameter }+ return (10 + (image.image?.size.width ?? 14) + 5 + Self.textWidth(text) + 10).rounded(.up)+ }private var tipAnchor: ArcTooltipAnchorView?/// Arc-style hover tip (ArcTooltip), not AppKit's yellow one.var tip: String { didSet { tipAnchor?.text = tip; setAccessibilityLabel(tip) } }@@ -138,6 +173,7 @@ final class PictureInPictureButton: NSView {init(symbol: String, pointSize: CGFloat, diameter: CGFloat, tip: String) {self.symbol = symbolself.pointSize = pointSize+ self.diameter = diameterself.tip = tipsuper.init(frame: NSRect(x: 0, y: 0, width: diameter, height: diameter))wantsLayer = true@@ -146,8 +182,12 @@ final class PictureInPictureButton: NSView {image.contentTintColor = .whiteimage.imageScaling = .scaleNoneimage.frame = bounds- image.autoresizingMask = [.width, .height]addSubview(image)+ text.font = .systemFont(ofSize: 12, weight: .medium)+ text.textColor = .white+ text.isHidden = true+ addSubview(text)+ layer?.cornerCurve = .continuoustipAnchor = ArcTooltipAnchorView.attach(to: self, help: tip)setAccessibilityRole(.button)setAccessibilityLabel(tip)@@ -156,6 +196,22 @@ final class PictureInPictureButton: NSView {required init?(coder: NSCoder) { fatalError() }+ override func layout() {+ super.layout()+ guard label != nil else { image.frame = bounds; return }+ let g = image.image?.size.width ?? 14+ image.frame = NSRect(x: 10, y: 0, width: g, height: bounds.height)+ let h = ceil(text.intrinsicContentSize.height)+ text.frame = NSRect(x: 10 + g + 5, y: (bounds.height - h) / 2, width: Self.textWidth(text), height: h)+ }++ /// What a one-line label needs to show all of its text: its cell's size, which adds the cell's+ /// and the line fragment's padding to the string (4 pt a side). The intrinsic width came out+ /// 4 pt short, and the address and "Back to Tab" were cut.+ static func textWidth(_ field: NSTextField) -> CGFloat {+ ceil(field.cell?.cellSize.width ?? field.intrinsicContentSize.width)+ }+private static func image(_ name: String, _ size: CGFloat) -> NSImage? {let config = NSImage.SymbolConfiguration(pointSize: size, weight: .semibold)return NSImage(systemSymbolName: name, accessibilityDescription: nil)?.withSymbolConfiguration(config)diff --git a/Sources/CraCEF/CraCEF.mm b/Sources/CraCEF/CraCEF.mmindex 9e43d4f..742d550 100644--- a/Sources/CraCEF/CraCEF.mm+++ b/Sources/CraCEF/CraCEF.mm@@ -691,6 +691,13 @@ public:// Tab sleeping discards a page in place (Cra.discard), as Arc's Chromium does: the tab// keeps its back/forward list and scroll position, and loads again when shown (#153).+ "WebContentsDiscard,"+ // Chrome keeps its video PiP's origin strip (favicon, host, a dark top scrim) on screen+ // until the person clicks or types in that window, unless the page is file:// or has+ // high media engagement (VideoOverlayWindowViews::UpdateControlsVisibility). Cra's+ // overlay takes every click, so on YouTube the strip never left (#246). Treated as+ // trusted, the window hides it from the start; Cra's own top bar shows the host on hover,+ // as Arc's does. The feature does nothing else (Chromium 156).+ + "VideoPipForceTrustedForMediaPlaybackForTesting,"// A hidden page's frame unlocks, so Chromium can evict it past its saved-frame cap or// after 5 minutes, as Chrome does for background tabs (Cra's are never detached from// their window, which is how Chrome gets there). Cra's page windows then let go ofdiff --git a/Tests/BrowserManagerSupport/AppServices.swift b/Tests/BrowserManagerSupport/AppServices.swiftindex 40e6257..6168bcb 100644--- a/Tests/BrowserManagerSupport/AppServices.swift+++ b/Tests/BrowserManagerSupport/AppServices.swift@@ -109,6 +109,7 @@ final class PictureInPictureChrome {static let shared = PictureInPictureChrome()var actions: PictureInPictureActions?var isPlaying = false+ var address = ""func videoEntered() {}func videoLeft() {}}diff --git a/Tests/Scenarios/pip-title-strip.scenario b/Tests/Scenarios/pip-title-strip.scenarionew file mode 100644index 0000000..79fbcff--- /dev/null+++ b/Tests/Scenarios/pip-title-strip.scenario@@ -0,0 +1,12 @@+# Chrome keeps its video Picture in Picture window's origin strip (favicon, host and a dark top+# scrim) on screen until the person clicks or types in that window, unless the page is trusted+# for media playback (file://, or high media engagement). Cra's overlay takes every click, so on+# YouTube the strip never left (GitHub #246); the scenarios' file:// fixtures hid it. Cra starts+# Chromium with every video PiP trusted, so the strip goes with the controls from the start and+# only Cra's own top bar shows the host, on hover. Whether the strip is drawn is pixels in+# Chromium's compositor (docs/release-checklist.md); this pins the switch that decides it.+# promise: #246+cra://open?url=chrome://version+wait 2+cra://debug?cdp=Runtime.evaluate¶ms={"expression":"'pip-trusted:'+document.body.innerText.includes('VideoPipForceTrustedForMediaPlaybackForTesting')"}+expect-log Cra cdp Runtime.evaluate .*"value":"pip-trusted:true"diff --git a/Tests/promises.lock b/Tests/promises.lockindex bdba39f..175f330 100644--- a/Tests/promises.lock+++ b/Tests/promises.lock@@ -380,3 +380,7 @@#242 Tests/Scenarios/peek-per-tab.scenario 985d0534cd4f#243 Packages/CraCore/Tests/CraCoreTests/TabRowTrailingTests.swift::hoveredNameRunsToTheCloseButton 0a8658ede567#243 Packages/CraCore/Tests/CraCoreTests/TabRowTrailingTests.swift::restingTailIsUnchanged f479053f4258+#245 Packages/CraCore/Tests/CraCoreTests/DownloadListTests.swift::libraryListsRunningDownloads fec003db07c1+#246 Packages/CraCore/Tests/CraCoreTests/PictureInPictureLayoutTests.swift::sizeStaysInArcsLimits f3363f2b0bcf+#246 Packages/CraCore/Tests/CraCoreTests/PictureInPictureLayoutTests.swift::topBarIsArcs ac06153d1f62+#246 Tests/Scenarios/pip-title-strip.scenario 3aab46cf7e80diff --git a/Tests/test-browser-manager.sh b/Tests/test-browser-manager.shindex d3d1309..267cc40 100755--- a/Tests/test-browser-manager.sh+++ b/Tests/test-browser-manager.sh@@ -12,7 +12,7 @@ xcrun swiftc -swift-version 5 -parse-as-library ${CRA_TEST_SWIFTC_FLAGS:-} -I "$-Xlinker -rpath -Xlinker "$TEST_DIR" \"$MANAGER_SOURCE" Sources/Cra/Services/NowPlaying.swift Sources/Cra/Services/PageScript.swift Sources/Cra/Services/Scheduler.swift Sources/Cra/Services/DevToolsToggle.swift Sources/Cra/Services/CraLog.swift Sources/Cra/Services/PageProbe.swift Sources/Cra/Services/Persistence.swift \Sources/Cra/Perf/Perf.swift Packages/CraCore/Sources/CraCore/Perf/*.swift Packages/CraCore/Sources/CraCore/ExtensionPageRetry.swift Packages/CraCore/Sources/CraCore/PermissionPrompt.swift Packages/CraCore/Sources/CraCore/TabSleepPolicy.swift Packages/CraCore/Sources/CraCore/ProtectedMedia.swift Sources/Cra/Services/WebKit/PageEngines.swift Tests/Support/ManualScheduler.swift Tests/BrowserManagerSupport/AppServices.swift \- Packages/CraCore/Sources/CraCore/DialogActions.swift Packages/CraCore/Sources/CraCore/Boost.swift Tests/BrowserManagerLifecycleTests.swift -o "$TEST_DIR/lifecycle-tests"+ Packages/CraCore/Sources/CraCore/DialogActions.swift Packages/CraCore/Sources/CraCore/Boost.swift Packages/CraCore/Sources/CraCore/PictureInPictureLayout.swift Tests/BrowserManagerLifecycleTests.swift -o "$TEST_DIR/lifecycle-tests"# A data folder of its own: PageEngines keeps protected-media.json there, not in the real Cra's.CRA_DATA_DIR="$TEST_DIR/data" "$TEST_DIR/lifecycle-tests"[ -z "${CRA_TEST_KEEP:-}" ] || cp "$TEST_DIR/lifecycle-tests" "$CRA_TEST_KEEP/"diff --git a/docs/arc-reverse-engineering.md b/docs/arc-reverse-engineering.mdindex d36c37d..1e0645a 100644--- a/docs/arc-reverse-engineering.md+++ b/docs/arc-reverse-engineering.md@@ -726,10 +726,33 @@ Over another app's full-screen Space (6 Nov, GitHub #206):overlay is a borderless non-activating NSPanel. Measured on a test copy with a full-screen stand-in app infront: main had video and Document PiP off that Space. Now both are on it, so is a video PiP opened while thatSpace is in front, and a click and a drag on it keep the full-screen app frontmost and its Space active.-One residual difference: Chrome paints its origin strip ("File on your device", top gradient)-inside the compositor layer for about two seconds when the window first appears (present at-1.5 s, gone at 2.5 s in quarter-second captures); it is drawn whether or not the window is-resized or focused, so it cannot be suppressed from CEF. After that nothing is drawn, as in Arc.+Chrome's origin strip (8 Nov, GitHub #246): Chrome draws its title strip (favicon, host, top scrim)+for 5 s after the window appears and then keeps it until a click or key press reaches its window,+unless the page is trusted for media playback (file://, or high media engagement;+`VideoOverlayWindowViews::UpdateControlsVisibility`). The 24 Oct captures used a file:// page, so+the strip went after about two seconds; on YouTube it never went, because Cra's overlay takes every+click. CraCEF enables `VideoPipForceTrustedForMediaPlaybackForTesting` (it only feeds that check), so+the strip never shows: on an http page it is absent at 0.5 s and after 10 s (captures of a test copy).+Arc 1.172 binary (otool/llvm-objdump on the arm64 slice, 8 Nov, #246):+- [O static] Position keys are now `LastVideoPIPPosition` / `LastDocumentPIPPosition`. No fixed default+ size: `.screen(corner, size: nil)` keeps the window's current size inside the limits, 10 pt in. The+ first size most likely comes from the video's rect on the page [I]. Limits: at least 224×126 scaled+ to the content's aspect (a 16:9 window is 224×126 at its smallest, which is the 223×125.5 the #246+ reporter measured), at most max(224, 0.617 × screen width) × max(126, visible height − 20).+- [O static] Hover layer: one flat `Color.black.opacity(0.33)` scrim, `.easeInOut(duration: 0.2)` in+ and out; the controls fade with it. Buttons press-scale to 0.95.+- [O static] Size classes by width: tiny < 280, small < 400, normal < 600, large. Controls 12 pt in when+ tiny, 16 pt otherwise, button padding 8 (10 from 400 pt): glyph centres 26 / 30 / 32 pt from the+ edges (the reporter measured 26 on a tiny window). Back to Tab is a pill top-left, 12 pt medium+ words from 400 pt wide, 6 pt continuous corners. Minimize and Close are a group (top-right [I]),+ glyphs with tooltips only. The address centred between them is from the reporter's captures; no+ host label was found in the binary.+- [O static] Minimize is per site (`minimizeEnabled` in its PiP config) and asks Chromium to leave PiP;+ `offscreen` is a separate "stash" past the screen edge. Cra has neither.+- [O static] Scrubber: 5 pt capsule (15 pt drag area) 8 pt above the bottom (4 when tiny), white over+ white 30 %; dragging upwards slows seeking by 2^round(dy / 60 pt), down to 1/16. Cra has none yet.+Cra follows the limits, the scrim, the fade, the insets and the Back to Tab words+(`PictureInPictureLayout` in CraCore) and keeps its 782×440-on-1728×1117 opening size.Chromium only enters PiP from a page holding a user activation. `CefBrowserHost::SendKeyEvent`never reached the page in Chrome-style hosting (CEF 154), so Cra sends an F19 key down/up straightdiff --git a/docs/release-checklist.md b/docs/release-checklist.mdindex 58dea3f..8e07ba5 100644--- a/docs/release-checklist.md+++ b/docs/release-checklist.md@@ -99,6 +99,10 @@ built release app with a test profile. Note anything that fails in the release'sPiP and coming back closes it. The tab shows the recording dot and doesn't sleep.- **#134:** with another app in front, the PiP edges show resize cursors, and a click on playdoesn't move the window.+- **#246:** a YouTube video's PiP shows no Chrome strip (site icon, host, dark top band) at any+ point, also in the first seconds; with the pointer away it is the bare video. On hover: Back to+ Tab on the left (with its words from 400 pt wide), the host centred and whole, Close on the+ right, one even dim layer.- **#178:** in a split, the focused pane's ring shows (also over docked DevTools), and so doesthe card shadow.- **#90:** Capture on a second display and behind other windows isn't blank. It goes to the