Skip to content

Commit

Permalink
Auto merge of #12847 - clstl:HTMLDialogElement#close, r=nox
Browse files Browse the repository at this point in the history
Implements HTMLDialogElement#close

<!-- Please describe your changes on the following line: -->
Implements HTMLDialogElement#close according to [link](https://html.spec.whatwg.org/multipage/#the-dialog-element:dom-dialog-close)

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #12352
- [X] There are tests for these change

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/12847)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo committed Aug 24, 2016
2 parents 9d32088 + 0539022 commit ff1f9d4
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
27 changes: 26 additions & 1 deletion components/script/dom/htmldialogelement.rs
Expand Up @@ -5,11 +5,14 @@
use dom::bindings::cell::DOMRefCell;
use dom::bindings::codegen::Bindings::HTMLDialogElementBinding;
use dom::bindings::codegen::Bindings::HTMLDialogElementBinding::HTMLDialogElementMethods;
use dom::bindings::inheritance::Castable;
use dom::bindings::js::Root;
use dom::bindings::str::DOMString;
use dom::document::Document;
use dom::element::Element;
use dom::eventtarget::EventTarget;
use dom::htmlelement::HTMLElement;
use dom::node::Node;
use dom::node::{Node, window_from_node};
use string_cache::Atom;

#[dom_struct]
Expand Down Expand Up @@ -56,4 +59,26 @@ impl HTMLDialogElementMethods for HTMLDialogElement {
fn SetReturnValue(&self, return_value: DOMString) {
*self.return_value.borrow_mut() = return_value;
}

// https://html.spec.whatwg.org/multipage/#dom-dialog-close
fn Close(&self, return_value: Option<DOMString>) {
let element = self.upcast::<Element>();
let target = self.upcast::<EventTarget>();
let win = window_from_node(self);

// Step 1 & 2
if element.remove_attribute(&ns!(), &atom!("open")).is_none() {
return;
}

// Step 3
if let Some(new_value) = return_value {
*self.return_value.borrow_mut() = new_value;
}

// TODO: Step 4 implement pending dialog stack removal

// Step 5
win.dom_manipulation_task_source().queue_simple_event(target, atom!("close"), win.r());
}
}
2 changes: 1 addition & 1 deletion components/script/dom/webidls/HTMLDialogElement.webidl
Expand Up @@ -8,5 +8,5 @@ interface HTMLDialogElement : HTMLElement {
attribute DOMString returnValue;
//void show(optional (MouseEvent or Element) anchor);
//void showModal(optional (MouseEvent or Element) anchor);
//void close(optional DOMString returnValue);
void close(optional DOMString returnValue);
};
Expand Up @@ -36,10 +36,9 @@
was_queued = false;

test(function(){
assert_throws("INVALID_STATE_ERR", function() {
d1.close();
});
}, "close() on a <dialog> that doesn't have an open attribute throws an InvalidStateError exception");
d1.close("closedialog");
assert_equals(d1.returnValue, "");
}, "close() on a <dialog> that doesn't have an open attribute aborts the steps");

test(function(){
assert_true(d2.open);
Expand Down

0 comments on commit ff1f9d4

Please sign in to comment.