View Javadoc
1   /*
2    * Copyright (c) 2002-2026 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 java.io.Serializable;
18  import java.util.ArrayList;
19  import java.util.List;
20  import java.util.function.Supplier;
21  
22  import org.htmlunit.html.DomElement;
23  import org.htmlunit.html.DomNode;
24  import org.htmlunit.html.HtmlArea;
25  import org.htmlunit.html.HtmlMap;
26  import org.htmlunit.javascript.configuration.JsxClass;
27  import org.htmlunit.javascript.configuration.JsxConstructor;
28  import org.htmlunit.javascript.configuration.JsxGetter;
29  import org.htmlunit.javascript.configuration.JsxSetter;
30  
31  /**
32   * The JavaScript object {@code HTMLMapElement}.
33   *
34   * @author Ahmed Ashour
35   * @author Ronald Brill
36   *
37   * @see <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLMapElement">MDN Documentation</a>
38   */
39  @JsxClass(domClass = HtmlMap.class)
40  public class HTMLMapElement extends HTMLElement {
41  
42      private HTMLCollection areas_;
43  
44      /**
45       * JavaScript constructor.
46       */
47      @Override
48      @JsxConstructor
49      public void jsConstructor() {
50          super.jsConstructor();
51      }
52  
53      /**
54       * Returns the value of the JavaScript attribute {@code areas}.
55       * @return the value of this attribute
56       */
57      @JsxGetter
58      public HTMLCollection getAreas() {
59          if (areas_ == null) {
60              final HtmlMap map = (HtmlMap) getDomNodeOrDie();
61              areas_ = new HTMLCollection(map, false);
62              areas_.setElementsSupplier(
63                      (Supplier<List<DomNode>> & Serializable)
64                      () -> {
65                          final List<DomNode> list = new ArrayList<>();
66                          for (final DomNode node : map.getChildElements()) {
67                              if (node instanceof HtmlArea) {
68                                  list.add(node);
69                              }
70                          }
71                          return list;
72                      });
73          }
74          return areas_;
75      }
76  
77      /**
78       * Returns the {@code name} attribute.
79       * @return the {@code name} attribute
80       */
81      @JsxGetter
82      @Override
83      public String getName() {
84          return getDomNodeOrDie().getAttributeDirect(DomElement.NAME_ATTRIBUTE);
85      }
86  
87      /**
88       * Sets the {@code name} attribute.
89       * @param name the {@code name} attribute value
90       */
91      @JsxSetter
92      @Override
93      public void setName(final String name) {
94          getDomNodeOrDie().setAttribute(DomElement.NAME_ATTRIBUTE, name);
95      }
96  
97  }