Skip to content

Commit

Permalink
style: Fix some rebase messups from the rule tree refactoring.
Browse files Browse the repository at this point in the history
This code was all long gone already from Gecko :)
  • Loading branch information
emilio committed Apr 18, 2020
1 parent 83ea321 commit b80d798
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 219 deletions.
192 changes: 0 additions & 192 deletions components/style/rule_tree/mod.rs
Expand Up @@ -353,198 +353,6 @@ impl StrongRuleNode {
}
}

/// Returns true if any properties specified by `rule_type_mask` was set by
/// an author rule.
#[cfg(feature = "gecko")]
pub fn has_author_specified_rules<E>(
&self,
mut element: E,
mut pseudo: Option<PseudoElement>,
guards: &StylesheetGuards,
rule_type_mask: u32,
author_colors_allowed: bool,
) -> bool
where
E: crate::dom::TElement,
{
use crate::gecko_bindings::structs::NS_AUTHOR_SPECIFIED_BACKGROUND;
use crate::gecko_bindings::structs::NS_AUTHOR_SPECIFIED_BORDER;
use crate::gecko_bindings::structs::NS_AUTHOR_SPECIFIED_PADDING;
use crate::properties::{CSSWideKeyword, LonghandId};
use crate::properties::{PropertyDeclaration, PropertyDeclarationId};
use std::borrow::Cow;

// Reset properties:
const BACKGROUND_PROPS: &'static [LonghandId] =
&[LonghandId::BackgroundColor, LonghandId::BackgroundImage];

const BORDER_PROPS: &'static [LonghandId] = &[
LonghandId::BorderTopColor,
LonghandId::BorderTopStyle,
LonghandId::BorderTopWidth,
LonghandId::BorderRightColor,
LonghandId::BorderRightStyle,
LonghandId::BorderRightWidth,
LonghandId::BorderBottomColor,
LonghandId::BorderBottomStyle,
LonghandId::BorderBottomWidth,
LonghandId::BorderLeftColor,
LonghandId::BorderLeftStyle,
LonghandId::BorderLeftWidth,
LonghandId::BorderTopLeftRadius,
LonghandId::BorderTopRightRadius,
LonghandId::BorderBottomRightRadius,
LonghandId::BorderBottomLeftRadius,
LonghandId::BorderInlineStartColor,
LonghandId::BorderInlineStartStyle,
LonghandId::BorderInlineStartWidth,
LonghandId::BorderInlineEndColor,
LonghandId::BorderInlineEndStyle,
LonghandId::BorderInlineEndWidth,
LonghandId::BorderBlockStartColor,
LonghandId::BorderBlockStartStyle,
LonghandId::BorderBlockStartWidth,
LonghandId::BorderBlockEndColor,
LonghandId::BorderBlockEndStyle,
LonghandId::BorderBlockEndWidth,
];

const PADDING_PROPS: &'static [LonghandId] = &[
LonghandId::PaddingTop,
LonghandId::PaddingRight,
LonghandId::PaddingBottom,
LonghandId::PaddingLeft,
LonghandId::PaddingInlineStart,
LonghandId::PaddingInlineEnd,
LonghandId::PaddingBlockStart,
LonghandId::PaddingBlockEnd,
];

// Set of properties that we are currently interested in.
let mut properties = LonghandIdSet::new();

if rule_type_mask & NS_AUTHOR_SPECIFIED_BACKGROUND != 0 {
for id in BACKGROUND_PROPS {
properties.insert(*id);
}
}
if rule_type_mask & NS_AUTHOR_SPECIFIED_BORDER != 0 {
for id in BORDER_PROPS {
properties.insert(*id);
}
}
if rule_type_mask & NS_AUTHOR_SPECIFIED_PADDING != 0 {
for id in PADDING_PROPS {
properties.insert(*id);
}
}

// If author colors are not allowed, don't look at those properties
// (except for background-color which is special and we handle below).
if !author_colors_allowed {
properties.remove_all(LonghandIdSet::ignored_when_colors_disabled());
if rule_type_mask & NS_AUTHOR_SPECIFIED_BACKGROUND != 0 {
properties.insert(LonghandId::BackgroundColor);
}
}

let mut element_rule_node = Cow::Borrowed(self);

loop {
// We need to be careful not to count styles covered up by
// user-important or UA-important declarations. But we do want to
// catch explicit inherit styling in those and check our parent
// element to see whether we have user styling for those properties.
// Note that we don't care here about inheritance due to lack of a
// specified value, since all the properties we care about are reset
// properties.

let mut inherited_properties = LonghandIdSet::new();
let mut have_explicit_ua_inherit = false;

for node in element_rule_node.self_and_ancestors() {
let source = node.style_source();
let declarations = if source.is_some() {
source
.as_ref()
.unwrap()
.read(node.cascade_level().guard(guards))
.declaration_importance_iter()
} else {
continue;
};

// Iterate over declarations of the longhands we care about.
let node_importance = node.importance();
let longhands = declarations.rev().filter_map(|(declaration, importance)| {
if importance != node_importance {
return None;
}
match declaration.id() {
PropertyDeclarationId::Longhand(id) => Some((id, declaration)),
_ => None,
}
});

let is_author = node.cascade_level().origin() == Origin::Author;
for (id, declaration) in longhands {
if !properties.contains(id) {
continue;
}

if is_author {
if !author_colors_allowed {
if let PropertyDeclaration::BackgroundColor(ref color) = *declaration {
if color.is_transparent() {
return true;
}
continue;
}
}
return true;
}

// This property was set by a non-author rule.
// Stop looking for it in this element's rule
// nodes.
properties.remove(id);

// However, if it is inherited, then it might be
// inherited from an author rule from an
// ancestor element's rule nodes.
if declaration.get_css_wide_keyword() == Some(CSSWideKeyword::Inherit) {
have_explicit_ua_inherit = true;
inherited_properties.insert(id);
}
}
}

if !have_explicit_ua_inherit {
break;
}

// Continue to the parent element and search for the inherited properties.
if let Some(pseudo) = pseudo.take() {
if pseudo.inherits_from_default_values() {
break;
}
} else {
element = match element.inheritance_parent() {
Some(parent) => parent,
None => break,
};

let parent_data = element.mutate_data().unwrap();
let parent_rule_node = parent_data.styles.primary().rules().clone();
element_rule_node = Cow::Owned(parent_rule_node);
}

properties = inherited_properties;
}

false
}

/// Returns true if there is either animation or transition level rule.
pub fn has_animation_or_transition_rules(&self) -> bool {
self.self_and_ancestors()
Expand Down
28 changes: 1 addition & 27 deletions components/style/rule_tree/source.rs
Expand Up @@ -2,8 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

// FIXME: Make that forbid once the two unsafe gecko-specific methods are removed.
#![deny(unsafe_code)]
#![forbid(unsafe_code)]

use crate::properties::PropertyDeclarationBlock;
use crate::shared_lock::{Locked, SharedRwLockReadGuard};
Expand Down Expand Up @@ -53,31 +52,6 @@ impl StyleSource {
let _ = write!(writer, " -> {:?}", self.read(guard).declarations());
}

// This is totally unsafe, should be removed when we figure out the cause of
// bug 1607553.
#[allow(unsafe_code)]
#[cfg(feature = "gecko")]
pub(super) unsafe fn dump_unchecked<W: Write>(&self, writer: &mut W) {
if let Some(ref rule) = self.0.as_first() {
let rule = rule.read_unchecked();
let _ = write!(writer, "{:?}", rule.selectors);
}
let _ = write!(writer, " -> {:?}", self.read_unchecked().declarations());
}

// This is totally unsafe, should be removed when we figure out the cause of
// bug 1607553.
#[inline]
#[allow(unsafe_code)]
#[cfg(feature = "gecko")]
pub(super) unsafe fn read_unchecked(&self) -> &PropertyDeclarationBlock {
let block: &Locked<PropertyDeclarationBlock> = match self.0.borrow() {
ArcUnionBorrow::First(ref rule) => &rule.get().read_unchecked().block,
ArcUnionBorrow::Second(ref block) => block.get(),
};
block.read_unchecked()
}

/// Read the style source guard, and obtain thus read access to the
/// underlying property declaration block.
#[inline]
Expand Down

0 comments on commit b80d798

Please sign in to comment.