Skip to content

Commit c57975c

Browse files
AtkinsSJtcl3
authored andcommitted
LibWeb: Move and rename CSSStyleValue to StyleValues/StyleValue.{h,cpp}
This reverts 0e3487b. Back when I made that change, I thought we could make our StyleValue classes match the typed-om definitions directly. However, they have different requirements. Typed-om types need to be mutable and GCed, whereas StyleValues are immutable and ideally wouldn't require a JS VM. While I was already making such a cataclysmic change, I've moved it into the StyleValues directory, because it *not* being there has bothered me for a long time. 😅
1 parent 0d8ad0a commit c57975c

File tree

167 files changed

+991
-992
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

167 files changed

+991
-992
lines changed

Documentation/CSSGeneratedFiles.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Each property will have some set of these fields on it:
2525
| `affects-stacking-context` | No | `false` | Boolean. Whether this property can cause a new stacking context for the element. | `bool property_affects_stacking_context(PropertyID)` |
2626
| `animation-type` | Yes | | String. How the property should be animated. Defined by the spec. See below. | `AnimationType animation_type_from_longhand_property(PropertyID)` |
2727
| `inherited` | Yes | | Boolean. Whether the property is inherited by its child elements. | `bool is_inherited_property(PropertyID)` |
28-
| `initial` | Yes | | String. The property's initial value if it is not specified. | `NonnullRefPtr<CSSStyleValue const> property_initial_value(PropertyID)` |
28+
| `initial` | Yes | | String. The property's initial value if it is not specified. | `NonnullRefPtr<StyleValue const> property_initial_value(PropertyID)` |
2929
| `legacy-alias-for` | No | Nothing | String. The name of a property this is an alias for. See below. | |
3030
| `logical-alias-for` | No | Nothing | An object. See below. | `bool property_is_logical_alias(PropertyID);`<br/>`PropertyID map_logical_alias_to_physical_property(PropertyID, LogicalAliasMappingContext const&)` |
3131
| `longhands` | No | `[]` | Array of strings. If this is a shorthand, these are the property names that it expands out into. | `Vector<PropertyID> longhands_for_shorthand(PropertyID)`<br/>`Vector<PropertyID> expanded_longhands_for_shorthand(PropertyID)`<br/>`Vector<PropertyID> shorthands_for_longhand(PropertyID)` |
@@ -129,7 +129,7 @@ The generated code provides:
129129
it exists in that at-rule.
130130
- `FlyString to_string(DescriptorID)` for serializing descriptor names.
131131
- `bool at_rule_supports_descriptor(AtRuleID, DescriptorID)` to query if the given at-rule allows the descriptor.
132-
- `RefPtr<CSSStyleValue const> descriptor_initial_value(AtRuleID, DescriptorID)` for getting a descriptor's initial value.
132+
- `RefPtr<StyleValue const> descriptor_initial_value(AtRuleID, DescriptorID)` for getting a descriptor's initial value.
133133
- `DescriptorMetadata get_descriptor_metadata(AtRuleID, DescriptorID)` returns data used for parsing the descriptor.
134134

135135
### At-rule fields

Documentation/CSSProperties.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ However, there are many CSS properties with more complicated grammar and so they
1818

1919
Property-parsing code goes in `CSS/Parser/PropertyParsing.cpp`, and `CSS/Parser/Parser.h`. First,
2020
`Parser::parse_css_value()` is called, which has a switch for specific properties. Call your method from there. It
21-
should return a `RefPtr` to a `CSSStyleValue` or one of its subclasses.
21+
should return a `RefPtr` to a `StyleValue` or one of its subclasses.
2222

2323
For shorthands, you should normally use `ShorthandStyleValue`, which automatically expands its longhand values. You
2424
might need to modify `ShorthandStyleValue::to_string` if your shorthand has special serialization rules. For example,
@@ -29,7 +29,7 @@ If you need to do this, pester @AtkinsSJ until he gets around to documenting it.
2929

3030
## Computed style
3131

32-
After parsing and style computation, longhand properties are stored as `CSSStyleValue` pointers in
32+
After parsing and style computation, longhand properties are stored as `StyleValue` pointers in
3333
`ComputedProperties`. Any shorthands have been expanded out, and so we do not need to store them directly.
3434

3535
These longhands then need to be converted to a more usable form. To do this, add a getter to `ComputedProperties` with

Documentation/LibWebFromLoadingToPainting.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ The cascade origin determines the processing order for rules. The "user-agent" s
8080

8181
Note: the user-agent style is a built-in CSS style sheet that lives in the LibWeb source code [here](https://github.com/LadybirdBrowser/ladybird/blob/master/Libraries/LibWeb/CSS/Default.css).
8282

83-
The end product of style computation is a fully populated StyleProperties object. It has a CSSStyleValue for each CSS::PropertyID. In spec parlance, these are the *computed* values. (Note that these are not the same as you get from `getComputedStyle()`, that API returns the *resolved* values.)
83+
The end product of style computation is a fully populated StyleProperties object. It has a StyleValue for each CSS::PropertyID. In spec parlance, these are the *computed* values. (Note that these are not the same as you get from `getComputedStyle()`, that API returns the *resolved* values.)
8484

8585
#### Resolving CSS custom properties ("variables")
8686

Libraries/LibWeb/Animations/AnimationEffect.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ WebIDL::ExceptionOr<void> AnimationEffect::update_timing(OptionalEffectTiming ti
158158

159159
// 4. If the easing member of input exists but cannot be parsed using the <easing-function> production
160160
// [CSS-EASING-1], throw a TypeError and abort this procedure.
161-
RefPtr<CSS::CSSStyleValue const> easing_value;
161+
RefPtr<CSS::StyleValue const> easing_value;
162162
if (timing.easing.has_value()) {
163163
easing_value = parse_easing_string(timing.easing.value());
164164
if (!easing_value)
@@ -604,7 +604,7 @@ Optional<double> AnimationEffect::transformed_progress() const
604604
return m_timing_function.evaluate_at(directed_progress.value(), before_flag);
605605
}
606606

607-
RefPtr<CSS::CSSStyleValue const> AnimationEffect::parse_easing_string(StringView value)
607+
RefPtr<CSS::StyleValue const> AnimationEffect::parse_easing_string(StringView value)
608608
{
609609
if (auto style_value = parse_css_value(CSS::Parser::ParsingParams(), value, CSS::PropertyID::AnimationTimingFunction)) {
610610
if (style_value->is_easing())
@@ -631,7 +631,7 @@ void AnimationEffect::visit_edges(JS::Cell::Visitor& visitor)
631631
visitor.visit(m_associated_animation);
632632
}
633633

634-
static CSS::RequiredInvalidationAfterStyleChange compute_required_invalidation_for_animated_properties(HashMap<CSS::PropertyID, NonnullRefPtr<CSS::CSSStyleValue const>> const& old_properties, HashMap<CSS::PropertyID, NonnullRefPtr<CSS::CSSStyleValue const>> const& new_properties)
634+
static CSS::RequiredInvalidationAfterStyleChange compute_required_invalidation_for_animated_properties(HashMap<CSS::PropertyID, NonnullRefPtr<CSS::StyleValue const>> const& old_properties, HashMap<CSS::PropertyID, NonnullRefPtr<CSS::StyleValue const>> const& new_properties)
635635
{
636636
CSS::RequiredInvalidationAfterStyleChange invalidation;
637637
auto old_and_new_properties = MUST(Bitmap::create(to_underlying(CSS::last_property_id) + 1, 0));

Libraries/LibWeb/Animations/AnimationEffect.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Bindings::PlaybackDirection css_animation_direction_to_bindings_playback_directi
6262
// This object lives for the duration of an animation update, and is used to store per-element data about animated CSS properties.
6363
struct AnimationUpdateContext {
6464
struct ElementData {
65-
using PropertyMap = HashMap<CSS::PropertyID, NonnullRefPtr<CSS::CSSStyleValue const>>;
65+
using PropertyMap = HashMap<CSS::PropertyID, NonnullRefPtr<CSS::StyleValue const>>;
6666
PropertyMap animated_properties_before_update;
6767
GC::Ptr<CSS::ComputedProperties> target_style;
6868
};
@@ -79,7 +79,7 @@ class AnimationEffect : public Bindings::PlatformObject {
7979
GC_DECLARE_ALLOCATOR(AnimationEffect);
8080

8181
public:
82-
static RefPtr<CSS::CSSStyleValue const> parse_easing_string(StringView value);
82+
static RefPtr<CSS::StyleValue const> parse_easing_string(StringView value);
8383

8484
EffectTiming get_timing() const;
8585
ComputedEffectTiming get_computed_timing() const;

Libraries/LibWeb/Animations/KeyframeEffect.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ static WebIDL::ExceptionOr<Vector<BaseKeyframe>> process_a_keyframes_argument(JS
563563
if (!easing_value)
564564
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, MUST(String::formatted("Invalid animation easing value: \"{}\"", easing_string)) };
565565

566-
keyframe.easing.set(NonnullRefPtr<CSS::CSSStyleValue const> { *easing_value });
566+
keyframe.easing.set(NonnullRefPtr<CSS::StyleValue const> { *easing_value });
567567
}
568568

569569
// 9. Parse each of the values in unused easings using the CSS syntax defined for easing member of the EffectTiming
@@ -591,7 +591,7 @@ void KeyframeEffect::generate_initial_and_final_frames(RefPtr<KeyFrameSet> keyfr
591591
initial_keyframe = keyframe_set->keyframes_by_key.find(0);
592592
}
593593

594-
auto expanded_properties = [&](HashMap<CSS::PropertyID, Variant<KeyFrameSet::UseInitial, NonnullRefPtr<CSS::CSSStyleValue const>>>& properties) {
594+
auto expanded_properties = [&](HashMap<CSS::PropertyID, Variant<KeyFrameSet::UseInitial, NonnullRefPtr<CSS::StyleValue const>>>& properties) {
595595
HashTable<CSS::PropertyID> result;
596596

597597
for (auto property : properties) {
@@ -827,7 +827,7 @@ WebIDL::ExceptionOr<GC::RootVector<JS::Object*>> KeyframeEffect::get_keyframes()
827827
auto object = JS::Object::create(realm, realm.intrinsics().object_prototype());
828828
TRY(object->set(vm.names.offset, keyframe.offset.has_value() ? JS::Value(keyframe.offset.value()) : JS::js_null(), ShouldThrowExceptions::Yes));
829829
TRY(object->set(vm.names.computedOffset, JS::Value(keyframe.computed_offset.value()), ShouldThrowExceptions::Yes));
830-
auto easing_value = keyframe.easing.get<NonnullRefPtr<CSS::CSSStyleValue const>>();
830+
auto easing_value = keyframe.easing.get<NonnullRefPtr<CSS::StyleValue const>>();
831831
TRY(object->set(vm.names.easing, JS::PrimitiveString::create(vm, easing_value->to_string(CSS::SerializationMode::Normal)), ShouldThrowExceptions::Yes));
832832

833833
if (keyframe.composite == Bindings::CompositeOperationOrAuto::Replace) {
@@ -881,7 +881,7 @@ WebIDL::ExceptionOr<void> KeyframeEffect::set_keyframes(Optional<GC::Root<JS::Ob
881881
property_value = CSS::Parser::Parser::resolve_unresolved_style_value(CSS::Parser::ParsingParams { target->document() }, *target, pseudo_element_type(), property_id, property_value->as_unresolved());
882882

883883
resolved_keyframe.properties.set(property_id, property_value);
884-
CSS::StyleComputer::for_each_property_expanding_shorthands(property_id, property_value, [&](CSS::PropertyID longhand_id, CSS::CSSStyleValue const&) {
884+
CSS::StyleComputer::for_each_property_expanding_shorthands(property_id, property_value, [&](CSS::PropertyID longhand_id, CSS::StyleValue const&) {
885885
m_target_properties.set(longhand_id);
886886
});
887887
}

Libraries/LibWeb/Animations/KeyframeEffect.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
#include <LibWeb/Animations/AnimationEffect.h>
1212
#include <LibWeb/Bindings/KeyframeEffectPrototype.h>
1313
#include <LibWeb/Bindings/PlatformObject.h>
14-
#include <LibWeb/CSS/CSSStyleValue.h>
1514
#include <LibWeb/CSS/PropertyID.h>
1615
#include <LibWeb/CSS/Selector.h>
16+
#include <LibWeb/CSS/StyleValues/StyleValue.h>
1717

1818
namespace Web::Animations {
1919

20-
using EasingValue = Variant<String, NonnullRefPtr<CSS::CSSStyleValue const>>;
20+
using EasingValue = Variant<String, NonnullRefPtr<CSS::StyleValue const>>;
2121

2222
// https://www.w3.org/TR/web-animations-1/#the-keyframeeffectoptions-dictionary
2323
struct KeyframeEffectOptions : public EffectTiming {
@@ -39,7 +39,7 @@ struct BasePropertyIndexedKeyframe {
3939
// https://www.w3.org/TR/web-animations-1/#dictdef-basekeyframe
4040
struct BaseKeyframe {
4141
using UnparsedProperties = HashMap<String, String>;
42-
using ParsedProperties = HashMap<CSS::PropertyID, NonnullRefPtr<CSS::CSSStyleValue const>>;
42+
using ParsedProperties = HashMap<CSS::PropertyID, NonnullRefPtr<CSS::StyleValue const>>;
4343

4444
Optional<double> offset {};
4545
EasingValue easing { "linear"_string };
@@ -64,9 +64,9 @@ class KeyframeEffect : public AnimationEffect {
6464
struct KeyFrameSet : public RefCounted<KeyFrameSet> {
6565
struct UseInitial { };
6666
struct ResolvedKeyFrame {
67-
// These CSSStyleValue properties can be unresolved, as they may be generated from a @keyframes rule, well
67+
// These StyleValue properties can be unresolved, as they may be generated from a @keyframes rule, well
6868
// before they are applied to an element
69-
HashMap<CSS::PropertyID, Variant<UseInitial, NonnullRefPtr<CSS::CSSStyleValue const>>> properties {};
69+
HashMap<CSS::PropertyID, Variant<UseInitial, NonnullRefPtr<CSS::StyleValue const>>> properties {};
7070
};
7171
RedBlackTree<u64, ResolvedKeyFrame> keyframes_by_key;
7272
};

Libraries/LibWeb/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ set(SOURCES
125125
CSS/CSSStyleProperties.cpp
126126
CSS/CSSStyleRule.cpp
127127
CSS/CSSStyleSheet.cpp
128-
CSS/CSSStyleValue.cpp
129128
CSS/CSSSupportsRule.cpp
130129
CSS/CSSTransition.cpp
131130
CSS/Descriptor.cpp
@@ -234,6 +233,7 @@ set(SOURCES
234233
CSS/StyleValues/ScrollbarColorStyleValue.cpp
235234
CSS/StyleValues/ShadowStyleValue.cpp
236235
CSS/StyleValues/ShorthandStyleValue.cpp
236+
CSS/StyleValues/StyleValue.cpp
237237
CSS/StyleValues/StyleValueList.cpp
238238
CSS/StyleValues/TransformationStyleValue.cpp
239239
CSS/StyleValues/TransitionStyleValue.cpp

Libraries/LibWeb/CSS/CSS.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ WebIDL::ExceptionOr<void> register_property(JS::VM& vm, PropertyDefinition defin
8989
return WebIDL::SyntaxError::create(realm, "Invalid syntax definition"_string);
9090
}
9191

92-
RefPtr<CSSStyleValue const> initial_value_maybe;
92+
RefPtr<StyleValue const> initial_value_maybe;
9393

9494
// 4. If syntax definition is the universal syntax definition, and initialValue is not present,
9595
if (maybe_syntax->type() == Parser::SyntaxNode::NodeType::Universal) {

Libraries/LibWeb/CSS/CSSAnimation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
#pragma once
88

99
#include <LibWeb/Animations/Animation.h>
10-
#include <LibWeb/CSS/CSSStyleValue.h>
1110
#include <LibWeb/CSS/PropertyID.h>
11+
#include <LibWeb/CSS/StyleValues/StyleValue.h>
1212

1313
namespace Web::CSS {
1414

0 commit comments

Comments
 (0)