mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Add todos for missing steps while processing parse font query
This commit is contained in:
parent
7883718c12
commit
f3cb7a1910
3 changed files with 88 additions and 42 deletions
|
@ -37,7 +37,7 @@ use std::sync::{Arc, Mutex};
|
||||||
use style::computed_values::display::T as Display;
|
use style::computed_values::display::T as Display;
|
||||||
use style::computed_values::position::T as Position;
|
use style::computed_values::position::T as Position;
|
||||||
use style::computed_values::visibility::T as Visibility;
|
use style::computed_values::visibility::T as Visibility;
|
||||||
use style::context::{StyleContext, ThreadLocalStyleContext};
|
use style::context::{QuirksMode, SharedStyleContext, StyleContext, ThreadLocalStyleContext};
|
||||||
use style::dom::TElement;
|
use style::dom::TElement;
|
||||||
use style::logical_geometry::{BlockFlowDirection, InlineBaseDirection, WritingMode};
|
use style::logical_geometry::{BlockFlowDirection, InlineBaseDirection, WritingMode};
|
||||||
use style::properties::{
|
use style::properties::{
|
||||||
|
@ -750,28 +750,18 @@ pub fn process_node_scroll_area_request(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn process_parse_font_request<'dom, E>(
|
fn create_font_declaration(
|
||||||
context: &LayoutContext,
|
value: &str,
|
||||||
node: E,
|
|
||||||
font_value: &str,
|
|
||||||
property: &PropertyId,
|
property: &PropertyId,
|
||||||
url_data: ServoUrl,
|
url_data: &ServoUrl,
|
||||||
shared_lock: &SharedRwLock,
|
quirks_mode: QuirksMode,
|
||||||
) -> Option<ServoArc<ComputedValues>>
|
) -> Option<PropertyDeclarationBlock> {
|
||||||
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 mut declarations = SourcePropertyDeclaration::new();
|
||||||
let result = parse_one_declaration_into(
|
let result = parse_one_declaration_into(
|
||||||
&mut declarations,
|
&mut declarations,
|
||||||
property.clone(),
|
property.clone(),
|
||||||
font_value,
|
value,
|
||||||
&url_data,
|
url_data,
|
||||||
None,
|
None,
|
||||||
ParsingMode::DEFAULT,
|
ParsingMode::DEFAULT,
|
||||||
quirks_mode,
|
quirks_mode,
|
||||||
|
@ -784,32 +774,84 @@ where
|
||||||
},
|
},
|
||||||
Err(_) => return None,
|
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)),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn process_parse_font_request<'dom, E>(
|
||||||
|
context: &LayoutContext,
|
||||||
|
node: E,
|
||||||
|
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 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
|
// 2. Get resolved styles for the parent element
|
||||||
let element = node.as_element().unwrap();
|
let element = node.as_element().unwrap();
|
||||||
let parent_style = if element.has_data() {
|
let parent_style = if node.is_connected() {
|
||||||
node.to_threadsafe().as_element().unwrap().resolved_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()
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
let mut tlc = ThreadLocalStyleContext::new(&context.style_context);
|
let default_declarations =
|
||||||
let mut context = StyleContext {
|
create_font_declaration("10px sans-serif", property, &url_data, quirks_mode).unwrap();
|
||||||
shared: &context.style_context,
|
resolve_for_declarations::<E>(
|
||||||
thread_local: &mut tlc,
|
&context.style_context,
|
||||||
};
|
None,
|
||||||
let styles = resolve_style(&mut context, element, RuleInclusion::All, None);
|
default_declarations,
|
||||||
styles.primary().clone()
|
shared_lock,
|
||||||
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
// 3. Resolve the parsed value with resolved styles of the parent element
|
// 3. Resolve the parsed value with resolved styles of the parent element
|
||||||
Some(
|
Some(resolve_for_declarations::<E>(
|
||||||
context
|
&context.style_context,
|
||||||
.style_context
|
Some(&*parent_style),
|
||||||
.stylist
|
declarations,
|
||||||
.compute_for_declarations::<E::ConcreteElement>(
|
shared_lock,
|
||||||
&context.style_context.guards,
|
))
|
||||||
&*parent_style,
|
|
||||||
ServoArc::new(shared_lock.wrap(declarations)),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the resolved value of property for a given (pseudo)element.
|
/// Return the resolved value of property for a given (pseudo)element.
|
||||||
|
|
|
@ -22,7 +22,7 @@ use crate::dom::element::Element;
|
||||||
use crate::dom::globalscope::GlobalScope;
|
use crate::dom::globalscope::GlobalScope;
|
||||||
use crate::dom::htmlcanvaselement::{CanvasContext, HTMLCanvasElement};
|
use crate::dom::htmlcanvaselement::{CanvasContext, HTMLCanvasElement};
|
||||||
use crate::dom::imagedata::ImageData;
|
use crate::dom::imagedata::ImageData;
|
||||||
use crate::dom::node::{Node, NodeDamage};
|
use crate::dom::node::{window_from_node, Node, NodeDamage};
|
||||||
use crate::dom::offscreencanvas::{OffscreenCanvas, OffscreenCanvasContext};
|
use crate::dom::offscreencanvas::{OffscreenCanvas, OffscreenCanvasContext};
|
||||||
use crate::dom::paintworkletglobalscope::PaintWorkletGlobalScope;
|
use crate::dom::paintworkletglobalscope::PaintWorkletGlobalScope;
|
||||||
use crate::dom::textmetrics::TextMetrics;
|
use crate::dom::textmetrics::TextMetrics;
|
||||||
|
@ -1007,7 +1007,14 @@ impl CanvasState {
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-font
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-font
|
||||||
pub fn set_font(&self, _canvas: Option<&HTMLCanvasElement>, _value: DOMString) {
|
pub fn set_font(&self, canvas: Option<&HTMLCanvasElement>, value: DOMString) {
|
||||||
|
let _resolved_font = if let Some(element) = canvas {
|
||||||
|
let node = element.upcast::<Node>();
|
||||||
|
let window = window_from_node(&*node);
|
||||||
|
window.parse_font_query(&node, value.to_string())
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1849,9 +1849,6 @@ impl Window {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_font_query(&self, node: &Node, value: String) -> Option<ServoArc<ComputedValues>> {
|
pub fn parse_font_query(&self, node: &Node, value: String) -> Option<ServoArc<ComputedValues>> {
|
||||||
if !node.is_connected() {
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
let id = PropertyId::Shorthand(ShorthandId::Font);
|
let id = PropertyId::Shorthand(ShorthandId::Font);
|
||||||
if !self.layout_reflow(QueryMsg::ParseFontQuery(
|
if !self.layout_reflow(QueryMsg::ParseFontQuery(
|
||||||
node.to_trusted_node_address(),
|
node.to_trusted_node_address(),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue