Bläddra i källkod

LibWeb: Add plumbing for the new 'object-position' property

Now, the 'object-position' property gets properly parsed and is
provided to the rest of the ecosystem.
In the parser we use the same parsing as for the background-position,
which is not entirely correct but almost a <position>.
Tobias Christiansen 1 år sedan
förälder
incheckning
d00c7e55a5

+ 6 - 0
Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp

@@ -5952,6 +5952,12 @@ Parser::ParseErrorOr<NonnullRefPtr<StyleValue>> Parser::parse_css_value(Property
         if (auto parsed_value = parse_math_depth_value(component_values))
             return parsed_value.release_nonnull();
         return ParseError::SyntaxError;
+    case PropertyID::ObjectPosition:
+        // FIXME: This should use a parse_position compatible to VALUES-4
+        //        and not the background position, which is almost the same.
+        if (auto parsed_value = parse_comma_separated_value_list(component_values, [this](auto& tokens) { return parse_single_background_position_value(tokens); }))
+            return parsed_value.release_nonnull();
+        return ParseError::SyntaxError;
     case PropertyID::Overflow:
         if (auto parsed_value = parse_overflow_value(component_values))
             return parsed_value.release_nonnull();

+ 7 - 0
Userland/Libraries/LibWeb/CSS/StyleProperties.cpp

@@ -22,6 +22,7 @@
 #include <LibWeb/CSS/StyleValues/MathDepthStyleValue.h>
 #include <LibWeb/CSS/StyleValues/NumberStyleValue.h>
 #include <LibWeb/CSS/StyleValues/PercentageStyleValue.h>
+#include <LibWeb/CSS/StyleValues/PositionStyleValue.h>
 #include <LibWeb/CSS/StyleValues/RectStyleValue.h>
 #include <LibWeb/CSS/StyleValues/ShadowStyleValue.h>
 #include <LibWeb/CSS/StyleValues/StringStyleValue.h>
@@ -1007,6 +1008,12 @@ Optional<CSS::ObjectFit> StyleProperties::object_fit() const
     return value_id_to_object_fit(value->to_identifier());
 }
 
+CSS::PositionStyleValue const& StyleProperties::object_position() const
+{
+    auto value = property(CSS::PropertyID::ObjectPosition);
+    return value->as_position();
+}
+
 Optional<CSS::TableLayout> StyleProperties::table_layout() const
 {
     auto value = property(CSS::PropertyID::TableLayout);

+ 1 - 0
Userland/Libraries/LibWeb/CSS/StyleProperties.h

@@ -117,6 +117,7 @@ public:
     Vector<Vector<String>> grid_template_areas() const;
     String grid_area() const;
     Optional<CSS::ObjectFit> object_fit() const;
+    CSS::PositionStyleValue const& object_position() const;
     Optional<CSS::TableLayout> table_layout() const;
 
     Vector<CSS::Transformation> transformations() const;