aboutsummaryrefslogtreecommitdiffstats
path: root/components/script
diff options
context:
space:
mode:
authortakumi <takumi@indeed.com>2019-10-12 21:37:21 +0900
committertakumi <takumi@indeed.com>2019-10-18 15:00:03 +0900
commit7ce40080bf8a956a60a0a2a6d4258ed959ebceab (patch)
tree372e1fe0c50571af7c832d9834468d29a10f03e0 /components/script
parent8ecbed9e423c473854143cef059d3bbc687777da (diff)
downloadservo-7ce40080bf8a956a60a0a2a6d4258ed959ebceab.tar.gz
servo-7ce40080bf8a956a60a0a2a6d4258ed959ebceab.zip
[WIP] solve #22782
TODO: write tests for my change
Diffstat (limited to 'components/script')
-rw-r--r--components/script/dom/activation.rs3
-rw-r--r--components/script/dom/document.rs43
-rw-r--r--components/script/dom/htmlanchorelement.rs10
-rw-r--r--components/script/dom/htmlareaelement.rs9
-rwxr-xr-xcomponents/script/dom/htmlbuttonelement.rs29
-rwxr-xr-xcomponents/script/dom/htmlinputelement.rs138
-rw-r--r--components/script/dom/htmllabelelement.rs12
7 files changed, 85 insertions, 159 deletions
diff --git a/components/script/dom/activation.rs b/components/script/dom/activation.rs
index e4658de2e9f..a12874b9b43 100644
--- a/components/script/dom/activation.rs
+++ b/components/script/dom/activation.rs
@@ -30,9 +30,6 @@ pub trait Activatable {
// https://html.spec.whatwg.org/multipage/#run-post-click-activation-steps
fn activation_behavior(&self, event: &Event, target: &EventTarget);
- // https://html.spec.whatwg.org/multipage/#implicit-submission
- fn implicit_submission(&self, ctrl_key: bool, shift_key: bool, alt_key: bool, meta_key: bool);
-
// https://html.spec.whatwg.org/multipage/#concept-selector-active
fn enter_formal_activation_state(&self) {
self.as_element().set_active_state(true);
diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs
index 6581dbd54bb..3515008588b 100644
--- a/components/script/dom/document.rs
+++ b/components/script/dom/document.rs
@@ -121,7 +121,7 @@ use html5ever::{LocalName, Namespace, QualName};
use hyper_serde::Serde;
use ipc_channel::ipc::{self, IpcSender};
use js::jsapi::{JSObject, JSRuntime};
-use keyboard_types::{Key, KeyState, Modifiers};
+use keyboard_types::{Code, Key, KeyState};
use metrics::{
InteractiveFlag, InteractiveMetrics, InteractiveWindow, ProfilerMetadataFactory,
ProgressiveWebMetric,
@@ -1469,35 +1469,20 @@ impl Document {
// however *when* we do it is up to us.
// Here, we're dispatching it after the key event so the script has a chance to cancel it
// https://www.w3.org/Bugs/Public/show_bug.cgi?id=27337
- match keyboard_event.key {
- Key::Character(ref letter)
- if letter == " " && keyboard_event.state == KeyState::Up =>
- {
- let maybe_elem = target.downcast::<Element>();
- if let Some(el) = maybe_elem {
- synthetic_click_activation(
- el,
- false,
- false,
- false,
- false,
- ActivationSource::NotFromClick,
- )
- }
+ if (keyboard_event.key == Key::Enter && keyboard_event.state == KeyState::Up) ||
+ (keyboard_event.code == Code::Space && keyboard_event.state == KeyState::Down)
+ {
+ let maybe_elem = target.downcast::<Element>();
+ if let Some(el) = maybe_elem {
+ synthetic_click_activation(
+ el,
+ false,
+ false,
+ false,
+ false,
+ ActivationSource::NotFromClick,
+ )
}
- Key::Enter if keyboard_event.state == KeyState::Up => {
- let maybe_elem = target.downcast::<Element>();
- if let Some(el) = maybe_elem {
- if let Some(a) = el.as_maybe_activatable() {
- let ctrl = keyboard_event.modifiers.contains(Modifiers::CONTROL);
- let alt = keyboard_event.modifiers.contains(Modifiers::ALT);
- let shift = keyboard_event.modifiers.contains(Modifiers::SHIFT);
- let meta = keyboard_event.modifiers.contains(Modifiers::META);
- a.implicit_submission(ctrl, alt, shift, meta);
- }
- }
- },
- _ => (),
}
}
diff --git a/components/script/dom/htmlanchorelement.rs b/components/script/dom/htmlanchorelement.rs
index c5b3fb51362..de082a9807e 100644
--- a/components/script/dom/htmlanchorelement.rs
+++ b/components/script/dom/htmlanchorelement.rs
@@ -578,16 +578,6 @@ impl Activatable for HTMLAnchorElement {
//TODO: Download the link is `download` attribute is set.
follow_hyperlink(element, ismap_suffix);
}
-
- //TODO:https://html.spec.whatwg.org/multipage/#the-a-element
- fn implicit_submission(
- &self,
- _ctrl_key: bool,
- _shift_key: bool,
- _alt_key: bool,
- _meta_key: bool,
- ) {
- }
}
/// <https://html.spec.whatwg.org/multipage/#following-hyperlinks-2>
diff --git a/components/script/dom/htmlareaelement.rs b/components/script/dom/htmlareaelement.rs
index 65e47911c0d..85253339347 100644
--- a/components/script/dom/htmlareaelement.rs
+++ b/components/script/dom/htmlareaelement.rs
@@ -326,15 +326,6 @@ impl Activatable for HTMLAreaElement {
fn canceled_activation(&self) {}
- fn implicit_submission(
- &self,
- _ctrl_key: bool,
- _shift_key: bool,
- _alt_key: bool,
- _meta_key: bool,
- ) {
- }
-
fn activation_behavior(&self, _event: &Event, _target: &EventTarget) {
follow_hyperlink(self.as_element(), None);
}
diff --git a/components/script/dom/htmlbuttonelement.rs b/components/script/dom/htmlbuttonelement.rs
index a7b8dacd060..1406ceb870b 100755
--- a/components/script/dom/htmlbuttonelement.rs
+++ b/components/script/dom/htmlbuttonelement.rs
@@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
-use crate::dom::activation::{synthetic_click_activation, Activatable, ActivationSource};
+use crate::dom::activation::Activatable;
use crate::dom::attr::Attr;
use crate::dom::bindings::codegen::Bindings::HTMLButtonElementBinding;
use crate::dom::bindings::codegen::Bindings::HTMLButtonElementBinding::HTMLButtonElementMethods;
@@ -18,7 +18,7 @@ use crate::dom::htmlfieldsetelement::HTMLFieldSetElement;
use crate::dom::htmlformelement::HTMLFormElement;
use crate::dom::htmlformelement::{FormControl, FormDatum, FormDatumValue};
use crate::dom::htmlformelement::{FormSubmitter, ResetFrom, SubmittedFrom};
-use crate::dom::node::{document_from_node, window_from_node, BindContext, Node, UnbindContext};
+use crate::dom::node::{window_from_node, BindContext, Node, UnbindContext};
use crate::dom::nodelist::NodeList;
use crate::dom::validation::Validatable;
use crate::dom::validitystate::{ValidationFlags, ValidityState};
@@ -322,29 +322,4 @@ impl Activatable for HTMLButtonElement {
_ => (),
}
}
-
- // https://html.spec.whatwg.org/multipage/#implicit-submission
- #[allow(unsafe_code)]
- fn implicit_submission(&self, ctrl_key: bool, shift_key: bool, alt_key: bool, meta_key: bool) {
- let doc = document_from_node(self);
- let node = doc.upcast::<Node>();
- let owner = self.form_owner();
- if owner.is_none() || self.upcast::<Element>().click_in_progress() {
- return;
- }
- node.query_selector_iter(DOMString::from("button[type=submit]"))
- .unwrap()
- .filter_map(DomRoot::downcast::<HTMLButtonElement>)
- .find(|r| r.form_owner() == owner)
- .map(|s| {
- synthetic_click_activation(
- s.as_element(),
- ctrl_key,
- shift_key,
- alt_key,
- meta_key,
- ActivationSource::NotFromClick,
- )
- });
- }
}
diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs
index cb99d0426ee..60b5cb9bcb1 100755
--- a/components/script/dom/htmlinputelement.rs
+++ b/components/script/dom/htmlinputelement.rs
@@ -1221,6 +1221,75 @@ impl HTMLInputElement {
fn selection(&self) -> TextControlSelection<Self> {
TextControlSelection::new(&self, &self.textinput)
}
+
+ // https://html.spec.whatwg.org/multipage/#implicit-submission
+ #[allow(unsafe_code)]
+ fn implicit_submission(&self, ctrl_key: bool, shift_key: bool, alt_key: bool, meta_key: bool) {
+ let doc = document_from_node(self);
+ let node = doc.upcast::<Node>();
+ let owner = self.form_owner();
+ let form = match owner {
+ None => return,
+ Some(ref f) => f,
+ };
+
+ if self.upcast::<Element>().click_in_progress() {
+ return;
+ }
+ let submit_button;
+ submit_button = node
+ .query_selector_iter(DOMString::from("input[type=submit]"))
+ .unwrap()
+ .filter_map(DomRoot::downcast::<HTMLInputElement>)
+ .find(|r| r.form_owner() == owner);
+ match submit_button {
+ Some(ref button) => {
+ if button.is_instance_activatable() {
+ synthetic_click_activation(
+ button.as_element(),
+ ctrl_key,
+ shift_key,
+ alt_key,
+ meta_key,
+ ActivationSource::NotFromClick,
+ )
+ }
+ },
+ None => {
+ let inputs = node
+ .query_selector_iter(DOMString::from("input"))
+ .unwrap()
+ .filter_map(DomRoot::downcast::<HTMLInputElement>)
+ .filter(|input| {
+ input.form_owner() == owner &&
+ match input.input_type() {
+ InputType::Text |
+ InputType::Search |
+ InputType::Url |
+ InputType::Tel |
+ InputType::Email |
+ InputType::Password |
+ InputType::Date |
+ InputType::Month |
+ InputType::Week |
+ InputType::Time |
+ InputType::DatetimeLocal |
+ InputType::Number => true,
+ _ => false,
+ }
+ });
+
+ if inputs.skip(1).next().is_some() {
+ // lazily test for > 1 submission-blocking inputs
+ return;
+ }
+ form.submit(
+ SubmittedFrom::NotFromForm,
+ FormSubmitter::FormElement(&form),
+ );
+ },
+ }
+ }
}
impl VirtualMethods for HTMLInputElement {
@@ -1746,75 +1815,6 @@ impl Activatable for HTMLInputElement {
_ => (),
}
}
-
- // https://html.spec.whatwg.org/multipage/#implicit-submission
- #[allow(unsafe_code)]
- fn implicit_submission(&self, ctrl_key: bool, shift_key: bool, alt_key: bool, meta_key: bool) {
- let doc = document_from_node(self);
- let node = doc.upcast::<Node>();
- let owner = self.form_owner();
- let form = match owner {
- None => return,
- Some(ref f) => f,
- };
-
- if self.upcast::<Element>().click_in_progress() {
- return;
- }
- let submit_button;
- submit_button = node
- .query_selector_iter(DOMString::from("input[type=submit]"))
- .unwrap()
- .filter_map(DomRoot::downcast::<HTMLInputElement>)
- .find(|r| r.form_owner() == owner);
- match submit_button {
- Some(ref button) => {
- if button.is_instance_activatable() {
- synthetic_click_activation(
- button.as_element(),
- ctrl_key,
- shift_key,
- alt_key,
- meta_key,
- ActivationSource::NotFromClick,
- )
- }
- },
- None => {
- let inputs = node
- .query_selector_iter(DOMString::from("input"))
- .unwrap()
- .filter_map(DomRoot::downcast::<HTMLInputElement>)
- .filter(|input| {
- input.form_owner() == owner &&
- match input.input_type() {
- InputType::Text |
- InputType::Search |
- InputType::Url |
- InputType::Tel |
- InputType::Email |
- InputType::Password |
- InputType::Date |
- InputType::Month |
- InputType::Week |
- InputType::Time |
- InputType::DatetimeLocal |
- InputType::Number => true,
- _ => false,
- }
- });
-
- if inputs.skip(1).next().is_some() {
- // lazily test for > 1 submission-blocking inputs
- return;
- }
- form.submit(
- SubmittedFrom::NotFromForm,
- FormSubmitter::FormElement(&form),
- );
- },
- }
- }
}
// https://html.spec.whatwg.org/multipage/#attr-input-accept
diff --git a/components/script/dom/htmllabelelement.rs b/components/script/dom/htmllabelelement.rs
index 11ee09bce94..0a1401d6283 100644
--- a/components/script/dom/htmllabelelement.rs
+++ b/components/script/dom/htmllabelelement.rs
@@ -83,18 +83,6 @@ impl Activatable for HTMLLabelElement {
);
}
}
-
- // https://html.spec.whatwg.org/multipage/#implicit-submission
- fn implicit_submission(
- &self,
- _ctrl_key: bool,
- _shift_key: bool,
- _alt_key: bool,
- _meta_key: bool,
- ) {
- //FIXME: Investigate and implement implicit submission for label elements
- // Issue filed at https://github.com/servo/servo/issues/8263
- }
}
impl HTMLLabelElementMethods for HTMLLabelElement {