Diff
Modified: trunk/Source/WebCore/ChangeLog (112515 => 112516)
--- trunk/Source/WebCore/ChangeLog 2012-03-29 10:14:32 UTC (rev 112515)
+++ trunk/Source/WebCore/ChangeLog 2012-03-29 10:17:19 UTC (rev 112516)
@@ -1,3 +1,97 @@
+2012-03-28 Antti Koivisto <[email protected]>
+
+ Split WebKitCSSKeyframeRule into internal and CSSOM types
+ https://bugs.webkit.org/show_bug.cgi?id=82490
+
+ Reviewed by Andreas Kling.
+
+ WebKitCSSKeyframeRule is a CSSOM type and should not be used internally.
+
+ - Add StyleKeyframe as the internal data structure for keyframes.
+ - WebKitCSSKeyframeRule becomes a wrapper for StyleKeyframe.
+ - Use StyleKeyframe internally so WebKitCSSKeyframeRules are created on CSSOM access only.
+
+ * css/CSSGrammar.y:
+
+ Use StyleKeyframes instead of WebKitCSSKeyframeRules.
+
+ * css/CSSMediaRule.h:
+ (CSSMediaRule):
+ (WebCore::CSSMediaRule::length):
+ (WebCore::CSSMediaRule::item):
+
+ Adapt to LiveCSSRuleList changes.
+
+ * css/CSSParser.cpp:
+ (WebCore::CSSParser::parseKeyframeRule):
+ (WebCore::CSSParser::createKeyframe):
+ * css/CSSParser.h:
+ (WebCore):
+ (CSSParser):
+
+ Construct StyleKeyframes.
+
+ * css/CSSRuleList.h:
+ (WebCore::LiveCSSRuleList::length):
+ (WebCore::LiveCSSRuleList::item):
+
+ Make LiveCSSRuleList call rule item()/length() to avoid accessor duplication.
+
+ * css/CSSStyleSelector.cpp:
+ (WebCore::CSSStyleSelector::collectMatchingRulesForList):
+ * css/CSSStyleSelector.h:
+ (CSSStyleSelector):
+ * css/WebKitCSSKeyframeRule.cpp:
+
+ Use StyleKeyframe.
+ Make 0% and 100% keyframes static.
+
+ (WebCore):
+ (WebCore::StyleKeyframe::setProperties):
+ (WebCore::StyleKeyframe::parseKeyString):
+ (WebCore::StyleKeyframe::cssText):
+ (WebCore::WebKitCSSKeyframeRule::WebKitCSSKeyframeRule):
+ (WebCore::WebKitCSSKeyframeRule::~WebKitCSSKeyframeRule):
+ (WebCore::WebKitCSSKeyframeRule::style):
+ * css/WebKitCSSKeyframeRule.h:
+ (WebCore):
+ (WebCore::StyleKeyframe::create):
+ (WebCore::StyleKeyframe::keyText):
+ (WebCore::StyleKeyframe::setKeyText):
+ (StyleKeyframe):
+ (WebCore::StyleKeyframe::properties):
+ (WebCore::StyleKeyframe::StyleKeyframe):
+ (WebKitCSSKeyframeRule):
+ (WebCore::WebKitCSSKeyframeRule::keyText):
+ (WebCore::WebKitCSSKeyframeRule::setKeyText):
+ (WebCore::WebKitCSSKeyframeRule::cssText):
+
+ Split to internal and CSSOM wrapper type. The wrapper refs StyleKeyframe.
+
+ * css/WebKitCSSKeyframesRule.cpp:
+ (WebCore::WebKitCSSKeyframesRule::~WebKitCSSKeyframesRule):
+ (WebCore::WebKitCSSKeyframesRule::parserAppendKeyframe):
+ (WebCore::WebKitCSSKeyframesRule::insertRule):
+ (WebCore::WebKitCSSKeyframesRule::deleteRule):
+ (WebCore::WebKitCSSKeyframesRule::findRule):
+ (WebCore::WebKitCSSKeyframesRule::findKeyframeIndex):
+ (WebCore::WebKitCSSKeyframesRule::cssText):
+ (WebCore):
+ (WebCore::WebKitCSSKeyframesRule::item):
+ * css/WebKitCSSKeyframesRule.h:
+ (WebCore):
+ (WebCore::WebKitCSSKeyframesRule::keyframes):
+ (WebKitCSSKeyframesRule):
+ (WebCore::WebKitCSSKeyframesRule::length):
+
+ Keep StyleKeyframes and the wrappers (WebKitCSSKeyframeRules) in separate vectors.
+ Construct the wrapper vector and wrappers themselves on demand.
+ Keep the vectors in sync during mutations.
+
+ * css/WebKitCSSRegionRule.h:
+
+ Adapt to LiveCSSRuleList changes.
+
2012-03-29 Zeno Albisser <[email protected]>
Fieldset disabled attribute does not work.
Modified: trunk/Source/WebCore/css/CSSGrammar.y (112515 => 112516)
--- trunk/Source/WebCore/css/CSSGrammar.y 2012-03-29 10:14:32 UTC (rev 112515)
+++ trunk/Source/WebCore/css/CSSGrammar.y 2012-03-29 10:17:19 UTC (rev 112516)
@@ -81,7 +81,7 @@
CSSParserValue value;
CSSParserValueList* valueList;
Vector<OwnPtr<MediaQueryExp> >* mediaQueryExpList;
- WebKitCSSKeyframeRule* keyframeRule;
+ StyleKeyframe* keyframe;
WebKitCSSKeyframesRule* keyframesRule;
float val;
}
@@ -245,7 +245,7 @@
%type <mediaQueryExpList> maybe_and_media_query_exp_list
%type <string> keyframe_name
-%type <keyframeRule> keyframe_rule
+%type <keyframe> keyframe_rule
%type <keyframesRule> keyframes_rule
%type <valueList> key_list
%type <value> key
@@ -627,13 +627,13 @@
| keyframes_rule keyframe_rule maybe_space {
$$ = $1;
if ($2)
- $$->append($2);
+ $$->parserAppendKeyframe($2);
}
;
keyframe_rule:
key_list maybe_space '{' maybe_space declaration_list '}' {
- $$ = static_cast<CSSParser*>(parser)->createKeyframeRule($1);
+ $$ = static_cast<CSSParser*>(parser)->createKeyframe($1);
}
;
Modified: trunk/Source/WebCore/css/CSSMediaRule.h (112515 => 112516)
--- trunk/Source/WebCore/css/CSSMediaRule.h 2012-03-29 10:14:32 UTC (rev 112515)
+++ trunk/Source/WebCore/css/CSSMediaRule.h 2012-03-29 10:17:19 UTC (rev 112516)
@@ -53,6 +53,10 @@
unsigned ruleCount() const { return m_childRules.size(); }
CSSRule* ruleAt(unsigned index) const { return m_childRules[index].get(); }
+
+ // For CSSRuleList
+ unsigned length() const { return ruleCount(); }
+ CSSRule* item(unsigned index) const { return index < ruleCount() ? ruleAt(index) : 0; }
private:
CSSMediaRule(CSSStyleSheet* parent, PassRefPtr<MediaQuerySet>, Vector<RefPtr<CSSRule> >& adoptRules);
Modified: trunk/Source/WebCore/css/CSSParser.cpp (112515 => 112516)
--- trunk/Source/WebCore/css/CSSParser.cpp 2012-03-29 10:14:32 UTC (rev 112515)
+++ trunk/Source/WebCore/css/CSSParser.cpp 2012-03-29 10:17:19 UTC (rev 112516)
@@ -319,7 +319,7 @@
return m_rule.release();
}
-PassRefPtr<WebKitCSSKeyframeRule> CSSParser::parseKeyframeRule(CSSStyleSheet *sheet, const String &string)
+PassRefPtr<StyleKeyframe> CSSParser::parseKeyframeRule(CSSStyleSheet *sheet, const String &string)
{
setStyleSheet(sheet);
setupParser("@-webkit-keyframe-rule{ ", string, "} ");
@@ -9265,7 +9265,7 @@
}
}
-WebKitCSSKeyframeRule* CSSParser::createKeyframeRule(CSSParserValueList* keys)
+StyleKeyframe* CSSParser::createKeyframe(CSSParserValueList* keys)
{
// Create a key string from the passed keys
String keyString;
@@ -9277,14 +9277,14 @@
keyString += "%";
}
- RefPtr<WebKitCSSKeyframeRule> keyframe = WebKitCSSKeyframeRule::create(m_styleSheet);
+ RefPtr<StyleKeyframe> keyframe = StyleKeyframe::create();
keyframe->setKeyText(keyString);
- keyframe->setDeclaration(StylePropertySet::create(m_parsedProperties.data(), m_parsedProperties.size(), inStrictMode()));
+ keyframe->setProperties(StylePropertySet::create(m_parsedProperties.data(), m_parsedProperties.size(), inStrictMode()));
clearProperties();
- WebKitCSSKeyframeRule* keyframePtr = keyframe.get();
- m_parsedRules.append(keyframe.release());
+ StyleKeyframe* keyframePtr = keyframe.get();
+ m_parsedKeyframes.append(keyframe.release());
return keyframePtr;
}
Modified: trunk/Source/WebCore/css/CSSParser.h (112515 => 112516)
--- trunk/Source/WebCore/css/CSSParser.h 2012-03-29 10:14:32 UTC (rev 112515)
+++ trunk/Source/WebCore/css/CSSParser.h 2012-03-29 10:17:19 UTC (rev 112516)
@@ -59,8 +59,8 @@
class MediaQueryExp;
class MediaQuerySet;
class StylePropertySet;
+class StyleKeyframe;
class StyledElement;
-class WebKitCSSKeyframeRule;
class WebKitCSSKeyframesRule;
class CSSParser {
@@ -74,7 +74,7 @@
void parseSheet(CSSStyleSheet*, const String&, int startLineNumber = 0, StyleRuleRangeMap* ruleRangeMap = 0);
PassRefPtr<CSSRule> parseRule(CSSStyleSheet*, const String&);
- PassRefPtr<WebKitCSSKeyframeRule> parseKeyframeRule(CSSStyleSheet*, const String&);
+ PassRefPtr<StyleKeyframe> parseKeyframeRule(CSSStyleSheet*, const String&);
static bool parseValue(StylePropertySet*, int propId, const String&, bool important, bool strict, CSSStyleSheet* contextStyleSheet);
static bool parseColor(RGBA32& color, const String&, bool strict = false);
static bool parseSystemColor(RGBA32& color, const String&, Document*);
@@ -249,7 +249,7 @@
MediaQuerySet* createMediaQuerySet();
CSSRule* createImportRule(const CSSParserString&, MediaQuerySet*);
- WebKitCSSKeyframeRule* createKeyframeRule(CSSParserValueList*);
+ StyleKeyframe* createKeyframe(CSSParserValueList*);
WebKitCSSKeyframesRule* createKeyframesRule();
typedef Vector<RefPtr<CSSRule> > RuleList;
@@ -292,7 +292,7 @@
int m_id;
CSSStyleSheet* m_styleSheet;
RefPtr<CSSRule> m_rule;
- RefPtr<WebKitCSSKeyframeRule> m_keyframe;
+ RefPtr<StyleKeyframe> m_keyframe;
OwnPtr<MediaQuery> m_mediaQuery;
OwnPtr<CSSParserValueList> m_valueList;
Vector<CSSProperty, 256> m_parsedProperties;
@@ -411,6 +411,7 @@
bool m_allowNamespaceDeclarations;
Vector<RefPtr<CSSRule> > m_parsedRules;
+ Vector<RefPtr<StyleKeyframe> > m_parsedKeyframes;
Vector<RefPtr<MediaQuerySet> > m_parsedMediaQuerySets;
Vector<OwnPtr<RuleList> > m_parsedRuleLists;
HashSet<CSSParserSelector*> m_floatingSelectors;
Modified: trunk/Source/WebCore/css/CSSRuleList.h (112515 => 112516)
--- trunk/Source/WebCore/css/CSSRuleList.h 2012-03-29 10:14:32 UTC (rev 112515)
+++ trunk/Source/WebCore/css/CSSRuleList.h 2012-03-29 10:17:19 UTC (rev 112516)
@@ -82,8 +82,8 @@
virtual void deref() { m_rule->deref(); }
private:
- virtual unsigned length() const { return m_rule->ruleCount(); }
- virtual CSSRule* item(unsigned index) const { return index < m_rule->ruleCount() ? m_rule->ruleAt(index) : 0; }
+ virtual unsigned length() const { return m_rule->length(); }
+ virtual CSSRule* item(unsigned index) const { return m_rule->item(index); }
virtual CSSStyleSheet* styleSheet() const { return m_rule->parentStyleSheet(); }
Rule* m_rule;
Modified: trunk/Source/WebCore/css/CSSStyleSelector.cpp (112515 => 112516)
--- trunk/Source/WebCore/css/CSSStyleSelector.cpp 2012-03-29 10:14:32 UTC (rev 112515)
+++ trunk/Source/WebCore/css/CSSStyleSelector.cpp 2012-03-29 10:17:19 UTC (rev 112516)
@@ -1629,11 +1629,11 @@
return m_style.release();
}
-PassRefPtr<RenderStyle> CSSStyleSelector::styleForKeyframe(const RenderStyle* elementStyle, const WebKitCSSKeyframeRule* keyframeRule, KeyframeValue& keyframe)
+PassRefPtr<RenderStyle> CSSStyleSelector::styleForKeyframe(const RenderStyle* elementStyle, const StyleKeyframe* keyframe, KeyframeValue& keyframeValue)
{
MatchResult result;
- if (keyframeRule->declaration())
- addMatchedProperties(result, keyframeRule->declaration());
+ if (keyframe->properties())
+ addMatchedProperties(result, keyframe->properties());
ASSERT(!m_style);
@@ -1645,7 +1645,7 @@
// We don't need to bother with !important. Since there is only ever one
// decl, there's nothing to override. So just add the first properties.
bool inheritedOnly = false;
- if (keyframeRule->style())
+ if (keyframe->properties())
applyMatchedProperties<true>(result, false, 0, result.matchedProperties.size() - 1, inheritedOnly);
// If our font got dirtied, go ahead and update it now.
@@ -1656,7 +1656,7 @@
applyProperty(CSSPropertyLineHeight, m_lineHeightValue);
// Now do rest of the properties.
- if (keyframeRule->style())
+ if (keyframe->properties())
applyMatchedProperties<false>(result, false, 0, result.matchedProperties.size() - 1, inheritedOnly);
// If our font got dirtied by one of the non-essential font props,
@@ -1672,14 +1672,14 @@
#endif
// Add all the animating properties to the keyframe.
- if (StylePropertySet* styleDeclaration = keyframeRule->declaration()) {
+ if (StylePropertySet* styleDeclaration = keyframe->properties()) {
unsigned propertyCount = styleDeclaration->propertyCount();
for (unsigned i = 0; i < propertyCount; ++i) {
int property = styleDeclaration->propertyAt(i).id();
// Timing-function within keyframes is special, because it is not animated; it just
// describes the timing function between this keyframe and the next.
if (property != CSSPropertyWebkitAnimationTimingFunction)
- keyframe.addProperty(property);
+ keyframeValue.addProperty(property);
}
}
@@ -1703,42 +1703,49 @@
const WebKitCSSKeyframesRule* keyframesRule = it->second.get();
// Construct and populate the style for each keyframe
- for (unsigned i = 0; i < keyframesRule->ruleCount(); ++i) {
+ const Vector<RefPtr<StyleKeyframe> >& keyframes = keyframesRule->keyframes();
+ for (unsigned i = 0; i < keyframes.size(); ++i) {
// Apply the declaration to the style. This is a simplified version of the logic in styleForElement
initElement(e);
initForStyleResolve(e);
- const WebKitCSSKeyframeRule* keyframeRule = keyframesRule->ruleAt(i);
+ const StyleKeyframe* keyframe = keyframes[i].get();
- KeyframeValue keyframe(0, 0);
- keyframe.setStyle(styleForKeyframe(elementStyle, keyframeRule, keyframe));
+ KeyframeValue keyframeValue(0, 0);
+ keyframeValue.setStyle(styleForKeyframe(elementStyle, keyframe, keyframeValue));
// Add this keyframe style to all the indicated key times
Vector<float> keys;
- keyframeRule->getKeys(keys);
+ keyframe->getKeys(keys);
for (size_t keyIndex = 0; keyIndex < keys.size(); ++keyIndex) {
- keyframe.setKey(keys[keyIndex]);
- list.insert(keyframe);
+ keyframeValue.setKey(keys[keyIndex]);
+ list.insert(keyframeValue);
}
}
// If the 0% keyframe is missing, create it (but only if there is at least one other keyframe)
int initialListSize = list.size();
if (initialListSize > 0 && list[0].key() != 0) {
- RefPtr<WebKitCSSKeyframeRule> keyframeRule = WebKitCSSKeyframeRule::create();
- keyframeRule->setKeyText("0%");
- KeyframeValue keyframe(0, 0);
- keyframe.setStyle(styleForKeyframe(elementStyle, keyframeRule.get(), keyframe));
- list.insert(keyframe);
+ static StyleKeyframe* zeroPercentKeyframe;
+ if (!zeroPercentKeyframe) {
+ zeroPercentKeyframe = StyleKeyframe::create().leakRef();
+ zeroPercentKeyframe->setKeyText("0%");
+ }
+ KeyframeValue keyframeValue(0, 0);
+ keyframeValue.setStyle(styleForKeyframe(elementStyle, zeroPercentKeyframe, keyframeValue));
+ list.insert(keyframeValue);
}
// If the 100% keyframe is missing, create it (but only if there is at least one other keyframe)
if (initialListSize > 0 && (list[list.size() - 1].key() != 1)) {
- RefPtr<WebKitCSSKeyframeRule> keyframeRule = WebKitCSSKeyframeRule::create();
- keyframeRule->setKeyText("100%");
- KeyframeValue keyframe(1, 0);
- keyframe.setStyle(styleForKeyframe(elementStyle, keyframeRule.get(), keyframe));
- list.insert(keyframe);
+ static StyleKeyframe* hundredPercentKeyframe;
+ if (!hundredPercentKeyframe) {
+ hundredPercentKeyframe = StyleKeyframe::create().leakRef();
+ hundredPercentKeyframe->setKeyText("100%");
+ }
+ KeyframeValue keyframeValue(1, 0);
+ keyframeValue.setStyle(styleForKeyframe(elementStyle, hundredPercentKeyframe, keyframeValue));
+ list.insert(keyframeValue);
}
}
Modified: trunk/Source/WebCore/css/CSSStyleSelector.h (112515 => 112516)
--- trunk/Source/WebCore/css/CSSStyleSelector.h 2012-03-29 10:14:32 UTC (rev 112515)
+++ trunk/Source/WebCore/css/CSSStyleSelector.h 2012-03-29 10:17:19 UTC (rev 112516)
@@ -70,6 +70,7 @@
class Settings;
class StaticCSSRuleList;
class StyleImage;
+class StyleKeyframe;
class StylePendingImage;
class StylePropertySet;
class StyleRule;
@@ -77,7 +78,6 @@
class StyleSheet;
class StyleSheetList;
class StyledElement;
-class WebKitCSSKeyframeRule;
class WebKitCSSKeyframesRule;
class WebKitCSSFilterValue;
class WebKitCSSRegionRule;
@@ -151,7 +151,7 @@
StyledElement* findSiblingForStyleSharing(Node*, unsigned& count) const;
bool canShareStyleWithElement(StyledElement*) const;
- PassRefPtr<RenderStyle> styleForKeyframe(const RenderStyle*, const WebKitCSSKeyframeRule*, KeyframeValue&);
+ PassRefPtr<RenderStyle> styleForKeyframe(const RenderStyle*, const StyleKeyframe*, KeyframeValue&);
#if ENABLE(STYLE_SCOPED)
void pushScope(const ContainerNode* scope, const ContainerNode* scopeParent);
Modified: trunk/Source/WebCore/css/WebKitCSSKeyframeRule.cpp (112515 => 112516)
--- trunk/Source/WebCore/css/WebKitCSSKeyframeRule.cpp 2012-03-29 10:14:32 UTC (rev 112515)
+++ trunk/Source/WebCore/css/WebKitCSSKeyframeRule.cpp 2012-03-29 10:17:19 UTC (rev 112516)
@@ -27,38 +27,17 @@
#include "WebKitCSSKeyframeRule.h"
#include "StylePropertySet.h"
+#include "WebKitCSSKeyframesRule.h"
namespace WebCore {
-
-WebKitCSSKeyframeRule::WebKitCSSKeyframeRule(CSSStyleSheet* parent)
- : CSSRule(parent, CSSRule::WEBKIT_KEYFRAME_RULE)
+
+void StyleKeyframe::setProperties(PassRefPtr<StylePropertySet> properties)
{
+ m_properties = properties;
}
-WebKitCSSKeyframeRule::~WebKitCSSKeyframeRule()
-{
- if (m_style)
- m_style->clearParentRule(this);
-}
-
-String WebKitCSSKeyframeRule::cssText() const
-{
- String result = m_key;
-
- result += " { ";
- result += m_style->asText();
- result += "}";
-
- return result;
-}
-
-void WebKitCSSKeyframeRule::setDeclaration(PassRefPtr<StylePropertySet> style)
-{
- m_style = style;
-}
-
/* static */
-void WebKitCSSKeyframeRule::parseKeyString(const String& s, Vector<float>& keys)
+void StyleKeyframe::parseKeyString(const String& s, Vector<float>& keys)
{
keys.clear();
Vector<String> strings;
@@ -67,7 +46,7 @@
for (size_t i = 0; i < strings.size(); ++i) {
float key = -1;
String cur = strings[i].stripWhiteSpace();
-
+
// For now the syntax MUST be 'xxx%' or 'from' or 'to', where xxx is a legal floating point number
if (cur == "from")
key = 0;
@@ -78,7 +57,6 @@
if (k >= 0 && k <= 100)
key = k/100;
}
-
if (key < 0) {
keys.clear();
return;
@@ -88,4 +66,32 @@
}
}
+String StyleKeyframe::cssText() const
+{
+ String result = keyText();
+
+ result += " { ";
+ result += m_properties->asText();
+ result += "}";
+
+ return result;
+}
+
+WebKitCSSKeyframeRule::WebKitCSSKeyframeRule(StyleKeyframe* keyframe, WebKitCSSKeyframesRule* parent)
+ : CSSRule(0, CSSRule::WEBKIT_KEYFRAME_RULE)
+ , m_keyframe(keyframe)
+{
+ setParentRule(parent);
+}
+
+WebKitCSSKeyframeRule::~WebKitCSSKeyframeRule()
+{
+ m_keyframe->properties()->clearParentRule(this);
+}
+
+CSSStyleDeclaration* WebKitCSSKeyframeRule::style() const
+{
+ return m_keyframe->properties() ? m_keyframe->properties()->ensureRuleCSSStyleDeclaration(this) : 0;
+}
+
} // namespace WebCore
Modified: trunk/Source/WebCore/css/WebKitCSSKeyframeRule.h (112515 => 112516)
--- trunk/Source/WebCore/css/WebKitCSSKeyframeRule.h 2012-03-29 10:14:32 UTC (rev 112515)
+++ trunk/Source/WebCore/css/WebKitCSSKeyframeRule.h 2012-03-29 10:17:19 UTC (rev 112516)
@@ -27,46 +27,60 @@
#define WebKitCSSKeyframeRule_h
#include "CSSRule.h"
+#include "ExceptionCode.h"
#include "StylePropertySet.h"
#include <wtf/PassRefPtr.h>
#include <wtf/RefPtr.h>
namespace WebCore {
-typedef int ExceptionCode;
+class WebKitCSSKeyframesRule;
-class WebKitCSSKeyframeRule : public CSSRule {
+class StyleKeyframe : public RefCounted<StyleKeyframe> {
public:
- static PassRefPtr<WebKitCSSKeyframeRule> create()
+ static PassRefPtr<StyleKeyframe> create()
{
- return adoptRef(new WebKitCSSKeyframeRule(0));
+ return adoptRef(new StyleKeyframe());
}
- static PassRefPtr<WebKitCSSKeyframeRule> create(CSSStyleSheet* parent)
- {
- return adoptRef(new WebKitCSSKeyframeRule(parent));
- }
- ~WebKitCSSKeyframeRule();
+ String keyText() const { return m_key; }
+ void setKeyText(const String& s) { m_key = s; }
- String keyText() const { return m_key; }
- void setKeyText(const String& s) { m_key = s; }
-
void getKeys(Vector<float>& keys) const { parseKeyString(m_key, keys); }
+
+ StylePropertySet* properties() const { return m_properties.get(); }
+ void setProperties(PassRefPtr<StylePropertySet>);
+
+ String cssText() const;
- CSSStyleDeclaration* style() const { return m_style ? m_style->ensureRuleCSSStyleDeclaration(this) : 0; }
+private:
+ StyleKeyframe() { }
+
+ static void parseKeyString(const String&, Vector<float>& keys);
+
+ RefPtr<StylePropertySet> m_properties;
+ // FIXME: This should be a parsed vector of floats.
+ // comma separated list of keys
+ String m_key;
+};
- String cssText() const;
+class WebKitCSSKeyframeRule : public CSSRule {
+public:
+ ~WebKitCSSKeyframeRule();
- StylePropertySet* declaration() const { return m_style.get(); }
- void setDeclaration(PassRefPtr<StylePropertySet>);
+ String keyText() const { return m_keyframe->keyText(); }
+ void setKeyText(const String& s) { m_keyframe->setKeyText(s); }
+ CSSStyleDeclaration* style() const;
+
+ String cssText() const { return m_keyframe->cssText(); }
+
private:
- static void parseKeyString(const String& s, Vector<float>& keys);
+ WebKitCSSKeyframeRule(StyleKeyframe*, WebKitCSSKeyframesRule* parent);
- WebKitCSSKeyframeRule(CSSStyleSheet* parent);
-
- RefPtr<StylePropertySet> m_style;
- String m_key; // comma separated list of keys
+ RefPtr<StyleKeyframe> m_keyframe;
+
+ friend class WebKitCSSKeyframesRule;
};
} // namespace WebCore
Modified: trunk/Source/WebCore/css/WebKitCSSKeyframesRule.cpp (112515 => 112516)
--- trunk/Source/WebCore/css/WebKitCSSKeyframesRule.cpp 2012-03-29 10:14:32 UTC (rev 112515)
+++ trunk/Source/WebCore/css/WebKitCSSKeyframesRule.cpp 2012-03-29 10:17:19 UTC (rev 112516)
@@ -42,8 +42,13 @@
WebKitCSSKeyframesRule::~WebKitCSSKeyframesRule()
{
- for (unsigned i = 0; i < m_childRules.size(); ++i)
- m_childRules[i]->setParentRule(0);
+ if (m_childRuleCSSOMWrappers) {
+ ASSERT(m_childRuleCSSOMWrappers->size() == m_keyframes.size());
+ for (unsigned i = 0; i < m_childRuleCSSOMWrappers->size(); ++i) {
+ if (m_childRuleCSSOMWrappers->at(i))
+ m_childRuleCSSOMWrappers->at(i)->setParentRule(0);
+ }
+ }
}
void WebKitCSSKeyframesRule::setName(const String& name)
@@ -56,41 +61,49 @@
styleSheet->styleSheetChanged();
}
-void WebKitCSSKeyframesRule::append(WebKitCSSKeyframeRule* rule)
+void WebKitCSSKeyframesRule::parserAppendKeyframe(PassRefPtr<StyleKeyframe> keyframe)
{
- if (!rule)
+ ASSERT(!m_childRuleCSSOMWrappers);
+ if (!keyframe)
return;
-
- m_childRules.append(rule);
- rule->setParentRule(this);
+ m_keyframes.append(keyframe);
}
-void WebKitCSSKeyframesRule::insertRule(const String& rule)
+void WebKitCSSKeyframesRule::insertRule(const String& ruleText)
{
CSSParser p(useStrictParsing());
- RefPtr<WebKitCSSKeyframeRule> newRule = p.parseKeyframeRule(parentStyleSheet(), rule);
- if (newRule)
- append(newRule.get());
+ RefPtr<StyleKeyframe> keyframe = p.parseKeyframeRule(parentStyleSheet(), ruleText);
+ if (!keyframe)
+ return;
+
+ m_keyframes.append(keyframe);
+
+ if (m_childRuleCSSOMWrappers)
+ m_childRuleCSSOMWrappers->grow(m_keyframes.size());
}
void WebKitCSSKeyframesRule::deleteRule(const String& s)
{
- int i = findRuleIndex(s);
+ int i = findKeyframeIndex(s);
if (i < 0)
return;
- WebKitCSSKeyframeRule* rule = item(i);
- rule->setParentRule(0);
- m_childRules.remove(i);
+ m_keyframes.remove(i);
+
+ if (m_childRuleCSSOMWrappers) {
+ if (m_childRuleCSSOMWrappers->at(i))
+ m_childRuleCSSOMWrappers->at(i)->setParentRule(0);
+ m_childRuleCSSOMWrappers->remove(i);
+ }
}
WebKitCSSKeyframeRule* WebKitCSSKeyframesRule::findRule(const String& s)
{
- int i = findRuleIndex(s);
- return (i >= 0) ? m_childRules[i].get() : 0;
+ int i = findKeyframeIndex(s);
+ return (i >= 0) ? item(i) : 0;
}
-int WebKitCSSKeyframesRule::findRuleIndex(const String& key) const
+int WebKitCSSKeyframesRule::findKeyframeIndex(const String& key) const
{
String percentageString;
if (equalIgnoringCase(key, "from"))
@@ -100,8 +113,8 @@
else
percentageString = key;
- for (unsigned i = 0; i < m_childRules.size(); ++i) {
- if (m_childRules[i]->keyText() == percentageString)
+ for (unsigned i = 0; i < m_keyframes.size(); ++i) {
+ if (m_keyframes[i]->keyText() == percentageString)
return i;
}
@@ -115,16 +128,31 @@
result.append(m_name);
result.append(" { \n");
- for (unsigned i = 0; i < m_childRules.size(); ++i) {
+ for (unsigned i = 0; i < m_keyframes.size(); ++i) {
result.append(" ");
- result.append(m_childRules[i]->cssText());
+ result.append(m_keyframes[i]->cssText());
result.append("\n");
}
result.append("}");
return result.toString();
}
-
+
+WebKitCSSKeyframeRule* WebKitCSSKeyframesRule::item(unsigned index) const
+{
+ if (index >= m_keyframes.size())
+ return 0;
+ if (!m_childRuleCSSOMWrappers)
+ m_childRuleCSSOMWrappers = adoptPtr(new Vector<RefPtr<WebKitCSSKeyframeRule> >(m_keyframes.size()));
+
+ ASSERT(m_childRuleCSSOMWrappers->size() == m_keyframes.size());
+ RefPtr<WebKitCSSKeyframeRule>& rule = m_childRuleCSSOMWrappers->at(index);
+ if (!rule)
+ rule = adoptRef(new WebKitCSSKeyframeRule(m_keyframes[index].get(), const_cast<WebKitCSSKeyframesRule*>(this)));
+
+ return rule.get();
+}
+
CSSRuleList* WebKitCSSKeyframesRule::cssRules()
{
if (!m_ruleListCSSOMWrapper)
Modified: trunk/Source/WebCore/css/WebKitCSSKeyframesRule.h (112515 => 112516)
--- trunk/Source/WebCore/css/WebKitCSSKeyframesRule.h 2012-03-29 10:14:32 UTC (rev 112515)
+++ trunk/Source/WebCore/css/WebKitCSSKeyframesRule.h 2012-03-29 10:17:19 UTC (rev 112516)
@@ -34,6 +34,7 @@
namespace WebCore {
class CSSRuleList;
+class StyleKeyframe;
class WebKitCSSKeyframeRule;
typedef int ExceptionCode;
@@ -71,24 +72,24 @@
String cssText() const;
// Not part of the CSSOM.
- unsigned ruleCount() const { return m_childRules.size(); }
- WebKitCSSKeyframeRule* ruleAt(unsigned index) const { return m_childRules[index].get(); }
+ const Vector<RefPtr<StyleKeyframe> >& keyframes() const { return m_keyframes; }
- void append(WebKitCSSKeyframeRule*);
+ void parserAppendKeyframe(PassRefPtr<StyleKeyframe>);
- // For IndexedGetter.
- unsigned length() const { return ruleCount(); }
- WebKitCSSKeyframeRule* item(unsigned index) const { return index < ruleCount() ? ruleAt(index) : 0; }
+ // For IndexedGetter and CSSRuleList.
+ unsigned length() const { return m_keyframes.size(); }
+ WebKitCSSKeyframeRule* item(unsigned index) const;
private:
WebKitCSSKeyframesRule(CSSStyleSheet* parent);
- int findRuleIndex(const String& key) const;
+ int findKeyframeIndex(const String& key) const;
- Vector<RefPtr<WebKitCSSKeyframeRule> > m_childRules;
+ Vector<RefPtr<StyleKeyframe> > m_keyframes;
AtomicString m_name;
-
- OwnPtr<CSSRuleList> m_ruleListCSSOMWrapper;
+
+ mutable OwnPtr<Vector<RefPtr<WebKitCSSKeyframeRule> > > m_childRuleCSSOMWrappers;
+ mutable OwnPtr<CSSRuleList> m_ruleListCSSOMWrapper;
};
} // namespace WebCore
Modified: trunk/Source/WebCore/css/WebKitCSSRegionRule.h (112515 => 112516)
--- trunk/Source/WebCore/css/WebKitCSSRegionRule.h 2012-03-29 10:14:32 UTC (rev 112515)
+++ trunk/Source/WebCore/css/WebKitCSSRegionRule.h 2012-03-29 10:17:19 UTC (rev 112516)
@@ -57,7 +57,11 @@
// Not part of the CSSOM.
unsigned ruleCount() const { return m_childRules.size(); }
- CSSRule* ruleAt(unsigned index) { return m_childRules[index].get(); }
+ CSSRule* ruleAt(unsigned index) const { return m_childRules[index].get(); }
+
+ // For CSSRuleList
+ unsigned length() const { return ruleCount(); }
+ CSSRule* item(unsigned index) const { return index < ruleCount() ? ruleAt(index) : 0; }
private:
WebKitCSSRegionRule(CSSStyleSheet* parent, Vector<OwnPtr<CSSParserSelector> >* selectors, Vector<RefPtr<CSSRule> >&);