Query layout to resolve canvas font property value

This commit is contained in:
Utsav Oza 2020-05-28 00:28:42 +05:30
parent f161ab8e57
commit 7883718c12
11 changed files with 161 additions and 9 deletions

View file

@ -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>(