mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-10 13:00:29 +03:00
LibWeb: Convert remaining CSS identifiers to use IdentifierStyleValue
This commit is contained in:
parent
96233bfc53
commit
6e7edd6e77
Notes:
sideshowbarker
2024-07-19 00:52:20 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/6e7edd6e77e
@ -396,6 +396,56 @@ static Optional<CSS::ValueID> value_id_from_string(const String& string)
|
|||||||
return CSS::ValueID::Fixed;
|
return CSS::ValueID::Fixed;
|
||||||
if (string.equals_ignoring_case("sticky"))
|
if (string.equals_ignoring_case("sticky"))
|
||||||
return CSS::ValueID::Sticky;
|
return CSS::ValueID::Sticky;
|
||||||
|
if (string.equals_ignoring_case("none"))
|
||||||
|
return CSS::ValueID::None;
|
||||||
|
if (string.equals_ignoring_case("both"))
|
||||||
|
return CSS::ValueID::Both;
|
||||||
|
if (string.equals_ignoring_case("hidden"))
|
||||||
|
return CSS::ValueID::Hidden;
|
||||||
|
if (string.equals_ignoring_case("dotted"))
|
||||||
|
return CSS::ValueID::Dotted;
|
||||||
|
if (string.equals_ignoring_case("dashed"))
|
||||||
|
return CSS::ValueID::Dashed;
|
||||||
|
if (string.equals_ignoring_case("solid"))
|
||||||
|
return CSS::ValueID::Solid;
|
||||||
|
if (string.equals_ignoring_case("double"))
|
||||||
|
return CSS::ValueID::Double;
|
||||||
|
if (string.equals_ignoring_case("groove"))
|
||||||
|
return CSS::ValueID::Groove;
|
||||||
|
if (string.equals_ignoring_case("ridge"))
|
||||||
|
return CSS::ValueID::Ridge;
|
||||||
|
if (string.equals_ignoring_case("inset"))
|
||||||
|
return CSS::ValueID::Inset;
|
||||||
|
if (string.equals_ignoring_case("outset"))
|
||||||
|
return CSS::ValueID::Outset;
|
||||||
|
if (string.equals_ignoring_case("nowrap"))
|
||||||
|
return CSS::ValueID::Nowrap;
|
||||||
|
if (string.equals_ignoring_case("pre"))
|
||||||
|
return CSS::ValueID::Pre;
|
||||||
|
if (string.equals_ignoring_case("pre-line"))
|
||||||
|
return CSS::ValueID::PreLine;
|
||||||
|
if (string.equals_ignoring_case("pre-wrap"))
|
||||||
|
return CSS::ValueID::PreWrap;
|
||||||
|
if (string.equals_ignoring_case("block"))
|
||||||
|
return CSS::ValueID::Block;
|
||||||
|
if (string.equals_ignoring_case("inline"))
|
||||||
|
return CSS::ValueID::Inline;
|
||||||
|
if (string.equals_ignoring_case("inline-block"))
|
||||||
|
return CSS::ValueID::InlineBlock;
|
||||||
|
if (string.equals_ignoring_case("list-item"))
|
||||||
|
return CSS::ValueID::ListItem;
|
||||||
|
if (string.equals_ignoring_case("table"))
|
||||||
|
return CSS::ValueID::Table;
|
||||||
|
if (string.equals_ignoring_case("table-row"))
|
||||||
|
return CSS::ValueID::TableRow;
|
||||||
|
if (string.equals_ignoring_case("table-cell"))
|
||||||
|
return CSS::ValueID::TableCell;
|
||||||
|
if (string.equals_ignoring_case("table-row-group"))
|
||||||
|
return CSS::ValueID::TableRowGroup;
|
||||||
|
if (string.equals_ignoring_case("table-header-group"))
|
||||||
|
return CSS::ValueID::TableHeaderGroup;
|
||||||
|
if (string.equals_ignoring_case("table-footer-group"))
|
||||||
|
return CSS::ValueID::TableFooterGroup;
|
||||||
if (string.starts_with("-libweb-palette-", CaseSensitivity::CaseInsensitive))
|
if (string.starts_with("-libweb-palette-", CaseSensitivity::CaseInsensitive))
|
||||||
return value_id_for_palette_string(string.substring_view(16, string.length() - 16));
|
return value_id_for_palette_string(string.substring_view(16, string.length() - 16));
|
||||||
return {};
|
return {};
|
||||||
|
@ -291,110 +291,122 @@ Optional<CSS::TextAlign> StyleProperties::text_align() const
|
|||||||
Optional<CSS::WhiteSpace> StyleProperties::white_space() const
|
Optional<CSS::WhiteSpace> StyleProperties::white_space() const
|
||||||
{
|
{
|
||||||
auto value = property(CSS::PropertyID::WhiteSpace);
|
auto value = property(CSS::PropertyID::WhiteSpace);
|
||||||
if (!value.has_value() || !value.value()->is_string())
|
if (!value.has_value() || !value.value()->is_identifier())
|
||||||
return {};
|
return {};
|
||||||
auto string = value.value()->to_string();
|
switch (static_cast<const IdentifierStyleValue&>(*value.value()).id()) {
|
||||||
if (string == "normal")
|
case CSS::ValueID::Normal:
|
||||||
return CSS::WhiteSpace::Normal;
|
return CSS::WhiteSpace::Normal;
|
||||||
if (string == "nowrap")
|
case CSS::ValueID::Nowrap:
|
||||||
return CSS::WhiteSpace::Nowrap;
|
return CSS::WhiteSpace::Nowrap;
|
||||||
if (string == "pre")
|
case CSS::ValueID::Pre:
|
||||||
return CSS::WhiteSpace::Pre;
|
return CSS::WhiteSpace::Pre;
|
||||||
if (string == "pre-line")
|
case CSS::ValueID::PreLine:
|
||||||
return CSS::WhiteSpace::PreLine;
|
return CSS::WhiteSpace::PreLine;
|
||||||
if (string == "pre-wrap")
|
case CSS::ValueID::PreWrap:
|
||||||
return CSS::WhiteSpace::PreWrap;
|
return CSS::WhiteSpace::PreWrap;
|
||||||
return {};
|
default:
|
||||||
|
return {};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<CSS::LineStyle> StyleProperties::line_style(CSS::PropertyID property_id) const
|
Optional<CSS::LineStyle> StyleProperties::line_style(CSS::PropertyID property_id) const
|
||||||
{
|
{
|
||||||
auto value = property(property_id);
|
auto value = property(property_id);
|
||||||
if (!value.has_value() || !value.value()->is_string())
|
if (!value.has_value() || !value.value()->is_identifier())
|
||||||
return {};
|
return {};
|
||||||
auto string = value.value()->to_string();
|
switch (static_cast<const IdentifierStyleValue&>(*value.value()).id()) {
|
||||||
if (string == "none")
|
case CSS::ValueID::None:
|
||||||
return CSS::LineStyle::None;
|
return CSS::LineStyle::None;
|
||||||
if (string == "hidden")
|
case CSS::ValueID::Hidden:
|
||||||
return CSS::LineStyle::Hidden;
|
return CSS::LineStyle::Hidden;
|
||||||
if (string == "dotted")
|
case CSS::ValueID::Dotted:
|
||||||
return CSS::LineStyle::Dotted;
|
return CSS::LineStyle::Dotted;
|
||||||
if (string == "dashed")
|
case CSS::ValueID::Dashed:
|
||||||
return CSS::LineStyle::Dashed;
|
return CSS::LineStyle::Dashed;
|
||||||
if (string == "solid")
|
case CSS::ValueID::Solid:
|
||||||
return CSS::LineStyle::Solid;
|
return CSS::LineStyle::Solid;
|
||||||
if (string == "double")
|
case CSS::ValueID::Double:
|
||||||
return CSS::LineStyle::Double;
|
return CSS::LineStyle::Double;
|
||||||
if (string == "groove")
|
case CSS::ValueID::Groove:
|
||||||
return CSS::LineStyle::Groove;
|
return CSS::LineStyle::Groove;
|
||||||
if (string == "ridge")
|
case CSS::ValueID::Ridge:
|
||||||
return CSS::LineStyle::Ridge;
|
return CSS::LineStyle::Ridge;
|
||||||
if (string == "inset")
|
case CSS::ValueID::Inset:
|
||||||
return CSS::LineStyle::Inset;
|
return CSS::LineStyle::Inset;
|
||||||
if (string == "outset")
|
case CSS::ValueID::Outset:
|
||||||
return CSS::LineStyle::Outset;
|
return CSS::LineStyle::Outset;
|
||||||
return {};
|
default:
|
||||||
|
return {};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<CSS::Float> StyleProperties::float_() const
|
Optional<CSS::Float> StyleProperties::float_() const
|
||||||
{
|
{
|
||||||
auto value = property(CSS::PropertyID::Float);
|
auto value = property(CSS::PropertyID::Float);
|
||||||
if (!value.has_value() || !value.value()->is_string())
|
if (!value.has_value() || !value.value()->is_identifier())
|
||||||
return {};
|
return {};
|
||||||
auto string = value.value()->to_string();
|
switch (static_cast<const IdentifierStyleValue&>(*value.value()).id()) {
|
||||||
if (string == "none")
|
case CSS::ValueID::None:
|
||||||
return CSS::Float::None;
|
return CSS::Float::None;
|
||||||
if (string == "left")
|
case CSS::ValueID::Left:
|
||||||
return CSS::Float::Left;
|
return CSS::Float::Left;
|
||||||
if (string == "right")
|
case CSS::ValueID::Right:
|
||||||
return CSS::Float::Right;
|
return CSS::Float::Right;
|
||||||
return {};
|
default:
|
||||||
|
return {};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<CSS::Clear> StyleProperties::clear() const
|
Optional<CSS::Clear> StyleProperties::clear() const
|
||||||
{
|
{
|
||||||
auto value = property(CSS::PropertyID::Clear);
|
auto value = property(CSS::PropertyID::Clear);
|
||||||
if (!value.has_value() || !value.value()->is_string())
|
if (!value.has_value() || !value.value()->is_identifier())
|
||||||
return {};
|
return {};
|
||||||
auto string = value.value()->to_string();
|
switch (static_cast<const IdentifierStyleValue&>(*value.value()).id()) {
|
||||||
if (string == "none")
|
case CSS::ValueID::None:
|
||||||
return CSS::Clear::None;
|
return CSS::Clear::None;
|
||||||
if (string == "left")
|
case CSS::ValueID::Left:
|
||||||
return CSS::Clear::Left;
|
return CSS::Clear::Left;
|
||||||
if (string == "right")
|
case CSS::ValueID::Right:
|
||||||
return CSS::Clear::Right;
|
return CSS::Clear::Right;
|
||||||
if (string == "both")
|
case CSS::ValueID::Both:
|
||||||
return CSS::Clear::Both;
|
return CSS::Clear::Both;
|
||||||
return {};
|
default:
|
||||||
|
return {};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CSS::Display StyleProperties::display() const
|
CSS::Display StyleProperties::display() const
|
||||||
{
|
{
|
||||||
auto display = string_or_fallback(CSS::PropertyID::Display, "inline");
|
auto value = property(CSS::PropertyID::Display);
|
||||||
if (display == "none")
|
if (!value.has_value() || !value.value()->is_identifier())
|
||||||
return CSS::Display::None;
|
|
||||||
if (display == "block")
|
|
||||||
return CSS::Display::Block;
|
|
||||||
if (display == "inline")
|
|
||||||
return CSS::Display::Inline;
|
return CSS::Display::Inline;
|
||||||
if (display == "inline-block")
|
switch (static_cast<const IdentifierStyleValue&>(*value.value()).id()) {
|
||||||
|
case CSS::ValueID::None:
|
||||||
|
return CSS::Display::None;
|
||||||
|
case CSS::ValueID::Block:
|
||||||
|
return CSS::Display::Block;
|
||||||
|
case CSS::ValueID::Inline:
|
||||||
|
return CSS::Display::Inline;
|
||||||
|
case CSS::ValueID::InlineBlock:
|
||||||
return CSS::Display::InlineBlock;
|
return CSS::Display::InlineBlock;
|
||||||
if (display == "list-item")
|
case CSS::ValueID::ListItem:
|
||||||
return CSS::Display::ListItem;
|
return CSS::Display::ListItem;
|
||||||
if (display == "table")
|
case CSS::ValueID::Table:
|
||||||
return CSS::Display::Table;
|
return CSS::Display::Table;
|
||||||
if (display == "table-row")
|
case CSS::ValueID::TableRow:
|
||||||
return CSS::Display::TableRow;
|
return CSS::Display::TableRow;
|
||||||
if (display == "table-cell")
|
case CSS::ValueID::TableCell:
|
||||||
return CSS::Display::TableCell;
|
return CSS::Display::TableCell;
|
||||||
if (display == "table-row-group")
|
case CSS::ValueID::TableRowGroup:
|
||||||
return CSS::Display::TableRowGroup;
|
return CSS::Display::TableRowGroup;
|
||||||
if (display == "table-header-group")
|
case CSS::ValueID::TableHeaderGroup:
|
||||||
return CSS::Display::TableHeaderGroup;
|
return CSS::Display::TableHeaderGroup;
|
||||||
if (display == "table-footer-group")
|
case CSS::ValueID::TableFooterGroup:
|
||||||
return CSS::Display::TableFooterGroup;
|
return CSS::Display::TableFooterGroup;
|
||||||
dbg() << "Unknown display type: _" << display << "_";
|
default:
|
||||||
return CSS::Display::Block;
|
return CSS::Display::Block;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -163,7 +163,7 @@ String IdentifierStyleValue::to_string() const
|
|||||||
case CSS::ValueID::VendorSpecificPaletteSyntaxPreprocessorValue:
|
case CSS::ValueID::VendorSpecificPaletteSyntaxPreprocessorValue:
|
||||||
return "-libweb-palette-syntax-preprocessor-value";
|
return "-libweb-palette-syntax-preprocessor-value";
|
||||||
default:
|
default:
|
||||||
ASSERT_NOT_REACHED();
|
return String::formatted("-fixme-css-value-id-{}", (int)id());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,6 +122,31 @@ enum class ValueID {
|
|||||||
Absolute,
|
Absolute,
|
||||||
Fixed,
|
Fixed,
|
||||||
Sticky,
|
Sticky,
|
||||||
|
Both,
|
||||||
|
None,
|
||||||
|
Hidden,
|
||||||
|
Dotted,
|
||||||
|
Dashed,
|
||||||
|
Solid,
|
||||||
|
Double,
|
||||||
|
Groove,
|
||||||
|
Ridge,
|
||||||
|
Inset,
|
||||||
|
Outset,
|
||||||
|
Nowrap,
|
||||||
|
Pre,
|
||||||
|
PreLine,
|
||||||
|
PreWrap,
|
||||||
|
Block,
|
||||||
|
Inline,
|
||||||
|
InlineBlock,
|
||||||
|
ListItem,
|
||||||
|
Table,
|
||||||
|
TableRow,
|
||||||
|
TableCell,
|
||||||
|
TableHeaderGroup,
|
||||||
|
TableRowGroup,
|
||||||
|
TableFooterGroup,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class Position {
|
enum class Position {
|
||||||
|
Loading…
Reference in New Issue
Block a user