Support float:left/right for images and blocks with text wrapping#1319
Merged
Conversation
CSS float was parsed into DTHTMLElementFloatStyle but never used; floated images were forced to be their own block as a workaround. Floats are now laid out for real: - Floated content is marked with DTFloatStyleAttribute (plus DTFloatWidthAttribute for an explicit CSS width) and taken out of the normal flow during line building in CoreTextLayoutFrame. - A floated image becomes a box at the left/right content edge; a floated block (div, span, table) becomes a shrink-to-fit or fixed-width column laid out via the table cell flow, including its backgrounds and borders. - Text lines vertically intersecting a float region are narrowed and re-typeset until the assumed insets match the line's real extent; several floats on one side stack next to each other and move down when there is no room, and a float that does not fit a finite frame moves to the continuation frame. - The clear property (left/right/both) makes paragraphs and floats start below earlier floated content, via DTClearFloatsAttribute. - HTMLWriter round-trips floats: floated attachments get a wrapping span with the float style, floated block ranges become a div with float and width, and clear is emitted on paragraph styles. - New Floats.html demo snippet and a FloatLayoutTests suite covering attribute emission, wrap geometry, side-by-side floats, shrink-to-fit, clear, frame height, pagination and writer round-trips. Co-Authored-By: Claude Fable 5 <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 552db605af
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Float lines inflated typesetLines.count past the strict-equality truncation checks, so numberOfLines (and the lines-fitting retry) never fired after a leading float. Line limits now count only lines of the normal flow — floated content is out of the flow, like in CSS — and the checks tolerate jumps (>= instead of ==). The lines-fitting retry also captures the flow line count so a rebuild cannot recurse with a zero limit when only float lines exist. Co-Authored-By: Claude Fable 5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Implements real CSS float layout.
floatwas parsed intoDTHTMLElementFloatStylebut never used — floated images were forced to be their own block as a workaround (the old comment inTextAttachmentHTMLElementsaid "we don't support float yet"). Now:div,span, eventable) become a column — explicit CSSwidthor shrink-to-fit — laid out via the existing table-cell flow, including their backgrounds, padding and nested tables.clear:left/right/bothmakes paragraphs and floats start below earlier floated content.<span style="float:…">, floated block ranges become<div style="float:…;width:…px">,clearis emitted on paragraph styles.How
DTFloatStyleAttribute(andDTFloatWidthAttributefor an explicit width,DTClearFloatsAttributefor clear) over their output range; the attachment workaround that forced floated images to be blocks is removed so they stay inline.CoreTextLayoutFrame._buildLinesWithTypesettertakes marked content out of the flow before the table check (so floated tables become columns), tracks float regions, and narrows the lines that vertically intersect them. Since a line's height is only known after typesetting, each line is re-typeset until the assumed float insets match its real vertical extent.Notes for review
clearignored). So unlike tables/NSTextTablethere was nothing native to mirror, and DT-specific attributes are the only encoding option.NSTextViewnow shows a floated image inline in its paragraph (previously: own line). The wrap itself only happens in DT's own layout engine.FloatLayoutTestssuite (16 tests: attribute emission, wrap geometry left/right, side-by-side floats, shrink-to-fit, clear, frame height, pagination, writer round-trips) plus aFloats.htmldemo snippet. Full suite passes: 315 tests on macOS, 307 on the iOS simulator (CI-equivalent invocations).🤖 Generated with Claude Code