<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[179197] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/179197">179197</a></dd>
<dt>Author</dt> <dd>dino@apple.com</dd>
<dt>Date</dt> <dd>2015-01-27 11:39:22 -0800 (Tue, 27 Jan 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>CSSKeyframesRule::findRule() and deleteRule() should delete the last matching rule, not the first
https://bugs.webkit.org/show_bug.cgi?id=139732

Patch by Sylvain Galineau &lt;galineau@adobe.com&gt; on 2015-01-26
Reviewed by Dean Jackson and Darin Adler.

Source/WebCore:

No new tests because existing tests have been updated to verify this behavior.

* css/CSSKeyframeRule.h:
(WebCore::StyleKeyframe::getKeys): Deleted.
* css/StyleResolver.cpp:
(WebCore::StyleResolver::keyframeStylesForAnimation): use StyleKeyframe::keys().
* css/CSSKeyframeRule.cpp:
(WebCore::StyleKeyframe::parseKeyString): Deleted. Moved to CSSParser.
(WebCore::StyleKeyframe::keyText): Build keyframe selector from Vector&lt;double&gt; representation.
* css/CSSKeyframeRule.h:
(WebCore::StyleKeyframe::setKeyText): parse keyframe selector into Vector&lt;double&gt;.
(WebCore::StyleKeyframe::keys): Added. Returns vector representation of selector keys.
(WebCore::StyleKeyframe::getKeys): Deleted. Now keys().
* css/CSSKeyframesRule.cpp:
(WebCore::StyleRuleKeyframes::findKeyframeIndex): Return last matching rule.
* css/CSSParser.cpp:
(WebCore::CSSParser::parseKeyframeSelector): Added. Moved from StyleKeyframe.
* css/CSSParser.h:
(WebCore::CSSParser::parseKeyframeSelector): Added. Moved from StyleKeyframe.

LayoutTests:

Update existing keyframes OM tests to check for findRule/deleteRule matching order i.e. find/delete last specified rule.

* animations/keyframes-rule-expected.txt:
* animations/keyframes-rule.html:
* animations/unprefixed-keyframes-rule-expected.txt:
* animations/unprefixed-keyframes-rule.html:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsanimationskeyframesruleexpectedtxt">trunk/LayoutTests/animations/keyframes-rule-expected.txt</a></li>
<li><a href="#trunkLayoutTestsanimationskeyframesrulehtml">trunk/LayoutTests/animations/keyframes-rule.html</a></li>
<li><a href="#trunkLayoutTestsanimationsunprefixedkeyframesruleexpectedtxt">trunk/LayoutTests/animations/unprefixed-keyframes-rule-expected.txt</a></li>
<li><a href="#trunkLayoutTestsanimationsunprefixedkeyframesrulehtml">trunk/LayoutTests/animations/unprefixed-keyframes-rule.html</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorecssCSSKeyframeRulecpp">trunk/Source/WebCore/css/CSSKeyframeRule.cpp</a></li>
<li><a href="#trunkSourceWebCorecssCSSKeyframeRuleh">trunk/Source/WebCore/css/CSSKeyframeRule.h</a></li>
<li><a href="#trunkSourceWebCorecssCSSKeyframesRulecpp">trunk/Source/WebCore/css/CSSKeyframesRule.cpp</a></li>
<li><a href="#trunkSourceWebCorecssCSSParsercpp">trunk/Source/WebCore/css/CSSParser.cpp</a></li>
<li><a href="#trunkSourceWebCorecssCSSParserh">trunk/Source/WebCore/css/CSSParser.h</a></li>
<li><a href="#trunkSourceWebCorecssStyleResolvercpp">trunk/Source/WebCore/css/StyleResolver.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (179196 => 179197)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2015-01-27 19:16:00 UTC (rev 179196)
+++ trunk/LayoutTests/ChangeLog        2015-01-27 19:39:22 UTC (rev 179197)
</span><span class="lines">@@ -1,3 +1,17 @@
</span><ins>+2015-01-26  Sylvain Galineau  &lt;galineau@adobe.com&gt;
+
+        CSSKeyframesRule::findRule() and deleteRule() should delete the last matching rule, not the first
+        https://bugs.webkit.org/show_bug.cgi?id=139732
+
+        Reviewed by Dean Jackson and Darin Adler.
+
+        Update existing keyframes OM tests to check for findRule/deleteRule matching order i.e. find/delete last specified rule.
+
+        * animations/keyframes-rule-expected.txt:
+        * animations/keyframes-rule.html:
+        * animations/unprefixed-keyframes-rule-expected.txt:
+        * animations/unprefixed-keyframes-rule.html:
+
</ins><span class="cx"> 2015-01-27  Chris Dumez  &lt;cdumez@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Unreviewed, rebaseline fast/css/css2-system-fonts.html on iOS.
</span></span></pre></div>
<a id="trunkLayoutTestsanimationskeyframesruleexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/animations/keyframes-rule-expected.txt (179196 => 179197)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/animations/keyframes-rule-expected.txt        2015-01-27 19:16:00 UTC (rev 179196)
+++ trunk/LayoutTests/animations/keyframes-rule-expected.txt        2015-01-27 19:39:22 UTC (rev 179197)
</span><span class="lines">@@ -75,6 +75,41 @@
</span><span class="cx"> PASS rules2.item(0).keyText is '0%'
</span><span class="cx"> PASS rules2.item(1).keyText is '100%'
</span><span class="cx"> 
</span><ins>+findRule matching order: from last to first specified
+PASS keyframesFindLast.type is window.CSSRule.KEYFRAMES_RULE
+PASS keyframesFindLast.name is 'test-find-last'
+PASS rule.type is window.CSSRule.KEYFRAME_RULE
+PASS rule.cssText is '10% { left: 10px; }'
+PASS rule.type is window.CSSRule.KEYFRAME_RULE
+PASS rule.cssText is '10% { left: 10px; }'
+PASS rule.type is window.CSSRule.KEYFRAME_RULE
+FAIL rule.cssText should be 10%,20%  { left: 10px; }. Was 10%,20% { left: 1020px; }.
+PASS rule.type is window.CSSRule.KEYFRAME_RULE
+FAIL rule.cssText should be 10%,20%  { left: 10px; }. Was 10%,20% { left: 1020px; }.
+PASS rule is null
+PASS rule.type is window.CSSRule.KEYFRAME_RULE
+PASS rule.cssText is '0% { left: 0px; }'
+PASS rule.type is window.CSSRule.KEYFRAME_RULE
+PASS rule.cssText is '100% { left: 100px; }'
+
+deleteRule matching order: from last to first specified
+PASS keyframesDeleteLast.type is window.CSSRule.KEYFRAMES_RULE
+PASS keyframesDeleteLast.name is 'test-delete-last'
+PASS rulesDeleteLast.length is 8
+PASS rulesDeleteLast.length is 7
+PASS rule.type is window.CSSRule.KEYFRAME_RULE
+PASS rule.cssText is '10% { left: 10px; }'
+PASS rulesDeleteLast.length is 6
+PASS rule.type is window.CSSRule.KEYFRAME_RULE
+PASS rule.cssText is '10%,20% { left: 1020px; }'
+PASS rulesDeleteLast.length is 6
+PASS rulesDeleteLast.length is 5
+PASS rule.type is window.CSSRule.KEYFRAME_RULE
+PASS rule.cssText is '0% { left: 0px; }'
+PASS rulesDeleteLast.length is 4
+PASS rule.type is window.CSSRule.KEYFRAME_RULE
+PASS rule.cssText is '100% { left: 100px; }'
+
</ins><span class="cx"> PASS successfullyParsed is true
</span><span class="cx"> 
</span><span class="cx"> TEST COMPLETE
</span></span></pre></div>
<a id="trunkLayoutTestsanimationskeyframesrulehtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/animations/keyframes-rule.html (179196 => 179197)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/animations/keyframes-rule.html        2015-01-27 19:16:00 UTC (rev 179196)
+++ trunk/LayoutTests/animations/keyframes-rule.html        2015-01-27 19:39:22 UTC (rev 179197)
</span><span class="lines">@@ -15,6 +15,27 @@
</span><span class="cx">     50% { left: 30px; }
</span><span class="cx">     to { left: 20px; }
</span><span class="cx">   }
</span><ins>+  @-webkit-keyframes test-find-last {
+    from { left: -1px;  }
+    0% { left: 0px; }
+    10% { left: -1px; }
+    10% { left: 10px;}
+    10%, 20% { left: -1px;   }
+    10%,20% { left: 1020px; }
+    100% { left: -1px; }
+    to { left: 100px; }
+  }
+  @-webkit-keyframes test-delete-last {
+    from { left: 0px;  }
+    0% { left: -1px; }
+    10% { left: 10px; }
+    10% { left: -1px;}
+    10%, 20% { left: 1020px;   }
+    10%,20% { left: -1px; }
+    100% { left: 100px; }
+    to { left: -1px; }
+  }
+
</ins><span class="cx"> &lt;/style&gt;
</span><span class="cx"> &lt;script src=&quot;../resources/js-test-pre.js&quot;&gt;&lt;/script&gt;
</span><span class="cx"> &lt;/head&gt;
</span><span class="lines">@@ -168,7 +189,69 @@
</span><span class="cx"> shouldBe(&quot;rules2.item(1).keyText&quot;, &quot;'100%'&quot;);
</span><span class="cx"> 
</span><span class="cx"> debug(&quot;&quot;);
</span><ins>+debug(&quot;findRule matching order: from last to first specified&quot;);
</ins><span class="cx"> 
</span><ins>+var keyframesFindLast = document.styleSheets.item(0).cssRules.item(3);
+shouldBe(&quot;keyframesFindLast.type&quot;, &quot;window.CSSRule.KEYFRAMES_RULE&quot;);
+shouldBe(&quot;keyframesFindLast.name&quot;, &quot;'test-find-last'&quot;);
+
+
+rule = keyframesFindLast.findRule(&quot;10%&quot;);
+shouldBe(&quot;rule.type&quot;, &quot;window.CSSRule.KEYFRAME_RULE&quot;);
+shouldBe(&quot;rule.cssText&quot;, &quot;'10% { left: 10px; }'&quot;);
+rule = keyframesFindLast.findRule(&quot;10.0%&quot;);
+shouldBe(&quot;rule.type&quot;, &quot;window.CSSRule.KEYFRAME_RULE&quot;);
+shouldBe(&quot;rule.cssText&quot;, &quot;'10% { left: 10px; }'&quot;);
+rule = keyframesFindLast.findRule(&quot;10%,20%&quot;);
+shouldBe(&quot;rule.type&quot;, &quot;window.CSSRule.KEYFRAME_RULE&quot;);
+shouldBe(&quot;rule.cssText&quot;, &quot;'10%,20%  { left: 10px; }'&quot;);
+rule = keyframesFindLast.findRule(&quot;   10%, 20% &quot;);
+shouldBe(&quot;rule.type&quot;, &quot;window.CSSRule.KEYFRAME_RULE&quot;);
+shouldBe(&quot;rule.cssText&quot;, &quot;'10%,20%  { left: 10px; }'&quot;);
+rule = keyframesFindLast.findRule(&quot;20%, 10% &quot;);
+shouldBe(&quot;rule&quot;, &quot;null&quot;);
+rule = keyframesFindLast.findRule(&quot;from&quot;);
+shouldBe(&quot;rule.type&quot;, &quot;window.CSSRule.KEYFRAME_RULE&quot;);
+shouldBe(&quot;rule.cssText&quot;, &quot;'0% { left: 0px; }'&quot;);
+rule = keyframesFindLast.findRule(&quot;100%&quot;);
+shouldBe(&quot;rule.type&quot;, &quot;window.CSSRule.KEYFRAME_RULE&quot;);
+shouldBe(&quot;rule.cssText&quot;, &quot;'100% { left: 100px; }'&quot;);
+
+debug(&quot;&quot;);
+debug(&quot;deleteRule matching order: from last to first specified&quot;);
+
+var keyframesDeleteLast = document.styleSheets.item(0).cssRules.item(4);
+shouldBe(&quot;keyframesDeleteLast.type&quot;, &quot;window.CSSRule.KEYFRAMES_RULE&quot;);
+shouldBe(&quot;keyframesDeleteLast.name&quot;, &quot;'test-delete-last'&quot;);
+
+var rulesDeleteLast = keyframesDeleteLast.cssRules;
+shouldBe(&quot;rulesDeleteLast.length&quot;, &quot;8&quot;);
+
+keyframesDeleteLast.deleteRule(&quot;10%&quot;);
+shouldBe(&quot;rulesDeleteLast.length&quot;, &quot;7&quot;);
+rule = keyframesDeleteLast.findRule(&quot;10%&quot;);
+shouldBe(&quot;rule.type&quot;, &quot;window.CSSRule.KEYFRAME_RULE&quot;);
+shouldBe(&quot;rule.cssText&quot;, &quot;'10% { left: 10px; }'&quot;);
+keyframesDeleteLast.deleteRule(&quot;10%,20%&quot;);
+shouldBe(&quot;rulesDeleteLast.length&quot;, &quot;6&quot;);
+rule = keyframesDeleteLast.findRule(&quot;10%,20%&quot;);
+shouldBe(&quot;rule.type&quot;, &quot;window.CSSRule.KEYFRAME_RULE&quot;);
+shouldBe(&quot;rule.cssText&quot;, &quot;'10%,20% { left: 1020px; }'&quot;);
+keyframesDeleteLast.deleteRule(&quot;20%, 10% &quot;);
+shouldBe(&quot;rulesDeleteLast.length&quot;, &quot;6&quot;);
+keyframesDeleteLast.deleteRule(&quot;from&quot;);
+shouldBe(&quot;rulesDeleteLast.length&quot;, &quot;5&quot;);
+rule = keyframesDeleteLast.findRule(&quot;from&quot;);
+shouldBe(&quot;rule.type&quot;, &quot;window.CSSRule.KEYFRAME_RULE&quot;);
+shouldBe(&quot;rule.cssText&quot;, &quot;'0% { left: 0px; }'&quot;);
+keyframesDeleteLast.deleteRule(&quot;100%&quot;);
+shouldBe(&quot;rulesDeleteLast.length&quot;, &quot;4&quot;);
+rule = keyframesDeleteLast.findRule(&quot;100%&quot;);
+shouldBe(&quot;rule.type&quot;, &quot;window.CSSRule.KEYFRAME_RULE&quot;);
+shouldBe(&quot;rule.cssText&quot;, &quot;'100% { left: 100px; }'&quot;);
+
+debug(&quot;&quot;);
+
</ins><span class="cx"> &lt;/script&gt;
</span><span class="cx"> &lt;script src=&quot;../resources/js-test-post.js&quot;&gt;&lt;/script&gt;
</span><span class="cx"> &lt;/body&gt;
</span></span></pre></div>
<a id="trunkLayoutTestsanimationsunprefixedkeyframesruleexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/animations/unprefixed-keyframes-rule-expected.txt (179196 => 179197)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/animations/unprefixed-keyframes-rule-expected.txt        2015-01-27 19:16:00 UTC (rev 179196)
+++ trunk/LayoutTests/animations/unprefixed-keyframes-rule-expected.txt        2015-01-27 19:39:22 UTC (rev 179197)
</span><span class="lines">@@ -75,6 +75,41 @@
</span><span class="cx"> PASS rules2.item(0).keyText is '0%'
</span><span class="cx"> PASS rules2.item(1).keyText is '100%'
</span><span class="cx"> 
</span><ins>+findRule matching order: from last to first specified
+PASS keyframesFindLast.type is window.CSSRule.KEYFRAMES_RULE
+PASS keyframesFindLast.name is 'test-find-last'
+PASS rule.type is window.CSSRule.KEYFRAME_RULE
+PASS rule.cssText is '10% { left: 10px; }'
+PASS rule.type is window.CSSRule.KEYFRAME_RULE
+PASS rule.cssText is '10% { left: 10px; }'
+PASS rule.type is window.CSSRule.KEYFRAME_RULE
+FAIL rule.cssText should be 10%,20%  { left: 10px; }. Was 10%,20% { left: 1020px; }.
+PASS rule.type is window.CSSRule.KEYFRAME_RULE
+FAIL rule.cssText should be 10%,20%  { left: 10px; }. Was 10%,20% { left: 1020px; }.
+PASS rule is null
+PASS rule.type is window.CSSRule.KEYFRAME_RULE
+PASS rule.cssText is '0% { left: 0px; }'
+PASS rule.type is window.CSSRule.KEYFRAME_RULE
+PASS rule.cssText is '100% { left: 100px; }'
+
+deleteRule matching order: from last to first specified
+PASS keyframesDeleteLast.type is window.CSSRule.KEYFRAMES_RULE
+PASS keyframesDeleteLast.name is 'test-delete-last'
+PASS rulesDeleteLast.length is 8
+PASS rulesDeleteLast.length is 7
+PASS rule.type is window.CSSRule.KEYFRAME_RULE
+PASS rule.cssText is '10% { left: 10px; }'
+PASS rulesDeleteLast.length is 6
+PASS rule.type is window.CSSRule.KEYFRAME_RULE
+PASS rule.cssText is '10%,20% { left: 1020px; }'
+PASS rulesDeleteLast.length is 6
+PASS rulesDeleteLast.length is 5
+PASS rule.type is window.CSSRule.KEYFRAME_RULE
+PASS rule.cssText is '0% { left: 0px; }'
+PASS rulesDeleteLast.length is 4
+PASS rule.type is window.CSSRule.KEYFRAME_RULE
+PASS rule.cssText is '100% { left: 100px; }'
+
</ins><span class="cx"> PASS successfullyParsed is true
</span><span class="cx"> 
</span><span class="cx"> TEST COMPLETE
</span></span></pre></div>
<a id="trunkLayoutTestsanimationsunprefixedkeyframesrulehtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/animations/unprefixed-keyframes-rule.html (179196 => 179197)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/animations/unprefixed-keyframes-rule.html        2015-01-27 19:16:00 UTC (rev 179196)
+++ trunk/LayoutTests/animations/unprefixed-keyframes-rule.html        2015-01-27 19:39:22 UTC (rev 179197)
</span><span class="lines">@@ -15,6 +15,27 @@
</span><span class="cx">     50% { left: 30px; }
</span><span class="cx">     to { left: 20px; }
</span><span class="cx">   }
</span><ins>+  @keyframes test-find-last {
+    from { left: -1px;  }
+    0% { left: 0px; }
+    10% { left: -1px; }
+    10% { left: 10px;}
+    10%, 20% { left: -1px;   }
+    10%,20% { left: 1020px; }
+    100% { left: -1px; }
+    to { left: 100px; }
+  }
+  @keyframes test-delete-last {
+    from { left: 0px;  }
+    0% { left: -1px; }
+    10% { left: 10px; }
+    10% { left: -1px;}
+    10%, 20% { left: 1020px;   }
+    10%,20% { left: -1px; }
+    100% { left: 100px; }
+    to { left: -1px; }
+  }
+
</ins><span class="cx"> &lt;/style&gt;
</span><span class="cx"> &lt;script src=&quot;../resources/js-test-pre.js&quot;&gt;&lt;/script&gt;
</span><span class="cx"> &lt;/head&gt;
</span><span class="lines">@@ -168,7 +189,69 @@
</span><span class="cx"> shouldBe(&quot;rules2.item(1).keyText&quot;, &quot;'100%'&quot;);
</span><span class="cx"> 
</span><span class="cx"> debug(&quot;&quot;);
</span><ins>+debug(&quot;findRule matching order: from last to first specified&quot;);
</ins><span class="cx"> 
</span><ins>+var keyframesFindLast = document.styleSheets.item(0).cssRules.item(3);
+shouldBe(&quot;keyframesFindLast.type&quot;, &quot;window.CSSRule.KEYFRAMES_RULE&quot;);
+shouldBe(&quot;keyframesFindLast.name&quot;, &quot;'test-find-last'&quot;);
+
+
+rule = keyframesFindLast.findRule(&quot;10%&quot;);
+shouldBe(&quot;rule.type&quot;, &quot;window.CSSRule.KEYFRAME_RULE&quot;);
+shouldBe(&quot;rule.cssText&quot;, &quot;'10% { left: 10px; }'&quot;);
+rule = keyframesFindLast.findRule(&quot;10.0%&quot;);
+shouldBe(&quot;rule.type&quot;, &quot;window.CSSRule.KEYFRAME_RULE&quot;);
+shouldBe(&quot;rule.cssText&quot;, &quot;'10% { left: 10px; }'&quot;);
+rule = keyframesFindLast.findRule(&quot;10%,20%&quot;);
+shouldBe(&quot;rule.type&quot;, &quot;window.CSSRule.KEYFRAME_RULE&quot;);
+shouldBe(&quot;rule.cssText&quot;, &quot;'10%,20%  { left: 10px; }'&quot;);
+rule = keyframesFindLast.findRule(&quot;   10%, 20% &quot;);
+shouldBe(&quot;rule.type&quot;, &quot;window.CSSRule.KEYFRAME_RULE&quot;);
+shouldBe(&quot;rule.cssText&quot;, &quot;'10%,20%  { left: 10px; }'&quot;);
+rule = keyframesFindLast.findRule(&quot;20%, 10% &quot;);
+shouldBe(&quot;rule&quot;, &quot;null&quot;);
+rule = keyframesFindLast.findRule(&quot;from&quot;);
+shouldBe(&quot;rule.type&quot;, &quot;window.CSSRule.KEYFRAME_RULE&quot;);
+shouldBe(&quot;rule.cssText&quot;, &quot;'0% { left: 0px; }'&quot;);
+rule = keyframesFindLast.findRule(&quot;100%&quot;);
+shouldBe(&quot;rule.type&quot;, &quot;window.CSSRule.KEYFRAME_RULE&quot;);
+shouldBe(&quot;rule.cssText&quot;, &quot;'100% { left: 100px; }'&quot;);
+
+debug(&quot;&quot;);
+debug(&quot;deleteRule matching order: from last to first specified&quot;);
+
+var keyframesDeleteLast = document.styleSheets.item(0).cssRules.item(4);
+shouldBe(&quot;keyframesDeleteLast.type&quot;, &quot;window.CSSRule.KEYFRAMES_RULE&quot;);
+shouldBe(&quot;keyframesDeleteLast.name&quot;, &quot;'test-delete-last'&quot;);
+
+var rulesDeleteLast = keyframesDeleteLast.cssRules;
+shouldBe(&quot;rulesDeleteLast.length&quot;, &quot;8&quot;);
+
+keyframesDeleteLast.deleteRule(&quot;10%&quot;);
+shouldBe(&quot;rulesDeleteLast.length&quot;, &quot;7&quot;);
+rule = keyframesDeleteLast.findRule(&quot;10%&quot;);
+shouldBe(&quot;rule.type&quot;, &quot;window.CSSRule.KEYFRAME_RULE&quot;);
+shouldBe(&quot;rule.cssText&quot;, &quot;'10% { left: 10px; }'&quot;);
+keyframesDeleteLast.deleteRule(&quot;10%,20%&quot;);
+shouldBe(&quot;rulesDeleteLast.length&quot;, &quot;6&quot;);
+rule = keyframesDeleteLast.findRule(&quot;10%,20%&quot;);
+shouldBe(&quot;rule.type&quot;, &quot;window.CSSRule.KEYFRAME_RULE&quot;);
+shouldBe(&quot;rule.cssText&quot;, &quot;'10%,20% { left: 1020px; }'&quot;);
+keyframesDeleteLast.deleteRule(&quot;20%, 10% &quot;);
+shouldBe(&quot;rulesDeleteLast.length&quot;, &quot;6&quot;);
+keyframesDeleteLast.deleteRule(&quot;from&quot;);
+shouldBe(&quot;rulesDeleteLast.length&quot;, &quot;5&quot;);
+rule = keyframesDeleteLast.findRule(&quot;from&quot;);
+shouldBe(&quot;rule.type&quot;, &quot;window.CSSRule.KEYFRAME_RULE&quot;);
+shouldBe(&quot;rule.cssText&quot;, &quot;'0% { left: 0px; }'&quot;);
+keyframesDeleteLast.deleteRule(&quot;100%&quot;);
+shouldBe(&quot;rulesDeleteLast.length&quot;, &quot;4&quot;);
+rule = keyframesDeleteLast.findRule(&quot;100%&quot;);
+shouldBe(&quot;rule.type&quot;, &quot;window.CSSRule.KEYFRAME_RULE&quot;);
+shouldBe(&quot;rule.cssText&quot;, &quot;'100% { left: 100px; }'&quot;);
+
+debug(&quot;&quot;);
+
</ins><span class="cx"> &lt;/script&gt;
</span><span class="cx"> &lt;script src=&quot;../resources/js-test-post.js&quot;&gt;&lt;/script&gt;
</span><span class="cx"> &lt;/body&gt;
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (179196 => 179197)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2015-01-27 19:16:00 UTC (rev 179196)
+++ trunk/Source/WebCore/ChangeLog        2015-01-27 19:39:22 UTC (rev 179197)
</span><span class="lines">@@ -1,3 +1,30 @@
</span><ins>+2015-01-26  Sylvain Galineau  &lt;galineau@adobe.com&gt;
+
+        CSSKeyframesRule::findRule() and deleteRule() should delete the last matching rule, not the first
+        https://bugs.webkit.org/show_bug.cgi?id=139732
+
+        Reviewed by Dean Jackson and Darin Adler.
+
+        No new tests because existing tests have been updated to verify this behavior.
+
+        * css/CSSKeyframeRule.h:
+        (WebCore::StyleKeyframe::getKeys): Deleted.
+        * css/StyleResolver.cpp:
+        (WebCore::StyleResolver::keyframeStylesForAnimation): use StyleKeyframe::keys().
+        * css/CSSKeyframeRule.cpp:
+        (WebCore::StyleKeyframe::parseKeyString): Deleted. Moved to CSSParser.
+        (WebCore::StyleKeyframe::keyText): Build keyframe selector from Vector&lt;double&gt; representation.
+        * css/CSSKeyframeRule.h:
+        (WebCore::StyleKeyframe::setKeyText): parse keyframe selector into Vector&lt;double&gt;.
+        (WebCore::StyleKeyframe::keys): Added. Returns vector representation of selector keys.
+        (WebCore::StyleKeyframe::getKeys): Deleted. Now keys().
+        * css/CSSKeyframesRule.cpp:
+        (WebCore::StyleRuleKeyframes::findKeyframeIndex): Return last matching rule.
+        * css/CSSParser.cpp:
+        (WebCore::CSSParser::parseKeyframeSelector): Added. Moved from StyleKeyframe.
+        * css/CSSParser.h:
+        (WebCore::CSSParser::parseKeyframeSelector): Added. Moved from StyleKeyframe.
+
</ins><span class="cx"> 2015-01-26  Geoffrey Garen  &lt;ggaren@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Use FastMalloc (bmalloc) instead of BlockAllocator for GC pages
</span></span></pre></div>
<a id="trunkSourceWebCorecssCSSKeyframeRulecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/CSSKeyframeRule.cpp (179196 => 179197)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/CSSKeyframeRule.cpp        2015-01-27 19:16:00 UTC (rev 179196)
+++ trunk/Source/WebCore/css/CSSKeyframeRule.cpp        2015-01-27 19:39:22 UTC (rev 179197)
</span><span class="lines">@@ -49,33 +49,18 @@
</span><span class="cx">     return downcast&lt;MutableStyleProperties&gt;(m_properties.get());
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-/* static */
-void StyleKeyframe::parseKeyString(const String&amp; s, Vector&lt;double&gt;&amp; keys)
</del><ins>+String StyleKeyframe::keyText() const
</ins><span class="cx"> {
</span><del>-    keys.clear();
-    Vector&lt;String&gt; strings;
-    s.split(',', strings);
</del><ins>+    StringBuilder keyText;
</ins><span class="cx"> 
</span><del>-    for (size_t i = 0; i &lt; strings.size(); ++i) {
-        double 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 == &quot;from&quot;)
-            key = 0;
-        else if (cur == &quot;to&quot;)
-            key = 1;
-        else if (cur.endsWith('%')) {
-            double k = cur.substring(0, cur.length() - 1).toDouble();
-            if (k &gt;= 0 &amp;&amp; k &lt;= 100)
-                key = k / 100;
-        }
-        if (key &lt; 0) {
-            keys.clear();
-            return;
-        }
-        keys.append(key);
</del><ins>+    for (size_t i = 0; i &lt; m_keys.size(); ++i) {
+        if (i)
+            keyText.append(',');
+        keyText.appendNumber(m_keys.at(i) * 100);
+        keyText.append('%');
</ins><span class="cx">     }
</span><ins>+
+    return keyText.toString();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> String StyleKeyframe::cssText() const
</span></span></pre></div>
<a id="trunkSourceWebCorecssCSSKeyframeRuleh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/CSSKeyframeRule.h (179196 => 179197)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/CSSKeyframeRule.h        2015-01-27 19:16:00 UTC (rev 179196)
+++ trunk/Source/WebCore/css/CSSKeyframeRule.h        2015-01-27 19:39:22 UTC (rev 179197)
</span><span class="lines">@@ -26,6 +26,7 @@
</span><span class="cx"> #ifndef CSSKeyframeRule_h
</span><span class="cx"> #define CSSKeyframeRule_h
</span><span class="cx"> 
</span><ins>+#include &quot;CSSParser.h&quot;
</ins><span class="cx"> #include &quot;CSSRule.h&quot;
</span><span class="cx"> #include &quot;StyleProperties.h&quot;
</span><span class="cx"> 
</span><span class="lines">@@ -44,25 +45,21 @@
</span><span class="cx">     }
</span><span class="cx">     ~StyleKeyframe();
</span><span class="cx"> 
</span><del>-    String keyText() const { return m_key; }
-    void setKeyText(const String&amp; s) { m_key = s; }
</del><ins>+    String keyText() const;
+    void setKeyText(const String&amp; text) { m_keys = CSSParser::parseKeyframeSelector(text); }
</ins><span class="cx"> 
</span><del>-    void getKeys(Vector&lt;double&gt;&amp; keys) const   { parseKeyString(m_key, keys); }
-    
</del><ins>+    const Vector&lt;double&gt;&amp; keys() const { return m_keys; };
+
</ins><span class="cx">     const StyleProperties&amp; properties() const { return m_properties; }
</span><span class="cx">     MutableStyleProperties&amp; mutableProperties();
</span><del>-    
</del><ins>+
</ins><span class="cx">     String cssText() const;
</span><span class="cx"> 
</span><span class="cx"> private:
</span><span class="cx">     explicit StyleKeyframe(Ref&lt;StyleProperties&gt;&amp;&amp;);
</span><del>-    
-    static void parseKeyString(const String&amp;, Vector&lt;double&gt;&amp; keys);
-    
</del><ins>+
</ins><span class="cx">     Ref&lt;StyleProperties&gt; m_properties;
</span><del>-    // FIXME: This should be a parsed vector of floats.
-    // comma separated list of keys
-    String m_key;
</del><ins>+    Vector&lt;double&gt; m_keys;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> class CSSKeyframeRule final : public CSSRule {
</span><span class="lines">@@ -73,7 +70,7 @@
</span><span class="cx">     virtual void reattach(StyleRuleBase&amp;) override;
</span><span class="cx"> 
</span><span class="cx">     String keyText() const { return m_keyframe-&gt;keyText(); }
</span><del>-    void setKeyText(const String&amp; s) { m_keyframe-&gt;setKeyText(s); }
</del><ins>+    void setKeyText(const String&amp; text) { m_keyframe-&gt;setKeyText(text); }
</ins><span class="cx"> 
</span><span class="cx">     CSSStyleDeclaration&amp; style();
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCorecssCSSKeyframesRulecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/CSSKeyframesRule.cpp (179196 => 179197)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/CSSKeyframesRule.cpp        2015-01-27 19:16:00 UTC (rev 179196)
+++ trunk/Source/WebCore/css/CSSKeyframesRule.cpp        2015-01-27 19:39:22 UTC (rev 179197)
</span><span class="lines">@@ -72,18 +72,13 @@
</span><span class="cx"> 
</span><span class="cx"> int StyleRuleKeyframes::findKeyframeIndex(const String&amp; key) const
</span><span class="cx"> {
</span><del>-    String percentageString;
-    if (equalIgnoringCase(key, &quot;from&quot;))
-        percentageString = ASCIILiteral(&quot;0%&quot;);
-    else if (equalIgnoringCase(key, &quot;to&quot;))
-        percentageString = ASCIILiteral(&quot;100%&quot;);
-    else
-        percentageString = key;
-    
-    for (unsigned i = 0; i &lt; m_keyframes.size(); ++i) {
-        if (m_keyframes[i]-&gt;keyText() == percentageString)
</del><ins>+    Vector&lt;double&gt;&amp;&amp; keys = CSSParser::parseKeyframeSelector(key);
+
+    for (size_t i = m_keyframes.size(); i--; ) {
+        if (m_keyframes[i]-&gt;keys() == keys)
</ins><span class="cx">             return i;
</span><span class="cx">     }
</span><ins>+
</ins><span class="cx">     return -1;
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCorecssCSSParsercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/CSSParser.cpp (179196 => 179197)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/CSSParser.cpp        2015-01-27 19:16:00 UTC (rev 179196)
+++ trunk/Source/WebCore/css/CSSParser.cpp        2015-01-27 19:39:22 UTC (rev 179197)
</span><span class="lines">@@ -76,6 +76,8 @@
</span><span class="cx"> #include &quot;RenderTheme.h&quot;
</span><span class="cx"> #include &quot;RuntimeEnabledFeatures.h&quot;
</span><span class="cx"> #include &quot;SVGParserUtilities.h&quot;
</span><ins>+#include &quot;SelectorChecker.h&quot;
+#include &quot;SelectorCheckerTestFunctions.h&quot;
</ins><span class="cx"> #include &quot;Settings.h&quot;
</span><span class="cx"> #include &quot;StyleProperties.h&quot;
</span><span class="cx"> #include &quot;StylePropertyShorthand.h&quot;
</span><span class="lines">@@ -4682,6 +4684,36 @@
</span><span class="cx">     return nullptr;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+/* static */
+Vector&lt;double&gt; CSSParser::parseKeyframeSelector(const String&amp; selector) {
+    Vector&lt;double&gt; keys;
+    Vector&lt;String&gt; strings;
+    selector.split(',', strings);
+
+    for (size_t i = 0; i &lt; strings.size(); ++i) {
+        double 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 (equalIgnoringASCIICase(cur, &quot;from&quot;))
+            key = 0;
+        else if (equalIgnoringASCIICase(cur, &quot;to&quot;))
+            key = 1;
+        else if (cur.endsWith('%')) {
+            double k = cur.substring(0, cur.length() - 1).toDouble();
+            if (k &gt;= 0 &amp;&amp; k &lt;= 100)
+                key = k / 100;
+        }
+        if (key &lt; 0) {
+            keys.clear();
+            break;
+        }
+        keys.append(key);
+    }
+
+    return keys;
+}
+
</ins><span class="cx"> bool CSSParser::parseTransformOriginShorthand(RefPtr&lt;CSSValue&gt;&amp; value1, RefPtr&lt;CSSValue&gt;&amp; value2, RefPtr&lt;CSSValue&gt;&amp; value3)
</span><span class="cx"> {
</span><span class="cx">     parse2ValuesFillPosition(*m_valueList, value1, value2);
</span></span></pre></div>
<a id="trunkSourceWebCorecssCSSParserh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/CSSParser.h (179196 => 179197)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/CSSParser.h        2015-01-27 19:16:00 UTC (rev 179196)
+++ trunk/Source/WebCore/css/CSSParser.h        2015-01-27 19:39:22 UTC (rev 179197)
</span><span class="lines">@@ -171,6 +171,7 @@
</span><span class="cx">     PassRefPtr&lt;CSSValue&gt; parseAnimationPlayState();
</span><span class="cx">     PassRefPtr&lt;CSSValue&gt; parseAnimationProperty(AnimationParseContext&amp;);
</span><span class="cx">     PassRefPtr&lt;CSSValue&gt; parseAnimationTimingFunction();
</span><ins>+    static Vector&lt;double&gt; parseKeyframeSelector(const String&amp;);
</ins><span class="cx"> 
</span><span class="cx">     bool parseTransformOriginShorthand(RefPtr&lt;CSSValue&gt;&amp;, RefPtr&lt;CSSValue&gt;&amp;, RefPtr&lt;CSSValue&gt;&amp;);
</span><span class="cx">     bool parseCubicBezierTimingFunctionValue(CSSParserValueList&amp; args, double&amp; result);
</span></span></pre></div>
<a id="trunkSourceWebCorecssStyleResolvercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/StyleResolver.cpp (179196 => 179197)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/StyleResolver.cpp        2015-01-27 19:16:00 UTC (rev 179196)
+++ trunk/Source/WebCore/css/StyleResolver.cpp        2015-01-27 19:39:22 UTC (rev 179197)
</span><span class="lines">@@ -890,10 +890,8 @@
</span><span class="cx">         keyframeValue.setStyle(styleForKeyframe(elementStyle, keyframe, keyframeValue));
</span><span class="cx"> 
</span><span class="cx">         // Add this keyframe style to all the indicated key times
</span><del>-        Vector&lt;double&gt; keys;
-        keyframe-&gt;getKeys(keys);
-        for (size_t keyIndex = 0; keyIndex &lt; keys.size(); ++keyIndex) {
-            keyframeValue.setKey(keys[keyIndex]);
</del><ins>+        for (auto&amp; key: keyframe-&gt;keys()) {
+            keyframeValue.setKey(key);
</ins><span class="cx">             list.insert(keyframeValue);
</span><span class="cx">         }
</span><span class="cx">     }
</span></span></pre>
</div>
</div>

</body>
</html>