Commit graph

8835 commits

Author SHA1 Message Date
Andreas Kling
b981e6f7bc LibWeb: Avoid many style invalidations on DOM attribute mutation
Many times, attribute mutation doesn't necessitate a full style
invalidation on the element. However, the conditions are pretty
elaborate, so this first version has a lot of false positives.

We only need to invalidate style when any of these things apply:

1. The change may affect the match state of a selector somewhere.
2. The change may affect presentational hints applied to the element.

For (1) in this first version, we have a fixed list of attribute names
that may affect selectors. We also collect all names referenced by
attribute selectors anywhere in the document.

For (2), we add a new Element::is_presentational_hint() virtual that
tells us whether a given attribute name is a presentational hint.

This drastically reduces style work on many websites. As an example,
https://cnn.com/ is once again browseable.
2024-12-24 17:17:09 +01:00
Andrew Kaster
44e3817219 LibWeb: Add WebAssembly.Global and exports support for global instances 2024-12-24 15:20:28 +01:00
Shannon Booth
910ff8b694 LibWeb/HTML: Consider <a> all-named elements instead of <link>
Leaving only the unimplemented legacy [[Call]] override funkiness
of HTMLAllCollection left not passing in the WPT tests.
2024-12-23 21:19:08 +01:00
Andreas Kling
d5bbf8dcf8 LibWeb: Do lighter style invalidation for style attribute changes
When the `style` attribute changes, we only need to update style on the
element itself (unless there are [style] attribute selectors somewhere).

Descendants of the element don't need a full style update, a simple
inheritance propagation is enough.
2024-12-23 17:05:09 +01:00
Andreas Kling
6983c65c54 LibWeb: Collect interesting document-wide insights about CSS selectors
Starting out with these two things:
- Whether any :has() selectors are present
- The set of all names referenced by attribute selectors
2024-12-23 17:05:09 +01:00
Andreas Kling
dc8343cc23 LibWeb: Add mechanism to invalidate only inherited styles
We can now mark an element as needing an "inherited style update" rather
than a full "style update". This effectively means that the next style
update will visit the element and pull all of its inherited properties
from the relevant ancestor element.

This is now used for descendants of elements with animated style.
2024-12-23 17:05:09 +01:00
Andreas Kling
92ac702c0c LibWeb: Always note whether a CSS property was inherited
This will be relevant when we start recomputing inherited style only.
2024-12-23 17:05:09 +01:00
sideshowbarker
966c68ae0e LibWeb: Align accname alt-vs-title behavior w/ HTML-AAM spec & WPT tests
The https://wpt.fyi/results/accname/name/comp_tooltip.tentative.html
test was recently added by moving an existing subtest out from the test
at https://wpt.fyi/results/accname/name/comp_tooltip.html, and changing
the test expectations to match the HTML-AAM spec requirements at
https://w3c.github.io/html-aam/#img-element-accessible-name-computation.
See https://github.com/web-platform-tests/wpt/pull/49552.

So this code change updates Ladybird to match the updated WPT test
expectations — and to match the existing HTML-AAM spec requirements.
2024-12-23 14:01:37 +01:00
Ali Mohammad Pur
50733c564c LibRegex: Use the *actually* correct repeat start offset for Repeat
Fixes #2931 and various frequent crashes.
2024-12-23 13:13:52 +01:00
devgianlu
89061dd3c4 LibCrypto: Replace all hashes implementation with OpenSSL
This required multiple changes:
- Make hashes non-copiable because they contain a heap allocated pointer
- Reference classes via `NonnullOwnPtr` only (they are non-copiable)
- Drop all existing hashes implementations
- Use the `OpenSSLHashFunction` base class to implement the same hashes

I was not able to come up with a way to divide this commit into multiple
without increasing the amount of changes.

Nothing breaks with this commit!
2024-12-22 18:53:45 +01:00
devgianlu
2d799727e8 LibCrypto: Introduce utility class for OpenSSL backed hashes
This abstract class allows implementing hashes backed by OpenSSL with
very few lines of code, see next commit.
2024-12-22 18:53:45 +01:00
devgianlu
002a93a33c LibCrypto: Link with OpenSSL
Add OpenSSL with vcpkg and link with LibCrypto using CMake.

Also added a placeholder GN setup.
2024-12-22 18:53:45 +01:00
Pavel Shliak
b6561f5e2b LibWeb: Make is_identifier always return false the simple way 2024-12-22 12:33:41 +01:00
Pavel Shliak
d6466da4db LibWeb: Correct interception state assertion logic
The previous VERIFY statement incorrectly asserted that the
interception state was not "committed" or "scrolled". Updated
the condition to ensure the interception state is either
"committed" or "scrolled" as intended.
2024-12-22 12:33:41 +01:00
Pavel Shliak
fa02d94d30 LibTLS: Remove unreachable buffer length check
Refer to the while condition
2024-12-22 12:33:41 +01:00
Pavel Shliak
811d5a5c3e LibRegex: Remove duplicated condition 2024-12-22 12:33:41 +01:00
Pavel Shliak
7dd7f77219 LibRegex: Remove duplicated assignments 2024-12-22 12:33:41 +01:00
Sam Atkins
349caecc18 LibWeb/CSS: Use fetch for CSS import rules
This still has a few FIXMEs, but it's a ResourceLoader use gone! :^)
2024-12-22 12:30:09 +01:00
Sam Atkins
a4db7e9e23 LibWeb: Add method for "is CORS-same-origin" 2024-12-22 12:30:09 +01:00
Sam Atkins
ae943965dc LibWeb/CSS: Implement "fetch a style resource" algorithm 2024-12-22 12:30:09 +01:00
Sam Atkins
00948c4746 LibWeb/CSS: Expose CSSStyleSheet's origin clean flag 2024-12-22 12:30:09 +01:00
Andreas Kling
74469a0c1f LibWeb: Make CSS::ComputedProperties GC-allocated 2024-12-22 10:12:49 +01:00
Andreas Kling
c1cad8fa0e LibWeb: Rename CSS::StyleProperties => CSS::ComputedProperties
Now that StyleProperties is only used to hold computed properties, let's
name it ComputedProperties.
2024-12-22 10:12:49 +01:00
Andreas Kling
ed7f4664c2 LibWeb: Split StyleComputer work into two phases with separate outputs
Before this change, StyleComputer would essentially take a DOM element,
find all the CSS rules that apply to it, and resolve the computed value
for each CSS property for that element.

This worked great, but it meant we had to do all the work of selector
matching and cascading every time.

To enable new optimizations, this change introduces a break in the
middle of this process where we've produced a "CascadedProperties".
This object contains the result of the cascade, before we've begun
turning cascaded values into computed values.

The cascaded properties are now stored with each element, which will
later allow us to do partial updates without re-running the full
StyleComputer machine. This will be particularly valuable for
re-implementing CSS inheritance, which is extremely heavy today.

Note that CSS animations and CSS transitions operate entirely on the
computed values, even though the cascade order would have you believe
they happen earlier. I'm not confident we have the right architecture
for this, but that's a separate issue.
2024-12-22 10:12:49 +01:00
Jelle Raaijmakers
4d9f17eddf LibGfx+LibWeb: Draw glyph runs with subpixel accuracy
This improves the quality of our font rendering, especially when
animations are involved. Relevant changes:

  * Skia fonts have their subpixel flag set, which means that individual
    glyphs are rendered at subpixel offsets causing glyph runs as a
    whole to look better.

  * Fragment offsets are no longer rounded to whole device pixels, and
    instead the floating point offset is kept. This allows us to pass
    through the floating point baseline position all the way to the Skia
    calls, which already expected that to be a float position.

The `scrollable-contains-table.html` ref test needed different table
headings since they would slightly inflate the column size in the test
file, but not the reference.
2024-12-21 23:09:52 +01:00
Ali Mohammad Pur
e32a9b2c6f LibWeb/WebAssembly: Use wasm funcaddr of exported functions on import
Previously this was proxying the call through javascript, which lead to
unexpected crashes when functions returned things that js-api did not
like.
This commit also adds in the spec comments and fixes a few inaccuracies
that were present in the process.
2024-12-21 20:16:12 +01:00
Jelle Raaijmakers
c0285f4a7e LibWeb: Do not require visible nodes in the wrap editing algorithm
The spec doesn't say they should exist, so we should not
`VERIFY_NOT_REACHED()` when they don't. Prevents a crash in the WPT
`editing/event.html` tests.
2024-12-21 19:15:58 +01:00
Jelle Raaijmakers
c093c895da LibWeb: Implement step 15 of the editing delete action 2024-12-21 19:15:58 +01:00
Jelle Raaijmakers
30a3fe8387 LibWeb: Remove unnecessary condition from editing delete action 2024-12-21 19:15:58 +01:00
Jelle Raaijmakers
ff25d66dae LibWeb: Prevent potential null deref in editing delete action 2024-12-21 19:15:58 +01:00
Jelle Raaijmakers
a7c75f6fdb LibWeb: Update CSS resolved values spec link to editor's draft URL 2024-12-21 19:15:58 +01:00
Jelle Raaijmakers
e6631a4216 LibWeb: Add concept of boundary point to DOM::AbstractRange
This makes comparing the relative position of boundary points a bit
nicer when one of the boundary points is the range's start or end.
2024-12-21 19:15:58 +01:00
Jelle Raaijmakers
a3b3f2f30d LibWeb: Prevent null deref in the "restore the values of nodes" algo 2024-12-21 19:15:58 +01:00
Jelle Raaijmakers
c90c5aad29 LibWeb: Implement the "record current states and values" Editing algo 2024-12-21 19:15:58 +01:00
Jelle Raaijmakers
2c51ed8dec LibWeb: Rework obtaining resolved styles in the Editing API
The algorithm referenced to in the Editing spec whenever they talk about
obtaining the "resolved" style or value is actually implemented in
ResolvedCSSStyleDeclaration, so use that instead of going directly to
the computed styles.
2024-12-21 19:15:58 +01:00
Jelle Raaijmakers
433c19c1ed LibWeb: Lay out CommandDefinitions for Editing API a bit nicer
No functional changes.
2024-12-21 19:15:58 +01:00
Jelle Raaijmakers
2d130ffad4 LibWeb: Make new_container in insertParagraph command a GC::Ref
This value will never be null.
2024-12-21 19:15:58 +01:00
Jelle Raaijmakers
5e2cb00f75 LibWeb: Update active range after updating selection in insertParagraph
We were using an old range after collapsing the selection. Fixes 3 WPT
subtests in `editing/run`.
2024-12-21 19:15:58 +01:00
Jelle Raaijmakers
2052792663 LibWeb: Use correct boundaries in Selection::collapse_to_start/end()
We were using the anchor_node() as the boundary point node when
collapsing a selection, but the spec tells us to use the start and end
boundary point nodes.
2024-12-21 19:15:58 +01:00
Sam Atkins
eb11c35640 LibWeb/CSS: Use CSSNumericType for CalculationResult's numeric type
When we originally implemented calc(), the result of a calculation was
guaranteed to be a single CSS type like a Length or Angle. However, CSS
Values 4 now allows more complex type arithmetic, which is represented
by the CSSNumericType class. Using that directly makes us more correct,
and allows us to remove a large amount of now ad-hoc code.

Unfortunately this is a large commit but the changes it makes are
interconnected enough that doing one at a time causes test
regressions.

In no particular order:

- Update our "determine the type of a calculation" code to match the
  newest spec, which sets percent hints in a couple more cases. (One of
  these we're skipping for now, I think it fails because of the FIXMEs
  in CSSNumericType::matches_foo().)
- Make the generated math-function-parsing code aware of the difference
  between arguments being the same type, and being "consistent" types,
  for each function. Otherwise those extra percent hints would cause
  them to fail validation incorrectly.
- Use the CSSNumericType as the type for the CalculationResult.
- Calculate and assign each math function's type in its constructor,
  instead of calculating it repeatedly on-demand.

The `CalculationNode::resolved_type()` method is now entirely unused and
has been removed.
2024-12-21 18:14:28 +01:00
Sam Atkins
8d40550478 LibWeb/CSS: Bring CSSNumericType algorithms up to date with spec
Took the opportunity to pull out a helper function for
entry_with_value_1_while_all_others_are_0(), too.

A couple of these require us to have extra contextual information about
what type percentages should resolve to. Until we have that available,
these are left as FIXMEs with a rough approximation.
2024-12-21 18:14:28 +01:00
Sam Atkins
0d19007cb5 LibWeb/CSS: Make CSSNumericType dump() infallible
This is a remnant of the tiny-OOM-propagation party.
2024-12-21 18:14:28 +01:00
Sam Atkins
9cbd08a330 LibWeb/CSS: Implement "consistent type" concept on CSSNumericType 2024-12-21 18:14:28 +01:00
Sam Atkins
2192868a0e LibWeb/CSS: Remove unused ProductOperation enum 2024-12-21 18:14:28 +01:00
Sam Atkins
0149f7d4e4 LibWeb/CSS: Remove unnecessary CalculatedStyleValue const-casts 2024-12-21 18:14:28 +01:00
Sam Atkins
69a0f28d04 Revert "LibWeb/CSS: Rename CalculatedStyleValue -> CSSMathValue"
This reverts commit 76daba3069.

We're going to need separate types for the JS-exposed style values, so
it doesn't make sense for us to match their names with our internal
types.
2024-12-21 18:14:28 +01:00
Aliaksandr Kalenik
30d915c361 LibGfx+LibWeb: Specify bottom left origin for WebGL's PaintingSurface
By doing that we eliminate the need for the vertical flip flag.

As a side effect it fixes the bug when doing:
`canvasContext2d.drawImage(canvasWithWebGLContext, 0, 0);`
produced a flipped image because we didn't account for different origin
while serializing PaintingSurface into Gfx::Bitmap.

Visual progress on https://ciechanow.ski/curves-and-surfaces/
2024-12-20 20:47:45 +01:00
Sam Atkins
28388f1fd2 LibWeb/CSS: Don't overwrite active font load when requesting a pt size
start_loading_next_url() is a no-op if there's a pending resource load,
but not if that resource load has successfully loaded already. There is
a delay between the font resource loading, and it being processed into
a vector font. Calling font_with_point_size() in that gap would
previously erase the previously-loaded font, if the font had multiple
URLs to choose from.

This fixes the icon font on mods.factorio.com :^)
2024-12-20 18:19:37 +01:00
Feng Yu
b3edbd7bf2 LibWeb: Implement the ClipboardItem API
Spec: https://w3c.github.io/clipboard-apis/#clipboard-item-interface
2024-12-20 15:29:18 +00:00
Gingeh
bdd6729d78 LibWeb: Use paintables when calculating mouse event offset 2024-12-20 15:50:41 +01:00