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::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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue