Commit Graph

1612 Commits

Author SHA1 Message Date
sin-ack
9121cc7cae LibWeb: Implement CanvasRenderingContext2D.measureText
This requires an implementation of the "text preparation algorithm" as
specified here:

html.spec.whatwg.org/multipage/canvas.html#text-preparation-algorithm

However, we're missing a lot of things such as the
CanvasTextDrawingStyles interface, so most of the algorithm was not
implemented. Additionally, we also are not able to use a LineBox like
the algorithm suggests, because our layouting infra is not up to the
task yet. The prepare_text function does nothing other than figuring out
the width of the given text and return glyphs with offsets at the
moment.
2022-01-04 22:41:07 +00:00
Linus Groh
85f0fc2b83 LibJS: Return Optional<T> from Completion::{value,target}(), not T
In the end this is a nicer API than having separate has_{value,target}()
and having to check those first, and then making another Optional from
the unwrapped value:

    completion.has_value() ? completion.value() : Optional<Value> {}
    //                       ^^^^^^^^^^^^^^^^^^
    //         Implicit creation of non-empty Optional<Value>

This way we need to unwrap the optional ourselves, but can easily pass
it to something else as well.

This is in anticipation of the AST using completions :^)
2022-01-03 21:50:50 +01:00
Sam Atkins
416033a660 LibWeb: Support range syntax for media queries
This means you can now do queries like:

```css
@media (400px <= width < 800px) { }
```

Chromium and Firefox which I tested with both don't support this yet, so
that's cool. :^)
2022-01-02 15:43:51 +01:00
Sam Atkins
c3bf9e5b79 LibWeb: Rewrite media-query parsing to match spec grammar
Past me decided that the grammar was overly verbose and I could do it
better myself. Which seemed fine until the spec changed and I didn't
know how to integrate the changes. Lesson learned! :^)

Rather than have a function for every single part of the grammar, I have
written some as lambdas, and combned `<media-condition>` and
`<media-condition-without-or>` into one function. But otherwise it's
close to the spec, with comments listing the part of the grammar being
parsed, so hopefully it will be easier to make future adjustments!

This does not add any new functionality.
2022-01-02 15:43:51 +01:00
Sam Atkins
b6fe7cc324 LibWeb: Make MediaCondition a top-level type and add factory methods 2022-01-02 15:43:51 +01:00
Sam Atkins
ae4f0000c8 LibWeb: Make MediaFeature a top-level class and add factory methods
Web::CSS::MediaQuery::MediaFeature::Type was getting a bit ridiculous!
Also, this moves the detection of "min-" and "max-" media-features into
the MediaFeature itself, since this is an implementation detail, not
part of the spec.
2022-01-02 15:43:51 +01:00
Sam Atkins
d470e7e817 LibWeb: Remove media-query-related identifiers from identifiers.json
Having these in here was a hack to support the other hack of making
media-queries use StyleValues. Now they don't do that, so we can remove
these again and keep things hygienic.
2022-01-02 15:43:51 +01:00
Sam Atkins
6299d68e45 LibWeb: Introduce MediaFeatureValue type for use in media queries
Previously, we were using StyleValues for this, which was a bit of a
hack and was brittle, breaking when I modified how custom properties
were parsed. This is better and also lets us limit the kinds of value
that can be used here, to match the spec.
2022-01-02 15:43:51 +01:00
Sam Atkins
0a8e289f37 LibWeb: Update <general-enclosed> definition to match spec change
See https://github.com/w3c/csswg-drafts/pull/6799
2022-01-02 15:43:51 +01:00
Ben Wiederhake
3013e74d3a LibWeb: Avoid unnecessary copies in StyleInvalidator 2022-01-01 15:40:39 +01:00
Elyse
8d1fb299b1 LibGUI+LibWeb: Use 'decrease_slider_by_steps()' method
This method allow us to avoid repeating the pattern
'set_value(value() - step() * step_number)'.
2021-12-30 14:31:50 +01:00
Elyse
cee4e02134 LibGUI+LibWeb: Use 'increase_slider_by_steps()' method
This method allow us to avoid repeating the pattern
'set_value(value() + step() * step_number)'.
2021-12-30 14:31:50 +01:00
Elyse
086615535f Everywhere: Use 'decrease_slider_by()' method from AbstractSlider
The same idea as 'increase_slider_by()', it helps us to avoid repeating
the pattern 'set_value(value() - delta)'.
2021-12-30 14:31:50 +01:00
Elyse
d53e1fa1fa Everywhere: Use 'increase_slider_by()' method from AbstractSlider
This method help us to avoid repeating the pattern
'set_value(value() + delta)'.
2021-12-30 14:31:50 +01:00
Luke Wilde
4427386d5f LibWeb: Implement Element.getAttributeNames 2021-12-30 14:30:35 +01:00
Sam Atkins
5d0851cb0e LibWeb: Use start_of_input_stream_twin() for is_valid_escape_sequence()
This means we can get rid of the hacks where we were peeking a code
point instead of getting the next one so that we could peek_twin()
later. Now, we follow the spec more closely. :^)
2021-12-27 22:56:08 +01:00
Sam Atkins
269a24d4ca LibWeb: Pass correct values to would_start_an_identifier()
Same as with would_start_a_number(), we were skipping a code point.
2021-12-27 22:56:08 +01:00
Sam Atkins
bb82ee5530 LibWeb: Pass correct values to would_start_a_number()
This fixes the crash that Luke found using Domato:
```css
. foo {
    mso-border-alt: solid  .-1pt;
}
```

The spec distinguishes between "If the next 3 code points would
start..." and "If the input stream starts with..." but we were treating
them the same way, skipping the first code point in the process.
2021-12-27 22:56:08 +01:00
Sam Atkins
981badb45f LibWeb: Add CSS::Tokenizer::start_of_input_stream_[twin|triplet]()
These correspond to "If the input stream starts with..." in the spec,
which up until now we were not handling correctly, which led to some fun
bugs.

As noted, reconsuming the input code point in order to read its value is
hacky, but works. Keeping track of the current code point in Tokenizer
would be nicer, when I'm feeling brave enough to mess with it!
2021-12-27 22:56:08 +01:00
Sam Atkins
2f3e24d71e LibWeb: Add rudimentary styling to <details> and <summary> 2021-12-27 21:44:07 +01:00
Linus Groh
1298c27ca9 LibWeb: Implement CanvasRenderingContext2D.isContextLost()
Note that we don't implement the "context lost steps" yet, so this will
always return the initial value (false).
2021-12-27 16:43:23 +01:00
Linus Groh
2576af5db1 LibWeb: Implement CanvasRenderingContext2D.reset() 2021-12-27 16:43:23 +01:00
Linus Groh
3e0e965f24 LibWeb: Implement CanvasRenderingContext2D.restore() 2021-12-27 16:43:23 +01:00
Linus Groh
7d435b5ada LibWeb: Implement CanvasRenderingContext2D.save() 2021-12-27 16:43:23 +01:00
Linus Groh
6d50ff71de LibWeb: Encapsulate canvas drawing state in a struct
This will allow us to easily add copies of the relevant canvas drawing
state to a stack, and likewise replace the current drawing  state with
an entry from that stack.
2021-12-27 16:43:23 +01:00
Linus Groh
b32893eb54 LibWeb: Let canvas {fill,stroke}Style default to black, not transparent
I don't know if the original author simply missed this or thought the
default color of Gfx::Color is black, but this meant that drawing on a
canvas without explicitly setting a fillStyle or strokeStyle first would
be drawn in transparent color and therefore be invisible.

In the spec this is indicated by a small comment in the IDL definition:

    attribute ... strokeStyle; // (default black)
    attribute ... fillStyle; // (default black)

I'm starting to question whether Gfx::Color actually *should* have a
default constructor.
2021-12-27 16:43:23 +01:00
Linus Groh
6faaee2bc8 LibWeb: Fix copy/paste typo in CanvasRenderingContext2D::stroke_style()
This returned the fill style, not the stroke style!
2021-12-27 16:43:23 +01:00
Luke Wilde
7fae46361b LibWeb: Fix null-deref in <table> delete_row with index = -1 and no rows
This wasn't quite following what the spec says for step 2:
"If index is −1, then remove the last element in the rows collection
from its parent, or do nothing if the rows collection is empty."

It was behaving like:
"If index is −1 and the rows collection is not empty, then remove the
last element in the rows collection from its parent."

Which is not the same, as it will fall into the "Otherwise" if
`index == -1` and the rows collection is empty and try and get the -2nd
element of the rows.

Found with Domato.
2021-12-21 13:51:15 -08:00
Luke Wilde
54454952e0 LibWeb: Capture <script> element's node document on execution
Step 1 of the spec is to capture the <script> element's node document
into a local variable.

When I originally implemented this, I thought this was not necessary.
However, I realised that the script that runs can adopt the current
script element into a different document, meaning step 5.4 and 6 then
operate on the incorrect document.

Covered by this WPT: 7b0ebaccc6/html/semantics/scripting-1/the-script-element/moving-between-documents-during-evaluation.html
2021-12-21 13:50:00 -08:00
Linus Groh
67788641d3 LibWeb: Add a workaround to assign a proper mime type to QOI images 2021-12-21 13:27:27 +01:00
Ali Mohammad Pur
ed9c79e131 LibWeb: Use ByteBuffer::copy() instead of a manual copy in SubtleCrypto
Also use the HashManager(HashKind) constructor instead of the default
constructor + manual initialize() call.
2021-12-15 12:54:34 +00:00
Linus Groh
5f993eecdb LibWeb: Replace incorrect empty Optional return with ByteBuffer
This function initially returned a ByteBuffer, so `return {}` was fine.
It was then changed to return Optional<ByteBuffer>, so we accidentally
started returning an empty Optional instead. Explicitly specify the
constructor name to fix this.

Thanks to DexesTTP for catching this!
2021-12-14 19:49:15 +00:00
Linus Groh
69fe4c2aca LibWeb: Remove dbgln() left from debugging :^) 2021-12-14 08:58:13 +00:00
Linus Groh
4daf07e69f LibWeb: Implement SubtleCrypto.digest()
This is a simple implementation of SubtleCrypto.digest() using LibCrypto
under the hood, so it supports all the required hash functions:
SHA-1, SHA-256, SHA-384, SHA-512.

Two FIXMEs remain: doing the hashing "in parallel", and supporting an
object argument instead of a plain string.
2021-12-14 09:01:06 +01:00
Linus Groh
5e06d5e9e5 LibWeb: Implement "get a copy of the bytes held by the buffer source" 2021-12-14 09:01:06 +01:00
Linus Groh
615be9eb7c LibWeb: Add the SubtleCrypto interface
Just some boilerplate code to get started :^)
This adds both the SubtleCrypto constructor to the window object, as
well as the crypto.subtle instance attribute.
2021-12-14 09:01:06 +01:00
Linus Groh
f8387dea26 LibWeb: Implement TextEncoder.prototype.encoding 2021-12-12 20:58:36 +01:00
Linus Groh
f37d00c07b LibWeb: Implement TextEncoder.prototype.encode() 2021-12-12 20:58:36 +01:00
Linus Groh
35d3a1e77b LibWeb: Add the TextEncoder interface
This is from the Encoding Standard (https://encoding.spec.whatwg.org),
and therefore gets its own namespace and subdirectory within LibWeb :^)
2021-12-12 20:58:36 +01:00
Daniel Bertalan
4a81b33c07 Everywhere: Fix -Winconsistent-missing-override warnings from Clang
This option is already enabled when building Lagom, so let's enable it
for the main build too. We will no longer be surprised by Lagom Clang
CI builds failing while everything compiles locally.

Furthermore, the stronger `-Wsuggest-override` warning is enabled in
this commit, which enforces the use of the `override` keyword in all
classes, not just those which already have some methods marked as
`override`. This works with both GCC and Clang.
2021-12-11 13:14:15 -08:00
Linus Groh
038d354b5d LibJS: Remove Object::value_of()
Being really close to Object.prototype.valueOf() name wise makes this
unnecessarily confusing - while it sometimes serves as the
implementation of a valueOf() function, it's an abstraction which the
spec doesn't have.
Use the appropriate getters to retrieve specific internal slots instead,
most commonly [[FooData]] from the primitive wrapper objects.
For the Object class specifically, use the Value(Object*) ctor instead.
2021-12-10 22:52:36 +00:00
Luke Wilde
1a5bf15b4d LibWeb: Implement AbortSignal.throwIfAborted
See: https://github.com/whatwg/dom/commit/cfe2f1e
2021-12-10 23:05:36 +02:00
Luke Wilde
64040c136e LibWeb: Add support for AbortSignal.reason 2021-12-10 23:05:36 +02:00
Sam Atkins
197759e30f LibWeb: Fix off-by-one error when highlighting unquoted HTML attributes
This fixes #11166
2021-12-10 21:27:13 +01:00
Sam Atkins
54bbb97ac6 Browser+LibWeb+WebContent: Add variables display to Inspector
This allows us to see which custom properties apply to a given element,
which previously wasn't shown.
2021-12-10 06:52:17 +01:00
Sam Atkins
c9062b4ed5 LibWeb: Remove now-unused CustomStyleValue 2021-12-09 21:30:31 +01:00
Sam Atkins
c3437bccb3 LibWeb: Handle dependency cycles in CSS var()s :^)
We now detect situations like this, where variables infinitely recur,
without crashing:

```css
div {
  --a: var(--b);
  --b: var(--a);
  background: var(--a);
}

p {
  --foo: var(--foo);
  background: var(--foo);
}
```
2021-12-09 21:30:31 +01:00
Sam Atkins
3df0bf2c8d LibWeb: Mitigate the billion-laughs attack on CSS variables
We now stop processing variables once a length of 16384 tokens is
reached. This is an arbitrary number, but should be far beyond what
anyone will reasonably use, and small enough to not crash.
2021-12-09 21:30:31 +01:00
Sam Atkins
67e1125b4c LibWeb: Handle fallback values for CSS variables :^) 2021-12-09 21:30:31 +01:00
Sam Atkins
23dc0dac88 LibWeb: Parse and resolve UnresolvedStyleValues
If a property is custom or contains a `var()` reference, it cannot be
parsed into a proper StyleValue immediately, so we store it as an
UnresolvedStyleValue until the property is compute. Then, at compute
time, we resolve them by expanding out any `var()` references, and
parsing the result.

The implementation here is very naive, and involves copying the
UnresolvedStyleValue's tree of StyleComponentValueRules while copying
the contents of any `var()`s it finds along the way. This is quite an
expensive operation to do every time that the style is computed.
2021-12-09 21:30:31 +01:00