diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp index d0aa9a33d5..5141b039ee 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021, Andreas Kling + * Copyright (c) 2020-2023, Andreas Kling * Copyright (c) 2021-2023, Linus Groh * Copyright (c) 2021, Luke Wilde * Copyright (c) 2022, Ali Mohammad Pur @@ -915,7 +915,7 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter // 3. Let types be the flattened member types of the union type. auto types = union_type.flattened_member_types(); - RefPtr dictionary_type; + RefPtr dictionary_type; for (auto& dictionary : interface.dictionaries) { for (auto& type : types) { if (type.name() == dictionary.key) { @@ -1077,7 +1077,7 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter // 10. If Type(V) is Object, then: // 1. If types includes a sequence type, then: - RefPtr sequence_type; + RefPtr sequence_type; for (auto& type : types) { if (type.name() == "sequence") { sequence_type = verify_cast(type); @@ -1117,7 +1117,7 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter } // 4. If types includes a record type, then return the result of converting V to that record type. - RefPtr record_type; + RefPtr record_type; for (auto& type : types) { if (type.name() == "record") { record_type = verify_cast(type); @@ -1165,7 +1165,7 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter )~~~"); } - RefPtr numeric_type; + RefPtr numeric_type; for (auto& type : types) { if (type.is_numeric()) { numeric_type = type; @@ -1794,7 +1794,7 @@ static EffectiveOverloadSet compute_the_effective_overload_set(auto const& overl int argument_count = (int)arguments.size(); // 3. Let types be a type list. - NonnullRefPtrVector types; + NonnullRefPtrVector types; // 4. Let optionalityValues be an optionality list. Vector optionality_values; @@ -1911,7 +1911,7 @@ static DeprecatedString generate_constructor_for_idl_type(Type const& type) case Type::Kind::Parameterized: { auto const& parameterized_type = type.as_parameterized(); StringBuilder builder; - builder.appendff("make_ref_counted(\"{}\", {}, NonnullRefPtrVector {{", type.name(), type.is_nullable()); + builder.appendff("make_ref_counted(\"{}\", {}, NonnullRefPtrVector {{", type.name(), type.is_nullable()); append_type_list(builder, parameterized_type.parameters()); builder.append("})"sv); return builder.to_deprecated_string(); @@ -1919,7 +1919,7 @@ static DeprecatedString generate_constructor_for_idl_type(Type const& type) case Type::Kind::Union: { auto const& union_type = type.as_union(); StringBuilder builder; - builder.appendff("make_ref_counted(\"{}\", {}, NonnullRefPtrVector {{", type.name(), type.is_nullable()); + builder.appendff("make_ref_counted(\"{}\", {}, NonnullRefPtrVector {{", type.name(), type.is_nullable()); append_type_list(builder, union_type.member_types()); builder.append("})"sv); return builder.to_deprecated_string(); @@ -1978,7 +1978,7 @@ JS_DEFINE_NATIVE_FUNCTION(@class_name@::@function.name:snakecase@) continue; StringBuilder types_builder; - types_builder.append("NonnullRefPtrVector { "sv); + types_builder.append("NonnullRefPtrVector { "sv); StringBuilder optionality_builder; optionality_builder.append("Vector { "sv); diff --git a/Userland/Libraries/LibIDL/IDLParser.cpp b/Userland/Libraries/LibIDL/IDLParser.cpp index e3fe59ec57..7f12d0b313 100644 --- a/Userland/Libraries/LibIDL/IDLParser.cpp +++ b/Userland/Libraries/LibIDL/IDLParser.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021, Andreas Kling + * Copyright (c) 2020-2023, Andreas Kling * Copyright (c) 2021-2022, Linus Groh * Copyright (c) 2021, Luke Wilde * Copyright (c) 2022, Ali Mohammad Pur @@ -163,10 +163,10 @@ Optional Parser::resolve_import(auto path) return result; } -NonnullRefPtr Parser::parse_type() +NonnullRefPtr Parser::parse_type() { if (lexer.consume_specific('(')) { - NonnullRefPtrVector union_member_types; + NonnullRefPtrVector union_member_types; union_member_types.append(parse_type()); consume_whitespace(); assert_string("or"sv); @@ -203,7 +203,7 @@ NonnullRefPtr Parser::parse_type() name = "long long"sv; } - NonnullRefPtrVector parameters; + NonnullRefPtrVector parameters; bool is_parameterized_type = false; if (lexer.consume_specific('<')) { is_parameterized_type = true; @@ -820,11 +820,11 @@ void Parser::parse_non_interface_entities(bool allow_interface, Interface& inter static void resolve_union_typedefs(Interface& interface, UnionType& union_); -static void resolve_typedef(Interface& interface, NonnullRefPtr& type, HashMap* extended_attributes = {}) +static void resolve_typedef(Interface& interface, NonnullRefPtr& type, HashMap* extended_attributes = {}) { if (is(*type)) { - auto& parameterized_type = type->as_parameterized(); - auto& parameters = static_cast>&>(parameterized_type.parameters()); + auto& parameterized_type = const_cast(*type).as_parameterized(); + auto& parameters = static_cast>&>(parameterized_type.parameters()); for (auto& parameter : parameters) resolve_typedef(interface, parameter); return; @@ -832,7 +832,7 @@ static void resolve_typedef(Interface& interface, NonnullRefPtr& type, Has // Resolve anonymous union types until we get named types that can be resolved in the next step. if (is(*type) && type->name().is_empty()) { - resolve_union_typedefs(interface, type->as_union()); + resolve_union_typedefs(interface, const_cast(*type).as_union()); return; } @@ -841,7 +841,7 @@ static void resolve_typedef(Interface& interface, NonnullRefPtr& type, Has return; bool nullable = type->is_nullable(); type = it->value.type; - type->set_nullable(nullable); + const_cast(*type).set_nullable(nullable); if (extended_attributes) { for (auto& attribute : it->value.extended_attributes) extended_attributes->set(attribute.key, attribute.value); @@ -859,12 +859,12 @@ static void resolve_typedef(Interface& interface, NonnullRefPtr& type, Has // UnionType(UnionType(A, B), UnionType(C, D)) // Note that flattening unions is handled separately as per the spec. if (is(*type)) - resolve_union_typedefs(interface, type->as_union()); + resolve_union_typedefs(interface, const_cast(*type).as_union()); } static void resolve_union_typedefs(Interface& interface, UnionType& union_) { - auto& member_types = static_cast>&>(union_.member_types()); + auto& member_types = static_cast>&>(union_.member_types()); for (auto& member_type : member_types) resolve_typedef(interface, member_type); } diff --git a/Userland/Libraries/LibIDL/IDLParser.h b/Userland/Libraries/LibIDL/IDLParser.h index e1239c54f7..69b3b2ec04 100644 --- a/Userland/Libraries/LibIDL/IDLParser.h +++ b/Userland/Libraries/LibIDL/IDLParser.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021, Andreas Kling + * Copyright (c) 2020-2023, Andreas Kling * Copyright (c) 2021, Linus Groh * Copyright (c) 2021, Luke Wilde * Copyright (c) 2022, Ali Mohammad Pur @@ -54,7 +54,7 @@ private: void parse_iterable(Interface&); Function parse_function(HashMap& extended_attributes, Interface&, IsSpecialOperation is_special_operation = IsSpecialOperation::No); Vector parse_parameters(); - NonnullRefPtr parse_type(); + NonnullRefPtr parse_type(); void parse_constant(Interface&); DeprecatedString import_base_path; diff --git a/Userland/Libraries/LibIDL/Types.h b/Userland/Libraries/LibIDL/Types.h index 9f52afa39f..7f1c2dd158 100644 --- a/Userland/Libraries/LibIDL/Types.h +++ b/Userland/Libraries/LibIDL/Types.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021, Andreas Kling + * Copyright (c) 2020-2023, Andreas Kling * Copyright (c) 2021, Linus Groh * Copyright (c) 2021, Luke Wilde * Copyright (c) 2022, Ali Mohammad Pur @@ -143,7 +143,7 @@ private: }; struct Parameter { - NonnullRefPtr type; + NonnullRefPtr type; DeprecatedString name; bool optional { false }; Optional optional_default_value; @@ -152,7 +152,7 @@ struct Parameter { }; struct Function { - NonnullRefPtr return_type; + NonnullRefPtr return_type; DeprecatedString name; Vector parameters; HashMap extended_attributes; @@ -170,7 +170,7 @@ struct Constructor { }; struct Constant { - NonnullRefPtr type; + NonnullRefPtr type; DeprecatedString name; DeprecatedString value; }; @@ -178,7 +178,7 @@ struct Constant { struct Attribute { bool inherit { false }; bool readonly { false }; - NonnullRefPtr type; + NonnullRefPtr type; DeprecatedString name; HashMap extended_attributes; @@ -189,7 +189,7 @@ struct Attribute { struct DictionaryMember { bool required { false }; - NonnullRefPtr type; + NonnullRefPtr type; DeprecatedString name; HashMap extended_attributes; Optional default_value; @@ -202,7 +202,7 @@ struct Dictionary { struct Typedef { HashMap extended_attributes; - NonnullRefPtr type; + NonnullRefPtr type; }; struct Enumeration { @@ -213,7 +213,7 @@ struct Enumeration { }; struct CallbackFunction { - NonnullRefPtr return_type; + NonnullRefPtr return_type; Vector parameters; bool is_legacy_treat_non_object_as_null { false }; }; @@ -222,7 +222,7 @@ class Interface; class ParameterizedType : public Type { public: - ParameterizedType(DeprecatedString name, bool nullable, NonnullRefPtrVector parameters) + ParameterizedType(DeprecatedString name, bool nullable, NonnullRefPtrVector parameters) : Type(Kind::Parameterized, move(name), nullable) , m_parameters(move(parameters)) { @@ -232,11 +232,11 @@ public: void generate_sequence_from_iterable(SourceGenerator& generator, DeprecatedString const& cpp_name, DeprecatedString const& iterable_cpp_name, DeprecatedString const& iterator_method_cpp_name, IDL::Interface const&, size_t recursion_depth) const; - NonnullRefPtrVector const& parameters() const { return m_parameters; } - NonnullRefPtrVector& parameters() { return m_parameters; } + NonnullRefPtrVector const& parameters() const { return m_parameters; } + NonnullRefPtrVector& parameters() { return m_parameters; } private: - NonnullRefPtrVector m_parameters; + NonnullRefPtrVector m_parameters; }; static inline size_t get_shortest_function_length(Vector const& overload_set) @@ -270,8 +270,8 @@ public: Optional stringifier_attribute; bool has_unscopable_member { false }; - Optional> value_iterator_type; - Optional, NonnullRefPtr>> pair_iterator_types; + Optional> value_iterator_type; + Optional, NonnullRefPtr>> pair_iterator_types; Optional named_property_getter; Optional named_property_setter; @@ -318,7 +318,7 @@ public: class UnionType : public Type { public: - UnionType(DeprecatedString name, bool nullable, NonnullRefPtrVector member_types) + UnionType(DeprecatedString name, bool nullable, NonnullRefPtrVector member_types) : Type(Kind::Union, move(name), nullable) , m_member_types(move(member_types)) { @@ -326,16 +326,16 @@ public: virtual ~UnionType() override = default; - NonnullRefPtrVector const& member_types() const { return m_member_types; } - NonnullRefPtrVector& member_types() { return m_member_types; } + NonnullRefPtrVector const& member_types() const { return m_member_types; } + NonnullRefPtrVector& member_types() { return m_member_types; } // https://webidl.spec.whatwg.org/#dfn-flattened-union-member-types - NonnullRefPtrVector flattened_member_types() const + NonnullRefPtrVector flattened_member_types() const { // 1. Let T be the union type. // 2. Initialize S to ∅. - NonnullRefPtrVector types; + NonnullRefPtrVector types; // 3. For each member type U of T: for (auto& type : m_member_types) { @@ -390,7 +390,7 @@ public: } private: - NonnullRefPtrVector m_member_types; + NonnullRefPtrVector m_member_types; }; // https://webidl.spec.whatwg.org/#dfn-optionality-value @@ -405,7 +405,7 @@ class EffectiveOverloadSet { public: struct Item { int callable_id; - NonnullRefPtrVector types; + NonnullRefPtrVector types; Vector optionality_values; }; diff --git a/Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.cpp b/Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.cpp index 2e0fac1430..53c581ef63 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.cpp +++ b/Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2022, Andreas Kling + * Copyright (c) 2018-2023, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ @@ -172,7 +172,7 @@ void ElementInlineCSSStyleDeclaration::update_style_attribute() } // https://drafts.csswg.org/cssom/#set-a-css-declaration -bool PropertyOwningCSSStyleDeclaration::set_a_css_declaration(PropertyID property_id, NonnullRefPtr value, Important important) +bool PropertyOwningCSSStyleDeclaration::set_a_css_declaration(PropertyID property_id, NonnullRefPtr value, Important important) { // FIXME: Handle logical property groups. diff --git a/Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.h b/Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.h index edafb34220..a04eebd38a 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.h +++ b/Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2022, Andreas Kling + * Copyright (c) 2018-2023, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ @@ -21,7 +21,7 @@ enum class Important { struct StyleProperty { Important important { Important::No }; CSS::PropertyID property_id; - NonnullRefPtr value; + NonnullRefPtr value; DeprecatedString custom_name {}; }; @@ -92,7 +92,7 @@ protected: void set_the_declarations(Vector properties, HashMap custom_properties); private: - bool set_a_css_declaration(PropertyID, NonnullRefPtr, Important); + bool set_a_css_declaration(PropertyID, NonnullRefPtr, Important); Vector m_properties; HashMap m_custom_properties; diff --git a/Userland/Libraries/LibWeb/CSS/ComputedValues.h b/Userland/Libraries/LibWeb/CSS/ComputedValues.h index 930fe8232f..9760a3f4d0 100644 --- a/Userland/Libraries/LibWeb/CSS/ComputedValues.h +++ b/Userland/Libraries/LibWeb/CSS/ComputedValues.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2022, Andreas Kling + * Copyright (c) 2020-2023, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ @@ -77,7 +77,7 @@ public: }; struct BackgroundLayerData { - RefPtr background_image { nullptr }; + RefPtr background_image { nullptr }; CSS::BackgroundAttachment attachment { CSS::BackgroundAttachment::Scroll }; CSS::BackgroundBox origin { CSS::BackgroundBox::PaddingBox }; CSS::BackgroundBox clip { CSS::BackgroundBox::BorderBox }; diff --git a/Userland/Libraries/LibWeb/CSS/MediaList.cpp b/Userland/Libraries/LibWeb/CSS/MediaList.cpp index 3b850a64d1..f9523315f9 100644 --- a/Userland/Libraries/LibWeb/CSS/MediaList.cpp +++ b/Userland/Libraries/LibWeb/CSS/MediaList.cpp @@ -1,6 +1,6 @@ /* * Copyright (c) 2021, Sam Atkins - * Copyright (c) 2022, Andreas Kling + * Copyright (c) 2022-2023, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ @@ -64,11 +64,21 @@ DeprecatedString MediaList::item(u32 index) const // https://www.w3.org/TR/cssom-1/#dom-medialist-appendmedium void MediaList::append_medium(DeprecatedString medium) { + // 1. Let m be the result of parsing the given value. auto m = parse_media_query({}, medium); + + // 2. If m is null, then return. if (!m) return; - if (m_media.contains_slow(*m)) - return; + + // 3. If comparing m with any of the media queries in the collection of media queries returns true, then return. + auto serialized = m->to_string().release_value_but_fixme_should_propagate_errors(); + for (auto& existing_medium : m_media) { + if (existing_medium.to_string().release_value_but_fixme_should_propagate_errors() == serialized) + return; + } + + // 4. Append m to the collection of media queries. m_media.append(m.release_nonnull()); } diff --git a/Userland/Libraries/LibWeb/CSS/Parser/ComponentValue.h b/Userland/Libraries/LibWeb/CSS/Parser/ComponentValue.h index a7f9a75a57..b10dbeb206 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/ComponentValue.h +++ b/Userland/Libraries/LibWeb/CSS/Parser/ComponentValue.h @@ -1,6 +1,7 @@ /* * Copyright (c) 2020-2021, the SerenityOS developers. * Copyright (c) 2021-2023, Sam Atkins + * Copyright (c) 2023, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ @@ -23,10 +24,10 @@ public: ~ComponentValue(); bool is_block() const { return m_value.has>(); } - Block const& block() const { return m_value.get>(); } + Block& block() const { return m_value.get>(); } bool is_function() const { return m_value.has>(); } - Function const& function() const { return m_value.get>(); } + Function& function() const { return m_value.get>(); } bool is_token() const { return m_value.has(); } bool is(Token::Type type) const { return is_token() && token().is(type); } diff --git a/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp b/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp index 190916e5db..16f1459aa3 100644 --- a/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp +++ b/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022, Andreas Kling + * Copyright (c) 2021-2023, Andreas Kling * Copyright (c) 2021, Tobias Christiansen * Copyright (c) 2022, Sam Atkins * @@ -122,14 +122,14 @@ static RefPtr style_value_for_display(CSS::Display display) TODO(); } -static NonnullRefPtr value_or_default(Optional property, NonnullRefPtr default_style) +static NonnullRefPtr value_or_default(Optional property, NonnullRefPtr default_style) { if (property.has_value()) return property.value().value; return default_style; } -static NonnullRefPtr style_value_for_length_percentage(LengthPercentage const& length_percentage) +static NonnullRefPtr style_value_for_length_percentage(LengthPercentage const& length_percentage) { if (length_percentage.is_percentage()) return PercentageStyleValue::create(length_percentage.percentage()); @@ -138,7 +138,7 @@ static NonnullRefPtr style_value_for_length_percentage(LengthPercent return length_percentage.calculated(); } -static NonnullRefPtr style_value_for_size(CSS::Size const& size) +static NonnullRefPtr style_value_for_size(CSS::Size const& size) { if (size.is_none()) return IdentifierStyleValue::create(ValueID::None); @@ -156,7 +156,7 @@ static NonnullRefPtr style_value_for_size(CSS::Size const& size) TODO(); } -RefPtr ResolvedCSSStyleDeclaration::style_value_for_property(Layout::NodeWithStyle const& layout_node, PropertyID property_id) const +RefPtr ResolvedCSSStyleDeclaration::style_value_for_property(Layout::NodeWithStyle const& layout_node, PropertyID property_id) const { switch (property_id) { case CSS::PropertyID::Background: { @@ -222,7 +222,7 @@ RefPtr ResolvedCSSStyleDeclaration::style_value_for_property(Layout: auto maybe_top_right_radius = property(CSS::PropertyID::BorderTopRightRadius); auto maybe_bottom_left_radius = property(CSS::PropertyID::BorderBottomLeftRadius); auto maybe_bottom_right_radius = property(CSS::PropertyID::BorderBottomRightRadius); - RefPtr top_left_radius, top_right_radius, bottom_left_radius, bottom_right_radius; + RefPtr top_left_radius, top_right_radius, bottom_left_radius, bottom_right_radius; if (maybe_top_left_radius.has_value()) { VERIFY(maybe_top_left_radius.value().value->is_border_radius()); top_left_radius = maybe_top_left_radius.value().value->as_border_radius(); @@ -337,7 +337,7 @@ RefPtr ResolvedCSSStyleDeclaration::style_value_for_property(Layout: auto maybe_grid_column_start = property(CSS::PropertyID::GridColumnStart); auto maybe_grid_row_end = property(CSS::PropertyID::GridRowEnd); auto maybe_grid_column_end = property(CSS::PropertyID::GridColumnEnd); - RefPtr grid_row_start, grid_column_start, grid_row_end, grid_column_end; + RefPtr grid_row_start, grid_column_start, grid_row_end, grid_column_end; if (maybe_grid_row_start.has_value()) { VERIFY(maybe_grid_row_start.value().value->is_grid_track_placement()); grid_row_start = maybe_grid_row_start.value().value->as_grid_track_placement(); @@ -363,7 +363,7 @@ RefPtr ResolvedCSSStyleDeclaration::style_value_for_property(Layout: case CSS::PropertyID::GridColumn: { auto maybe_grid_column_end = property(CSS::PropertyID::GridColumnEnd); auto maybe_grid_column_start = property(CSS::PropertyID::GridColumnStart); - RefPtr grid_column_start, grid_column_end; + RefPtr grid_column_start, grid_column_end; if (maybe_grid_column_end.has_value()) { VERIFY(maybe_grid_column_end.value().value->is_grid_track_placement()); grid_column_end = maybe_grid_column_end.value().value->as_grid_track_placement(); @@ -381,7 +381,7 @@ RefPtr ResolvedCSSStyleDeclaration::style_value_for_property(Layout: case CSS::PropertyID::GridRow: { auto maybe_grid_row_end = property(CSS::PropertyID::GridRowEnd); auto maybe_grid_row_start = property(CSS::PropertyID::GridRowStart); - RefPtr grid_row_start, grid_row_end; + RefPtr grid_row_start, grid_row_end; if (maybe_grid_row_end.has_value()) { VERIFY(maybe_grid_row_end.value().value->is_grid_track_placement()); grid_row_end = maybe_grid_row_end.value().value->as_grid_track_placement(); diff --git a/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.h b/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.h index b659be5dda..3fb7686a17 100644 --- a/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.h +++ b/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Andreas Kling + * Copyright (c) 2021-2023, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ @@ -32,7 +32,7 @@ private: virtual void visit_edges(Cell::Visitor&) override; - RefPtr style_value_for_property(Layout::NodeWithStyle const&, PropertyID) const; + RefPtr style_value_for_property(Layout::NodeWithStyle const&, PropertyID) const; JS::NonnullGCPtr m_element; }; diff --git a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp index a1a29bee7f..f76ef83c44 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2022, Andreas Kling + * Copyright (c) 2018-2023, Andreas Kling * Copyright (c) 2021, the SerenityOS developers. * Copyright (c) 2021-2023, Sam Atkins * @@ -587,7 +587,7 @@ static void set_property_expanding_shorthands(StyleProperties& style, CSS::Prope style.set_property(property_id, value); } -static RefPtr get_custom_property(DOM::Element const& element, FlyString const& custom_property_name) +static RefPtr get_custom_property(DOM::Element const& element, FlyString const& custom_property_name) { for (auto const* current_element = &element; current_element; current_element = current_element->parent_element()) { if (auto it = current_element->custom_properties().find(custom_property_name.to_string().to_deprecated_string()); it != current_element->custom_properties().end()) @@ -907,7 +907,7 @@ static DOM::Element const* element_to_inherit_style_from(DOM::Element const* ele return parent_element; } -static NonnullRefPtr get_inherit_value(CSS::PropertyID property_id, DOM::Element const* element, Optional pseudo_element) +static NonnullRefPtr get_inherit_value(CSS::PropertyID property_id, DOM::Element const* element, Optional pseudo_element) { auto* parent_element = element_to_inherit_style_from(element, pseudo_element); @@ -1083,7 +1083,7 @@ void StyleComputer::compute_font(StyleProperties& style, DOM::Element const* ele else weight = Gfx::FontWeight::Black; } else if (font_weight->is_calculated()) { - auto maybe_weight = font_weight->as_calculated().resolve_integer(); + auto maybe_weight = const_cast(font_weight->as_calculated()).resolve_integer(); if (maybe_weight.has_value()) weight = maybe_weight.value(); } @@ -1152,7 +1152,7 @@ void StyleComputer::compute_font(StyleProperties& style, DOM::Element const* ele maybe_length = font_size->to_length(); } else if (font_size->is_calculated()) { - maybe_length = Length::make_calculated(font_size->as_calculated()); + maybe_length = Length::make_calculated(const_cast(font_size->as_calculated())); } if (maybe_length.has_value()) { // FIXME: Support font-size: calc(...) @@ -1187,7 +1187,7 @@ void StyleComputer::compute_font(StyleProperties& style, DOM::Element const* ele FontSelector font_selector; bool monospace = false; - auto find_font = [&](String const& family) -> RefPtr { + auto find_font = [&](String const& family) -> RefPtr { float font_size_in_pt = font_size_in_px * 0.75f; font_selector = { family, font_size_in_pt, weight, width, slope }; @@ -1206,7 +1206,7 @@ void StyleComputer::compute_font(StyleProperties& style, DOM::Element const* ele return {}; }; - auto find_generic_font = [&](ValueID font_id) -> RefPtr { + auto find_generic_font = [&](ValueID font_id) -> RefPtr { Platform::GenericFont generic_font {}; switch (font_id) { case ValueID::Monospace: @@ -1241,7 +1241,7 @@ void StyleComputer::compute_font(StyleProperties& style, DOM::Element const* ele return find_font(String::from_utf8(Platform::FontPlugin::the().generic_font_name(generic_font)).release_value_but_fixme_should_propagate_errors()); }; - RefPtr found_font; + RefPtr found_font; auto family_value = style.property(PropertyID::FontFamily); if (family_value->is_value_list()) { diff --git a/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp b/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp index a8785b6e1c..0075dccc9f 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2022, Andreas Kling + * Copyright (c) 2018-2023, Andreas Kling * Copyright (c) 2021-2022, Sam Atkins * * SPDX-License-Identifier: BSD-2-Clause @@ -31,12 +31,12 @@ NonnullRefPtr StyleProperties::clone() const return adopt_ref(*new StyleProperties(*this)); } -void StyleProperties::set_property(CSS::PropertyID id, NonnullRefPtr value) +void StyleProperties::set_property(CSS::PropertyID id, NonnullRefPtr value) { m_property_values[to_underlying(id)] = move(value); } -NonnullRefPtr StyleProperties::property(CSS::PropertyID property_id) const +NonnullRefPtr StyleProperties::property(CSS::PropertyID property_id) const { auto value = m_property_values[to_underlying(property_id)]; // By the time we call this method, all properties have values assigned. @@ -44,7 +44,7 @@ NonnullRefPtr StyleProperties::property(CSS::PropertyID property_id) return value.release_nonnull(); } -RefPtr StyleProperties::maybe_null_property(CSS::PropertyID property_id) const +RefPtr StyleProperties::maybe_null_property(CSS::PropertyID property_id) const { return m_property_values[to_underlying(property_id)]; } @@ -68,7 +68,7 @@ CSS::Size StyleProperties::size_value(CSS::PropertyID id) const } if (value->is_calculated()) - return CSS::Size::make_length(CSS::Length::make_calculated(value->as_calculated())); + return CSS::Size::make_length(CSS::Length::make_calculated(const_cast(value->as_calculated()))); if (value->is_percentage()) return CSS::Size::make_percentage(value->as_percentage().percentage()); @@ -95,7 +95,7 @@ Optional StyleProperties::length_percentage(CSS::PropertyID id auto value = property(id); if (value->is_calculated()) - return LengthPercentage { value->as_calculated() }; + return LengthPercentage { const_cast(value->as_calculated()) }; if (value->is_percentage()) return value->as_percentage().percentage(); @@ -124,7 +124,7 @@ Color StyleProperties::color_or_fallback(CSS::PropertyID id, Layout::NodeWithSty return value->to_color(node); } -NonnullRefPtr StyleProperties::font_fallback(bool monospace, bool bold) +NonnullRefPtr StyleProperties::font_fallback(bool monospace, bool bold) { if (monospace && bold) return Platform::FontPlugin::the().default_fixed_width_font().bold_variant(); @@ -161,7 +161,7 @@ CSSPixels StyleProperties::line_height(Layout::Node const& layout_node) const } if (line_height->is_calculated()) - return CSS::Length::make_calculated(line_height->as_calculated()).to_px(layout_node); + return CSS::Length::make_calculated(const_cast(line_height->as_calculated())).to_px(layout_node); return layout_node.font().pixel_metrics().line_spacing(); } @@ -193,7 +193,7 @@ float StyleProperties::opacity() const else dbgln("Unable to resolve calc() as opacity (percentage): {}", value->to_string()); } else { - auto maybe_number = value->as_calculated().resolve_number(); + auto maybe_number = const_cast(value->as_calculated()).resolve_number(); if (maybe_number.has_value()) unclamped_opacity = maybe_number.value(); else diff --git a/Userland/Libraries/LibWeb/CSS/StyleProperties.h b/Userland/Libraries/LibWeb/CSS/StyleProperties.h index 572528a6dc..7c780fe218 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleProperties.h +++ b/Userland/Libraries/LibWeb/CSS/StyleProperties.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2020, Andreas Kling + * Copyright (c) 2018-2023, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ @@ -38,9 +38,9 @@ public: auto& properties() { return m_property_values; } auto const& properties() const { return m_property_values; } - void set_property(CSS::PropertyID, NonnullRefPtr value); - NonnullRefPtr property(CSS::PropertyID) const; - RefPtr maybe_null_property(CSS::PropertyID) const; + void set_property(CSS::PropertyID, NonnullRefPtr value); + NonnullRefPtr property(CSS::PropertyID) const; + RefPtr maybe_null_property(CSS::PropertyID) const; CSS::Size size_value(CSS::PropertyID) const; LengthPercentage length_percentage_or_fallback(CSS::PropertyID, LengthPercentage const& fallback) const; @@ -103,7 +103,7 @@ public: return *m_font; } - void set_computed_font(NonnullRefPtr font) + void set_computed_font(NonnullRefPtr font) { m_font = move(font); } @@ -115,16 +115,16 @@ public: Optional position() const; Optional z_index() const; - static NonnullRefPtr font_fallback(bool monospace, bool bold); + static NonnullRefPtr font_fallback(bool monospace, bool bold); private: friend class StyleComputer; - Array, to_underlying(CSS::last_property_id) + 1> m_property_values; + Array, to_underlying(CSS::last_property_id) + 1> m_property_values; Optional overflow(CSS::PropertyID) const; Vector shadow(CSS::PropertyID) const; - mutable RefPtr m_font; + mutable RefPtr m_font; }; } diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.cpp b/Userland/Libraries/LibWeb/CSS/StyleValue.cpp index 6743d32f6c..770df8b3bd 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValue.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleValue.cpp @@ -291,14 +291,14 @@ StyleValueList const& StyleValue::as_value_list() const } BackgroundStyleValue::BackgroundStyleValue( - ValueComparingNonnullRefPtr color, - ValueComparingNonnullRefPtr image, - ValueComparingNonnullRefPtr position, - ValueComparingNonnullRefPtr size, - ValueComparingNonnullRefPtr repeat, - ValueComparingNonnullRefPtr attachment, - ValueComparingNonnullRefPtr origin, - ValueComparingNonnullRefPtr clip) + ValueComparingNonnullRefPtr color, + ValueComparingNonnullRefPtr image, + ValueComparingNonnullRefPtr position, + ValueComparingNonnullRefPtr size, + ValueComparingNonnullRefPtr repeat, + ValueComparingNonnullRefPtr attachment, + ValueComparingNonnullRefPtr origin, + ValueComparingNonnullRefPtr clip) : StyleValueWithDefaultOperators(Type::Background) , m_properties { .color = move(color), @@ -335,7 +335,7 @@ ErrorOr BackgroundStyleValue::to_string() const return String::formatted("{} {} {} {} {} {} {} {}", TRY(m_properties.color->to_string()), TRY(m_properties.image->to_string()), TRY(m_properties.position->to_string()), TRY(m_properties.size->to_string()), TRY(m_properties.repeat->to_string()), TRY(m_properties.attachment->to_string()), TRY(m_properties.origin->to_string()), TRY(m_properties.clip->to_string())); } - auto get_layer_value_string = [](ValueComparingNonnullRefPtr const& style_value, size_t index) { + auto get_layer_value_string = [](ValueComparingNonnullRefPtr const& style_value, size_t index) { if (style_value->is_value_list()) return style_value->as_value_list().value_at(index, true)->to_string(); return style_value->to_string(); @@ -2236,19 +2236,19 @@ static Optional absolutized_length(CSS::Length const& length, CSSPi return {}; } -ValueComparingNonnullRefPtr StyleValue::absolutized(CSSPixelRect const&, Gfx::FontPixelMetrics const&, CSSPixels, CSSPixels) const +ValueComparingNonnullRefPtr StyleValue::absolutized(CSSPixelRect const&, Gfx::FontPixelMetrics const&, CSSPixels, CSSPixels) const { return *this; } -ValueComparingNonnullRefPtr LengthStyleValue::absolutized(CSSPixelRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, CSSPixels font_size, CSSPixels root_font_size) const +ValueComparingNonnullRefPtr LengthStyleValue::absolutized(CSSPixelRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, CSSPixels font_size, CSSPixels root_font_size) const { if (auto length = absolutized_length(m_length, viewport_rect, font_metrics, font_size, root_font_size); length.has_value()) return LengthStyleValue::create(length.release_value()); return *this; } -ValueComparingNonnullRefPtr ShadowStyleValue::absolutized(CSSPixelRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, CSSPixels font_size, CSSPixels root_font_size) const +ValueComparingNonnullRefPtr ShadowStyleValue::absolutized(CSSPixelRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, CSSPixels font_size, CSSPixels root_font_size) const { auto absolutized_offset_x = absolutized_length(m_properties.offset_x, viewport_rect, font_metrics, font_size, root_font_size).value_or(m_properties.offset_x); auto absolutized_offset_y = absolutized_length(m_properties.offset_y, viewport_rect, font_metrics, font_size, root_font_size).value_or(m_properties.offset_y); @@ -2257,7 +2257,7 @@ ValueComparingNonnullRefPtr ShadowStyleValue::absolutized(CSSPixelRe return ShadowStyleValue::create(m_properties.color, absolutized_offset_x, absolutized_offset_y, absolutized_blur_radius, absolutized_spread_distance, m_properties.placement); } -ValueComparingNonnullRefPtr BorderRadiusStyleValue::absolutized(CSSPixelRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, CSSPixels font_size, CSSPixels root_font_size) const +ValueComparingNonnullRefPtr BorderRadiusStyleValue::absolutized(CSSPixelRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, CSSPixels font_size, CSSPixels root_font_size) const { if (m_properties.horizontal_radius.is_percentage() && m_properties.vertical_radius.is_percentage()) return *this; diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValue.h index 4e842922b9..638f2dfe07 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValue.h +++ b/Userland/Libraries/LibWeb/CSS/StyleValue.h @@ -269,7 +269,7 @@ private: template using ValueComparingNonnullRefPtrVector = AK::NonnullPtrVector>; -using StyleValueVector = ValueComparingNonnullRefPtrVector; +using StyleValueVector = ValueComparingNonnullRefPtrVector; class StyleValue : public RefCounted { public: @@ -469,7 +469,7 @@ public: virtual bool has_number() const { return false; } virtual bool has_integer() const { return false; } - virtual ValueComparingNonnullRefPtr absolutized(CSSPixelRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, CSSPixels font_size, CSSPixels root_font_size) const; + virtual ValueComparingNonnullRefPtr absolutized(CSSPixelRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, CSSPixels font_size, CSSPixels root_font_size) const; virtual Color to_color(Layout::NodeWithStyle const&) const { return {}; } virtual EdgeRect to_rect() const { VERIFY_NOT_REACHED(); } @@ -533,14 +533,14 @@ private: class BackgroundStyleValue final : public StyleValueWithDefaultOperators { public: static ValueComparingNonnullRefPtr create( - ValueComparingNonnullRefPtr color, - ValueComparingNonnullRefPtr image, - ValueComparingNonnullRefPtr position, - ValueComparingNonnullRefPtr size, - ValueComparingNonnullRefPtr repeat, - ValueComparingNonnullRefPtr attachment, - ValueComparingNonnullRefPtr origin, - ValueComparingNonnullRefPtr clip) + ValueComparingNonnullRefPtr color, + ValueComparingNonnullRefPtr image, + ValueComparingNonnullRefPtr position, + ValueComparingNonnullRefPtr size, + ValueComparingNonnullRefPtr repeat, + ValueComparingNonnullRefPtr attachment, + ValueComparingNonnullRefPtr origin, + ValueComparingNonnullRefPtr clip) { return adopt_ref(*new BackgroundStyleValue(move(color), move(image), move(position), move(size), move(repeat), move(attachment), move(origin), move(clip))); } @@ -548,14 +548,14 @@ public: size_t layer_count() const { return m_properties.layer_count; } - ValueComparingNonnullRefPtr attachment() const { return m_properties.attachment; } - ValueComparingNonnullRefPtr clip() const { return m_properties.clip; } - ValueComparingNonnullRefPtr color() const { return m_properties.color; } - ValueComparingNonnullRefPtr image() const { return m_properties.image; } - ValueComparingNonnullRefPtr origin() const { return m_properties.origin; } - ValueComparingNonnullRefPtr position() const { return m_properties.position; } - ValueComparingNonnullRefPtr repeat() const { return m_properties.repeat; } - ValueComparingNonnullRefPtr size() const { return m_properties.size; } + auto attachment() const { return m_properties.attachment; } + auto clip() const { return m_properties.clip; } + auto color() const { return m_properties.color; } + auto image() const { return m_properties.image; } + auto origin() const { return m_properties.origin; } + auto position() const { return m_properties.position; } + auto repeat() const { return m_properties.repeat; } + auto size() const { return m_properties.size; } virtual ErrorOr to_string() const override; @@ -563,24 +563,24 @@ public: private: BackgroundStyleValue( - ValueComparingNonnullRefPtr color, - ValueComparingNonnullRefPtr image, - ValueComparingNonnullRefPtr position, - ValueComparingNonnullRefPtr size, - ValueComparingNonnullRefPtr repeat, - ValueComparingNonnullRefPtr attachment, - ValueComparingNonnullRefPtr origin, - ValueComparingNonnullRefPtr clip); + ValueComparingNonnullRefPtr color, + ValueComparingNonnullRefPtr image, + ValueComparingNonnullRefPtr position, + ValueComparingNonnullRefPtr size, + ValueComparingNonnullRefPtr repeat, + ValueComparingNonnullRefPtr attachment, + ValueComparingNonnullRefPtr origin, + ValueComparingNonnullRefPtr clip); struct Properties { - ValueComparingNonnullRefPtr color; - ValueComparingNonnullRefPtr image; - ValueComparingNonnullRefPtr position; - ValueComparingNonnullRefPtr size; - ValueComparingNonnullRefPtr repeat; - ValueComparingNonnullRefPtr attachment; - ValueComparingNonnullRefPtr origin; - ValueComparingNonnullRefPtr clip; + ValueComparingNonnullRefPtr color; + ValueComparingNonnullRefPtr image; + ValueComparingNonnullRefPtr position; + ValueComparingNonnullRefPtr size; + ValueComparingNonnullRefPtr repeat; + ValueComparingNonnullRefPtr attachment; + ValueComparingNonnullRefPtr origin; + ValueComparingNonnullRefPtr clip; size_t layer_count; bool operator==(Properties const&) const = default; } m_properties; @@ -705,7 +705,7 @@ private: { } - virtual ValueComparingNonnullRefPtr absolutized(CSSPixelRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, CSSPixels font_size, CSSPixels root_font_size) const override; + virtual ValueComparingNonnullRefPtr absolutized(CSSPixelRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, CSSPixels font_size, CSSPixels root_font_size) const override; struct Properties { bool is_elliptical; @@ -717,33 +717,41 @@ private: class BorderRadiusShorthandStyleValue final : public StyleValueWithDefaultOperators { public: - static ValueComparingNonnullRefPtr create(ValueComparingNonnullRefPtr top_left, ValueComparingNonnullRefPtr top_right, ValueComparingNonnullRefPtr bottom_right, ValueComparingNonnullRefPtr bottom_left) + static ValueComparingNonnullRefPtr create( + ValueComparingNonnullRefPtr top_left, + ValueComparingNonnullRefPtr top_right, + ValueComparingNonnullRefPtr bottom_right, + ValueComparingNonnullRefPtr bottom_left) { return adopt_ref(*new BorderRadiusShorthandStyleValue(move(top_left), move(top_right), move(bottom_right), move(bottom_left))); } virtual ~BorderRadiusShorthandStyleValue() override = default; - ValueComparingNonnullRefPtr top_left() const { return m_properties.top_left; } - ValueComparingNonnullRefPtr top_right() const { return m_properties.top_right; } - ValueComparingNonnullRefPtr bottom_right() const { return m_properties.bottom_right; } - ValueComparingNonnullRefPtr bottom_left() const { return m_properties.bottom_left; } + auto top_left() const { return m_properties.top_left; } + auto top_right() const { return m_properties.top_right; } + auto bottom_right() const { return m_properties.bottom_right; } + auto bottom_left() const { return m_properties.bottom_left; } virtual ErrorOr to_string() const override; bool properties_equal(BorderRadiusShorthandStyleValue const& other) const { return m_properties == other.m_properties; } private: - BorderRadiusShorthandStyleValue(ValueComparingNonnullRefPtr top_left, ValueComparingNonnullRefPtr top_right, ValueComparingNonnullRefPtr bottom_right, ValueComparingNonnullRefPtr bottom_left) + BorderRadiusShorthandStyleValue( + ValueComparingNonnullRefPtr top_left, + ValueComparingNonnullRefPtr top_right, + ValueComparingNonnullRefPtr bottom_right, + ValueComparingNonnullRefPtr bottom_left) : StyleValueWithDefaultOperators(Type::BorderRadiusShorthand) , m_properties { .top_left = move(top_left), .top_right = move(top_right), .bottom_right = move(bottom_right), .bottom_left = move(bottom_left) } { } struct Properties { - ValueComparingNonnullRefPtr top_left; - ValueComparingNonnullRefPtr top_right; - ValueComparingNonnullRefPtr bottom_right; - ValueComparingNonnullRefPtr bottom_left; + ValueComparingNonnullRefPtr top_left; + ValueComparingNonnullRefPtr top_right; + ValueComparingNonnullRefPtr bottom_right; + ValueComparingNonnullRefPtr bottom_left; bool operator==(Properties const&) const = default; } m_properties; }; @@ -1206,7 +1214,7 @@ private: class GridTrackPlacementShorthandStyleValue final : public StyleValueWithDefaultOperators { public: - static ValueComparingNonnullRefPtr create(ValueComparingNonnullRefPtr start, ValueComparingNonnullRefPtr end) + static ValueComparingNonnullRefPtr create(ValueComparingNonnullRefPtr start, ValueComparingNonnullRefPtr end) { return adopt_ref(*new GridTrackPlacementShorthandStyleValue(move(start), move(end))); } @@ -1216,30 +1224,34 @@ public: } virtual ~GridTrackPlacementShorthandStyleValue() override = default; - ValueComparingNonnullRefPtr start() const { return m_properties.start; } - ValueComparingNonnullRefPtr end() const { return m_properties.end; } + auto start() const { return m_properties.start; } + auto end() const { return m_properties.end; } virtual ErrorOr to_string() const override; bool properties_equal(GridTrackPlacementShorthandStyleValue const& other) const { return m_properties == other.m_properties; }; private: - GridTrackPlacementShorthandStyleValue(ValueComparingNonnullRefPtr start, ValueComparingNonnullRefPtr end) + GridTrackPlacementShorthandStyleValue(ValueComparingNonnullRefPtr start, ValueComparingNonnullRefPtr end) : StyleValueWithDefaultOperators(Type::GridTrackPlacementShorthand) , m_properties { .start = move(start), .end = move(end) } { } struct Properties { - ValueComparingNonnullRefPtr start; - ValueComparingNonnullRefPtr end; + ValueComparingNonnullRefPtr start; + ValueComparingNonnullRefPtr end; bool operator==(Properties const&) const = default; } m_properties; }; class GridAreaShorthandStyleValue final : public StyleValueWithDefaultOperators { public: - static ValueComparingNonnullRefPtr create(ValueComparingNonnullRefPtr row_start, ValueComparingNonnullRefPtr column_start, ValueComparingNonnullRefPtr row_end, ValueComparingNonnullRefPtr column_end) + static ValueComparingNonnullRefPtr create( + ValueComparingNonnullRefPtr row_start, + ValueComparingNonnullRefPtr column_start, + ValueComparingNonnullRefPtr row_end, + ValueComparingNonnullRefPtr column_end) { return adopt_ref(*new GridAreaShorthandStyleValue(row_start, column_start, row_end, column_end)); } @@ -1249,27 +1261,27 @@ public: } virtual ~GridAreaShorthandStyleValue() override = default; - ValueComparingNonnullRefPtr row_start() const { return m_properties.row_start; } - ValueComparingNonnullRefPtr column_start() const { return m_properties.column_start; } - ValueComparingNonnullRefPtr row_end() const { return m_properties.row_end; } - ValueComparingNonnullRefPtr column_end() const { return m_properties.column_end; } + auto row_start() const { return m_properties.row_start; } + auto column_start() const { return m_properties.column_start; } + auto row_end() const { return m_properties.row_end; } + auto column_end() const { return m_properties.column_end; } virtual ErrorOr to_string() const override; bool properties_equal(GridAreaShorthandStyleValue const& other) const { return m_properties == other.m_properties; } private: - GridAreaShorthandStyleValue(ValueComparingNonnullRefPtr row_start, ValueComparingNonnullRefPtr column_start, ValueComparingNonnullRefPtr row_end, ValueComparingNonnullRefPtr column_end) + GridAreaShorthandStyleValue(ValueComparingNonnullRefPtr row_start, ValueComparingNonnullRefPtr column_start, ValueComparingNonnullRefPtr row_end, ValueComparingNonnullRefPtr column_end) : StyleValueWithDefaultOperators(Type::GridAreaShorthand) , m_properties { .row_start = move(row_start), .column_start = move(column_start), .row_end = move(row_end), .column_end = move(column_end) } { } struct Properties { - ValueComparingNonnullRefPtr row_start; - ValueComparingNonnullRefPtr column_start; - ValueComparingNonnullRefPtr row_end; - ValueComparingNonnullRefPtr column_end; + ValueComparingNonnullRefPtr row_start; + ValueComparingNonnullRefPtr column_start; + ValueComparingNonnullRefPtr row_end; + ValueComparingNonnullRefPtr column_end; bool operator==(Properties const&) const = default; } m_properties; }; @@ -1623,7 +1635,7 @@ public: virtual ErrorOr to_string() const override { return m_length.to_string(); } virtual Length to_length() const override { return m_length; } virtual ValueID to_identifier() const override { return has_auto() ? ValueID::Auto : ValueID::Invalid; } - virtual ValueComparingNonnullRefPtr absolutized(CSSPixelRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, CSSPixels font_size, CSSPixels root_font_size) const override; + virtual ValueComparingNonnullRefPtr absolutized(CSSPixelRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, CSSPixels font_size, CSSPixels root_font_size) const override; bool properties_equal(LengthStyleValue const& other) const { return m_length == other.m_length; } @@ -1852,7 +1864,7 @@ private: { } - virtual ValueComparingNonnullRefPtr absolutized(CSSPixelRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, CSSPixels font_size, CSSPixels root_font_size) const override; + virtual ValueComparingNonnullRefPtr absolutized(CSSPixelRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, CSSPixels font_size, CSSPixels root_font_size) const override; struct Properties { Color color; @@ -2038,7 +2050,7 @@ public: size_t size() const { return m_properties.values.size(); } StyleValueVector const& values() const { return m_properties.values; } - ValueComparingNonnullRefPtr value_at(size_t i, bool allow_loop) const + ValueComparingNonnullRefPtr value_at(size_t i, bool allow_loop) const { if (allow_loop) return m_properties.values[i % size()]; diff --git a/Userland/Libraries/LibWeb/DOM/Element.h b/Userland/Libraries/LibWeb/DOM/Element.h index 7b1ca4b494..5beb5257bf 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.h +++ b/Userland/Libraries/LibWeb/DOM/Element.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2021, Andreas Kling + * Copyright (c) 2018-2023, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ @@ -122,6 +122,7 @@ public: DeprecatedString name() const { return attribute(HTML::AttributeNames::name); } + CSS::StyleProperties* computed_css_values() { return m_computed_css_values.ptr(); } CSS::StyleProperties const* computed_css_values() const { return m_computed_css_values.ptr(); } void set_computed_css_values(RefPtr style) { m_computed_css_values = move(style); } NonnullRefPtr resolved_css_values(); diff --git a/Userland/Libraries/LibWeb/FontCache.cpp b/Userland/Libraries/LibWeb/FontCache.cpp index 30b93f641f..b37bf8e553 100644 --- a/Userland/Libraries/LibWeb/FontCache.cpp +++ b/Userland/Libraries/LibWeb/FontCache.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2020, Andreas Kling + * Copyright (c) 2018-2023, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ @@ -13,7 +13,7 @@ FontCache& FontCache::the() return cache; } -RefPtr FontCache::get(FontSelector const& font_selector) const +RefPtr FontCache::get(FontSelector const& font_selector) const { auto cached_font = m_fonts.get(font_selector); if (cached_font.has_value()) @@ -21,7 +21,7 @@ RefPtr FontCache::get(FontSelector const& font_selector) const return nullptr; } -void FontCache::set(FontSelector const& font_selector, NonnullRefPtr font) +void FontCache::set(FontSelector const& font_selector, NonnullRefPtr font) { m_fonts.set(font_selector, move(font)); } diff --git a/Userland/Libraries/LibWeb/FontCache.h b/Userland/Libraries/LibWeb/FontCache.h index ce9cfe7622..daf725305f 100644 --- a/Userland/Libraries/LibWeb/FontCache.h +++ b/Userland/Libraries/LibWeb/FontCache.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2020, Andreas Kling + * Copyright (c) 2018-2023, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ @@ -34,10 +34,10 @@ struct Traits : public GenericTraits { class FontCache { public: static FontCache& the(); - RefPtr get(FontSelector const&) const; - void set(FontSelector const&, NonnullRefPtr); + RefPtr get(FontSelector const&) const; + void set(FontSelector const&, NonnullRefPtr); private: FontCache() = default; - mutable HashMap> m_fonts; + mutable HashMap> m_fonts; }; diff --git a/Userland/Libraries/LibWeb/Layout/Node.cpp b/Userland/Libraries/LibWeb/Layout/Node.cpp index 8809e9c832..7bfd886de5 100644 --- a/Userland/Libraries/LibWeb/Layout/Node.cpp +++ b/Userland/Libraries/LibWeb/Layout/Node.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2022, Andreas Kling + * Copyright (c) 2018-2023, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ @@ -277,7 +277,7 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& computed_style) return 1; }; - auto value_for_layer = [](auto& style_value, size_t layer_index) -> RefPtr { + auto value_for_layer = [](auto& style_value, size_t layer_index) -> RefPtr { if (style_value->is_value_list()) return style_value->as_value_list().value_at(layer_index, true); return style_value; @@ -301,7 +301,7 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& computed_style) if (auto image_value = value_for_layer(images, layer_index); image_value) { if (image_value->is_abstract_image()) { layer.background_image = image_value->as_abstract_image(); - layer.background_image->load_any_resources(document()); + const_cast(*layer.background_image).load_any_resources(document()); } } @@ -517,7 +517,7 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& computed_style) auto list_style_image = computed_style.property(CSS::PropertyID::ListStyleImage); if (list_style_image->is_abstract_image()) { m_list_style_image = list_style_image->as_abstract_image(); - m_list_style_image->load_any_resources(document()); + const_cast(*m_list_style_image).load_any_resources(document()); } computed_values.set_color(computed_style.color_or_fallback(CSS::PropertyID::Color, *this, CSS::InitialValues::color())); @@ -574,7 +574,7 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& computed_style) auto resolve_border_width = [&]() { auto value = computed_style.property(width_property); if (value->is_calculated()) - return CSS::Length::make_calculated(value->as_calculated()).to_px(*this).value(); + return CSS::Length::make_calculated(const_cast(value->as_calculated())).to_px(*this).value(); if (value->has_length()) return value->to_length().to_px(*this).value(); if (value->is_identifier()) { diff --git a/Userland/Libraries/LibWeb/Layout/Node.h b/Userland/Libraries/LibWeb/Layout/Node.h index effb811f01..6df5d3495b 100644 --- a/Userland/Libraries/LibWeb/Layout/Node.h +++ b/Userland/Libraries/LibWeb/Layout/Node.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2021, Andreas Kling + * Copyright (c) 2018-2023, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ @@ -195,9 +195,9 @@ protected: private: CSS::ComputedValues m_computed_values; - RefPtr m_font; + RefPtr m_font; CSSPixels m_line_height { 0 }; - RefPtr m_list_style_image; + RefPtr m_list_style_image; }; class NodeWithStyleAndBoxModelMetrics : public NodeWithStyle { diff --git a/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp b/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp index bb1c807eeb..e3af41b338 100644 --- a/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp +++ b/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Andreas Kling + * Copyright (c) 2022-2023, Andreas Kling * Copyright (c) 2022, Sam Atkins * * SPDX-License-Identifier: BSD-2-Clause @@ -513,7 +513,7 @@ static void paint_text_fragment(PaintContext& context, Layout::TextNode const& t Utf8View view { text.substring_view(fragment.start(), fragment.length()) }; auto& font = fragment.layout_node().font(); - auto scaled_font = [&]() -> RefPtr { + auto scaled_font = [&]() -> RefPtr { auto device_font_pt_size = context.enclosing_device_pixels(font.presentation_size()); FontSelector font_selector = { FlyString::from_utf8(font.family()).release_value_but_fixme_should_propagate_errors(), static_cast(device_font_pt_size.value()), font.weight(), font.width(), font.slope() }; if (auto cached_font = FontCache::the().get(font_selector)) {