mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-20 11:36:10 +00:00
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.
31 lines
699 B
C++
31 lines
699 B
C++
/*
|
|
* 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;
|
|
|
|
}
|