summaryrefslogtreecommitdiff
path: root/src/eval/styles.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-02-08 16:39:37 +0100
committerLaurenz <laurmaedje@gmail.com>2022-02-09 12:34:19 +0100
commite089b6ea40015e012302dc55ac5d6cb42ca4876e (patch)
treedbb66237cb996bc880560dfd94ac9b682e1ac985 /src/eval/styles.rs
parent68503b9a07b00bce3f4d377bcfe945452de815ea (diff)
Set rules for everything
Diffstat (limited to 'src/eval/styles.rs')
-rw-r--r--src/eval/styles.rs30
1 files changed, 16 insertions, 14 deletions
diff --git a/src/eval/styles.rs b/src/eval/styles.rs
index 863dcc6f..2bf3f239 100644
--- a/src/eval/styles.rs
+++ b/src/eval/styles.rs
@@ -49,6 +49,11 @@ impl StyleMap {
self
}
+ /// Whether this map contains scoped styles.
+ pub fn has_scoped(&self) -> bool {
+ self.0.iter().any(|e| e.scoped)
+ }
+
/// Make `self` the first link of the style chain `outer`.
///
/// The resulting style chain contains styles from `self` as well as
@@ -136,20 +141,6 @@ impl<'a> StyleChain<'a> {
self.links().count()
}
- /// Convert to an owned style map.
- ///
- /// Panics if the chain contains barrier links.
- pub fn to_map(self) -> StyleMap {
- let mut suffix = StyleMap::new();
- for link in self.links() {
- match link {
- Link::Map(map) => suffix.apply(map),
- Link::Barrier(_) => panic!("chain contains barrier"),
- }
- }
- suffix
- }
-
/// Build a style map from the suffix (all links beyond the `len`) of the
/// chain.
///
@@ -170,6 +161,17 @@ impl<'a> StyleChain<'a> {
pub fn pop(&mut self) {
*self = self.outer.copied().unwrap_or_default();
}
+
+ /// Return the chain, but without the last link if that one contains only
+ /// scoped styles. This is a hack.
+ pub(crate) fn unscoped(mut self, node: TypeId) -> Self {
+ if let Some(Link::Map(map)) = self.link {
+ if map.0.iter().all(|e| e.scoped && e.is_of_id(node)) {
+ self.pop();
+ }
+ }
+ self
+ }
}
impl<'a> StyleChain<'a> {