[librsvg: 4/8] try_apply_by_selector(): move function from CssRules::lookup_apply()
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 4/8] try_apply_by_selector(): move function from CssRules::lookup_apply()
- Date: Fri, 3 May 2019 19:25:42 +0000 (UTC)
commit c24679b91b2af2bdcb7554dfbd870b51f866dfaf
Author: Federico Mena Quintero <federico gnome org>
Date: Fri May 3 13:23:10 2019 -0500
try_apply_by_selector(): move function from CssRules::lookup_apply()
CssRules should not have to deal with SpecifiedValues nor the stateful
important_styles.
rsvg_internals/src/css.rs | 23 ++---------------------
rsvg_internals/src/node.rs | 39 +++++++++++++++++++++++++++++++--------
2 files changed, 33 insertions(+), 29 deletions(-)
---
diff --git a/rsvg_internals/src/css.rs b/rsvg_internals/src/css.rs
index a41e683a..2a12cb2d 100644
--- a/rsvg_internals/src/css.rs
+++ b/rsvg_internals/src/css.rs
@@ -1,6 +1,6 @@
use cssparser::{Parser, ParserInput};
use std::collections::hash_map::{Entry, Iter as HashMapIter};
-use std::collections::{HashMap, HashSet};
+use std::collections::HashMap;
use std::ptr;
use std::str::{self, FromStr};
@@ -15,7 +15,7 @@ use crate::attributes::Attribute;
use crate::croco::*;
use crate::error::LoadingError;
use crate::io::{self, BinaryData};
-use crate::properties::{parse_attribute_value_into_parsed_property, Declaration, SpecifiedValues};
+use crate::properties::{parse_attribute_value_into_parsed_property, Declaration};
use crate::util::utf8_cstr;
pub struct DeclarationList {
@@ -154,25 +154,6 @@ impl CssRules {
pub fn lookup(&self, selector: &str) -> Option<&DeclarationList> {
self.selectors_to_declarations.get(selector)
}
-
- /// takes CSS rules which match the given `selector` name and applies them
- /// to the `values`.
- pub fn lookup_apply(
- &self,
- selector: &str,
- values: &mut SpecifiedValues,
- important_styles: &mut HashSet<Attribute>,
- ) -> bool {
- if let Some(decl_list) = self.lookup(selector) {
- for declaration in decl_list.iter() {
- values.set_property_from_declaration(declaration, important_styles);
- }
-
- true
- } else {
- false
- }
- }
}
struct DocHandlerData<'a> {
diff --git a/rsvg_internals/src/node.rs b/rsvg_internals/src/node.rs
index 34f9c948..b5feb698 100644
--- a/rsvg_internals/src/node.rs
+++ b/rsvg_internals/src/node.rs
@@ -461,10 +461,10 @@ impl Node {
let mut important_styles = self.data.important_styles.borrow_mut();
// *
- css_rules.lookup_apply("*", &mut specified_values, &mut important_styles);
+ try_apply_by_selector(css_rules, "*", &mut specified_values, &mut important_styles);
// tag
- css_rules.lookup_apply(element_name, &mut specified_values, &mut important_styles);
+ try_apply_by_selector(css_rules, element_name, &mut specified_values, &mut important_styles);
if let Some(klazz) = self.get_class() {
for cls in klazz.split_whitespace() {
@@ -475,7 +475,8 @@ impl Node {
if let Some(id) = self.get_id() {
let target = format!("{}.{}#{}", element_name, cls, id);
found = found
- || css_rules.lookup_apply(
+ || try_apply_by_selector(
+ css_rules,
&target,
&mut specified_values,
&mut important_styles,
@@ -486,7 +487,8 @@ impl Node {
if let Some(id) = self.get_id() {
let target = format!(".{}#{}", cls, id);
found = found
- || css_rules.lookup_apply(
+ || try_apply_by_selector(
+ css_rules,
&target,
&mut specified_values,
&mut important_styles,
@@ -496,7 +498,8 @@ impl Node {
// tag.class
let target = format!("{}.{}", element_name, cls);
found = found
- || css_rules.lookup_apply(
+ || try_apply_by_selector(
+ css_rules,
&target,
&mut specified_values,
&mut important_styles,
@@ -505,7 +508,8 @@ impl Node {
if !found {
// didn't find anything more specific, just apply the class style
let target = format!(".{}", cls);
- css_rules.lookup_apply(
+ try_apply_by_selector(
+ css_rules,
&target,
&mut specified_values,
&mut important_styles,
@@ -518,11 +522,11 @@ impl Node {
if let Some(id) = self.get_id() {
// id
let target = format!("#{}", id);
- css_rules.lookup_apply(&target, &mut specified_values, &mut important_styles);
+ try_apply_by_selector(css_rules, &target, &mut specified_values, &mut important_styles);
// tag#id
let target = format!("{}#{}", element_name, id);
- css_rules.lookup_apply(&target, &mut specified_values, &mut important_styles);
+ try_apply_by_selector(css_rules, &target, &mut specified_values, &mut important_styles);
}
}
@@ -677,3 +681,22 @@ pub fn node_new(
node_impl,
))
}
+
+/// takes CSS rules which match the given `selector` name and applies them
+/// to the `values`.
+pub fn try_apply_by_selector(
+ css_rules: &CssRules,
+ selector: &str,
+ values: &mut SpecifiedValues,
+ important_styles: &mut HashSet<Attribute>,
+) -> bool {
+ if let Some(decl_list) = css_rules.lookup(selector) {
+ for declaration in decl_list.iter() {
+ values.set_property_from_declaration(declaration, important_styles);
+ }
+
+ true
+ } else {
+ false
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]