home *** CD-ROM | disk | FTP | other *** search
/ Computer Active 2010 August / CA08.iso / Multimedija / shufflr.air / ShufflrClient.swf / scripts / mx / styles / StyleManagerImpl.as < prev    next >
Encoding:
Text File  |  2010-06-23  |  15.1 KB  |  490 lines

  1. package mx.styles
  2. {
  3.    import flash.events.IEventDispatcher;
  4.    import flash.events.TimerEvent;
  5.    import flash.system.ApplicationDomain;
  6.    import flash.system.SecurityDomain;
  7.    import flash.utils.Timer;
  8.    import mx.core.FlexVersion;
  9.    import mx.core.mx_internal;
  10.    import mx.events.ModuleEvent;
  11.    import mx.events.StyleEvent;
  12.    import mx.managers.SystemManagerGlobals;
  13.    import mx.modules.IModuleInfo;
  14.    import mx.modules.ModuleManager;
  15.    import mx.resources.IResourceManager;
  16.    import mx.resources.ResourceManager;
  17.    
  18.    use namespace mx_internal;
  19.    
  20.    public class StyleManagerImpl implements IStyleManager2
  21.    {
  22.       private static var instance:IStyleManager2;
  23.       
  24.       mx_internal static const VERSION:String = "3.5.0.12683";
  25.       
  26.       private static var inheritingTextFormatStyles:Object = {
  27.          "align":true,
  28.          "bold":true,
  29.          "color":true,
  30.          "font":true,
  31.          "indent":true,
  32.          "italic":true,
  33.          "size":true
  34.       };
  35.       
  36.       private static var sizeInvalidatingStyles:Object = {
  37.          "borderStyle":true,
  38.          "borderThickness":true,
  39.          "fontAntiAliasType":true,
  40.          "fontFamily":true,
  41.          "fontGridFitType":true,
  42.          "fontSharpness":true,
  43.          "fontSize":true,
  44.          "fontStyle":true,
  45.          "fontThickness":true,
  46.          "fontWeight":true,
  47.          "headerHeight":true,
  48.          "horizontalAlign":true,
  49.          "horizontalGap":true,
  50.          "kerning":true,
  51.          "leading":true,
  52.          "letterSpacing":true,
  53.          "paddingBottom":true,
  54.          "paddingLeft":true,
  55.          "paddingRight":true,
  56.          "paddingTop":true,
  57.          "strokeWidth":true,
  58.          "tabHeight":true,
  59.          "tabWidth":true,
  60.          "verticalAlign":true,
  61.          "verticalGap":true
  62.       };
  63.       
  64.       private static var parentSizeInvalidatingStyles:Object = {
  65.          "bottom":true,
  66.          "horizontalCenter":true,
  67.          "left":true,
  68.          "right":true,
  69.          "top":true,
  70.          "verticalCenter":true,
  71.          "baseline":true
  72.       };
  73.       
  74.       private static var parentDisplayListInvalidatingStyles:Object = {
  75.          "bottom":true,
  76.          "horizontalCenter":true,
  77.          "left":true,
  78.          "right":true,
  79.          "top":true,
  80.          "verticalCenter":true,
  81.          "baseline":true
  82.       };
  83.       
  84.       private static var colorNames:Object = {
  85.          "transparent":"transparent",
  86.          "black":0,
  87.          "blue":255,
  88.          "green":32768,
  89.          "gray":8421504,
  90.          "silver":12632256,
  91.          "lime":65280,
  92.          "olive":8421376,
  93.          "white":16777215,
  94.          "yellow":16776960,
  95.          "maroon":8388608,
  96.          "navy":128,
  97.          "red":16711680,
  98.          "purple":8388736,
  99.          "teal":32896,
  100.          "fuchsia":16711935,
  101.          "aqua":65535,
  102.          "magenta":16711935,
  103.          "cyan":65535,
  104.          "halogreen":8453965,
  105.          "haloblue":40447,
  106.          "haloorange":16758272,
  107.          "halosilver":11455193
  108.       };
  109.       
  110.       private var _stylesRoot:Object;
  111.       
  112.       private var _selectors:Object = {};
  113.       
  114.       private var styleModules:Object = {};
  115.       
  116.       private var _inheritingStyles:Object = {};
  117.       
  118.       private var resourceManager:IResourceManager = ResourceManager.getInstance();
  119.       
  120.       private var _typeSelectorCache:Object = {};
  121.       
  122.       public function StyleManagerImpl()
  123.       {
  124.          super();
  125.       }
  126.       
  127.       public static function getInstance() : IStyleManager2
  128.       {
  129.          if(!instance)
  130.          {
  131.             instance = new StyleManagerImpl();
  132.          }
  133.          return instance;
  134.       }
  135.       
  136.       public function setStyleDeclaration(param1:String, param2:CSSStyleDeclaration, param3:Boolean) : void
  137.       {
  138.          ++param2.mx_internal::selectorRefCount;
  139.          _selectors[param1] = param2;
  140.          typeSelectorCache = {};
  141.          if(param3)
  142.          {
  143.             styleDeclarationsChanged();
  144.          }
  145.       }
  146.       
  147.       public function registerParentDisplayListInvalidatingStyle(param1:String) : void
  148.       {
  149.          parentDisplayListInvalidatingStyles[param1] = true;
  150.       }
  151.       
  152.       public function getStyleDeclaration(param1:String) : CSSStyleDeclaration
  153.       {
  154.          var _loc2_:int = 0;
  155.          if(param1.charAt(0) != ".")
  156.          {
  157.             _loc2_ = int(param1.lastIndexOf("."));
  158.             if(_loc2_ != -1)
  159.             {
  160.                param1 = param1.substr(_loc2_ + 1);
  161.             }
  162.          }
  163.          return _selectors[param1];
  164.       }
  165.       
  166.       public function set typeSelectorCache(param1:Object) : void
  167.       {
  168.          _typeSelectorCache = param1;
  169.       }
  170.       
  171.       public function isColorName(param1:String) : Boolean
  172.       {
  173.          return colorNames[param1.toLowerCase()] !== undefined;
  174.       }
  175.       
  176.       public function set inheritingStyles(param1:Object) : void
  177.       {
  178.          _inheritingStyles = param1;
  179.       }
  180.       
  181.       public function getColorNames(param1:Array) : void
  182.       {
  183.          var _loc4_:uint = 0;
  184.          if(!param1)
  185.          {
  186.             return;
  187.          }
  188.          var _loc2_:int = int(param1.length);
  189.          var _loc3_:int = 0;
  190.          while(_loc3_ < _loc2_)
  191.          {
  192.             if(param1[_loc3_] != null && isNaN(param1[_loc3_]))
  193.             {
  194.                _loc4_ = getColorName(param1[_loc3_]);
  195.                if(_loc4_ != StyleManager.NOT_A_COLOR)
  196.                {
  197.                   param1[_loc3_] = _loc4_;
  198.                }
  199.             }
  200.             _loc3_++;
  201.          }
  202.       }
  203.       
  204.       public function isInheritingTextFormatStyle(param1:String) : Boolean
  205.       {
  206.          return inheritingTextFormatStyles[param1] == true;
  207.       }
  208.       
  209.       public function registerParentSizeInvalidatingStyle(param1:String) : void
  210.       {
  211.          parentSizeInvalidatingStyles[param1] = true;
  212.       }
  213.       
  214.       public function registerColorName(param1:String, param2:uint) : void
  215.       {
  216.          colorNames[param1.toLowerCase()] = param2;
  217.       }
  218.       
  219.       public function isParentSizeInvalidatingStyle(param1:String) : Boolean
  220.       {
  221.          return parentSizeInvalidatingStyles[param1] == true;
  222.       }
  223.       
  224.       public function registerInheritingStyle(param1:String) : void
  225.       {
  226.          inheritingStyles[param1] = true;
  227.       }
  228.       
  229.       public function set stylesRoot(param1:Object) : void
  230.       {
  231.          _stylesRoot = param1;
  232.       }
  233.       
  234.       public function get typeSelectorCache() : Object
  235.       {
  236.          return _typeSelectorCache;
  237.       }
  238.       
  239.       public function isParentDisplayListInvalidatingStyle(param1:String) : Boolean
  240.       {
  241.          return parentDisplayListInvalidatingStyles[param1] == true;
  242.       }
  243.       
  244.       public function isSizeInvalidatingStyle(param1:String) : Boolean
  245.       {
  246.          return sizeInvalidatingStyles[param1] == true;
  247.       }
  248.       
  249.       public function styleDeclarationsChanged() : void
  250.       {
  251.          var _loc4_:Object = null;
  252.          var _loc1_:Array = SystemManagerGlobals.topLevelSystemManagers;
  253.          var _loc2_:int = int(_loc1_.length);
  254.          var _loc3_:int = 0;
  255.          while(_loc3_ < _loc2_)
  256.          {
  257.             _loc4_ = _loc1_[_loc3_];
  258.             _loc4_.regenerateStyleCache(true);
  259.             _loc4_.notifyStyleChangeInChildren(null,true);
  260.             _loc3_++;
  261.          }
  262.       }
  263.       
  264.       public function isValidStyleValue(param1:*) : Boolean
  265.       {
  266.          return param1 !== undefined;
  267.       }
  268.       
  269.       public function loadStyleDeclarations(param1:String, param2:Boolean = true, param3:Boolean = false) : IEventDispatcher
  270.       {
  271.          return loadStyleDeclarations2(param1,param2);
  272.       }
  273.       
  274.       public function get inheritingStyles() : Object
  275.       {
  276.          return _inheritingStyles;
  277.       }
  278.       
  279.       public function unloadStyleDeclarations(param1:String, param2:Boolean = true) : void
  280.       {
  281.          var _loc4_:IModuleInfo = null;
  282.          var _loc3_:StyleModuleInfo = styleModules[param1];
  283.          if(_loc3_)
  284.          {
  285.             _loc3_.styleModule.unload();
  286.             _loc4_ = _loc3_.module;
  287.             _loc4_.unload();
  288.             _loc4_.removeEventListener(ModuleEvent.READY,_loc3_.readyHandler);
  289.             _loc4_.removeEventListener(ModuleEvent.ERROR,_loc3_.errorHandler);
  290.             styleModules[param1] = null;
  291.          }
  292.          if(param2)
  293.          {
  294.             styleDeclarationsChanged();
  295.          }
  296.       }
  297.       
  298.       public function getColorName(param1:Object) : uint
  299.       {
  300.          var _loc2_:Number = NaN;
  301.          var _loc3_:* = undefined;
  302.          if(param1 is String)
  303.          {
  304.             if(param1.charAt(0) == "#")
  305.             {
  306.                _loc2_ = Number("0x" + param1.slice(1));
  307.                return isNaN(_loc2_) ? StyleManager.NOT_A_COLOR : uint(_loc2_);
  308.             }
  309.             if(param1.charAt(1) == "x" && param1.charAt(0) == "0")
  310.             {
  311.                _loc2_ = Number(param1);
  312.                return isNaN(_loc2_) ? StyleManager.NOT_A_COLOR : uint(_loc2_);
  313.             }
  314.             _loc3_ = colorNames[param1.toLowerCase()];
  315.             if(_loc3_ === undefined)
  316.             {
  317.                return StyleManager.NOT_A_COLOR;
  318.             }
  319.             return uint(_loc3_);
  320.          }
  321.          return uint(param1);
  322.       }
  323.       
  324.       public function isInheritingStyle(param1:String) : Boolean
  325.       {
  326.          return inheritingStyles[param1] == true;
  327.       }
  328.       
  329.       public function get stylesRoot() : Object
  330.       {
  331.          return _stylesRoot;
  332.       }
  333.       
  334.       public function initProtoChainRoots() : void
  335.       {
  336.          if(FlexVersion.compatibilityVersion < FlexVersion.VERSION_3_0)
  337.          {
  338.             delete _inheritingStyles["textDecoration"];
  339.             delete _inheritingStyles["leading"];
  340.          }
  341.          if(!stylesRoot)
  342.          {
  343.             stylesRoot = _selectors["global"].addStyleToProtoChain({},null);
  344.          }
  345.       }
  346.       
  347.       public function loadStyleDeclarations2(param1:String, param2:Boolean = true, param3:ApplicationDomain = null, param4:SecurityDomain = null) : IEventDispatcher
  348.       {
  349.          var errorHandler:Function;
  350.          var module:IModuleInfo = null;
  351.          var styleEventDispatcher:StyleEventDispatcher = null;
  352.          var timer:Timer = null;
  353.          var timerHandler:Function = null;
  354.          var url:String = param1;
  355.          var update:Boolean = param2;
  356.          var applicationDomain:ApplicationDomain = param3;
  357.          var securityDomain:SecurityDomain = param4;
  358.          module = ModuleManager.getModule(url);
  359.          var readyHandler:Function = function(param1:ModuleEvent):void
  360.          {
  361.             var _loc2_:IStyleModule = IStyleModule(param1.module.factory.create());
  362.             styleModules[param1.module.url].styleModule = _loc2_;
  363.             if(update)
  364.             {
  365.                styleDeclarationsChanged();
  366.             }
  367.          };
  368.          module.addEventListener(ModuleEvent.READY,readyHandler,false,0,true);
  369.          styleEventDispatcher = new StyleEventDispatcher(module);
  370.          errorHandler = function(param1:ModuleEvent):void
  371.          {
  372.             var _loc3_:StyleEvent = null;
  373.             var _loc2_:String = resourceManager.getString("styles","unableToLoad",[param1.errorText,url]);
  374.             if(styleEventDispatcher.willTrigger(StyleEvent.ERROR))
  375.             {
  376.                _loc3_ = new StyleEvent(StyleEvent.ERROR,param1.bubbles,param1.cancelable);
  377.                _loc3_.bytesLoaded = 0;
  378.                _loc3_.bytesTotal = 0;
  379.                _loc3_.errorText = _loc2_;
  380.                styleEventDispatcher.dispatchEvent(_loc3_);
  381.                return;
  382.             }
  383.             throw new Error(_loc2_);
  384.          };
  385.          module.addEventListener(ModuleEvent.ERROR,errorHandler,false,0,true);
  386.          styleModules[url] = new StyleModuleInfo(module,readyHandler,errorHandler);
  387.          timer = new Timer(0);
  388.          timerHandler = function(param1:TimerEvent):void
  389.          {
  390.             timer.removeEventListener(TimerEvent.TIMER,timerHandler);
  391.             timer.stop();
  392.             module.load(applicationDomain,securityDomain);
  393.          };
  394.          timer.addEventListener(TimerEvent.TIMER,timerHandler,false,0,true);
  395.          timer.start();
  396.          return styleEventDispatcher;
  397.       }
  398.       
  399.       public function registerSizeInvalidatingStyle(param1:String) : void
  400.       {
  401.          sizeInvalidatingStyles[param1] = true;
  402.       }
  403.       
  404.       public function clearStyleDeclaration(param1:String, param2:Boolean) : void
  405.       {
  406.          var _loc3_:CSSStyleDeclaration = getStyleDeclaration(param1);
  407.          if(Boolean(_loc3_) && _loc3_.mx_internal::selectorRefCount > 0)
  408.          {
  409.             --_loc3_.mx_internal::selectorRefCount;
  410.          }
  411.          delete _selectors[param1];
  412.          if(param2)
  413.          {
  414.             styleDeclarationsChanged();
  415.          }
  416.       }
  417.       
  418.       public function get selectors() : Array
  419.       {
  420.          var _loc2_:String = null;
  421.          var _loc1_:Array = [];
  422.          for(_loc2_ in _selectors)
  423.          {
  424.             _loc1_.push(_loc2_);
  425.          }
  426.          return _loc1_;
  427.       }
  428.    }
  429. }
  430.  
  431. import flash.events.EventDispatcher;
  432. import mx.events.ModuleEvent;
  433. import mx.events.StyleEvent;
  434. import mx.modules.IModuleInfo;
  435.  
  436. class StyleEventDispatcher extends EventDispatcher
  437. {
  438.    public function StyleEventDispatcher(param1:IModuleInfo)
  439.    {
  440.       super();
  441.       param1.addEventListener(ModuleEvent.ERROR,moduleInfo_errorHandler,false,0,true);
  442.       param1.addEventListener(ModuleEvent.PROGRESS,moduleInfo_progressHandler,false,0,true);
  443.       param1.addEventListener(ModuleEvent.READY,moduleInfo_readyHandler,false,0,true);
  444.    }
  445.    
  446.    private function moduleInfo_progressHandler(param1:ModuleEvent) : void
  447.    {
  448.       var _loc2_:StyleEvent = new StyleEvent(StyleEvent.PROGRESS,param1.bubbles,param1.cancelable);
  449.       _loc2_.bytesLoaded = param1.bytesLoaded;
  450.       _loc2_.bytesTotal = param1.bytesTotal;
  451.       dispatchEvent(_loc2_);
  452.    }
  453.    
  454.    private function moduleInfo_readyHandler(param1:ModuleEvent) : void
  455.    {
  456.       var _loc2_:StyleEvent = new StyleEvent(StyleEvent.COMPLETE);
  457.       _loc2_.bytesLoaded = param1.bytesLoaded;
  458.       _loc2_.bytesTotal = param1.bytesTotal;
  459.       dispatchEvent(_loc2_);
  460.    }
  461.    
  462.    private function moduleInfo_errorHandler(param1:ModuleEvent) : void
  463.    {
  464.       var _loc2_:StyleEvent = new StyleEvent(StyleEvent.ERROR,param1.bubbles,param1.cancelable);
  465.       _loc2_.bytesLoaded = param1.bytesLoaded;
  466.       _loc2_.bytesTotal = param1.bytesTotal;
  467.       _loc2_.errorText = param1.errorText;
  468.       dispatchEvent(_loc2_);
  469.    }
  470. }
  471.  
  472. class StyleModuleInfo
  473. {
  474.    public var errorHandler:Function;
  475.    
  476.    public var readyHandler:Function;
  477.    
  478.    public var module:IModuleInfo;
  479.    
  480.    public var styleModule:IStyleModule;
  481.    
  482.    public function StyleModuleInfo(param1:IModuleInfo, param2:Function, param3:Function)
  483.    {
  484.       super();
  485.       this.module = param1;
  486.       this.readyHandler = param2;
  487.       this.errorHandler = param3;
  488.    }
  489. }
  490.