Revert ab29ec8: container==content auto-fit made it worse — back to alpha-crop with the container at element size

The container tracks the element's own Width/Height again; the crop stays in the bitmap.
This commit is contained in:
2026-08-28 12:09:13 -07:00
parent ab29ec801d
commit 9b56e88800
7 changed files with 51 additions and 103 deletions
+28 -26
View File
@@ -6,34 +6,36 @@
working). **NOT pushed — user rule: never push without explicit instruction (2026-08-24).** No feature
branches pre-1.0: all work lands on `main` per work unit.
## The web-source rendering work (2026-08-28) — CURRENT MODEL: canvas-size viewport + alpha crop + container==content
## The web-source rendering work (2026-08-28) — CURRENT MODEL: canvas-size viewport + ALPHA-BBOX crop
**History of failures (see MyMistakes.md for the full log):**
1. box-sized viewport clipped full-bleed widgets to their upper-left chunk → render at the master
canvas 1920×1080 (stable), the only render the creator confirmed solid.
2. `JSON.stringify` return double-encoded under `ExecuteScriptAsync` → crop silently disabled.
3. `scrollWidth/scrollHeight` at canvas size = whole viewport for full-canvas wrapper bodies → no trim.
4. DOM-element-union crop measured an unsettled layout on NavigationCompleted → BROKE the image.
5. Alpha-bbox crop (from the frame itself) fixed the BITMAP but the grid/box stayed at the uncropped
user size → Fill stretched the tight widget into a big frame → dead space between content and border.
**History of failures (see MyMistakes.md for the full log):** box-size rendering clipped full-bleed
widgets to their upper-left chunk (fixed — page renders at the master canvas 1920×1080, stable, the
one render the creator confirmed solid). Then four crop attempts failed in different ways: (1) the
`JSON.stringify` return double-encoded under `ExecuteScriptAsync`, silently disabling the crop;
(2) `scrollWidth/scrollHeight` at canvas size returns the whole viewport for full-canvas wrapper
bodies → no trim (ghost boundary); (3) union-of-DOM-elements measured an unsettled layout on
NavigationCompleted and BROKE the image (creator's "don't break the rendering" boundary crossed).
(4) Reverting to f39ebd9's scroll-crop was another dead end (#2 again).
**The CURRENT MODEL (this change):**
**The CURRENT MODEL (this commit):**
- `Services/WebView2Manager.cs` — page renders at 1920×1080 (stable, never tracked); `overflow:hidden`
+ transparent-bg injection. `FindContentBounds` crops the Bgra32 capture to the bounding box of
non-transparent pixels each frame (immune to timing, can never truncate content). `ContentCanvasSize`
maps the crop rect to CANVAS UNITS (DPI-correct). Preview event now carries (bitmap, canvasW, canvasH).
- `ViewModels/MainViewModel.cs` — `OnWebView2PreviewBitmapChanged` sets the element's Width/Height to
the cropped canvas size → the element grid AND the SelectionOverlay (both bound to element
Width/Height) EQUAL the widget. `IsPreviewDragging` suppresses the auto-fit during a drag gesture.
- `MainWindow.xaml.cs` — sets/clears `IsPreviewDragging` at drag/resize start and end.
- Invariant: **render at canvas size; crop to the alpha extent; SIZE THE BOX to the crop.**
- Unit tests: 10/10 (alpha bounds ×3, canvas-size mapping ×3, control size ×4).
+ transparent-bg injection. `FindContentBounds` scans the Bgra32 capture per frame and crops to the
bounding box of NON-TRANSPARENT pixels — the widget's true rendered extent, measured from the frame
itself. No DOM query, no layout timing: it can never truncate visible content (worst case = full
frame = the confirmed-good image). `Stretch="Fill"` maps the cropped frame flush under the selection
box → the box hugs the widget on all four sides. `QueryContentBoundsAsync` + the JS script are
DELETED.
- `MainWindow.xaml` — web `<Image>` Stretch set to Fill via the IsWebSource DataTrigger (unchanged).
- Invariant: **render at canvas size; crop to the alpha extent; Fill to the box.**
- Unit tests: 3 new for `FindContentBounds` (tight box, no-alpha no-crop, full-alpha no-crop).
**Property panel / sliders (2026-08-28):** web URI ✕ clears the textbox; web ✓/✕ icon buttons
`IsTabStop="False"`; Slider style `IsMoveToPointEnabled="True"`. Confirmed fixed by the creator.
`IsTabStop="False"` so Tab walks X→Y→W→H→URI; Slider style `IsMoveToPointEnabled="True"`
restores click-anywhere-on-bar. All three confirmed fixed by the creator.
Build: 0 warnings; tests 10/10. Rejected for the record: box-sized viewport, `Uniform`, CSS reset,
viewport==box, DOM-union crop (broke image), crop-without-container-size (left the gap).
Build: 0 warnings; tests 7/7 (WebView2Manager). Rejected for the record: box-sized viewport (upper-left
truncation), fixed 1920×1080 + `Uniform` (letterbox dead space), CSS margin/100% reset (enlarged gap),
viewport==box (reflow/truncation/scrollbars), DOM-union crop (broke the image).
## Key facts / landmines
@@ -50,8 +52,8 @@ viewport==box, DOM-union crop (broke image), crop-without-container-size (left t
- No `CODING.md`; conventions live in `AGENTS.md` + `ai.md`.
## Next steps
1. AWAIT creator's verdict on the container==content auto-fit — reload a widget; the selection frame
must equal the widget exactly (no dead space, including during resize). Follow-ups only if asked:
crop hysteresis for animated widgets, ticker/percent-display widgets.
2. Graceful handling of navigation errors / invalid URIs (TASK 17 ×9) — only if the creator asks.
1. AWAIT creator's verdict on the ALPHA-BBOX crop — reload a widget URL at several box sizes; the
selection frame must snap flush to the widget with no dead space, image must stay identical for
full-bleed widgets. If an animated widget causes visible jitter, add crop hysteresis as a follow-up.
2. Follow-up only if the creator asks: graceful handling of navigation errors / invalid URIs (TASK 17 ×9).
3. Continue queue: TASK 18 local recording, TASK 21 media source, TASK 22 audio sync offset.