2013-09-04 17:00:52 +00:00
|
|
|
|
/* 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/. */
|
|
|
|
|
|
2016-06-27 22:14:55 +00:00
|
|
|
|
//! Style sheets and their CSS rules.
|
|
|
|
|
|
servo: Merge #14043 - Update to string-cache 0.3 (from servo:string-cache-up); r=nox
Previously, `string-cache` defined:
* An string-like `Atom` type,
* An `atom!("foo")` macro that expands to a value of that type, for a set of strings known at compile-time,
* A `struct Namespace(Atom);` type
* A `ns!(html)` macro that maps known prefixed to `Namespace` values with the corresponding namespace URL.
Adding a string to the static set required making a change to the `string-cache` crate.
With 0.3, the `Atom` type is now generic, with a type parameter that provides a set of static strings. We can have multiple such sets, defined in different crates. The `string_cache_codegen` crate, to be used in build scripts, generates code that defines such a set, a new atom type (a type alias for `Atom<_>` with the type parameter set), and an `atom!`-like macro.
The html5ever repository has a new `html5ever_atoms` crate that defines three such types: `Prefix`, `Namespace`, and `LocalName` (with respective `namespace_prefix!`, `namespace_url!`, and `local_name!` macros). It also defines the `ns!` macro like before.
This repository has a new `servo_atoms` crate in `components/atoms` that, for now, defines a single `Atom` type (and `atom!`) macro. (`servo_atoms::Atom` is defined as something like `type Atom = string_cache::Atom<ServoStaticStringSet>;`, so overall there’s now two types named `Atom`.)
In this PR, `servo_atoms::Atom` is used for everything else that was `string_cache::Atom` before. But more atom types can be defined as needed. Two reasons to do this are to auto-generate the set of static strings (I’m planning to do this for CSS property names, which is the motivation for this change), or to have the type system help us avoid mix up unrelated things (this is why we had a `Namespace` type ever before this change).
Introducing new types helped me find a bug: when creating a new attribute `dom::Element::set_style_attr`, would pass `Some(atom!("style"))` instead of `None` (now `Option<html5ever_atoms::Prefix>` instead of `Option<string_cache::Atom>`) to the `prefix` argument of `Attr::new`. I suppose the author of that code confused it with the `local_name` argument.
---
Note that Stylo is not affected by any of this. The `gecko_string_cache` module is unchanged, with a single `Atom` type. The `style` crate conditionally compiles `Prefix` and `LocalName` re-exports for that are both `gecko_string_cache::Atom` on stylo.
---
<!-- 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
- [ ] These changes fix #__ (github issue number if applicable).
<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____
<!-- 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: 5b4cc9568dbd5c15e5d2fbc62719172f11566ffa
2016-11-03 16:19:44 +00:00
|
|
|
|
use {Atom, Prefix, Namespace};
|
2015-09-23 21:02:56 +00:00
|
|
|
|
use cssparser::{AtRuleParser, Parser, QualifiedRuleParser, decode_stylesheet_bytes};
|
servo: Merge #11766 - Add `@keyframes` and `animation-*` support (from emilio:keyframes-parsing); r=SimonSapin,pcwalton
- [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. -->
This adds support for parsing `@keyframes` rules, and animation properties. Stylo will need it sometime soonish, plus I want to make animations work in Servo.
The remaining part is doin the math and trigger the animations correctly from servo. I don't expect it to be *that* hard, but probaby I'll need to learn a bit more about the current animation infra (e.g. why the heck is the `new_animations_sender` guarded by a `Mutex`?).
I'd expect to land this, since this is already a bunch of work, this is the part exclusively required by stylo (at least if we don't use Servo's machinery), the media query parsing is tested, and the properties land after a flag, but if you prefer to wait until I finish this up it's fine for me too.
r? @SimonSapin
cc @pcwalton @bholley
Source-Repo: https://github.com/servo/servo
Source-Revision: d3a81373e44634c30d31da0457e1c1e86c0911ed
2016-06-28 22:31:01 +00:00
|
|
|
|
use cssparser::{AtRuleType, RuleListParser, Token};
|
2016-11-16 21:05:59 +00:00
|
|
|
|
use cssparser::ToCss as ParserToCss;
|
2015-09-19 19:34:51 +00:00
|
|
|
|
use encoding::EncodingRef;
|
2016-01-12 03:53:31 +00:00
|
|
|
|
use error_reporting::ParseErrorReporter;
|
2015-08-20 13:43:56 +00:00
|
|
|
|
use font_face::{FontFaceRule, parse_font_face_block};
|
servo: Merge #11766 - Add `@keyframes` and `animation-*` support (from emilio:keyframes-parsing); r=SimonSapin,pcwalton
- [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. -->
This adds support for parsing `@keyframes` rules, and animation properties. Stylo will need it sometime soonish, plus I want to make animations work in Servo.
The remaining part is doin the math and trigger the animations correctly from servo. I don't expect it to be *that* hard, but probaby I'll need to learn a bit more about the current animation infra (e.g. why the heck is the `new_animations_sender` guarded by a `Mutex`?).
I'd expect to land this, since this is already a bunch of work, this is the part exclusively required by stylo (at least if we don't use Servo's machinery), the media query parsing is tested, and the properties land after a flag, but if you prefer to wait until I finish this up it's fine for me too.
r? @SimonSapin
cc @pcwalton @bholley
Source-Repo: https://github.com/servo/servo
Source-Revision: d3a81373e44634c30d31da0457e1c1e86c0911ed
2016-06-28 22:31:01 +00:00
|
|
|
|
use keyframes::{Keyframe, parse_keyframe_list};
|
2016-11-08 07:46:40 +00:00
|
|
|
|
use media_queries::{Device, MediaList, parse_media_query_list};
|
2016-10-04 16:58:56 +00:00
|
|
|
|
use parking_lot::RwLock;
|
2016-05-24 21:41:04 +00:00
|
|
|
|
use parser::{ParserContext, ParserContextExtraData, log_css_error};
|
2015-01-21 21:27:48 +00:00
|
|
|
|
use properties::{PropertyDeclarationBlock, parse_property_declaration_list};
|
servo: Merge #12515 - Make the style crate more concrete (from servo:concrete-style); r=bholley
Background:
The changes to Servo code to support Stylo began in the `selectors` crate with making pseudo-elements generic, defined be the user, so that different users (such as Servo and Gecko/Stylo) could have a different set of pseudo-elements supported and parsed. Adding a trait makes sense there since `selectors` is in its own repository and has others users (or at least [one](https://github.com/SimonSapin/kuchiki)).
Then we kind of kept going with the same pattern and added a bunch of traits in the `style` crate to make everything generic, allowing Servo and Gecko/Stylo to do things differently. But we’ve also added a `gecko` Cargo feature to do conditional compilation, at first to enable or disable some CSS properties and values in the Mako templates. Since we’re doing conditional compilation anyway, it’s often easier and simpler to do it more (with `#[cfg(feature = "gecko")]` and `#[cfg(feature = "servo")]`) that to keep adding traits and making everything generic. When a type is generic, any method that we want to call on it needs to be part of some trait.
----
The first several commits move some code around, mostly from `geckolib` to `style` (with `#[cfg(feature = "gecko")]`) but otherwise don’t change much.
The following commits remove some traits and many type parameters through the `style` crate, replacing them with pairs of conditionally-compiled API-compatible items (types, methods, …).
Simplifying code is nice to make it more maintainable, but this is motivated by another change described in https://github.com/servo/servo/pull/12391#issuecomment-232183942. (Porting Servo for that change proved difficult because some code in the `style` crate was becoming generic over `String` vs `Atom`, and this PR will help make that concrete. That change, in turn, is motivated by removing geckolib’s `[replace]` override for string-cache, in order to enable using a single Cargo "workspace" in this repository.)
r? @bholley
---
<!-- 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
- [x] These changes fix #__ (github issue number if applicable).
<!-- Either: -->
- [ ] There are tests for these changes OR
- [x] These changes do not require new tests because refactoring
<!-- 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: 2d01d41a506bcbc7f26a2284b9f42390d6ef96ab
--HG--
rename : servo/ports/geckolib/selector_impl.rs => servo/components/style/gecko_selector_impl.rs
rename : servo/ports/geckolib/values.rs => servo/components/style/gecko_values.rs
rename : servo/ports/geckolib/properties.mako.rs => servo/components/style/properties/gecko.mako.rs
2016-07-20 07:58:34 +00:00
|
|
|
|
use selector_impl::TheSelectorImpl;
|
|
|
|
|
use selectors::parser::{Selector, parse_selector_list};
|
2016-11-17 21:34:47 +00:00
|
|
|
|
use servo_url::ServoUrl;
|
2015-09-19 19:34:51 +00:00
|
|
|
|
use std::cell::Cell;
|
2016-11-16 21:05:59 +00:00
|
|
|
|
use std::fmt;
|
2016-08-31 21:30:56 +00:00
|
|
|
|
use std::sync::Arc;
|
2016-11-16 21:05:59 +00:00
|
|
|
|
use style_traits::ToCss;
|
2015-05-06 17:41:09 +00:00
|
|
|
|
use viewport::ViewportRule;
|
2013-09-04 17:00:52 +00:00
|
|
|
|
|
2015-11-26 22:26:08 +00:00
|
|
|
|
|
2015-04-18 10:44:50 +00:00
|
|
|
|
/// Each style rule has an origin, which determines where it enters the cascade.
|
|
|
|
|
///
|
|
|
|
|
/// http://dev.w3.org/csswg/css-cascade/#cascading-origins
|
2016-06-22 14:43:20 +00:00
|
|
|
|
#[derive(Clone, PartialEq, Eq, Copy, Debug)]
|
|
|
|
|
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
2015-01-21 21:27:48 +00:00
|
|
|
|
pub enum Origin {
|
2015-04-18 10:44:50 +00:00
|
|
|
|
/// http://dev.w3.org/csswg/css-cascade/#cascade-origin-ua
|
2015-01-21 21:27:48 +00:00
|
|
|
|
UserAgent,
|
2015-04-18 10:44:50 +00:00
|
|
|
|
|
|
|
|
|
/// http://dev.w3.org/csswg/css-cascade/#cascade-origin-author
|
2015-01-21 21:27:48 +00:00
|
|
|
|
Author,
|
2015-04-18 10:44:50 +00:00
|
|
|
|
|
|
|
|
|
/// http://dev.w3.org/csswg/css-cascade/#cascade-origin-user
|
2015-01-21 21:27:48 +00:00
|
|
|
|
User,
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-16 21:05:59 +00:00
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
|
pub struct CssRules(pub Arc<RwLock<Vec<CssRule>>>);
|
|
|
|
|
|
|
|
|
|
impl From<Vec<CssRule>> for CssRules {
|
|
|
|
|
fn from(other: Vec<CssRule>) -> Self {
|
|
|
|
|
CssRules(Arc::new(RwLock::new(other)))
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-01-21 21:27:48 +00:00
|
|
|
|
|
2016-10-04 16:58:56 +00:00
|
|
|
|
#[derive(Debug)]
|
servo: Merge #12515 - Make the style crate more concrete (from servo:concrete-style); r=bholley
Background:
The changes to Servo code to support Stylo began in the `selectors` crate with making pseudo-elements generic, defined be the user, so that different users (such as Servo and Gecko/Stylo) could have a different set of pseudo-elements supported and parsed. Adding a trait makes sense there since `selectors` is in its own repository and has others users (or at least [one](https://github.com/SimonSapin/kuchiki)).
Then we kind of kept going with the same pattern and added a bunch of traits in the `style` crate to make everything generic, allowing Servo and Gecko/Stylo to do things differently. But we’ve also added a `gecko` Cargo feature to do conditional compilation, at first to enable or disable some CSS properties and values in the Mako templates. Since we’re doing conditional compilation anyway, it’s often easier and simpler to do it more (with `#[cfg(feature = "gecko")]` and `#[cfg(feature = "servo")]`) that to keep adding traits and making everything generic. When a type is generic, any method that we want to call on it needs to be part of some trait.
----
The first several commits move some code around, mostly from `geckolib` to `style` (with `#[cfg(feature = "gecko")]`) but otherwise don’t change much.
The following commits remove some traits and many type parameters through the `style` crate, replacing them with pairs of conditionally-compiled API-compatible items (types, methods, …).
Simplifying code is nice to make it more maintainable, but this is motivated by another change described in https://github.com/servo/servo/pull/12391#issuecomment-232183942. (Porting Servo for that change proved difficult because some code in the `style` crate was becoming generic over `String` vs `Atom`, and this PR will help make that concrete. That change, in turn, is motivated by removing geckolib’s `[replace]` override for string-cache, in order to enable using a single Cargo "workspace" in this repository.)
r? @bholley
---
<!-- 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
- [x] These changes fix #__ (github issue number if applicable).
<!-- Either: -->
- [ ] There are tests for these changes OR
- [x] These changes do not require new tests because refactoring
<!-- 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: 2d01d41a506bcbc7f26a2284b9f42390d6ef96ab
--HG--
rename : servo/ports/geckolib/selector_impl.rs => servo/components/style/gecko_selector_impl.rs
rename : servo/ports/geckolib/values.rs => servo/components/style/gecko_values.rs
rename : servo/ports/geckolib/properties.mako.rs => servo/components/style/properties/gecko.mako.rs
2016-07-20 07:58:34 +00:00
|
|
|
|
pub struct Stylesheet {
|
2013-11-14 04:13:34 +00:00
|
|
|
|
/// List of rules in the order they were found (important for
|
|
|
|
|
/// cascading order)
|
2016-11-16 21:05:59 +00:00
|
|
|
|
pub rules: CssRules,
|
2016-11-10 07:37:57 +00:00
|
|
|
|
/// List of media associated with the Stylesheet.
|
|
|
|
|
pub media: MediaList,
|
2015-01-21 21:27:48 +00:00
|
|
|
|
pub origin: Origin,
|
2016-03-19 20:50:54 +00:00
|
|
|
|
pub dirty_on_viewport_size_change: bool,
|
2013-09-04 17:00:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2016-08-23 13:34:04 +00:00
|
|
|
|
/// This structure holds the user-agent and user stylesheets.
|
|
|
|
|
pub struct UserAgentStylesheets {
|
|
|
|
|
pub user_or_user_agent_stylesheets: Vec<Stylesheet>,
|
|
|
|
|
pub quirks_mode_stylesheet: Stylesheet,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2016-11-16 21:05:59 +00:00
|
|
|
|
#[derive(Debug, Clone)]
|
2016-11-14 09:36:37 +00:00
|
|
|
|
pub enum CssRule {
|
2016-08-31 21:30:56 +00:00
|
|
|
|
// No Charset here, CSSCharsetRule has been removed from CSSOM
|
|
|
|
|
// https://drafts.csswg.org/cssom/#changes-from-5-december-2013
|
|
|
|
|
|
2016-10-20 16:29:27 +00:00
|
|
|
|
Namespace(Arc<RwLock<NamespaceRule>>),
|
|
|
|
|
Style(Arc<RwLock<StyleRule>>),
|
|
|
|
|
Media(Arc<RwLock<MediaRule>>),
|
|
|
|
|
FontFace(Arc<RwLock<FontFaceRule>>),
|
|
|
|
|
Viewport(Arc<RwLock<ViewportRule>>),
|
|
|
|
|
Keyframes(Arc<RwLock<KeyframesRule>>),
|
servo: Merge #11766 - Add `@keyframes` and `animation-*` support (from emilio:keyframes-parsing); r=SimonSapin,pcwalton
- [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. -->
This adds support for parsing `@keyframes` rules, and animation properties. Stylo will need it sometime soonish, plus I want to make animations work in Servo.
The remaining part is doin the math and trigger the animations correctly from servo. I don't expect it to be *that* hard, but probaby I'll need to learn a bit more about the current animation infra (e.g. why the heck is the `new_animations_sender` guarded by a `Mutex`?).
I'd expect to land this, since this is already a bunch of work, this is the part exclusively required by stylo (at least if we don't use Servo's machinery), the media query parsing is tested, and the properties land after a flag, but if you prefer to wait until I finish this up it's fine for me too.
r? @SimonSapin
cc @pcwalton @bholley
Source-Repo: https://github.com/servo/servo
Source-Revision: d3a81373e44634c30d31da0457e1c1e86c0911ed
2016-06-28 22:31:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-14 09:36:37 +00:00
|
|
|
|
impl CssRule {
|
2016-10-20 16:29:27 +00:00
|
|
|
|
/// Call `f` with the slice of rules directly contained inside this rule.
|
|
|
|
|
///
|
|
|
|
|
/// Note that only some types of rules can contain rules. An empty slice is used for others.
|
|
|
|
|
pub fn with_nested_rules_and_mq<F, R>(&self, mut f: F) -> R
|
2016-11-14 09:36:37 +00:00
|
|
|
|
where F: FnMut(&[CssRule], Option<&MediaList>) -> R {
|
2016-10-20 16:29:27 +00:00
|
|
|
|
match *self {
|
2016-11-14 09:36:37 +00:00
|
|
|
|
CssRule::Namespace(_) |
|
|
|
|
|
CssRule::Style(_) |
|
|
|
|
|
CssRule::FontFace(_) |
|
|
|
|
|
CssRule::Viewport(_) |
|
|
|
|
|
CssRule::Keyframes(_) => {
|
2016-10-20 16:29:27 +00:00
|
|
|
|
f(&[], None)
|
|
|
|
|
}
|
2016-11-14 09:36:37 +00:00
|
|
|
|
CssRule::Media(ref lock) => {
|
2016-10-20 16:29:27 +00:00
|
|
|
|
let media_rule = lock.read();
|
|
|
|
|
let mq = media_rule.media_queries.read();
|
2016-11-16 21:05:59 +00:00
|
|
|
|
let rules = media_rule.rules.0.read();
|
|
|
|
|
f(&rules, Some(&mq))
|
2016-10-20 16:29:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
servo: Merge #11766 - Add `@keyframes` and `animation-*` support (from emilio:keyframes-parsing); r=SimonSapin,pcwalton
- [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. -->
This adds support for parsing `@keyframes` rules, and animation properties. Stylo will need it sometime soonish, plus I want to make animations work in Servo.
The remaining part is doin the math and trigger the animations correctly from servo. I don't expect it to be *that* hard, but probaby I'll need to learn a bit more about the current animation infra (e.g. why the heck is the `new_animations_sender` guarded by a `Mutex`?).
I'd expect to land this, since this is already a bunch of work, this is the part exclusively required by stylo (at least if we don't use Servo's machinery), the media query parsing is tested, and the properties land after a flag, but if you prefer to wait until I finish this up it's fine for me too.
r? @SimonSapin
cc @pcwalton @bholley
Source-Repo: https://github.com/servo/servo
Source-Revision: d3a81373e44634c30d31da0457e1c1e86c0911ed
2016-06-28 22:31:01 +00:00
|
|
|
|
|
2016-08-31 21:30:56 +00:00
|
|
|
|
#[derive(Debug, PartialEq)]
|
|
|
|
|
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
|
|
|
|
pub struct NamespaceRule {
|
|
|
|
|
/// `None` for the default Namespace
|
servo: Merge #14043 - Update to string-cache 0.3 (from servo:string-cache-up); r=nox
Previously, `string-cache` defined:
* An string-like `Atom` type,
* An `atom!("foo")` macro that expands to a value of that type, for a set of strings known at compile-time,
* A `struct Namespace(Atom);` type
* A `ns!(html)` macro that maps known prefixed to `Namespace` values with the corresponding namespace URL.
Adding a string to the static set required making a change to the `string-cache` crate.
With 0.3, the `Atom` type is now generic, with a type parameter that provides a set of static strings. We can have multiple such sets, defined in different crates. The `string_cache_codegen` crate, to be used in build scripts, generates code that defines such a set, a new atom type (a type alias for `Atom<_>` with the type parameter set), and an `atom!`-like macro.
The html5ever repository has a new `html5ever_atoms` crate that defines three such types: `Prefix`, `Namespace`, and `LocalName` (with respective `namespace_prefix!`, `namespace_url!`, and `local_name!` macros). It also defines the `ns!` macro like before.
This repository has a new `servo_atoms` crate in `components/atoms` that, for now, defines a single `Atom` type (and `atom!`) macro. (`servo_atoms::Atom` is defined as something like `type Atom = string_cache::Atom<ServoStaticStringSet>;`, so overall there’s now two types named `Atom`.)
In this PR, `servo_atoms::Atom` is used for everything else that was `string_cache::Atom` before. But more atom types can be defined as needed. Two reasons to do this are to auto-generate the set of static strings (I’m planning to do this for CSS property names, which is the motivation for this change), or to have the type system help us avoid mix up unrelated things (this is why we had a `Namespace` type ever before this change).
Introducing new types helped me find a bug: when creating a new attribute `dom::Element::set_style_attr`, would pass `Some(atom!("style"))` instead of `None` (now `Option<html5ever_atoms::Prefix>` instead of `Option<string_cache::Atom>`) to the `prefix` argument of `Attr::new`. I suppose the author of that code confused it with the `local_name` argument.
---
Note that Stylo is not affected by any of this. The `gecko_string_cache` module is unchanged, with a single `Atom` type. The `style` crate conditionally compiles `Prefix` and `LocalName` re-exports for that are both `gecko_string_cache::Atom` on stylo.
---
<!-- 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
- [ ] These changes fix #__ (github issue number if applicable).
<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____
<!-- 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: 5b4cc9568dbd5c15e5d2fbc62719172f11566ffa
2016-11-03 16:19:44 +00:00
|
|
|
|
pub prefix: Option<Prefix>,
|
2016-08-31 21:30:56 +00:00
|
|
|
|
pub url: Namespace,
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-04 16:58:56 +00:00
|
|
|
|
#[derive(Debug)]
|
servo: Merge #11766 - Add `@keyframes` and `animation-*` support (from emilio:keyframes-parsing); r=SimonSapin,pcwalton
- [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. -->
This adds support for parsing `@keyframes` rules, and animation properties. Stylo will need it sometime soonish, plus I want to make animations work in Servo.
The remaining part is doin the math and trigger the animations correctly from servo. I don't expect it to be *that* hard, but probaby I'll need to learn a bit more about the current animation infra (e.g. why the heck is the `new_animations_sender` guarded by a `Mutex`?).
I'd expect to land this, since this is already a bunch of work, this is the part exclusively required by stylo (at least if we don't use Servo's machinery), the media query parsing is tested, and the properties land after a flag, but if you prefer to wait until I finish this up it's fine for me too.
r? @SimonSapin
cc @pcwalton @bholley
Source-Repo: https://github.com/servo/servo
Source-Revision: d3a81373e44634c30d31da0457e1c1e86c0911ed
2016-06-28 22:31:01 +00:00
|
|
|
|
pub struct KeyframesRule {
|
|
|
|
|
pub name: Atom,
|
2016-10-20 16:29:27 +00:00
|
|
|
|
pub keyframes: Vec<Arc<RwLock<Keyframe>>>,
|
2013-09-04 17:00:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-04 16:58:56 +00:00
|
|
|
|
#[derive(Debug)]
|
servo: Merge #12515 - Make the style crate more concrete (from servo:concrete-style); r=bholley
Background:
The changes to Servo code to support Stylo began in the `selectors` crate with making pseudo-elements generic, defined be the user, so that different users (such as Servo and Gecko/Stylo) could have a different set of pseudo-elements supported and parsed. Adding a trait makes sense there since `selectors` is in its own repository and has others users (or at least [one](https://github.com/SimonSapin/kuchiki)).
Then we kind of kept going with the same pattern and added a bunch of traits in the `style` crate to make everything generic, allowing Servo and Gecko/Stylo to do things differently. But we’ve also added a `gecko` Cargo feature to do conditional compilation, at first to enable or disable some CSS properties and values in the Mako templates. Since we’re doing conditional compilation anyway, it’s often easier and simpler to do it more (with `#[cfg(feature = "gecko")]` and `#[cfg(feature = "servo")]`) that to keep adding traits and making everything generic. When a type is generic, any method that we want to call on it needs to be part of some trait.
----
The first several commits move some code around, mostly from `geckolib` to `style` (with `#[cfg(feature = "gecko")]`) but otherwise don’t change much.
The following commits remove some traits and many type parameters through the `style` crate, replacing them with pairs of conditionally-compiled API-compatible items (types, methods, …).
Simplifying code is nice to make it more maintainable, but this is motivated by another change described in https://github.com/servo/servo/pull/12391#issuecomment-232183942. (Porting Servo for that change proved difficult because some code in the `style` crate was becoming generic over `String` vs `Atom`, and this PR will help make that concrete. That change, in turn, is motivated by removing geckolib’s `[replace]` override for string-cache, in order to enable using a single Cargo "workspace" in this repository.)
r? @bholley
---
<!-- 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
- [x] These changes fix #__ (github issue number if applicable).
<!-- Either: -->
- [ ] There are tests for these changes OR
- [x] These changes do not require new tests because refactoring
<!-- 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: 2d01d41a506bcbc7f26a2284b9f42390d6ef96ab
--HG--
rename : servo/ports/geckolib/selector_impl.rs => servo/components/style/gecko_selector_impl.rs
rename : servo/ports/geckolib/values.rs => servo/components/style/gecko_values.rs
rename : servo/ports/geckolib/properties.mako.rs => servo/components/style/properties/gecko.mako.rs
2016-07-20 07:58:34 +00:00
|
|
|
|
pub struct MediaRule {
|
2016-11-08 07:46:40 +00:00
|
|
|
|
pub media_queries: Arc<RwLock<MediaList>>,
|
2016-11-16 21:05:59 +00:00
|
|
|
|
pub rules: CssRules,
|
2015-01-21 21:27:48 +00:00
|
|
|
|
}
|
2013-09-04 17:00:52 +00:00
|
|
|
|
|
2016-10-04 16:58:56 +00:00
|
|
|
|
#[derive(Debug)]
|
servo: Merge #12515 - Make the style crate more concrete (from servo:concrete-style); r=bholley
Background:
The changes to Servo code to support Stylo began in the `selectors` crate with making pseudo-elements generic, defined be the user, so that different users (such as Servo and Gecko/Stylo) could have a different set of pseudo-elements supported and parsed. Adding a trait makes sense there since `selectors` is in its own repository and has others users (or at least [one](https://github.com/SimonSapin/kuchiki)).
Then we kind of kept going with the same pattern and added a bunch of traits in the `style` crate to make everything generic, allowing Servo and Gecko/Stylo to do things differently. But we’ve also added a `gecko` Cargo feature to do conditional compilation, at first to enable or disable some CSS properties and values in the Mako templates. Since we’re doing conditional compilation anyway, it’s often easier and simpler to do it more (with `#[cfg(feature = "gecko")]` and `#[cfg(feature = "servo")]`) that to keep adding traits and making everything generic. When a type is generic, any method that we want to call on it needs to be part of some trait.
----
The first several commits move some code around, mostly from `geckolib` to `style` (with `#[cfg(feature = "gecko")]`) but otherwise don’t change much.
The following commits remove some traits and many type parameters through the `style` crate, replacing them with pairs of conditionally-compiled API-compatible items (types, methods, …).
Simplifying code is nice to make it more maintainable, but this is motivated by another change described in https://github.com/servo/servo/pull/12391#issuecomment-232183942. (Porting Servo for that change proved difficult because some code in the `style` crate was becoming generic over `String` vs `Atom`, and this PR will help make that concrete. That change, in turn, is motivated by removing geckolib’s `[replace]` override for string-cache, in order to enable using a single Cargo "workspace" in this repository.)
r? @bholley
---
<!-- 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
- [x] These changes fix #__ (github issue number if applicable).
<!-- Either: -->
- [ ] There are tests for these changes OR
- [x] These changes do not require new tests because refactoring
<!-- 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: 2d01d41a506bcbc7f26a2284b9f42390d6ef96ab
--HG--
rename : servo/ports/geckolib/selector_impl.rs => servo/components/style/gecko_selector_impl.rs
rename : servo/ports/geckolib/values.rs => servo/components/style/gecko_values.rs
rename : servo/ports/geckolib/properties.mako.rs => servo/components/style/properties/gecko.mako.rs
2016-07-20 07:58:34 +00:00
|
|
|
|
pub struct StyleRule {
|
|
|
|
|
pub selectors: Vec<Selector<TheSelectorImpl>>,
|
2016-10-04 16:58:56 +00:00
|
|
|
|
pub block: Arc<RwLock<PropertyDeclarationBlock>>,
|
2013-09-04 17:00:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-16 21:05:59 +00:00
|
|
|
|
impl StyleRule {
|
|
|
|
|
/// Serialize the group of selectors for this rule.
|
|
|
|
|
///
|
|
|
|
|
/// https://drafts.csswg.org/cssom/#serialize-a-group-of-selectors
|
|
|
|
|
pub fn selectors_to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
|
|
|
|
let mut iter = self.selectors.iter();
|
|
|
|
|
try!(iter.next().unwrap().to_css(dest));
|
|
|
|
|
for selector in iter {
|
|
|
|
|
try!(write!(dest, ", "));
|
|
|
|
|
try!(selector.to_css(dest));
|
|
|
|
|
}
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl ToCss for StyleRule {
|
|
|
|
|
// https://drafts.csswg.org/cssom/#serialize-a-css-rule CSSStyleRule
|
|
|
|
|
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
|
|
|
|
// Step 1
|
|
|
|
|
try!(self.selectors_to_css(dest));
|
|
|
|
|
// Step 2
|
|
|
|
|
try!(dest.write_str(" { "));
|
|
|
|
|
// Step 3
|
|
|
|
|
let declaration_block = self.block.read();
|
|
|
|
|
try!(declaration_block.to_css(dest));
|
|
|
|
|
// Step 4
|
|
|
|
|
if declaration_block.declarations.len() > 0 {
|
|
|
|
|
try!(write!(dest, " "));
|
|
|
|
|
}
|
|
|
|
|
// Step 5
|
|
|
|
|
try!(dest.write_str("}"));
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 17:00:52 +00:00
|
|
|
|
|
servo: Merge #12515 - Make the style crate more concrete (from servo:concrete-style); r=bholley
Background:
The changes to Servo code to support Stylo began in the `selectors` crate with making pseudo-elements generic, defined be the user, so that different users (such as Servo and Gecko/Stylo) could have a different set of pseudo-elements supported and parsed. Adding a trait makes sense there since `selectors` is in its own repository and has others users (or at least [one](https://github.com/SimonSapin/kuchiki)).
Then we kind of kept going with the same pattern and added a bunch of traits in the `style` crate to make everything generic, allowing Servo and Gecko/Stylo to do things differently. But we’ve also added a `gecko` Cargo feature to do conditional compilation, at first to enable or disable some CSS properties and values in the Mako templates. Since we’re doing conditional compilation anyway, it’s often easier and simpler to do it more (with `#[cfg(feature = "gecko")]` and `#[cfg(feature = "servo")]`) that to keep adding traits and making everything generic. When a type is generic, any method that we want to call on it needs to be part of some trait.
----
The first several commits move some code around, mostly from `geckolib` to `style` (with `#[cfg(feature = "gecko")]`) but otherwise don’t change much.
The following commits remove some traits and many type parameters through the `style` crate, replacing them with pairs of conditionally-compiled API-compatible items (types, methods, …).
Simplifying code is nice to make it more maintainable, but this is motivated by another change described in https://github.com/servo/servo/pull/12391#issuecomment-232183942. (Porting Servo for that change proved difficult because some code in the `style` crate was becoming generic over `String` vs `Atom`, and this PR will help make that concrete. That change, in turn, is motivated by removing geckolib’s `[replace]` override for string-cache, in order to enable using a single Cargo "workspace" in this repository.)
r? @bholley
---
<!-- 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
- [x] These changes fix #__ (github issue number if applicable).
<!-- Either: -->
- [ ] There are tests for these changes OR
- [x] These changes do not require new tests because refactoring
<!-- 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: 2d01d41a506bcbc7f26a2284b9f42390d6ef96ab
--HG--
rename : servo/ports/geckolib/selector_impl.rs => servo/components/style/gecko_selector_impl.rs
rename : servo/ports/geckolib/values.rs => servo/components/style/gecko_values.rs
rename : servo/ports/geckolib/properties.mako.rs => servo/components/style/properties/gecko.mako.rs
2016-07-20 07:58:34 +00:00
|
|
|
|
impl Stylesheet {
|
2015-01-28 01:15:50 +00:00
|
|
|
|
pub fn from_bytes_iter<I: Iterator<Item=Vec<u8>>>(
|
2016-11-17 21:34:47 +00:00
|
|
|
|
input: I, base_url: ServoUrl, protocol_encoding_label: Option<&str>,
|
2015-11-26 22:26:08 +00:00
|
|
|
|
environment_encoding: Option<EncodingRef>, origin: Origin,
|
2016-05-24 21:41:04 +00:00
|
|
|
|
error_reporter: Box<ParseErrorReporter + Send>,
|
servo: Merge #12515 - Make the style crate more concrete (from servo:concrete-style); r=bholley
Background:
The changes to Servo code to support Stylo began in the `selectors` crate with making pseudo-elements generic, defined be the user, so that different users (such as Servo and Gecko/Stylo) could have a different set of pseudo-elements supported and parsed. Adding a trait makes sense there since `selectors` is in its own repository and has others users (or at least [one](https://github.com/SimonSapin/kuchiki)).
Then we kind of kept going with the same pattern and added a bunch of traits in the `style` crate to make everything generic, allowing Servo and Gecko/Stylo to do things differently. But we’ve also added a `gecko` Cargo feature to do conditional compilation, at first to enable or disable some CSS properties and values in the Mako templates. Since we’re doing conditional compilation anyway, it’s often easier and simpler to do it more (with `#[cfg(feature = "gecko")]` and `#[cfg(feature = "servo")]`) that to keep adding traits and making everything generic. When a type is generic, any method that we want to call on it needs to be part of some trait.
----
The first several commits move some code around, mostly from `geckolib` to `style` (with `#[cfg(feature = "gecko")]`) but otherwise don’t change much.
The following commits remove some traits and many type parameters through the `style` crate, replacing them with pairs of conditionally-compiled API-compatible items (types, methods, …).
Simplifying code is nice to make it more maintainable, but this is motivated by another change described in https://github.com/servo/servo/pull/12391#issuecomment-232183942. (Porting Servo for that change proved difficult because some code in the `style` crate was becoming generic over `String` vs `Atom`, and this PR will help make that concrete. That change, in turn, is motivated by removing geckolib’s `[replace]` override for string-cache, in order to enable using a single Cargo "workspace" in this repository.)
r? @bholley
---
<!-- 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
- [x] These changes fix #__ (github issue number if applicable).
<!-- Either: -->
- [ ] There are tests for these changes OR
- [x] These changes do not require new tests because refactoring
<!-- 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: 2d01d41a506bcbc7f26a2284b9f42390d6ef96ab
--HG--
rename : servo/ports/geckolib/selector_impl.rs => servo/components/style/gecko_selector_impl.rs
rename : servo/ports/geckolib/values.rs => servo/components/style/gecko_values.rs
rename : servo/ports/geckolib/properties.mako.rs => servo/components/style/properties/gecko.mako.rs
2016-07-20 07:58:34 +00:00
|
|
|
|
extra_data: ParserContextExtraData) -> Stylesheet {
|
2015-02-13 10:06:49 +00:00
|
|
|
|
let mut bytes = vec![];
|
2014-12-12 09:12:51 +00:00
|
|
|
|
// TODO: incremental decoding and tokenization/parsing
|
2013-10-18 21:25:34 +00:00
|
|
|
|
for chunk in input {
|
2015-12-10 23:27:58 +00:00
|
|
|
|
bytes.extend_from_slice(&chunk)
|
2013-10-18 21:25:34 +00:00
|
|
|
|
}
|
2015-02-13 10:06:49 +00:00
|
|
|
|
Stylesheet::from_bytes(&bytes, base_url, protocol_encoding_label,
|
2016-05-24 21:41:04 +00:00
|
|
|
|
environment_encoding, origin, error_reporter,
|
|
|
|
|
extra_data)
|
2013-12-17 17:04:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-12-16 02:33:46 +00:00
|
|
|
|
pub fn from_bytes(bytes: &[u8],
|
2016-11-17 21:34:47 +00:00
|
|
|
|
base_url: ServoUrl,
|
2014-12-16 02:33:46 +00:00
|
|
|
|
protocol_encoding_label: Option<&str>,
|
|
|
|
|
environment_encoding: Option<EncodingRef>,
|
2016-05-24 21:41:04 +00:00
|
|
|
|
origin: Origin, error_reporter: Box<ParseErrorReporter + Send>,
|
|
|
|
|
extra_data: ParserContextExtraData)
|
servo: Merge #12515 - Make the style crate more concrete (from servo:concrete-style); r=bholley
Background:
The changes to Servo code to support Stylo began in the `selectors` crate with making pseudo-elements generic, defined be the user, so that different users (such as Servo and Gecko/Stylo) could have a different set of pseudo-elements supported and parsed. Adding a trait makes sense there since `selectors` is in its own repository and has others users (or at least [one](https://github.com/SimonSapin/kuchiki)).
Then we kind of kept going with the same pattern and added a bunch of traits in the `style` crate to make everything generic, allowing Servo and Gecko/Stylo to do things differently. But we’ve also added a `gecko` Cargo feature to do conditional compilation, at first to enable or disable some CSS properties and values in the Mako templates. Since we’re doing conditional compilation anyway, it’s often easier and simpler to do it more (with `#[cfg(feature = "gecko")]` and `#[cfg(feature = "servo")]`) that to keep adding traits and making everything generic. When a type is generic, any method that we want to call on it needs to be part of some trait.
----
The first several commits move some code around, mostly from `geckolib` to `style` (with `#[cfg(feature = "gecko")]`) but otherwise don’t change much.
The following commits remove some traits and many type parameters through the `style` crate, replacing them with pairs of conditionally-compiled API-compatible items (types, methods, …).
Simplifying code is nice to make it more maintainable, but this is motivated by another change described in https://github.com/servo/servo/pull/12391#issuecomment-232183942. (Porting Servo for that change proved difficult because some code in the `style` crate was becoming generic over `String` vs `Atom`, and this PR will help make that concrete. That change, in turn, is motivated by removing geckolib’s `[replace]` override for string-cache, in order to enable using a single Cargo "workspace" in this repository.)
r? @bholley
---
<!-- 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
- [x] These changes fix #__ (github issue number if applicable).
<!-- Either: -->
- [ ] There are tests for these changes OR
- [x] These changes do not require new tests because refactoring
<!-- 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: 2d01d41a506bcbc7f26a2284b9f42390d6ef96ab
--HG--
rename : servo/ports/geckolib/selector_impl.rs => servo/components/style/gecko_selector_impl.rs
rename : servo/ports/geckolib/values.rs => servo/components/style/gecko_values.rs
rename : servo/ports/geckolib/properties.mako.rs => servo/components/style/properties/gecko.mako.rs
2016-07-20 07:58:34 +00:00
|
|
|
|
-> Stylesheet {
|
2014-05-04 21:25:39 +00:00
|
|
|
|
// TODO: bytes.as_slice could be bytes.container_as_bytes()
|
2014-07-07 06:30:04 +00:00
|
|
|
|
let (string, _) = decode_stylesheet_bytes(
|
2015-02-13 10:06:49 +00:00
|
|
|
|
bytes, protocol_encoding_label, environment_encoding);
|
2016-05-24 21:41:04 +00:00
|
|
|
|
Stylesheet::from_str(&string, base_url, origin, error_reporter, extra_data)
|
2013-10-18 21:25:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-17 21:34:47 +00:00
|
|
|
|
pub fn from_str(css: &str, base_url: ServoUrl, origin: Origin,
|
2016-05-24 21:41:04 +00:00
|
|
|
|
error_reporter: Box<ParseErrorReporter + Send>,
|
servo: Merge #12515 - Make the style crate more concrete (from servo:concrete-style); r=bholley
Background:
The changes to Servo code to support Stylo began in the `selectors` crate with making pseudo-elements generic, defined be the user, so that different users (such as Servo and Gecko/Stylo) could have a different set of pseudo-elements supported and parsed. Adding a trait makes sense there since `selectors` is in its own repository and has others users (or at least [one](https://github.com/SimonSapin/kuchiki)).
Then we kind of kept going with the same pattern and added a bunch of traits in the `style` crate to make everything generic, allowing Servo and Gecko/Stylo to do things differently. But we’ve also added a `gecko` Cargo feature to do conditional compilation, at first to enable or disable some CSS properties and values in the Mako templates. Since we’re doing conditional compilation anyway, it’s often easier and simpler to do it more (with `#[cfg(feature = "gecko")]` and `#[cfg(feature = "servo")]`) that to keep adding traits and making everything generic. When a type is generic, any method that we want to call on it needs to be part of some trait.
----
The first several commits move some code around, mostly from `geckolib` to `style` (with `#[cfg(feature = "gecko")]`) but otherwise don’t change much.
The following commits remove some traits and many type parameters through the `style` crate, replacing them with pairs of conditionally-compiled API-compatible items (types, methods, …).
Simplifying code is nice to make it more maintainable, but this is motivated by another change described in https://github.com/servo/servo/pull/12391#issuecomment-232183942. (Porting Servo for that change proved difficult because some code in the `style` crate was becoming generic over `String` vs `Atom`, and this PR will help make that concrete. That change, in turn, is motivated by removing geckolib’s `[replace]` override for string-cache, in order to enable using a single Cargo "workspace" in this repository.)
r? @bholley
---
<!-- 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
- [x] These changes fix #__ (github issue number if applicable).
<!-- Either: -->
- [ ] There are tests for these changes OR
- [x] These changes do not require new tests because refactoring
<!-- 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: 2d01d41a506bcbc7f26a2284b9f42390d6ef96ab
--HG--
rename : servo/ports/geckolib/selector_impl.rs => servo/components/style/gecko_selector_impl.rs
rename : servo/ports/geckolib/values.rs => servo/components/style/gecko_values.rs
rename : servo/ports/geckolib/properties.mako.rs => servo/components/style/properties/gecko.mako.rs
2016-07-20 07:58:34 +00:00
|
|
|
|
extra_data: ParserContextExtraData) -> Stylesheet {
|
2015-01-30 22:27:53 +00:00
|
|
|
|
let rule_parser = TopLevelRuleParser {
|
2016-05-24 21:41:04 +00:00
|
|
|
|
context: ParserContext::new_with_extra_data(origin, &base_url, error_reporter.clone(),
|
|
|
|
|
extra_data),
|
2015-01-30 22:27:53 +00:00
|
|
|
|
state: Cell::new(State::Start),
|
2014-12-16 02:33:46 +00:00
|
|
|
|
};
|
2015-01-30 22:27:53 +00:00
|
|
|
|
let mut input = Parser::new(css);
|
2016-03-19 20:50:54 +00:00
|
|
|
|
input.look_for_viewport_percentages();
|
|
|
|
|
|
servo: Merge #11766 - Add `@keyframes` and `animation-*` support (from emilio:keyframes-parsing); r=SimonSapin,pcwalton
- [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. -->
This adds support for parsing `@keyframes` rules, and animation properties. Stylo will need it sometime soonish, plus I want to make animations work in Servo.
The remaining part is doin the math and trigger the animations correctly from servo. I don't expect it to be *that* hard, but probaby I'll need to learn a bit more about the current animation infra (e.g. why the heck is the `new_animations_sender` guarded by a `Mutex`?).
I'd expect to land this, since this is already a bunch of work, this is the part exclusively required by stylo (at least if we don't use Servo's machinery), the media query parsing is tested, and the properties land after a flag, but if you prefer to wait until I finish this up it's fine for me too.
r? @SimonSapin
cc @pcwalton @bholley
Source-Repo: https://github.com/servo/servo
Source-Revision: d3a81373e44634c30d31da0457e1c1e86c0911ed
2016-06-28 22:31:01 +00:00
|
|
|
|
let mut rules = vec![];
|
2016-03-19 20:50:54 +00:00
|
|
|
|
{
|
|
|
|
|
let mut iter = RuleListParser::new_for_stylesheet(&mut input, rule_parser);
|
|
|
|
|
while let Some(result) = iter.next() {
|
|
|
|
|
match result {
|
2016-09-08 20:50:12 +00:00
|
|
|
|
Ok(rule) => rules.push(rule),
|
2016-03-19 20:50:54 +00:00
|
|
|
|
Err(range) => {
|
|
|
|
|
let pos = range.start;
|
|
|
|
|
let message = format!("Invalid rule: '{}'", iter.input.slice(range));
|
|
|
|
|
let context = ParserContext::new(origin, &base_url, error_reporter.clone());
|
|
|
|
|
log_css_error(iter.input, pos, &*message, &context);
|
2015-01-30 22:27:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
servo: Merge #11766 - Add `@keyframes` and `animation-*` support (from emilio:keyframes-parsing); r=SimonSapin,pcwalton
- [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. -->
This adds support for parsing `@keyframes` rules, and animation properties. Stylo will need it sometime soonish, plus I want to make animations work in Servo.
The remaining part is doin the math and trigger the animations correctly from servo. I don't expect it to be *that* hard, but probaby I'll need to learn a bit more about the current animation infra (e.g. why the heck is the `new_animations_sender` guarded by a `Mutex`?).
I'd expect to land this, since this is already a bunch of work, this is the part exclusively required by stylo (at least if we don't use Servo's machinery), the media query parsing is tested, and the properties land after a flag, but if you prefer to wait until I finish this up it's fine for me too.
r? @SimonSapin
cc @pcwalton @bholley
Source-Repo: https://github.com/servo/servo
Source-Revision: d3a81373e44634c30d31da0457e1c1e86c0911ed
2016-06-28 22:31:01 +00:00
|
|
|
|
|
2015-01-21 21:27:48 +00:00
|
|
|
|
Stylesheet {
|
|
|
|
|
origin: origin,
|
2016-11-16 21:05:59 +00:00
|
|
|
|
rules: rules.into(),
|
2016-11-10 07:37:57 +00:00
|
|
|
|
media: Default::default(),
|
2016-08-16 18:48:20 +00:00
|
|
|
|
dirty_on_viewport_size_change:
|
|
|
|
|
input.seen_viewport_percentages(),
|
servo: Merge #8039 - Move Stylesheet loading and ownership from the layout task into HTML elements (from tschneidereit:script-owns-stylesheets); r=jdm
Stylesheets for `HTMLLinkElement`s are now loaded by the resource task, triggered by the element in question. Stylesheets are owned by the elements they're associated with, which can be `HTMLStyleElement`, `HTMLLinkElement`, and `HTMLMetaElement` (for `<meta name="viewport">).
Additionally, the quirks mode stylesheet (just as the user and user agent stylesheets a couple of commits ago), is implemented as a lazy static, loaded once per process and shared between all documents.
This all has various nice consequences:
- Stylesheet loading becomes a non-blocking operation.
- Stylesheets are removed when the element they're associated with is removed from the document.
- It'll be possible to implement the CSSOM APIs that require direct access to the stylesheets (i.e., ~ all of them).
- Various subtle correctness issues are fixed.
One piece of interesting follow-up work would be to move parsing of external stylesheets to the resource task, too. Right now, it happens in the link element once loading is complete, so blocks the script task. Moving it to the resource task would probably be fairly straight-forward as it doesn't require access to any external state.
Depends on #7979 because without that loading stylesheets asynchronously breaks lots of content.
Source-Repo: https://github.com/servo/servo
Source-Revision: 7ff3a17524e0e703e3ac279441729c185444be24
2015-11-07 19:41:54 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-08 07:46:40 +00:00
|
|
|
|
/// Set the MediaList associated with the style-sheet.
|
2016-11-10 07:37:57 +00:00
|
|
|
|
pub fn set_media(&mut self, media: MediaList) {
|
servo: Merge #8039 - Move Stylesheet loading and ownership from the layout task into HTML elements (from tschneidereit:script-owns-stylesheets); r=jdm
Stylesheets for `HTMLLinkElement`s are now loaded by the resource task, triggered by the element in question. Stylesheets are owned by the elements they're associated with, which can be `HTMLStyleElement`, `HTMLLinkElement`, and `HTMLMetaElement` (for `<meta name="viewport">).
Additionally, the quirks mode stylesheet (just as the user and user agent stylesheets a couple of commits ago), is implemented as a lazy static, loaded once per process and shared between all documents.
This all has various nice consequences:
- Stylesheet loading becomes a non-blocking operation.
- Stylesheets are removed when the element they're associated with is removed from the document.
- It'll be possible to implement the CSSOM APIs that require direct access to the stylesheets (i.e., ~ all of them).
- Various subtle correctness issues are fixed.
One piece of interesting follow-up work would be to move parsing of external stylesheets to the resource task, too. Right now, it happens in the link element once loading is complete, so blocks the script task. Moving it to the resource task would probably be fairly straight-forward as it doesn't require access to any external state.
Depends on #7979 because without that loading stylesheets asynchronously breaks lots of content.
Source-Repo: https://github.com/servo/servo
Source-Revision: 7ff3a17524e0e703e3ac279441729c185444be24
2015-11-07 19:41:54 +00:00
|
|
|
|
self.media = media;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Returns whether the style-sheet applies for the current device depending
|
2016-11-08 07:46:40 +00:00
|
|
|
|
/// on the associated MediaList.
|
servo: Merge #8039 - Move Stylesheet loading and ownership from the layout task into HTML elements (from tschneidereit:script-owns-stylesheets); r=jdm
Stylesheets for `HTMLLinkElement`s are now loaded by the resource task, triggered by the element in question. Stylesheets are owned by the elements they're associated with, which can be `HTMLStyleElement`, `HTMLLinkElement`, and `HTMLMetaElement` (for `<meta name="viewport">).
Additionally, the quirks mode stylesheet (just as the user and user agent stylesheets a couple of commits ago), is implemented as a lazy static, loaded once per process and shared between all documents.
This all has various nice consequences:
- Stylesheet loading becomes a non-blocking operation.
- Stylesheets are removed when the element they're associated with is removed from the document.
- It'll be possible to implement the CSSOM APIs that require direct access to the stylesheets (i.e., ~ all of them).
- Various subtle correctness issues are fixed.
One piece of interesting follow-up work would be to move parsing of external stylesheets to the resource task, too. Right now, it happens in the link element once loading is complete, so blocks the script task. Moving it to the resource task would probably be fairly straight-forward as it doesn't require access to any external state.
Depends on #7979 because without that loading stylesheets asynchronously breaks lots of content.
Source-Repo: https://github.com/servo/servo
Source-Revision: 7ff3a17524e0e703e3ac279441729c185444be24
2015-11-07 19:41:54 +00:00
|
|
|
|
///
|
2016-11-08 07:46:40 +00:00
|
|
|
|
/// Always true if no associated MediaList exists.
|
servo: Merge #8039 - Move Stylesheet loading and ownership from the layout task into HTML elements (from tschneidereit:script-owns-stylesheets); r=jdm
Stylesheets for `HTMLLinkElement`s are now loaded by the resource task, triggered by the element in question. Stylesheets are owned by the elements they're associated with, which can be `HTMLStyleElement`, `HTMLLinkElement`, and `HTMLMetaElement` (for `<meta name="viewport">).
Additionally, the quirks mode stylesheet (just as the user and user agent stylesheets a couple of commits ago), is implemented as a lazy static, loaded once per process and shared between all documents.
This all has various nice consequences:
- Stylesheet loading becomes a non-blocking operation.
- Stylesheets are removed when the element they're associated with is removed from the document.
- It'll be possible to implement the CSSOM APIs that require direct access to the stylesheets (i.e., ~ all of them).
- Various subtle correctness issues are fixed.
One piece of interesting follow-up work would be to move parsing of external stylesheets to the resource task, too. Right now, it happens in the link element once loading is complete, so blocks the script task. Moving it to the resource task would probably be fairly straight-forward as it doesn't require access to any external state.
Depends on #7979 because without that loading stylesheets asynchronously breaks lots of content.
Source-Repo: https://github.com/servo/servo
Source-Revision: 7ff3a17524e0e703e3ac279441729c185444be24
2015-11-07 19:41:54 +00:00
|
|
|
|
pub fn is_effective_for_device(&self, device: &Device) -> bool {
|
2016-11-10 07:37:57 +00:00
|
|
|
|
self.media.evaluate(device)
|
2015-01-21 21:27:48 +00:00
|
|
|
|
}
|
2015-04-11 00:17:49 +00:00
|
|
|
|
|
|
|
|
|
/// Return an iterator over the effective rules within the style-sheet, as
|
|
|
|
|
/// according to the supplied `Device`.
|
|
|
|
|
///
|
|
|
|
|
/// If a condition does not hold, its associated conditional group rule and
|
|
|
|
|
/// nested rules will be skipped. Use `rules` if all rules need to be
|
|
|
|
|
/// examined.
|
|
|
|
|
#[inline]
|
2016-11-14 09:36:37 +00:00
|
|
|
|
pub fn effective_rules<F>(&self, device: &Device, mut f: F) where F: FnMut(&CssRule) {
|
2016-11-16 21:05:59 +00:00
|
|
|
|
effective_rules(&self.rules.0.read(), device, &mut f);
|
2015-04-11 00:17:49 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-14 09:36:37 +00:00
|
|
|
|
fn effective_rules<F>(rules: &[CssRule], device: &Device, f: &mut F) where F: FnMut(&CssRule) {
|
2016-10-20 16:29:27 +00:00
|
|
|
|
for rule in rules {
|
|
|
|
|
f(rule);
|
|
|
|
|
rule.with_nested_rules_and_mq(|rules, mq| {
|
|
|
|
|
if let Some(media_queries) = mq {
|
|
|
|
|
if !media_queries.evaluate(device) {
|
|
|
|
|
return
|
2015-04-11 00:17:49 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-10-20 16:29:27 +00:00
|
|
|
|
effective_rules(rules, device, f)
|
|
|
|
|
})
|
2015-04-11 00:17:49 +00:00
|
|
|
|
}
|
2015-01-21 21:27:48 +00:00
|
|
|
|
}
|
2014-12-16 02:33:46 +00:00
|
|
|
|
|
2016-10-20 16:29:27 +00:00
|
|
|
|
macro_rules! rule_filter {
|
|
|
|
|
($( $method: ident($variant:ident => $rule_type: ident), )+) => {
|
|
|
|
|
impl Stylesheet {
|
|
|
|
|
$(
|
|
|
|
|
pub fn $method<F>(&self, device: &Device, mut f: F) where F: FnMut(&$rule_type) {
|
|
|
|
|
self.effective_rules(device, |rule| {
|
2016-11-14 09:36:37 +00:00
|
|
|
|
if let CssRule::$variant(ref lock) = *rule {
|
2016-10-20 16:29:27 +00:00
|
|
|
|
let rule = lock.read();
|
|
|
|
|
f(&rule)
|
2015-04-11 00:17:49 +00:00
|
|
|
|
}
|
2016-10-20 16:29:27 +00:00
|
|
|
|
})
|
2015-04-11 00:17:49 +00:00
|
|
|
|
}
|
2016-10-20 16:29:27 +00:00
|
|
|
|
)+
|
2015-04-11 00:17:49 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-20 16:29:27 +00:00
|
|
|
|
rule_filter! {
|
|
|
|
|
effective_style_rules(Style => StyleRule),
|
|
|
|
|
effective_media_rules(Media => MediaRule),
|
|
|
|
|
effective_font_face_rules(FontFace => FontFaceRule),
|
|
|
|
|
effective_viewport_rules(Viewport => ViewportRule),
|
|
|
|
|
effective_keyframes_rules(Keyframes => KeyframesRule),
|
2015-04-11 00:17:49 +00:00
|
|
|
|
}
|
2013-10-18 21:25:34 +00:00
|
|
|
|
|
2016-11-16 21:05:59 +00:00
|
|
|
|
fn parse_nested_rules(context: &ParserContext, input: &mut Parser) -> CssRules {
|
2016-02-13 22:29:59 +00:00
|
|
|
|
let mut iter = RuleListParser::new_for_nested_rule(input,
|
servo: Merge #12515 - Make the style crate more concrete (from servo:concrete-style); r=bholley
Background:
The changes to Servo code to support Stylo began in the `selectors` crate with making pseudo-elements generic, defined be the user, so that different users (such as Servo and Gecko/Stylo) could have a different set of pseudo-elements supported and parsed. Adding a trait makes sense there since `selectors` is in its own repository and has others users (or at least [one](https://github.com/SimonSapin/kuchiki)).
Then we kind of kept going with the same pattern and added a bunch of traits in the `style` crate to make everything generic, allowing Servo and Gecko/Stylo to do things differently. But we’ve also added a `gecko` Cargo feature to do conditional compilation, at first to enable or disable some CSS properties and values in the Mako templates. Since we’re doing conditional compilation anyway, it’s often easier and simpler to do it more (with `#[cfg(feature = "gecko")]` and `#[cfg(feature = "servo")]`) that to keep adding traits and making everything generic. When a type is generic, any method that we want to call on it needs to be part of some trait.
----
The first several commits move some code around, mostly from `geckolib` to `style` (with `#[cfg(feature = "gecko")]`) but otherwise don’t change much.
The following commits remove some traits and many type parameters through the `style` crate, replacing them with pairs of conditionally-compiled API-compatible items (types, methods, …).
Simplifying code is nice to make it more maintainable, but this is motivated by another change described in https://github.com/servo/servo/pull/12391#issuecomment-232183942. (Porting Servo for that change proved difficult because some code in the `style` crate was becoming generic over `String` vs `Atom`, and this PR will help make that concrete. That change, in turn, is motivated by removing geckolib’s `[replace]` override for string-cache, in order to enable using a single Cargo "workspace" in this repository.)
r? @bholley
---
<!-- 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
- [x] These changes fix #__ (github issue number if applicable).
<!-- Either: -->
- [ ] There are tests for these changes OR
- [x] These changes do not require new tests because refactoring
<!-- 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: 2d01d41a506bcbc7f26a2284b9f42390d6ef96ab
--HG--
rename : servo/ports/geckolib/selector_impl.rs => servo/components/style/gecko_selector_impl.rs
rename : servo/ports/geckolib/values.rs => servo/components/style/gecko_values.rs
rename : servo/ports/geckolib/properties.mako.rs => servo/components/style/properties/gecko.mako.rs
2016-07-20 07:58:34 +00:00
|
|
|
|
NestedRuleParser { context: context });
|
2015-01-30 22:27:53 +00:00
|
|
|
|
let mut rules = Vec::new();
|
|
|
|
|
while let Some(result) = iter.next() {
|
|
|
|
|
match result {
|
|
|
|
|
Ok(rule) => rules.push(rule),
|
|
|
|
|
Err(range) => {
|
2015-02-12 00:24:45 +00:00
|
|
|
|
let pos = range.start;
|
2015-01-30 22:27:53 +00:00
|
|
|
|
let message = format!("Unsupported rule: '{}'", iter.input.slice(range));
|
2015-12-03 08:54:37 +00:00
|
|
|
|
log_css_error(iter.input, pos, &*message, &context);
|
2015-01-30 22:27:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-11-16 21:05:59 +00:00
|
|
|
|
rules.into()
|
2015-01-21 21:27:48 +00:00
|
|
|
|
}
|
2013-10-18 21:25:34 +00:00
|
|
|
|
|
2015-01-21 21:27:48 +00:00
|
|
|
|
|
servo: Merge #12515 - Make the style crate more concrete (from servo:concrete-style); r=bholley
Background:
The changes to Servo code to support Stylo began in the `selectors` crate with making pseudo-elements generic, defined be the user, so that different users (such as Servo and Gecko/Stylo) could have a different set of pseudo-elements supported and parsed. Adding a trait makes sense there since `selectors` is in its own repository and has others users (or at least [one](https://github.com/SimonSapin/kuchiki)).
Then we kind of kept going with the same pattern and added a bunch of traits in the `style` crate to make everything generic, allowing Servo and Gecko/Stylo to do things differently. But we’ve also added a `gecko` Cargo feature to do conditional compilation, at first to enable or disable some CSS properties and values in the Mako templates. Since we’re doing conditional compilation anyway, it’s often easier and simpler to do it more (with `#[cfg(feature = "gecko")]` and `#[cfg(feature = "servo")]`) that to keep adding traits and making everything generic. When a type is generic, any method that we want to call on it needs to be part of some trait.
----
The first several commits move some code around, mostly from `geckolib` to `style` (with `#[cfg(feature = "gecko")]`) but otherwise don’t change much.
The following commits remove some traits and many type parameters through the `style` crate, replacing them with pairs of conditionally-compiled API-compatible items (types, methods, …).
Simplifying code is nice to make it more maintainable, but this is motivated by another change described in https://github.com/servo/servo/pull/12391#issuecomment-232183942. (Porting Servo for that change proved difficult because some code in the `style` crate was becoming generic over `String` vs `Atom`, and this PR will help make that concrete. That change, in turn, is motivated by removing geckolib’s `[replace]` override for string-cache, in order to enable using a single Cargo "workspace" in this repository.)
r? @bholley
---
<!-- 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
- [x] These changes fix #__ (github issue number if applicable).
<!-- Either: -->
- [ ] There are tests for these changes OR
- [x] These changes do not require new tests because refactoring
<!-- 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: 2d01d41a506bcbc7f26a2284b9f42390d6ef96ab
--HG--
rename : servo/ports/geckolib/selector_impl.rs => servo/components/style/gecko_selector_impl.rs
rename : servo/ports/geckolib/values.rs => servo/components/style/gecko_values.rs
rename : servo/ports/geckolib/properties.mako.rs => servo/components/style/properties/gecko.mako.rs
2016-07-20 07:58:34 +00:00
|
|
|
|
struct TopLevelRuleParser<'a> {
|
2015-01-30 22:27:53 +00:00
|
|
|
|
context: ParserContext<'a>,
|
|
|
|
|
state: Cell<State>,
|
2015-01-21 21:27:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-04-28 22:52:49 +00:00
|
|
|
|
#[derive(Eq, PartialEq, Ord, PartialOrd, Copy, Clone)]
|
2015-01-21 21:27:48 +00:00
|
|
|
|
enum State {
|
|
|
|
|
Start = 1,
|
|
|
|
|
Imports = 2,
|
|
|
|
|
Namespaces = 3,
|
|
|
|
|
Body = 4,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
enum AtRulePrelude {
|
servo: Merge #11766 - Add `@keyframes` and `animation-*` support (from emilio:keyframes-parsing); r=SimonSapin,pcwalton
- [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. -->
This adds support for parsing `@keyframes` rules, and animation properties. Stylo will need it sometime soonish, plus I want to make animations work in Servo.
The remaining part is doin the math and trigger the animations correctly from servo. I don't expect it to be *that* hard, but probaby I'll need to learn a bit more about the current animation infra (e.g. why the heck is the `new_animations_sender` guarded by a `Mutex`?).
I'd expect to land this, since this is already a bunch of work, this is the part exclusively required by stylo (at least if we don't use Servo's machinery), the media query parsing is tested, and the properties land after a flag, but if you prefer to wait until I finish this up it's fine for me too.
r? @SimonSapin
cc @pcwalton @bholley
Source-Repo: https://github.com/servo/servo
Source-Revision: d3a81373e44634c30d31da0457e1c1e86c0911ed
2016-06-28 22:31:01 +00:00
|
|
|
|
/// A @font-face rule prelude.
|
2015-01-21 21:27:48 +00:00
|
|
|
|
FontFace,
|
servo: Merge #11766 - Add `@keyframes` and `animation-*` support (from emilio:keyframes-parsing); r=SimonSapin,pcwalton
- [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. -->
This adds support for parsing `@keyframes` rules, and animation properties. Stylo will need it sometime soonish, plus I want to make animations work in Servo.
The remaining part is doin the math and trigger the animations correctly from servo. I don't expect it to be *that* hard, but probaby I'll need to learn a bit more about the current animation infra (e.g. why the heck is the `new_animations_sender` guarded by a `Mutex`?).
I'd expect to land this, since this is already a bunch of work, this is the part exclusively required by stylo (at least if we don't use Servo's machinery), the media query parsing is tested, and the properties land after a flag, but if you prefer to wait until I finish this up it's fine for me too.
r? @SimonSapin
cc @pcwalton @bholley
Source-Repo: https://github.com/servo/servo
Source-Revision: d3a81373e44634c30d31da0457e1c1e86c0911ed
2016-06-28 22:31:01 +00:00
|
|
|
|
/// A @media rule prelude, with its media queries.
|
2016-11-08 07:46:40 +00:00
|
|
|
|
Media(Arc<RwLock<MediaList>>),
|
servo: Merge #11766 - Add `@keyframes` and `animation-*` support (from emilio:keyframes-parsing); r=SimonSapin,pcwalton
- [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. -->
This adds support for parsing `@keyframes` rules, and animation properties. Stylo will need it sometime soonish, plus I want to make animations work in Servo.
The remaining part is doin the math and trigger the animations correctly from servo. I don't expect it to be *that* hard, but probaby I'll need to learn a bit more about the current animation infra (e.g. why the heck is the `new_animations_sender` guarded by a `Mutex`?).
I'd expect to land this, since this is already a bunch of work, this is the part exclusively required by stylo (at least if we don't use Servo's machinery), the media query parsing is tested, and the properties land after a flag, but if you prefer to wait until I finish this up it's fine for me too.
r? @SimonSapin
cc @pcwalton @bholley
Source-Repo: https://github.com/servo/servo
Source-Revision: d3a81373e44634c30d31da0457e1c1e86c0911ed
2016-06-28 22:31:01 +00:00
|
|
|
|
/// A @viewport rule prelude.
|
2015-05-06 17:41:09 +00:00
|
|
|
|
Viewport,
|
servo: Merge #11766 - Add `@keyframes` and `animation-*` support (from emilio:keyframes-parsing); r=SimonSapin,pcwalton
- [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. -->
This adds support for parsing `@keyframes` rules, and animation properties. Stylo will need it sometime soonish, plus I want to make animations work in Servo.
The remaining part is doin the math and trigger the animations correctly from servo. I don't expect it to be *that* hard, but probaby I'll need to learn a bit more about the current animation infra (e.g. why the heck is the `new_animations_sender` guarded by a `Mutex`?).
I'd expect to land this, since this is already a bunch of work, this is the part exclusively required by stylo (at least if we don't use Servo's machinery), the media query parsing is tested, and the properties land after a flag, but if you prefer to wait until I finish this up it's fine for me too.
r? @SimonSapin
cc @pcwalton @bholley
Source-Repo: https://github.com/servo/servo
Source-Revision: d3a81373e44634c30d31da0457e1c1e86c0911ed
2016-06-28 22:31:01 +00:00
|
|
|
|
/// A @keyframes rule, with its animation name.
|
|
|
|
|
Keyframes(Atom),
|
2015-01-21 21:27:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
servo: Merge #12515 - Make the style crate more concrete (from servo:concrete-style); r=bholley
Background:
The changes to Servo code to support Stylo began in the `selectors` crate with making pseudo-elements generic, defined be the user, so that different users (such as Servo and Gecko/Stylo) could have a different set of pseudo-elements supported and parsed. Adding a trait makes sense there since `selectors` is in its own repository and has others users (or at least [one](https://github.com/SimonSapin/kuchiki)).
Then we kind of kept going with the same pattern and added a bunch of traits in the `style` crate to make everything generic, allowing Servo and Gecko/Stylo to do things differently. But we’ve also added a `gecko` Cargo feature to do conditional compilation, at first to enable or disable some CSS properties and values in the Mako templates. Since we’re doing conditional compilation anyway, it’s often easier and simpler to do it more (with `#[cfg(feature = "gecko")]` and `#[cfg(feature = "servo")]`) that to keep adding traits and making everything generic. When a type is generic, any method that we want to call on it needs to be part of some trait.
----
The first several commits move some code around, mostly from `geckolib` to `style` (with `#[cfg(feature = "gecko")]`) but otherwise don’t change much.
The following commits remove some traits and many type parameters through the `style` crate, replacing them with pairs of conditionally-compiled API-compatible items (types, methods, …).
Simplifying code is nice to make it more maintainable, but this is motivated by another change described in https://github.com/servo/servo/pull/12391#issuecomment-232183942. (Porting Servo for that change proved difficult because some code in the `style` crate was becoming generic over `String` vs `Atom`, and this PR will help make that concrete. That change, in turn, is motivated by removing geckolib’s `[replace]` override for string-cache, in order to enable using a single Cargo "workspace" in this repository.)
r? @bholley
---
<!-- 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
- [x] These changes fix #__ (github issue number if applicable).
<!-- Either: -->
- [ ] There are tests for these changes OR
- [x] These changes do not require new tests because refactoring
<!-- 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: 2d01d41a506bcbc7f26a2284b9f42390d6ef96ab
--HG--
rename : servo/ports/geckolib/selector_impl.rs => servo/components/style/gecko_selector_impl.rs
rename : servo/ports/geckolib/values.rs => servo/components/style/gecko_values.rs
rename : servo/ports/geckolib/properties.mako.rs => servo/components/style/properties/gecko.mako.rs
2016-07-20 07:58:34 +00:00
|
|
|
|
impl<'a> AtRuleParser for TopLevelRuleParser<'a> {
|
2015-01-30 22:27:53 +00:00
|
|
|
|
type Prelude = AtRulePrelude;
|
2016-11-14 09:36:37 +00:00
|
|
|
|
type AtRule = CssRule;
|
2015-01-30 22:27:53 +00:00
|
|
|
|
|
2016-09-08 20:50:12 +00:00
|
|
|
|
fn parse_prelude(&mut self, name: &str, input: &mut Parser)
|
2016-11-14 09:36:37 +00:00
|
|
|
|
-> Result<AtRuleType<AtRulePrelude, CssRule>, ()> {
|
2015-01-28 01:15:50 +00:00
|
|
|
|
match_ignore_ascii_case! { name,
|
2015-01-21 21:27:48 +00:00
|
|
|
|
"import" => {
|
2015-01-30 22:27:53 +00:00
|
|
|
|
if self.state.get() <= State::Imports {
|
|
|
|
|
self.state.set(State::Imports);
|
2015-01-21 21:27:48 +00:00
|
|
|
|
// TODO: support @import
|
|
|
|
|
return Err(()) // "@import is not supported yet"
|
|
|
|
|
} else {
|
|
|
|
|
return Err(()) // "@import must be before any rule but @charset"
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
"namespace" => {
|
2015-01-30 22:27:53 +00:00
|
|
|
|
if self.state.get() <= State::Namespaces {
|
|
|
|
|
self.state.set(State::Namespaces);
|
|
|
|
|
|
2016-09-08 20:50:12 +00:00
|
|
|
|
let prefix_result = input.try(|input| input.expect_ident());
|
servo: Merge #14043 - Update to string-cache 0.3 (from servo:string-cache-up); r=nox
Previously, `string-cache` defined:
* An string-like `Atom` type,
* An `atom!("foo")` macro that expands to a value of that type, for a set of strings known at compile-time,
* A `struct Namespace(Atom);` type
* A `ns!(html)` macro that maps known prefixed to `Namespace` values with the corresponding namespace URL.
Adding a string to the static set required making a change to the `string-cache` crate.
With 0.3, the `Atom` type is now generic, with a type parameter that provides a set of static strings. We can have multiple such sets, defined in different crates. The `string_cache_codegen` crate, to be used in build scripts, generates code that defines such a set, a new atom type (a type alias for `Atom<_>` with the type parameter set), and an `atom!`-like macro.
The html5ever repository has a new `html5ever_atoms` crate that defines three such types: `Prefix`, `Namespace`, and `LocalName` (with respective `namespace_prefix!`, `namespace_url!`, and `local_name!` macros). It also defines the `ns!` macro like before.
This repository has a new `servo_atoms` crate in `components/atoms` that, for now, defines a single `Atom` type (and `atom!`) macro. (`servo_atoms::Atom` is defined as something like `type Atom = string_cache::Atom<ServoStaticStringSet>;`, so overall there’s now two types named `Atom`.)
In this PR, `servo_atoms::Atom` is used for everything else that was `string_cache::Atom` before. But more atom types can be defined as needed. Two reasons to do this are to auto-generate the set of static strings (I’m planning to do this for CSS property names, which is the motivation for this change), or to have the type system help us avoid mix up unrelated things (this is why we had a `Namespace` type ever before this change).
Introducing new types helped me find a bug: when creating a new attribute `dom::Element::set_style_attr`, would pass `Some(atom!("style"))` instead of `None` (now `Option<html5ever_atoms::Prefix>` instead of `Option<string_cache::Atom>`) to the `prefix` argument of `Attr::new`. I suppose the author of that code confused it with the `local_name` argument.
---
Note that Stylo is not affected by any of this. The `gecko_string_cache` module is unchanged, with a single `Atom` type. The `style` crate conditionally compiles `Prefix` and `LocalName` re-exports for that are both `gecko_string_cache::Atom` on stylo.
---
<!-- 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
- [ ] These changes fix #__ (github issue number if applicable).
<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____
<!-- 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: 5b4cc9568dbd5c15e5d2fbc62719172f11566ffa
2016-11-03 16:19:44 +00:00
|
|
|
|
let url = Namespace::from(try!(input.expect_url_or_string()));
|
2016-09-08 20:50:12 +00:00
|
|
|
|
|
|
|
|
|
let opt_prefix = if let Ok(prefix) = prefix_result {
|
servo: Merge #14043 - Update to string-cache 0.3 (from servo:string-cache-up); r=nox
Previously, `string-cache` defined:
* An string-like `Atom` type,
* An `atom!("foo")` macro that expands to a value of that type, for a set of strings known at compile-time,
* A `struct Namespace(Atom);` type
* A `ns!(html)` macro that maps known prefixed to `Namespace` values with the corresponding namespace URL.
Adding a string to the static set required making a change to the `string-cache` crate.
With 0.3, the `Atom` type is now generic, with a type parameter that provides a set of static strings. We can have multiple such sets, defined in different crates. The `string_cache_codegen` crate, to be used in build scripts, generates code that defines such a set, a new atom type (a type alias for `Atom<_>` with the type parameter set), and an `atom!`-like macro.
The html5ever repository has a new `html5ever_atoms` crate that defines three such types: `Prefix`, `Namespace`, and `LocalName` (with respective `namespace_prefix!`, `namespace_url!`, and `local_name!` macros). It also defines the `ns!` macro like before.
This repository has a new `servo_atoms` crate in `components/atoms` that, for now, defines a single `Atom` type (and `atom!`) macro. (`servo_atoms::Atom` is defined as something like `type Atom = string_cache::Atom<ServoStaticStringSet>;`, so overall there’s now two types named `Atom`.)
In this PR, `servo_atoms::Atom` is used for everything else that was `string_cache::Atom` before. But more atom types can be defined as needed. Two reasons to do this are to auto-generate the set of static strings (I’m planning to do this for CSS property names, which is the motivation for this change), or to have the type system help us avoid mix up unrelated things (this is why we had a `Namespace` type ever before this change).
Introducing new types helped me find a bug: when creating a new attribute `dom::Element::set_style_attr`, would pass `Some(atom!("style"))` instead of `None` (now `Option<html5ever_atoms::Prefix>` instead of `Option<string_cache::Atom>`) to the `prefix` argument of `Attr::new`. I suppose the author of that code confused it with the `local_name` argument.
---
Note that Stylo is not affected by any of this. The `gecko_string_cache` module is unchanged, with a single `Atom` type. The `style` crate conditionally compiles `Prefix` and `LocalName` re-exports for that are both `gecko_string_cache::Atom` on stylo.
---
<!-- 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
- [ ] These changes fix #__ (github issue number if applicable).
<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____
<!-- 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: 5b4cc9568dbd5c15e5d2fbc62719172f11566ffa
2016-11-03 16:19:44 +00:00
|
|
|
|
let prefix = Prefix::from(prefix);
|
2016-09-08 20:50:12 +00:00
|
|
|
|
self.context.selector_context.namespace_prefixes.insert(
|
|
|
|
|
prefix.clone(), url.clone());
|
|
|
|
|
Some(prefix)
|
|
|
|
|
} else {
|
|
|
|
|
self.context.selector_context.default_namespace = Some(url.clone());
|
|
|
|
|
None
|
|
|
|
|
};
|
|
|
|
|
|
2016-11-14 09:36:37 +00:00
|
|
|
|
return Ok(AtRuleType::WithoutBlock(CssRule::Namespace(Arc::new(RwLock::new(
|
2016-10-20 16:29:27 +00:00
|
|
|
|
NamespaceRule {
|
|
|
|
|
prefix: opt_prefix,
|
|
|
|
|
url: url,
|
|
|
|
|
}
|
|
|
|
|
)))))
|
2015-01-21 21:27:48 +00:00
|
|
|
|
} else {
|
|
|
|
|
return Err(()) // "@namespace must be before any rule but @charset and @import"
|
|
|
|
|
}
|
2016-01-21 17:15:51 +00:00
|
|
|
|
},
|
2016-08-31 21:30:56 +00:00
|
|
|
|
// @charset is removed by rust-cssparser if it’s the first rule in the stylesheet
|
|
|
|
|
// anything left is invalid.
|
|
|
|
|
"charset" => return Err(()), // (insert appropriate error message)
|
2015-01-21 21:27:48 +00:00
|
|
|
|
_ => {}
|
2013-09-04 17:00:52 +00:00
|
|
|
|
}
|
2015-01-21 21:27:48 +00:00
|
|
|
|
|
2015-01-30 22:27:53 +00:00
|
|
|
|
self.state.set(State::Body);
|
2016-09-08 20:50:12 +00:00
|
|
|
|
AtRuleParser::parse_prelude(&mut NestedRuleParser { context: &self.context }, name, input)
|
2015-01-30 22:27:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[inline]
|
2016-11-14 09:36:37 +00:00
|
|
|
|
fn parse_block(&mut self, prelude: AtRulePrelude, input: &mut Parser) -> Result<CssRule, ()> {
|
2016-09-08 20:50:12 +00:00
|
|
|
|
AtRuleParser::parse_block(&mut NestedRuleParser { context: &self.context }, prelude, input)
|
2015-01-30 22:27:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2015-01-21 21:27:48 +00:00
|
|
|
|
|
2015-01-30 22:27:53 +00:00
|
|
|
|
|
servo: Merge #12515 - Make the style crate more concrete (from servo:concrete-style); r=bholley
Background:
The changes to Servo code to support Stylo began in the `selectors` crate with making pseudo-elements generic, defined be the user, so that different users (such as Servo and Gecko/Stylo) could have a different set of pseudo-elements supported and parsed. Adding a trait makes sense there since `selectors` is in its own repository and has others users (or at least [one](https://github.com/SimonSapin/kuchiki)).
Then we kind of kept going with the same pattern and added a bunch of traits in the `style` crate to make everything generic, allowing Servo and Gecko/Stylo to do things differently. But we’ve also added a `gecko` Cargo feature to do conditional compilation, at first to enable or disable some CSS properties and values in the Mako templates. Since we’re doing conditional compilation anyway, it’s often easier and simpler to do it more (with `#[cfg(feature = "gecko")]` and `#[cfg(feature = "servo")]`) that to keep adding traits and making everything generic. When a type is generic, any method that we want to call on it needs to be part of some trait.
----
The first several commits move some code around, mostly from `geckolib` to `style` (with `#[cfg(feature = "gecko")]`) but otherwise don’t change much.
The following commits remove some traits and many type parameters through the `style` crate, replacing them with pairs of conditionally-compiled API-compatible items (types, methods, …).
Simplifying code is nice to make it more maintainable, but this is motivated by another change described in https://github.com/servo/servo/pull/12391#issuecomment-232183942. (Porting Servo for that change proved difficult because some code in the `style` crate was becoming generic over `String` vs `Atom`, and this PR will help make that concrete. That change, in turn, is motivated by removing geckolib’s `[replace]` override for string-cache, in order to enable using a single Cargo "workspace" in this repository.)
r? @bholley
---
<!-- 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
- [x] These changes fix #__ (github issue number if applicable).
<!-- Either: -->
- [ ] There are tests for these changes OR
- [x] These changes do not require new tests because refactoring
<!-- 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: 2d01d41a506bcbc7f26a2284b9f42390d6ef96ab
--HG--
rename : servo/ports/geckolib/selector_impl.rs => servo/components/style/gecko_selector_impl.rs
rename : servo/ports/geckolib/values.rs => servo/components/style/gecko_values.rs
rename : servo/ports/geckolib/properties.mako.rs => servo/components/style/properties/gecko.mako.rs
2016-07-20 07:58:34 +00:00
|
|
|
|
impl<'a> QualifiedRuleParser for TopLevelRuleParser<'a> {
|
|
|
|
|
type Prelude = Vec<Selector<TheSelectorImpl>>;
|
2016-11-14 09:36:37 +00:00
|
|
|
|
type QualifiedRule = CssRule;
|
2015-01-30 22:27:53 +00:00
|
|
|
|
|
|
|
|
|
#[inline]
|
2016-09-08 20:50:12 +00:00
|
|
|
|
fn parse_prelude(&mut self, input: &mut Parser) -> Result<Vec<Selector<TheSelectorImpl>>, ()> {
|
2015-01-30 22:27:53 +00:00
|
|
|
|
self.state.set(State::Body);
|
2016-09-08 20:50:12 +00:00
|
|
|
|
QualifiedRuleParser::parse_prelude(&mut NestedRuleParser { context: &self.context }, input)
|
2015-01-30 22:27:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[inline]
|
2016-09-08 20:50:12 +00:00
|
|
|
|
fn parse_block(&mut self, prelude: Vec<Selector<TheSelectorImpl>>, input: &mut Parser)
|
2016-11-14 09:36:37 +00:00
|
|
|
|
-> Result<CssRule, ()> {
|
2016-09-08 20:50:12 +00:00
|
|
|
|
QualifiedRuleParser::parse_block(&mut NestedRuleParser { context: &self.context },
|
2015-01-30 22:27:53 +00:00
|
|
|
|
prelude, input)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
servo: Merge #12515 - Make the style crate more concrete (from servo:concrete-style); r=bholley
Background:
The changes to Servo code to support Stylo began in the `selectors` crate with making pseudo-elements generic, defined be the user, so that different users (such as Servo and Gecko/Stylo) could have a different set of pseudo-elements supported and parsed. Adding a trait makes sense there since `selectors` is in its own repository and has others users (or at least [one](https://github.com/SimonSapin/kuchiki)).
Then we kind of kept going with the same pattern and added a bunch of traits in the `style` crate to make everything generic, allowing Servo and Gecko/Stylo to do things differently. But we’ve also added a `gecko` Cargo feature to do conditional compilation, at first to enable or disable some CSS properties and values in the Mako templates. Since we’re doing conditional compilation anyway, it’s often easier and simpler to do it more (with `#[cfg(feature = "gecko")]` and `#[cfg(feature = "servo")]`) that to keep adding traits and making everything generic. When a type is generic, any method that we want to call on it needs to be part of some trait.
----
The first several commits move some code around, mostly from `geckolib` to `style` (with `#[cfg(feature = "gecko")]`) but otherwise don’t change much.
The following commits remove some traits and many type parameters through the `style` crate, replacing them with pairs of conditionally-compiled API-compatible items (types, methods, …).
Simplifying code is nice to make it more maintainable, but this is motivated by another change described in https://github.com/servo/servo/pull/12391#issuecomment-232183942. (Porting Servo for that change proved difficult because some code in the `style` crate was becoming generic over `String` vs `Atom`, and this PR will help make that concrete. That change, in turn, is motivated by removing geckolib’s `[replace]` override for string-cache, in order to enable using a single Cargo "workspace" in this repository.)
r? @bholley
---
<!-- 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
- [x] These changes fix #__ (github issue number if applicable).
<!-- Either: -->
- [ ] There are tests for these changes OR
- [x] These changes do not require new tests because refactoring
<!-- 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: 2d01d41a506bcbc7f26a2284b9f42390d6ef96ab
--HG--
rename : servo/ports/geckolib/selector_impl.rs => servo/components/style/gecko_selector_impl.rs
rename : servo/ports/geckolib/values.rs => servo/components/style/gecko_values.rs
rename : servo/ports/geckolib/properties.mako.rs => servo/components/style/properties/gecko.mako.rs
2016-07-20 07:58:34 +00:00
|
|
|
|
struct NestedRuleParser<'a, 'b: 'a> {
|
2015-01-30 22:27:53 +00:00
|
|
|
|
context: &'a ParserContext<'b>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
servo: Merge #12515 - Make the style crate more concrete (from servo:concrete-style); r=bholley
Background:
The changes to Servo code to support Stylo began in the `selectors` crate with making pseudo-elements generic, defined be the user, so that different users (such as Servo and Gecko/Stylo) could have a different set of pseudo-elements supported and parsed. Adding a trait makes sense there since `selectors` is in its own repository and has others users (or at least [one](https://github.com/SimonSapin/kuchiki)).
Then we kind of kept going with the same pattern and added a bunch of traits in the `style` crate to make everything generic, allowing Servo and Gecko/Stylo to do things differently. But we’ve also added a `gecko` Cargo feature to do conditional compilation, at first to enable or disable some CSS properties and values in the Mako templates. Since we’re doing conditional compilation anyway, it’s often easier and simpler to do it more (with `#[cfg(feature = "gecko")]` and `#[cfg(feature = "servo")]`) that to keep adding traits and making everything generic. When a type is generic, any method that we want to call on it needs to be part of some trait.
----
The first several commits move some code around, mostly from `geckolib` to `style` (with `#[cfg(feature = "gecko")]`) but otherwise don’t change much.
The following commits remove some traits and many type parameters through the `style` crate, replacing them with pairs of conditionally-compiled API-compatible items (types, methods, …).
Simplifying code is nice to make it more maintainable, but this is motivated by another change described in https://github.com/servo/servo/pull/12391#issuecomment-232183942. (Porting Servo for that change proved difficult because some code in the `style` crate was becoming generic over `String` vs `Atom`, and this PR will help make that concrete. That change, in turn, is motivated by removing geckolib’s `[replace]` override for string-cache, in order to enable using a single Cargo "workspace" in this repository.)
r? @bholley
---
<!-- 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
- [x] These changes fix #__ (github issue number if applicable).
<!-- Either: -->
- [ ] There are tests for these changes OR
- [x] These changes do not require new tests because refactoring
<!-- 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: 2d01d41a506bcbc7f26a2284b9f42390d6ef96ab
--HG--
rename : servo/ports/geckolib/selector_impl.rs => servo/components/style/gecko_selector_impl.rs
rename : servo/ports/geckolib/values.rs => servo/components/style/gecko_values.rs
rename : servo/ports/geckolib/properties.mako.rs => servo/components/style/properties/gecko.mako.rs
2016-07-20 07:58:34 +00:00
|
|
|
|
impl<'a, 'b> AtRuleParser for NestedRuleParser<'a, 'b> {
|
2015-01-30 22:27:53 +00:00
|
|
|
|
type Prelude = AtRulePrelude;
|
2016-11-14 09:36:37 +00:00
|
|
|
|
type AtRule = CssRule;
|
2015-01-30 22:27:53 +00:00
|
|
|
|
|
2016-09-08 20:50:12 +00:00
|
|
|
|
fn parse_prelude(&mut self, name: &str, input: &mut Parser)
|
2016-11-14 09:36:37 +00:00
|
|
|
|
-> Result<AtRuleType<AtRulePrelude, CssRule>, ()> {
|
2015-01-28 01:15:50 +00:00
|
|
|
|
match_ignore_ascii_case! { name,
|
2015-01-21 21:27:48 +00:00
|
|
|
|
"media" => {
|
|
|
|
|
let media_queries = parse_media_query_list(input);
|
2016-10-20 16:29:27 +00:00
|
|
|
|
Ok(AtRuleType::WithBlock(AtRulePrelude::Media(Arc::new(RwLock::new(media_queries)))))
|
2015-01-21 21:27:48 +00:00
|
|
|
|
},
|
|
|
|
|
"font-face" => {
|
|
|
|
|
Ok(AtRuleType::WithBlock(AtRulePrelude::FontFace))
|
2015-05-06 17:41:09 +00:00
|
|
|
|
},
|
|
|
|
|
"viewport" => {
|
2016-10-10 13:11:32 +00:00
|
|
|
|
if ::util::prefs::PREFS.get("layout.viewport.enabled").as_boolean().unwrap_or(false) ||
|
|
|
|
|
cfg!(feature = "gecko") {
|
2015-05-06 17:41:09 +00:00
|
|
|
|
Ok(AtRuleType::WithBlock(AtRulePrelude::Viewport))
|
|
|
|
|
} else {
|
|
|
|
|
Err(())
|
|
|
|
|
}
|
2016-01-21 17:15:51 +00:00
|
|
|
|
},
|
servo: Merge #11766 - Add `@keyframes` and `animation-*` support (from emilio:keyframes-parsing); r=SimonSapin,pcwalton
- [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. -->
This adds support for parsing `@keyframes` rules, and animation properties. Stylo will need it sometime soonish, plus I want to make animations work in Servo.
The remaining part is doin the math and trigger the animations correctly from servo. I don't expect it to be *that* hard, but probaby I'll need to learn a bit more about the current animation infra (e.g. why the heck is the `new_animations_sender` guarded by a `Mutex`?).
I'd expect to land this, since this is already a bunch of work, this is the part exclusively required by stylo (at least if we don't use Servo's machinery), the media query parsing is tested, and the properties land after a flag, but if you prefer to wait until I finish this up it's fine for me too.
r? @SimonSapin
cc @pcwalton @bholley
Source-Repo: https://github.com/servo/servo
Source-Revision: d3a81373e44634c30d31da0457e1c1e86c0911ed
2016-06-28 22:31:01 +00:00
|
|
|
|
"keyframes" => {
|
|
|
|
|
let name = match input.next() {
|
|
|
|
|
Ok(Token::Ident(ref value)) if value != "none" => Atom::from(&**value),
|
|
|
|
|
Ok(Token::QuotedString(value)) => Atom::from(&*value),
|
|
|
|
|
_ => return Err(())
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Ok(AtRuleType::WithBlock(AtRulePrelude::Keyframes(Atom::from(name))))
|
|
|
|
|
},
|
2015-01-21 21:27:48 +00:00
|
|
|
|
_ => Err(())
|
2014-11-07 00:24:28 +00:00
|
|
|
|
}
|
2013-09-04 17:00:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-14 09:36:37 +00:00
|
|
|
|
fn parse_block(&mut self, prelude: AtRulePrelude, input: &mut Parser) -> Result<CssRule, ()> {
|
2015-01-21 21:27:48 +00:00
|
|
|
|
match prelude {
|
|
|
|
|
AtRulePrelude::FontFace => {
|
2016-11-14 09:36:37 +00:00
|
|
|
|
Ok(CssRule::FontFace(Arc::new(RwLock::new(
|
2016-10-20 16:29:27 +00:00
|
|
|
|
try!(parse_font_face_block(self.context, input))))))
|
2015-01-21 21:27:48 +00:00
|
|
|
|
}
|
|
|
|
|
AtRulePrelude::Media(media_queries) => {
|
2016-11-14 09:36:37 +00:00
|
|
|
|
Ok(CssRule::Media(Arc::new(RwLock::new(MediaRule {
|
2015-01-21 21:27:48 +00:00
|
|
|
|
media_queries: media_queries,
|
|
|
|
|
rules: parse_nested_rules(self.context, input),
|
2016-10-20 16:29:27 +00:00
|
|
|
|
}))))
|
2015-01-21 21:27:48 +00:00
|
|
|
|
}
|
2015-05-06 17:41:09 +00:00
|
|
|
|
AtRulePrelude::Viewport => {
|
2016-11-14 09:36:37 +00:00
|
|
|
|
Ok(CssRule::Viewport(Arc::new(RwLock::new(
|
2016-10-20 16:29:27 +00:00
|
|
|
|
try!(ViewportRule::parse(input, self.context))))))
|
2015-05-06 17:41:09 +00:00
|
|
|
|
}
|
servo: Merge #11766 - Add `@keyframes` and `animation-*` support (from emilio:keyframes-parsing); r=SimonSapin,pcwalton
- [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. -->
This adds support for parsing `@keyframes` rules, and animation properties. Stylo will need it sometime soonish, plus I want to make animations work in Servo.
The remaining part is doin the math and trigger the animations correctly from servo. I don't expect it to be *that* hard, but probaby I'll need to learn a bit more about the current animation infra (e.g. why the heck is the `new_animations_sender` guarded by a `Mutex`?).
I'd expect to land this, since this is already a bunch of work, this is the part exclusively required by stylo (at least if we don't use Servo's machinery), the media query parsing is tested, and the properties land after a flag, but if you prefer to wait until I finish this up it's fine for me too.
r? @SimonSapin
cc @pcwalton @bholley
Source-Repo: https://github.com/servo/servo
Source-Revision: d3a81373e44634c30d31da0457e1c1e86c0911ed
2016-06-28 22:31:01 +00:00
|
|
|
|
AtRulePrelude::Keyframes(name) => {
|
2016-11-14 09:36:37 +00:00
|
|
|
|
Ok(CssRule::Keyframes(Arc::new(RwLock::new(KeyframesRule {
|
servo: Merge #11766 - Add `@keyframes` and `animation-*` support (from emilio:keyframes-parsing); r=SimonSapin,pcwalton
- [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. -->
This adds support for parsing `@keyframes` rules, and animation properties. Stylo will need it sometime soonish, plus I want to make animations work in Servo.
The remaining part is doin the math and trigger the animations correctly from servo. I don't expect it to be *that* hard, but probaby I'll need to learn a bit more about the current animation infra (e.g. why the heck is the `new_animations_sender` guarded by a `Mutex`?).
I'd expect to land this, since this is already a bunch of work, this is the part exclusively required by stylo (at least if we don't use Servo's machinery), the media query parsing is tested, and the properties land after a flag, but if you prefer to wait until I finish this up it's fine for me too.
r? @SimonSapin
cc @pcwalton @bholley
Source-Repo: https://github.com/servo/servo
Source-Revision: d3a81373e44634c30d31da0457e1c1e86c0911ed
2016-06-28 22:31:01 +00:00
|
|
|
|
name: name,
|
|
|
|
|
keyframes: parse_keyframe_list(&self.context, input),
|
2016-10-20 16:29:27 +00:00
|
|
|
|
}))))
|
servo: Merge #11766 - Add `@keyframes` and `animation-*` support (from emilio:keyframes-parsing); r=SimonSapin,pcwalton
- [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. -->
This adds support for parsing `@keyframes` rules, and animation properties. Stylo will need it sometime soonish, plus I want to make animations work in Servo.
The remaining part is doin the math and trigger the animations correctly from servo. I don't expect it to be *that* hard, but probaby I'll need to learn a bit more about the current animation infra (e.g. why the heck is the `new_animations_sender` guarded by a `Mutex`?).
I'd expect to land this, since this is already a bunch of work, this is the part exclusively required by stylo (at least if we don't use Servo's machinery), the media query parsing is tested, and the properties land after a flag, but if you prefer to wait until I finish this up it's fine for me too.
r? @SimonSapin
cc @pcwalton @bholley
Source-Repo: https://github.com/servo/servo
Source-Revision: d3a81373e44634c30d31da0457e1c1e86c0911ed
2016-06-28 22:31:01 +00:00
|
|
|
|
}
|
2014-12-16 02:33:46 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-09-04 17:00:52 +00:00
|
|
|
|
|
servo: Merge #12515 - Make the style crate more concrete (from servo:concrete-style); r=bholley
Background:
The changes to Servo code to support Stylo began in the `selectors` crate with making pseudo-elements generic, defined be the user, so that different users (such as Servo and Gecko/Stylo) could have a different set of pseudo-elements supported and parsed. Adding a trait makes sense there since `selectors` is in its own repository and has others users (or at least [one](https://github.com/SimonSapin/kuchiki)).
Then we kind of kept going with the same pattern and added a bunch of traits in the `style` crate to make everything generic, allowing Servo and Gecko/Stylo to do things differently. But we’ve also added a `gecko` Cargo feature to do conditional compilation, at first to enable or disable some CSS properties and values in the Mako templates. Since we’re doing conditional compilation anyway, it’s often easier and simpler to do it more (with `#[cfg(feature = "gecko")]` and `#[cfg(feature = "servo")]`) that to keep adding traits and making everything generic. When a type is generic, any method that we want to call on it needs to be part of some trait.
----
The first several commits move some code around, mostly from `geckolib` to `style` (with `#[cfg(feature = "gecko")]`) but otherwise don’t change much.
The following commits remove some traits and many type parameters through the `style` crate, replacing them with pairs of conditionally-compiled API-compatible items (types, methods, …).
Simplifying code is nice to make it more maintainable, but this is motivated by another change described in https://github.com/servo/servo/pull/12391#issuecomment-232183942. (Porting Servo for that change proved difficult because some code in the `style` crate was becoming generic over `String` vs `Atom`, and this PR will help make that concrete. That change, in turn, is motivated by removing geckolib’s `[replace]` override for string-cache, in order to enable using a single Cargo "workspace" in this repository.)
r? @bholley
---
<!-- 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
- [x] These changes fix #__ (github issue number if applicable).
<!-- Either: -->
- [ ] There are tests for these changes OR
- [x] These changes do not require new tests because refactoring
<!-- 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: 2d01d41a506bcbc7f26a2284b9f42390d6ef96ab
--HG--
rename : servo/ports/geckolib/selector_impl.rs => servo/components/style/gecko_selector_impl.rs
rename : servo/ports/geckolib/values.rs => servo/components/style/gecko_values.rs
rename : servo/ports/geckolib/properties.mako.rs => servo/components/style/properties/gecko.mako.rs
2016-07-20 07:58:34 +00:00
|
|
|
|
impl<'a, 'b> QualifiedRuleParser for NestedRuleParser<'a, 'b> {
|
|
|
|
|
type Prelude = Vec<Selector<TheSelectorImpl>>;
|
2016-11-14 09:36:37 +00:00
|
|
|
|
type QualifiedRule = CssRule;
|
2015-01-30 22:27:53 +00:00
|
|
|
|
|
2016-09-08 20:50:12 +00:00
|
|
|
|
fn parse_prelude(&mut self, input: &mut Parser) -> Result<Vec<Selector<TheSelectorImpl>>, ()> {
|
2015-02-23 15:39:47 +00:00
|
|
|
|
parse_selector_list(&self.context.selector_context, input)
|
2015-01-21 21:27:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-09-08 20:50:12 +00:00
|
|
|
|
fn parse_block(&mut self, prelude: Vec<Selector<TheSelectorImpl>>, input: &mut Parser)
|
2016-11-14 09:36:37 +00:00
|
|
|
|
-> Result<CssRule, ()> {
|
|
|
|
|
Ok(CssRule::Style(Arc::new(RwLock::new(StyleRule {
|
2015-01-21 21:27:48 +00:00
|
|
|
|
selectors: prelude,
|
2016-10-04 16:58:56 +00:00
|
|
|
|
block: Arc::new(RwLock::new(parse_property_declaration_list(self.context, input)))
|
2016-10-20 16:29:27 +00:00
|
|
|
|
}))))
|
2013-09-04 17:00:52 +00:00
|
|
|
|
}
|
|
|
|
|
}
|