mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Added document.activeElement attribute.
This commit is contained in:
parent
82f70c5d50
commit
7da356cd05
6 changed files with 43 additions and 9 deletions
|
@ -834,6 +834,19 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
|
|||
self.url().serialize()
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/interaction.html#dom-document-activeelement
|
||||
fn GetActiveElement(self) -> Option<Temporary<Element>> {
|
||||
// TODO: Step 2.
|
||||
|
||||
match self.get_focused_element() {
|
||||
Some(element) => Some(element), // Step 3. and 4.
|
||||
None => match self.GetBody() { // Step 5.
|
||||
Some(body) => Some(ElementCast::from_temporary(body)),
|
||||
None => self.GetDocumentElement(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// http://dom.spec.whatwg.org/#dom-document-documenturi
|
||||
fn DocumentURI(self) -> DOMString {
|
||||
self.URL()
|
||||
|
|
|
@ -435,6 +435,7 @@ pub trait ElementHelpers<'a> {
|
|||
fn get_inline_style_declaration(self, property: &Atom) -> Option<PropertyDeclaration>;
|
||||
fn get_important_inline_style_declaration(self, property: &Atom) -> Option<PropertyDeclaration>;
|
||||
fn serialize(self, traversal_scope: TraversalScope) -> Fallible<DOMString>;
|
||||
fn get_root_element(self) -> Option<Temporary<Element>>;
|
||||
}
|
||||
|
||||
impl<'a> ElementHelpers<'a> for JSRef<'a, Element> {
|
||||
|
@ -593,6 +594,15 @@ impl<'a> ElementHelpers<'a> for JSRef<'a, Element> {
|
|||
Err(_) => panic!("Cannot serialize element"),
|
||||
}
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/infrastructure.html#root-element
|
||||
fn get_root_element(self) -> Option<Temporary<Element>> {
|
||||
let node: JSRef<Node> = NodeCast::from_ref(self);
|
||||
match node.ancestors().last().map(ElementCast::to_ref) {
|
||||
Some(n) => n.map(Temporary::from_rooted),
|
||||
None => Some(self).map(Temporary::from_rooted),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub trait AttributeHandlers {
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
interface Document : Node {
|
||||
readonly attribute DOMImplementation implementation;
|
||||
readonly attribute DOMString URL;
|
||||
readonly attribute Element? activeElement;
|
||||
readonly attribute DOMString documentURI;
|
||||
readonly attribute DOMString compatMode;
|
||||
readonly attribute DOMString characterSet;
|
||||
|
|
19
tests/content/test_document_activeElement.html
Normal file
19
tests/content/test_document_activeElement.html
Normal file
|
@ -0,0 +1,19 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head >
|
||||
<title></title>
|
||||
<script src="harness.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<input id="foo" type="text"></input>
|
||||
<script>
|
||||
is_not(document.activeElement, null, "test_1.1, document.activeElement");
|
||||
is(document.activeElement, document.body, "test_1.2, document.activeElement");
|
||||
|
||||
//TODO: uncomment following lines when focus() method will be available
|
||||
//document.getElementById('foo').focus();
|
||||
is_not(document.activeElement, null, "test_2.1, document.activeElement");
|
||||
//is(document.activeElement, document.getElementById("foo"), "test_2.2, document.activeElement");
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -30,9 +30,6 @@
|
|||
[Document interface: operation writeln(DOMString)]
|
||||
expected: FAIL
|
||||
|
||||
[Document interface: attribute activeElement]
|
||||
expected: FAIL
|
||||
|
||||
[Document interface: operation hasFocus()]
|
||||
expected: FAIL
|
||||
|
||||
|
@ -1125,9 +1122,6 @@
|
|||
[Document interface: document.implementation.createDocument(null, "", null) must inherit property "defaultView" with the proper type (59)]
|
||||
expected: FAIL
|
||||
|
||||
[Document interface: document.implementation.createDocument(null, "", null) must inherit property "activeElement" with the proper type (60)]
|
||||
expected: FAIL
|
||||
|
||||
[Document interface: document.implementation.createDocument(null, "", null) must inherit property "hasFocus" with the proper type (61)]
|
||||
expected: FAIL
|
||||
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
[disabledElement.html]
|
||||
type: testharness
|
||||
[The body element must be the active element if no element is focused]
|
||||
expected: FAIL
|
||||
|
||||
[A disabled <button> should not be focusable]
|
||||
expected: FAIL
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue