-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathDocument.java
More file actions
71 lines (62 loc) · 1.81 KB
/
Document.java
File metadata and controls
71 lines (62 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package snap.webapi;
/**
* This class is a wrapper for Web API Document (https://developer.mozilla.org/en-US/docs/Web/API/Document).
*/
public class Document extends Node implements EventTarget {
// The document HTML element
private HTMLHtmlElement _html;
// The Body element
private HTMLBodyElement _body;
/**
* Constructor.
*/
public Document(Object jsObj)
{
super(jsObj);
}
/**
* Returns Document.documentElement for this document.
*/
public HTMLHtmlElement getDocumentElement()
{
if (_html != null) return _html;
Object htmlElementJS = getMember("documentElement");
return _html = new HTMLHtmlElement(htmlElementJS);
}
/**
* Returns the HTMLBodyElement for this document.
*/
public HTMLBodyElement getBody()
{
if (_body != null) return _body;
Object bodyJS = getMember("body");
return _body = new HTMLBodyElement(bodyJS);
}
/**
* Returns the HTMLHeadElement for this document.
*/
public HTMLHeadElement getHead()
{
Object headJS = getMember("head");
return new HTMLHeadElement(headJS);
}
/**
* Returns an object reference to the identified element.
*/
public HTMLElement getElementById(String idStr)
{
Object elementJS = call("getElementById", idStr);
if (elementJS == null)
return null;
String tagName = WebEnv.get().getMemberString(elementJS, "nodeName");
return HTMLElement.getElementForName(tagName, elementJS);
}
/**
* Creates the HTML element specified by tagName.
*/
public HTMLElement createElement(String tagName)
{
Object elementJS = call("createElement", tagName);
return HTMLElement.getElementForName(tagName, elementJS);
}
}