Remove servo_config dependency for geckolib

This commit is contained in:
Xidorn Quan 2017-04-07 17:12:01 +10:00
parent 3150a92651
commit c857878ce9
6 changed files with 53 additions and 12 deletions

View file

@ -16,7 +16,7 @@ doctest = false
gecko = ["nsstring_vendor", "rayon/unstable", "num_cpus"] gecko = ["nsstring_vendor", "rayon/unstable", "num_cpus"]
use_bindgen = ["bindgen", "regex"] use_bindgen = ["bindgen", "regex"]
servo = ["serde/unstable", "serde", "serde_derive", "heapsize", "heapsize_derive", servo = ["serde/unstable", "serde", "serde_derive", "heapsize", "heapsize_derive",
"style_traits/servo", "servo_atoms", "html5ever-atoms", "style_traits/servo", "servo_atoms", "servo_config", "html5ever-atoms",
"cssparser/heapsize", "cssparser/serde", "encoding", "cssparser/heapsize", "cssparser/serde", "encoding",
"rayon/unstable", "servo_url", "servo_url/servo"] "rayon/unstable", "servo_url", "servo_url/servo"]
testing = [] testing = []
@ -49,7 +49,7 @@ selectors = { path = "../selectors" }
serde = {version = "0.9", optional = true} serde = {version = "0.9", optional = true}
serde_derive = {version = "0.9", optional = true} serde_derive = {version = "0.9", optional = true}
servo_atoms = {path = "../atoms", optional = true} servo_atoms = {path = "../atoms", optional = true}
servo_config = {path = "../config"} servo_config = {path = "../config", optional = true}
smallvec = "0.3" smallvec = "0.3"
style_traits = {path = "../style_traits"} style_traits = {path = "../style_traits"}
servo_url = {path = "../url", optional = true} servo_url = {path = "../url", optional = true}

View file

@ -17,10 +17,10 @@ use matching::StyleSharingCandidateCache;
use parking_lot::RwLock; use parking_lot::RwLock;
#[cfg(feature = "gecko")] use selector_parser::PseudoElement; #[cfg(feature = "gecko")] use selector_parser::PseudoElement;
use selectors::matching::ElementSelectorFlags; use selectors::matching::ElementSelectorFlags;
use servo_config::opts; #[cfg(feature = "servo")] use servo_config::opts;
use shared_lock::StylesheetGuards; use shared_lock::StylesheetGuards;
use std::collections::HashMap; use std::collections::HashMap;
use std::env; #[cfg(not(feature = "servo"))] use std::env;
use std::fmt; use std::fmt;
use std::ops::Add; use std::ops::Add;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
@ -170,6 +170,7 @@ impl fmt::Display for TraversalStatistics {
} }
} }
#[cfg(not(feature = "servo"))]
lazy_static! { lazy_static! {
/// Whether to dump style statistics, computed statically. We use an environmental /// Whether to dump style statistics, computed statically. We use an environmental
/// variable so that this is easy to set for Gecko builds, and matches the /// variable so that this is easy to set for Gecko builds, and matches the
@ -182,10 +183,20 @@ lazy_static! {
}; };
} }
#[cfg(feature = "servo")]
fn shall_stat_style_sharing() -> bool {
opts::get().style_sharing_stats
}
#[cfg(not(feature = "servo"))]
fn shall_stat_style_sharing() -> bool {
*DUMP_STYLE_STATISTICS
}
impl TraversalStatistics { impl TraversalStatistics {
/// Returns whether statistics dumping is enabled. /// Returns whether statistics dumping is enabled.
pub fn should_dump() -> bool { pub fn should_dump() -> bool {
*DUMP_STYLE_STATISTICS || opts::get().style_sharing_stats shall_stat_style_sharing()
} }
/// Computes the traversal time given the start time in seconds. /// Computes the traversal time given the start time in seconds.

View file

@ -70,7 +70,7 @@ extern crate rayon;
extern crate selectors; extern crate selectors;
#[cfg(feature = "servo")] #[macro_use] extern crate serde_derive; #[cfg(feature = "servo")] #[macro_use] extern crate serde_derive;
#[cfg(feature = "servo")] #[macro_use] extern crate servo_atoms; #[cfg(feature = "servo")] #[macro_use] extern crate servo_atoms;
extern crate servo_config; #[cfg(feature = "servo")] extern crate servo_config;
#[cfg(feature = "servo")] extern crate servo_url; #[cfg(feature = "servo")] extern crate servo_url;
extern crate smallvec; extern crate smallvec;
#[macro_use] #[macro_use]

View file

@ -23,7 +23,7 @@ use selector_parser::{PseudoElement, RestyleDamage, SelectorImpl};
use selectors::bloom::BloomFilter; use selectors::bloom::BloomFilter;
use selectors::matching::{ElementSelectorFlags, StyleRelations}; use selectors::matching::{ElementSelectorFlags, StyleRelations};
use selectors::matching::AFFECTED_BY_PSEUDO_ELEMENTS; use selectors::matching::AFFECTED_BY_PSEUDO_ELEMENTS;
use servo_config::opts; #[cfg(feature = "servo")] use servo_config::opts;
use sink::ForgetfulSink; use sink::ForgetfulSink;
use std::sync::Arc; use std::sync::Arc;
use stylist::ApplicableDeclarationBlock; use stylist::ApplicableDeclarationBlock;
@ -783,6 +783,16 @@ pub enum StyleSharingBehavior {
Disallow, Disallow,
} }
#[cfg(feature = "servo")]
fn is_share_style_cache_disabled() -> bool {
opts::get().disable_share_style_cache
}
#[cfg(not(feature = "servo"))]
fn is_share_style_cache_disabled() -> bool {
false
}
/// The public API that elements expose for selector matching. /// The public API that elements expose for selector matching.
pub trait MatchMethods : TElement { pub trait MatchMethods : TElement {
/// Performs selector matching and property cascading on an element and its eager pseudos. /// Performs selector matching and property cascading on an element and its eager pseudos.
@ -1069,7 +1079,7 @@ pub trait MatchMethods : TElement {
shared_context: &SharedStyleContext, shared_context: &SharedStyleContext,
data: &mut AtomicRefMut<ElementData>) data: &mut AtomicRefMut<ElementData>)
-> StyleSharingResult { -> StyleSharingResult {
if opts::get().disable_share_style_cache { if is_share_style_cache_disabled() {
return StyleSharingResult::CannotShare return StyleSharingResult::CannotShare
} }

View file

@ -27,6 +27,7 @@ use parser::{Parse, ParserContext, log_css_error};
use properties::{PropertyDeclarationBlock, parse_property_declaration_list}; use properties::{PropertyDeclarationBlock, parse_property_declaration_list};
use selector_parser::{SelectorImpl, SelectorParser}; use selector_parser::{SelectorImpl, SelectorParser};
use selectors::parser::SelectorList; use selectors::parser::SelectorList;
#[cfg(feature = "servo")]
use servo_config::prefs::PREFS; use servo_config::prefs::PREFS;
#[cfg(not(feature = "gecko"))] #[cfg(not(feature = "gecko"))]
use servo_url::ServoUrl; use servo_url::ServoUrl;
@ -997,6 +998,16 @@ impl<'a, 'b> NestedRuleParser<'a, 'b> {
} }
} }
#[cfg(feature = "servo")]
fn is_viewport_enabled() -> bool {
PREFS.get("layout.viewport.enabled").as_boolean().unwrap_or(false)
}
#[cfg(not(feature = "servo"))]
fn is_viewport_enabled() -> bool {
true
}
impl<'a, 'b> AtRuleParser for NestedRuleParser<'a, 'b> { impl<'a, 'b> AtRuleParser for NestedRuleParser<'a, 'b> {
type Prelude = AtRulePrelude; type Prelude = AtRulePrelude;
type AtRule = CssRule; type AtRule = CssRule;
@ -1017,8 +1028,7 @@ impl<'a, 'b> AtRuleParser for NestedRuleParser<'a, 'b> {
Ok(AtRuleType::WithBlock(AtRulePrelude::FontFace)) Ok(AtRuleType::WithBlock(AtRulePrelude::FontFace))
}, },
"viewport" => { "viewport" => {
if PREFS.get("layout.viewport.enabled").as_boolean().unwrap_or(false) || if is_viewport_enabled() {
cfg!(feature = "gecko") {
Ok(AtRuleType::WithBlock(AtRulePrelude::Viewport)) Ok(AtRuleType::WithBlock(AtRulePrelude::Viewport))
} else { } else {
Err(()) Err(())

View file

@ -13,7 +13,7 @@ use dom::{DirtyDescendants, NodeInfo, TElement, TNode};
use matching::{MatchMethods, StyleSharingBehavior}; use matching::{MatchMethods, StyleSharingBehavior};
use restyle_hints::{RESTYLE_DESCENDANTS, RESTYLE_SELF}; use restyle_hints::{RESTYLE_DESCENDANTS, RESTYLE_SELF};
use selector_parser::RestyleDamage; use selector_parser::RestyleDamage;
use servo_config::opts; #[cfg(feature = "servo")] use servo_config::opts;
use std::borrow::BorrowMut; use std::borrow::BorrowMut;
use stylist::Stylist; use stylist::Stylist;
@ -100,6 +100,16 @@ impl TraversalDriver {
} }
} }
#[cfg(feature = "servo")]
fn is_servo_nonincremental_layout() -> bool {
opts::get().nonincremental_layout
}
#[cfg(not(feature = "servo"))]
fn is_servo_nonincremental_layout() -> bool {
false
}
/// A DOM Traversal trait, that is used to generically implement styling for /// A DOM Traversal trait, that is used to generically implement styling for
/// Gecko and Servo. /// Gecko and Servo.
pub trait DomTraversal<E: TElement> : Sync { pub trait DomTraversal<E: TElement> : Sync {
@ -175,7 +185,7 @@ pub trait DomTraversal<E: TElement> : Sync {
/// Returns true if traversal is needed for the given node and subtree. /// Returns true if traversal is needed for the given node and subtree.
fn node_needs_traversal(node: E::ConcreteNode, animation_only: bool) -> bool { fn node_needs_traversal(node: E::ConcreteNode, animation_only: bool) -> bool {
// Non-incremental layout visits every node. // Non-incremental layout visits every node.
if cfg!(feature = "servo") && opts::get().nonincremental_layout { if is_servo_nonincremental_layout() {
return true; return true;
} }