mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-19 16:59:47 +00:00
LibWeb/CSS: Merge MediaFeature data members
A MediaFeature either has a MediaFeatureValue, or a Range, or nothing. Combining these into a Variant reduces the size from 176 bytes to 128, and also makes constructing these a little less awkward.
This commit is contained in:
parent
0f5e054f97
commit
e125ab360e
Notes:
github-actions[bot]
2025-03-17 10:01:36 +00:00
Author: https://github.com/AtkinsSJ
Commit: e125ab360e
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3941
2 changed files with 42 additions and 39 deletions
|
@ -127,25 +127,23 @@ public:
|
|||
// Corresponds to `<mf-range>` grammar, with a single comparison
|
||||
static NonnullOwnPtr<MediaFeature> half_range(MediaFeatureValue value, Comparison comparison, MediaFeatureID id)
|
||||
{
|
||||
auto feature = adopt_own(*new MediaFeature(Type::Range, id));
|
||||
feature->m_range = Range {
|
||||
.left_value = move(value),
|
||||
.left_comparison = comparison,
|
||||
};
|
||||
return feature;
|
||||
return adopt_own(*new MediaFeature(Type::Range, id,
|
||||
Range {
|
||||
.left_value = move(value),
|
||||
.left_comparison = comparison,
|
||||
}));
|
||||
}
|
||||
|
||||
// Corresponds to `<mf-range>` grammar, with two comparisons
|
||||
static NonnullOwnPtr<MediaFeature> range(MediaFeatureValue left_value, Comparison left_comparison, MediaFeatureID id, Comparison right_comparison, MediaFeatureValue right_value)
|
||||
{
|
||||
auto feature = adopt_own(*new MediaFeature(Type::Range, id));
|
||||
feature->m_range = Range {
|
||||
.left_value = move(left_value),
|
||||
.left_comparison = left_comparison,
|
||||
.right_comparison = right_comparison,
|
||||
.right_value = move(right_value),
|
||||
};
|
||||
return feature;
|
||||
return adopt_own(*new MediaFeature(Type::Range, id,
|
||||
Range {
|
||||
.left_value = move(left_value),
|
||||
.left_comparison = left_comparison,
|
||||
.right_comparison = right_comparison,
|
||||
.right_value = move(right_value),
|
||||
}));
|
||||
}
|
||||
|
||||
virtual MatchResult evaluate(HTML::Window const*) const override;
|
||||
|
@ -161,15 +159,6 @@ private:
|
|||
Range,
|
||||
};
|
||||
|
||||
MediaFeature(Type type, MediaFeatureID id, Optional<MediaFeatureValue> value = {})
|
||||
: m_type(type)
|
||||
, m_id(move(id))
|
||||
, m_value(move(value))
|
||||
{
|
||||
}
|
||||
|
||||
static bool compare(HTML::Window const& window, MediaFeatureValue left, Comparison comparison, MediaFeatureValue right);
|
||||
|
||||
struct Range {
|
||||
MediaFeatureValue left_value;
|
||||
Comparison left_comparison;
|
||||
|
@ -177,10 +166,20 @@ private:
|
|||
Optional<MediaFeatureValue> right_value {};
|
||||
};
|
||||
|
||||
MediaFeature(Type type, MediaFeatureID id, Variant<Empty, MediaFeatureValue, Range> value = {})
|
||||
: m_type(type)
|
||||
, m_id(move(id))
|
||||
, m_value(move(value))
|
||||
{
|
||||
}
|
||||
|
||||
static bool compare(HTML::Window const& window, MediaFeatureValue left, Comparison comparison, MediaFeatureValue right);
|
||||
MediaFeatureValue const& value() const { return m_value.get<MediaFeatureValue>(); }
|
||||
Range const& range() const { return m_value.get<Range>(); }
|
||||
|
||||
Type m_type;
|
||||
MediaFeatureID m_id;
|
||||
Optional<MediaFeatureValue> m_value {};
|
||||
Optional<Range> m_range {};
|
||||
Variant<Empty, MediaFeatureValue, Range> m_value {};
|
||||
};
|
||||
|
||||
class MediaQuery : public RefCounted<MediaQuery> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue