зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1791281 - Simplify our setup for font metric queries from style. r=jfkthame
While looking at moving the flag around I realized that the only reason we have FontMetricsProvider and co is because we didn't have access to the per-document font-prefs cache. That's trivial to fix tho, so do that and simplify the setup for font queries even more. Differential Revision: https://phabricator.services.mozilla.com/D157589
This commit is contained in:
Родитель
5a9a3f516c
Коммит
d9a694f78f
|
@ -217,7 +217,7 @@ void nsPresContext::ForceReflowForFontInfoUpdate(bool aNeedsReframe) {
|
|||
|
||||
// We also need to trigger restyling for ex/ch units changes to take effect,
|
||||
// if needed.
|
||||
auto restyleHint = UsesFontMetricDependentFontUnits()
|
||||
auto restyleHint = StyleSet()->UsesFontMetrics()
|
||||
? RestyleHint::RecascadeSubtree()
|
||||
: RestyleHint{0};
|
||||
|
||||
|
@ -275,11 +275,9 @@ nsPresContext::nsPresContext(dom::Document* aDocument, nsPresContextType aType)
|
|||
mPendingUIResolutionChanged(false),
|
||||
mPendingFontInfoUpdateReflowFromStyle(false),
|
||||
mIsGlyph(false),
|
||||
mUsesFontMetricDependentFontUnits(false),
|
||||
mCounterStylesDirty(true),
|
||||
mFontFeatureValuesDirty(true),
|
||||
mIsVisual(false),
|
||||
mUnused(false),
|
||||
mHasWarnedAboutTooLargeDashedOrDottedRadius(false),
|
||||
mQuirkSheetAdded(false),
|
||||
mHadNonBlankPaint(false),
|
||||
|
@ -609,7 +607,7 @@ void nsPresContext::PreferenceChanged(const char* aPrefName) {
|
|||
// Changes to font_rendering prefs need to trigger a reflow
|
||||
StringBeginsWith(prefName, "gfx.font_rendering."_ns)) {
|
||||
changeHint |= NS_STYLE_HINT_REFLOW;
|
||||
if (UsesFontMetricDependentFontUnits()) {
|
||||
if (StyleSet()->UsesFontMetrics()) {
|
||||
restyleHint |= RestyleHint::RecascadeSubtree();
|
||||
}
|
||||
}
|
||||
|
@ -1846,9 +1844,6 @@ void nsPresContext::PostRebuildAllStyleDataEvent(
|
|||
// We must have been torn down. Nothing to do here.
|
||||
return;
|
||||
}
|
||||
if (aRestyleHint.DefinitelyRecascadesAllSubtree()) {
|
||||
mUsesFontMetricDependentFontUnits = false;
|
||||
}
|
||||
RestyleManager()->RebuildAllStyleData(aExtraHint, aRestyleHint);
|
||||
}
|
||||
|
||||
|
@ -2050,9 +2045,8 @@ void nsPresContext::UserFontSetUpdated(gfxUserFontEntry* aUpdatedFont) {
|
|||
// TODO(emilio): We could be more granular if we knew which families have
|
||||
// potentially changed.
|
||||
if (!aUpdatedFont) {
|
||||
auto hint = UsesFontMetricDependentFontUnits()
|
||||
? RestyleHint::RecascadeSubtree()
|
||||
: RestyleHint{0};
|
||||
auto hint = StyleSet()->UsesFontMetrics() ? RestyleHint::RecascadeSubtree()
|
||||
: RestyleHint{0};
|
||||
PostRebuildAllStyleDataEvent(NS_STYLE_HINT_REFLOW, hint);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -1058,14 +1058,6 @@ class nsPresContext : public nsISupports, public mozilla::SupportsWeakPtr {
|
|||
bool HasEverBuiltInvisibleText() const { return mHasEverBuiltInvisibleText; }
|
||||
void SetBuiltInvisibleText() { mHasEverBuiltInvisibleText = true; }
|
||||
|
||||
bool UsesFontMetricDependentFontUnits() const {
|
||||
return mUsesFontMetricDependentFontUnits;
|
||||
}
|
||||
|
||||
void SetUsesFontMetricDependentFontUnits(bool aValue) {
|
||||
mUsesFontMetricDependentFontUnits = aValue;
|
||||
}
|
||||
|
||||
bool IsDeviceSizePageSize();
|
||||
|
||||
bool HasWarnedAboutTooLargeDashedOrDottedRadius() const {
|
||||
|
@ -1342,12 +1334,6 @@ class nsPresContext : public nsISupports, public mozilla::SupportsWeakPtr {
|
|||
// Are we currently drawing an SVG glyph?
|
||||
unsigned mIsGlyph : 1;
|
||||
|
||||
// Does the associated document use ex or ch units?
|
||||
//
|
||||
// TODO(emilio, bug 1791281): It's a bit weird that this lives here but all
|
||||
// the other relevant bits live in Device on the rust side.
|
||||
unsigned mUsesFontMetricDependentFontUnits : 1;
|
||||
|
||||
// Is the current mCounterStyleManager valid?
|
||||
unsigned mCounterStylesDirty : 1;
|
||||
|
||||
|
@ -1356,12 +1342,6 @@ class nsPresContext : public nsISupports, public mozilla::SupportsWeakPtr {
|
|||
|
||||
unsigned mIsVisual : 1;
|
||||
|
||||
// FIXME(emilio, bug 1791281): Remove this and
|
||||
// mUsesFontMetricDependentFontUnits, which can be written to from multiple
|
||||
// threads (synchronized, but other code reads from other bits
|
||||
// unsynchronized).
|
||||
unsigned mUnused : 1;
|
||||
|
||||
unsigned mHasWarnedAboutTooLargeDashedOrDottedRadius : 1;
|
||||
|
||||
// Have we added quirk.css to the style set?
|
||||
|
|
|
@ -200,7 +200,6 @@ nscoord nsMathMLFrame::CalcLength(nsPresContext* aPresContext,
|
|||
}
|
||||
|
||||
if (eCSSUnit_XHeight == unit) {
|
||||
aPresContext->SetUsesFontMetricDependentFontUnits(true);
|
||||
RefPtr<nsFontMetrics> fm = nsLayoutUtils::GetFontMetricsForComputedStyle(
|
||||
aComputedStyle, aPresContext, aFontSizeInflation);
|
||||
nscoord xHeight = fm->XHeight();
|
||||
|
|
|
@ -986,6 +986,13 @@ StyleGenericFontFamily Gecko_nsStyleFont_ComputeFallbackFontTypeForLanguage(
|
|||
return ThreadSafeGetLangGroupFontPrefs(*aDoc, aLanguage)->GetDefaultGeneric();
|
||||
}
|
||||
|
||||
Length Gecko_GetBaseSize(const Document* aDoc, nsAtom* aLang,
|
||||
StyleGenericFontFamily aGeneric) {
|
||||
return ThreadSafeGetLangGroupFontPrefs(*aDoc, aLang)
|
||||
->GetDefaultFont(aGeneric)
|
||||
->size;
|
||||
}
|
||||
|
||||
gfxFontFeatureValueSet* Gecko_ConstructFontFeatureValueSet() {
|
||||
return new gfxFontFeatureValueSet();
|
||||
}
|
||||
|
@ -1320,17 +1327,6 @@ Length Gecko_nsStyleFont_ComputeMinSize(const nsStyleFont* aFont,
|
|||
return minFontSize;
|
||||
}
|
||||
|
||||
StyleDefaultFontSizes Gecko_GetBaseSize(nsAtom* aLanguage) {
|
||||
LangGroupFontPrefs prefs;
|
||||
nsStaticAtom* langGroupAtom =
|
||||
StaticPresData::Get()->GetUncachedLangGroup(aLanguage);
|
||||
prefs.Initialize(langGroupAtom);
|
||||
return {prefs.mDefaultVariableFont.size, prefs.mDefaultSerifFont.size,
|
||||
prefs.mDefaultSansSerifFont.size, prefs.mDefaultMonospaceFont.size,
|
||||
prefs.mDefaultCursiveFont.size, prefs.mDefaultFantasyFont.size,
|
||||
prefs.mDefaultSystemUiFont.size};
|
||||
}
|
||||
|
||||
static StaticRefPtr<UACacheReporter> gUACacheReporter;
|
||||
|
||||
namespace mozilla {
|
||||
|
@ -1385,8 +1381,6 @@ GeckoFontMetrics Gecko_GetFontMetrics(const nsPresContext* aPresContext,
|
|||
// ArrayBuffer-backed FontFace objects are handled synchronously.
|
||||
|
||||
nsPresContext* presContext = const_cast<nsPresContext*>(aPresContext);
|
||||
presContext->SetUsesFontMetricDependentFontUnits(true);
|
||||
|
||||
RefPtr<nsFontMetrics> fm = nsLayoutUtils::GetMetricsFor(
|
||||
presContext, aIsVertical, aFont, aFontSize, aUseUserFontSet);
|
||||
RefPtr<gfxFont> font = fm->GetThebesFontGroup()->GetFirstValidFont();
|
||||
|
|
|
@ -464,7 +464,9 @@ mozilla::StyleGenericFontFamily
|
|||
Gecko_nsStyleFont_ComputeFallbackFontTypeForLanguage(
|
||||
const mozilla::dom::Document*, nsAtom* language);
|
||||
|
||||
mozilla::StyleDefaultFontSizes Gecko_GetBaseSize(nsAtom* lang);
|
||||
mozilla::Length Gecko_GetBaseSize(const mozilla::dom::Document*,
|
||||
nsAtom* language,
|
||||
mozilla::StyleGenericFontFamily);
|
||||
|
||||
struct GeckoFontMetrics {
|
||||
mozilla::Length mXSize;
|
||||
|
|
|
@ -593,7 +593,6 @@ cbindgen-types = [
|
|||
{ gecko = "StyleSVGOpacity", servo = "crate::values::computed::svg::SVGOpacity" },
|
||||
{ gecko = "StyleSVGLength", servo = "crate::values::computed::svg::SVGLength" },
|
||||
{ gecko = "StyleFontSizeKeyword", servo = "crate::values::specified::font::FontSizeKeyword" },
|
||||
{ gecko = "StyleDefaultFontSizes", servo = "crate::gecko::wrapper::DefaultFontSizes" },
|
||||
{ gecko = "StyleCaptionSide", servo = "crate::values::computed::table::CaptionSide" },
|
||||
{ gecko = "StylePageName", servo = "crate::values::specified::page::PageName" },
|
||||
{ gecko = "StylePageSize", servo = "crate::values::computed::page::PageSize" },
|
||||
|
|
|
@ -1059,6 +1059,10 @@ already_AddRefed<RawServoAnimationValue> ServoStyleSet::ComputeAnimationValue(
|
|||
.Consume();
|
||||
}
|
||||
|
||||
bool ServoStyleSet::UsesFontMetrics() const {
|
||||
return Servo_StyleSet_UsesFontMetrics(mRawSet.get());
|
||||
}
|
||||
|
||||
bool ServoStyleSet::EnsureUniqueInnerOnCSSSheets() {
|
||||
using SheetOwner = Variant<ServoStyleSet*, ShadowRoot*>;
|
||||
|
||||
|
|
|
@ -153,6 +153,8 @@ class ServoStyleSet {
|
|||
|
||||
bool GetAuthorStyleDisabled() const { return mAuthorStyleDisabled; }
|
||||
|
||||
bool UsesFontMetrics() const;
|
||||
|
||||
void SetAuthorStyleDisabled(bool aStyleDisabled);
|
||||
|
||||
// Get a CopmutedStyle for a text node (which no rules will match).
|
||||
|
|
|
@ -172,6 +172,8 @@ void nsFontFaceUtils::MarkDirtyForFontChange(nsIFrame* aSubtreeRoot,
|
|||
nsPresContext* pc = aSubtreeRoot->PresContext();
|
||||
PresShell* presShell = pc->PresShell();
|
||||
|
||||
const bool usesMetricsFromStyle = pc->StyleSet()->UsesFontMetrics();
|
||||
|
||||
// StyleSingleFontFamily::IsNamedFamily expects a UTF-16 string. Convert it
|
||||
// once here rather than on each call.
|
||||
NS_ConvertUTF8toUTF16 familyName(aFont->FamilyName());
|
||||
|
@ -210,7 +212,7 @@ void nsFontFaceUtils::MarkDirtyForFontChange(nsIFrame* aSubtreeRoot,
|
|||
}
|
||||
|
||||
if (alreadyScheduled == ReflowAlreadyScheduled::No ||
|
||||
pc->UsesFontMetricDependentFontUnits()) {
|
||||
usesMetricsFromStyle) {
|
||||
if (f->IsPlaceholderFrame()) {
|
||||
nsIFrame* oof = nsPlaceholderFrame::GetRealFrameForPlaceholder(f);
|
||||
if (!nsLayoutUtils::IsProperAncestorFrame(subtreeRoot, oof)) {
|
||||
|
|
|
@ -9,7 +9,6 @@ use crate::animation::DocumentAnimationSet;
|
|||
use crate::bloom::StyleBloom;
|
||||
use crate::data::{EagerPseudoStyles, ElementData};
|
||||
use crate::dom::{SendElement, TElement};
|
||||
use crate::font_metrics::FontMetricsProvider;
|
||||
#[cfg(feature = "gecko")]
|
||||
use crate::gecko_bindings::structs;
|
||||
use crate::parallel::{STACK_SAFETY_MARGIN_KB, STYLE_THREAD_STACK_SIZE_KB};
|
||||
|
@ -640,9 +639,6 @@ pub struct ThreadLocalStyleContext<E: TElement> {
|
|||
pub tasks: SequentialTaskList<E>,
|
||||
/// Statistics about the traversal.
|
||||
pub statistics: PerThreadTraversalStatistics,
|
||||
/// The struct used to compute and cache font metrics from style
|
||||
/// for evaluation of the font-relative em/ch units and font-size
|
||||
pub font_metrics_provider: E::FontMetricsProvider,
|
||||
/// A checker used to ensure that parallel.rs does not recurse indefinitely
|
||||
/// even on arbitrarily deep trees. See Gecko bug 1376883.
|
||||
pub stack_limit_checker: StackLimitChecker,
|
||||
|
@ -651,33 +647,14 @@ pub struct ThreadLocalStyleContext<E: TElement> {
|
|||
}
|
||||
|
||||
impl<E: TElement> ThreadLocalStyleContext<E> {
|
||||
/// Creates a new `ThreadLocalStyleContext` from a shared one.
|
||||
#[cfg(feature = "servo")]
|
||||
pub fn new(shared: &SharedStyleContext) -> Self {
|
||||
/// Creates a new `ThreadLocalStyleContext`
|
||||
pub fn new() -> Self {
|
||||
ThreadLocalStyleContext {
|
||||
sharing_cache: StyleSharingCache::new(),
|
||||
rule_cache: RuleCache::new(),
|
||||
bloom_filter: StyleBloom::new(),
|
||||
tasks: SequentialTaskList(Vec::new()),
|
||||
statistics: PerThreadTraversalStatistics::default(),
|
||||
font_metrics_provider: E::FontMetricsProvider::create_from(shared),
|
||||
stack_limit_checker: StackLimitChecker::new(
|
||||
(STYLE_THREAD_STACK_SIZE_KB - STACK_SAFETY_MARGIN_KB) * 1024,
|
||||
),
|
||||
nth_index_cache: NthIndexCache::default(),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "gecko")]
|
||||
/// Creates a new `ThreadLocalStyleContext` from a shared one.
|
||||
pub fn new(shared: &SharedStyleContext) -> Self {
|
||||
ThreadLocalStyleContext {
|
||||
sharing_cache: StyleSharingCache::new(),
|
||||
rule_cache: RuleCache::new(),
|
||||
bloom_filter: StyleBloom::new(),
|
||||
tasks: SequentialTaskList(Vec::new()),
|
||||
statistics: PerThreadTraversalStatistics::default(),
|
||||
font_metrics_provider: E::FontMetricsProvider::create_from(shared),
|
||||
stack_limit_checker: StackLimitChecker::new(
|
||||
(STYLE_THREAD_STACK_SIZE_KB - STACK_SAFETY_MARGIN_KB) * 1024,
|
||||
),
|
||||
|
|
|
@ -12,7 +12,6 @@ use crate::context::SharedStyleContext;
|
|||
#[cfg(feature = "gecko")]
|
||||
use crate::context::{PostAnimationTasks, UpdateAnimationsTasks};
|
||||
use crate::data::ElementData;
|
||||
use crate::font_metrics::FontMetricsProvider;
|
||||
use crate::media_queries::Device;
|
||||
use crate::properties::{AnimationDeclarations, ComputedValues, PropertyDeclarationBlock};
|
||||
use crate::selector_parser::{AttrValue, Lang, PseudoElement, SelectorImpl};
|
||||
|
@ -363,12 +362,6 @@ pub trait TElement:
|
|||
/// syntax.
|
||||
type TraversalChildrenIterator: Iterator<Item = Self::ConcreteNode>;
|
||||
|
||||
/// Type of the font metrics provider
|
||||
///
|
||||
/// XXXManishearth It would be better to make this a type parameter on
|
||||
/// ThreadLocalStyleContext and StyleContext
|
||||
type FontMetricsProvider: FontMetricsProvider + Send;
|
||||
|
||||
/// Get this element as a node.
|
||||
fn as_node(&self) -> Self::ConcreteNode;
|
||||
|
||||
|
|
|
@ -91,7 +91,7 @@ where
|
|||
// ThreadLocalStyleContext has not released its TLS borrow by that point,
|
||||
// we'll panic on double-borrow.
|
||||
let mut tls_slots = None;
|
||||
let mut tlc = ThreadLocalStyleContext::new(traversal.shared_context());
|
||||
let mut tlc = ThreadLocalStyleContext::new();
|
||||
let mut context = StyleContext {
|
||||
shared: traversal.shared_context(),
|
||||
thread_local: &mut tlc,
|
||||
|
|
|
@ -6,9 +6,7 @@
|
|||
|
||||
#![deny(missing_docs)]
|
||||
|
||||
use crate::context::SharedStyleContext;
|
||||
use crate::values::computed::Length;
|
||||
use crate::Atom;
|
||||
|
||||
/// Represents the font metrics that style needs from a font to compute the
|
||||
/// value of certain CSS units like `ex`.
|
||||
|
@ -58,65 +56,3 @@ pub enum FontMetricsOrientation {
|
|||
/// Force getting horizontal metrics.
|
||||
Horizontal,
|
||||
}
|
||||
|
||||
/// A trait used to represent something capable of providing us font metrics.
|
||||
pub trait FontMetricsProvider {
|
||||
/// Obtain the metrics for given font family.
|
||||
fn query(
|
||||
&self,
|
||||
_context: &crate::values::computed::Context,
|
||||
_base_size: crate::values::specified::length::FontBaseSize,
|
||||
_orientation: FontMetricsOrientation,
|
||||
_retrieve_math_scales: bool,
|
||||
) -> FontMetrics {
|
||||
Default::default()
|
||||
}
|
||||
|
||||
/// Get default size of a given language and generic family.
|
||||
fn get_size(
|
||||
&self,
|
||||
font_name: &Atom,
|
||||
font_family: crate::values::computed::font::GenericFontFamily,
|
||||
) -> Length;
|
||||
|
||||
/// Construct from a shared style context
|
||||
fn create_from(context: &SharedStyleContext) -> Self
|
||||
where
|
||||
Self: Sized;
|
||||
}
|
||||
|
||||
// TODO: Servo's font metrics provider will probably not live in this crate, so this will
|
||||
// have to be replaced with something else (perhaps a trait method on TElement)
|
||||
// when we get there
|
||||
#[derive(Debug)]
|
||||
#[cfg(feature = "servo")]
|
||||
/// Dummy metrics provider for Servo. Knows nothing about fonts and does not provide
|
||||
/// any metrics.
|
||||
pub struct ServoMetricsProvider;
|
||||
|
||||
#[cfg(feature = "servo")]
|
||||
impl FontMetricsProvider for ServoMetricsProvider {
|
||||
fn create_from(_: &SharedStyleContext) -> Self {
|
||||
ServoMetricsProvider
|
||||
}
|
||||
|
||||
fn get_size(&self, _: &Atom, _: crate::values::computed::font::GenericFontFamily) -> Length {
|
||||
unreachable!("Dummy provider should never be used to compute font size")
|
||||
}
|
||||
}
|
||||
|
||||
// Servo's font metrics provider will probably not live in this crate, so this will
|
||||
// have to be replaced with something else (perhaps a trait method on TElement)
|
||||
// when we get there
|
||||
|
||||
#[cfg(feature = "gecko")]
|
||||
/// Construct a font metrics provider for the current product
|
||||
pub fn get_metrics_provider_for_product() -> crate::gecko::wrapper::GeckoFontMetricsProvider {
|
||||
crate::gecko::wrapper::GeckoFontMetricsProvider::new()
|
||||
}
|
||||
|
||||
#[cfg(feature = "servo")]
|
||||
/// Construct a font metrics provider for the current product
|
||||
pub fn get_metrics_provider_for_product() -> ServoMetricsProvider {
|
||||
ServoMetricsProvider
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
use crate::context::QuirksMode;
|
||||
use crate::custom_properties::CssEnvironment;
|
||||
use crate::font_metrics::FontMetrics;
|
||||
use crate::gecko::values::{convert_nscolor_to_rgba, convert_rgba_to_nscolor};
|
||||
use crate::gecko_bindings::bindings;
|
||||
use crate::gecko_bindings::structs;
|
||||
|
@ -13,6 +14,7 @@ use crate::media_queries::MediaType;
|
|||
use crate::properties::ComputedValues;
|
||||
use crate::string_cache::Atom;
|
||||
use crate::values::computed::{ColorScheme, Length};
|
||||
use crate::values::computed::font::GenericFontFamily;
|
||||
use crate::values::specified::color::SystemColor;
|
||||
use crate::values::specified::font::FONT_MEDIUM_PX;
|
||||
use crate::values::specified::ViewportVariant;
|
||||
|
@ -52,6 +54,8 @@ pub struct Device {
|
|||
/// Whether any styles computed in the document relied on the root font-size
|
||||
/// by using rem units.
|
||||
used_root_font_size: AtomicBool,
|
||||
/// Whether any styles computed in the document relied on font metrics.
|
||||
used_font_metrics: AtomicBool,
|
||||
/// Whether any styles computed in the document relied on the viewport size
|
||||
/// by using vw/vh/vmin/vmax units.
|
||||
used_viewport_size: AtomicBool,
|
||||
|
@ -98,6 +102,7 @@ impl Device {
|
|||
// matter which color-scheme we look at here.
|
||||
body_text_color: AtomicUsize::new(prefs.mLightColors.mDefault as usize),
|
||||
used_root_font_size: AtomicBool::new(false),
|
||||
used_font_metrics: AtomicBool::new(false),
|
||||
used_viewport_size: AtomicBool::new(false),
|
||||
used_dynamic_viewport_size: AtomicBool::new(false),
|
||||
environment: CssEnvironment,
|
||||
|
@ -165,6 +170,69 @@ impl Device {
|
|||
.store(convert_rgba_to_nscolor(&color) as usize, Ordering::Relaxed)
|
||||
}
|
||||
|
||||
/// Gets the base size given a generic font family and a language.
|
||||
pub fn base_size_for_generic(&self, language: &Atom, generic: GenericFontFamily) -> Length {
|
||||
unsafe {
|
||||
bindings::Gecko_GetBaseSize(self.document(), language.as_ptr(), generic)
|
||||
}
|
||||
}
|
||||
|
||||
/// Queries font metrics
|
||||
pub fn query_font_metrics(
|
||||
&self,
|
||||
vertical: bool,
|
||||
font: &crate::properties::style_structs::Font,
|
||||
base_size: Length,
|
||||
in_media_query: bool,
|
||||
retrieve_math_scales: bool,
|
||||
) -> FontMetrics {
|
||||
self.used_font_metrics.store(true, Ordering::Relaxed);
|
||||
let pc = match self.pres_context() {
|
||||
Some(pc) => pc,
|
||||
None => return Default::default(),
|
||||
};
|
||||
let gecko_metrics = unsafe {
|
||||
bindings::Gecko_GetFontMetrics(
|
||||
pc,
|
||||
vertical,
|
||||
font.gecko(),
|
||||
base_size,
|
||||
// we don't use the user font set in a media query
|
||||
!in_media_query,
|
||||
retrieve_math_scales,
|
||||
)
|
||||
};
|
||||
FontMetrics {
|
||||
x_height: Some(gecko_metrics.mXSize),
|
||||
zero_advance_measure: if gecko_metrics.mChSize.px() >= 0. {
|
||||
Some(gecko_metrics.mChSize)
|
||||
} else {
|
||||
None
|
||||
},
|
||||
cap_height: if gecko_metrics.mCapHeight.px() >= 0. {
|
||||
Some(gecko_metrics.mCapHeight)
|
||||
} else {
|
||||
None
|
||||
},
|
||||
ic_width: if gecko_metrics.mIcWidth.px() >= 0. {
|
||||
Some(gecko_metrics.mIcWidth)
|
||||
} else {
|
||||
None
|
||||
},
|
||||
ascent: gecko_metrics.mAscent,
|
||||
script_percent_scale_down: if gecko_metrics.mScriptPercentScaleDown > 0. {
|
||||
Some(gecko_metrics.mScriptPercentScaleDown)
|
||||
} else {
|
||||
None
|
||||
},
|
||||
script_script_percent_scale_down: if gecko_metrics.mScriptScriptPercentScaleDown > 0. {
|
||||
Some(gecko_metrics.mScriptScriptPercentScaleDown)
|
||||
} else {
|
||||
None
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the body text color.
|
||||
pub fn body_text_color(&self) -> RGBA {
|
||||
convert_nscolor_to_rgba(self.body_text_color.load(Ordering::Relaxed) as u32)
|
||||
|
@ -204,6 +272,7 @@ impl Device {
|
|||
pub fn rebuild_cached_data(&mut self) {
|
||||
self.reset_computed_values();
|
||||
self.used_root_font_size.store(false, Ordering::Relaxed);
|
||||
self.used_font_metrics.store(false, Ordering::Relaxed);
|
||||
self.used_viewport_size.store(false, Ordering::Relaxed);
|
||||
self.used_dynamic_viewport_size
|
||||
.store(false, Ordering::Relaxed);
|
||||
|
@ -342,6 +411,11 @@ impl Device {
|
|||
self.used_dynamic_viewport_size.load(Ordering::Relaxed)
|
||||
}
|
||||
|
||||
/// Returns whether font metrics have been queried.
|
||||
pub fn used_font_metrics(&self) -> bool {
|
||||
self.used_font_metrics.load(Ordering::Relaxed)
|
||||
}
|
||||
|
||||
/// Returns whether visited styles are enabled.
|
||||
pub fn visited_styles_enabled(&self) -> bool {
|
||||
unsafe { bindings::Gecko_VisitedStylesEnabled(self.document()) }
|
||||
|
|
|
@ -20,7 +20,6 @@ use crate::context::{PostAnimationTasks, QuirksMode, SharedStyleContext, UpdateA
|
|||
use crate::data::ElementData;
|
||||
use crate::dom::{LayoutIterator, NodeInfo, OpaqueNode, TDocument, TElement, TNode, TShadowRoot};
|
||||
use dom::{DocumentState, ElementState};
|
||||
use crate::font_metrics::{FontMetrics, FontMetricsOrientation, FontMetricsProvider};
|
||||
use crate::gecko::data::GeckoStyleSheet;
|
||||
use crate::gecko::selector_parser::{NonTSPseudoClass, PseudoElement, SelectorImpl};
|
||||
use crate::gecko::snapshot_helpers;
|
||||
|
@ -64,9 +63,6 @@ use crate::selector_parser::{AttrValue, Lang};
|
|||
use crate::shared_lock::{Locked, SharedRwLock};
|
||||
use crate::string_cache::{Atom, Namespace, WeakAtom, WeakNamespace};
|
||||
use crate::stylist::CascadeData;
|
||||
use crate::values::computed::font::GenericFontFamily;
|
||||
use crate::values::computed::Length;
|
||||
use crate::values::specified::length::FontBaseSize;
|
||||
use crate::values::{AtomIdent, AtomString};
|
||||
use crate::CaseSensitivityExt;
|
||||
use crate::LocalName;
|
||||
|
@ -82,7 +78,6 @@ use selectors::sink::Push;
|
|||
use selectors::{Element, OpaqueElement};
|
||||
use servo_arc::{Arc, ArcBorrow, RawOffsetArc};
|
||||
use std::sync::atomic::{AtomicU32, Ordering};
|
||||
use std::cell::RefCell;
|
||||
use std::fmt;
|
||||
use std::hash::{Hash, Hasher};
|
||||
use std::mem;
|
||||
|
@ -955,150 +950,8 @@ fn get_animation_rule(
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
/// Gecko font metrics provider
|
||||
pub struct GeckoFontMetricsProvider {
|
||||
/// Cache of base font sizes for each language. Usually will have 1 element.
|
||||
///
|
||||
/// This may be slow on pages using more languages, might be worth
|
||||
/// optimizing by caching lang->group mapping separately and/or using a
|
||||
/// hashmap on larger loads.
|
||||
pub font_size_cache: RefCell<Vec<(Atom, DefaultFontSizes)>>,
|
||||
}
|
||||
|
||||
impl GeckoFontMetricsProvider {
|
||||
/// Construct
|
||||
pub fn new() -> Self {
|
||||
GeckoFontMetricsProvider {
|
||||
font_size_cache: RefCell::new(Vec::new()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl FontMetricsProvider for GeckoFontMetricsProvider {
|
||||
fn create_from(_: &SharedStyleContext) -> GeckoFontMetricsProvider {
|
||||
GeckoFontMetricsProvider::new()
|
||||
}
|
||||
|
||||
fn get_size(&self, font_name: &Atom, font_family: GenericFontFamily) -> Length {
|
||||
let mut cache = self.font_size_cache.borrow_mut();
|
||||
if let Some(sizes) = cache.iter().find(|el| el.0 == *font_name) {
|
||||
return sizes.1.size_for_generic(font_family);
|
||||
}
|
||||
let sizes = unsafe { bindings::Gecko_GetBaseSize(font_name.as_ptr()) };
|
||||
let size = sizes.size_for_generic(font_family);
|
||||
cache.push((font_name.clone(), sizes));
|
||||
size
|
||||
}
|
||||
|
||||
fn query(
|
||||
&self,
|
||||
context: &crate::values::computed::Context,
|
||||
base_size: FontBaseSize,
|
||||
orientation: FontMetricsOrientation,
|
||||
retrieve_math_scales: bool,
|
||||
) -> FontMetrics {
|
||||
let pc = match context.device().pres_context() {
|
||||
Some(pc) => pc,
|
||||
None => return Default::default(),
|
||||
};
|
||||
|
||||
let size = base_size.resolve(context);
|
||||
let style = context.style();
|
||||
|
||||
let (wm, font) = match base_size {
|
||||
FontBaseSize::CurrentStyle => (style.writing_mode, style.get_font()),
|
||||
// This is only used for font-size computation.
|
||||
FontBaseSize::InheritedStyle => {
|
||||
(*style.inherited_writing_mode(), style.get_parent_font())
|
||||
},
|
||||
};
|
||||
|
||||
let vertical_metrics = match orientation {
|
||||
FontMetricsOrientation::MatchContextPreferHorizontal => {
|
||||
wm.is_vertical() && wm.is_upright()
|
||||
},
|
||||
FontMetricsOrientation::MatchContextPreferVertical => {
|
||||
wm.is_vertical() && !wm.is_sideways()
|
||||
},
|
||||
FontMetricsOrientation::Horizontal => false,
|
||||
};
|
||||
let gecko_metrics = unsafe {
|
||||
bindings::Gecko_GetFontMetrics(
|
||||
pc,
|
||||
vertical_metrics,
|
||||
font.gecko(),
|
||||
size,
|
||||
// we don't use the user font set in a media query
|
||||
!context.in_media_query,
|
||||
retrieve_math_scales,
|
||||
)
|
||||
};
|
||||
FontMetrics {
|
||||
x_height: Some(gecko_metrics.mXSize),
|
||||
zero_advance_measure: if gecko_metrics.mChSize.px() >= 0. {
|
||||
Some(gecko_metrics.mChSize)
|
||||
} else {
|
||||
None
|
||||
},
|
||||
cap_height: if gecko_metrics.mCapHeight.px() >= 0. {
|
||||
Some(gecko_metrics.mCapHeight)
|
||||
} else {
|
||||
None
|
||||
},
|
||||
ic_width: if gecko_metrics.mIcWidth.px() >= 0. {
|
||||
Some(gecko_metrics.mIcWidth)
|
||||
} else {
|
||||
None
|
||||
},
|
||||
ascent: gecko_metrics.mAscent,
|
||||
script_percent_scale_down: if gecko_metrics.mScriptPercentScaleDown > 0. {
|
||||
Some(gecko_metrics.mScriptPercentScaleDown)
|
||||
} else {
|
||||
None
|
||||
},
|
||||
script_script_percent_scale_down: if gecko_metrics.mScriptScriptPercentScaleDown > 0. {
|
||||
Some(gecko_metrics.mScriptScriptPercentScaleDown)
|
||||
} else {
|
||||
None
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The default font sizes for generic families for a given language group.
|
||||
#[derive(Debug)]
|
||||
#[repr(C)]
|
||||
pub struct DefaultFontSizes {
|
||||
variable: Length,
|
||||
serif: Length,
|
||||
sans_serif: Length,
|
||||
monospace: Length,
|
||||
cursive: Length,
|
||||
fantasy: Length,
|
||||
system_ui: Length,
|
||||
}
|
||||
|
||||
impl DefaultFontSizes {
|
||||
fn size_for_generic(&self, font_family: GenericFontFamily) -> Length {
|
||||
match font_family {
|
||||
GenericFontFamily::None => self.variable,
|
||||
GenericFontFamily::Serif => self.serif,
|
||||
GenericFontFamily::SansSerif => self.sans_serif,
|
||||
GenericFontFamily::Monospace => self.monospace,
|
||||
GenericFontFamily::Cursive => self.cursive,
|
||||
GenericFontFamily::Fantasy => self.fantasy,
|
||||
GenericFontFamily::SystemUi => self.system_ui,
|
||||
GenericFontFamily::MozEmoji => unreachable!(
|
||||
"Should never get here, since this doesn't (yet) appear on font family"
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'le> TElement for GeckoElement<'le> {
|
||||
type ConcreteNode = GeckoNode<'le>;
|
||||
type FontMetricsProvider = GeckoFontMetricsProvider;
|
||||
type TraversalChildrenIterator = GeckoChildrenIterator<'le>;
|
||||
|
||||
fn inheritance_parent(&self) -> Option<Self> {
|
||||
|
|
|
@ -75,14 +75,12 @@ type WorkUnit<N> = ArrayVec<SendNode<N>, WORK_UNIT_MAX>;
|
|||
/// out of line so we don't allocate stack space for the entire struct
|
||||
/// in the caller.
|
||||
#[inline(never)]
|
||||
fn create_thread_local_context<'scope, E, D>(
|
||||
traversal: &'scope D,
|
||||
fn create_thread_local_context<'scope, E>(
|
||||
slot: &mut Option<ThreadLocalStyleContext<E>>,
|
||||
) where
|
||||
E: TElement + 'scope,
|
||||
D: DomTraversal<E>,
|
||||
{
|
||||
*slot = Some(ThreadLocalStyleContext::new(traversal.shared_context()));
|
||||
*slot = Some(ThreadLocalStyleContext::new());
|
||||
}
|
||||
|
||||
/// A parallel top-down DOM traversal.
|
||||
|
@ -127,7 +125,7 @@ fn top_down_dom<'a, 'scope, E, D>(
|
|||
// Scope the borrow of the TLS so that the borrow is dropped before
|
||||
// a potential recursive call when we pass TailCall.
|
||||
let mut tlc = tls.ensure(|slot: &mut Option<ThreadLocalStyleContext<E>>| {
|
||||
create_thread_local_context(traversal, slot)
|
||||
create_thread_local_context(slot)
|
||||
});
|
||||
|
||||
// Check that we're not in danger of running out of stack.
|
||||
|
|
|
@ -8,7 +8,7 @@ use crate::applicable_declarations::CascadePriority;
|
|||
use crate::context::QuirksMode;
|
||||
use crate::custom_properties::CustomPropertiesBuilder;
|
||||
use crate::dom::TElement;
|
||||
use crate::font_metrics::{FontMetricsProvider, FontMetricsOrientation};
|
||||
use crate::font_metrics::FontMetricsOrientation;
|
||||
use crate::values::specified::length::FontBaseSize;
|
||||
use crate::logical_geometry::WritingMode;
|
||||
use crate::media_queries::Device;
|
||||
|
@ -60,7 +60,6 @@ pub fn cascade<E>(
|
|||
parent_style_ignoring_first_line: Option<&ComputedValues>,
|
||||
layout_parent_style: Option<&ComputedValues>,
|
||||
visited_rules: Option<&StrongRuleNode>,
|
||||
font_metrics_provider: &dyn FontMetricsProvider,
|
||||
quirks_mode: QuirksMode,
|
||||
rule_cache: Option<&RuleCache>,
|
||||
rule_cache_conditions: &mut RuleCacheConditions,
|
||||
|
@ -77,7 +76,6 @@ where
|
|||
parent_style,
|
||||
parent_style_ignoring_first_line,
|
||||
layout_parent_style,
|
||||
font_metrics_provider,
|
||||
CascadeMode::Unvisited { visited_rules },
|
||||
quirks_mode,
|
||||
rule_cache,
|
||||
|
@ -177,7 +175,6 @@ fn cascade_rules<E>(
|
|||
parent_style: Option<&ComputedValues>,
|
||||
parent_style_ignoring_first_line: Option<&ComputedValues>,
|
||||
layout_parent_style: Option<&ComputedValues>,
|
||||
font_metrics_provider: &dyn FontMetricsProvider,
|
||||
cascade_mode: CascadeMode,
|
||||
quirks_mode: QuirksMode,
|
||||
rule_cache: Option<&RuleCache>,
|
||||
|
@ -200,7 +197,6 @@ where
|
|||
parent_style,
|
||||
parent_style_ignoring_first_line,
|
||||
layout_parent_style,
|
||||
font_metrics_provider,
|
||||
cascade_mode,
|
||||
quirks_mode,
|
||||
rule_cache,
|
||||
|
@ -236,7 +232,6 @@ pub fn apply_declarations<'a, E, I>(
|
|||
parent_style: Option<&ComputedValues>,
|
||||
parent_style_ignoring_first_line: Option<&ComputedValues>,
|
||||
layout_parent_style: Option<&ComputedValues>,
|
||||
font_metrics_provider: &dyn FontMetricsProvider,
|
||||
cascade_mode: CascadeMode,
|
||||
quirks_mode: QuirksMode,
|
||||
rule_cache: Option<&RuleCache>,
|
||||
|
@ -301,7 +296,6 @@ where
|
|||
for_smil_animation: false,
|
||||
for_non_inherited_property: None,
|
||||
container_info: None,
|
||||
font_metrics_provider,
|
||||
quirks_mode,
|
||||
rule_cache_conditions: RefCell::new(rule_cache_conditions),
|
||||
};
|
||||
|
@ -760,7 +754,6 @@ impl<'a, 'b: 'a> Cascade<'a, 'b> {
|
|||
visited_parent!(parent_style),
|
||||
visited_parent!(parent_style_ignoring_first_line),
|
||||
visited_parent!(layout_parent_style),
|
||||
self.context.font_metrics_provider,
|
||||
CascadeMode::Visited { writing_mode },
|
||||
self.context.quirks_mode,
|
||||
// The rule cache doesn't care about caching :visited
|
||||
|
@ -1135,13 +1128,12 @@ impl<'a, 'b: 'a> Cascade<'a, 'b> {
|
|||
SCALE_FACTOR_WHEN_INCREMENTING_MATH_DEPTH_BY_ONE {
|
||||
(parent_font.mScriptSizeMultiplier as f32).powi(delta as i32)
|
||||
} else {
|
||||
builder.add_flags(ComputedValueFlags::DEPENDS_ON_SELF_FONT_METRICS);
|
||||
// Script scale factors are independent of orientation.
|
||||
let font_metrics = self.context
|
||||
.font_metrics_provider
|
||||
.query(self.context, FontBaseSize::InheritedStyle,
|
||||
FontMetricsOrientation::Horizontal,
|
||||
true /* retrieve_math_scales */);
|
||||
let font_metrics = self.context.query_font_metrics(
|
||||
FontBaseSize::InheritedStyle,
|
||||
FontMetricsOrientation::Horizontal,
|
||||
/* retrieve_math_scales = */ true,
|
||||
);
|
||||
scale_factor_for_math_depth_change(
|
||||
parent_font.mMathDepth as i32,
|
||||
font.mMathDepth as i32,
|
||||
|
|
|
@ -351,7 +351,6 @@ where
|
|||
parent_style,
|
||||
parent_style,
|
||||
layout_parent_style,
|
||||
&self.context.thread_local.font_metrics_provider,
|
||||
Some(&self.context.thread_local.rule_cache),
|
||||
&mut conditions,
|
||||
);
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
|
||||
use crate::context::QuirksMode;
|
||||
use crate::error_reporting::ContextualParseError;
|
||||
use crate::font_metrics::get_metrics_provider_for_product;
|
||||
use crate::media_queries::Device;
|
||||
use crate::parser::{Parse, ParserContext};
|
||||
use crate::properties::StyleBuilder;
|
||||
|
@ -673,14 +672,11 @@ impl MaybeNew for ViewportConstraints {
|
|||
// DEVICE-ADAPT § 6.2.3 Resolve non-auto lengths to pixel lengths
|
||||
let initial_viewport = device.au_viewport_size();
|
||||
|
||||
let provider = get_metrics_provider_for_product();
|
||||
|
||||
let mut conditions = RuleCacheConditions::default();
|
||||
let context = Context {
|
||||
// Note: DEVICE-ADAPT § 5. states that relative length values are
|
||||
// resolved against initial values
|
||||
builder: StyleBuilder::for_inheritance(device, None, None),
|
||||
font_metrics_provider: &provider,
|
||||
cached_system_font: None,
|
||||
in_media_query: false,
|
||||
quirks_mode,
|
||||
|
|
|
@ -9,7 +9,6 @@ use crate::applicable_declarations::{
|
|||
};
|
||||
use crate::context::{CascadeInputs, QuirksMode};
|
||||
use crate::dom::{TElement, TShadowRoot};
|
||||
use crate::font_metrics::FontMetricsProvider;
|
||||
#[cfg(feature = "gecko")]
|
||||
use crate::gecko_bindings::structs::{ServoStyleSetSizes, StyleRuleInclusion};
|
||||
use crate::invalidation::element::invalidation_map::InvalidationMap;
|
||||
|
@ -861,7 +860,6 @@ impl Stylist {
|
|||
guards: &StylesheetGuards,
|
||||
pseudo: &PseudoElement,
|
||||
parent: Option<&ComputedValues>,
|
||||
font_metrics: &dyn FontMetricsProvider,
|
||||
) -> Arc<ComputedValues>
|
||||
where
|
||||
E: TElement,
|
||||
|
@ -874,7 +872,6 @@ impl Stylist {
|
|||
guards,
|
||||
pseudo,
|
||||
parent,
|
||||
font_metrics,
|
||||
rule_node,
|
||||
)
|
||||
}
|
||||
|
@ -889,7 +886,6 @@ impl Stylist {
|
|||
guards: &StylesheetGuards,
|
||||
pseudo: &PseudoElement,
|
||||
parent: Option<&ComputedValues>,
|
||||
font_metrics: &dyn FontMetricsProvider,
|
||||
rules: StrongRuleNode,
|
||||
) -> Arc<ComputedValues>
|
||||
where
|
||||
|
@ -903,7 +899,6 @@ impl Stylist {
|
|||
pseudo,
|
||||
guards,
|
||||
parent,
|
||||
font_metrics,
|
||||
None,
|
||||
)
|
||||
}
|
||||
|
@ -958,12 +953,10 @@ impl Stylist {
|
|||
where
|
||||
E: TElement,
|
||||
{
|
||||
use crate::font_metrics::ServoMetricsProvider;
|
||||
self.precomputed_values_for_pseudo::<E>(
|
||||
guards,
|
||||
&pseudo,
|
||||
Some(parent_style),
|
||||
&ServoMetricsProvider,
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -982,7 +975,6 @@ impl Stylist {
|
|||
rule_inclusion: RuleInclusion,
|
||||
parent_style: &ComputedValues,
|
||||
is_probe: bool,
|
||||
font_metrics: &dyn FontMetricsProvider,
|
||||
matching_fn: Option<&dyn Fn(&PseudoElement) -> bool>,
|
||||
) -> Option<Arc<ComputedValues>>
|
||||
where
|
||||
|
@ -1003,7 +995,6 @@ impl Stylist {
|
|||
pseudo,
|
||||
guards,
|
||||
Some(parent_style),
|
||||
font_metrics,
|
||||
Some(element),
|
||||
))
|
||||
}
|
||||
|
@ -1018,7 +1009,6 @@ impl Stylist {
|
|||
pseudo: &PseudoElement,
|
||||
guards: &StylesheetGuards,
|
||||
parent_style: Option<&ComputedValues>,
|
||||
font_metrics: &dyn FontMetricsProvider,
|
||||
element: Option<E>,
|
||||
) -> Arc<ComputedValues>
|
||||
where
|
||||
|
@ -1044,7 +1034,6 @@ impl Stylist {
|
|||
parent_style,
|
||||
parent_style,
|
||||
parent_style,
|
||||
font_metrics,
|
||||
/* rule_cache = */ None,
|
||||
&mut RuleCacheConditions::default(),
|
||||
)
|
||||
|
@ -1071,7 +1060,6 @@ impl Stylist {
|
|||
parent_style: Option<&ComputedValues>,
|
||||
parent_style_ignoring_first_line: Option<&ComputedValues>,
|
||||
layout_parent_style: Option<&ComputedValues>,
|
||||
font_metrics: &dyn FontMetricsProvider,
|
||||
rule_cache: Option<&RuleCache>,
|
||||
rule_cache_conditions: &mut RuleCacheConditions,
|
||||
) -> Arc<ComputedValues>
|
||||
|
@ -1108,7 +1096,6 @@ impl Stylist {
|
|||
parent_style_ignoring_first_line,
|
||||
layout_parent_style,
|
||||
visited_rules,
|
||||
font_metrics,
|
||||
self.quirks_mode,
|
||||
rule_cache,
|
||||
rule_cache_conditions,
|
||||
|
@ -1494,10 +1481,7 @@ impl Stylist {
|
|||
where
|
||||
E: TElement,
|
||||
{
|
||||
use crate::font_metrics::get_metrics_provider_for_product;
|
||||
|
||||
let block = declarations.read_with(guards.author);
|
||||
let metrics = get_metrics_provider_for_product();
|
||||
|
||||
// We don't bother inserting these declarations in the rule tree, since
|
||||
// it'd be quite useless and slow.
|
||||
|
@ -1522,7 +1506,6 @@ impl Stylist {
|
|||
Some(parent_style),
|
||||
Some(parent_style),
|
||||
Some(parent_style),
|
||||
&metrics,
|
||||
CascadeMode::Unvisited {
|
||||
visited_rules: None,
|
||||
},
|
||||
|
|
|
@ -14,14 +14,16 @@ use super::generics::transform::IsParallelTo;
|
|||
use super::generics::{self, GreaterThanOrEqualToOne, NonNegative, ZeroToOne};
|
||||
use super::specified;
|
||||
use super::{CSSFloat, CSSInteger};
|
||||
use crate::computed_value_flags::ComputedValueFlags;
|
||||
use crate::context::QuirksMode;
|
||||
use crate::stylesheets::container_rule::ContainerInfo;
|
||||
use crate::font_metrics::{get_metrics_provider_for_product, FontMetricsProvider};
|
||||
use crate::font_metrics::{FontMetrics, FontMetricsOrientation};
|
||||
use crate::media_queries::Device;
|
||||
#[cfg(feature = "gecko")]
|
||||
use crate::properties;
|
||||
use crate::properties::{ComputedValues, LonghandId, StyleBuilder};
|
||||
use crate::rule_cache::RuleCacheConditions;
|
||||
use crate::values::specified::length::FontBaseSize;
|
||||
use crate::{ArcSlice, Atom, One};
|
||||
use euclid::{default, Point2D, Rect, Size2D};
|
||||
use servo_arc::Arc;
|
||||
|
@ -157,10 +159,6 @@ pub struct Context<'a> {
|
|||
#[cfg(feature = "servo")]
|
||||
pub cached_system_font: Option<()>,
|
||||
|
||||
/// A font metrics provider, used to access font metrics to implement
|
||||
/// font-relative units.
|
||||
pub font_metrics_provider: &'a dyn FontMetricsProvider,
|
||||
|
||||
/// Whether or not we are computing the media list in a media query
|
||||
pub in_media_query: bool,
|
||||
|
||||
|
@ -197,11 +195,8 @@ impl<'a> Context<'a> {
|
|||
F: FnOnce(&Context) -> R,
|
||||
{
|
||||
let mut conditions = RuleCacheConditions::default();
|
||||
let provider = get_metrics_provider_for_product();
|
||||
|
||||
let context = Context {
|
||||
builder: StyleBuilder::for_inheritance(device, None, None),
|
||||
font_metrics_provider: &provider,
|
||||
cached_system_font: None,
|
||||
in_media_query: true,
|
||||
quirks_mode,
|
||||
|
@ -210,7 +205,6 @@ impl<'a> Context<'a> {
|
|||
for_non_inherited_property: None,
|
||||
rule_cache_conditions: RefCell::new(&mut conditions),
|
||||
};
|
||||
|
||||
f(&context)
|
||||
}
|
||||
|
||||
|
@ -225,7 +219,6 @@ impl<'a> Context<'a> {
|
|||
F: FnOnce(&Context) -> R,
|
||||
{
|
||||
let mut conditions = RuleCacheConditions::default();
|
||||
let provider = get_metrics_provider_for_product();
|
||||
|
||||
let (container_info, style) = match container_info_and_style {
|
||||
Some((ci, s)) => (Some(ci), Some(s)),
|
||||
|
@ -236,7 +229,6 @@ impl<'a> Context<'a> {
|
|||
let quirks_mode = device.quirks_mode();
|
||||
let context = Context {
|
||||
builder: StyleBuilder::for_inheritance(device, style, None),
|
||||
font_metrics_provider: &provider,
|
||||
cached_system_font: None,
|
||||
in_media_query: true,
|
||||
quirks_mode,
|
||||
|
@ -254,6 +246,49 @@ impl<'a> Context<'a> {
|
|||
self.builder.device
|
||||
}
|
||||
|
||||
/// Queries font metrics.
|
||||
pub fn query_font_metrics(
|
||||
&self,
|
||||
base_size: FontBaseSize,
|
||||
orientation: FontMetricsOrientation,
|
||||
retrieve_math_scales: bool,
|
||||
) -> FontMetrics {
|
||||
if self.for_non_inherited_property.is_some() {
|
||||
self.rule_cache_conditions.borrow_mut().set_uncacheable();
|
||||
}
|
||||
self.builder.add_flags(match base_size {
|
||||
FontBaseSize::CurrentStyle => ComputedValueFlags::DEPENDS_ON_SELF_FONT_METRICS,
|
||||
FontBaseSize::InheritedStyle => ComputedValueFlags::DEPENDS_ON_INHERITED_FONT_METRICS,
|
||||
});
|
||||
let size = base_size.resolve(self);
|
||||
let style = self.style();
|
||||
|
||||
let (wm, font) = match base_size {
|
||||
FontBaseSize::CurrentStyle => (style.writing_mode, style.get_font()),
|
||||
// This is only used for font-size computation.
|
||||
FontBaseSize::InheritedStyle => {
|
||||
(*style.inherited_writing_mode(), style.get_parent_font())
|
||||
},
|
||||
};
|
||||
|
||||
let vertical = match orientation {
|
||||
FontMetricsOrientation::MatchContextPreferHorizontal => {
|
||||
wm.is_vertical() && wm.is_upright()
|
||||
},
|
||||
FontMetricsOrientation::MatchContextPreferVertical => {
|
||||
wm.is_vertical() && !wm.is_sideways()
|
||||
},
|
||||
FontMetricsOrientation::Horizontal => false,
|
||||
};
|
||||
self.device().query_font_metrics(
|
||||
vertical,
|
||||
font,
|
||||
size,
|
||||
self.in_media_query,
|
||||
retrieve_math_scales
|
||||
)
|
||||
}
|
||||
|
||||
/// The current viewport size, used to resolve viewport units.
|
||||
pub fn viewport_size_for_viewport_unit_resolution(
|
||||
&self,
|
||||
|
|
|
@ -5,12 +5,11 @@
|
|||
//! Specified values for font properties
|
||||
|
||||
use crate::context::QuirksMode;
|
||||
use crate::font_metrics::FontMetricsProvider;
|
||||
use crate::parser::{Parse, ParserContext};
|
||||
use crate::values::computed::font::{FamilyName, FontFamilyList, SingleFontFamily};
|
||||
use crate::values::computed::FontSizeAdjust as ComputedFontSizeAdjust;
|
||||
use crate::values::computed::{font as computed, Length, NonNegativeLength};
|
||||
use crate::values::computed::{Percentage as ComputedPercentage};
|
||||
use crate::values::computed::Percentage as ComputedPercentage;
|
||||
use crate::values::computed::{CSSPixelLength, Context, ToComputedValue};
|
||||
use crate::values::generics::font::VariationValue;
|
||||
use crate::values::generics::font::{
|
||||
|
@ -778,16 +777,13 @@ impl FontSizeKeyword {
|
|||
fn to_length(&self, cx: &Context) -> NonNegativeLength {
|
||||
let gecko_font = cx.style().get_font().gecko();
|
||||
let family = &gecko_font.mFont.family.families;
|
||||
unsafe {
|
||||
let generic = family.single_generic().unwrap_or(computed::GenericFontFamily::None);
|
||||
let base_size = unsafe {
|
||||
Atom::with(gecko_font.mLanguage.mRawPtr, |language| {
|
||||
self.to_length_without_context(
|
||||
cx.quirks_mode,
|
||||
cx.font_metrics_provider,
|
||||
language,
|
||||
family,
|
||||
)
|
||||
cx.device().base_size_for_generic(language, generic)
|
||||
})
|
||||
}
|
||||
};
|
||||
self.to_length_without_context(cx.quirks_mode, base_size)
|
||||
}
|
||||
|
||||
/// Resolve a keyword length without any context, with explicit arguments.
|
||||
|
@ -796,9 +792,7 @@ impl FontSizeKeyword {
|
|||
pub fn to_length_without_context(
|
||||
&self,
|
||||
quirks_mode: QuirksMode,
|
||||
font_metrics_provider: &dyn FontMetricsProvider,
|
||||
language: &Atom,
|
||||
family: &FontFamilyList,
|
||||
base_size: Length,
|
||||
) -> NonNegativeLength {
|
||||
// The tables in this function are originally from
|
||||
// nsRuleNode::CalcFontPointSize in Gecko:
|
||||
|
@ -843,11 +837,6 @@ impl FontSizeKeyword {
|
|||
];
|
||||
|
||||
static FONT_SIZE_FACTORS: [i32; 8] = [60, 75, 89, 100, 120, 150, 200, 300];
|
||||
|
||||
let generic = family
|
||||
.single_generic()
|
||||
.unwrap_or(computed::GenericFontFamily::None);
|
||||
let base_size = font_metrics_provider.get_size(language, generic);
|
||||
let base_size_px = base_size.px().round() as i32;
|
||||
let html_size = self.html_size() as usize;
|
||||
NonNegative(if base_size_px >= 9 && base_size_px <= 16 {
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
//! [length]: https://drafts.csswg.org/css-values/#lengths
|
||||
|
||||
use super::{AllowQuirks, Number, Percentage, ToComputedValue};
|
||||
use crate::computed_value_flags::ComputedValueFlags;
|
||||
use crate::font_metrics::{FontMetrics, FontMetricsOrientation};
|
||||
use crate::parser::{Parse, ParserContext};
|
||||
use crate::values::computed::{self, CSSPixelLength, Context};
|
||||
|
@ -162,17 +161,15 @@ impl FontRelativeLength {
|
|||
base_size: FontBaseSize,
|
||||
orientation: FontMetricsOrientation,
|
||||
) -> FontMetrics {
|
||||
context
|
||||
.font_metrics_provider
|
||||
.query(context, base_size, orientation,
|
||||
false /* retrieve_math_scales */)
|
||||
let retrieve_math_scales = false;
|
||||
context.query_font_metrics(
|
||||
base_size,
|
||||
orientation,
|
||||
retrieve_math_scales,
|
||||
)
|
||||
}
|
||||
|
||||
let reference_font_size = base_size.resolve(context);
|
||||
let font_metrics_flag = match base_size {
|
||||
FontBaseSize::CurrentStyle => ComputedValueFlags::DEPENDS_ON_SELF_FONT_METRICS,
|
||||
FontBaseSize::InheritedStyle => ComputedValueFlags::DEPENDS_ON_INHERITED_FONT_METRICS,
|
||||
};
|
||||
match *self {
|
||||
FontRelativeLength::Em(length) => {
|
||||
if context.for_non_inherited_property.is_some() {
|
||||
|
@ -187,10 +184,6 @@ impl FontRelativeLength {
|
|||
(reference_font_size, length)
|
||||
},
|
||||
FontRelativeLength::Ex(length) => {
|
||||
if context.for_non_inherited_property.is_some() {
|
||||
context.rule_cache_conditions.borrow_mut().set_uncacheable();
|
||||
}
|
||||
context.builder.add_flags(font_metrics_flag);
|
||||
// The x-height is an intrinsically horizontal metric.
|
||||
let metrics =
|
||||
query_font_metrics(context, base_size, FontMetricsOrientation::Horizontal);
|
||||
|
@ -206,10 +199,6 @@ impl FontRelativeLength {
|
|||
(reference_size, length)
|
||||
},
|
||||
FontRelativeLength::Ch(length) => {
|
||||
if context.for_non_inherited_property.is_some() {
|
||||
context.rule_cache_conditions.borrow_mut().set_uncacheable();
|
||||
}
|
||||
context.builder.add_flags(font_metrics_flag);
|
||||
// https://drafts.csswg.org/css-values/#ch:
|
||||
//
|
||||
// Equal to the used advance measure of the “0” (ZERO,
|
||||
|
@ -243,10 +232,6 @@ impl FontRelativeLength {
|
|||
(reference_size, length)
|
||||
},
|
||||
FontRelativeLength::Cap(length) => {
|
||||
if context.for_non_inherited_property.is_some() {
|
||||
context.rule_cache_conditions.borrow_mut().set_uncacheable();
|
||||
}
|
||||
context.builder.add_flags(font_metrics_flag);
|
||||
let metrics =
|
||||
query_font_metrics(context, base_size, FontMetricsOrientation::Horizontal);
|
||||
let reference_size = metrics.cap_height.unwrap_or_else(|| {
|
||||
|
@ -260,10 +245,6 @@ impl FontRelativeLength {
|
|||
(reference_size, length)
|
||||
},
|
||||
FontRelativeLength::Ic(length) => {
|
||||
if context.for_non_inherited_property.is_some() {
|
||||
context.rule_cache_conditions.borrow_mut().set_uncacheable();
|
||||
}
|
||||
context.builder.add_flags(font_metrics_flag);
|
||||
let metrics = query_font_metrics(
|
||||
context,
|
||||
base_size,
|
||||
|
|
|
@ -29,7 +29,6 @@ use style::dom::{ShowSubtreeData, TDocument, TElement, TNode};
|
|||
use style::driver;
|
||||
use style::error_reporting::{ContextualParseError, ParseErrorReporter};
|
||||
use style::font_face::{self, FontFaceSourceListComponent, FontFaceSourceFormat, Source};
|
||||
use style::font_metrics::{get_metrics_provider_for_product, FontMetricsProvider};
|
||||
use style::gecko::data::{GeckoStyleSheet, PerDocumentStyleData, PerDocumentStyleDataImpl};
|
||||
use style::gecko::restyle_damage::GeckoRestyleDamage;
|
||||
use style::gecko::selector_parser::{NonTSPseudoClass, PseudoElement};
|
||||
|
@ -1187,7 +1186,7 @@ pub extern "C" fn Servo_StyleSet_GetBaseComputedValuesForElement(
|
|||
TraversalFlags::empty(),
|
||||
unsafe { &*snapshots },
|
||||
);
|
||||
let mut tlc = ThreadLocalStyleContext::new(&shared);
|
||||
let mut tlc = ThreadLocalStyleContext::new();
|
||||
let context = StyleContext {
|
||||
shared: &shared,
|
||||
thread_local: &mut tlc,
|
||||
|
@ -1238,7 +1237,7 @@ pub extern "C" fn Servo_StyleSet_GetComputedValuesByAddingAnimation(
|
|||
TraversalFlags::empty(),
|
||||
unsafe { &*snapshots },
|
||||
);
|
||||
let mut tlc: ThreadLocalStyleContext<GeckoElement> = ThreadLocalStyleContext::new(&shared);
|
||||
let mut tlc: ThreadLocalStyleContext<GeckoElement> = ThreadLocalStyleContext::new();
|
||||
let context = StyleContext {
|
||||
shared: &shared,
|
||||
thread_local: &mut tlc,
|
||||
|
@ -1973,6 +1972,12 @@ pub extern "C" fn Servo_StyleSet_SetAuthorStyleDisabled(
|
|||
data.stylist.set_author_styles_enabled(enabled);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn Servo_StyleSet_UsesFontMetrics(raw_data: &RawServoStyleSet) -> bool {
|
||||
let doc_data = PerDocumentStyleData::from_ffi(raw_data);
|
||||
doc_data.borrow().stylist.device().used_font_metrics()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn Servo_StyleSheet_HasRules(raw_contents: &RawServoStyleSheetContents) -> bool {
|
||||
let global_style_data = &*GLOBAL_STYLE_DATA;
|
||||
|
@ -3871,8 +3876,6 @@ pub unsafe extern "C" fn Servo_ComputedValues_GetForAnonymousBox(
|
|||
let pseudo = PseudoElement::from_pseudo_type(pseudo).unwrap();
|
||||
debug_assert!(pseudo.is_anon_box());
|
||||
|
||||
let metrics = get_metrics_provider_for_product();
|
||||
|
||||
// If the pseudo element is PageContent, we should append @page rules to the
|
||||
// precomputed pseudo.
|
||||
//
|
||||
|
@ -3906,7 +3909,6 @@ pub unsafe extern "C" fn Servo_ComputedValues_GetForAnonymousBox(
|
|||
&guards,
|
||||
&pseudo,
|
||||
parent_style_or_null.map(|x| &*x),
|
||||
&metrics,
|
||||
rule_node,
|
||||
)
|
||||
.into()
|
||||
|
@ -4078,14 +4080,12 @@ fn get_pseudo_style(
|
|||
// the computed style case is a bit unclear.
|
||||
let inherited_styles = inherited_styles.unwrap_or(styles.primary());
|
||||
let guards = StylesheetGuards::same(guard);
|
||||
let metrics = get_metrics_provider_for_product();
|
||||
let inputs = CascadeInputs::new_from_style(pseudo_styles);
|
||||
stylist.compute_pseudo_element_style_with_inputs(
|
||||
inputs,
|
||||
pseudo,
|
||||
&guards,
|
||||
Some(inherited_styles),
|
||||
&metrics,
|
||||
Some(element),
|
||||
)
|
||||
})
|
||||
|
@ -4128,7 +4128,6 @@ fn get_pseudo_style(
|
|||
styles.primary()
|
||||
};
|
||||
let guards = StylesheetGuards::same(guard);
|
||||
let metrics = get_metrics_provider_for_product();
|
||||
stylist.lazily_compute_pseudo_element_style(
|
||||
&guards,
|
||||
element,
|
||||
|
@ -4136,7 +4135,6 @@ fn get_pseudo_style(
|
|||
rule_inclusion,
|
||||
base,
|
||||
is_probe,
|
||||
&metrics,
|
||||
matching_func,
|
||||
)
|
||||
},
|
||||
|
@ -5856,7 +5854,7 @@ pub extern "C" fn Servo_ResolveStyleLazily(
|
|||
TraversalFlags::empty(),
|
||||
unsafe { &*snapshots },
|
||||
);
|
||||
let mut tlc = ThreadLocalStyleContext::new(&shared);
|
||||
let mut tlc = ThreadLocalStyleContext::new();
|
||||
let mut context = StyleContext {
|
||||
shared: &shared,
|
||||
thread_local: &mut tlc,
|
||||
|
@ -5892,7 +5890,6 @@ pub extern "C" fn Servo_ReparentStyle(
|
|||
let guard = global_style_data.shared_lock.read();
|
||||
let doc_data = PerDocumentStyleData::from_ffi(raw_data).borrow();
|
||||
let inputs = CascadeInputs::new_from_style(style_to_reparent);
|
||||
let metrics = get_metrics_provider_for_product();
|
||||
let pseudo = style_to_reparent.pseudo();
|
||||
let element = element.map(GeckoElement);
|
||||
|
||||
|
@ -5906,7 +5903,6 @@ pub extern "C" fn Servo_ReparentStyle(
|
|||
Some(parent_style),
|
||||
Some(parent_style_ignoring_first_line),
|
||||
Some(layout_parent_style),
|
||||
&metrics,
|
||||
/* rule_cache = */ None,
|
||||
&mut RuleCacheConditions::default(),
|
||||
)
|
||||
|
@ -5927,7 +5923,6 @@ fn simulate_compute_values_failure(_: &PropertyValuePair) -> bool {
|
|||
|
||||
fn create_context_for_animation<'a>(
|
||||
per_doc_data: &'a PerDocumentStyleDataImpl,
|
||||
font_metrics_provider: &'a dyn FontMetricsProvider,
|
||||
style: &'a ComputedValues,
|
||||
parent_style: Option<&'a ComputedValues>,
|
||||
for_smil_animation: bool,
|
||||
|
@ -5935,7 +5930,6 @@ fn create_context_for_animation<'a>(
|
|||
) -> Context<'a> {
|
||||
Context {
|
||||
builder: StyleBuilder::for_animation(per_doc_data.stylist.device(), style, parent_style),
|
||||
font_metrics_provider,
|
||||
cached_system_font: None,
|
||||
in_media_query: false,
|
||||
quirks_mode: per_doc_data.stylist.quirks_mode(),
|
||||
|
@ -6006,7 +6000,6 @@ pub extern "C" fn Servo_GetComputedKeyframeValues(
|
|||
computed_keyframes: &mut nsTArray<structs::ComputedKeyframeValues>,
|
||||
) {
|
||||
let data = PerDocumentStyleData::from_ffi(raw_data).borrow();
|
||||
let metrics = get_metrics_provider_for_product();
|
||||
|
||||
let element = GeckoElement(element);
|
||||
let pseudo = PseudoElement::from_pseudo_type(pseudo_type);
|
||||
|
@ -6024,7 +6017,6 @@ pub extern "C" fn Servo_GetComputedKeyframeValues(
|
|||
let mut conditions = Default::default();
|
||||
let mut context = create_context_for_animation(
|
||||
&data,
|
||||
&metrics,
|
||||
&style,
|
||||
parent_style,
|
||||
/* for_smil_animation = */ false,
|
||||
|
@ -6136,7 +6128,6 @@ pub extern "C" fn Servo_GetAnimationValues(
|
|||
animation_values: &mut nsTArray<structs::RefPtr<structs::RawServoAnimationValue>>,
|
||||
) {
|
||||
let data = PerDocumentStyleData::from_ffi(raw_data).borrow();
|
||||
let metrics = get_metrics_provider_for_product();
|
||||
|
||||
let element = GeckoElement(element);
|
||||
let parent_element = element.inheritance_parent();
|
||||
|
@ -6149,7 +6140,6 @@ pub extern "C" fn Servo_GetAnimationValues(
|
|||
let mut conditions = Default::default();
|
||||
let mut context = create_context_for_animation(
|
||||
&data,
|
||||
&metrics,
|
||||
&style,
|
||||
parent_style,
|
||||
/* for_smil_animation = */ true,
|
||||
|
@ -6189,7 +6179,6 @@ pub extern "C" fn Servo_AnimationValue_Compute(
|
|||
raw_data: &RawServoStyleSet,
|
||||
) -> Strong<RawServoAnimationValue> {
|
||||
let data = PerDocumentStyleData::from_ffi(raw_data).borrow();
|
||||
let metrics = get_metrics_provider_for_product();
|
||||
|
||||
let element = GeckoElement(element);
|
||||
let parent_element = element.inheritance_parent();
|
||||
|
@ -6202,7 +6191,6 @@ pub extern "C" fn Servo_AnimationValue_Compute(
|
|||
let mut conditions = Default::default();
|
||||
let mut context = create_context_for_animation(
|
||||
&data,
|
||||
&metrics,
|
||||
style,
|
||||
parent_style,
|
||||
/* for_smil_animation = */ false,
|
||||
|
@ -7163,12 +7151,9 @@ pub unsafe extern "C" fn Servo_ParseFontShorthandForMatching(
|
|||
},
|
||||
// Map absolute-size keywords to sizes.
|
||||
specified::FontSize::Keyword(info) => {
|
||||
let metrics = get_metrics_provider_for_product();
|
||||
// TODO: Maybe get a meaningful language / quirks-mode from the
|
||||
// caller?
|
||||
let language = atom!("x-western");
|
||||
// TODO: Maybe get a meaningful quirks / base size from the caller?
|
||||
let quirks_mode = QuirksMode::NoQuirks;
|
||||
info.kw.to_length_without_context(quirks_mode, &metrics, &language, family).0.px()
|
||||
info.kw.to_length_without_context(quirks_mode, computed::Length::new(specified::FONT_MEDIUM_PX)).0.px()
|
||||
}
|
||||
// smaller, larger not currently supported
|
||||
specified::FontSize::Smaller | specified::FontSize::Larger | specified::FontSize::System(_) => {
|
||||
|
|
Загрузка…
Ссылка в новой задаче