mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 04:17:34 +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
|
@ -163,8 +163,10 @@
|
||||||
"lowercase",
|
"lowercase",
|
||||||
"ltr",
|
"ltr",
|
||||||
"listbox",
|
"listbox",
|
||||||
|
"max-content",
|
||||||
"medium",
|
"medium",
|
||||||
"middle",
|
"middle",
|
||||||
|
"min-content",
|
||||||
"minimal-ui",
|
"minimal-ui",
|
||||||
"monospace",
|
"monospace",
|
||||||
"more",
|
"more",
|
||||||
|
|
|
@ -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>
|
* Copyright (c) 2021-2022, Sam Atkins <atkinssj@serenityos.org>
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
@ -44,6 +44,42 @@ NonnullRefPtr<StyleValue> StyleProperties::property(CSS::PropertyID property_id)
|
||||||
return value.release_nonnull();
|
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
|
Length StyleProperties::length_or_fallback(CSS::PropertyID id, Length const& fallback) const
|
||||||
{
|
{
|
||||||
auto value = property(id);
|
auto value = property(id);
|
||||||
|
|
|
@ -41,6 +41,7 @@ public:
|
||||||
void set_property(CSS::PropertyID, NonnullRefPtr<StyleValue> value);
|
void set_property(CSS::PropertyID, NonnullRefPtr<StyleValue> value);
|
||||||
NonnullRefPtr<StyleValue> property(CSS::PropertyID) const;
|
NonnullRefPtr<StyleValue> property(CSS::PropertyID) const;
|
||||||
|
|
||||||
|
CSS::Size size_value(CSS::PropertyID) const;
|
||||||
Length length_or_fallback(CSS::PropertyID, Length const& fallback) const;
|
Length length_or_fallback(CSS::PropertyID, Length const& fallback) const;
|
||||||
LengthPercentage length_percentage_or_fallback(CSS::PropertyID, LengthPercentage const& fallback) const;
|
LengthPercentage length_percentage_or_fallback(CSS::PropertyID, LengthPercentage const& fallback) const;
|
||||||
Optional<LengthPercentage> length_percentage(CSS::PropertyID) const;
|
Optional<LengthPercentage> length_percentage(CSS::PropertyID) const;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue