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