mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 03:57:43 +00:00
LibWeb: Replace FlexStyleValue with ShorthandStyleValue
We still need the custom parsing and to_string() logic, but nothing else. :^)
This commit is contained in:
parent
a72788b889
commit
aa45b3dfe3
11 changed files with 44 additions and 106 deletions
|
@ -5,13 +5,14 @@
|
|||
*/
|
||||
|
||||
#include "ShorthandStyleValue.h"
|
||||
#include <LibWeb/CSS/PropertyID.h>
|
||||
#include <LibWeb/CSS/StyleValues/StyleValueList.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
||||
ShorthandStyleValue::ShorthandStyleValue(Vector<PropertyID> sub_properties, Vector<ValueComparingNonnullRefPtr<StyleValue const>> values)
|
||||
ShorthandStyleValue::ShorthandStyleValue(PropertyID shorthand, Vector<PropertyID> sub_properties, Vector<ValueComparingNonnullRefPtr<StyleValue const>> values)
|
||||
: StyleValueWithDefaultOperators(Type::Shorthand)
|
||||
, m_properties { move(sub_properties), move(values) }
|
||||
, m_properties { shorthand, move(sub_properties), move(values) }
|
||||
{
|
||||
if (m_properties.sub_properties.size() != m_properties.values.size()) {
|
||||
dbgln("ShorthandStyleValue: sub_properties and values must be the same size! {} != {}", m_properties.sub_properties.size(), m_properties.values.size());
|
||||
|
@ -21,18 +22,33 @@ ShorthandStyleValue::ShorthandStyleValue(Vector<PropertyID> sub_properties, Vect
|
|||
|
||||
ShorthandStyleValue::~ShorthandStyleValue() = default;
|
||||
|
||||
ValueComparingRefPtr<StyleValue const> ShorthandStyleValue::longhand(PropertyID longhand) const
|
||||
{
|
||||
for (auto i = 0u; i < m_properties.sub_properties.size(); ++i) {
|
||||
if (m_properties.sub_properties[i] == longhand)
|
||||
return m_properties.values[i];
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
String ShorthandStyleValue::to_string() const
|
||||
{
|
||||
StringBuilder builder;
|
||||
auto first = true;
|
||||
for (auto& value : m_properties.values) {
|
||||
if (first)
|
||||
first = false;
|
||||
else
|
||||
builder.append(' ');
|
||||
builder.append(value->to_string());
|
||||
// Special-cases first
|
||||
switch (m_properties.shorthand_property) {
|
||||
case PropertyID::Flex:
|
||||
return MUST(String::formatted("{} {} {}", longhand(PropertyID::FlexGrow)->to_string(), longhand(PropertyID::FlexShrink)->to_string(), longhand(PropertyID::FlexBasis)->to_string()));
|
||||
default:
|
||||
StringBuilder builder;
|
||||
auto first = true;
|
||||
for (auto& value : m_properties.values) {
|
||||
if (first)
|
||||
first = false;
|
||||
else
|
||||
builder.append(' ');
|
||||
builder.append(value->to_string());
|
||||
}
|
||||
return MUST(builder.to_string());
|
||||
}
|
||||
return MUST(builder.to_string());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue