Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
jaytaph committed Jan 31, 2024
1 parent cef5c65 commit 0deb093
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 0 deletions.
62 changes: 62 additions & 0 deletions src/css3/cssom/cssrule.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
pub enum CssRuleType {
UnknownRule = 0,
StyleRule = 1,
CharsetRule = 2, // Obsolete
ImportRule = 3,
MediaRule = 4,
FontFaceRule = 5,
PageRule = 6,
KeyframesRule = 7,
KeyframeRule = 8,
MarginRule = 9, // Obsolete
NamespaceRule = 10,
CounterStyleRule = 11,
SupportsRule = 12,
DocumentRule = 13, // Obsolete
FontFeatureValuesRule = 14,
ViewportRule = 15, // Obsolete
RegionStyleRule = 16, // Obsolete
}

pub struct CssStyleRule {
}

pub enum CssTypeRuleType {
StyleRule(CssStyleRule),
CharsetRule(CssCharsetRule),
ImportRule(CssImportRule),
MediaRule(CssMediaRule),
FontFaceRule(CssFontFaceRule),
PageRule(CssPageRule),
KeyframesRule(CssKeyframesRule),
KeyframeRule(CssKeyframeRule),
MarginRule(CssMarginRule),
NamespaceRule(CssNamespaceRule),
CounterStyleRule(CssCounterStyleRule),
SupportsRule(CssSupportsRule),
DocumentRule(CssDocumentRule),
FontFeatureValuesRule(CssFontFeatureValuesRule),
ViewportRule(CssViewportRule),
RegionStyleRule(CssRegionStyleRule),
}

struct CssRule {
text: String,
parent_rule: Option<Rc<CssRule>>,
parent_stylesheet: Option<Rc<CSSStyleSheet>>,
type_: CssRuleType,
}

struct CssGroupingRule {
css_rules: CssRuleList,
}

impl CssGroupingRule {
pub fn delete_rule(&mut self, idx: usize) {
self.css_rules.remove(idx);
}

pub fn insert_rule(&mut self, idx: usize, rule: CssRule) {
self.css_rules.insert(idx, rule);
}
}
11 changes: 11 additions & 0 deletions src/css3/cssom/cssrule_list.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
type CssRuleList = vec<CssRule>;

impl CssRuleList {
fn item(&self, idx: usize) -> Option<&CssRule> {
self.get(idx)
}

fn length(&self) -> usize {
self.len()
}
}
32 changes: 32 additions & 0 deletions src/css3/cssom/stylesheet.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
struct CSSStyleSheet {
rules: CssRuleList
}

impl CSSStyleSheet {
pub fn new() -> Self {
Self {
rules: vec![]
}
}

pub fn delete_rule(&mut self, idx: usize) {
self.rules.remove(idx);
}

pub fn insert_rule(&mut self, idx: usize, rule: CssRule) {
self.rules.insert(idx, rule);
}

pub fn replace_async(&mut self, idx: usize, rule: CssRule) {
self.rules[idx] = rule;
}

pub fn replace(&mut self, idx: usize, rule: CssRule) {
self.rules[idx] = rule;
}

// CSSOM:
// property: rules obsolete
// method: addRule() obsolete
// method: removeRule() obsolete
}
3 changes: 3 additions & 0 deletions src/css3/cssom/stylesheet_list.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
struct StyleSheetList {
item: vec<StyleSheet>
}

0 comments on commit 0deb093

Please sign in to comment.