mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-28 05:52:53 +00:00
LibWeb/CSS: Parse <url>
as a new CSS::URL type
Our previous approach to `<url>` had a couple of issues: - We'd complete the URL during parsing, when we should actually keep it as the original string until it's used. - There's nowhere for us to store `<url-modifier>`s on a `URL::URL`. So, `CSS::URL` is a solution to this. It holds the original URL string, and later will also hold any modifiers. This commit parses all `<url>`s as `CSS::URL`, but then converts it into a `URL::URL`, so no user code is changed. These will be modified in subsequent commits. For `@namespace`, we were never supposed to complete the URL at all, so this makes that more correct already. However, in practice all `@namespace`s are absolute URLs already, so this should have no observable effects.
This commit is contained in:
parent
c82f4b46a2
commit
7216c6b050
Notes:
github-actions[bot]
2025-04-09 17:47:57 +00:00
Author: https://github.com/AtkinsSJ
Commit: 7216c6b050
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4285
Reviewed-by: https://github.com/tcl3 ✅
7 changed files with 101 additions and 27 deletions
31
Libraries/LibWeb/CSS/URL.cpp
Normal file
31
Libraries/LibWeb/CSS/URL.cpp
Normal file
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* Copyright (c) 2025, Sam Atkins <sam@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibWeb/CSS/Serialize.h>
|
||||
#include <LibWeb/CSS/URL.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
||||
URL::URL(String url)
|
||||
: m_url(move(url))
|
||||
{
|
||||
}
|
||||
|
||||
// https://drafts.csswg.org/cssom-1/#serialize-a-url
|
||||
String URL::to_string() const
|
||||
{
|
||||
// To serialize a URL means to create a string represented by "url(", followed by the serialization of the URL as a string, followed by ")".
|
||||
StringBuilder builder;
|
||||
builder.append("url("sv);
|
||||
serialize_a_string(builder, m_url);
|
||||
builder.append(')');
|
||||
|
||||
return builder.to_string_without_validation();
|
||||
}
|
||||
|
||||
bool URL::operator==(URL const&) const = default;
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue