mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-10-16 21:20:18 +00:00
LibWeb/CSS: Use generated FooUnit types instead of Foo::Type
I've also renamed the `m_type` and `type()` members to be `m_unit` and `unit()` instead, to match what they actually are.
This commit is contained in:
parent
bda4f8cbe8
commit
b3e32445d3
Notes:
github-actions[bot]
2025-09-11 16:08:15 +00:00
Author: https://github.com/AtkinsSJ
Commit: b3e32445d3
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6071
29 changed files with 232 additions and 669 deletions
|
@ -10,15 +10,15 @@
|
|||
|
||||
namespace Web::CSS {
|
||||
|
||||
Resolution::Resolution(double value, Type type)
|
||||
: m_type(type)
|
||||
Resolution::Resolution(double value, ResolutionUnit unit)
|
||||
: m_unit(unit)
|
||||
, m_value(value)
|
||||
{
|
||||
}
|
||||
|
||||
Resolution Resolution::make_dots_per_pixel(double value)
|
||||
{
|
||||
return { value, Type::Dppx };
|
||||
return { value, ResolutionUnit::Dppx };
|
||||
}
|
||||
|
||||
String Resolution::to_string(SerializationMode serialization_mode) const
|
||||
|
@ -42,44 +42,16 @@ String Resolution::to_string(SerializationMode serialization_mode) const
|
|||
|
||||
double Resolution::to_dots_per_pixel() const
|
||||
{
|
||||
switch (m_type) {
|
||||
case Type::Dpi:
|
||||
switch (m_unit) {
|
||||
case ResolutionUnit::Dpi:
|
||||
return m_value / 96; // 1in = 2.54cm = 96px
|
||||
case Type::Dpcm:
|
||||
case ResolutionUnit::Dpcm:
|
||||
return m_value / (96.0 / 2.54); // 1cm = 96px/2.54
|
||||
case Type::Dppx:
|
||||
case Type::X:
|
||||
case ResolutionUnit::Dppx:
|
||||
case ResolutionUnit::X:
|
||||
return m_value;
|
||||
}
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
StringView Resolution::unit_name() const
|
||||
{
|
||||
switch (m_type) {
|
||||
case Type::Dpi:
|
||||
return "dpi"sv;
|
||||
case Type::Dpcm:
|
||||
return "dpcm"sv;
|
||||
case Type::Dppx:
|
||||
return "dppx"sv;
|
||||
case Type::X:
|
||||
return "x"sv;
|
||||
}
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
Optional<Resolution::Type> Resolution::unit_from_name(StringView name)
|
||||
{
|
||||
if (name.equals_ignoring_ascii_case("dpi"sv))
|
||||
return Type::Dpi;
|
||||
if (name.equals_ignoring_ascii_case("dpcm"sv))
|
||||
return Type::Dpcm;
|
||||
if (name.equals_ignoring_ascii_case("dppx"sv))
|
||||
return Type::Dppx;
|
||||
if (name.equals_ignoring_ascii_case("x"sv))
|
||||
return Type::X;
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue