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.
A page's right-click menu is Arc's: Chromium's own menu, extension icons, Arc's items
Victor8c26618e676b
diff --git a/Packages/CraCore/Sources/CraCore/ContentCapture.swift b/Packages/CraCore/Sources/CraCore/ContentCapture.swiftindex f279195..c633c8f 100644--- a/Packages/CraCore/Sources/CraCore/ContentCapture.swift+++ b/Packages/CraCore/Sources/CraCore/ContentCapture.swift@@ -79,6 +79,53 @@ public enum ContentCapture {return CGRect(x: max(bounds.minX + menuMargin, x), y: max(bounds.minY + menuMargin, y), width: size.width, height: size.height)}+ // MARK: Capture Image… (a page's context menu on an image)++ /// Arc 1.172 (Little Arc, 2x window capture, 6 Nov 2026): Capture Image… greys the page and+ /// moves the image, at its size on the page, to the middle of the page in the 4 pt ring with no+ /// clearance; the menu sits 10 pt right of the ring, top level with it, and image, ring and menu+ /// are centred on the page together, the menu counted 10 pt narrower than it draws (on a+ /// 1688 pt page a 160 pt image's ring starts at 623.5). The image's own place stays grey.+ public static let liftedMenuGap: CGFloat = 10+ static let liftedMenuCentringInset: CGFloat = 10++ /// The image (inside the ring) and the menu. An image too big for the page shrinks to fit;+ /// where the menu has no room beside it, it goes where `menuFrame` puts it.+ public static func liftedLayout(image: CGSize, menu: CGSize, in bounds: CGRect) -> (image: CGRect, menu: CGRect) {+ let room = bounds.insetBy(dx: menuMargin + lensRing, dy: menuMargin + lensRing)+ var size = image+ if size.width > room.width || size.height > room.height, size.width > 0, size.height > 0 {+ let k = min(room.width / size.width, room.height / size.height)+ size = CGSize(width: (size.width * k).rounded(.down), height: (size.height * k).rounded(.down))+ }+ let fits = size.width + 2 * lensRing + liftedMenuGap + menu.width <= bounds.width - 2 * menuMargin+ let centred = size.width + 2 * lensRing + liftedMenuGap + menu.width - liftedMenuCentringInset+ let x = fits ? bounds.midX - centred / 2 + lensRing : bounds.midX - size.width / 2+ // To the half point, as Arc's 2x captures land.+ let half = { (v: CGFloat) in (v * 2).rounded() / 2 }+ let rect = CGRect(x: half(x), y: half(bounds.midY - size.height / 2), width: size.width, height: size.height)+ let ring = lensFrame(around: rect)+ let beside = CGRect(x: ring.maxX + liftedMenuGap, y: ring.minY, width: menu.width, height: menu.height)+ let menuRect = fits && beside.maxY <= bounds.maxY - menuMargin ? beside : menuFrame(size: menu, besideLens: ring, in: bounds)+ return (rect, menuRect)+ }++ /// The image the context menu was opened on: the topmost image, picture, canvas or SVG image+ /// under the point, else the topmost element. Takes and returns device pixels, as the picker does.+ public static func imageRectScript(x: CGFloat, y: CGFloat) -> String {+ """+ (() => {+ const vv = visualViewport, dpr = devicePixelRatio, k = vv.scale;+ const px = \(Double(x)) / dpr / k + vv.offsetLeft, py = \(Double(y)) / dpr / k + vv.offsetTop;+ const all = document.elementsFromPoint(px, py);+ const el = all.find(e => ['IMG', 'PICTURE', 'CANVAS', 'image'].includes(e.tagName)) || all[0];+ if (!el) return null;+ const r = el.getBoundingClientRect();+ return {x: (r.left - vv.offsetLeft) * k * dpr, y: (r.top - vv.offsetTop) * k * dpr, width: r.width * k * dpr, height: r.height * k * dpr};+ })()+ """+ }+private static func number(_ v: Any?) -> CGFloat? {if let d = v as? Double { return CGFloat(d) }if let n = v as? NSNumber { return CGFloat(truncating: n) }diff --git a/Packages/CraCore/Tests/CraCoreTests/ContentCaptureTests.swift b/Packages/CraCore/Tests/CraCoreTests/ContentCaptureTests.swiftindex 4714b49..a077860 100644--- a/Packages/CraCore/Tests/CraCoreTests/ContentCaptureTests.swift+++ b/Packages/CraCore/Tests/CraCoreTests/ContentCaptureTests.swift@@ -96,4 +96,29 @@ struct ContentCaptureTests {#expect(s.contains("456.0 / dpr"))#expect(s.contains("elementsFromPoint"))}++ @Test func capturedImageMovesToTheMiddleWithTheMenuBesideIt() {+ // Arc 1.172's Little Arc: a 1688 × 963 pt page, a 160 × 100 pt image, the 273 pt menu.+ let page = CGRect(x: 0, y: 0, width: 1688, height: 963)+ let l = ContentCapture.liftedLayout(image: CGSize(width: 160, height: 100), menu: CGSize(width: 273, height: 300), in: page)+ #expect(l.image == CGRect(x: 627.5, y: 431.5, width: 160, height: 100))+ // Ring 623.5…791.5, the menu 10 pt on, level with the ring's top.+ #expect(l.menu == CGRect(x: 801.5, y: 427.5, width: 273, height: 300))+ }++ @Test func capturedImageTooBigShrinksAndTheMenuFindsRoom() {+ let l = ContentCapture.liftedLayout(image: CGSize(width: 2000, height: 1000), menu: CGSize(width: 273, height: 300), in: Self.page)+ // Fits inside the ring and margins, aspect kept.+ #expect(l.image.width == 976 && l.image.height == 488)+ #expect(Self.page.contains(ContentCapture.lensFrame(around: l.image)))+ // No room beside it: menuFrame's place, inside the page.+ #expect(Self.page.insetBy(dx: ContentCapture.menuMargin, dy: ContentCapture.menuMargin).contains(l.menu))+ }++ @Test func imageScriptLooksForTheImageUnderThePoint() {+ let js = ContentCapture.imageRectScript(x: 120, y: 80)+ #expect(js.contains("elementsFromPoint(px, py)"))+ #expect(js.contains("120.0 / dpr / k"))+ #expect(js.contains("'IMG'"))+ }}diff --git a/Sources/Cra/App/AppDelegate.swift b/Sources/Cra/App/AppDelegate.swiftindex 2d13c73..bc2fbe0 100644--- a/Sources/Cra/App/AppDelegate.swift+++ b/Sources/Cra/App/AppDelegate.swift@@ -49,7 +49,6 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuItemValidation {installURLEventHandler()PerfCEF.install(app: self)CraCEFRuntime.setChromeHosting(store.settings.chromeEngine)- CraCEFRuntime.setOwnContextMenus(EmbeddedPages.isEnabled)CraCEFRuntime.setDocumentStartScript(PageScript.mainWorld, isolatedScript: PageScript.isolatedWorld, world: PageScript.world)startContentBlocking()observeGlobalShortcut()@@ -443,11 +442,13 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuItemValidation {/// Arc's New Window (⌘N): another window on the space in use, cascaded from the/// current one, with the command bar up. With every window closed it brings the/// hidden one back instead. New Incognito Window (⇧⌘N) always opens a new one.- func openNewWindow(incognito: Bool = false) {+ /// With `url` (a page's Open Link in New Window) the window opens on that page instead.+ func openNewWindow(incognito: Bool = false, url: String? = nil) {if !incognito, let hidden = mainWindows.first(where: { !$0.isIncognito }),!mainWindows.contains(where: { $0.window?.isVisible == true || $0.window?.isMiniaturized == true }) {hidden.showWindow(nil)NSApp.activate(ignoringOtherApps: true)+ if let url { store.createTab(url: url, select: true, window: hidden.windowID) }return}var frame: String?@@ -465,7 +466,20 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuItemValidation {store.activeWindowID = c.windowIDc.showWindow(nil)NSApp.activate(ignoringOtherApps: true)- c.openCommandBar(.newTab)+ if let url { store.createTab(url: url, select: true, window: c.windowID) } else { c.openCommandBar(.newTab) }+ }++ /// A page's context menu: Arc's Open Link in New Window, Little Arc (Little Window here)+ /// and Incognito Window. From an incognito page a new window is incognito too, as in Chrome,+ /// and nothing opens in a Little Window, whose pages load in the normal profile.+ func openLink(_ url: String, in kind: CraLinkWindow, space: UUID?, fromIncognito: Bool) {+ // cra:// is Cra's scripting scheme; a page must not drive it.+ if url.lowercased().hasPrefix("cra:") { return }+ switch kind {+ case .little where !fromIncognito: openLittleWindow(url: url, space: space)+ case .incognito: openNewWindow(incognito: true, url: url)+ default: openNewWindow(incognito: fromIncognito, url: url)+ }}/// Closing one of several windows ends it; the last normal one stays around hidden,diff --git a/Sources/Cra/Services/BrowserManager.swift b/Sources/Cra/Services/BrowserManager.swiftindex 6ec1afc..67fdb1d 100644--- a/Sources/Cra/Services/BrowserManager.swift+++ b/Sources/Cra/Services/BrowserManager.swift@@ -81,6 +81,10 @@ protocol BrowserManagerDelegate: AnyObject {/// Arc's Peek: a link the user clicked (or Shift-clicked) in `tabID`, whose page is at/// `pageURL`. Return true when it opens in a Peek instead.func browserManagerOpensPeek(url: String, fromTab tabID: UUID, pageURL: String, shiftClick: Bool, newTab: Bool) -> Bool+ /// The page's context menu: Open Link in New Window, Little Window or Incognito Window.+ func browserManagerOpenLink(_ url: String, in kind: CraLinkWindow, space: UUID?, fromIncognito: Bool)+ /// The page's context menu on an image: Capture Image… (page points from the top left).+ func browserManagerCaptureImage(at point: NSPoint, tabID: UUID)}/// Creates, shows, hides and tears down CEF browsers inside a container view.@@ -1131,6 +1135,16 @@ final class BrowserManager: NSObject, @preconcurrency CraBrowserDelegate {openLinkTab(url, from: tabID(of: browser), inBackground: background)}+ func browser(_ browser: CraBrowser, requestsCaptureOfImageAt point: NSPoint) {+ guard let id = tabID(of: browser) else { return }+ delegate?.browserManagerCaptureImage(at: point, tabID: id)+ }++ func browser(_ browser: CraBrowser, requestsWindowWithURL url: String, kind: CraLinkWindow) {+ guard let id = tabID(of: browser) else { return }+ delegate?.browserManagerOpenLink(url, in: kind, space: store.spaceID(ofItem: id), fromIncognito: browser.isIncognito)+ }+/// A link that asks for a new tab, from `source`'s page or from a Peek over it (#202): a/// Today tab in `source`'s space, else the window's.func openLinkTab(_ url: String, from source: UUID?, inBackground background: Bool) {diff --git a/Sources/Cra/UI/Windows/CaptureOverlay.swift b/Sources/Cra/UI/Windows/CaptureOverlay.swiftindex dd1f6eb..cb5a0b4 100644--- a/Sources/Cra/UI/Windows/CaptureOverlay.swift+++ b/Sources/Cra/UI/Windows/CaptureOverlay.swift@@ -48,6 +48,9 @@ final class CaptureOverlay {func close() { finish(nil, nil) }+ /// Capture Image…: takes the image at `rect` (page points) straight away (CaptureView.lift).+ func lift(_ rect: CGRect) { view.lift(rect) }+private func finish(_ action: Action?, _ png: Data?) {guard !closed else { return }closed = true@@ -126,6 +129,9 @@ final class CaptureView: NSView {private let ring = CAShapeLayer()private let ringShadow = CAShapeLayer()private let ringShadowMask = CAShapeLayer()+ /// Capture Image…: the image, moved off its place on the page to the middle (`lift`).+ private let liftLayer = CALayer()+ private var lifted = falseprivate let bubble = CaptureBubble()private var actionsMenu: CaptureMenu?@@ -192,6 +198,12 @@ final class CaptureView: NSView {ring.fillColor = CaptureStyle.ring.cgColorring.fillRule = .evenOddring.opacity = 0+ liftLayer.isHidden = true+ liftLayer.contentsGravity = .resize+ liftLayer.contentsScale = scale+ liftLayer.cornerRadius = ContentCapture.lensInnerRadius+ liftLayer.masksToBounds = true+ root.addSublayer(liftLayer)root.addSublayer(ringShadow)root.addSublayer(ring)CATransaction.commit()@@ -281,6 +293,11 @@ final class CaptureView: NSView {if let actionsMenu, actionsMenu.frame.contains(p) { return }// A press beside the capture starts over, from this press.dropMenu()+ if lifted {+ lifted = false+ liftLayer.isHidden = true+ snapLens(to: nil)+ }mode = .selectingbubble.show(true)}@@ -463,6 +480,36 @@ final class CaptureView: NSView {NSCursor.arrow.set()}+ /// Capture Image… (a page's context menu, Arc's): `rect`, an image on the page, is taken at once+ /// and springs from its place to the middle of the grey page, the menu beside it+ /// (ContentCapture.liftedLayout). Its place on the page stays grey.+ func lift(_ rect: CGRect) {+ let px = ContentCapture.pixelRect(for: rect, pageSize: bounds.size, imageSize: CGSize(width: shot.width, height: shot.height))+ guard let cropped = shot.cropping(to: px), let png = Self.png(cropped) else { finish?(nil, nil); return }+ let menu = makeMenu(png: png)+ let layout = ContentCapture.liftedLayout(image: rect.size, menu: menu.intrinsicContentSize, in: bounds)+ mode = .captured(layout.image)+ element = nil+ pressedOnElement = nil+ lifted = true+ CATransaction.begin()+ CATransaction.setDisableActions(true)+ liftLayer.contents = cropped+ liftLayer.isHidden = false+ CATransaction.commit()+ snapLens(to: rect)+ lensTarget = layout.image+ run()+ CaptureSound.play()+ bubble.show(false)+ dropMenu()+ menu.frame = layout.menu+ addSubview(menu)+ menu.appear()+ actionsMenu = menu+ NSCursor.arrow.set()+ }+static func png(_ image: CGImage) -> Data? {let data = NSMutableData()guard let dest = CGImageDestinationCreateWithData(data, UTType.png.identifier as CFString, 1, nil) else { return nil }@@ -470,9 +517,8 @@ final class CaptureView: NSView {return CGImageDestinationFinalize(dest) ? data as Data : nil}- private func showMenu(png: Data) {- dropMenu()- let m = CaptureMenu { [weak self] action in+ private func makeMenu(png: Data) -> CaptureMenu {+ CaptureMenu { [weak self] action inguard let self else { return }self.isSettled = falseif action == .retake {@@ -481,6 +527,11 @@ final class CaptureView: NSView {self.finish?(action, png)}}+ }++ private func showMenu(png: Data) {+ dropMenu()+ let m = makeMenu(png: png)let lensFrame = ContentCapture.lensFrame(around: lens ?? .zero)m.frame = ContentCapture.menuFrame(size: m.intrinsicContentSize, besideLens: lensFrame, in: bounds)addSubview(m)@@ -610,6 +661,8 @@ final class CaptureView: NSView {ring.opacity = Float(lensAlpha)ringShadow.opacity = Float(lensAlpha)greyFull.opacity = Float(1 - lensAlpha)+ // A lifted image covers the hole exactly: the page under it stays out of sight.+ if lifted { liftLayer.frame = r }} else {holeMask.path = fullring.opacity = 0diff --git a/Sources/Cra/UI/Windows/LittleWindowController.swift b/Sources/Cra/UI/Windows/LittleWindowController.swiftindex 8305fec..f278de4 100644--- a/Sources/Cra/UI/Windows/LittleWindowController.swift+++ b/Sources/Cra/UI/Windows/LittleWindowController.swift@@ -1120,6 +1120,10 @@ final class LittleWindowController: NSWindowController, NSWindowDelegate, @precoif background { window?.makeKeyAndOrderFront(nil) }}+ func browser(_ browser: CraBrowser, requestsWindowWithURL url: String, kind: CraLinkWindow) {+ app.openLink(url, in: kind, space: state.targetSpaceID, fromIncognito: browser.isIncognito)+ }+/// Arc 1.171 (#202): a link from a Peek that asks for a new tab is a Today tab in the space,/// placed as a link from the tab under the Peek would be, and the Peek closes for it. A/// background one (⌘-click) leaves the Peek open, as the click left the page in a tab.diff --git a/Sources/Cra/UI/Windows/MainWindowController.swift b/Sources/Cra/UI/Windows/MainWindowController.swiftindex 9de8f4b..1791e23 100644--- a/Sources/Cra/UI/Windows/MainWindowController.swift+++ b/Sources/Cra/UI/Windows/MainWindowController.swift@@ -1466,6 +1466,15 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserMreturn true}+ func browserManagerCaptureImage(at point: NSPoint, tabID: UUID) {+ guard tabID == browsers.visibleTabID else { return }+ capturePage(liftImageAt: point)+ }++ func browserManagerOpenLink(_ url: String, in kind: CraLinkWindow, space: UUID?, fromIncognito: Bool) {+ app.openLink(url, in: kind, space: space, fromIncognito: fromIncognito)+ }+/// The area Arc's Peek is centred on (window coordinates): right of the sidebar to the/// window's edge, top to bottom; the whole window with the sidebar out of the way.private func peekAreaInWindow() -> NSRect {@@ -1691,12 +1700,38 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserM/// pointer and a drag a rectangle, then a menu copies, saves or sends it (CaptureOverlay)./// Chromium draws the picture it works on (Page.captureScreenshot), so it holds the page/// whatever display the window is on and whatever is in front of it.- func capturePage() {- if let open = captureOverlay, open.isOpen { open.close(); return }+ /// `liftImageAt` (Capture Image… on an image, page points from its top left): the image there+ /// is taken at once and moves to the middle of the page with the menu beside it, as in Arc.+ func capturePage(liftImageAt point: NSPoint? = nil) {+ if let open = captureOverlay, open.isOpen {+ open.close()+ if point == nil { return }+ }guard !captureStarting, let rt = browsers.visibleRuntime, rt.browser.isCreated, !rt.browser.isClosed,pageScreenRect(rt) != nil else { return }let b = rt.browsercaptureStarting = true+ guard let point else { takeCapture(b, liftImageAt: nil); return }+ // Where the image is first: the picture is taken with the menu already closed.+ let scale = window?.backingScaleFactor ?? 2+ let script = ContentCapture.imageRectScript(x: point.x * scale, y: point.y * scale)+ let params = (try? JSONSerialization.data(withJSONObject: ["expression": script, "returnByValue": true]))+ .flatMap { String(data: $0, encoding: .utf8) } ?? "{}"+ b.evaluate(inIsolatedWorld: PageScript.world, params: params) { [weak self, weak b] result, _ in+ MainActor.assumeIsolated {+ guard let self, let b else { return }+ let value = result.flatMap { try? JSONSerialization.jsonObject(with: Data($0.utf8)) as? [String: Any] }+ .flatMap { ($0["result"] as? [String: Any])?["value"] as? [String: Any] }+ guard let value, let rt = self.browsers.visibleRuntime, rt.browser === b, let page = self.pageScreenRect(rt),+ let rect = ContentCapture.elementRect(fromPicker: value, scale: scale, pageBounds: CGRect(origin: .zero, size: page.size))+ else { self.captureStarting = false; return }+ self.takeCapture(b, liftImageAt: rect)+ }+ }+ }++ private func takeCapture(_ b: CraBrowser, liftImageAt image: CGRect?) {+ let lift = imageb.sendDevToolsMethod("Page.captureScreenshot", params: #"{"format":"png","captureBeyondViewport":false}"#) { [weak self, weak b] shot, error inMainActor.assumeIsolated {guard let self else { return }@@ -1711,6 +1746,7 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserMlet overlay = CaptureOverlay(over: window, pageRect: rect, shot: image, browser: b)overlay.onFinish = { [weak self] action, png in self?.captureFinished(action, png) }self.captureOverlay = overlay+ if let lift { overlay.lift(lift) }}}}diff --git a/Sources/CraCEF/CraCEF.mm b/Sources/CraCEF/CraCEF.mmindex dd2082b..aa6d78e 100644--- a/Sources/CraCEF/CraCEF.mm+++ b/Sources/CraCEF/CraCEF.mm@@ -87,8 +87,6 @@ static CefString CefStringFromNS(NSString* s) {return CefString(std::string(s.UTF8String ?: ""));}-/// Page context menus shown by Cra (RunContextMenu) instead of Chrome.-static BOOL g_ownContextMenus = NO;// The two "open link" items on a page's context menu, from CraCore's LinkMenu (GitHub #183).static NSArray<NSString*>* g_linkMenuTitles = @[@"Open Link in New Tab", @"Open Link in Background Tab"];static NSArray<NSNumber*>* g_linkMenuBackground = @[@NO, @YES];@@ -97,58 +95,31 @@ static NSArray<NSNumber*>* g_linkMenuBackground = @[@NO, @YES];/// (the page's world, then Cra's isolated world).static NSArray<NSString*>* g_documentStartParams = nil;-/// The command picked from a context menu Cra shows; -1 while none is.-@interface CraMenuPick : NSObject-@property (nonatomic) int commandID;-- (void)choose:(NSMenuItem*)item;-@end--@implementation CraMenuPick-- (instancetype)init {- if ((self = [super init])) _commandID = -1;- return self;-}-- (void)choose:(NSMenuItem*)item { self.commandID = (int)item.tag; }-@end--/// Chrome's labels mark mnemonics with "&" ("&&" is a literal ampersand).-static NSString* CraMenuLabel(CefRefPtr<CefMenuModel> model, size_t i) {- NSString* s = NSStringFromCef(model->GetLabelAt(i));- s = [s stringByReplacingOccurrencesOfString:@"&&" withString:@"\u0001"];- s = [s stringByReplacingOccurrencesOfString:@"&" withString:@""];- return [s stringByReplacingOccurrencesOfString:@"\u0001" withString:@"&"];-}--static NSMenu* CraMenuFromModel(CefRefPtr<CefMenuModel> model, CraMenuPick* pick) {- NSMenu* menu = [[NSMenu alloc] initWithTitle:@""];- menu.autoenablesItems = NO;- for (size_t i = 0; i < model->GetCount(); i++) {- cef_menu_item_type_t type = model->GetTypeAt(i);- if (type == MENUITEMTYPE_SEPARATOR) {- if (menu.numberOfItems > 0 && !menu.itemArray.lastObject.isSeparatorItem) [menu addItem:[NSMenuItem separatorItem]];- continue;- }- if (type == MENUITEMTYPE_NONE) continue;- NSMenuItem* item = [[NSMenuItem alloc] initWithTitle:CraMenuLabel(model, i) action:nil keyEquivalent:@""];- if (type == MENUITEMTYPE_SUBMENU) {- item.submenu = CraMenuFromModel(model->GetSubMenuAt(i), pick);+/// Removes separators a removed item left at either end or next to another one. Hidden items+/// don't count: Chrome's model keeps some it doesn't show.+static void CraTidySeparators(CefRefPtr<CefMenuModel> model) {+ bool separatorAfter = true; // walking back from the end, which counts as one+ for (size_t i = model->GetCount(); i-- > 0;) {+ if (model->GetTypeAt(i) != MENUITEMTYPE_SEPARATOR) {+ if (model->IsVisibleAt(i)) separatorAfter = false;+ } else if (separatorAfter) {+ model->RemoveAt(i);} else {- item.action = @selector(choose:);- item.target = pick;- item.tag = model->GetCommandIdAt(i);- if (model->IsCheckedAt(i)) item.state = NSControlStateValueOn;+ separatorAfter = true;}- item.enabled = model->IsEnabledAt(i);- item.hidden = !model->IsVisibleAt(i);- [menu addItem:item];}- while (menu.itemArray.lastObject.isSeparatorItem) [menu removeItem:menu.itemArray.lastObject];- return menu;+ for (size_t i = 0; i < model->GetCount();) {+ if (model->GetTypeAt(i) == MENUITEMTYPE_SEPARATOR) model->RemoveAt(i);+ else if (model->IsVisibleAt(i)) break;+ else i++;+ }}enum CraMenuCommand {kMenuOpenLinkFirst = MENU_ID_USER_FIRST + 1,kMenuOpenLinkSecond,+ kMenuOpenLinkLittleWindow,+ kMenuCaptureImage,kMenuCopyLink,kMenuInspectElement,kMenuOpenImageInNewTab,@@ -1687,34 +1658,72 @@ public:// Context menu --------------------------------------------------------- // Embedded pages (EmbeddedPages.swift): Chrome shows the menu through the views widget that- // owns the page's view, found through the view's window, which is now Cra's: it showed- // nothing. Cra shows the menu itself and hands the pick back.- bool RunContextMenu(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame,- CefRefPtr<CefContextMenuParams> params, CefRefPtr<CefMenuModel> model,- CefRefPtr<CefRunContextMenuCallback> callback) override {- if (!g_ownContextMenus || model->GetCount() == 0) return false;- CraMenuPick* pick = [CraMenuPick new];- NSMenu* menu = CraMenuFromModel(model, pick);- NSPoint at = [NSEvent mouseLocation];- CefRefPtr<CefRunContextMenuCallback> done = callback;- dispatch_async(dispatch_get_main_queue(), ^{- [menu popUpMenuPositioningItem:nil atLocation:at inView:nil];- if (pick.commandID >= 0) done->Continue(pick.commandID, EVENTFLAG_NONE);- else done->Cancel();- });- return true;- }-+ // Chrome-style pages get Chrome's own context menu, shown by Chrome as in Chrome and Arc:+ // extension icons, Look Up, Speech, Services, Writing Tools and AutoFill come with it. A page+ // embedded in Cra's window (EmbeddedPages.swift) got none until+ // cef-patches/context-menu-embedded-view.patch, so Cra drew its own from the model then.+ // Alloy-style pages (Chrome engine off) get CEF's short menu with Cra's few items added.void OnBeforeContextMenu(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame,CefRefPtr<CefContextMenuParams> params, CefRefPtr<CefMenuModel> model) override {+ if (browser->GetHost()->GetRuntimeStyle() == CEF_RUNTIME_STYLE_CHROME) MakeArcMenu(params, model);+ else AddAlloyItems(params, model);+ }++ // Arc's page menus are Chrome's with a few changes (Arc 1.172, 6 Nov 2026):+ // - link: Open Link in New Tab, New Window, Little Arc, Incognito Window. Cra's New Tab item+ // follows the background-links setting, with the other kind of tab under it (LinkMenu, #183).+ // - page: no QR code item; Translate sits with Save As…, Print… and Cast….+ // - selected text: Search <engine> for "…" comes before Copy (not with a link).+ // - image: Capture Image… after Save Image As…, and Search <engine> for Image where Chromium+ // 156 has Google Lens's "Search image with <engine>"; video: no frame search.+ void MakeArcMenu(CefRefPtr<CefContextMenuParams> params, CefRefPtr<CefMenuModel> model) {+ int newTab = model->GetIndexOf(IDC_CONTENT_CONTEXT_OPENLINKNEWTAB);+ if (newTab >= 0) {+ model->RemoveAt(newTab);+ model->InsertItemAt(newTab, kMenuOpenLinkFirst, g_linkMenuTitles[0].UTF8String);+ model->InsertItemAt(newTab + 1, kMenuOpenLinkSecond, g_linkMenuTitles[1].UTF8String);+ }+ // Little Windows load in the normal profile: none from an incognito page.+ CraBrowser* o = owner_;+ int newWindow = model->GetIndexOf(IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW);+ if (newWindow >= 0 && !o.isIncognito) model->InsertItemAt(newWindow + 1, kMenuOpenLinkLittleWindow, "Open Link in Little Window");+ for (int id : {IDC_CONTENT_CONTEXT_GENERATE_QR_CODE, IDC_CONTENT_CONTEXT_OPENLINKINPROFILE,+ IDC_CONTENT_CONTEXT_OPENLINKSPLITVIEW, IDC_CONTENT_CONTEXT_OPENLINKBOOKMARKAPP,+ IDC_CONTENT_CONTEXT_SEARCHLENSFORVIDEOFRAME, IDC_CONTENT_CONTEXT_SEARCHWEBFORVIDEOFRAME}) {+ while (model->Remove(id)) {}+ }+ CraTidySeparators(model); // the QR code item's group is gone: one separator before Translate+ int translate = model->GetIndexOf(IDC_CONTENT_CONTEXT_TRANSLATE);+ int before = translate - 1;+ while (before >= 0 && model->GetTypeAt(before) != MENUITEMTYPE_SEPARATOR && !model->IsVisibleAt(before)) before--;+ if (translate > 0 && before >= 0 && model->GetTypeAt(before) == MENUITEMTYPE_SEPARATOR) model->RemoveAt(before);+ int search = model->GetIndexOf(IDC_CONTENT_CONTEXT_SEARCHWEBFOR), copy = model->GetIndexOf(IDC_CONTENT_CONTEXT_COPY);+ if (params->GetLinkUrl().empty() && !params->IsEditable() && search > copy && copy >= 0) {+ CefString label = model->GetLabelAt(search);+ model->RemoveAt(search);+ model->InsertItemAt(copy, IDC_CONTENT_CONTEXT_SEARCHWEBFOR, label);+ }+ int lens = model->GetIndexOf(IDC_CONTENT_CONTEXT_SEARCHLENSFORIMAGE);+ if (lens >= 0) {+ // "Search image with Google" → "Search Google for Image", Chrome's own item for it.+ std::string label = model->GetLabelAt(lens).ToString(), with = "Search image with ";+ std::string engine = label.rfind(with, 0) == 0 ? label.substr(with.size()) : "Google";+ model->RemoveAt(lens);+ model->InsertItemAt(lens, IDC_CONTENT_CONTEXT_SEARCHWEBFORIMAGE, "Search " + engine + " for Image");+ }+ int saveImage = model->GetIndexOf(IDC_CONTENT_CONTEXT_SAVEIMAGEAS);+ if (saveImage >= 0 && params->GetMediaType() == CM_MEDIATYPE_IMAGE &&+ [o.delegate respondsToSelector:@selector(browser:requestsCaptureOfImageAt:)]) {+ model->InsertItemAt(saveImage + 1, kMenuCaptureImage, "Capture Image…");+ }+ CraTidySeparators(model);+ }++ static void AddAlloyItems(CefRefPtr<CefContextMenuParams> params, CefRefPtr<CefMenuModel> model) {size_t index = 0;if (!params->GetLinkUrl().empty()) {model->InsertItemAt(index++, kMenuOpenLinkFirst, g_linkMenuTitles[0].UTF8String);model->InsertItemAt(index++, kMenuOpenLinkSecond, g_linkMenuTitles[1].UTF8String);- // Chrome-style menus carry Chrome's own "Open Link in New Tab" further down, which- // always opens in the background: one item by that name, the one the setting rules (#183).- model->Remove(IDC_CONTENT_CONTEXT_OPENLINKNEWTAB);model->InsertItemAt(index++, kMenuCopyLink, "Copy Link");model->InsertSeparatorAt(index++);}@@ -1723,9 +1732,7 @@ public:model->InsertItemAt(index++, kMenuCopyImageURL, "Copy Image Address");model->InsertSeparatorAt(index++);}- // Chrome-style menus already carry Chrome's own "Picture in picture" item.- if (params->GetMediaType() == CM_MEDIATYPE_VIDEO && (params->GetMediaStateFlags() & CM_MEDIAFLAG_CAN_PICTURE_IN_PICTURE) &&- model->GetIndexOf(IDC_CONTENT_CONTEXT_PICTUREINPICTURE) < 0) {+ if (params->GetMediaType() == CM_MEDIATYPE_VIDEO && (params->GetMediaStateFlags() & CM_MEDIAFLAG_CAN_PICTURE_IN_PICTURE)) {bool inPiP = params->GetMediaStateFlags() & CM_MEDIAFLAG_PICTURE_IN_PICTURE;model->InsertItemAt(index++, kMenuPictureInPicture, inPiP ? "Exit Picture in Picture" : "Picture in Picture");model->InsertSeparatorAt(index++);@@ -1757,6 +1764,26 @@ public:[pb setString:s forType:NSPasteboardTypeString];return true;}+ // Chrome's New Window and Incognito Window items would open Chrome windows: Cra's own.+ case IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW:+ case IDC_CONTENT_CONTEXT_OPENLINKOFFTHERECORD:+ case kMenuOpenLinkLittleWindow: {+ NSString* url = NSStringFromCef(params->GetLinkUrl());+ if (![o.delegate respondsToSelector:@selector(browser:requestsWindowWithURL:kind:)]) {+ [o.delegate browser:o requestsNewTabWithURL:url inBackground:NO];+ return true;+ }+ CraLinkWindow kind = command_id == kMenuOpenLinkLittleWindow ? CraLinkWindowLittle+ : command_id == IDC_CONTENT_CONTEXT_OPENLINKOFFTHERECORD ? CraLinkWindowIncognito : CraLinkWindowNew;+ [o.delegate browser:o requestsWindowWithURL:url kind:kind];+ return true;+ }+ case kMenuCaptureImage:+ if ([o.delegate respondsToSelector:@selector(browser:requestsCaptureOfImageAt:)])+ [o.delegate browser:o requestsCaptureOfImageAt:NSMakePoint(params->GetXCoord(), params->GetYCoord())];+ return true;+ // Chrome's Inspect: Cra's DevTools (docked in the card, DevToolsToggle) on that element.+ case IDC_CONTENT_CONTEXT_INSPECTELEMENT:case kMenuInspectElement:[o showDevToolsInspectingPoint:NSMakePoint(params->GetXCoord(), params->GetYCoord())];return true;@@ -2615,7 +2642,6 @@ static void MarkProfileExitedCleanly(NSString* profileDir) {@implementation CraCEFRuntime+ (void)setChromeHosting:(BOOL)enabled { g_chromeHosting = enabled; }-+ (void)setOwnContextMenus:(BOOL)enabled { g_ownContextMenus = enabled; }+ (void)setLinkMenuTitles:(NSArray<NSString*>*)titles opensInBackground:(NSArray<NSNumber*>*)background {if (titles.count != 2 || background.count != 2) return;g_linkMenuTitles = [titles copy];diff --git a/Sources/CraCEF/include/CraCEF.h b/Sources/CraCEF/include/CraCEF.hindex b9c0c08..388dae4 100644--- a/Sources/CraCEF/include/CraCEF.h+++ b/Sources/CraCEF/include/CraCEF.h@@ -13,6 +13,13 @@ typedef NS_ENUM(NSInteger, CraDownloadState) {CraDownloadStateInterrupted = 3,};+/// Where a page's context menu opens a link that isn't for a tab.+typedef NS_ENUM(NSInteger, CraLinkWindow) {+ CraLinkWindowNew = 0,+ CraLinkWindowIncognito = 1,+ CraLinkWindowLittle = 2,+};+@interface CraDownloadInfo : NSObject@property (nonatomic) uint32_t identifier;@property (nonatomic, copy) NSString *url;@@ -81,6 +88,11 @@ typedef NS_ENUM(NSInteger, CraDownloadState) {- (void)browserDidReceiveFocus:(CraBrowser *)browser;- (void)browserDidClose:(CraBrowser *)browser;@optional+/// The page's context menu: Open Link in New Window, Little Window or Incognito Window.+- (void)browser:(CraBrowser *)browser requestsWindowWithURL:(NSString *)url kind:(CraLinkWindow)kind;+/// The page's context menu on an image: Capture Image… at `point` (page points from the top+/// left). Without it the menu has no such item.+- (void)browser:(CraBrowser *)browser requestsCaptureOfImageAt:(NSPoint)point;/// A video of this page entered or left Chromium's Picture in Picture window/// (whether the page, the user or Cra asked for it).- (void)browser:(CraBrowser *)browser didChangePictureInPicture:(BOOL)active;@@ -239,8 +251,6 @@ typedef NS_ENUM(NSInteger, CraDownloadState) {/// DevTools) instead of embedded Alloy views. Set before any browser exists.+ (void)setChromeHosting:(BOOL)enabled;+ (BOOL)chromeHosting;-/// Page context menus are shown by Cra, not Chrome (pages embedded in their cards).-+ (void)setOwnContextMenus:(BOOL)enabled;/// The two "open link" items at the top of a page's context menu, in order: their titles and/// whether each opens its tab in the background. Exactly two; read when a menu opens.+ (void)setLinkMenuTitles:(NSArray<NSString *> *)titles opensInBackground:(NSArray<NSNumber *> *)background;diff --git a/Tests/BrowserManagerLifecycleTests.swift b/Tests/BrowserManagerLifecycleTests.swiftindex 0308329..d50b992 100644--- a/Tests/BrowserManagerLifecycleTests.swift+++ b/Tests/BrowserManagerLifecycleTests.swift@@ -40,6 +40,19 @@ enum BrowserManagerLifecycleTests {expect(observer.activatedTabs == [id, id] && observer.activatedByPage == [false, true],"a page's own focus request (a notification click) arrives marked as the page's")+ // The page's context menu: Open Link in New Window / Little Window / Incognito Window and+ // Capture Image… go to the window, with the tab's space; a closed page's requests don't.+ manager.browser(replacement.browser, requestsWindowWithURL: "https://example.test/link", kind: .little)+ manager.browser(old.browser, requestsWindowWithURL: "https://example.test/stale", kind: .new)+ expect(observer.openedLinks.map(\.url) == ["https://example.test/link"] && observer.openedLinks.first?.kind == .little+ && observer.openedLinks.first?.space == store.spaceID(ofItem: id) && observer.openedLinks.first?.incognito == false,+ "Open Link in Little Window reaches the window with the tab's space")+ manager.browser(replacement.browser, requestsCaptureOfImageAt: NSPoint(x: 12, y: 34))+ manager.browser(old.browser, requestsCaptureOfImageAt: NSPoint(x: 1, y: 1))+ expect(observer.capturedImages.count == 1 && observer.capturedImages.first?.tab == id+ && observer.capturedImages.first?.point == NSPoint(x: 12, y: 34),+ "Capture Image… reaches the window for the live page's tab only")+let retainedID = store.createTab(url: "https://example.test/retained").idweak var retainedBrowser = manager.ensureRuntime(for: retainedID)?.browsermanager.unload(retainedID)@@ -1024,4 +1037,10 @@ private final class Observer: BrowserManagerDelegate {activatedByPage.append(byPage)}func browserManagerOpensPeek(url: String, fromTab tabID: UUID, pageURL: String, shiftClick: Bool, newTab: Bool) -> Bool { false }+ var openedLinks: [(url: String, kind: CraLinkWindow, space: UUID?, incognito: Bool)] = []+ var capturedImages: [(point: NSPoint, tab: UUID)] = []+ func browserManagerOpenLink(_ url: String, in kind: CraLinkWindow, space: UUID?, fromIncognito: Bool) {+ openedLinks.append((url, kind, space, fromIncognito))+ }+ func browserManagerCaptureImage(at point: NSPoint, tabID: UUID) { capturedImages.append((point, tabID)) }}diff --git a/Tests/BrowserManagerSupport/CraCEF.swift b/Tests/BrowserManagerSupport/CraCEF.swiftindex 066fb35..f941b33 100644--- a/Tests/BrowserManagerSupport/CraCEF.swift+++ b/Tests/BrowserManagerSupport/CraCEF.swift@@ -11,6 +11,8 @@ public protocol CraBrowserDelegate: AnyObject {public final class CraDownloadInfo {}+@objc public enum CraLinkWindow: Int { case new, incognito, little }+/// `open`: the app subclasses it (WebKitBrowser, faked in AppServices.swift).@MainActoropen class CraBrowser {diff --git a/docs/arc-reverse-engineering.md b/docs/arc-reverse-engineering.mdindex 75681c7..5ebff5d 100644--- a/docs/arc-reverse-engineering.md+++ b/docs/arc-reverse-engineering.md@@ -3284,3 +3284,29 @@ Read from the arm64 slice's Swift field metadata (`__swift5_fieldmd`, case and fselection of directory for file downloads"). [?] The menu's own labels aren't in the strings. Cra (#190):AppSettings.downloadLocations per profile (folder or ask), a Downloads card under Profiles with the folder,"Ask Where to Save Each File" and "Other…"; save panels queue one at a time as sheets on Cra's window.++## Page context menus (Arc 1.172, 6 Nov 2026, Victor's Arc, Little Arc at 2x, AX menu dumps)++- [O] Arc shows Chromium's own Mac menu (MenuControllerCocoa): extension items carry the extension's icon (one+ item: its own title; several: a submenu named after the extension), and AppKit adds Look Up, Speech, Writing+ Tools, Services and AutoFill as it does for Chrome. System items are British ("Summarise"): Arc's bundle has+ en-GB.lproj and Victor's macOS is en-DK. Chromium items are Chrome's, with these changes:+- [O] Page: Back, Forward, Reload | Save As…, Print…, Cast…, Translate to <language> | extensions | View Page+ Source, Inspect. No "Create QR code for this page", no separate Inspect Element.+- [O] Link: Open Link in New Tab, Open Link in New Window, Open Link in Little Arc, Open Link in Incognito Window |+ Save Link As…, Copy Link Address | Copy, Copy link to highlight, Search Google for "…", Print… (the link text is+ selected) | extensions | Inspect.+- [O] Selected text: Look up '…' | Search Google for "…", Copy, Copy link to highlight, Print… (search first).+- [O] Image: Open Image in New Tab, Save Image As…, Capture Image…, Copy Image, Copy Image Address, Search Google+ for Image. Video: Loop, Show all controls | Open Video in New Tab, Save Video Frame As…, Save Video As…, Copy+ Video Frame, Copy Video Address, Picture-in-Picture, Cast… (no frame search). Text field: Emoji and symbols |+ Select password | Undo, Redo | Cut, Copy, Paste, Paste and Match Style, Select All | Language Settings, Writing+ direction ▸.+- [O] Capture Image… greys the page at once, and the image (its size on the page) moves to the middle in the 4 pt+ #161C2F ring with no clearance, the capture menu 10 pt right of the ring, top level with it; its own place stays+ grey. On a 1688 × 963 pt page a 160 × 100 pt image's ring ran 623.5…791.5 pt, the 273 pt menu 801.5…1074.5.+- Cra: Chromium 156 shows the same menu once cef-patches/context-menu-embedded-view.patch lets it show in Cra's+ window. CraCEF's MakeArcMenu drops the QR code and video-frame search items, joins Translate to Save As…'s group,+ puts Search first for a selection, turns Lens's "Search image with Google" into "Search Google for Image", adds+ Open Link in Little Window and Capture Image… (ContentCapture.liftedLayout), and opens New Window / Incognito /+ Inspect in Cra's own windows and DevTools. Kept on purpose: Open Link in Background Tab under New Tab (#183).diff --git a/resources/Info.plist b/resources/Info.plistindex 058dacc..9e27480 100644--- a/resources/Info.plist+++ b/resources/Info.plist@@ -4,6 +4,13 @@<dict><key>CFBundleDevelopmentRegion</key><string>en</string>+ <!-- British English for the system's own menu items (Summarise, Colours) where macOS+ prefers it, as in Arc; Cra's own words stay as they are. -->+ <key>CFBundleLocalizations</key>+ <array>+ <string>en</string>+ <string>en-GB</string>+ </array><key>CFBundleExecutable</key><string>Cra</string><key>CFBundleIdentifier</key>diff --git a/scripts/cef-patches/context-menu-embedded-view.patch b/scripts/cef-patches/context-menu-embedded-view.patchnew file mode 100644index 0000000..1874b3c--- /dev/null+++ b/scripts/cef-patches/context-menu-embedded-view.patch@@ -0,0 +1,51 @@+Cra: show Chrome's own page context menu when the page's view sits in a window+that is no views widget (Cra's embedded pages), instead of showing nothing.+Gives Cra the same menu as Chrome and Arc: extension icons, Look Up, Speech,+Services, Writing Tools and AutoFill.++--- a/chrome/browser/ui/cocoa/renderer_context_menu/render_view_context_menu_mac_cocoa.mm 2026-11-06 11:20:36++++ b/chrome/browser/ui/cocoa/renderer_context_menu/render_view_context_menu_mac_cocoa.mm 2026-11-06 11:20:36+@@ -82,12 +82,29 @@+ views::Widget* widget = views::Widget::GetTopLevelWidgetForNativeView(+ source_web_contents_->GetNativeView());++- if (!widget || headless::IsHeadlessMode()) {++ if (headless::IsHeadlessMode()) {+ return;+ }+++ // Cra: the embedder can move the page's view into a window of its own,++ // which is no views widget. Show the menu there all the same (Chrome's++ // native menu, with extension icons and the system's items), with fixed++ // badge colours, instead of not at all.++ remote_cocoa::mojom::MenuControllerParamsPtr menu_params;++ if (widget) {++ menu_params = MenuControllerParamsForWidget(widget);++ } else {++ menu_params = remote_cocoa::mojom::MenuControllerParams::New();++ menu_params->badge_color = SkColorSetRGB(0x0B, 0x57, 0xD0);++ menu_params->badge_text_color = SK_ColorWHITE;++ menu_params->badge_horizontal_margin = 4;++ menu_params->badge_internal_padding = 4;++ menu_params->badge_min_height = 14;++ menu_params->badge_radius = 4;++ menu_params->iph_dot_color = SkColorSetRGB(0x0B, 0x57, 0xD0);++ }+ menu_controller_delegate_ = [[MenuControllerCocoaDelegateImpl alloc]+- initWithParams:MenuControllerParamsForWidget(widget)];++ initWithParams:std::move(menu_params)];+ menu_controller_ =+ [[MenuControllerCocoa alloc] initWithModel:&menu_model_+ isContextMenu:YES+@@ -101,7 +118,10 @@++ ui::ShowContextMenu(menu_controller_.menu, clickEvent, parent_view_,+ /*allow_nested_tasks=*/true,+- views::ElementTrackerViews::GetContextForWidget(widget));++ widget++ ? views::ElementTrackerViews::GetContextForWidget(++ widget)++ : ui::ElementContext());+ }++ bool RenderViewContextMenuMacCocoa::IsRunning() {diff --git a/scripts/fetch-cef.sh b/scripts/fetch-cef.shindex 62661d8..11fe17a 100755--- a/scripts/fetch-cef.sh+++ b/scripts/fetch-cef.sh@@ -13,7 +13,7 @@ CEF_VERSION="${CEF_VERSION:-156.0.15+gcf671c0+chromium-156.0.8078.80}"ARCH="${CEF_ARCH:-macosarm64}"NAME="cef_binary_${CEF_VERSION}_${ARCH}_minimal"# Bump the suffix (codecs2, …) when the build changes but CEF_VERSION does not.-CEF_RELEASE="${CEF_RELEASE:-cef-${CEF_VERSION%%+*}-codecs14}"+CEF_RELEASE="${CEF_RELEASE:-cef-${CEF_VERSION%%+*}-codecs15}"URL="${CEF_URL:-https://github.com/VictorKildahl/cra/releases/download/${CEF_RELEASE}/cef_binary_${ARCH}_minimal.tar.bz2}"mkdir -p vendor