Commit Graph

37 Commits

Author SHA1 Message Date
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
Karol Kosek
ae28e3ff5c LibWeb: Use Unicode data for CSS text-transform property
Previously it was only transforming ASCII characters.
2022-05-04 23:21:34 +02:00
Sam Atkins
7c91fda088 LibWeb: Allow multiple text-decoration-lines
The spec grammar for `text-decoration-line` is:

`none | [ underline || overline || line-through || blink ]`

Which means that it's either `none`, or any combination of the other
values. This patch makes that parse for `text-decoration-line` and
`text-decoration`, stores the results as a Vector, and adjusts
`paint_text_decoration()` to run as a loop over all the values that are
provided.

As noted, storing a Vector of values is a bit wasteful, as they could be
stored as flags in a single `u8`. But I was getting too confused trying
to do that in a nice way.
2022-04-14 21:54:10 +02:00
Karol Kosek
119873b822 LibWeb: Make default text-decoration-thickness a fraction of font height
Previously the default was always 1px, which didn't look great on higher
font sizes.

This changes the default thickness to one-tenth to the font height. The
one-tenth part was chosen arbitrarily, but I think it does the job
pretty well. :^)
2022-04-04 23:44:04 +01:00
Idan Horowitz
086969277e Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
Andreas Kling
6a4247bee9 LibWeb: Use more precise font metrics when doing inline layout
We now position inline-level boxes based on ascent and descent metrics
from the font in use. This makes our basic text layouts look a lot more
like those produced by other browsers. :^)

I've tried to match the terminology used by the CSS Inline Layout spec.

This will regress Acid2 a little bit, and probably various other sites,
but on the whole it's the direction we should be heading, so let's go.
2022-03-30 01:12:44 +02:00
Andreas Kling
fae8fde913 LibWeb: Draw inspector overlay label with default font 2022-03-30 00:57:15 +02:00
Andreas Kling
1c88536298 LibWeb: Use the new Gfx::Painter::draw_text_run() API for drawing text
This avoids a bunch of unnecessary work in Painter which not only took
time, but sometimes also led to alignment issues. draw_text_run() will
draw the text where we tell it, and that's it.
2022-03-30 00:57:15 +02:00
Andreas Kling
0de488749f LibWeb: Use rounding instead of enclosing_int_rect() when painting
By using enclosing_int_rect(), borders and backgrounds of boxes were
sometimes 1 pixel off, making things slightly larger than they should
be. Fix this by using to_rounded() instead of enclosing_int_rect().

There's definitely more of these type of issues lurking in the code,
and we'll get to them in time.
2022-03-29 16:35:46 +02:00
Andreas Kling
c49c036c84 LibWeb: Stop allowing position:relative to affect layout
Relatively positioned boxes should not affect the *layout* of their
siblings. So instead of applying relative inset as a layout-time
translation on the box, we now perform the adjustment at the paintable
level instead.

This makes position:relative actually work as expected, and exposes some
new bugs we need to take care of for Acid2. :^)
2022-03-27 18:16:08 +02:00
Andreas Kling
b0208f38f6 LibWeb: Use Gfx::Font::pixel_size() when we want pixel metrics
This gives us consistent results with both bitmap and scalable fonts.
2022-03-27 01:14:56 +01:00
Linus Groh
9bc7912f84 LibWeb: Paint the focus outline using Painter::draw_focus_rect()
Now it actually looks like a classic focus outline and not some
misplaced border :^)
2022-03-26 01:35:39 +00:00
Linus Groh
642491fc74 LibWeb: Paint the focus outline actually *outside* the element
Instead of using the absolute_rect(), use absolute_border_box_rect() -
at least for PaintableBox - and inflate it by 2px on each side.

This looks much nicer for text input elements, especially when they have
padding, which would be applied outside the focus rect previously.
2022-03-26 01:35:39 +00:00
Andreas Kling
d5aca1c6c4 LibWeb: Treate SVG paintable coordinates as relative to <svg> element
Normally, paintable coordinates are relative to the nearest containing
block, but in the SVG case, since <svg> doesn't form a containing block,
we have to specialize the computation of SVGPaintable::absolute_rect().
2022-03-24 18:14:01 +01:00
Sam Atkins
5aad32b504 LibWeb: Implement text-shadow painting
We don't yet take the spread-distance parameter into account, since we
don't have a way to "inflate" the text shadow.

Also, I'm not sure if we need to inflate the shadow slightly anyway.
Blurred shadows of our pixel fonts seem very faint. Part of this is
that a blur of < 3px does nothing, see #13231, but even so we might
want to inflate it a little.
2022-03-24 18:08:34 +01:00
Sam Atkins
1094654adc LbWeb: Rename BoxShadowFoo => ShadowFoo
The `text-shadow` property is almost identical to `box-shadow`:
> Values are interpreted as for box-shadow [CSS-BACKGROUNDS-3].
> (But note that the inset keyword are not allowed.)

So, let's use the same data structures and parsing code for both. :^)
2022-03-24 18:08:34 +01:00
Andreas Kling
196a3eb239 LibWeb: Ignore invisible boxes and stacking contexts during hit testing 2022-03-21 15:43:37 +01:00
Andreas Kling
01662b2320 LibWeb: Remove now-unused PaintableBox::for_each_child_in_paint_order() 2022-03-21 14:57:00 +01:00
Andreas Kling
a779ace6a1 LibWeb: Don't compute fragment absolute rect twice while hit testing 2022-03-21 13:03:33 +01:00
Andreas Kling
996f3228a2 LibWeb: Fix O(n^2) traversal in hit testing
We already walk the entire paint tree within each stacking context in
the main hit testing function (StackingContext::hit_test()), so there's
no need for each individual paintable to walk its own children again.

By not doing that, we remove a source of O(n^2) traversal which made hit
testing on deeply nested web pages unbearably slow.
2022-03-21 13:03:33 +01:00
Andreas Kling
0ba785894c LibWeb: Make hit testing functions return Optional<HitTestResult>
Using "HitTestResult with null paintable" as a way to signal misses was
unnecessarily confusing. Let's use Optional instead. :^)
2022-03-21 13:03:33 +01:00
Andreas Kling
59afdb959f LibWeb: Build stacking context tree lazily
There's no actual need to build the stacking context tree before
performing layout. Instead, make it lazy and build the tree when it's
actually needed for something.

This avoids a bunch of work in situations where multiple synchronous
layouts are forced (typically by JavaScript) without painting or hit
testing taking place in between.

It also opens up for style invalidations that only target the stacking
context tree.
2022-03-21 13:03:33 +01:00
Andreas Kling
8cc757b92b LibWeb: Always call Layout::Box::did_set_rect()
Since paintables have a default content size of 0x0, we were neglecting
to notify the corresponding layout node about size changes, if the used
content size came out to 0x0.

This fixes an issue where resizing an iframe to 0x0 didn't take effect.
2022-03-20 19:03:43 +01:00
Simon Wanner
48efdaa8c4 LibWeb: Update hit_test for CSS Transforms
This now also takes a FloatPoint instead of an IntPoint to avoid
excessive rounding when multiple transforms apply on top of each other.
2022-03-18 18:51:42 +01:00
Andreas Kling
15dc48b431 LibWeb: Make PaintableBox::enclosing_stacking_context() cheaper
No need to call the expensive establishes_stacking_context() here, as
we've already built the stacking context tree and can simply test for
the presence of existing stacking contexts.
2022-03-18 15:18:48 +01:00
Andreas Kling
be5f0b5ac4 LibWeb: Move text fragment painting to PaintableWithLines
All the other painting code has moved to paintables already.
2022-03-16 23:13:05 +01:00
Andreas Kling
b14c6eaef3 LibWeb: Let paintables cache their containing block and absolute rect
The absolute rect of a paintable is somewhat expensive to compute. This
is because all coordinates are relative to the nearest containing block,
so we have to traverse the containing block chain and apply each offset
to get the final rect.

Paintables will never move between containing blocks, nor will their
absolute rect change. If anything changes, we'll simpl make a new
paintable and replace the old one.

Take advantage of this by caching the containing block and absolute rect
after first access.
2022-03-12 00:39:31 +01:00
Andreas Kling
5779a910e5 LibWeb: Move hit testing to the painting tree 2022-03-11 00:21:49 +01:00
Andreas Kling
ba606d9057 LibWeb: Move PaintingBox to its own .cpp and .h files 2022-03-11 00:21:49 +01:00