Bug 1815186 - Add ColorTo to InspectorUtils to convert color to other color spaces. r=emilio,layout-reviewers,supply-chain-reviewers

This will allow calling `InspectorUtils.ColorTo("red", "lab")` and
receive `{color: "lab(54.3 80.8 69.9)", components: [54.3, 80.8, 69.9, 1.0], adjusted: false}`.

The adjusted value is always "false", because gamut checking and mapping
is not supported at the moment. See:
https://bugzilla.mozilla.org/show_bug.cgi?id=1823363

Differential Revision: https://phabricator.services.mozilla.com/D169942
This commit is contained in:
Tiaan Louw 2023-05-22 17:19:14 +00:00
Родитель 8f67002337
Коммит fc8e61b225
15 изменённых файлов: 249 добавлений и 29 удалений

Просмотреть файл

@ -105,9 +105,9 @@ git = "https://github.com/mozilla/uniffi-rs.git"
rev = "bc7ff8977bf38d0fdd1a458810b14f434d4dc4de"
replace-with = "vendored-sources"
[source."git+https://github.com/servo/rust-cssparser?rev=6ce91afdf292c4290118843e7421e146f0a4c48b"]
[source."git+https://github.com/servo/rust-cssparser?rev=8a24b1118747dc76c9ba3a9c88bd2456516c598d"]
git = "https://github.com/servo/rust-cssparser"
rev = "6ce91afdf292c4290118843e7421e146f0a4c48b"
rev = "8a24b1118747dc76c9ba3a9c88bd2456516c598d"
replace-with = "vendored-sources"

4
Cargo.lock сгенерированный
Просмотреть файл

@ -1017,7 +1017,7 @@ dependencies = [
[[package]]
name = "cssparser"
version = "0.31.0"
source = "git+https://github.com/servo/rust-cssparser?rev=6ce91afdf292c4290118843e7421e146f0a4c48b#6ce91afdf292c4290118843e7421e146f0a4c48b"
source = "git+https://github.com/servo/rust-cssparser?rev=8a24b1118747dc76c9ba3a9c88bd2456516c598d#8a24b1118747dc76c9ba3a9c88bd2456516c598d"
dependencies = [
"cssparser-macros",
"dtoa-short",
@ -1032,7 +1032,7 @@ dependencies = [
[[package]]
name = "cssparser-macros"
version = "0.6.0"
source = "git+https://github.com/servo/rust-cssparser?rev=6ce91afdf292c4290118843e7421e146f0a4c48b#6ce91afdf292c4290118843e7421e146f0a4c48b"
source = "git+https://github.com/servo/rust-cssparser?rev=8a24b1118747dc76c9ba3a9c88bd2456516c598d#8a24b1118747dc76c9ba3a9c88bd2456516c598d"
dependencies = [
"quote",
"syn",

Просмотреть файл

@ -153,8 +153,8 @@ moz_asserts = { path = "mozglue/static/rust/moz_asserts" }
rure = { path = "third_party/rust/rure" }
# To-be-published changes.
cssparser = { git = "https://github.com/servo/rust-cssparser", rev = "6ce91afdf292c4290118843e7421e146f0a4c48b" }
cssparser-macros = { git = "https://github.com/servo/rust-cssparser", rev = "6ce91afdf292c4290118843e7421e146f0a4c48b" }
cssparser = { git = "https://github.com/servo/rust-cssparser", rev = "8a24b1118747dc76c9ba3a9c88bd2456516c598d" }
cssparser-macros = { git = "https://github.com/servo/rust-cssparser", rev = "8a24b1118747dc76c9ba3a9c88bd2456516c598d" }
# Other overrides
chardetng = { git = "https://github.com/hsivonen/chardetng", rev="3484d3e3ebdc8931493aa5df4d7ee9360a90e76b" }

Просмотреть файл

@ -39,6 +39,7 @@ namespace InspectorUtils {
[Throws] sequence<DOMString> getCSSValuesForProperty(UTF8String property);
DOMString rgbToColorName(octet r, octet g, octet b);
InspectorRGBATuple? colorToRGBA(UTF8String colorString, optional Document? doc = null);
InspectorColorToResult? colorTo(UTF8String fromColor, UTF8String toColorSpace);
boolean isValidCSSColor(UTF8String colorString);
[Throws] sequence<DOMString> getSubpropertiesForCSSProperty(UTF8String property);
[Throws] boolean cssPropertyIsShorthand(UTF8String property);
@ -118,6 +119,12 @@ dictionary InspectorRGBATuple {
double a = 1;
};
dictionary InspectorColorToResult {
required DOMString color;
required sequence<float> components;
required boolean adjusted;
};
// Any update to this enum should probably also update
// devtools/shared/css/constants.js
enum InspectorPropertyType {

Просмотреть файл

@ -584,6 +584,26 @@ void InspectorUtils::ColorToRGBA(GlobalObject&, const nsACString& aColorString,
tuple.mA = nsStyleUtil::ColorComponentToFloat(NS_GET_A(color));
}
/* static */
void InspectorUtils::ColorTo(GlobalObject&, const nsACString& aFromColor,
const nsACString& aToColorSpace,
Nullable<InspectorColorToResult>& aResult) {
nsCString resultColor;
nsTArray<float> resultComponents;
bool resultAdjusted = false;
if (!ServoCSSParser::ColorTo(aFromColor, aToColorSpace, &resultColor,
&resultComponents, &resultAdjusted)) {
aResult.SetNull();
return;
}
auto& result = aResult.SetValue();
result.mColor.AssignASCII(resultColor);
result.mComponents = std::move(resultComponents);
result.mAdjusted = resultAdjusted;
}
/* static */
bool InspectorUtils::IsValidCSSColor(GlobalObject& aGlobalObject,
const nsACString& aColorString) {

Просмотреть файл

@ -136,6 +136,11 @@ class InspectorUtils {
const Document*,
Nullable<InspectorRGBATuple>& aResult);
// Convert a given CSS color string to another color space.
static void ColorTo(GlobalObject&, const nsACString& aFromColor,
const nsACString& aToColorSpace,
Nullable<InspectorColorToResult>& aResult);
// Check whether a given color is a valid CSS color.
static bool IsValidCSSColor(GlobalObject& aGlobal,
const nsACString& aColorString);

Просмотреть файл

@ -7,19 +7,21 @@ support-files =
bug856317.css
file_bug522601.html
[test_bug1006595.html]
[test_bug462787.html]
[test_bug462789.html]
[test_bug522601-shadow.xhtml]
[test_bug536379.html]
[test_bug536379-2.html]
[test_bug536379.html]
[test_bug557726.html]
[test_bug609549-shadow.xhtml]
[test_bug856317.html]
[test_bug877690.html]
[test_bug1006595.html]
[test_color_to.html]
[test_color_to_rgba.html]
[test_containing_block_of.html]
[test_css_property_is_shorthand.html]
[test_getCSSPseudoElementNames.html]
[test_getCSSStyleRules.html]
support-files =
file_getCSSStyleRules-default.html
@ -28,7 +30,6 @@ support-files =
getCSSStyleRules-2.css
[test_getCSSStyleRules_pseudo.html]
[test_getCSSStyleRules_slotted.html]
[test_getCSSPseudoElementNames.html]
[test_getRelativeRuleLine.html]
[test_get_all_style_sheets.html]
[test_is_element_themed.html]

Просмотреть файл

@ -0,0 +1,68 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Test InspectorUtils::ColorTo</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
<script>
const InspectorUtils = SpecialPowers.InspectorUtils;
const kEpsilon = 0.001;
testColor("chocolate", "srgb", "rgb(210, 105, 30)", [0.8235294222831726, 0.4117647111415863, 0.11764705926179886, 1], false);
testColor("chocolate", "hsl", "hsl(25 75% 47.0588%)", [25, 0.75, 0.4706], false);
testColor("chocolate", "hwb", "hwb(25 11.7647% 17.6471%)", [25, 0.1176, 0.1765], false);
testColor("chocolate", "lab", "lab(56.6293 39.2463 57.5567)", [56.6293, 39.2463, 57.5567], false);
testColor("chocolate", "lch", "lch(56.6293 69.6638 55.711)", [56.6293, 69.6638, 55.711], false);
testColor("chocolate", "oklab", "oklab(0.634398 0.099074 0.119193)", [0.634398, 0.099074, 0.119193], false);
testColor("chocolate", "oklch", "oklch(0.634398 0.154992 50.2665)", [0.634398, 0.154992, 50.2665], false);
testColor("chocolate", "srgb-linear", "color(srgb-linear 0.64448 0.141263 0.012983)", [0.64448, 0.141263, 0.012983], false);
testColor("chocolate", "display-p3", "color(display-p3 0.770569 0.434015 0.199849)", [0.770569, 0.434015, 0.199849], false);
testColor("chocolate", "a98-rgb", "color(a98-rgb 0.730405 0.410688 0.162005)", [0.730405, 0.410688, 0.162005], false);
testColor("chocolate", "prophoto-rgb", "color(prophoto-rgb 0.592311 0.394149 0.164286)", [0.592311, 0.394149, 0.164286], false);
testColor("chocolate", "rec2020", "color(rec2020 0.669266 0.401901 0.142716)", [0.669266, 0.401901, 0.142716], false);
testColor("chocolate", "xyz-d50", "color(xyz-d50 0.337301 0.245449 0.0319589)", [0.337301, 0.245449, 0.0319589], false);
testColor("chocolate", "xyz-d65", "color(xyz-d65 0.318634 0.239006 0.041637)", [0.318634, 0.239006, 0.041637], false);
testColor("chocolate", "xyz", "color(xyz-d65 0.318634 0.239006 0.041637)", [0.318634, 0.239006, 0.041637], false);
// Invalid color.
testColor("darkblueorange", "srgb", null, null, null);
testColor("rgb(none, none, none)", "lab", null, null, null);
testColor(null, "lab", null, null, null);
// Invalid color spaces.
testColor("chocolate", "something", null, null, null);
testColor("chocolate", "", null, null, null);
testColor("chocolate", null, null, null, null);
function testColor(color, colorSpace, expected, expectedComponents, expectedAdjust) {
let actual = InspectorUtils.colorTo(color, colorSpace);
// If we only get 3 elements for the expected components, we just add the
// default alpha.
if (expectedComponents && expectedComponents.length === 3) {
expectedComponents.push(1);
}
if (actual === null) {
is(expected, null, "color: converting " + color + " to " + colorSpace + " returns null");
return;
}
is(actual.color, expected, "color is correctly converted to " + colorSpace);
for (let i = 0; i < 4; i++) {
isfuzzy(actual.components[i], expectedComponents[i], kEpsilon, "component " + i + " when converting to " + colorSpace);
}
is(actual.adjusted, expectedAdjust, "color adjusted status currect");
}
</script>
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none"></div>
<pre id="test"></pre>
</body>
</html>

Просмотреть файл

@ -31,6 +31,16 @@ bool ServoCSSParser::ComputeColor(ServoStyleSet* aStyleSet,
aWasCurrentColor, aLoader);
}
/* static */
bool ServoCSSParser::ColorTo(const nsACString& aFromColor,
const nsACString& aToColorSpace,
nsACString* aResultColor,
nsTArray<float>* aResultComponents,
bool* aResultAdjusted, css::Loader* aLoader) {
return Servo_ColorTo(&aFromColor, &aToColorSpace, aResultColor,
aResultComponents, aResultAdjusted, aLoader);
}
/* static */
already_AddRefed<StyleLockedDeclarationBlock> ServoCSSParser::ParseProperty(
nsCSSPropertyID aProperty, const nsACString& aValue,

Просмотреть файл

@ -78,6 +78,27 @@ class ServoCSSParser {
bool* aWasCurrentColor = nullptr,
css::Loader* aLoader = nullptr);
/**
* Takes a CSS <color> and convert it to another color space.
*
* @param aStyleSet The style set whose nsPresContext will be used to
* compute system colors and other special color values.
* @param aFromColor The CSS <color> we use to convert from.
* @param aToColorSpace The CSS <color-space> to convert the color into.
* @param aResultColor The resulting converted color value.
* @param aResultAdjusted Whether the color was adjusted to fit into the SRGB
color space.
* @param aLoader The CSS loader for document we're parsing a color for,
* so that parse errors can be reported to the console. If nullptr, errors
* won't be reported to the console.
* @return Whether aFromColor and aToColorSpace was successfully parsed and
* aResultColor and aResultAdjusted was set.
*/
static bool ColorTo(const nsACString& aFromColor,
const nsACString& aToColorSpace, nsACString* aResultColor,
nsTArray<float>* aResultComponents, bool* aResultAdjusted,
css::Loader* aLoader = nullptr);
/**
* Parse a string representing a CSS property value into a
* StyleLockedDeclarationBlock.

Просмотреть файл

@ -142,7 +142,7 @@ use style::values::generics::easing::BeforeFlag;
use style::values::specified::gecko::IntersectionObserverRootMargin;
use style::values::specified::source_size_list::SourceSizeList;
use style::values::specified::{AbsoluteLength, NoCalcLength};
use style::values::{specified, AtomIdent, CustomIdent, KeyframesName};
use style::values::{serialize_percentage, specified, AtomIdent, CustomIdent, KeyframesName};
use style_traits::{CssWriter, ParseError, ParsingMode, ToCss};
use thin_vec::ThinVec;
use to_shmem::SharedMemoryBuilder;
@ -7075,6 +7075,94 @@ pub unsafe extern "C" fn Servo_ComputeColor(
true
}
#[no_mangle]
pub unsafe extern "C" fn Servo_ColorTo(
from_color: &nsACString,
to_color_space: &nsACString,
result_color: &mut nsACString,
result_components: &mut nsTArray<f32>,
result_adjusted: &mut bool,
loader: *mut Loader,
) -> bool {
// Figure out the color space.
let mut input = ParserInput::new(to_color_space.as_str_unchecked());
let mut input = Parser::new(&mut input);
let to_color_space = match ColorSpace::parse(&mut input) {
Ok(color_space) => color_space,
Err(_) => {
// Can't parse the color space? Fail the conversion.
return false;
},
};
let mut input = ParserInput::new(from_color.as_str_unchecked());
let mut input = Parser::new(&mut input);
let reporter = loader.as_mut().and_then(|loader| {
// Make an ErrorReporter that will report errors as being "from DOM".
ErrorReporter::new(ptr::null_mut(), loader, ptr::null_mut())
});
let context = ParserContext::new(
Origin::Author,
dummy_url_data(),
Some(CssRuleType::Style),
ParsingMode::DEFAULT,
QuirksMode::NoQuirks,
/* namespaces = */ Default::default(),
reporter.as_ref().map(|e| e as &dyn ParseErrorReporter),
None,
);
let specified = match specified::Color::parse(&context, &mut input) {
Ok(color) => color,
Err(_) => return false,
};
let color = match specified {
specified::Color::Absolute(ref absolute) => &absolute.color,
_ => {
// Can't do anything with a non-absolute color from here, so we
// fail the conversion.
return false;
},
};
let color = color.to_color_space(to_color_space);
let mut writer = CssWriter::new(result_color);
match color.color_space {
ColorSpace::Hsl => {
writer.write_str("hsl(").unwrap();
style_traits::values::ToCss::to_css(&color.components.0, &mut writer).unwrap();
writer.write_char(' ').unwrap();
serialize_percentage(color.components.1, &mut writer).unwrap();
writer.write_char(' ').unwrap();
serialize_percentage(color.components.2, &mut writer).unwrap();
// cssparser::serialize_alpha(&mut writer, Some(color.alpha), false).unwrap();
writer.write_str(")").unwrap();
},
ColorSpace::Hwb => {
writer.write_str("hwb(").unwrap();
style_traits::values::ToCss::to_css(&color.components.0, &mut writer).unwrap();
writer.write_char(' ').unwrap();
serialize_percentage(color.components.1, &mut writer).unwrap();
writer.write_char(' ').unwrap();
serialize_percentage(color.components.2, &mut writer).unwrap();
// cssparser::serialize_alpha(&mut writer, Some(color.alpha), false).unwrap();
writer.write_str(")").unwrap();
},
_ => color.to_css(&mut writer).unwrap(),
}
result_components.assign_from_iter_pod(color.raw_components().iter().copied());
// For now we don't do gamut mapping, so always false.
*result_adjusted = false;
true
}
#[no_mangle]
pub extern "C" fn Servo_ResolveColor(
color: &computed::Color,

Просмотреть файл

@ -782,12 +782,6 @@ was developed by other mozilla folks. Unsafe code there is reasonable (utf-8
casts for serialization and parsing).
"""
[[audits.cssparser]]
who = "Emilio Cobos Álvarez <emilio@crisal.io>"
criteria = "safe-to-deploy"
version = "0.31.0@git:6ce91afdf292c4290118843e7421e146f0a4c48b"
notes = "Local changes authored by me that aren't published yet."
[[audits.cssparser]]
who = "Bobby Holley <bobbyholley@gmail.com>"
criteria = "safe-to-deploy"
@ -797,6 +791,12 @@ All the changes in this release were authored by Mozilla staff, except the
uninit_array stuff, which looks fine.
"""
[[audits.cssparser]]
who = "Tiaan Louw <tlouw@mozilla.com>"
criteria = "safe-to-deploy"
delta = "0.31.0 -> 0.31.0@git:8a24b1118747dc76c9ba3a9c88bd2456516c598d"
notes = "To use unpublished changes."
[[audits.cssparser-macros]]
who = "Emilio Cobos Álvarez <emilio@crisal.io>"
criteria = "safe-to-deploy"
@ -807,10 +807,9 @@ to a match expression.
"""
[[audits.cssparser-macros]]
who = "Emilio Cobos Álvarez <emilio@crisal.io>"
who = "Tiaan Louw <tlouw@mozilla.com>"
criteria = "safe-to-deploy"
version = "0.6.0@git:6ce91afdf292c4290118843e7421e146f0a4c48b"
notes = "We are pulling this package from a non crates.io source until the changes are published. No changes were made to the code."
delta = "0.6.0 -> 0.6.0@git:8a24b1118747dc76c9ba3a9c88bd2456516c598d"
[[audits.cstr]]
who = "Emilio Cobos Álvarez <emilio@crisal.io>"

Просмотреть файл

@ -1 +1 @@
{"files":{".github/workflows/main.yml":"73c57dbb2c5471de2fcba828e356d09931ae89176f3bb695029b169dbb3f696f","Cargo.toml":"cffe5d5b5b66f65b9e4ca2aee56cf046604075ccfff0a89ca37ef4bb59164d02","LICENSE":"fab3dd6bdab226f1c08630b1dd917e11fcb4ec5e1e020e2c16f83a0a13863e85","README.md":"53a6805edd80f642473514cb93f1f4197e17a911d66a2dfcefc3dc5e82bac206","docs/.nojekyll":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855","docs/404.html":"025861f76f8d1f6d67c20ab624c6e418f4f824385e2dd8ad8732c4ea563c6a2e","docs/index.html":"025861f76f8d1f6d67c20ab624c6e418f4f824385e2dd8ad8732c4ea563c6a2e","src/color.rs":"df7d97636896df02b7ba56abf6f74f121d8320615f9e6ef6d43e6f272d3600cb","src/cow_rc_str.rs":"22d6829ab54c51486af4bacf5f184a6c95c15febdbbd5630a98b995ed0ee3e55","src/from_bytes.rs":"b1cf15c4e975523fef46b575598737a39f3c63e5ce0b2bfd6ec627c69c6ea54a","src/lib.rs":"d4e37941cfa90e42deb7d0537483ac0b2bac033adf4bb0007b000cd807c588f5","src/macros.rs":"883df01d4a8dfc661b8ffa17fab694ff6fb271e99e9c6b023e73d49bbaa6e5d6","src/nth.rs":"2fc26915f0a36cb22ac45dd9a7ecbdc64c327b2ec135370258ec3db9f9985460","src/parser.rs":"50fa448b316902d5f4aa18725220633c28bb7d82cbaff125177d79d4cf8dae58","src/rules_and_declarations.rs":"cb08533dd4b239a6cbd59d8fcca1447c8089940dd519edea9c9a9b51fa999d49","src/serializer.rs":"3a0155521676deea9a6327c2ed00af6d5dabb29a97e2341d0f565f8c2b66d0a3","src/size_of_tests.rs":"da0cbcaa304f7800e9122e2bce0a11d42a70b9012e646a723cb23ee74a6b858c","src/tests.rs":"6c950841e8c454c50ae439543fa8718f935058a6bb1b1bf77033439daeff08a7","src/tokenizer.rs":"9900460d9bad82b7a41829d01537094203fafc7092c954aac969546ea53d5bba","src/unicode_range.rs":"20d96f06fbb73921e308cc340c9fe065e27f19843005689fb259007a6a372bcc"},"package":null}
{"files":{".github/workflows/main.yml":"73c57dbb2c5471de2fcba828e356d09931ae89176f3bb695029b169dbb3f696f","Cargo.toml":"cffe5d5b5b66f65b9e4ca2aee56cf046604075ccfff0a89ca37ef4bb59164d02","LICENSE":"fab3dd6bdab226f1c08630b1dd917e11fcb4ec5e1e020e2c16f83a0a13863e85","README.md":"53a6805edd80f642473514cb93f1f4197e17a911d66a2dfcefc3dc5e82bac206","docs/.nojekyll":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855","docs/404.html":"025861f76f8d1f6d67c20ab624c6e418f4f824385e2dd8ad8732c4ea563c6a2e","docs/index.html":"025861f76f8d1f6d67c20ab624c6e418f4f824385e2dd8ad8732c4ea563c6a2e","src/color.rs":"08424f5101c04f715b53fd91a2187fe9e7a11287cf6deee485fb6741eace130d","src/cow_rc_str.rs":"22d6829ab54c51486af4bacf5f184a6c95c15febdbbd5630a98b995ed0ee3e55","src/from_bytes.rs":"b1cf15c4e975523fef46b575598737a39f3c63e5ce0b2bfd6ec627c69c6ea54a","src/lib.rs":"8f1657c507380db0281e5aa7eb06f17d7f559c582b265d6589006042ffad18ad","src/macros.rs":"883df01d4a8dfc661b8ffa17fab694ff6fb271e99e9c6b023e73d49bbaa6e5d6","src/nth.rs":"2fc26915f0a36cb22ac45dd9a7ecbdc64c327b2ec135370258ec3db9f9985460","src/parser.rs":"50fa448b316902d5f4aa18725220633c28bb7d82cbaff125177d79d4cf8dae58","src/rules_and_declarations.rs":"cb08533dd4b239a6cbd59d8fcca1447c8089940dd519edea9c9a9b51fa999d49","src/serializer.rs":"3a0155521676deea9a6327c2ed00af6d5dabb29a97e2341d0f565f8c2b66d0a3","src/size_of_tests.rs":"da0cbcaa304f7800e9122e2bce0a11d42a70b9012e646a723cb23ee74a6b858c","src/tests.rs":"6c950841e8c454c50ae439543fa8718f935058a6bb1b1bf77033439daeff08a7","src/tokenizer.rs":"9900460d9bad82b7a41829d01537094203fafc7092c954aac969546ea53d5bba","src/unicode_range.rs":"20d96f06fbb73921e308cc340c9fe065e27f19843005689fb259007a6a372bcc"},"package":null}

11
third_party/rust/cssparser/src/color.rs поставляемый
Просмотреть файл

@ -26,9 +26,10 @@ where
}
}
/// Serialize the alpha copmonent of a color according to the specification.
/// <https://drafts.csswg.org/css-color-4/#serializing-alpha-values>
#[inline]
fn serialize_alpha(
pub fn serialize_color_alpha(
dest: &mut impl fmt::Write,
alpha: Option<f32>,
legacy_syntax: bool,
@ -146,7 +147,7 @@ impl ToCss for RGBA {
self.blue.unwrap_or(0).to_css(dest)?;
// Legacy syntax does not allow none components.
serialize_alpha(dest, Some(self.alpha.unwrap_or(0.0)), true)?;
serialize_color_alpha(dest, Some(self.alpha.unwrap_or(0.0)), true)?;
dest.write_char(')')
}
@ -367,7 +368,7 @@ macro_rules! impl_lab_like {
serialize_none_or(dest, &self.a)?;
dest.write_char(' ')?;
serialize_none_or(dest, &self.b)?;
serialize_alpha(dest, self.alpha, false)?;
serialize_color_alpha(dest, self.alpha, false)?;
dest.write_char(')')
}
}
@ -458,7 +459,7 @@ macro_rules! impl_lch_like {
serialize_none_or(dest, &self.chroma)?;
dest.write_char(' ')?;
serialize_none_or(dest, &self.hue)?;
serialize_alpha(dest, self.alpha, false)?;
serialize_color_alpha(dest, self.alpha, false)?;
dest.write_char(')')
}
}
@ -584,7 +585,7 @@ impl ToCss for ColorFunction {
dest.write_char(' ')?;
serialize_none_or(dest, &self.c3)?;
serialize_alpha(dest, self.alpha, false)?;
serialize_color_alpha(dest, self.alpha, false)?;
dest.write_char(')')
}

8
third_party/rust/cssparser/src/lib.rs поставляемый
Просмотреть файл

@ -68,9 +68,9 @@ fn parse_border_spacing(_context: &ParserContext, input: &mut Parser)
#![recursion_limit = "200"] // For color::parse_color_keyword
pub use crate::color::{
hsl_to_rgb, hwb_to_rgb, parse_color_keyword, parse_color_with, parse_hash_color, AngleOrNumber,
Color, ColorFunction, ColorParser, FromParsedColor, Hsl, Hwb, Lab, Lch, NumberOrPercentage,
Oklab, Oklch, PredefinedColorSpace, RGBA,
hsl_to_rgb, hwb_to_rgb, parse_color_keyword, parse_color_with, parse_hash_color,
serialize_color_alpha, AngleOrNumber, Color, ColorFunction, ColorParser, FromParsedColor, Hsl,
Hwb, Lab, Lch, NumberOrPercentage, Oklab, Oklch, PredefinedColorSpace, RGBA,
};
pub use crate::cow_rc_str::CowRcStr;
pub use crate::from_bytes::{stylesheet_encoding, EncodingSupport};
@ -84,7 +84,7 @@ pub use crate::parser::{Delimiter, Delimiters, Parser, ParserInput, ParserState}
pub use crate::rules_and_declarations::{parse_important, parse_one_declaration};
pub use crate::rules_and_declarations::{parse_one_rule, StyleSheetParser};
pub use crate::rules_and_declarations::{AtRuleParser, QualifiedRuleParser};
pub use crate::rules_and_declarations::{RuleBodyParser, RuleBodyItemParser, DeclarationParser};
pub use crate::rules_and_declarations::{DeclarationParser, RuleBodyItemParser, RuleBodyParser};
pub use crate::serializer::{serialize_identifier, serialize_name, serialize_string};
pub use crate::serializer::{CssStringWriter, ToCss, TokenSerializationType};
pub use crate::tokenizer::{SourceLocation, SourcePosition, Token};