mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-24 20:12:53 +00:00
LibWeb: Implement functional pseudo-element parsing
"Functional" as in "it's a function token" and not "it works", because the behaviour for these is unimplemented. :^) This is modeled after the pseudo-class parsing, but with some changes based on things I don't like about that implementation. I've implemented the `<pt-name-selector>` parameter used by view-transitions for now, but nothing else.
This commit is contained in:
parent
5cf04a33ad
commit
88e11eea2d
Notes:
github-actions[bot]
2025-03-25 07:56:12 +00:00
Author: https://github.com/AtkinsSJ
Commit: 88e11eea2d
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4063
8 changed files with 237 additions and 43 deletions
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020, Andreas Kling <andreas@ladybird.org>
|
||||
* Copyright (c) 2021-2024, Sam Atkins <sam@ladybird.org>
|
||||
* Copyright (c) 2021-2025, Sam Atkins <sam@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -285,6 +285,31 @@ u32 Selector::specificity() const
|
|||
return *m_specificity;
|
||||
}
|
||||
|
||||
String Selector::PseudoElementSelector::serialize() const
|
||||
{
|
||||
StringBuilder builder;
|
||||
builder.append("::"sv);
|
||||
|
||||
if (!m_name.is_empty()) {
|
||||
builder.append(m_name);
|
||||
} else {
|
||||
builder.append(pseudo_element_name(m_type));
|
||||
}
|
||||
|
||||
m_value.visit(
|
||||
[&builder](PTNameSelector const& pt_name_selector) {
|
||||
builder.append('(');
|
||||
if (pt_name_selector.is_universal)
|
||||
builder.append('*');
|
||||
else
|
||||
builder.append(pt_name_selector.value);
|
||||
builder.append(')');
|
||||
},
|
||||
[](Empty const&) {});
|
||||
|
||||
return builder.to_string_without_validation();
|
||||
}
|
||||
|
||||
// https://www.w3.org/TR/cssom/#serialize-a-simple-selector
|
||||
String Selector::SimpleSelector::serialize() const
|
||||
{
|
||||
|
@ -519,8 +544,7 @@ String Selector::serialize() const
|
|||
// 4. If this is the last part of the chain of the selector and there is a pseudo-element,
|
||||
// append "::" followed by the name of the pseudo-element, to s.
|
||||
if (compound_selector.simple_selectors.last().type == Selector::SimpleSelector::Type::PseudoElement) {
|
||||
s.append("::"sv);
|
||||
s.append(compound_selector.simple_selectors.last().pseudo_element().name());
|
||||
s.append(compound_selector.simple_selectors.last().pseudo_element().serialize());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue