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 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 @JsxClass(domClass = HtmlMap.class)
38 public class HTMLMapElement extends HTMLElement {
39
40 private HTMLCollection areas_;
41
42 /**
43 * JavaScript constructor.
44 */
45 @Override
46 @JsxConstructor
47 public void jsConstructor() {
48 super.jsConstructor();
49 }
50
51 /**
52 * Returns the value of the JavaScript attribute {@code areas}.
53 * @return the value of this attribute
54 */
55 @JsxGetter
56 public HTMLCollection getAreas() {
57 if (areas_ == null) {
58 final HtmlMap map = (HtmlMap) getDomNodeOrDie();
59 areas_ = new HTMLCollection(map, false);
60 areas_.setElementsSupplier(
61 (Supplier<List<DomNode>> & Serializable)
62 () -> {
63 final List<DomNode> list = new ArrayList<>();
64 for (final DomNode node : map.getChildElements()) {
65 if (node instanceof HtmlArea) {
66 list.add(node);
67 }
68 }
69 return list;
70 });
71 }
72 return areas_;
73 }
74
75 /**
76 * Returns the {@code name} attribute.
77 * @return the {@code name} attribute
78 */
79 @JsxGetter
80 @Override
81 public String getName() {
82 return getDomNodeOrDie().getAttributeDirect(DomElement.NAME_ATTRIBUTE);
83 }
84
85 /**
86 * Sets the {@code name} attribute.
87 * @param name the {@code name} attribute
88 */
89 @JsxSetter
90 @Override
91 public void setName(final String name) {
92 getDomNodeOrDie().setAttribute(DomElement.NAME_ATTRIBUTE, name);
93 }
94
95 }