mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
style: Part 2. Use Device for parameter instead of CssEnvironment.
CssEnvironment always is in Device, so use Device as parameter instead of CssEnvironment. Differential Revision: https://phabricator.services.mozilla.com/D52507
This commit is contained in:
parent
c5bd98354d
commit
80a1b64384
5 changed files with 31 additions and 30 deletions
|
@ -7,6 +7,7 @@
|
||||||
//! [custom]: https://drafts.csswg.org/css-variables/
|
//! [custom]: https://drafts.csswg.org/css-variables/
|
||||||
|
|
||||||
use crate::hash::map::Entry;
|
use crate::hash::map::Entry;
|
||||||
|
use crate::media_queries::Device;
|
||||||
use crate::properties::{CSSWideKeyword, CustomDeclaration, CustomDeclarationValue};
|
use crate::properties::{CSSWideKeyword, CustomDeclaration, CustomDeclarationValue};
|
||||||
use crate::selector_map::{PrecomputedHashMap, PrecomputedHashSet, PrecomputedHasher};
|
use crate::selector_map::{PrecomputedHashMap, PrecomputedHashSet, PrecomputedHasher};
|
||||||
use crate::stylesheets::{Origin, PerOrigin};
|
use crate::stylesheets::{Origin, PerOrigin};
|
||||||
|
@ -497,14 +498,14 @@ pub struct CustomPropertiesBuilder<'a> {
|
||||||
may_have_cycles: bool,
|
may_have_cycles: bool,
|
||||||
custom_properties: Option<CustomPropertiesMap>,
|
custom_properties: Option<CustomPropertiesMap>,
|
||||||
inherited: Option<&'a Arc<CustomPropertiesMap>>,
|
inherited: Option<&'a Arc<CustomPropertiesMap>>,
|
||||||
environment: &'a CssEnvironment,
|
device: &'a Device,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> CustomPropertiesBuilder<'a> {
|
impl<'a> CustomPropertiesBuilder<'a> {
|
||||||
/// Create a new builder, inheriting from a given custom properties map.
|
/// Create a new builder, inheriting from a given custom properties map.
|
||||||
pub fn new(
|
pub fn new(
|
||||||
inherited: Option<&'a Arc<CustomPropertiesMap>>,
|
inherited: Option<&'a Arc<CustomPropertiesMap>>,
|
||||||
environment: &'a CssEnvironment,
|
device: &'a Device,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
seen: PrecomputedHashSet::default(),
|
seen: PrecomputedHashSet::default(),
|
||||||
|
@ -512,7 +513,7 @@ impl<'a> CustomPropertiesBuilder<'a> {
|
||||||
may_have_cycles: false,
|
may_have_cycles: false,
|
||||||
custom_properties: None,
|
custom_properties: None,
|
||||||
inherited,
|
inherited,
|
||||||
environment,
|
device,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -554,7 +555,7 @@ impl<'a> CustomPropertiesBuilder<'a> {
|
||||||
// of forcing a full traversal in `substitute_all` afterwards.
|
// of forcing a full traversal in `substitute_all` afterwards.
|
||||||
let value = if !has_references && unparsed_value.references_environment {
|
let value = if !has_references && unparsed_value.references_environment {
|
||||||
let result =
|
let result =
|
||||||
substitute_references_in_value(unparsed_value, &map, &self.environment);
|
substitute_references_in_value(unparsed_value, &map, &self.device);
|
||||||
match result {
|
match result {
|
||||||
Ok(new_value) => Arc::new(new_value),
|
Ok(new_value) => Arc::new(new_value),
|
||||||
Err(..) => {
|
Err(..) => {
|
||||||
|
@ -632,7 +633,7 @@ impl<'a> CustomPropertiesBuilder<'a> {
|
||||||
None => return self.inherited.cloned(),
|
None => return self.inherited.cloned(),
|
||||||
};
|
};
|
||||||
if self.may_have_cycles {
|
if self.may_have_cycles {
|
||||||
substitute_all(&mut map, self.environment);
|
substitute_all(&mut map, self.device);
|
||||||
}
|
}
|
||||||
Some(Arc::new(map))
|
Some(Arc::new(map))
|
||||||
}
|
}
|
||||||
|
@ -641,7 +642,7 @@ impl<'a> CustomPropertiesBuilder<'a> {
|
||||||
/// Resolve all custom properties to either substituted or invalid.
|
/// Resolve all custom properties to either substituted or invalid.
|
||||||
///
|
///
|
||||||
/// It does cycle dependencies removal at the same time as substitution.
|
/// It does cycle dependencies removal at the same time as substitution.
|
||||||
fn substitute_all(custom_properties_map: &mut CustomPropertiesMap, environment: &CssEnvironment) {
|
fn substitute_all(custom_properties_map: &mut CustomPropertiesMap, device: &Device) {
|
||||||
// The cycle dependencies removal in this function is a variant
|
// The cycle dependencies removal in this function is a variant
|
||||||
// of Tarjan's algorithm. It is mostly based on the pseudo-code
|
// of Tarjan's algorithm. It is mostly based on the pseudo-code
|
||||||
// listed in
|
// listed in
|
||||||
|
@ -677,8 +678,8 @@ fn substitute_all(custom_properties_map: &mut CustomPropertiesMap, environment:
|
||||||
/// all unfinished strong connected components.
|
/// all unfinished strong connected components.
|
||||||
stack: SmallVec<[usize; 5]>,
|
stack: SmallVec<[usize; 5]>,
|
||||||
map: &'a mut CustomPropertiesMap,
|
map: &'a mut CustomPropertiesMap,
|
||||||
/// The environment to substitute `env()` variables.
|
/// to resolve the environment to substitute `env()` variables.
|
||||||
environment: &'a CssEnvironment,
|
device: &'a Device,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This function combines the traversal for cycle removal and value
|
/// This function combines the traversal for cycle removal and value
|
||||||
|
@ -813,7 +814,7 @@ fn substitute_all(custom_properties_map: &mut CustomPropertiesMap, environment:
|
||||||
// Now we have shown that this variable is not in a loop, and
|
// Now we have shown that this variable is not in a loop, and
|
||||||
// all of its dependencies should have been resolved. We can
|
// all of its dependencies should have been resolved. We can
|
||||||
// start substitution now.
|
// start substitution now.
|
||||||
let result = substitute_references_in_value(&value, &context.map, &context.environment);
|
let result = substitute_references_in_value(&value, &context.map, &context.device);
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
Ok(computed_value) => {
|
Ok(computed_value) => {
|
||||||
|
@ -838,7 +839,7 @@ fn substitute_all(custom_properties_map: &mut CustomPropertiesMap, environment:
|
||||||
stack: SmallVec::new(),
|
stack: SmallVec::new(),
|
||||||
var_info: SmallVec::new(),
|
var_info: SmallVec::new(),
|
||||||
map: custom_properties_map,
|
map: custom_properties_map,
|
||||||
environment,
|
device,
|
||||||
};
|
};
|
||||||
traverse(name, &mut context);
|
traverse(name, &mut context);
|
||||||
}
|
}
|
||||||
|
@ -848,7 +849,7 @@ fn substitute_all(custom_properties_map: &mut CustomPropertiesMap, environment:
|
||||||
fn substitute_references_in_value<'i>(
|
fn substitute_references_in_value<'i>(
|
||||||
value: &'i VariableValue,
|
value: &'i VariableValue,
|
||||||
custom_properties: &CustomPropertiesMap,
|
custom_properties: &CustomPropertiesMap,
|
||||||
environment: &CssEnvironment,
|
device: &Device,
|
||||||
) -> Result<ComputedValue, ParseError<'i>> {
|
) -> Result<ComputedValue, ParseError<'i>> {
|
||||||
debug_assert!(!value.references.is_empty() || value.references_environment);
|
debug_assert!(!value.references.is_empty() || value.references_environment);
|
||||||
|
|
||||||
|
@ -862,7 +863,7 @@ fn substitute_references_in_value<'i>(
|
||||||
&mut position,
|
&mut position,
|
||||||
&mut computed_value,
|
&mut computed_value,
|
||||||
custom_properties,
|
custom_properties,
|
||||||
environment,
|
device,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
computed_value.push_from(&input, position, last_token_type)?;
|
computed_value.push_from(&input, position, last_token_type)?;
|
||||||
|
@ -884,7 +885,7 @@ fn substitute_block<'i>(
|
||||||
position: &mut (SourcePosition, TokenSerializationType),
|
position: &mut (SourcePosition, TokenSerializationType),
|
||||||
partial_computed_value: &mut ComputedValue,
|
partial_computed_value: &mut ComputedValue,
|
||||||
custom_properties: &CustomPropertiesMap,
|
custom_properties: &CustomPropertiesMap,
|
||||||
env: &CssEnvironment,
|
device: &Device,
|
||||||
) -> Result<TokenSerializationType, ParseError<'i>> {
|
) -> Result<TokenSerializationType, ParseError<'i>> {
|
||||||
let mut last_token_type = TokenSerializationType::nothing();
|
let mut last_token_type = TokenSerializationType::nothing();
|
||||||
let mut set_position_at_next_iteration = false;
|
let mut set_position_at_next_iteration = false;
|
||||||
|
@ -929,7 +930,7 @@ fn substitute_block<'i>(
|
||||||
};
|
};
|
||||||
|
|
||||||
let value = if is_env {
|
let value = if is_env {
|
||||||
env.get(&name)
|
device.environment().get(&name)
|
||||||
} else {
|
} else {
|
||||||
custom_properties.get(&name).map(|v| &**v)
|
custom_properties.get(&name).map(|v| &**v)
|
||||||
};
|
};
|
||||||
|
@ -956,7 +957,7 @@ fn substitute_block<'i>(
|
||||||
&mut position,
|
&mut position,
|
||||||
partial_computed_value,
|
partial_computed_value,
|
||||||
custom_properties,
|
custom_properties,
|
||||||
env,
|
device,
|
||||||
)?;
|
)?;
|
||||||
partial_computed_value.push_from(input, position, last_token_type)?;
|
partial_computed_value.push_from(input, position, last_token_type)?;
|
||||||
}
|
}
|
||||||
|
@ -974,7 +975,7 @@ fn substitute_block<'i>(
|
||||||
position,
|
position,
|
||||||
partial_computed_value,
|
partial_computed_value,
|
||||||
custom_properties,
|
custom_properties,
|
||||||
env,
|
device,
|
||||||
)
|
)
|
||||||
})?;
|
})?;
|
||||||
// It's the same type for CloseCurlyBracket and CloseSquareBracket.
|
// It's the same type for CloseCurlyBracket and CloseSquareBracket.
|
||||||
|
@ -1000,7 +1001,7 @@ pub fn substitute<'i>(
|
||||||
input: &'i str,
|
input: &'i str,
|
||||||
first_token_type: TokenSerializationType,
|
first_token_type: TokenSerializationType,
|
||||||
computed_values_map: Option<&Arc<CustomPropertiesMap>>,
|
computed_values_map: Option<&Arc<CustomPropertiesMap>>,
|
||||||
env: &CssEnvironment,
|
device: &Device,
|
||||||
) -> Result<String, ParseError<'i>> {
|
) -> Result<String, ParseError<'i>> {
|
||||||
let mut substituted = ComputedValue::empty();
|
let mut substituted = ComputedValue::empty();
|
||||||
let mut input = ParserInput::new(input);
|
let mut input = ParserInput::new(input);
|
||||||
|
@ -1016,7 +1017,7 @@ pub fn substitute<'i>(
|
||||||
&mut position,
|
&mut position,
|
||||||
&mut substituted,
|
&mut substituted,
|
||||||
&custom_properties,
|
&custom_properties,
|
||||||
env,
|
device,
|
||||||
)?;
|
)?;
|
||||||
substituted.push_from(&input, position, last_token_type)?;
|
substituted.push_from(&input, position, last_token_type)?;
|
||||||
Ok(substituted.css)
|
Ok(substituted.css)
|
||||||
|
|
|
@ -250,7 +250,7 @@ where
|
||||||
let custom_properties = {
|
let custom_properties = {
|
||||||
let mut builder = CustomPropertiesBuilder::new(
|
let mut builder = CustomPropertiesBuilder::new(
|
||||||
inherited_style.custom_properties(),
|
inherited_style.custom_properties(),
|
||||||
device.environment(),
|
device,
|
||||||
);
|
);
|
||||||
|
|
||||||
for (declaration, origin) in iter_declarations() {
|
for (declaration, origin) in iter_declarations() {
|
||||||
|
@ -424,7 +424,7 @@ impl<'a, 'b: 'a> Cascade<'a, 'b> {
|
||||||
declaration.id,
|
declaration.id,
|
||||||
self.context.builder.custom_properties.as_ref(),
|
self.context.builder.custom_properties.as_ref(),
|
||||||
self.context.quirks_mode,
|
self.context.quirks_mode,
|
||||||
self.context.device().environment(),
|
self.context.device(),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::context::QuirksMode;
|
use crate::context::QuirksMode;
|
||||||
use crate::custom_properties::{CssEnvironment, CustomPropertiesBuilder};
|
use crate::custom_properties::CustomPropertiesBuilder;
|
||||||
use crate::error_reporting::{ContextualParseError, ParseErrorReporter};
|
use crate::error_reporting::{ContextualParseError, ParseErrorReporter};
|
||||||
use crate::parser::ParserContext;
|
use crate::parser::ParserContext;
|
||||||
use crate::properties::animated_properties::{AnimationValue, AnimationValueMap};
|
use crate::properties::animated_properties::{AnimationValue, AnimationValueMap};
|
||||||
|
@ -778,7 +778,7 @@ impl PropertyDeclarationBlock {
|
||||||
dest: &mut CssStringWriter,
|
dest: &mut CssStringWriter,
|
||||||
computed_values: Option<&ComputedValues>,
|
computed_values: Option<&ComputedValues>,
|
||||||
custom_properties_block: Option<&PropertyDeclarationBlock>,
|
custom_properties_block: Option<&PropertyDeclarationBlock>,
|
||||||
environment: &CssEnvironment,
|
device: &Device,
|
||||||
) -> fmt::Result {
|
) -> fmt::Result {
|
||||||
if let Ok(shorthand) = property.as_shorthand() {
|
if let Ok(shorthand) = property.as_shorthand() {
|
||||||
return self.shorthand_to_css(shorthand, dest);
|
return self.shorthand_to_css(shorthand, dest);
|
||||||
|
@ -797,7 +797,7 @@ impl PropertyDeclarationBlock {
|
||||||
if let Some(block) = custom_properties_block {
|
if let Some(block) = custom_properties_block {
|
||||||
// FIXME(emilio): This is not super-efficient here, and all this
|
// FIXME(emilio): This is not super-efficient here, and all this
|
||||||
// feels like a hack anyway...
|
// feels like a hack anyway...
|
||||||
block.cascade_custom_properties(cv.custom_properties(), environment)
|
block.cascade_custom_properties(cv.custom_properties(), device)
|
||||||
} else {
|
} else {
|
||||||
cv.custom_properties().cloned()
|
cv.custom_properties().cloned()
|
||||||
}
|
}
|
||||||
|
@ -820,7 +820,7 @@ impl PropertyDeclarationBlock {
|
||||||
declaration.id,
|
declaration.id,
|
||||||
custom_properties.as_ref(),
|
custom_properties.as_ref(),
|
||||||
QuirksMode::NoQuirks,
|
QuirksMode::NoQuirks,
|
||||||
environment,
|
device,
|
||||||
)
|
)
|
||||||
.to_css(dest)
|
.to_css(dest)
|
||||||
},
|
},
|
||||||
|
@ -868,7 +868,7 @@ impl PropertyDeclarationBlock {
|
||||||
) -> Option<Arc<crate::custom_properties::CustomPropertiesMap>> {
|
) -> Option<Arc<crate::custom_properties::CustomPropertiesMap>> {
|
||||||
self.cascade_custom_properties(
|
self.cascade_custom_properties(
|
||||||
context.style().custom_properties(),
|
context.style().custom_properties(),
|
||||||
context.device().environment(),
|
context.device(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -878,9 +878,9 @@ impl PropertyDeclarationBlock {
|
||||||
fn cascade_custom_properties(
|
fn cascade_custom_properties(
|
||||||
&self,
|
&self,
|
||||||
inherited_custom_properties: Option<&Arc<crate::custom_properties::CustomPropertiesMap>>,
|
inherited_custom_properties: Option<&Arc<crate::custom_properties::CustomPropertiesMap>>,
|
||||||
environment: &CssEnvironment,
|
device: &Device,
|
||||||
) -> Option<Arc<crate::custom_properties::CustomPropertiesMap>> {
|
) -> Option<Arc<crate::custom_properties::CustomPropertiesMap>> {
|
||||||
let mut builder = CustomPropertiesBuilder::new(inherited_custom_properties, environment);
|
let mut builder = CustomPropertiesBuilder::new(inherited_custom_properties, device);
|
||||||
|
|
||||||
for declaration in self.normal_declaration_iter() {
|
for declaration in self.normal_declaration_iter() {
|
||||||
if let PropertyDeclaration::Custom(ref declaration) = *declaration {
|
if let PropertyDeclaration::Custom(ref declaration) = *declaration {
|
||||||
|
|
|
@ -507,7 +507,7 @@ impl AnimationValue {
|
||||||
declaration.id,
|
declaration.id,
|
||||||
custom_properties,
|
custom_properties,
|
||||||
context.quirks_mode,
|
context.quirks_mode,
|
||||||
context.device().environment(),
|
context.device(),
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
return AnimationValue::from_declaration(
|
return AnimationValue::from_declaration(
|
||||||
|
|
|
@ -1584,7 +1584,7 @@ impl UnparsedValue {
|
||||||
longhand_id: LonghandId,
|
longhand_id: LonghandId,
|
||||||
custom_properties: Option<<&Arc<crate::custom_properties::CustomPropertiesMap>>,
|
custom_properties: Option<<&Arc<crate::custom_properties::CustomPropertiesMap>>,
|
||||||
quirks_mode: QuirksMode,
|
quirks_mode: QuirksMode,
|
||||||
environment: &::custom_properties::CssEnvironment,
|
device: &Device,
|
||||||
) -> PropertyDeclaration {
|
) -> PropertyDeclaration {
|
||||||
let invalid_at_computed_value_time = || {
|
let invalid_at_computed_value_time = || {
|
||||||
let keyword = if longhand_id.inherited() {
|
let keyword = if longhand_id.inherited() {
|
||||||
|
@ -1602,7 +1602,7 @@ impl UnparsedValue {
|
||||||
&self.css,
|
&self.css,
|
||||||
self.first_token_type,
|
self.first_token_type,
|
||||||
custom_properties,
|
custom_properties,
|
||||||
environment,
|
device,
|
||||||
) {
|
) {
|
||||||
Ok(css) => css,
|
Ok(css) => css,
|
||||||
Err(..) => return invalid_at_computed_value_time(),
|
Err(..) => return invalid_at_computed_value_time(),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue