diff --git a/Documentation/Implementation-Handoff.md b/Documentation/Implementation-Handoff.md index 4a908ef..aa99ffd 100644 --- a/Documentation/Implementation-Handoff.md +++ b/Documentation/Implementation-Handoff.md @@ -63,6 +63,21 @@ The build guard supports macOS `/bin/bash` 3.2. When reusing an engine build fro checkout, compare source bytes and report provenance warnings. Never repoint copied submodule `.git` metadata. Do not write shared CMake/generated/lib outputs from a different worktree. Check available disk space before cold engine builds. + +Setting up a worktree means initializing its own submodule clone — `git worktree add` records the +pin but leaves `Extern/ladybird/` empty (`Documentation/Traps.md`): + + git worktree add ../ -b + cd ../ + git -c protocol.file.allow=always submodule update --init Extern/ladybird + git submodule status # no leading '-' means it is populated + git -C Extern/ladybird rev-parse --show-toplevel # must print THIS worktree + ./Scripts/check-layers.sh + +To work on the fork too, `git -C Extern/ladybird checkout ava-port` — a detached pin will not build +the fork's branch changes. Then cold-build `Extern/ladybird/Build/release`; history is hardlinked +across worktrees, the build tree is not. + Isolated temporary shim/probe output may reuse audited cached dependencies read-only, but record exact commands and prove the new shim is the one loaded. Never claim a dry-run built/tested the code. diff --git a/Documentation/README.md b/Documentation/README.md index 49c65e8..7d747b7 100644 --- a/Documentation/README.md +++ b/Documentation/README.md @@ -54,6 +54,7 @@ Point-in-time findings. Useful as evidence; not maintained as current truth: - [Safari header, first pass](Reports/SafariHeader-FirstPass.md) - [Manual unload readiness](Reports/ManualUnload-Readiness.md) - [Space settings, first pass](Reports/SpaceSettings-FirstPass.md) +- [Bridge gap inventory](Reports/Bridge-Gap-Inventory.md) ## Conventions diff --git a/Documentation/Reports/Bridge-Gap-Inventory.md b/Documentation/Reports/Bridge-Gap-Inventory.md new file mode 100644 index 0000000..de50fa8 --- /dev/null +++ b/Documentation/Reports/Bridge-Gap-Inventory.md @@ -0,0 +1,301 @@ +# Bridge Gap Inventory: Qt surface vs the C ABI + +**Status:** Measured inventory. Nothing here is inferred from the Qt *app* code alone — every "used by Qt" +claim names the `ViewImplementation` symbol Qt calls, and every "missing" claim names the absence in +`Libraries/LibPort/ladybird_port.h`. + +**Goal:** make the ABI complete enough that new Mac UI work never requires another engine change. The +thing to get right once is the *shape*; the *tiers* below say what is worth bridging at all. + +**Method:** the complete `ViewImplementation` surface (90 `on_*` callback members, the public methods Qt +calls) was diffed against the 21 exported `Lb*` functions and the 10 `LbCallbacks` fields. Every row below +is one of those two lists. + +--- + +## 0. Read this first: most of these are bugs, not gaps + +B1–B7 are not "a feature we have not built yet". They are things the app does today that are wrong or dead, +and four of them make ordinary pages look broken. B8 is a false promise in the header that will mislead the +next person who adds a request callback. + +### B1. ⌘C / ⌘V / ⌘X / ⌘A / ⌘Z in page content do nothing + +`PortWebView.translate` maps AppKit virtual key codes through a switch whose `default` arm is +`PortKey.invalid`, and it deliberately suppresses `code_point` whenever `.command` is held: + +```swift +if !flags.contains(.command), let characters = event.characters, ... +``` + +So ⌘C crosses the ABI as `(key = invalid, code_point = 0, modifiers = Mod_Super)`. The engine's editing +shortcuts require the key itself — `EventHandler` checks `key == UIEvents::KeyCode::Key_C` and friends +under `Mod_PlatformCtrl`, which is `Mod_Super` on macOS. `PortKey` mirrors only non-text keys, so no +letter ever reaches it. + +There is no Edit menu either: `Sources/LadybirdMac/main.swift` declares no `Commands`, so the standard +`copy:`/`paste:` selectors go down the responder chain and `PortWebView` does not implement them. + +Consequence: copying text out of a page is impossible. This is the single most user-visible defect here. + +### B2. `` are dead controls + +`ViewImplementation::did_request_select_dropdown` and `did_request_file_picker` both record the requesting +page and then only call the host callback **if it exists**. No ABI callback is installed, so: + +- the dropdown never opens, and the `HTMLSelectElement` stays `is_open` forever; +- no file chooser ever appears, and the input stays open. + +Clicking again does not help: the engine treats a request from the *same* page as non-conflicting and takes +the same silent path. Any form with a `` popup (B2) | **1** | +| C22 | `on_request_file_picker` | file input (B2) | **1** | +| C23 | `on_request_color_picker` | `` | 3 | +| C24 | `on_request_set_prompt_text` | prompt retry text | 3 | +| C25 | `on_request_dictionary_lookup` | AppKit dictionary | 4 | +| C26 | `on_network_request_started` … `_finished`, `on_console_message`, `on_resource_status_change`, `on_received_js_console_result` | DevTools | 4 | +| C27 | the whole `on_received_*` / `on_dom_mutation_received` / `on_debugger_*` family | DevTools | 4 | +| C28 | `on_received_accessibility_tree`, `on_accessibility_focus_changed` | accessibility bridge | 3 | +| C29 | context menus: `page_context_menu`, `link_context_menu`, `selected_text_link_context_menu`, `image_context_menu`, `media_context_menu` | right-click menus | 3 | +| C30 | `on_request_website_issue_report`, `on_crash_report_saved` | issue reporting | 4 | + +### 2.2 Methods Qt calls that the ABI cannot express + +| # | Engine method | Qt's use | Tier | +|---|---|---|---| +| M1 | `reload(BypassCache)`, `stop_loading` | the reload/stop button (B5) | **1** | +| M2 | `set_preferred_color_scheme`, `set_preferred_contrast`, `set_preferred_motion` | page dark mode (B6) | **1** | +| M3 | `zoom_in`, `zoom_out`, `set_zoom`, `reset_zoom`, `zoom_level` | ⌘+ / ⌘- / ⌘0 | 2 | +| M4 | `select_all`, `undo`, `redo`, `paste_from_clipboard`, `selected_text`, `cut_selected_text` | Edit menu (B1) | **1** | +| M5 | `find_in_page`, `find_in_page_next_match`, `find_in_page_previous_match`, `find_in_page_end` | ⌘F | 2 | +| M6 | `toggle_page_mute_state`, `page_mute_state` | mute button | 2 | +| M7 | `set_is_fullscreen`, `is_fullscreen`, `exit_fullscreen` | page fullscreen | 3 | +| M8 | `set_system_visibility_state`, `set_has_system_focus` | background-tab throttle, `document.hasFocus()` | 2 | +| M9 | `request_close`, `request_close_preflight`, `prepare_for_close_without_prompting`, `force_close`, `needs_beforeunload_check` | close-with-unsaved-work (today Ava answers a `beforeunload` it never asked for) | 2 | +| M10 | `set_window_size`, `set_window_position`, `set_display_metadata`, `update_screen_rects` | `window.resizeTo`, screen info, frame pacing | 3 | +| M11 | `session_history_snapshot`, `restore_session_history_from_snapshot` | real session restore | 3 | +| M12 | `traverse_the_history_to_step`, `session_history_traversal_menu_items`, `recent_history_entries` | back/forward long-press menu | 3 | +| M13 | `get_source` | View Source | 3 | +| M14 | `take_screenshot(ScreenshotType)` | screenshot tool | 4 | +| M15 | `set_viewport_corner_radius`, `set_has_rounded_corners` | rounded page corners | 3 | +| M16 | `set_marked_text_from_input_method`, `commit_text_from_input_method`, `unmark_text_from_input_method` | IME | 3 | +| M17 | `web_content_pid`, `crash_report_name`, `crash_overlay_failed_url` | crash reporting | 4 | +| M18 | `set_next_history_visit_transition` | correct history classification | 2 | +| M19 | `initialize_tab(VisibilityState)` / `set_device_pixel_ratio_for_testing` | already used, but the only public scale setter is named `_for_testing` | **1** | +| M20 | `set_scales_frames_to_fit`, `enable_picture_in_picture_controls`, `inspect_*`, `run_javascript`, `debug_request` | PiP, DevTools | 4 | + +Tier 1 = Ava's current UI is wrong without it. Tier 2 = the obvious next features, and needed for the app to +feel finished. Tier 3 = Qt parity minus DevTools. Tier 4 = deliberately never (DevTools, WebDriver, PiP, +bookmarkets internals, session store, crash upload). + +--- + +## 3. The shape to build, and why it is the whole point + +The header's rule R4 says additive-only, and a previous review already rejected the naive solution — +appending fields to `LbCallbacks` — for a concrete reason: field offsets are baked into Swift at compile +time, so a widened struct run against an older dylib is an immediate startup `SIGSEGV`, not a stale build. + +So each new concern gets **its own size-tagged struct and its own registration function**: + +```c +typedef struct LbPageCallbacks { + uint32_t struct_size; // sizeof(this struct), written by the caller + uint32_t version; // LB_CALLBACKS_VERSION + void (*on_load_start)(void* ctx, uint64_t tab); + void (*on_navigation_commit)(void* ctx, uint64_t tab); + void (*on_history_traversal_complete)(void* ctx, uint64_t tab); + void (*on_crash)(void* ctx, uint64_t tab, int32_t reason); + void (*on_new_tab)(void* ctx, uint64_t parent_tab, uint64_t new_tab, int activate); + // ... +} LbPageCallbacks; + +// Returns 1 when applied, 0 when this dylib predates the group or the size is short. A host that +// fails to register simply loses the feature, and never crashes. +int LbAppSetPageCallbacks(LbApp*, const LbPageCallbacks*); +``` + +Why this shape earns its boilerplate: + +- **Never a layout change to `LbCallbacks`.** The four existing groups stay untouched; new groups arrive as + new functions. An old host and a new dylib, or the reverse, both stay alive. +- **One group per concern**, so adding "zoom" later touches one struct and one setter, never the shared one. +- **`on_new_tab` returns a tab id owned by the shim, not a `CanonicalTraversable&`.** This is the one place + the engine's type genuinely cannot cross a C ABI — `HeadlessWebView` hands out a traversable the host is + expected to adopt. The shim does the adopting, registers an `LbTab`, and reports its id. The Mac side + then decides whether to show it. That also fixes B3 without exposing engine types. +- **`struct_size` means a new field is a new minor version, not a break.** A host compiled against an older + header passes a smaller size and the shim zero-fills. + +Cross-cutting rules for everything below, matching the existing house style: + +- Strings cross as `(const char*, size_t)` UTF-8, never NUL-terminated. `Utf16String::to_byte_string()` is + the only correct narrowing (see `Traps.md`). +- Structured payloads (select items, file filters, content-blocking snapshot, session history, performance + stats, a whole context menu) cross as **JSON text**, because they are `Vector` graphs with no C + shape and each would otherwise become its own bespoke ABI. +- Any request the engine waits on gets a `uint64_t request_id` and a matching `LbTabAnswer*`; anything that + is not answered hangs a page. Grouping a "present-but-silent" callback is the failure mode the header + already warns about. +- Every new group gets a native probe in `Tests/LibWebView/TestNative*`, per `AGENTS.md`. + +--- + +## 4. Proposed phasing + +One fork commit + one app commit + one probe per phase. Never a fork change and an app change in the same +commit, and never two writers in one worktree. + +| Phase | Content | Fixes | Why first | +|---|---|---|---| +| **P0** | Tracking area + cursor rects; letter key codes for ⌘C/X/V/A/Z; Edit menu wired to `LbTabSendKey`; `LbTabReload`; `LbTabStopLoading`; real theme selection; **correct the header's "absent is safe" paragraph** | B1, B5, B7, half of B6, B8 (docs) | No new callback groups. Pure defects. The header fix is text-only and stops the next group inheriting a false guarantee. | +| **P1** | `LbPageCallbacks`: load_start, navigation_commit, history_complete, crash, crash_overlay, new_tab, audio, find | B3, B4 | Unblocks popups and stops silent renderer deaths. | +| **P2** | `LbPickerCallbacks` + answers: select dropdown, file picker, color picker, permission, external URL — **each with an explicit "unavailable" answer on the absent path** (B8) | B2, B8 | Dead form controls are a compatibility wall. | +| **P3** | `LbUICallbacks`: cursor, link hover, tooltips | B7 remainder | Cheap, very visible. | +| **P4** | Commands: zoom, find, mute, visibility/focus, close-with-prompt, color scheme/contrast/motion, editing (undo/redo/copy/cut/paste/select-all) | B1 remainder, B6 | Editing needs both the key fix and these. | +| **P5** | IME: marked text, `commit_text_from_input_method`, `input_method_state`, `on_finish_handling_key_event` | CJK/diacritics | Not urgent, but it is the last hard blocker for non-English input. | +| **P6** | Context menus: menu model → JSON + action dispatch | right-click | Largest single item; a `Menu` is a tree of `Action`s with enabled/checked/visible state. | +| **P7** | Accessibility tree bridge | VoiceOver | Independent and large. | + +The phasing is what stops the engine being touched "again and again" for two different reasons: +P0–P5 add **groups**, and after P3 the shape has proved itself, so P6/P7 are additions to an existing pattern +rather than new design. + +**One rule applies to every group from P2 onward, derived from B8:** an absent callback must never mean "the +engine will answer itself". For anything the engine blocks on, the shim registers its own handler that +answers *unavailable* immediately, and only hands the request to the host when the host's callback exists. +The host groups stay all-or-none; the shim always has an answer. + +### Deliberately out of scope + +DevTools (`inspect_*`, `on_debugger_*`, the network/console observers, `on_received_*`), WebDriver, +Picture-in-Picture, bookmark store internals, session store, crash-report upload, download UI. Ava has no UI +for these and bridging them would be permanent rebase debt for zero user-visible behaviour. Everything in +Tier 4 above is intentionally unbudgeted. + +--- + +## 5. Verified non-issues + +Worth recording so nobody "fixes" them: + +- **`is_page_covered_by_overlay` / overlay painting is Qt-only.** A headless view needs none of it; the + crash overlay is a host concern (see C4/C5), not a shim one. +- **`clipboard_item` / `insert_clipboard_item` are already virtual on `WebView::Application` and the base + implementation keeps an in-process clipboard.** So the shim can implement paste without ObjC, by + overriding in `PortApplication` and reading the pasteboard in the host through a `LbTabAnswerPaste`. + The engine side is not blocked — only the ABI is. +- **`ViewImplementation::load(std::move(navigation))` already calls `prepare_for_navigation_after_crash`,** + which is why reload-after-crash recovers today despite B4. +- **A wheel event is a `MouseEvent`**, and the tick fields must be derived with + `wheel_tick_120ths_from_pixel_delta(..., WheelDeltaPrecision::Precise)` — already handled, and the reason + trackpad scrolling works while a notched wheel needed the host-side line height in `PortWebView`. diff --git a/Documentation/Traps.md b/Documentation/Traps.md index e7e71f6..7df7899 100644 --- a/Documentation/Traps.md +++ b/Documentation/Traps.md @@ -87,10 +87,26 @@ whole time. *Fix: compare the pin against the `CMAKE_HOME_DIRECTORY` checkout's that was actually built, and print a `note:` when a separate checkout is in use rather than passing quietly.* Only `check-layers.sh` caught this before; now both do. +**A new worktree never shares `Build/release`.** Git shares submodule *history* between worktrees +(hardlinked objects) but not the build tree, so a fresh worktree costs a cold engine build however +cheap its checkout was. The one sanctioned shortcut is a `Build/release` symlink to another checkout, +and the provenance check above is what makes it safe: it compares the pin against the checkout +`CMAKE_HOME_DIRECTORY` actually names, so a symlink at the wrong commit is refused rather than +silently compiled. + **A stale remote-tracking ref will make you doubt a real push.** `git cat-file -t ` against a submodule fails until `git fetch` — the ref is local and stale, the object genuinely absent. *Fix: fetch before concluding a push did not happen.* +**A worktree inherits the submodule pin but none of its bytes.** +`git worktree add` checks out the superproject commit, so `git rev-parse HEAD:Extern/ladybird` +reports the correct pin immediately — while `Extern/ladybird/` is an empty directory with no +`.git`. `git submodule status` prints a leading `-` (`-4b042dd... Extern/ladybird`), which is the +only signal that nothing is checked out. A build or `check-layers.sh` in that worktree then fails +for a reason that looks nothing like a missing submodule. +*Fix: `git -c protocol.file.allow=always submodule update --init Extern/ladybird` in each new +worktree. Never copy `Extern/ladybird/.git` from another checkout to skip this.* + **A copied submodule `.git` file can make Git inspect a different worktree than the bytes you build.** An Orca worktree inherited `Extern/ladybird/.git` pointing at the main checkout's module gitdir, then that gitdir's `core.worktree` was repointed at Orca. In the main checkout, `git status`, @@ -100,6 +116,50 @@ and `diff` read the main bytes. Same HEAD plus clean status was true — for the `git -C Extern/ladybird rev-parse --show-toplevel` and raw file hashes; never infer byte identity from HEAD/status alone. Preserve both trees before repairing a pointer.* +The mechanism, measured on git 2.56: a worktree's submodule clone lives at +`.git/worktrees//modules/Extern/ladybird`, and its working copy's `.git` file points there +(`gitdir: ../../../.git/worktrees//modules/Extern/ladybird`). Objects are **hardlinks** into the +main checkout's `.git/modules/Extern/ladybird` — same inode, so the shared engine history costs no +extra disk — while HEAD, refs, index and config are per-worktree files. That directory is what +`core.worktree` in `.git/modules/Extern/ladybird/config` must name, and it can only name one path. + +**Sibling worktrees' submodule clones are isolated, not merely separate refs.** +A commit made on a local branch inside one worktree's submodule is not readable from another's +(`git cat-file -t ` fails). So a fetch, branch or detached checkout in one worktree does not +propagate: `git submodule update` in the second worktree is what moves it, and it moves only to that +worktree's recorded pin. This is why one writer per worktree is safe, and why "I pushed from the +other checkout" is not evidence about this one. + +**`git worktree remove` refuses a worktree that contains a submodule.** +It fails with `working trees containing submodules cannot be moved or removed`. `-f` removes it and +cleans `.git/worktrees/`; the main checkout's submodule is untouched afterwards. A second `-f` +reports `is not a working tree` — that is success, not an error. + +**An absent dialog callback does NOT make the engine answer itself.** +`ladybird_port.h` claims the four blocking dialogs are safe to omit because "the engine answers itself". +It does not, for this shim: `PortWebView` derives from `HeadlessWebView`, whose constructor already +installed handlers that only record `m_pending_dialog`. `LibPort` replaces those handlers when the host +supplies a callback and leaves the recording ones otherwise, and nothing then calls `alert_closed` / +`confirm_closed` / `prompt_closed`. `Page::did_request_alert` is parked in +`spin_event_loop_until_dialog_closed`, so the tab wedges permanently. The guarantee holds for a fresh +`ViewImplementation`, which a `HeadlessWebView` is not. *Fix: every request callback the shim adds must +have its own always-installed handler that answers "unavailable" when the host's callback is absent; +never inherit the absent-means-safe assumption. Grouped host callbacks stay all-or-none.* + +**A `mouseMoved` override receives nothing without a tracking area.** +AppKit delivers move events to a view only through an `NSTrackingArea` (or with +`window.acceptsMouseMovedEvents`). `PortWebView` overrides the method and installs neither, so CSS `:hover`, +the pointing-hand cursor over links, and tooltips were all silently absent while clicks worked. +*Fix: tracking area with `.mouseMoved`/`.mouseEntered`/`.mouseExited`/`.activeInKeyWindow`/`.inVisibleRect`, +plus cursor rects (or `cursorUpdate`) for the pointer.* + +**⌘-modified letter keys must cross the ABI as a `KeyCode`, not as `code_point`.** +The engine's editing shortcuts match `KeyCode::Key_C` / `Key_V` / `Key_X` / `Key_A` / `Key_Z` under +`Mod_PlatformCtrl` (which is `Mod_Super` on macOS) — see `EventHandler`. A host that suppresses +`code_point` when Command is held and maps only non-text virtual key codes delivers +`(invalid, 0, Mod_Super)` for every one of them, so copy, paste, cut, select-all and undo do nothing and +report no error. *Fix: map the letter virtual key codes too, and send the key with Command still set.* + **The R7 fork-diff guard must diff against the merge-base, not `upstream/master`.** Otherwise every commit upstream has landed since this fork's HEAD looks like a local change and the guard reports hundreds of irrelevant files. Measured: `upstream/master` reported 300 files and