mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-19 15:32:31 +00:00
LibWeb/CSS: Store CSSStyleSheet location as a URL
We already have a URL when we construct these, and we want a URL later, so avoid serializing and re-parsing it.
This commit is contained in:
parent
5cc371d54c
commit
da1ff1ba40
Notes:
github-actions[bot]
2025-04-09 17:48:14 +00:00
Author: https://github.com/AtkinsSJ
Commit: da1ff1ba40
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4285
Reviewed-by: https://github.com/tcl3 ✅
7 changed files with 20 additions and 12 deletions
|
@ -37,13 +37,13 @@ WebIDL::ExceptionOr<GC::Ref<CSSStyleSheet>> CSSStyleSheet::construct_impl(JS::Re
|
|||
|
||||
// 2. Set sheet’s location to the base URL of the associated Document for the current principal global object.
|
||||
auto associated_document = as<HTML::Window>(HTML::current_principal_global_object()).document();
|
||||
sheet->set_location(associated_document->base_url().to_string());
|
||||
sheet->set_location(associated_document->base_url());
|
||||
|
||||
// 3. Set sheet’s stylesheet base URL to the baseURL attribute value from options.
|
||||
if (options.has_value() && options->base_url.has_value()) {
|
||||
Optional<URL::URL> sheet_location_url;
|
||||
if (sheet->location().has_value())
|
||||
sheet_location_url = URL::Parser::basic_parse(sheet->location().release_value());
|
||||
sheet_location_url = sheet->location().release_value();
|
||||
|
||||
// AD-HOC: This isn't explicitly mentioned in the specification, but multiple modern browsers do this.
|
||||
Optional<URL::URL> url = sheet->location().has_value() ? sheet_location_url->complete_url(options->base_url.value()) : URL::Parser::basic_parse(options->base_url.value());
|
||||
|
@ -100,7 +100,7 @@ CSSStyleSheet::CSSStyleSheet(JS::Realm& realm, CSSRuleList& rules, MediaList& me
|
|||
, m_rules(&rules)
|
||||
{
|
||||
if (location.has_value())
|
||||
set_location(location->to_string());
|
||||
set_location(move(location));
|
||||
|
||||
for (auto& rule : *m_rules)
|
||||
rule->set_parent_style_sheet(this);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue