aboutsummaryrefslogtreecommitdiffstats
path: root/components/layout_2020/flow/float.rs
Commit message (Collapse)AuthorAgeFilesLines
* Layout 2020: Rename `flow_relative` types to `Logical...` (#30324)Martin Robinson2023-09-121-26/+30
| | | | | | This makes the names of flow relative geometry consistent with what is used in the style crate and removes them from a module. With this change it's more obvious what makes these types different from the ones in `euclid`.
* Strict import formatting (grouping and granularity) (#30325)Samson2023-09-111-11/+13
| | | | | * strict imports formatting * Reformat all imports
* remove `extern crate` (#30311)Samson2023-09-081-0/+1
| | | | | | | | | | | * remove extern crate * Update components/script_plugins/lib.rs Co-authored-by: Martin Robinson <mrobinson@igalia.com> --------- Co-authored-by: Martin Robinson <mrobinson@igalia.com>
* Fix PlacementAmongFloats to avoid missing some bands (#30280)Oriol Brufau2023-09-011-2/+18
| | | | | | | | | | PlacementAmongFloats would stop iterating when current_bands would be empty, even if next_band wasn't at infinity. Then the BFC root or replaced block was placed after all the floats, even if it could fit next to some of them. This patch moves the next_band into current_bands so that the loop keeps considering bands.
* Avoid crash in PlacementAmongFloats (#30235)Oriol Brufau2023-08-291-1/+1
| | | | | | | | | | | PlacementAmongFloats was assuming that there would always be a FloatBand at a position smaller than or equal to the given ceiling, but this was not the case for negative ceilings. The reason is that the FloatContext initialized the FloatBandTree with a band at 0, and another at +∞. This patch changes the initial bands to −∞ and +∞. This seems more consistent and matches the expectation of PlacementAmongFloats.
* Handle inline margins when avoiding floats (#30072)Oriol Brufau2023-08-091-13/+26
|
* Handle BFC roots with auto width next to floats (#30057)Oriol Brufau2023-08-081-3/+65
| | | Co-authored-by: Martin Robinson <mrobinson@igalia.com>
* Refactor PlacementAmongFloats (#30068)Oriol Brufau2023-08-041-30/+65
| | | | | | | | | | | | | | - Add explanatory comments. - Rename some methods. - Store the ceiling instead of relying on the first band, this allows calling place() when current_bands is empty. - Make current_bands_height() work when current_bands is empty. - Add add_one_band() helper method. - Make place() return a Rect. Follow-up patches will need to know the size of the area shrunk by floats. This will be useful for #30057 and #30050. Co-authored-by: Martin Robinson <mrobinson@igalia.com>
* Minor refactoring for PlacementAmongFloats (#30055)Oriol Brufau2023-08-011-20/+17
| | | | | | | | | | | | No difference in behavior, just these changes: - PlacementAmongFloats::new() initializes the top of the 1st band to the ceiling, so that other methods can just refer to the former without having to floor by the later. - In fact, the 'ceiling' field becomes unnecessary, and is removed. - top_of_placement_for_current_bands() is renamed to current_ceiling(). - try_place_once() is reorganized to reduce indentation. - The condition 'len() > 0' becomes '!is_empty()'. - The 1st band is now popped in place() instead of try_place_once(), then it's easier to see why the loop will end.
* Fix interaction of margins and clearance for PlacementAmongFloats (#30038)Oriol Brufau2023-07-311-26/+71
| | | | | | | | | Consumers of PlacementAmongFloats weren't handling margins properly. They were assuming that they would either get a positive adjustment, or zero for no-op. However, just like the regular clearance triggered by 'clear', the clearance added onto blocks that establish an independent FC can be zero or negative, and the effect is different than having no clearance.
* Remove ClearSide enum (#30035)Oriol Brufau2023-07-271-37/+14
| | | Just use Clear instead, they have the same values.
* Run unit tests with both layout 2013 and layout 2020 (#30032)Oriol Brufau2023-07-271-2/+2
| | | | | | | | Since #29950, unit tests were only running with the legacy layout, and there was no way to run them for layout 2020. This patch makes './mach test-unit' run unit tests for both. Also doing some changes so that the layout 2020 floats.rs tests compile.
* Remove calculate_clearance_and_adjoin_margin (#30033)Oriol Brufau2023-07-261-16/+0
| | | It was useful when it had 3 callers, but #29977 removed 2 of them.
* Place replaced and non-auto inline size independent FCs next to floats (#29977)Martin Robinson2023-07-181-13/+120
| | | | | | | | | | | | | | | | | | | | | * Place replaced and non-auto inline size independent FCs next to floats The CSS2 specification says that replaced content and independent formatting contexts should be placed next to floats. This change adds support for that, but punts on support for independent formatting contexts that have an auto inline size. With an auto inline size, we which requires a much more complex layout algorithm. Co-authored-by: Oriol Brufau <obrufau@igalia.com> * Fix issue with where last band was taken into account for inline size * adjustment_from_floats should prevent margin collapse * Properly handle elements with 0 height --------- Co-authored-by: Oriol Brufau <obrufau@igalia.com>
* Layout 2020: Properly calculate clearanceOriol Brufau2023-06-301-16/+52
| | | | | calculate_clearance() was not taking into account that adding clearance prevents top margin from collapsing with earlier margins.
* Layout 2020: implement clearance as Option<Length>Oriol Brufau2023-06-291-4/+7
| | | | | | | | | | Clearance was implemented as a Length, where zero meant no clearance. However, having a clearance of 0px should be different than having no clearance, since the former can still prevent margin collapse. This patch keeps the existing behavior, so it won't be possible to get a clearance of Some(Length::zero()), but it prepares the terrain for a follow-up to fix calculate_clearance to return the proper thing.
* Properly position floats when subsequent boxes collapse margins with ↵Martin Robinson2023-06-271-48/+61
| | | | | | | | | | | | | | | | containing block Margins should be able to collapse through floats when collapsing with parent blocks (the containing block). To properly place floats in this situation, we need to look at these subsequent floats to find out how much of the margin will collapse with the parent. This initial implementation is very basic and the second step would be to cache this in order to avoid having to constantly recalculate it. Fixes #29915. Co-authored-by: Oriol Brufau <obrufau@igalia.com>
* Auto merge of #29894 - mrobinson:ditch-static-position-closure, r=Loirooriolbors-servo2023-06-211-1/+0
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Simplify layout of absolutes with static insets Absolutes with static insets need to be laid out at their ancestor containing blocks, but their position is dependent on their parent's layout. The static layout position is passed up the tree during hoisting and ancestors each add their own offset to the position until it is relative to the containing block that contains the absolute. This is currently done with a closure and a fairly tricky "tree rank" numbering system that needs to be threaded through the entire layout. This change replaces that system. Every time a child is laid out we create a positioning context to hold any absolute children (this can be optimized away at a later time). At each of these moments, we call a method to aggregate offsets to the static insets of hoisted absolutes. This makes the logic easier to follow and will also allow implementing this behavior for inline-blocks, which was impossible with the old system. <!-- 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 do not require tests because it should not change behavior. <!-- 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. -->
| * Simplify layout of absolutes with static insetsMartin Robinson2023-06-201-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Absolutes with static insets need to be laid out at their ancestor containing blocks, but their position is dependent on their parent's layout. The static layout position is passed up the tree during hoisting and ancestors each add their own offset to the position until it is relative to the containing block that contains the absolute. This is currently done with a closure and a fairly tricky "tree rank" numbering system that needs to be threaded through the entire layout. This change replaces that system. Every time a child is laid out we create a positioning context to hold any absolute children (this can be optimized away at a later time). At each of these moments, we call a method to aggregate offsets to the static insets of hoisted absolutes. This makes the logic easier to follow and will also allow implementing this behavior for inline-blocks, which was impossible with the old system.
* | Auto merge of #29870 - mrobinson:float-root, r=Loirooriolbors-servo2023-06-201-16/+9
|\ \ | |/ |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Layout 2020: Correct rendering of floated root Fix two issues around floating a root element: 1. In the StackingContext code handle the case where a root element is a Float fragment and not a Box fragment. This fixes a debug assertion failure in the css/CSS2/float/float-root.html test. 2. When initializing the SequentialLayoutState, use the containing block width as the maximum inline float placement position instead of infinity. This fixes the rendering of css/CSS2/float/float-root.html. Note that css/CSS2/float/float-root.html was passing before, because both the test and reference were subject to the same bug. This fixes a couple other tests as well. <!-- 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] There are tests for these changes <!-- 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. -->
| * Correct rendering of floated rootMartin Robinson2023-06-201-16/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fix two issues around floating a root element: 1. In the StackingContext code handle the case where a root element is a Float fragment and not a Box fragment. This fixes a debug assertion failure in the css/CSS2/float/float-root.html test. 2. When initializing the SequentialLayoutState, use the containing block width as the maximum inline float placement position instead of infinity. This fixes the rendering of css/CSS2/float/float-root.html. Note that css/CSS2/float/float-root.html was passing before, because both the test and reference were subject to the same bug. This fixes a couple other tests as well.
* | Handle floats in BlockContainer::inline_content_sizesOriol Brufau2023-06-191-6/+1
|/ | | | | | Typically, block-level contents are stacked vertically, so this was just taking the maximum size among all contents. However, floats can be stacked horizontally, so we need to sum their sizes.
* Layout 2020: Fix issues with float implementation documentationMartin Robinson2023-06-141-57/+60
| | | | | | Fix some rustdoc comments which won't process properly unless they start with three '/' characters. In addition, improve the name of a function and add some missing documentation.
* Layout 2020: Properly handle negative block margins in floatsMartin Robinson2023-06-111-4/+11
| | | | | | | | | | If a float has negative block margins, it should be pushed upward, but shouldn't affect the positioning of any floats that came before it. It should lower the ceiling though when it still has some non-negative block contribution. In order to implement this behavior, we should only place the float considering its non-negative block length contribution. If the float is pushed up completely past it's "natural" position, it should be placed like a float with zero block size.
* Layout 2020: Move all Fragment code to the `fragment_tree` directoryMartin Robinson2023-06-041-1/+1
| | | | | | | | This is a simple code organization change with no behavior change with the idea of making Layout 2020 easier to understand by new folks to the project. The idea is that we will have a cleaner separation between the different parts of layout ie one directory for the fragment tree and one (currently multiple) directory for the box tree.
* Fix the unit testMartin Robinson2023-06-031-8/+18
| | | | These were broken for various issues.
* Do not hoist floated fragmentsMartin Robinson2023-06-031-112/+80
| | | | | | | | | | | | | | | | | | | | | Instead of hoisting floated fragments to be siblings of the fragment created by their containing block formatting context, keep them in "normal" fragment tree position and adjust their positioning to be relative to the containing block. This means that float fragments follow the existing invariants of the fragment tree and properly handle hit testing, painting order, and relative positioning. The tradeoff here is more complexity tracking the containing block offsets from the block formatting context (including handling collapsed margins), but less complexity dealing with hoisting / shared ownership in addition to the correctness benefits. Some tests are failing now because this change revealed some additional shortcomings with clearing block formatting context content size past the end of their contained floats. This will be fixed in a followup change. Co-authored-by: Oriol Brufau <obrufau@igalia.com>
* Place floats in layout 2020, but don't flow text around the floats yet.Patrick Walton2023-06-031-36/+390
| | | | | | | | | | | | | | | This commit puts floats behind the `layout.floats.enabled` pref, because of the following issues and unimplemented features: * Inline formatting contexts don't take floats into account, so text doesn't flow around the floats yet. * Non-floated block formatting contexts don't take floats into account, so BFCs can overlap floats. * Block formatting contexts that contain floats don't expand vertically to contain all the floats. That is, floats can stick out the bottom of BFCs, contra spec.
* Combine DOM-related concepts in Layout 2020 into dom.rsMartin Robinson2023-05-131-1/+2
|
* Use the size of the containing block, not the size of the block formattingPatrick Walton2020-07-221-52/+105
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Add an implementation of the core float and clear placement logic in layoutPatrick Walton2020-07-201-4/+469
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 2020, not yet wired to the rest of layout. This commit implements an object that handles the 10 rules in CSS 2.1: https://www.w3.org/TR/CSS2/visuren.html#float-position The implementation strategy is that of a persistent balanced binary search tree of float bands. Binary search trees are commonly used for implementing float positioning; e.g. by WebKit. Persistence enables each object that interacts with floats to efficiently contain a snapshot of the float list at the time that object was laid out. That way, incremental layout can invalidate and start reflow at any point in a containing block. This commit features extensive use of [QuickCheck](https://github.com/BurntSushi/quickcheck) to ensure that the rules of the CSS specification are followed. Because this is not yet connected to layout, floats will not actually be laid out in Web pages yet. Note that unit tests as set up in Servo currently require types that they access to be public. Therefore, some internal layout 2020 types that were previously private have been made public. This is somewhat unfortunate. Part of #25167.
* Compute content sizes lazily in layout 2020Anthony Ramine2020-06-181-4/+1
|
* layout_2020: Tag fragments with their pseudo content typeMartin Robinson2020-06-061-8/+4
| | | | | This will allow us to answer queries and properly handle animations in the future for fragments generated for pseudo content.
* Propagate text decoration where neededFernando Jiménez Moreno2020-03-231-0/+3
|
* Dump box tree state into json files and display it on layout 2020 viewerFernando Jiménez Moreno2020-02-211-1/+1
|
* Remove the Node type parameter from ContentsAnthony Ramine2019-12-131-1/+3
| | | | We now pass the Node as an argument during DOM traversal in layout.
* Fix a “Accessing content size that was not requested” panicSimon Sapin2019-12-101-1/+1
| | | | | | Percentage `width` are treated as `auto` for the purpose of min/max-content computation, so they also need to be considered when testing “wether width is auto”
* Replace boolean parameters by a new `ContentSizesRequest` enumSimon Sapin2019-12-041-2/+3
|
* Add a `request_content_sizes` parameter to ↵Simon Sapin2019-12-031-0/+25
| | | | `IndependentFormattingContext::construct`
* Un-allow and fix warnings in `components/layout_2020`Simon Sapin2019-12-021-2/+0
|
* Make IndependentFormattingContext a struct that owns stylesSimon Sapin2019-11-261-2/+1
| | | | | | | | … and has a private enum for its contents. Privacy forces the rest of the code to go through methods rather than matching on the enum, reducing accidental layout-mode-specific behavior.
* Import victor's layout system 🍷Anthony Ramine2019-09-111-3/+9
|
* Import files from VictorSimon Sapin2019-09-111-0/+18
https://github.com/SimonSapin/victor/tree/fdb11f3e87f6d2d59170d10169fa6deb94e53b94