      *  whether the style chain has already been built or not.
      */
     public static const STYLE_UNINITIALIZED:Object = {};
-    
+
     //--------------------------------------------------------------------------
     //
     //  Class methods
     //
     //--------------------------------------------------------------------------
+
+    /**
+     *  @private
+     *  Implements the getClassStyleDeclarations() logic
+     *  for UIComponent and TextGraphicElement.
+     *  The 'object' parameter will be one or the other.
+     */
+    public static function getClassStyleDeclarations(object:IStyleClient):Array
+    {
+        var myApplicationDomain:ApplicationDomain;
+
+        var factory:IFlexModuleFactory = ModuleManager.getAssociatedFactory(object);
+        if (factory != null)
+        {
+            myApplicationDomain = ApplicationDomain(factory.info()["currentDomain"]);
+        }
+        else
+        {
+            var myRoot:DisplayObject = SystemManager.getSWFRoot(object);
+            if (!myRoot)
+                return [];
+            myApplicationDomain = myRoot.loaderInfo.applicationDomain;
+        }
+
+        var className:String = getQualifiedClassName(object)
+        className = className.replace("::", ".");
+        
+        var cache:Array = StyleManager.typeSelectorCache[className];
+        if (cache)
+            return cache;
+                
+        var decls:Array = [];
+        var classNames:Array = [];
+        var caches:Array = [];
+        var declcache:Array = [];
+
+        while (className != null &&
+               className != "mx.core.UIComponent" &&
+               className != "mx.core.UITextField" &&
+               className != "flex.graphics.graphicsClasses.GraphicElement")
+        {
+            var s:CSSStyleDeclaration;
+            cache = StyleManager.typeSelectorCache[className];
+            if (cache)
+            {
+                decls = decls.concat(cache);
+                break;
+            }
+
+            s = StyleManager.getStyleDeclaration(className);
+            
+            if (s)
+            {
+                decls.unshift(s);
+                // We found one so the next set define the selectors
+                // for this found class and its ancestors.
+                // Save the old list and start a new list.
+                classNames.push(className);
+                caches.push(classNames);
+                declcache.push(decls);
+                decls = [];
+                classNames = [];
+            }
+            else
+            {
+                classNames.push(className);
+            }
+
+            try
+            {
+                className = getQualifiedSuperclassName(
+                    myApplicationDomain.getDefinition(className));
+                className = className.replace("::", ".");
+            }
+            catch(e:ReferenceError)
+            {
+                className = null;
+            }
+        }
+
+        caches.push(classNames);
+        declcache.push(decls);
+        decls = [];
+        
+        while (caches.length)
+        {
+            classNames = caches.pop();
+            decls = decls.concat(declcache.pop());
+            while (classNames.length)
+            {
+                StyleManager.typeSelectorCache[classNames.pop()] = decls;
+            }
+        }
+
+        return decls;
+    }
+
+    /**
+     *  @private
+     *  Implements the initProtoChain() logic for UIComponent and TextGraphicElement.
+     *  The 'object' parameter will be one or the other.
+     */
+    public static function initProtoChain(object:IStyleClient):void
+    {
+        var n:int;
+        var i:int;
+
+        var uicObject:UIComponent = object as UIComponent;
+        
+        var classSelectors:Array = [];
+        var styleName:Object = object.styleName;
+        if (styleName)
+        {
+            if (styleName is CSSStyleDeclaration)
+            {
+                // Get the style sheet referenced by the styleName property.
+                classSelectors.push(CSSStyleDeclaration(styleName));
+            }
+            else if (styleName is IFlexDisplayObject || styleName is IStyleClient)
+            {
+                // If the styleName property is a UIComponent, then there's a
+                // special search path for that case.
+                StyleProtoChain.initProtoChainForUIComponentStyleName(object);
+                return;
+            }
+            else if (styleName is String)
+            {
+                // Get the style sheets referenced by the styleName property             
+                var styleNames:Array = styleName.split(/\s+/);
+                n = styleNames.length;
+                for (i = 0; i < n; i++)
+                {
+                    if (styleNames[i].length)
+                    {
+                        classSelectors.push(
+                            StyleManager.getStyleDeclaration("." + styleNames[i]));
+                    }
+                }
+            }
+        }
+
+        // To build the proto chain, we start at the end and work forward.
+        // Referring to the list at the top of this function, we'll start
+        // by getting the tail of the proto chain, which is:
+        //  - for non-inheriting styles, the global style sheet
+        //  - for inheriting styles, my parent's style object
+        var nonInheritChain:Object = StyleManager.stylesRoot;
+
+        if (nonInheritChain && nonInheritChain.effects)
+            object.registerEffects(nonInheritChain.effects);
+
+        // TODO: Unify concept of parent for UIComponents and GraphicElements
+        var p:IStyleClient;
+        if (uicObject)
+            p = uicObject.parent as IStyleClient;
+        else if ("elementHost" in object) // object is TextGraphicElement
+            p = object["elementHost"] as IStyleClient;
+
+        if (p)
+        {
+            var inheritChain:Object = p.inheritingStyles;
+            if (inheritChain == StyleProtoChain.STYLE_UNINITIALIZED)
+                inheritChain = nonInheritChain;
+        }
+        else
+        {
+            // Pop ups inheriting chain starts at Application instead of global.
+            // This allows popups to grab styles like themeColor that are
+            // set on Application.
+            if (uicObject && uicObject.isPopUp)
+            {
+                var owner:DisplayObjectContainer = uicObject._owner;
+                if (FlexVersion.compatibilityVersion >= FlexVersion.VERSION_3_0 && 
+                    owner && owner is IStyleClient)
+                {
+                    inheritChain = IStyleClient(owner).inheritingStyles;
+                }
+                else
+                {
+                    inheritChain = ApplicationGlobals.application.inheritingStyles;
+                }
+            }
+            else
+            {
+                inheritChain = StyleManager.stylesRoot;
+            }
+        }
+
+        // Working backwards up the list, the next element in the
+        // search path is the type selector
+        var typeSelectors:Array = object.getClassStyleDeclarations();
+        n = typeSelectors.length;
+        for (i = 0; i < n; i++)
+        {
+            var typeSelector:CSSStyleDeclaration = typeSelectors[i];
+            
+            inheritChain =
+                typeSelector.addStyleToProtoChain(inheritChain, uicObject);
+
+            nonInheritChain =
+                typeSelector.addStyleToProtoChain(nonInheritChain, uicObject);
+
+            if (typeSelector.effects)
+                object.registerEffects(typeSelector.effects);
+        }
+
+        // Next are the class selectors
+        n = classSelectors.length;
+        for (i = 0; i < n; i++)
+        {
+            var classSelector:CSSStyleDeclaration = classSelectors[i];
+            if (classSelector)
+            {
+                inheritChain =
+                    classSelector.addStyleToProtoChain(inheritChain, uicObject);
+
+                nonInheritChain =
+                    classSelector.addStyleToProtoChain(nonInheritChain, uicObject);
+
+                if (classSelector.effects)
+                    object.registerEffects(classSelector.effects);
+            }
+        }
+
+        // Finally, we'll add the in-line styles
+        // to the head of the proto chain.
+        
+        var styleDeclaration:CSSStyleDeclaration = object.styleDeclaration;
+        
+        object.inheritingStyles =
+            styleDeclaration ?
+            styleDeclaration.addStyleToProtoChain(inheritChain, uicObject) :
+            inheritChain;
+
+        object.nonInheritingStyles =
+            styleDeclaration ?
+            styleDeclaration.addStyleToProtoChain(nonInheritChain, uicObject) :
+            nonInheritChain;
+    }
 
     /**
      *  @private

{

import flash.display.DisplayObject;
import mx.core.UIComponent;
import mx.core.IUITextField;
import mx.core.mx_internal;
import mx.styles.IStyleClient;
import mx.styles.StyleProxy;


        obj.inheritingStyles = inheritChain;
        obj.nonInheritingStyles = nonInheritChain;
    }

    /**
     *  @private
     *  Implements the setStyle() logic for UIComponent and TextGraphicElement.
     *  The 'object' parameter will be one or the other.
     */
    public static function setStyle(object:IStyleClient, styleProp:String,
                                    newValue:*):void
    {
        if (styleProp == "styleName")
        {
            // Let the setter handle this one, see UIComponent.
            object.styleName = newValue;

            // Short circuit, because styleName isn't really a style.
            return;
        }

        if (EffectManager.getEventForEffectTrigger(styleProp) != "")
            EffectManager.setStyle(styleProp, object);

        // If this UIComponent didn't previously have any inline styles,
        // then regenerate the UIComponent's proto chain (and the proto chains
        // of this UIComponent's descendants).
        var isInheritingStyle:Boolean =
            StyleManager.isInheritingStyle(styleProp);
        var isProtoChainInitialized:Boolean =
            object.inheritingStyles != StyleProtoChain.STYLE_UNINITIALIZED;
        var valueChanged:Boolean = object.getStyle(styleProp) != newValue;
        
        if (!object.styleDeclaration)
        {
            object.styleDeclaration = new CSSStyleDeclaration();
           
            object.styleDeclaration.mx_internal::setStyle(styleProp, newValue);

            // If inheritingStyles is undefined, then this object is being
            // initialized and we haven't yet generated the proto chain.  To
            // avoid redundant work, don't bother to create the proto chain here.
            if (isProtoChainInitialized)
                object.regenerateStyleCache(isInheritingStyle);
        }
        else
        {
            object.styleDeclaration.mx_internal::setStyle(styleProp, newValue);
        }

        if (isProtoChainInitialized && valueChanged)
        {
            object.styleChanged(styleProp);
            object.notifyStyleChangeInChildren(styleProp, isInheritingStyle);
        }
    }

    /**
     *  @private
     *  Implements the styleChanged() logic for UIComponent and TextGraphicElement.
     *  The 'object' parameter will be one or the other.
     */
    public static function styleChanged(object:IInvalidating, styleProp:String):void
    {
        // If font changed, then invalidateProperties so
        // we can re-create the text field in commitProperties
        // TODO: Should hasFontContextChanged() be added to IFontContextComponent?
        if (object is IFontContextComponent &&
            "hasFontContextChanged" in object &&
            object["hasFontContextChanged"]())
        {
            object.invalidateProperties();
        }
        
        // Check to see if this is one of the style properties
        // that is known to affect layout.
        if (!styleProp ||
            styleProp == "styleName" ||
            StyleManager.isSizeInvalidatingStyle(styleProp))
        {
            // This style property change may affect the layout of this
            // object. Signal the LayoutManager to re-measure the object.
            object.invalidateSize();
        }

        // TODO: Should initThemeColor() be in some interface?
        if (!styleProp || 
            styleProp == "styleName" ||
            styleProp == "themeColor")
        {
            if ("initThemeColor" in object)
                object["initThemeColor"]();
        }
        
        object.invalidateDisplayList();

        // TODO: Unify concept of parent for UIComponents and GraphicElements
        var parent:IInvalidating;
        if (object is UIComponent)
            parent = UIComponent(object).parent as IInvalidating;
        else if ("elementHost" in object) // object is TextGraphicElement
            parent = object["elementHost"] as IInvalidating;

        if (parent)
        {
            if (StyleManager.isParentSizeInvalidatingStyle(styleProp))
                parent.invalidateSize();

            if (StyleManager.isParentDisplayListInvalidatingStyle(styleProp))
                parent.invalidateDisplayList();
        }
    }
}

}
