View Javadoc
1   /*
2    * Copyright (c) 2002-2025 Gargoyle Software Inc.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * https://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS,
11   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   * See the License for the specific language governing permissions and
13   * limitations under the License.
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.configuration.JsxClass;
22  import org.htmlunit.javascript.configuration.JsxConstructor;
23  
24  /**
25   * The JavaScript object {@code HTMLMenuElement}.
26   *
27   * @author Ahmed Ashour
28   * @author Frank Danek
29   * @author Ronald Brill
30   */
31  @JsxClass(domClass = HtmlMenu.class)
32  public class HTMLMenuElement extends HTMLListElement {
33  
34      /**
35       * JavaScript constructor.
36       */
37      @Override
38      @JsxConstructor
39      public void jsConstructor() {
40          super.jsConstructor();
41      }
42  
43      /**
44       * Returns the value of the {@code type} property.
45       * @return the value of the {@code type} property
46       */
47      @Override
48      public String getType() {
49          final String type = getDomNodeOrDie().getAttributeDirect("type");
50          if (getBrowserVersion().hasFeature(JS_MENU_TYPE_PASS)) {
51              return type;
52          }
53  
54          if ("context".equalsIgnoreCase(type)) {
55              return "context";
56          }
57          if ("toolbar".equalsIgnoreCase(type)) {
58              return "toolbar";
59          }
60  
61          return "list";
62      }
63  
64      /**
65       * Sets the value of the {@code type} property.
66       * @param type the value of the {@code type} property
67       */
68      @Override
69      public void setType(final String type) {
70          if (getBrowserVersion().hasFeature(JS_MENU_TYPE_PASS)) {
71              getDomNodeOrDie().setAttribute(DomElement.TYPE_ATTRIBUTE, type);
72              return;
73          }
74  
75          if ("context".equalsIgnoreCase(type)) {
76              getDomNodeOrDie().setAttribute(DomElement.TYPE_ATTRIBUTE, "context");
77              return;
78          }
79          if ("toolbar".equalsIgnoreCase(type)) {
80              getDomNodeOrDie().setAttribute(DomElement.TYPE_ATTRIBUTE, "toolbar");
81              return;
82          }
83  
84          getDomNodeOrDie().setAttribute(DomElement.TYPE_ATTRIBUTE, "list");
85      }
86  }