1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-09 09:34:57 +09:00
Commit graph

67940 commits

Author SHA1 Message Date
Timothy Flynn
b169a98495 LibWeb+LibWebView+WebContent: Introduce a basic about:settings page
This adds a basic settings page to manage persistent Ladybird settings.
As a first pass, this exposes settings for the new tab page URL and the
default search engine.

The way the search engine option works is that once search is enabled,
the user must choose their default search engine; we do not apply any
default automatically. Search remains disabled until this is done.

There are a couple of improvements that we should make here:

* Settings changes are not broadcasted to all open about:settings pages.
  So if two instances are open, and the user changes the search engine
  in one instance, the other instance will have a stale UI.

* Adding an IPC per setting is going to get annoying. It would be nice
  if we can come up with a smaller set of IPCs to send only the relevant
  changed settings.
2025-03-22 17:27:45 +01:00
Timothy Flynn
e084a86861 LibWebView+UI: Introduce a persistent settings object
This adds a WebView::Settings class to own persistent browser settings.
In this first pass, it now owns the new tab page URL and search engine
settings.

For simplicitly, we currently use a JSON format for these settings. They
are stored alongside the cookie database. As of this commit, the saved
JSON will have the form:

    {
        "newTabPageURL": "about:blank",
        "searchEngine": {
            "name": "Google"
        }
    }

(The search engine is an object to allow room for a future patch to
implement custom search engine URLs.)

For Qt, this replaces the management of these particular settings in the
Qt settings UI. We will have an internal browser page to control these
settings instead. In the future, we will want to port all settings to
this new class. We will also want to allow UI-specific settings (such as
whether the hamburger menu is displayed in Qt).
2025-03-22 17:27:45 +01:00
Timothy Flynn
b4fde1ef64 LibWebView: Remove non-generic search engines
It really doesn't make sense for GitHub to be the default search engine.
If some really wants this, we can eventually implement setting custom
search engine URLs.
2025-03-22 17:27:45 +01:00
Timothy Flynn
a69ecc3943 UI: Add a default CSS file for internal Ladybird pages
In order to maintain a consistent look and feel between internal about:
pages going forward, let's use a central CSS file to define Ladybird
colors and some common form control styles.
2025-03-22 17:27:45 +01:00
Timothy Flynn
5f0f97b3cc LibWeb: Do not insert "return" key presses into input element values
When the return key is pressed, we try to handle it as a commit action
for input elements. However, we would then go on to actually insert the
return key's code point (U+000D) into the input element. This would be
sanitized out, but would leave the input element in a state where it
thinks it has text to commit. This would result in a change event being
fired when the return key is pressed multiple times in a row.

We were also firing the beforeinput/input events twice for all return
key presses.

To fix this, this patch changes the input event target to signify if it
actually handled the return key. If not (i.e. for textarea elements),
only then do we insert the code point. We also must not fall through to
the generic key handler, to avoid the repeated input events.
2025-03-22 17:27:45 +01:00
Timothy Flynn
206ec6694c LibWeb: Update the select element's text when setting the selected index
We were updating the IDL values, but the rendered text would remain on
the previously selected value.
2025-03-22 17:27:45 +01:00
Timothy Flynn
9b6ae962d0 LibWebView+UI: Handle DPR for select elements like other menus
The select dropdown was doing its own ad-hoc method of handling DPR. We
now handle it just like other context menus. Previously, the drop down
in the AppKit chrome was twice as large as it should be.
2025-03-22 17:27:45 +01:00
Timothy Flynn
3961a4f16a AK: Fully qualify use of move in TemporaryChange
For some reason, after some seemingly unrelated upcoming changes, the
unqualified `move`s in this header result in an ADL failure:

AK/TemporaryChange.h:22:39: error: call to function 'move' that is
neither visible in the template definition nor found by argument-
dependent lookup
   22 |     ~TemporaryChange() { m_variable = move(m_old_value); }
      |                                       ^

Libraries/LibDNS/Resolver.h:491:29: note: in instantiation of member
function 'AK::TemporaryChange<bool>::~TemporaryChange' requested here
  491 |             TemporaryChange change(m_attempting_restart, true);
2025-03-22 17:27:45 +01:00
Tim Ledbetter
cbf47abd24 LibWeb/CSS: Set the initial value of the appearance property to "none" 2025-03-22 17:05:17 +01:00
Tim Ledbetter
ecd6636b3e LibWeb/CSS: Use "0s" as the initial value for animation-duration 2025-03-22 17:04:33 +01:00
Tim Ledbetter
e1f6a170d5 LibWeb: Invalidate style when media content attribute changes
Previously, we would only invalidate style when setting the `media` IDL
attribute; changing the attribute via `setAttribute()` and
`removeAttribute()` had no immediate effect.
2025-03-22 17:03:56 +01:00
Ryan Liptak
0b0f47e320 LibWeb: Make named character references more spec-compliant & efficient
There are two changes happening here: a correctness fix, and an
optimization. In theory they are unrelated, but the optimization
actually paves the way for the correctness fix.

Before this commit, the HTML tokenizer would attempt to look for named
character references by checking from after the `&` until the end of
m_decoded_input, which meant that it was unable to recognize things like
named character references that are inserted via `document.write` one
byte at a time. For example, if `&notin;` was written one-byte-at-a-time
with `document.write`, then the tokenizer would only check against `n`
since that's all that would exist at the time of the check and therefore
erroneously conclude that it was an invalid named character reference.

This commit modifies the approach taken for named character reference
matching by using a trie-like structure (specifically, a deterministic
acyclic finite state automaton or DAFSA), which allows for efficiently
matching one-character-at-a-time and therefore it is able to pick up
matching where it left off after each code point is consumed.

Note: Because it's possible for a partial match to not actually develop
into a full match (e.g. `&notindo` which could lead to `&notindot;`),
some backtracking is performed after-the-fact in order to only consume
the code points within the longest match found (e.g. `&notindo` would
backtrack back to `&not`).

With this new approach, `document.write` being called one-byte-at-a-time
is handled correctly, which allows for passing more WPT tests, with the
most directly relevant tests being
`/html/syntax/parsing/html5lib_entities01.html`
and
`/html/syntax/parsing/html5lib_entities02.html`
when run with `?run_type=write_single`. Additionally, the implementation
now better conforms to the language of the spec (and resolves a FIXME)
because exactly the matched characters are consumed and nothing more, so
SWITCH_TO is able to be used as the spec says instead of RECONSUME_IN.

The new approach is also an optimization:

- Instead of a linear search using `starts_with`, the usage of a DAFSA
  means that it is always aware of which characters can lead to a match
  at any given point, and will bail out whenever a match is no longer
  possible.
- The DAFSA is able to take advantage of the note in the section
  `13.5 Named character references` that says "This list is static and
  will not be expanded or changed in the future." and tailor its Node
  struct accordingly to tightly pack each node's data into 32-bits.
  Together with the inherent DAFSA property of redundant node
  deduplication, the amount of data stored for named character reference
  matching is minimized.

In my testing:

- A benchmark tokenizing an arbitrary set of HTML test files was about
  1.23x faster (2070ms to 1682ms).
- A benchmark tokenizing a file with tens of thousands of named
  character references mixed in with truncated named character
  references and arbitrary ASCII characters/ampersands runs about 8x
  faster (758ms to 93ms).
- The size of `liblagom-web.so` was reduced by 94.96KiB.

Some technical details:

A DAFSA (deterministic acyclic finite state automaton) is essentially a
trie flattened into an array, but it also uses techniques to minimize
redundant nodes. This provides fast lookups while minimizing the
required data size, but normally does not allow for associating data
related to each word. However, by adding a count of the number of
possible words from each node, it becomes possible to also use it to
achieve minimal perfect hashing for the set of words (which allows going
from word -> unique index as well as unique index -> word). This allows
us to store a second array of data so that the DAFSA can be used as a
lookup for e.g. the associated code points.

For the Swift implementation, the new NamedCharacterReferenceMatcher
was used to satisfy the previous API and the tokenizer was left alone
otherwise. In the future, the Swift implementation should be updated to
use the same implementation for its NamedCharacterReference state as
the updated C++ implementation.
2025-03-22 16:03:44 +01:00
Jelle Raaijmakers
2752e01fe7 CI: Add js-benchmarks workflow
This workflow starts after a successful js-artifacts workflow, picks up
the JS repl binary and runs our js-benchmarks tool. It does not yet
publish or otherwise store the benchmark results, but it's a start!
2025-03-22 13:05:43 +01:00
Jelle Raaijmakers
8671b0568d CI: Rename ladybird-js-artifacts to js-artifacts
Everything is Ladybird in this repository :^)
2025-03-22 13:05:43 +01:00
Aliaksandr Kalenik
c49dd2036b LibWeb: Mark height as definite before doing inner layout of abspos
...boxes with non-auto height.

We know for sure that by the time we layout abspos boxes, their
containing block has definite height, so it's possible to resolve
non-auto heights and mark it as definite before doing inner layout.

Big step towards having reasonable performance on
https://demo.immich.app/photos because now we avoid a bunch of work
initiated by mistakenly invoked intersection observer callbacks.

Co-Authored-By: Andreas Kling <andreas@ladybird.org>
2025-03-21 14:46:31 -05:00
Tim Ledbetter
ed62aa6224 Revert "LibJS: Reduce number of proxy traps called during for..in…
…iteration"

This reverts commit 357eeba49c.
2025-03-21 11:44:21 -05:00
Aliaksandr Kalenik
9ec986753a LibWeb: Delete const from GridDimension function parameters in GFC
Using const on primitive type was only adding unnecessary noise.
2025-03-21 15:19:39 +01:00
Aliaksandr Kalenik
76482559d0 LibWeb: Unify grid item's width and height resolution in GFC
It was annoying to maintain two separate but almost identical functions
that gradually accumulated small differences over time. This change
replaces them with a single function that resolves either width or
height, depending on the specified dimension.
2025-03-21 15:19:39 +01:00
Aliaksandr Kalenik
484cd8a0c3 LibWeb: Move item's available space getter into GridItem method in GFC
No behavior change intended.
2025-03-21 15:19:39 +01:00
Aliaksandr Kalenik
2ce40b5687 LibWeb: Move preferred size getter into GridItem method in GFC
No behavior change intended.
2025-03-21 15:19:39 +01:00
Aliaksandr Kalenik
c40f88ddcb LibWeb: Move minimum/maximum size getter into GridItem method in GFC
No behavior change intended.
2025-03-21 15:19:39 +01:00
Tim Ledbetter
40760308c6 LibWeb: Don't crash when border-spacing is set to a calc() value
Previously, the browser would crash if the `border-spacing` property
had 2 lengths and either one of these was set to a `calc()` value.
2025-03-21 08:16:30 +00:00
Andreas Kling
c528c01745 LibJS: Elide empty variable environment for default parameters
No need to create a separate variable environment if all the parameters
are going into locals anyway.
2025-03-21 00:58:34 +01:00
Andreas Kling
b971e1ece0 LibJS: Mark locals as outside TDZ immediately after initializing
This avoids emitting TDZ checks for multiple bindings declared and
referenced within one variable declaration, i.e:

    var foo = 0, bar = foo;

In the above case, we'd emit an unnecessary TDZ check for the second
reference to `foo`.
2025-03-21 00:58:34 +01:00
Jelle Raaijmakers
01031bcccb Revert "CI: Only run builds after successful linting"
This reverts commits bf333eaea2 and
6f69a445bd.

The commit linter needs to run on event `pull_request_target` to have
access to its secret token, which means we cannot have a dependency on
that job from another workflow that is run as a result of the
`pull_request` event.

Additionally, the linters were no longer run for first-time
contributors. This isn't a huge problem but it was nice that a
preliminary check took place before running the full CI on their PRs.
2025-03-21 00:02:44 +01:00
Andreas Kling
357eeba49c LibJS: Reduce number of proxy traps called during for..in iteration
Before this change, we would enumerate all the keys with
[[OwnPropertyKeys]], and then do [[GetOwnPropertyDescriptor]] twice for
each key as we went through them.

We now only do one [[GetOwnPropertyDescriptor]] per key, which
drastically reduces the number of proxy traps when those are involved.
The new trap sequence matches what you get with V8, so I don't think
anyone will be unpleasantly surprised here.
2025-03-20 17:50:02 -05:00
Jelle Raaijmakers
acc9499c5d UI: Show "Disable" title in DevTools disable button
The "disable DevTools" button looked like a "close this notification"
button to me, and although a tooltip was set, it only showed up
immediately on the AppKit UI and not the Qt version.

This makes the behavior of clicking the disable button a lot clearer by
showing a button with "Disable" as its title.
2025-03-20 17:44:07 -04:00
Andreas Kling
49d2a8df23 LibJS: Elide empty lexical environments for parameter evaluation
If all the parameter default values end up in locals, the lexical
environment we create to hold them would never be used for anything,
and so we can elide it and avoid the GC work.
2025-03-20 12:51:21 -05:00
Andreas Kling
842a189c2e LibJS: Elide empty lexical environment when direct eval() is present
Direct eval() always creates a new lexical environment, so we don't have
to worry about those here. The var environments still need special care.
2025-03-20 12:51:21 -05:00
Andreas Kling
f6141df589 LibJS: Remove unnecessary check in for..in iterator implementation 2025-03-20 12:51:21 -05:00
Andreas Kling
fb3d1c2754 LibJS: Reuse the internal iterator object across a for..in iteration
Instead of creating a new iterator result Object for every step of
for..in iteration, we can create a single object up front and reuse it
for every step. This avoids generating a bunch of garbage that isn't
observable by author code anyway.

We can also reuse the existing premade shape for these objects.
2025-03-20 12:51:21 -05:00
Andreas Kling
37bf083536 LibJS: Do a single pass to prune non-enumerable keys for iteration
Instead of pruning as-we-go, which means a ton of hash lookups,
we now only do a single pass to prune all non-enumerable keys when
setting up for for..in iteration.
2025-03-20 12:51:21 -05:00
Andreas Kling
660d533b50 LibJS: Don't assume [[GetOwnPropertyDescriptor]] always succeeds
It can fail if we're talking to a badly-behaved proxy when enumerating
object properties for iteration.
2025-03-20 12:51:21 -05:00
Andreas Kling
37c7eb14fe LibJS: Let GetGlobal cache module environment lookups when possible 2025-03-20 12:51:21 -05:00
Andreas Kling
8fcff2fa18 LibJS: Store Module::environment() as ModuleEnvironment
Let's use a more specific type here to allow for devirtualization.
2025-03-20 12:51:21 -05:00
Andrew Kaster
603df37a88 LibWeb: Devirtualize CSS::CalculatedOr
This fixes a compile warning on GCC 13.3.0 where it warns about the
use of Variant within this class with no key function. Since the class
was almost a CRTP base class, make it a real one.
2025-03-20 11:36:09 -06:00
Andrew Kaster
f22f6e1f5b CMake: Remove unused CMake functions 2025-03-20 11:36:09 -06:00
Tim Ledbetter
5bfbb7abe6 LibWeb: Preserve unit when serializing angle values
Previously, when serializing an angle value, we would always convert it
to degrees. We now canonicalize the angle value only when serializing
its computed value.
2025-03-20 16:59:27 +00:00
Tim Ledbetter
d0be5a0cdf LibWeb: Preserve unit when serializing time values
Previously, when serializing a time value, we would always convert it
to seconds. We now canonicalize the time value only when serializing
its computed value.
2025-03-20 16:59:27 +00:00
Tim Ledbetter
2672fe99b7 LibWeb: Set correct longhands if grid-area subproperties are omitted 2025-03-20 16:59:27 +00:00
Tim Ledbetter
c029a9c98c LibWeb: Serialize grid-area as auto if all sub-properties are auto 2025-03-20 16:59:27 +00:00
aplefull
57d0c563e0 LibGfx: Fix handling of partially corrupt GIFs
GIF loader was completely failing when encountering errors with
frame descriptors or individual frames, even when some frames were
successfully loaded. Now we attempt to decode at least some frames
and fail only when no frames can be decoded at all.
2025-03-20 16:12:53 +01:00
Tim Ledbetter
54351e7327 LibWeb: Use shortest serialization for shorthands with repeated values
For shorthands where all the values are repeated, we now only output
the value once.
2025-03-20 14:30:55 +01:00
Psychpsyo
528af90cd4 Meta: Make CI enforce doctype in test cases
This currently does not enforce it on Layout tests, even though
it seems most necessary there.
This is to speed up the review on this PR due to an excessive
amount of layout tests that would need rebaselining if DOCTYPEs
were added to them.
2025-03-20 11:50:49 +01:00
Psychpsyo
0b0dd7d4a5 Meta: Add DOCTYPEs to text tests that need rebaselining after
This is a separate commit from the one that adds DOCTYPEs to all
the other text tests, to make review easier.
2025-03-20 11:50:49 +01:00
Psychpsyo
fed0d6b892 Meta: Add DOCTYPEs to ref tests 2025-03-20 11:50:49 +01:00
Psychpsyo
b3487d8994 Meta: Add DOCTYPEs to most text tests 2025-03-20 11:50:49 +01:00
Psychpsyo
a5a84159a3 Meta: Add DOCTYPEs to sceenshot tests
input-placeholder-ref was modified because the input box ends up
being slightly wider outside of quirks mode.
2025-03-20 11:50:49 +01:00
Jelle Raaijmakers
bf333eaea2 CI: Only run commit linter for pull requests, not pushes
This requires us to always run the CI job and check the individual jobs'
results, since only having `needs:` will not work when `lint_commits` is
potentially skipped.
2025-03-20 11:39:29 +01:00
Jelle Raaijmakers
6f69a445bd CI: Only run builds after successful linting
We can prevent running builds unnecessarily by requiring the linters to
succeed first. If either the code or commit linter fails, it means the
author of the PR needs to rework their branch and after pushing their
changes, we need to do a full new CI run anyway.
2025-03-20 11:14:56 +01:00