1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit.javascript.host.css;
16
17 import org.htmlunit.css.CssMediaList;
18 import org.htmlunit.css.CssStyleSheet;
19 import org.htmlunit.cssparser.dom.CSSImportRuleImpl;
20 import org.htmlunit.cssparser.dom.MediaListImpl;
21 import org.htmlunit.javascript.configuration.JsxClass;
22 import org.htmlunit.javascript.configuration.JsxConstructor;
23 import org.htmlunit.javascript.configuration.JsxGetter;
24 import org.htmlunit.javascript.host.html.HTMLElement;
25
26
27
28
29
30
31
32
33 @JsxClass
34 public class CSSImportRule extends CSSRule {
35
36 private MediaList media_;
37 private CSSStyleSheet importedStylesheet_;
38
39
40
41
42 public CSSImportRule() {
43 super();
44 }
45
46
47
48
49 @JsxConstructor
50 @Override
51 public void jsConstructor() {
52 super.jsConstructor();
53 }
54
55
56
57
58
59
60 protected CSSImportRule(final CSSStyleSheet stylesheet, final CSSImportRuleImpl rule) {
61 super(stylesheet, rule);
62 }
63
64
65
66
67
68 @JsxGetter
69 public String getHref() {
70 return getImportRule().getHref();
71 }
72
73
74
75
76
77 @JsxGetter
78 public MediaList getMedia() {
79 if (media_ == null) {
80 final CSSStyleSheet parent = getParentStyleSheet();
81 final MediaListImpl ml = getImportRule().getMedia();
82
83 media_ = new MediaList(parent, new CssMediaList(ml));
84 }
85 return media_;
86 }
87
88
89
90
91
92 @JsxGetter
93 public CSSStyleSheet getStyleSheet() {
94 if (importedStylesheet_ == null) {
95 final CSSStyleSheet owningSheet = getParentStyleSheet();
96 final HTMLElement ownerNode = owningSheet.getOwnerNode();
97 final CssStyleSheet importedSheet = owningSheet.getCssStyleSheet().getImportedStyleSheet(getImportRule());
98 importedStylesheet_ = new CSSStyleSheet(null, ownerNode.getWindow(), importedSheet);
99 }
100 return importedStylesheet_;
101 }
102
103
104
105
106
107 private CSSImportRuleImpl getImportRule() {
108 return (CSSImportRuleImpl) getRule();
109 }
110 }