mirror of
https://github.com/servo/servo.git
synced 2025-07-23 07:13:52 +01:00
layout: Add an implementation of process_resolved_font_style_query
for Layout 2020 (#31436)
* layout: support setting canvas font Signed-off-by: syvb <me@iter.ca> * Update 2d.reset.state.font.html test Signed-off-by: syvb <me@iter.ca> --------- Signed-off-by: syvb <me@iter.ca>
This commit is contained in:
parent
a89bacb7c5
commit
5c87fe940e
11 changed files with 120 additions and 38 deletions
|
@ -20,18 +20,22 @@ use script_layout_interface::wrapper_traits::{
|
|||
};
|
||||
use script_traits::UntrustedNodeAddress;
|
||||
use servo_arc::Arc as ServoArc;
|
||||
use servo_url::ServoUrl;
|
||||
use style::computed_values::position::T as Position;
|
||||
use style::context::{StyleContext, ThreadLocalStyleContext};
|
||||
use style::context::{QuirksMode, SharedStyleContext, StyleContext, ThreadLocalStyleContext};
|
||||
use style::dom::{OpaqueNode, TElement};
|
||||
use style::properties::style_structs::Font;
|
||||
use style::properties::{
|
||||
Importance, LonghandId, PropertyDeclarationBlock, PropertyDeclarationId, PropertyId,
|
||||
parse_one_declaration_into, ComputedValues, Importance, LonghandId, PropertyDeclarationBlock,
|
||||
PropertyDeclarationId, PropertyId, SourcePropertyDeclaration,
|
||||
};
|
||||
use style::selector_parser::PseudoElement;
|
||||
use style::shared_lock::SharedRwLock;
|
||||
use style::stylesheets::{CssRuleType, Origin, UrlExtraData};
|
||||
use style::stylist::RuleInclusion;
|
||||
use style::traversal::resolve_style;
|
||||
use style::values::generics::text::LineHeight;
|
||||
use style_traits::{CSSPixel, ToCss};
|
||||
use style_traits::{CSSPixel, ParsingMode, ToCss};
|
||||
use webrender_api::units::LayoutPixel;
|
||||
use webrender_api::{DisplayListBuilder, ExternalScrollId};
|
||||
|
||||
|
@ -645,10 +649,107 @@ pub fn process_text_index_request(_node: OpaqueNode, _point: Point2D<Au>) -> Tex
|
|||
TextIndexResponse(None)
|
||||
}
|
||||
|
||||
pub fn process_resolved_font_style_query<'dom>(
|
||||
_node: impl LayoutNode<'dom>,
|
||||
_property: &PropertyId,
|
||||
_value: &str,
|
||||
) -> Option<ServoArc<Font>> {
|
||||
None
|
||||
pub fn process_resolved_font_style_query<'dom, E>(
|
||||
context: &LayoutContext,
|
||||
node: E,
|
||||
property: &PropertyId,
|
||||
value: &str,
|
||||
url_data: ServoUrl,
|
||||
shared_lock: &SharedRwLock,
|
||||
) -> Option<ServoArc<Font>>
|
||||
where
|
||||
E: LayoutNode<'dom>,
|
||||
{
|
||||
fn create_font_declaration(
|
||||
value: &str,
|
||||
property: &PropertyId,
|
||||
url_data: &ServoUrl,
|
||||
quirks_mode: QuirksMode,
|
||||
) -> Option<PropertyDeclarationBlock> {
|
||||
let mut declarations = SourcePropertyDeclaration::default();
|
||||
let result = parse_one_declaration_into(
|
||||
&mut declarations,
|
||||
property.clone(),
|
||||
value,
|
||||
Origin::Author,
|
||||
&UrlExtraData(url_data.get_arc()),
|
||||
None,
|
||||
ParsingMode::DEFAULT,
|
||||
quirks_mode,
|
||||
CssRuleType::Style,
|
||||
);
|
||||
let declarations = match result {
|
||||
Ok(()) => {
|
||||
let mut block = PropertyDeclarationBlock::new();
|
||||
block.extend(declarations.drain(), Importance::Normal);
|
||||
block
|
||||
},
|
||||
Err(_) => return None,
|
||||
};
|
||||
// TODO: Force to set line-height property to 'normal' font property.
|
||||
Some(declarations)
|
||||
}
|
||||
fn resolve_for_declarations<'dom, E>(
|
||||
context: &SharedStyleContext,
|
||||
parent_style: Option<&ComputedValues>,
|
||||
declarations: PropertyDeclarationBlock,
|
||||
shared_lock: &SharedRwLock,
|
||||
) -> ServoArc<ComputedValues>
|
||||
where
|
||||
E: LayoutNode<'dom>,
|
||||
{
|
||||
let parent_style = match parent_style {
|
||||
Some(parent) => parent,
|
||||
None => context.stylist.device().default_computed_values(),
|
||||
};
|
||||
context
|
||||
.stylist
|
||||
.compute_for_declarations::<E::ConcreteElement>(
|
||||
&context.guards,
|
||||
parent_style,
|
||||
ServoArc::new(shared_lock.wrap(declarations)),
|
||||
)
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-font
|
||||
// 1. Parse the given font property value
|
||||
let quirks_mode = context.style_context.quirks_mode();
|
||||
let declarations = create_font_declaration(value, property, &url_data, quirks_mode)?;
|
||||
|
||||
// TODO: Reject 'inherit' and 'initial' values for the font property.
|
||||
|
||||
// 2. Get resolved styles for the parent element
|
||||
let element = node.as_element().unwrap();
|
||||
let parent_style = if node.is_connected() {
|
||||
if element.has_data() {
|
||||
node.to_threadsafe().as_element().unwrap().resolved_style()
|
||||
} else {
|
||||
let mut tlc = ThreadLocalStyleContext::new();
|
||||
let mut context = StyleContext {
|
||||
shared: &context.style_context,
|
||||
thread_local: &mut tlc,
|
||||
};
|
||||
let styles = resolve_style(&mut context, element, RuleInclusion::All, None, None);
|
||||
styles.primary().clone()
|
||||
}
|
||||
} else {
|
||||
let default_declarations =
|
||||
create_font_declaration("10px sans-serif", property, &url_data, quirks_mode).unwrap();
|
||||
resolve_for_declarations::<E>(
|
||||
&context.style_context,
|
||||
None,
|
||||
default_declarations,
|
||||
shared_lock,
|
||||
)
|
||||
};
|
||||
|
||||
// 3. Resolve the parsed value with resolved styles of the parent element
|
||||
let computed_values = resolve_for_declarations::<E>(
|
||||
&context.style_context,
|
||||
Some(&*parent_style),
|
||||
declarations,
|
||||
shared_lock,
|
||||
);
|
||||
|
||||
Some(computed_values.clone_font())
|
||||
}
|
||||
|
|
|
@ -870,6 +870,7 @@ impl LayoutThread {
|
|||
&mut *rw_data,
|
||||
&mut layout_context,
|
||||
data.result.borrow_mut().as_mut().unwrap(),
|
||||
document_shared_lock,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -879,6 +880,7 @@ impl LayoutThread {
|
|||
rw_data: &mut LayoutThreadData,
|
||||
context: &mut LayoutContext,
|
||||
reflow_result: &mut ReflowComplete,
|
||||
shared_lock: &SharedRwLock,
|
||||
) {
|
||||
reflow_result.pending_images =
|
||||
std::mem::replace(&mut *context.pending_images.lock().unwrap(), vec![]);
|
||||
|
@ -925,8 +927,14 @@ impl LayoutThread {
|
|||
},
|
||||
&QueryMsg::ResolvedFontStyleQuery(node, ref property, ref value) => {
|
||||
let node = unsafe { ServoLayoutNode::<DOMLayoutData>::new(&node) };
|
||||
rw_data.resolved_font_style_response =
|
||||
process_resolved_font_style_query(node, property, value);
|
||||
rw_data.resolved_font_style_response = process_resolved_font_style_query(
|
||||
context,
|
||||
node,
|
||||
property,
|
||||
value,
|
||||
self.url.clone(),
|
||||
shared_lock,
|
||||
);
|
||||
},
|
||||
&QueryMsg::OffsetParentQuery(node) => {
|
||||
rw_data.offset_parent_response =
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
[2d.reset.state.font.html]
|
||||
[check that the state is reset]
|
||||
expected: FAIL
|
|
@ -1,3 +0,0 @@
|
|||
[2d.text.font.parse.basic.html]
|
||||
[Canvas test: 2d.text.font.parse.basic]
|
||||
expected: FAIL
|
|
@ -1,3 +0,0 @@
|
|||
[2d.text.font.parse.complex.html]
|
||||
[Canvas test: 2d.text.font.parse.complex]
|
||||
expected: FAIL
|
|
@ -1,3 +0,0 @@
|
|||
[2d.text.font.parse.complex2.html]
|
||||
[Canvas test: 2d.text.font.parse.complex2]
|
||||
expected: FAIL
|
|
@ -1,3 +0,0 @@
|
|||
[2d.text.font.parse.family.html]
|
||||
[Canvas test: 2d.text.font.parse.family]
|
||||
expected: FAIL
|
|
@ -1,3 +0,0 @@
|
|||
[2d.text.font.parse.size.percentage.default.html]
|
||||
[Canvas test: 2d.text.font.parse.size.percentage.default]
|
||||
expected: FAIL
|
|
@ -1,3 +0,0 @@
|
|||
[2d.text.font.parse.size.percentage.html]
|
||||
[Canvas test: 2d.text.font.parse.size.percentage]
|
||||
expected: FAIL
|
|
@ -1,3 +0,0 @@
|
|||
[2d.text.font.parse.tiny.html]
|
||||
[Canvas test: 2d.text.font.parse.tiny]
|
||||
expected: FAIL
|
|
@ -1,6 +1,3 @@
|
|||
[parent-style-relative-units.html]
|
||||
[Font-size based on canvas element font-size]
|
||||
expected: FAIL
|
||||
|
||||
[Font-size based on canvas element line-height]
|
||||
expected: FAIL
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue