| 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/AtomicString.h> |
| 33 | |
| 34 | namespace WebCore { |
| 35 | |
| 36 | class CSSRuleList; |
| 37 | class StyleRuleKeyframe; |
| 38 | class CSSKeyframeRule; |
| 39 | |
| 40 | class StyleRuleKeyframes final : public StyleRuleBase { |
| 41 | public: |
| 42 | static Ref<StyleRuleKeyframes> create(const AtomicString& name) { return adoptRef(*new StyleRuleKeyframes(name)); } |
| 43 | static Ref<StyleRuleKeyframes> create(const AtomicString& name, std::unique_ptr<DeferredStyleGroupRuleList>&& deferredRules) { return adoptRef(*new StyleRuleKeyframes(name, WTFMove(deferredRules))); } |
| 44 | |
| 45 | ~StyleRuleKeyframes(); |
| 46 | |
| 47 | const Vector<Ref<StyleRuleKeyframe>>& keyframes() const; |
| 48 | const Vector<Ref<StyleRuleKeyframe>>* keyframesWithoutDeferredParsing() const |
| 49 | { |
| 50 | return !m_deferredRules ? &m_keyframes : nullptr; |
| 51 | } |
| 52 | |
| 53 | void parserAppendKeyframe(RefPtr<StyleRuleKeyframe>&&); |
| 54 | void wrapperAppendKeyframe(Ref<StyleRuleKeyframe>&&); |
| 55 | void wrapperRemoveKeyframe(unsigned); |
| 56 | |
| 57 | const AtomicString& name() const { return m_name; } |
| 58 | void setName(const AtomicString& name) { m_name = name; } |
| 59 | |
| 60 | size_t findKeyframeIndex(const String& key) const; |
| 61 | |
| 62 | Ref<StyleRuleKeyframes> copy() const { return adoptRef(*new StyleRuleKeyframes(*this)); } |
| 63 | |
| 64 | private: |
| 65 | StyleRuleKeyframes(const AtomicString&); |
| 66 | StyleRuleKeyframes(const AtomicString&, std::unique_ptr<DeferredStyleGroupRuleList>&&); |
| 67 | StyleRuleKeyframes(const StyleRuleKeyframes&); |
| 68 | |
| 69 | void parseDeferredRulesIfNeeded() const; |
| 70 | |
| 71 | mutable Vector<Ref<StyleRuleKeyframe>> m_keyframes; |
| 72 | AtomicString m_name; |
| 73 | |
| 74 | mutable std::unique_ptr<DeferredStyleGroupRuleList> m_deferredRules; |
| 75 | }; |
| 76 | |
| 77 | class CSSKeyframesRule final : public CSSRule { |
| 78 | public: |
| 79 | static Ref<CSSKeyframesRule> create(StyleRuleKeyframes& rule, CSSStyleSheet* sheet) { return adoptRef(*new CSSKeyframesRule(rule, sheet)); } |
| 80 | |
| 81 | virtual ~CSSKeyframesRule(); |
| 82 | |
| 83 | CSSRule::Type type() const final { return KEYFRAMES_RULE; } |
| 84 | String cssText() const final; |
| 85 | void reattach(StyleRuleBase&) final; |
| 86 | |
| 87 | String name() const { return m_keyframesRule->name(); } |
| 88 | void setName(const String&); |
| 89 | |
| 90 | CSSRuleList& cssRules(); |
| 91 | |
| 92 | void insertRule(const String& rule); |
| 93 | void appendRule(const String& rule); |
| 94 | void deleteRule(const String& key); |
| 95 | CSSKeyframeRule* findRule(const String& key); |
| 96 | |
| 97 | // For IndexedGetter and CSSRuleList. |
| 98 | unsigned length() const; |
| 99 | CSSKeyframeRule* item(unsigned index) const; |
| 100 | |
| 101 | private: |
| 102 | CSSKeyframesRule(StyleRuleKeyframes&, CSSStyleSheet* parent); |
| 103 | |
| 104 | Ref<StyleRuleKeyframes> m_keyframesRule; |
| 105 | mutable Vector<RefPtr<CSSKeyframeRule>> m_childRuleCSSOMWrappers; |
| 106 | mutable std::unique_ptr<CSSRuleList> m_ruleListCSSOMWrapper; |
| 107 | }; |
| 108 | |
| 109 | } // namespace WebCore |
| 110 | |
| 111 | SPECIALIZE_TYPE_TRAITS_CSS_RULE(CSSKeyframesRule, CSSRule::KEYFRAMES_RULE) |
| 112 | |
| 113 | SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::StyleRuleKeyframes) |
| 114 | static bool isType(const WebCore::StyleRuleBase& rule) { return rule.isKeyframesRule(); } |
| 115 | SPECIALIZE_TYPE_TRAITS_END() |
| 116 | |