1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 01:47:34 +00:00

LibWeb: Add CSS ValueListStyleValue

As the new CSS parser tokenizes its input, we can no longer easily
rely on a StringStyleValue for multi-value properties. (eg, border)
ValueListStyleValue lets us wrap all of the ComponentValues that
the Parser produced for one declaration, as a single StyleValue, to
then be parsed into StyleValues by the StyleResolver.

Originally, I wanted it to be a list of StyleValues, but several
properties use syntax that makes use of non-StyleValue tokens, eg:
```css
/* Syntax using a / */
font: 12px/14px sans-serif;
/* Multiple values separated by commas */
background: url(catdog.png), url(another-image.jpg), blue;
```
Passing the ComponentValue tokens themselves means that all that
information is carried over. The alternative might be to create a
StyleValue subclass for each property and parse them fully inside
the Parser. (eg, `FontStyleValue`)

I decided against `ListStyleValue` as a name, to avoid confusion
with list styles. It's not ideal, but names are hard.
This commit is contained in:
Sam Atkins 2021-07-13 16:50:58 +01:00 committed by Andreas Kling
parent 8c2be4b3dc
commit 4a03279539
2 changed files with 42 additions and 0 deletions

View file

@ -1,11 +1,14 @@
/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021, Sam Atkins <atkinssj@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/ByteBuffer.h>
#include <AK/Vector.h>
#include <LibGfx/Palette.h>
#include <LibWeb/CSS/Parser/StyleComponentValueRule.h>
#include <LibWeb/CSS/StyleValue.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/InProcessWebView.h>
@ -169,4 +172,23 @@ void ImageStyleValue::resource_did_load()
m_document->browsing_context()->set_needs_display({});
}
ValueListStyleValue::ValueListStyleValue(Vector<StyleComponentValueRule>&& values)
: StyleValue(Type::ValueList)
, m_values(move(values))
{
}
String ValueListStyleValue::to_string() const
{
StringBuilder builder;
builder.appendff("List[{}](", m_values.size());
for (auto& value : m_values) {
builder.append(value.to_debug_string());
builder.append(",");
}
builder.append(")");
return builder.to_string();
}
}