[librsvg: 1/8] Make DeclarationList a real type, so we can change it later
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 1/8] Make DeclarationList a real type, so we can change it later
- Date: Fri, 3 May 2019 19:25:27 +0000 (UTC)
commit d65548c6ec9eb25b7593f312b1843b76765466d5
Author: Federico Mena Quintero <federico gnome org>
Date: Fri May 3 12:32:17 2019 -0500
Make DeclarationList a real type, so we can change it later
rsvg_internals/src/css.rs | 46 ++++++++++++++++++++++++++++++----------------
1 file changed, 30 insertions(+), 16 deletions(-)
---
diff --git a/rsvg_internals/src/css.rs b/rsvg_internals/src/css.rs
index 3ecbd8af..00032b24 100644
--- a/rsvg_internals/src/css.rs
+++ b/rsvg_internals/src/css.rs
@@ -18,8 +18,10 @@ use crate::io::{self, BinaryData};
use crate::properties::{parse_attribute_value_into_parsed_property, Declaration, SpecifiedValues};
use crate::util::utf8_cstr;
-// Maps property_name -> Declaration
-type DeclarationList = HashMap<Attribute, Declaration>;
+pub struct DeclarationList {
+ // Maps property_name -> Declaration
+ declarations: HashMap<Attribute, Declaration>,
+}
type Selector = String;
@@ -29,6 +31,30 @@ pub struct CssRules {
selectors_to_declarations: HashMap<Selector, DeclarationList>,
}
+impl DeclarationList {
+ fn new() -> DeclarationList {
+ DeclarationList {
+ declarations: HashMap::new(),
+ }
+ }
+
+ fn add_declaration(&mut self, declaration: Declaration) {
+ match self.declarations.entry(declaration.attribute) {
+ Entry::Occupied(mut e) => {
+ let decl = e.get_mut();
+
+ if !decl.important {
+ *decl = declaration;
+ }
+ }
+
+ Entry::Vacant(v) => {
+ v.insert(declaration);
+ }
+ }
+ }
+}
+
impl CssRules {
pub fn new() -> CssRules {
CssRules {
@@ -108,19 +134,7 @@ impl CssRules {
.entry(selector.to_string())
.or_insert_with(|| DeclarationList::new());
- match decl_list.entry(declaration.attribute) {
- Entry::Occupied(mut e) => {
- let decl = e.get_mut();
-
- if !decl.important {
- *decl = declaration;
- }
- }
-
- Entry::Vacant(v) => {
- v.insert(declaration);
- }
- }
+ decl_list.add_declaration(declaration);
}
/// Takes CSS rules which match the given `selector` name and applies them
@@ -132,7 +146,7 @@ impl CssRules {
important_styles: &mut HashSet<Attribute>,
) -> bool {
if let Some(decl_list) = self.selectors_to_declarations.get(selector) {
- for (_, declaration) in decl_list.iter() {
+ for (_, declaration) in decl_list.declarations.iter() {
values.set_property_from_declaration(declaration, important_styles);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]