зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1503662 - Use used, rather than computed font-size for font-metric dependent units. r=jfkthame
Differential Revision: https://phabricator.services.mozilla.com/D165737
This commit is contained in:
Родитель
b535975ae1
Коммит
3cfb4f60c1
|
@ -0,0 +1,6 @@
|
|||
<!doctype html>
|
||||
<div style="font: 32px monospace;">
|
||||
the quick brown fox <br>
|
||||
jumps over the lazy <br>
|
||||
dog
|
||||
</div>
|
|
@ -0,0 +1,5 @@
|
|||
<!doctype html>
|
||||
<!-- NOTE: this testcase will be loaded with a minimum-size preference applied -->
|
||||
<div style="font: 5px monospace; width: 20ch;">
|
||||
the quick brown fox jumps over the lazy dog
|
||||
</div>
|
|
@ -152,6 +152,7 @@ pref(layout.css.caption-side-non-standard.enabled,true) == 134706-6c.html 134706
|
|||
== 144004-1.html 144004-1-ref.html
|
||||
== 144004-2.html 144004-2-ref.html
|
||||
!= 144004-3.html 144004-3-ref.html
|
||||
test-pref(font.minimum-size.x-western,32) == 1503662.html 1503662-ref.html
|
||||
== 163504-1a.html 163504-1-ref.html
|
||||
== 163504-1b.html 163504-1-ref.html
|
||||
== 163504-2a.html 163504-2-ref.html
|
||||
|
|
|
@ -919,7 +919,7 @@ pub trait MatchMethods: TElement {
|
|||
if is_root {
|
||||
let device = context.shared.stylist.device();
|
||||
debug_assert!(self.owner_doc_matches_for_testing(device));
|
||||
device.set_root_font_size(new_font_size.size().into());
|
||||
device.set_root_font_size(new_font_size.computed_size().into());
|
||||
if device.used_root_font_size() {
|
||||
// If the root font-size changed since last time, and something
|
||||
// in the document did use rem units, ensure we recascade the
|
||||
|
|
|
@ -983,7 +983,7 @@ impl<'a, 'b: 'a> Cascade<'a, 'b> {
|
|||
},
|
||||
};
|
||||
|
||||
if font.gecko().mScriptUnconstrainedSize == new_size.size {
|
||||
if font.gecko().mScriptUnconstrainedSize == new_size.computed_size {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -863,6 +863,8 @@ fn static_assert() {
|
|||
self.gecko.mScriptUnconstrainedSize = other.gecko.mScriptUnconstrainedSize;
|
||||
|
||||
self.gecko.mSize = other.gecko.mScriptUnconstrainedSize;
|
||||
// NOTE: Intentionally not copying from mFont.size. The cascade process
|
||||
// recomputes the used size as needed.
|
||||
self.gecko.mFont.size = other.gecko.mSize;
|
||||
self.gecko.mFontSizeKeyword = other.gecko.mFontSizeKeyword;
|
||||
|
||||
|
@ -876,12 +878,14 @@ fn static_assert() {
|
|||
}
|
||||
|
||||
pub fn set_font_size(&mut self, v: FontSize) {
|
||||
let size = v.size;
|
||||
self.gecko.mScriptUnconstrainedSize = size;
|
||||
let computed_size = v.computed_size;
|
||||
self.gecko.mScriptUnconstrainedSize = computed_size;
|
||||
|
||||
// These two may be changed from Cascade::fixup_font_stuff.
|
||||
self.gecko.mSize = size;
|
||||
self.gecko.mFont.size = size;
|
||||
self.gecko.mSize = computed_size;
|
||||
// NOTE: Intentionally not copying from used_size. The cascade process
|
||||
// recomputes the used size as needed.
|
||||
self.gecko.mFont.size = computed_size;
|
||||
|
||||
self.gecko.mFontSizeKeyword = v.keyword_info.kw;
|
||||
self.gecko.mFontSizeFactor = v.keyword_info.factor;
|
||||
|
@ -892,7 +896,8 @@ fn static_assert() {
|
|||
use crate::values::specified::font::KeywordInfo;
|
||||
|
||||
FontSize {
|
||||
size: self.gecko.mSize,
|
||||
computed_size: self.gecko.mSize,
|
||||
used_size: self.gecko.mFont.size,
|
||||
keyword_info: KeywordInfo {
|
||||
kw: self.gecko.mFontSizeKeyword,
|
||||
factor: self.gecko.mFontSizeFactor,
|
||||
|
|
|
@ -382,10 +382,12 @@ pub mod system_font {
|
|||
);
|
||||
&mut *system.as_mut_ptr()
|
||||
};
|
||||
let size = NonNegative(cx.maybe_zoom_text(system.size.0));
|
||||
let ret = ComputedSystemFont {
|
||||
font_family: system.family.clone(),
|
||||
font_size: FontSize {
|
||||
size: NonNegative(cx.maybe_zoom_text(system.size.0)),
|
||||
computed_size: size,
|
||||
used_size: size,
|
||||
keyword_info: KeywordInfo::none()
|
||||
},
|
||||
font_weight: system.weight,
|
||||
|
|
|
@ -53,7 +53,7 @@ impl RuleCacheConditions {
|
|||
}
|
||||
|
||||
if let Some(fs) = self.font_size {
|
||||
if style.get_font().clone_font_size().size != fs {
|
||||
if style.get_font().clone_font_size().computed_size != fs {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -224,8 +224,13 @@ impl FontWeight {
|
|||
#[cfg_attr(feature = "servo", derive(Serialize, Deserialize))]
|
||||
/// The computed value of font-size
|
||||
pub struct FontSize {
|
||||
/// The size.
|
||||
pub size: NonNegativeLength,
|
||||
/// The computed size, that we use to compute ems etc. This accounts for
|
||||
/// e.g., text-zoom.
|
||||
pub computed_size: NonNegativeLength,
|
||||
/// The actual used size. This is the computed font size, potentially
|
||||
/// constrained by other factors like minimum font-size settings and so on.
|
||||
#[css(skip)]
|
||||
pub used_size: NonNegativeLength,
|
||||
/// If derived from a keyword, the keyword and additional transformations applied to it
|
||||
#[css(skip)]
|
||||
pub keyword_info: KeywordInfo,
|
||||
|
@ -234,15 +239,22 @@ pub struct FontSize {
|
|||
impl FontSize {
|
||||
/// The actual computed font size.
|
||||
#[inline]
|
||||
pub fn size(&self) -> Length {
|
||||
self.size.0
|
||||
pub fn computed_size(&self) -> Length {
|
||||
self.computed_size.0
|
||||
}
|
||||
|
||||
/// The actual used font size.
|
||||
#[inline]
|
||||
pub fn used_size(&self) -> Length {
|
||||
self.used_size.0
|
||||
}
|
||||
|
||||
#[inline]
|
||||
/// Get default value of font size.
|
||||
pub fn medium() -> Self {
|
||||
Self {
|
||||
size: NonNegative(Length::new(specified::FONT_MEDIUM_PX)),
|
||||
computed_size: NonNegative(Length::new(specified::FONT_MEDIUM_PX)),
|
||||
used_size: NonNegative(Length::new(specified::FONT_MEDIUM_PX)),
|
||||
keyword_info: KeywordInfo::medium(),
|
||||
}
|
||||
}
|
||||
|
@ -253,13 +265,14 @@ impl ToAnimatedValue for FontSize {
|
|||
|
||||
#[inline]
|
||||
fn to_animated_value(self) -> Self::AnimatedValue {
|
||||
self.size.0
|
||||
self.computed_size.0
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn from_animated_value(animated: Self::AnimatedValue) -> Self {
|
||||
FontSize {
|
||||
size: NonNegative(animated.clamp_to_non_negative()),
|
||||
computed_size: NonNegative(animated.clamp_to_non_negative()),
|
||||
used_size: NonNegative(animated.clamp_to_non_negative()),
|
||||
keyword_info: KeywordInfo::none(),
|
||||
}
|
||||
}
|
||||
|
@ -796,7 +809,7 @@ impl ToComputedValue for specified::MozScriptMinSize {
|
|||
match self.0 {
|
||||
NoCalcLength::FontRelative(value) => value.to_computed_value(cx, base_size),
|
||||
NoCalcLength::ServoCharacterWidth(value) => {
|
||||
value.to_computed_value(base_size.resolve(cx))
|
||||
value.to_computed_value(base_size.resolve(cx).computed_size())
|
||||
},
|
||||
ref l => l.to_computed_value(cx),
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ impl specified::NoCalcLength {
|
|||
length.to_computed_value(context)
|
||||
},
|
||||
specified::NoCalcLength::ServoCharacterWidth(length) => {
|
||||
length.to_computed_value(context.style().get_font().clone_font_size().size())
|
||||
length.to_computed_value(context.style().get_font().clone_font_size().computed_size())
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -327,7 +327,7 @@ impl<'a> Context<'a> {
|
|||
FontBaseSize::CurrentStyle => ComputedValueFlags::DEPENDS_ON_SELF_FONT_METRICS,
|
||||
FontBaseSize::InheritedStyle => ComputedValueFlags::DEPENDS_ON_INHERITED_FONT_METRICS,
|
||||
});
|
||||
let size = base_size.resolve(self);
|
||||
let size = base_size.resolve(self).used_size();
|
||||
let style = self.style();
|
||||
|
||||
let (wm, font) = match base_size {
|
||||
|
|
|
@ -879,11 +879,11 @@ impl FontSize {
|
|||
// If the parent font was keyword-derived, this is too.
|
||||
// Tack the % onto the factor
|
||||
info = compose_keyword(pc.0);
|
||||
(base_size.resolve(context) * pc.0).normalized()
|
||||
(base_size.resolve(context).computed_size() * pc.0).normalized()
|
||||
},
|
||||
FontSize::Length(LengthPercentage::Calc(ref calc)) => {
|
||||
let calc = calc.to_computed_value_zoomed(context, base_size);
|
||||
calc.resolve(base_size.resolve(context))
|
||||
calc.resolve(base_size.resolve(context).computed_size())
|
||||
},
|
||||
FontSize::Keyword(i) => {
|
||||
// As a specified keyword, this is keyword derived
|
||||
|
@ -912,13 +912,13 @@ impl FontSize {
|
|||
.as_ref()
|
||||
.unwrap()
|
||||
.font_size
|
||||
.size
|
||||
.0
|
||||
.computed_size()
|
||||
}
|
||||
},
|
||||
};
|
||||
computed::FontSize {
|
||||
size: NonNegative(size),
|
||||
computed_size: NonNegative(size),
|
||||
used_size: NonNegative(size),
|
||||
keyword_info: info,
|
||||
}
|
||||
}
|
||||
|
@ -935,7 +935,7 @@ impl ToComputedValue for FontSize {
|
|||
#[inline]
|
||||
fn from_computed_value(computed: &computed::FontSize) -> Self {
|
||||
FontSize::Length(LengthPercentage::Length(
|
||||
ToComputedValue::from_computed_value(&computed.size.0),
|
||||
ToComputedValue::from_computed_value(&computed.computed_size()),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,12 +77,10 @@ pub enum FontBaseSize {
|
|||
|
||||
impl FontBaseSize {
|
||||
/// Calculate the actual size for a given context
|
||||
pub fn resolve(&self, context: &Context) -> computed::Length {
|
||||
pub fn resolve(&self, context: &Context) -> computed::FontSize {
|
||||
match *self {
|
||||
FontBaseSize::CurrentStyle => context.style().get_font().clone_font_size().size(),
|
||||
FontBaseSize::InheritedStyle => {
|
||||
context.style().get_parent_font().clone_font_size().size()
|
||||
},
|
||||
FontBaseSize::CurrentStyle => context.style().get_font().clone_font_size(),
|
||||
FontBaseSize::InheritedStyle => context.style().get_parent_font().clone_font_size(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -167,11 +165,11 @@ impl FontRelativeLength {
|
|||
context
|
||||
.rule_cache_conditions
|
||||
.borrow_mut()
|
||||
.set_font_size_dependency(reference_font_size.into());
|
||||
.set_font_size_dependency(reference_font_size.computed_size);
|
||||
}
|
||||
}
|
||||
|
||||
(reference_font_size, length)
|
||||
(reference_font_size.computed_size(), length)
|
||||
},
|
||||
FontRelativeLength::Ex(length) => {
|
||||
// The x-height is an intrinsically horizontal metric.
|
||||
|
@ -184,7 +182,9 @@ impl FontRelativeLength {
|
|||
// determine the x-height, a value of 0.5em must be
|
||||
// assumed.
|
||||
//
|
||||
reference_font_size * 0.5
|
||||
// (But note we use 0.5em of the used, not computed
|
||||
// font-size)
|
||||
reference_font_size.used_size() * 0.5
|
||||
});
|
||||
(reference_size, length)
|
||||
},
|
||||
|
@ -212,11 +212,13 @@ impl FontRelativeLength {
|
|||
// writing-mode is vertical-rl or vertical-lr and
|
||||
// text-orientation is upright).
|
||||
//
|
||||
// Same caveat about computed vs. used font-size applies
|
||||
// above.
|
||||
let wm = context.style().writing_mode;
|
||||
if wm.is_vertical() && wm.is_upright() {
|
||||
reference_font_size
|
||||
reference_font_size.used_size()
|
||||
} else {
|
||||
reference_font_size * 0.5
|
||||
reference_font_size.used_size() * 0.5
|
||||
}
|
||||
});
|
||||
(reference_size, length)
|
||||
|
@ -228,7 +230,8 @@ impl FontRelativeLength {
|
|||
// https://drafts.csswg.org/css-values/#cap
|
||||
//
|
||||
// In the cases where it is impossible or impractical to
|
||||
// determine the cap-height, the font’s ascent must be used.
|
||||
// determine the cap-height, the font’s ascent must be
|
||||
// used.
|
||||
//
|
||||
metrics.ascent
|
||||
});
|
||||
|
@ -247,7 +250,9 @@ impl FontRelativeLength {
|
|||
// determine the ideographic advance measure, it must be
|
||||
// assumed to be 1em.
|
||||
//
|
||||
reference_font_size
|
||||
// Same caveat about computed vs. used as for other
|
||||
// metric-dependent units.
|
||||
reference_font_size.used_size()
|
||||
});
|
||||
(reference_size, length)
|
||||
},
|
||||
|
@ -259,7 +264,7 @@ impl FontRelativeLength {
|
|||
// value.
|
||||
//
|
||||
let reference_size = if context.builder.is_root_element || context.in_media_query {
|
||||
reference_font_size
|
||||
reference_font_size.computed_size()
|
||||
} else {
|
||||
context.device().root_font_size()
|
||||
};
|
||||
|
|
|
@ -123,7 +123,7 @@ impl ToComputedValue for LineHeight {
|
|||
LengthPercentage::Calc(ref calc) => {
|
||||
let computed_calc =
|
||||
calc.to_computed_value_zoomed(context, FontBaseSize::CurrentStyle);
|
||||
let base = context.style().get_font().clone_font_size().size();
|
||||
let base = context.style().get_font().clone_font_size().computed_size();
|
||||
computed_calc.resolve(base)
|
||||
},
|
||||
};
|
||||
|
|
Загрузка…
Ссылка в новой задаче