Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 1354970 - Add @counter-style rules #16455

Merged
merged 26 commits into from Apr 26, 2017
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
4993a80
Introduce a style::values::CustomIdent type
SimonSapin Apr 14, 2017
d9c2d1a
Use CustomIdent for animation-name and @keyframes
SimonSapin Apr 14, 2017
627c823
Use CustomIdent in counter-increment
SimonSapin Apr 14, 2017
71f9a0c
Fix up unit tests
SimonSapin Apr 14, 2017
5a8e330
Remove some intermediate conversions in style/properties/gecko.mako.rs
SimonSapin Apr 14, 2017
797f40b
Add initial style system support for @counter-style rules
SimonSapin Apr 14, 2017
4477a2d
Add the 'system' descriptor of @counter-style
SimonSapin Apr 14, 2017
d1558a2
Add 'negative' descriptor of @counter-style
SimonSapin Apr 14, 2017
29bcb5b
Add 'prefix' and 'suffix' descriptors for @counter-style
SimonSapin Apr 14, 2017
6f79684
Add 'range' descriptor to @counter-style
SimonSapin Apr 14, 2017
e27de38
Add 'pad' descritor of @counter-style
SimonSapin Apr 14, 2017
0ba5cae
Add 'fallback' descriptor to @counter-style
SimonSapin Apr 14, 2017
fe15663
Add the 'symbols' descriptor for @counter-style
SimonSapin Apr 14, 2017
617e8e9
CSSOM requires @counter-style to keep track of which descriptors were…
SimonSapin Apr 14, 2017
f93a9a4
Don’t make up initial values not in spec for @counter-style descriptors
SimonSapin Apr 14, 2017
62d261a
Add 'additive-symbols' descriptor for @counter-style
SimonSapin Apr 14, 2017
6dc317f
Add speak-as descriptor for @counter-style
SimonSapin Apr 14, 2017
331acfa
Check rule-level @counter-style validity
SimonSapin Apr 14, 2017
ade56bb
Add missing 'additive-symbols' validity checks
SimonSapin Apr 14, 2017
e7a2a98
Make the style::counter_style module a directory
SimonSapin Apr 24, 2017
82c0411
Make predefined counter style names ASCII-lowercase.
SimonSapin Apr 24, 2017
1146921
Keep custom-ident and string separate in animation/keyframes name.
SimonSapin Apr 25, 2017
0ff64bd
Allow 'decimal' and 'none' in `<counter-style-name>`
SimonSapin Apr 25, 2017
be38c9a
Consider `foo` and `"foo"` equal as keyframes/animation names.
SimonSapin Apr 26, 2017
029150c
Exclude 'none' from <counter-style-name> after all.
SimonSapin Apr 26, 2017
1b41900
CSSKeyframesRule::name setter doesn’t throw anymore
SimonSapin Apr 26, 2017
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -12,7 +12,20 @@ use std::path::Path;
fn main() {
let static_atoms = Path::new(&env::var("CARGO_MANIFEST_DIR").unwrap()).join("static_atoms.txt");
let static_atoms = BufReader::new(File::open(&static_atoms).unwrap());
string_cache_codegen::AtomType::new("Atom", "atom!")
let mut atom_type = string_cache_codegen::AtomType::new("Atom", "atom!");

macro_rules! predefined {
($($name: expr,)+) => {
{
$(
atom_type.atom($name);
)+
}
}
}
include!("../style/counter_style/predefined.rs");

atom_type
.atoms(static_atoms.lines().map(Result::unwrap))
.write_to_file(&Path::new(&env::var("OUT_DIR").unwrap()).join("atom.rs"))
.unwrap();
@@ -8,6 +8,8 @@ left
center
right

none

hidden
submit
button
@@ -273,25 +273,27 @@ impl<'a,'b> ResolveGeneratedContentFragmentMutator<'a,'b> {
self.traversal.list_item.truncate_to_level(self.level);

for &(ref counter_name, value) in &fragment.style().get_counters().counter_reset.0 {
let counter_name = &*counter_name.0;
if let Some(ref mut counter) = self.traversal.counters.get_mut(counter_name) {
counter.reset(self.level, value);
continue
}

let mut counter = Counter::new();
counter.reset(self.level, value);
self.traversal.counters.insert((*counter_name).clone(), counter);
self.traversal.counters.insert(counter_name.to_owned(), counter);
}

for &(ref counter_name, value) in &fragment.style().get_counters().counter_increment.0 {
let counter_name = &*counter_name.0;
if let Some(ref mut counter) = self.traversal.counters.get_mut(counter_name) {
counter.increment(self.level, value);
continue
}

let mut counter = Counter::new();
counter.increment(self.level, value);
self.traversal.counters.insert((*counter_name).clone(), counter);
self.traversal.counters.insert(counter_name.to_owned(), counter);
}

self.incremented = true
@@ -5,7 +5,7 @@
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::error::ErrorResult;
use dom::bindings::inheritance::Castable;
use dom::bindings::js::{MutNullableJS, Root};
use dom::bindings::reflector::{DomObject, reflect_dom_object};
@@ -16,11 +16,11 @@ use dom::cssrulelist::{CSSRuleList, RulesSource};
use dom::cssstylesheet::CSSStyleSheet;
use dom::window::Window;
use dom_struct::dom_struct;
use servo_atoms::Atom;
use std::sync::Arc;
use style::keyframes::{Keyframe, KeyframeSelector};
use style::shared_lock::{Locked, ToCssWithGuard};
use style::stylesheets::KeyframesRule;
use style::values::KeyframesName;

#[dom_struct]
pub struct CSSKeyframesRule {
@@ -107,23 +107,17 @@ impl CSSKeyframesRuleMethods for CSSKeyframesRule {
// https://drafts.csswg.org/css-animations/#dom-csskeyframesrule-name
fn Name(&self) -> DOMString {
let guard = self.cssrule.shared_lock().read();
DOMString::from(&*self.keyframesrule.read_with(&guard).name)
DOMString::from(&**self.keyframesrule.read_with(&guard).name.as_atom())
}

// 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),
_ => ()
}
// Spec deviation: https://github.com/w3c/csswg-drafts/issues/801
// Setting this property to a CSS-wide keyword or `none` does not throw,
// it stores a value that serializes as a quoted string.
let name = KeyframesName::from_ident(value.into());
let mut guard = self.cssrule.shared_lock().write();
self.keyframesrule.write_with(&mut guard).name = Atom::from(value);
self.keyframesrule.write_with(&mut guard).name = name;
Ok(())
}
}
@@ -78,6 +78,7 @@ impl CSSRule {
StyleCssRule::Import(s) => Root::upcast(CSSImportRule::new(window, parent_stylesheet, s)),
StyleCssRule::Style(s) => Root::upcast(CSSStyleRule::new(window, parent_stylesheet, s)),
StyleCssRule::FontFace(s) => Root::upcast(CSSFontFaceRule::new(window, parent_stylesheet, s)),
StyleCssRule::CounterStyle(_) => unimplemented!(),
StyleCssRule::Keyframes(s) => Root::upcast(CSSKeyframesRule::new(window, parent_stylesheet, s)),
StyleCssRule::Media(s) => Root::upcast(CSSMediaRule::new(window, parent_stylesheet, s)),
StyleCssRule::Namespace(s) => Root::upcast(CSSNamespaceRule::new(window, parent_stylesheet, s)),
@@ -464,13 +464,19 @@ pub fn maybe_start_animations(context: &SharedStyleContext,

let box_style = new_style.get_box();
for (i, name) in box_style.animation_name_iter().enumerate() {
let name = if let Some(atom) = name.as_atom() {
atom
} else {
continue
};

debug!("maybe_start_animations: name={}", name);
let total_duration = box_style.animation_duration_mod(i).seconds();
if total_duration == 0. {
continue
}

if let Some(ref anim) = context.stylist.animations().get(&name.0) {
if let Some(ref anim) = context.stylist.animations().get(name) {
debug!("maybe_start_animations: animation {} found", name);

// If this animation doesn't have any keyframe, we can just continue
@@ -506,7 +512,7 @@ pub fn maybe_start_animations(context: &SharedStyleContext,


new_animations_sender
.send(Animation::Keyframes(node, name.0.clone(), KeyframesAnimationState {
.send(Animation::Keyframes(node, name.clone(), KeyframesAnimationState {
started_at: animation_start,
duration: duration as f64,
delay: delay as f64,
@@ -584,9 +590,10 @@ pub fn update_style_for_animation(context: &SharedStyleContext,

debug_assert!(!animation.steps.is_empty());

let maybe_index = style.get_box()
.animation_name_iter()
.position(|animation_name| *name == animation_name.0);
let maybe_index = style
.get_box()
.animation_name_iter()
.position(|animation_name| Some(name) == animation_name.as_atom());

let index = match maybe_index {
Some(index) => index,
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.