mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 21:08:12 +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
|
@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue