Commit graph

59964 commits

Author SHA1 Message Date
Nico Weber 290c9541de Tests/LibPDF: Add a test for resolving indirect refs during parsing
This test uses a JBIG2Globals with an indirect reference,
and contains an indirect reference for a stream length.
When we parse the main JBIG2 image's stream, we unfilter
its data, which causes these two indirect references to
be resolved during parsing.

I started with the output of

    Meta/jbig2_to_pdf.py -o foo.pdf \
        Tests/LibGfx/test-inputs/jbig2/bitmap.jbig2

and then manually added a

    /DecodeParms <</JBIG2Globals 6 0 R>>

entry pointing to an empty stream, and made that new stream
object's length an indirect reference too for good measure.

I used `mutool clean` to fix up offsets a bit. But that also
removes the indirect reference for a stream's length, so I
manually put that back in and adjusted the offset to the last
object in the xref table and the startxref value.
2024-03-19 19:20:01 -04:00
Nico Weber 495aaa295c LibPDF: Add some logging behind PDF_DEBUG
I've added these two lines a bunch of times by now. Let's check
them in. If they turn out to be annoying, we can remove them again.
2024-03-19 19:20:01 -04:00
Andreas Kling f58ca99a66 LibWeb: Parse the ::backdrop pseudo element
We don't do anything with this yet, but let's at least not reject
selectors with ::backdrop in the parser.
2024-03-19 20:59:41 +01:00
Andreas Kling 6bb4a2bfaa LibWeb: Let HTMLCollection cache its element list
Use the new DOM tree version mechanism to allow HTMLCollection to
remember its internal list of elements instead of rebuilding it on
every access.

This avoids thousands of full DOM walks while loading our GitHub repo.

~15% speed-up on jQuery subtests in Speedometer 3.0 :^)
2024-03-19 20:59:36 +01:00
Andreas Kling cf60f52a78 LibWeb: Add DOM tree version counter
This patch adds a u64 version counter to DOM::Document that increments
whenever the tree structure changes (via node insertion or removal),
or an element attribute is changed somehow.

This will be used as a crude invalidation mechanism for HTMLCollection
to cache its elements.
2024-03-19 20:59:36 +01:00
Aliaksandr Kalenik cf7c933312 LibWeb: Add fast path to calculate invalidations for animated css props
- Compare only the animated properties
- Clone only the hash map containing animated properties, instead of
  the entire StyleProperties.

Reduces `KeyframeEffect::update_style_properties()` from 10% to 3% in
GitHub profiles.
2024-03-19 17:30:34 +01:00
Andreas Kling ce2bfb4a12 LibWeb: Make CSSStyleRule::declaration() return a more specific type
This removes the need for some hot verify_casts in StyleComputer.
2024-03-19 16:48:22 +01:00
Andreas Kling 7c9368f402 LibWeb: Support most simple pseudo classes in the fast selector matcher
Non-recursive pseudo classes are easy to evaluate, so let's allow them
on the fast path.

Increases fast path coverage when loading our GitHub repo from 48% to
56% of all selectors evaluated.
2024-03-19 16:48:22 +01:00
Andreas Kling 3c3e591f03 LibWeb: Add a fast (iterative) selector matcher for trivial selectors
If we determine that a selector is simple enough, we now run it using a
special matching loop that traverses up the DOM ancestor chain without
recursion.

The criteria for this fast path are:

- All combinators involved must be either descendant or child.
- Only tag name, class, ID and attribute selectors allowed.

It's definitely possible to increase the coverage of this fast path,
but this first version already provides a substantial reduction in time
spent evaluating selectors.

48% of the selectors evaluated when loading our GitHub repo are now
using this fast path.

18% speed-up on the "Descendant and child combinators" subtest of
StyleBench. :^)
2024-03-19 16:48:22 +01:00
Andreas Kling 432536f0b3 LibWeb: Make SelectorEngine::matches_namespace() a standalone function
This will allow me to reuse it in the next commit.
2024-03-19 16:48:22 +01:00
Andreas Kling a6c23d3db5 LibWeb: Make Element::has_class() an inline function
This is extremely hot when running CSS selectors, so let's make it
easier for it to be inlined.
2024-03-19 16:48:22 +01:00
Andreas Kling b40f0415ef LibWeb: Make Node::parent_element() an inline function
Also remove a redundant verify_cast<Element> while we're here.
2024-03-19 16:48:22 +01:00
MacDue d7e2894e57 LibGfx: Output an SVG compatible string from Path::to_byte_string()
This is much more useful than the previous format, as you can now just
paste the path into a site like https://svg-path-visualizer.netlify.app/
to debug issues.
2024-03-19 09:55:55 -04:00
MacDue 0d7107e1d3 LibGfx: Slightly simplify Path::append_segment()
Rather than reorder the points here, just update the callers.

No behaviour change.
2024-03-19 09:55:55 -04:00
Andreas Kling 4e4b9f440f Revert "LibWeb: Run IntersectionObserver steps only when needed"
This reverts commit 11b4216e65.
2024-03-19 13:04:39 +01:00
Lucas CHOLLET 1e023a589d LibPDF: Plug in the CCITT3 1D decoder and pass corresponding options 2024-03-19 12:22:28 +01:00
Lucas CHOLLET 7730b743db LibGfx/CCITT: Add PDF-specific options for CCITT3 1D
These two options are additions of the PDF specification. They are valid
for both 1D and 2D, but let's bail out if we encounter them in a 2D
image, as we don't have a test case yet.
2024-03-19 12:22:28 +01:00
Aliaksandr Kalenik 6fc59039c4 LibWeb: Skip cells layout in table box width calculation
There is no need to run full table layout if we are only interested in
calculating its width.

This change reduces compute_table_box_width_inside_table_wrapper()
from ~30% to ~15% in profiles of "File changed" pages on github.
2024-03-19 11:51:49 +01:00
Xexxa 541161d5e0 Base: Add more emoji
🏴󠁢󠁱󠁢󠁯󠁿 - U+1F3F4 U+E0062 U+E0071 U+E0062 U+E006F U+E007F
BQ-BO Bonaire
🏴󠁢󠁱󠁳󠁡󠁿 - U+1F3F4 U+E0062 U+E0071 U+E0073 U+E0061 U+E007F
BQ-SA Saba
🏴󠁢󠁱󠁳󠁥󠁿 - U+1F3F4 U+E0062 U+E0071 U+E0073 U+E0065 U+E007F
BQ-SE Sint Eustatius
🏴󠁫󠁲󠀱󠀱󠁿 - U+1F3F4 U+E006B U+E0072 U+E0031 U+E0031 U+E007F
KR-11 Seoul
🏴󠁫󠁲󠀲󠀹󠁿 - U+1F3F4 U+E006B U+E0072 U+E0032 U+E0039 U+E007F
KR-29 Gwangju City
🏴󠁫󠁲󠀳󠀰󠁿 - U+1F3F4 U+E006B U+E0072 U+E0033 U+E0030 U+E007F
KR-30 Daejeon
🏴󠁫󠁲󠀴󠀱󠁿 - U+1F3F4 U+E006B U+E0072 U+E0034 U+E0031 U+E007F
KR-41 Gyeonggi
🏴󠁫󠁲󠀴󠀴󠁿 - U+1F3F4 U+E006B U+E0072 U+E0034 U+E0034 U+E007F
KR-44 South Chungcheong
🏴󠁫󠁲󠀴󠀶󠁿 - U+1F3F4 U+E006B U+E0072 U+E0034 U+E0036 U+E007F
KR-46 South Jeolla
🏴󠁫󠁲󠀴󠀸󠁿 - U+1F3F4 U+E006B U+E0072 U+E0034 U+E0038 U+E007F
KR-48 South Gyeongsang
🏴󠁫󠁲󠀴󠀹󠁿 - U+1F3F4 U+E006B U+E0072 U+E0034 U+E0039 U+E007F
KR-49 Jeju
🏴󠁮󠁬󠁢󠁱󠀱󠁿 - U+1F3F4 U+E006E U+E006C U+E0062 U+E0071 U+E0031 U+E007F
NL-BQ1 Bonaire
🏴󠁮󠁬󠁢󠁱󠀲󠁿 - U+1F3F4 U+E006E U+E006C U+E0062 U+E0071 U+E0032 U+E007F
NL-BQ2 Saba
🏴󠁮󠁬󠁢󠁱󠀳󠁿 - U+1F3F4 U+E006E U+E006C U+E0062 U+E0071 U+E0033 U+E007F
NL-BQ3 Sint Eustatius
🏴󠁮󠁬󠁤󠁲󠁿 - U+1F3F4 U+E006E U+E006C U+E0064 U+E0072 U+E007F
NL-DR Drenthe
🏴󠁮󠁬󠁦󠁬󠁿 - U+1F3F4 U+E006E U+E006C U+E0066 U+E006C U+E007F
NL-FL Flevoland
🏴󠁮󠁬󠁦󠁲󠁿 - U+1F3F4 U+E006E U+E006C U+E0066 U+E0072 U+E007F
NL-FR Friesland
🏴󠁮󠁬󠁧󠁥󠁿 - U+1F3F4 U+E006E U+E006C U+E0067 U+E0065 U+E007F
NL-GE Gelderland
🏴󠁮󠁬󠁧󠁲󠁿 - U+1F3F4 U+E006E U+E006C U+E0067 U+E0072 U+E007F
NL-GR Groningen
🏴󠁮󠁬󠁬󠁩󠁿 - U+1F3F4 U+E006E U+E006C U+E006C U+E0069 U+E007F
NL-LI Limburg
🏴󠁮󠁬󠁮󠁢󠁿 - U+1F3F4 U+E006E U+E006C U+E006E U+E0062 U+E007F
NL-NB North Brabant
🏴󠁮󠁬󠁮󠁨󠁿 - U+1F3F4 U+E006E U+E006C U+E006E U+E0068 U+E007F
NL-NH North Holland
🏴󠁮󠁬󠁯󠁶󠁿 - U+1F3F4 U+E006E U+E006C U+E006F U+E0076 U+E007F
NL-OV Overijssel
🏴󠁮󠁬󠁵󠁴󠁿 - U+1F3F4 U+E006E U+E006C U+E0075 U+E0074 U+E007F
NL-UT Utrecht
🏴󠁮󠁬󠁺󠁥󠁿 - U+1F3F4 U+E006E U+E006C U+E007A U+E0065 U+E007F
NL-ZE Zeeland
🏴󠁮󠁬󠁺󠁨󠁿 - U+1F3F4 U+E006E U+E006C U+E007A U+E0068 U+E007F
NL-ZH South Holland
🏴󠁵󠁳󠁡󠁬󠁿 - U+1F3F4 U+E0075 U+E0073 U+E0061 U+E006C U+E007F
US-AL Alabama
🏴󠁵󠁳󠁡󠁺󠁿 - U+1F3F4 U+E0075 U+E0073 U+E0061 U+E007A U+E007F
US-AZ Arizona
🏴󠁵󠁳󠁴󠁸󠁿 - U+1F3F4 U+E0075 U+E0073 U+E0074 U+E0078 U+E007F
US-TX Texas
👨‍🔬 - U+1F468 U+200D U+1F52C MAN SCIENTIST
🧤 - U+1F9E4 GLOVES
🧥 - U+1F9E5 COAT
2024-03-19 06:51:04 -04:00
Andreas Kling 08a956f544 LibWeb: Ignore all pseudo element rules when matching non-pseudo element 2024-03-19 09:44:25 +01:00
Andreas Kling 4679dbc9df LibWeb: Make Element::inline_style() return specific declaration type
This removes a bunch of RTTI checks in StyleComputer.
2024-03-19 09:44:25 +01:00
Andreas Kling 25c22bb5e5 LibWeb: Reorder MatchingRule members to make it smaller
By packing the members more efficiently, it goes from 64 to 56 bytes.
2024-03-19 09:44:25 +01:00
Andreas Kling 963aa213c5 LibWeb: Avoid two calls to Selector::specificity() when sorting rules 2024-03-19 09:44:25 +01:00
Andreas Kling 22465e80fe LibWeb: Avoid FlyString copy when matching tag selector namespace URI 2024-03-19 09:44:25 +01:00
Aliaksandr Kalenik e3e6af39bc LibWeb: Add basic implementation of has_a_rendering_opportunity()
Return true only if we are ready to repaint. This fixes the issue where
requestAnimationFrame() was invoked more than once between repaints.
2024-03-19 07:54:14 +01:00
Shannon Booth e800605ad3 AK+LibURL: Move AK::URL into a new URL library
This URL library ends up being a relatively fundamental base library of
the system, as LibCore depends on LibURL.

This change has two main benefits:
 * Moving AK back more towards being an agnostic library that can
   be used between the kernel and userspace. URL has never really fit
   that description - and is not used in the kernel.
 * URL _should_ depend on LibUnicode, as it needs punnycode support.
   However, it's not really possible to do this inside of AK as it can't
   depend on any external library. This change brings us a little closer
   to being able to do that, but unfortunately we aren't there quite
   yet, as the code generators depend on LibCore.
2024-03-18 14:06:28 -04:00
Andreas Kling 21bfa001b1 LibWeb: Make StyleProperties::m_property_values a bit smaller
Instead of wrapping every entry in Optional, use the null state of the
style pointer for the same purpose.

This shrinks StyleProperties by 1752 bytes per instance.
2024-03-18 13:42:16 +01:00
Andreas Kling 7be0aed4b6 LibWeb: Keep StyleProperties animated properties in a HashMap
Instead of a gigantic array with space for every possible CSS property
being animated at the same time.

This shrinks StyleProperties by 3480 bytes per instance.
2024-03-18 13:42:16 +01:00
Andreas Kling dd8504c68d LibWeb: Store "text for rendering" in TextPaintable
Instead of TextPaintable fragments being an offset+length view into the
layout node, they are now a view into the paintable instead.

This removes an awkward time window where we'd have bogus state in text
fragments after layout invalidation but before relayout. It also makes
the code slightly nicer in general, since there's less mixing of layout
and painting concepts.
2024-03-18 13:42:16 +01:00
Andreas Kling 2be47c3d7a LibWeb: Add fast_is<TextPaintable>() 2024-03-18 13:42:16 +01:00
Andreas Kling 1987318cc2 LibWeb: Move selection state from layout tree to paint tree
Where we paint the selection is obviously paint-related information,
so let's keep it in the paint tree.
2024-03-18 13:42:16 +01:00
Andreas Kling d18a5b904d LibWeb: Remove unused LineBoxFragment member 2024-03-18 13:42:16 +01:00
Andreas Kling 9c5da0eed0 LibWeb: Remove unused PaintableFragment member 2024-03-18 13:42:16 +01:00
Andreas Kling 94e55768f6 LibWeb: Ensure layout is up-to-date before blinking the input cursor 2024-03-18 13:42:16 +01:00
Andreas Kling a7d7c5b7b4 LibWeb: Don't force relayout after every keyboard input event
Instead, just rely on the invalidation and lazy relayout that happens as
a consequence of mutating the DOM.

This allows multiple keystrokes to coalesce into a single relayout if
necessary, dramatically improving performance when typing text into
form fields on complex pages.
2024-03-18 13:42:16 +01:00
Andreas Kling c51a4cc007 LibWeb: Detach paintables from *all* DOM nodes before committing layout
Before this change, we were not detaching paintables from DOM nodes
within shadow subtrees.

This appears to be the main reason that keyboard editing was doing
immediate forced relayout: doing a full layout invalidation meant we'd
build a new layout tree, which then hid the problem with with
still-attached paintables.

By detaching them before committing a new layout, we make it possible
for keyboard editing to just use normal relayout, instead of full forced
invalidation & relayout.
2024-03-18 13:42:16 +01:00
Andreas Kling a97e9f1d58 LibWeb: Don't mark CharacterData nodes for style update when changed
CharacterData nodes and their subclasses (most commonly Text) don't have
style, as style is specific to Elements. So there's no need to mark them
for a style update when their content is programmatically changed.
2024-03-18 13:42:16 +01:00
Tim Ledbetter 3a7a84f39b LibWeb: Limit progress element attribute values to the correct ranges
The max attribute is now clamped to ensure it is limited to positive
numbers and the value attribute is clamped to ensure it is non-negative.
2024-03-18 11:16:35 +01:00
Tim Ledbetter ecbc686bc8 LibWeb: Allow progress element value to be set higher than the max value
Previously, we returned from the value setter if the specified value
was above the max value. This is not required, as the getter clamps the
returned value to the max value.
2024-03-18 11:16:35 +01:00
Tim Ledbetter e795c24fdd LibWeb: Don't crash when modifying detached progress element attributes 2024-03-18 11:16:35 +01:00
MacDue 8057542dea LibGfx: Simplify path storage and tidy up APIs
Rather than make path segments virtual and refcounted let's store
`Gfx::Path`s as a list of `FloatPoints` and a separate list of commands.

This reduces the size of paths, for example, a `MoveTo` goes from 24
bytes to 9 bytes (one point + a single byte command), and removes a
layer of indirection when accessing segments. A nice little bonus is
transforming a path can now be done by applying the transform to all
points in the path (without looking at the commands).

Alongside this there's been a few minor API changes:

- `path.segments()` has been removed
  * All current uses could be replaced by a new `path.is_empty()` API
  * There's also now an iterator for looping over `Gfx::Path` segments
- `path.add_path(other_path)` has been removed
  * This was a duplicate of `path.append_path(other_path)`
- `path.ensure_subpath(point)` has been removed
  * Had one use and is equivalent to an `is_empty()` check + `move_to()`
- `path.close()` and `path.close_all_subpaths()` assume an implicit
  `moveto 0,0` if there's no `moveto` at the start of a path (for
  consistency with `path.segmentize_path()`).

Only the last point could change behaviour (though in LibWeb/SVGs all
paths start with a `moveto` as per the spec, it's only possible to
construct a path without a starting `moveto` via LibGfx APIs).
2024-03-18 07:09:37 +01:00
Space Meyer 14005f89a6 Meta: Correct gdb example in serenity.sh 2024-03-17 20:44:18 -06:00
Nico Weber 7650e657aa LibGfx/JBIG2: Implement support for TPGDON 2024-03-17 17:38:30 +01:00
Nico Weber edec2b9baa Tests/LibGfx: Add a test jbig2 file using TPGDON
"TPGD" is short for "Typical Prediction for Generic Direct coding",
and the "ON" bit turns it on. In this mode, before decoding a line,
we decode a single bit first that controls if the current line is
just a copy of the previous line. If so, the line's pixels aren't
encoded, the decoder just copies the previous line.

I created this by running

    jbig2 -i Tests/LibGfx/test-inputs/bmp/bitmap -f bmp \
        -o bitmap -F jb2 -ini tpgdon.ini

where tpgdon.ini contained:

    -Gen -Seg 1
    -Gen -Param -TpGDon 1

See previous commits in this directory for details on the `jbig2` tool.

Sadly, the TPGDON writing path in `jbig2` wasn't implemented yet,
so I had to add this. See the PR that added this commit for my
local diff to `jbig2`.

I'm somewhat confident that my change to `jbig2` (and hence the
image added in this commit) is correct because:

1. `jbig2` succeeds in converting this file to a bmp file,
   while it failed without my patch (the decoding codepath in
   `jbig2` does have TPGDON support)

2. Other pdf viewers display the output of
   `Meta/jbig2_to_pdf.py -o foo.pdf path/to/bitmap-tpgdon.jbig2 399 400`
   the same way we do
2024-03-17 17:38:30 +01:00
Nico Weber 7d0e752590 Meta: Add a script that takes a JBIG2 file and writes a PDF embedding it
Most image viewers can't display JBIG2 files.
All PDF viewers can display JBIG2 files.

This is useful for checking that PDF viewers render JBIG2 files the
same way we do.
2024-03-17 17:38:30 +01:00
Kenneth Myhra 49d7719a04 LibWeb: Add and use serialize_enum() 2024-03-17 17:16:09 +01:00
Kenneth Myhra 94c6389fc0 LibWeb: Add {,de}serialization steps for DOMRect 2024-03-17 17:16:09 +01:00
Kenneth Myhra 9f5fa4f4a0 LibWeb: Add {,de}serialization steps for DOMRectReadonly 2024-03-17 17:16:09 +01:00
Kenneth Myhra b7006b2423 LibWeb: Add {,de}serialization steps for DOMPoint 2024-03-17 17:16:09 +01:00
Kenneth Myhra bf4fb39bfb LibWeb: Add {,de}serialization steps for DOMPointReadonly 2024-03-17 17:16:09 +01:00