Move check for mutability up as a guard clause

This commit is contained in:
Keith Yeung 2016-04-11 08:55:26 -04:00
parent 916c035b57
commit 814afd6537

View file

@ -1016,8 +1016,8 @@ impl Activatable for HTMLInputElement {
// https://html.spec.whatwg.org/multipage/#run-post-click-activation-steps // https://html.spec.whatwg.org/multipage/#run-post-click-activation-steps
fn activation_behavior(&self, _event: &Event, _target: &EventTarget) { fn activation_behavior(&self, _event: &Event, _target: &EventTarget) {
let ty = self.input_type.get(); let ty = self.input_type.get();
if self.activation_state.borrow().old_type != ty { if self.activation_state.borrow().old_type != ty || !self.is_mutable() {
// Type changed, abandon ship // Type changed or input is immutable, abandon ship
// https://www.w3.org/Bugs/Public/show_bug.cgi?id=27414 // https://www.w3.org/Bugs/Public/show_bug.cgi?id=27414
return; return;
} }
@ -1025,34 +1025,31 @@ impl Activatable for HTMLInputElement {
InputType::InputSubmit => { InputType::InputSubmit => {
// https://html.spec.whatwg.org/multipage/#submit-button-state-(type=submit):activation-behavior // https://html.spec.whatwg.org/multipage/#submit-button-state-(type=submit):activation-behavior
// FIXME (Manishearth): support document owners (needs ability to get parent browsing context) // FIXME (Manishearth): support document owners (needs ability to get parent browsing context)
if self.is_mutable() /* and document owner is fully active */ { // Check if document owner is fully active
self.form_owner().map(|o| { self.form_owner().map(|o| {
o.submit(SubmittedFrom::NotFromFormSubmitMethod, o.submit(SubmittedFrom::NotFromFormSubmitMethod,
FormSubmitter::InputElement(self.clone())) FormSubmitter::InputElement(self.clone()))
}); });
}
}, },
InputType::InputReset => { InputType::InputReset => {
// https://html.spec.whatwg.org/multipage/#reset-button-state-(type=reset):activation-behavior // https://html.spec.whatwg.org/multipage/#reset-button-state-(type=reset):activation-behavior
// FIXME (Manishearth): support document owners (needs ability to get parent browsing context) // FIXME (Manishearth): support document owners (needs ability to get parent browsing context)
if self.is_mutable() /* and document owner is fully active */ { // Check if document owner is fully active
self.form_owner().map(|o| { self.form_owner().map(|o| {
o.reset(ResetFrom::NotFromFormResetMethod) o.reset(ResetFrom::NotFromFormResetMethod)
}); });
}
}, },
InputType::InputCheckbox | InputType::InputRadio => { InputType::InputCheckbox | InputType::InputRadio => {
// https://html.spec.whatwg.org/multipage/#checkbox-state-(type=checkbox):activation-behavior // https://html.spec.whatwg.org/multipage/#checkbox-state-(type=checkbox):activation-behavior
// https://html.spec.whatwg.org/multipage/#radio-button-state-(type=radio):activation-behavior // https://html.spec.whatwg.org/multipage/#radio-button-state-(type=radio):activation-behavior
if self.is_mutable() { // Check if document owner is fully active
let target = self.upcast::<EventTarget>(); let target = self.upcast::<EventTarget>();
target.fire_event("input", target.fire_event("input",
EventBubbles::Bubbles, EventBubbles::Bubbles,
EventCancelable::NotCancelable); EventCancelable::NotCancelable);
target.fire_event("change", target.fire_event("change",
EventBubbles::Bubbles, EventBubbles::Bubbles,
EventCancelable::NotCancelable); EventCancelable::NotCancelable);
}
}, },
_ => () _ => ()
} }