mirror of
https://github.com/servo/servo.git
synced 2025-07-25 08:10:21 +01:00
Auto merge of #19984 - upsuper:media-ident-atom, r=emilio
Use atom for identifier media features This is the Servo side change of [bug 1435944](https://bugzilla.mozilla.org/show_bug.cgi?id=1435944). <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/19984) <!-- Reviewable:end -->
This commit is contained in:
commit
0d7c2271c2
1 changed files with 9 additions and 16 deletions
|
@ -7,7 +7,7 @@
|
||||||
use app_units::AU_PER_PX;
|
use app_units::AU_PER_PX;
|
||||||
use app_units::Au;
|
use app_units::Au;
|
||||||
use context::QuirksMode;
|
use context::QuirksMode;
|
||||||
use cssparser::{CssStringWriter, Parser, RGBA, Token, BasicParseErrorKind};
|
use cssparser::{Parser, RGBA, Token, BasicParseErrorKind};
|
||||||
use euclid::Size2D;
|
use euclid::Size2D;
|
||||||
use euclid::TypedScale;
|
use euclid::TypedScale;
|
||||||
use gecko::values::{convert_nscolor_to_rgba, convert_rgba_to_nscolor};
|
use gecko::values::{convert_nscolor_to_rgba, convert_rgba_to_nscolor};
|
||||||
|
@ -28,7 +28,7 @@ use style_traits::{CSSPixel, CssWriter, DevicePixel};
|
||||||
use style_traits::{ToCss, ParseError, StyleParseErrorKind};
|
use style_traits::{ToCss, ParseError, StyleParseErrorKind};
|
||||||
use style_traits::viewport::ViewportConstraints;
|
use style_traits::viewport::ViewportConstraints;
|
||||||
use stylesheets::Origin;
|
use stylesheets::Origin;
|
||||||
use values::{CSSFloat, CustomIdent, KeyframesName};
|
use values::{CSSFloat, CustomIdent, KeyframesName, serialize_atom_identifier};
|
||||||
use values::computed::{self, ToComputedValue};
|
use values::computed::{self, ToComputedValue};
|
||||||
use values::computed::font::FontSize;
|
use values::computed::font::FontSize;
|
||||||
use values::specified::{Integer, Length, Number};
|
use values::specified::{Integer, Length, Number};
|
||||||
|
@ -352,15 +352,11 @@ pub enum MediaExpressionValue {
|
||||||
/// feature's `mData` member.
|
/// feature's `mData` member.
|
||||||
Enumerated(i16),
|
Enumerated(i16),
|
||||||
/// An identifier.
|
/// An identifier.
|
||||||
///
|
Ident(Atom),
|
||||||
/// TODO(emilio): Maybe atomize?
|
|
||||||
Ident(String),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MediaExpressionValue {
|
impl MediaExpressionValue {
|
||||||
fn from_css_value(for_expr: &Expression, css_value: &nsCSSValue) -> Option<Self> {
|
fn from_css_value(for_expr: &Expression, css_value: &nsCSSValue) -> Option<Self> {
|
||||||
use gecko::conversions::string_from_chars_pointer;
|
|
||||||
|
|
||||||
// NB: If there's a null value, that means that we don't support the
|
// NB: If there's a null value, that means that we don't support the
|
||||||
// feature.
|
// feature.
|
||||||
if css_value.mUnit == nsCSSUnit::eCSSUnit_Null {
|
if css_value.mUnit == nsCSSUnit::eCSSUnit_Null {
|
||||||
|
@ -397,13 +393,10 @@ impl MediaExpressionValue {
|
||||||
Some(MediaExpressionValue::Enumerated(value))
|
Some(MediaExpressionValue::Enumerated(value))
|
||||||
}
|
}
|
||||||
nsMediaFeature_ValueType::eIdent => {
|
nsMediaFeature_ValueType::eIdent => {
|
||||||
debug_assert_eq!(css_value.mUnit, nsCSSUnit::eCSSUnit_Ident);
|
debug_assert_eq!(css_value.mUnit, nsCSSUnit::eCSSUnit_AtomIdent);
|
||||||
let string = unsafe {
|
Some(MediaExpressionValue::Ident(Atom::from(unsafe {
|
||||||
let buffer = *css_value.mValue.mString.as_ref();
|
*css_value.mValue.mAtom.as_ref()
|
||||||
debug_assert!(!buffer.is_null());
|
})))
|
||||||
string_from_chars_pointer(buffer.offset(1) as *const u16)
|
|
||||||
};
|
|
||||||
Some(MediaExpressionValue::Ident(string))
|
|
||||||
}
|
}
|
||||||
nsMediaFeature_ValueType::eIntRatio => {
|
nsMediaFeature_ValueType::eIntRatio => {
|
||||||
let array = unsafe { css_value.array_unchecked() };
|
let array = unsafe { css_value.array_unchecked() };
|
||||||
|
@ -436,7 +429,7 @@ impl MediaExpressionValue {
|
||||||
},
|
},
|
||||||
MediaExpressionValue::Resolution(ref r) => r.to_css(dest),
|
MediaExpressionValue::Resolution(ref r) => r.to_css(dest),
|
||||||
MediaExpressionValue::Ident(ref ident) => {
|
MediaExpressionValue::Ident(ref ident) => {
|
||||||
CssStringWriter::new(dest).write_str(ident)
|
serialize_atom_identifier(ident, dest)
|
||||||
}
|
}
|
||||||
MediaExpressionValue::Enumerated(value) => unsafe {
|
MediaExpressionValue::Enumerated(value) => unsafe {
|
||||||
use std::{slice, str};
|
use std::{slice, str};
|
||||||
|
@ -561,7 +554,7 @@ fn parse_feature_value<'i, 't>(
|
||||||
MediaExpressionValue::Enumerated(value)
|
MediaExpressionValue::Enumerated(value)
|
||||||
}
|
}
|
||||||
nsMediaFeature_ValueType::eIdent => {
|
nsMediaFeature_ValueType::eIdent => {
|
||||||
MediaExpressionValue::Ident(input.expect_ident()?.as_ref().to_owned())
|
MediaExpressionValue::Ident(Atom::from(input.expect_ident()?.as_ref()))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue