diff --git a/apple/TablePro/Core/Services/Infrastructure/MainSplitViewController+AgentPanes.swift b/apple/TablePro/Core/Services/Infrastructure/MainSplitViewController+AgentPanes.swift index 5d2e9ce699..e69d4df569 100644 --- a/apple/TablePro/Core/Services/Infrastructure/MainSplitViewController+AgentPanes.swift +++ b/apple/TablePro/Core/Services/Infrastructure/MainSplitViewController+AgentPanes.swift @@ -18,9 +18,9 @@ import SwiftUI internal extension MainSplitViewController { func refreshAgentPanes(of workspace: ConnectionWorkspace) { guard workspace.resolvedContentMode == .agent else { return } - workspace.panes.agentRail.rootView = AnyView(buildAgentRailView(for: workspace)) + workspace.panes.agentRail.rootView = AnyView(buildAgentRailView(for: workspace).onSplitItem()) workspace.panes.agentConversation.rootView = AnyView(buildAgentConversationView(for: workspace)) - workspace.panes.agentResult.rootView = AnyView(buildAgentResultView(for: workspace)) + workspace.panes.agentResult.rootView = AnyView(buildAgentResultView(for: workspace).onSplitItem()) } /// Re-arms only when the session naming the window changes, so the title can be asked for on diff --git a/apple/TablePro/Core/Services/Infrastructure/MainSplitViewController.swift b/apple/TablePro/Core/Services/Infrastructure/MainSplitViewController.swift index 867911de50..341d3bd2fe 100644 --- a/apple/TablePro/Core/Services/Infrastructure/MainSplitViewController.swift +++ b/apple/TablePro/Core/Services/Infrastructure/MainSplitViewController.swift @@ -342,6 +342,7 @@ internal final class MainSplitViewController: NSSplitViewController { addSplitViewItem(detailSplitItem) inspectorPaneHost = WorkspacePaneHost() + inspectorPaneHost.installBackdrop(SplitItemBackdrop.makeView()) inspectorSplitItem = NSSplitViewItem(inspectorWithViewController: inspectorPaneHost) inspectorSplitItem.canCollapse = true inspectorSplitItem.minimumThickness = Self.inspectorMinThickness @@ -825,10 +826,10 @@ internal final class MainSplitViewController: NSSplitViewController { /// `teardown()` needs only because its panes are never parented again: here it would mount every /// intermediate value instead of letting one run-loop turn settle on the final one. private func refreshPanes(of workspace: ConnectionWorkspace) { - workspace.panes.sidebar.rootView = AnyView(buildSidebarView(for: workspace)) + workspace.panes.sidebar.rootView = AnyView(buildSidebarView(for: workspace).onSplitItem()) workspace.panes.detail.rootView = AnyView(buildDetailView(for: workspace)) - workspace.panes.inspector.rootView = AnyView(buildInspectorView(for: workspace)) - workspace.panes.assistant.rootView = AnyView(buildAssistantView(for: workspace)) + workspace.panes.inspector.rootView = AnyView(buildInspectorView(for: workspace).onSplitItem()) + workspace.panes.assistant.rootView = AnyView(buildAssistantView(for: workspace).onSplitItem()) refreshAgentPanes(of: workspace) refreshTabStripPane(of: workspace) workspace.panes.markRendered(workspace.paneRenderKey) @@ -1065,8 +1066,8 @@ internal final class MainSplitViewController: NSSplitViewController { /// publishes those actions. func rebuildTrailingPanes() { guard let selected = workspaces.selected else { return } - selected.panes.inspector.rootView = AnyView(buildInspectorView(for: selected)) - selected.panes.assistant.rootView = AnyView(buildAssistantView(for: selected)) + selected.panes.inspector.rootView = AnyView(buildInspectorView(for: selected).onSplitItem()) + selected.panes.assistant.rootView = AnyView(buildAssistantView(for: selected).onSplitItem()) } // MARK: - Session Bindings diff --git a/apple/TablePro/Core/Services/Infrastructure/NavigationSidebarViewController.swift b/apple/TablePro/Core/Services/Infrastructure/NavigationSidebarViewController.swift index ed04fe4b86..18182ca6aa 100644 --- a/apple/TablePro/Core/Services/Infrastructure/NavigationSidebarViewController.swift +++ b/apple/TablePro/Core/Services/Infrastructure/NavigationSidebarViewController.swift @@ -55,6 +55,16 @@ internal final class NavigationSidebarViewController: NSViewController { override func loadView() { view = NSView() + // On the pane root and not the split below it, so it reaches the titlebar band too. + let backdrop = SplitItemBackdrop.makeView() + backdrop.translatesAutoresizingMaskIntoConstraints = false + view.addSubview(backdrop) + NSLayoutConstraint.activate([ + backdrop.leadingAnchor.constraint(equalTo: view.leadingAnchor), + backdrop.trailingAnchor.constraint(equalTo: view.trailingAnchor), + backdrop.topAnchor.constraint(equalTo: view.topAnchor), + backdrop.bottomAnchor.constraint(equalTo: view.bottomAnchor), + ]) _ = railController.view railController.isStripShown = false diff --git a/apple/TablePro/Theme/MaterialAccessibility.swift b/apple/TablePro/Theme/MaterialAccessibility.swift index ada488a4cb..5a7af6ac4b 100644 --- a/apple/TablePro/Theme/MaterialAccessibility.swift +++ b/apple/TablePro/Theme/MaterialAccessibility.swift @@ -1,4 +1,5 @@ import SwiftUI +import TableProTheme internal enum MaterialRole { case toolbar @@ -56,15 +57,28 @@ private struct AccessibleMaterialBackgroundShape: ViewModifier { } } +// The scrim covers a detail pane, so its solid stand-in is the window color that pane sits on. internal struct AccessibleMaterialScrim: View { let material: Material - @Environment(\.accessibilityReduceTransparency) private var reduceTransparency + // The environment value is get-only, so a test hands its own. + var reduceTransparency: Bool? + + @ObservedObject private var themeEngine = ThemeEngine.shared + @Environment(\.accessibilityReduceTransparency) private var systemReduceTransparency @Environment(\.colorSchemeContrast) private var contrast var body: some View { + let reduceTransparency = reduceTransparency ?? systemReduceTransparency if SolidSurfacePreference.prefersSolid(reduceTransparency: reduceTransparency, contrast: contrast) { - Rectangle().fill(MaterialRole.scrim.solidFallback) + Rectangle().fill( + ThemeShapeStyle.style( + .windowBackdrop, + native: MaterialRole.scrim.solidFallback, + engine: themeEngine, + contrast: contrast + ) + ) } else { Rectangle().fill(material) } diff --git a/apple/TablePro/Theme/PaneBarBackground.swift b/apple/TablePro/Theme/PaneBarBackground.swift index 3873506830..80d6beae44 100644 --- a/apple/TablePro/Theme/PaneBarBackground.swift +++ b/apple/TablePro/Theme/PaneBarBackground.swift @@ -1,16 +1,17 @@ import SwiftUI -/// A bar's material is drawn for the system window color, so over a themed backdrop it reads as a -/// system band. The bar then draws nothing and shows the pane's theme through it. +// A bar's material is drawn for the system window color, so over a themed backdrop it reads as a +// system band. The bar then draws nothing and shows the pane's theme through it. private struct PaneBarBackground: ViewModifier { @ObservedObject private var themeEngine = ThemeEngine.shared @Environment(\.colorSchemeContrast) private var contrast + @Environment(\.isOnSplitItem) private var isOnSplitItem let native: Native let edges: Edge.Set func body(content: Content) -> some View { - let isThemed = ThemeBackdropState.isThemed(highContrast: contrast == .increased) + let isThemed = ThemeBackdropState.isThemed(highContrast: contrast == .increased, onSplitItem: isOnSplitItem) return content.background( isThemed ? AnyShapeStyle(Color.clear) : AnyShapeStyle(native), ignoresSafeAreaEdges: edges @@ -19,8 +20,7 @@ private struct PaneBarBackground: ViewModifier { } internal extension View { - /// No edges by default: a bar at the top of a pane would otherwise reach under the toolbar and - /// pull its glass toward the bar's material. + // No edges by default: a top bar would otherwise reach under the toolbar and pull its glass toward the bar's material. func paneBarBackground(_ native: some ShapeStyle = .bar, ignoresSafeAreaEdges edges: Edge.Set = []) -> some View { modifier(PaneBarBackground(native: native, edges: edges)) } diff --git a/apple/TablePro/Theme/SplitItemBackdrop.swift b/apple/TablePro/Theme/SplitItemBackdrop.swift new file mode 100644 index 0000000000..3d0ef821b4 --- /dev/null +++ b/apple/TablePro/Theme/SplitItemBackdrop.swift @@ -0,0 +1,63 @@ +import AppKit +import SwiftUI +import TableProTheme + +// Under Reduce Transparency the sidebar and inspector glass draws an opaque system fill that drops the +// window color, so the pane draws `window.background` itself until the glass comes back. +@MainActor +internal enum SplitItemBackdrop { + internal static func fills(reachesChrome: Bool, reduceTransparency: Bool, isThemed: Bool) -> Bool { + reachesChrome && reduceTransparency && isThemed + } + + internal static func makeView(reduceTransparency: Bool? = nil) -> NSView { + let view = SplitItemBackdropView(rootView: SplitItemBackdropSurface(reduceTransparency: reduceTransparency)) + view.sizingOptions = [] + return view + } +} + +internal struct SplitItemBackdropFill: ViewModifier { + @ObservedObject private var themeEngine = ThemeEngine.shared + @Environment(\.accessibilityReduceTransparency) private var systemReduceTransparency + @Environment(\.colorSchemeContrast) private var contrast + + // The environment value is get-only, so a test hands its own. + internal var reduceTransparency: Bool? + internal var reachesChrome = ThemeWindowBackdrop.canReachChrome + + internal func body(content: Content) -> some View { + let fills = SplitItemBackdrop.fills( + reachesChrome: reachesChrome, + reduceTransparency: reduceTransparency ?? systemReduceTransparency, + isThemed: ThemeBackdropState.isThemed(highContrast: contrast == .increased) + ) + return content.background( + fills ? AnyShapeStyle(Color(nsColor: themeEngine.palette[.windowBackdrop])) : AnyShapeStyle(Color.clear), + ignoresSafeAreaEdges: .all + ) + } +} + +internal extension View { + func splitItemBackdrop() -> some View { + modifier(SplitItemBackdropFill()) + } +} + +private struct SplitItemBackdropSurface: View { + let reduceTransparency: Bool? + + var body: some View { + Color.clear + .modifier(SplitItemBackdropFill(reduceTransparency: reduceTransparency)) + .accessibilityHidden(true) + } +} + +// A point the pane above leaves unclaimed still reaches the glass and the window. +private final class SplitItemBackdropView: NSHostingView { + override func hitTest(_ point: NSPoint) -> NSView? { + nil + } +} diff --git a/apple/TablePro/Theme/ThemeBackdropState.swift b/apple/TablePro/Theme/ThemeBackdropState.swift index 61cf007d6f..880392397f 100644 --- a/apple/TablePro/Theme/ThemeBackdropState.swift +++ b/apple/TablePro/Theme/ThemeBackdropState.swift @@ -1,16 +1,43 @@ import AppKit +import SwiftUI import TableProTheme -/// Whether the window backdrop draws the theme's color. Chrome over the backdrop asks this rather -/// than reading a slot: a bar keeps its material until the theme colors what is behind it. +// Chrome asks this rather than reading a slot: a bar keeps its material until the theme colors what is behind it. @MainActor internal enum ThemeBackdropState { internal static func isThemed(in appearance: NSAppearance, scope: ThemeScope = .live) -> Bool { isThemed(highContrast: appearance.isHighContrast, scope: scope) } - /// For SwiftUI, which knows the contrast from its environment rather than from an appearance. internal static func isThemed(highContrast: Bool, scope: ThemeScope = .live) -> Bool { scope.activeTheme.isOverridden(.windowBackdrop, highContrast: highContrast) } + + // A sidebar or inspector takes the theme only through the window color, which reaches it from macOS 26. + internal static func isThemed( + highContrast: Bool, + onSplitItem: Bool, + reachesChrome: Bool = ThemeWindowBackdrop.canReachChrome, + scope: ThemeScope = .live + ) -> Bool { + guard !onSplitItem || reachesChrome else { return false } + return isThemed(highContrast: highContrast, scope: scope) + } +} + +private struct OnSplitItemKey: EnvironmentKey { + static let defaultValue = false +} + +internal extension EnvironmentValues { + var isOnSplitItem: Bool { + get { self[OnSplitItemKey.self] } + set { self[OnSplitItemKey.self] = newValue } + } +} + +internal extension View { + func onSplitItem() -> some View { + environment(\.isOnSplitItem, true) + } } diff --git a/apple/TablePro/Views/Agent/AgentSessionRailView.swift b/apple/TablePro/Views/Agent/AgentSessionRailView.swift index c73a2eaefe..69b7a681e4 100644 --- a/apple/TablePro/Views/Agent/AgentSessionRailView.swift +++ b/apple/TablePro/Views/Agent/AgentSessionRailView.swift @@ -94,6 +94,7 @@ internal struct AgentSessionRailView: View { guard let session = highlightedSession else { return } onDelete(session.id) } + .splitItemGlassBackground() } /// A contextual menu leaves out what does not apply rather than dimming it, which is the reverse diff --git a/apple/TablePro/Views/DataFiles/DataFileRowDetailsView.swift b/apple/TablePro/Views/DataFiles/DataFileRowDetailsView.swift index 20ae8e73fa..1f8ebcc081 100644 --- a/apple/TablePro/Views/DataFiles/DataFileRowDetailsView.swift +++ b/apple/TablePro/Views/DataFiles/DataFileRowDetailsView.swift @@ -36,6 +36,8 @@ struct DataFileRowDetailsView: View { } } .frame(maxWidth: .infinity, maxHeight: .infinity) + .splitItemBackdrop() + .onSplitItem() .onAppear(perform: configure) .onChange(of: controller.selectedRowIndices) { _ in configure() } .onChange(of: controller.pageRevision) { _ in configure() } diff --git a/apple/TablePro/Views/Results/StatusBarChrome.swift b/apple/TablePro/Views/Results/StatusBarChrome.swift index 4901bbe05d..7a57f6e18a 100644 --- a/apple/TablePro/Views/Results/StatusBarChrome.swift +++ b/apple/TablePro/Views/Results/StatusBarChrome.swift @@ -28,13 +28,14 @@ private struct StatusBarMaterial: NSViewRepresentable { func updateNSView(_ nsView: NSVisualEffectView, context: Context) {} } -/// The material does not follow a custom window color, so over a themed backdrop the bar draws none. +// The material does not follow a custom window color, so over a themed backdrop the bar draws none. private struct StatusBarChromeModifier: ViewModifier { @ObservedObject private var themeEngine = ThemeEngine.shared @Environment(\.colorSchemeContrast) private var contrast + @Environment(\.isOnSplitItem) private var isOnSplitItem func body(content: Content) -> some View { - let isThemed = ThemeBackdropState.isThemed(highContrast: contrast == .increased) + let isThemed = ThemeBackdropState.isThemed(highContrast: contrast == .increased, onSplitItem: isOnSplitItem) return VStack(spacing: 0) { Divider() content diff --git a/apple/TableProTests/Theme/SplitItemBackdropTests.swift b/apple/TableProTests/Theme/SplitItemBackdropTests.swift new file mode 100644 index 0000000000..6c23deada2 --- /dev/null +++ b/apple/TableProTests/Theme/SplitItemBackdropTests.swift @@ -0,0 +1,162 @@ +// +// SplitItemBackdropTests.swift +// TableProTests +// + +import AppKit +import SwiftUI +@testable import TablePro +import TableProTheme +import Testing + +// Reduce Transparency is passed in, never read: the CI image runs with it on. +@MainActor +struct SplitItemBackdropTests { + private static let center = CGPoint(x: 0.5, y: 0.5) + + private func pane(reduceTransparency: Bool, reachesChrome: Bool = true) -> some View { + Color.clear + .frame(width: 80, height: 80) + .modifier(SplitItemBackdropFill(reduceTransparency: reduceTransparency, reachesChrome: reachesChrome)) + } + + @Test("The pane fills only on macOS 26 and later, under Reduce Transparency, with a themed window") + func gateNeedsAllThree() { + for reachesChrome in [false, true] { + for reduceTransparency in [false, true] { + for isThemed in [false, true] { + let fills = SplitItemBackdrop.fills( + reachesChrome: reachesChrome, + reduceTransparency: reduceTransparency, + isThemed: isThemed + ) + #expect(fills == (reachesChrome && reduceTransparency && isThemed)) + } + } + } + } + + @Test("Under Reduce Transparency the pane draws the window theme") + func reduceTransparencyDrawsTheWindowTheme() throws { + try ThemeTestFixture.adopting([.windowBackdrop: ThemeTestFixture.windowHex], appearance: .dark) { + let theme = try ThemeTestFixture.filled(hex: ThemeTestFixture.windowHex, colorScheme: .dark) + let drawn = try ThemeTestFixture.color(of: pane(reduceTransparency: true), at: Self.center, colorScheme: .dark) + #expect(ThemeTestFixture.matches(drawn, theme), "drew \(drawn), theme \(theme)") + } + } + + @Test("With transparency on the pane draws nothing, so the glass shows") + func glassShowsWithoutReduceTransparency() throws { + try ThemeTestFixture.adopting([.windowBackdrop: ThemeTestFixture.windowHex], appearance: .dark) { + let drawn = try ThemeTestFixture.color(of: pane(reduceTransparency: false), at: Self.center, colorScheme: .dark) + #expect(drawn.alphaComponent < 0.05, "drew \(drawn)") + } + } + + @Test("A theme without a window color leaves the system fill alone") + func defaultThemeDrawsNothing() throws { + try ThemeTestFixture.adopting(.builtIn, appearance: .dark) { + let drawn = try ThemeTestFixture.color(of: pane(reduceTransparency: true), at: Self.center, colorScheme: .dark) + #expect(drawn.alphaComponent < 0.05, "drew \(drawn)") + } + } + + @Test("Before macOS 26 the sidebar never took the theme, so it stays system") + func noFillBeforeTheBackdropRelease() throws { + try ThemeTestFixture.adopting([.windowBackdrop: ThemeTestFixture.windowHex], appearance: .dark) { + let drawn = try ThemeTestFixture.color( + of: pane(reduceTransparency: true, reachesChrome: false), + at: Self.center, + colorScheme: .dark + ) + #expect(drawn.alphaComponent < 0.05, "drew \(drawn)") + } + } + + @Test("Increase Contrast keeps the system fill") + func increaseContrastIsNotThemed() throws { + try ThemeTestFixture.adopting([.windowBackdrop: ThemeTestFixture.windowHex], appearance: .dark) { + #expect(ThemeBackdropState.isThemed(highContrast: false)) + #expect(!ThemeBackdropState.isThemed(highContrast: true)) + } + } + + @Test("The backdrop never takes a click") + func backdropPassesClicks() { + let backdrop = SplitItemBackdrop.makeView(reduceTransparency: true) + backdrop.frame = NSRect(x: 0, y: 0, width: 80, height: 80) + #expect(backdrop.hitTest(NSPoint(x: 10, y: 10)) == nil) + } + + @Test("The main window's sidebar and inspector sit on the backdrop, over the full pane") + func mainWindowPanesHaveTheBackdrop() throws { + let fixture = try OffscreenConnectionWindow(size: CGSize(width: 1_200, height: 800)) + defer { fixture.tearDown() } + fixture.setInspectorOpen(true) + + let sidebar = fixture.split.sidebarSplitItem.viewController.view + let sidebarBackdrop = try #require(sidebar.subviews.first) + #expect(String(describing: type(of: sidebarBackdrop)).contains("SplitItemBackdrop")) + #expect(sidebarBackdrop.frame == sidebar.bounds) + + let inspector = fixture.split.inspectorPaneHost.view + let inspectorBackdrop = try #require(inspector.subviews.first) + #expect(String(describing: type(of: inspectorBackdrop)).contains("SplitItemBackdrop")) + #expect(inspectorBackdrop.frame == inspector.bounds) + } + + // The one case that follows this Mac's setting: the view reads it from its environment. + @Test("The data file inspector fills with the window theme exactly while this Mac reduces transparency") + func dataFileInspectorFollowsReduceTransparency() throws { + try ThemeTestFixture.adopting([.windowBackdrop: ThemeTestFixture.windowHex], appearance: .dark) { + let host = NSHostingView(rootView: DataFileRowDetailsView(controller: DataFileDocument().controller)) + host.sizingOptions = [] + host.frame = NSRect(x: 0, y: 0, width: 300, height: 400) + let window = NSWindow(contentRect: host.frame, styleMask: [.borderless], backing: .buffered, defer: false) + window.isReleasedWhenClosed = false + window.appearance = NSAppearance(named: .darkAqua) + window.contentView = host + defer { window.contentView = nil } + + host.layoutSubtreeIfNeeded() + host.displayIfNeeded() + let bitmap = try #require(host.bitmapImageRepForCachingDisplay(in: host.bounds)) + host.cacheDisplay(in: host.bounds, to: bitmap) + let drawn = try #require(ThemeTestFixture.pixel(bitmap, x: 4, y: bitmap.pixelsHigh - 4)) + + let fills = ThemeWindowBackdrop.canReachChrome && NSWorkspace.shared.accessibilityDisplayShouldReduceTransparency + if fills { + let theme = try ThemeTestFixture.filled(hex: ThemeTestFixture.windowHex, colorScheme: .dark) + #expect(ThemeTestFixture.matches(drawn, theme, tolerance: 0.04), "drew \(drawn), theme \(theme)") + } else { + #expect(drawn.alphaComponent < 0.05, "drew \(drawn)") + } + } + } + + @Test("A bar over a sidebar or inspector keeps its material where the window color cannot reach it") + func barsOnASplitItemNeedTheBackdropRelease() throws { + try ThemeTestFixture.adopting([.windowBackdrop: ThemeTestFixture.windowHex], appearance: .dark) { + #expect(ThemeBackdropState.isThemed(highContrast: false, onSplitItem: false, reachesChrome: false)) + #expect(!ThemeBackdropState.isThemed(highContrast: false, onSplitItem: true, reachesChrome: false)) + #expect(ThemeBackdropState.isThemed(highContrast: false, onSplitItem: true, reachesChrome: true)) + #expect(!ThemeBackdropState.isThemed(highContrast: true, onSplitItem: true, reachesChrome: true)) + } + } + + @Test("Under Reduce Transparency the license scrim is the window color its pane sits on") + func solidScrimFollowsTheWindowTheme() throws { + let scrim = AccessibleMaterialScrim(material: .ultraThinMaterial, reduceTransparency: true) + .frame(width: 80, height: 80) + try ThemeTestFixture.adopting([.windowBackdrop: ThemeTestFixture.windowHex], appearance: .dark) { + let theme = try ThemeTestFixture.filled(hex: ThemeTestFixture.windowHex, colorScheme: .dark) + let drawn = try ThemeTestFixture.color(of: scrim, at: Self.center, colorScheme: .dark) + #expect(ThemeTestFixture.matches(drawn, theme), "drew \(drawn), theme \(theme)") + } + try ThemeTestFixture.adopting(.builtIn, appearance: .dark) { + let native = try ThemeTestFixture.filled(.windowBackgroundColor, colorScheme: .dark) + let drawn = try ThemeTestFixture.color(of: scrim, at: Self.center, colorScheme: .dark) + #expect(ThemeTestFixture.matches(drawn, native), "drew \(drawn), native \(native)") + } + } +} diff --git a/apple/changelog.d/4153.changed.md b/apple/changelog.d/4153.changed.md new file mode 100644 index 0000000000..6d789a926b --- /dev/null +++ b/apple/changelog.d/4153.changed.md @@ -0,0 +1 @@ +With Reduce Transparency on, themes now color the sidebar and inspector on macOS 26 and later. diff --git a/apple/changelog.d/4153.fixed.1.md b/apple/changelog.d/4153.fixed.1.md new file mode 100644 index 0000000000..6a9d4072aa --- /dev/null +++ b/apple/changelog.d/4153.fixed.1.md @@ -0,0 +1 @@ +Bars in the inspector lost their background under a theme on macOS 13 to 15. diff --git a/apple/changelog.d/4153.fixed.md b/apple/changelog.d/4153.fixed.md new file mode 100644 index 0000000000..a13381d1f8 --- /dev/null +++ b/apple/changelog.d/4153.fixed.md @@ -0,0 +1 @@ +The license notice over Charts and Query Insights covered a themed window in system gray with Reduce Transparency on.