mirror of
https://github.com/zebrajr/ladybird.git
synced 2025-12-06 00:19:53 +01:00
LibWeb: Absolutize CSS image URLs for computed style resolution
For getComputedStyle(), we must return an absolute URL for image style values. We currently return the raw parsed URL. This fixes loading the marker icons on https://usermap.serenityos.org.
This commit is contained in:
parent
3ae2220534
commit
7d99a92135
|
|
@ -7,6 +7,7 @@
|
|||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibURL/Parser.h>
|
||||
#include <LibWeb/CSS/ComputedValues.h>
|
||||
#include <LibWeb/CSS/Fetch.h>
|
||||
#include <LibWeb/CSS/StyleValues/ImageStyleValue.h>
|
||||
|
|
@ -182,4 +183,33 @@ void ImageStyleValue::set_style_sheet(GC::Ptr<CSSStyleSheet> style_sheet)
|
|||
m_style_sheet = style_sheet;
|
||||
}
|
||||
|
||||
ValueComparingNonnullRefPtr<CSSStyleValue const> ImageStyleValue::absolutized(CSSPixelRect const&, Length::FontMetrics const&, Length::FontMetrics const&) const
|
||||
{
|
||||
if (m_url.url().is_empty())
|
||||
return *this;
|
||||
|
||||
// FIXME: The spec has been updated to handle this better. The computation of the base URL here is roughly based on:
|
||||
// https://drafts.csswg.org/css-values-4/#style-resource-base-url
|
||||
// https://github.com/w3c/csswg-drafts/pull/12261
|
||||
auto base_url = [&]() -> Optional<::URL::URL> {
|
||||
if (m_style_sheet) {
|
||||
return m_style_sheet->base_url()
|
||||
.value_or_lazy_evaluated_optional([&]() { return m_style_sheet->location(); })
|
||||
.value_or_lazy_evaluated_optional([&]() { return HTML::relevant_settings_object(*m_style_sheet).api_base_url(); });
|
||||
}
|
||||
|
||||
if (m_document)
|
||||
return m_document->base_url();
|
||||
|
||||
return {};
|
||||
}();
|
||||
|
||||
if (base_url.has_value()) {
|
||||
if (auto resolved_url = ::URL::Parser::basic_parse(m_url.url(), *base_url); resolved_url.has_value())
|
||||
return ImageStyleValue::create(*resolved_url);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,6 +53,7 @@ private:
|
|||
ImageStyleValue(URL const&);
|
||||
|
||||
virtual void set_style_sheet(GC::Ptr<CSSStyleSheet>) override;
|
||||
virtual ValueComparingNonnullRefPtr<CSSStyleValue const> absolutized(CSSPixelRect const& viewport_rect, Length::FontMetrics const& font_metrics, Length::FontMetrics const& root_font_metrics) const override;
|
||||
|
||||
void animate();
|
||||
Gfx::ImmutableBitmap const* bitmap(size_t frame_index, Gfx::IntSize = {}) const;
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ Harness status: OK
|
|||
|
||||
Found 2 tests
|
||||
|
||||
2 Fail
|
||||
Fail base-relative URL: relative-image-url
|
||||
1 Pass
|
||||
1 Fail
|
||||
Pass base-relative URL: relative-image-url
|
||||
Fail base-relative URL: relative-image-variable-url
|
||||
|
|
@ -2,7 +2,8 @@ Harness status: OK
|
|||
|
||||
Found 3 tests
|
||||
|
||||
3 Fail
|
||||
Fail stylesheet-relative URL: stylesheet-relative-image
|
||||
1 Pass
|
||||
2 Fail
|
||||
Pass stylesheet-relative URL: stylesheet-relative-image
|
||||
Fail stylesheet-relative URL: stylesheet-relative-variable-image
|
||||
Fail stylesheet-relative URL: stylesheet-relative-document-variable-image
|
||||
Loading…
Reference in New Issue
Block a user