mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-11-08 04:09:03 +02:00
This changeset gets rid of the `FooView` phantom type in favor of a more brute force approach that just whitelists methods that layout is allowed to call. The set is surprisingly small now that layout isn't going to the DOM for much. If this approach turns out not to scale, we can do something fancier, but I'd rather just have it be safe and secure first and then refactor later for programmer happiness. r? @kmcallister Source-Repo: https://github.com/servo/servo Source-Revision: 824c7ac613ebb80bb432ff6425c5e25c642b6afb
65 lines
1.9 KiB
Rust
65 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::attr::Attr;
|
|
use dom::bindings::codegen::AttrListBinding;
|
|
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
|
|
use dom::node::{AbstractNode};
|
|
use dom::window::Window;
|
|
|
|
pub struct AttrList {
|
|
reflector_: Reflector,
|
|
window: @mut Window,
|
|
owner: AbstractNode,
|
|
}
|
|
|
|
impl AttrList {
|
|
pub fn new_inherited(window: @mut Window, elem: AbstractNode) -> AttrList {
|
|
AttrList {
|
|
reflector_: Reflector::new(),
|
|
window: window,
|
|
owner: elem
|
|
}
|
|
}
|
|
|
|
pub fn new(window: @mut Window, elem: AbstractNode) -> @mut AttrList {
|
|
reflect_dom_object(@mut AttrList::new_inherited(window, elem),
|
|
window, AttrListBinding::Wrap)
|
|
}
|
|
|
|
pub fn Length(&self) -> u32 {
|
|
self.owner.with_imm_element(|elem| elem.attrs_insert_order.len() as u32)
|
|
}
|
|
|
|
pub fn Item(&self, index: u32) -> Option<@mut Attr> {
|
|
if index >= self.Length() {
|
|
None
|
|
} else {
|
|
do self.owner.with_imm_element |elem| {
|
|
let insert_order = &elem.attrs_insert_order[index];
|
|
do elem.attrs.find_equiv(&insert_order.first()).and_then |attrs| {
|
|
attrs.iter()
|
|
.find(|attr| attr.namespace == insert_order.second())
|
|
.map(|attr| *attr)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
pub fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option<@mut Attr> {
|
|
let item = self.Item(index);
|
|
*found = item.is_some();
|
|
item
|
|
}
|
|
}
|
|
|
|
impl Reflectable for AttrList {
|
|
fn reflector<'a>(&'a self) -> &'a Reflector {
|
|
&self.reflector_
|
|
}
|
|
|
|
fn mut_reflector<'a>(&'a mut self) -> &'a mut Reflector {
|
|
&mut self.reflector_
|
|
}
|
|
}
|