mirror of
https://github.com/servo/servo.git
synced 2025-08-02 20:20:14 +01:00
Don't go through the layout thread to retrieve a node's primary style
This commit is contained in:
parent
030a1cf8fb
commit
c10e839924
10 changed files with 38 additions and 79 deletions
|
@ -15,7 +15,6 @@ use crate::dom::document::AnimationFrameCallback;
|
|||
use crate::dom::element::Element;
|
||||
use crate::dom::globalscope::GlobalScope;
|
||||
use crate::dom::node::{window_from_node, Node, ShadowIncluding};
|
||||
use crate::dom::window::Window;
|
||||
use crate::realms::enter_realm;
|
||||
use crate::script_thread::Documents;
|
||||
use devtools_traits::{AutoMargins, ComputedNodeLayout, TimelineMarkerType};
|
||||
|
@ -150,7 +149,7 @@ pub fn handle_get_layout(
|
|||
position: String::from(computed_style.Position()),
|
||||
zIndex: String::from(computed_style.ZIndex()),
|
||||
boxSizing: String::from(computed_style.BoxSizing()),
|
||||
autoMargins: determine_auto_margins(&window, &*node),
|
||||
autoMargins: determine_auto_margins(&node),
|
||||
marginTop: String::from(computed_style.MarginTop()),
|
||||
marginRight: String::from(computed_style.MarginRight()),
|
||||
marginBottom: String::from(computed_style.MarginBottom()),
|
||||
|
@ -169,8 +168,8 @@ pub fn handle_get_layout(
|
|||
.unwrap();
|
||||
}
|
||||
|
||||
fn determine_auto_margins(window: &Window, node: &Node) -> AutoMargins {
|
||||
let style = window.style_query(node.to_trusted_node_address()).unwrap();
|
||||
fn determine_auto_margins(node: &Node) -> AutoMargins {
|
||||
let style = node.style().unwrap();
|
||||
let margin = style.get_margin();
|
||||
AutoMargins {
|
||||
top: margin.margin_top.is_auto(),
|
||||
|
|
|
@ -396,7 +396,7 @@ impl Element {
|
|||
/// style will be `None` for elements in a `display: none` subtree. otherwise, the element has a
|
||||
/// layout box iff it doesn't have `display: none`.
|
||||
pub fn style(&self) -> Option<Arc<ComputedValues>> {
|
||||
window_from_node(self).style_query(self.upcast::<Node>().to_trusted_node_address())
|
||||
self.upcast::<Node>().style()
|
||||
}
|
||||
|
||||
// https://drafts.csswg.org/cssom-view/#css-layout-box
|
||||
|
|
|
@ -75,6 +75,7 @@ use malloc_size_of::{MallocSizeOf, MallocSizeOfOps};
|
|||
use msg::constellation_msg::{BrowsingContextId, PipelineId};
|
||||
use net_traits::image::base::{Image, ImageMetadata};
|
||||
use ref_slice::ref_slice;
|
||||
use script_layout_interface::message::QueryMsg;
|
||||
use script_layout_interface::{HTMLCanvasData, HTMLMediaData, LayoutElementType, LayoutNodeType};
|
||||
use script_layout_interface::{SVGSVGData, StyleAndOpaqueLayoutData, TrustedNodeAddress};
|
||||
use script_traits::DocumentActivity;
|
||||
|
@ -95,6 +96,7 @@ use std::ops::Range;
|
|||
use std::sync::Arc as StdArc;
|
||||
use style::context::QuirksMode;
|
||||
use style::dom::OpaqueNode;
|
||||
use style::properties::ComputedValues;
|
||||
use style::selector_parser::{SelectorImpl, SelectorParser};
|
||||
use style::stylesheets::Stylesheet;
|
||||
use uuid::Uuid;
|
||||
|
@ -1229,6 +1231,23 @@ impl Node {
|
|||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
pub fn style(&self) -> Option<Arc<ComputedValues>> {
|
||||
if !window_from_node(self).layout_reflow(QueryMsg::StyleQuery) {
|
||||
return None;
|
||||
}
|
||||
unsafe {
|
||||
(*self.style_and_layout_data.get()).as_ref().map(|data| {
|
||||
data.style_data
|
||||
.element_data
|
||||
.borrow()
|
||||
.styles
|
||||
.primary()
|
||||
.clone()
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Iterate through `nodes` until we find a `Node` that is not in `not_in`
|
||||
|
|
|
@ -131,7 +131,7 @@ use style::dom::OpaqueNode;
|
|||
use style::error_reporting::{ContextualParseError, ParseErrorReporter};
|
||||
use style::media_queries;
|
||||
use style::parser::ParserContext as CssParserContext;
|
||||
use style::properties::{ComputedValues, PropertyId};
|
||||
use style::properties::PropertyId;
|
||||
use style::selector_parser::PseudoElement;
|
||||
use style::str::HTML_SPACE_CHARACTERS;
|
||||
use style::stylesheets::CssRuleType;
|
||||
|
@ -1904,13 +1904,6 @@ impl Window {
|
|||
(element, response.rect)
|
||||
}
|
||||
|
||||
pub fn style_query(&self, node: TrustedNodeAddress) -> Option<servo_arc::Arc<ComputedValues>> {
|
||||
if !self.layout_reflow(QueryMsg::StyleQuery(node)) {
|
||||
return None;
|
||||
}
|
||||
self.layout_rpc.style().0
|
||||
}
|
||||
|
||||
pub fn text_index_query(
|
||||
&self,
|
||||
node: &Node,
|
||||
|
@ -2461,7 +2454,7 @@ fn debug_reflow_events(id: PipelineId, reflow_goal: &ReflowGoal, reason: &Reflow
|
|||
&QueryMsg::NodeScrollIdQuery(_n) => "\tNodeScrollIdQuery",
|
||||
&QueryMsg::ResolvedStyleQuery(_, _, _) => "\tResolvedStyleQuery",
|
||||
&QueryMsg::OffsetParentQuery(_n) => "\tOffsetParentQuery",
|
||||
&QueryMsg::StyleQuery(_n) => "\tStyleQuery",
|
||||
&QueryMsg::StyleQuery => "\tStyleQuery",
|
||||
&QueryMsg::TextIndexQuery(..) => "\tTextIndexQuery",
|
||||
&QueryMsg::ElementInnerTextQuery(_) => "\tElementInnerTextQuery",
|
||||
&QueryMsg::InnerWindowDimensionsQuery(_) => "\tInnerWindowDimensionsQuery",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue