mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 20:37:35 +00:00
LibWeb: Teach CSS::StyleProperties to create CSS::Size values
You can now use StyleProperties::size_value(CSS::PropertyID) to extract a CSS::Size for a given property.
This commit is contained in:
parent
ba78fe008f
commit
844321d89f
3 changed files with 40 additions and 1 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2018-2022, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2021-2022, Sam Atkins <atkinssj@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
|
@ -44,6 +44,42 @@ NonnullRefPtr<StyleValue> StyleProperties::property(CSS::PropertyID property_id)
|
|||
return value.release_nonnull();
|
||||
}
|
||||
|
||||
CSS::Size StyleProperties::size_value(CSS::PropertyID id) const
|
||||
{
|
||||
auto value = property(id);
|
||||
if (value->is_identifier()) {
|
||||
switch (value->to_identifier()) {
|
||||
case ValueID::Auto:
|
||||
return CSS::Size::make_auto();
|
||||
case ValueID::MinContent:
|
||||
return CSS::Size::make_min_content();
|
||||
case ValueID::MaxContent:
|
||||
return CSS::Size::make_max_content();
|
||||
case ValueID::None:
|
||||
return CSS::Size::make_none();
|
||||
default:
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
}
|
||||
|
||||
if (value->is_calculated())
|
||||
return CSS::Size::make_length(CSS::Length::make_calculated(value->as_calculated()));
|
||||
|
||||
if (value->is_percentage())
|
||||
return CSS::Size::make_percentage(value->as_percentage().percentage());
|
||||
|
||||
if (value->has_length()) {
|
||||
auto length = value->to_length();
|
||||
if (length.is_auto())
|
||||
return CSS::Size::make_auto();
|
||||
return CSS::Size::make_length(value->to_length());
|
||||
}
|
||||
|
||||
// FIXME: Support `fit-content(<length>)`
|
||||
dbgln("FIXME: Unsupported size value: `{}`, treating as `auto`", value->to_string());
|
||||
return CSS::Size::make_auto();
|
||||
}
|
||||
|
||||
Length StyleProperties::length_or_fallback(CSS::PropertyID id, Length const& fallback) const
|
||||
{
|
||||
auto value = property(id);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue