script/dom/touch/
touchlist.rs1use dom_struct::dom_struct;
6use js::context::JSContext;
7use script_bindings::reflector::{Reflector, reflect_dom_object_with_cx};
8
9use crate::dom::bindings::codegen::Bindings::TouchListBinding::TouchListMethods;
10use crate::dom::bindings::root::{Dom, DomRoot};
11use crate::dom::touch::Touch;
12use crate::dom::window::Window;
13
14#[dom_struct]
15pub(crate) struct TouchList {
16 reflector_: Reflector,
17 touches: Vec<Dom<Touch>>,
18}
19
20impl TouchList {
21 fn new_inherited(touches: &[&Touch]) -> TouchList {
22 TouchList {
23 reflector_: Reflector::new(),
24 touches: touches.iter().map(|touch| Dom::from_ref(*touch)).collect(),
25 }
26 }
27
28 pub(crate) fn new(
29 cx: &mut JSContext,
30 window: &Window,
31 touches: &[&Touch],
32 ) -> DomRoot<TouchList> {
33 reflect_dom_object_with_cx(Box::new(TouchList::new_inherited(touches)), window, cx)
34 }
35}
36
37impl TouchListMethods<crate::DomTypeHolder> for TouchList {
38 fn Length(&self) -> u32 {
40 self.touches.len() as u32
41 }
42
43 fn Item(&self, index: u32) -> Option<DomRoot<Touch>> {
45 self.touches
46 .get(index as usize)
47 .map(|js| DomRoot::from_ref(&**js))
48 }
49
50 fn IndexedGetter(&self, index: u32) -> Option<DomRoot<Touch>> {
52 self.Item(index)
53 }
54}