mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
[clippy] Rename enum FormSubmitter and its elements (#32791)
* [clippy] Renames enum FormSubmitter and its elements Signed-off-by: Danila Matveev <usurname.r@gmail.com> * fmt Signed-off-by: Danila Matveev <usurname.r@gmail.com> --------- Signed-off-by: Danila Matveev <usurname.r@gmail.com>
This commit is contained in:
parent
882a855b8c
commit
e4ad1d3ab9
3 changed files with 44 additions and 44 deletions
|
@ -23,7 +23,7 @@ use crate::dom::eventtarget::EventTarget;
|
||||||
use crate::dom::htmlelement::HTMLElement;
|
use crate::dom::htmlelement::HTMLElement;
|
||||||
use crate::dom::htmlfieldsetelement::HTMLFieldSetElement;
|
use crate::dom::htmlfieldsetelement::HTMLFieldSetElement;
|
||||||
use crate::dom::htmlformelement::{
|
use crate::dom::htmlformelement::{
|
||||||
FormControl, FormDatum, FormDatumValue, FormSubmitter, HTMLFormElement, ResetFrom,
|
FormControl, FormDatum, FormDatumValue, FormSubmitterElement, HTMLFormElement, ResetFrom,
|
||||||
SubmittedFrom,
|
SubmittedFrom,
|
||||||
};
|
};
|
||||||
use crate::dom::node::{window_from_node, BindContext, Node, UnbindContext};
|
use crate::dom::node::{window_from_node, BindContext, Node, UnbindContext};
|
||||||
|
@ -192,11 +192,11 @@ impl HTMLButtonElementMethods for HTMLButtonElement {
|
||||||
impl HTMLButtonElement {
|
impl HTMLButtonElement {
|
||||||
/// <https://html.spec.whatwg.org/multipage/#constructing-the-form-data-set>
|
/// <https://html.spec.whatwg.org/multipage/#constructing-the-form-data-set>
|
||||||
/// Steps range from 3.1 to 3.7 (specific to HTMLButtonElement)
|
/// Steps range from 3.1 to 3.7 (specific to HTMLButtonElement)
|
||||||
pub fn form_datum(&self, submitter: Option<FormSubmitter>) -> Option<FormDatum> {
|
pub fn form_datum(&self, submitter: Option<FormSubmitterElement>) -> Option<FormDatum> {
|
||||||
// Step 3.1: disabled state check is in get_unclean_dataset
|
// Step 3.1: disabled state check is in get_unclean_dataset
|
||||||
|
|
||||||
// Step 3.1: only run steps if this is the submitter
|
// Step 3.1: only run steps if this is the submitter
|
||||||
if let Some(FormSubmitter::ButtonElement(submitter)) = submitter {
|
if let Some(FormSubmitterElement::Button(submitter)) = submitter {
|
||||||
if submitter != self {
|
if submitter != self {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
@ -351,7 +351,7 @@ impl Activatable for HTMLButtonElement {
|
||||||
if let Some(owner) = self.form_owner() {
|
if let Some(owner) = self.form_owner() {
|
||||||
owner.submit(
|
owner.submit(
|
||||||
SubmittedFrom::NotFromForm,
|
SubmittedFrom::NotFromForm,
|
||||||
FormSubmitter::ButtonElement(self),
|
FormSubmitterElement::Button(self),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -260,12 +260,12 @@ impl HTMLFormElementMethods for HTMLFormElement {
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#the-form-element:concept-form-submit
|
// https://html.spec.whatwg.org/multipage/#the-form-element:concept-form-submit
|
||||||
fn Submit(&self) {
|
fn Submit(&self) {
|
||||||
self.submit(SubmittedFrom::FromForm, FormSubmitter::FormElement(self));
|
self.submit(SubmittedFrom::FromForm, FormSubmitterElement::Form(self));
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-form-requestsubmit
|
// https://html.spec.whatwg.org/multipage/#dom-form-requestsubmit
|
||||||
fn RequestSubmit(&self, submitter: Option<&HTMLElement>) -> Fallible<()> {
|
fn RequestSubmit(&self, submitter: Option<&HTMLElement>) -> Fallible<()> {
|
||||||
let submitter: FormSubmitter = match submitter {
|
let submitter: FormSubmitterElement = match submitter {
|
||||||
Some(submitter_element) => {
|
Some(submitter_element) => {
|
||||||
// Step 1.1
|
// Step 1.1
|
||||||
let error_not_a_submit_button =
|
let error_not_a_submit_button =
|
||||||
|
@ -279,12 +279,12 @@ impl HTMLFormElementMethods for HTMLFormElement {
|
||||||
};
|
};
|
||||||
|
|
||||||
let submit_button = match element {
|
let submit_button = match element {
|
||||||
HTMLElementTypeId::HTMLInputElement => FormSubmitter::InputElement(
|
HTMLElementTypeId::HTMLInputElement => FormSubmitterElement::Input(
|
||||||
submitter_element
|
submitter_element
|
||||||
.downcast::<HTMLInputElement>()
|
.downcast::<HTMLInputElement>()
|
||||||
.expect("Failed to downcast submitter elem to HTMLInputElement."),
|
.expect("Failed to downcast submitter elem to HTMLInputElement."),
|
||||||
),
|
),
|
||||||
HTMLElementTypeId::HTMLButtonElement => FormSubmitter::ButtonElement(
|
HTMLElementTypeId::HTMLButtonElement => FormSubmitterElement::Button(
|
||||||
submitter_element
|
submitter_element
|
||||||
.downcast::<HTMLButtonElement>()
|
.downcast::<HTMLButtonElement>()
|
||||||
.expect("Failed to downcast submitter elem to HTMLButtonElement."),
|
.expect("Failed to downcast submitter elem to HTMLButtonElement."),
|
||||||
|
@ -316,7 +316,7 @@ impl HTMLFormElementMethods for HTMLFormElement {
|
||||||
},
|
},
|
||||||
None => {
|
None => {
|
||||||
// Step 2
|
// Step 2
|
||||||
FormSubmitter::FormElement(self)
|
FormSubmitterElement::Form(self)
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
// Step 3
|
// Step 3
|
||||||
|
@ -691,7 +691,7 @@ impl HTMLFormElement {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// [Form submission](https://html.spec.whatwg.org/multipage/#concept-form-submit)
|
/// [Form submission](https://html.spec.whatwg.org/multipage/#concept-form-submit)
|
||||||
pub fn submit(&self, submit_method_flag: SubmittedFrom, submitter: FormSubmitter) {
|
pub fn submit(&self, submit_method_flag: SubmittedFrom, submitter: FormSubmitterElement) {
|
||||||
// Step 1
|
// Step 1
|
||||||
if self.upcast::<Element>().cannot_navigate() {
|
if self.upcast::<Element>().cannot_navigate() {
|
||||||
return;
|
return;
|
||||||
|
@ -722,15 +722,15 @@ impl HTMLFormElement {
|
||||||
// spec calls this "submitterButton" but it doesn't have to be a button,
|
// spec calls this "submitterButton" but it doesn't have to be a button,
|
||||||
// just not be the form itself
|
// just not be the form itself
|
||||||
let submitter_button = match submitter {
|
let submitter_button = match submitter {
|
||||||
FormSubmitter::FormElement(f) => {
|
FormSubmitterElement::Form(f) => {
|
||||||
if f == self {
|
if f == self {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some(f.upcast::<HTMLElement>())
|
Some(f.upcast::<HTMLElement>())
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
FormSubmitter::InputElement(i) => Some(i.upcast::<HTMLElement>()),
|
FormSubmitterElement::Input(i) => Some(i.upcast::<HTMLElement>()),
|
||||||
FormSubmitter::ButtonElement(b) => Some(b.upcast::<HTMLElement>()),
|
FormSubmitterElement::Button(b) => Some(b.upcast::<HTMLElement>()),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Step 6.5
|
// Step 6.5
|
||||||
|
@ -1081,7 +1081,7 @@ impl HTMLFormElement {
|
||||||
/// 5.x substeps are mostly handled inside element-specific methods
|
/// 5.x substeps are mostly handled inside element-specific methods
|
||||||
fn get_unclean_dataset(
|
fn get_unclean_dataset(
|
||||||
&self,
|
&self,
|
||||||
submitter: Option<FormSubmitter>,
|
submitter: Option<FormSubmitterElement>,
|
||||||
encoding: Option<&'static Encoding>,
|
encoding: Option<&'static Encoding>,
|
||||||
) -> Vec<FormDatum> {
|
) -> Vec<FormDatum> {
|
||||||
let controls = self.controls.borrow();
|
let controls = self.controls.borrow();
|
||||||
|
@ -1171,7 +1171,7 @@ impl HTMLFormElement {
|
||||||
/// <https://html.spec.whatwg.org/multipage/#constructing-the-form-data-set>
|
/// <https://html.spec.whatwg.org/multipage/#constructing-the-form-data-set>
|
||||||
pub fn get_form_dataset(
|
pub fn get_form_dataset(
|
||||||
&self,
|
&self,
|
||||||
submitter: Option<FormSubmitter>,
|
submitter: Option<FormSubmitterElement>,
|
||||||
encoding: Option<&'static Encoding>,
|
encoding: Option<&'static Encoding>,
|
||||||
) -> Option<Vec<FormDatum>> {
|
) -> Option<Vec<FormDatum>> {
|
||||||
fn clean_crlf(s: &str) -> DOMString {
|
fn clean_crlf(s: &str) -> DOMString {
|
||||||
|
@ -1380,24 +1380,24 @@ pub enum FormMethod {
|
||||||
|
|
||||||
/// <https://html.spec.whatwg.org/multipage/#form-associated-element>
|
/// <https://html.spec.whatwg.org/multipage/#form-associated-element>
|
||||||
#[derive(Clone, Copy, MallocSizeOf)]
|
#[derive(Clone, Copy, MallocSizeOf)]
|
||||||
pub enum FormSubmitter<'a> {
|
pub enum FormSubmitterElement<'a> {
|
||||||
FormElement(&'a HTMLFormElement),
|
Form(&'a HTMLFormElement),
|
||||||
InputElement(&'a HTMLInputElement),
|
Input(&'a HTMLInputElement),
|
||||||
ButtonElement(&'a HTMLButtonElement),
|
Button(&'a HTMLButtonElement),
|
||||||
// TODO: implement other types of form associated elements
|
// TODO: implement other types of form associated elements
|
||||||
// (including custom elements) that can be passed as submitter.
|
// (including custom elements) that can be passed as submitter.
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> FormSubmitter<'a> {
|
impl<'a> FormSubmitterElement<'a> {
|
||||||
fn action(&self) -> DOMString {
|
fn action(&self) -> DOMString {
|
||||||
match *self {
|
match *self {
|
||||||
FormSubmitter::FormElement(form) => form.Action(),
|
FormSubmitterElement::Form(form) => form.Action(),
|
||||||
FormSubmitter::InputElement(input_element) => input_element.get_form_attribute(
|
FormSubmitterElement::Input(input_element) => input_element.get_form_attribute(
|
||||||
&local_name!("formaction"),
|
&local_name!("formaction"),
|
||||||
|i| i.FormAction(),
|
|i| i.FormAction(),
|
||||||
|f| f.Action(),
|
|f| f.Action(),
|
||||||
),
|
),
|
||||||
FormSubmitter::ButtonElement(button_element) => button_element.get_form_attribute(
|
FormSubmitterElement::Button(button_element) => button_element.get_form_attribute(
|
||||||
&local_name!("formaction"),
|
&local_name!("formaction"),
|
||||||
|i| i.FormAction(),
|
|i| i.FormAction(),
|
||||||
|f| f.Action(),
|
|f| f.Action(),
|
||||||
|
@ -1407,13 +1407,13 @@ impl<'a> FormSubmitter<'a> {
|
||||||
|
|
||||||
fn enctype(&self) -> FormEncType {
|
fn enctype(&self) -> FormEncType {
|
||||||
let attr = match *self {
|
let attr = match *self {
|
||||||
FormSubmitter::FormElement(form) => form.Enctype(),
|
FormSubmitterElement::Form(form) => form.Enctype(),
|
||||||
FormSubmitter::InputElement(input_element) => input_element.get_form_attribute(
|
FormSubmitterElement::Input(input_element) => input_element.get_form_attribute(
|
||||||
&local_name!("formenctype"),
|
&local_name!("formenctype"),
|
||||||
|i| i.FormEnctype(),
|
|i| i.FormEnctype(),
|
||||||
|f| f.Enctype(),
|
|f| f.Enctype(),
|
||||||
),
|
),
|
||||||
FormSubmitter::ButtonElement(button_element) => button_element.get_form_attribute(
|
FormSubmitterElement::Button(button_element) => button_element.get_form_attribute(
|
||||||
&local_name!("formenctype"),
|
&local_name!("formenctype"),
|
||||||
|i| i.FormEnctype(),
|
|i| i.FormEnctype(),
|
||||||
|f| f.Enctype(),
|
|f| f.Enctype(),
|
||||||
|
@ -1430,13 +1430,13 @@ impl<'a> FormSubmitter<'a> {
|
||||||
|
|
||||||
fn method(&self) -> FormMethod {
|
fn method(&self) -> FormMethod {
|
||||||
let attr = match *self {
|
let attr = match *self {
|
||||||
FormSubmitter::FormElement(form) => form.Method(),
|
FormSubmitterElement::Form(form) => form.Method(),
|
||||||
FormSubmitter::InputElement(input_element) => input_element.get_form_attribute(
|
FormSubmitterElement::Input(input_element) => input_element.get_form_attribute(
|
||||||
&local_name!("formmethod"),
|
&local_name!("formmethod"),
|
||||||
|i| i.FormMethod(),
|
|i| i.FormMethod(),
|
||||||
|f| f.Method(),
|
|f| f.Method(),
|
||||||
),
|
),
|
||||||
FormSubmitter::ButtonElement(button_element) => button_element.get_form_attribute(
|
FormSubmitterElement::Button(button_element) => button_element.get_form_attribute(
|
||||||
&local_name!("formmethod"),
|
&local_name!("formmethod"),
|
||||||
|i| i.FormMethod(),
|
|i| i.FormMethod(),
|
||||||
|f| f.Method(),
|
|f| f.Method(),
|
||||||
|
@ -1451,13 +1451,13 @@ impl<'a> FormSubmitter<'a> {
|
||||||
|
|
||||||
fn target(&self) -> DOMString {
|
fn target(&self) -> DOMString {
|
||||||
match *self {
|
match *self {
|
||||||
FormSubmitter::FormElement(form) => form.Target(),
|
FormSubmitterElement::Form(form) => form.Target(),
|
||||||
FormSubmitter::InputElement(input_element) => input_element.get_form_attribute(
|
FormSubmitterElement::Input(input_element) => input_element.get_form_attribute(
|
||||||
&local_name!("formtarget"),
|
&local_name!("formtarget"),
|
||||||
|i| i.FormTarget(),
|
|i| i.FormTarget(),
|
||||||
|f| f.Target(),
|
|f| f.Target(),
|
||||||
),
|
),
|
||||||
FormSubmitter::ButtonElement(button_element) => button_element.get_form_attribute(
|
FormSubmitterElement::Button(button_element) => button_element.get_form_attribute(
|
||||||
&local_name!("formtarget"),
|
&local_name!("formtarget"),
|
||||||
|i| i.FormTarget(),
|
|i| i.FormTarget(),
|
||||||
|f| f.Target(),
|
|f| f.Target(),
|
||||||
|
@ -1467,13 +1467,13 @@ impl<'a> FormSubmitter<'a> {
|
||||||
|
|
||||||
fn no_validate(&self, _form_owner: &HTMLFormElement) -> bool {
|
fn no_validate(&self, _form_owner: &HTMLFormElement) -> bool {
|
||||||
match *self {
|
match *self {
|
||||||
FormSubmitter::FormElement(form) => form.NoValidate(),
|
FormSubmitterElement::Form(form) => form.NoValidate(),
|
||||||
FormSubmitter::InputElement(input_element) => input_element.get_form_boolean_attribute(
|
FormSubmitterElement::Input(input_element) => input_element.get_form_boolean_attribute(
|
||||||
&local_name!("formnovalidate"),
|
&local_name!("formnovalidate"),
|
||||||
|i| i.FormNoValidate(),
|
|i| i.FormNoValidate(),
|
||||||
|f| f.NoValidate(),
|
|f| f.NoValidate(),
|
||||||
),
|
),
|
||||||
FormSubmitter::ButtonElement(button_element) => button_element
|
FormSubmitterElement::Button(button_element) => button_element
|
||||||
.get_form_boolean_attribute(
|
.get_form_boolean_attribute(
|
||||||
&local_name!("formnovalidate"),
|
&local_name!("formnovalidate"),
|
||||||
|i| i.FormNoValidate(),
|
|i| i.FormNoValidate(),
|
||||||
|
@ -1487,9 +1487,9 @@ impl<'a> FormSubmitter<'a> {
|
||||||
match *self {
|
match *self {
|
||||||
// https://html.spec.whatwg.org/multipage/#image-button-state-(type=image)
|
// https://html.spec.whatwg.org/multipage/#image-button-state-(type=image)
|
||||||
// https://html.spec.whatwg.org/multipage/#submit-button-state-(type=submit)
|
// https://html.spec.whatwg.org/multipage/#submit-button-state-(type=submit)
|
||||||
FormSubmitter::InputElement(input_element) => input_element.is_submit_button(),
|
FormSubmitterElement::Input(input_element) => input_element.is_submit_button(),
|
||||||
// https://html.spec.whatwg.org/multipage/#attr-button-type-submit-state
|
// https://html.spec.whatwg.org/multipage/#attr-button-type-submit-state
|
||||||
FormSubmitter::ButtonElement(button_element) => button_element.is_submit_button(),
|
FormSubmitterElement::Button(button_element) => button_element.is_submit_button(),
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1497,8 +1497,8 @@ impl<'a> FormSubmitter<'a> {
|
||||||
// https://html.spec.whatwg.org/multipage/#form-owner
|
// https://html.spec.whatwg.org/multipage/#form-owner
|
||||||
fn form_owner(&self) -> Option<DomRoot<HTMLFormElement>> {
|
fn form_owner(&self) -> Option<DomRoot<HTMLFormElement>> {
|
||||||
match *self {
|
match *self {
|
||||||
FormSubmitter::ButtonElement(button_el) => button_el.form_owner(),
|
FormSubmitterElement::Button(button_el) => button_el.form_owner(),
|
||||||
FormSubmitter::InputElement(input_el) => input_el.form_owner(),
|
FormSubmitterElement::Input(input_el) => input_el.form_owner(),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,7 +59,7 @@ use crate::dom::htmldatalistelement::HTMLDataListElement;
|
||||||
use crate::dom::htmlelement::HTMLElement;
|
use crate::dom::htmlelement::HTMLElement;
|
||||||
use crate::dom::htmlfieldsetelement::HTMLFieldSetElement;
|
use crate::dom::htmlfieldsetelement::HTMLFieldSetElement;
|
||||||
use crate::dom::htmlformelement::{
|
use crate::dom::htmlformelement::{
|
||||||
FormControl, FormDatum, FormDatumValue, FormSubmitter, HTMLFormElement, ResetFrom,
|
FormControl, FormDatum, FormDatumValue, FormSubmitterElement, HTMLFormElement, ResetFrom,
|
||||||
SubmittedFrom,
|
SubmittedFrom,
|
||||||
};
|
};
|
||||||
use crate::dom::keyboardevent::KeyboardEvent;
|
use crate::dom::keyboardevent::KeyboardEvent;
|
||||||
|
@ -1679,7 +1679,7 @@ impl HTMLInputElement {
|
||||||
/// Steps range from 5.1 to 5.10 (specific to HTMLInputElement)
|
/// Steps range from 5.1 to 5.10 (specific to HTMLInputElement)
|
||||||
pub fn form_datums(
|
pub fn form_datums(
|
||||||
&self,
|
&self,
|
||||||
submitter: Option<FormSubmitter>,
|
submitter: Option<FormSubmitterElement>,
|
||||||
encoding: Option<&'static Encoding>,
|
encoding: Option<&'static Encoding>,
|
||||||
) -> Vec<FormDatum> {
|
) -> Vec<FormDatum> {
|
||||||
// 3.1: disabled state check is in get_unclean_dataset
|
// 3.1: disabled state check is in get_unclean_dataset
|
||||||
|
@ -1690,7 +1690,7 @@ impl HTMLInputElement {
|
||||||
// Step 5.4
|
// Step 5.4
|
||||||
let name = self.Name();
|
let name = self.Name();
|
||||||
let is_submitter = match submitter {
|
let is_submitter = match submitter {
|
||||||
Some(FormSubmitter::InputElement(s)) => self == s,
|
Some(FormSubmitterElement::Input(s)) => self == s,
|
||||||
_ => false,
|
_ => false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -2107,7 +2107,7 @@ impl HTMLInputElement {
|
||||||
// lazily test for > 1 submission-blocking inputs
|
// lazily test for > 1 submission-blocking inputs
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
form.submit(SubmittedFrom::NotFromForm, FormSubmitter::FormElement(form));
|
form.submit(SubmittedFrom::NotFromForm, FormSubmitterElement::Form(form));
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2821,7 +2821,7 @@ impl Activatable for HTMLInputElement {
|
||||||
if let Some(o) = self.form_owner() {
|
if let Some(o) = self.form_owner() {
|
||||||
o.submit(
|
o.submit(
|
||||||
SubmittedFrom::NotFromForm,
|
SubmittedFrom::NotFromForm,
|
||||||
FormSubmitter::InputElement(self),
|
FormSubmitterElement::Input(self),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue