Skip to content

Commit

Permalink
Implement cannot navigate
Browse files Browse the repository at this point in the history
  • Loading branch information
CYBAI committed Jan 22, 2019
1 parent 9d70f51 commit cb86d45
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
12 changes: 12 additions & 0 deletions components/script/dom/element.rs
Expand Up @@ -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 {
Expand Down
16 changes: 14 additions & 2 deletions components/script/dom/htmlformelement.rs
Expand Up @@ -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;
Expand All @@ -342,6 +346,11 @@ impl HTMLFormElement {
if event.DefaultPrevented() {
return;
}

// Step 7-3
if self.upcast::<Element>().cannot_navigate() {
return;
}
}

// Step 8
Expand All @@ -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();
Expand Down
4 changes: 0 additions & 4 deletions tests/wpt/metadata/dom/events/Event-dispatch-click.html.ini
Expand Up @@ -18,7 +18,3 @@

[redispatch during post-click handling]
expected: TIMEOUT

[disconnected form should not submit]
expected: FAIL

@@ -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

Expand Down

0 comments on commit cb86d45

Please sign in to comment.