Class CSSEngine

  • Direct Known Subclasses:
    SVGCSSEngine

    public abstract class CSSEngine
    extends java.lang.Object
    This is the base class for all the CSS engines.
    • Field Detail

      • userAgent

        protected CSSEngineUserAgent userAgent
        The user agent used for showing error messages.
      • cssContext

        protected CSSContext cssContext
        The CSS context.
      • document

        protected org.w3c.dom.Document document
        The associated document.
      • documentURI

        protected ParsedURL documentURI
        The document URI.
      • isCSSNavigableDocument

        protected boolean isCSSNavigableDocument
        Whether the document is a CSSNavigableDocument.
      • indexes

        protected StringIntMap indexes
        The property/int mappings.
      • shorthandIndexes

        protected StringIntMap shorthandIndexes
        The shorthand-property/int mappings.
      • valueManagers

        protected ValueManager[] valueManagers
        The value managers.
      • shorthandManagers

        protected ShorthandManager[] shorthandManagers
        The shorthand managers.
      • pseudoElementNames

        protected java.lang.String[] pseudoElementNames
        The pseudo-element names.
      • fontSizeIndex

        protected int fontSizeIndex
        The font-size property index.
      • lineHeightIndex

        protected int lineHeightIndex
        The line-height property index.
      • colorIndex

        protected int colorIndex
        The color property index.
      • userAgentStyleSheet

        protected StyleSheet userAgentStyleSheet
        The user-agent style-sheet.
      • userStyleSheet

        protected StyleSheet userStyleSheet
        The user style-sheet.
      • media

        protected org.w3c.css.sac.SACMediaList media
        The media to use to cascade properties.
      • styleSheetNodes

        protected java.util.List styleSheetNodes
        The DOM nodes which contains StyleSheets.
      • fontFaces

        protected java.util.List fontFaces
        List of StyleMap objects, one for each @font-face rule encountered by this CSSEngine.
      • styleNamespaceURI

        protected java.lang.String styleNamespaceURI
        The style attribute namespace URI.
      • styleLocalName

        protected java.lang.String styleLocalName
        The style attribute local name.
      • classNamespaceURI

        protected java.lang.String classNamespaceURI
        The class attribute namespace URI.
      • classLocalName

        protected java.lang.String classLocalName
        The class attribute local name.
      • nonCSSPresentationalHints

        protected java.util.Set nonCSSPresentationalHints
        The non CSS presentational hints.
      • nonCSSPresentationalHintsNamespaceURI

        protected java.lang.String nonCSSPresentationalHintsNamespaceURI
        The non CSS presentational hints namespace URI.
      • styleDeclarationBuilder

        protected CSSEngine.StyleDeclarationBuilder styleDeclarationBuilder
        The style declaration document handler used to build a StyleDeclaration object.
      • cssBaseURI

        protected ParsedURL cssBaseURI
        The current base URI.
      • alternateStyleSheet

        protected java.lang.String alternateStyleSheet
        The alternate stylesheet title.
      • domAttrModifiedListener

        protected org.w3c.dom.events.EventListener domAttrModifiedListener
        The DOMAttrModified event listener.
      • domNodeInsertedListener

        protected org.w3c.dom.events.EventListener domNodeInsertedListener
        The DOMNodeInserted event listener.
      • domNodeRemovedListener

        protected org.w3c.dom.events.EventListener domNodeRemovedListener
        The DOMNodeRemoved event listener.
      • domSubtreeModifiedListener

        protected org.w3c.dom.events.EventListener domSubtreeModifiedListener
        The DOMSubtreeModified event listener.
      • domCharacterDataModifiedListener

        protected org.w3c.dom.events.EventListener domCharacterDataModifiedListener
        The DOMCharacterDataModified event listener.
      • styleSheetRemoved

        protected boolean styleSheetRemoved
        Whether a style sheet as been removed from the document.
      • removedStylableElementSibling

        protected org.w3c.dom.Node removedStylableElementSibling
        The right sibling of the last removed node.
      • listeners

        protected java.util.List listeners
        The listeners.
      • selectorAttributes

        protected java.util.Set selectorAttributes
        The attributes found in stylesheets selectors.
      • ALL_PROPERTIES

        protected final int[] ALL_PROPERTIES
        Used to fire a change event for all the properties.
      • cssConditionFactory

        protected CSSConditionFactory cssConditionFactory
        The CSS condition factory.
    • Constructor Detail

      • CSSEngine

        protected CSSEngine​(org.w3c.dom.Document doc,
                            ParsedURL uri,
                            ExtendedParser p,
                            ValueManager[] vm,
                            ShorthandManager[] sm,
                            java.lang.String[] pe,
                            java.lang.String sns,
                            java.lang.String sln,
                            java.lang.String cns,
                            java.lang.String cln,
                            boolean hints,
                            java.lang.String hintsNS,
                            CSSContext ctx)
        Creates a new CSSEngine.
        Parameters:
        doc - The associated document.
        uri - The document URI.
        p - The CSS parser.
        vm - The property value managers.
        sm - The shorthand properties managers.
        pe - The pseudo-element names supported by the associated XML dialect. Must be null if no support for pseudo- elements is required.
        sns - The namespace URI of the style attribute.
        sln - The local name of the style attribute.
        cns - The namespace URI of the class attribute.
        cln - The local name of the class attribute.
        hints - Whether the CSS engine should support non CSS presentational hints.
        hintsNS - The hints namespace URI.
        ctx - The CSS context.
    • Method Detail

      • getCSSParentNode

        public static org.w3c.dom.Node getCSSParentNode​(org.w3c.dom.Node n)
        Returns the CSS parent node of the given node.
      • getCSSFirstChild

        protected static org.w3c.dom.Node getCSSFirstChild​(org.w3c.dom.Node n)
        Returns the CSS first child node of the given node.
      • getCSSNextSibling

        protected static org.w3c.dom.Node getCSSNextSibling​(org.w3c.dom.Node n)
        Returns the CSS next sibling node of the given node.
      • getCSSPreviousSibling

        protected static org.w3c.dom.Node getCSSPreviousSibling​(org.w3c.dom.Node n)
        Returns the CSS previous sibling node of the given node.
      • getParentCSSStylableElement

        public static CSSStylableElement getParentCSSStylableElement​(org.w3c.dom.Element elt)
        Returns the next stylable parent of the given element.
      • addEventListeners

        protected void addEventListeners​(org.w3c.dom.events.EventTarget doc)
        Adds event listeners to the document to track CSS changes.
      • removeEventListeners

        protected void removeEventListeners​(org.w3c.dom.events.EventTarget doc)
        Removes the event listeners from the document.
      • dispose

        public void dispose()
        Disposes the CSSEngine and all the attached resources.
      • disposeStyleMaps

        protected void disposeStyleMaps​(org.w3c.dom.Node node)
        Removes the style maps from each CSSStylableElement in the document.
      • getCSSContext

        public CSSContext getCSSContext()
        Returns the CSS context.
      • getDocument

        public org.w3c.dom.Document getDocument()
        Returns the document associated with this engine.
      • getFontSizeIndex

        public int getFontSizeIndex()
        Returns the font-size property index.
      • getLineHeightIndex

        public int getLineHeightIndex()
        Returns the line-height property index.
      • getColorIndex

        public int getColorIndex()
        Returns the color property index.
      • getNumberOfProperties

        public int getNumberOfProperties()
        Returns the number of properties.
      • getPropertyIndex

        public int getPropertyIndex​(java.lang.String name)
        Returns the property index, or -1.
      • getShorthandIndex

        public int getShorthandIndex​(java.lang.String name)
        Returns the shorthand property index, or -1.
      • getPropertyName

        public java.lang.String getPropertyName​(int idx)
        Returns the name of the property at the given index.
      • setCSSEngineUserAgent

        public void setCSSEngineUserAgent​(CSSEngineUserAgent userAgent)
      • setUserAgentStyleSheet

        public void setUserAgentStyleSheet​(StyleSheet ss)
        Sets the user agent style-sheet.
      • setUserStyleSheet

        public void setUserStyleSheet​(StyleSheet ss)
        Sets the user style-sheet.
      • getValueManagers

        public ValueManager[] getValueManagers()
        Returns the ValueManagers.
      • getShorthandManagers

        public ShorthandManager[] getShorthandManagers()
        Returns the ShorthandManagers.
      • getFontFaces

        public java.util.List getFontFaces()
        Gets the StyleMaps generated by @font-face rules encountered by this CSSEngine thus far.
      • setMedia

        public void setMedia​(java.lang.String str)
        Sets the media to use to compute the styles.
      • setAlternateStyleSheet

        public void setAlternateStyleSheet​(java.lang.String str)
        Sets the alternate style-sheet title.
      • importCascadedStyleMaps

        public void importCascadedStyleMaps​(org.w3c.dom.Element src,
                                            CSSEngine srceng,
                                            org.w3c.dom.Element dest)
        Recursively imports the cascaded style from a source element to an element of the current document.
      • getCSSBaseURI

        public ParsedURL getCSSBaseURI()
        Returns the current base-url.
      • getCascadedStyleMap

        public StyleMap getCascadedStyleMap​(CSSStylableElement elt,
                                            java.lang.String pseudo)
        Returns the cascaded style of the given element/pseudo-element.
        Parameters:
        elt - The stylable element.
        pseudo - Optional pseudo-element string (null if none).
      • getComputedStyle

        public Value getComputedStyle​(CSSStylableElement elt,
                                      java.lang.String pseudo,
                                      int propidx)
        Returns the computed style of the given element/pseudo for the property corresponding to the given index.
      • getStyleSheetNodes

        public java.util.List getStyleSheetNodes()
        Returns the document CSSStyleSheetNodes in a list. This list is updated as the document is modified.
      • findStyleSheetNodes

        protected void findStyleSheetNodes​(org.w3c.dom.Node n)
        An auxiliary method for getStyleSheets().
      • findSelectorAttributes

        protected void findSelectorAttributes​(java.util.Set attrs,
                                              StyleSheet ss)
        Finds the selector attributes in the given stylesheet.
      • parsePropertyValue

        public Value parsePropertyValue​(CSSStylableElement elt,
                                        java.lang.String prop,
                                        java.lang.String value)
        Parses and creates a property value from elt.
        Parameters:
        elt - The element property is from.
        prop - The property name.
        value - The property value.
      • parseStyleDeclaration

        public StyleDeclaration parseStyleDeclaration​(CSSStylableElement elt,
                                                      java.lang.String value)
        Parses and creates a style declaration.
        Parameters:
        value - The style declaration text.
      • parseStyleSheet

        public StyleSheet parseStyleSheet​(ParsedURL uri,
                                          java.lang.String media)
                                   throws org.w3c.dom.DOMException
        Parses and creates a new style-sheet.
        Parameters:
        uri - The style-sheet URI.
        media - The target media of the style-sheet.
        Throws:
        org.w3c.dom.DOMException
      • parseStyleSheet

        public StyleSheet parseStyleSheet​(org.w3c.css.sac.InputSource is,
                                          ParsedURL uri,
                                          java.lang.String media)
                                   throws org.w3c.dom.DOMException
        Parses and creates a new style-sheet.
        Parameters:
        is - The input source used to read the document.
        uri - The base URI.
        media - The target media of the style-sheet.
        Throws:
        org.w3c.dom.DOMException
      • parseStyleSheet

        public void parseStyleSheet​(StyleSheet ss,
                                    ParsedURL uri)
                             throws org.w3c.dom.DOMException
        Parses and fills the given style-sheet.
        Parameters:
        ss - The stylesheet to fill.
        uri - The base URI.
        Throws:
        org.w3c.dom.DOMException
      • parseStyleSheet

        public StyleSheet parseStyleSheet​(java.lang.String rules,
                                          ParsedURL uri,
                                          java.lang.String media)
                                   throws org.w3c.dom.DOMException
        Parses and creates a new style-sheet.
        Parameters:
        rules - The style-sheet rules to parse.
        uri - The style-sheet URI.
        media - The target media of the style-sheet.
        Throws:
        org.w3c.dom.DOMException
      • parseStyleSheet

        public void parseStyleSheet​(StyleSheet ss,
                                    java.lang.String rules,
                                    ParsedURL uri)
                             throws org.w3c.dom.DOMException
        Parses and fills the given style-sheet.
        Parameters:
        ss - The stylesheet to fill.
        rules - The style-sheet rules to parse.
        uri - The base URI.
        Throws:
        org.w3c.dom.DOMException
      • parseStyleSheet

        protected void parseStyleSheet​(StyleSheet ss,
                                       org.w3c.css.sac.InputSource is,
                                       ParsedURL uri)
                                throws java.io.IOException
        Parses and fills the given style-sheet.
        Parameters:
        ss - The stylesheet to fill.
        uri - The base URI.
        Throws:
        java.io.IOException
      • putAuthorProperty

        protected void putAuthorProperty​(StyleMap dest,
                                         int idx,
                                         Value sval,
                                         boolean imp,
                                         short origin)
        Puts an author property from a style-map in another style-map, if possible.
      • addMatchingRules

        protected void addMatchingRules​(java.util.List rules,
                                        StyleSheet ss,
                                        org.w3c.dom.Element elt,
                                        java.lang.String pseudo)
        Adds the rules matching the element/pseudo-element of given style sheet to the list.
      • addRules

        protected void addRules​(org.w3c.dom.Element elt,
                                java.lang.String pseudo,
                                StyleMap sm,
                                java.util.ArrayList rules,
                                short origin)
        Adds the rules contained in the given list to a stylemap.
      • sortRules

        protected void sortRules​(java.util.ArrayList rules,
                                 org.w3c.dom.Element elt,
                                 java.lang.String pseudo)
        Sorts the rules matching the element/pseudo-element of given style sheet to the list.
      • mediaMatch

        protected boolean mediaMatch​(org.w3c.css.sac.SACMediaList ml)
        Whether the given media list matches the media list of this CSSEngine object.
      • addCSSEngineListener

        public void addCSSEngineListener​(CSSEngineListener l)
        Adds a CSS engine listener.
      • removeCSSEngineListener

        public void removeCSSEngineListener​(CSSEngineListener l)
        Removes a CSS engine listener.
      • firePropertiesChangedEvent

        protected void firePropertiesChangedEvent​(org.w3c.dom.Element target,
                                                  int[] props)
        Fires a CSSEngineEvent, given a list of modified properties.
      • inlineStyleAttributeUpdated

        protected void inlineStyleAttributeUpdated​(CSSStylableElement elt,
                                                   StyleMap style,
                                                   short attrChange,
                                                   java.lang.String prevValue,
                                                   java.lang.String newValue)
        Called when the inline style of the given element has been updated.
      • invalidateProperties

        protected void invalidateProperties​(org.w3c.dom.Node node,
                                            int[] properties,
                                            boolean[] updated,
                                            boolean recascade)
        Invalidates all the properties of the given node.
      • propagateChanges

        protected void propagateChanges​(org.w3c.dom.Node node,
                                        int[] props,
                                        boolean recascade)
        Propagates the changes that occurs on the parent of the given node. Props is a list of known 'changed' properties. If recascade is true then the stylesheets will be applied again to see if the any new rules apply (or old rules don't apply).
      • nonCSSPresentationalHintUpdated

        protected void nonCSSPresentationalHintUpdated​(CSSStylableElement elt,
                                                       StyleMap style,
                                                       java.lang.String property,
                                                       short attrChange,
                                                       java.lang.String newValue)
        Called when a non-CSS presentational hint has been updated.
      • hasStyleSheetNode

        protected boolean hasStyleSheetNode​(org.w3c.dom.Node n)
        Returns whether the DOM subtree rooted at the specified node contains a CSSStyleSheetNode.
      • handleAttrModified

        protected void handleAttrModified​(org.w3c.dom.Element e,
                                          org.w3c.dom.Attr attr,
                                          short attrChange,
                                          java.lang.String prevValue,
                                          java.lang.String newValue)
        Handles an attribute change in the document.
      • handleNodeInserted

        protected void handleNodeInserted​(org.w3c.dom.Node n)
        Handles a node insertion in the document.
      • handleNodeRemoved

        protected void handleNodeRemoved​(org.w3c.dom.Node n)
        Handles a node removal from the document.
      • handleSubtreeModified

        protected void handleSubtreeModified​(org.w3c.dom.Node ignored)
        Handles a subtree modification in the document. todo the incoming Node is actually ignored (not used) here, but it seems caller-sites assume that it is used - is this done right??
      • handleCharacterDataModified

        protected void handleCharacterDataModified​(org.w3c.dom.Node n)
        Handles a character data modification in the document.