Commit graph

35 commits

Author SHA1 Message Date
Andreas Kling
c4826eae4f LibWeb: Rename Layout::BlockBox => BlockContainer
There's a subtle difference here. A "block box" in the spec is a
block-level box, while a "block container" is a box whose children are
either all inline-level boxes in an IFC, or all block-level boxes
participating in a BFC.

Notably, an "inline-block" box is a "block container" but not a "block
box" since it is itself inline-level.
2021-10-06 20:10:36 +02:00
Sam Atkins
e1f3fb0146 LibWeb: Move border-painting code out of Box
The logic here is needed by InlineNode too. Moving it into a
`paint_all_borders()` function makes it available to them both, as well
as anyone else who wants it. :^)
2021-09-19 22:53:35 +02:00
Sam Atkins
abc22b727c LibWeb: Move background painting from Box to its own file
This makes the code accessible to things that aren't a Box, such as
InlineNode.
2021-09-19 22:53:35 +02:00
Sam Atkins
b047c1bc97 LibWeb: Move box-shadow painting out of Box to its own file
This makes the code accessible to things that aren't a Box, such as
InlineNode.
2021-09-19 22:53:35 +02:00
Sam Atkins
aaf12929d5 LibWeb: Extract border-radius normalization code from Box
This is going to be needed by InlineNodes too!

`BorderPainting.{h,cpp}` might not be the best place for it, but it
works for now.
2021-09-19 22:53:35 +02:00
Andreas Kling
19c492e976 LibWeb: Avoid unnecessary padded_rect() call in Box::paint()
We were computing the padded rect of the box during every paint phase,
despite only needing it in the Overlay phase.

Since this is an expensive call, let's take care not to make it
unnecessarily.
2021-09-18 20:07:38 +02:00
Andreas Kling
4e47e6d578 LibWeb: Use floating-point math for border-radius rendering
We're still limited by Gfx::Painter here, but we can at least do most
of the LibWeb things in floating-point math.
2021-09-18 12:21:42 +02:00
Tobias Christiansen
3cc6ffd4a6 LibGfx: Don't crash on request to draw impossible circle segment
The previous VERIFY_NOT_REACHED() could be reached when there were equal
coodinates. This could be the case for a small radius which lead to
rounding making the two coordinates equal.
2021-09-17 23:51:03 +02:00
Andreas Kling
4fcb1be734 LibWeb: Skip rendering box-shadow blur if we don't have memory for it
A slight loss in graphical fidelity is better than not rendering the
page at all.
2021-09-17 13:20:18 +02:00
Andreas Kling
eac31e21f2 LibWeb: Avoid some redundant calls to Layout::Box::absolute_rect()
Computing the absolute rect of a box requires walking the chain of
containing blocks and apply any offsets encountered. This can be slow in
deeply nested box trees, so let's at least avoid doing it multiple times
when once is enough.
2021-09-15 14:18:17 +02:00
Sam Atkins
2844f89a83 LibWeb: Implement "out-of-flow" property of Layout Box
In some situations, a layout box should not participate in the standard
layout process, for example when set to `position: absolute`.
2021-09-15 13:55:25 +02:00
Andreas Kling
e91edcaa28 LibWeb: Rename InitialContainingBlockBox => InitialContainingBlock
The "Box" suffix added nothing here.
2021-09-08 11:27:46 +02:00
Brian Gianforcaro
217179a39f LibWeb: Remove unused header includes 2021-08-01 08:10:16 +02:00
Tobias Christiansen
5745e8e18c LibWeb: Add blurring support to box-shadow
Now the box-shadow-rendering is done by using the new
Gfx::FastBoxBlurFilter. :^)
2021-07-26 17:54:19 +01:00
Tobias Christiansen
5471c87246 LibWeb: Add box-shadow rendering
This patch adds the box-shadow rendering to Boxes. We do parse the
blur-radius of a box-shadow but we don't use it for now as the Filter
in the system don't seem quite powerful enough yet to handle that.
2021-07-24 22:16:48 +02:00
Andreas Kling
ee3a73ddbb AK: Rename downcast<T> => verify_cast<T>
This makes it much clearer what this cast actually does: it will
VERIFY that the thing we're casting is a T (using is<T>()).
2021-06-24 19:57:01 +02:00
Andreas Kling
4190fd2199 LibWeb: Rename Web::Frame to Web::BrowsingContext
Our "frame" concept very closely matches what the web specs call a
"browsing context", so let's rename it to that. :^)

The "main frame" becomes the "top-level browsing context",
and "sub-frames" are now "nested browsing contexts".
2021-05-30 12:39:53 +02:00
Tobias Christiansen
adfdfd6aba LibWeb: Deal with Boxes that have a background, border and -radius
This hack allows for Boxes that have a background to be painted and a
border to accurately paint their border-radii if needed.
For that the box in with the background is drawn is extended to the
bordered_rect. The border is later drawn over this regardless.
Previously when drawing a Box that had all three, background, border
and a border-radius, there could be some white between the filling and
the border.
2021-05-20 22:08:02 +02:00
Tobias Christiansen
7a566e54e5 LibWeb: Introduce struct to hold border radii and normalize once
The struct BorderRadiusData contains the four radii of the box.
In case the specified borders are too large for the dimensions of the
box, they get scaled down.
2021-05-20 22:08:02 +02:00
Tobias Christiansen
c31046d952 LibWeb: Draw rounded corners for the backgrounds of Boxes
Even if the Box doesn't have a border-radius, we'll pass the rendering
of the Box and its corners to the Painter.
2021-05-20 22:08:02 +02:00
Tobias Christiansen
9e04c0598b LibWeb: Basic rendering of border-radius
It supports all four corners.
2021-05-20 22:08:02 +02:00
Tobias Christiansen
d13526e1e7 LibWeb: Handle background-painting of Box in seperate function 2021-05-20 22:08:02 +02:00
Tobias Christiansen
ff0b3518fa LibWeb: Move the painting of the border out of paint()
So other Boxes can override this function.
2021-05-20 22:08:02 +02:00
Timothy Flynn
dba261f79b LibWeb: Propagate body background properties to root HTML element
The Acid1 test has a bit of an unusual background - the html and body
tags have different background colors. Our painting order of the DOM was
such that the body background was painted first, then all other elements
were painted in-phase according to Appendix E of CSS 2.1. So the html
element's background color was painted over the body background.

This removes the special handling of the body background from
InitialContainingBlockBox and now all boxes are painted in-phase. Doing
this also exposed that we weren't handling Section 2.11.2 of the spec;
when the html background is unset, the body's background should be
propagated to the html element.
2021-05-13 16:16:25 +02:00
Egor Ananyin
d2b6148787 LibWeb: Make painting order more spec-compliant
Now our painting order inside stacking contexts is closer to the
algorithm specified by CSS 2.1 (see section 9.9 and Appendix E)
2021-05-07 22:27:48 +02:00
Matthew Olsson
88cfaf7bf0 LibGfx: Unify Rect, Point, and Size
This commit unifies methods and method/param names between the above
classes, as well as adds [[nodiscard]] and ALWAYS_INLINE where
appropriate. It also renamed the various move_by methods to
translate_by, as that more closely matches the transformation
terminology.
2021-05-02 22:48:06 +02:00
Brian Gianforcaro
1682f0b760 Everything: Move to SPDX license identifiers in all files.
SPDX License Identifiers are a more compact / standardized
way of representing file license information.

See: https://spdx.dev/resources/use/#identifiers

This was done with the `ambr` search and replace tool.

 ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-04-22 11:22:27 +02:00
Timothy Flynn
5de0e0068c LibWeb: Support two-value background-repeat
The background-repeat value may be specified as either one- or two-value
identifiers (to be interpreted as horizontal and vertical repeat). This
adds two pseudo-properties, background-repeat-x and background-repeat-y,
to handle this. One-value identifiers are mapped to two-value in
accordance with the spec.
2021-04-05 18:49:04 +02:00
Timothy Flynn
735829f694 LibWeb: Move painting of background images to common location
For now, painting of background color is kept separate. The ICB needs to
perform a "translate" call between painting the color and background,
whereas other divs must not make that call.
2021-04-05 18:49:04 +02:00
Timothy Flynn
fa9ba8bce5 LibWeb: Support rendering background images with 'background-repeat'
Update the painting of background images for both <body> nodes and other
non-initial nodes. Currently, only the following values are supported:
    repeat, repeat-x, repeat-y, no-repeat

This also doesn't support the two-value syntax which allows for setting
horizontal and vertical repetition separately.
2021-04-03 11:24:33 +02:00
Mihai Parparita
c2f3d3afe1 LibWeb: Make CSS background image painting respect destination origin and transparency
It was previously using draw_tiled_bitmap, which always aligns the
tiles with the global origin and does not respect the alpha of the
source. Switch to a new Painter::blit_tiled helper which uses
Painter::blit under the hood, which has more correct behavior.
2021-03-06 14:56:31 +01:00
Andreas Kling
5d180d1f99 Everywhere: Rename ASSERT => VERIFY
(...and ASSERT_NOT_REACHED => VERIFY_NOT_REACHED)

Since all of these checks are done in release builds as well,
let's rename them to VERIFY to prevent confusion, as everyone is
used to assertions being compiled out in release.

We can introduce a new ASSERT macro that is specifically for debug
checks, but I'm doing this wholesale conversion first since we've
accumulated thousands of these already, and it's not immediately
obvious which ones are suitable for ASSERT.
2021-02-23 20:56:54 +01:00
Andreas Kling
543dd54a1d LibWeb: Add bordered_rect() and padded_rect() helpers in Layout::Box 2021-02-22 18:52:58 +01:00
Andreas Kling
794ebb699c LibWeb: Remove low-hanging LibGUI fruit from LibWeb
We'll want to remove the LibGUI dependency from the WebContent process.
This is the first basic step of removing unnecessary LibGUI includes
and swapping out GUI::Painter for Gfx::Painter.
2021-02-10 09:13:29 +01:00
Andreas Kling
13d7c09125 Libraries: Move to Userland/Libraries/ 2021-01-12 12:17:46 +01:00
Renamed from Libraries/LibWeb/Layout/Box.cpp (Browse further)