1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 19:47:44 +00:00

LibWeb: Implement <center> as -libweb-center

To get the expected behavior for <center>, we needed a special text
alignment mode that centers block-level elements (and not just line
box fragments.)
This commit is contained in:
Andreas Kling 2020-06-13 10:54:58 +02:00
parent 6de937a689
commit 784ed004e6
6 changed files with 26 additions and 14 deletions

View file

@ -59,7 +59,7 @@ article, aside, section {
}
center {
text-align: center;
text-align: -libweb-center;
}
h1, h2, h3 {

View file

@ -216,4 +216,19 @@ bool StyleProperties::operator==(const StyleProperties& other) const
return true;
}
CSS::ValueID StyleProperties::text_align() const
{
auto string = string_or_fallback(CSS::PropertyID::TextAlign, "left");
if (string == "center")
return CSS::ValueID::Center;
if (string == "right")
return CSS::ValueID::Right;
if (string == "justify")
return CSS::ValueID::Justify;
if (string == "-libweb-center")
return CSS::ValueID::VendorSpecificCenter;
// Otherwise, just assume "left"..
return CSS::ValueID::Left;
}
}

View file

@ -58,6 +58,7 @@ public:
Length length_or_fallback(CSS::PropertyID, const Length& fallback, float reference_for_percentages) const;
String string_or_fallback(CSS::PropertyID, const StringView& fallback) const;
Color color_or_fallback(CSS::PropertyID, const Document&, Color fallback) const;
CSS::ValueID text_align() const;
const Gfx::Font& font() const
{

View file

@ -53,6 +53,8 @@ String IdentifierStyleValue::to_string() const
return "(invalid)";
case CSS::ValueID::VendorSpecificLink:
return "-libweb-link";
case CSS::ValueID::VendorSpecificCenter:
return "-libweb-center";
case CSS::ValueID::VendorSpecificPaletteDesktopBackground:
return "-libweb-palette-desktop-background";
case CSS::ValueID::VendorSpecificPaletteActiveWindowBorder1:

View file

@ -104,6 +104,7 @@ enum class ValueID {
Left,
Right,
Justify,
VendorSpecificCenter,
};
enum class Position {