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