Skip to content

Commit

Permalink
Implementing document.hasFocus method. #6475
Browse files Browse the repository at this point in the history
  • Loading branch information
Maciej Skrzypkowski committed Aug 10, 2015
1 parent 8edf1a5 commit 07c0cd8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
21 changes: 21 additions & 0 deletions components/script/dom/document.rs
Expand Up @@ -1183,6 +1183,27 @@ impl<'a> DocumentMethods for &'a Document {
}
}

// https://html.spec.whatwg.org/#dom-document-hasfocus
fn HasFocus(self) -> bool {
let target = self; // Step 1.
let window = self.window.root();
let window = window.r();
let browsing_context = window.browsing_context();
let browsing_context = browsing_context.as_ref();

match browsing_context {
Some(browsing_context) => {
let condidate = browsing_context.active_document(); // Step 2.
if condidate.node.get_unique_id() == target.node.get_unique_id() { // Step 3.
true
} else {
false //TODO Step 4.
}
}
None => false
}
}

// https://dom.spec.whatwg.org/#dom-document-documenturi
fn DocumentURI(self) -> DOMString {
self.URL()
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/webidls/Document.webidl
Expand Up @@ -114,7 +114,7 @@ partial /*sealed*/ interface Document {
// user interaction
readonly attribute Window/*Proxy?*/ defaultView;
// readonly attribute Element? activeElement;
// boolean hasFocus();
boolean hasFocus();
// attribute DOMString designMode;
// boolean execCommand(DOMString commandId, optional boolean showUI = false, optional DOMString value = "");
// boolean queryCommandEnabled(DOMString commandId);
Expand Down
6 changes: 0 additions & 6 deletions tests/wpt/metadata/html/dom/interfaces.html.ini
Expand Up @@ -30,9 +30,6 @@
[Document interface: operation writeln(DOMString)]
expected: FAIL

[Document interface: operation hasFocus()]
expected: FAIL

[Document interface: attribute designMode]
expected: FAIL

Expand Down Expand Up @@ -1098,9 +1095,6 @@
[Document interface: calling writeln(DOMString) on document.implementation.createDocument(null, "", null) with too few arguments must throw TypeError]
expected: FAIL

[Document interface: document.implementation.createDocument(null, "", null) must inherit property "hasFocus" with the proper type (61)]
expected: FAIL

[Document interface: document.implementation.createDocument(null, "", null) must inherit property "designMode" with the proper type (62)]
expected: FAIL

Expand Down

0 comments on commit 07c0cd8

Please sign in to comment.