Commit graph

78 commits

Author SHA1 Message Date
Aliaksandr Kalenik
87fa1c5e66 Revert "LibWeb: Fix clip of hidden overflow..."
This reverts commit eb1ef59603c13c43b87c099c43c4d118dc8441f6.

The idea of saving clip box to apply it to handle `overflow: hidden`
turned out to break painting if box is painted before it's containing
block (it is possible if box has negative z-index).
2023-02-24 20:55:40 +01:00
Andreas Kling
f11899f885 LibWeb+LibIDL: Fix (or paper over) various const-correctness issues
There's definitely stuff to iterate on here, but this takes care of
making the libraries compile with stricter RP and NNRP.
2023-02-21 00:54:04 +01:00
Sam Atkins
1c77867c78 LibWeb: Port FontCache to new Strings 2023-02-19 00:51:16 +01:00
Aliaksandr Kalenik
ac440e6c0e LibWeb: Scale font size to device pixels 2023-02-11 20:59:13 +00:00
Aliaksandr Kalenik
08f217526a LibWeb: Use rect of containing block instead of parent to clip overflow
Move overflow clipping from `before_children_paint` into separate
method and call this method on containing block instead of parent.

Example that got fixed:
```html
<!DOCTYPE html><html><head><style>
    * {
      border: 2px solid black;
    }
    body {
      overflow: hidden;
    }
    .inner {
      position: absolute;
      width: 100px;
      height: 100px;
      background: lime;
    }
</style></head><body><div class=inner></div>
```
2023-01-25 10:44:58 +01:00
Aliaksandr Kalenik
ee4ba7617c LibWeb: Fix clip of hidden overflow when translated boxes are involved
There is a problem with current approach where overflow clip rectange is
calculated by aggregating intersection of absolute padding boxes of
boxes in containing block chain that resulting rectangle doesn't
respect transform properties.

To solve this problem `PaintableBox` is changed to store clip rectangle
saved from painter because it does respect transform properties of all
previously applied clip rectangles.
2023-01-25 10:44:58 +01:00
Andreas Kling
51555dea7c LibWeb: Make Layout::Node::containing_block() return a Layout::Box
Containing blocks can be formed by boxes that aren't block containers,
so let's make this return a Box and work towards type correctness here.
2023-01-24 11:44:03 +01:00
Aliaksandr Kalenik
802d9336f0 LibWeb: Use CSS Pixels for overflow clip rect 2023-01-23 10:21:23 +01:00
Andreas Kling
4d401bf796 LibWeb: Make the paint tree GC-allocated
This simplifies the ownership model between DOM/layout/paint nodes
immensely by deferring to the garbage collector for figuring out what's
live and what's not.
2023-01-11 12:55:00 +01:00
Sam Atkins
8cc0bdf777 LibWeb: Resolve Lengths to CSSPixels 2023-01-05 17:42:31 +01:00
Sam Atkins
65cdf89a8b LibWeb: Convert Layout Boxes to new pixel units 2023-01-05 17:42:31 +01:00
martinfalisse
d467a0a730 LibWeb: Use the layout_state border values when drawing borders
This will be useful for conditionally drawing borders in the
TableFormattingContext.
2023-01-03 20:02:47 +01:00
Andreas Kling
32e35a02f9 LibWeb: Apply CSS text-transform during layout
Previously we were doing this at the painting stage, which meant that
layout potentially used the wrong glyphs when measuring text.

This would lead to incorrect layout metrics and was visible on the
HTML5Test score display, for example. :^)
2022-12-24 12:27:46 +01:00
Matt Purnell
0bda06c9c5 LibWeb: Don't const_cast layout_box() when calling const functions
layout_box() already has a non-const overload, so we don't need to
const_cast them anymore. This gets rid of 2 FIXMEs. :^)
2022-12-18 12:56:33 +01:00
Sam Atkins
ab49dbf137 LibWeb: Convert Paintable coordinates to new pixel units
This fixes a few sizing issues too. The page size is now correct in most
cases! \o/

We get to remove some of the `to_type<>()` shenanigans, though it
reappears in some other places.
2022-12-14 16:47:57 +00:00
Sam Atkins
1a68a4292d LibWeb: Convert text and text-decoration painting to new pixel units
This does not touch the actual font selection, so the text itself is
still small for now.
2022-12-14 16:47:57 +00:00
Sam Atkins
fb43a71981 LibWeb: Convert shadow painting to new pixel units 2022-12-14 16:47:57 +00:00
Sam Atkins
7c8eecbaa5 LibWeb: Convert backdrop-filter painting to new pixel units 2022-12-14 16:47:57 +00:00
Sam Atkins
0bf4089af9 LibWeb: Convert border painting to new pixel units 2022-12-14 16:47:57 +00:00
Sam Atkins
0233627545 LibWeb: Convert background painting to new pixel units 2022-12-14 16:47:57 +00:00
Sam Atkins
4440af0870 LibWeb: Split PaintContext::viewport_rect() into device/css variants
For now, everyone uses `device_viewport_rect()`, until I convert them.
2022-12-14 16:47:57 +00:00
Andreas Oppebøen
4b12def5d8 LibWeb: Use start-of-line in hit test of position directly to the left
This fixes a bug where selecting from the left within a line would
begin the selection from the right, as pointed out by @AtkinsSJ in
https://github.com/SerenityOS/serenity/pull/16245#pullrequestreview-1197595820
2022-12-10 13:19:49 +01:00
Andreas Oppebøen
9cab5059f8 LibWeb: Use correct end-of-fragment node index for HitTestResult
The indexes are into the _node_, not in the fragment, so when a node is
split into multiple fragments, simply taking the length of the fragment
is incorrect. This patch corrects this mistake.
2022-12-10 13:19:49 +01:00
Sam Atkins
3c7bd5a317 LibWeb+WebContent+headless-browser: Use CSSPixels for PageClient events
...and also for hit testing, which is involved in most of them.

Much of this is temporary conversions and other awkwardness, which
should resolve itself as the rest of LibWeb is converted to these new
types. Hopefully. :thousandyakstare:
2022-12-10 12:03:19 +00:00
MacDue
1574f2c3f6 Meta+Userland: Pass Gfx::FloatSize by value
Just two floats like Gfx::FloatPoint.
2022-12-07 11:48:27 +01:00
MacDue
e011eafd37 Meta+Userland: Pass Gfx::FloatPoint by value
Just a small 8-byte value like Gfx::IntPoint.
2022-12-07 11:48:27 +01:00
MacDue
7be0b27dd3 Meta+Userland: Pass Gfx::IntPoint by value
This is just two ints or 8 bytes or the size of the reference on
x86_64 or AArch64.
2022-12-07 11:48:27 +01:00
Linus Groh
57dc179b1f Everywhere: Rename to_{string => deprecated_string}() where applicable
This will make it easier to support both string types at the same time
while we convert code, and tracking down remaining uses.

One big exception is Value::to_string() in LibJS, where the name is
dictated by the ToString AO.
2022-12-06 08:54:33 +01:00
Andreas Oppebøen
ad25a415ae LibWeb: Return the position at end-of-line in TextCursor hit-test
When starting to drag the cursor below the text, we would start the
selection from the closest point in the line above in the last
fragment. This is not the behavior seen in other browsers, and it
causes weird behavior when the cursor is to the left of the last
fragment, for instances when trying to select with the text
`before <span>middle</span> after`.

By starting the selection from the _end_ of the last fragment,
including the line end character, selection behavior is similar to
that of other browsers.
2022-11-29 13:52:01 +00:00
Aliaksandr Kalenik
f3d57e1157 LibWeb: Clip hidden overflow by absolute rect of containing block
Since handling overflow: hidden in PaintableBox::before_children_paint
while following paint traversal order can't result in correctly computed
clip rectangle for elements that create their own stacking context
(because before_children_paint is called only for parent but overflow:
hidden can be set somewhere deeper but not in direct ancestor), here
introduced new function PaintableBox::clip_rect() that computes clip
rectangle by looking into containing block.

should_clip_overflow flag that disables clip for absolutely positioned
elements in before_children_paint and after_children_paint is removed
because after changing clip rectangle to be computed from not parent
but containing block it is not needed anymore (absolutely positioned
item is clipped if it's containing block has hidden overflow)
2022-11-15 22:53:47 +01:00
Luke Wilde
bee4df7bfb LibWeb: Skip hit testing a line box fragment if it has no container
The container appears to be null for certain elements such as the
"update your browser" box when clicking on the document during certain
parts of loading. Skipping it works fine, but should obviously be
fixed, so it prints a debug output when this happens.
2022-11-07 14:10:41 +01:00
Andreas Kling
4de3449ad6 LibWeb: Recurse into block-level children when hit testing a box
Otherwise, we always say you hit the parent, even when you're really
clicking on a child that's visually above the parent.
2022-11-04 10:38:00 +01:00
Andreas Kling
268b9c5d90 LibWeb: Make the layout tree GC-allocated
This removes a set of complex reference cycles between DOM, layout tree
and browsing context.

It also makes lifetimes much easier to reason about, as the DOM and
layout trees are now free to keep each other alive.
2022-10-20 15:16:23 +02:00
MacDue
4507920187 LibWeb: Fix position: fixed canvases/images disappearing when scrolling
This fixes the Serenity logo vanishing after scrolling on the 4th
birthday post.

The previous check did not account for any translation in the painter.
This now uses the painter's clip rect and translation to work out
if a rect is visible. It also makes use of `absolute_paint_rect()`
rather than `absolute_rect()` which can account for things like
box-shadows.
2022-10-13 11:16:27 +02:00
MacDue
8967fe9d92 LibWeb: Add PaintableBox::absolute_paint_rect()
This method returns the total area this element will paint to.
Currently, this just means accounting for box-shadows, though
there are likely more effects that need to be accounted for here.
2022-09-25 18:37:31 +02:00
Andreas Kling
e72896e35e LibWeb: Get default fonts via Platform::FontPlugin
Instead of asking Gfx::FontDatabase for the "default font" and the
"default fixed-width font", we now proxy those requests out via
the Platform::FontPlugin. This will allow Ladybird to use other default
fonts as fallback.
2022-09-17 21:27:32 +02:00
MacDue
011439d3e3 LibWeb: Paint backdrop-filter effects!
This implements all the filters other than `saturate()`,
`hue-rotate()`, and `drop-shadow()`.

There are still a lot of FIXMEs to handle in the actual implementation
though, particularly around supporting transforms, but this handles
the most common use cases :^)
2022-09-16 10:50:48 +01:00
Andreas Kling
63c727a4a3 LibWeb: Don't clip to containing block when painting abspos descendants 2022-09-14 00:09:49 +02:00
MacDue
1473842b56 LibWeb: Follow image-rendering when painting image style values 2022-08-10 19:39:07 +02:00
MacDue
038017ce11 LibWeb: Enable CSS clip for position: fixed elements
This fixes the clip-absolute-positioned-002 web platform test.
2022-08-08 14:03:29 +02:00
Tom
5049a56d96 LibWeb: Implement clip property
Implement clip when it is defined in the css property 'clip' as a rect
according to spec; only when the div is absolutely positioned.
2022-08-07 22:40:11 +02:00
MacDue
b68f48eb71 LibWeb: Shrink the inner border radii to accommodate the border widths
This fixes the shape of the subreddit logo on new reddit.
2022-07-26 23:56:29 +01:00
MacDue
f079214b18 LibWeb: Apply overflow: hidden to all (relevant) child paint phases
Previously, before/after_children_paint() was only called for the
"Foreground" paint phase, this meant the backgrounds and other
features of child nodes of a element with overflow: hidden were
not clipped.
2022-07-19 15:00:59 +02:00
MacDue
f283e0ddc5 LibWeb: Support overflow: hidden with a border-radius
Note: With this change the border-radius is clipped if ethier the
overflow-x or overflow-y is hidden (it is a little unclear what
happens if just one is set, but it seems like most browsers
treat one set + border-radius the same as if overflow: hidden
was set).
2022-07-04 23:09:06 +02:00
MacDue
2ceb143571 LibWeb: Use padding box for clipping overflow
The padding box should be used otherwise the content can overflow
on to the boxes borders.
2022-07-04 23:09:06 +02:00
MacDue
97e2e40e4c LibWeb: Fix off-by-one shadow position on non-integer positioned boxes
This fixes a issue due to the background/border painting using
.to_rounded<int>() to get an IntRect, but shadow painting was using
enclosing_int_rect().

enclosing_int_rect() uses some floors/ceils and does not always match
.to_rounded<int>().
2022-06-30 11:16:22 +02:00
MacDue
08baeb1e7d LibWeb: Pass border radii data to shadow painting
This is not used yet, but will be needed for painting shadows on
elements that have a border-radius.
2022-06-23 19:13:24 +01:00
MacDue
9e71fa9aa7 LibWeb: Bring border painting much closer to the spec/other browsers
This commit adds some much nicer border painting, which now supports:

 - Elliptical corners
 - Blending between different border thicknesses, with rounded corners
 - Anti-aliasing

There are some little TODOs left to tackle:

 - Painting the corners with line styles other than solid
 - Blending between colors on the corners (see comments)

The painting requires allocating a small bitmap, that only fits the
corners (so in most cases this is very small).

This bitmap is then cached so for all paints but the first there will
be no further allocations.
2022-06-14 00:25:12 +01:00
MacDue
0e7aa1e98c LibWeb: Add flag to normalize border radii to width only
This is needed to avoid issues (such as overlapping curves) for outline
border radii, which do not currently support elliptical corners.
2022-06-13 09:43:45 +01:00
MacDue
28c78b45ca LibWeb: Keep both horizontal and vertical border radii till painting 2022-06-13 09:43:45 +01:00