home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2012 April / ME_04_2012.iso / Video-Tutorial / iPhoto / media / player.swf / scripts / mx / styles / CSSStyleDeclaration.as < prev    next >
Encoding:
Text File  |  2011-11-11  |  18.4 KB  |  617 lines

  1. package mx.styles
  2. {
  3.    import flash.display.DisplayObject;
  4.    import flash.events.EventDispatcher;
  5.    import flash.utils.Dictionary;
  6.    import mx.core.Singleton;
  7.    import mx.core.mx_internal;
  8.    import mx.managers.ISystemManager;
  9.    import mx.managers.SystemManagerGlobals;
  10.    import mx.utils.ObjectUtil;
  11.    
  12.    use namespace mx_internal;
  13.    
  14.    public class CSSStyleDeclaration extends EventDispatcher
  15.    {
  16.       mx_internal static const VERSION:String = "4.5.0.20967";
  17.       
  18.       private static const NOT_A_COLOR:uint = 4294967295;
  19.       
  20.       private static const FILTERMAP_PROP:String = "__reserved__filterMap";
  21.       
  22.       private var clones:Dictionary = new Dictionary(true);
  23.       
  24.       mx_internal var selectorRefCount:int = 0;
  25.       
  26.       mx_internal var effects:Array;
  27.       
  28.       private var styleManager:IStyleManager2;
  29.       
  30.       private var _defaultFactory:Function;
  31.       
  32.       private var _factory:Function;
  33.       
  34.       private var _overrides:Object;
  35.       
  36.       private var _selector:CSSSelector;
  37.       
  38.       private var _selectorString:String;
  39.       
  40.       public function CSSStyleDeclaration(param1:Object = null, param2:IStyleManager2 = null, param3:Boolean = true)
  41.       {
  42.          super();
  43.          if(!param2)
  44.          {
  45.             param2 = Singleton.getInstance("mx.styles::IStyleManager2") as IStyleManager2;
  46.          }
  47.          this.styleManager = param2;
  48.          if(param1)
  49.          {
  50.             if(param1 is CSSSelector)
  51.             {
  52.                this.selector = param1 as CSSSelector;
  53.             }
  54.             else
  55.             {
  56.                this.mx_internal::selectorString = param1.toString();
  57.             }
  58.             if(param3)
  59.             {
  60.                param2.setStyleDeclaration(this.mx_internal::selectorString,this,false);
  61.             }
  62.          }
  63.       }
  64.       
  65.       public function get defaultFactory() : Function
  66.       {
  67.          return this._defaultFactory;
  68.       }
  69.       
  70.       public function set defaultFactory(param1:Function) : void
  71.       {
  72.          this._defaultFactory = param1;
  73.       }
  74.       
  75.       public function get factory() : Function
  76.       {
  77.          return this._factory;
  78.       }
  79.       
  80.       public function set factory(param1:Function) : void
  81.       {
  82.          this._factory = param1;
  83.       }
  84.       
  85.       public function get overrides() : Object
  86.       {
  87.          return this._overrides;
  88.       }
  89.       
  90.       public function set overrides(param1:Object) : void
  91.       {
  92.          this._overrides = param1;
  93.       }
  94.       
  95.       public function get selector() : CSSSelector
  96.       {
  97.          return this._selector;
  98.       }
  99.       
  100.       public function set selector(param1:CSSSelector) : void
  101.       {
  102.          this._selector = param1;
  103.          this._selectorString = null;
  104.       }
  105.       
  106.       mx_internal function get selectorString() : String
  107.       {
  108.          if(this._selectorString == null && this._selector != null)
  109.          {
  110.             this._selectorString = this._selector.toString();
  111.          }
  112.          return this._selectorString;
  113.       }
  114.       
  115.       mx_internal function set selectorString(param1:String) : void
  116.       {
  117.          var _loc2_:CSSCondition = null;
  118.          if(param1.charAt(0) == ".")
  119.          {
  120.             _loc2_ = new CSSCondition(CSSConditionKind.CLASS,param1.substr(1));
  121.             this._selector = new CSSSelector("",[_loc2_]);
  122.          }
  123.          else
  124.          {
  125.             this._selector = new CSSSelector(param1);
  126.          }
  127.          this._selectorString = param1;
  128.       }
  129.       
  130.       public function get specificity() : int
  131.       {
  132.          return !!this._selector ? this._selector.specificity : 0;
  133.       }
  134.       
  135.       public function get subject() : String
  136.       {
  137.          if(this._selector != null)
  138.          {
  139.             if(this._selector.subject == "" && Boolean(this._selector.conditions))
  140.             {
  141.                return "*";
  142.             }
  143.             return this._selector.subject;
  144.          }
  145.          return null;
  146.       }
  147.       
  148.       mx_internal function getPseudoCondition() : String
  149.       {
  150.          return this.selector != null ? this.selector.mx_internal::getPseudoCondition() : null;
  151.       }
  152.       
  153.       mx_internal function isAdvanced() : Boolean
  154.       {
  155.          var _loc1_:CSSCondition = null;
  156.          if(this.selector != null)
  157.          {
  158.             if(this.selector.ancestor)
  159.             {
  160.                return true;
  161.             }
  162.             if(this.selector.conditions)
  163.             {
  164.                if(this.subject != "*" && this.subject != "global")
  165.                {
  166.                   return true;
  167.                }
  168.                for each(_loc1_ in this.selector.conditions)
  169.                {
  170.                   if(_loc1_.kind != CSSConditionKind.CLASS)
  171.                   {
  172.                      return true;
  173.                   }
  174.                }
  175.             }
  176.          }
  177.          return false;
  178.       }
  179.       
  180.       public function matchesStyleClient(param1:IAdvancedStyleClient) : Boolean
  181.       {
  182.          return this.selector != null ? this.selector.matchesStyleClient(param1) : false;
  183.       }
  184.       
  185.       mx_internal function equals(param1:CSSStyleDeclaration) : Boolean
  186.       {
  187.          var _loc2_:Object = null;
  188.          if(param1 == null)
  189.          {
  190.             return false;
  191.          }
  192.          if(ObjectUtil.compare(this.overrides,param1.overrides) != 0)
  193.          {
  194.             return false;
  195.          }
  196.          if(this.factory == null && param1.factory != null || this.factory != null && param1.factory == null)
  197.          {
  198.             return false;
  199.          }
  200.          if(this.factory != null)
  201.          {
  202.             if(ObjectUtil.compare(new this.factory(),new param1.factory()) != 0)
  203.             {
  204.                return false;
  205.             }
  206.          }
  207.          if(this.defaultFactory == null && param1.defaultFactory != null || this.defaultFactory != null && param1.defaultFactory == null)
  208.          {
  209.             return false;
  210.          }
  211.          if(this.defaultFactory != null)
  212.          {
  213.             if(ObjectUtil.compare(new this.defaultFactory(),new param1.defaultFactory()) != 0)
  214.             {
  215.                return false;
  216.             }
  217.          }
  218.          if(ObjectUtil.compare(this.mx_internal::effects,param1.mx_internal::effects))
  219.          {
  220.             return false;
  221.          }
  222.          return true;
  223.       }
  224.       
  225.       public function getStyle(param1:String) : *
  226.       {
  227.          var _loc2_:* = undefined;
  228.          var _loc3_:* = undefined;
  229.          if(this.overrides)
  230.          {
  231.             if(param1 in this.overrides && this.overrides[param1] === undefined)
  232.             {
  233.                return undefined;
  234.             }
  235.             _loc3_ = this.overrides[param1];
  236.             if(_loc3_ !== undefined)
  237.             {
  238.                return _loc3_;
  239.             }
  240.          }
  241.          if(this.factory != null)
  242.          {
  243.             this.factory.prototype = {};
  244.             _loc2_ = new this.factory();
  245.             _loc3_ = _loc2_[param1];
  246.             if(_loc3_ !== undefined)
  247.             {
  248.                return _loc3_;
  249.             }
  250.          }
  251.          if(this.defaultFactory != null)
  252.          {
  253.             this.defaultFactory.prototype = {};
  254.             _loc2_ = new this.defaultFactory();
  255.             _loc3_ = _loc2_[param1];
  256.             if(_loc3_ !== undefined)
  257.             {
  258.                return _loc3_;
  259.             }
  260.          }
  261.          return undefined;
  262.       }
  263.       
  264.       public function setStyle(param1:String, param2:*) : void
  265.       {
  266.          var _loc7_:int = 0;
  267.          var _loc8_:ISystemManager = null;
  268.          var _loc9_:Object = null;
  269.          var _loc3_:Object = this.getStyle(param1);
  270.          var _loc4_:Boolean = false;
  271.          if(this.mx_internal::selectorRefCount > 0 && this.factory == null && this.defaultFactory == null && !this.overrides && _loc3_ !== param2)
  272.          {
  273.             _loc4_ = true;
  274.          }
  275.          if(param2 !== undefined)
  276.          {
  277.             this.mx_internal::setLocalStyle(param1,param2);
  278.          }
  279.          else
  280.          {
  281.             if(param2 == _loc3_)
  282.             {
  283.                return;
  284.             }
  285.             this.mx_internal::setLocalStyle(param1,param2);
  286.          }
  287.          var _loc5_:Array = SystemManagerGlobals.topLevelSystemManagers;
  288.          var _loc6_:int = int(_loc5_.length);
  289.          if(_loc4_)
  290.          {
  291.             _loc7_ = 0;
  292.             while(_loc7_ < _loc6_)
  293.             {
  294.                _loc8_ = _loc5_[_loc7_];
  295.                _loc9_ = _loc8_.getImplementation("mx.managers::ISystemManagerChildManager");
  296.                _loc9_.regenerateStyleCache(true);
  297.                _loc7_++;
  298.             }
  299.          }
  300.          _loc7_ = 0;
  301.          while(_loc7_ < _loc6_)
  302.          {
  303.             _loc8_ = _loc5_[_loc7_];
  304.             _loc9_ = _loc8_.getImplementation("mx.managers::ISystemManagerChildManager");
  305.             _loc9_.notifyStyleChangeInChildren(param1,true);
  306.             _loc7_++;
  307.          }
  308.       }
  309.       
  310.       mx_internal function setLocalStyle(param1:String, param2:*) : void
  311.       {
  312.          var _loc4_:Object = null;
  313.          var _loc5_:Number = NaN;
  314.          var _loc3_:Object = this.getStyle(param1);
  315.          if(param2 === undefined)
  316.          {
  317.             this.clearStyleAttr(param1);
  318.             return;
  319.          }
  320.          if(param2 is String)
  321.          {
  322.             if(!this.styleManager)
  323.             {
  324.                this.styleManager = Singleton.getInstance("mx.styles::IStyleManager2") as IStyleManager2;
  325.             }
  326.             _loc5_ = Number(this.styleManager.getColorName(param2));
  327.             if(_loc5_ != NOT_A_COLOR)
  328.             {
  329.                param2 = _loc5_;
  330.             }
  331.          }
  332.          if(this.defaultFactory != null)
  333.          {
  334.             _loc4_ = new this.defaultFactory();
  335.             if(_loc4_[param1] !== param2)
  336.             {
  337.                if(!this.overrides)
  338.                {
  339.                   this.overrides = {};
  340.                }
  341.                this.overrides[param1] = param2;
  342.             }
  343.             else if(this.overrides)
  344.             {
  345.                delete this.overrides[param1];
  346.             }
  347.          }
  348.          if(this.factory != null)
  349.          {
  350.             _loc4_ = new this.factory();
  351.             if(_loc4_[param1] !== param2)
  352.             {
  353.                if(!this.overrides)
  354.                {
  355.                   this.overrides = {};
  356.                }
  357.                this.overrides[param1] = param2;
  358.             }
  359.             else if(this.overrides)
  360.             {
  361.                delete this.overrides[param1];
  362.             }
  363.          }
  364.          if(this.defaultFactory == null && this.factory == null)
  365.          {
  366.             if(!this.overrides)
  367.             {
  368.                this.overrides = {};
  369.             }
  370.             this.overrides[param1] = param2;
  371.          }
  372.          this.mx_internal::updateClones(param1,param2);
  373.       }
  374.       
  375.       public function clearStyle(param1:String) : void
  376.       {
  377.          this.setStyle(param1,undefined);
  378.       }
  379.       
  380.       mx_internal function createProtoChainRoot() : Object
  381.       {
  382.          var _loc1_:Object = {};
  383.          if(this.defaultFactory != null)
  384.          {
  385.             this.defaultFactory.prototype = _loc1_;
  386.             _loc1_ = new this.defaultFactory();
  387.          }
  388.          if(this.factory != null)
  389.          {
  390.             this.factory.prototype = _loc1_;
  391.             _loc1_ = new this.factory();
  392.          }
  393.          this.clones[_loc1_] = 1;
  394.          return _loc1_;
  395.       }
  396.       
  397.       mx_internal function addStyleToProtoChain(param1:Object, param2:DisplayObject, param3:Object = null) : Object
  398.       {
  399.          var addedParentStyleToProtoChain:Boolean;
  400.          var style:CSSStyleDeclaration = null;
  401.          var inChain:Object = null;
  402.          var parentStyle:CSSStyleDeclaration = null;
  403.          var emptyObjectFactory:Function = null;
  404.          var chain:Object = param1;
  405.          var target:DisplayObject = param2;
  406.          var filterMap:Object = param3;
  407.          var nodeAddedToChain:Boolean = false;
  408.          var originalChain:Object = chain;
  409.          var parentStyleDeclarations:Vector.<CSSStyleDeclaration> = new Vector.<CSSStyleDeclaration>();
  410.          var styleParent:IStyleManager2 = this.styleManager.parent;
  411.          while(styleParent)
  412.          {
  413.             parentStyle = styleParent.getStyleDeclaration(this.mx_internal::selectorString);
  414.             if(parentStyle)
  415.             {
  416.                parentStyleDeclarations.unshift(parentStyle);
  417.             }
  418.             styleParent = styleParent.parent;
  419.          }
  420.          for each(style in parentStyleDeclarations)
  421.          {
  422.             if(style.defaultFactory != null)
  423.             {
  424.                chain = style.mx_internal::addDefaultStyleToProtoChain(chain,target,filterMap);
  425.             }
  426.          }
  427.          if(this.defaultFactory != null)
  428.          {
  429.             chain = this.mx_internal::addDefaultStyleToProtoChain(chain,target,filterMap);
  430.          }
  431.          addedParentStyleToProtoChain = false;
  432.          for each(style in parentStyleDeclarations)
  433.          {
  434.             if(style.factory != null || style.overrides != null)
  435.             {
  436.                chain = style.mx_internal::addFactoryAndOverrideStylesToProtoChain(chain,target,filterMap);
  437.                addedParentStyleToProtoChain = true;
  438.             }
  439.          }
  440.          inChain = chain;
  441.          if(this.factory != null || this.overrides != null)
  442.          {
  443.             chain = this.mx_internal::addFactoryAndOverrideStylesToProtoChain(chain,target,filterMap);
  444.             if(inChain != chain)
  445.             {
  446.                nodeAddedToChain = true;
  447.             }
  448.          }
  449.          if(this.defaultFactory != null && !nodeAddedToChain)
  450.          {
  451.             if(addedParentStyleToProtoChain)
  452.             {
  453.                emptyObjectFactory = function():void
  454.                {
  455.                };
  456.                emptyObjectFactory.prototype = chain;
  457.                chain = new emptyObjectFactory();
  458.             }
  459.             nodeAddedToChain = true;
  460.          }
  461.          if(nodeAddedToChain)
  462.          {
  463.             this.clones[chain] = 1;
  464.          }
  465.          return chain;
  466.       }
  467.       
  468.       mx_internal function addDefaultStyleToProtoChain(param1:Object, param2:DisplayObject, param3:Object = null) : Object
  469.       {
  470.          var _loc4_:Object = null;
  471.          if(this.defaultFactory != null)
  472.          {
  473.             _loc4_ = param1;
  474.             if(param3)
  475.             {
  476.                param1 = {};
  477.             }
  478.             this.defaultFactory.prototype = param1;
  479.             param1 = new this.defaultFactory();
  480.             if(param3)
  481.             {
  482.                param1 = this.mx_internal::applyFilter(_loc4_,param1,param3);
  483.             }
  484.          }
  485.          return param1;
  486.       }
  487.       
  488.       mx_internal function addFactoryAndOverrideStylesToProtoChain(param1:Object, param2:DisplayObject, param3:Object = null) : Object
  489.       {
  490.          var objectFactory:Object;
  491.          var p:String = null;
  492.          var emptyObjectFactory:Function = null;
  493.          var chain:Object = param1;
  494.          var target:DisplayObject = param2;
  495.          var filterMap:Object = param3;
  496.          var originalChain:Object = chain;
  497.          if(filterMap)
  498.          {
  499.             chain = {};
  500.          }
  501.          objectFactory = null;
  502.          if(this.factory != null)
  503.          {
  504.             objectFactory = new this.factory();
  505.             this.factory.prototype = chain;
  506.             chain = new this.factory();
  507.          }
  508.          if(this.overrides)
  509.          {
  510.             if(this.factory == null)
  511.             {
  512.                emptyObjectFactory = function():void
  513.                {
  514.                };
  515.                emptyObjectFactory.prototype = chain;
  516.                chain = new emptyObjectFactory();
  517.             }
  518.             for(p in this.overrides)
  519.             {
  520.                if(this.overrides[p] === undefined)
  521.                {
  522.                   delete chain[p];
  523.                }
  524.                else
  525.                {
  526.                   chain[p] = this.overrides[p];
  527.                }
  528.             }
  529.          }
  530.          if(filterMap)
  531.          {
  532.             if(this.factory != null || Boolean(this.overrides))
  533.             {
  534.                chain = this.mx_internal::applyFilter(originalChain,chain,filterMap);
  535.             }
  536.             else
  537.             {
  538.                chain = originalChain;
  539.             }
  540.          }
  541.          if(this.factory != null || Boolean(this.overrides))
  542.          {
  543.             this.clones[chain] = 1;
  544.          }
  545.          return chain;
  546.       }
  547.       
  548.       mx_internal function applyFilter(param1:Object, param2:Object, param3:Object) : Object
  549.       {
  550.          var i:String = null;
  551.          var originalChain:Object = param1;
  552.          var chain:Object = param2;
  553.          var filterMap:Object = param3;
  554.          var filteredChain:Object = {};
  555.          var filterObjectFactory:Function = function():void
  556.          {
  557.          };
  558.          filterObjectFactory.prototype = originalChain;
  559.          filteredChain = new filterObjectFactory();
  560.          for(i in chain)
  561.          {
  562.             if(filterMap[i] != null)
  563.             {
  564.                filteredChain[filterMap[i]] = chain[i];
  565.             }
  566.          }
  567.          chain = filteredChain;
  568.          chain[FILTERMAP_PROP] = filterMap;
  569.          return chain;
  570.       }
  571.       
  572.       mx_internal function clearOverride(param1:String) : void
  573.       {
  574.          if(Boolean(this.overrides) && this.overrides[param1] !== undefined)
  575.          {
  576.             delete this.overrides[param1];
  577.          }
  578.       }
  579.       
  580.       private function clearStyleAttr(param1:String) : void
  581.       {
  582.          var _loc2_:* = undefined;
  583.          if(!this.overrides)
  584.          {
  585.             this.overrides = {};
  586.          }
  587.          this.overrides[param1] = undefined;
  588.          for(_loc2_ in this.clones)
  589.          {
  590.             delete _loc2_[param1];
  591.          }
  592.       }
  593.       
  594.       mx_internal function updateClones(param1:String, param2:*) : void
  595.       {
  596.          var _loc3_:* = undefined;
  597.          var _loc4_:Object = null;
  598.          for(_loc3_ in this.clones)
  599.          {
  600.             _loc4_ = _loc3_[FILTERMAP_PROP];
  601.             if(_loc4_)
  602.             {
  603.                if(_loc4_[param1] != null)
  604.                {
  605.                   _loc3_[_loc4_[param1]] = param2;
  606.                }
  607.             }
  608.             else
  609.             {
  610.                _loc3_[param1] = param2;
  611.             }
  612.          }
  613.       }
  614.    }
  615. }
  616.  
  617.