mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Move util::vec::ForgetfulSink to style::sink and simplify it
This commit is contained in:
parent
51ff916e09
commit
a5b524d559
14 changed files with 58 additions and 89 deletions
|
@ -75,7 +75,6 @@ use selectors::matching::{DeclarationBlock, ElementFlags, matches};
|
|||
use selectors::matching::{HAS_SLOW_SELECTOR, HAS_EDGE_CHILD_SELECTOR, HAS_SLOW_SELECTOR_LATER_SIBLINGS};
|
||||
use selectors::matching::{common_style_affecting_attributes, rare_style_affecting_attributes};
|
||||
use selectors::parser::{AttrSelector, NamespaceConstraint, parse_author_origin_selector_list_from_str};
|
||||
use smallvec::VecLike;
|
||||
use std::ascii::AsciiExt;
|
||||
use std::borrow::Cow;
|
||||
use std::cell::{Cell, Ref};
|
||||
|
@ -91,6 +90,7 @@ use style::properties::DeclaredValue;
|
|||
use style::properties::longhands::{self, background_image, border_spacing, font_family, overflow_x, font_size};
|
||||
use style::properties::{PropertyDeclaration, PropertyDeclarationBlock, parse_style_attribute};
|
||||
use style::selector_impl::{NonTSPseudoClass, ServoSelectorImpl};
|
||||
use style::sink::Push;
|
||||
use style::values::CSSFloat;
|
||||
use style::values::specified::{self, CSSColor, CSSRGBA, LengthOrPercentage};
|
||||
|
||||
|
@ -275,7 +275,7 @@ pub trait LayoutElementHelpers {
|
|||
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn synthesize_presentational_hints_for_legacy_attributes<V>(&self, &mut V)
|
||||
where V: VecLike<DeclarationBlock<Vec<PropertyDeclaration>>>;
|
||||
where V: Push<DeclarationBlock<Vec<PropertyDeclaration>>>;
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn get_colspan(self) -> u32;
|
||||
#[allow(unsafe_code)]
|
||||
|
@ -308,7 +308,7 @@ impl LayoutElementHelpers for LayoutJS<Element> {
|
|||
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn synthesize_presentational_hints_for_legacy_attributes<V>(&self, hints: &mut V)
|
||||
where V: VecLike<DeclarationBlock<Vec<PropertyDeclaration>>>
|
||||
where V: Push<DeclarationBlock<Vec<PropertyDeclaration>>>
|
||||
{
|
||||
#[inline]
|
||||
fn from_declaration(rule: PropertyDeclaration) -> DeclarationBlock<Vec<PropertyDeclaration>> {
|
||||
|
|
|
@ -49,7 +49,6 @@ use script_layout_interface::{HTMLCanvasData, LayoutNodeType, TrustedNodeAddress
|
|||
use script_layout_interface::{OpaqueStyleAndLayoutData, PartialStyleAndLayoutData};
|
||||
use selectors::matching::{DeclarationBlock, ElementFlags};
|
||||
use selectors::parser::{AttrSelector, NamespaceConstraint};
|
||||
use smallvec::VecLike;
|
||||
use std::marker::PhantomData;
|
||||
use std::mem::{transmute, transmute_copy};
|
||||
use string_cache::{Atom, BorrowedAtom, BorrowedNamespace, Namespace};
|
||||
|
@ -63,6 +62,7 @@ use style::refcell::{Ref, RefCell, RefMut};
|
|||
use style::restyle_hints::ElementSnapshot;
|
||||
use style::selector_impl::{NonTSPseudoClass, ServoSelectorImpl};
|
||||
use style::servo::{PrivateStyleData, SharedStyleContext};
|
||||
use style::sink::Push;
|
||||
use url::Url;
|
||||
use util::str::is_whitespace;
|
||||
|
||||
|
@ -360,7 +360,7 @@ pub struct ServoLayoutElement<'le> {
|
|||
|
||||
impl<'le> PresentationalHintsSynthetizer for ServoLayoutElement<'le> {
|
||||
fn synthesize_presentational_hints_for_legacy_attributes<V>(&self, hints: &mut V)
|
||||
where V: VecLike<DeclarationBlock<Vec<PropertyDeclaration>>>
|
||||
where V: Push<DeclarationBlock<Vec<PropertyDeclaration>>>
|
||||
{
|
||||
unsafe {
|
||||
self.element.synthesize_presentational_hints_for_legacy_attributes(hints);
|
||||
|
@ -995,5 +995,5 @@ impl <'le> ::selectors::Element for ServoThreadSafeLayoutElement<'le> {
|
|||
|
||||
impl<'le> PresentationalHintsSynthetizer for ServoThreadSafeLayoutElement<'le> {
|
||||
fn synthesize_presentational_hints_for_legacy_attributes<V>(&self, _hints: &mut V)
|
||||
where V: VecLike<DeclarationBlock<Vec<PropertyDeclaration>>> {}
|
||||
where V: Push<DeclarationBlock<Vec<PropertyDeclaration>>> {}
|
||||
}
|
||||
|
|
1
components/servo/Cargo.lock
generated
1
components/servo/Cargo.lock
generated
|
@ -2471,7 +2471,6 @@ dependencies = [
|
|||
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 0.7.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_macros 0.7.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"smallvec 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"url 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"xdg 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
|
|
@ -15,7 +15,7 @@ use restyle_hints::{ElementSnapshot, RESTYLE_DESCENDANTS, RESTYLE_LATER_SIBLINGS
|
|||
use selector_impl::{ElementExt, SelectorImplExt};
|
||||
use selectors::Element;
|
||||
use selectors::matching::DeclarationBlock;
|
||||
use smallvec::VecLike;
|
||||
use sink::Push;
|
||||
use std::ops::BitOr;
|
||||
use std::sync::Arc;
|
||||
use string_cache::{Atom, Namespace};
|
||||
|
@ -194,7 +194,7 @@ pub trait TDocument : Sized + Copy + Clone {
|
|||
|
||||
pub trait PresentationalHintsSynthetizer {
|
||||
fn synthesize_presentational_hints_for_legacy_attributes<V>(&self, hints: &mut V)
|
||||
where V: VecLike<DeclarationBlock<Vec<PropertyDeclaration>>>;
|
||||
where V: Push<DeclarationBlock<Vec<PropertyDeclaration>>>;
|
||||
}
|
||||
|
||||
pub trait TElement : Sized + Copy + Clone + ElementExt + PresentationalHintsSynthetizer {
|
||||
|
|
|
@ -88,6 +88,7 @@ pub mod selector_impl;
|
|||
pub mod selector_matching;
|
||||
pub mod sequential;
|
||||
pub mod servo;
|
||||
pub mod sink;
|
||||
pub mod stylesheets;
|
||||
pub mod traversal;
|
||||
#[macro_use]
|
||||
|
|
|
@ -17,6 +17,7 @@ use selectors::Element;
|
|||
use selectors::bloom::BloomFilter;
|
||||
use selectors::matching::{CommonStyleAffectingAttributeMode, CommonStyleAffectingAttributes};
|
||||
use selectors::matching::{common_style_affecting_attributes, rare_style_affecting_attributes};
|
||||
use sink::ForgetfulSink;
|
||||
use smallvec::SmallVec;
|
||||
use std::collections::HashMap;
|
||||
use std::hash::{BuildHasherDefault, Hash, Hasher};
|
||||
|
@ -26,7 +27,6 @@ use string_cache::{Atom, Namespace};
|
|||
use util::arc_ptr_eq;
|
||||
use util::cache::{LRUCache, SimpleHashCache};
|
||||
use util::opts;
|
||||
use util::vec::ForgetfulSink;
|
||||
|
||||
fn create_common_style_affecting_attributes_from_element<E: TElement>(element: &E)
|
||||
-> CommonStyleAffectingAttributes {
|
||||
|
|
|
@ -18,6 +18,7 @@ use selectors::bloom::BloomFilter;
|
|||
use selectors::matching::DeclarationBlock as GenericDeclarationBlock;
|
||||
use selectors::matching::{Rule, SelectorMap};
|
||||
use selectors::parser::SelectorImpl;
|
||||
use sink::Push;
|
||||
use smallvec::VecLike;
|
||||
use std::collections::HashMap;
|
||||
use std::hash::BuildHasherDefault;
|
||||
|
@ -389,7 +390,7 @@ impl<Impl: SelectorImplExt> Stylist<Impl> {
|
|||
applicable_declarations: &mut V)
|
||||
-> bool
|
||||
where E: Element<Impl=Impl> + PresentationalHintsSynthetizer,
|
||||
V: VecLike<DeclarationBlock> {
|
||||
V: Push<DeclarationBlock> + VecLike<DeclarationBlock> {
|
||||
assert!(!self.is_device_dirty);
|
||||
assert!(style_attribute.is_none() || pseudo_element.is_none(),
|
||||
"Style attributes do not apply to pseudo-elements");
|
||||
|
@ -430,7 +431,8 @@ impl<Impl: SelectorImplExt> Stylist<Impl> {
|
|||
// Step 4: Normal style attributes.
|
||||
style_attribute.map(|sa| {
|
||||
shareable = false;
|
||||
applicable_declarations.push(
|
||||
Push::push(
|
||||
applicable_declarations,
|
||||
GenericDeclarationBlock::from_declarations(sa.normal.clone()))
|
||||
});
|
||||
|
||||
|
@ -443,7 +445,8 @@ impl<Impl: SelectorImplExt> Stylist<Impl> {
|
|||
// Step 6: `!important` style attributes.
|
||||
style_attribute.map(|sa| {
|
||||
shareable = false;
|
||||
applicable_declarations.push(
|
||||
Push::push(
|
||||
applicable_declarations,
|
||||
GenericDeclarationBlock::from_declarations(sa.important.clone()))
|
||||
});
|
||||
|
||||
|
|
40
components/style/sink.rs
Normal file
40
components/style/sink.rs
Normal file
|
@ -0,0 +1,40 @@
|
|||
/* 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/. */
|
||||
|
||||
use smallvec::{Array, SmallVec};
|
||||
use std::marker::PhantomData;
|
||||
|
||||
pub trait Push<T> {
|
||||
fn push(&mut self, value: T);
|
||||
}
|
||||
|
||||
impl<T> Push<T> for Vec<T> {
|
||||
fn push(&mut self, value: T) {
|
||||
Vec::push(self, value);
|
||||
}
|
||||
}
|
||||
|
||||
impl<A: Array> Push<A::Item> for SmallVec<A> {
|
||||
fn push(&mut self, value: A::Item) {
|
||||
SmallVec::push(self, value);
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ForgetfulSink<T>(bool, PhantomData<T>);
|
||||
|
||||
impl<T> ForgetfulSink<T> {
|
||||
pub fn new() -> Self {
|
||||
ForgetfulSink(true, PhantomData)
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Push<T> for ForgetfulSink<T> {
|
||||
fn push(&mut self, _value: T) {
|
||||
self.0 = false;
|
||||
}
|
||||
}
|
|
@ -31,7 +31,6 @@ rand = "0.3"
|
|||
rustc-serialize = "0.3"
|
||||
serde = {version = "0.7.11", optional = true}
|
||||
serde_macros = {version = "0.7.11", optional = true}
|
||||
smallvec = "0.1"
|
||||
url = "1.0.0"
|
||||
|
||||
[target.'cfg(all(unix, not(target_os = "macos"), not(target_os = "ios"), not(target_os = "android")))'.dependencies]
|
||||
|
|
|
@ -27,7 +27,6 @@ extern crate num_traits;
|
|||
extern crate rand;
|
||||
extern crate rustc_serialize;
|
||||
#[cfg(feature = "servo")] extern crate serde;
|
||||
extern crate smallvec;
|
||||
extern crate url;
|
||||
#[cfg(all(unix, not(target_os = "macos"), not(target_os = "ios"), not(target_os = "android")))]
|
||||
extern crate xdg;
|
||||
|
|
|
@ -2,10 +2,6 @@
|
|||
* 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/. */
|
||||
|
||||
use std::marker::PhantomData;
|
||||
use std::ops;
|
||||
use super::smallvec::VecLike;
|
||||
|
||||
// TODO(pcwalton): Speed up with SIMD, or better yet, find some way to not do this.
|
||||
pub fn byte_swap(data: &mut [u8]) {
|
||||
let length = data.len();
|
||||
|
@ -18,70 +14,3 @@ pub fn byte_swap(data: &mut [u8]) {
|
|||
i += 4;
|
||||
}
|
||||
}
|
||||
|
||||
/// A `VecLike` that only tracks whether or not something was ever pushed to it.
|
||||
pub struct ForgetfulSink<T> {
|
||||
empty: bool,
|
||||
_data: PhantomData<T>,
|
||||
}
|
||||
|
||||
impl<T> ForgetfulSink<T> {
|
||||
pub fn new() -> ForgetfulSink<T> {
|
||||
ForgetfulSink {
|
||||
empty: true,
|
||||
_data: PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.empty
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> ops::Deref for ForgetfulSink<T> {
|
||||
type Target = [T];
|
||||
fn deref(&self) -> &[T] {
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> ops::DerefMut for ForgetfulSink<T> {
|
||||
fn deref_mut(&mut self) -> &mut [T] {
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! impl_index {
|
||||
($index_type: ty, $output_type: ty) => {
|
||||
impl<T> ops::Index<$index_type> for ForgetfulSink<T> {
|
||||
type Output = $output_type;
|
||||
fn index(&self, _index: $index_type) -> &$output_type {
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> ops::IndexMut<$index_type> for ForgetfulSink<T> {
|
||||
fn index_mut(&mut self, _index: $index_type) -> &mut $output_type {
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl_index!(usize, T);
|
||||
impl_index!(ops::Range<usize>, [T]);
|
||||
impl_index!(ops::RangeFrom<usize>, [T]);
|
||||
impl_index!(ops::RangeTo<usize>, [T]);
|
||||
impl_index!(ops::RangeFull, [T]);
|
||||
|
||||
impl<T> VecLike<T> for ForgetfulSink<T> {
|
||||
#[inline]
|
||||
fn len(&self) -> usize {
|
||||
unreachable!()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn push(&mut self, _value: T) {
|
||||
self.empty = false;
|
||||
}
|
||||
}
|
||||
|
|
1
ports/cef/Cargo.lock
generated
1
ports/cef/Cargo.lock
generated
|
@ -2340,7 +2340,6 @@ dependencies = [
|
|||
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 0.7.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_macros 0.7.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"smallvec 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"url 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"xdg 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
|
1
ports/geckolib/Cargo.lock
generated
1
ports/geckolib/Cargo.lock
generated
|
@ -577,7 +577,6 @@ dependencies = [
|
|||
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 0.7.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_macros 0.7.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"smallvec 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"url 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"xdg 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
|
|
@ -50,6 +50,7 @@ use style::properties::{PropertyDeclaration, PropertyDeclarationBlock};
|
|||
use style::refcell::{Ref, RefCell, RefMut};
|
||||
use style::restyle_hints::ElementSnapshot;
|
||||
use style::selector_impl::ElementExt;
|
||||
use style::sink::Push;
|
||||
#[allow(unused_imports)] // Used in commented-out code.
|
||||
use url::Url;
|
||||
|
||||
|
@ -377,7 +378,7 @@ impl<'le> TElement for GeckoElement<'le> {
|
|||
|
||||
impl<'le> PresentationalHintsSynthetizer for GeckoElement<'le> {
|
||||
fn synthesize_presentational_hints_for_legacy_attributes<V>(&self, _hints: &mut V)
|
||||
where V: VecLike<DeclarationBlock<Vec<PropertyDeclaration>>>
|
||||
where V: Push<DeclarationBlock<Vec<PropertyDeclaration>>>
|
||||
{
|
||||
// FIXME(bholley) - Need to implement this.
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue