mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-11-12 22:28:59 +02:00
The rustup is needed for https://github.com/rust-lang/rust/pull/40039. Source-Repo: https://github.com/servo/servo Source-Revision: a204c4176dcccdad8ec99d74055c66794c3f64ba --HG-- rename : servo/components/domobject_derive/Cargo.toml => servo/components/dom_struct/Cargo.toml extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear extra : subtree_revision : 2cad140c3d6b99837f0bd15a6f3ccba0f353e049
57 lines
1.9 KiB
Rust
57 lines
1.9 KiB
Rust
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
use dom::bindings::codegen::Bindings::StyleSheetListBinding;
|
|
use dom::bindings::codegen::Bindings::StyleSheetListBinding::StyleSheetListMethods;
|
|
use dom::bindings::js::{JS, Root};
|
|
use dom::bindings::reflector::{Reflector, reflect_dom_object};
|
|
use dom::document::Document;
|
|
use dom::stylesheet::StyleSheet;
|
|
use dom::window::Window;
|
|
use dom_struct::dom_struct;
|
|
|
|
#[dom_struct]
|
|
pub struct StyleSheetList {
|
|
reflector_: Reflector,
|
|
document: JS<Document>,
|
|
}
|
|
|
|
impl StyleSheetList {
|
|
#[allow(unrooted_must_root)]
|
|
fn new_inherited(doc: JS<Document>) -> StyleSheetList {
|
|
StyleSheetList {
|
|
reflector_: Reflector::new(),
|
|
document: doc
|
|
}
|
|
}
|
|
|
|
#[allow(unrooted_must_root)]
|
|
pub fn new(window: &Window, document: JS<Document>) -> Root<StyleSheetList> {
|
|
reflect_dom_object(box StyleSheetList::new_inherited(document),
|
|
window, StyleSheetListBinding::Wrap)
|
|
}
|
|
}
|
|
|
|
impl StyleSheetListMethods for StyleSheetList {
|
|
// https://drafts.csswg.org/cssom/#dom-stylesheetlist-length
|
|
fn Length(&self) -> u32 {
|
|
self.document.with_style_sheets_in_document(|s| s.len() as u32)
|
|
}
|
|
|
|
// https://drafts.csswg.org/cssom/#dom-stylesheetlist-item
|
|
fn Item(&self, index: u32) -> Option<Root<StyleSheet>> {
|
|
// XXXManishearth this doesn't handle the origin clean flag
|
|
// and is a cors vulnerability
|
|
self.document.with_style_sheets_in_document(|sheets| {
|
|
sheets.get(index as usize)
|
|
.and_then(|sheet| sheet.node.get_cssom_stylesheet())
|
|
.map(Root::upcast)
|
|
})
|
|
}
|
|
|
|
// check-tidy: no specs after this line
|
|
fn IndexedGetter(&self, index: u32) -> Option<Root<StyleSheet>> {
|
|
self.Item(index)
|
|
}
|
|
}
|