summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp
diff options
context:
space:
mode:
authorSam Atkins <atkinssj@serenityos.org>2022-04-13 20:05:56 +0100
committerAndreas Kling <kling@serenityos.org>2022-04-14 14:54:06 +0200
commitae40e9a66c52a614d43edc4849a37493ff5f1cd6 (patch)
treeefff5b3f374a056c5821b4ff976904233013d668 /Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp
parent9bf511caa35728d80b554fcda505f6cf88e6070d (diff)
downloadserenity-ae40e9a66c52a614d43edc4849a37493ff5f1cd6.zip
LibWeb: Use generated to_value_id() functions
Diffstat (limited to 'Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp')
-rw-r--r--Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp435
1 files changed, 27 insertions, 408 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp b/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp
index 00c2e00559..d943a7c99e 100644
--- a/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp
+++ b/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp
@@ -7,6 +7,7 @@
#include <AK/Debug.h>
#include <AK/NonnullRefPtr.h>
+#include <LibWeb/CSS/Enums.h>
#include <LibWeb/CSS/ResolvedCSSStyleDeclaration.h>
#include <LibWeb/CSS/StyleComputer.h>
#include <LibWeb/DOM/Document.h>
@@ -30,17 +31,6 @@ String ResolvedCSSStyleDeclaration::item(size_t index) const
return {};
}
-static CSS::ValueID to_css_value_id(CSS::BoxSizing value)
-{
- switch (value) {
- case CSS::BoxSizing::BorderBox:
- return CSS::ValueID::BorderBox;
- case CSS::BoxSizing::ContentBox:
- return CSS::ValueID::ContentBox;
- }
- VERIFY_NOT_REACHED();
-}
-
static RefPtr<StyleValue> style_value_for_display(CSS::Display display)
{
if (display.is_none())
@@ -115,377 +105,6 @@ static RefPtr<StyleValue> style_value_for_display(CSS::Display display)
TODO();
}
-static CSS::ValueID to_css_value_id(CSS::Float value)
-{
- switch (value) {
- case Float::None:
- return CSS::ValueID::None;
- case Float::Left:
- return CSS::ValueID::Left;
- case Float::Right:
- return CSS::ValueID::Right;
- }
- VERIFY_NOT_REACHED();
-}
-
-static CSS::ValueID to_css_value_id(CSS::Clear value)
-{
- switch (value) {
- case Clear::None:
- return CSS::ValueID::None;
- case Clear::Left:
- return CSS::ValueID::Left;
- case Clear::Right:
- return CSS::ValueID::Right;
- case Clear::Both:
- return CSS::ValueID::Both;
- }
- VERIFY_NOT_REACHED();
-}
-
-static CSS::ValueID to_css_value_id(CSS::TextDecorationLine value)
-{
- switch (value) {
- case TextDecorationLine::None:
- return CSS::ValueID::None;
- case TextDecorationLine::Underline:
- return CSS::ValueID::Underline;
- case TextDecorationLine::Overline:
- return CSS::ValueID::Overline;
- case TextDecorationLine::LineThrough:
- return CSS::ValueID::LineThrough;
- case TextDecorationLine::Blink:
- return CSS::ValueID::Blink;
- }
- VERIFY_NOT_REACHED();
-}
-
-static CSS::ValueID to_css_value_id(CSS::TextDecorationStyle value)
-{
- switch (value) {
- case TextDecorationStyle::Solid:
- return CSS::ValueID::Solid;
- case TextDecorationStyle::Double:
- return CSS::ValueID::Double;
- case TextDecorationStyle::Dotted:
- return CSS::ValueID::Dotted;
- case TextDecorationStyle::Dashed:
- return CSS::ValueID::Dashed;
- case TextDecorationStyle::Wavy:
- return CSS::ValueID::Wavy;
- }
- VERIFY_NOT_REACHED();
-}
-
-static CSS::ValueID to_css_value_id(CSS::Cursor value)
-{
- switch (value) {
- case Cursor::Auto:
- return CSS::ValueID::Auto;
- case Cursor::Default:
- return CSS::ValueID::Default;
- case Cursor::None:
- return CSS::ValueID::None;
- case Cursor::ContextMenu:
- return CSS::ValueID::ContextMenu;
- case Cursor::Help:
- return CSS::ValueID::Help;
- case Cursor::Pointer:
- return CSS::ValueID::Pointer;
- case Cursor::Progress:
- return CSS::ValueID::Progress;
- case Cursor::Wait:
- return CSS::ValueID::Wait;
- case Cursor::Cell:
- return CSS::ValueID::Cell;
- case Cursor::Crosshair:
- return CSS::ValueID::Crosshair;
- case Cursor::Text:
- return CSS::ValueID::Text;
- case Cursor::VerticalText:
- return CSS::ValueID::VerticalText;
- case Cursor::Alias:
- return CSS::ValueID::Alias;
- case Cursor::Copy:
- return CSS::ValueID::Copy;
- case Cursor::Move:
- return CSS::ValueID::Move;
- case Cursor::NoDrop:
- return CSS::ValueID::NoDrop;
- case Cursor::NotAllowed:
- return CSS::ValueID::NotAllowed;
- case Cursor::Grab:
- return CSS::ValueID::Grab;
- case Cursor::Grabbing:
- return CSS::ValueID::Grabbing;
- case Cursor::EResize:
- return CSS::ValueID::EResize;
- case Cursor::NResize:
- return CSS::ValueID::NResize;
- case Cursor::NeResize:
- return CSS::ValueID::NeResize;
- case Cursor::NwResize:
- return CSS::ValueID::NwResize;
- case Cursor::SResize:
- return CSS::ValueID::SResize;
- case Cursor::SeResize:
- return CSS::ValueID::SeResize;
- case Cursor::SwResize:
- return CSS::ValueID::SwResize;
- case Cursor::WResize:
- return CSS::ValueID::WResize;
- case Cursor::EwResize:
- return CSS::ValueID::EwResize;
- case Cursor::NsResize:
- return CSS::ValueID::NsResize;
- case Cursor::NeswResize:
- return CSS::ValueID::NeswResize;
- case Cursor::NwseResize:
- return CSS::ValueID::NwseResize;
- case Cursor::ColResize:
- return CSS::ValueID::ColResize;
- case Cursor::RowResize:
- return CSS::ValueID::RowResize;
- case Cursor::AllScroll:
- return CSS::ValueID::AllScroll;
- case Cursor::ZoomIn:
- return CSS::ValueID::ZoomIn;
- case Cursor::ZoomOut:
- return CSS::ValueID::ZoomOut;
- }
- VERIFY_NOT_REACHED();
-}
-
-static CSS::ValueID to_css_value_id(CSS::TextAlign value)
-{
- switch (value) {
- case TextAlign::Left:
- return CSS::ValueID::Left;
- case TextAlign::Center:
- return CSS::ValueID::Center;
- case TextAlign::Right:
- return CSS::ValueID::Right;
- case TextAlign::Justify:
- return CSS::ValueID::Justify;
- case TextAlign::LibwebCenter:
- return CSS::ValueID::LibwebCenter;
- }
- VERIFY_NOT_REACHED();
-}
-
-static CSS::ValueID to_css_value_id(CSS::TextTransform value)
-{
- switch (value) {
- case TextTransform::None:
- return CSS::ValueID::None;
- case TextTransform::Capitalize:
- return CSS::ValueID::Capitalize;
- case TextTransform::Uppercase:
- return CSS::ValueID::Uppercase;
- case TextTransform::Lowercase:
- return CSS::ValueID::Lowercase;
- case TextTransform::FullWidth:
- return CSS::ValueID::FullWidth;
- case TextTransform::FullSizeKana:
- return CSS::ValueID::FullSizeKana;
- }
- VERIFY_NOT_REACHED();
-}
-
-static CSS::ValueID to_css_value_id(CSS::Position value)
-{
- switch (value) {
- case Position::Static:
- return CSS::ValueID::Static;
- case Position::Relative:
- return CSS::ValueID::Relative;
- case Position::Absolute:
- return CSS::ValueID::Absolute;
- case Position::Fixed:
- return CSS::ValueID::Fixed;
- case Position::Sticky:
- return CSS::ValueID::Sticky;
- }
- VERIFY_NOT_REACHED();
-}
-
-static CSS::ValueID to_css_value_id(CSS::WhiteSpace value)
-{
- switch (value) {
- case WhiteSpace::Normal:
- return CSS::ValueID::Normal;
- case WhiteSpace::Pre:
- return CSS::ValueID::Pre;
- case WhiteSpace::Nowrap:
- return CSS::ValueID::Nowrap;
- case WhiteSpace::PreLine:
- return CSS::ValueID::PreLine;
- case WhiteSpace::PreWrap:
- return CSS::ValueID::PreWrap;
- }
- VERIFY_NOT_REACHED();
-}
-
-static CSS::ValueID to_css_value_id(CSS::FlexDirection value)
-{
- switch (value) {
- case FlexDirection::Row:
- return CSS::ValueID::Row;
- case FlexDirection::RowReverse:
- return CSS::ValueID::RowReverse;
- case FlexDirection::Column:
- return CSS::ValueID::Column;
- case FlexDirection::ColumnReverse:
- return CSS::ValueID::ColumnReverse;
- }
- VERIFY_NOT_REACHED();
-}
-
-static CSS::ValueID to_css_value_id(CSS::FlexWrap value)
-{
- switch (value) {
- case FlexWrap::Nowrap:
- return CSS::ValueID::Nowrap;
- case FlexWrap::Wrap:
- return CSS::ValueID::Wrap;
- case FlexWrap::WrapReverse:
- return CSS::ValueID::WrapReverse;
- }
- VERIFY_NOT_REACHED();
-}
-
-static CSS::ValueID to_css_value_id(CSS::ImageRendering value)
-{
- switch (value) {
- case ImageRendering::Auto:
- return CSS::ValueID::Auto;
- case ImageRendering::CrispEdges:
- return CSS::ValueID::CrispEdges;
- case ImageRendering::HighQuality:
- return CSS::ValueID::HighQuality;
- case ImageRendering::Pixelated:
- return CSS::ValueID::Pixelated;
- case ImageRendering::Smooth:
- return CSS::ValueID::Smooth;
- }
- VERIFY_NOT_REACHED();
-}
-
-static CSS::ValueID to_css_value_id(CSS::JustifyContent value)
-{
- switch (value) {
- case JustifyContent::FlexStart:
- return CSS::ValueID::FlexStart;
- case JustifyContent::FlexEnd:
- return CSS::ValueID::FlexEnd;
- case JustifyContent::Center:
- return CSS::ValueID::Center;
- case JustifyContent::SpaceBetween:
- return CSS::ValueID::SpaceBetween;
- case JustifyContent::SpaceAround:
- return CSS::ValueID::SpaceAround;
- }
- VERIFY_NOT_REACHED();
-}
-
-static CSS::ValueID to_css_value_id(CSS::Overflow value)
-{
- switch (value) {
- case Overflow::Auto:
- return CSS::ValueID::Auto;
- case Overflow::Clip:
- return CSS::ValueID::Clip;
- case Overflow::Hidden:
- return CSS::ValueID::Hidden;
- case Overflow::Scroll:
- return CSS::ValueID::Scroll;
- case Overflow::Visible:
- return CSS::ValueID::Visible;
- }
- VERIFY_NOT_REACHED();
-}
-
-static CSS::ValueID to_css_value_id(CSS::VerticalAlign value)
-{
- switch (value) {
- case CSS::VerticalAlign::Baseline:
- return CSS::ValueID::Baseline;
- case CSS::VerticalAlign::Bottom:
- return CSS::ValueID::Bottom;
- case CSS::VerticalAlign::Middle:
- return CSS::ValueID::Middle;
- case CSS::VerticalAlign::Sub:
- return CSS::ValueID::Sub;
- case CSS::VerticalAlign::Super:
- return CSS::ValueID::Super;
- case CSS::VerticalAlign::TextBottom:
- return CSS::ValueID::TextBottom;
- case CSS::VerticalAlign::TextTop:
- return CSS::ValueID::TextTop;
- case CSS::VerticalAlign::Top:
- return CSS::ValueID::Top;
- }
- VERIFY_NOT_REACHED();
-}
-
-static CSS::ValueID to_css_value_id(CSS::ListStyleType value)
-{
- switch (value) {
- case ListStyleType::None:
- return CSS::ValueID::None;
- case ListStyleType::Disc:
- return CSS::ValueID::Disc;
- case ListStyleType::Circle:
- return CSS::ValueID::Circle;
- case ListStyleType::Square:
- return CSS::ValueID::Square;
- case ListStyleType::Decimal:
- return CSS::ValueID::Decimal;
- case ListStyleType::DecimalLeadingZero:
- return CSS::ValueID::DecimalLeadingZero;
- case ListStyleType::LowerAlpha:
- return CSS::ValueID::LowerAlpha;
- case ListStyleType::LowerLatin:
- return CSS::ValueID::LowerLatin;
- case ListStyleType::LowerRoman:
- return CSS::ValueID::LowerRoman;
- case ListStyleType::UpperAlpha:
- return CSS::ValueID::UpperAlpha;
- case ListStyleType::UpperLatin:
- return CSS::ValueID::UpperLatin;
- case ListStyleType::UpperRoman:
- return CSS::ValueID::UpperRoman;
- }
- VERIFY_NOT_REACHED();
-}
-
-static CSS::ValueID to_css_value_id(CSS::LineStyle value)
-{
- switch (value) {
- case CSS::LineStyle::None:
- return CSS::ValueID::None;
- case CSS::LineStyle::Hidden:
- return CSS::ValueID::Hidden;
- case CSS::LineStyle::Dotted:
- return CSS::ValueID::Dotted;
- case CSS::LineStyle::Dashed:
- return CSS::ValueID::Dashed;
- case CSS::LineStyle::Solid:
- return CSS::ValueID::Solid;
- case CSS::LineStyle::Double:
- return CSS::ValueID::Double;
- case CSS::LineStyle::Groove:
- return CSS::ValueID::Groove;
- case CSS::LineStyle::Ridge:
- return CSS::ValueID::Ridge;
- case CSS::LineStyle::Inset:
- return CSS::ValueID::Inset;
- case CSS::LineStyle::Outset:
- return CSS::ValueID::Outset;
- }
- VERIFY_NOT_REACHED();
-}
-
static NonnullRefPtr<StyleValue> value_or_default(Optional<StyleProperty> property, NonnullRefPtr<StyleValue> default_style)
{
if (property.has_value())
@@ -506,11 +125,11 @@ RefPtr<StyleValue> ResolvedCSSStyleDeclaration::style_value_for_property(Layout:
{
switch (property_id) {
case CSS::PropertyID::Float:
- return IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().float_()));
+ return IdentifierStyleValue::create(to_value_id(layout_node.computed_values().float_()));
case CSS::PropertyID::Clear:
- return IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().clear()));
+ return IdentifierStyleValue::create(to_value_id(layout_node.computed_values().clear()));
case CSS::PropertyID::Cursor:
- return IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().cursor()));
+ return IdentifierStyleValue::create(to_value_id(layout_node.computed_values().cursor()));
case CSS::PropertyID::Display:
return style_value_for_display(layout_node.computed_values().display());
case CSS::PropertyID::ZIndex: {
@@ -520,21 +139,21 @@ RefPtr<StyleValue> ResolvedCSSStyleDeclaration::style_value_for_property(Layout:
return NumericStyleValue::create_integer(maybe_z_index.release_value());
}
case CSS::PropertyID::TextAlign:
- return IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().text_align()));
+ return IdentifierStyleValue::create(to_value_id(layout_node.computed_values().text_align()));
case CSS::PropertyID::TextDecorationLine:
- return IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().text_decoration_line()));
+ return IdentifierStyleValue::create(to_value_id(layout_node.computed_values().text_decoration_line()));
case CSS::PropertyID::TextDecorationStyle:
- return IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().text_decoration_style()));
+ return IdentifierStyleValue::create(to_value_id(layout_node.computed_values().text_decoration_style()));
case CSS::PropertyID::TextTransform:
- return IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().text_transform()));
+ return IdentifierStyleValue::create(to_value_id(layout_node.computed_values().text_transform()));
case CSS::PropertyID::Position:
- return IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().position()));
+ return IdentifierStyleValue::create(to_value_id(layout_node.computed_values().position()));
case CSS::PropertyID::WhiteSpace:
- return IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().white_space()));
+ return IdentifierStyleValue::create(to_value_id(layout_node.computed_values().white_space()));
case CSS::PropertyID::FlexDirection:
- return IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().flex_direction()));
+ return IdentifierStyleValue::create(to_value_id(layout_node.computed_values().flex_direction()));
case CSS::PropertyID::FlexWrap:
- return IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().flex_wrap()));
+ return IdentifierStyleValue::create(to_value_id(layout_node.computed_values().flex_wrap()));
case CSS::PropertyID::FlexBasis: {
switch (layout_node.computed_values().flex_basis().type) {
case FlexBasis::Content:
@@ -556,9 +175,9 @@ RefPtr<StyleValue> ResolvedCSSStyleDeclaration::style_value_for_property(Layout:
case CSS::PropertyID::Opacity:
return NumericStyleValue::create_float(layout_node.computed_values().opacity());
case CSS::PropertyID::ImageRendering:
- return IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().image_rendering()));
+ return IdentifierStyleValue::create(to_value_id(layout_node.computed_values().image_rendering()));
case CSS::PropertyID::JustifyContent:
- return IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().justify_content()));
+ return IdentifierStyleValue::create(to_value_id(layout_node.computed_values().justify_content()));
case CSS::PropertyID::BoxShadow: {
auto box_shadow_layers = layout_node.computed_values().box_shadow();
if (box_shadow_layers.is_empty())
@@ -682,45 +301,45 @@ RefPtr<StyleValue> ResolvedCSSStyleDeclaration::style_value_for_property(Layout:
case CSS::PropertyID::BorderLeftColor:
return ColorStyleValue::create(layout_node.computed_values().border_left().color);
case CSS::PropertyID::BorderTopStyle:
- return IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().border_top().line_style));
+ return IdentifierStyleValue::create(to_value_id(layout_node.computed_values().border_top().line_style));
case CSS::PropertyID::BorderRightStyle:
- return IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().border_right().line_style));
+ return IdentifierStyleValue::create(to_value_id(layout_node.computed_values().border_right().line_style));
case CSS::PropertyID::BorderBottomStyle:
- return IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().border_bottom().line_style));
+ return IdentifierStyleValue::create(to_value_id(layout_node.computed_values().border_bottom().line_style));
case CSS::PropertyID::BorderLeftStyle:
- return IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().border_left().line_style));
+ return IdentifierStyleValue::create(to_value_id(layout_node.computed_values().border_left().line_style));
case CSS::PropertyID::BorderTop: {
auto border = layout_node.computed_values().border_top();
auto width = LengthStyleValue::create(Length::make_px(border.width));
- auto style = IdentifierStyleValue::create(to_css_value_id(border.line_style));
+ auto style = IdentifierStyleValue::create(to_value_id(border.line_style));
auto color = ColorStyleValue::create(border.color);
return BorderStyleValue::create(width, style, color);
}
case CSS::PropertyID::BorderRight: {
auto border = layout_node.computed_values().border_right();
auto width = LengthStyleValue::create(Length::make_px(border.width));
- auto style = IdentifierStyleValue::create(to_css_value_id(border.line_style));
+ auto style = IdentifierStyleValue::create(to_value_id(border.line_style));
auto color = ColorStyleValue::create(border.color);
return BorderStyleValue::create(width, style, color);
}
case CSS::PropertyID::BorderBottom: {
auto border = layout_node.computed_values().border_bottom();
auto width = LengthStyleValue::create(Length::make_px(border.width));
- auto style = IdentifierStyleValue::create(to_css_value_id(border.line_style));
+ auto style = IdentifierStyleValue::create(to_value_id(border.line_style));
auto color = ColorStyleValue::create(border.color);
return BorderStyleValue::create(width, style, color);
}
case CSS::PropertyID::BorderLeft: {
auto border = layout_node.computed_values().border_left();
auto width = LengthStyleValue::create(Length::make_px(border.width));
- auto style = IdentifierStyleValue::create(to_css_value_id(border.line_style));
+ auto style = IdentifierStyleValue::create(to_value_id(border.line_style));
auto color = ColorStyleValue::create(border.color);
return BorderStyleValue::create(width, style, color);
}
case CSS::PropertyID::OverflowX:
- return IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().overflow_x()));
+ return IdentifierStyleValue::create(to_value_id(layout_node.computed_values().overflow_x()));
case CSS::PropertyID::OverflowY:
- return IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().overflow_y()));
+ return IdentifierStyleValue::create(to_value_id(layout_node.computed_values().overflow_y()));
case CSS::PropertyID::Color:
return ColorStyleValue::create(layout_node.computed_values().color());
case PropertyID::BackgroundColor:
@@ -753,11 +372,11 @@ RefPtr<StyleValue> ResolvedCSSStyleDeclaration::style_value_for_property(Layout:
return PercentageStyleValue::create(length_percentage->percentage());
VERIFY_NOT_REACHED();
}
- return IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().vertical_align().get<CSS::VerticalAlign>()));
+ return IdentifierStyleValue::create(to_value_id(layout_node.computed_values().vertical_align().get<CSS::VerticalAlign>()));
case CSS::PropertyID::ListStyleType:
- return IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().list_style_type()));
+ return IdentifierStyleValue::create(to_value_id(layout_node.computed_values().list_style_type()));
case CSS::PropertyID::BoxSizing:
- return IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().box_sizing()));
+ return IdentifierStyleValue::create(to_value_id(layout_node.computed_values().box_sizing()));
case CSS::PropertyID::Invalid:
return IdentifierStyleValue::create(CSS::ValueID::Invalid);
case CSS::PropertyID::Custom: