mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 05:57:44 +00:00
LibWeb: Add LinearGradientStyleValue
This commit is contained in:
parent
8603541e56
commit
259bb30c35
3 changed files with 188 additions and 1 deletions
|
@ -58,6 +58,31 @@ enum class FlexBasis {
|
|||
Auto,
|
||||
};
|
||||
|
||||
enum class SideOrCorner {
|
||||
Top,
|
||||
Bottom,
|
||||
Left,
|
||||
Right,
|
||||
TopLeft,
|
||||
TopRight,
|
||||
BottomLeft,
|
||||
BottomRight
|
||||
};
|
||||
|
||||
struct GradientColorStop {
|
||||
Color color;
|
||||
Optional<LengthPercentage> length;
|
||||
};
|
||||
|
||||
struct GradientColorHint {
|
||||
LengthPercentage value;
|
||||
};
|
||||
|
||||
struct ColorStopListElement {
|
||||
Optional<GradientColorHint> transition_hint;
|
||||
GradientColorStop color_stop;
|
||||
};
|
||||
|
||||
// FIXME: Find a better place for this helper.
|
||||
inline Gfx::Painter::ScalingMode to_gfx_scaling_mode(CSS::ImageRendering css_value)
|
||||
{
|
||||
|
@ -99,6 +124,7 @@ public:
|
|||
Initial,
|
||||
Invalid,
|
||||
Length,
|
||||
LinearGradient,
|
||||
ListStyle,
|
||||
Numeric,
|
||||
Overflow,
|
||||
|
@ -112,7 +138,7 @@ public:
|
|||
Transformation,
|
||||
Unresolved,
|
||||
Unset,
|
||||
ValueList,
|
||||
ValueList
|
||||
};
|
||||
|
||||
Type type() const { return m_type; }
|
||||
|
@ -136,6 +162,7 @@ public:
|
|||
bool is_inherit() const { return type() == Type::Inherit; }
|
||||
bool is_initial() const { return type() == Type::Initial; }
|
||||
bool is_length() const { return type() == Type::Length; }
|
||||
bool is_linear_gradient() const { return type() == Type::LinearGradient; }
|
||||
bool is_list_style() const { return type() == Type::ListStyle; }
|
||||
bool is_numeric() const { return type() == Type::Numeric; }
|
||||
bool is_overflow() const { return type() == Type::Overflow; }
|
||||
|
@ -172,6 +199,7 @@ public:
|
|||
InheritStyleValue const& as_inherit() const;
|
||||
InitialStyleValue const& as_initial() const;
|
||||
LengthStyleValue const& as_length() const;
|
||||
LinearGradientStyleValue const& as_linear_gradient() const;
|
||||
ListStyleStyleValue const& as_list_style() const;
|
||||
NumericStyleValue const& as_numeric() const;
|
||||
OverflowStyleValue const& as_overflow() const;
|
||||
|
@ -206,6 +234,7 @@ public:
|
|||
InheritStyleValue& as_inherit() { return const_cast<InheritStyleValue&>(const_cast<StyleValue const&>(*this).as_inherit()); }
|
||||
InitialStyleValue& as_initial() { return const_cast<InitialStyleValue&>(const_cast<StyleValue const&>(*this).as_initial()); }
|
||||
LengthStyleValue& as_length() { return const_cast<LengthStyleValue&>(const_cast<StyleValue const&>(*this).as_length()); }
|
||||
LinearGradientStyleValue& as_linear_gradient() { return const_cast<LinearGradientStyleValue&>(const_cast<StyleValue const&>(*this).as_linear_gradient()); }
|
||||
ListStyleStyleValue& as_list_style() { return const_cast<ListStyleStyleValue&>(const_cast<StyleValue const&>(*this).as_list_style()); }
|
||||
NumericStyleValue& as_numeric() { return const_cast<NumericStyleValue&>(const_cast<StyleValue const&>(*this).as_numeric()); }
|
||||
OverflowStyleValue& as_overflow() { return const_cast<OverflowStyleValue&>(const_cast<StyleValue const&>(*this).as_overflow()); }
|
||||
|
@ -887,6 +916,39 @@ private:
|
|||
RefPtr<Gfx::Bitmap> m_bitmap;
|
||||
};
|
||||
|
||||
class LinearGradientStyleValue final : public StyleValue {
|
||||
public:
|
||||
using GradientDirection = Variant<Angle, SideOrCorner>;
|
||||
|
||||
static NonnullRefPtr<LinearGradientStyleValue> create(GradientDirection direction, Vector<ColorStopListElement> color_stop_list)
|
||||
{
|
||||
VERIFY(color_stop_list.size() >= 2);
|
||||
return adopt_ref(*new LinearGradientStyleValue(direction, move(color_stop_list)));
|
||||
}
|
||||
|
||||
virtual String to_string() const override;
|
||||
virtual ~LinearGradientStyleValue() override = default;
|
||||
virtual bool equals(StyleValue const& other) const override;
|
||||
|
||||
Vector<ColorStopListElement> const& color_stop_list() const
|
||||
{
|
||||
return m_color_stop_list;
|
||||
}
|
||||
|
||||
float angle(Gfx::FloatRect const& background_box) const;
|
||||
|
||||
private:
|
||||
LinearGradientStyleValue(GradientDirection direction, Vector<ColorStopListElement> color_stop_list)
|
||||
: StyleValue(Type::LinearGradient)
|
||||
, m_direction(direction)
|
||||
, m_color_stop_list(move(color_stop_list))
|
||||
{
|
||||
}
|
||||
|
||||
GradientDirection m_direction;
|
||||
Vector<ColorStopListElement> m_color_stop_list;
|
||||
};
|
||||
|
||||
class InheritStyleValue final : public StyleValue {
|
||||
public:
|
||||
static NonnullRefPtr<InheritStyleValue> the()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue