Commit graph

100 commits

Author SHA1 Message Date
Martin Robinson
77e9e3deba
fonts: Add support for generic font families and font size configuration (#32673)
This adds support for generic font families in Servo and allows for
configuration of them as well as their default font sizes. One
interesting fix here is that now monospace default to 13px, like it does
in other browsers.

In addition to that, this exposes a new interface in Stylo which allows
setting a default style. This is quite useful for fonts, but also for
other kinds of default style settings -- like text zoom.

Fixes #8371.
Fixes #14773.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Mukilan Thiyagarajan <mukilan@igalia.com>
2024-07-08 17:17:48 +00:00
atbrakhi
26c585a0c5
use app unit in box_fragement (#32349) 2024-06-21 14:54:21 +00:00
Martin Robinson
66edef8065
layout: Simplify Contents a little (#32487)
Instead of duplicating some of `NonReplacedContents` in `Contents`,
divide it into either replaced and non-replaced content, since this is
how the layout system processes `Contents` always. In addition, stop
using `TryInto` to match replaced or non-replaced contents, as it is
quite confusing to handle an `Err` as a success case.
2024-06-21 10:13:31 +00:00
Martin Robinson
e74075255b
layout: Flatten inline box storage in InlineFormattingContexts (#32539)
This accomplishes two things:

1. Makes it easier to iterate through all inline formatting context
   items.
2. Will make it possible to easily move back and forth through the tree
   of inline boxes, in order to enable reordering and splitting inline
   boxes on lines -- necessary for BiDi.

Co-authored-by: Rakhi Sharma <atbrakhi@igalia.com>
2024-06-19 08:51:10 +00:00
Mukilan Thiyagarajan
2af6fe0b30
compositor: Move WebRender-ish messages and types to webrender_traits (#32315)
* Move WebRender related types to `webrender_traits`

This refactor moves several WebRender related types
from `compositing_traits`, `script_traits` and `net_traits`
crates to the `webrender_traits` crate.

This change also moves the `Image` type and associated
function out of `net_traits` and into the `pixels` crate.

Co-authored-by: Martin Robinson <mrobinson@igalia.com>
Signed-off-by: Mukilan Thiyagarajan <mukilan@igalia.com>

* Move `script_traits::WebrenderIpcSender` to `webrender_traits::WebRenderScriptApi`

---------

Signed-off-by: Mukilan Thiyagarajan <mukilan@igalia.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
2024-05-20 10:35:18 +00:00
Martin Robinson
f379041597
layout: Add support for <object> with image data URLs (#32069)
This is enough support for `<object>` to get Acid2 working.

Co-authored-by: Oriol Brufau <obrufau@igalia.com>
2024-04-15 20:20:55 +00:00
Martin Robinson
08ef158d4e
script: Split style and layout data in DOM nodes (#31985)
This change splits the style and layout data in DOM nodes that is
populated by style and layout passes. This makes Servo's data design
more like Gecko's. This allows:

1. Removing the various `StyleAndLayout` data structures used by layout.
2. Removing the `GetStyleAndLayoutData` and
   `GetStyleAndOpaqueLayoutData` traits. Accessing style and layout data
   are now just functions on the `LayoutNode` and `ThreadSafeLayoutNode`
   traits.
3. Styling now doesn't populate layout data. This is is postponed until
   layout itself.
4. Allows the DOM wrappers to no longer have to be generic over the
   layout data. This data was already stored using `std::any::Any` and
   the new code just makes layout responsible for downcasting. Cleaning
   up the generic type parameter in the DOM wrappers can happen in a
   followup change.

The main benefit to all of this is that we should be able to remove
unsafe creation of `ServoLayoutNode` in layout and
`TrustedLayoutNodeAddress` entirely, because `ServoLayoutNode` will be
able to be passed directly from script to layout. In addition, this
removes one more abstraction layer from the layout DOM wrappers, making
the code a lot more understandable.

Note: This increases the measured size of DOM types, but the same data
is stored. It's simply that before that data was stored behind a heap
pointer.
2024-04-04 07:56:51 +00:00
Martin Robinson
ad37a54f59
dependencies: Upgrade to WebRender 0.64 (#31486)
This brings the version of WebRender used in Servo up-to-date with Gecko
upstream. The big change here is that HiDPI is no longer handled via
WebRender. Instead this happens via a scale applied to the root layer in
the compositor. In addition to this change, various changes are made to
Servo to adapt to the new WebRender API.

Co-authored-by: Mukilan Thiyagarajan <mukilan@igalia.com>
2024-03-14 17:40:54 +00:00
Martin Robinson
716f4a006d
layout: Propagate overflow values from <body> to root element (#31618)
The specification gives instructions for how these values should be
propagated. The other big changs here is that they aren't applied to the
`<body>`.

 Co-authored-by: Oriol Brufau <obrufau@igalia.com>
2024-03-13 09:17:09 +00:00
eri
b03411f567
clippy: Fix warnings in components/layout_2020 (#31611)
* clippy: fix warnings in components/layout_2020

* fix: review comments
2024-03-11 14:24:33 +00:00
atbrakhi
d5c9e569bf
make size of DefiniteContainingBlock use app units (#31369) 2024-02-17 01:10:14 +00:00
Oriol Brufau
50f56affe3
Lint layout_2020 with clippy (#31169)
cargo clippy --fix -p layout_2020 --allow-dirty --broken-code
2024-01-25 09:03:31 +00:00
Martin Robinson
5c1723c983
rustdoc: Fix many rustdoc errors (#31147)
This fixes many rustdoc errors that occur due to raw URLs in rustdoc
comments as well as unescaped Rust code that should be in backticks.
2024-01-22 13:13:48 +00:00
Martin Robinson
f0b4162328
Add initial support for table box tree construction (#30799)
This is the first part of constructing the box tree for table layout. No
layout is actually done and the construction of tables is now hidden
behind a flag (in order to not regress WPT).  Notably, this does not
handle anonymous table part construction, when the DOM does not reflect
a fully-formed table. That's part two.

Progress toward #27459.

Co-authored-by: Oriol Brufau <obrufau@igalia.com>
Co-authored-by: Manish Goregaokar <manishsmail@gmail.com>
2023-12-05 11:10:45 +00:00
Martin Robinson
8299868bd5
Layout 2020: Rename flow_relative types to Logical... (#30324)
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`.
2023-09-12 07:31:30 +00:00
Samson
aad2dccc9c
Strict import formatting (grouping and granularity) (#30325)
* strict imports formatting

* Reformat all imports
2023-09-11 19:16:54 +00:00
Samson
711dbbd4af
remove extern crate (#30311)
* 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>
2023-09-08 12:11:31 +00:00
Martin Robinson
4f4c2a5922
Remove rayon_croissant and clean up contains_floats (#29960)
Remove rayon_croissant and refactor the way that information about
floats in flows bubbles up. This simplifies the code a good deal and
lets us take advantage of some more optimized functions provided by
rayon. This removes 2 crates from the dependency tree.

In addition, this allows avoiding passing `contains_floats` up from
every box tree construction function. This makes things simpler, but
also opens up the possibility of passing more of these flags up in the
future (such as `contains_counters`).
2023-07-19 07:01:55 +00:00
Martin Robinson
459a7d26aa
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.
2023-06-20 11:44:25 +02:00
Martin Robinson
e563927718 Layout 2020: Move all Fragment code to the fragment_tree directory
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.
2023-06-04 18:12:11 +02:00
Martin Robinson
25f6cc04a2 Do not hoist floated fragments
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>
2023-06-03 06:10:17 +02:00
Patrick Walton
cdec48328e Place floats in layout 2020, but don't flow text around the floats yet.
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.
2023-06-03 06:09:21 +02:00
Martin Robinson
b60e105526 Refactor Layout 2020 layout for a compositor-side scroll tree
This change refactors how layout is done in Layout 2020 in preparation
for a compositor-side scroll tree:

1. Now the SpatialId and ClipId of each fragment is stored separately.
   This will allow storing a scroll node id instead of only the handle
   to the WebRender spatial node.
2. Separate out stacking context tree construction and display list
   building. This change will make it possible to eventually build the
   stacking context tree without the full display list if we find that
   necessary. For instance, this might be useful to cache containing
   block boundaries.
3. Add a `DisplayList` struct that stores both the WebRender display
   list builder and the compositor info. This exposes the API to the
   layout thread for display list building.

In addition, this change adds a lot of missing documentation.  This
should not change behavior.
2023-05-17 10:46:27 +02:00
Martin Robinson
72b5fcd0b6 Combine DOM-related concepts in Layout 2020 into dom.rs 2023-05-13 11:52:59 +02:00
Martin Robinson
e167526618 Better implement getComputedStyle() for positioned insets
The specification dictates quite quite idiosyncratic return values when
querying insets of positioned elements via getComputedStyle(). These
depend on whether or not the elements size was overconstrained. This
change adds a better implementation of that in preparation for returning
proper values for position: sticky.
2023-05-09 12:07:20 +02:00
Martin Robinson
72302e2dae Detect body elements during layout
During layout it is often useful, for various specification reasons, to
know if an element is the `<body>` element of an `<html>` element root. There
are a couple places where a brittle heuristic is used to detect `<body>`
elements. This information is going to be even more important to
properly handle `<html>` elements that inherit their overflow property from
their `<body>` children.

Implementing this properly requires updating the DOM wrapper interface.
This check does reach up to the parent of thread-safe nodes, but this is
essentially the same kind of operation that `parent_style()` does, so is
ostensibly safe.

This change should not change any behavior and is just a preparation
step for properly handle `<body>` overflow.
2023-05-04 10:46:27 +02:00
Martin Robinson
0c13fcb9f2 Rework CB management during stacking context tree construction
Manage containing blocks and WebRender SpaceAndClip during stacking
context tree constuction using the ContainingBlockInfo data structure.
This will allow us to reuse this data structure whenever we traverse the
fragment tree. In addition, StackingContextBuilder is no longer
necessary at all. This change also fixes some bugs where fixed position
fragments were not placed in the correct spatial node. Unfortunately,
these fixes are difficult to test because of #29659.
2023-05-03 10:43:56 +02:00
Martin Robinson
404ee8b984 Fix scrolling from script in Layout 2020
Script will only scroll if it detects that an element has a scrolling
box, so this change adds an implementation of the scroll area query to
Layout 2020. This allows some scrolling tests to start passing.

This change also updates all expected results in css-backgrounds and
cssom-view.
2023-04-25 21:25:01 +02:00
Martin Robinson
9e0b41ebc4 Add support for <iframe> elements for Layout 2020
This change adds support for the <iframe> element to Layout 2020. In
addition, certain aspects of the implementation are made the same
between both layout systems.
2023-04-04 17:49:24 +02:00
yvt
638941ac43 refactor(layout_2020): add depth parameter to the closure passed to FragmentTree::find 2021-06-16 00:56:41 +09:00
bors-servo
53263595f1
Auto merge of #26968 - servo:layout-2020-lazy-content-sizes, r=SimonSapin
Compute content sizes lazily in layout 2020
2020-06-19 13:50:29 -04:00
Anthony Ramine
235df94f2e Compute content sizes lazily in layout 2020 2020-06-18 14:11:02 +02:00
Martin Robinson
f3e373bc62 Add animation and transition support for pseudo-elements
This change extends the DocumentAnimationSet to hold animations for
pseudo-elements. Since pseudo-elements in Servo are not in the DOM like
in Gecko, they need to be handled a bit carefully in stylo.  When a
pseudo-element has an animation, recascade the style. Finally, this
change passes the pseudo-element string properly to animation events.

Fixes: #10316
2020-06-16 16:33:55 +02:00
Martin Robinson
4a3995bb37 Add DocumentAnimationSet and AnimationSetKey
This will be used in order to hold animations for pseudo elements in the
DocumentAnimationSet. Also no longer store the OpaqueNode in the
animation and transition data structures. This is already part of the
DocumentAnimationSet key.
2020-06-15 10:28:30 +02:00
Anthony Ramine
e975d24c4b Store abspos boxes in a RefCell too
We want to mutate them when lazily computing their content sizes, but they
are behind an Arc for the hoisting infra, so it also needs its own layer
of inner mutability.
2020-06-09 15:13:18 +02:00
Martin Robinson
89855afa4d layout_2020: Tag fragments with their pseudo content type
This will allow us to answer queries and properly handle animations in
the future for fragments generated for pseudo content.
2020-06-06 17:25:08 +02:00
Simon Sapin
ec548e849c Flex items in the box tree 2020-06-04 13:19:53 +02:00
Anthony Ramine
a30bdc16dd Reconstruct the box tree incrementally in some case 2020-06-04 10:49:45 +02:00
Martin Robinson
a238597a18 layout_2020: Add support for transitions and animations 2020-05-19 10:02:03 +02:00
Simon Sapin
1f6efbf9e9 Correctly paint the CSS canvas’ background
https://drafts.csswg.org/css-backgrounds/#special-backgrounds

Fixes https://github.com/servo/servo/issues/25559
Closes https://github.com/servo/servo/pull/26121, as it is an alternative.
2020-05-15 13:37:09 +02:00
Simon Sapin
3e8623332b Rewrite handling of pointers to boxes in the DOM tree 2020-05-15 13:25:35 +02:00
Simon Sapin
c43ab0c267 Rename BoxTreeRoot/FragmentTreeRoot to BoxTree/FragmentTree 2020-05-15 13:25:35 +02:00
Simon Sapin
ee62c7f2e4 Set in the DOM the box generated by the root element 2020-05-15 13:25:35 +02:00
Simon Sapin
09dbf91e7b display: contents computes to block on the root element 2020-05-15 13:25:35 +02:00
bors-servo
aa9f16ce45
Auto merge of #26477 - mrobinson:layout-2020-get-computed-value, r=jdm
Add support for getComputedStyle() to layout_2020

These changes add support for `getComputedStyle()` to layout_2020.

---
<!-- 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. -->
2020-05-11 15:57:25 -04:00
Martin Robinson
9c7b1ae715 layout_2020: Add initial support for getComputedStyle
This implementation is more-or-less on par with the one from layout_2013
and in some cases better. There are still some cases where we don't
return the correct "resolved value," but this is enough to test
animations and transitions.
2020-05-11 20:14:01 +02:00
Martin Robinson
a637810df3 layout_2020: Add support for transform-style
This requires creating a matching stacking context for every reference
frame and also properly placing those stacking contexts inside them.
2020-05-11 15:03:29 +02:00
bors-servo
15d8c6058b
Auto merge of #26048 - nox:layout-2020-transparent-data, r=jdm
Give a lifetime parameter to LayoutDom
2020-03-28 13:37:31 -04:00
Martin Robinson
19f4b708b3 layout_2020: Use ArcRefCell to track hoisted fragments
This avoids the use of lookup tables for containing blocks when
constructing the stacking context tree.

This seems to catch some laid-out hoisted fragments that were otherwise
dropped in the previous design. The changes cause one new test to pass
and one to fail. Visual examination of the failing tests reveals that
it's a progression (list markers are appearing when they were previously
not rendered).
2020-03-27 13:02:22 +01:00
bors-servo
4dbe3b30cd
Auto merge of #26037 - mrobinson:arcrefcell-fragment-tree, r=SimonSapin
layout_2020: Use ArcRefCell in the fragment tree

This will allow mutability which is useful for things like animations.

<!-- 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
- [ ] These changes fix #___ (GitHub issue number if applicable)

<!-- Either: -->
- [ ] There are tests for these changes OR
- [x] These changes do not require tests because they 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. -->
2020-03-26 10:23:23 -04:00