Class RelativeLength


  • @API(type=NOT_EXTENDABLE,
         src=PRIVATE)
    public class RelativeLength
    extends java.lang.Object
    A length that may be expressed as an absolute or relative value, or as an "auto" value, that is to be computed at later time, by the layout engine.
    • Constructor Detail

      • RelativeLength

        protected RelativeLength​(float value,
                                 byte type)
        Constructor
        Parameters:
        value - The absolute or percentage value.
        type - Indicates if the value is absolute, relative or "auto".
    • Method Detail

      • createAbsolute

        public static RelativeLength createAbsolute​(int value)
        Create an absolute value length.
        Parameters:
        value - The value of the absolute length.
        Returns:
        The new absolute value RelativeLength.
      • createRelative

        public static RelativeLength createRelative​(float percentage)
        Create a relative length representing a relative value.
        Parameters:
        percentage - The percentage from the value this length will refer to. (e.g: 50%)
        Returns:
        The new relative value RelativeLength.
      • createAuto

        public static RelativeLength createAuto()
        Create an automatic relative length. This is just an immutable constant marker.
        Returns:
        The "auto" relative length. Always the same object.
      • get

        public int get​(int referenceLength)
        Return the evaluated value of the RelativeLength given a reference value. If this object represents an absolute value, that value is simply returned. Otherwise, returns the given reference length multiplied by the given percentage divided to 100 and rounded to the nearest integer, or maybe a calculated expression.
        Parameters:
        referenceLength - Reference length for percentage lengths.
        Returns:
        The actual value.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
        See Also:
        Object.hashCode()
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
        See Also:
        Object.equals(java.lang.Object)
      • getLengthRepr

        public java.lang.String getLengthRepr()
        Returns:
        a string representing the equivalent CSS expression.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
        See Also:
        Object.toString()
      • isAuto

        public boolean isAuto()
        Returns:
        True if the relative length is automatic.
      • isRelative

        public boolean isRelative()
        Returns:
        True if the length is relative.
      • isAbsolute

        public boolean isAbsolute()
        Returns:
        True if the length is absolute.
      • getValue

        public float getValue()
        Returns:
        The value of the absolute length or the percentage of a relative length.
      • isCalc

        public boolean isCalc()
        Returns:
        True if the length is a calculated value.
      • createAbsolute

        public static RelativeLength createAbsolute​(org.w3c.css.sac.LexicalUnit lu,
                                                    float fontSize,
                                                    ro.sync.ecss.css.LexicalUnitEvaluator evaluator)
        Create an absolute value length.
        Parameters:
        lu - The value of the absolute length.
        fontSize - the size of the font, used to solve ems.
        evaluator - The evaluator, used to solve rems, pc, pt, in, cm.
        Returns:
        The new absolute value RelativeLength.
      • createRelativeOrCalc

        public static RelativeLength createRelativeOrCalc​(org.w3c.css.sac.LexicalUnit lu,
                                                          float fontSize,
                                                          ro.sync.ecss.css.LexicalUnitEvaluator evaluator)
        Create a relative length representing a relative value, like a percent, or a calc expression.
        Parameters:
        lu - The percentage from the value this length will refer to. (e.g: 50%) or a calc expression (e.g 50% - 3pt).
        fontSize - The element font size. This is used to solve em's.
        evaluator - The lexical unit evaluator. This is used to solve rem's, pt's, and othersizes.
        Returns:
        The new relative value RelativeLength.