diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Dimension.h b/Userland/Libraries/LibWeb/CSS/Parser/Dimension.h new file mode 100644 index 0000000000..70e0da572b --- /dev/null +++ b/Userland/Libraries/LibWeb/CSS/Parser/Dimension.h @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2022-2023, Sam Atkins + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace Web::CSS::Parser { + +class Dimension { +public: + Dimension(Angle&& value) + : m_value(move(value)) + { + } + + Dimension(Frequency&& value) + : m_value(move(value)) + { + } + + Dimension(Length&& value) + : m_value(move(value)) + { + } + Dimension(Percentage&& value) + : m_value(move(value)) + { + } + + Dimension(Resolution&& value) + : m_value(move(value)) + { + } + + Dimension(Time&& value) + : m_value(move(value)) + { + } + + bool is_angle() const { return m_value.has(); } + Angle angle() const { return m_value.get(); } + + bool is_angle_percentage() const { return is_angle() || is_percentage(); } + AnglePercentage angle_percentage() const + { + if (is_angle()) + return angle(); + return percentage(); + } + + bool is_frequency() const { return m_value.has(); } + Frequency frequency() const { return m_value.get(); } + + bool is_frequency_percentage() const { return is_frequency() || is_percentage(); } + FrequencyPercentage frequency_percentage() const + { + if (is_frequency()) + return frequency(); + return percentage(); + } + + bool is_length() const { return m_value.has(); } + Length length() const { return m_value.get(); } + + bool is_length_percentage() const { return is_length() || is_percentage(); } + LengthPercentage length_percentage() const + { + if (is_length()) + return length(); + return percentage(); + } + + bool is_percentage() const { return m_value.has(); } + Percentage percentage() const { return m_value.get(); } + + bool is_resolution() const { return m_value.has(); } + Resolution resolution() const { return m_value.get(); } + + bool is_time() const { return m_value.has