1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit.javascript.host.html;
16
17 import static org.htmlunit.BrowserVersionFeatures.JS_MENU_TYPE_PASS;
18
19 import org.htmlunit.html.DomElement;
20 import org.htmlunit.html.HtmlMenu;
21 import org.htmlunit.javascript.JavaScriptEngine;
22 import org.htmlunit.javascript.configuration.JsxClass;
23 import org.htmlunit.javascript.configuration.JsxConstructor;
24 import org.htmlunit.javascript.configuration.JsxGetter;
25 import org.htmlunit.javascript.configuration.JsxSetter;
26
27
28
29
30
31
32
33
34
35
36 @JsxClass(domClass = HtmlMenu.class)
37 public class HTMLMenuElement extends HTMLElement {
38
39
40
41
42 @Override
43 @JsxConstructor
44 public void jsConstructor() {
45 super.jsConstructor();
46 }
47
48
49
50
51
52 protected String getType() {
53 final String type = getDomNodeOrDie().getAttributeDirect("type");
54 if (getBrowserVersion().hasFeature(JS_MENU_TYPE_PASS)) {
55 return type;
56 }
57
58 if ("context".equalsIgnoreCase(type)) {
59 return "context";
60 }
61 if ("toolbar".equalsIgnoreCase(type)) {
62 return "toolbar";
63 }
64
65 return "list";
66 }
67
68
69
70
71
72 protected void setType(final String type) {
73 if (getBrowserVersion().hasFeature(JS_MENU_TYPE_PASS)) {
74 getDomNodeOrDie().setAttribute(DomElement.TYPE_ATTRIBUTE, type);
75 return;
76 }
77
78 if ("context".equalsIgnoreCase(type)) {
79 getDomNodeOrDie().setAttribute(DomElement.TYPE_ATTRIBUTE, "context");
80 return;
81 }
82 if ("toolbar".equalsIgnoreCase(type)) {
83 getDomNodeOrDie().setAttribute(DomElement.TYPE_ATTRIBUTE, "toolbar");
84 return;
85 }
86
87 getDomNodeOrDie().setAttribute(DomElement.TYPE_ATTRIBUTE, "list");
88 }
89
90
91
92
93
94 @JsxGetter
95 public boolean isCompact() {
96 return getDomNodeOrDie().hasAttribute("compact");
97 }
98
99
100
101
102
103 @JsxSetter
104 public void setCompact(final Object compact) {
105 if (JavaScriptEngine.toBoolean(compact)) {
106 getDomNodeOrDie().setAttribute("compact", "");
107 }
108 else {
109 getDomNodeOrDie().removeAttribute("compact");
110 }
111 }
112 }