mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01: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::position::T as Position;
|
||||
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::logical_geometry::{BlockFlowDirection, InlineBaseDirection, WritingMode};
|
||||
use style::properties::{
|
||||
|
@ -750,28 +750,18 @@ pub fn process_node_scroll_area_request(
|
|||
}
|
||||
}
|
||||
|
||||
pub fn process_parse_font_request<'dom, E>(
|
||||
context: &LayoutContext,
|
||||
node: E,
|
||||
font_value: &str,
|
||||
fn create_font_declaration(
|
||||
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();
|
||||
url_data: &ServoUrl,
|
||||
quirks_mode: QuirksMode,
|
||||
) -> Option<PropertyDeclarationBlock> {
|
||||
let mut declarations = SourcePropertyDeclaration::new();
|
||||
let result = parse_one_declaration_into(
|
||||
&mut declarations,
|
||||
property.clone(),
|
||||
font_value,
|
||||
&url_data,
|
||||
value,
|
||||
url_data,
|
||||
None,
|
||||
ParsingMode::DEFAULT,
|
||||
quirks_mode,
|
||||
|
@ -784,32 +774,84 @@ where
|
|||
},
|
||||
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
|
||||
let element = node.as_element().unwrap();
|
||||
let parent_style = if element.has_data() {
|
||||
node.to_threadsafe().as_element().unwrap().resolved_style()
|
||||
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(&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 {
|
||||
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()
|
||||
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
|
||||
Some(
|
||||
context
|
||||
.style_context
|
||||
.stylist
|
||||
.compute_for_declarations::<E::ConcreteElement>(
|
||||
&context.style_context.guards,
|
||||
&*parent_style,
|
||||
ServoArc::new(shared_lock.wrap(declarations)),
|
||||
),
|
||||
)
|
||||
Some(resolve_for_declarations::<E>(
|
||||
&context.style_context,
|
||||
Some(&*parent_style),
|
||||
declarations,
|
||||
shared_lock,
|
||||
))
|
||||
}
|
||||
|
||||
/// 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::htmlcanvaselement::{CanvasContext, HTMLCanvasElement};
|
||||
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::paintworkletglobalscope::PaintWorkletGlobalScope;
|
||||
use crate::dom::textmetrics::TextMetrics;
|
||||
|
@ -1007,7 +1007,14 @@ impl CanvasState {
|
|||
}
|
||||
|
||||
// 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!()
|
||||
}
|
||||
|
||||
|
|
|
@ -1849,9 +1849,6 @@ impl Window {
|
|||
}
|
||||
|
||||
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);
|
||||
if !self.layout_reflow(QueryMsg::ParseFontQuery(
|
||||
node.to_trusted_node_address(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue