Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Named form getter #25070

Merged
merged 13 commits into from Dec 16, 2019

created sourced names w/o past names map part

  • Loading branch information
Chintan Gandhi
Chintan Gandhi committed Dec 3, 2019
commit 2108a85764c4a7f4b9cdc6f2d2b1afaeb7ba4371
@@ -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<RadioNodeListOrElement> {
// return Option::Some::<RadioNodeListOrElement>;
unimplemented!();
}

// https://html.spec.whatwg.org/multipage/forms.html#the-form-element:supported-property-names
fn SupportedPropertyNames(&self) -> Vec<DOMString> {

enum SourcedNameSource {
Id,
Name,
Past(std::time::Duration)
}

struct SourcedName {
name: DOMString,
element: DomRoot<Element>,
source: SourcedNameSource,
}

// vector to store sourced names tuple information
let mut sourcedNamesVec: Vec<SourcedName> = 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::<HTMLImageElement>() {

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<DOMString> = Vec::new();
for elem in sourcedNamesVec.iter() {
namesVec.push(elem.name.clone());
}

return namesVec;
}
}

#[derive(Clone, Copy, MallocSizeOf, PartialEq)]
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.