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

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

Issue 876433002: Remove even more @keyframes related code. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 11 months 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/StyleKeyframe.h ('k') | sky/engine/core/css/StyleRule.h » ('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/StyleKeyframe.h"
28
29 #include "sky/engine/core/css/StylePropertySet.h"
30 #include "sky/engine/core/css/parser/BisonCSSParser.h"
31 #include "sky/engine/wtf/text/StringBuilder.h"
32
33 namespace blink {
34
35 StyleKeyframe::StyleKeyframe()
36 {
37 }
38
39 StyleKeyframe::~StyleKeyframe()
40 {
41 }
42
43 String StyleKeyframe::keyText() const
44 {
45 if (m_keyText.isNull()) {
46 // Keys are always set when these objects are created.
47 ASSERT(m_keys && !m_keys->isEmpty());
48 StringBuilder keyText;
49 for (unsigned i = 0; i < m_keys->size(); ++i) {
50 if (i)
51 keyText.append(',');
52 keyText.append(String::number(m_keys->at(i) * 100));
53 keyText.append('%');
54 }
55 m_keyText = keyText.toString();
56 }
57 ASSERT(!m_keyText.isNull());
58 return m_keyText;
59 }
60
61 void StyleKeyframe::setKeyText(const String& keyText)
62 {
63 // FIXME: Should we trim whitespace?
64 // FIXME: Should we leave keyText unchanged when attempting to set to an
65 // invalid string?
66 ASSERT(!keyText.isNull());
67 m_keyText = keyText;
68 m_keys.clear();
69 }
70
71 const Vector<double>& StyleKeyframe::keys() const
72 {
73 if (!m_keys) {
74 // Keys can only be cleared by setting the key text from JavaScript
75 // and this can never be null.
76 ASSERT(!m_keyText.isNull());
77 m_keys = BisonCSSParser(strictCSSParserContext()).parseKeyframeKeyList(m _keyText);
78 }
79 // If an invalid key string was set, m_keys may be empty.
80 ASSERT(m_keys);
81 return *m_keys;
82 }
83
84 void StyleKeyframe::setKeys(PassOwnPtr<Vector<double> > keys)
85 {
86 ASSERT(keys && !keys->isEmpty());
87 m_keys = keys;
88 m_keyText = String();
89 ASSERT(m_keyText.isNull());
90 }
91
92 void StyleKeyframe::setProperties(PassRefPtr<StylePropertySet> properties)
93 {
94 ASSERT(properties);
95 m_properties = properties;
96 }
97
98 String StyleKeyframe::cssText() const
99 {
100 StringBuilder result;
101 result.append(keyText());
102 result.appendLiteral(" { ");
103 String decls = m_properties->asText();
104 result.append(decls);
105 if (!decls.isEmpty())
106 result.append(' ');
107 result.append('}');
108 return result.toString();
109 }
110
111 PassOwnPtr<Vector<double> > StyleKeyframe::createKeyList(CSSParserValueList* key s)
112 {
113 OwnPtr<Vector<double> > keyVector = adoptPtr(new Vector<double>(keys->size() ));
114 for (unsigned i = 0; i < keys->size(); ++i) {
115 ASSERT(keys->valueAt(i)->unit == blink::CSSPrimitiveValue::CSS_NUMBER);
116 double key = keys->valueAt(i)->fValue;
117 if (key < 0 || key > 100) {
118 // As per http://www.w3.org/TR/css3-animations/#keyframes,
119 // "If a keyframe selector specifies negative percentage values
120 // or values higher than 100%, then the keyframe will be ignored."
121 keyVector->clear();
122 break;
123 }
124 keyVector->at(i) = key / 100;
125 }
126 return keyVector.release();
127 }
128
129 } // namespace blink
OLDNEW
« no previous file with comments | « sky/engine/core/css/StyleKeyframe.h ('k') | sky/engine/core/css/StyleRule.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698