Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Move selector matching to an external library, for use outside Servo. #5010

Merged
merged 1 commit into from Feb 23, 2015
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Move selector matching to an external library, for use outside Servo.

  • Loading branch information
SimonSapin committed Feb 23, 2015
commit 2a50755c8a751218c8e3d5de53c831deaf061e64
@@ -43,6 +43,9 @@ path = "../util"
[dependencies.cssparser]
git = "https://github.com/servo/rust-cssparser"

[dependencies.selectors]
git = "https://github.com/servo/rust-selectors"

[dependencies.geom]
git = "https://github.com/servo/rust-geom"

@@ -12,7 +12,7 @@ use util::{LayoutDataAccess, LayoutDataWrapper};
use wrapper::{LayoutElement, LayoutNode, TLayoutNode};

use script::dom::node::NodeTypeId;
use servo_util::bloom::BloomFilter;
use selectors::bloom::BloomFilter;
use servo_util::cache::{LRUCache, SimpleHashCache};
use servo_util::smallvec::{SmallVec, SmallVec16};
use servo_util::arc_ptr_eq;
@@ -21,12 +21,12 @@ use std::mem;
use std::hash::{Hash, Hasher, Writer};
use std::slice::Iter;
use string_cache::{Atom, Namespace};
use style::selectors::PseudoElement;
use selectors::parser::PseudoElement;
use style::selector_matching::{Stylist, DeclarationBlock};
use style::node::{TElement, TNode};
use style::properties::{ComputedValues, cascade};
use style::selector_matching::{CommonStyleAffectingAttributeMode, CommonStyleAffectingAttributes};
use style::selector_matching::{common_style_affecting_attributes, rare_style_affecting_attributes};
use selectors::matching::{CommonStyleAffectingAttributeMode, CommonStyleAffectingAttributes};
use selectors::matching::{common_style_affecting_attributes, rare_style_affecting_attributes};
use std::sync::Arc;

pub struct ApplicableDeclarations {
@@ -41,6 +41,7 @@ extern crate style;
extern crate "plugins" as servo_plugins;
extern crate net;
extern crate msg;
extern crate selectors;
#[macro_use]
extern crate "util" as servo_util;

@@ -18,7 +18,7 @@ use wrapper::{layout_node_to_unsafe_layout_node, LayoutNode};
use wrapper::{PostorderNodeMutTraversal, ThreadSafeLayoutNode, UnsafeLayoutNode};
use wrapper::{PreorderDomTraversal, PostorderDomTraversal};

use servo_util::bloom::BloomFilter;
use selectors::bloom::BloomFilter;
use servo_util::opts;
use servo_util::tid::tid;
use style::node::TNode;
@@ -68,7 +68,7 @@ use std::mem;
use std::sync::mpsc::Sender;
use string_cache::{Atom, Namespace};
use style::computed_values::{content, display, white_space};
use style::selectors::{NamespaceConstraint, AttrSelector};
use selectors::parser::{NamespaceConstraint, AttrSelector};
use style::legacy::{LengthAttribute, SimpleColorAttribute, UnsignedIntegerAttribute, IntegerAttribute};
use style::node::{TElement, TElementAttributes, TNode};
use style::properties::PropertyDeclarationBlock;
@@ -42,6 +42,9 @@ path = "../canvas"
[dependencies.cssparser]
git = "https://github.com/servo/rust-cssparser"

[dependencies.selectors]
git = "https://github.com/servo/rust-selectors"

[dependencies.geom]
git = "https://github.com/servo/rust-geom"

@@ -53,9 +53,9 @@ use dom::nodelist::NodeList;
use dom::virtualmethods::{VirtualMethods, vtable_for};
use devtools_traits::AttrInfo;
use style::legacy::{SimpleColorAttribute, UnsignedIntegerAttribute, IntegerAttribute, LengthAttribute};
use style::selector_matching::matches;
use selectors::matching::matches;
use style::properties::{PropertyDeclarationBlock, PropertyDeclaration, parse_style_attribute};
use style::selectors::parse_author_origin_selector_list_from_str;
use selectors::parser::parse_author_origin_selector_list_from_str;
use style;
use util::namespace;
use util::str::{DOMString, LengthOrPercentageOrAuto};
@@ -48,9 +48,9 @@ use devtools_traits::NodeInfo;
use script_traits::UntrustedNodeAddress;
use util::geometry::Au;
use util::str::{DOMString, null_str_as_empty};
use style::selectors::{Selector, AttrSelector, NamespaceConstraint};
use style::selectors::parse_author_origin_selector_list_from_str;
use style::selector_matching::matches;
use selectors::parser::{Selector, AttrSelector, NamespaceConstraint};
use selectors::parser::parse_author_origin_selector_list_from_str;
use selectors::matching::matches;
use style::properties::ComputedValues;
use style;

@@ -41,6 +41,7 @@ extern crate "rustc-serialize" as rustc_serialize;
extern crate time;
extern crate canvas;
extern crate script_traits;
extern crate selectors;
#[no_link] #[plugin] #[macro_use]
extern crate "plugins" as servo_plugins;
extern crate util;

Some generated files are not rendered by default. Learn more.

@@ -21,6 +21,9 @@ git = "https://github.com/servo/rust-geom"
[dependencies.cssparser]
git = "https://github.com/servo/rust-cssparser"

[dependencies.selectors]
git = "https://github.com/servo/rust-selectors"

[dependencies.lazy_static]
git = "https://github.com/Kimundi/lazy-static.rs"

@@ -5,17 +5,21 @@
//! Legacy presentational attributes defined in the HTML5 specification: `<td width>`,
//! `<input size>`, and so forth.

use node::{TElement, TElementAttributes, TNode};
use std::sync::Arc;

use selectors::tree::{TElement, TNode};
use selectors::matching::DeclarationBlock;
use node::TElementAttributes;
use values::specified::CSSColor;
use values::{CSSFloat, specified};
use properties::DeclaredValue::SpecifiedValue;
use properties::PropertyDeclaration;
use properties::longhands;
use selector_matching::{DeclarationBlock, Stylist};
use selector_matching::Stylist;

use cssparser::Color;
use selectors::smallvec::VecLike;
use util::geometry::Au;
use util::smallvec::VecLike;
use util::str::LengthOrPercentageOrAuto;

/// Legacy presentational attributes that take a length as defined in HTML5 § 2.4.4.4.
@@ -68,7 +72,7 @@ pub trait PresentationalHintSynthesis {
where E: TElement<'a> +
TElementAttributes,
N: TNode<'a,E>,
V: VecLike<DeclarationBlock>;
V: VecLike<DeclarationBlock<Vec<PropertyDeclaration>>>;
/// Synthesizes rules for the legacy `bgcolor` attribute.
fn synthesize_presentational_hint_for_legacy_background_color_attribute<'a,E,V>(
&self,
@@ -80,7 +84,7 @@ pub trait PresentationalHintSynthesis {
E: TElement<'a> +
TElementAttributes,
V: VecLike<
DeclarationBlock>;
DeclarationBlock<Vec<PropertyDeclaration>>>;
/// Synthesizes rules for the legacy `border` attribute.
fn synthesize_presentational_hint_for_legacy_border_attribute<'a,E,V>(
&self,
@@ -90,7 +94,7 @@ pub trait PresentationalHintSynthesis {
where
E: TElement<'a> +
TElementAttributes,
V: VecLike<DeclarationBlock>;
V: VecLike<DeclarationBlock<Vec<PropertyDeclaration>>>;
}

impl PresentationalHintSynthesis for Stylist {
@@ -102,21 +106,21 @@ impl PresentationalHintSynthesis for Stylist {
where E: TElement<'a> +
TElementAttributes,
N: TNode<'a,E>,
V: VecLike<DeclarationBlock> {
V: VecLike<DeclarationBlock<Vec<PropertyDeclaration>>> {
let element = node.as_element();
match element.get_local_name() {
name if *name == atom!("td") => {
match element.get_length_attribute(LengthAttribute::Width) {
LengthOrPercentageOrAuto::Auto => {}
LengthOrPercentageOrAuto::Percentage(percentage) => {
let width_value = specified::LengthOrPercentageOrAuto::Percentage(percentage);
matching_rules_list.vec_push(DeclarationBlock::from_declaration(
matching_rules_list.vec_push(from_declaration(
PropertyDeclaration::Width(SpecifiedValue(width_value))));
*shareable = false
}
LengthOrPercentageOrAuto::Length(length) => {
let width_value = specified::LengthOrPercentageOrAuto::Length(specified::Length::Au(length));
matching_rules_list.vec_push(DeclarationBlock::from_declaration(
matching_rules_list.vec_push(from_declaration(
PropertyDeclaration::Width(SpecifiedValue(width_value))));
*shareable = false
}
@@ -160,7 +164,7 @@ impl PresentationalHintSynthesis for Stylist {
}
_ => specified::Length::Au(Au::from_px(value as int)),
};
matching_rules_list.vec_push(DeclarationBlock::from_declaration(
matching_rules_list.vec_push(from_declaration(
PropertyDeclaration::Width(SpecifiedValue(
specified::LengthOrPercentageOrAuto::Length(value)))));
*shareable = false
@@ -177,7 +181,7 @@ impl PresentationalHintSynthesis for Stylist {
//
// https://html.spec.whatwg.org/multipage/rendering.html#textarea-effective-width
let value = specified::Length::ServoCharacterWidth(value);
matching_rules_list.vec_push(DeclarationBlock::from_declaration(
matching_rules_list.vec_push(from_declaration(
PropertyDeclaration::Width(SpecifiedValue(
specified::LengthOrPercentageOrAuto::Length(value)))));
*shareable = false
@@ -190,7 +194,7 @@ impl PresentationalHintSynthesis for Stylist {
//
// https://html.spec.whatwg.org/multipage/rendering.html#textarea-effective-height
let value = specified::Length::Em(value as CSSFloat);
matching_rules_list.vec_push(DeclarationBlock::from_declaration(
matching_rules_list.vec_push(from_declaration(
PropertyDeclaration::Height(SpecifiedValue(
longhands::height::SpecifiedValue(
specified::LengthOrPercentageOrAuto::Length(value))))));
@@ -213,11 +217,11 @@ impl PresentationalHintSynthesis for Stylist {
E: TElement<'a> +
TElementAttributes,
V: VecLike<
DeclarationBlock> {
DeclarationBlock<Vec<PropertyDeclaration>>> {
match element.get_simple_color_attribute(SimpleColorAttribute::BgColor) {
None => {}
Some(color) => {
matching_rules_list.vec_push(DeclarationBlock::from_declaration(
matching_rules_list.vec_push(from_declaration(
PropertyDeclaration::BackgroundColor(SpecifiedValue(
CSSColor { parsed: Color::RGBA(color), authored: None }))));
*shareable = false
@@ -233,21 +237,21 @@ impl PresentationalHintSynthesis for Stylist {
where
E: TElement<'a> +
TElementAttributes,
V: VecLike<DeclarationBlock> {
V: VecLike<DeclarationBlock<Vec<PropertyDeclaration>>> {
match element.get_unsigned_integer_attribute(UnsignedIntegerAttribute::Border) {
None => {}
Some(length) => {
let width_value = specified::Length::Au(Au::from_px(length as int));
matching_rules_list.vec_push(DeclarationBlock::from_declaration(
matching_rules_list.vec_push(from_declaration(
PropertyDeclaration::BorderTopWidth(SpecifiedValue(
longhands::border_top_width::SpecifiedValue(width_value)))));
matching_rules_list.vec_push(DeclarationBlock::from_declaration(
matching_rules_list.vec_push(from_declaration(
PropertyDeclaration::BorderLeftWidth(SpecifiedValue(
longhands::border_left_width::SpecifiedValue(width_value)))));
matching_rules_list.vec_push(DeclarationBlock::from_declaration(
matching_rules_list.vec_push(from_declaration(
PropertyDeclaration::BorderBottomWidth(SpecifiedValue(
longhands::border_bottom_width::SpecifiedValue(width_value)))));
matching_rules_list.vec_push(DeclarationBlock::from_declaration(
matching_rules_list.vec_push(from_declaration(
PropertyDeclaration::BorderRightWidth(SpecifiedValue(
longhands::border_right_width::SpecifiedValue(width_value)))));
*shareable = false
@@ -256,3 +260,10 @@ impl PresentationalHintSynthesis for Stylist {
}
}


/// A convenience function to create a declaration block from a single declaration. This is
/// primarily used in `synthesize_rules_for_legacy_attributes`.
#[inline]
pub fn from_declaration(rule: PropertyDeclaration) -> DeclarationBlock<Vec<PropertyDeclaration>> {
DeclarationBlock::from_declarations(Arc::new(vec![rule]))
}
@@ -7,7 +7,6 @@
#![feature(box_syntax)]
#![feature(core)]
#![feature(std_misc)]
#![feature(hash)]
#![feature(collections)]
#![feature(rustc_private)]

@@ -30,6 +29,7 @@ extern crate matches;

extern crate encoding;
extern crate string_cache;
extern crate selectors;

#[macro_use]
extern crate lazy_static;
@@ -41,7 +41,6 @@ extern crate util;

pub mod stylesheets;
pub mod parser;
pub mod selectors;
pub mod selector_matching;
#[macro_use] pub mod values;

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.