1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 15:38:10 +00:00

LibWeb: Add flex-grow and flex-shrink

They get parsed and are available to the programmer of Layouts :^)
This commit is contained in:
Tobias Christiansen 2021-05-30 20:22:25 +02:00 committed by Ali Mohammad Pur
parent af4d80af4d
commit ae61e9ded2
5 changed files with 46 additions and 1 deletions

View file

@ -4,6 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/TypeCasts.h>
#include <LibCore/DirIterator.h>
#include <LibGfx/FontDatabase.h>
#include <LibWeb/CSS/StyleProperties.h>
@ -272,6 +273,32 @@ Optional<CSS::FlexBasisData> StyleProperties::flex_basis() const
return {};
}
Optional<float> StyleProperties::flex_grow_factor() const
{
auto value = property(CSS::PropertyID::FlexGrow);
if (!value.has_value())
return {};
if (value.value()->is_length() && downcast<CSS::LengthStyleValue>(value.value().ptr())->to_length().raw_value() == 0)
return { 0 };
if (!value.value()->is_numeric())
return {};
auto numeric = downcast<CSS::NumericStyleValue>(value.value().ptr());
return numeric->value();
}
Optional<float> StyleProperties::flex_shrink_factor() const
{
auto value = property(CSS::PropertyID::FlexShrink);
if (!value.has_value())
return {};
if (value.value()->is_length() && downcast<CSS::LengthStyleValue>(value.value().ptr())->to_length().raw_value() == 0)
return { 0 };
if (!value.value()->is_numeric())
return {};
auto numeric = downcast<CSS::NumericStyleValue>(value.value().ptr());
return numeric->value();
}
Optional<CSS::Position> StyleProperties::position() const
{
auto value = property(CSS::PropertyID::Position);
@ -694,5 +721,4 @@ Optional<CSS::Repeat> StyleProperties::background_repeat_y() const
return {};
}
}
}