From 2108a85764c4a7f4b9cdc6f2d2b1afaeb7ba4371 Mon Sep 17 00:00:00 2001 From: Chintan Gandhi Date: Tue, 3 Dec 2019 16:12:51 -0500 Subject: [PATCH] created sourced names w/o past names map part --- components/script/dom/htmlformelement.rs | 75 ++++++++++++++++++++++++ 1 file changed, 75 insertions(+) mode change 100755 => 100644 components/script/dom/htmlformelement.rs diff --git a/components/script/dom/htmlformelement.rs b/components/script/dom/htmlformelement.rs old mode 100755 new mode 100644 index b09804e397c..fc96145e25e --- a/components/script/dom/htmlformelement.rs +++ b/components/script/dom/htmlformelement.rs @@ -64,6 +64,8 @@ use std::cell::Cell; use style::attr::AttrValue; use style::str::split_html_space_chars; +use crate::dom::bindings::codegen::UnionTypes::RadioNodeListOrElement; + #[derive(Clone, Copy, JSTraceable, MallocSizeOf, PartialEq)] pub struct GenerationId(u32); @@ -253,6 +255,79 @@ impl HTMLFormElementMethods for HTMLFormElement { let elements = self.Elements(); elements.IndexedGetter(index) } + + fn NamedGetter(&self, name: DOMString) -> Option { + // return Option::Some::; + unimplemented!(); + } + + // https://html.spec.whatwg.org/multipage/forms.html#the-form-element:supported-property-names + fn SupportedPropertyNames(&self) -> Vec { + + enum SourcedNameSource { + Id, + Name, + Past(std::time::Duration) + } + + struct SourcedName { + name: DOMString, + element: DomRoot, + source: SourcedNameSource, + } + + // vector to store sourced names tuple information + let mut sourcedNamesVec: Vec = Vec::new(); + + // let controls = self.controls.borrow_mut(); - line 849 → unsure of which "borrow" to use + let controls = self.controls.borrow(); // line 807 in this file + + // controls - list of form elements + // check all listed elements first, push to sourcedNamesVec as per spec + for child in controls.iter() { + + if child.is_html_element() { // if child.is_listed() + + if child.has_attribute(&local_name!("id")) { + // https://learning-rust.github.io/docs/b2.structs.html + let entry = SourcedName {name: child.get_string_attribute(&local_name!("id")), element: child.root_element(), source: SourcedNameSource::Id}; + sourcedNamesVec.push(entry); + } + else if child.has_attribute(&local_name!("name")) { + let entry = SourcedName {name: child.get_string_attribute(&local_name!("name")), element: child.root_element(), source: SourcedNameSource::Name}; + sourcedNamesVec.push(entry); + } + } + } + + // check img elements now, push to sourcedNamesVec as per spec + for child in controls.iter() { + // https://doc.servo.org/src/script/dom/htmlelement.rs.html#645-665 + // if child.get_string_attribute(&local_name!("type")) == "image" { + + // https://users.rust-lang.org/t/how-check-type-of-variable/33845/7 + if child.is::() { + + if child.has_attribute(&local_name!("id")) { + // https://learning-rust.github.io/docs/b2.structs.html + let entry = SourcedName {name: child.get_string_attribute(&local_name!("id")), element: child.root_element(), source: SourcedNameSource::Id}; + sourcedNamesVec.push(entry); + } + else if child.has_attribute(&local_name!("name")) { + let entry = SourcedName {name: child.get_string_attribute(&local_name!("name")), element: child.root_element(), source: SourcedNameSource::Name}; + sourcedNamesVec.push(entry); + } + } + } + + // return list of names + let mut namesVec: Vec = Vec::new(); + for elem in sourcedNamesVec.iter() { + namesVec.push(elem.name.clone()); + } + + return namesVec; + } } #[derive(Clone, Copy, MallocSizeOf, PartialEq)]