Class CSSStyleDeclaration

java.lang.Object
org.htmlunit.corejs.javascript.ScriptableObject
org.htmlunit.javascript.HtmlUnitScriptable
org.htmlunit.javascript.host.css.CSSStyleDeclaration
All Implemented Interfaces:
Serializable, Cloneable, org.htmlunit.corejs.javascript.ConstProperties, org.htmlunit.corejs.javascript.debug.DebuggableObject, org.htmlunit.corejs.javascript.Scriptable, org.htmlunit.corejs.javascript.SymbolScriptable
Direct Known Subclasses:
ComputedCSSStyleDeclaration

public class CSSStyleDeclaration extends HtmlUnitScriptable
A JavaScript object for CSSStyleDeclaration.
See Also:
  • Field Details

    • LENGTH_PROPERTIES_FFFF

      private static final Set<String> LENGTH_PROPERTIES_FFFF
    • LENGTH_PROPERTIES_TTFF

      private static final Set<String> LENGTH_PROPERTIES_TTFF
    • LENGTH_PROPERTIES_FTFF

      private static final Set<String> LENGTH_PROPERTIES_FTFF
    • THIN_MED_THICK

      private static final String[] THIN_MED_THICK
    • ALIGN_KEYWORDS

      private static final String[] ALIGN_KEYWORDS
    • styleDeclaration_

      private AbstractCssStyleDeclaration styleDeclaration_
      The wrapped CSSStyleDeclaration
  • Constructor Details

    • CSSStyleDeclaration

      public CSSStyleDeclaration()
      Creates an instance.
    • CSSStyleDeclaration

      public CSSStyleDeclaration(Element element, AbstractCssStyleDeclaration styleDeclaration)
      Creates an instance and sets its parent scope to the one of the provided element.
      Parameters:
      element - the element to which this style is bound
      styleDeclaration - the style declaration to be based on
    • CSSStyleDeclaration

      CSSStyleDeclaration(CSSStyleSheet parentStyleSheet, WrappedCssStyleDeclaration styleDeclaration)
      Creates an instance which wraps the specified style declaration.
      Parameters:
      parentStyleSheet - the parent CSSStyleSheet to use
      styleDeclaration - the style declaration to wrap
  • Method Details

    • jsConstructor

      public void jsConstructor(String type, org.htmlunit.corejs.javascript.ScriptableObject details)
      JavaScript constructor.
      Parameters:
      type - the event type
      details - the event details (optional)
    • getCssStyleDeclaration

      protected AbstractCssStyleDeclaration getCssStyleDeclaration()
    • getStylePriority

      protected String getStylePriority(String name)
      Returns the priority of the named style attribute, or an empty string if it is not found.
      Parameters:
      name - the name of the style attribute whose value is to be retrieved
      Returns:
      the named style attribute value, or an empty string if it is not found
    • setStyleAttribute

      protected void setStyleAttribute(String name, String newValue)
      Sets the specified style attribute.
      Parameters:
      name - the attribute name (camel-cased)
      newValue - the attribute value
    • setStyleAttribute

      protected void setStyleAttribute(String name, String newValue, String important)
      Sets the specified style attribute.
      Parameters:
      name - the attribute name (camel-cased)
      newValue - the attribute value
      important - important value
    • removeStyleAttribute

      private String removeStyleAttribute(String name)
      Removes the specified style attribute, returning the value of the removed attribute.
      Parameters:
      name - the attribute name (delimiter-separated, not camel-cased)
    • getStyleMap

      private Map<String,StyleElement> getStyleMap()
      Returns a sorted map containing style elements, keyed on style element name. We use a LinkedHashMap map so that results are deterministic and are thus testable.
      Returns:
      a sorted map containing style elements, keyed on style element name
    • getBackgroundAttachment

      public String getBackgroundAttachment()
      Gets the backgroundAttachment style attribute.
      Returns:
      the style attribute
    • setBackgroundAttachment

      public void setBackgroundAttachment(String backgroundAttachment)
      Sets the backgroundAttachment style attribute.
      Parameters:
      backgroundAttachment - the new attribute
    • getBackgroundColor

      public String getBackgroundColor()
      Gets the backgroundColor style attribute.
      Returns:
      the style attribute
    • setBackgroundColor

      public void setBackgroundColor(String backgroundColor)
      Sets the backgroundColor style attribute.
      Parameters:
      backgroundColor - the new attribute
    • getBackgroundImage

      public String getBackgroundImage()
      Gets the backgroundImage style attribute.
      Returns:
      the style attribute
    • setBackgroundImage

      public void setBackgroundImage(String backgroundImage)
      Sets the backgroundImage style attribute.
      Parameters:
      backgroundImage - the new attribute
    • getBackgroundPosition

      public String getBackgroundPosition()
      Gets the backgroundPosition style attribute.
      Returns:
      the style attribute
    • setBackgroundPosition

      public void setBackgroundPosition(String backgroundPosition)
      Sets the backgroundPosition style attribute.
      Parameters:
      backgroundPosition - the new attribute
    • getBackgroundRepeat

      public String getBackgroundRepeat()
      Gets the backgroundRepeat style attribute.
      Returns:
      the style attribute
    • setBackgroundRepeat

      public void setBackgroundRepeat(String backgroundRepeat)
      Sets the backgroundRepeat style attribute.
      Parameters:
      backgroundRepeat - the new attribute
    • getBorderBottomColor

      public String getBorderBottomColor()
      Gets the borderBottomColor style attribute.
      Returns:
      the style attribute
    • setBorderBottomColor

      public void setBorderBottomColor(String borderBottomColor)
      Sets the borderBottomColor style attribute.
      Parameters:
      borderBottomColor - the new attribute
    • getBorderBottomStyle

      public String getBorderBottomStyle()
      Gets the borderBottomStyle style attribute.
      Returns:
      the style attribute
    • setBorderBottomStyle

      public void setBorderBottomStyle(String borderBottomStyle)
      Sets the borderBottomStyle style attribute.
      Parameters:
      borderBottomStyle - the new attribute
    • getBorderBottomWidth

      public String getBorderBottomWidth()
      Gets the borderBottomWidth style attribute.
      Returns:
      the style attribute
    • setBorderBottomWidth

      public void setBorderBottomWidth(Object borderBottomWidth)
      Sets the borderBottomWidth style attribute.
      Parameters:
      borderBottomWidth - the new attribute
    • getBorderLeftColor

      public String getBorderLeftColor()
      Gets the borderLeftColor style attribute.
      Returns:
      the style attribute
    • setBorderLeftColor

      public void setBorderLeftColor(String borderLeftColor)
      Sets the borderLeftColor style attribute.
      Parameters:
      borderLeftColor - the new attribute
    • getBorderLeftStyle

      public String getBorderLeftStyle()
      Gets the borderLeftStyle style attribute.
      Returns:
      the style attribute
    • setBorderLeftStyle

      public void setBorderLeftStyle(String borderLeftStyle)
      Sets the borderLeftStyle style attribute.
      Parameters:
      borderLeftStyle - the new attribute
    • getBorderLeftWidth

      public String getBorderLeftWidth()
      Gets the borderLeftWidth style attribute.
      Returns:
      the style attribute
    • setBorderLeftWidth

      public void setBorderLeftWidth(Object borderLeftWidth)
      Sets the borderLeftWidth style attribute.
      Parameters:
      borderLeftWidth - the new attribute
    • getBorderRightColor

      public String getBorderRightColor()
      Gets the borderRightColor style attribute.
      Returns:
      the style attribute
    • setBorderRightColor

      public void setBorderRightColor(String borderRightColor)
      Sets the borderRightColor style attribute.
      Parameters:
      borderRightColor - the new attribute
    • getBorderRightStyle

      public String getBorderRightStyle()
      Gets the borderRightStyle style attribute.
      Returns:
      the style attribute
    • setBorderRightStyle

      public void setBorderRightStyle(String borderRightStyle)
      Sets the borderRightStyle style attribute.
      Parameters:
      borderRightStyle - the new attribute
    • getBorderRightWidth

      public String getBorderRightWidth()
      Gets the borderRightWidth style attribute.
      Returns:
      the style attribute
    • setBorderRightWidth

      public void setBorderRightWidth(Object borderRightWidth)
      Sets the borderRightWidth style attribute.
      Parameters:
      borderRightWidth - the new attribute
    • getBorderTop

      public String getBorderTop()
      Gets the borderTop style attribute.
      Returns:
      the style attribute
    • setBorderTop

      public void setBorderTop(String borderTop)
      Sets the borderTop style attribute.
      Parameters:
      borderTop - the new attribute
    • getBorderTopColor

      public String getBorderTopColor()
      Gets the borderTopColor style attribute.
      Returns:
      the style attribute
    • setBorderTopColor

      public void setBorderTopColor(String borderTopColor)
      Sets the borderTopColor style attribute.
      Parameters:
      borderTopColor - the new attribute
    • getBorderTopStyle

      public String getBorderTopStyle()
      Gets the borderTopStyle style attribute.
      Returns:
      the style attribute
    • setBorderTopStyle

      public void setBorderTopStyle(String borderTopStyle)
      Sets the borderTopStyle style attribute.
      Parameters:
      borderTopStyle - the new attribute
    • getBorderTopWidth

      public String getBorderTopWidth()
      Gets the borderTopWidth style attribute.
      Returns:
      the style attribute
    • setBorderTopWidth

      public void setBorderTopWidth(Object borderTopWidth)
      Sets the borderTopWidth style attribute.
      Parameters:
      borderTopWidth - the new attribute
    • getBottom

      public String getBottom()
      Gets the bottom style attribute.
      Returns:
      the style attribute
    • setBottom

      public void setBottom(Object bottom)
      Sets the bottom style attribute.
      Parameters:
      bottom - the new attribute
    • getColor

      public String getColor()
      Gets the color style attribute.
      Returns:
      the style attribute
    • setColor

      public void setColor(String color)
      Sets the color style attribute.
      Parameters:
      color - the new attribute
    • getCssFloat

      public String getCssFloat()
      Gets the cssFloat style attribute.
      Returns:
      the style attribute
    • setCssFloat

      public void setCssFloat(String value)
      Sets the cssFloat style attribute.
      Parameters:
      value - the new attribute
    • getCssText

      public String getCssText()
      Returns the actual text of the style.
      Returns:
      the actual text of the style
    • setCssText

      public void setCssText(String value)
      Sets the actual text of the style.
      Parameters:
      value - the new text
    • getDisplay

      public String getDisplay()
      Gets the display style attribute.
      Returns:
      the style attribute
    • setDisplay

      public void setDisplay(String display)
      Sets the display style attribute.
      Parameters:
      display - the new attribute
    • getFontSize

      public String getFontSize()
      Gets the fontSize style attribute.
      Returns:
      the style attribute
    • setFontSize

      public void setFontSize(Object fontSize)
      Sets the fontSize style attribute.
      Parameters:
      fontSize - the new attribute
    • getLineHeight

      public String getLineHeight()
      Gets the lineHeight style attribute.
      Returns:
      the style attribute
    • setLineHeight

      public void setLineHeight(String lineHeight)
      Sets the lineHeight style attribute.
      Parameters:
      lineHeight - the new attribute
    • getFontFamily

      public String getFontFamily()
      Gets the fontFamily style attribute.
      Returns:
      the style attribute
    • setFontFamily

      public void setFontFamily(String fontFamily)
      Sets the fontFamily style attribute.
      Parameters:
      fontFamily - the new attribute
    • updateFont

      private void updateFont(String font, boolean force)
    • getFont

      public String getFont()
      Gets the font style attribute.
      Returns:
      the style attribute
    • setFont

      public void setFont(String font)
      Sets the font style attribute.
      Parameters:
      font - the new attribute
    • getHeight

      public String getHeight()
      Gets the height style attribute.
      Returns:
      the style attribute
    • setHeight

      public void setHeight(Object height)
      Sets the height style attribute.
      Parameters:
      height - the new attribute
    • getLeft

      public String getLeft()
      Gets the left style attribute.
      Returns:
      the style attribute
    • setLeft

      public void setLeft(Object left)
      Sets the left style attribute.
      Parameters:
      left - the new attribute
    • getLength

      public int getLength()
      Returns the length property.
      Returns:
      the length property
    • item

      public Object item(int index)
      Returns the item in the given index.
      Parameters:
      index - the index
      Returns:
      the item in the given index
    • values

      public org.htmlunit.corejs.javascript.Scriptable values()
      Returns an Iterator allowing to go through all keys contained in this object.
      Returns:
      a NativeArrayIterator
    • getLetterSpacing

      public String getLetterSpacing()
      Gets the letterSpacing style attribute.
      Returns:
      the style attribute
    • setLetterSpacing

      public void setLetterSpacing(Object letterSpacing)
      Sets the letterSpacing style attribute.
      Parameters:
      letterSpacing - the new attribute
    • getMargin

      public String getMargin()
      Gets the margin style attribute.
      Returns:
      the style attribute
    • setMargin

      public void setMargin(String margin)
      Sets the margin style attribute.
      Parameters:
      margin - the new attribute
    • getMarginBottom

      public String getMarginBottom()
      Gets the marginBottom style attribute.
      Returns:
      the style attribute
    • setMarginBottom

      public void setMarginBottom(Object marginBottom)
      Sets the marginBottom style attribute.
      Parameters:
      marginBottom - the new attribute
    • getMarginLeft

      public String getMarginLeft()
      Gets the marginLeft style attribute.
      Returns:
      the style attribute
    • setMarginLeft

      public void setMarginLeft(Object marginLeft)
      Sets the marginLeft style attribute.
      Parameters:
      marginLeft - the new attribute
    • getMarginRight

      public String getMarginRight()
      Gets the marginRight style attribute.
      Returns:
      the style attribute
    • setMarginRight

      public void setMarginRight(Object marginRight)
      Sets the marginRight style attribute.
      Parameters:
      marginRight - the new attribute
    • getMarginTop

      public String getMarginTop()
      Gets the marginTop style attribute.
      Returns:
      the style attribute
    • setMarginTop

      public void setMarginTop(Object marginTop)
      Sets the marginTop style attribute.
      Parameters:
      marginTop - the new attribute
    • getMaxHeight

      public String getMaxHeight()
      Gets the maxHeight style attribute.
      Returns:
      the style attribute
    • setMaxHeight

      public void setMaxHeight(Object maxHeight)
      Sets the maxHeight style attribute.
      Parameters:
      maxHeight - the new attribute
    • getMaxWidth

      public String getMaxWidth()
      Gets the maxWidth style attribute.
      Returns:
      the style attribute
    • setMaxWidth

      public void setMaxWidth(Object maxWidth)
      Sets the maxWidth style attribute.
      Parameters:
      maxWidth - the new attribute
    • getMinHeight

      public String getMinHeight()
      Gets the minHeight style attribute.
      Returns:
      the style attribute
    • setMinHeight

      public void setMinHeight(Object minHeight)
      Sets the minHeight style attribute.
      Parameters:
      minHeight - the new attribute
    • getMinWidth

      public String getMinWidth()
      Gets the minWidth style attribute.
      Returns:
      the style attribute
    • setMinWidth

      public void setMinWidth(Object minWidth)
      Sets the minWidth style attribute.
      Parameters:
      minWidth - the new attribute
    • get

      public Object get(String name, org.htmlunit.corejs.javascript.Scriptable start)
      Gets a named property from the object. Normally HtmlUnit objects don't need to overwrite this method as properties are defined on the prototypes from the XML configuration. In some cases where "content" of object has priority compared to the properties consider using utility HtmlUnitScriptable.getWithPreemption(String).
      Specified by:
      get in interface org.htmlunit.corejs.javascript.Scriptable
      Overrides:
      get in class HtmlUnitScriptable
    • get

      public Object get(int index, org.htmlunit.corejs.javascript.Scriptable start)
      Specified by:
      get in interface org.htmlunit.corejs.javascript.Scriptable
      Overrides:
      get in class org.htmlunit.corejs.javascript.ScriptableObject
    • getStyleAttribute

      public final String getStyleAttribute(StyleAttributes.Definition definition)
      Get the value for the style attribute.
      Parameters:
      definition - the definition
      Returns:
      the value
    • getStyleAttribute

      public String getStyleAttribute(StyleAttributes.Definition definition, boolean getDefaultValueIfEmpty)
      Get the value for the style attribute. This impl ignores the default getDefaultValueIfEmpty flag, but there is a overload in ComputedCSSStyleDeclaration.
      Parameters:
      definition - the definition
      getDefaultValueIfEmpty - whether to get the default value if empty or not
      Returns:
      the value
    • put

      public void put(String name, org.htmlunit.corejs.javascript.Scriptable start, Object value)
      Description copied from class: HtmlUnitScriptable
      Specified by:
      put in interface org.htmlunit.corejs.javascript.Scriptable
      Overrides:
      put in class HtmlUnitScriptable
    • has

      public boolean has(String name, org.htmlunit.corejs.javascript.Scriptable start)
      Specified by:
      has in interface org.htmlunit.corejs.javascript.Scriptable
      Overrides:
      has in class org.htmlunit.corejs.javascript.ScriptableObject
    • getIds

      public Object[] getIds()
      Specified by:
      getIds in interface org.htmlunit.corejs.javascript.Scriptable
      Overrides:
      getIds in class org.htmlunit.corejs.javascript.ScriptableObject
    • getOpacity

      public String getOpacity()
      Gets the opacity style attribute.
      Returns:
      the style attribute
    • setOpacity

      public void setOpacity(Object opacity)
      Sets the opacity style attribute.
      Parameters:
      opacity - the new attribute
    • getOutline

      public String getOutline()
      Gets the outline style attribute.
      Returns:
      the style attribute
    • setOutline

      public void setOutline(String outline)
      Sets the outline style attribute.
      Parameters:
      outline - the new attribute
    • getOutlineWidth

      public String getOutlineWidth()
      Gets the outlineWidth style attribute.
      Returns:
      the style attribute
    • setOutlineWidth

      public void setOutlineWidth(Object outlineWidth)
      Sets the outlineWidth style attribute.
      Parameters:
      outlineWidth - the new attribute
    • getPadding

      public String getPadding()
      Gets the padding style attribute.
      Returns:
      the style attribute
    • setPadding

      public void setPadding(String padding)
      Sets the padding style attribute.
      Parameters:
      padding - the new attribute
    • getPaddingBottom

      public String getPaddingBottom()
      Gets the paddingBottom style attribute.
      Returns:
      the style attribute
    • setPaddingBottom

      public void setPaddingBottom(Object paddingBottom)
      Sets the paddingBottom style attribute.
      Parameters:
      paddingBottom - the new attribute
    • getPaddingLeft

      public String getPaddingLeft()
      Gets the paddingLeft style attribute.
      Returns:
      the style attribute
    • setPaddingLeft

      public void setPaddingLeft(Object paddingLeft)
      Sets the paddingLeft style attribute.
      Parameters:
      paddingLeft - the new attribute
    • getPaddingRight

      public String getPaddingRight()
      Gets the paddingRight style attribute.
      Returns:
      the style attribute
    • setPaddingRight

      public void setPaddingRight(Object paddingRight)
      Sets the paddingRight style attribute.
      Parameters:
      paddingRight - the new attribute
    • getPaddingTop

      public String getPaddingTop()
      Gets the paddingTop style attribute.
      Returns:
      the style attribute
    • setPaddingTop

      public void setPaddingTop(Object paddingTop)
      Sets the paddingTop style attribute.
      Parameters:
      paddingTop - the new attribute
    • getParentRule

      public CSSRule getParentRule()
      Returns the CSSRule that is the parent of this style block or null if this CSSStyleDeclaration is not attached to a CSSRule.
      Returns:
      the CSSRule that is the parent of this style block or null if this CSSStyleDeclaration is not attached to a CSSRule
    • setParentRule

      public void setParentRule(CSSRule parentRule)
      Nothing.
      Parameters:
      parentRule - ignored
    • getRight

      public String getRight()
      Gets the right style attribute.
      Returns:
      the style attribute
    • setRight

      public void setRight(Object right)
      Sets the right style attribute.
      Parameters:
      right - the new attribute
    • getRubyAlign

      public String getRubyAlign()
      Gets the rubyAlign style attribute.
      Returns:
      the style attribute
    • setRubyAlign

      public void setRubyAlign(String rubyAlign)
      Sets the rubyAlign style attribute.
      Parameters:
      rubyAlign - the new attribute
    • getSize

      public String getSize()
      Gets the size style attribute.
      Returns:
      the style attribute
    • setSize

      public void setSize(String size)
      Sets the size style attribute.
      Parameters:
      size - the new attribute
    • getTextIndent

      public String getTextIndent()
      Gets the textIndent style attribute.
      Returns:
      the style attribute
    • setTextIndent

      public void setTextIndent(Object textIndent)
      Sets the textIndent style attribute.
      Parameters:
      textIndent - the new attribute
    • getTop

      public String getTop()
      Gets the top style attribute.
      Returns:
      the style attribute
    • setTop

      public void setTop(Object top)
      Sets the top style attribute.
      Parameters:
      top - the new attribute
    • getVerticalAlign

      public String getVerticalAlign()
      Gets the verticalAlign style attribute.
      Returns:
      the style attribute
    • setVerticalAlign

      public void setVerticalAlign(Object verticalAlign)
      Sets the verticalAlign style attribute.
      Parameters:
      verticalAlign - the new attribute
    • getWidth

      public String getWidth()
      Gets the width style attribute.
      Returns:
      the style attribute
    • setWidth

      public void setWidth(Object width)
      Sets the width style attribute.
      Parameters:
      width - the new attribute
    • getWidows

      public String getWidows()
      Gets the widows style attribute.
      Returns:
      the style attribute
    • setWidows

      public void setWidows(String widows)
      Sets the widows style attribute.
      Parameters:
      widows - the new attribute
    • getOrphans

      public String getOrphans()
      Gets the orphans style attribute.
      Returns:
      the style attribute
    • setOrphans

      public void setOrphans(String orphans)
      Sets the orphans style attribute.
      Parameters:
      orphans - the new attribute
    • getPosition

      public String getPosition()
      Gets the position style attribute.
      Returns:
      the style attribute
    • setPosition

      public void setPosition(String position)
      Sets the position style attribute.
      Parameters:
      position - the new attribute
    • getWordSpacing

      public String getWordSpacing()
      Gets the wordSpacing style attribute.
      Returns:
      the style attribute
    • setWordSpacing

      public void setWordSpacing(Object wordSpacing)
      Sets the wordSpacing style attribute.
      Parameters:
      wordSpacing - the new attribute
    • getZIndex

      public Object getZIndex()
      Gets the zIndex style attribute.
      Returns:
      the style attribute
    • setZIndex

      public void setZIndex(Object zIndex)
      Sets the zIndex style attribute.
      Parameters:
      zIndex - the new attribute
    • getPropertyValue

      public String getPropertyValue(String name)
      Gets the value of the specified property of the style.
      Parameters:
      name - the style property name
      Returns:
      empty string if nothing found
    • getPropertyPriority

      public String getPropertyPriority(String name)
      Gets the value of the specified property of the style.
      Parameters:
      name - the style property name
      Returns:
      empty string if nothing found
    • setProperty

      public void setProperty(String name, Object value, String important)
      Sets the value of the specified property.
      Parameters:
      name - the name of the attribute
      value - the value to assign to the attribute
      important - may be null
    • removeProperty

      public String removeProperty(Object name)
      Removes the named property.
      Parameters:
      name - the name of the property to remove
      Returns:
      the value deleted
    • isLength

      static boolean isLength(String token)
      Returns if the specified token is a length.
      Parameters:
      token - the token to check
      Returns:
      whether the token is a length or not
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • setStyleLengthAttribute

      private void setStyleLengthAttribute(String name, Object value, String important, boolean auto, boolean percent, boolean unitRequired, String[] validValues)
      Sets the style attribute which should be treated as an integer in pixels.
      Parameters:
      name - the attribute name
      value - the attribute value
      important - important value
      auto - true if auto is supported
      percent - true if percent is supported
      unitRequired - unit is required
      validValues - valid values