mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 21:37:35 +00:00
LibWeb: Introduce and parse CSS Ratio type
This is only used by media-queries, so for now we can skip adding/parsing a StyleValue for these.
This commit is contained in:
parent
e30bfabbca
commit
5f93f1c161
5 changed files with 99 additions and 0 deletions
35
Userland/Libraries/LibWeb/CSS/Ratio.cpp
Normal file
35
Userland/Libraries/LibWeb/CSS/Ratio.cpp
Normal file
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "Ratio.h"
|
||||
#include <math.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
||||
Ratio::Ratio(float first, float second)
|
||||
: m_first_value(first)
|
||||
, m_second_value(second)
|
||||
{
|
||||
}
|
||||
|
||||
// https://www.w3.org/TR/css-values-4/#degenerate-ratio
|
||||
bool Ratio::is_degenerate() const
|
||||
{
|
||||
return !isfinite(m_first_value) || m_first_value == 0
|
||||
|| !isfinite(m_second_value) || m_second_value == 0;
|
||||
}
|
||||
|
||||
String Ratio::to_string() const
|
||||
{
|
||||
return String::formatted("{} / {}", m_first_value, m_second_value);
|
||||
}
|
||||
|
||||
auto Ratio::operator<=>(const Ratio& other) const
|
||||
{
|
||||
return value() - other.value();
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue