Skip to content

Commit

Permalink
Auto merge of #12469 - emilio:stylo, r=bholley
Browse files Browse the repository at this point in the history
style: Rewrite the restyle hints code to allow different kinds of element snapshots.

<!-- Please describe your changes on the following line: -->

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors

<!-- Either: -->
- [x] These changes do not require tests because refactoring.

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

This is a rewrite for how style interfaces with its consumers in order to allow
different representations for an element snapshot.

This also changes the requirements of an element snapshot, requiring them to
only implement MatchAttr, instead of MatchAttrGeneric. This is important for
stylo since implementing MatchAttrGeneric is way more difficult for us given the
atom limitations. This also allows for more performant implementations in the
Gecko side of things.

I don't want to get this merged just yet, mainly because the stylo part is not
implemented, but I'd like early feedback from @bholley and/or @heycam: How do
you see this approach? I don't think we'll have much problem to implement
MatchAttr for our element snapshots, but... worth checking.

r? @heycam

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/12469)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo committed Jul 21, 2016
2 parents f8eab2b + f44e31a commit 1e0321f
Show file tree
Hide file tree
Showing 18 changed files with 1,170 additions and 243 deletions.
3 changes: 1 addition & 2 deletions components/script/dom/bindings/trace.rs
Expand Up @@ -89,8 +89,7 @@ use string_cache::{Atom, Namespace, QualName};
use style::attr::{AttrIdentifier, AttrValue, LengthOrPercentageOrAuto};
use style::element_state::*;
use style::properties::PropertyDeclarationBlock;
use style::restyle_hints::ElementSnapshot;
use style::selector_impl::PseudoElement;
use style::selector_impl::{PseudoElement, ElementSnapshot};
use style::values::specified::Length;
use url::Origin as UrlOrigin;
use url::Url;
Expand Down
12 changes: 9 additions & 3 deletions components/script/dom/document.rs
Expand Up @@ -122,7 +122,7 @@ use std::sync::Arc;
use string_cache::{Atom, QualName};
use style::attr::AttrValue;
use style::context::ReflowGoal;
use style::restyle_hints::ElementSnapshot;
use style::selector_impl::ElementSnapshot;
use style::str::{split_html_space_chars, str_join};
use style::stylesheets::Stylesheet;
use time;
Expand Down Expand Up @@ -1851,15 +1851,21 @@ impl Document {

pub fn element_state_will_change(&self, el: &Element) {
let mut map = self.modified_elements.borrow_mut();
let snapshot = map.entry(JS::from_ref(el)).or_insert(ElementSnapshot::new());
let snapshot = map.entry(JS::from_ref(el))
.or_insert_with(|| {
ElementSnapshot::new(el.html_element_in_html_document())
});
if snapshot.state.is_none() {
snapshot.state = Some(el.state());
}
}

pub fn element_attr_will_change(&self, el: &Element) {
let mut map = self.modified_elements.borrow_mut();
let mut snapshot = map.entry(JS::from_ref(el)).or_insert(ElementSnapshot::new());
let mut snapshot = map.entry(JS::from_ref(el))
.or_insert_with(|| {
ElementSnapshot::new(el.html_element_in_html_document())
});
if snapshot.attrs.is_none() {
let attrs = el.attrs()
.iter()
Expand Down
3 changes: 1 addition & 2 deletions components/script/layout_wrapper.rs
Expand Up @@ -60,8 +60,7 @@ use style::dom::{PresentationalHintsSynthetizer, OpaqueNode, TDocument, TElement
use style::element_state::*;
use style::properties::{PropertyDeclaration, PropertyDeclarationBlock};
use style::refcell::{Ref, RefCell, RefMut};
use style::restyle_hints::ElementSnapshot;
use style::selector_impl::{NonTSPseudoClass, ServoSelectorImpl};
use style::selector_impl::{ElementSnapshot, NonTSPseudoClass, ServoSelectorImpl};
use style::sink::Push;
use style::str::is_whitespace;
use url::Url;
Expand Down
2 changes: 1 addition & 1 deletion components/style/attr.rs
Expand Up @@ -29,7 +29,7 @@ pub enum LengthOrPercentageOrAuto {
Length(Au),
}

#[derive(PartialEq, Clone)]
#[derive(PartialEq, Clone, Debug)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub enum AttrValue {
String(String),
Expand Down
5 changes: 3 additions & 2 deletions components/style/dom.rs
Expand Up @@ -11,7 +11,7 @@ use data::PrivateStyleData;
use element_state::ElementState;
use properties::{ComputedValues, PropertyDeclaration, PropertyDeclarationBlock};
use refcell::{Ref, RefMut};
use restyle_hints::{ElementSnapshot, RESTYLE_DESCENDANTS, RESTYLE_LATER_SIBLINGS, RESTYLE_SELF, RestyleHint};
use restyle_hints::{RESTYLE_DESCENDANTS, RESTYLE_LATER_SIBLINGS, RESTYLE_SELF, RestyleHint};
use selector_impl::{ElementExt, SelectorImplExt};
use selectors::Element;
use selectors::matching::DeclarationBlock;
Expand Down Expand Up @@ -192,7 +192,8 @@ pub trait TDocument : Sized + Copy + Clone {

fn root_node(&self) -> Option<Self::ConcreteNode>;

fn drain_modified_elements(&self) -> Vec<(Self::ConcreteElement, ElementSnapshot)>;
fn drain_modified_elements(&self) -> Vec<(Self::ConcreteElement,
<Self::ConcreteElement as ElementExt>::Snapshot)>;
}

pub trait PresentationalHintsSynthetizer {
Expand Down

0 comments on commit 1e0321f

Please sign in to comment.