aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCYBAI <cyb.ai.815@gmail.com>2019-01-10 18:58:07 +0800
committerCYBAI <cyb.ai.815@gmail.com>2019-01-23 00:38:45 +0800
commitcb86d451e663646c496e6bece8b456f5196afca7 (patch)
tree92157282da4d6a9d15e4b463886d7b4b05bcfe68
parent9d70f5135614b8fa0ba4e1322ac114587b959eb5 (diff)
downloadservo-cb86d451e663646c496e6bece8b456f5196afca7.tar.gz
servo-cb86d451e663646c496e6bece8b456f5196afca7.zip
Implement cannot navigate
-rw-r--r--components/script/dom/element.rs12
-rwxr-xr-xcomponents/script/dom/htmlformelement.rs16
-rw-r--r--tests/wpt/metadata/dom/events/Event-dispatch-click.html.ini4
-rw-r--r--tests/wpt/metadata/html/semantics/forms/the-button-element/button-click-submits.html.ini6
4 files changed, 26 insertions, 12 deletions
diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs
index 155098247b6..234a10f9448 100644
--- a/components/script/dom/element.rs
+++ b/components/script/dom/element.rs
@@ -3235,6 +3235,18 @@ impl Element {
let root = node.GetRootNode();
root.is::<Document>()
}
+
+ // https://html.spec.whatwg.org/multipage/#cannot-navigate
+ pub fn cannot_navigate(&self) -> bool {
+ let document = document_from_node(self);
+
+ // Step 1.
+ !document.is_fully_active() ||
+ (
+ // Step 2.
+ !self.is::<HTMLAnchorElement>() && !self.is_connected()
+ )
+ }
}
impl Element {
diff --git a/components/script/dom/htmlformelement.rs b/components/script/dom/htmlformelement.rs
index 6a4a4b97fe5..e81613d750d 100755
--- a/components/script/dom/htmlformelement.rs
+++ b/components/script/dom/htmlformelement.rs
@@ -317,7 +317,11 @@ impl HTMLFormElement {
/// [Form submission](https://html.spec.whatwg.org/multipage/#concept-form-submit)
pub fn submit(&self, submit_method_flag: SubmittedFrom, submitter: FormSubmitter) {
- // TODO: Step 1. If form cannot navigate , then return.
+ // Step 1
+ if self.upcast::<Element>().cannot_navigate() {
+ return;
+ }
+
// Step 2
if self.constructing_entry_list.get() {
return;
@@ -342,6 +346,11 @@ impl HTMLFormElement {
if event.DefaultPrevented() {
return;
}
+
+ // Step 7-3
+ if self.upcast::<Element>().cannot_navigate() {
+ return;
+ }
}
// Step 8
@@ -353,7 +362,10 @@ impl HTMLFormElement {
None => return,
};
- // TODO: Step 10. If form cannot navigate, then return.
+ // Step 10
+ if self.upcast::<Element>().cannot_navigate() {
+ return;
+ }
// Step 11
let mut action = submitter.action();
diff --git a/tests/wpt/metadata/dom/events/Event-dispatch-click.html.ini b/tests/wpt/metadata/dom/events/Event-dispatch-click.html.ini
index be409a414f9..79e10b2df01 100644
--- a/tests/wpt/metadata/dom/events/Event-dispatch-click.html.ini
+++ b/tests/wpt/metadata/dom/events/Event-dispatch-click.html.ini
@@ -18,7 +18,3 @@
[redispatch during post-click handling]
expected: TIMEOUT
-
- [disconnected form should not submit]
- expected: FAIL
-
diff --git a/tests/wpt/metadata/html/semantics/forms/the-button-element/button-click-submits.html.ini b/tests/wpt/metadata/html/semantics/forms/the-button-element/button-click-submits.html.ini
index 13f78590065..680eb46f5d3 100644
--- a/tests/wpt/metadata/html/semantics/forms/the-button-element/button-click-submits.html.ini
+++ b/tests/wpt/metadata/html/semantics/forms/the-button-element/button-click-submits.html.ini
@@ -1,15 +1,9 @@
[button-click-submits.html]
type: testharness
expected: TIMEOUT
- [clicking a button with .click() should not trigger a submit (form disconnected)]
- expected: FAIL
-
[clicking a button by dispatching an event should trigger a submit (form connected)]
expected: TIMEOUT
- [clicking a button that cancels the event should not trigger a submit]
- expected: FAIL
-
[clicking the child of a button by dispatching a bubbling event should trigger a submit]
expected: TIMEOUT