servo: Merge #14576 - Implement CSSKeyframesRule.name (from canaltinova:keyframes-name); r=Manishearth,emilio
authorNazım Can Altınova <canaltinova@gmail.com>
Wed, 14 Dec 2016 03:37:45 -0800
changeset 478501 93b1445bc137f128bbf05a4c532ad5bd0e4d7169
parent 478500 3d8ed74143f3093285641719434a448760406f1e
child 478502 4f041c806f946dd5f869d3a05449b71bb6b89210
push id44079
push userbmo:gps@mozilla.com
push dateSat, 04 Feb 2017 00:14:49 +0000
reviewersManishearth, emilio
servo: Merge #14576 - Implement CSSKeyframesRule.name (from canaltinova:keyframes-name); r=Manishearth,emilio <!-- Please describe your changes on the following line: --> Implementation of CSSKeyframesRule.name --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors <!-- Either: --> - [X] There are tests for these changes <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Source-Repo: https://github.com/servo/servo Source-Revision: a2391162a12c5cfa00872ead33a1551d82c46594
servo/components/script/dom/csskeyframesrule.rs
servo/components/script/dom/webidls/CSSKeyframesRule.webidl
--- a/servo/components/script/dom/csskeyframesrule.rs
+++ b/servo/components/script/dom/csskeyframesrule.rs
@@ -1,25 +1,27 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 use cssparser::Parser;
 use dom::bindings::codegen::Bindings::CSSKeyframesRuleBinding;
 use dom::bindings::codegen::Bindings::CSSKeyframesRuleBinding::CSSKeyframesRuleMethods;
+use dom::bindings::error::{Error, ErrorResult};
 use dom::bindings::inheritance::Castable;
 use dom::bindings::js::{MutNullableJS, Root};
 use dom::bindings::reflector::{DomObject, reflect_dom_object};
 use dom::bindings::str::DOMString;
 use dom::csskeyframerule::CSSKeyframeRule;
 use dom::cssrule::{CSSRule, SpecificCSSRule};
 use dom::cssrulelist::{CSSRuleList, RulesSource};
 use dom::cssstylesheet::CSSStyleSheet;
 use dom::window::Window;
 use parking_lot::RwLock;
+use servo_atoms::Atom;
 use std::sync::Arc;
 use style::keyframes::{Keyframe, KeyframeSelector};
 use style::parser::ParserContextExtraData;
 use style::stylesheets::KeyframesRule;
 use style_traits::ToCss;
 
 #[dom_struct]
 pub struct CSSKeyframesRule {
@@ -96,16 +98,37 @@ impl CSSKeyframesRuleMethods for CSSKeyf
     }
 
     // https://drafts.csswg.org/css-animations/#dom-csskeyframesrule-findrule
     fn FindRule(&self, selector: DOMString) -> Option<Root<CSSKeyframeRule>> {
         self.find_rule(&selector).and_then(|idx| {
             self.rulelist().item(idx as u32)
         }).and_then(Root::downcast)
     }
+
+    // https://drafts.csswg.org/css-animations/#dom-csskeyframesrule-name
+    fn Name(&self) -> DOMString {
+        DOMString::from(&*self.keyframesrule.read().name)
+    }
+
+    // https://drafts.csswg.org/css-animations/#dom-csskeyframesrule-name
+    fn SetName(&self, value: DOMString) -> ErrorResult {
+        // https://github.com/w3c/csswg-drafts/issues/801
+        // Setting this property to a CSS-wide keyword or `none` will
+        // throw a Syntax Error.
+        match_ignore_ascii_case! { value,
+            "initial" => return Err(Error::Syntax),
+            "inherit" => return Err(Error::Syntax),
+            "unset" => return Err(Error::Syntax),
+            "none" => return Err(Error::Syntax),
+            _ => ()
+        }
+        self.keyframesrule.write().name = Atom::from(value);
+        Ok(())
+    }
 }
 
 impl SpecificCSSRule for CSSKeyframesRule {
     fn ty(&self) -> u16 {
         use dom::bindings::codegen::Bindings::CSSRuleBinding::CSSRuleConstants;
         CSSRuleConstants::KEYFRAMES_RULE
     }
 
--- a/servo/components/script/dom/webidls/CSSKeyframesRule.webidl
+++ b/servo/components/script/dom/webidls/CSSKeyframesRule.webidl
@@ -1,14 +1,15 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 // https://drafts.csswg.org/css-animations/#interface-csskeyframesrule
 [Exposed=Window]
 interface CSSKeyframesRule : CSSRule {
-  //          attribute DOMString   name;
+  [SetterThrows]
+           attribute DOMString   name;
   readonly attribute CSSRuleList cssRules;
 
   void            appendRule(DOMString rule);
   void            deleteRule(DOMString select);
   CSSKeyframeRule? findRule(DOMString select);
 };