mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 20:47:43 +00:00
LibWeb: Remove CSS::Parser::ParsingContext's default constructor
This relied on pulling the current realm from the main thread VM, which requires an execution context to be on the VM's stack. This heavily relied on the dummy execution context that is always on the stack, for example, when parsing the UA style sheets where no JavaScript is running.
This commit is contained in:
parent
54a1ec2f10
commit
f7ff1fd985
12 changed files with 73 additions and 72 deletions
|
@ -49,6 +49,7 @@ ErrorOr<void> generate_header_file(JsonObject& properties, Core::File& file)
|
||||||
#include <AK/NonnullRefPtr.h>
|
#include <AK/NonnullRefPtr.h>
|
||||||
#include <AK/StringView.h>
|
#include <AK/StringView.h>
|
||||||
#include <AK/Traits.h>
|
#include <AK/Traits.h>
|
||||||
|
#include <LibJS/Forward.h>
|
||||||
#include <LibWeb/Forward.h>
|
#include <LibWeb/Forward.h>
|
||||||
|
|
||||||
namespace Web::CSS {
|
namespace Web::CSS {
|
||||||
|
@ -106,7 +107,7 @@ PropertyID property_id_from_camel_case_string(StringView);
|
||||||
PropertyID property_id_from_string(StringView);
|
PropertyID property_id_from_string(StringView);
|
||||||
StringView string_from_property_id(PropertyID);
|
StringView string_from_property_id(PropertyID);
|
||||||
bool is_inherited_property(PropertyID);
|
bool is_inherited_property(PropertyID);
|
||||||
NonnullRefPtr<StyleValue> property_initial_value(PropertyID);
|
NonnullRefPtr<StyleValue> property_initial_value(JS::Realm&, PropertyID);
|
||||||
|
|
||||||
bool property_accepts_value(PropertyID, StyleValue&);
|
bool property_accepts_value(PropertyID, StyleValue&);
|
||||||
size_t property_maximum_value_count(PropertyID);
|
size_t property_maximum_value_count(PropertyID);
|
||||||
|
@ -308,13 +309,13 @@ bool property_affects_stacking_context(PropertyID property_id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NonnullRefPtr<StyleValue> property_initial_value(PropertyID property_id)
|
NonnullRefPtr<StyleValue> property_initial_value(JS::Realm& context_realm, PropertyID property_id)
|
||||||
{
|
{
|
||||||
static Array<RefPtr<StyleValue>, to_underlying(last_property_id) + 1> initial_values;
|
static Array<RefPtr<StyleValue>, to_underlying(last_property_id) + 1> initial_values;
|
||||||
static bool initialized = false;
|
static bool initialized = false;
|
||||||
if (!initialized) {
|
if (!initialized) {
|
||||||
initialized = true;
|
initialized = true;
|
||||||
Parser::ParsingContext parsing_context;
|
Parser::ParsingContext parsing_context(context_realm);
|
||||||
)~~~");
|
)~~~");
|
||||||
|
|
||||||
// NOTE: Parsing a shorthand property requires that its longhands are already available here.
|
// NOTE: Parsing a shorthand property requires that its longhands are already available here.
|
||||||
|
|
|
@ -41,6 +41,8 @@ JS_DEFINE_NATIVE_FUNCTION(CSSNamespace::escape)
|
||||||
// https://www.w3.org/TR/css-conditional-3/#dom-css-supports
|
// https://www.w3.org/TR/css-conditional-3/#dom-css-supports
|
||||||
JS_DEFINE_NATIVE_FUNCTION(CSSNamespace::supports)
|
JS_DEFINE_NATIVE_FUNCTION(CSSNamespace::supports)
|
||||||
{
|
{
|
||||||
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
if (!vm.argument_count())
|
if (!vm.argument_count())
|
||||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountAtLeastOne, "CSS.supports");
|
return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountAtLeastOne, "CSS.supports");
|
||||||
|
|
||||||
|
@ -53,7 +55,7 @@ JS_DEFINE_NATIVE_FUNCTION(CSSNamespace::supports)
|
||||||
auto property = CSS::property_id_from_string(property_name);
|
auto property = CSS::property_id_from_string(property_name);
|
||||||
if (property != CSS::PropertyID::Invalid) {
|
if (property != CSS::PropertyID::Invalid) {
|
||||||
auto value_string = TRY(vm.argument(1).to_deprecated_string(vm));
|
auto value_string = TRY(vm.argument(1).to_deprecated_string(vm));
|
||||||
if (parse_css_value({}, value_string, property))
|
if (parse_css_value(CSS::Parser::ParsingContext { realm }, value_string, property))
|
||||||
return JS::Value(true);
|
return JS::Value(true);
|
||||||
}
|
}
|
||||||
// Otherwise, if property is a custom property name string, return true.
|
// Otherwise, if property is a custom property name string, return true.
|
||||||
|
@ -69,11 +71,11 @@ JS_DEFINE_NATIVE_FUNCTION(CSSNamespace::supports)
|
||||||
auto supports_text = TRY(vm.argument(0).to_deprecated_string(vm));
|
auto supports_text = TRY(vm.argument(0).to_deprecated_string(vm));
|
||||||
|
|
||||||
// If conditionText, parsed and evaluated as a <supports-condition>, would return true, return true.
|
// If conditionText, parsed and evaluated as a <supports-condition>, would return true, return true.
|
||||||
if (auto supports = parse_css_supports({}, supports_text); supports && supports->matches())
|
if (auto supports = parse_css_supports(CSS::Parser::ParsingContext { realm }, supports_text); supports && supports->matches())
|
||||||
return JS::Value(true);
|
return JS::Value(true);
|
||||||
|
|
||||||
// Otherwise, If conditionText, wrapped in parentheses and then parsed and evaluated as a <supports-condition>, would return true, return true.
|
// Otherwise, If conditionText, wrapped in parentheses and then parsed and evaluated as a <supports-condition>, would return true, return true.
|
||||||
if (auto supports = parse_css_supports({}, DeprecatedString::formatted("({})", supports_text)); supports && supports->matches())
|
if (auto supports = parse_css_supports(CSS::Parser::ParsingContext { realm }, DeprecatedString::formatted("({})", supports_text)); supports && supports->matches())
|
||||||
return JS::Value(true);
|
return JS::Value(true);
|
||||||
|
|
||||||
// Otherwise, return false.
|
// Otherwise, return false.
|
||||||
|
|
|
@ -93,7 +93,7 @@ WebIDL::ExceptionOr<void> PropertyOwningCSSStyleDeclaration::set_property(Proper
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
// 5. Let component value list be the result of parsing value for property property.
|
// 5. Let component value list be the result of parsing value for property property.
|
||||||
auto component_value_list = parse_css_value(CSS::Parser::ParsingContext {}, value, property_id);
|
auto component_value_list = parse_css_value(CSS::Parser::ParsingContext { realm() }, value, property_id);
|
||||||
|
|
||||||
// 6. If component value list is null, then return.
|
// 6. If component value list is null, then return.
|
||||||
if (!component_value_list)
|
if (!component_value_list)
|
||||||
|
|
|
@ -99,7 +99,7 @@ DeprecatedString CSSStyleRule::selector_text() const
|
||||||
void CSSStyleRule::set_selector_text(StringView selector_text)
|
void CSSStyleRule::set_selector_text(StringView selector_text)
|
||||||
{
|
{
|
||||||
// 1. Run the parse a group of selectors algorithm on the given value.
|
// 1. Run the parse a group of selectors algorithm on the given value.
|
||||||
auto parsed_selectors = parse_selector({}, selector_text);
|
auto parsed_selectors = parse_selector(Parser::ParsingContext { realm() }, selector_text);
|
||||||
|
|
||||||
// 2. If the algorithm returns a non-null value replace the associated group of selectors with the returned value.
|
// 2. If the algorithm returns a non-null value replace the associated group of selectors with the returned value.
|
||||||
if (parsed_selectors.has_value())
|
if (parsed_selectors.has_value())
|
||||||
|
|
|
@ -54,7 +54,8 @@ WebIDL::ExceptionOr<unsigned> CSSStyleSheet::insert_rule(StringView rule, unsign
|
||||||
// FIXME: 2. If the disallow modification flag is set, throw a NotAllowedError DOMException.
|
// FIXME: 2. If the disallow modification flag is set, throw a NotAllowedError DOMException.
|
||||||
|
|
||||||
// 3. Let parsed rule be the return value of invoking parse a rule with rule.
|
// 3. Let parsed rule be the return value of invoking parse a rule with rule.
|
||||||
auto parsed_rule = parse_css_rule(CSS::Parser::ParsingContext {}, rule);
|
auto context = m_style_sheet_list ? CSS::Parser::ParsingContext { m_style_sheet_list->document() } : CSS::Parser::ParsingContext { realm() };
|
||||||
|
auto parsed_rule = parse_css_rule(context, rule);
|
||||||
|
|
||||||
// 4. If parsed rule is a syntax error, return parsed rule.
|
// 4. If parsed rule is a syntax error, return parsed rule.
|
||||||
if (!parsed_rule)
|
if (!parsed_rule)
|
||||||
|
|
|
@ -37,7 +37,7 @@ DeprecatedString CSSSupportsRule::condition_text() const
|
||||||
|
|
||||||
void CSSSupportsRule::set_condition_text(DeprecatedString text)
|
void CSSSupportsRule::set_condition_text(DeprecatedString text)
|
||||||
{
|
{
|
||||||
if (auto new_supports = parse_css_supports({}, text))
|
if (auto new_supports = parse_css_supports(Parser::ParsingContext { realm() }, text))
|
||||||
m_supports = new_supports.release_nonnull();
|
m_supports = new_supports.release_nonnull();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ void MediaList::set_media_text(DeprecatedString const& text)
|
||||||
m_media.clear();
|
m_media.clear();
|
||||||
if (text.is_empty())
|
if (text.is_empty())
|
||||||
return;
|
return;
|
||||||
m_media = parse_media_query_list({}, text);
|
m_media = parse_media_query_list(Parser::ParsingContext { realm() }, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MediaList::is_supported_property_index(u32 index) const
|
bool MediaList::is_supported_property_index(u32 index) const
|
||||||
|
@ -65,7 +65,7 @@ DeprecatedString MediaList::item(u32 index) const
|
||||||
void MediaList::append_medium(DeprecatedString medium)
|
void MediaList::append_medium(DeprecatedString medium)
|
||||||
{
|
{
|
||||||
// 1. Let m be the result of parsing the given value.
|
// 1. Let m be the result of parsing the given value.
|
||||||
auto m = parse_media_query({}, medium);
|
auto m = parse_media_query(Parser::ParsingContext { realm() }, medium);
|
||||||
|
|
||||||
// 2. If m is null, then return.
|
// 2. If m is null, then return.
|
||||||
if (!m)
|
if (!m)
|
||||||
|
@ -85,7 +85,7 @@ void MediaList::append_medium(DeprecatedString medium)
|
||||||
// https://www.w3.org/TR/cssom-1/#dom-medialist-deletemedium
|
// https://www.w3.org/TR/cssom-1/#dom-medialist-deletemedium
|
||||||
void MediaList::delete_medium(DeprecatedString medium)
|
void MediaList::delete_medium(DeprecatedString medium)
|
||||||
{
|
{
|
||||||
auto m = parse_media_query({}, medium);
|
auto m = parse_media_query(Parser::ParsingContext { realm() }, medium);
|
||||||
if (!m)
|
if (!m)
|
||||||
return;
|
return;
|
||||||
m_media.remove_all_matching([&](auto& existing) -> bool {
|
m_media.remove_all_matching([&](auto& existing) -> bool {
|
||||||
|
|
|
@ -40,11 +40,6 @@ static void log_parse_error(SourceLocation const& location = SourceLocation::cur
|
||||||
|
|
||||||
namespace Web::CSS::Parser {
|
namespace Web::CSS::Parser {
|
||||||
|
|
||||||
ParsingContext::ParsingContext()
|
|
||||||
: m_realm(*Bindings::main_thread_vm().current_realm())
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
ParsingContext::ParsingContext(JS::Realm& realm)
|
ParsingContext::ParsingContext(JS::Realm& realm)
|
||||||
: m_realm(realm)
|
: m_realm(realm)
|
||||||
{
|
{
|
||||||
|
@ -1414,7 +1409,7 @@ Optional<Supports::Feature> Parser::parse_supports_feature(TokenStream<Component
|
||||||
if (auto declaration = consume_a_declaration(block_tokens); declaration.has_value()) {
|
if (auto declaration = consume_a_declaration(block_tokens); declaration.has_value()) {
|
||||||
transaction.commit();
|
transaction.commit();
|
||||||
return Supports::Feature {
|
return Supports::Feature {
|
||||||
Supports::Declaration { declaration->to_string().release_value_but_fixme_should_propagate_errors() }
|
Supports::Declaration { declaration->to_string().release_value_but_fixme_should_propagate_errors(), JS::make_handle(m_context.realm()) }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1427,7 +1422,7 @@ Optional<Supports::Feature> Parser::parse_supports_feature(TokenStream<Component
|
||||||
builder.append(item.to_string().release_value_but_fixme_should_propagate_errors());
|
builder.append(item.to_string().release_value_but_fixme_should_propagate_errors());
|
||||||
transaction.commit();
|
transaction.commit();
|
||||||
return Supports::Feature {
|
return Supports::Feature {
|
||||||
Supports::Selector { builder.to_string().release_value_but_fixme_should_propagate_errors() }
|
Supports::Selector { builder.to_string().release_value_but_fixme_should_propagate_errors(), JS::make_handle(m_context.realm()) }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4075,15 +4070,15 @@ RefPtr<StyleValue> Parser::parse_background_value(Vector<ComponentValue> const&
|
||||||
};
|
};
|
||||||
|
|
||||||
auto complete_background_layer = [&]() {
|
auto complete_background_layer = [&]() {
|
||||||
background_images.append(background_image ? background_image.release_nonnull() : property_initial_value(PropertyID::BackgroundImage));
|
background_images.append(background_image ? background_image.release_nonnull() : property_initial_value(m_context.realm(), PropertyID::BackgroundImage));
|
||||||
background_positions.append(background_position ? background_position.release_nonnull() : property_initial_value(PropertyID::BackgroundPosition));
|
background_positions.append(background_position ? background_position.release_nonnull() : property_initial_value(m_context.realm(), PropertyID::BackgroundPosition));
|
||||||
background_sizes.append(background_size ? background_size.release_nonnull() : property_initial_value(PropertyID::BackgroundSize));
|
background_sizes.append(background_size ? background_size.release_nonnull() : property_initial_value(m_context.realm(), PropertyID::BackgroundSize));
|
||||||
background_repeats.append(background_repeat ? background_repeat.release_nonnull() : property_initial_value(PropertyID::BackgroundRepeat));
|
background_repeats.append(background_repeat ? background_repeat.release_nonnull() : property_initial_value(m_context.realm(), PropertyID::BackgroundRepeat));
|
||||||
background_attachments.append(background_attachment ? background_attachment.release_nonnull() : property_initial_value(PropertyID::BackgroundAttachment));
|
background_attachments.append(background_attachment ? background_attachment.release_nonnull() : property_initial_value(m_context.realm(), PropertyID::BackgroundAttachment));
|
||||||
|
|
||||||
if (!background_origin && !background_clip) {
|
if (!background_origin && !background_clip) {
|
||||||
background_origin = property_initial_value(PropertyID::BackgroundOrigin);
|
background_origin = property_initial_value(m_context.realm(), PropertyID::BackgroundOrigin);
|
||||||
background_clip = property_initial_value(PropertyID::BackgroundClip);
|
background_clip = property_initial_value(m_context.realm(), PropertyID::BackgroundClip);
|
||||||
} else if (!background_clip) {
|
} else if (!background_clip) {
|
||||||
background_clip = background_origin;
|
background_clip = background_origin;
|
||||||
}
|
}
|
||||||
|
@ -4195,7 +4190,7 @@ RefPtr<StyleValue> Parser::parse_background_value(Vector<ComponentValue> const&
|
||||||
complete_background_layer();
|
complete_background_layer();
|
||||||
|
|
||||||
if (!background_color)
|
if (!background_color)
|
||||||
background_color = property_initial_value(PropertyID::BackgroundColor);
|
background_color = property_initial_value(m_context.realm(), PropertyID::BackgroundColor);
|
||||||
return BackgroundStyleValue::create(
|
return BackgroundStyleValue::create(
|
||||||
background_color.release_nonnull(),
|
background_color.release_nonnull(),
|
||||||
StyleValueList::create(move(background_images), StyleValueList::Separator::Comma),
|
StyleValueList::create(move(background_images), StyleValueList::Separator::Comma),
|
||||||
|
@ -4208,21 +4203,21 @@ RefPtr<StyleValue> Parser::parse_background_value(Vector<ComponentValue> const&
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!background_color)
|
if (!background_color)
|
||||||
background_color = property_initial_value(PropertyID::BackgroundColor);
|
background_color = property_initial_value(m_context.realm(), PropertyID::BackgroundColor);
|
||||||
if (!background_image)
|
if (!background_image)
|
||||||
background_image = property_initial_value(PropertyID::BackgroundImage);
|
background_image = property_initial_value(m_context.realm(), PropertyID::BackgroundImage);
|
||||||
if (!background_position)
|
if (!background_position)
|
||||||
background_position = property_initial_value(PropertyID::BackgroundPosition);
|
background_position = property_initial_value(m_context.realm(), PropertyID::BackgroundPosition);
|
||||||
if (!background_size)
|
if (!background_size)
|
||||||
background_size = property_initial_value(PropertyID::BackgroundSize);
|
background_size = property_initial_value(m_context.realm(), PropertyID::BackgroundSize);
|
||||||
if (!background_repeat)
|
if (!background_repeat)
|
||||||
background_repeat = property_initial_value(PropertyID::BackgroundRepeat);
|
background_repeat = property_initial_value(m_context.realm(), PropertyID::BackgroundRepeat);
|
||||||
if (!background_attachment)
|
if (!background_attachment)
|
||||||
background_attachment = property_initial_value(PropertyID::BackgroundAttachment);
|
background_attachment = property_initial_value(m_context.realm(), PropertyID::BackgroundAttachment);
|
||||||
|
|
||||||
if (!background_origin && !background_clip) {
|
if (!background_origin && !background_clip) {
|
||||||
background_origin = property_initial_value(PropertyID::BackgroundOrigin);
|
background_origin = property_initial_value(m_context.realm(), PropertyID::BackgroundOrigin);
|
||||||
background_clip = property_initial_value(PropertyID::BackgroundClip);
|
background_clip = property_initial_value(m_context.realm(), PropertyID::BackgroundClip);
|
||||||
} else if (!background_clip) {
|
} else if (!background_clip) {
|
||||||
background_clip = background_origin;
|
background_clip = background_origin;
|
||||||
}
|
}
|
||||||
|
@ -4552,11 +4547,11 @@ RefPtr<StyleValue> Parser::parse_border_value(Vector<ComponentValue> const& comp
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!border_width)
|
if (!border_width)
|
||||||
border_width = property_initial_value(PropertyID::BorderWidth);
|
border_width = property_initial_value(m_context.realm(), PropertyID::BorderWidth);
|
||||||
if (!border_style)
|
if (!border_style)
|
||||||
border_style = property_initial_value(PropertyID::BorderStyle);
|
border_style = property_initial_value(m_context.realm(), PropertyID::BorderStyle);
|
||||||
if (!border_color)
|
if (!border_color)
|
||||||
border_color = property_initial_value(PropertyID::BorderColor);
|
border_color = property_initial_value(m_context.realm(), PropertyID::BorderColor);
|
||||||
|
|
||||||
return BorderStyleValue::create(border_width.release_nonnull(), border_style.release_nonnull(), border_color.release_nonnull());
|
return BorderStyleValue::create(border_width.release_nonnull(), border_style.release_nonnull(), border_color.release_nonnull());
|
||||||
}
|
}
|
||||||
|
@ -5080,11 +5075,11 @@ RefPtr<StyleValue> Parser::parse_flex_value(Vector<ComponentValue> const& compon
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!flex_grow)
|
if (!flex_grow)
|
||||||
flex_grow = property_initial_value(PropertyID::FlexGrow);
|
flex_grow = property_initial_value(m_context.realm(), PropertyID::FlexGrow);
|
||||||
if (!flex_shrink)
|
if (!flex_shrink)
|
||||||
flex_shrink = property_initial_value(PropertyID::FlexShrink);
|
flex_shrink = property_initial_value(m_context.realm(), PropertyID::FlexShrink);
|
||||||
if (!flex_basis)
|
if (!flex_basis)
|
||||||
flex_basis = property_initial_value(PropertyID::FlexBasis);
|
flex_basis = property_initial_value(m_context.realm(), PropertyID::FlexBasis);
|
||||||
|
|
||||||
return FlexStyleValue::create(flex_grow.release_nonnull(), flex_shrink.release_nonnull(), flex_basis.release_nonnull());
|
return FlexStyleValue::create(flex_grow.release_nonnull(), flex_shrink.release_nonnull(), flex_basis.release_nonnull());
|
||||||
}
|
}
|
||||||
|
@ -5116,9 +5111,9 @@ RefPtr<StyleValue> Parser::parse_flex_flow_value(Vector<ComponentValue> const& c
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!flex_direction)
|
if (!flex_direction)
|
||||||
flex_direction = property_initial_value(PropertyID::FlexDirection);
|
flex_direction = property_initial_value(m_context.realm(), PropertyID::FlexDirection);
|
||||||
if (!flex_wrap)
|
if (!flex_wrap)
|
||||||
flex_wrap = property_initial_value(PropertyID::FlexWrap);
|
flex_wrap = property_initial_value(m_context.realm(), PropertyID::FlexWrap);
|
||||||
|
|
||||||
return FlexFlowStyleValue::create(flex_direction.release_nonnull(), flex_wrap.release_nonnull());
|
return FlexFlowStyleValue::create(flex_direction.release_nonnull(), flex_wrap.release_nonnull());
|
||||||
}
|
}
|
||||||
|
@ -5229,13 +5224,13 @@ RefPtr<StyleValue> Parser::parse_font_value(Vector<ComponentValue> const& compon
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
if (!font_stretch)
|
if (!font_stretch)
|
||||||
font_stretch = property_initial_value(PropertyID::FontStretch);
|
font_stretch = property_initial_value(m_context.realm(), PropertyID::FontStretch);
|
||||||
if (!font_style)
|
if (!font_style)
|
||||||
font_style = property_initial_value(PropertyID::FontStyle);
|
font_style = property_initial_value(m_context.realm(), PropertyID::FontStyle);
|
||||||
if (!font_weight)
|
if (!font_weight)
|
||||||
font_weight = property_initial_value(PropertyID::FontWeight);
|
font_weight = property_initial_value(m_context.realm(), PropertyID::FontWeight);
|
||||||
if (!line_height)
|
if (!line_height)
|
||||||
line_height = property_initial_value(PropertyID::LineHeight);
|
line_height = property_initial_value(m_context.realm(), PropertyID::LineHeight);
|
||||||
|
|
||||||
return FontStyleValue::create(font_stretch.release_nonnull(), font_style.release_nonnull(), font_weight.release_nonnull(), font_size.release_nonnull(), line_height.release_nonnull(), font_families.release_nonnull());
|
return FontStyleValue::create(font_stretch.release_nonnull(), font_style.release_nonnull(), font_weight.release_nonnull(), font_size.release_nonnull(), line_height.release_nonnull(), font_families.release_nonnull());
|
||||||
}
|
}
|
||||||
|
@ -5559,11 +5554,11 @@ RefPtr<StyleValue> Parser::parse_list_style_value(Vector<ComponentValue> const&
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!list_position)
|
if (!list_position)
|
||||||
list_position = property_initial_value(PropertyID::ListStylePosition);
|
list_position = property_initial_value(m_context.realm(), PropertyID::ListStylePosition);
|
||||||
if (!list_image)
|
if (!list_image)
|
||||||
list_image = property_initial_value(PropertyID::ListStyleImage);
|
list_image = property_initial_value(m_context.realm(), PropertyID::ListStyleImage);
|
||||||
if (!list_type)
|
if (!list_type)
|
||||||
list_type = property_initial_value(PropertyID::ListStyleType);
|
list_type = property_initial_value(m_context.realm(), PropertyID::ListStyleType);
|
||||||
|
|
||||||
return ListStyleStyleValue::create(list_position.release_nonnull(), list_image.release_nonnull(), list_type.release_nonnull());
|
return ListStyleStyleValue::create(list_position.release_nonnull(), list_image.release_nonnull(), list_type.release_nonnull());
|
||||||
}
|
}
|
||||||
|
@ -5645,13 +5640,13 @@ RefPtr<StyleValue> Parser::parse_text_decoration_value(Vector<ComponentValue> co
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!decoration_line)
|
if (!decoration_line)
|
||||||
decoration_line = property_initial_value(PropertyID::TextDecorationLine);
|
decoration_line = property_initial_value(m_context.realm(), PropertyID::TextDecorationLine);
|
||||||
if (!decoration_thickness)
|
if (!decoration_thickness)
|
||||||
decoration_thickness = property_initial_value(PropertyID::TextDecorationThickness);
|
decoration_thickness = property_initial_value(m_context.realm(), PropertyID::TextDecorationThickness);
|
||||||
if (!decoration_style)
|
if (!decoration_style)
|
||||||
decoration_style = property_initial_value(PropertyID::TextDecorationStyle);
|
decoration_style = property_initial_value(m_context.realm(), PropertyID::TextDecorationStyle);
|
||||||
if (!decoration_color)
|
if (!decoration_color)
|
||||||
decoration_color = property_initial_value(PropertyID::TextDecorationColor);
|
decoration_color = property_initial_value(m_context.realm(), PropertyID::TextDecorationColor);
|
||||||
|
|
||||||
return TextDecorationStyleValue::create(decoration_line.release_nonnull(), decoration_thickness.release_nonnull(), decoration_style.release_nonnull(), decoration_color.release_nonnull());
|
return TextDecorationStyleValue::create(decoration_line.release_nonnull(), decoration_thickness.release_nonnull(), decoration_style.release_nonnull(), decoration_color.release_nonnull());
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,6 @@ namespace Web::CSS::Parser {
|
||||||
|
|
||||||
class ParsingContext {
|
class ParsingContext {
|
||||||
public:
|
public:
|
||||||
ParsingContext();
|
|
||||||
explicit ParsingContext(JS::Realm&);
|
explicit ParsingContext(JS::Realm&);
|
||||||
explicit ParsingContext(DOM::Document const&);
|
explicit ParsingContext(DOM::Document const&);
|
||||||
explicit ParsingContext(DOM::Document const&, AK::URL);
|
explicit ParsingContext(DOM::Document const&, AK::URL);
|
||||||
|
|
|
@ -111,22 +111,22 @@ private:
|
||||||
HashMap<float, NonnullRefPtr<Gfx::ScaledFont>> mutable m_cached_fonts;
|
HashMap<float, NonnullRefPtr<Gfx::ScaledFont>> mutable m_cached_fonts;
|
||||||
};
|
};
|
||||||
|
|
||||||
static CSSStyleSheet& default_stylesheet()
|
static CSSStyleSheet& default_stylesheet(DOM::Document const& document)
|
||||||
{
|
{
|
||||||
static JS::Handle<CSSStyleSheet> sheet;
|
static JS::Handle<CSSStyleSheet> sheet;
|
||||||
if (!sheet.cell()) {
|
if (!sheet.cell()) {
|
||||||
extern StringView default_stylesheet_source;
|
extern StringView default_stylesheet_source;
|
||||||
sheet = JS::make_handle(parse_css_stylesheet(CSS::Parser::ParsingContext(), default_stylesheet_source));
|
sheet = JS::make_handle(parse_css_stylesheet(CSS::Parser::ParsingContext(document), default_stylesheet_source));
|
||||||
}
|
}
|
||||||
return *sheet;
|
return *sheet;
|
||||||
}
|
}
|
||||||
|
|
||||||
static CSSStyleSheet& quirks_mode_stylesheet()
|
static CSSStyleSheet& quirks_mode_stylesheet(DOM::Document const& document)
|
||||||
{
|
{
|
||||||
static JS::Handle<CSSStyleSheet> sheet;
|
static JS::Handle<CSSStyleSheet> sheet;
|
||||||
if (!sheet.cell()) {
|
if (!sheet.cell()) {
|
||||||
extern StringView quirks_mode_stylesheet_source;
|
extern StringView quirks_mode_stylesheet_source;
|
||||||
sheet = JS::make_handle(parse_css_stylesheet(CSS::Parser::ParsingContext(), quirks_mode_stylesheet_source));
|
sheet = JS::make_handle(parse_css_stylesheet(CSS::Parser::ParsingContext(document), quirks_mode_stylesheet_source));
|
||||||
}
|
}
|
||||||
return *sheet;
|
return *sheet;
|
||||||
}
|
}
|
||||||
|
@ -135,9 +135,9 @@ template<typename Callback>
|
||||||
void StyleComputer::for_each_stylesheet(CascadeOrigin cascade_origin, Callback callback) const
|
void StyleComputer::for_each_stylesheet(CascadeOrigin cascade_origin, Callback callback) const
|
||||||
{
|
{
|
||||||
if (cascade_origin == CascadeOrigin::UserAgent) {
|
if (cascade_origin == CascadeOrigin::UserAgent) {
|
||||||
callback(default_stylesheet());
|
callback(default_stylesheet(document()));
|
||||||
if (document().in_quirks_mode())
|
if (document().in_quirks_mode())
|
||||||
callback(quirks_mode_stylesheet());
|
callback(quirks_mode_stylesheet(document()));
|
||||||
}
|
}
|
||||||
if (cascade_origin == CascadeOrigin::Author) {
|
if (cascade_origin == CascadeOrigin::Author) {
|
||||||
for (auto const& sheet : document().style_sheets().sheets()) {
|
for (auto const& sheet : document().style_sheets().sheets()) {
|
||||||
|
@ -907,12 +907,12 @@ static DOM::Element const* element_to_inherit_style_from(DOM::Element const* ele
|
||||||
return parent_element;
|
return parent_element;
|
||||||
}
|
}
|
||||||
|
|
||||||
static NonnullRefPtr<StyleValue const> get_inherit_value(CSS::PropertyID property_id, DOM::Element const* element, Optional<CSS::Selector::PseudoElement> pseudo_element)
|
static NonnullRefPtr<StyleValue const> get_inherit_value(JS::Realm& initial_value_context_realm, CSS::PropertyID property_id, DOM::Element const* element, Optional<CSS::Selector::PseudoElement> pseudo_element)
|
||||||
{
|
{
|
||||||
auto* parent_element = element_to_inherit_style_from(element, pseudo_element);
|
auto* parent_element = element_to_inherit_style_from(element, pseudo_element);
|
||||||
|
|
||||||
if (!parent_element || !parent_element->computed_css_values())
|
if (!parent_element || !parent_element->computed_css_values())
|
||||||
return property_initial_value(property_id);
|
return property_initial_value(initial_value_context_realm, property_id);
|
||||||
return parent_element->computed_css_values()->property(property_id);
|
return parent_element->computed_css_values()->property(property_id);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -923,19 +923,19 @@ void StyleComputer::compute_defaulted_property_value(StyleProperties& style, DOM
|
||||||
auto& value_slot = style.m_property_values[to_underlying(property_id)];
|
auto& value_slot = style.m_property_values[to_underlying(property_id)];
|
||||||
if (!value_slot) {
|
if (!value_slot) {
|
||||||
if (is_inherited_property(property_id))
|
if (is_inherited_property(property_id))
|
||||||
style.m_property_values[to_underlying(property_id)] = get_inherit_value(property_id, element, pseudo_element);
|
style.m_property_values[to_underlying(property_id)] = get_inherit_value(document().realm(), property_id, element, pseudo_element);
|
||||||
else
|
else
|
||||||
style.m_property_values[to_underlying(property_id)] = property_initial_value(property_id);
|
style.m_property_values[to_underlying(property_id)] = property_initial_value(document().realm(), property_id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value_slot->is_initial()) {
|
if (value_slot->is_initial()) {
|
||||||
value_slot = property_initial_value(property_id);
|
value_slot = property_initial_value(document().realm(), property_id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value_slot->is_inherit()) {
|
if (value_slot->is_inherit()) {
|
||||||
value_slot = get_inherit_value(property_id, element, pseudo_element);
|
value_slot = get_inherit_value(document().realm(), property_id, element, pseudo_element);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -944,10 +944,10 @@ void StyleComputer::compute_defaulted_property_value(StyleProperties& style, DOM
|
||||||
if (value_slot->is_unset()) {
|
if (value_slot->is_unset()) {
|
||||||
if (is_inherited_property(property_id)) {
|
if (is_inherited_property(property_id)) {
|
||||||
// then if it is an inherited property, this is treated as inherit,
|
// then if it is an inherited property, this is treated as inherit,
|
||||||
value_slot = get_inherit_value(property_id, element, pseudo_element);
|
value_slot = get_inherit_value(document().realm(), property_id, element, pseudo_element);
|
||||||
} else {
|
} else {
|
||||||
// and if it is not, this is treated as initial.
|
// and if it is not, this is treated as initial.
|
||||||
value_slot = property_initial_value(property_id);
|
value_slot = property_initial_value(document().realm(), property_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <LibJS/Runtime/Realm.h>
|
||||||
#include <LibWeb/CSS/Parser/Parser.h>
|
#include <LibWeb/CSS/Parser/Parser.h>
|
||||||
#include <LibWeb/CSS/Supports.h>
|
#include <LibWeb/CSS/Supports.h>
|
||||||
|
|
||||||
|
@ -52,13 +53,13 @@ bool Supports::InParens::evaluate() const
|
||||||
|
|
||||||
bool Supports::Declaration::evaluate() const
|
bool Supports::Declaration::evaluate() const
|
||||||
{
|
{
|
||||||
auto style_property = parse_css_supports_condition({}, declaration);
|
auto style_property = parse_css_supports_condition(Parser::ParsingContext { *realm }, declaration);
|
||||||
return style_property.has_value();
|
return style_property.has_value();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Supports::Selector::evaluate() const
|
bool Supports::Selector::evaluate() const
|
||||||
{
|
{
|
||||||
auto style_property = parse_selector({}, selector);
|
auto style_property = parse_selector(Parser::ParsingContext { *realm }, selector);
|
||||||
return style_property.has_value();
|
return style_property.has_value();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,12 +23,14 @@ class Supports final : public RefCounted<Supports> {
|
||||||
public:
|
public:
|
||||||
struct Declaration {
|
struct Declaration {
|
||||||
String declaration;
|
String declaration;
|
||||||
|
JS::Handle<JS::Realm> realm;
|
||||||
bool evaluate() const;
|
bool evaluate() const;
|
||||||
ErrorOr<String> to_string() const;
|
ErrorOr<String> to_string() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Selector {
|
struct Selector {
|
||||||
String selector;
|
String selector;
|
||||||
|
JS::Handle<JS::Realm> realm;
|
||||||
bool evaluate() const;
|
bool evaluate() const;
|
||||||
ErrorOr<String> to_string() const;
|
ErrorOr<String> to_string() const;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue