mirror of
https://github.com/servo/servo.git
synced 2025-08-01 11:40:30 +01:00
Auto merge of #27255 - avr1254:master, r=jdm
Implemented HTMLFormElement.relList <!-- Please describe your changes on the following line: --> Updated the tests to reflect addition of rel and relList for HTMLFormElement, as well as porting those code snippets from HTMLAnchorElement. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #27252 (GitHub issue number if applicable) <!-- Either: --> - [X] There are tests for these changes OR - [ ] These changes do not require tests because ___ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
This commit is contained in:
commit
c8d0548824
4 changed files with 33 additions and 17 deletions
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue