View Javadoc
1   /*
2    * Copyright (c) 2002-2017 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    * http://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 com.gargoylesoftware.htmlunit.javascript.host.html;
16  
17  import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_TABLE_VALIGN_SUPPORTS_IE_VALUES;
18  import static com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.CHROME;
19  import static com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.EDGE;
20  import static com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.FF;
21  import static com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.IE;
22  
23  import com.gargoylesoftware.htmlunit.html.HtmlTableBody;
24  import com.gargoylesoftware.htmlunit.html.HtmlTableFooter;
25  import com.gargoylesoftware.htmlunit.html.HtmlTableHeader;
26  import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass;
27  import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstructor;
28  import com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter;
29  import com.gargoylesoftware.htmlunit.javascript.configuration.JsxSetter;
30  
31  import net.sourceforge.htmlunit.corejs.javascript.Context;
32  
33  /**
34   * A JavaScript object representing "HTMLTableSectionElement", it is used by
35   * {@link HtmlTableBody}, {@link HtmlTableHeader}, and {@link HtmlTableFooter}.
36   *
37   * @author Daniel Gredler
38   * @author Ahmed Ashour
39   * @author Ronald Brill
40   */
41  @JsxClass(domClass = HtmlTableBody.class)
42  @JsxClass(domClass = HtmlTableHeader.class)
43  @JsxClass(domClass = HtmlTableFooter.class)
44  public class HTMLTableSectionElement extends RowContainer {
45  
46      /** The valid "vAlign" values for this element, when emulating IE. */
47      private static final String[] VALIGN_VALID_VALUES_IE = {"top", "bottom", "middle", "baseline"};
48  
49      /** The default value of the "vAlign" property. */
50      private static final String VALIGN_DEFAULT_VALUE = "top";
51  
52      /**
53       * Creates an instance.
54       */
55      @JsxConstructor({CHROME, FF, EDGE})
56      public HTMLTableSectionElement() {
57      }
58  
59      /**
60       * Returns the value of the {@code vAlign} property.
61       * @return the value of the {@code vAlign} property
62       */
63      @JsxGetter
64      public String getVAlign() {
65          return getVAlign(getValidVAlignValues(), VALIGN_DEFAULT_VALUE);
66      }
67  
68      /**
69       * Sets the value of the {@code vAlign} property.
70       * @param vAlign the value of the {@code vAlign} property
71       */
72      @JsxSetter
73      public void setVAlign(final Object vAlign) {
74          setVAlign(vAlign, getValidVAlignValues());
75      }
76  
77      /**
78       * Returns the valid "vAlign" values for this element, depending on the browser being emulated.
79       * @return the valid "vAlign" values for this element, depending on the browser being emulated
80       */
81      private String[] getValidVAlignValues() {
82          if (getBrowserVersion().hasFeature(JS_TABLE_VALIGN_SUPPORTS_IE_VALUES)) {
83              return VALIGN_VALID_VALUES_IE;
84          }
85          return null;
86      }
87  
88      /**
89       * Returns the value of the {@code ch} property.
90       * @return the value of the {@code ch} property
91       */
92      @Override
93      @JsxGetter
94      public String getCh() {
95          return super.getCh();
96      }
97  
98      /**
99       * Sets the value of the {@code ch} property.
100      * @param ch the value of the {@code ch} property
101      */
102     @Override
103     @JsxSetter
104     public void setCh(final String ch) {
105         super.setCh(ch);
106     }
107 
108     /**
109      * Returns the value of the {@code chOff} property.
110      * @return the value of the {@code chOff} property
111      */
112     @Override
113     @JsxGetter
114     public String getChOff() {
115         return super.getChOff();
116     }
117 
118     /**
119      * Sets the value of the {@code chOff} property.
120      * @param chOff the value of the {@code chOff} property
121      */
122     @Override
123     @JsxSetter
124     public void setChOff(final String chOff) {
125         super.setChOff(chOff);
126     }
127 
128     /**
129      * Returns the value of the {@code bgColor} attribute.
130      * @return the value of the {@code bgColor} attribute
131      * @see <a href="http://msdn.microsoft.com/en-us/library/ms533505.aspx">MSDN Documentation</a>
132      */
133     @JsxGetter(IE)
134     public String getBgColor() {
135         return getDomNodeOrDie().getAttribute("bgColor");
136     }
137 
138     /**
139      * Sets the value of the {@code bgColor} attribute.
140      * @param bgColor the value of the {@code bgColor} attribute
141      * @see <a href="http://msdn.microsoft.com/en-us/library/ms533505.aspx">MSDN Documentation</a>
142      */
143     @JsxSetter(IE)
144     public void setBgColor(final String bgColor) {
145         setColorAttribute("bgColor", bgColor);
146     }
147 
148     /**
149      * Overwritten to throw an exception.
150      * @param value the new value for replacing this node
151      */
152     @JsxSetter
153     @Override
154     public void setOuterHTML(final Object value) {
155         throw Context.reportRuntimeError("outerHTML is read-only for tag '"
156                             + getDomNodeOrDie().getNodeName() + "'");
157     }
158 
159     /**
160      * Overwritten to throw an exception because this is readonly.
161      * @param value the new value for the contents of this node
162      */
163     @Override
164     @JsxSetter({IE, CHROME})
165     public void setInnerText(final Object value) {
166         super.setInnerText(value);
167     }
168 }