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 @JsxClass(domClass = HtmlMenu.class)
35 public class HTMLMenuElement extends HTMLElement {
36
37
38
39
40 @Override
41 @JsxConstructor
42 public void jsConstructor() {
43 super.jsConstructor();
44 }
45
46
47
48
49
50 protected String getType() {
51 final String type = getDomNodeOrDie().getAttributeDirect("type");
52 if (getBrowserVersion().hasFeature(JS_MENU_TYPE_PASS)) {
53 return type;
54 }
55
56 if ("context".equalsIgnoreCase(type)) {
57 return "context";
58 }
59 if ("toolbar".equalsIgnoreCase(type)) {
60 return "toolbar";
61 }
62
63 return "list";
64 }
65
66
67
68
69
70 protected void setType(final String type) {
71 if (getBrowserVersion().hasFeature(JS_MENU_TYPE_PASS)) {
72 getDomNodeOrDie().setAttribute(DomElement.TYPE_ATTRIBUTE, type);
73 return;
74 }
75
76 if ("context".equalsIgnoreCase(type)) {
77 getDomNodeOrDie().setAttribute(DomElement.TYPE_ATTRIBUTE, "context");
78 return;
79 }
80 if ("toolbar".equalsIgnoreCase(type)) {
81 getDomNodeOrDie().setAttribute(DomElement.TYPE_ATTRIBUTE, "toolbar");
82 return;
83 }
84
85 getDomNodeOrDie().setAttribute(DomElement.TYPE_ATTRIBUTE, "list");
86 }
87
88
89
90
91
92 @JsxGetter
93 public boolean isCompact() {
94 return getDomNodeOrDie().hasAttribute("compact");
95 }
96
97
98
99
100
101 @JsxSetter
102 public void setCompact(final Object compact) {
103 if (JavaScriptEngine.toBoolean(compact)) {
104 getDomNodeOrDie().setAttribute("compact", "");
105 }
106 else {
107 getDomNodeOrDie().removeAttribute("compact");
108 }
109 }
110 }