mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-10-15 20:49:41 +00:00
LibWeb/CSS: Store StyleValue pointer instead of string on CSSStyleValue
When setting style to a CSSStyleValue we need to convert it to a StyleValue. If we already have one, we might as well use it avoid the work of serialization and re-parsing. I realised I misunderstood what "constructed from a USVString" means, so I've adjusted based on that. It does raise a question on what the source USVString is if that string resulted in multiple CSSStyleValues being created - see the linked issue.
This commit is contained in:
parent
1e1752b33b
commit
2de4fe8104
Notes:
github-actions[bot]
2025-10-04 20:58:33 +00:00
Author: https://github.com/AtkinsSJ
Commit: 2de4fe8104
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6370
6 changed files with 40 additions and 24 deletions
|
@ -7,20 +7,20 @@
|
|||
#include "CSSImageValue.h"
|
||||
#include <LibWeb/Bindings/CSSImageValuePrototype.h>
|
||||
#include <LibWeb/Bindings/Intrinsics.h>
|
||||
#include <LibWeb/CSS/StyleValues/StyleValue.h>
|
||||
#include <LibWeb/WebIDL/ExceptionOr.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
||||
GC_DEFINE_ALLOCATOR(CSSImageValue);
|
||||
|
||||
GC::Ref<CSSImageValue> CSSImageValue::create(JS::Realm& realm, String constructed_from_string)
|
||||
GC::Ref<CSSImageValue> CSSImageValue::create(JS::Realm& realm, NonnullRefPtr<StyleValue const> source_value)
|
||||
{
|
||||
return realm.create<CSSImageValue>(realm, move(constructed_from_string));
|
||||
return realm.create<CSSImageValue>(realm, move(source_value));
|
||||
}
|
||||
|
||||
CSSImageValue::CSSImageValue(JS::Realm& realm, String constructed_from_string)
|
||||
: CSSStyleValue(realm)
|
||||
, m_constructed_from_string(move(constructed_from_string))
|
||||
CSSImageValue::CSSImageValue(JS::Realm& realm, NonnullRefPtr<StyleValue const> source_value)
|
||||
: CSSStyleValue(realm, move(source_value))
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -34,8 +34,8 @@ void CSSImageValue::initialize(JS::Realm& realm)
|
|||
WebIDL::ExceptionOr<String> CSSImageValue::to_string() const
|
||||
{
|
||||
// AD-HOC: The spec doesn't say how to serialize this, as it's intentionally a black box.
|
||||
// We just serialize the source string that was used to construct this.
|
||||
return m_constructed_from_string;
|
||||
// We just rely on CSSStyleValue serializing its held StyleValue.
|
||||
return Base::to_string();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue