Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(321)

Side by Side Diff: sky/engine/core/css/CSSKeyframesRule.cpp

Issue 780483002: Remove the CSSOM. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sky/engine/core/css/CSSKeyframesRule.h ('k') | sky/engine/core/css/CSSKeyframesRule.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2007, 2008, 2012 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 COMPUTER, 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 COMPUTER, 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 #include "sky/engine/config.h"
27 #include "sky/engine/core/css/CSSKeyframesRule.h"
28
29 #include "sky/engine/core/css/CSSKeyframeRule.h"
30 #include "sky/engine/core/css/CSSRuleList.h"
31 #include "sky/engine/core/css/CSSStyleSheet.h"
32 #include "sky/engine/core/css/parser/BisonCSSParser.h"
33 #include "sky/engine/core/frame/UseCounter.h"
34 #include "sky/engine/wtf/text/StringBuilder.h"
35
36 namespace blink {
37
38 StyleRuleKeyframes::StyleRuleKeyframes()
39 : StyleRuleBase(Keyframes)
40 {
41 }
42
43 StyleRuleKeyframes::StyleRuleKeyframes(const StyleRuleKeyframes& o)
44 : StyleRuleBase(o)
45 , m_keyframes(o.m_keyframes)
46 , m_name(o.m_name)
47 , m_isPrefixed(o.m_isPrefixed)
48 {
49 }
50
51 StyleRuleKeyframes::~StyleRuleKeyframes()
52 {
53 }
54
55 void StyleRuleKeyframes::parserAppendKeyframe(PassRefPtr<StyleKeyframe> keyframe )
56 {
57 if (!keyframe)
58 return;
59 m_keyframes.append(keyframe);
60 }
61
62 void StyleRuleKeyframes::wrapperAppendKeyframe(PassRefPtr<StyleKeyframe> keyfram e)
63 {
64 m_keyframes.append(keyframe);
65 }
66
67 void StyleRuleKeyframes::wrapperRemoveKeyframe(unsigned index)
68 {
69 m_keyframes.remove(index);
70 }
71
72 int StyleRuleKeyframes::findKeyframeIndex(const String& key) const
73 {
74 String percentageString;
75 if (equalIgnoringCase(key, "from"))
76 percentageString = "0%";
77 else if (equalIgnoringCase(key, "to"))
78 percentageString = "100%";
79 else
80 percentageString = key;
81
82 for (unsigned i = 0; i < m_keyframes.size(); ++i) {
83 if (m_keyframes[i]->keyText() == percentageString)
84 return i;
85 }
86 return -1;
87 }
88
89 CSSKeyframesRule::CSSKeyframesRule(StyleRuleKeyframes* keyframesRule, CSSStyleSh eet* parent)
90 : CSSRule(parent)
91 , m_keyframesRule(keyframesRule)
92 , m_childRuleCSSOMWrappers(keyframesRule->keyframes().size())
93 , m_isPrefixed(keyframesRule->isVendorPrefixed())
94 {
95 }
96
97 CSSKeyframesRule::~CSSKeyframesRule()
98 {
99 #if !ENABLE(OILPAN)
100 ASSERT(m_childRuleCSSOMWrappers.size() == m_keyframesRule->keyframes().size( ));
101 for (unsigned i = 0; i < m_childRuleCSSOMWrappers.size(); ++i) {
102 if (m_childRuleCSSOMWrappers[i])
103 m_childRuleCSSOMWrappers[i]->setParentRule(0);
104 }
105 #endif
106 }
107
108 void CSSKeyframesRule::setName(const String& name)
109 {
110 CSSStyleSheet::RuleMutationScope mutationScope(this);
111
112 m_keyframesRule->setName(name);
113 }
114
115 void CSSKeyframesRule::insertRule(const String& ruleText)
116 {
117 ASSERT(m_childRuleCSSOMWrappers.size() == m_keyframesRule->keyframes().size( ));
118
119 CSSStyleSheet* styleSheet = parentStyleSheet();
120 CSSParserContext context(parserContext(), UseCounter::getFrom(styleSheet));
121 BisonCSSParser parser(context);
122 RefPtr<StyleKeyframe> keyframe = parser.parseKeyframeRule(styleSheet ? style Sheet->contents() : 0, ruleText);
123 if (!keyframe)
124 return;
125
126 CSSStyleSheet::RuleMutationScope mutationScope(this);
127
128 m_keyframesRule->wrapperAppendKeyframe(keyframe);
129
130 m_childRuleCSSOMWrappers.grow(length());
131 }
132
133 void CSSKeyframesRule::deleteRule(const String& s)
134 {
135 ASSERT(m_childRuleCSSOMWrappers.size() == m_keyframesRule->keyframes().size( ));
136
137 int i = m_keyframesRule->findKeyframeIndex(s);
138 if (i < 0)
139 return;
140
141 CSSStyleSheet::RuleMutationScope mutationScope(this);
142
143 m_keyframesRule->wrapperRemoveKeyframe(i);
144
145 if (m_childRuleCSSOMWrappers[i])
146 m_childRuleCSSOMWrappers[i]->setParentRule(0);
147 m_childRuleCSSOMWrappers.remove(i);
148 }
149
150 CSSKeyframeRule* CSSKeyframesRule::findRule(const String& s)
151 {
152 int i = m_keyframesRule->findKeyframeIndex(s);
153 return (i >= 0) ? item(i) : 0;
154 }
155
156 String CSSKeyframesRule::cssText() const
157 {
158 StringBuilder result;
159 if (isVendorPrefixed())
160 result.appendLiteral("@-webkit-keyframes ");
161 else
162 result.appendLiteral("@keyframes ");
163 result.append(name());
164 result.appendLiteral(" { \n");
165
166 unsigned size = length();
167 for (unsigned i = 0; i < size; ++i) {
168 result.appendLiteral(" ");
169 result.append(m_keyframesRule->keyframes()[i]->cssText());
170 result.append('\n');
171 }
172 result.append('}');
173 return result.toString();
174 }
175
176 unsigned CSSKeyframesRule::length() const
177 {
178 return m_keyframesRule->keyframes().size();
179 }
180
181 CSSKeyframeRule* CSSKeyframesRule::item(unsigned index) const
182 {
183 if (index >= length())
184 return 0;
185
186 ASSERT(m_childRuleCSSOMWrappers.size() == m_keyframesRule->keyframes().size( ));
187 RefPtr<CSSKeyframeRule>& rule = m_childRuleCSSOMWrappers[index];
188 if (!rule)
189 rule = adoptRef(new CSSKeyframeRule(m_keyframesRule->keyframes()[index]. get(), const_cast<CSSKeyframesRule*>(this)));
190
191 return rule.get();
192 }
193
194 CSSRuleList* CSSKeyframesRule::cssRules()
195 {
196 if (!m_ruleListCSSOMWrapper)
197 m_ruleListCSSOMWrapper = LiveCSSRuleList<CSSKeyframesRule>::create(this) ;
198 return m_ruleListCSSOMWrapper.get();
199 }
200
201 void CSSKeyframesRule::reattach(StyleRuleBase* rule)
202 {
203 ASSERT(rule);
204 m_keyframesRule = toStyleRuleKeyframes(rule);
205 }
206
207 } // namespace blink
OLDNEW
« no previous file with comments | « sky/engine/core/css/CSSKeyframesRule.h ('k') | sky/engine/core/css/CSSKeyframesRule.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698