LibWeb: Implement missing basic shapes

This commit is contained in:
Gingeh 2024-10-27 11:58:52 +11:00 committed by Sam Atkins
commit a7e83c38ee
Notes: github-actions[bot] 2024-10-31 10:49:39 +00:00
8 changed files with 620 additions and 28 deletions

View file

@ -7,12 +7,71 @@
#pragma once
#include <AK/Variant.h>
#include <LibGfx/DeprecatedPath.h>
#include <LibWeb/CSS/CSSStyleValue.h>
#include <LibWeb/CSS/LengthBox.h>
#include <LibWeb/CSS/PercentageOr.h>
#include <LibWeb/CSS/StyleValues/PositionStyleValue.h>
namespace Web::CSS {
struct Inset {
Gfx::Path to_path(CSSPixelRect reference_box, Layout::Node const&) const;
String to_string() const;
bool operator==(Inset const&) const = default;
LengthBox inset_box;
};
struct Xywh {
Gfx::Path to_path(CSSPixelRect reference_box, Layout::Node const&) const;
String to_string() const;
bool operator==(Xywh const&) const = default;
LengthPercentage x;
LengthPercentage y;
LengthPercentage width;
LengthPercentage height;
};
struct Rect {
Gfx::Path to_path(CSSPixelRect reference_box, Layout::Node const&) const;
String to_string() const;
bool operator==(Rect const&) const = default;
LengthBox box;
};
enum class FitSide {
ClosestSide,
FarthestSide,
};
using ShapeRadius = Variant<LengthPercentage, FitSide>;
struct Circle {
Gfx::Path to_path(CSSPixelRect reference_box, Layout::Node const&) const;
String to_string() const;
bool operator==(Circle const&) const = default;
ShapeRadius radius;
ValueComparingNonnullRefPtr<PositionStyleValue> position;
};
struct Ellipse {
Gfx::Path to_path(CSSPixelRect reference_box, Layout::Node const&) const;
String to_string() const;
bool operator==(Ellipse const&) const = default;
ShapeRadius radius_x;
ShapeRadius radius_y;
ValueComparingNonnullRefPtr<PositionStyleValue> position;
};
struct Polygon {
struct Point {
bool operator==(Point const&) const = default;
@ -25,12 +84,13 @@ struct Polygon {
bool operator==(Polygon const&) const = default;
// FIXME: Actually use the fill rule
FillRule fill_rule;
Vector<Point> points;
};
// FIXME: Implement other basic shapes. See: https://www.w3.org/TR/css-shapes-1/#basic-shape-functions
using BasicShape = Variant<Polygon>;
// FIXME: Implement path(). See: https://www.w3.org/TR/css-shapes-1/#basic-shape-functions
using BasicShape = Variant<Inset, Xywh, Rect, Circle, Ellipse, Polygon>;
class BasicShapeStyleValue : public StyleValueWithDefaultOperators<BasicShapeStyleValue> {
public: