LibWeb: Add Flex::from_style_value method
This commit is contained in:
parent
5807d201b7
commit
06b22d620d
2 changed files with 15 additions and 0 deletions
|
|
@ -7,6 +7,8 @@
|
|||
#include <LibWeb/CSS/Flex.h>
|
||||
#include <LibWeb/CSS/Percentage.h>
|
||||
#include <LibWeb/CSS/Serialize.h>
|
||||
#include <LibWeb/CSS/StyleValues/CalculatedStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/FlexStyleValue.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
||||
|
|
@ -21,6 +23,17 @@ Flex Flex::make_fr(double value)
|
|||
return { value, FlexUnit::Fr };
|
||||
}
|
||||
|
||||
Flex Flex::from_style_value(NonnullRefPtr<StyleValue const> const& value)
|
||||
{
|
||||
if (value->is_flex())
|
||||
return value->as_flex().flex();
|
||||
|
||||
if (value->is_calculated())
|
||||
return value->as_calculated().resolve_flex({}).value();
|
||||
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
Flex Flex::percentage_of(Percentage const& percentage) const
|
||||
{
|
||||
return Flex { percentage.as_fraction() * m_value, m_unit };
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ class Flex {
|
|||
public:
|
||||
Flex(double value, FlexUnit unit);
|
||||
static Flex make_fr(double);
|
||||
static Flex from_style_value(NonnullRefPtr<StyleValue const> const&);
|
||||
|
||||
Flex percentage_of(Percentage const&) const;
|
||||
|
||||
void serialize(StringBuilder&, SerializationMode = SerializationMode::Normal) const;
|
||||
|
|
|
|||
Loading…
Reference in a new issue