1use dom_struct::dom_struct;
6
7use crate::dom::bindings::codegen::Bindings::TouchListBinding::TouchListMethods;
8use crate::dom::bindings::reflector::{Reflector, reflect_dom_object};
9use crate::dom::bindings::root::{Dom, DomRoot};
10use crate::dom::touch::Touch;
11use crate::dom::window::Window;
12use crate::script_runtime::CanGc;
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(window: &Window, touches: &[&Touch], can_gc: CanGc) -> DomRoot<TouchList> {
29 reflect_dom_object(Box::new(TouchList::new_inherited(touches)), window, can_gc)
30 }
31}
32
33impl TouchListMethods<crate::DomTypeHolder> for TouchList {
34 fn Length(&self) -> u32 {
36 self.touches.len() as u32
37 }
38
39 fn Item(&self, index: u32) -> Option<DomRoot<Touch>> {
41 self.touches
42 .get(index as usize)
43 .map(|js| DomRoot::from_ref(&**js))
44 }
45
46 fn IndexedGetter(&self, index: u32) -> Option<DomRoot<Touch>> {
48 self.Item(index)
49 }
50}