[librsvg: 2/10] Rename CssStyles to CssRules
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 2/10] Rename CssStyles to CssRules
- Date: Thu, 2 May 2019 15:33:59 +0000 (UTC)
commit 9dfa49137c793761abf50b7ef36674c592f2daa3
Author: Federico Mena Quintero <federico gnome org>
Date: Tue Apr 30 21:30:57 2019 -0500
Rename CssStyles to CssRules
That struct holds the rules, i.e. the mapping of selectors to
declaration lists.
rsvg_internals/src/css.rs | 18 ++++++++++--------
rsvg_internals/src/node.rs | 24 ++++++++++++------------
rsvg_internals/src/structure.rs | 6 +++---
rsvg_internals/src/xml.rs | 18 +++++++++---------
4 files changed, 34 insertions(+), 32 deletions(-)
---
diff --git a/rsvg_internals/src/css.rs b/rsvg_internals/src/css.rs
index 8d5ca8c0..9bec5ba1 100644
--- a/rsvg_internals/src/css.rs
+++ b/rsvg_internals/src/css.rs
@@ -25,13 +25,15 @@ struct Declaration {
// Maps property_name -> Declaration
type DeclarationList = HashMap<String, Declaration>;
-pub struct CssStyles {
+/// Contains all the mappings of selectors to style declarations
+/// that result from loading an SVG document.
+pub struct CssRules {
selectors_to_declarations: HashMap<String, DeclarationList>,
}
-impl CssStyles {
- pub fn new() -> CssStyles {
- CssStyles {
+impl CssRules {
+ pub fn new() -> CssRules {
+ CssRules {
selectors_to_declarations: HashMap::new(),
}
}
@@ -44,7 +46,7 @@ impl CssStyles {
unsafe {
let mut handler_data = DocHandlerData {
base_url,
- css_styles: self,
+ css_rules: self,
selector: ptr::null_mut(),
};
@@ -155,7 +157,7 @@ impl CssStyles {
struct DocHandlerData<'a> {
base_url: Option<&'a Url>,
- css_styles: &'a mut CssStyles,
+ css_rules: &'a mut CssRules,
selector: *mut CRSelector,
}
@@ -192,7 +194,7 @@ unsafe extern "C" fn css_import_style(
if let Ok(aurl) = AllowedUrl::from_href(uri, handler_data.base_url) {
// FIXME: handle CSS errors
- let _ = handler_data.css_styles.load_css(&aurl);
+ let _ = handler_data.css_rules.load_css(&aurl);
} else {
rsvg_log!("disallowed URL \"{}\" for importing CSS", uri);
}
@@ -250,7 +252,7 @@ unsafe extern "C" fn css_property(
let important = from_glib(a_is_important);
handler_data
- .css_styles
+ .css_rules
.define(&selector_name, prop_name, &prop_value, important);
}
}
diff --git a/rsvg_internals/src/node.rs b/rsvg_internals/src/node.rs
index a2486dba..ba3e2cd5 100644
--- a/rsvg_internals/src/node.rs
+++ b/rsvg_internals/src/node.rs
@@ -6,7 +6,7 @@ use std::rc::{Rc, Weak};
use crate::attributes::Attribute;
use crate::cond::{RequiredExtensions, RequiredFeatures, SystemLanguage};
-use crate::css::CssStyles;
+use crate::css::CssRules;
use crate::drawing_ctx::DrawingCtx;
use crate::error::*;
use crate::parsers::Parse;
@@ -449,7 +449,7 @@ impl Node {
}
/// Implements a very limited CSS selection engine
- fn set_css_styles(&self, css_styles: &CssStyles) {
+ fn set_css_styles(&self, css_rules: &CssRules) {
// Try to properly support all of the following, including inheritance:
// *
// #id
@@ -465,10 +465,10 @@ impl Node {
let mut important_styles = self.data.important_styles.borrow_mut();
// *
- css_styles.lookup_apply("*", &mut specified_values, &mut important_styles);
+ css_rules.lookup_apply("*", &mut specified_values, &mut important_styles);
// tag
- css_styles.lookup_apply(element_name, &mut specified_values, &mut important_styles);
+ css_rules.lookup_apply(element_name, &mut specified_values, &mut important_styles);
if let Some(klazz) = self.get_class() {
for cls in klazz.split_whitespace() {
@@ -479,7 +479,7 @@ impl Node {
if let Some(id) = self.get_id() {
let target = format!("{}.{}#{}", element_name, cls, id);
found = found
- || css_styles.lookup_apply(
+ || css_rules.lookup_apply(
&target,
&mut specified_values,
&mut important_styles,
@@ -490,7 +490,7 @@ impl Node {
if let Some(id) = self.get_id() {
let target = format!(".{}#{}", cls, id);
found = found
- || css_styles.lookup_apply(
+ || css_rules.lookup_apply(
&target,
&mut specified_values,
&mut important_styles,
@@ -500,7 +500,7 @@ impl Node {
// tag.class
let target = format!("{}.{}", element_name, cls);
found = found
- || css_styles.lookup_apply(
+ || css_rules.lookup_apply(
&target,
&mut specified_values,
&mut important_styles,
@@ -509,7 +509,7 @@ impl Node {
if !found {
// didn't find anything more specific, just apply the class style
let target = format!(".{}", cls);
- css_styles.lookup_apply(
+ css_rules.lookup_apply(
&target,
&mut specified_values,
&mut important_styles,
@@ -522,11 +522,11 @@ impl Node {
if let Some(id) = self.get_id() {
// id
let target = format!("#{}", id);
- css_styles.lookup_apply(&target, &mut specified_values, &mut important_styles);
+ css_rules.lookup_apply(&target, &mut specified_values, &mut important_styles);
// tag#id
let target = format!("{}#{}", element_name, id);
- css_styles.lookup_apply(&target, &mut specified_values, &mut important_styles);
+ css_rules.lookup_apply(&target, &mut specified_values, &mut important_styles);
}
}
@@ -555,9 +555,9 @@ impl Node {
// Sets the node's specified values from the style-related attributes in the pbag.
// Also applies CSS rules in our limited way based on the node's tag/class/id.
- pub fn set_style(&self, css_styles: &CssStyles, pbag: &PropertyBag<'_>) {
+ pub fn set_style(&self, css_rules: &CssRules, pbag: &PropertyBag<'_>) {
self.set_presentation_attributes(pbag);
- self.set_css_styles(css_styles);
+ self.set_css_styles(css_rules);
self.set_style_attribute(pbag);
}
diff --git a/rsvg_internals/src/structure.rs b/rsvg_internals/src/structure.rs
index 77a9ff93..a17120cc 100644
--- a/rsvg_internals/src/structure.rs
+++ b/rsvg_internals/src/structure.rs
@@ -6,7 +6,7 @@ use cairo::Rectangle;
use crate::allowed_url::Fragment;
use crate::aspect_ratio::*;
use crate::attributes::Attribute;
-use crate::css::CssStyles;
+use crate::css::CssRules;
use crate::dpi::Dpi;
use crate::drawing_ctx::{ClipMode, DrawingCtx, ViewParams};
use crate::error::{AttributeResultExt, RenderingError};
@@ -128,10 +128,10 @@ impl NodeSvg {
}
}
- pub fn set_delayed_style(&self, node: &RsvgNode, css_styles: &CssStyles) {
+ pub fn set_delayed_style(&self, node: &RsvgNode, css_rules: &CssRules) {
if let Some(owned_pbag) = self.pbag.borrow().as_ref() {
let pbag = PropertyBag::from_owned(owned_pbag);
- node.set_style(css_styles, &pbag);
+ node.set_style(css_rules, &pbag);
}
}
diff --git a/rsvg_internals/src/xml.rs b/rsvg_internals/src/xml.rs
index 5c96a4b0..9f39fc81 100644
--- a/rsvg_internals/src/xml.rs
+++ b/rsvg_internals/src/xml.rs
@@ -10,7 +10,7 @@ use std::str;
use crate::allowed_url::AllowedUrl;
use crate::attributes::Attribute;
use crate::create_node::create_node_and_register_id;
-use crate::css::CssStyles;
+use crate::css::CssRules;
use crate::error::LoadingError;
use crate::handle::LoadOptions;
use crate::io::{self, get_input_stream_for_loading};
@@ -70,7 +70,7 @@ extern "C" {
pub struct XmlState {
tree_root: Option<Rc<Node>>,
ids: Option<HashMap<String, RsvgNode>>,
- css_styles: Option<CssStyles>,
+ css_rules: Option<CssRules>,
context_stack: Vec<Context>,
current_node: Option<Rc<Node>>,
@@ -96,7 +96,7 @@ impl XmlState {
XmlState {
tree_root: None,
ids: Some(HashMap::new()),
- css_styles: Some(CssStyles::new()),
+ css_rules: Some(CssRules::new()),
context_stack: vec![Context::Start],
current_node: None,
entities: HashMap::new(),
@@ -212,8 +212,8 @@ impl XmlState {
AllowedUrl::from_href(&href.unwrap(), self.load_options.base_url.as_ref())
{
// FIXME: handle CSS errors
- let css_styles = self.css_styles.as_mut().unwrap();
- let _ = css_styles.load_css(&aurl);
+ let css_rules = self.css_rules.as_mut().unwrap();
+ let _ = css_rules.load_css(&aurl);
} else {
self.error("disallowed URL in xml-stylesheet");
}
@@ -268,16 +268,16 @@ impl XmlState {
// here, not during element creation.
if node.get_type() == NodeType::Svg {
node.with_impl(|svg: &NodeSvg| {
- svg.set_delayed_style(&node, self.css_styles.as_ref().unwrap());
+ svg.set_delayed_style(&node, self.css_rules.as_ref().unwrap());
});
}
if node.get_type() == NodeType::Style {
let css_data = node.with_impl(|style: &NodeStyle| style.get_css(&node));
- let css_styles = self.css_styles.as_mut().unwrap();
+ let css_rules = self.css_rules.as_mut().unwrap();
- css_styles.parse(self.load_options.base_url.as_ref(), &css_data);
+ css_rules.parse(self.load_options.base_url.as_ref(), &css_data);
}
self.current_node = node.get_parent();
@@ -326,7 +326,7 @@ impl XmlState {
// The "svg" node is special; it will parse its style attributes
// until the end, in standard_element_end().
if new_node.get_type() != NodeType::Svg {
- new_node.set_style(self.css_styles.as_ref().unwrap(), pbag);
+ new_node.set_style(self.css_rules.as_ref().unwrap(), pbag);
}
new_node.set_overridden_properties();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]