End the libstyle 'pub use' madness.

This commit is contained in:
Simon Sapin 2015-01-28 21:46:51 +01:00
parent 493a9e6a89
commit d13d36f57f
39 changed files with 159 additions and 169 deletions

View file

@ -6,7 +6,7 @@ use cssparser::{Token, Parser, DeclarationListParser, AtRuleParser, DeclarationP
use std::ascii::AsciiExt;
use stylesheets::CSSRule;
use properties::longhands::font_family::parse_one_family;
use properties::computed_values::font_family::FontFamily;
use computed_values::font_family::FontFamily;
use media_queries::Device;
use url::{Url, UrlParser};
use parser::{ParserContext, log_css_error};

View file

@ -35,40 +35,27 @@ extern crate lazy_static;
extern crate util;
pub use media_queries::{Device, MediaType};
pub use stylesheets::{Stylesheet, iter_font_face_rules};
pub use selector_matching::{Stylist};
pub use selector_matching::{DeclarationBlock, CommonStyleAffectingAttributes};
pub use selector_matching::{CommonStyleAffectingAttributeInfo, CommonStyleAffectingAttributeMode};
pub use selector_matching::{matches, matches_simple_selector, common_style_affecting_attributes};
pub use selector_matching::{rare_style_affecting_attributes};
pub use selector_matching::{RECOMMENDED_SELECTOR_BLOOM_FILTER_SIZE, SELECTOR_WHITESPACE};
pub use properties::{cascade, cascade_anonymous, longhands_from_shorthand};
pub use properties::{is_supported_property, make_inline};
pub use properties::{PropertyDeclaration};
pub use properties::{computed_values, ComputedValues, style_structs};
pub use properties::{PropertyDeclarationBlock, parse_style_attribute}; // Style attributes
pub use properties::{DeclaredValue, PropertyDeclarationParseResult};
pub use values::CSSFloat;
pub use values::specified::{Angle, AngleOrCorner, HorizontalDirection, VerticalDirection};
pub use values::computed;
pub use node::{TElement, TElementAttributes, TNode};
pub use selectors::{PseudoElement, SelectorList};
pub use selectors::{AttrSelector, NamespaceConstraint};
pub use selectors::{SimpleSelector, parse_author_origin_selector_list_from_str};
pub use cssparser::{Color, RGBA};
pub use legacy::{IntegerAttribute, LengthAttribute};
pub use legacy::{SimpleColorAttribute, UnsignedIntegerAttribute};
pub use font_face::Source;
pub use stylesheets::Origin as StylesheetOrigin;
pub mod stylesheets;
pub mod parser;
pub mod selectors;
pub mod selector_matching;
#[macro_use] pub mod values;
pub mod properties;
#[macro_use] pub mod properties;
pub mod node;
pub mod media_queries;
pub mod font_face;
pub mod legacy;
macro_rules! reexport_computed_values {
( $( $name: ident )+ ) => {
pub mod computed_values {
$(
pub use properties::longhands::$name::computed_value as $name;
)+
// Don't use a side-specific name needlessly:
pub use properties::longhands::border_top_style::computed_value as border_style;
}
}
}
longhand_properties_idents!(reexport_computed_values);

View file

@ -22,6 +22,7 @@ use values::computed;
use selector_matching::DeclarationBlock;
use parser::{ParserContext, log_css_error};
use stylesheets::Origin;
use computed_values;
use self::property_bit_field::PropertyBitField;
@ -2629,43 +2630,43 @@ impl ComputedValues {
}
#[inline]
pub fn content_inline_size(&self) -> computed_values::LengthOrPercentageOrAuto {
pub fn content_inline_size(&self) -> computed::LengthOrPercentageOrAuto {
let box_style = self.get_box();
if self.writing_mode.is_vertical() { box_style.height } else { box_style.width }
}
#[inline]
pub fn content_block_size(&self) -> computed_values::LengthOrPercentageOrAuto {
pub fn content_block_size(&self) -> computed::LengthOrPercentageOrAuto {
let box_style = self.get_box();
if self.writing_mode.is_vertical() { box_style.width } else { box_style.height }
}
#[inline]
pub fn min_inline_size(&self) -> computed_values::LengthOrPercentage {
pub fn min_inline_size(&self) -> computed::LengthOrPercentage {
let box_style = self.get_box();
if self.writing_mode.is_vertical() { box_style.min_height } else { box_style.min_width }
}
#[inline]
pub fn min_block_size(&self) -> computed_values::LengthOrPercentage {
pub fn min_block_size(&self) -> computed::LengthOrPercentage {
let box_style = self.get_box();
if self.writing_mode.is_vertical() { box_style.min_width } else { box_style.min_height }
}
#[inline]
pub fn max_inline_size(&self) -> computed_values::LengthOrPercentageOrNone {
pub fn max_inline_size(&self) -> computed::LengthOrPercentageOrNone {
let box_style = self.get_box();
if self.writing_mode.is_vertical() { box_style.max_height } else { box_style.max_width }
}
#[inline]
pub fn max_block_size(&self) -> computed_values::LengthOrPercentageOrNone {
pub fn max_block_size(&self) -> computed::LengthOrPercentageOrNone {
let box_style = self.get_box();
if self.writing_mode.is_vertical() { box_style.max_width } else { box_style.max_height }
}
#[inline]
pub fn logical_padding(&self) -> LogicalMargin<computed_values::LengthOrPercentage> {
pub fn logical_padding(&self) -> LogicalMargin<computed::LengthOrPercentage> {
let padding_style = self.get_padding();
LogicalMargin::from_physical(self.writing_mode, SideOffsets2D::new(
padding_style.padding_top,
@ -2687,7 +2688,7 @@ impl ComputedValues {
}
#[inline]
pub fn logical_margin(&self) -> LogicalMargin<computed_values::LengthOrPercentageOrAuto> {
pub fn logical_margin(&self) -> LogicalMargin<computed::LengthOrPercentageOrAuto> {
let margin_style = self.get_margin();
LogicalMargin::from_physical(self.writing_mode, SideOffsets2D::new(
margin_style.margin_top,
@ -2698,7 +2699,7 @@ impl ComputedValues {
}
#[inline]
pub fn logical_position(&self) -> LogicalMargin<computed_values::LengthOrPercentageOrAuto> {
pub fn logical_position(&self) -> LogicalMargin<computed::LengthOrPercentageOrAuto> {
// FIXME(SimonSapin): should be the writing mode of the containing block, maybe?
let position_style = self.get_positionoffsets();
LogicalMargin::from_physical(self.writing_mode, SideOffsets2D::new(
@ -3169,6 +3170,17 @@ macro_rules! css_properties_accessors {
}
}
macro_rules! longhand_properties_idents {
($macro_name: ident) => {
$macro_name! {
% for property in LONGHANDS:
${property.ident}
% endfor
}
}
}
pub fn longhands_from_shorthand(shorthand: &str) -> Option<Vec<String>> {
match shorthand {
% for property in SHORTHANDS:
@ -3181,18 +3193,3 @@ pub fn longhands_from_shorthand(shorthand: &str) -> Option<Vec<String>> {
_ => None,
}
}
// Only re-export the types for computed values.
pub mod computed_values {
% for property in LONGHANDS:
pub use super::longhands::${property.ident}::computed_value as ${property.ident};
% endfor
// Don't use a side-specific name needlessly:
pub use super::longhands::border_top_style::computed_value as border_style;
pub use cssparser::RGBA;
pub use values::computed::{
LengthOrPercentage,
LengthOrPercentageOrAuto,
LengthOrPercentageOrNone};
}

View file

@ -21,8 +21,7 @@ use media_queries::Device;
use node::{TElement, TElementAttributes, TNode};
use properties::{PropertyDeclaration, PropertyDeclarationBlock};
use selectors::{CaseSensitivity, Combinator, CompoundSelector, LocalName};
use selectors::{PseudoElement, SelectorList, SimpleSelector};
use selectors::{get_selector_list_selectors};
use selectors::{PseudoElement, SimpleSelector, Selector};
use stylesheets::{Stylesheet, iter_stylesheet_media_rules, iter_stylesheet_style_rules, Origin};
@ -549,14 +548,15 @@ impl DeclarationBlock {
}
}
pub fn matches<'a,E,N>(selector_list: &SelectorList,
pub fn matches<'a,E,N>(selector_list: &Vec<Selector>,
element: &N,
parent_bf: &Option<Box<BloomFilter>>)
-> bool
where E: TElement<'a>, N: TNode<'a,E> {
get_selector_list_selectors(selector_list).iter().any(|selector|
selector_list.iter().any(|selector| {
selector.pseudo_element.is_none() &&
matches_compound_selector(&*selector.compound_selectors, element, parent_bf, &mut false))
matches_compound_selector(&*selector.compound_selectors, element, parent_bf, &mut false)
})
}
/// Determines whether the given element matches the given single or compound selector.

View file

@ -111,17 +111,6 @@ pub enum NamespaceConstraint {
}
/// Re-exported to script, but opaque.
pub struct SelectorList {
selectors: Vec<Selector>
}
/// Public to the style crate, but not re-exported to script
pub fn get_selector_list_selectors<'a>(selector_list: &'a SelectorList) -> &'a [Selector] {
selector_list.selectors.as_slice()
}
fn compute_specificity(mut selector: &CompoundSelector,
pseudo_element: &Option<PseudoElement>) -> u32 {
struct Specificity {
@ -193,12 +182,10 @@ fn compute_specificity(mut selector: &CompoundSelector,
pub fn parse_author_origin_selector_list_from_str(input: &str)
-> Result<SelectorList,()> {
pub fn parse_author_origin_selector_list_from_str(input: &str) -> Result<Vec<Selector>, ()> {
let url = Url::parse("about:blank").unwrap();
let context = ParserContext::new(Origin::Author, &url);
parse_selector_list(&context, &mut Parser::new(input))
.map(|s| SelectorList { selectors: s })
}
/// Parse a comma-separated list of Selectors.

View file

@ -4,6 +4,8 @@
#![allow(non_camel_case_types)]
pub use cssparser::RGBA;
macro_rules! define_css_keyword_enum {
($name: ident: $( $css: expr => $variant: ident ),+,) => {