mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 19:57:35 +00:00
LibWeb: Cache and reuse some very common StyleValue objects
Length values: auto, 0px, 1px Color values: black, white, transparent
This commit is contained in:
parent
141b01d3e3
commit
bfe69e9d0d
3 changed files with 42 additions and 8 deletions
|
@ -48,6 +48,7 @@ public:
|
|||
|
||||
bool is_auto() const { return m_type == Type::Auto; }
|
||||
bool is_calculated() const { return m_type == Type::Calculated; }
|
||||
bool is_px() const { return m_type == Type::Px; }
|
||||
|
||||
bool is_absolute() const
|
||||
{
|
||||
|
|
|
@ -1193,4 +1193,43 @@ String StyleValueList::to_string() const
|
|||
return String::join(separator, m_values);
|
||||
}
|
||||
|
||||
NonnullRefPtr<ColorStyleValue> ColorStyleValue::create(Color color)
|
||||
{
|
||||
if (color.value() == 0) {
|
||||
static auto transparent = adopt_ref(*new ColorStyleValue(color));
|
||||
return transparent;
|
||||
}
|
||||
|
||||
if (color == Color::from_rgb(0x000000)) {
|
||||
static auto black = adopt_ref(*new ColorStyleValue(color));
|
||||
return black;
|
||||
}
|
||||
|
||||
if (color == Color::from_rgb(0xffffff)) {
|
||||
static auto white = adopt_ref(*new ColorStyleValue(color));
|
||||
return white;
|
||||
}
|
||||
|
||||
return adopt_ref(*new ColorStyleValue(color));
|
||||
}
|
||||
|
||||
NonnullRefPtr<LengthStyleValue> LengthStyleValue::create(Length const& length)
|
||||
{
|
||||
if (length.is_auto()) {
|
||||
static auto value = adopt_ref(*new LengthStyleValue(CSS::Length::make_auto()));
|
||||
return value;
|
||||
}
|
||||
if (length.is_px()) {
|
||||
if (length.raw_value() == 0) {
|
||||
static auto value = adopt_ref(*new LengthStyleValue(CSS::Length::make_px(0)));
|
||||
return value;
|
||||
}
|
||||
if (length.raw_value() == 1) {
|
||||
static auto value = adopt_ref(*new LengthStyleValue(CSS::Length::make_px(1)));
|
||||
return value;
|
||||
}
|
||||
}
|
||||
return adopt_ref(*new LengthStyleValue(length));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -856,10 +856,7 @@ private:
|
|||
|
||||
class ColorStyleValue : public StyleValue {
|
||||
public:
|
||||
static NonnullRefPtr<ColorStyleValue> create(Color color)
|
||||
{
|
||||
return adopt_ref(*new ColorStyleValue(color));
|
||||
}
|
||||
static NonnullRefPtr<ColorStyleValue> create(Color color);
|
||||
virtual ~ColorStyleValue() override { }
|
||||
|
||||
Color color() const { return m_color; }
|
||||
|
@ -1101,10 +1098,7 @@ private:
|
|||
|
||||
class LengthStyleValue : public StyleValue {
|
||||
public:
|
||||
static NonnullRefPtr<LengthStyleValue> create(Length const& length)
|
||||
{
|
||||
return adopt_ref(*new LengthStyleValue(length));
|
||||
}
|
||||
static NonnullRefPtr<LengthStyleValue> create(Length const&);
|
||||
virtual ~LengthStyleValue() override { }
|
||||
|
||||
Length const& length() const { return m_length; }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue