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.HTMLELEMENT_ALIGN_INVALID;
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.HtmlCaption;
24  import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass;
25  import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstructor;
26  import com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter;
27  import com.gargoylesoftware.htmlunit.javascript.configuration.JsxSetter;
28  
29  import net.sourceforge.htmlunit.corejs.javascript.Context;
30  
31  /**
32   * The JavaScript object {@code HTMLTableCaptionElement}.
33   *
34   * @author Ahmed Ashour
35   * @author Ronald Brill
36   */
37  @JsxClass(domClass = HtmlCaption.class)
38  public class HTMLTableCaptionElement extends HTMLElement {
39  
40      /** The valid <tt>vAlign</tt> values for this element, when emulating IE. */
41      private static final String[] VALIGN_VALID_VALUES_IE = {"top", "bottom"};
42  
43      /** The default value of the "vAlign" property. */
44      private static final String VALIGN_DEFAULT_VALUE = "";
45  
46      /**
47       * Creates an instance.
48       */
49      @JsxConstructor({CHROME, FF, EDGE})
50      public HTMLTableCaptionElement() {
51      }
52  
53      /**
54       * Returns the value of the {@code align} property.
55       * @return the value of the {@code align} property
56       */
57      @JsxGetter
58      public String getAlign() {
59          final boolean invalidValues = getBrowserVersion().hasFeature(HTMLELEMENT_ALIGN_INVALID);
60          return getAlign(invalidValues);
61      }
62  
63      /**
64       * Sets the value of the {@code align} property.
65       * @param align the value of the {@code align} property
66       */
67      @JsxSetter
68      public void setAlign(final String align) {
69          setAlign(align, false);
70      }
71  
72      /**
73       * Returns the value of the {@code vAlign} property.
74       * @return the value of the {@code vAlign} property
75       */
76      @JsxGetter(IE)
77      public String getVAlign() {
78          return getVAlign(VALIGN_VALID_VALUES_IE, VALIGN_DEFAULT_VALUE);
79      }
80  
81      /**
82       * Sets the value of the {@code vAlign} property.
83       * @param vAlign the value of the {@code vAlign} property
84       */
85      @JsxSetter(IE)
86      public void setVAlign(final Object vAlign) {
87          setVAlign(vAlign, VALIGN_VALID_VALUES_IE);
88      }
89  
90      /**
91       * Overwritten to throw an exception.
92       * @param value the new value for replacing this node
93       */
94      @JsxSetter
95      @Override
96      public void setOuterHTML(final Object value) {
97          throw Context.reportRuntimeError("outerHTML is read-only for tag 'caption'");
98      }
99  }