1 | /*
|
---|
2 | * Copyright (C) 2007, 2008, 2012, 2014 Apple Inc. All rights reserved.
|
---|
3 | *
|
---|
4 | * Redistribution and use in source and binary forms, with or without
|
---|
5 | * modification, are permitted provided that the following conditions
|
---|
6 | * are met:
|
---|
7 | * 1. Redistributions of source code must retain the above copyright
|
---|
8 | * notice, this list of conditions and the following disclaimer.
|
---|
9 | * 2. Redistributions in binary form must reproduce the above copyright
|
---|
10 | * notice, this list of conditions and the following disclaimer in the
|
---|
11 | * documentation and/or other materials provided with the distribution.
|
---|
12 | *
|
---|
13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
|
---|
14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
---|
15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
---|
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
|
---|
17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
---|
18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
---|
19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
---|
20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
---|
21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
---|
23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
24 | */
|
---|
25 |
|
---|
26 | #pragma once
|
---|
27 |
|
---|
28 | #include "CSSRule.h"
|
---|
29 | #include "StyleRule.h"
|
---|
30 | #include <memory>
|
---|
31 | #include <wtf/Forward.h>
|
---|
32 | #include <wtf/text/AtomString.h>
|
---|
33 |
|
---|
34 | namespace WebCore {
|
---|
35 |
|
---|
36 | class CSSKeyframeRule;
|
---|
37 | class CSSRuleList;
|
---|
38 | class StyleRuleKeyframe;
|
---|
39 |
|
---|
40 | class StyleRuleKeyframes final : public StyleRuleBase {
|
---|
41 | public:
|
---|
42 | static Ref<StyleRuleKeyframes> create(const AtomString& name);
|
---|
43 | ~StyleRuleKeyframes();
|
---|
44 |
|
---|
45 | const Vector<Ref<StyleRuleKeyframe>>& keyframes() const;
|
---|
46 |
|
---|
47 | void parserAppendKeyframe(RefPtr<StyleRuleKeyframe>&&);
|
---|
48 | void wrapperAppendKeyframe(Ref<StyleRuleKeyframe>&&);
|
---|
49 | void wrapperRemoveKeyframe(unsigned);
|
---|
50 |
|
---|
51 | const AtomString& name() const { return m_name; }
|
---|
52 | void setName(const AtomString& name) { m_name = name; }
|
---|
53 |
|
---|
54 | std::optional<size_t> findKeyframeIndex(const String& key) const;
|
---|
55 |
|
---|
56 | Ref<StyleRuleKeyframes> copy() const { return adoptRef(*new StyleRuleKeyframes(*this)); }
|
---|
57 |
|
---|
58 | void shrinkToFit();
|
---|
59 |
|
---|
60 | private:
|
---|
61 | explicit StyleRuleKeyframes(const AtomString&);
|
---|
62 | StyleRuleKeyframes(const StyleRuleKeyframes&);
|
---|
63 |
|
---|
64 | mutable Vector<Ref<StyleRuleKeyframe>> m_keyframes;
|
---|
65 | AtomString m_name;
|
---|
66 | };
|
---|
67 |
|
---|
68 | class CSSKeyframesRule final : public CSSRule {
|
---|
69 | public:
|
---|
70 | static Ref<CSSKeyframesRule> create(StyleRuleKeyframes& rule, CSSStyleSheet* sheet) { return adoptRef(*new CSSKeyframesRule(rule, sheet)); }
|
---|
71 |
|
---|
72 | virtual ~CSSKeyframesRule();
|
---|
73 |
|
---|
74 | StyleRuleType styleRuleType() const final { return StyleRuleType::Keyframes; }
|
---|
75 | String cssText() const final;
|
---|
76 | void reattach(StyleRuleBase&) final;
|
---|
77 |
|
---|
78 | const AtomString& name() const { return m_keyframesRule->name(); }
|
---|
79 | void setName(const AtomString&);
|
---|
80 |
|
---|
81 | CSSRuleList& cssRules();
|
---|
82 |
|
---|
83 | void insertRule(const String& rule);
|
---|
84 | void appendRule(const String& rule);
|
---|
85 | void deleteRule(const String& key);
|
---|
86 | CSSKeyframeRule* findRule(const String& key);
|
---|
87 |
|
---|
88 | // For IndexedGetter and CSSRuleList.
|
---|
89 | unsigned length() const;
|
---|
90 | CSSKeyframeRule* item(unsigned index) const;
|
---|
91 |
|
---|
92 | private:
|
---|
93 | CSSKeyframesRule(StyleRuleKeyframes&, CSSStyleSheet* parent);
|
---|
94 |
|
---|
95 | Ref<StyleRuleKeyframes> m_keyframesRule;
|
---|
96 | mutable Vector<RefPtr<CSSKeyframeRule>> m_childRuleCSSOMWrappers;
|
---|
97 | mutable std::unique_ptr<CSSRuleList> m_ruleListCSSOMWrapper;
|
---|
98 | };
|
---|
99 |
|
---|
100 | } // namespace WebCore
|
---|
101 |
|
---|
102 | SPECIALIZE_TYPE_TRAITS_CSS_RULE(CSSKeyframesRule, StyleRuleType::Keyframes)
|
---|
103 |
|
---|
104 | SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::StyleRuleKeyframes)
|
---|
105 | static bool isType(const WebCore::StyleRuleBase& rule) { return rule.isKeyframesRule(); }
|
---|
106 | SPECIALIZE_TYPE_TRAITS_END()
|
---|