mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Auto merge of #8187 - Ms2ger:layoutnode-new, r=pcwalton
Introduce a Layoutnode::new function and use it. <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/8187) <!-- Reviewable:end -->
This commit is contained in:
commit
6cc8186481
2 changed files with 31 additions and 33 deletions
|
@ -51,9 +51,7 @@ use profile_traits::time::{self, ProfilerMetadata, profile};
|
||||||
use query::{LayoutRPCImpl, process_content_box_request, process_content_boxes_request};
|
use query::{LayoutRPCImpl, process_content_box_request, process_content_boxes_request};
|
||||||
use query::{MarginPadding, MarginRetrievingFragmentBorderBoxIterator, PositionProperty};
|
use query::{MarginPadding, MarginRetrievingFragmentBorderBoxIterator, PositionProperty};
|
||||||
use query::{PositionRetrievingFragmentBorderBoxIterator, Side};
|
use query::{PositionRetrievingFragmentBorderBoxIterator, Side};
|
||||||
use script::dom::bindings::js::LayoutJS;
|
use script::dom::node::LayoutData;
|
||||||
use script::dom::document::Document;
|
|
||||||
use script::dom::node::{LayoutData, Node};
|
|
||||||
use script::layout_interface::Animation;
|
use script::layout_interface::Animation;
|
||||||
use script::layout_interface::{LayoutChan, LayoutRPC, OffsetParentResponse};
|
use script::layout_interface::{LayoutChan, LayoutRPC, OffsetParentResponse};
|
||||||
use script::layout_interface::{Msg, NewLayoutTaskInfo, Reflow, ReflowGoal, ReflowQueryType};
|
use script::layout_interface::{Msg, NewLayoutTaskInfo, Reflow, ReflowGoal, ReflowQueryType};
|
||||||
|
@ -90,7 +88,7 @@ use util::opts;
|
||||||
use util::task::spawn_named_with_send_on_failure;
|
use util::task::spawn_named_with_send_on_failure;
|
||||||
use util::task_state;
|
use util::task_state;
|
||||||
use util::workqueue::WorkQueue;
|
use util::workqueue::WorkQueue;
|
||||||
use wrapper::{LayoutDocument, LayoutNode, ThreadSafeLayoutNode};
|
use wrapper::{LayoutNode, ThreadSafeLayoutNode};
|
||||||
|
|
||||||
/// The number of screens of data we're allowed to generate display lists for in each direction.
|
/// The number of screens of data we're allowed to generate display lists for in each direction.
|
||||||
pub const DISPLAY_PORT_SIZE_FACTOR: i32 = 8;
|
pub const DISPLAY_PORT_SIZE_FACTOR: i32 = 8;
|
||||||
|
@ -892,17 +890,9 @@ impl LayoutTask {
|
||||||
property: &Atom,
|
property: &Atom,
|
||||||
layout_root: &mut FlowRef)
|
layout_root: &mut FlowRef)
|
||||||
-> Option<String> {
|
-> Option<String> {
|
||||||
// FIXME: Isolate this transmutation into a "bridge" module.
|
let node = unsafe { LayoutNode::new(&requested_node) };
|
||||||
// FIXME(rust#16366): The following line had to be moved because of a
|
|
||||||
// rustc bug. It should be in the next unsafe block.
|
|
||||||
let node: LayoutJS<Node> = unsafe {
|
|
||||||
LayoutJS::from_trusted_node_address(requested_node)
|
|
||||||
};
|
|
||||||
let node: &LayoutNode = unsafe {
|
|
||||||
transmute(&node)
|
|
||||||
};
|
|
||||||
|
|
||||||
let layout_node = ThreadSafeLayoutNode::new(node);
|
let layout_node = ThreadSafeLayoutNode::new(&node);
|
||||||
let layout_node = match pseudo {
|
let layout_node = match pseudo {
|
||||||
&Some(PseudoElement::Before) => layout_node.get_before_pseudo(),
|
&Some(PseudoElement::Before) => layout_node.get_before_pseudo(),
|
||||||
&Some(PseudoElement::After) => layout_node.get_after_pseudo(),
|
&Some(PseudoElement::After) => layout_node.get_after_pseudo(),
|
||||||
|
@ -1133,15 +1123,9 @@ impl LayoutTask {
|
||||||
};
|
};
|
||||||
let _ajst = AutoJoinScriptTask { data: data };
|
let _ajst = AutoJoinScriptTask { data: data };
|
||||||
|
|
||||||
// FIXME: Isolate this transmutation into a "bridge" module.
|
let document = unsafe { LayoutNode::new(&data.document) };
|
||||||
let mut doc: LayoutJS<Document> = unsafe {
|
let document = document.as_document().unwrap();
|
||||||
LayoutJS::from_trusted_node_address(data.document).downcast::<Document>().unwrap()
|
let node: LayoutNode = match document.root_node() {
|
||||||
};
|
|
||||||
let doc: &mut LayoutDocument = unsafe {
|
|
||||||
transmute(&mut doc)
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut node: LayoutNode = match doc.root_node() {
|
|
||||||
None => return,
|
None => return,
|
||||||
Some(x) => x,
|
Some(x) => x,
|
||||||
};
|
};
|
||||||
|
@ -1187,7 +1171,7 @@ impl LayoutTask {
|
||||||
let needs_reflow = screen_size_changed && !needs_dirtying;
|
let needs_reflow = screen_size_changed && !needs_dirtying;
|
||||||
unsafe {
|
unsafe {
|
||||||
if needs_dirtying {
|
if needs_dirtying {
|
||||||
LayoutTask::dirty_all_nodes(&mut node);
|
LayoutTask::dirty_all_nodes(node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if needs_reflow {
|
if needs_reflow {
|
||||||
|
@ -1196,7 +1180,7 @@ impl LayoutTask {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let event_state_changes = doc.drain_event_state_changes();
|
let event_state_changes = document.drain_event_state_changes();
|
||||||
if !needs_dirtying {
|
if !needs_dirtying {
|
||||||
for &(el, state) in event_state_changes.iter() {
|
for &(el, state) in event_state_changes.iter() {
|
||||||
assert!(!state.is_empty());
|
assert!(!state.is_empty());
|
||||||
|
@ -1229,7 +1213,7 @@ impl LayoutTask {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Retrieve the (possibly rebuilt) root flow.
|
// Retrieve the (possibly rebuilt) root flow.
|
||||||
rw_data.root_flow = self.try_get_layout_root(node.clone());
|
rw_data.root_flow = self.try_get_layout_root(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send new canvas renderers to the paint task
|
// Send new canvas renderers to the paint task
|
||||||
|
@ -1459,7 +1443,7 @@ impl LayoutTask {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn dirty_all_nodes(node: &mut LayoutNode) {
|
unsafe fn dirty_all_nodes(node: LayoutNode) {
|
||||||
for node in node.traverse_preorder() {
|
for node in node.traverse_preorder() {
|
||||||
// TODO(cgaebel): mark nodes which are sensitive to media queries as
|
// TODO(cgaebel): mark nodes which are sensitive to media queries as
|
||||||
// "changed":
|
// "changed":
|
||||||
|
|
|
@ -53,6 +53,7 @@ use script::dom::htmltextareaelement::{HTMLTextAreaElement, LayoutHTMLTextAreaEl
|
||||||
use script::dom::node::{HAS_CHANGED, HAS_DIRTY_DESCENDANTS, IS_DIRTY};
|
use script::dom::node::{HAS_CHANGED, HAS_DIRTY_DESCENDANTS, IS_DIRTY};
|
||||||
use script::dom::node::{LayoutNodeHelpers, Node, SharedLayoutData};
|
use script::dom::node::{LayoutNodeHelpers, Node, SharedLayoutData};
|
||||||
use script::dom::text::Text;
|
use script::dom::text::Text;
|
||||||
|
use script::layout_interface::TrustedNodeAddress;
|
||||||
use selectors::matching::DeclarationBlock;
|
use selectors::matching::DeclarationBlock;
|
||||||
use selectors::parser::{AttrSelector, NamespaceConstraint};
|
use selectors::parser::{AttrSelector, NamespaceConstraint};
|
||||||
use smallvec::VecLike;
|
use smallvec::VecLike;
|
||||||
|
@ -80,7 +81,7 @@ pub struct LayoutNode<'a> {
|
||||||
node: LayoutJS<Node>,
|
node: LayoutJS<Node>,
|
||||||
|
|
||||||
/// Being chained to a PhantomData prevents `LayoutNode`s from escaping.
|
/// Being chained to a PhantomData prevents `LayoutNode`s from escaping.
|
||||||
pub chain: PhantomData<&'a ()>,
|
chain: PhantomData<&'a ()>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> PartialEq for LayoutNode<'a> {
|
impl<'a> PartialEq for LayoutNode<'a> {
|
||||||
|
@ -91,6 +92,14 @@ impl<'a> PartialEq for LayoutNode<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'ln> LayoutNode<'ln> {
|
impl<'ln> LayoutNode<'ln> {
|
||||||
|
pub unsafe fn new(address: &TrustedNodeAddress) -> LayoutNode {
|
||||||
|
let node = LayoutJS::from_trusted_node_address(*address);
|
||||||
|
LayoutNode {
|
||||||
|
node: node,
|
||||||
|
chain: PhantomData,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Creates a new layout node with the same lifetime as this layout node.
|
/// Creates a new layout node with the same lifetime as this layout node.
|
||||||
pub unsafe fn new_with_this_lifetime(&self, node: &LayoutJS<Node>) -> LayoutNode<'ln> {
|
pub unsafe fn new_with_this_lifetime(&self, node: &LayoutJS<Node>) -> LayoutNode<'ln> {
|
||||||
LayoutNode {
|
LayoutNode {
|
||||||
|
@ -206,6 +215,15 @@ impl<'ln> LayoutNode<'ln> {
|
||||||
as_element(self.node)
|
as_element(self.node)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn as_document(&self) -> Option<LayoutDocument<'ln>> {
|
||||||
|
self.node.downcast().map(|document| {
|
||||||
|
LayoutDocument {
|
||||||
|
document: document,
|
||||||
|
chain: PhantomData,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
fn parent_node(&self) -> Option<LayoutNode<'ln>> {
|
fn parent_node(&self) -> Option<LayoutNode<'ln>> {
|
||||||
unsafe {
|
unsafe {
|
||||||
self.node.parent_node_ref().map(|node| self.new_with_this_lifetime(&node))
|
self.node.parent_node_ref().map(|node| self.new_with_this_lifetime(&node))
|
||||||
|
@ -354,11 +372,7 @@ impl<'le> LayoutDocument<'le> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn root_node(&self) -> Option<LayoutNode<'le>> {
|
pub fn root_node(&self) -> Option<LayoutNode<'le>> {
|
||||||
let mut node = self.as_node().first_child();
|
self.as_node().children().find(LayoutNode::is_element)
|
||||||
while node.is_some() && !node.unwrap().is_element() {
|
|
||||||
node = node.unwrap().next_sibling();
|
|
||||||
}
|
|
||||||
node
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn drain_event_state_changes(&self) -> Vec<(LayoutElement, EventState)> {
|
pub fn drain_event_state_changes(&self) -> Vec<(LayoutElement, EventState)> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue