mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 08:18:11 +00:00
LibWeb: Support "pt" length units :^)
This commit is contained in:
parent
7fc988b919
commit
7d3c8d066f
3 changed files with 9 additions and 23 deletions
|
@ -47,6 +47,8 @@ const char* Length::unit_name() const
|
||||||
switch (m_type) {
|
switch (m_type) {
|
||||||
case Type::Px:
|
case Type::Px:
|
||||||
return "px";
|
return "px";
|
||||||
|
case Type::Pt:
|
||||||
|
return "pt";
|
||||||
case Type::Em:
|
case Type::Em:
|
||||||
return "em";
|
return "em";
|
||||||
case Type::Rem:
|
case Type::Rem:
|
||||||
|
|
|
@ -38,6 +38,7 @@ public:
|
||||||
Percentage,
|
Percentage,
|
||||||
Auto,
|
Auto,
|
||||||
Px,
|
Px,
|
||||||
|
Pt,
|
||||||
Em,
|
Em,
|
||||||
Rem,
|
Rem,
|
||||||
};
|
};
|
||||||
|
@ -82,7 +83,7 @@ public:
|
||||||
bool is_undefined() const { return m_type == Type::Undefined; }
|
bool is_undefined() const { return m_type == Type::Undefined; }
|
||||||
bool is_percentage() const { return m_type == Type::Percentage; }
|
bool is_percentage() const { return m_type == Type::Percentage; }
|
||||||
bool is_auto() const { return m_type == Type::Auto; }
|
bool is_auto() const { return m_type == Type::Auto; }
|
||||||
bool is_absolute() const { return m_type == Type::Px; }
|
bool is_absolute() const { return m_type == Type::Px || m_type == Type::Pt; }
|
||||||
bool is_relative() const { return m_type == Type::Em || m_type == Type::Rem; }
|
bool is_relative() const { return m_type == Type::Em || m_type == Type::Rem; }
|
||||||
|
|
||||||
float raw_value() const { return m_value; }
|
float raw_value() const { return m_value; }
|
||||||
|
@ -95,6 +96,8 @@ public:
|
||||||
return 0;
|
return 0;
|
||||||
case Type::Px:
|
case Type::Px:
|
||||||
return m_value;
|
return m_value;
|
||||||
|
case Type::Pt:
|
||||||
|
return m_value * 1.33333333f;
|
||||||
case Type::Undefined:
|
case Type::Undefined:
|
||||||
case Type::Percentage:
|
case Type::Percentage:
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -264,28 +264,6 @@ static Optional<float> try_parse_float(const StringView& string)
|
||||||
return is_negative ? -value : value;
|
return is_negative ? -value : value;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Optional<float> parse_number(const CSS::ParsingContext& context, const StringView& view)
|
|
||||||
{
|
|
||||||
if (view.ends_with('%'))
|
|
||||||
return parse_number(context, view.substring_view(0, view.length() - 1));
|
|
||||||
|
|
||||||
// FIXME: Maybe we should have "ends_with_ignoring_case()" ?
|
|
||||||
if (view.to_string().to_lowercase().ends_with("px"))
|
|
||||||
return parse_number(context, view.substring_view(0, view.length() - 2));
|
|
||||||
if (view.to_string().to_lowercase().ends_with("rem"))
|
|
||||||
return parse_number(context, view.substring_view(0, view.length() - 3));
|
|
||||||
if (view.to_string().to_lowercase().ends_with("em"))
|
|
||||||
return parse_number(context, view.substring_view(0, view.length() - 2));
|
|
||||||
if (view == "0")
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
// NOTE: We don't allow things like "width: 100" in standards mode.
|
|
||||||
if (!context.in_quirks_mode())
|
|
||||||
return {};
|
|
||||||
|
|
||||||
return try_parse_float(view);
|
|
||||||
}
|
|
||||||
|
|
||||||
static Length parse_length(const CSS::ParsingContext& context, const StringView& view, bool& is_bad_length)
|
static Length parse_length(const CSS::ParsingContext& context, const StringView& view, bool& is_bad_length)
|
||||||
{
|
{
|
||||||
Length::Type type = Length::Type::Undefined;
|
Length::Type type = Length::Type::Undefined;
|
||||||
|
@ -297,6 +275,9 @@ static Length parse_length(const CSS::ParsingContext& context, const StringView&
|
||||||
} else if (view.to_string().to_lowercase().ends_with("px")) {
|
} else if (view.to_string().to_lowercase().ends_with("px")) {
|
||||||
type = Length::Type::Px;
|
type = Length::Type::Px;
|
||||||
value = try_parse_float(view.substring_view(0, view.length() - 2));
|
value = try_parse_float(view.substring_view(0, view.length() - 2));
|
||||||
|
} else if (view.to_string().to_lowercase().ends_with("pt")) {
|
||||||
|
type = Length::Type::Pt;
|
||||||
|
value = try_parse_float(view.substring_view(0, view.length() - 2));
|
||||||
} else if (view.to_string().to_lowercase().ends_with("rem")) {
|
} else if (view.to_string().to_lowercase().ends_with("rem")) {
|
||||||
type = Length::Type::Rem;
|
type = Length::Type::Rem;
|
||||||
value = try_parse_float(view.substring_view(0, view.length() - 3));
|
value = try_parse_float(view.substring_view(0, view.length() - 3));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue