pub struct CSSStyleSheet { /* private fields */ }Expand description
CSSStyleSheet 对象
表示一个 CSS 样式表,提供对样式表规则的完整操作能力。
对标 Web API: CSSStyleSheet
§示例
use iris_cssom::stylesheet::CSSStyleSheet;
let mut sheet = CSSStyleSheet::new();
sheet.insert_rule(".container { color: red; }", 0).unwrap();
assert_eq!(sheet.css_rules().lock().unwrap().length(), 1);Implementations§
Source§impl CSSStyleSheet
impl CSSStyleSheet
Sourcepub fn new() -> Self
pub fn new() -> Self
创建空的样式表
§示例
use iris_cssom::stylesheet::CSSStyleSheet;
let sheet = CSSStyleSheet::new();
assert!(!sheet.disabled());
assert_eq!(sheet.css_rules().lock().unwrap().length(), 0);Sourcepub fn set_disabled(&mut self, disabled: bool)
pub fn set_disabled(&mut self, disabled: bool)
设置样式表禁用状态
Sourcepub fn owner_node(&self) -> Option<&str>
pub fn owner_node(&self) -> Option<&str>
获取拥有此样式表的 DOM 元素标识
Sourcepub fn set_owner_node(&mut self, node_id: &str)
pub fn set_owner_node(&mut self, node_id: &str)
设置拥有此样式表的 DOM 元素标识
Sourcepub fn css_rules(&self) -> Arc<Mutex<CSSRuleList>>
pub fn css_rules(&self) -> Arc<Mutex<CSSRuleList>>
获取规则列表(实时更新的 live list)
§示例
use iris_cssom::stylesheet::CSSStyleSheet;
let mut sheet = CSSStyleSheet::new();
sheet.insert_rule(".class { color: red; }", 0).unwrap();
let rules = sheet.css_rules();
assert_eq!(rules.lock().unwrap().length(), 1);Sourcepub fn insert_rule(&mut self, rule: &str, index: usize) -> Result<u32, String>
pub fn insert_rule(&mut self, rule: &str, index: usize) -> Result<u32, String>
插入一条新规则
§参数
rule- CSS 规则文本(如 “.class { color: red; }”)index- 插入位置(从 0 开始)
§返回值
成功返回插入位置的索引,失败返回错误
§错误
- 如果索引超出范围,返回
Err - 如果 CSS 规则语法错误,返回
Err
§示例
use iris_cssom::stylesheet::CSSStyleSheet;
let mut sheet = CSSStyleSheet::new();
let index = sheet.insert_rule(".container { color: red; }", 0);
assert!(index.is_ok());
assert_eq!(index.unwrap(), 0);Sourcepub fn internal_stylesheet(&self) -> Stylesheet
pub fn internal_stylesheet(&self) -> Stylesheet
获取内部样式表(用于与 iris-layout 集成)
Sourcepub fn get_css_text(&self) -> String
pub fn get_css_text(&self) -> String
获取 CSS 文本(整个样式表的文本表示)
§示例
use iris_cssom::stylesheet::CSSStyleSheet;
let mut sheet = CSSStyleSheet::new();
sheet.insert_rule(".class { color: red; }", 0).unwrap();
let css_text = sheet.get_css_text();
assert!(css_text.contains(".class"));Sourcepub fn rule_count(&self) -> u32
pub fn rule_count(&self) -> u32
获取规则数量
Trait Implementations§
Source§impl Clone for CSSStyleSheet
impl Clone for CSSStyleSheet
Source§fn clone(&self) -> CSSStyleSheet
fn clone(&self) -> CSSStyleSheet
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for CSSStyleSheet
impl Debug for CSSStyleSheet
Auto Trait Implementations§
impl Freeze for CSSStyleSheet
impl RefUnwindSafe for CSSStyleSheet
impl !Send for CSSStyleSheet
impl !Sync for CSSStyleSheet
impl Unpin for CSSStyleSheet
impl UnsafeUnpin for CSSStyleSheet
impl UnwindSafe for CSSStyleSheet
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more