mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Putting the font computation data in its own struct
This commit is contained in:
parent
3c267d7fdd
commit
af124f2d89
3 changed files with 53 additions and 30 deletions
|
@ -57,6 +57,7 @@ use logical_geometry::WritingMode;
|
||||||
use media_queries::Device;
|
use media_queries::Device;
|
||||||
use properties::animated_properties::TransitionProperty;
|
use properties::animated_properties::TransitionProperty;
|
||||||
use properties::longhands;
|
use properties::longhands;
|
||||||
|
use properties:: FontComputationData;
|
||||||
use properties::{Importance, LonghandId};
|
use properties::{Importance, LonghandId};
|
||||||
use properties::{PropertyDeclaration, PropertyDeclarationBlock, PropertyDeclarationId};
|
use properties::{PropertyDeclaration, PropertyDeclarationBlock, PropertyDeclarationId};
|
||||||
use std::fmt::{self, Debug};
|
use std::fmt::{self, Debug};
|
||||||
|
@ -74,6 +75,7 @@ pub mod style_structs {
|
||||||
% endfor
|
% endfor
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct ComputedValues {
|
pub struct ComputedValues {
|
||||||
% for style_struct in data.style_structs:
|
% for style_struct in data.style_structs:
|
||||||
|
@ -83,23 +85,7 @@ pub struct ComputedValues {
|
||||||
custom_properties: Option<Arc<ComputedValuesMap>>,
|
custom_properties: Option<Arc<ComputedValuesMap>>,
|
||||||
pub writing_mode: WritingMode,
|
pub writing_mode: WritingMode,
|
||||||
pub root_font_size: Au,
|
pub root_font_size: Au,
|
||||||
/// font-size keyword values (and font-size-relative values applied
|
pub font_computation_data: FontComputationData,
|
||||||
/// to keyword values) need to preserve their identity as originating
|
|
||||||
/// from keywords and relative font sizes. We store this information
|
|
||||||
/// out of band in the ComputedValues. When None, the font size on the
|
|
||||||
/// current struct was computed from a value that was not a keyword
|
|
||||||
/// or a chain of font-size-relative values applying to successive parents
|
|
||||||
/// terminated by a keyword. When Some, this means the font-size was derived
|
|
||||||
/// from a keyword value or a keyword value on some ancestor with only
|
|
||||||
/// font-size-relative keywords and regular inheritance in between. The
|
|
||||||
/// integer stores the final ratio of the chain of font size relative values.
|
|
||||||
/// and is 1 when there was just a keyword and no relative values.
|
|
||||||
///
|
|
||||||
/// When this is Some, we compute font sizes by computing the keyword against
|
|
||||||
/// the generic font, and then multiplying it by the ratio.
|
|
||||||
pub font_size_keyword: Option<(longhands::font_size::KeywordSize, f32)>,
|
|
||||||
/// The cached system font. See longhand/font.mako.rs
|
|
||||||
pub cached_system_font: Option<longhands::system_font::ComputedSystemFont>,
|
|
||||||
|
|
||||||
/// The element's computed values if visited, only computed if there's a
|
/// The element's computed values if visited, only computed if there's a
|
||||||
/// relevant link for this element. A element's "relevant link" is the
|
/// relevant link for this element. A element's "relevant link" is the
|
||||||
|
@ -121,8 +107,7 @@ impl ComputedValues {
|
||||||
custom_properties: custom_properties,
|
custom_properties: custom_properties,
|
||||||
writing_mode: writing_mode,
|
writing_mode: writing_mode,
|
||||||
root_font_size: root_font_size,
|
root_font_size: root_font_size,
|
||||||
cached_system_font: None,
|
font_computation_data: FontComputationData::new(font_size_keyword),
|
||||||
font_size_keyword: font_size_keyword,
|
|
||||||
visited_style: visited_style,
|
visited_style: visited_style,
|
||||||
% for style_struct in data.style_structs:
|
% for style_struct in data.style_structs:
|
||||||
${style_struct.ident}: ${style_struct.ident},
|
${style_struct.ident}: ${style_struct.ident},
|
||||||
|
@ -135,8 +120,7 @@ impl ComputedValues {
|
||||||
custom_properties: None,
|
custom_properties: None,
|
||||||
writing_mode: WritingMode::empty(), // FIXME(bz): This seems dubious
|
writing_mode: WritingMode::empty(), // FIXME(bz): This seems dubious
|
||||||
root_font_size: longhands::font_size::get_initial_value(), // FIXME(bz): Also seems dubious?
|
root_font_size: longhands::font_size::get_initial_value(), // FIXME(bz): Also seems dubious?
|
||||||
font_size_keyword: Some((Default::default(), 1.)),
|
font_computation_data: FontComputationData::default_values(),
|
||||||
cached_system_font: None,
|
|
||||||
visited_style: None,
|
visited_style: None,
|
||||||
% for style_struct in data.style_structs:
|
% for style_struct in data.style_structs:
|
||||||
${style_struct.ident}: style_structs::${style_struct.name}::default(pres_context),
|
${style_struct.ident}: style_structs::${style_struct.name}::default(pres_context),
|
||||||
|
@ -144,6 +128,7 @@ impl ComputedValues {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_display_contents(&self) -> bool {
|
pub fn is_display_contents(&self) -> bool {
|
||||||
self.get_box().clone_display() == longhands::display::computed_value::T::contents
|
self.get_box().clone_display() == longhands::display::computed_value::T::contents
|
||||||
|
|
|
@ -900,7 +900,7 @@ ${helpers.single_keyword_system("font-variant-caps",
|
||||||
// recomputed from the base size for the keyword and the relative size.
|
// recomputed from the base size for the keyword and the relative size.
|
||||||
//
|
//
|
||||||
// See bug 1355707
|
// See bug 1355707
|
||||||
if let Some((kw, fraction)) = context.inherited_style().font_size_keyword {
|
if let Some((kw, fraction)) = context.inherited_style().font_computation_data.font_size_keyword {
|
||||||
context.mutate_style().font_size_keyword = Some((kw, fraction * ratio));
|
context.mutate_style().font_size_keyword = Some((kw, fraction * ratio));
|
||||||
} else {
|
} else {
|
||||||
context.mutate_style().font_size_keyword = None;
|
context.mutate_style().font_size_keyword = None;
|
||||||
|
@ -950,7 +950,7 @@ ${helpers.single_keyword_system("font-variant-caps",
|
||||||
.inherit_font_size_from(parent, kw_inherited_size);
|
.inherit_font_size_from(parent, kw_inherited_size);
|
||||||
if used_kw {
|
if used_kw {
|
||||||
context.mutate_style().font_size_keyword =
|
context.mutate_style().font_size_keyword =
|
||||||
context.inherited_style.font_size_keyword;
|
context.inherited_style.font_computation_data.font_size_keyword;
|
||||||
} else {
|
} else {
|
||||||
context.mutate_style().font_size_keyword = None;
|
context.mutate_style().font_size_keyword = None;
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,6 +65,44 @@ pub trait MaybeBoxed<Out> {
|
||||||
fn maybe_boxed(self) -> Out;
|
fn maybe_boxed(self) -> Out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// This is where we store extra font data while
|
||||||
|
/// while computing font sizes.
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub struct FontComputationData {
|
||||||
|
/// font-size keyword values (and font-size-relative values applied
|
||||||
|
/// to keyword values) need to preserve their identity as originating
|
||||||
|
/// from keywords and relative font sizes. We store this information
|
||||||
|
/// out of band in the ComputedValues. When None, the font size on the
|
||||||
|
/// current struct was computed from a value that was not a keyword
|
||||||
|
/// or a chain of font-size-relative values applying to successive parents
|
||||||
|
/// terminated by a keyword. When Some, this means the font-size was derived
|
||||||
|
/// from a keyword value or a keyword value on some ancestor with only
|
||||||
|
/// font-size-relative keywords and regular inheritance in between. The
|
||||||
|
/// integer stores the final ratio of the chain of font size relative values.
|
||||||
|
/// and is 1 when there was just a keyword and no relative values.
|
||||||
|
///
|
||||||
|
/// When this is Some, we compute font sizes by computing the keyword against
|
||||||
|
/// the generic font, and then multiplying it by the ratio.
|
||||||
|
pub font_size_keyword: Option<(longhands::font_size::KeywordSize, f32)>
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
impl FontComputationData{
|
||||||
|
/// Assigns values for variables in struct FontComputationData
|
||||||
|
pub fn new(font_size_keyword: Option<(longhands::font_size::KeywordSize, f32)>) -> Self {
|
||||||
|
FontComputationData {
|
||||||
|
font_size_keyword: font_size_keyword
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// Assigns default values for variables in struct FontComputationData
|
||||||
|
pub fn default_values() -> Self {
|
||||||
|
FontComputationData{
|
||||||
|
font_size_keyword: Some((Default::default(), 1.))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<T> MaybeBoxed<T> for T {
|
impl<T> MaybeBoxed<T> for T {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn maybe_boxed(self) -> T { self }
|
fn maybe_boxed(self) -> T { self }
|
||||||
|
@ -1793,7 +1831,7 @@ pub struct ComputedValues {
|
||||||
/// The root element's computed font size.
|
/// The root element's computed font size.
|
||||||
pub root_font_size: Au,
|
pub root_font_size: Au,
|
||||||
/// The keyword behind the current font-size property, if any
|
/// The keyword behind the current font-size property, if any
|
||||||
pub font_size_keyword: Option<(longhands::font_size::KeywordSize, f32)>,
|
pub font_computation_data: FontComputationData,
|
||||||
|
|
||||||
/// The element's computed values if visited, only computed if there's a
|
/// The element's computed values if visited, only computed if there's a
|
||||||
/// relevant link for this element. A element's "relevant link" is the
|
/// relevant link for this element. A element's "relevant link" is the
|
||||||
|
@ -1817,7 +1855,7 @@ impl ComputedValues {
|
||||||
custom_properties: custom_properties,
|
custom_properties: custom_properties,
|
||||||
writing_mode: writing_mode,
|
writing_mode: writing_mode,
|
||||||
root_font_size: root_font_size,
|
root_font_size: root_font_size,
|
||||||
font_size_keyword: font_size_keyword,
|
font_computation_data: FontComputationData::new(font_size_keyword),
|
||||||
visited_style: visited_style,
|
visited_style: visited_style,
|
||||||
% for style_struct in data.active_style_structs():
|
% for style_struct in data.active_style_structs():
|
||||||
${style_struct.ident}: ${style_struct.ident},
|
${style_struct.ident}: ${style_struct.ident},
|
||||||
|
@ -2303,7 +2341,7 @@ impl<'a> StyleBuilder<'a> {
|
||||||
Self::new(parent.custom_properties(),
|
Self::new(parent.custom_properties(),
|
||||||
parent.writing_mode,
|
parent.writing_mode,
|
||||||
parent.root_font_size,
|
parent.root_font_size,
|
||||||
parent.font_size_keyword,
|
parent.font_computation_data.font_size_keyword,
|
||||||
parent.clone_visited_style(),
|
parent.clone_visited_style(),
|
||||||
% for style_struct in data.active_style_structs():
|
% for style_struct in data.active_style_structs():
|
||||||
% if style_struct.inherited:
|
% if style_struct.inherited:
|
||||||
|
@ -2403,7 +2441,7 @@ pub use self::lazy_static_module::INITIAL_SERVO_VALUES;
|
||||||
mod lazy_static_module {
|
mod lazy_static_module {
|
||||||
use logical_geometry::WritingMode;
|
use logical_geometry::WritingMode;
|
||||||
use stylearc::Arc;
|
use stylearc::Arc;
|
||||||
use super::{ComputedValues, longhands, style_structs};
|
use super::{ComputedValues, longhands, style_structs, FontComputationData};
|
||||||
|
|
||||||
/// The initial values for all style structs as defined by the specification.
|
/// The initial values for all style structs as defined by the specification.
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
|
@ -2421,7 +2459,7 @@ mod lazy_static_module {
|
||||||
custom_properties: None,
|
custom_properties: None,
|
||||||
writing_mode: WritingMode::empty(),
|
writing_mode: WritingMode::empty(),
|
||||||
root_font_size: longhands::font_size::get_initial_value(),
|
root_font_size: longhands::font_size::get_initial_value(),
|
||||||
font_size_keyword: Some((Default::default(), 1.)),
|
font_computation_data: FontComputationData::default_values()
|
||||||
visited_style: None,
|
visited_style: None,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -2571,7 +2609,7 @@ pub fn apply_declarations<'a, F, I>(device: &Device,
|
||||||
StyleBuilder::new(custom_properties,
|
StyleBuilder::new(custom_properties,
|
||||||
WritingMode::empty(),
|
WritingMode::empty(),
|
||||||
inherited_style.root_font_size,
|
inherited_style.root_font_size,
|
||||||
inherited_style.font_size_keyword,
|
inherited_style.font_computation_data.font_size_keyword,
|
||||||
visited_style,
|
visited_style,
|
||||||
% for style_struct in data.active_style_structs():
|
% for style_struct in data.active_style_structs():
|
||||||
% if style_struct.inherited:
|
% if style_struct.inherited:
|
||||||
|
@ -2585,7 +2623,7 @@ pub fn apply_declarations<'a, F, I>(device: &Device,
|
||||||
StyleBuilder::new(custom_properties,
|
StyleBuilder::new(custom_properties,
|
||||||
WritingMode::empty(),
|
WritingMode::empty(),
|
||||||
inherited_style.root_font_size,
|
inherited_style.root_font_size,
|
||||||
inherited_style.font_size_keyword,
|
inherited_style.font_computation_data.font_size_keyword,
|
||||||
visited_style,
|
visited_style,
|
||||||
% for style_struct in data.active_style_structs():
|
% for style_struct in data.active_style_structs():
|
||||||
inherited_style.${style_struct.name_lower}_arc(),
|
inherited_style.${style_struct.name_lower}_arc(),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue