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

stylo: Don't persist styles on elements not in the document. #14776

Merged
merged 1 commit into from Dec 30, 2016
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Don't persist styles on elements not in the document.

  • Loading branch information
heycam committed Dec 30, 2016
commit be1a73dac53ed8ccc7a77790db6e39fbc19ba901
@@ -199,6 +199,10 @@ impl<'ln> TNode for ServoLayoutNode<'ln> {
self.node.parent_node_ref().map(|node| self.new_with_this_lifetime(&node))
}
}

fn is_in_doc(&self) -> bool {
unsafe { (*self.node.unsafe_get()).is_in_doc() }
}
}

pub struct ServoChildrenIterator<'a> {
@@ -99,6 +99,8 @@ pub trait TNode : Sized + Copy + Clone + Debug + NodeInfo {
unsafe fn set_can_be_fragmented(&self, value: bool);

fn parent_node(&self) -> Option<Self>;

fn is_in_doc(&self) -> bool;
}

/// Wrapper to output the ElementData along with the node when formatting for
@@ -157,6 +157,10 @@ impl<'ln> TNode for GeckoNode<'ln> {
unsafe { bindings::Gecko_GetParentNode(self.0).map(GeckoNode) }
}

fn is_in_doc(&self) -> bool {
unsafe { bindings::Gecko_IsInDocument(self.0) }
}

fn needs_dirty_on_viewport_size_changed(&self) -> bool {
// Gecko's node doesn't have the DIRTY_ON_VIEWPORT_SIZE_CHANGE flag,
// so we force them to be dirtied on viewport size change, regardless if
@@ -267,6 +267,9 @@ extern "C" {
extern "C" {
pub fn Gecko_NodeIsElement(node: RawGeckoNodeBorrowed) -> bool;
}
extern "C" {
pub fn Gecko_IsInDocument(node: RawGeckoNodeBorrowed) -> bool;
}
extern "C" {
pub fn Gecko_GetParentNode(node: RawGeckoNodeBorrowed)
-> RawGeckoNodeBorrowedOrNull;
@@ -324,16 +324,23 @@ pub fn resolve_style<E, F, G, H>(context: &StyleContext<E>, element: E,
// on the Element.
callback(element.borrow_data().unwrap().styles());

// Clear any styles in display:none subtrees to leave the tree in a valid state.
if let Some(root) = display_none_root {
// Clear any styles in display:none subtrees or subtrees not in the document,
// to leave the tree in a valid state. For display:none subtrees, we leave
// the styles on the display:none root, but for subtrees not in the document,
// we clear styles all the way up to the root of the disconnected subtree.
let in_doc = element.as_node().is_in_doc();
if !in_doc || display_none_root.is_some() {
let mut curr = element;
loop {
unsafe { curr.unset_dirty_descendants(); }
if curr == root {
if in_doc && curr == display_none_root.unwrap() {
break;
}
clear_data(curr);
curr = curr.parent_element().unwrap();
curr = match curr.parent_element() {
Some(parent) => parent,
None => break,
};
}
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.