From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- servo/components/style/values/specified/font.rs | 2100 +++++++++++++++++++++++ 1 file changed, 2100 insertions(+) create mode 100644 servo/components/style/values/specified/font.rs (limited to 'servo/components/style/values/specified/font.rs') diff --git a/servo/components/style/values/specified/font.rs b/servo/components/style/values/specified/font.rs new file mode 100644 index 0000000000..fbb373a1a4 --- /dev/null +++ b/servo/components/style/values/specified/font.rs @@ -0,0 +1,2100 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + +//! Specified values for font properties + +use crate::context::QuirksMode; +use crate::parser::{Parse, ParserContext}; +use crate::values::computed::font::{FamilyName, FontFamilyList, SingleFontFamily}; +use crate::values::computed::Percentage as ComputedPercentage; +use crate::values::computed::{font as computed, Length, NonNegativeLength}; +use crate::values::computed::{CSSPixelLength, Context, ToComputedValue}; +use crate::values::generics::font::VariationValue; +use crate::values::generics::font::{ + self as generics, FeatureTagValue, FontSettings, FontTag, GenericFontSizeAdjust, +}; +use crate::values::generics::NonNegative; +use crate::values::specified::length::{FontBaseSize, PX_PER_PT}; +use crate::values::specified::{AllowQuirks, Angle, Integer, LengthPercentage}; +use crate::values::specified::{NoCalcLength, NonNegativeNumber, NonNegativePercentage, Number}; +use crate::values::{serialize_atom_identifier, CustomIdent, SelectorParseErrorKind}; +use crate::Atom; +use cssparser::{Parser, Token}; +#[cfg(feature = "gecko")] +use malloc_size_of::{MallocSizeOf, MallocSizeOfOps, MallocUnconditionalSizeOf}; +use std::fmt::{self, Write}; +use style_traits::values::SequenceWriter; +use style_traits::{CssWriter, KeywordsCollectFn, ParseError}; +use style_traits::{SpecifiedValueInfo, StyleParseErrorKind, ToCss}; + +// FIXME(emilio): The system font code is copy-pasta, and should be cleaned up. +macro_rules! system_font_methods { + ($ty:ident, $field:ident) => { + system_font_methods!($ty); + + fn compute_system(&self, _context: &Context) -> <$ty as ToComputedValue>::ComputedValue { + debug_assert!(matches!(*self, $ty::System(..))); + #[cfg(feature = "gecko")] + { + _context.cached_system_font.as_ref().unwrap().$field.clone() + } + #[cfg(feature = "servo")] + { + unreachable!() + } + } + }; + + ($ty:ident) => { + /// Get a specified value that represents a system font. + pub fn system_font(f: SystemFont) -> Self { + $ty::System(f) + } + + /// Retreive a SystemFont from the specified value. + pub fn get_system(&self) -> Option { + if let $ty::System(s) = *self { + Some(s) + } else { + None + } + } + }; +} + +/// System fonts. +#[repr(u8)] +#[derive( + Clone, Copy, Debug, Eq, Hash, MallocSizeOf, Parse, PartialEq, SpecifiedValueInfo, ToCss, ToShmem, +)] +#[allow(missing_docs)] +pub enum SystemFont { + /// https://drafts.csswg.org/css-fonts/#valdef-font-caption + Caption, + /// https://drafts.csswg.org/css-fonts/#valdef-font-icon + Icon, + /// https://drafts.csswg.org/css-fonts/#valdef-font-menu + Menu, + /// https://drafts.csswg.org/css-fonts/#valdef-font-message-box + MessageBox, + /// https://drafts.csswg.org/css-fonts/#valdef-font-small-caption + SmallCaption, + /// https://drafts.csswg.org/css-fonts/#valdef-font-status-bar + StatusBar, + /// Internal system font, used by the ``s on macOS. + #[parse(condition = "ParserContext::in_ua_or_chrome_sheet")] + MozPullDownMenu, + /// Internal system font, used for `