LibWeb/CSS: Use CSS::URL for <url> and <paint> types

This commit is contained in:
Sam Atkins 2025-04-29 15:32:46 +01:00
commit 326933cd93
Notes: github-actions[bot] 2025-04-30 16:39:41 +00:00
7 changed files with 40 additions and 26 deletions

View file

@ -8,6 +8,7 @@
#pragma once
#include <LibGfx/PaintStyle.h>
#include <LibWeb/CSS/URL.h>
#include <LibWeb/DOM/Node.h>
#include <LibWeb/SVG/AttributeParser.h>
#include <LibWeb/SVG/SVGAnimatedTransformList.h>
@ -91,6 +92,21 @@ protected:
return {};
}
template<typename T>
GC::Ptr<T> try_resolve_url_to(CSS::URL const& url) const
{
// FIXME: Complete and use the entire URL, not just the fragment.
Optional<FlyString> fragment;
if (auto fragment_offset = url.url().find_byte_offset('#'); fragment_offset.has_value()) {
fragment = MUST(url.url().substring_from_byte_offset_with_shared_superstring(fragment_offset.value() + 1));
}
if (!fragment.has_value())
return {};
if (auto node = document().get_element_by_id(*fragment); node && is<T>(*node))
return static_cast<T&>(*node);
return {};
}
private:
virtual bool is_svg_graphics_element() const final { return true; }
float resolve_relative_to_viewport_size(CSS::LengthPercentage const& length_percentage) const;