aboutsummaryrefslogtreecommitdiffstats
path: root/components/layout/query.rs
diff options
context:
space:
mode:
authorUtsav Oza <utsavoza96@gmail.com>2020-05-28 00:28:42 +0530
committerUtsav Oza <utsavoza96@gmail.com>2020-06-10 22:10:42 +0530
commit7883718c125f2580490254efdf0aac952b50ce3d (patch)
tree866d431004f1e925d5d23919f4d6276f5fd92118 /components/layout/query.rs
parentf161ab8e57b0149b368f892f11c83d953c55dd5a (diff)
downloadservo-7883718c125f2580490254efdf0aac952b50ce3d.tar.gz
servo-7883718c125f2580490254efdf0aac952b50ce3d.zip
Query layout to resolve canvas font property value
Diffstat (limited to 'components/layout/query.rs')
-rw-r--r--components/layout/query.rs81
1 files changed, 79 insertions, 2 deletions
diff --git a/components/layout/query.rs b/components/layout/query.rs
index a5f66cb9dcd..b78a642ec1d 100644
--- a/components/layout/query.rs
+++ b/components/layout/query.rs
@@ -29,6 +29,8 @@ use script_layout_interface::wrapper_traits::{
use script_layout_interface::{LayoutElementType, LayoutNodeType};
use script_traits::LayoutMsg as ConstellationMsg;
use script_traits::UntrustedNodeAddress;
+use servo_arc::Arc as ServoArc;
+use servo_url::ServoUrl;
use std::cmp::{max, min};
use std::ops::Deref;
use std::sync::{Arc, Mutex};
@@ -38,9 +40,13 @@ use style::computed_values::visibility::T as Visibility;
use style::context::{StyleContext, ThreadLocalStyleContext};
use style::dom::TElement;
use style::logical_geometry::{BlockFlowDirection, InlineBaseDirection, WritingMode};
-use style::properties::{style_structs, LonghandId, PropertyDeclarationId, PropertyId};
+use style::properties::{
+ parse_one_declaration_into, style_structs, ComputedValues, Importance, LonghandId,
+ PropertyDeclarationBlock, PropertyDeclarationId, PropertyId, SourcePropertyDeclaration,
+};
use style::selector_parser::PseudoElement;
-use style_traits::{CSSPixel, ToCss};
+use style::shared_lock::SharedRwLock;
+use style_traits::{CSSPixel, ParsingMode, ToCss};
use webrender_api::ExternalScrollId;
/// Mutable data belonging to the LayoutThread.
@@ -73,6 +79,9 @@ pub struct LayoutThreadData {
/// A queued response for the resolved style property of an element.
pub resolved_style_response: String,
+ /// A queued response for the resolved font style for canvas.
+ pub parse_font_response: Option<ServoArc<ComputedValues>>,
+
/// A queued response for the offset parent/rect of a node.
pub offset_parent_response: OffsetParentResponse,
@@ -170,6 +179,12 @@ impl LayoutRPC for LayoutRPCImpl {
ResolvedStyleResponse(rw_data.resolved_style_response.clone())
}
+ fn parsed_font(&self) -> Option<ServoArc<ComputedValues>> {
+ let &LayoutRPCImpl(ref rw_data) = self;
+ let rw_data = rw_data.lock().unwrap();
+ rw_data.parse_font_response.clone()
+ }
+
fn offset_parent(&self) -> OffsetParentResponse {
let &LayoutRPCImpl(ref rw_data) = self;
let rw_data = rw_data.lock().unwrap();
@@ -735,6 +750,68 @@ pub fn process_node_scroll_area_request(
}
}
+pub fn process_parse_font_request<'dom, E>(
+ context: &LayoutContext,
+ node: E,
+ font_value: &str,
+ property: &PropertyId,
+ url_data: ServoUrl,
+ shared_lock: &SharedRwLock,
+) -> Option<ServoArc<ComputedValues>>
+where
+ E: LayoutNode<'dom>,
+{
+ use style::stylist::RuleInclusion;
+ use style::traversal::resolve_style;
+
+ // 1. Parse the given font property value
+ let quirks_mode = context.style_context.quirks_mode();
+ let mut declarations = SourcePropertyDeclaration::new();
+ let result = parse_one_declaration_into(
+ &mut declarations,
+ property.clone(),
+ font_value,
+ &url_data,
+ None,
+ ParsingMode::DEFAULT,
+ quirks_mode,
+ );
+ let declarations = match result {
+ Ok(()) => {
+ let mut block = PropertyDeclarationBlock::new();
+ block.extend(declarations.drain(), Importance::Normal);
+ block
+ },
+ Err(_) => return None,
+ };
+
+ // 2. Get resolved styles for the parent element
+ let element = node.as_element().unwrap();
+ let parent_style = if element.has_data() {
+ node.to_threadsafe().as_element().unwrap().resolved_style()
+ } else {
+ let mut tlc = ThreadLocalStyleContext::new(&context.style_context);
+ let mut context = StyleContext {
+ shared: &context.style_context,
+ thread_local: &mut tlc,
+ };
+ let styles = resolve_style(&mut context, element, RuleInclusion::All, None);
+ styles.primary().clone()
+ };
+
+ // 3. Resolve the parsed value with resolved styles of the parent element
+ Some(
+ context
+ .style_context
+ .stylist
+ .compute_for_declarations::<E::ConcreteElement>(
+ &context.style_context.guards,
+ &*parent_style,
+ ServoArc::new(shared_lock.wrap(declarations)),
+ ),
+ )
+}
+
/// Return the resolved value of property for a given (pseudo)element.
/// <https://drafts.csswg.org/cssom/#resolved-value>
pub fn process_resolved_style_request<'dom>(