Ported Rel, SetRel, and RelList from HTMLAnchorElement into HTMLForElement

Updated tests to reflect rel and relList in HTMLFormElement

Added AttrValue as style

Added attr

Updated outstanding test cases

Fixed formatting. Hopefully this time works

Implemented HTMLFormElement.relList
This commit is contained in:
Arjun Ramachandrula 2020-07-13 15:39:08 -04:00
parent 352ecda7b5
commit 00f69dd50f
4 changed files with 33 additions and 17 deletions

View file

@ -20,10 +20,11 @@ use crate::dom::bindings::error::{Error, Fallible};
use crate::dom::bindings::inheritance::{Castable, ElementTypeId, HTMLElementTypeId, NodeTypeId};
use crate::dom::bindings::refcounted::Trusted;
use crate::dom::bindings::reflector::DomObject;
use crate::dom::bindings::root::{Dom, DomOnceCell, DomRoot};
use crate::dom::bindings::root::{Dom, DomOnceCell, DomRoot, MutNullableDom};
use crate::dom::bindings::str::DOMString;
use crate::dom::blob::Blob;
use crate::dom::document::Document;
use crate::dom::domtokenlist::DOMTokenList;
use crate::dom::element::{AttributeMutation, Element};
use crate::dom::event::{Event, EventBubbles, EventCancelable};
use crate::dom::eventtarget::EventTarget;
@ -68,6 +69,7 @@ use servo_atoms::Atom;
use servo_rand::random;
use std::borrow::ToOwned;
use std::cell::Cell;
use style::attr::AttrValue;
use style::str::split_html_space_chars;
use crate::dom::bindings::codegen::UnionTypes::RadioNodeListOrElement;
@ -90,6 +92,7 @@ pub struct HTMLFormElement {
controls: DomRefCell<Vec<Dom<Element>>>,
past_names_map: DomRefCell<HashMap<Atom, (Dom<Element>, Tm)>>,
firing_submission_events: Cell<bool>,
rel_list: MutNullableDom<DOMTokenList>,
}
impl HTMLFormElement {
@ -107,6 +110,7 @@ impl HTMLFormElement {
controls: DomRefCell::new(Vec::new()),
past_names_map: DomRefCell::new(HashMap::new()),
firing_submission_events: Cell::new(false),
rel_list: Default::default(),
}
}
@ -241,6 +245,9 @@ impl HTMLFormElementMethods for HTMLFormElement {
// https://html.spec.whatwg.org/multipage/#dom-fs-target
make_setter!(SetTarget, "target");
// https://html.spec.whatwg.org/multipage/#dom-a-rel
make_getter!(Rel, "rel");
// https://html.spec.whatwg.org/multipage/#the-form-element:concept-form-submit
fn Submit(&self) {
self.submit(SubmittedFrom::FromForm, FormSubmitter::FormElement(self));
@ -434,6 +441,18 @@ impl HTMLFormElementMethods for HTMLFormElement {
)));
}
// https://html.spec.whatwg.org/multipage/#dom-a-rel
fn SetRel(&self, rel: DOMString) {
self.upcast::<Element>()
.set_tokenlist_attribute(&local_name!("rel"), rel);
}
// https://html.spec.whatwg.org/multipage/#dom-a-rellist
fn RelList(&self) -> DomRoot<DOMTokenList> {
self.rel_list
.or_init(|| DOMTokenList::new(self.upcast(), &local_name!("rel")))
}
// https://html.spec.whatwg.org/multipage/#the-form-element:supported-property-names
#[allow(non_snake_case)]
fn SupportedPropertyNames(&self) -> Vec<DOMString> {
@ -1636,6 +1655,16 @@ impl VirtualMethods for HTMLFormElement {
.reset_form_owner();
}
}
fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue {
match name {
&local_name!("rel") => AttrValue::from_serialized_tokenlist(value.into()),
_ => self
.super_type()
.unwrap()
.parse_plain_attribute(name, value),
}
}
}
pub trait FormControlElementHelpers {

View file

@ -25,6 +25,9 @@ interface HTMLFormElement : HTMLElement {
attribute boolean noValidate;
[CEReactions]
attribute DOMString target;
[CEReactions]
attribute DOMString rel;
[SameObject, PutForwards=value] readonly attribute DOMTokenList relList;
[SameObject] readonly attribute HTMLFormControlsCollection elements;
readonly attribute unsigned long length;

View file

@ -1,4 +0,0 @@
[put-forwards.html]
type: testharness
[Setting form.relList to noreferrer is reflected in rel]
expected: FAIL

View file

@ -1911,9 +1911,6 @@
[HTMLElement interface: attribute accessKey]
expected: FAIL
[HTMLFormElement interface: attribute rel]
expected: FAIL
[HTMLObjectElement interface: document.createElement("object") must inherit property "vspace" with the proper type]
expected: FAIL
@ -2547,9 +2544,6 @@
[HTMLInputElement interface: createInput("password") must inherit property "useMap" with the proper type]
expected: FAIL
[HTMLFormElement interface: attribute relList]
expected: FAIL
[HTMLElement interface: document.createElement("noscript") must inherit property "onauxclick" with the proper type]
expected: FAIL
@ -3237,9 +3231,6 @@
[HTMLInputElement interface: createInput("radio") must inherit property "useMap" with the proper type]
expected: FAIL
[HTMLFormElement interface: document.createElement("form") must inherit property "rel" with the proper type]
expected: FAIL
[HTMLIFrameElement interface: attribute allowPaymentRequest]
expected: FAIL
@ -3375,9 +3366,6 @@
[HTMLAreaElement interface: document.createElement("area") must inherit property "username" with the proper type]
expected: FAIL
[HTMLFormElement interface: document.createElement("form") must inherit property "relList" with the proper type]
expected: FAIL
[HTMLInputElement interface: createInput("search") must inherit property "height" with the proper type]
expected: FAIL