mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-11 02:13:56 +09:00
LibWeb: Add missing Formatters for CSS dimension types
This commit is contained in:
parent
9d0dccaa3f
commit
ef2469bfed
Notes:
sideshowbarker
2024-07-17 08:32:21 +09:00
Author: https://github.com/AtkinsSJ
Commit: ef2469bfed
Pull-request: https://github.com/SerenityOS/serenity/pull/14705
4 changed files with 44 additions and 0 deletions
|
@ -7,6 +7,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/RefPtr.h>
|
#include <AK/RefPtr.h>
|
||||||
|
#include <AK/String.h>
|
||||||
#include <LibWeb/Forward.h>
|
#include <LibWeb/Forward.h>
|
||||||
|
|
||||||
namespace Web::CSS {
|
namespace Web::CSS {
|
||||||
|
@ -55,3 +56,11 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct AK::Formatter<Web::CSS::Angle> : Formatter<StringView> {
|
||||||
|
ErrorOr<void> format(FormatBuilder& builder, Web::CSS::Angle const& angle)
|
||||||
|
{
|
||||||
|
return Formatter<StringView>::format(builder, angle.to_string());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/RefPtr.h>
|
#include <AK/RefPtr.h>
|
||||||
|
#include <AK/String.h>
|
||||||
#include <LibWeb/Forward.h>
|
#include <LibWeb/Forward.h>
|
||||||
|
|
||||||
namespace Web::CSS {
|
namespace Web::CSS {
|
||||||
|
@ -50,4 +51,13 @@ private:
|
||||||
float m_value { 0 };
|
float m_value { 0 };
|
||||||
RefPtr<CalculatedStyleValue> m_calculated_style;
|
RefPtr<CalculatedStyleValue> m_calculated_style;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct AK::Formatter<Web::CSS::Frequency> : Formatter<StringView> {
|
||||||
|
ErrorOr<void> format(FormatBuilder& builder, Web::CSS::Frequency const& frequency)
|
||||||
|
{
|
||||||
|
return Formatter<StringView>::format(builder, frequency.to_string());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <AK/String.h>
|
||||||
#include <AK/Types.h>
|
#include <AK/Types.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
|
@ -68,8 +69,23 @@ public:
|
||||||
return { Type::Number, m_value / other.m_value };
|
return { Type::Number, m_value / other.m_value };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String to_string() const
|
||||||
|
{
|
||||||
|
if (m_type == Type::IntegerWithExplicitSign)
|
||||||
|
return String::formatted("{:+}", m_value);
|
||||||
|
return String::number(m_value);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
float m_value { 0 };
|
float m_value { 0 };
|
||||||
Type m_type;
|
Type m_type;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct AK::Formatter<Web::CSS::Number> : Formatter<StringView> {
|
||||||
|
ErrorOr<void> format(FormatBuilder& builder, Web::CSS::Number const& number)
|
||||||
|
{
|
||||||
|
return Formatter<StringView>::format(builder, number.to_string());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/RefPtr.h>
|
#include <AK/RefPtr.h>
|
||||||
|
#include <AK/String.h>
|
||||||
#include <LibWeb/Forward.h>
|
#include <LibWeb/Forward.h>
|
||||||
|
|
||||||
namespace Web::CSS {
|
namespace Web::CSS {
|
||||||
|
@ -53,3 +54,11 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct AK::Formatter<Web::CSS::Time> : Formatter<StringView> {
|
||||||
|
ErrorOr<void> format(FormatBuilder& builder, Web::CSS::Time const& time)
|
||||||
|
{
|
||||||
|
return Formatter<StringView>::format(builder, time.to_string());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue