Skip to content

Commit

Permalink
Remove servo_config dependency for geckolib
Browse files Browse the repository at this point in the history
  • Loading branch information
upsuper committed Apr 7, 2017
1 parent 3150a92 commit c857878
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 12 deletions.
4 changes: 2 additions & 2 deletions components/style/Cargo.toml
Expand Up @@ -16,7 +16,7 @@ doctest = false
gecko = ["nsstring_vendor", "rayon/unstable", "num_cpus"]
use_bindgen = ["bindgen", "regex"]
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",
"rayon/unstable", "servo_url", "servo_url/servo"]
testing = []
Expand Down Expand Up @@ -49,7 +49,7 @@ selectors = { path = "../selectors" }
serde = {version = "0.9", optional = true}
serde_derive = {version = "0.9", optional = true}
servo_atoms = {path = "../atoms", optional = true}
servo_config = {path = "../config"}
servo_config = {path = "../config", optional = true}
smallvec = "0.3"
style_traits = {path = "../style_traits"}
servo_url = {path = "../url", optional = true}
Expand Down
17 changes: 14 additions & 3 deletions components/style/context.rs
Expand Up @@ -17,10 +17,10 @@ use matching::StyleSharingCandidateCache;
use parking_lot::RwLock;
#[cfg(feature = "gecko")] use selector_parser::PseudoElement;
use selectors::matching::ElementSelectorFlags;
use servo_config::opts;
#[cfg(feature = "servo")] use servo_config::opts;
use shared_lock::StylesheetGuards;
use std::collections::HashMap;
use std::env;
#[cfg(not(feature = "servo"))] use std::env;
use std::fmt;
use std::ops::Add;
use std::sync::{Arc, Mutex};
Expand Down Expand Up @@ -170,6 +170,7 @@ impl fmt::Display for TraversalStatistics {
}
}

#[cfg(not(feature = "servo"))]
lazy_static! {
/// 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
Expand All @@ -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 {
/// Returns whether statistics dumping is enabled.
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.
Expand Down
2 changes: 1 addition & 1 deletion components/style/lib.rs
Expand Up @@ -70,7 +70,7 @@ extern crate rayon;
extern crate selectors;
#[cfg(feature = "servo")] #[macro_use] extern crate serde_derive;
#[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;
extern crate smallvec;
#[macro_use]
Expand Down
14 changes: 12 additions & 2 deletions components/style/matching.rs
Expand Up @@ -23,7 +23,7 @@ use selector_parser::{PseudoElement, RestyleDamage, SelectorImpl};
use selectors::bloom::BloomFilter;
use selectors::matching::{ElementSelectorFlags, StyleRelations};
use selectors::matching::AFFECTED_BY_PSEUDO_ELEMENTS;
use servo_config::opts;
#[cfg(feature = "servo")] use servo_config::opts;
use sink::ForgetfulSink;
use std::sync::Arc;
use stylist::ApplicableDeclarationBlock;
Expand Down Expand Up @@ -783,6 +783,16 @@ pub enum StyleSharingBehavior {
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.
pub trait MatchMethods : TElement {
/// Performs selector matching and property cascading on an element and its eager pseudos.
Expand Down Expand Up @@ -1069,7 +1079,7 @@ pub trait MatchMethods : TElement {
shared_context: &SharedStyleContext,
data: &mut AtomicRefMut<ElementData>)
-> StyleSharingResult {
if opts::get().disable_share_style_cache {
if is_share_style_cache_disabled() {
return StyleSharingResult::CannotShare
}

Expand Down
14 changes: 12 additions & 2 deletions components/style/stylesheets.rs
Expand Up @@ -27,6 +27,7 @@ use parser::{Parse, ParserContext, log_css_error};
use properties::{PropertyDeclarationBlock, parse_property_declaration_list};
use selector_parser::{SelectorImpl, SelectorParser};
use selectors::parser::SelectorList;
#[cfg(feature = "servo")]
use servo_config::prefs::PREFS;
#[cfg(not(feature = "gecko"))]
use servo_url::ServoUrl;
Expand Down Expand Up @@ -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> {
type Prelude = AtRulePrelude;
type AtRule = CssRule;
Expand All @@ -1017,8 +1028,7 @@ impl<'a, 'b> AtRuleParser for NestedRuleParser<'a, 'b> {
Ok(AtRuleType::WithBlock(AtRulePrelude::FontFace))
},
"viewport" => {
if PREFS.get("layout.viewport.enabled").as_boolean().unwrap_or(false) ||
cfg!(feature = "gecko") {
if is_viewport_enabled() {
Ok(AtRuleType::WithBlock(AtRulePrelude::Viewport))
} else {
Err(())
Expand Down
14 changes: 12 additions & 2 deletions components/style/traversal.rs
Expand Up @@ -13,7 +13,7 @@ use dom::{DirtyDescendants, NodeInfo, TElement, TNode};
use matching::{MatchMethods, StyleSharingBehavior};
use restyle_hints::{RESTYLE_DESCENDANTS, RESTYLE_SELF};
use selector_parser::RestyleDamage;
use servo_config::opts;
#[cfg(feature = "servo")] use servo_config::opts;
use std::borrow::BorrowMut;
use stylist::Stylist;

Expand Down Expand Up @@ -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
/// Gecko and Servo.
pub trait DomTraversal<E: TElement> : Sync {
Expand Down Expand Up @@ -175,7 +185,7 @@ pub trait DomTraversal<E: TElement> : Sync {
/// Returns true if traversal is needed for the given node and subtree.
fn node_needs_traversal(node: E::ConcreteNode, animation_only: bool) -> bool {
// Non-incremental layout visits every node.
if cfg!(feature = "servo") && opts::get().nonincremental_layout {
if is_servo_nonincremental_layout() {
return true;
}

Expand Down

0 comments on commit c857878

Please sign in to comment.