mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-23 12:51:06 +00:00
Bug 1844295
- Don't duplicate ParsingMode in rust and C++. r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D184409
This commit is contained in:
parent
8d7377e94d
commit
98ad5a0692
@ -652,7 +652,8 @@ static Maybe<PropertyValuePair> MakePropertyValuePair(
|
||||
ServoCSSParser::ParsingEnvironment env =
|
||||
ServoCSSParser::GetParsingEnvironment(aDocument);
|
||||
RefPtr<StyleLockedDeclarationBlock> servoDeclarationBlock =
|
||||
ServoCSSParser::ParseProperty(aProperty, aStringValue, env);
|
||||
ServoCSSParser::ParseProperty(aProperty, aStringValue, env,
|
||||
StyleParsingMode::DEFAULT);
|
||||
|
||||
if (servoDeclarationBlock) {
|
||||
result.emplace(aProperty, std::move(servoDeclarationBlock));
|
||||
|
@ -2472,7 +2472,8 @@ static already_AddRefed<StyleLockedDeclarationBlock> CreateDeclarationForServo(
|
||||
aDocument->GetCompatibilityMode(),
|
||||
aDocument->CSSLoader()};
|
||||
RefPtr<StyleLockedDeclarationBlock> servoDeclarations =
|
||||
ServoCSSParser::ParseProperty(aProperty, aPropertyValue, env);
|
||||
ServoCSSParser::ParseProperty(aProperty, aPropertyValue, env,
|
||||
StyleParsingMode::DEFAULT);
|
||||
|
||||
if (!servoDeclarations) {
|
||||
// We got a syntax error. The spec says this value must be ignored.
|
||||
@ -2485,8 +2486,8 @@ static already_AddRefed<StyleLockedDeclarationBlock> CreateDeclarationForServo(
|
||||
const nsCString normalString = "normal"_ns;
|
||||
Servo_DeclarationBlock_SetPropertyById(
|
||||
servoDeclarations, eCSSProperty_line_height, &normalString, false,
|
||||
env.mUrlExtraData, ParsingMode::Default, env.mCompatMode, env.mLoader,
|
||||
env.mRuleType, {});
|
||||
env.mUrlExtraData, StyleParsingMode::DEFAULT, env.mCompatMode,
|
||||
env.mLoader, env.mRuleType, {});
|
||||
}
|
||||
|
||||
return servoDeclarations.forget();
|
||||
@ -2555,7 +2556,7 @@ static already_AddRefed<const ComputedStyle> GetFontStyleForServo(
|
||||
sc->GetComputedPropertyValue(eCSSProperty_font_size, computedFontSize);
|
||||
Servo_DeclarationBlock_SetPropertyById(
|
||||
declarations, eCSSProperty_font_size, &computedFontSize, false, nullptr,
|
||||
ParsingMode::Default, eCompatibility_FullStandards, nullptr,
|
||||
StyleParsingMode::DEFAULT, eCompatibility_FullStandards, nullptr,
|
||||
StyleCssRuleType::Style, {});
|
||||
}
|
||||
|
||||
|
@ -423,10 +423,10 @@ static ServoAnimationValues ValueFromStringHelper(
|
||||
ServoCSSParser::ParsingEnvironment env =
|
||||
ServoCSSParser::GetParsingEnvironment(doc);
|
||||
RefPtr<StyleLockedDeclarationBlock> servoDeclarationBlock =
|
||||
ServoCSSParser::ParseProperty(aPropID, NS_ConvertUTF16toUTF8(aString),
|
||||
env,
|
||||
ParsingMode::AllowUnitlessLength |
|
||||
ParsingMode::AllowAllNumericValues);
|
||||
ServoCSSParser::ParseProperty(
|
||||
aPropID, NS_ConvertUTF16toUTF8(aString), env,
|
||||
StyleParsingMode::ALLOW_UNITLESS_LENGTH |
|
||||
StyleParsingMode::ALLOW_ALL_NUMERIC_VALUES);
|
||||
if (!servoDeclarationBlock) {
|
||||
return result;
|
||||
}
|
||||
|
@ -1190,7 +1190,7 @@ void MappedAttrParser::ParseMappedAttrValue(nsAtom* aMappedAttrName,
|
||||
auto* doc = mElement.OwnerDoc();
|
||||
changed = Servo_DeclarationBlock_SetPropertyById(
|
||||
&EnsureDeclarationBlock(), propertyID, &value, false,
|
||||
&EnsureExtraData(), ParsingMode::AllowUnitlessLength,
|
||||
&EnsureExtraData(), StyleParsingMode::ALLOW_UNITLESS_LENGTH,
|
||||
doc->GetCompatibilityMode(), doc->CSSLoader(), StyleCssRuleType::Style,
|
||||
{});
|
||||
|
||||
|
@ -350,7 +350,6 @@ allowlist-types = [
|
||||
"mozilla::DefaultDelete",
|
||||
"mozilla::Side",
|
||||
"mozilla::binding_danger::AssertAndSuppressCleanupPolicy",
|
||||
"mozilla::ParsingMode",
|
||||
"mozilla::InheritTarget",
|
||||
"mozilla::dom::MediaList",
|
||||
"mozilla::StyleRuleInclusion",
|
||||
|
@ -34,7 +34,8 @@ bool ServoCSSParser::ComputeColor(ServoStyleSet* aStyleSet,
|
||||
/* static */
|
||||
already_AddRefed<StyleLockedDeclarationBlock> ServoCSSParser::ParseProperty(
|
||||
nsCSSPropertyID aProperty, const nsACString& aValue,
|
||||
const ParsingEnvironment& aParsingEnvironment, ParsingMode aParsingMode) {
|
||||
const ParsingEnvironment& aParsingEnvironment,
|
||||
const StyleParsingMode& aParsingMode) {
|
||||
return Servo_ParseProperty(
|
||||
aProperty, &aValue, aParsingEnvironment.mUrlExtraData,
|
||||
aParsingMode, aParsingEnvironment.mCompatMode,
|
||||
|
@ -11,7 +11,6 @@
|
||||
|
||||
#include "mozilla/AlreadyAddRefed.h"
|
||||
#include "mozilla/gfx/Matrix.h"
|
||||
#include "mozilla/ServoTypes.h"
|
||||
#include "nsColor.h"
|
||||
#include "nsCSSPropertyID.h"
|
||||
#include "nsDOMCSSDeclaration.h"
|
||||
@ -30,6 +29,7 @@ struct StyleFontStretch;
|
||||
struct StyleFontWeight;
|
||||
struct StyleFontStyle;
|
||||
struct StyleLockedDeclarationBlock;
|
||||
struct StyleParsingMode;
|
||||
union StyleComputedFontStyleDescriptor;
|
||||
|
||||
template <typename Integer, typename Number, typename LinearStops>
|
||||
@ -85,7 +85,7 @@ class ServoCSSParser {
|
||||
* @param aProperty The property to be parsed.
|
||||
* @param aValue The specified value.
|
||||
* @param aParsingEnvironment All the parsing environment data we need.
|
||||
* @param aParsingMode The paring mode we apply.
|
||||
* @param aParsingMode The parsing mode we apply.
|
||||
* @return The parsed value as a StyleLockedDeclarationBlock. We put the value
|
||||
* in a declaration block since that is how we represent specified values
|
||||
* in Servo.
|
||||
@ -93,7 +93,7 @@ class ServoCSSParser {
|
||||
static already_AddRefed<StyleLockedDeclarationBlock> ParseProperty(
|
||||
nsCSSPropertyID aProperty, const nsACString& aValue,
|
||||
const ParsingEnvironment& aParsingEnvironment,
|
||||
ParsingMode aParsingMode = ParsingMode::Default);
|
||||
const StyleParsingMode& aParsingMode);
|
||||
|
||||
/**
|
||||
* Parse a animation timing function.
|
||||
|
@ -80,29 +80,6 @@ enum class UpdateAnimationsTasks : uint8_t {
|
||||
|
||||
MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(UpdateAnimationsTasks)
|
||||
|
||||
// The mode to use when parsing values.
|
||||
//
|
||||
// TODO(zrhoffman, bug 1844295): Generate ParsingMode using cbindgen
|
||||
enum class ParsingMode : uint8_t {
|
||||
// In CSS, lengths must have units, except for zero values, where the unit can
|
||||
// be omitted.
|
||||
// https://www.w3.org/TR/css3-values/#lengths
|
||||
Default = 0,
|
||||
// In SVG, a coordinate or length value without a unit identifier (e.g., "25")
|
||||
// is assumed to be in user units (px).
|
||||
// https://www.w3.org/TR/SVG/coords.html#Units
|
||||
AllowUnitlessLength = 1 << 0,
|
||||
// In SVG, out-of-range values are not treated as an error in parsing.
|
||||
// https://www.w3.org/TR/SVG/implnote.html#RangeClamping
|
||||
AllowAllNumericValues = 1 << 1,
|
||||
// In CSS Properties and Values, the initial value must be computationally
|
||||
// independent.
|
||||
// <https://drafts.css-houdini.org/css-properties-values-api-1/#ref-for-computationally-independent%E2%91%A0>
|
||||
DisallowFontRelative = 1 << 2,
|
||||
};
|
||||
|
||||
MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(ParsingMode)
|
||||
|
||||
// The kind of style we're generating when requesting Servo to give us an
|
||||
// inherited style.
|
||||
enum class InheritTarget {
|
||||
|
@ -208,7 +208,8 @@ AnimationValue AnimationValue::FromString(nsCSSPropertyID aProperty,
|
||||
|
||||
RefPtr<StyleLockedDeclarationBlock> declarations =
|
||||
ServoCSSParser::ParseProperty(aProperty, aValue,
|
||||
ServoCSSParser::GetParsingEnvironment(doc));
|
||||
ServoCSSParser::GetParsingEnvironment(doc),
|
||||
StyleParsingMode::DEFAULT);
|
||||
|
||||
if (!declarations) {
|
||||
return result;
|
||||
|
@ -284,8 +284,8 @@ nsresult nsDOMCSSDeclaration::ParsePropertyValue(
|
||||
[&](DeclarationBlock* decl, ParsingEnvironment& env) {
|
||||
return Servo_DeclarationBlock_SetPropertyById(
|
||||
decl->Raw(), aPropID, &aPropValue, aIsImportant, env.mUrlExtraData,
|
||||
ParsingMode::Default, env.mCompatMode, env.mLoader, env.mRuleType,
|
||||
closure);
|
||||
StyleParsingMode::DEFAULT, env.mCompatMode, env.mLoader,
|
||||
env.mRuleType, closure);
|
||||
});
|
||||
}
|
||||
|
||||
@ -307,7 +307,7 @@ nsresult nsDOMCSSDeclaration::ParseCustomPropertyValue(
|
||||
[&](DeclarationBlock* decl, ParsingEnvironment& env) {
|
||||
return Servo_DeclarationBlock_SetProperty(
|
||||
decl->Raw(), &aPropertyName, &aPropValue, aIsImportant,
|
||||
env.mUrlExtraData, ParsingMode::Default, env.mCompatMode,
|
||||
env.mUrlExtraData, StyleParsingMode::DEFAULT, env.mCompatMode,
|
||||
env.mLoader, env.mRuleType, closure);
|
||||
});
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ static void ServoSetPropertyByIdBench(const nsACString& css) {
|
||||
for (int i = 0; i < SETPROPERTY_REPETITIONS; i++) {
|
||||
Servo_DeclarationBlock_SetPropertyById(
|
||||
block, eCSSProperty_width, &css,
|
||||
/* is_important = */ false, data, ParsingMode::Default,
|
||||
/* is_important = */ false, data, StyleParsingMode::DEFAULT,
|
||||
eCompatibility_FullStandards, nullptr, STYLE_RULE, {});
|
||||
}
|
||||
}
|
||||
@ -84,7 +84,7 @@ static void ServoGetPropertyValueById() {
|
||||
const nsACString& css = css_;
|
||||
Servo_DeclarationBlock_SetPropertyById(
|
||||
block, eCSSProperty_width, &css,
|
||||
/* is_important = */ false, data, ParsingMode::Default,
|
||||
/* is_important = */ false, data, StyleParsingMode::DEFAULT,
|
||||
eCompatibility_FullStandards, nullptr, STYLE_RULE, {});
|
||||
|
||||
for (int i = 0; i < GETPROPERTY_REPETITIONS; i++) {
|
||||
|
@ -12,33 +12,6 @@ use cssparser::{Parser, SourceLocation, UnicodeRange};
|
||||
use std::borrow::Cow;
|
||||
use style_traits::{OneOrMoreSeparated, ParseError, ParsingMode, Separator};
|
||||
|
||||
/// Asserts that all ParsingMode flags have a matching ParsingMode value in gecko.
|
||||
#[cfg(feature = "gecko")]
|
||||
#[inline]
|
||||
pub fn assert_parsing_mode_match() {
|
||||
use crate::gecko_bindings::structs;
|
||||
|
||||
macro_rules! check_parsing_modes {
|
||||
( $( $a:ident => $b:path ),*, ) => {
|
||||
if cfg!(debug_assertions) {
|
||||
let mut modes = ParsingMode::all();
|
||||
$(
|
||||
assert_eq!(structs::$a as usize, $b.bits() as usize, stringify!($b));
|
||||
modes.remove($b);
|
||||
)*
|
||||
assert_eq!(modes, ParsingMode::empty(), "all ParsingMode bits should have an assertion");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
check_parsing_modes! {
|
||||
ParsingMode_Default => ParsingMode::DEFAULT,
|
||||
ParsingMode_AllowUnitlessLength => ParsingMode::ALLOW_UNITLESS_LENGTH,
|
||||
ParsingMode_AllowAllNumericValues => ParsingMode::ALLOW_ALL_NUMERIC_VALUES,
|
||||
ParsingMode_DisallowFontRelative => ParsingMode::DISALLOW_FONT_RELATIVE,
|
||||
}
|
||||
}
|
||||
|
||||
/// The data that the parser needs from outside in order to parse a stylesheet.
|
||||
pub struct ParserContext<'a> {
|
||||
/// The `Origin` of the stylesheet, whether it's a user, author or
|
||||
|
@ -243,6 +243,7 @@ pub enum PropertySyntaxParseError {
|
||||
bitflags! {
|
||||
/// The mode to use when parsing values.
|
||||
#[derive(Clone, Copy, Eq, PartialEq)]
|
||||
#[repr(C)]
|
||||
pub struct ParsingMode: u8 {
|
||||
/// In CSS; lengths must have units, except for zero values, where the unit can be omitted.
|
||||
/// <https://www.w3.org/TR/css3-values/#lengths>
|
||||
|
@ -301,7 +301,6 @@ renaming_overrides_prefixing = true
|
||||
"AnimationPropertySegment" = "AnimationPropertySegment"
|
||||
"RawServoAnimationValueTable" = "RawServoAnimationValueTable"
|
||||
"nsCSSUnit" = "nsCSSUnit"
|
||||
"ParsingMode" = "ParsingMode"
|
||||
"InheritTarget" = "InheritTarget"
|
||||
"PseudoStyleType" = "PseudoStyleType"
|
||||
"DeclarationBlockMutationClosure" = "DeclarationBlockMutationClosure"
|
||||
|
@ -97,7 +97,7 @@ use style::global_style_data::{
|
||||
use style::invalidation::element::restyle_hints::RestyleHint;
|
||||
use style::invalidation::stylesheets::RuleChangeKind;
|
||||
use style::media_queries::MediaList;
|
||||
use style::parser::{self, Parse, ParserContext};
|
||||
use style::parser::{Parse, ParserContext};
|
||||
use style::properties::animated_properties::{AnimationValue, AnimationValueMap};
|
||||
use style::properties::{parse_one_declaration_into, parse_style_attribute};
|
||||
use style::properties::{ComputedValues, CountedUnknownProperty, Importance, NonCustomPropertyId};
|
||||
@ -189,7 +189,6 @@ pub unsafe extern "C" fn Servo_Initialize(
|
||||
|
||||
// Perform some debug-only runtime assertions.
|
||||
origin_flags::assert_flags_match();
|
||||
parser::assert_parsing_mode_match();
|
||||
traversal_flags::assert_traversal_flags_match();
|
||||
specified::font::assert_variant_east_asian_matches();
|
||||
specified::font::assert_variant_ligatures_matches();
|
||||
@ -4401,13 +4400,12 @@ fn parse_property_into(
|
||||
value: &nsACString,
|
||||
origin: Origin,
|
||||
url_data: &UrlExtraData,
|
||||
parsing_mode: structs::ParsingMode,
|
||||
parsing_mode: ParsingMode,
|
||||
quirks_mode: QuirksMode,
|
||||
rule_type: CssRuleType,
|
||||
reporter: Option<&dyn ParseErrorReporter>,
|
||||
) -> Result<(), ()> {
|
||||
let value = unsafe { value.as_str_unchecked() };
|
||||
let parsing_mode = ParsingMode::from_bits_retain(parsing_mode);
|
||||
|
||||
if let Some(non_custom) = property_id.non_custom_id() {
|
||||
if !non_custom.allowed_in_rule(rule_type.into()) {
|
||||
@ -4433,7 +4431,7 @@ pub unsafe extern "C" fn Servo_ParseProperty(
|
||||
property: nsCSSPropertyID,
|
||||
value: &nsACString,
|
||||
data: *mut URLExtraData,
|
||||
parsing_mode: structs::ParsingMode,
|
||||
parsing_mode: ParsingMode,
|
||||
quirks_mode: nsCompatibility,
|
||||
loader: *mut Loader,
|
||||
rule_type: CssRuleType,
|
||||
@ -4802,7 +4800,7 @@ fn set_property(
|
||||
value: &nsACString,
|
||||
is_important: bool,
|
||||
data: &UrlExtraData,
|
||||
parsing_mode: structs::ParsingMode,
|
||||
parsing_mode: ParsingMode,
|
||||
quirks_mode: QuirksMode,
|
||||
loader: *mut Loader,
|
||||
rule_type: CssRuleType,
|
||||
@ -4849,7 +4847,7 @@ pub unsafe extern "C" fn Servo_DeclarationBlock_SetProperty(
|
||||
value: &nsACString,
|
||||
is_important: bool,
|
||||
data: *mut URLExtraData,
|
||||
parsing_mode: structs::ParsingMode,
|
||||
parsing_mode: ParsingMode,
|
||||
quirks_mode: nsCompatibility,
|
||||
loader: *mut Loader,
|
||||
rule_type: CssRuleType,
|
||||
@ -4894,7 +4892,7 @@ pub unsafe extern "C" fn Servo_DeclarationBlock_SetPropertyById(
|
||||
value: &nsACString,
|
||||
is_important: bool,
|
||||
data: *mut URLExtraData,
|
||||
parsing_mode: structs::ParsingMode,
|
||||
parsing_mode: ParsingMode,
|
||||
quirks_mode: nsCompatibility,
|
||||
loader: *mut Loader,
|
||||
rule_type: CssRuleType,
|
||||
@ -5689,7 +5687,7 @@ pub extern "C" fn Servo_CSSSupports2(property: &nsACString, value: &nsACString)
|
||||
value,
|
||||
Origin::Author,
|
||||
unsafe { dummy_url_data() },
|
||||
structs::ParsingMode_Default,
|
||||
ParsingMode::DEFAULT,
|
||||
QuirksMode::NoQuirks,
|
||||
CssRuleType::Style,
|
||||
None,
|
||||
|
Loading…
Reference in New Issue
Block a user