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.css;
16
17 import org.htmlunit.WebWindow;
18 import org.htmlunit.css.CssStyleSheet;
19 import org.htmlunit.cssparser.dom.MediaListImpl;
20 import org.htmlunit.javascript.configuration.JsxClass;
21 import org.htmlunit.javascript.configuration.JsxConstructor;
22 import org.htmlunit.javascript.configuration.JsxFunction;
23 import org.htmlunit.javascript.configuration.JsxGetter;
24 import org.htmlunit.javascript.host.event.EventTarget;
25
26 /**
27 * A JavaScript object for {@code MediaQueryList}.
28 *
29 * @author Ahmed Ashour
30 * @author Ronald Brill
31 */
32 @JsxClass
33 public class MediaQueryList extends EventTarget {
34
35 private String media_;
36
37 /**
38 * Default constructor.
39 */
40 public MediaQueryList() {
41 super();
42 }
43
44 /**
45 * JavaScript constructor.
46 */
47 @Override
48 @JsxConstructor
49 public void jsConstructor() {
50 super.jsConstructor();
51 }
52
53 /**
54 * Constructor.
55 *
56 * @param mediaQueryString the media query string
57 */
58 public MediaQueryList(final String mediaQueryString) {
59 super();
60 media_ = mediaQueryString;
61 }
62
63 /**
64 * Returns the {@code media} property.
65 * @return the {@code media} property
66 */
67 @JsxGetter
68 public String getMedia() {
69 return media_;
70 }
71
72 /**
73 * Returns whether the document currently matches the media query list or not.
74 * @return whether the document currently matches the media query list or not
75 */
76 @JsxGetter
77 public boolean isMatches() {
78 final WebWindow webWindow = getWindow().getWebWindow();
79 final MediaListImpl mediaList = CssStyleSheet.parseMedia(media_, webWindow.getWebClient());
80 return CssStyleSheet.isActive(mediaList, webWindow);
81 }
82
83 /**
84 * Adds the {@code listener} event handler for this element.
85 * @param listener the {@code listener} event handler for this element
86 */
87 @JsxFunction
88 public void addListener(final Object listener) {
89 // dummy impl for the moment
90 }
91
92 /**
93 * Removes the {@code listener} event handler for this element.
94 * @param listener the {@code listener} event handler to be removed
95 */
96 @JsxFunction
97 public void removeListener(final Object listener) {
98 // dummy impl for the moment
99 }
100 }