mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-26 23:23:33 +00:00
Bug 1630676 - Reformat recent changes, various build fixes, and tidy fixes.
MANUAL PUSH: Review information for upstream patches would get lost otherwise.
This commit is contained in:
parent
0bff3e6dfd
commit
694173c605
@ -2043,7 +2043,10 @@ where
|
||||
// given selector is allowed to match a featureless element,
|
||||
// it must do so while ignoring the default namespace.
|
||||
//
|
||||
if !matches!(result, SimpleSelectorParseResult::SimpleSelector(Component::Host(..))) {
|
||||
if !matches!(
|
||||
result,
|
||||
SimpleSelectorParseResult::SimpleSelector(Component::Host(..))
|
||||
) {
|
||||
builder.push_simple_selector(Component::DefaultNamespace(url));
|
||||
}
|
||||
}
|
||||
|
@ -408,7 +408,9 @@ impl ToCss for System {
|
||||
}
|
||||
|
||||
/// <https://drafts.csswg.org/css-counter-styles/#typedef-symbol>
|
||||
#[derive(Clone, Debug, Eq, MallocSizeOf, PartialEq, ToComputedValue, ToResolvedValue, ToCss, ToShmem)]
|
||||
#[derive(
|
||||
Clone, Debug, Eq, MallocSizeOf, PartialEq, ToComputedValue, ToResolvedValue, ToCss, ToShmem,
|
||||
)]
|
||||
#[repr(u8)]
|
||||
pub enum Symbol {
|
||||
/// <string>
|
||||
@ -554,7 +556,9 @@ impl Parse for Fallback {
|
||||
}
|
||||
|
||||
/// <https://drafts.csswg.org/css-counter-styles/#descdef-counter-style-symbols>
|
||||
#[derive(Clone, Debug, Eq, MallocSizeOf, PartialEq, ToComputedValue, ToResolvedValue, ToCss, ToShmem)]
|
||||
#[derive(
|
||||
Clone, Debug, Eq, MallocSizeOf, PartialEq, ToComputedValue, ToResolvedValue, ToCss, ToShmem,
|
||||
)]
|
||||
#[repr(C)]
|
||||
pub struct Symbols(#[css(iterable)] pub crate::OwnedSlice<Symbol>);
|
||||
|
||||
|
@ -582,7 +582,7 @@ impl<'a> CustomPropertiesBuilder<'a> {
|
||||
// Don't touch the map, this has the same effect as
|
||||
// making it compute to the inherited one.
|
||||
return;
|
||||
}
|
||||
},
|
||||
}
|
||||
} else {
|
||||
(*unparsed_value).clone()
|
||||
@ -848,7 +848,7 @@ fn substitute_all(
|
||||
match result {
|
||||
Ok(computed_value) => {
|
||||
context.map.insert(name, Arc::new(computed_value));
|
||||
}
|
||||
},
|
||||
Err(..) => {
|
||||
// This is invalid, reset it to the unset (inherited) value.
|
||||
let inherited = context.inherited.and_then(|m| m.get(&name)).cloned();
|
||||
@ -860,7 +860,7 @@ fn substitute_all(
|
||||
context.map.remove(&name);
|
||||
},
|
||||
};
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
// All resolved, so return the signal value.
|
||||
|
@ -10,7 +10,7 @@ use crate::context::QuirksMode;
|
||||
use crate::error_reporting::ParseErrorReporter;
|
||||
use crate::media_queries::MediaList;
|
||||
use crate::shared_lock::SharedRwLock;
|
||||
use crate::stylesheets::{Origin, Stylesheet, StylesheetLoader, UrlExtraData};
|
||||
use crate::stylesheets::{AllowImportRules, Origin, Stylesheet, StylesheetLoader, UrlExtraData};
|
||||
use cssparser::{stylesheet_encoding, EncodingSupport};
|
||||
use servo_arc::Arc;
|
||||
use std::borrow::Cow;
|
||||
@ -78,6 +78,7 @@ impl Stylesheet {
|
||||
error_reporter,
|
||||
quirks_mode,
|
||||
0,
|
||||
AllowImportRules::Yes,
|
||||
)
|
||||
}
|
||||
|
||||
@ -100,6 +101,7 @@ impl Stylesheet {
|
||||
stylesheet_loader,
|
||||
error_reporter,
|
||||
0,
|
||||
AllowImportRules::Yes,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
#![allow(unsafe_code)]
|
||||
|
||||
use crate::gecko_bindings::structs::{Matrix4x4Components, nsresult};
|
||||
use crate::gecko_bindings::structs::{nsresult, Matrix4x4Components};
|
||||
use crate::stylesheets::RulesMutateError;
|
||||
use crate::values::computed::transform::Matrix3D;
|
||||
|
||||
|
@ -318,7 +318,9 @@ impl Device {
|
||||
let mut right = 0.0;
|
||||
let mut bottom = 0.0;
|
||||
let mut left = 0.0;
|
||||
unsafe { bindings::Gecko_GetSafeAreaInsets(pc, &mut top, &mut right, &mut bottom, &mut left) };
|
||||
unsafe {
|
||||
bindings::Gecko_GetSafeAreaInsets(pc, &mut top, &mut right, &mut bottom, &mut left)
|
||||
};
|
||||
SideOffsets2D::new(top, right, bottom, left)
|
||||
}
|
||||
}
|
||||
|
@ -173,7 +173,7 @@ impl NonTSPseudoClass {
|
||||
#[inline]
|
||||
fn is_enabled_in_content(&self) -> bool {
|
||||
if matches!(*self, NonTSPseudoClass::FocusVisible) {
|
||||
return static_prefs::pref!("layout.css.focus-visible.enabled")
|
||||
return static_prefs::pref!("layout.css.focus-visible.enabled");
|
||||
}
|
||||
!self.has_any_flag(NonTSPseudoClassFlag::PSEUDO_CLASS_ENABLED_IN_UA_SHEETS_AND_CHROME)
|
||||
}
|
||||
|
@ -93,13 +93,7 @@ pub(super) fn each_exported_part(
|
||||
None => return,
|
||||
};
|
||||
let mut length = 0;
|
||||
let atoms = unsafe {
|
||||
bindings::Gecko_Element_ExportedParts(
|
||||
attr,
|
||||
name.as_ptr(),
|
||||
&mut length,
|
||||
)
|
||||
};
|
||||
let atoms = unsafe { bindings::Gecko_Element_ExportedParts(attr, name.as_ptr(), &mut length) };
|
||||
if atoms.is_null() {
|
||||
return;
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ use crate::values::computed::Length;
|
||||
use crate::values::specified::length::FontBaseSize;
|
||||
use crate::CaseSensitivityExt;
|
||||
use app_units::Au;
|
||||
use atomic_refcell::{AtomicRefCell, AtomicRefMut};
|
||||
use atomic_refcell::{AtomicRef, AtomicRefCell, AtomicRefMut};
|
||||
use selectors::attr::{AttrSelectorOperation, AttrSelectorOperator};
|
||||
use selectors::attr::{CaseSensitivity, NamespaceConstraint};
|
||||
use selectors::matching::VisitedHandlingMode;
|
||||
@ -557,8 +557,9 @@ impl<'le> fmt::Debug for GeckoElement<'le> {
|
||||
}
|
||||
|
||||
impl<'le> GeckoElement<'le> {
|
||||
/// Gets the raw `ElementData` refcell for the element.
|
||||
#[inline(always)]
|
||||
fn get_data(&self) -> Option<&AtomicRefCell<ElementData>> {
|
||||
pub fn get_data(&self) -> Option<&AtomicRefCell<ElementData>> {
|
||||
unsafe { self.0.mServoData.get().as_ref() }
|
||||
}
|
||||
|
||||
@ -1391,21 +1392,6 @@ impl<'le> TElement for GeckoElement<'le> {
|
||||
panic!("Atomic child count not implemented in Gecko");
|
||||
}
|
||||
|
||||
/// Whether there is an ElementData container.
|
||||
fn has_data(&self) -> bool {
|
||||
self.get_data().is_some()
|
||||
}
|
||||
|
||||
/// Immutably borrows the ElementData.
|
||||
fn borrow_data(&self) -> Option<AtomicRef<ElementData>> {
|
||||
self.get_data().map(|x| x.borrow())
|
||||
}
|
||||
|
||||
/// Mutably borrows the ElementData.
|
||||
fn mutate_data(&self) -> Option<AtomicRefMut<ElementData>> {
|
||||
self.get_data().map(|x| x.borrow_mut())
|
||||
}
|
||||
|
||||
unsafe fn ensure_data(&self) -> AtomicRefMut<ElementData> {
|
||||
if !self.has_data() {
|
||||
debug!("Creating ElementData for {:?}", self);
|
||||
@ -1642,6 +1628,22 @@ impl<'le> TElement for GeckoElement<'le> {
|
||||
.any(|property| !transitions_to_keep.contains(*property))
|
||||
}
|
||||
|
||||
/// Whether there is an ElementData container.
|
||||
#[inline]
|
||||
fn has_data(&self) -> bool {
|
||||
self.get_data().is_some()
|
||||
}
|
||||
|
||||
/// Immutably borrows the ElementData.
|
||||
fn borrow_data(&self) -> Option<AtomicRef<ElementData>> {
|
||||
self.get_data().map(|x| x.borrow())
|
||||
}
|
||||
|
||||
/// Mutably borrows the ElementData.
|
||||
fn mutate_data(&self) -> Option<AtomicRefMut<ElementData>> {
|
||||
self.get_data().map(|x| x.borrow_mut())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn lang_attr(&self) -> Option<AttrValue> {
|
||||
let ptr = unsafe { bindings::Gecko_LangValue(self.0) };
|
||||
|
@ -24,7 +24,18 @@ macro_rules! ns {
|
||||
}
|
||||
|
||||
/// A Gecko namespace is just a wrapped atom.
|
||||
#[derive(Clone, Debug, Default, Eq, Hash, MallocSizeOf, PartialEq, ToComputedValue, ToResolvedValue, ToShmem)]
|
||||
#[derive(
|
||||
Clone,
|
||||
Debug,
|
||||
Default,
|
||||
Eq,
|
||||
Hash,
|
||||
MallocSizeOf,
|
||||
PartialEq,
|
||||
ToComputedValue,
|
||||
ToResolvedValue,
|
||||
ToShmem,
|
||||
)]
|
||||
#[repr(transparent)]
|
||||
pub struct Namespace(pub Atom);
|
||||
|
||||
|
@ -901,7 +901,8 @@ impl LonghandIdSet {
|
||||
pub fn border_background_properties() -> &'static Self {
|
||||
${static_longhand_id_set(
|
||||
"BORDER_BACKGROUND_PROPERTIES",
|
||||
lambda p: (p.logical_group and p.logical_group.startswith("border")) or p.name in ["background-color", "background-image"]
|
||||
lambda p: (p.logical_group and p.logical_group.startswith("border")) or \
|
||||
p.name in ["background-color", "background-image"]
|
||||
)}
|
||||
&BORDER_BACKGROUND_PROPERTIES
|
||||
}
|
||||
|
@ -148,7 +148,8 @@ where
|
||||
self.context.current_host = host.map(|e| e.opaque());
|
||||
f(self);
|
||||
if start != self.rules.len() {
|
||||
self.rules[start..].sort_unstable_by_key(|block| (block.specificity, block.source_order()));
|
||||
self.rules[start..]
|
||||
.sort_unstable_by_key(|block| (block.specificity, block.source_order()));
|
||||
}
|
||||
self.context.current_host = old_host;
|
||||
self.in_sort_scope = false;
|
||||
@ -214,11 +215,7 @@ where
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn collect_rules_in_list(
|
||||
&mut self,
|
||||
part_rules: &[Rule],
|
||||
cascade_level: CascadeLevel,
|
||||
) {
|
||||
fn collect_rules_in_list(&mut self, part_rules: &[Rule], cascade_level: CascadeLevel) {
|
||||
debug_assert!(self.in_sort_scope, "Rules gotta be sorted");
|
||||
SelectorMap::get_matching_rules(
|
||||
self.element,
|
||||
@ -231,11 +228,7 @@ where
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn collect_rules_in_map(
|
||||
&mut self,
|
||||
map: &SelectorMap<Rule>,
|
||||
cascade_level: CascadeLevel,
|
||||
) {
|
||||
fn collect_rules_in_map(&mut self, map: &SelectorMap<Rule>, cascade_level: CascadeLevel) {
|
||||
debug_assert!(self.in_sort_scope, "Rules gotta be sorted");
|
||||
map.get_all_matching_rules(
|
||||
self.element,
|
||||
@ -413,10 +406,7 @@ where
|
||||
self.in_tree(containing_host, |collector| {
|
||||
for p in &parts {
|
||||
if let Some(part_rules) = part_rules.get(p) {
|
||||
collector.collect_rules_in_list(
|
||||
part_rules,
|
||||
cascade_level,
|
||||
);
|
||||
collector.collect_rules_in_list(part_rules, cascade_level);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -229,10 +229,10 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> {
|
||||
|
||||
if !display.is_contents() {
|
||||
if !self
|
||||
.style
|
||||
.get_text()
|
||||
.clone_text_decoration_line()
|
||||
.is_empty()
|
||||
.style
|
||||
.get_text()
|
||||
.clone_text_decoration_line()
|
||||
.is_empty()
|
||||
{
|
||||
self.style
|
||||
.add_flags(ComputedValueFlags::HAS_TEXT_DECORATION_LINES);
|
||||
|
@ -58,8 +58,8 @@ pub use self::rule_parser::{InsertRuleContext, State, TopLevelRuleParser};
|
||||
pub use self::rules_iterator::{AllRules, EffectiveRules};
|
||||
pub use self::rules_iterator::{NestedRuleIterationCondition, RulesIterator};
|
||||
pub use self::style_rule::StyleRule;
|
||||
pub use self::stylesheet::{AllowImportRules, SanitizationData, SanitizationKind};
|
||||
pub use self::stylesheet::{DocumentStyleSheet, Namespaces, Stylesheet};
|
||||
pub use self::stylesheet::{SanitizationData, SanitizationKind, AllowImportRules};
|
||||
pub use self::stylesheet::{StylesheetContents, StylesheetInDocument, UserAgentStylesheets};
|
||||
pub use self::supports_rule::SupportsRule;
|
||||
pub use self::viewport_rule::ViewportRule;
|
||||
|
@ -10,7 +10,7 @@ use crate::str::CssStringWriter;
|
||||
use crate::stylesheets::loader::StylesheetLoader;
|
||||
use crate::stylesheets::rule_parser::{InsertRuleContext, State};
|
||||
use crate::stylesheets::stylesheet::StylesheetContents;
|
||||
use crate::stylesheets::{CssRule, RulesMutateError, AllowImportRules};
|
||||
use crate::stylesheets::{AllowImportRules, CssRule, RulesMutateError};
|
||||
#[cfg(feature = "gecko")]
|
||||
use malloc_size_of::{MallocShallowSizeOf, MallocSizeOfOps};
|
||||
use servo_arc::{Arc, RawOffsetArc};
|
||||
|
@ -694,9 +694,7 @@ where
|
||||
if let Some(ref values) = data.styles.primary {
|
||||
for image in &values.get_background().background_image.0 {
|
||||
let (name, arguments) = match *image {
|
||||
Image::PaintWorklet(ref worklet) => {
|
||||
(&worklet.name, &worklet.arguments)
|
||||
},
|
||||
Image::PaintWorklet(ref worklet) => (&worklet.name, &worklet.arguments),
|
||||
_ => continue,
|
||||
};
|
||||
let painter = match context.shared.registered_speculative_painters.get(name) {
|
||||
|
@ -227,7 +227,9 @@ impl ToCss for FontFamily {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, Hash, MallocSizeOf, PartialEq, ToComputedValue, ToResolvedValue, ToShmem)]
|
||||
#[derive(
|
||||
Clone, Debug, Eq, Hash, MallocSizeOf, PartialEq, ToComputedValue, ToResolvedValue, ToShmem,
|
||||
)]
|
||||
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
|
||||
/// The name of a font family of choice
|
||||
pub struct FamilyName {
|
||||
@ -270,7 +272,9 @@ impl ToCss for FamilyName {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, Hash, MallocSizeOf, PartialEq, ToComputedValue, ToResolvedValue, ToShmem)]
|
||||
#[derive(
|
||||
Clone, Copy, Debug, Eq, Hash, MallocSizeOf, PartialEq, ToComputedValue, ToResolvedValue, ToShmem,
|
||||
)]
|
||||
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
|
||||
/// Font family names must either be given quoted as strings,
|
||||
/// or unquoted as a sequence of one or more identifiers.
|
||||
@ -285,7 +289,9 @@ pub enum FontFamilyNameSyntax {
|
||||
Identifiers,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, MallocSizeOf, PartialEq, ToCss, ToComputedValue, ToResolvedValue, ToShmem)]
|
||||
#[derive(
|
||||
Clone, Debug, Eq, MallocSizeOf, PartialEq, ToCss, ToComputedValue, ToResolvedValue, ToShmem,
|
||||
)]
|
||||
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize, Hash))]
|
||||
/// A set of faces that vary in weight, width or slope.
|
||||
pub enum SingleFontFamily {
|
||||
@ -301,7 +307,18 @@ pub enum SingleFontFamily {
|
||||
/// `gfxPlatformFontList.h`s ranged array and `gfxFontFamilyList`'s
|
||||
/// sSingleGenerics are updated as well.
|
||||
#[derive(
|
||||
Clone, Copy, Debug, Eq, Hash, MallocSizeOf, PartialEq, Parse, ToCss, ToComputedValue, ToResolvedValue, ToShmem,
|
||||
Clone,
|
||||
Copy,
|
||||
Debug,
|
||||
Eq,
|
||||
Hash,
|
||||
MallocSizeOf,
|
||||
PartialEq,
|
||||
Parse,
|
||||
ToCss,
|
||||
ToComputedValue,
|
||||
ToResolvedValue,
|
||||
ToShmem,
|
||||
)]
|
||||
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
|
||||
#[repr(u8)]
|
||||
@ -427,7 +444,9 @@ impl SingleFontFamily {
|
||||
}
|
||||
|
||||
#[cfg(feature = "servo")]
|
||||
#[derive(Clone, Debug, Eq, Hash, MallocSizeOf, PartialEq, ToComputedValue, ToResolvedValue, ToShmem)]
|
||||
#[derive(
|
||||
Clone, Debug, Eq, Hash, MallocSizeOf, PartialEq, ToComputedValue, ToResolvedValue, ToShmem,
|
||||
)]
|
||||
/// A list of SingleFontFamily
|
||||
pub struct FontFamilyList(Box<[SingleFontFamily]>);
|
||||
|
||||
@ -684,7 +703,7 @@ pub type FontVariationSettings = FontSettings<VariationValue<Number>>;
|
||||
/// (see http://www.microsoft.com/typography/otspec/languagetags.htm).
|
||||
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, PartialEq, ToResolvedValue)]
|
||||
#[repr(C)]
|
||||
pub struct FontLanguageOverride(u32);
|
||||
pub struct FontLanguageOverride(pub u32);
|
||||
|
||||
impl FontLanguageOverride {
|
||||
#[inline]
|
||||
@ -743,6 +762,15 @@ impl ToCss for FontLanguageOverride {
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME(emilio): Make Gecko use the cbindgen'd fontLanguageOverride, then
|
||||
// remove this.
|
||||
#[cfg(feature = "gecko")]
|
||||
impl From<u32> for FontLanguageOverride {
|
||||
fn from(v: u32) -> Self {
|
||||
unsafe { Self::from_u32(v) }
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "gecko")]
|
||||
impl From<FontLanguageOverride> for u32 {
|
||||
fn from(v: FontLanguageOverride) -> u32 {
|
||||
|
@ -13,7 +13,8 @@ use crate::values::computed::url::ComputedImageUrl;
|
||||
use crate::values::computed::NumberOrPercentage;
|
||||
use crate::values::computed::{Angle, Color, Context};
|
||||
use crate::values::computed::{
|
||||
AngleOrPercentage, LengthPercentage, NonNegativeLength, NonNegativeLengthPercentage, ToComputedValue,
|
||||
AngleOrPercentage, LengthPercentage, NonNegativeLength, NonNegativeLengthPercentage,
|
||||
ToComputedValue,
|
||||
};
|
||||
use crate::values::generics::image::{self as generic, GradientCompatMode};
|
||||
use crate::values::specified::image::LineDirection as SpecifiedLineDirection;
|
||||
|
@ -34,8 +34,8 @@ use crate::Zero;
|
||||
use app_units::Au;
|
||||
use malloc_size_of::{MallocSizeOf, MallocSizeOfOps};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fmt::{self, Write};
|
||||
use std::borrow::Cow;
|
||||
use std::fmt::{self, Write};
|
||||
use style_traits::values::specified::AllowedNumericType;
|
||||
use style_traits::{CssWriter, ToCss};
|
||||
|
||||
@ -202,7 +202,9 @@ impl LengthPercentage {
|
||||
fn to_calc_node(&self) -> Cow<CalcNode> {
|
||||
match self.unpack() {
|
||||
Unpacked::Length(l) => Cow::Owned(CalcNode::Leaf(CalcLengthPercentageLeaf::Length(l))),
|
||||
Unpacked::Percentage(p) => Cow::Owned(CalcNode::Leaf(CalcLengthPercentageLeaf::Percentage(p))),
|
||||
Unpacked::Percentage(p) => {
|
||||
Cow::Owned(CalcNode::Leaf(CalcLengthPercentageLeaf::Percentage(p)))
|
||||
},
|
||||
Unpacked::Calc(p) => Cow::Borrowed(&p.node),
|
||||
}
|
||||
}
|
||||
@ -241,20 +243,20 @@ impl LengthPercentage {
|
||||
let mut node = v.to_calc_node().into_owned();
|
||||
node.negate();
|
||||
|
||||
let new_node = CalcNode::Sum(vec![
|
||||
CalcNode::Leaf(CalcLengthPercentageLeaf::Percentage(Percentage::hundred())),
|
||||
node,
|
||||
].into());
|
||||
let new_node = CalcNode::Sum(
|
||||
vec![
|
||||
CalcNode::Leaf(CalcLengthPercentageLeaf::Percentage(Percentage::hundred())),
|
||||
node,
|
||||
]
|
||||
.into(),
|
||||
);
|
||||
|
||||
Self::new_calc(new_node, clamping_mode)
|
||||
}
|
||||
|
||||
/// Constructs a `calc()` value.
|
||||
#[inline]
|
||||
pub fn new_calc(
|
||||
mut node: CalcNode,
|
||||
clamping_mode: AllowedNumericType,
|
||||
) -> Self {
|
||||
pub fn new_calc(mut node: CalcNode, clamping_mode: AllowedNumericType) -> Self {
|
||||
node.simplify_and_sort();
|
||||
|
||||
match node {
|
||||
@ -267,13 +269,11 @@ impl LengthPercentage {
|
||||
Self::new_percent(Percentage(clamping_mode.clamp(p.0)))
|
||||
},
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
Self::new_calc_unchecked(Box::new(CalcLengthPercentage {
|
||||
clamping_mode,
|
||||
node,
|
||||
}))
|
||||
}
|
||||
},
|
||||
_ => Self::new_calc_unchecked(Box::new(CalcLengthPercentage {
|
||||
clamping_mode,
|
||||
node,
|
||||
})),
|
||||
}
|
||||
}
|
||||
|
||||
@ -456,7 +456,7 @@ impl LengthPercentage {
|
||||
UnpackedMut::Calc(ref mut c) => {
|
||||
c.clamping_mode = AllowedNumericType::NonNegative;
|
||||
self
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -577,7 +577,17 @@ impl<'de> Deserialize<'de> for LengthPercentage {
|
||||
}
|
||||
|
||||
/// The leaves of a `<length-percentage>` calc expression.
|
||||
#[derive(Clone, Debug, Deserialize, MallocSizeOf, PartialEq, Serialize, ToAnimatedZero, ToCss, ToResolvedValue)]
|
||||
#[derive(
|
||||
Clone,
|
||||
Debug,
|
||||
Deserialize,
|
||||
MallocSizeOf,
|
||||
PartialEq,
|
||||
Serialize,
|
||||
ToAnimatedZero,
|
||||
ToCss,
|
||||
ToResolvedValue,
|
||||
)]
|
||||
#[allow(missing_docs)]
|
||||
#[repr(u8)]
|
||||
pub enum CalcLengthPercentageLeaf {
|
||||
@ -609,8 +619,10 @@ impl PartialOrd for CalcLengthPercentageLeaf {
|
||||
match *self {
|
||||
Length(..) | Percentage(..) => {},
|
||||
}
|
||||
unsafe { debug_unreachable!("Forgot a branch?"); }
|
||||
}
|
||||
unsafe {
|
||||
debug_unreachable!("Forgot a branch?");
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -670,7 +682,9 @@ impl calc::CalcNodeLeaf for CalcLengthPercentageLeaf {
|
||||
pub type CalcNode = calc::GenericCalcNode<CalcLengthPercentageLeaf>;
|
||||
|
||||
/// The representation of a calc() function with mixed lengths and percentages.
|
||||
#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize, ToAnimatedZero, ToResolvedValue, ToCss)]
|
||||
#[derive(
|
||||
Clone, Debug, Deserialize, MallocSizeOf, Serialize, ToAnimatedZero, ToResolvedValue, ToCss,
|
||||
)]
|
||||
#[repr(C)]
|
||||
pub struct CalcLengthPercentage {
|
||||
#[animation(constant)]
|
||||
@ -684,12 +698,15 @@ impl CalcLengthPercentage {
|
||||
#[inline]
|
||||
fn resolve(&self, basis: Length) -> Length {
|
||||
// unwrap() is fine because the conversion below is infallible.
|
||||
let px = self.node.resolve(|l| {
|
||||
Ok(match *l {
|
||||
CalcLengthPercentageLeaf::Length(l) => l.px(),
|
||||
CalcLengthPercentageLeaf::Percentage(ref p) => basis.px() * p.0,
|
||||
let px = self
|
||||
.node
|
||||
.resolve(|l| {
|
||||
Ok(match *l {
|
||||
CalcLengthPercentageLeaf::Length(l) => l.px(),
|
||||
CalcLengthPercentageLeaf::Percentage(ref p) => basis.px() * p.0,
|
||||
})
|
||||
})
|
||||
}).unwrap();
|
||||
.unwrap();
|
||||
Length::new(self.clamping_mode.clamp(px))
|
||||
}
|
||||
}
|
||||
@ -726,24 +743,16 @@ impl specified::CalcLengthPercentage {
|
||||
use crate::values::specified::calc::Leaf;
|
||||
use crate::values::specified::length::NoCalcLength;
|
||||
|
||||
let node = self.node.map_leaves(|leaf| {
|
||||
match *leaf {
|
||||
Leaf::Percentage(p) => CalcLengthPercentageLeaf::Percentage(Percentage(p)),
|
||||
Leaf::Length(l) => {
|
||||
CalcLengthPercentageLeaf::Length(match l {
|
||||
NoCalcLength::Absolute(ref abs) => {
|
||||
zoom_fn(abs.to_computed_value(context))
|
||||
},
|
||||
NoCalcLength::FontRelative(ref fr) => {
|
||||
fr.to_computed_value(context, base_size)
|
||||
},
|
||||
other => other.to_computed_value(context),
|
||||
})
|
||||
},
|
||||
Leaf::Number(..) |
|
||||
Leaf::Angle(..) |
|
||||
Leaf::Time(..) => unreachable!("Shouldn't have parsed"),
|
||||
}
|
||||
let node = self.node.map_leaves(|leaf| match *leaf {
|
||||
Leaf::Percentage(p) => CalcLengthPercentageLeaf::Percentage(Percentage(p)),
|
||||
Leaf::Length(l) => CalcLengthPercentageLeaf::Length(match l {
|
||||
NoCalcLength::Absolute(ref abs) => zoom_fn(abs.to_computed_value(context)),
|
||||
NoCalcLength::FontRelative(ref fr) => fr.to_computed_value(context, base_size),
|
||||
other => other.to_computed_value(context),
|
||||
}),
|
||||
Leaf::Number(..) | Leaf::Angle(..) | Leaf::Time(..) => {
|
||||
unreachable!("Shouldn't have parsed")
|
||||
},
|
||||
});
|
||||
|
||||
LengthPercentage::new_calc(node, self.clamping_mode)
|
||||
@ -788,12 +797,12 @@ impl specified::CalcLengthPercentage {
|
||||
|
||||
specified::CalcLengthPercentage {
|
||||
clamping_mode: computed.clamping_mode,
|
||||
node: computed.node.map_leaves(|l| {
|
||||
match l {
|
||||
CalcLengthPercentageLeaf::Length(ref l) => Leaf::Length(NoCalcLength::from_px(l.px())),
|
||||
CalcLengthPercentageLeaf::Percentage(ref p) => Leaf::Percentage(p.0),
|
||||
}
|
||||
})
|
||||
node: computed.node.map_leaves(|l| match l {
|
||||
CalcLengthPercentageLeaf::Length(ref l) => {
|
||||
Leaf::Length(NoCalcLength::from_px(l.px()))
|
||||
},
|
||||
CalcLengthPercentageLeaf::Percentage(ref p) => Leaf::Percentage(p.0),
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -819,7 +828,10 @@ impl Animate for LengthPercentage {
|
||||
one.mul_by(l as f32);
|
||||
other.mul_by(r as f32);
|
||||
|
||||
Self::new_calc(CalcNode::Sum(vec![one, other].into()), AllowedNumericType::All)
|
||||
Self::new_calc(
|
||||
CalcNode::Sum(vec![one, other].into()),
|
||||
AllowedNumericType::All,
|
||||
)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
@ -22,8 +22,6 @@ use crate::properties;
|
||||
use crate::properties::{ComputedValues, LonghandId, StyleBuilder};
|
||||
use crate::rule_cache::RuleCacheConditions;
|
||||
use crate::{ArcSlice, Atom};
|
||||
#[cfg(feature = "servo")]
|
||||
use crate::Prefix;
|
||||
use euclid::default::Size2D;
|
||||
use servo_arc::Arc;
|
||||
use std::cell::RefCell;
|
||||
@ -501,7 +499,9 @@ trivial_to_computed_value!(u32);
|
||||
trivial_to_computed_value!(usize);
|
||||
trivial_to_computed_value!(Atom);
|
||||
#[cfg(feature = "servo")]
|
||||
trivial_to_computed_value!(Prefix);
|
||||
trivial_to_computed_value!(html5ever::Namespace);
|
||||
#[cfg(feature = "servo")]
|
||||
trivial_to_computed_value!(html5ever::Prefix);
|
||||
trivial_to_computed_value!(String);
|
||||
trivial_to_computed_value!(Box<str>);
|
||||
trivial_to_computed_value!(crate::OwnedStr);
|
||||
|
@ -61,7 +61,7 @@ impl GenericPositionComponent for LengthPercentage {
|
||||
fn is_center(&self) -> bool {
|
||||
match self.to_percentage() {
|
||||
Some(Percentage(per)) => per == 0.5,
|
||||
_ => false
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -114,7 +114,10 @@ pub enum GenericClipPath<BasicShape, U> {
|
||||
Url(U),
|
||||
#[css(function)]
|
||||
Path(Path),
|
||||
Shape(Box<BasicShape>, #[css(skip_if = "is_default")] ShapeGeometryBox),
|
||||
Shape(
|
||||
Box<BasicShape>,
|
||||
#[css(skip_if = "is_default")] ShapeGeometryBox,
|
||||
),
|
||||
#[animation(error)]
|
||||
Box(ShapeGeometryBox),
|
||||
}
|
||||
|
@ -7,14 +7,25 @@
|
||||
//! [calc]: https://drafts.csswg.org/css-values/#calc-notation
|
||||
|
||||
use crate::Zero;
|
||||
use style_traits::{CssWriter, ToCss};
|
||||
use std::fmt::{self, Write};
|
||||
use std::{cmp, mem};
|
||||
use std::ops::Add;
|
||||
use smallvec::SmallVec;
|
||||
use std::fmt::{self, Write};
|
||||
use std::ops::Add;
|
||||
use std::{cmp, mem};
|
||||
use style_traits::{CssWriter, ToCss};
|
||||
|
||||
/// Whether we're a `min` or `max` function.
|
||||
#[derive(Clone, Copy, Debug, Deserialize, MallocSizeOf, PartialEq, Serialize, ToAnimatedZero, ToResolvedValue, ToShmem)]
|
||||
#[derive(
|
||||
Clone,
|
||||
Copy,
|
||||
Debug,
|
||||
Deserialize,
|
||||
MallocSizeOf,
|
||||
PartialEq,
|
||||
Serialize,
|
||||
ToAnimatedZero,
|
||||
ToResolvedValue,
|
||||
ToShmem,
|
||||
)]
|
||||
#[repr(u8)]
|
||||
pub enum MinMaxOp {
|
||||
/// `min()`
|
||||
@ -50,7 +61,17 @@ pub enum SortKey {
|
||||
/// FIXME: This would be much more elegant if we used `Self` in the types below,
|
||||
/// but we can't because of https://github.com/serde-rs/serde/issues/1565.
|
||||
#[repr(u8)]
|
||||
#[derive(Clone, Debug, Deserialize, MallocSizeOf, PartialEq, Serialize, ToAnimatedZero, ToResolvedValue, ToShmem)]
|
||||
#[derive(
|
||||
Clone,
|
||||
Debug,
|
||||
Deserialize,
|
||||
MallocSizeOf,
|
||||
PartialEq,
|
||||
Serialize,
|
||||
ToAnimatedZero,
|
||||
ToResolvedValue,
|
||||
ToShmem,
|
||||
)]
|
||||
pub enum GenericCalcNode<L> {
|
||||
/// A leaf node.
|
||||
Leaf(L),
|
||||
@ -73,7 +94,7 @@ pub enum GenericCalcNode<L> {
|
||||
pub use self::GenericCalcNode as CalcNode;
|
||||
|
||||
/// A trait that represents all the stuff a valid leaf of a calc expression.
|
||||
pub trait CalcNodeLeaf : Clone + Sized + PartialOrd + PartialEq + ToCss {
|
||||
pub trait CalcNodeLeaf: Clone + Sized + PartialOrd + PartialEq + ToCss {
|
||||
/// Whether this value is known-negative.
|
||||
fn is_negative(&self) -> bool;
|
||||
|
||||
@ -111,7 +132,9 @@ impl<L: CalcNodeLeaf> CalcNode<L> {
|
||||
/// Tries to merge one sum to another, that is, perform `x` + `y`.
|
||||
fn try_sum_in_place(&mut self, other: &Self) -> Result<(), ()> {
|
||||
match (self, other) {
|
||||
(&mut CalcNode::Leaf(ref mut one), &CalcNode::Leaf(ref other)) => one.try_sum_in_place(other),
|
||||
(&mut CalcNode::Leaf(ref mut one), &CalcNode::Leaf(ref other)) => {
|
||||
one.try_sum_in_place(other)
|
||||
},
|
||||
_ => Err(()),
|
||||
}
|
||||
}
|
||||
@ -139,25 +162,35 @@ impl<L: CalcNodeLeaf> CalcNode<L> {
|
||||
O: CalcNodeLeaf,
|
||||
F: FnMut(&L) -> O,
|
||||
{
|
||||
children.iter().map(|c| c.map_leaves_internal(map)).collect()
|
||||
children
|
||||
.iter()
|
||||
.map(|c| c.map_leaves_internal(map))
|
||||
.collect()
|
||||
}
|
||||
|
||||
match *self {
|
||||
Self::Leaf(ref l) => CalcNode::Leaf(map(l)),
|
||||
Self::Sum(ref c) => CalcNode::Sum(map_children(c, map)),
|
||||
Self::MinMax(ref c, op) => CalcNode::MinMax(map_children(c, map), op),
|
||||
Self::Clamp { ref min, ref center, ref max } => {
|
||||
Self::Clamp {
|
||||
ref min,
|
||||
ref center,
|
||||
ref max,
|
||||
} => {
|
||||
let min = Box::new(min.map_leaves_internal(map));
|
||||
let center = Box::new(center.map_leaves_internal(map));
|
||||
let max = Box::new(max.map_leaves_internal(map));
|
||||
CalcNode::Clamp { min, center, max }
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/// Resolves the expression returning a value of `O`, given a function to
|
||||
/// turn a leaf into the relevant value.
|
||||
pub fn resolve<O>(&self, mut leaf_to_output_fn: impl FnMut(&L) -> Result<O, ()>) -> Result<O, ()>
|
||||
pub fn resolve<O>(
|
||||
&self,
|
||||
mut leaf_to_output_fn: impl FnMut(&L) -> Result<O, ()>,
|
||||
) -> Result<O, ()>
|
||||
where
|
||||
O: PartialOrd + PartialEq + Add<Output = O> + Zero,
|
||||
{
|
||||
@ -192,7 +225,11 @@ impl<L: CalcNodeLeaf> CalcNode<L> {
|
||||
}
|
||||
result
|
||||
},
|
||||
Self::Clamp { ref min, ref center, ref max } => {
|
||||
Self::Clamp {
|
||||
ref min,
|
||||
ref center,
|
||||
ref max,
|
||||
} => {
|
||||
let min = min.resolve_internal(leaf_to_output_fn)?;
|
||||
let center = center.resolve_internal(leaf_to_output_fn)?;
|
||||
let max = max.resolve_internal(leaf_to_output_fn)?;
|
||||
@ -432,7 +469,7 @@ impl<L: CalcNodeLeaf> CalcNode<L> {
|
||||
},
|
||||
Self::Leaf(ref mut l) => {
|
||||
l.simplify();
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -341,8 +341,16 @@ where
|
||||
W: Write,
|
||||
{
|
||||
let (compat_mode, repeating) = match *self {
|
||||
Gradient::Linear { compat_mode, repeating, .. } => (compat_mode, repeating),
|
||||
Gradient::Radial { compat_mode, repeating, .. } => (compat_mode, repeating),
|
||||
Gradient::Linear {
|
||||
compat_mode,
|
||||
repeating,
|
||||
..
|
||||
} => (compat_mode, repeating),
|
||||
Gradient::Radial {
|
||||
compat_mode,
|
||||
repeating,
|
||||
..
|
||||
} => (compat_mode, repeating),
|
||||
Gradient::Conic { repeating, .. } => (GradientCompatMode::Modern, repeating),
|
||||
};
|
||||
|
||||
@ -357,7 +365,12 @@ where
|
||||
}
|
||||
|
||||
match *self {
|
||||
Gradient::Linear { ref direction, ref items, compat_mode, .. } => {
|
||||
Gradient::Linear {
|
||||
ref direction,
|
||||
ref items,
|
||||
compat_mode,
|
||||
..
|
||||
} => {
|
||||
dest.write_str("linear-gradient(")?;
|
||||
let mut skip_comma = if !direction.points_downwards(compat_mode) {
|
||||
direction.to_css(dest, compat_mode)?;
|
||||
@ -373,7 +386,13 @@ where
|
||||
item.to_css(dest)?;
|
||||
}
|
||||
},
|
||||
Gradient::Radial { ref shape, ref position, ref items, compat_mode, .. } => {
|
||||
Gradient::Radial {
|
||||
ref shape,
|
||||
ref position,
|
||||
ref items,
|
||||
compat_mode,
|
||||
..
|
||||
} => {
|
||||
dest.write_str("radial-gradient(")?;
|
||||
let omit_shape = match *shape {
|
||||
EndingShape::Ellipse(Ellipse::Extent(ShapeExtent::Cover)) |
|
||||
@ -412,7 +431,12 @@ where
|
||||
item.to_css(dest)?;
|
||||
}
|
||||
},
|
||||
Gradient::Conic { ref angle, ref position, ref items, .. } => {
|
||||
Gradient::Conic {
|
||||
ref angle,
|
||||
ref position,
|
||||
ref items,
|
||||
..
|
||||
} => {
|
||||
dest.write_str("conic-gradient(")?;
|
||||
let omit_angle = angle.is_zero();
|
||||
let omit_position = position.is_center();
|
||||
|
@ -79,6 +79,8 @@ trivial_to_resolved_value!(computed::url::ComputedUrl);
|
||||
#[cfg(feature = "gecko")]
|
||||
trivial_to_resolved_value!(computed::url::ComputedImageUrl);
|
||||
#[cfg(feature = "servo")]
|
||||
trivial_to_resolved_value!(html5ever::Namespace);
|
||||
#[cfg(feature = "servo")]
|
||||
trivial_to_resolved_value!(html5ever::Prefix);
|
||||
trivial_to_resolved_value!(computed::LengthPercentage);
|
||||
trivial_to_resolved_value!(style_traits::values::specified::AllowedNumericType);
|
||||
|
@ -126,12 +126,7 @@ impl Parse for ClipPath {
|
||||
return Ok(ClipPath::Url(url));
|
||||
}
|
||||
|
||||
parse_shape_or_box(
|
||||
context,
|
||||
input,
|
||||
ClipPath::Shape,
|
||||
ClipPath::Box,
|
||||
)
|
||||
parse_shape_or_box(context, input, ClipPath::Shape, ClipPath::Box)
|
||||
}
|
||||
}
|
||||
|
||||
@ -152,12 +147,7 @@ impl Parse for ShapeOutside {
|
||||
return Ok(ShapeOutside::Image(image));
|
||||
}
|
||||
|
||||
parse_shape_or_box(
|
||||
context,
|
||||
input,
|
||||
ShapeOutside::Shape,
|
||||
ShapeOutside::Box,
|
||||
)
|
||||
parse_shape_or_box(context, input, ShapeOutside::Shape, ShapeOutside::Box)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,8 +15,8 @@ use crate::values::specified::{self, Angle, Time};
|
||||
use crate::values::{CSSFloat, CSSInteger};
|
||||
use cssparser::{AngleOrNumber, CowRcStr, NumberOrPercentage, Parser, Token};
|
||||
use smallvec::SmallVec;
|
||||
use std::fmt::{self, Write};
|
||||
use std::cmp;
|
||||
use std::fmt::{self, Write};
|
||||
use style_traits::values::specified::AllowedNumericType;
|
||||
use style_traits::{CssWriter, ParseError, SpecifiedValueInfo, StyleParseErrorKind, ToCss};
|
||||
|
||||
@ -116,8 +116,10 @@ impl PartialOrd for Leaf {
|
||||
match *self {
|
||||
Length(..) | Percentage(..) | Angle(..) | Time(..) | Number(..) => {},
|
||||
}
|
||||
unsafe { debug_unreachable!("Forgot a branch?"); }
|
||||
}
|
||||
unsafe {
|
||||
debug_unreachable!("Forgot a branch?");
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -126,8 +128,7 @@ impl generic::CalcNodeLeaf for Leaf {
|
||||
fn is_negative(&self) -> bool {
|
||||
match *self {
|
||||
Self::Length(ref l) => l.is_negative(),
|
||||
Self::Percentage(n) |
|
||||
Self::Number(n) => n < 0.,
|
||||
Self::Percentage(n) | Self::Number(n) => n < 0.,
|
||||
Self::Angle(ref a) => a.degrees() < 0.,
|
||||
Self::Time(ref t) => t.seconds() < 0.,
|
||||
}
|
||||
@ -215,8 +216,10 @@ impl generic::CalcNodeLeaf for Leaf {
|
||||
match *other {
|
||||
Number(..) | Percentage(..) | Angle(..) | Time(..) | Length(..) => {},
|
||||
}
|
||||
unsafe { debug_unreachable!(); }
|
||||
}
|
||||
unsafe {
|
||||
debug_unreachable!();
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@ -252,11 +255,9 @@ impl CalcNode {
|
||||
value, ref unit, ..
|
||||
},
|
||||
CalcUnit::LengthPercentage,
|
||||
) => {
|
||||
match NoCalcLength::parse_dimension(context, value, unit) {
|
||||
Ok(l) => Ok(CalcNode::Leaf(Leaf::Length(l))),
|
||||
Err(()) => Err(location.new_custom_error(StyleParseErrorKind::UnspecifiedError)),
|
||||
}
|
||||
) => match NoCalcLength::parse_dimension(context, value, unit) {
|
||||
Ok(l) => Ok(CalcNode::Leaf(Leaf::Length(l))),
|
||||
Err(()) => Err(location.new_custom_error(StyleParseErrorKind::UnspecifiedError)),
|
||||
},
|
||||
(
|
||||
&Token::Dimension {
|
||||
@ -266,7 +267,9 @@ impl CalcNode {
|
||||
) => {
|
||||
match Angle::parse_dimension(value, unit, /* from_calc = */ true) {
|
||||
Ok(a) => Ok(CalcNode::Leaf(Leaf::Angle(a))),
|
||||
Err(()) => Err(location.new_custom_error(StyleParseErrorKind::UnspecifiedError)),
|
||||
Err(()) => {
|
||||
Err(location.new_custom_error(StyleParseErrorKind::UnspecifiedError))
|
||||
},
|
||||
}
|
||||
},
|
||||
(
|
||||
@ -277,7 +280,9 @@ impl CalcNode {
|
||||
) => {
|
||||
match Time::parse_dimension(value, unit, /* from_calc = */ true) {
|
||||
Ok(t) => Ok(CalcNode::Leaf(Leaf::Time(t))),
|
||||
Err(()) => Err(location.new_custom_error(StyleParseErrorKind::UnspecifiedError)),
|
||||
Err(()) => {
|
||||
Err(location.new_custom_error(StyleParseErrorKind::UnspecifiedError))
|
||||
},
|
||||
}
|
||||
},
|
||||
(&Token::Percentage { unit_value, .. }, CalcUnit::LengthPercentage) |
|
||||
@ -328,10 +333,9 @@ impl CalcNode {
|
||||
//
|
||||
// Consider adding an API to cssparser to specify the
|
||||
// initial vector capacity?
|
||||
let arguments = input
|
||||
.parse_comma_separated(|input| {
|
||||
Self::parse_argument(context, input, expected_unit)
|
||||
})?;
|
||||
let arguments = input.parse_comma_separated(|input| {
|
||||
Self::parse_argument(context, input, expected_unit)
|
||||
})?;
|
||||
|
||||
let op = match function {
|
||||
MathFunction::Min => MinMaxOp::Min,
|
||||
@ -474,43 +478,35 @@ impl CalcNode {
|
||||
|
||||
/// Tries to simplify this expression into a `<time>` value.
|
||||
fn to_time(&self) -> Result<Time, ()> {
|
||||
let seconds = self.resolve(|leaf| {
|
||||
match *leaf {
|
||||
Leaf::Time(ref t) => Ok(t.seconds()),
|
||||
_ => Err(()),
|
||||
}
|
||||
let seconds = self.resolve(|leaf| match *leaf {
|
||||
Leaf::Time(ref t) => Ok(t.seconds()),
|
||||
_ => Err(()),
|
||||
})?;
|
||||
Ok(Time::from_calc(seconds))
|
||||
}
|
||||
|
||||
/// Tries to simplify this expression into an `Angle` value.
|
||||
fn to_angle(&self) -> Result<Angle, ()> {
|
||||
let degrees = self.resolve(|leaf| {
|
||||
match *leaf {
|
||||
Leaf::Angle(ref angle) => Ok(angle.degrees()),
|
||||
_ => Err(()),
|
||||
}
|
||||
let degrees = self.resolve(|leaf| match *leaf {
|
||||
Leaf::Angle(ref angle) => Ok(angle.degrees()),
|
||||
_ => Err(()),
|
||||
})?;
|
||||
Ok(Angle::from_calc(degrees))
|
||||
}
|
||||
|
||||
/// Tries to simplify this expression into a `<number>` value.
|
||||
fn to_number(&self) -> Result<CSSFloat, ()> {
|
||||
self.resolve(|leaf| {
|
||||
match *leaf {
|
||||
Leaf::Number(n) => Ok(n),
|
||||
_ => Err(()),
|
||||
}
|
||||
self.resolve(|leaf| match *leaf {
|
||||
Leaf::Number(n) => Ok(n),
|
||||
_ => Err(()),
|
||||
})
|
||||
}
|
||||
|
||||
/// Tries to simplify this expression into a `<percentage>` value.
|
||||
fn to_percentage(&self) -> Result<CSSFloat, ()> {
|
||||
self.resolve(|leaf| {
|
||||
match *leaf {
|
||||
Leaf::Percentage(p) => Ok(p),
|
||||
_ => Err(()),
|
||||
}
|
||||
self.resolve(|leaf| match *leaf {
|
||||
Leaf::Percentage(p) => Ok(p),
|
||||
_ => Err(()),
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,8 @@ use crate::values::specified::position::{HorizontalPositionKeyword, VerticalPosi
|
||||
use crate::values::specified::position::{Position, PositionComponent, Side};
|
||||
use crate::values::specified::url::SpecifiedImageUrl;
|
||||
use crate::values::specified::{
|
||||
Angle, AngleOrPercentage, Color, Length, LengthPercentage, NonNegativeLength, NonNegativeLengthPercentage,
|
||||
Angle, AngleOrPercentage, Color, Length, LengthPercentage, NonNegativeLength,
|
||||
NonNegativeLengthPercentage,
|
||||
};
|
||||
use crate::values::specified::{Number, NumberOrPercentage, Percentage};
|
||||
use crate::Atom;
|
||||
@ -51,6 +52,16 @@ pub type Gradient = generic::Gradient<
|
||||
|
||||
type LengthPercentageItemList = crate::OwnedSlice<generic::GradientItem<Color, LengthPercentage>>;
|
||||
|
||||
#[cfg(feature = "gecko")]
|
||||
fn conic_gradients_enabled() -> bool {
|
||||
static_prefs::pref!("layout.css.conic-gradient.enabled")
|
||||
}
|
||||
|
||||
#[cfg(feature = "servo")]
|
||||
fn conic_gradients_enabled() -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
impl SpecifiedValueInfo for Gradient {
|
||||
const SUPPORTED_TYPES: u8 = CssType::GRADIENT;
|
||||
|
||||
@ -72,11 +83,8 @@ impl SpecifiedValueInfo for Gradient {
|
||||
"-webkit-gradient",
|
||||
]);
|
||||
|
||||
if static_prefs::pref!("layout.css.conic-gradient.enabled") {
|
||||
f(&[
|
||||
"conic-gradient",
|
||||
"repeating-conic-gradient",
|
||||
]);
|
||||
if conic_gradients_enabled() {
|
||||
f(&["conic-gradient", "repeating-conic-gradient"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -242,10 +250,10 @@ impl Parse for Gradient {
|
||||
"-moz-repeating-radial-gradient" => {
|
||||
(Shape::Radial, true, GradientCompatMode::Moz)
|
||||
},
|
||||
"conic-gradient" if static_prefs::pref!("layout.css.conic-gradient.enabled") => {
|
||||
"conic-gradient" if conic_gradients_enabled() => {
|
||||
(Shape::Conic, false, GradientCompatMode::Modern)
|
||||
},
|
||||
"repeating-conic-gradient" if static_prefs::pref!("layout.css.conic-gradient.enabled") => {
|
||||
"repeating-conic-gradient" if conic_gradients_enabled() => {
|
||||
(Shape::Conic, true, GradientCompatMode::Modern)
|
||||
},
|
||||
"-webkit-gradient" => {
|
||||
@ -527,7 +535,8 @@ impl Gradient {
|
||||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<LengthPercentageItemList, ParseError<'i>> {
|
||||
let items = generic::GradientItem::parse_comma_separated(context, input, LengthPercentage::parse)?;
|
||||
let items =
|
||||
generic::GradientItem::parse_comma_separated(context, input, LengthPercentage::parse)?;
|
||||
if items.len() < 2 {
|
||||
return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError));
|
||||
}
|
||||
@ -633,7 +642,11 @@ impl Gradient {
|
||||
|
||||
let angle = angle.unwrap_or(Angle::zero());
|
||||
let position = position.unwrap_or(Position::center());
|
||||
let items = generic::GradientItem::parse_comma_separated(context, input, AngleOrPercentage::parse_with_unitless)?;
|
||||
let items = generic::GradientItem::parse_comma_separated(
|
||||
context,
|
||||
input,
|
||||
AngleOrPercentage::parse_with_unitless,
|
||||
)?;
|
||||
|
||||
if items.len() < 2 {
|
||||
return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError));
|
||||
@ -853,7 +866,8 @@ impl<T> generic::GradientItem<Color, T> {
|
||||
fn parse_comma_separated<'i, 't>(
|
||||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
parse_position: impl for<'i1, 't1> Fn(&ParserContext, &mut Parser<'i1, 't1>) -> Result<T, ParseError<'i1>> + Copy,
|
||||
parse_position: impl for<'i1, 't1> Fn(&ParserContext, &mut Parser<'i1, 't1>) -> Result<T, ParseError<'i1>>
|
||||
+ Copy,
|
||||
) -> Result<crate::OwnedSlice<Self>, ParseError<'i>> {
|
||||
let mut items = Vec::new();
|
||||
let mut seen_stop = false;
|
||||
@ -906,7 +920,10 @@ impl<T> generic::ColorStop<Color, T> {
|
||||
fn parse<'i, 't>(
|
||||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
parse_position: impl for<'i1, 't1> Fn(&ParserContext, &mut Parser<'i1, 't1>) -> Result<T, ParseError<'i1>>,
|
||||
parse_position: impl for<'i1, 't1> Fn(
|
||||
&ParserContext,
|
||||
&mut Parser<'i1, 't1>,
|
||||
) -> Result<T, ParseError<'i1>>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
Ok(generic::ColorStop {
|
||||
color: Color::parse(context, input)?,
|
||||
|
@ -28,8 +28,8 @@ use std::ops::{Add, Mul};
|
||||
use style_traits::values::specified::AllowedNumericType;
|
||||
use style_traits::{ParseError, SpecifiedValueInfo, StyleParseErrorKind};
|
||||
|
||||
pub use super::image::{EndingShape as GradientEndingShape, Gradient};
|
||||
pub use super::image::Image;
|
||||
pub use super::image::{EndingShape as GradientEndingShape, Gradient};
|
||||
pub use crate::values::specified::calc::CalcLengthPercentage;
|
||||
|
||||
/// Number of app units per pixel
|
||||
|
@ -80,12 +80,12 @@ pub use self::svg::MozContextProperties;
|
||||
pub use self::svg::{SVGLength, SVGOpacity, SVGPaint};
|
||||
pub use self::svg::{SVGPaintOrder, SVGStrokeDashArray, SVGWidth};
|
||||
pub use self::svg_path::SVGPathData;
|
||||
pub use self::text::TextAlignLast;
|
||||
pub use self::text::TextUnderlinePosition;
|
||||
pub use self::text::{InitialLetter, LetterSpacing, LineBreak, LineHeight, TextAlign};
|
||||
pub use self::text::{OverflowWrap, TextEmphasisPosition, TextEmphasisStyle, WordBreak};
|
||||
pub use self::text::{TextAlignKeyword, TextDecorationLine, TextOverflow, WordSpacing};
|
||||
pub use self::text::{TextDecorationLength, TextDecorationSkipInk, TextTransform};
|
||||
pub use self::text::TextAlignLast;
|
||||
pub use self::time::Time;
|
||||
pub use self::transform::{Rotate, Scale, Transform};
|
||||
pub use self::transform::{TransformOrigin, TransformStyle, Translate};
|
||||
|
@ -35,8 +35,7 @@ use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss};
|
||||
pub struct SVGPathData(
|
||||
// TODO(emilio): Should probably measure this somehow only from the
|
||||
// specified values.
|
||||
#[ignore_malloc_size_of = "Arc"]
|
||||
pub crate::ArcSlice<PathCommand>,
|
||||
#[ignore_malloc_size_of = "Arc"] pub crate::ArcSlice<PathCommand>,
|
||||
);
|
||||
|
||||
impl SVGPathData {
|
||||
@ -541,7 +540,17 @@ impl CoordPair {
|
||||
|
||||
/// The EllipticalArc flag type.
|
||||
#[derive(
|
||||
Clone, Copy, Debug, Deserialize, MallocSizeOf, PartialEq, Serialize, SpecifiedValueInfo, ToComputedValue, ToResolvedValue, ToShmem,
|
||||
Clone,
|
||||
Copy,
|
||||
Debug,
|
||||
Deserialize,
|
||||
MallocSizeOf,
|
||||
PartialEq,
|
||||
Serialize,
|
||||
SpecifiedValueInfo,
|
||||
ToComputedValue,
|
||||
ToResolvedValue,
|
||||
ToShmem,
|
||||
)]
|
||||
#[repr(C)]
|
||||
pub struct ArcFlag(bool);
|
||||
|
@ -122,7 +122,18 @@ impl ToComputedValue for LineHeight {
|
||||
}
|
||||
|
||||
/// A generic value for the `text-overflow` property.
|
||||
#[derive(Clone, Debug, Eq, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToComputedValue, ToCss, ToResolvedValue, ToShmem)]
|
||||
#[derive(
|
||||
Clone,
|
||||
Debug,
|
||||
Eq,
|
||||
MallocSizeOf,
|
||||
PartialEq,
|
||||
SpecifiedValueInfo,
|
||||
ToComputedValue,
|
||||
ToCss,
|
||||
ToResolvedValue,
|
||||
ToShmem,
|
||||
)]
|
||||
#[repr(C, u8)]
|
||||
pub enum TextOverflowSide {
|
||||
/// Clip inline content.
|
||||
@ -687,7 +698,19 @@ pub enum TextEmphasisStyle {
|
||||
}
|
||||
|
||||
/// Fill mode for the text-emphasis-style property
|
||||
#[derive(Clone, Copy, Debug, MallocSizeOf, Parse, PartialEq, SpecifiedValueInfo, ToCss, ToComputedValue, ToResolvedValue, ToShmem)]
|
||||
#[derive(
|
||||
Clone,
|
||||
Copy,
|
||||
Debug,
|
||||
MallocSizeOf,
|
||||
Parse,
|
||||
PartialEq,
|
||||
SpecifiedValueInfo,
|
||||
ToCss,
|
||||
ToComputedValue,
|
||||
ToResolvedValue,
|
||||
ToShmem,
|
||||
)]
|
||||
#[repr(u8)]
|
||||
pub enum TextEmphasisFillMode {
|
||||
/// `filled`
|
||||
|
@ -58,7 +58,12 @@ impl Parse for CursorImage {
|
||||
hotspot_y = Number::parse(context, input)?;
|
||||
}
|
||||
|
||||
Ok(Self { url, has_hotspot, hotspot_x, hotspot_y })
|
||||
Ok(Self {
|
||||
url,
|
||||
has_hotspot,
|
||||
hotspot_x,
|
||||
hotspot_y,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -102,7 +102,10 @@ pub fn derive_to_value(
|
||||
} else {
|
||||
let to_body = cg::fmap_match(&input, bind_style, |binding| {
|
||||
let attrs = binding_attrs(&binding);
|
||||
assert!(!attrs.no_field_bound, "It doesn't make sense on a generic implementation");
|
||||
assert!(
|
||||
!attrs.no_field_bound,
|
||||
"It doesn't make sense on a generic implementation"
|
||||
);
|
||||
if attrs.field_bound {
|
||||
add_field_bound(&binding);
|
||||
}
|
||||
@ -111,8 +114,16 @@ pub fn derive_to_value(
|
||||
|
||||
let from_body = cg::fmap_match(&input, bind_style, |binding| call_from(&binding));
|
||||
|
||||
let self_ = if moves { quote! { self } } else { quote! { *self } };
|
||||
let from_ = if moves { quote! { from } } else { quote! { *from } };
|
||||
let self_ = if moves {
|
||||
quote! { self }
|
||||
} else {
|
||||
quote! { *self }
|
||||
};
|
||||
let from_ = if moves {
|
||||
quote! { from }
|
||||
} else {
|
||||
quote! { *from }
|
||||
};
|
||||
|
||||
let to_body = quote! {
|
||||
match #self_ {
|
||||
|
@ -300,7 +300,7 @@ pub extern "C" fn Servo_TraverseSubtree(
|
||||
let global_style_data = &*GLOBAL_STYLE_DATA;
|
||||
let guard = global_style_data.shared_lock.read();
|
||||
|
||||
let was_initial_style = element.get_data().is_none();
|
||||
let was_initial_style = element.has_data();
|
||||
|
||||
if needs_animation_only_restyle {
|
||||
debug!(
|
||||
@ -3718,7 +3718,7 @@ pub extern "C" fn Servo_SetExplicitStyle(element: &RawGeckoElement, style: &Comp
|
||||
debug!("Servo_SetExplicitStyle: {:?}", element);
|
||||
// We only support this API for initial styling. There's no reason it couldn't
|
||||
// work for other things, we just haven't had a reason to do so.
|
||||
debug_assert!(element.get_data().is_none());
|
||||
debug_assert!(!element.has_data());
|
||||
let mut data = unsafe { element.ensure_data() };
|
||||
data.styles.primary = Some(unsafe { ArcBorrow::from_ref(style) }.clone_arc());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user