Class ComputedCssStyleDeclaration

    • Field Detail

      • INHERITABLE_DEFINITIONS

        private static final java.util.Set<StyleAttributes.Definition> INHERITABLE_DEFINITIONS
        The set of 'inheritable' definitions.
      • EMPTY_FINAL

        public static final java.lang.String EMPTY_FINAL
        Denotes a value which should be returned as is.
      • width_

        private java.lang.Integer width_
        The computed, cached width of the element to which this computed style belongs (no padding, borders, etc.).
      • height_

        private java.lang.Integer height_
        The computed, cached height of the element to which this computed style belongs (no padding, borders, etc.), taking child elements into account.
      • height2_

        private java.lang.Integer height2_
        The computed, cached height of the element to which this computed style belongs (no padding, borders, etc.), not taking child elements into account.
      • paddingHorizontal_

        private java.lang.Integer paddingHorizontal_
        The computed, cached horizontal padding (left + right) of the element to which this computed style belongs.
      • paddingVertical_

        private java.lang.Integer paddingVertical_
        The computed, cached vertical padding (top + bottom) of the element to which this computed style belongs.
      • borderHorizontal_

        private java.lang.Integer borderHorizontal_
        The computed, cached horizontal border (left + right) of the element to which this computed style belongs.
      • borderVertical_

        private java.lang.Integer borderVertical_
        The computed, cached vertical border (top + bottom) of the element to which this computed style belongs.
      • top_

        private java.lang.Integer top_
        The computed, cached top of the element to which this computed style belongs.
      • localModifications_

        private final java.util.SortedMap<java.lang.String,​StyleElement> localModifications_
        Local modifications maintained here rather than in the element. We use a sorted map so that results are deterministic and thus easily testable.
    • Method Detail

      • getStylePriority

        public java.lang.String getStylePriority​(java.lang.String name)
        Returns the priority of the named style attribute, or an empty string if it is not found.
        Specified by:
        getStylePriority in class AbstractCssStyleDeclaration
        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
      • getCssText

        public java.lang.String getCssText()
        Returns the actual text of the style.
        Specified by:
        getCssText in class AbstractCssStyleDeclaration
        Returns:
        the actual text of the style
      • getStyleAttribute

        public java.lang.String getStyleAttribute​(java.lang.String name)
        Get the value for the style attribute.
        Specified by:
        getStyleAttribute in class AbstractCssStyleDeclaration
        Parameters:
        name - the name
        Returns:
        the value
      • getStyleAttribute

        public java.lang.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.
        Specified by:
        getStyleAttribute in class AbstractCssStyleDeclaration
        Parameters:
        definition - the definition
        getDefaultValueIfEmpty - whether to get the default value if empty or not
        Returns:
        the value
      • getStyleAttribute

        private java.lang.String getStyleAttribute​(StyleAttributes.Definition definition,
                                                   java.lang.String toReturnIfEmptyOrDefault,
                                                   java.lang.String defaultValue)
        Parameters:
        toReturnIfEmptyOrDefault - the value to return if empty or equals the defaultValue
        defaultValue - the default value of the string
        Returns:
        the string, or toReturnIfEmptyOrDefault
      • setCssText

        public void setCssText​(java.lang.String value)
        Sets the actual text of the style.
        Specified by:
        setCssText in class AbstractCssStyleDeclaration
        Parameters:
        value - the new text
      • setStyleAttribute

        public void setStyleAttribute​(java.lang.String name,
                                      java.lang.String newValue,
                                      java.lang.String important)
        Sets the specified style attribute.
        Specified by:
        setStyleAttribute in class AbstractCssStyleDeclaration
        Parameters:
        name - the attribute name (camel-cased)
        newValue - the attribute value
        important - important value
      • removeStyleAttribute

        public java.lang.String removeStyleAttribute​(java.lang.String name)
        Removes the specified style attribute, returning the value of the removed attribute.
        Specified by:
        removeStyleAttribute in class AbstractCssStyleDeclaration
        Parameters:
        name - the attribute name (delimiter-separated, not camel-cased)
        Returns:
        the removed value
      • item

        public java.lang.Object item​(int index)
        Returns the item in the given index.
        Specified by:
        item in class AbstractCssStyleDeclaration
        Parameters:
        index - the index
        Returns:
        the item in the given index
      • getParentRule

        public org.htmlunit.cssparser.dom.AbstractCSSRuleImpl getParentRule()
        Returns the CSSRule that is the parent of this style block or null if this CSSStyleDeclaration is not attached to a CSSRule.
        Specified by:
        getParentRule in class AbstractCssStyleDeclaration
        Returns:
        the CSSRule that is the parent of this style block or null if this CSSStyleDeclaration is not attached to a CSSRule
      • getStyleElement

        public StyleElement getStyleElement​(java.lang.String name)
        Determines the StyleElement for the given name.
        Specified by:
        getStyleElement in class AbstractCssStyleDeclaration
        Parameters:
        name - the name of the requested StyleElement
        Returns:
        the StyleElement or null if not found
      • getStyleElementCaseInSensitive

        public StyleElement getStyleElementCaseInSensitive​(java.lang.String name)
        Determines the StyleElement for the given name. This ignores the case of the name.
        Specified by:
        getStyleElementCaseInSensitive in class AbstractCssStyleDeclaration
        Parameters:
        name - the name of the requested StyleElement
        Returns:
        the StyleElement or null if not found
      • getStyleMap

        public java.util.Map<java.lang.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.
        Specified by:
        getStyleMap in class AbstractCssStyleDeclaration
        Returns:
        a sorted map containing style elements, keyed on style element name
      • getDomElement

        public DomElement getDomElement()
      • getTop

        public int getTop​(boolean includeMargin,
                          boolean includeBorder,
                          boolean includePadding)
        Returns the computed top (Y coordinate), relative to the node's parent's top edge.
        Parameters:
        includeMargin - whether or not to take the margin into account in the calculation
        includeBorder - whether or not to take the border into account in the calculation
        includePadding - whether or not to take the padding into account in the calculation
        Returns:
        the computed top (Y coordinate), relative to the node's parent's top edge
      • isBlock

        private static boolean isBlock​(java.lang.String display)
      • getTopWithInheritance

        public java.lang.String getTopWithInheritance()
        Returns the CSS top attribute, replacing inherited values with the actual parent values.
        Returns:
        the CSS top attribute, replacing inherited values with the actual parent values
      • getBottomWithInheritance

        public java.lang.String getBottomWithInheritance()
        Returns the CSS bottom attribute, replacing inherited values with the actual parent values.
        Returns:
        the CSS bottom attribute, replacing inherited values with the actual parent values
      • getMarginLeftValue

        public int getMarginLeftValue()
        Gets the left margin of the element.
        Returns:
        the value in pixels
      • getMarginRightValue

        public int getMarginRightValue()
        Gets the right margin of the element.
        Returns:
        the value in pixels
      • getMarginTopValue

        public int getMarginTopValue()
        Gets the top margin of the element.
        Returns:
        the value in pixels
      • getMarginBottomValue

        public int getMarginBottomValue()
        Gets the bottom margin of the element.
        Returns:
        the value in pixels
      • getLeft

        public int getLeft​(boolean includeMargin,
                           boolean includeBorder,
                           boolean includePadding)
        Returns the computed left (X coordinate), relative to the node's parent's left edge.
        Parameters:
        includeMargin - whether or not to take the margin into account in the calculation
        includeBorder - whether or not to take the border into account in the calculation
        includePadding - whether or not to take the padding into account in the calculation
        Returns:
        the computed left (X coordinate), relative to the node's parent's left edge
      • getPositionWithInheritance

        public java.lang.String getPositionWithInheritance()
        Returns the CSS position attribute, replacing inherited values with the actual parent values.
        Returns:
        the CSS position attribute, replacing inherited values with the actual parent values
      • getLeftWithInheritance

        public java.lang.String getLeftWithInheritance()
        Returns the CSS left attribute, replacing inherited values with the actual parent values.
        Returns:
        the CSS left attribute, replacing inherited values with the actual parent values
      • getRightWithInheritance

        public java.lang.String getRightWithInheritance()
        Returns the CSS right attribute, replacing inherited values with the actual parent values.
        Returns:
        the CSS right attribute, replacing inherited values with the actual parent values
      • getTopForAbsolutePositionWithInheritance

        private int getTopForAbsolutePositionWithInheritance()
      • getCalculatedHeight

        public int getCalculatedHeight​(boolean includeBorder,
                                       boolean includePadding)
        Returns the element's height, possibly including its padding and border.
        Parameters:
        includeBorder - whether or not to include the border height in the returned value
        includePadding - whether or not to include the padding height in the returned value
        Returns:
        the element's height, possibly including its padding and border
      • getCalculatedHeight

        private int getCalculatedHeight()
        Returns the element's calculated height, taking both relevant CSS and the element's children into account.
        Returns:
        the element's calculated height, taking both relevant CSS and the element's children into account
      • getCalculatedWidth

        public int getCalculatedWidth​(boolean includeBorder,
                                      boolean includePadding)
        Returns the element's width in pixels, possibly including its padding and border.
        Parameters:
        includeBorder - whether or not to include the border width in the returned value
        includePadding - whether or not to include the padding width in the returned value
        Returns:
        the element's width in pixels, possibly including its padding and border
      • getCalculatedWidth

        private int getCalculatedWidth()
      • getContentWidth

        public int getContentWidth()
        Returns the total width of the element's children.
        Returns:
        the total width of the element's children
      • getEmptyHeight

        private int getEmptyHeight()
        Returns the element's calculated height taking relevant CSS into account, but not the element's child elements.
        Returns:
        the element's calculated height taking relevant CSS into account, but not the element's child elements
      • getContentHeight

        public int getContentHeight()
        Returns the total height of the element's children.
        Returns:
        the total height of the element's children
      • isScrollable

        public boolean isScrollable​(boolean horizontal)
        Returns true if the element is scrollable along the specified axis.
        Parameters:
        horizontal - if true, the caller is interested in scrollability along the x-axis; if false, the caller is interested in scrollability along the y-axis
        Returns:
        true if the element is scrollable along the specified axis
      • isScrollable

        private boolean isScrollable​(boolean horizontal,
                                     boolean ignoreSize)
        Parameters:
        ignoreSize - whether to consider the content/calculated width/height
      • getBorderHorizontal

        private int getBorderHorizontal()
      • getBorderVertical

        private int getBorderVertical()
      • getBorderLeftValue

        public int getBorderLeftValue()
        Gets the size of the left border of the element.
        Returns:
        the value in pixels
      • getBorderRightValue

        public int getBorderRightValue()
        Gets the size of the right border of the element.
        Returns:
        the value in pixels
      • getBorderTopValue

        public int getBorderTopValue()
        Gets the size of the top border of the element.
        Returns:
        the value in pixels
      • getBorderBottomValue

        public int getBorderBottomValue()
        Gets the size of the bottom border of the element.
        Returns:
        the value in pixels
      • getPaddingHorizontal

        private int getPaddingHorizontal()
      • getPaddingVertical

        private int getPaddingVertical()
      • getPaddingLeftValue

        public int getPaddingLeftValue()
        Gets the left padding of the element.
        Returns:
        the value in pixels
      • getPaddingRightValue

        public int getPaddingRightValue()
        Gets the right padding of the element.
        Returns:
        the value in pixels
      • getPaddingTopValue

        public int getPaddingTopValue()
        Gets the top padding of the element.
        Returns:
        the value in pixels
      • getPaddingBottomValue

        public int getPaddingBottomValue()
        Gets the bottom padding of the element.
        Returns:
        the value in pixels
      • getCachedWidth

        public java.lang.Integer getCachedWidth()
        INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
        Returns:
        the cached width
      • setCachedWidth

        public int setCachedWidth​(int width)
        INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
        Parameters:
        width - the new value
        Returns:
        the param width
      • getCachedHeight

        public java.lang.Integer getCachedHeight()
        INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
        Returns:
        the cached height
      • setCachedHeight

        public int setCachedHeight​(int height)
        INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
        Parameters:
        height - the new value
        Returns:
        the param height
      • getCachedHeight2

        public java.lang.Integer getCachedHeight2()
        INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
        Returns:
        the cached height2
      • setCachedHeight2

        public int setCachedHeight2​(int height)
        INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
        Parameters:
        height - the new value
        Returns:
        the param height2
      • getCachedTop

        public java.lang.Integer getCachedTop()
        INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
        Returns:
        the cached top
      • setCachedTop

        public void setCachedTop​(java.lang.Integer top)
        INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
        Parameters:
        top - the new value
      • getCachedPaddingHorizontal

        public java.lang.Integer getCachedPaddingHorizontal()
        INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
        Returns:
        the cached padding horizontal
      • setCachedPaddingHorizontal

        public int setCachedPaddingHorizontal​(int paddingHorizontal)
        INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
        Parameters:
        paddingHorizontal - the new value
        Returns:
        the param paddingHorizontal
      • getCachedPaddingVertical

        public java.lang.Integer getCachedPaddingVertical()
        INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
        Returns:
        the cached padding vertical
      • setCachedPaddingVertical

        public int setCachedPaddingVertical​(int paddingVertical)
        INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
        Parameters:
        paddingVertical - the new value
        Returns:
        the param paddingVertical
      • getCachedBorderHorizontal

        public java.lang.Integer getCachedBorderHorizontal()
        INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
        Returns:
        the cached border horizontal
      • setCachedBorderHorizontal

        public int setCachedBorderHorizontal​(int borderHorizontal)
        INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
        Parameters:
        borderHorizontal - the new value
        Returns:
        the param borderHorizontal
      • getCachedBorderVertical

        public java.lang.Integer getCachedBorderVertical()
        INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
        Returns:
        the cached border vertical
      • setCachedBorderVertical

        public int setCachedBorderVertical​(int borderVertical)
        INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
        Parameters:
        borderVertical - the new value
        Returns:
        the param borderVertical
      • applyStyleFromSelector

        public void applyStyleFromSelector​(org.htmlunit.cssparser.dom.CSSStyleDeclarationImpl declaration,
                                           org.htmlunit.cssparser.parser.selector.Selector selector)
        Makes a local, "computed", modification to this CSS style.
        Parameters:
        declaration - the style declaration
        selector - the selector determining that the style applies to this element
      • applyLocalStyleAttribute

        private void applyLocalStyleAttribute​(java.lang.String name,
                                              java.lang.String newValue,
                                              java.lang.String priority,
                                              org.htmlunit.cssparser.parser.selector.SelectorSpecificity specificity)
      • setDefaultLocalStyleAttribute

        public void setDefaultLocalStyleAttribute​(java.lang.String name,
                                                  java.lang.String newValue)
        Makes a local, "computed", modification to this CSS style that won't override other style attributes of the same name. This method should be used to set default values for style attributes.
        Parameters:
        name - the name of the style attribute to set
        newValue - the value of the style attribute to set
      • hasFeature

        public boolean hasFeature​(BrowserVersionFeatures property)
        Indicates if the browser this is associated with has the feature.
        Specified by:
        hasFeature in class AbstractCssStyleDeclaration
        Parameters:
        property - the property name
        Returns:
        false if this browser doesn't have this feature
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • defaultIfEmpty

        private java.lang.String defaultIfEmpty​(java.lang.String str,
                                                StyleAttributes.Definition definition,
                                                boolean isPixel)
      • defaultIfEmpty

        private java.lang.String defaultIfEmpty​(java.lang.String str,
                                                java.lang.String toReturnIfEmptyOrDefault,
                                                java.lang.String defaultValue)
        Parameters:
        toReturnIfEmptyOrDefault - the value to return if empty or equals the defaultValue
        defaultValue - the default value of the string
        Returns:
        the string, or toReturnIfEmptyOrDefault
      • pixelString

        private static java.lang.String pixelString​(java.lang.String value)
        Returns the specified length value as a pixel length value. This method does NOT handle percentages correctly; use #pixelValue(Element, CssValue) if you need percentage support).
        Parameters:
        value - the length value to convert to a pixel length value
        Returns:
        the specified length value as a pixel length value
        See Also:
        #pixelString(Element, CSSStyleDeclaration.CssValue)