blob: 36f5c02f47dd90e29de2e54e85a388b6e7a12f9a [file] [log] [blame]
dino@apple.coma001d322008-08-05 23:01:41 +00001/*
akling@apple.comc713db32012-11-22 03:45:40 +00002 * Copyright (C) 2007, 2008, 2012 Apple Inc. All rights reserved.
dino@apple.coma001d322008-08-05 23:01:41 +00003 *
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
apavlov@chromium.orgf684aec2011-10-19 13:31:03 +000023 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
dino@apple.coma001d322008-08-05 23:01:41 +000024 */
25
26#include "config.h"
27#include "WebKitCSSKeyframeRule.h"
28
antti@apple.com745b7902012-03-31 18:02:35 +000029#include "PropertySetCSSStyleDeclaration.h"
antti@apple.com64288372012-03-29 10:17:19 +000030#include "WebKitCSSKeyframesRule.h"
commit-queue@webkit.org1ac47ab2012-08-24 23:58:43 +000031#include <wtf/text/StringBuilder.h>
dino@apple.coma001d322008-08-05 23:01:41 +000032
33namespace WebCore {
commit-queue@webkit.org42eb4e12012-07-18 15:15:22 +000034
35StylePropertySet* StyleKeyframe::mutableProperties()
36{
37 if (!m_properties->isMutable())
38 m_properties = m_properties->copy();
39 return m_properties.get();
40}
antti@apple.com64288372012-03-29 10:17:19 +000041
42void StyleKeyframe::setProperties(PassRefPtr<StylePropertySet> properties)
dino@apple.coma001d322008-08-05 23:01:41 +000043{
antti@apple.com64288372012-03-29 10:17:19 +000044 m_properties = properties;
dino@apple.coma001d322008-08-05 23:01:41 +000045}
46
47/* static */
antti@apple.com64288372012-03-29 10:17:19 +000048void StyleKeyframe::parseKeyString(const String& s, Vector<float>& keys)
dino@apple.coma001d322008-08-05 23:01:41 +000049{
dino@apple.com9300a0b2008-09-12 00:36:31 +000050 keys.clear();
51 Vector<String> strings;
52 s.split(',', strings);
apavlov@chromium.orgf684aec2011-10-19 13:31:03 +000053
dino@apple.com9300a0b2008-09-12 00:36:31 +000054 for (size_t i = 0; i < strings.size(); ++i) {
55 float key = -1;
56 String cur = strings[i].stripWhiteSpace();
antti@apple.com64288372012-03-29 10:17:19 +000057
dino@apple.com9300a0b2008-09-12 00:36:31 +000058 // For now the syntax MUST be 'xxx%' or 'from' or 'to', where xxx is a legal floating point number
59 if (cur == "from")
60 key = 0;
61 else if (cur == "to")
62 key = 1;
benjamin@webkit.org127cec2c2012-04-30 21:32:44 +000063 else if (cur.endsWith('%')) {
dino@apple.com9300a0b2008-09-12 00:36:31 +000064 float k = cur.substring(0, cur.length() - 1).toFloat();
dino@apple.coma001d322008-08-05 23:01:41 +000065 if (k >= 0 && k <= 100)
dino@apple.com9300a0b2008-09-12 00:36:31 +000066 key = k/100;
dino@apple.coma001d322008-08-05 23:01:41 +000067 }
dino@apple.com9300a0b2008-09-12 00:36:31 +000068 if (key < 0) {
69 keys.clear();
70 return;
71 }
72 else
73 keys.append(key);
dino@apple.coma001d322008-08-05 23:01:41 +000074 }
dino@apple.coma001d322008-08-05 23:01:41 +000075}
76
antti@apple.com64288372012-03-29 10:17:19 +000077String StyleKeyframe::cssText() const
78{
commit-queue@webkit.org1ac47ab2012-08-24 23:58:43 +000079 StringBuilder result;
80 result.append(keyText());
81 result.appendLiteral(" { ");
82 String decls = m_properties->asText();
83 result.append(decls);
84 if (!decls.isEmpty())
85 result.append(' ');
86 result.append('}');
87 return result.toString();
antti@apple.com64288372012-03-29 10:17:19 +000088}
89
yurys@chromium.orgbf5c0752012-08-01 13:29:59 +000090void StyleKeyframe::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
91{
loislo@chromium.org53b3ffd2012-09-05 15:11:06 +000092 MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::CSS);
loislo@chromium.org61a7dd62012-09-17 15:12:21 +000093 info.addMember(m_properties);
94 info.addMember(m_key);
yurys@chromium.orgbf5c0752012-08-01 13:29:59 +000095}
96
antti@apple.com64288372012-03-29 10:17:19 +000097WebKitCSSKeyframeRule::WebKitCSSKeyframeRule(StyleKeyframe* keyframe, WebKitCSSKeyframesRule* parent)
akling@apple.comc713db32012-11-22 03:45:40 +000098 : CSSRule(0)
antti@apple.com64288372012-03-29 10:17:19 +000099 , m_keyframe(keyframe)
100{
101 setParentRule(parent);
102}
103
104WebKitCSSKeyframeRule::~WebKitCSSKeyframeRule()
105{
antti@apple.com745b7902012-03-31 18:02:35 +0000106 if (m_propertiesCSSOMWrapper)
107 m_propertiesCSSOMWrapper->clearParentRule();
antti@apple.com64288372012-03-29 10:17:19 +0000108}
109
antti@apple.com745b7902012-03-31 18:02:35 +0000110CSSStyleDeclaration* WebKitCSSKeyframeRule::style() const
111{
112 if (!m_propertiesCSSOMWrapper)
commit-queue@webkit.org42eb4e12012-07-18 15:15:22 +0000113 m_propertiesCSSOMWrapper = StyleRuleCSSStyleDeclaration::create(m_keyframe->mutableProperties(), const_cast<WebKitCSSKeyframeRule*>(this));
antti@apple.com745b7902012-03-31 18:02:35 +0000114 return m_propertiesCSSOMWrapper.get();
antti@apple.com64288372012-03-29 10:17:19 +0000115}
116
akling@apple.comc713db32012-11-22 03:45:40 +0000117void WebKitCSSKeyframeRule::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
yurys@chromium.org7edf1e42012-08-03 10:18:31 +0000118{
loislo@chromium.org53b3ffd2012-09-05 15:11:06 +0000119 MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::CSS);
akling@apple.comc713db32012-11-22 03:45:40 +0000120 CSSRule::reportMemoryUsage(memoryObjectInfo);
loislo@chromium.org61a7dd62012-09-17 15:12:21 +0000121 info.addMember(m_keyframe);
122 info.addMember(m_propertiesCSSOMWrapper);
yurys@chromium.org7edf1e42012-08-03 10:18:31 +0000123}
124
akling@apple.comc713db32012-11-22 03:45:40 +0000125void WebKitCSSKeyframeRule::reattach(StyleRuleBase*)
126{
127 // No need to reattach, the underlying data is shareable on mutation.
128 ASSERT_NOT_REACHED();
129}
130
dino@apple.coma001d322008-08-05 23:01:41 +0000131} // namespace WebCore