Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the size of the containing block, not the size of the block formatting context, to place floats in layout 2020. #27376

Merged
merged 1 commit into from Jul 24, 2020

Conversation

@pcwalton
Copy link
Contributor

pcwalton commented Jul 23, 2020

The containing block for a float is not necessarily the same as the block
formatting context the float is in per CSS 2.1 1:

"For other elements, if the element’s position is relative or static, the
containing block is formed by the content edge of the nearest block container
ancestor box."

This shows up in the simplest case:

<html>
<body>
<div style="float: left">Hello</div>
</body>
</html>

In this case, the <html> element is the block formatting context with inline
size equal to the width of the window, but the <body> element with nonzero
inline margins is the containing block for the float. The float placement must
respect the content box of the <body> element (i.e. floats must not overlap
the <body> element's margins), not that of the <html> element.

Because a single block formatting context may contain floats with different
containing blocks, the left and right "walls" of that containing block become
properties of individual floats at the time of placement, not properties of the
float context itself.

Additionally, this commit generalizes the float placement logic a bit to allow
the placement of arbitrary objects, not just floats. This is intended to
support inline layout and block formatting context placement.

This commit updates the FloatContext and associated tests only and doesn't
actually wire the context up to the rest of layout, so floats in pages still
aren't actually laid out.

r? @Manishearth


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix #___ (GitHub issue number if applicable)
  • There are tests for these changes OR
  • These changes do not require tests because ___
…tting

context, to place floats in layout 2020.

The containing block for a float is not necessarily the same as the block
formatting context the float is in per CSS 2.1 [1]:

"For other elements, if the element’s position is relative or static, the
containing block is formed by the content edge of the nearest block container
ancestor box."

This shows up in the simplest case:

	<html>
	<body>
	<div style="float: left">Hello</div>
	</body>
	</html>

In this case, the `<html>` element is the block formatting context with inline
size equal to the width of the window, but the `<body>` element with nonzero
inline margins is the containing block for the float. The float placement must
respect the content box of the `<body>` element (i.e. floats must not overlap
the `<body>` element's margins), not that of the `<html>` element.

Because a single block formatting context may contain floats with different
containing blocks, the left and right "walls" of that containing block become
properties of individual floats at the time of placement, not properties of the
float context itself.

Additionally, this commit generalizes the float placement logic a bit to allow
the placement of arbitrary objects, not just floats. This is intended to
support inline layout and block formatting context placement.

This commit updates the `FloatContext` and associated tests only and doesn't
actually wire the context up to the rest of layout, so floats in pages still
aren't actually laid out.

[1]: https://drafts.csswg.org/css2/#containing-block-details
/// floats may be placed. If `None`, there are no floats to the right; distinguishing between
/// the cases of "a zero-width float is present" and "no floats at all are present" is
/// necessary to, for example, clear past zero-width floats.
/// The distance from the *left* edge of the block formatting context to the first legal

This comment has been minimized.

Copy link
@pcwalton

pcwalton Jul 23, 2020

Author Contributor

(The comment was incorrect before.)

@pcwalton pcwalton force-pushed the pcwalton:floats-2020-containing-block branch from 277393f to 362b64a Jul 23, 2020
@Manishearth
Copy link
Member

Manishearth commented Jul 23, 2020

@bors-servo
Copy link
Contributor

bors-servo commented Jul 23, 2020

📌 Commit 362b64a has been approved by Manishearth

bors-servo added a commit that referenced this pull request Jul 23, 2020
…hearth

Use the size of the containing block, not the size of the block formatting context, to place floats in layout 2020.

The containing block for a float is not necessarily the same as the block
formatting context the float is in per CSS 2.1 [1]:

"For other elements, if the element’s position is relative or static, the
containing block is formed by the content edge of the nearest block container
ancestor box."

This shows up in the simplest case:

	<html>
	<body>
	<div style="float: left">Hello</div>
	</body>
	</html>

In this case, the `<html>` element is the block formatting context with inline
size equal to the width of the window, but the `<body>` element with nonzero
inline margins is the containing block for the float. The float placement must
respect the content box of the `<body>` element (i.e. floats must not overlap
the `<body>` element's margins), not that of the `<html>` element.

Because a single block formatting context may contain floats with different
containing blocks, the left and right "walls" of that containing block become
properties of individual floats at the time of placement, not properties of the
float context itself.

Additionally, this commit generalizes the float placement logic a bit to allow
the placement of arbitrary objects, not just floats. This is intended to
support inline layout and block formatting context placement.

This commit updates the `FloatContext` and associated tests only and doesn't
actually wire the context up to the rest of layout, so floats in pages still
aren't actually laid out.

[1]: https://drafts.csswg.org/css2/#containing-block-details

r? @Manishearth

<!-- Please describe your changes on the following line: -->

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #___ (GitHub issue number if applicable)

<!-- Either: -->
- [x] There are tests for these changes OR
- [ ] These changes do not require tests because ___

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
@bors-servo
Copy link
Contributor

bors-servo commented Jul 23, 2020

Testing commit 362b64a with merge b58c9b5...

@bors-servo
Copy link
Contributor

bors-servo commented Jul 23, 2020

💔 Test failed - status-taskcluster

@jdm
Copy link
Member

jdm commented Jul 24, 2020

@bors-servo
Copy link
Contributor

bors-servo commented Jul 24, 2020

Testing commit 362b64a with merge 6ca3c84...

@bors-servo
Copy link
Contributor

bors-servo commented Jul 24, 2020

☀️ Test successful - status-taskcluster
Approved by: Manishearth
Pushing 6ca3c84 to master...

@bors-servo bors-servo merged commit 6ca3c84 into servo:master Jul 24, 2020
2 checks passed
2 checks passed
Community-TC (pull_request) TaskGroup: success
Details
homu Test successful
Details
@pcwalton pcwalton deleted the pcwalton:floats-2020-containing-block branch Jul 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants
You can’t perform that action at this time.