dino@apple.com | a001d32 | 2008-08-05 23:01:41 +0000 | [diff] [blame] | 1 | /* |
akling@apple.com | c713db3 | 2012-11-22 03:45:40 +0000 | [diff] [blame] | 2 | * Copyright (C) 2007, 2008, 2012 Apple Inc. All rights reserved. |
dino@apple.com | a001d32 | 2008-08-05 23:01:41 +0000 | [diff] [blame] | 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 |
apavlov@chromium.org | f684aec | 2011-10-19 13:31:03 +0000 | [diff] [blame] | 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
dino@apple.com | a001d32 | 2008-08-05 23:01:41 +0000 | [diff] [blame] | 24 | */ |
| 25 | |
| 26 | #include "config.h" |
| 27 | #include "WebKitCSSKeyframeRule.h" |
| 28 | |
antti@apple.com | 745b790 | 2012-03-31 18:02:35 +0000 | [diff] [blame] | 29 | #include "PropertySetCSSStyleDeclaration.h" |
antti@apple.com | 6428837 | 2012-03-29 10:17:19 +0000 | [diff] [blame] | 30 | #include "WebKitCSSKeyframesRule.h" |
commit-queue@webkit.org | 1ac47ab | 2012-08-24 23:58:43 +0000 | [diff] [blame] | 31 | #include <wtf/text/StringBuilder.h> |
dino@apple.com | a001d32 | 2008-08-05 23:01:41 +0000 | [diff] [blame] | 32 | |
| 33 | namespace WebCore { |
commit-queue@webkit.org | 42eb4e1 | 2012-07-18 15:15:22 +0000 | [diff] [blame] | 34 | |
| 35 | StylePropertySet* StyleKeyframe::mutableProperties() |
| 36 | { |
| 37 | if (!m_properties->isMutable()) |
| 38 | m_properties = m_properties->copy(); |
| 39 | return m_properties.get(); |
| 40 | } |
antti@apple.com | 6428837 | 2012-03-29 10:17:19 +0000 | [diff] [blame] | 41 | |
| 42 | void StyleKeyframe::setProperties(PassRefPtr<StylePropertySet> properties) |
dino@apple.com | a001d32 | 2008-08-05 23:01:41 +0000 | [diff] [blame] | 43 | { |
antti@apple.com | 6428837 | 2012-03-29 10:17:19 +0000 | [diff] [blame] | 44 | m_properties = properties; |
dino@apple.com | a001d32 | 2008-08-05 23:01:41 +0000 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | /* static */ |
antti@apple.com | 6428837 | 2012-03-29 10:17:19 +0000 | [diff] [blame] | 48 | void StyleKeyframe::parseKeyString(const String& s, Vector<float>& keys) |
dino@apple.com | a001d32 | 2008-08-05 23:01:41 +0000 | [diff] [blame] | 49 | { |
dino@apple.com | 9300a0b | 2008-09-12 00:36:31 +0000 | [diff] [blame] | 50 | keys.clear(); |
| 51 | Vector<String> strings; |
| 52 | s.split(',', strings); |
apavlov@chromium.org | f684aec | 2011-10-19 13:31:03 +0000 | [diff] [blame] | 53 | |
dino@apple.com | 9300a0b | 2008-09-12 00:36:31 +0000 | [diff] [blame] | 54 | for (size_t i = 0; i < strings.size(); ++i) { |
| 55 | float key = -1; |
| 56 | String cur = strings[i].stripWhiteSpace(); |
antti@apple.com | 6428837 | 2012-03-29 10:17:19 +0000 | [diff] [blame] | 57 | |
dino@apple.com | 9300a0b | 2008-09-12 00:36:31 +0000 | [diff] [blame] | 58 | // 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.org | 127cec2c | 2012-04-30 21:32:44 +0000 | [diff] [blame] | 63 | else if (cur.endsWith('%')) { |
dino@apple.com | 9300a0b | 2008-09-12 00:36:31 +0000 | [diff] [blame] | 64 | float k = cur.substring(0, cur.length() - 1).toFloat(); |
dino@apple.com | a001d32 | 2008-08-05 23:01:41 +0000 | [diff] [blame] | 65 | if (k >= 0 && k <= 100) |
dino@apple.com | 9300a0b | 2008-09-12 00:36:31 +0000 | [diff] [blame] | 66 | key = k/100; |
dino@apple.com | a001d32 | 2008-08-05 23:01:41 +0000 | [diff] [blame] | 67 | } |
dino@apple.com | 9300a0b | 2008-09-12 00:36:31 +0000 | [diff] [blame] | 68 | if (key < 0) { |
| 69 | keys.clear(); |
| 70 | return; |
| 71 | } |
| 72 | else |
| 73 | keys.append(key); |
dino@apple.com | a001d32 | 2008-08-05 23:01:41 +0000 | [diff] [blame] | 74 | } |
dino@apple.com | a001d32 | 2008-08-05 23:01:41 +0000 | [diff] [blame] | 75 | } |
| 76 | |
antti@apple.com | 6428837 | 2012-03-29 10:17:19 +0000 | [diff] [blame] | 77 | String StyleKeyframe::cssText() const |
| 78 | { |
commit-queue@webkit.org | 1ac47ab | 2012-08-24 23:58:43 +0000 | [diff] [blame] | 79 | 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.com | 6428837 | 2012-03-29 10:17:19 +0000 | [diff] [blame] | 88 | } |
| 89 | |
yurys@chromium.org | bf5c075 | 2012-08-01 13:29:59 +0000 | [diff] [blame] | 90 | void StyleKeyframe::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const |
| 91 | { |
loislo@chromium.org | 53b3ffd | 2012-09-05 15:11:06 +0000 | [diff] [blame] | 92 | MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::CSS); |
loislo@chromium.org | 61a7dd6 | 2012-09-17 15:12:21 +0000 | [diff] [blame] | 93 | info.addMember(m_properties); |
| 94 | info.addMember(m_key); |
yurys@chromium.org | bf5c075 | 2012-08-01 13:29:59 +0000 | [diff] [blame] | 95 | } |
| 96 | |
antti@apple.com | 6428837 | 2012-03-29 10:17:19 +0000 | [diff] [blame] | 97 | WebKitCSSKeyframeRule::WebKitCSSKeyframeRule(StyleKeyframe* keyframe, WebKitCSSKeyframesRule* parent) |
akling@apple.com | c713db3 | 2012-11-22 03:45:40 +0000 | [diff] [blame] | 98 | : CSSRule(0) |
antti@apple.com | 6428837 | 2012-03-29 10:17:19 +0000 | [diff] [blame] | 99 | , m_keyframe(keyframe) |
| 100 | { |
| 101 | setParentRule(parent); |
| 102 | } |
| 103 | |
| 104 | WebKitCSSKeyframeRule::~WebKitCSSKeyframeRule() |
| 105 | { |
antti@apple.com | 745b790 | 2012-03-31 18:02:35 +0000 | [diff] [blame] | 106 | if (m_propertiesCSSOMWrapper) |
| 107 | m_propertiesCSSOMWrapper->clearParentRule(); |
antti@apple.com | 6428837 | 2012-03-29 10:17:19 +0000 | [diff] [blame] | 108 | } |
| 109 | |
antti@apple.com | 745b790 | 2012-03-31 18:02:35 +0000 | [diff] [blame] | 110 | CSSStyleDeclaration* WebKitCSSKeyframeRule::style() const |
| 111 | { |
| 112 | if (!m_propertiesCSSOMWrapper) |
commit-queue@webkit.org | 42eb4e1 | 2012-07-18 15:15:22 +0000 | [diff] [blame] | 113 | m_propertiesCSSOMWrapper = StyleRuleCSSStyleDeclaration::create(m_keyframe->mutableProperties(), const_cast<WebKitCSSKeyframeRule*>(this)); |
antti@apple.com | 745b790 | 2012-03-31 18:02:35 +0000 | [diff] [blame] | 114 | return m_propertiesCSSOMWrapper.get(); |
antti@apple.com | 6428837 | 2012-03-29 10:17:19 +0000 | [diff] [blame] | 115 | } |
| 116 | |
akling@apple.com | c713db3 | 2012-11-22 03:45:40 +0000 | [diff] [blame] | 117 | void WebKitCSSKeyframeRule::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const |
yurys@chromium.org | 7edf1e4 | 2012-08-03 10:18:31 +0000 | [diff] [blame] | 118 | { |
loislo@chromium.org | 53b3ffd | 2012-09-05 15:11:06 +0000 | [diff] [blame] | 119 | MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::CSS); |
akling@apple.com | c713db3 | 2012-11-22 03:45:40 +0000 | [diff] [blame] | 120 | CSSRule::reportMemoryUsage(memoryObjectInfo); |
loislo@chromium.org | 61a7dd6 | 2012-09-17 15:12:21 +0000 | [diff] [blame] | 121 | info.addMember(m_keyframe); |
| 122 | info.addMember(m_propertiesCSSOMWrapper); |
yurys@chromium.org | 7edf1e4 | 2012-08-03 10:18:31 +0000 | [diff] [blame] | 123 | } |
| 124 | |
akling@apple.com | c713db3 | 2012-11-22 03:45:40 +0000 | [diff] [blame] | 125 | void WebKitCSSKeyframeRule::reattach(StyleRuleBase*) |
| 126 | { |
| 127 | // No need to reattach, the underlying data is shareable on mutation. |
| 128 | ASSERT_NOT_REACHED(); |
| 129 | } |
| 130 | |
dino@apple.com | a001d32 | 2008-08-05 23:01:41 +0000 | [diff] [blame] | 131 | } // namespace WebCore |