mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-01 05:39:11 +00:00
LibWeb: Parse CSS fit-content(<length-percentage>) values
Before this change, we only parsed fit-content as a standalone keyword, but CSS-SIZING-3 added it as a function as well. I don't know of anything else in CSS that is overloaded like this, so it ends up looking a little awkward in the implementation. Note that a lot of code had already been prepped for fit-content values to have an argument, we just weren't parsing it.
This commit is contained in:
parent
6fc19ec059
commit
8ab61843be
Notes:
github-actions[bot]
2025-02-26 23:45:14 +00:00
Author: https://github.com/awesomekling
Commit: 8ab61843be
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3706
Reviewed-by: https://github.com/AtkinsSJ
25 changed files with 185 additions and 67 deletions
52
Libraries/LibWeb/CSS/StyleValues/FitContentStyleValue.h
Normal file
52
Libraries/LibWeb/CSS/StyleValues/FitContentStyleValue.h
Normal file
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* Copyright (c) 2025, Andreas Kling <andreas@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <LibWeb/CSS/CSSStyleValue.h>
|
||||
#include <LibWeb/CSS/PercentageOr.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
||||
class FitContentStyleValue final : public CSSStyleValue {
|
||||
public:
|
||||
static ValueComparingNonnullRefPtr<FitContentStyleValue> create()
|
||||
{
|
||||
return adopt_ref(*new (nothrow) FitContentStyleValue(LengthPercentage { Length::make_auto() }));
|
||||
}
|
||||
static ValueComparingNonnullRefPtr<FitContentStyleValue> create(LengthPercentage length_percentage)
|
||||
{
|
||||
return adopt_ref(*new (nothrow) FitContentStyleValue(move(length_percentage)));
|
||||
}
|
||||
virtual ~FitContentStyleValue() override = default;
|
||||
|
||||
virtual String to_string(SerializationMode) const override
|
||||
{
|
||||
if (m_length_percentage.is_auto())
|
||||
return "fit-content"_string;
|
||||
return MUST(String::formatted("fit-content({})", m_length_percentage.to_string()));
|
||||
}
|
||||
|
||||
bool equals(CSSStyleValue const& other) const override
|
||||
{
|
||||
if (type() != other.type())
|
||||
return false;
|
||||
return m_length_percentage == other.as_fit_content().m_length_percentage;
|
||||
}
|
||||
|
||||
[[nodiscard]] LengthPercentage const& length_percentage() const { return m_length_percentage; }
|
||||
|
||||
private:
|
||||
FitContentStyleValue(LengthPercentage length_percentage)
|
||||
: CSSStyleValue(Type::FitContent)
|
||||
, m_length_percentage(move(length_percentage))
|
||||
{
|
||||
}
|
||||
|
||||
LengthPercentage m_length_percentage;
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue