mirror of
https://github.com/zebrajr/ladybird.git
synced 2025-12-06 00:19:53 +01:00
LibWeb/CSS: Add ability to reify a StyleValue
When no better reification form is available, we produce an opaque CSSStyleValue with a serialized value. For starters, this will be the only way to reify, and then we'll add others later.
This commit is contained in:
parent
b80930ae34
commit
276540fbe9
|
|
@ -13,12 +13,12 @@ namespace Web::CSS {
|
|||
|
||||
GC_DEFINE_ALLOCATOR(CSSStyleValue);
|
||||
|
||||
GC::Ref<CSSStyleValue> CSSStyleValue::create(JS::Realm& realm, Optional<String> associated_property, Optional<String> constructed_from_string)
|
||||
GC::Ref<CSSStyleValue> CSSStyleValue::create(JS::Realm& realm, String associated_property, String constructed_from_string)
|
||||
{
|
||||
return realm.create<CSSStyleValue>(realm, move(associated_property), move(constructed_from_string));
|
||||
}
|
||||
|
||||
CSSStyleValue::CSSStyleValue(JS::Realm& realm, Optional<String> associated_property, Optional<String> constructed_from_string)
|
||||
CSSStyleValue::CSSStyleValue(JS::Realm& realm, String associated_property, String constructed_from_string)
|
||||
: PlatformObject(realm)
|
||||
, m_associated_property(move(associated_property))
|
||||
, m_constructed_from_string(move(constructed_from_string))
|
||||
|
|
|
|||
|
|
@ -16,14 +16,14 @@ class CSSStyleValue : public Bindings::PlatformObject {
|
|||
GC_DECLARE_ALLOCATOR(CSSStyleValue);
|
||||
|
||||
public:
|
||||
[[nodiscard]] static GC::Ref<CSSStyleValue> create(JS::Realm&, Optional<String> associated_property = {}, Optional<String> constructed_from_string = {});
|
||||
[[nodiscard]] static GC::Ref<CSSStyleValue> create(JS::Realm&, String associated_property, String constructed_from_string);
|
||||
|
||||
virtual ~CSSStyleValue() override = default;
|
||||
|
||||
virtual String to_string() const;
|
||||
|
||||
private:
|
||||
explicit CSSStyleValue(JS::Realm&, Optional<String> associated_property = {}, Optional<String> constructed_from_string = {});
|
||||
explicit CSSStyleValue(JS::Realm&, String associated_property, String constructed_from_string);
|
||||
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
#include <LibGfx/Font/Font.h>
|
||||
#include <LibGfx/Font/FontStyleMapping.h>
|
||||
#include <LibGfx/Font/FontWeight.h>
|
||||
#include <LibWeb/CSS/CSSStyleValue.h>
|
||||
#include <LibWeb/CSS/Parser/Parser.h>
|
||||
#include <LibWeb/CSS/StyleValues/AbstractImageStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/AnchorSizeStyleValue.h>
|
||||
|
|
@ -142,6 +143,13 @@ Vector<Parser::ComponentValue> StyleValue::tokenize() const
|
|||
return Parser::Parser::create(Parser::ParsingParams {}, to_string(SerializationMode::Normal)).parse_as_list_of_component_values();
|
||||
}
|
||||
|
||||
// https://drafts.css-houdini.org/css-typed-om-1/#reify-as-a-cssstylevalue
|
||||
GC::Ref<CSSStyleValue> StyleValue::reify(JS::Realm& realm, String const& associated_property) const
|
||||
{
|
||||
// 1. Return a new CSSStyleValue object representing value whose [[associatedProperty]] internal slot is set to property.
|
||||
return CSSStyleValue::create(realm, associated_property, to_string(SerializationMode::Normal));
|
||||
}
|
||||
|
||||
int StyleValue::to_font_weight() const
|
||||
{
|
||||
if (is_keyword()) {
|
||||
|
|
|
|||
|
|
@ -207,6 +207,7 @@ public:
|
|||
|
||||
virtual String to_string(SerializationMode) const = 0;
|
||||
virtual Vector<Parser::ComponentValue> tokenize() const;
|
||||
virtual GC::Ref<CSSStyleValue> reify(JS::Realm&, String const& associated_property) const;
|
||||
|
||||
[[nodiscard]] int to_font_weight() const;
|
||||
[[nodiscard]] int to_font_slope() const;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user