Skip to content
Permalink
Browse files

style: Rustfmt recent changes.

  • Loading branch information
emilio committed Nov 30, 2019
1 parent 59eef57 commit 006417e40ace554db56d98b2df44f04f776268df
@@ -36,12 +36,15 @@ const CASCADE_LEVEL_SHIFT: usize = SOURCE_ORDER_BITS;

/// Stores the source order of a block, the cascade level it belongs to, and the
/// counter needed to handle Shadow DOM cascade order properly.
#[derive(Clone, Copy, Eq, MallocSizeOf, PartialEq, Debug)]
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, PartialEq)]
struct ApplicableDeclarationBits(u32);

impl ApplicableDeclarationBits {
fn new(source_order: u32, cascade_level: CascadeLevel) -> Self {
Self((source_order & SOURCE_ORDER_MASK) | ((cascade_level.to_byte_lossy() as u32) << CASCADE_LEVEL_SHIFT))
Self(
(source_order & SOURCE_ORDER_MASK) |
((cascade_level.to_byte_lossy() as u32) << CASCADE_LEVEL_SHIFT),
)
}

fn source_order(&self) -> u32 {
@@ -87,12 +90,7 @@ impl ApplicableDeclarationBlock {

/// Constructs an applicable declaration block from the given components
#[inline]
pub fn new(
source: StyleSource,
order: u32,
level: CascadeLevel,
specificity: u32,
) -> Self {
pub fn new(source: StyleSource, order: u32, level: CascadeLevel, specificity: u32) -> Self {
ApplicableDeclarationBlock {
source,
bits: ApplicableDeclarationBits::new(order, level),
@@ -83,7 +83,10 @@ pub fn get_id(attrs: &[structs::AttrArray_InternalAttr]) -> Option<&WeakAtom> {
}

#[inline(always)]
pub(super) fn exported_part(attrs: &[structs::AttrArray_InternalAttr], name: &Atom) -> Option<Atom> {
pub(super) fn exported_part(
attrs: &[structs::AttrArray_InternalAttr],
name: &Atom,
) -> Option<Atom> {
let attr = find_attr(attrs, &atom!("exportparts"))?;
let atom = unsafe { bindings::Gecko_Element_ExportedPart(attr, name.as_ptr()) };
if atom.is_null() {
@@ -93,7 +96,10 @@ pub(super) fn exported_part(attrs: &[structs::AttrArray_InternalAttr], name: &At
}

#[inline(always)]
pub(super) fn imported_part(attrs: &[structs::AttrArray_InternalAttr], name: &Atom) -> Option<Atom> {
pub(super) fn imported_part(
attrs: &[structs::AttrArray_InternalAttr],
name: &Atom,
) -> Option<Atom> {
let attr = find_attr(attrs, &atom!("exportparts"))?;
let atom = unsafe { bindings::Gecko_Element_ImportedPart(attr, name.as_ptr()) };
if atom.is_null() {
@@ -1244,7 +1244,8 @@ impl<'le> TElement for GeckoElement<'le> {

#[inline]
fn has_part_attr(&self) -> bool {
self.as_node().get_bool_flag(nsINode_BooleanFlag::ElementHasPart)
self.as_node()
.get_bool_flag(nsINode_BooleanFlag::ElementHasPart)
}

#[inline]
@@ -2193,7 +2194,8 @@ impl<'le> ::selectors::Element for GeckoElement<'le> {

#[inline]
fn is_link(&self) -> bool {
self.state().intersects(ElementState::IN_VISITED_OR_UNVISITED_STATE)
self.state()
.intersects(ElementState::IN_VISITED_OR_UNVISITED_STATE)
}

#[inline]
@@ -392,7 +392,8 @@ impl Atom {
// though.
//
// debug_assert!((index as usize) < STATIC_ATOM_COUNT);
let offset = (index as usize) * std::mem::size_of::<nsStaticAtom>() + kGkAtomsArrayOffset as usize;
let offset =
(index as usize) * std::mem::size_of::<nsStaticAtom>() + kGkAtomsArrayOffset as usize;
Atom(NonZeroUsize::new_unchecked((offset << 1) | 1))
}

@@ -8,10 +8,10 @@
use crate::context::StackLimitChecker;
use crate::dom::{TElement, TNode, TShadowRoot};
use crate::selector_parser::SelectorImpl;
use selectors::OpaqueElement;
use selectors::matching::matches_compound_selector_from;
use selectors::matching::{CompoundSelectorMatchingResult, MatchingContext};
use selectors::parser::{Combinator, Component, Selector};
use selectors::OpaqueElement;
use smallvec::SmallVec;
use std::fmt;

@@ -4,7 +4,6 @@

//! Collects a series of applicable rules for a given element.

use crate::Atom;
use crate::applicable_declarations::{ApplicableDeclarationBlock, ApplicableDeclarationList};
use crate::dom::{TElement, TNode, TShadowRoot};
use crate::properties::{AnimationRules, PropertyDeclarationBlock};
@@ -14,6 +13,7 @@ use crate::selector_parser::PseudoElement;
use crate::shared_lock::Locked;
use crate::stylesheets::Origin;
use crate::stylist::{AuthorStylesEnabled, Rule, RuleInclusion, Stylist};
use crate::Atom;
use selectors::matching::{ElementSelectorFlags, MatchingContext, MatchingMode};
use servo_arc::ArcBorrow;
use smallvec::SmallVec;
@@ -261,7 +261,9 @@ where
self.collect_rules_in_shadow_tree(
shadow.host(),
slotted_rules,
CascadeLevel::AuthorNormal { shadow_cascade_order },
CascadeLevel::AuthorNormal {
shadow_cascade_order,
},
);
}
}
@@ -312,7 +314,9 @@ where
self.collect_rules_in_shadow_tree(
rule_hash_target,
host_rules,
CascadeLevel::AuthorNormal { shadow_cascade_order },
CascadeLevel::AuthorNormal {
shadow_cascade_order,
},
);
}

@@ -283,7 +283,9 @@ impl RuleTree {
if any_important {
found_important = true;
match level {
AuthorNormal { shadow_cascade_order } => {
AuthorNormal {
shadow_cascade_order,
} => {
important_author.push((source.clone(), shadow_cascade_order));
},
UANormal => important_ua.push(source.clone()),
@@ -344,9 +346,13 @@ impl RuleTree {
}

for (source, shadow_cascade_order) in important_author.drain() {
current = current.ensure_child(self.root.downgrade(), source, AuthorImportant {
shadow_cascade_order: -shadow_cascade_order,
});
current = current.ensure_child(
self.root.downgrade(),
source,
AuthorImportant {
shadow_cascade_order: -shadow_cascade_order,
},
);
}

for source in important_user.drain() {
@@ -496,12 +502,7 @@ impl RuleTree {
if current.get().level == level {
*important_rules_changed |= level.is_important();

let current_decls = current
.get()
.source
.as_ref()
.unwrap()
.as_declarations();
let current_decls = current.get().source.as_ref().unwrap().as_declarations();

// If the only rule at the level we're replacing is exactly the
// same as `pdb`, we're done, and `path` is still valid.
@@ -701,10 +702,14 @@ impl CascadeLevel {
Self::UANormal => (0, 0),
Self::UserNormal => (1, 0),
Self::PresHints => (2, 0),
Self::AuthorNormal { shadow_cascade_order } => (3, shadow_cascade_order.0),
Self::AuthorNormal {
shadow_cascade_order,
} => (3, shadow_cascade_order.0),
Self::SMILOverride => (4, 0),
Self::Animations => (5, 0),
Self::AuthorImportant { shadow_cascade_order } => (6, shadow_cascade_order.0),
Self::AuthorImportant {
shadow_cascade_order,
} => (6, shadow_cascade_order.0),
Self::UserImportant => (7, 0),
Self::UAImportant => (8, 0),
Self::Transitions => (9, 0),
@@ -727,20 +732,28 @@ impl CascadeLevel {
let order = {
let abs = ((b & 0b01110000) >> 4) as i8;
let negative = b & 0b10000000 != 0;
if negative { -abs } else { abs }
if negative {
-abs
} else {
abs
}
};
let discriminant = b & 0xf;
let level = match discriminant {
0 => Self::UANormal,
1 => Self::UserNormal,
2 => Self::PresHints,
3 => return Self::AuthorNormal {
shadow_cascade_order: ShadowCascadeOrder(order),
3 => {
return Self::AuthorNormal {
shadow_cascade_order: ShadowCascadeOrder(order),
}
},
4 => Self::SMILOverride,
5 => Self::Animations,
6 => return Self::AuthorImportant {
shadow_cascade_order: ShadowCascadeOrder(order),
6 => {
return Self::AuthorImportant {
shadow_cascade_order: ShadowCascadeOrder(order),
}
},
7 => Self::UserImportant,
8 => Self::UAImportant,
@@ -1550,9 +1563,7 @@ impl StrongRuleNode {
// FIXME(emilio): this looks wrong, this should
// do: if color is not transparent, then return
// true, or something.
if let PropertyDeclaration::BackgroundColor(ref color) =
*declaration
{
if let PropertyDeclaration::BackgroundColor(ref color) = *declaration {
return *color == Color::transparent();
}
}
@@ -1567,9 +1578,7 @@ impl StrongRuleNode {
// 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)
{
if declaration.get_css_wide_keyword() == Some(CSSWideKeyword::Inherit) {
have_explicit_ua_inherit = true;
inherited_properties.insert(id);
}
@@ -271,9 +271,7 @@ impl SelectorMap<Rule> {
context,
flags_setter,
) {
matching_rules.push(
rule.to_applicable_declaration_block(cascade_level),
);
matching_rules.push(rule.to_applicable_declaration_block(cascade_level));
}
}
}
@@ -2325,12 +2325,7 @@ impl Rule {
level: CascadeLevel,
) -> ApplicableDeclarationBlock {
let source = StyleSource::from_rule(self.style_rule.clone());
ApplicableDeclarationBlock::new(
source,
self.source_order,
level,
self.specificity(),
)
ApplicableDeclarationBlock::new(source, self.source_order, level, self.specificity())
}

/// Creates a new Rule.

0 comments on commit 006417e

Please sign in to comment.
You can’t perform that action at this time.