Commit graph

77 commits

Author SHA1 Message Date
Sam Atkins
7bc5949e35 LibWeb: Implement the :placeholder-shown pseudo-class
This matches if the element has a placeholder, and that placeholder is
currently visible. This applies to `<input>` and `<textarea>` elements,
but our `<textarea>` is very limited so does not support placeholders.
2023-08-23 05:30:59 +02:00
Sam Atkins
9f5b1e6614 LibWeb: Implement the :read-only and :read-write pseudo-classes 2023-08-23 05:30:59 +02:00
Sam Atkins
3d10bf3ae7 LibWeb: Implement the :target-within pseudo-class selector
As noted in a9620d8784 we don't currently
set the target element so this does not function, so no tests. But it
should work once we have a fleshed out Navigables implementation. :^)
2023-08-23 05:30:59 +02:00
Sam Atkins
3af8b491b4 LibWeb: Implement :any-link and :local-link pseudo-class selectors
`:any-link` matches links, whether they have been visited or not.

`:local-link` matches links to the current URL.
2023-08-23 05:30:59 +02:00
Sam Atkins
b8e694c0f2 LibWeb: Implement the :dir() selector pseudo-class 2023-08-21 13:51:56 +02:00
Sam Atkins
12a2750d1e LibWeb: Support multiple values in :lang() selector
Parse them, and also don't give up completely if the first language
listed doesn't match an element.
2023-08-16 18:05:26 +02:00
Sam Atkins
b314a115ca LibWeb: Use generated PseudoClass data
Everything should behave the same as before.
2023-08-12 16:26:32 +02:00
Sam Atkins
a9620d8784 LibWeb: Implement the :target selector pseudo-class
We don't yet set the Document's target element in most cases, so this
does not function very well. But that will improve once we *do* set it,
which involves a more complete Navigables implementation.
2023-08-12 08:39:04 +02:00
Sam Atkins
debf38ee9d LibWeb: Add namespaces to Attribute selectors
For now, we parse these, but don't actually consider the namespace when
matching them. `DOM::Element` does not (yet) store attribute namespaces
so we can't check what they are.
2023-08-08 20:49:45 +01:00
Sam Atkins
1858f06881 LibWeb: Add namespaces to Universal and TagName selectors 2023-08-08 20:49:45 +01:00
Sam Atkins
14e6bae593 LibWeb: Implement the :focus-visible pseudo-class
This is very naive for now, and matches whenever `:focus` does.
2023-08-03 05:25:48 +02:00
Sam Atkins
f6e4caf197 LibWeb: Implement the :buffering and :stalled pseudo-classes
Currently, HTMLMediaElement doesn't implement the stall timeout, so
`:stalled` always returns false.
2023-08-01 12:50:40 -04:00
Sam Atkins
eb7cda1172 LibWeb: Implement the :volume-locked pseudo-class 2023-08-01 12:50:40 -04:00
Sam Atkins
c8a51f232d LibWeb: Implement the :muted pseudo-class 2023-08-01 12:50:40 -04:00
Sam Atkins
7b4ae43b91 LibWeb: Implement the :seeking pseudo-class
This matches while a media element is seeking.
2023-08-01 12:50:40 -04:00
Sam Atkins
4df5e24926 LibWeb: Implement the :playing and :paused pseudo-classes
These match media elements (`<video>` and `<audio>`) which are playing
or paused, respectively.
2023-08-01 12:50:40 -04:00
Andreas Kling
088cc4ea73 LibWeb: Parse CSS :host selector
Let's at least parse it, even if we don't implement matching for it yet.
2023-07-05 12:42:02 +02:00
Luke Wilde
a744ae79ff LibWeb: Implement the :defined pseudo class
This selects an element if it is either a built-in element, or an
upgraded custom element.
2023-04-06 11:36:56 +02:00
Simon Wanner
c8ebacb1c9 LibWeb: Support the :scope pseudo class 2023-03-21 10:45:19 +01:00
Srikavin Ramkumar
c3d6709a9e LibWeb: Implement selector matching for :indeterminate pseudo-class 2023-03-20 10:15:58 +00:00
Srikavin Ramkumar
aad4051885 LibWeb: Match selected option elements with checked pseudo-class 2023-03-20 10:15:58 +00:00
Kenneth Myhra
be958a14cf LibWeb: Use from_deprecated_fly_string() instead of from_utf8()
Use FlyString::from_deprecated_fly_string() in these instances instead
of FlyString::from_utf8(). As we convert to new FlyString/String we want
to be aware of these potential unnecessary allocations.
2023-03-11 18:32:33 +00:00
Andreas Kling
2042993997 LibWeb: Convert DOM::Element::m_classes to the new AK::FlyString
This makes selector matching significantly faster by not forcing us to
convert from FlyString to DeprecatedFlyString when matching class
selectors. :^)
2023-03-08 13:19:15 +01:00
Sam Atkins
13d2111b74 LibWeb: Port Selector to new Strings
Also use `Infra::is_ascii_case_insensitive_match()` in some appropriate
places, after checking the specs.
2023-02-19 00:51:16 +01:00
Timothy Flynn
f3db548a3d AK+Everywhere: Rename FlyString to DeprecatedFlyString
DeprecatedFlyString relies heavily on DeprecatedString's StringImpl, so
let's rename it to A) match the name of DeprecatedString, B) write a new
FlyString class that is tied to String.
2023-01-09 23:00:24 +00:00
Luke Wilde
9662eec388 LibWeb: Apply :enabled pseudo class to only certain elements
I thought the spec listing out the elements again was an oversight, but
it isn't, as simply inverting "is_actually_disabled" makes :enabled
apply to every element.
2022-09-30 21:46:53 +02:00
Luke Wilde
2133b7d58a LibWeb: Implement :enabled and :disabled pseudo classes to spec
Previously we only considered an element disabled if it was an <input>
element with the disabled attribute, but there's way more elements that
apply with more nuanced disabled/enabled rules.
2022-09-30 18:05:48 +02:00
Andreas Kling
1dd4e2dc87 LibWeb: Cache lowercased names in SimpleSelector
When matching selectors in HTML documents, we know that all the elements
have lowercase local names already (the parser makes sure of this.)

Style sheets still need to remember the original name strings, in case
we want to match against non-HTML content like XML/SVG. To make the
common HTML case faster, we now cache a lowercase version of the name
with each type/class/id SimpleSelector.

This makes tag type checks O(1) instead of O(n).
2022-09-15 16:16:56 +02:00
Andreas Kling
4b9c5635b3 LibWeb: Make :link selector behave according to spec
It should match any `a` or `area` element that has an `href` attribute,
not any element *inside* an enclosing linked element.
2022-09-14 14:43:17 +02:00
Andreas Kling
031322fde3 LibWeb: Make :enabled and :disabled selector handling more idiomatic 2022-07-27 17:29:48 +02:00
networkException
48c54e6796 LibWeb: Use lowercase type selectors to match against html elements
Previously we would fail to match a selector like "NAV" against a <nav>
html element.

Note that the strings must be identical in XML Documents.
2022-07-04 12:39:48 +02:00
Idan Horowitz
086969277e Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
Daniel Glazman
91e1383b85 LibWeb: Implement attribute selector case identifier 2022-03-29 18:53:20 +02:00
Daniel Glazman
049d847230 LibWeb: Clarify attribute selectors when needle is empty 2022-03-29 18:53:20 +02:00
Sam Atkins
31b24c2b29 LibWeb: Remove now-unused null values from Selector enums
Now that we use a Variant for the SimpleSelector's data, we don't need
to instantiate empty structs or variables for the types that aren't
used, and so we can remove `PseudoElement::None`,
`PsuedoClass::Type::None` and `Attribute::MatchType::None`.

Also, we now always initialize a SimpleSelector with a type, so
`SimpleSelector::Type::Invalid` can go too.
2022-03-22 15:47:36 +01:00
Sam Atkins
c0db19f63c LibWeb: Use a Variant for SimpleSelector's contents
This reduces SimpleSelector's size from 112 bytes to 80 bytes. :^)
2022-03-22 15:47:36 +01:00
Sam Atkins
d60b3be29a LibWeb: Implement the :focus-within selector
This matches if it has focus, or any nodes inside it do.
2022-03-20 17:35:31 +00:00
Andreas Kling
bdd42c9b0e LibWeb: Add basic support for :lang() CSS selector
This doesn't have parsing support for multiple languages in the same
selector. Support for language subcodes is not great either. But it
does do the basics.
2022-03-20 13:36:45 +01:00
Sam Atkins
5b0187477b LibWeb: Implement :nth-[last-]child(n of foo) syntax
In Selectors level 4, `:nth-child()` and `:nth-last-child()` can both
optionally take a selector-list argument. This selector-list acts as a
filter, so that only elements matching the list are counted. For
example, this means that the following are equivalent:

```css
:nth-child(2n+1 of p) {}
p:nth-of-type(2n+1) {}
```
2022-03-18 11:34:02 +01:00
Sam Atkins
993653317c LibWeb: Implement the :where() selector
This is identical to :is() except for specificity, so we can use the
same code paths. :^)
2022-03-18 11:34:02 +01:00
Sam Atkins
c148ed50bb LibWeb: Implement the :is() selector
This lets us finally get rid of a FIXME in the default style sheet. :^)
2022-03-18 11:34:02 +01:00
Andreas Kling
68f75ab98e LibWeb: :checked should only match inputs in checkbox/radio type state
We were erroneously allowing :checked to match any input element.
2022-03-16 23:29:17 +01:00
Sam Atkins
973f3c3642 LibWeb: Correct handling of negative step values in nth-foo() selectors
This should be 1% on Acid3. :^)

Added the `-5n+3` case to all `nth-of-whatever()` selector test pages,
so we can easily check that it works.
2022-03-02 17:39:57 +01:00
Sam Atkins
a57128467a LibWeb: Implement :nth-of-type and :nth-last-of-type selectors :^) 2022-02-26 15:30:24 +01:00
Andreas Kling
31508b2788 LibWeb: Make CSS :empty selector match empty text nodes as well
Previously we were only matching elements with *no* text children.
With this patch, we now also allow any number of empty text children to
be present as well.

1% progression on ACID3. :^)
2022-02-25 19:38:31 +01:00
Sam Atkins
7eb7396f8b LibWeb: Match styles for pseudo-elements
Since each selector can only have zero or one pseudo-element, we match
against it as a separate step, before matching the rest of the
selector. This should be faster, but mostly I did this because I could
not figure out how else to stop selectors without a pseudo-element from
matching the pseudo-element, eg so `.foo` styles don't affect
`.foo::before`.
2022-02-25 19:35:34 +01:00
Andreas Kling
7c33a084fb LibWeb: Support CSS :only-of-type selector
This matches any element that doesn't have a sibling with the same tag
name as itself.
2022-02-18 01:49:32 +01:00
Andreas Kling
eec34ae0e9 LibWeb: Make :checked selector actually look at checkedness
It was incorrectly testing for presence of the "checked" attribute.
2022-02-15 23:51:19 +01:00
Andreas Kling
05eb68d452 LibWeb: Make :root selector match <html> element only
We were matching every HTML element, instead of just the root (<html>)
2022-02-10 20:52:58 +01:00
Idan Horowitz
db32466499 LibWeb: Mark SelectorEngine matches-related functions as inline
The prologues and epilogues of these functions were pretty hot in a
profile of Browser, so this should help a bit.
2022-02-05 16:48:14 +01:00