Skip to content
Merged
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
2 changes: 1 addition & 1 deletion docs/native-window.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ The `add-link-rules` change's `design.md` (`openspec/changes/archive/2026-11-15-

The browser controls show in one of two places, chosen by the `ClairShowsToolbar` preference (`ToolbarPreference`, on by default): a toolbar across the top of the card, or the sidebar's top row and URL field. The `add-page-toolbar` change's `design.md` (D1–D9) has the reasoning.

- **One rule decides where the controls show (D1).** `PageHeaderPolicy` takes the preference and the window's pane count, always 1 for now. Each pane shows a header while the preference is on or there's more than one pane, and the sidebar shows its controls only while no pane shows one. `BrowserWindowModel` exposes the result as `showsPageHeader` and `sidebarShowsControls`, and views read only those two. Split view will change the pane count and nothing else.
- **One rule decides where the controls show (D1).** `PageHeaderPolicy` takes the preference and the window's pane count, always 1 for now. Each pane shows a header while the preference is on or there's more than one pane. The sidebar keeps its top row, URL field and pinned extensions while the preference is off, a split included, as in Arc, so it doesn't shift; only back, forward and reload leave it while a pane shows a header. `BrowserWindowModel` exposes the result as `showsPageHeader`, `sidebarShowsControls` and `sidebarShowsNavigation`. While a split shows the controls in both places, `bubblesInSidebar` says which the user used last, and bubbles, popups and the Site Control Center attach there.
- **The toolbar is a page header inside the card (D2).** `PageToolbar`, a SwiftUI view, sits in `PageCardView`'s container at the top of the card, with a 1 pt line over the page's top row. The page, the still, infobars, DevTools and the drag strip lie below it. `PageCardView.contentTop` gives that offset, and find and the notice popup are placed from it (D7). Page full screen hides the toolbar.
- **A Peek covers it (D3).** Being in the container, the toolbar shrinks and washes with the parent page, and the click catcher closes the Peek. The Peek has its own `PageToolbar` with `.peek` content: back, forward, reload and the host, acting on the Peek's page.
- **The same controls, moved (D4).** The toolbar reuses the sidebar's buttons and identifiers (`clair.hideSidebar`, `clair.back`, `clair.forward`, `clair.reload`, `clair.urlField`, `clair.copyURL`, `clair.siteControls`, `clair.extensionAction`). The toolbar is `clair.toolbar` and the Peek's `clair.peekToolbar`. `ToolbarArrangement` places them: Arc's leading slots, a 36 pt trailing pitch, the host centred on the card, and, in a narrow card, extensions and then reload with the link icon left out before the host truncates. `ToolbarLayout` lays them out from it. Every toolbar button is an `IconButton` at Arc's 32 × 24 (`IconButtonSize.toolbarHeight`), the link icon 22 × 24, with Arc's glyph sizes (`IconButtonSize.toolbarGlyph` and the other `toolbar…Glyph` sizes: 14 pt for the toggle, back, forward and reload, smaller than the sidebar's 16, and 12 for the link); a pinned extension is a `ToolbarExtensionButton`, which wraps one with the extension's menu, badge and anchor. The toolbar's blank areas move and zoom the window through `TitleBarArea`, whatever the page-top drag setting.
Expand Down
16 changes: 14 additions & 2 deletions native/ClairUI/AnchorResolver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ enum AnchorControl: Hashable {
}

/// Where a Chromium bubble attaches (design D7): below its control in the
/// toolbar while the toolbar shows (add-page-toolbar D6); else to its control
/// toolbar while the toolbar shows (add-page-toolbar D6), unless the user
/// last used the sidebar's while a split shows both; else to its control
/// in the sidebar while the sidebar is shown in place, or else to the card's
/// top-leading corner. A revealed sidebar slides away when the pointer
/// leaves, which would orphan a bubble, so it never anchors one.
Expand All @@ -28,15 +29,26 @@ struct AnchorResolver {
var sidebarInPlace: Bool
/// The controls' frames, in window coordinates (origin at the bottom left).
var controls: [AnchorControl: CGRect]
/// The card's frame, in window coordinates.
/// The card's frame, in window coordinates: the focused pane's in a split.
var card: CGRect
/// Whether the toolbar shows above the page: not while a page is in full
/// screen.
var toolbarShown = false
/// The toolbar's controls' frames, in window coordinates.
var toolbarControls: [AnchorControl: CGRect] = [:]
/// Whether the sidebar's controls come first: a split with the toolbar off
/// shows them in both, and the user last used the sidebar's.
var prefersSidebar = false

/// Whether bubbles attach to the sidebar's controls before the toolbar's.
var anchorsInSidebar: Bool { prefersSidebar && sidebarInPlace }

func anchor(for kind: AnchorKind, indicator: TabIndicators, extensionID: String?) -> BubbleAnchor {
if anchorsInSidebar,
let rect = controlRect(for: kind, indicator: indicator, extensionID: extensionID, in: controls)
{
return BubbleAnchor(rect: rect, edge: .trailing)
}
if toolbarShown,
let rect = controlRect(for: kind, indicator: indicator, extensionID: extensionID, in: toolbarControls)
{
Expand Down
36 changes: 36 additions & 0 deletions native/ClairUI/BrowserWindowController+Split.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ extension BrowserWindowController: SplitActions {
rootView.splitDivider.onDrag = { [weak self] x, done in
self?.dividerMoved(to: x, done: done)
}
rootView.splitDivider.onDoubleClick = { [weak self] in
self?.centreDivider()
}
for (index, card) in [rootView.card, rootView.secondCard].enumerated() {
card.onHover = { [weak model] inside in
guard let model else { return }
Expand Down Expand Up @@ -100,6 +103,7 @@ extension BrowserWindowController: SplitActions {
/// The divider snaps to equal panes near the centre as it moves, with
/// the trackpad's alignment feedback, and the ratio it's let go at sticks.
private func dividerMoved(to x: CGFloat, done: Bool) {
splitRatioAnimator.stop()
guard let split = model.shownSplit else { return }
let width = rootView.pageArea.width
let current = model.liveRatio(of: split) ?? split.ratio
Expand All @@ -114,6 +118,38 @@ extension BrowserWindowController: SplitActions {
}
}

/// Double-clicking the divider slides it to the centre, with the
/// sidebar's spring, and keeps equal panes.
func centreDivider() {
guard let split = model.shownSplit else { return }
let current = model.liveRatio(of: split) ?? split.ratio
guard current != 0.5 else { return }
let finish = { [weak self] in
guard let self else { return }
self.model.liveSplitPanes = split.paneIDs
self.model.liveSplitRatio = 0.5
self.browser?.setSplitRatio(0.5, of: split.leadingID)
}
guard rootView.window?.isVisible == true, !NSWorkspace.shared.accessibilityDisplayShouldReduceMotion else {
finish()
return
}
splitRatioAnimator.animate(in: rootView, from: current, to: 0.5) { [weak self] ratio, done in
// Another split, or none, ends it where it is.
guard let self, self.model.shownSplit?.paneIDs == split.paneIDs else { return false }
if done {
finish()
} else {
self.model.liveSplitPanes = split.paneIDs
self.model.liveSplitRatio = ratio
}
// Lay out now rather than on the next pass, so the pages resize in step.
self.rootView.needsLayout = true
self.rootView.layoutSubtreeIfNeeded()
return true
}
}

/// Lets go of the dragged ratio once the engine reports it, or once
/// the window shows another split or none.
func settleSplitRatio() {
Expand Down
19 changes: 13 additions & 6 deletions native/ClairUI/BrowserWindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ final class BrowserWindowController: NSObject, ClairWindow, SidebarActions, Over
/// The pane whose header reported `toolbarFrames`.
private var toolbarFramesPane = 0
private var extensionPopup: ExtensionPopupWindow?
/// Centres a split's divider when it's double-clicked.
let splitRatioAnimator = SplitRatioAnimator()
/// The window's dialogs (add-clair-dialogs D1), for every dialog on it.
private(set) lazy var dialogs = ClairDialogPresenter(window: window)
private lazy var extensionPrompts = ExtensionPromptSheets(dialogs: dialogs) { [weak self] promptID, accepted in
Expand Down Expand Up @@ -371,13 +373,16 @@ final class BrowserWindowController: NSObject, ClairWindow, SidebarActions, Over
}
}

deinit {
isolated deinit {
for observer in observers {
NotificationCenter.default.removeObserver(observer)
}
if let flagsMonitor {
NSEvent.removeMonitor(flagsMonitor)
}
// A window closed while the divider centres suspends the display link
// rather than invalidating it, which would keep it and the animator.
splitRatioAnimator.stop()
}

// MARK: Dragging the window from the top of the page
Expand Down Expand Up @@ -896,8 +901,8 @@ final class BrowserWindowController: NSObject, ClairWindow, SidebarActions, Over
return AnchorResolver(
sidebarInPlace: model.sidebar.isShownInPlace && !model.isPageFullscreen && !isWindowFullscreen,
controls: controls,
card: rootView.convert(rootView.card.frame, to: nil),
toolbarShown: isToolbarShown, toolbarControls: toolbarControls)
card: rootView.convert(rootView.focusedCard.frame, to: nil),
toolbarShown: isToolbarShown, toolbarControls: toolbarControls, prefersSidebar: model.bubblesInSidebar)
}

/// Whether the toolbar shows above the page: not while a page is in full
Expand All @@ -919,10 +924,12 @@ final class BrowserWindowController: NSObject, ClairWindow, SidebarActions, Over
let anchorRect = self.anchor(for: anchor, indicator: [], extensionID: extensionID).rect
let name = model.extensionActions.first { $0.extensionID == extensionID }?.name ?? ""
// While the toolbar shows, every popup opens at the same place over it,
// as in Arc; its tile still closes it (add-page-toolbar D6).
// the focused pane's in a split, as in Arc; its tile still closes it
// (add-page-toolbar D6).
let resolver = anchorResolver
var placement = ExtensionPopupWindow.Placement.besideAnchor
if isToolbarShown {
let card = rootView.convert(rootView.card.frame, to: nil)
if isToolbarShown && !resolver.anchorsInSidebar {
let card = resolver.card
placement = .topTrailing(NSPoint(x: card.maxX - ExtensionPopupWindow.toolbarInset, y: card.maxY))
}
let popup = ExtensionPopupWindow(
Expand Down
11 changes: 10 additions & 1 deletion native/ClairUI/BrowserWindowModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,11 @@ final class BrowserWindowModel {
/// Whether the page shows its header, the toolbar. Views read this, not
/// the preference.
var showsPageHeader: Bool { headerPolicy.panesShowHeader }
/// Whether the sidebar shows the browser controls.
/// Whether the sidebar shows its full top row, the URL field and the
/// pinned extensions.
var sidebarShowsControls: Bool { headerPolicy.sidebarShowsControls }
/// Whether the sidebar's top row shows back, forward and reload.
var sidebarShowsNavigation: Bool { headerPolicy.sidebarShowsNavigation }

/// The Peek the card shows over its parent, if any (add-peek D4).
var shownPeek: TabListLogic.ShownPeek?
Expand Down Expand Up @@ -297,6 +300,12 @@ final class BrowserWindowModel {
var isPageFullscreen = false
var isSiteControlCenterOpen = false
var isDownloadsListOpen = false
/// Whether the user last used the sidebar's controls rather than a pane
/// header's, while both show them: a split with the toolbar off.
var usedSidebarControls = false
/// Whether Chromium's bubbles, extension popups and the Site Control
/// Center attach to the sidebar's controls rather than the page header's.
var bubblesInSidebar: Bool { sidebarShowsControls && (!showsPageHeader || usedSidebarControls) }
/// A revealed sidebar stays revealed while one of its popovers is open
/// (arc-site-control-center design D8).
var isSidebarPopoverOpen: Bool { isSiteControlCenterOpen || isDownloadsListOpen }
Expand Down
65 changes: 45 additions & 20 deletions native/ClairUI/PageToolbar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,31 @@ enum PageHeaderContent: Equatable {
case tab
/// A Peek's: back, forward, reload, the link icon and the host.
case peek
/// A split's pane's header: the sidebar toggle in the leading pane, back,
/// forward, the link icon, the host and ×; with `expanded`, while the pane
/// is focused or under the pointer, also reload, the split button, site
/// controls, pinned extensions and indicators.
case pane(leading: Bool, expanded: Bool)
/// A split's pane's header: the sidebar toggle with `toggle` (the leading
/// pane's, while the toolbar preference is on), back, forward, the link
/// icon, the host and ×; with `expanded`, while the pane is focused or
/// under the pointer, also reload, the split button, site controls, pinned
/// extensions and indicators.
case pane(leading: Bool, toggle: Bool, expanded: Bool)

/// The leading controls that always show before reload.
var leadingCount: Int {
switch self {
case .tab: 3
case .peek: 2
case .pane(let leading, _): leading ? 3 : 2
case .pane(_, let toggle, _): toggle ? 3 : 2
}
}
var showsSidebarToggle: Bool { leadingCount == 3 }
var showsReload: Bool {
if case .pane(_, let expanded) = self { return expanded }
if case .pane(_, _, let expanded) = self { return expanded }
return true
}
private var showsAll: Bool {
switch self {
case .tab: true
case .peek: false
case .pane(_, let expanded): expanded
case .pane(_, _, let expanded): expanded
}
}
var showsSiteControls: Bool { showsAll }
Expand All @@ -58,7 +59,7 @@ enum PageHeaderContent: Equatable {
switch self {
case .tab: "clair.toolbar"
case .peek: "clair.peekToolbar"
case .pane(let leading, _): "clair.paneToolbar.\(leading ? 0 : 1)"
case .pane(let leading, _, _): "clair.paneToolbar.\(leading ? 0 : 1)"
}
}
}
Expand Down Expand Up @@ -111,7 +112,9 @@ struct PageToolbar: View {
case .peek: return .peek
case .pane(let index):
guard let split = model.shownSplit else { return .tab }
return .pane(leading: index == 0, expanded: split.focusedIndex == index || model.hoveredPane == index)
return .pane(
leading: index == 0, toggle: model.headerPolicy.togglePane == index,
expanded: split.focusedIndex == index || model.hoveredPane == index)
}
}

Expand All @@ -127,10 +130,12 @@ struct PageToolbar: View {
return split.focusedIndex != index
}

/// Runs `action` on the pane's tab: the pane is focused first.
/// Runs `action` on the pane's tab: the pane is focused first, and the
/// bubble it opens attaches to the header, not the sidebar.
private func onPane(_ action: @escaping () -> Void) -> () -> Void {
{ [weak actions] in
if isOtherPane, let paneTabID { actions?.focusPane(paneTabID) }
model.usedSidebarControls = false
action()
}
}
Expand Down Expand Up @@ -239,6 +244,9 @@ struct PageToolbar: View {
.toolbarRole(.trailingFixed(closeSlot))
}
}
// Showing another split, or none, swaps the header at once: the fade is
// only for the controls of the split already shown.
.transaction(value: model.shownSplit?.paneIDs) { $0.animation = nil }
// The other pane's controls fade in and out as the pointer comes and
// goes, as Arc's do (add-split-view, "Controls of the other pane").
.animation(reduceMotion ? nil : .easeInOut(duration: 0.15), value: content)
Expand Down Expand Up @@ -382,8 +390,12 @@ struct PageToolbar: View {
// A click while the popover is open only closes it (arc-site-control-center
// design D2).
.allowsHitTesting(!model.isSiteControlCenterOpen)
// Only the focused pane's button holds the popover (add-split-view D9).
.popover(isPresented: isOtherPane ? .constant(false) : $model.isSiteControlCenterOpen, arrowEdge: .bottom) {
// Only the focused pane's button holds the popover (add-split-view D9),
// unless it was opened from the sidebar's URL field.
.popover(
isPresented: isOtherPane || model.bubblesInSidebar ? .constant(false) : $model.isSiteControlCenterOpen,
arrowEdge: .bottom
) {
SiteControlCenter(model: model, actions: actions) { model.isSiteControlCenterOpen = false }
}
.anchorFrame(.siteControls)
Expand All @@ -402,16 +414,29 @@ struct PageToolbar: View {

/// The toolbar's context menu: Copy URL and Hide Toolbar, as in Arc.
private func menuItems(canCopy: Bool) -> [RowClickCatcher.Item] {
let paneTabID = self.paneTabID
return Self.menuItems(
canCopy: canCopy, showsToolbar: model.showsToolbar,
copy: { [weak actions] in
if let paneTabID { actions?.copyURL(of: paneTabID) } else { actions?.copyURL() }
},
hide: { [weak actions] in actions?.setToolbarShown(false) })
}

/// Copy URL when there's one to copy, and Hide Toolbar only while the
/// preference is on: a split's pane headers show with it off, and hiding
/// them would do nothing.
static func menuItems(
canCopy: Bool, showsToolbar: Bool, copy: @escaping () -> Void, hide: @escaping () -> Void
) -> [RowClickCatcher.Item] {
var items: [RowClickCatcher.Item] = []
if canCopy {
let paneTabID = self.paneTabID
items.append(
.action("Copy URL") { [weak actions] in
if let paneTabID { actions?.copyURL(of: paneTabID) } else { actions?.copyURL() }
})
items.append(.separator)
items.append(.action("Copy URL", copy))
}
if showsToolbar {
if !items.isEmpty { items.append(.separator) }
items.append(.action(ToolbarPreference.menuTitle(isOn: true), hide))
}
items.append(.action(ToolbarPreference.menuTitle(isOn: true)) { [weak actions] in actions?.setToolbarShown(false) })
return items
}
}
Loading