mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Bug 1374233 - Part 3: Use NonNegativeAu as computed values for font-size related properties.
For font-size and font-size-adjust. MozReview-Commit-ID: 5rrfVSzB7WF
This commit is contained in:
parent
191c2a282b
commit
234d2c1b32
13 changed files with 87 additions and 57 deletions
|
@ -116,7 +116,7 @@ impl FontContext {
|
||||||
|
|
||||||
let layout_font_group_cache_key = LayoutFontGroupCacheKey {
|
let layout_font_group_cache_key = LayoutFontGroupCacheKey {
|
||||||
pointer: style.clone(),
|
pointer: style.clone(),
|
||||||
size: style.font_size,
|
size: style.font_size.0,
|
||||||
};
|
};
|
||||||
if let Some(ref cached_font_group) = self.layout_font_group_cache.get(
|
if let Some(ref cached_font_group) = self.layout_font_group_cache.get(
|
||||||
&layout_font_group_cache_key) {
|
&layout_font_group_cache_key) {
|
||||||
|
@ -146,7 +146,7 @@ impl FontContext {
|
||||||
Some(ref cached_font_ref) => {
|
Some(ref cached_font_ref) => {
|
||||||
let cached_font = (*cached_font_ref).borrow();
|
let cached_font = (*cached_font_ref).borrow();
|
||||||
if cached_font.descriptor == desc &&
|
if cached_font.descriptor == desc &&
|
||||||
cached_font.requested_pt_size == style.font_size &&
|
cached_font.requested_pt_size == style.font_size.0 &&
|
||||||
cached_font.variant == style.font_variant_caps {
|
cached_font.variant == style.font_variant_caps {
|
||||||
fonts.push((*cached_font_ref).clone());
|
fonts.push((*cached_font_ref).clone());
|
||||||
cache_hit = true;
|
cache_hit = true;
|
||||||
|
@ -164,7 +164,7 @@ impl FontContext {
|
||||||
Some(template_info) => {
|
Some(template_info) => {
|
||||||
let layout_font = self.create_layout_font(template_info.font_template,
|
let layout_font = self.create_layout_font(template_info.font_template,
|
||||||
desc.clone(),
|
desc.clone(),
|
||||||
style.font_size,
|
style.font_size.0,
|
||||||
style.font_variant_caps,
|
style.font_variant_caps,
|
||||||
template_info.font_key
|
template_info.font_key
|
||||||
.expect("No font key present!"));
|
.expect("No font key present!"));
|
||||||
|
@ -198,7 +198,7 @@ impl FontContext {
|
||||||
for cached_font_entry in &self.fallback_font_cache {
|
for cached_font_entry in &self.fallback_font_cache {
|
||||||
let cached_font = cached_font_entry.font.borrow();
|
let cached_font = cached_font_entry.font.borrow();
|
||||||
if cached_font.descriptor == desc &&
|
if cached_font.descriptor == desc &&
|
||||||
cached_font.requested_pt_size == style.font_size &&
|
cached_font.requested_pt_size == style.font_size.0 &&
|
||||||
cached_font.variant == style.font_variant_caps {
|
cached_font.variant == style.font_variant_caps {
|
||||||
fonts.push(cached_font_entry.font.clone());
|
fonts.push(cached_font_entry.font.clone());
|
||||||
cache_hit = true;
|
cache_hit = true;
|
||||||
|
@ -210,7 +210,7 @@ impl FontContext {
|
||||||
let template_info = self.font_cache_thread.last_resort_font_template(desc.clone());
|
let template_info = self.font_cache_thread.last_resort_font_template(desc.clone());
|
||||||
let layout_font = self.create_layout_font(template_info.font_template,
|
let layout_font = self.create_layout_font(template_info.font_template,
|
||||||
desc.clone(),
|
desc.clone(),
|
||||||
style.font_size,
|
style.font_size.0,
|
||||||
style.font_variant_caps,
|
style.font_variant_caps,
|
||||||
template_info.font_key.expect("No font key present!"));
|
template_info.font_key.expect("No font key present!"));
|
||||||
match layout_font {
|
match layout_font {
|
||||||
|
|
|
@ -99,7 +99,7 @@ impl Flow for MulticolFlow {
|
||||||
|
|
||||||
let column_gap = match column_style.column_gap {
|
let column_gap = match column_style.column_gap {
|
||||||
Either::First(len) => len,
|
Either::First(len) => len,
|
||||||
Either::Second(_normal) => self.block_flow.fragment.style.get_font().font_size,
|
Either::Second(_normal) => self.block_flow.fragment.style.get_font().font_size.0,
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut column_count;
|
let mut column_count;
|
||||||
|
|
|
@ -446,7 +446,7 @@ pub fn font_metrics_for_style(font_context: &mut FontContext, font_style: ::Serv
|
||||||
|
|
||||||
/// Returns the line block-size needed by the given computed style and font size.
|
/// Returns the line block-size needed by the given computed style and font size.
|
||||||
pub fn line_height_from_style(style: &ComputedValues, metrics: &FontMetrics) -> Au {
|
pub fn line_height_from_style(style: &ComputedValues, metrics: &FontMetrics) -> Au {
|
||||||
let font_size = style.get_font().font_size;
|
let font_size = style.get_font().font_size.0;
|
||||||
match style.get_inheritedtext().line_height {
|
match style.get_inheritedtext().line_height {
|
||||||
LineHeight::Normal => metrics.line_gap,
|
LineHeight::Normal => metrics.line_gap,
|
||||||
LineHeight::Number(l) => font_size.scale_by(l),
|
LineHeight::Number(l) => font_size.scale_by(l),
|
||||||
|
|
|
@ -69,7 +69,8 @@ impl Device {
|
||||||
Device {
|
Device {
|
||||||
pres_context: pres_context,
|
pres_context: pres_context,
|
||||||
default_values: ComputedValues::default_values(unsafe { &*pres_context }),
|
default_values: ComputedValues::default_values(unsafe { &*pres_context }),
|
||||||
root_font_size: AtomicIsize::new(font_size::get_initial_value().0 as isize), // FIXME(bz): Seems dubious?
|
// FIXME(bz): Seems dubious?
|
||||||
|
root_font_size: AtomicIsize::new(font_size::get_initial_value().value() as isize),
|
||||||
used_root_font_size: AtomicBool::new(false),
|
used_root_font_size: AtomicBool::new(false),
|
||||||
used_viewport_size: AtomicBool::new(false),
|
used_viewport_size: AtomicBool::new(false),
|
||||||
}
|
}
|
||||||
|
|
|
@ -534,7 +534,7 @@ pub trait MatchMethods : TElement {
|
||||||
|
|
||||||
if old_styles.primary.as_ref().map_or(true, |s| s.get_font().clone_font_size() != new_font_size) {
|
if old_styles.primary.as_ref().map_or(true, |s| s.get_font().clone_font_size() != new_font_size) {
|
||||||
debug_assert!(self.owner_doc_matches_for_testing(device));
|
debug_assert!(self.owner_doc_matches_for_testing(device));
|
||||||
device.set_root_font_size(new_font_size);
|
device.set_root_font_size(new_font_size.0);
|
||||||
// If the root font-size changed since last time, and something
|
// If the root font-size changed since last time, and something
|
||||||
// in the document did use rem units, ensure we recascade the
|
// in the document did use rem units, ensure we recascade the
|
||||||
// entire tree.
|
// entire tree.
|
||||||
|
|
|
@ -62,7 +62,7 @@ use std::mem::{forget, uninitialized, transmute, zeroed};
|
||||||
use std::{cmp, ops, ptr};
|
use std::{cmp, ops, ptr};
|
||||||
use stylesheets::{MallocSizeOfWithRepeats, SizeOfState};
|
use stylesheets::{MallocSizeOfWithRepeats, SizeOfState};
|
||||||
use values::{self, Auto, CustomIdent, Either, KeyframesName};
|
use values::{self, Auto, CustomIdent, Either, KeyframesName};
|
||||||
use values::computed::ToComputedValue;
|
use values::computed::{NonNegativeAu, ToComputedValue};
|
||||||
use values::computed::effects::{BoxShadow, Filter, SimpleShadow};
|
use values::computed::effects::{BoxShadow, Filter, SimpleShadow};
|
||||||
use values::computed::length::Percentage;
|
use values::computed::length::Percentage;
|
||||||
use computed_values::border_style;
|
use computed_values::border_style;
|
||||||
|
@ -2259,15 +2259,15 @@ fn static_assert() {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_font_size(&mut self, v: longhands::font_size::computed_value::T) {
|
pub fn set_font_size(&mut self, v: longhands::font_size::computed_value::T) {
|
||||||
self.gecko.mSize = v.0;
|
self.gecko.mSize = v.value();
|
||||||
self.gecko.mScriptUnconstrainedSize = v.0;
|
self.gecko.mScriptUnconstrainedSize = v.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set font size, taking into account scriptminsize and scriptlevel
|
/// Set font size, taking into account scriptminsize and scriptlevel
|
||||||
/// Returns Some(size) if we have to recompute the script unconstrained size
|
/// Returns Some(size) if we have to recompute the script unconstrained size
|
||||||
pub fn apply_font_size(&mut self, v: longhands::font_size::computed_value::T,
|
pub fn apply_font_size(&mut self, v: longhands::font_size::computed_value::T,
|
||||||
parent: &Self,
|
parent: &Self,
|
||||||
device: &Device) -> Option<Au> {
|
device: &Device) -> Option<NonNegativeAu> {
|
||||||
let (adjusted_size, adjusted_unconstrained_size) =
|
let (adjusted_size, adjusted_unconstrained_size) =
|
||||||
self.calculate_script_level_size(parent, device);
|
self.calculate_script_level_size(parent, device);
|
||||||
// In this case, we have been unaffected by scriptminsize, ignore it
|
// In this case, we have been unaffected by scriptminsize, ignore it
|
||||||
|
@ -2277,9 +2277,9 @@ fn static_assert() {
|
||||||
self.fixup_font_min_size(device);
|
self.fixup_font_min_size(device);
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
self.gecko.mSize = v.0;
|
self.gecko.mSize = v.value();
|
||||||
self.fixup_font_min_size(device);
|
self.fixup_font_min_size(device);
|
||||||
Some(Au(parent.gecko.mScriptUnconstrainedSize))
|
Some(Au(parent.gecko.mScriptUnconstrainedSize).into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2287,8 +2287,8 @@ fn static_assert() {
|
||||||
unsafe { bindings::Gecko_nsStyleFont_FixupMinFontSize(&mut self.gecko, device.pres_context()) }
|
unsafe { bindings::Gecko_nsStyleFont_FixupMinFontSize(&mut self.gecko, device.pres_context()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn apply_unconstrained_font_size(&mut self, v: Au) {
|
pub fn apply_unconstrained_font_size(&mut self, v: NonNegativeAu) {
|
||||||
self.gecko.mScriptUnconstrainedSize = v.0;
|
self.gecko.mScriptUnconstrainedSize = v.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Calculates the constrained and unconstrained font sizes to be inherited
|
/// Calculates the constrained and unconstrained font sizes to be inherited
|
||||||
|
@ -2398,7 +2398,7 @@ fn static_assert() {
|
||||||
///
|
///
|
||||||
/// Returns true if the inherited keyword size was actually used
|
/// Returns true if the inherited keyword size was actually used
|
||||||
pub fn inherit_font_size_from(&mut self, parent: &Self,
|
pub fn inherit_font_size_from(&mut self, parent: &Self,
|
||||||
kw_inherited_size: Option<Au>,
|
kw_inherited_size: Option<NonNegativeAu>,
|
||||||
device: &Device) -> bool {
|
device: &Device) -> bool {
|
||||||
let (adjusted_size, adjusted_unconstrained_size)
|
let (adjusted_size, adjusted_unconstrained_size)
|
||||||
= self.calculate_script_level_size(parent, device);
|
= self.calculate_script_level_size(parent, device);
|
||||||
|
@ -2424,9 +2424,9 @@ fn static_assert() {
|
||||||
false
|
false
|
||||||
} else if let Some(size) = kw_inherited_size {
|
} else if let Some(size) = kw_inherited_size {
|
||||||
// Parent element was a keyword-derived size.
|
// Parent element was a keyword-derived size.
|
||||||
self.gecko.mSize = size.0;
|
self.gecko.mSize = size.value();
|
||||||
// MathML constraints didn't apply here, so we can ignore this.
|
// MathML constraints didn't apply here, so we can ignore this.
|
||||||
self.gecko.mScriptUnconstrainedSize = size.0;
|
self.gecko.mScriptUnconstrainedSize = size.value();
|
||||||
self.fixup_font_min_size(device);
|
self.fixup_font_min_size(device);
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
|
@ -2440,7 +2440,7 @@ fn static_assert() {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn clone_font_size(&self) -> longhands::font_size::computed_value::T {
|
pub fn clone_font_size(&self) -> longhands::font_size::computed_value::T {
|
||||||
Au(self.gecko.mSize)
|
Au(self.gecko.mSize).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_font_weight(&mut self, v: longhands::font_weight::computed_value::T) {
|
pub fn set_font_weight(&mut self, v: longhands::font_weight::computed_value::T) {
|
||||||
|
|
|
@ -566,7 +566,7 @@ ${helpers.single_keyword_system("font-variant-caps",
|
||||||
}
|
}
|
||||||
</%helpers:longhand>
|
</%helpers:longhand>
|
||||||
|
|
||||||
<%helpers:longhand name="font-size" need_clone="True" animation_value_type="ComputedValue"
|
<%helpers:longhand name="font-size" need_clone="True" animation_value_type="NonNegativeAu"
|
||||||
flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER"
|
flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER"
|
||||||
allow_quirks="True" spec="https://drafts.csswg.org/css-fonts/#propdef-font-size">
|
allow_quirks="True" spec="https://drafts.csswg.org/css-fonts/#propdef-font-size">
|
||||||
use app_units::Au;
|
use app_units::Au;
|
||||||
|
@ -574,6 +574,7 @@ ${helpers.single_keyword_system("font-variant-caps",
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use style_traits::{HasViewportPercentage, ToCss};
|
use style_traits::{HasViewportPercentage, ToCss};
|
||||||
use values::FONT_MEDIUM_PX;
|
use values::FONT_MEDIUM_PX;
|
||||||
|
use values::computed::NonNegativeAu;
|
||||||
use values::specified::{AllowQuirks, FontRelativeLength, LengthOrPercentage, NoCalcLength};
|
use values::specified::{AllowQuirks, FontRelativeLength, LengthOrPercentage, NoCalcLength};
|
||||||
use values::specified::length::FontBaseSize;
|
use values::specified::length::FontBaseSize;
|
||||||
|
|
||||||
|
@ -621,8 +622,8 @@ ${helpers.single_keyword_system("font-variant-caps",
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod computed_value {
|
pub mod computed_value {
|
||||||
use app_units::Au;
|
use values::computed::NonNegativeAu;
|
||||||
pub type T = Au;
|
pub type T = NonNegativeAu;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// CSS font keywords
|
/// CSS font keywords
|
||||||
|
@ -697,7 +698,7 @@ ${helpers.single_keyword_system("font-variant-caps",
|
||||||
|
|
||||||
% if product == "servo":
|
% if product == "servo":
|
||||||
impl ToComputedValue for KeywordSize {
|
impl ToComputedValue for KeywordSize {
|
||||||
type ComputedValue = Au;
|
type ComputedValue = NonNegativeAu;
|
||||||
#[inline]
|
#[inline]
|
||||||
fn to_computed_value(&self, _: &Context) -> computed_value::T {
|
fn to_computed_value(&self, _: &Context) -> computed_value::T {
|
||||||
// https://drafts.csswg.org/css-fonts-3/#font-size-prop
|
// https://drafts.csswg.org/css-fonts-3/#font-size-prop
|
||||||
|
@ -711,7 +712,7 @@ ${helpers.single_keyword_system("font-variant-caps",
|
||||||
XLarge => Au::from_px(FONT_MEDIUM_PX) * 3 / 2,
|
XLarge => Au::from_px(FONT_MEDIUM_PX) * 3 / 2,
|
||||||
XXLarge => Au::from_px(FONT_MEDIUM_PX) * 2,
|
XXLarge => Au::from_px(FONT_MEDIUM_PX) * 2,
|
||||||
XXXLarge => Au::from_px(FONT_MEDIUM_PX) * 3,
|
XXXLarge => Au::from_px(FONT_MEDIUM_PX) * 3,
|
||||||
}
|
}.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -721,7 +722,7 @@ ${helpers.single_keyword_system("font-variant-caps",
|
||||||
}
|
}
|
||||||
% else:
|
% else:
|
||||||
impl ToComputedValue for KeywordSize {
|
impl ToComputedValue for KeywordSize {
|
||||||
type ComputedValue = Au;
|
type ComputedValue = NonNegativeAu;
|
||||||
#[inline]
|
#[inline]
|
||||||
fn to_computed_value(&self, cx: &Context) -> computed_value::T {
|
fn to_computed_value(&self, cx: &Context) -> computed_value::T {
|
||||||
use gecko_bindings::structs::nsIAtom;
|
use gecko_bindings::structs::nsIAtom;
|
||||||
|
@ -757,9 +758,9 @@ ${helpers.single_keyword_system("font-variant-caps",
|
||||||
let base_size_px = au_to_int_px(base_size as f32);
|
let base_size_px = au_to_int_px(base_size as f32);
|
||||||
let html_size = self.html_size() as usize;
|
let html_size = self.html_size() as usize;
|
||||||
if base_size_px >= 9 && base_size_px <= 16 {
|
if base_size_px >= 9 && base_size_px <= 16 {
|
||||||
Au::from_px(FONT_SIZE_MAPPING[(base_size_px - 9) as usize][html_size])
|
NonNegativeAu::from_px(FONT_SIZE_MAPPING[(base_size_px - 9) as usize][html_size])
|
||||||
} else {
|
} else {
|
||||||
Au(FONT_SIZE_FACTORS[html_size] * base_size / 100)
|
Au(FONT_SIZE_FACTORS[html_size] * base_size / 100).into()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -818,37 +819,38 @@ ${helpers.single_keyword_system("font-variant-caps",
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Compute it against a given base font size
|
/// Compute it against a given base font size
|
||||||
pub fn to_computed_value_against(&self, context: &Context, base_size: FontBaseSize) -> Au {
|
pub fn to_computed_value_against(&self, context: &Context, base_size: FontBaseSize)
|
||||||
|
-> NonNegativeAu {
|
||||||
use values::specified::length::FontRelativeLength;
|
use values::specified::length::FontRelativeLength;
|
||||||
match *self {
|
match *self {
|
||||||
SpecifiedValue::Length(LengthOrPercentage::Length(
|
SpecifiedValue::Length(LengthOrPercentage::Length(
|
||||||
NoCalcLength::FontRelative(value))) => {
|
NoCalcLength::FontRelative(value))) => {
|
||||||
value.to_computed_value(context, base_size)
|
value.to_computed_value(context, base_size).into()
|
||||||
}
|
}
|
||||||
SpecifiedValue::Length(LengthOrPercentage::Length(
|
SpecifiedValue::Length(LengthOrPercentage::Length(
|
||||||
NoCalcLength::ServoCharacterWidth(value))) => {
|
NoCalcLength::ServoCharacterWidth(value))) => {
|
||||||
value.to_computed_value(base_size.resolve(context))
|
value.to_computed_value(base_size.resolve(context)).into()
|
||||||
}
|
}
|
||||||
SpecifiedValue::Length(LengthOrPercentage::Length(ref l)) => {
|
SpecifiedValue::Length(LengthOrPercentage::Length(ref l)) => {
|
||||||
context.maybe_zoom_text(l.to_computed_value(context))
|
context.maybe_zoom_text(l.to_computed_value(context).into())
|
||||||
}
|
}
|
||||||
SpecifiedValue::Length(LengthOrPercentage::Percentage(pc)) => {
|
SpecifiedValue::Length(LengthOrPercentage::Percentage(pc)) => {
|
||||||
base_size.resolve(context).scale_by(pc.0)
|
base_size.resolve(context).scale_by(pc.0).into()
|
||||||
}
|
}
|
||||||
SpecifiedValue::Length(LengthOrPercentage::Calc(ref calc)) => {
|
SpecifiedValue::Length(LengthOrPercentage::Calc(ref calc)) => {
|
||||||
let calc = calc.to_computed_value_zoomed(context);
|
let calc = calc.to_computed_value_zoomed(context);
|
||||||
calc.to_used_value(Some(base_size.resolve(context))).unwrap()
|
calc.to_used_value(Some(base_size.resolve(context))).unwrap().into()
|
||||||
}
|
}
|
||||||
SpecifiedValue::Keyword(ref key, fraction) => {
|
SpecifiedValue::Keyword(ref key, fraction) => {
|
||||||
context.maybe_zoom_text(key.to_computed_value(context).scale_by(fraction))
|
context.maybe_zoom_text(key.to_computed_value(context).scale_by(fraction))
|
||||||
}
|
}
|
||||||
SpecifiedValue::Smaller => {
|
SpecifiedValue::Smaller => {
|
||||||
FontRelativeLength::Em(1. / LARGER_FONT_SIZE_RATIO)
|
FontRelativeLength::Em(1. / LARGER_FONT_SIZE_RATIO)
|
||||||
.to_computed_value(context, base_size)
|
.to_computed_value(context, base_size).into()
|
||||||
}
|
}
|
||||||
SpecifiedValue::Larger => {
|
SpecifiedValue::Larger => {
|
||||||
FontRelativeLength::Em(LARGER_FONT_SIZE_RATIO)
|
FontRelativeLength::Em(LARGER_FONT_SIZE_RATIO)
|
||||||
.to_computed_value(context, base_size)
|
.to_computed_value(context, base_size).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
SpecifiedValue::System(_) => {
|
SpecifiedValue::System(_) => {
|
||||||
|
@ -863,7 +865,7 @@ ${helpers.single_keyword_system("font-variant-caps",
|
||||||
#[inline]
|
#[inline]
|
||||||
#[allow(missing_docs)]
|
#[allow(missing_docs)]
|
||||||
pub fn get_initial_value() -> computed_value::T {
|
pub fn get_initial_value() -> computed_value::T {
|
||||||
Au::from_px(FONT_MEDIUM_PX)
|
NonNegativeAu::from_px(FONT_MEDIUM_PX)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -883,7 +885,7 @@ ${helpers.single_keyword_system("font-variant-caps",
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_computed_value(computed: &computed_value::T) -> Self {
|
fn from_computed_value(computed: &computed_value::T) -> Self {
|
||||||
SpecifiedValue::Length(LengthOrPercentage::Length(
|
SpecifiedValue::Length(LengthOrPercentage::Length(
|
||||||
ToComputedValue::from_computed_value(computed)
|
ToComputedValue::from_computed_value(&computed.0)
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -930,7 +932,7 @@ ${helpers.single_keyword_system("font-variant-caps",
|
||||||
#[allow(unused_mut)]
|
#[allow(unused_mut)]
|
||||||
pub fn cascade_specified_font_size(context: &mut Context,
|
pub fn cascade_specified_font_size(context: &mut Context,
|
||||||
specified_value: &SpecifiedValue,
|
specified_value: &SpecifiedValue,
|
||||||
mut computed: Au) {
|
mut computed: NonNegativeAu) {
|
||||||
if let SpecifiedValue::Keyword(kw, fraction) = *specified_value {
|
if let SpecifiedValue::Keyword(kw, fraction) = *specified_value {
|
||||||
context.builder.font_size_keyword = Some((kw, fraction));
|
context.builder.font_size_keyword = Some((kw, fraction));
|
||||||
} else if let Some(ratio) = specified_value.as_font_ratio() {
|
} else if let Some(ratio) = specified_value.as_font_ratio() {
|
||||||
|
@ -976,7 +978,7 @@ ${helpers.single_keyword_system("font-variant-caps",
|
||||||
if let Some(parent) = parent_unconstrained {
|
if let Some(parent) = parent_unconstrained {
|
||||||
let new_unconstrained =
|
let new_unconstrained =
|
||||||
specified_value
|
specified_value
|
||||||
.to_computed_value_against(context, FontBaseSize::Custom(parent));
|
.to_computed_value_against(context, FontBaseSize::Custom(parent.0));
|
||||||
context.builder
|
context.builder
|
||||||
.mutate_font()
|
.mutate_font()
|
||||||
.apply_unconstrained_font_size(new_unconstrained);
|
.apply_unconstrained_font_size(new_unconstrained);
|
||||||
|
@ -1028,7 +1030,8 @@ ${helpers.single_keyword_system("font-variant-caps",
|
||||||
}
|
}
|
||||||
</%helpers:longhand>
|
</%helpers:longhand>
|
||||||
|
|
||||||
<%helpers:longhand products="gecko" name="font-size-adjust" animation_value_type="ComputedValue"
|
<%helpers:longhand products="gecko" name="font-size-adjust"
|
||||||
|
animation_value_type="longhands::font_size_adjust::computed_value::T"
|
||||||
flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER"
|
flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER"
|
||||||
spec="https://drafts.csswg.org/css-fonts/#propdef-font-size-adjust">
|
spec="https://drafts.csswg.org/css-fonts/#propdef-font-size-adjust">
|
||||||
use properties::longhands::system_font::SystemFont;
|
use properties::longhands::system_font::SystemFont;
|
||||||
|
@ -1082,7 +1085,7 @@ ${helpers.single_keyword_system("font-variant-caps",
|
||||||
pub mod computed_value {
|
pub mod computed_value {
|
||||||
use properties::animated_properties::Animatable;
|
use properties::animated_properties::Animatable;
|
||||||
use values::CSSFloat;
|
use values::CSSFloat;
|
||||||
use values::animated::ToAnimatedZero;
|
use values::animated::{ToAnimatedValue, ToAnimatedZero};
|
||||||
|
|
||||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, ToCss)]
|
#[derive(Copy, Clone, Debug, PartialEq, ToCss)]
|
||||||
|
@ -1125,6 +1128,23 @@ ${helpers.single_keyword_system("font-variant-caps",
|
||||||
#[inline]
|
#[inline]
|
||||||
fn to_animated_zero(&self) -> Result<Self, ()> { Err(()) }
|
fn to_animated_zero(&self) -> Result<Self, ()> { Err(()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ToAnimatedValue for T {
|
||||||
|
type AnimatedValue = Self;
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn to_animated_value(self) -> Self {
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn from_animated_value(animated: Self::AnimatedValue) -> Self {
|
||||||
|
match animated {
|
||||||
|
T::Number(number) => T::Number(number.max(0.)),
|
||||||
|
_ => animated
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -2514,7 +2534,7 @@ ${helpers.single_keyword("-moz-math-variant",
|
||||||
let weight = longhands::font_weight::computed_value::T::from_gecko_weight(system.weight);
|
let weight = longhands::font_weight::computed_value::T::from_gecko_weight(system.weight);
|
||||||
let ret = ComputedSystemFont {
|
let ret = ComputedSystemFont {
|
||||||
font_family: longhands::font_family::computed_value::T(family),
|
font_family: longhands::font_family::computed_value::T(family),
|
||||||
font_size: Au(system.size),
|
font_size: Au(system.size).into(),
|
||||||
font_weight: weight,
|
font_weight: weight,
|
||||||
font_size_adjust: longhands::font_size_adjust::computed_value
|
font_size_adjust: longhands::font_size_adjust::computed_value
|
||||||
::T::from_gecko_adjust(system.sizeAdjust),
|
::T::from_gecko_adjust(system.sizeAdjust),
|
||||||
|
|
|
@ -1648,12 +1648,12 @@ pub use gecko_properties::style_structs;
|
||||||
/// The module where all the style structs are defined.
|
/// The module where all the style structs are defined.
|
||||||
#[cfg(feature = "servo")]
|
#[cfg(feature = "servo")]
|
||||||
pub mod style_structs {
|
pub mod style_structs {
|
||||||
use app_units::Au;
|
|
||||||
use fnv::FnvHasher;
|
use fnv::FnvHasher;
|
||||||
use super::longhands;
|
use super::longhands;
|
||||||
use std::hash::{Hash, Hasher};
|
use std::hash::{Hash, Hasher};
|
||||||
use logical_geometry::WritingMode;
|
use logical_geometry::WritingMode;
|
||||||
use media_queries::Device;
|
use media_queries::Device;
|
||||||
|
use values::computed::NonNegativeAu;
|
||||||
|
|
||||||
% for style_struct in data.active_style_structs():
|
% for style_struct in data.active_style_structs():
|
||||||
% if style_struct.name == "Font":
|
% if style_struct.name == "Font":
|
||||||
|
@ -1771,7 +1771,8 @@ pub mod style_structs {
|
||||||
|
|
||||||
/// (Servo does not handle MathML, so this just calls copy_font_size_from)
|
/// (Servo does not handle MathML, so this just calls copy_font_size_from)
|
||||||
pub fn inherit_font_size_from(&mut self, parent: &Self,
|
pub fn inherit_font_size_from(&mut self, parent: &Self,
|
||||||
_: Option<Au>, _: &Device) -> bool {
|
_: Option<NonNegativeAu>,
|
||||||
|
_: &Device) -> bool {
|
||||||
self.copy_font_size_from(parent);
|
self.copy_font_size_from(parent);
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
@ -1779,12 +1780,12 @@ pub mod style_structs {
|
||||||
pub fn apply_font_size(&mut self,
|
pub fn apply_font_size(&mut self,
|
||||||
v: longhands::font_size::computed_value::T,
|
v: longhands::font_size::computed_value::T,
|
||||||
_: &Self,
|
_: &Self,
|
||||||
_: &Device) -> Option<Au> {
|
_: &Device) -> Option<NonNegativeAu> {
|
||||||
self.set_font_size(v);
|
self.set_font_size(v);
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
/// (Servo does not handle MathML, so this does nothing)
|
/// (Servo does not handle MathML, so this does nothing)
|
||||||
pub fn apply_unconstrained_font_size(&mut self, _: Au) {
|
pub fn apply_unconstrained_font_size(&mut self, _: NonNegativeAu) {
|
||||||
}
|
}
|
||||||
|
|
||||||
% elif style_struct.name == "Outline":
|
% elif style_struct.name == "Outline":
|
||||||
|
|
|
@ -60,7 +60,8 @@ impl Device {
|
||||||
media_type: media_type,
|
media_type: media_type,
|
||||||
viewport_size: viewport_size,
|
viewport_size: viewport_size,
|
||||||
device_pixel_ratio: device_pixel_ratio,
|
device_pixel_ratio: device_pixel_ratio,
|
||||||
root_font_size: AtomicIsize::new(font_size::get_initial_value().0 as isize), // FIXME(bz): Seems dubious?
|
// FIXME(bz): Seems dubious?
|
||||||
|
root_font_size: AtomicIsize::new(font_size::get_initial_value().value() as isize),
|
||||||
used_root_font_size: AtomicBool::new(false),
|
used_root_font_size: AtomicBool::new(false),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,7 +71,7 @@ impl ToComputedValue for specified::NoCalcLength {
|
||||||
specified::NoCalcLength::ViewportPercentage(length) =>
|
specified::NoCalcLength::ViewportPercentage(length) =>
|
||||||
length.to_computed_value(context.viewport_size()),
|
length.to_computed_value(context.viewport_size()),
|
||||||
specified::NoCalcLength::ServoCharacterWidth(length) =>
|
specified::NoCalcLength::ServoCharacterWidth(length) =>
|
||||||
length.to_computed_value(context.style().get_font().clone_font_size()),
|
length.to_computed_value(context.style().get_font().clone_font_size().0),
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
specified::NoCalcLength::Physical(length) =>
|
specified::NoCalcLength::Physical(length) =>
|
||||||
length.to_computed_value(context),
|
length.to_computed_value(context),
|
||||||
|
@ -265,7 +265,7 @@ impl specified::CalcLengthOrPercentage {
|
||||||
|
|
||||||
/// Compute font-size or line-height taking into account text-zoom if necessary.
|
/// Compute font-size or line-height taking into account text-zoom if necessary.
|
||||||
pub fn to_computed_value_zoomed(&self, context: &Context) -> CalcLengthOrPercentage {
|
pub fn to_computed_value_zoomed(&self, context: &Context) -> CalcLengthOrPercentage {
|
||||||
self.to_computed_value_with_zoom(context, |abs| context.maybe_zoom_text(abs))
|
self.to_computed_value_with_zoom(context, |abs| context.maybe_zoom_text(abs.into()).0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -137,12 +137,12 @@ impl<'a> Context<'a> {
|
||||||
|
|
||||||
/// Apply text-zoom if enabled
|
/// Apply text-zoom if enabled
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
pub fn maybe_zoom_text(&self, size: Au) -> Au {
|
pub fn maybe_zoom_text(&self, size: NonNegativeAu) -> NonNegativeAu {
|
||||||
// We disable zoom for <svg:text> by unsetting the
|
// We disable zoom for <svg:text> by unsetting the
|
||||||
// -x-text-zoom property, which leads to a false value
|
// -x-text-zoom property, which leads to a false value
|
||||||
// in mAllowZoom
|
// in mAllowZoom
|
||||||
if self.style().get_font().gecko.mAllowZoom {
|
if self.style().get_font().gecko.mAllowZoom {
|
||||||
self.device().zoom_text(size)
|
self.device().zoom_text(size.0).into()
|
||||||
} else {
|
} else {
|
||||||
size
|
size
|
||||||
}
|
}
|
||||||
|
@ -150,7 +150,7 @@ impl<'a> Context<'a> {
|
||||||
|
|
||||||
/// (Servo doesn't do text-zoom)
|
/// (Servo doesn't do text-zoom)
|
||||||
#[cfg(feature = "servo")]
|
#[cfg(feature = "servo")]
|
||||||
pub fn maybe_zoom_text(&self, size: Au) -> Au {
|
pub fn maybe_zoom_text(&self, size: NonNegativeAu) -> NonNegativeAu {
|
||||||
size
|
size
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -613,6 +613,13 @@ impl NonNegativeAu {
|
||||||
pub fn value(self) -> i32 {
|
pub fn value(self) -> i32 {
|
||||||
(self.0).0
|
(self.0).0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Scale this NonNegativeAu.
|
||||||
|
#[inline]
|
||||||
|
pub fn scale_by(self, factor: f32) -> Self {
|
||||||
|
// scale this by zero if factor is negative.
|
||||||
|
NonNegative::<Au>(self.0.scale_by(factor.max(0.)))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Au> for NonNegativeAu {
|
impl From<Au> for NonNegativeAu {
|
||||||
|
|
|
@ -92,8 +92,8 @@ impl FontBaseSize {
|
||||||
pub fn resolve(&self, context: &Context) -> Au {
|
pub fn resolve(&self, context: &Context) -> Au {
|
||||||
match *self {
|
match *self {
|
||||||
FontBaseSize::Custom(size) => size,
|
FontBaseSize::Custom(size) => size,
|
||||||
FontBaseSize::CurrentStyle => context.style().get_font().clone_font_size(),
|
FontBaseSize::CurrentStyle => context.style().get_font().clone_font_size().0,
|
||||||
FontBaseSize::InheritedStyle => context.style().get_parent_font().clone_font_size(),
|
FontBaseSize::InheritedStyle => context.style().get_parent_font().clone_font_size().0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,7 +95,7 @@ impl ToComputedValue for LineHeight {
|
||||||
GenericLineHeight::Number(number.to_computed_value(context))
|
GenericLineHeight::Number(number.to_computed_value(context))
|
||||||
},
|
},
|
||||||
GenericLineHeight::Length(LengthOrPercentage::Length(ref length)) => {
|
GenericLineHeight::Length(LengthOrPercentage::Length(ref length)) => {
|
||||||
GenericLineHeight::Length(context.maybe_zoom_text(length.to_computed_value(context)))
|
GenericLineHeight::Length(context.maybe_zoom_text(length.to_computed_value(context).into()).0)
|
||||||
},
|
},
|
||||||
GenericLineHeight::Length(LengthOrPercentage::Percentage(p)) => {
|
GenericLineHeight::Length(LengthOrPercentage::Percentage(p)) => {
|
||||||
let font_relative_length =
|
let font_relative_length =
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue