Commit Graph

32444 Commits

Author SHA1 Message Date
Andreas Kling
3851d3add0 LibJS: Make Token::m_message a StringView
This is only ever a string literal, so there's no need to keep creating
the same strings at runtime.
2024-03-24 13:28:24 +01:00
Kenneth Myhra
51847bbebf LibWeb: Remove ImageData's create_with_size() and use create() instead
Removes ImageData::create_with_size() and redirects previous usage to
ImageData::create().
2024-03-24 11:09:09 +01:00
Kenneth Myhra
8a1e88677f LibWeb: Add FIXME comments to ImageData.idl
Add FIXME comments for ImageData's missing constructor and attribute
colorSpace.
2024-03-24 11:09:09 +01:00
Kenneth Myhra
30a02fef91 LibWeb: Add one of the two documented constructors to ImageData
Also adds the IDL types:
- dictionary ImageDataSettings
- enum PredefinedColorSpace.
2024-03-24 11:09:09 +01:00
Ali Mohammad Pur
6adf1be06b Shell: Add support for octal escapes in strings
This adds all three common prefixes (\0, \o and \c).
2024-03-24 08:26:56 +01:00
Ali Mohammad Pur
27a38932da LibRegex: Account for extra explicit And/Or in class parser assertion
Fixes #23691.
2024-03-24 08:24:46 +01:00
Nico Weber
ced21d8419 LibGfx/JBIG2: Call decode_immediate_text_region for lossless text region
It seems to do the right thing already, and nothing in the spec says
not to do this as far as I can tell.

With this, we can finally decode the test input from #23659.

See f391c7822d for a similar change for generic regions and
lossless generic regions.
2024-03-23 17:30:15 -04:00
Nico Weber
b15e1d2b2a LibGfx/JBIG2: Implement initial support for text segments
Text segments conceptually store (x,y,id) triples. (x,y) are a
coordinate, and id refers to an id from a symbol segment.
A text segment has the effect of drawing some of the bitmaps stored
in a symbol segment to the output bitmap.

For example, the symbol segment might contain a small bitmap that
happens to look like the letter 'A', and the text segment might
draw that everywhere a scanned page has an 'A'. (The JBIG2 format
only treats it as an abstract bitmap. It doesn't know that this
small bitmap is an 'A'.)

This is missing support for many things:

* Huffman-coded input (not used in practice)
* Symbol refinement
* Transposed symbols
* Colors (not used in practice)

Still, we now have basic symbol/text segment support. This is enough
to decode the downloadable PDF here:
https://www.google.com/books/edition/Paradise_Lost/6qdbAAAAQAAJ

It doesn't lead to any progression on my 1000 file test PDF set.
The 7 files in there that use JBIG2 with symbol and text segments
now fail to load for other reasons (4 need symbol refinement for
text segments, one needs end-of-stripe segment support, one needs
support for symbol segments referring to other segments).

(And possibly, many other PDFs from Google Books, but that's the
only one I've tried so far.)
2024-03-23 17:30:15 -04:00
Nico Weber
3454970903 LibGfx/JBIG2: Extract composite_bitbuffer() and add some features
This extracts the bitbuffer combining code we had into a new function
composite_bitbuffer() and adds the following features:

* Real support for combination operators (which also lets us allow black
  as background color again, even if that's never used in practice)
* Clipping support (not used here yet, but will be needed elsewhere
  soon)

We're going to need this for text segment handling.

No behavior change.
2024-03-23 17:30:15 -04:00
Nico Weber
754e1b46fc LibGfx/JBIG2: Implement basic symbol segment processing
A symbol segment defines a bunch of small bitmaps and associates them
with numeric IDs.

This only implements reading symbols encoded with the arithmetic coder.
It does not support huffman coding. (In practice, everything seems to
use arithmetic coding.)

Support for refinement or aggregate coding isn't implemented yet.
Support for retaining bitmap coding contexts isn't implemented yet.
Support for symbol segments referring to other symbol segments isn't
implemented yet.
But all produce diagnostics if encountered, so we won't forget about
them. (I haven't seen either being used in the wild.)

No visible behavior change yet, but with JBIG2_DEBUG turned on,
it produces all kinds of debug output.
2024-03-23 17:30:15 -04:00
Nico Weber
93fcb529cf LibGfx/JBIG2: Move SegmentData down a bit
Symbol segments will store decoded symbols, and for that SegmentData
needs to come after BitBuffer.

No behavior change.
2024-03-23 17:30:15 -04:00
Nico Weber
2099ca48a1 LibGfx/JBIG2: Pass in decoder and contexts to generic region decoder
The symbol segment decoding procedure will read generic regions
that aren't at a byte boundary, and that share contexts across
several regions.

No behavior change.
2024-03-23 17:30:15 -04:00
Nico Weber
376b1a2309 LibGfx/JBIG2: Have just one CombinationOperator enum class
We already had two, and we would need another one for text segments.

No behavior change.
2024-03-23 17:30:15 -04:00
Nico Weber
c06110da87 LibGfx/JBIG2: Make AdaptiveTemplatePixel toplevel
We're going to need it for symbol segment decoding too.

No behavior change.
2024-03-23 17:30:15 -04:00
Nico Weber
8e82c2b932 LibGfx/JBIG2: Add arithmetic integer decoder
The existing ArithmeticEncoder (from Annex E) reads one bit at a
time.

ArithmeticIntegerDecoder (from Annex A) builds on top of that to
read integer values.

This will be used by both the symbol segment and the text segment
readers.

(This does not yet implement the IAID decoding procedure in A.3.
We only need that one in the text segment decoder at the moment,
and it's pretty small, so I'll put it inline there for now.)

Not used yet, so no behavior change yet.
2024-03-23 17:30:15 -04:00
Nico Weber
c99506da7d LibGfx/JBIG2: Initialize POD members
And use Array<> instead of C-style arrays.
2024-03-23 17:30:15 -04:00
Timothy Flynn
feddecde5b LibWeb: Emit the current token before EOF on invalid comments
The spec for each of these state:

    -> EOF:
    This is an eof-in-comment parse error. Emit the current comment
    token. Emit an end-of-file token.

We were neglecting to emit the current comment token before emitting an
EOF token. Note the existing EMIT_CURRENT_TOKEN macro was unused.
2024-03-23 20:58:31 +01:00
Timothy Flynn
775282f9fc LibWebView: Stop tokenizing the source HTML once we hit an EOF token 2024-03-23 20:58:31 +01:00
Aliaksandr Kalenik
26a516c85f LibWeb: Allow any FC type for replaced boxes in dimension_box_on_line()
If box is sized as replaced it still could be anything, not only SVG.

This fixes crashing on https://www.shopify.com/ that was caused by a
missing paintable for a box that has a layout node. This occurred
because the box was not laid out in dimension_box_on_line().
2024-03-23 20:57:05 +01:00
Tim Ledbetter
e1fbb08747 LibWeb: Avoid division by zero when calculating box aspect ratio 2024-03-23 20:56:26 +01:00
Tim Ledbetter
2227674b91 LibWeb: Don't crash when updating a select with detached option elements
`Node::shadow_including_root()` was missing a null check, which caused
a crash when manipulating a select element, whose option elements were
initially detached.
2024-03-23 20:56:26 +01:00
Tim Ledbetter
521a1be97f LibWeb: Don't crash when querying the CDataSection.assignedSlot property 2024-03-23 20:56:26 +01:00
Tim Ledbetter
3518f39b60 LibWeb: Don't crash when querying detached circle element properties 2024-03-23 20:56:26 +01:00
forchane
2d11fc6d44 LibJS: Rename ToSecondsStringPrecision to ToSecondsStringPrecisionRecord
This is an editorial change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/60f1052
2024-03-23 08:46:56 -04:00
forchane
d2e4da62c8 LibJS: Separate validation of roundingIncrement option
This is an editorial change in the temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/712c449
2024-03-23 08:45:59 -04:00
Timothy Flynn
7b3ddd5e15 LibWeb: Track fetching-related tasks in FetchController for cancellation
The HTMLMediaElement, for example, contains spec text which states any
ongoing fetch process must be "stopped". The spec does not indicate how
to do this, so our implementation is rather ad-hoc.

Our current implementation may cause a crash in places that assume one
of the fetch algorithms that we set to null is *not* null. For example:

    if (fetch_params.process_response) {
        queue_fetch_task([]() {
            fetch_params.process_response();
        };
    }

If the fetch process is stopped after queuing the fetch task, but not
before the fetch task is run, we will crash when running this fetch
algorithm.

We now track queued fetch tasks on the fetch controller. When the fetch
process is stopped, we cancel any such pending task.

It is a little bit awkward maintaining a fetch task ID. Ideally, we
could use the underlying task ID throughout. But we do not have access
to the underlying task nor its ID when the task is running, at which
point we need some ID to remove from the pending task list.
2024-03-23 13:45:35 +01:00
Timothy Flynn
4806cf9527 LibWeb: Return the ID of queued global events
This will allow callers to track the event.
2024-03-23 13:45:35 +01:00
Aliaksandr Kalenik
f932d5d825 LibWeb: Look for labeled control in DOM tree instead of layout tree
...because "change" event should be dispatched on control even if it
has "display: none" style.

This change fixes selection in labels dropdown on GitHub's "new issue"
page.
2024-03-23 12:46:37 +01:00
Nico Weber
730876fda9 LibGfx/JPEG: Add a comment to inverse_dct_8x8()
See here:
https://github.com/SerenityOS/serenity/issues/22739#issuecomment-1890599116

No behavior change.
2024-03-23 09:40:29 +01:00
MINAqwq
e1598233e1 LibCore: Remove unnecessary or invalid write after child remove 2024-03-22 16:32:39 -04:00
Aliaksandr Kalenik
561e011e07 LibWeb+WebContent+Ladybird: Add ability to paste text from clipboard
Text can be pasted by pressing Ctrl/Cmd+V or by using button in the
context menu. For now only the Qt client is supported.
2024-03-22 15:47:33 -04:00
Aliaksandr Kalenik
d5c6e45dca LibWeb: Change Element::closest() to check if any of selector matches
...instead of checking if all selectors match an element.

Fixes bug reduced from GitHub's "new issue" page.
2024-03-22 18:43:46 +01:00
Nico Weber
9bf29356a2 LibGfx/ISOBMFF: Support box header size 0 to mean "until end of data"
JPEG2000 uses this, and as far as I can tell it's also part of
ISO/IEC 14496-12.
2024-03-22 18:31:23 +01:00
Nico Weber
0d098211b7 LibRIFF+LibGfx/ISOBMFF: Make ChunkID (de)serialization self-consistent
Previously, ChunkID's from_big_endian_number() and
as_big_endian_number() weren't inverses of each other.

ChunkID::from_big_endian_number() used to take an u32 that contained
`('f' << 24) | ('t' << 16) | ('y' << 8) | 'p'`, that is
'f', 't', 'y', 'p' in memory on big-endian and 'p', 'y', 't', 'f'
on little-endian, and return a ChunkID for 'f', 't', 'y', 'p'.

ChunkID::as_big_endian_number() used to return an u32 that for a
ChunkID storing 'f', 't', 'y', 'p' was always 'f', 't', 'y', 'p'
in memory on both little-endian and big-endian, that is it stored
`('f' << 24) | ('t' << 16) | ('y' << 8) | 'p'` on big-endian and
`('p' << 24) | ('y' << 16) | ('t' << 8) | 'f'` on little-endian.

`ChunkID::from_big_endian_number(0x11223344).as_big_endian_number()`
returned 0x44332211.

This change makes the two methods self-consistent: they now take
and return a u32 that always has the first ChunkID part in the
highest bits of the u32 (`'f' << 24`), and so on. That also means
they return a u32 that in-memory looks differently on big-endian
and little-endian. Since that's normal for numbers, this also
renames the two methods to just `from_number()` and `to_number()`.

With the semantics cleared up, change the one use in ISOBMFF to read a
BigEndian for chunk headers and brand codes.  This has the effect of
tags now being printed in the right order.

Before:

```sh
% Build/lagom/bin/isobmff ~/Downloads/sample1.jp2
Unknown Box ('  Pj')
[ 4 bytes ]
('pytf') (version = 0, flags = 0x0)
- major_brand = ' 2pj'
- minor_version = 0
- compatible_brands = { ' 2pj' }
Unknown Box ('h2pj')
[ 37 bytes ]
Unknown Box ('fniu')
[ 92 bytes ]
Unknown Box (' lmx')
[ 2736 bytes ]
Unknown Box ('c2pj')
[ 667336 bytes ]
```

After:

```sh
% Build/lagom/bin/isobmff ~/Downloads/sample1.jp2
hmm 0x11223344 0x11223344
Unknown Box ('jP  ')
[ 4 bytes ]
('ftyp' ) (version = 0, flags = 0x0)
- major_brand = 'jp2 '
- minor_version = 0
- compatible_brands = { 'jp2 ' }
Unknown Box ('jp2h')
[ 37 bytes ]
Unknown Box ('uinf')
[ 92 bytes ]
Unknown Box ('xml ')
[ 2736 bytes ]
Unknown Box ('jp2c')
[ 667336 bytes ]
```
2024-03-22 18:31:15 +01:00
Nico Weber
b43092db46 LibGfx/ISOBMFF: Print only one set of quotes around FourCCs
AK::Formatter<RIFF::ChunkID> (in LibRIFF/ChunkID.h) adds them already,
so don't add them here too.
2024-03-22 18:31:15 +01:00
Ali Mohammad Pur
e2bab93fdd LibTLS: Avoid using new event loops when setting up connections
This was causing some racey behaviour in LibHTTP, and just generally
lead to really bad stack traces; avoid that by switching to
Core::Promise and using the existing event loop.

Possibly resolves #23524 and #23642.
2024-03-22 18:27:53 +01:00
Andreas Kling
afe6abfc09 LibWeb: Use an ancestor filter to quickly reject many CSS selectors
Given a selector like `.foo .bar #baz`, we know that elements with
the class names `foo` and `bar` must be present in the ancestor chain of
the candidate element, or the selector cannot match.

By keeping track of the current ancestor chain during style computation,
and which strings are used in tag names and attribute names, we can do
a quick check before evaluating the selector itself, to see if all the
required ancestors are present.

The way this works:

1. CSS::Selector now has a cache of up to 8 strings that must be present
   in the ancestor chain of a matching element. Note that we actually
   store string *hashes*, not the strings themselves.

2. When Document performs a recursive style update, we now push and pop
   elements to the ancestor chain stack as they are entered and exited.

3. When entering/exiting an ancestor, StyleComputer collects all the
   relevant string hashes from that ancestor element and updates a
   counting bloom filter.

4. Before evaluating a selector, we first check if any of the hashes
   required by the selector are definitely missing from the ancestor
   filter. If so, it cannot be a match, and we reject it immediately.

5. Otherwise, we carry on and evaluate the selector as usual.

I originally tried doing this with a HashMap, but we ended up losing
a huge chunk of the time saved to HashMap instead. As it turns out,
a simple counting bloom filter is way better at handling this.
The cost is a flat 8KB per StyleComputer, and since it's a bloom filter,
false positives are a thing.

This is extremely efficient, and allows us to quickly reject the
majority of selectors on many huge websites.

Some example rejection rates:
- https://amazon.com: 77%
- https://github.com/SerenityOS/serenity: 61%
- https://nytimes.com: 57%
- https://store.steampowered.com: 55%
- https://en.wikipedia.org: 45%
- https://youtube.com: 32%
- https://shopify.com: 25%

This also yields a chunky 37% speedup on StyleBench. :^)
2024-03-22 18:27:32 +01:00
Aliaksandr Kalenik
e232a84f0e LibWeb: Do not include box's own scroll offset in get_client_rects()
Fixes https://github.com/SerenityOS/serenity/issues/23631
2024-03-22 12:13:59 +01:00
Tim Ledbetter
7b08fd9f72 LibWeb: Simplify String to CORSSettingAttribute value conversion
There's no need to check the "anonymous" case explicitly, as
`CORSSettingAttribute::Anonymous` is the default value.
2024-03-22 11:29:57 +01:00
Tim Ledbetter
aabf1a65b1 LibWeb: Align CORSSettingsAttribute values with the specification
This change makes our crossOrigin attribute getter behave the same way
as other browsers.
2024-03-22 11:29:57 +01:00
Andreas Kling
df2cd33ccd Revert "LibWeb: Never claim "rendering opportunity" for SVG-as-image documents"
This reverts commit 8aae50f4ee.
2024-03-22 10:23:28 +01:00
Andreas Kling
34954f49b6 LibWeb: Log a FIXME when encountering an unexpected block-level box
I've seen a crash when trying to verify_cast some block-level box to a
BlockContainer when it's actually something else.

This patch adds a debug log message so we can learn more about it next
time it happens somewhere.
2024-03-22 06:43:57 +01:00
Andreas Kling
8aae50f4ee LibWeb: Never claim "rendering opportunity" for SVG-as-image documents
Since we drive painting for SVG-as-image manually anyway, there's no
need for them to say they are "ready to paint", since that just causes
unnecessary extra processing in the HTML event loop.
2024-03-22 06:43:57 +01:00
Aliaksandr Kalenik
42d5883d57 LibWeb: Set animation update flag from Animation::invalidate_effect()
Fixes regressed animation tests.
2024-03-21 16:10:26 +01:00
Timothy Flynn
aad110ec7e base64: Map input files into memory for reading
We do the same thing with the gzip utility for performance.

This reduces the runtime of `./bin/base64 enwik8 >/dev/null` from
0.428s to 0.303s.

This reduces the runtime of `./bin/base64 -d enwik8.base64 >/dev/null`
from 0.632s to 0.469s.

(enwik8 is a 100MB test file from http://mattmahoney.net/dc/enwik8.zip)
2024-03-21 15:53:46 +01:00
Aliaksandr Kalenik
b7d28ee57d LibWeb: Change update_style() to update animated style only if needed
Instead of invalidating animated style properties whenever
`Document::update_style()` is called, now we only do that when
animations might have actually progressed. We still have to ensure
animated properties are up-to-date in `update_style()` to ensure that
JS methods can access updated style properties.
2024-03-21 11:29:02 +01:00
MacDue
6b799a739c LibWeb: Use ensure_subpath() in CanvasPath::arc_to()
No behaviour change.
2024-03-21 09:19:22 +01:00
MacDue
d73c21b6fe LibWeb: Implement missing CanvasPath::ellipse() steps 2024-03-21 09:19:22 +01:00
MacDue
cf1f00943a LibWeb: Implement missing CanvasPath::bezierCurveTo() steps 2024-03-21 09:19:22 +01:00
MacDue
877a0e06c4 LibWeb: Implement missing CanvasPath::quadraticCurveTo() steps 2024-03-21 09:19:22 +01:00
MacDue
d951ee399f LibWeb: Implement missing CanvasPath::lineTo() steps 2024-03-21 09:19:22 +01:00
MacDue
6128a28f17 LibWeb: Implement missing CanvasPath::moveTo() steps 2024-03-21 09:19:22 +01:00
Aliaksandr Kalenik
96d67ded3e LibWeb: Always run layout and style updates from event loop processing
Before this change, we ran style and layout updates from both event
loop processing and update timers. This could have caused missed resize
observer updates and unnecessary updating of style or layout more than
once before repaint.

Also, we can now be sure unnecessary style or layout updates won't
happen in `EventLoop::spin_processing_tasks_with_source_until()`.
2024-03-20 20:28:21 +01:00
Aliaksandr Kalenik
e09816c37c LibWeb: Run only tasks with navigation source in "apply history step"
In our implementation of the "apply the history step" algorithm, we
have to spin-wait for the completion of tasks queued on the event loop.
Before this change, we allowed tasks from any source to be executed
while we were waiting. It should not be possible because it allows to
interrupt history step application by anything, including another
history step application.

Fixes https://github.com/SerenityOS/serenity/issues/23598
2024-03-20 20:28:21 +01:00
Andrew Kaster
f26dd29b4d LibWeb: Print more information about thrown DOMExceptions in the console
This doesn't quite match the behavior of other engines, but by golly is
it helpful.
2024-03-20 15:18:44 -04:00
Timothy Flynn
6e2685f091 LibWeb: Remove FLATTEN attribute from SelectorEngine::fast_matches
This causes compilation time with GCC to increase far too much.
2024-03-20 10:33:16 -04:00
Nico Weber
1ae174e380 image: Add a --crop option
You can now run

    image -o out.png Tests/LibGfx/test-inputs/bmp/bitmap.bmp \
        --crop 130,86,108,114

and end up with the nose part of that image in out.png.
2024-03-20 13:58:23 +01:00
Matthew Olsson
0d70311c90 LibWeb: Resolve unresolved style values eagerly in KeyframeEffect
This isn't required as the StyleComputer will do this when animating,
but this allows the properties to be resolved once instead of on
every animation frame.

Note that we still pass AllowUnresolved::Yes because the properties will
not be resolved if there is no target.
2024-03-20 09:17:33 +01:00
Matthew Olsson
3dd9f2715f LibWeb: Resolve unresolved style values when animating properties 2024-03-20 09:17:33 +01:00
Matthew Olsson
b2fb9cc7d3 LibWeb: Allow ignoring unresolved style values when iterating properties
When iterating through a @keyframes rule, it isn't possible to resolve
unresolved style properties since there are no elements. This change
allows those properties to simply pass through this helper function.
2024-03-20 09:17:33 +01:00
Matthew Olsson
1f53727a3f LibWeb: Remove Badge from CSS::Parser::resolve_unresolved_style_value
KeyframeEffect needs to use this method to resolve unresolved properties
in the same way that StyleComputer does.
2024-03-20 09:17:33 +01:00
Matthew Olsson
ebfc6c33a6 LibWeb: Remove "resolved" from the name of Keyframe's property map
These will need to store unresolved styles as well, since they may be
built during parsing of a @keyframes rule. In that case there is no
target element or pseudo-element, and thus the value cannot be resolved.
2024-03-20 09:17:33 +01:00
Kenneth Myhra
c92f556aa5 LibWeb: Add {,de}serialization steps for FileList 2024-03-20 09:16:01 +01:00
Kenneth Myhra
5397340724 LibWeb: Add {,de}serialization steps for DOMQuad 2024-03-20 09:16:01 +01:00
Kenneth Myhra
d086d0cd92 LibWeb: Remove 'FIXME' on comment which is already implemented 2024-03-20 09:16:01 +01:00
Kenneth Myhra
52f056503d LibWeb: Add {,de}serialization steps for CryptoKey 2024-03-20 09:16:01 +01:00
Kenneth Myhra
ca54691ecf LibWeb: Add structured_deserialize_internal()
structured_deserialize_internal() is added to support sub
deserialization from serializable interfaces serialization steps which
needs the ability to pass onto the current position in the deserialized
data.
2024-03-20 09:16:01 +01:00
Kenneth Myhra
31f345fcb0 LibWeb: Add DeserializationMemory parameter to deserialization_steps()
We want to bring with us the value of DeserializationMemory to
Serializable::deserialization_steps() when doing sub serialization.
2024-03-20 09:16:01 +01:00
Kenneth Myhra
4669c1ba31 LibWeb: Add SerializationMemory parameter to serialization_steps()
We want to bring with us the value of SerializationMemory to
Serializable::serialization_steps() when doing sub serialization.
2024-03-20 09:16:01 +01:00
Nico Weber
924423c596 LibGfx/JBIG2: Make context index a u8
This value is at most 46, so a u8 is enough.

We have tens of thousands of these contexts.

(We could pack the is_mps bit into that u8 as well, but
then the I() and MPS() functions need to return helper objects
instead of a direct reference, so let's not do that part for now.)
2024-03-20 09:09:54 +01:00
Nico Weber
7cb12e057f LibGfx/WebPLossless: Fix out-of-bounds write in color indexing transform
If a lossless webp has 3 or 4 colors, it uses 2 bits per pixel to
store an offset into a "color index" (which the spec explicitly does
not call palette since it says the 'color cache' is more like that).
This way, it can pack 4 pixels into a single pixel.

If the width of the output image wasn't evenly divisble by 4,
we used to write out-of-bounds in the last few columns of each
row, since we used to always write all 4 pixels.

Found by clusterfuzz. Probably fixes
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=66082

While here, spruce up the comments very slightly.
2024-03-20 09:09:47 +01:00
Tim Ledbetter
c8b219914e LibWeb: Use ErrorOr to propagate SVG attribute parsing errors
If an unexpected token is encountered when parsing an SVG attribute it
is now immediately propagated with ErrorOr. Previously, some situations
where an unexpected token was encountered could cause a crash.
2024-03-20 09:09:35 +01:00
Tim Ledbetter
a55394c383 LibWeb: Fix typo in SVG attribute parser method name 2024-03-20 09:09:35 +01:00
Tim Ledbetter
c1b1233575 LibWeb: Avoid duplicating SVG viewbox height calculation 2024-03-20 09:09:35 +01:00
Nico Weber
0374c1eb3b LibPDF: Handle indirect reference resolving during parsing more robustly
If `Document::resolve()` was called during parsing, it'd change the
reader's current position, so the parsing code that called it would
then end up at an unexpected position in the file.

Parser.cpp already had special-case recovery when a stream's length
was stored in an indirect reference.

Commit ead02da98ac70c ("/JBIG2Globals") in #23503 added another case
where we could resolve indirect reference during parsing, but wasn't
aware of having to save and restore the reader position for that.

Put the save/restore code in `DocumentParser::parse_object_with_index`
instead, right before the place that ultimately changes the reader's
position during `Document::resolve`. This fixes `/JBIG2Globals` and
lets us remove the special-case code for `/Length` handling.

Since this is kind of subtle, include a test.
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
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