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

Removed tidy-test errors

  • Loading branch information
jaymodi98 committed Dec 3, 2019
commit 2ee6150990d2bb58ccf3bd634db640e155164eff
@@ -256,18 +256,18 @@ impl HTMLFormElementMethods for HTMLFormElement {
elements.IndexedGetter(index)
}

// https://html.spec.whatwg.org/multipage/#the-form-element%3Adetermine-the-value-of-a-named-property
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
// https://html.spec.whatwg.org/multipage/#the-form-element:supported-property-names
fn SupportedPropertyNames(&self) -> Vec<DOMString> {

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

struct SourcedName {
@@ -285,16 +285,23 @@ impl HTMLFormElementMethods for HTMLFormElement {
// 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.is_html_element() {

This comment has been minimized.

Copy link
@cagandhi

cagandhi Dec 4, 2019

Contributor

@jdm Is the function call is_html_element() correct or we should use is_listed()? We weren't able to call the method is_listed_element() as mentioned by you on the project page. ./mach check was showing error for function call on incorrect variable type.

This comment has been minimized.

Copy link
@jdm

jdm Dec 4, 2019

Member

Ah, that's HTMLElement::is_listed_element. You can do:

if child.downcast::<HTMLElement>().map_or(false, |c| c.is_listed_element()) {

This comment has been minimized.

Copy link
@cagandhi

cagandhi Dec 4, 2019

Contributor

Done.

// 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};
let entry = SourcedName {
name: child.get_string_attribute(&local_name!("id")),
element: child.root_element(),

This comment has been minimized.

Copy link
@jdm

jdm Dec 4, 2019

Member

Instead of calling root_element (which returns a different element), you should use DomRoot::from_ref(&*child), which is a GC-rooted version of the same element. This also applies to all other uses of root_element.

This comment has been minimized.

Copy link
@cagandhi

cagandhi Dec 4, 2019

Contributor

Fixed it.

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};
} 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);
}
}
@@ -307,14 +314,20 @@ impl HTMLFormElementMethods for HTMLFormElement {

// 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};
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};
} 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);
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.