Commit Graph

32380 Commits

Author SHA1 Message Date
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