1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit.javascript.host.html;
16
17 import org.htmlunit.css.CssStyleSheet;
18 import org.htmlunit.html.HtmlStyle;
19 import org.htmlunit.javascript.configuration.JsxClass;
20 import org.htmlunit.javascript.configuration.JsxConstructor;
21 import org.htmlunit.javascript.configuration.JsxGetter;
22 import org.htmlunit.javascript.configuration.JsxSetter;
23 import org.htmlunit.javascript.host.css.CSSStyleSheet;
24
25
26
27
28
29
30
31
32
33 @JsxClass(domClass = HtmlStyle.class)
34 public class HTMLStyleElement extends HTMLElement {
35
36 private CSSStyleSheet sheet_;
37
38
39
40
41 @Override
42 @JsxConstructor
43 public void jsConstructor() {
44 super.jsConstructor();
45 }
46
47
48
49
50
51
52 @JsxGetter
53 public CSSStyleSheet getSheet() {
54 if (sheet_ != null) {
55 return sheet_;
56 }
57
58 final HtmlStyle style = (HtmlStyle) getDomNodeOrDie();
59 sheet_ = new CSSStyleSheet(this, getWindow(), style.getSheet());
60
61 return sheet_;
62 }
63
64
65
66
67
68 @JsxGetter
69 public String getType() {
70 final HtmlStyle style = (HtmlStyle) getDomNodeOrDie();
71 return style.getTypeAttribute();
72 }
73
74
75
76
77
78 @JsxSetter
79 public void setType(final String type) {
80 final HtmlStyle style = (HtmlStyle) getDomNodeOrDie();
81 style.setTypeAttribute(type);
82 }
83
84
85
86
87
88 @JsxGetter
89 public String getMedia() {
90 final HtmlStyle style = (HtmlStyle) getDomNodeOrDie();
91 return style.getAttributeDirect("media");
92 }
93
94
95
96
97
98 @JsxSetter
99 public void setMedia(final String media) {
100 final HtmlStyle style = (HtmlStyle) getDomNodeOrDie();
101 style.setAttribute("media", media);
102 }
103
104
105
106
107
108 @Override
109 @JsxGetter
110 public boolean isDisabled() {
111 return !getSheet().getCssStyleSheet().isEnabled();
112 }
113
114
115
116
117
118 @Override
119 @JsxSetter
120 public void setDisabled(final boolean disabled) {
121 final CssStyleSheet sheet = getSheet().getCssStyleSheet();
122 final boolean modified = disabled == sheet.isEnabled();
123 sheet.setEnabled(!disabled);
124
125 if (modified) {
126 getDomNodeOrDie().getPage().clearComputedStyles();
127 }
128 }
129 }