home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Freeware / Adobe Air 1.5 / AdobeAIRInstaller.exe / setup.swf / scripts / mx / styles / StyleManagerImpl.as < prev    next >
Encoding:
Text File  |  2008-10-29  |  15.1 KB  |  493 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.0.0.0";
  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;
  119.       
  120.       private var _typeSelectorCache:Object;
  121.       
  122.       public function StyleManagerImpl()
  123.       {
  124.          _selectors = {};
  125.          styleModules = {};
  126.          resourceManager = ResourceManager.getInstance();
  127.          _inheritingStyles = {};
  128.          _typeSelectorCache = {};
  129.          super();
  130.       }
  131.       
  132.       public static function getInstance() : IStyleManager2
  133.       {
  134.          if(!instance)
  135.          {
  136.             instance = new StyleManagerImpl();
  137.          }
  138.          return instance;
  139.       }
  140.       
  141.       public function setStyleDeclaration(param1:String, param2:CSSStyleDeclaration, param3:Boolean) : void
  142.       {
  143.          ++param2.mx_internal::selectorRefCount;
  144.          _selectors[param1] = param2;
  145.          typeSelectorCache = {};
  146.          if(param3)
  147.          {
  148.             styleDeclarationsChanged();
  149.          }
  150.       }
  151.       
  152.       public function registerParentDisplayListInvalidatingStyle(param1:String) : void
  153.       {
  154.          parentDisplayListInvalidatingStyles[param1] = true;
  155.       }
  156.       
  157.       public function getStyleDeclaration(param1:String) : CSSStyleDeclaration
  158.       {
  159.          var _loc2_:int = 0;
  160.          if(param1.charAt(0) != ".")
  161.          {
  162.             _loc2_ = int(param1.lastIndexOf("."));
  163.             if(_loc2_ != -1)
  164.             {
  165.                param1 = param1.substr(_loc2_ + 1);
  166.             }
  167.          }
  168.          return _selectors[param1];
  169.       }
  170.       
  171.       public function set typeSelectorCache(param1:Object) : void
  172.       {
  173.          _typeSelectorCache = param1;
  174.       }
  175.       
  176.       public function isColorName(param1:String) : Boolean
  177.       {
  178.          return colorNames[param1.toLowerCase()] !== undefined;
  179.       }
  180.       
  181.       public function set inheritingStyles(param1:Object) : void
  182.       {
  183.          _inheritingStyles = param1;
  184.       }
  185.       
  186.       public function getColorNames(param1:Array) : void
  187.       {
  188.          var _loc4_:uint = 0;
  189.          if(!param1)
  190.          {
  191.             return;
  192.          }
  193.          var _loc2_:int = int(param1.length);
  194.          var _loc3_:int = 0;
  195.          while(_loc3_ < _loc2_)
  196.          {
  197.             if(param1[_loc3_] != null && isNaN(param1[_loc3_]))
  198.             {
  199.                _loc4_ = getColorName(param1[_loc3_]);
  200.                if(_loc4_ != StyleManager.NOT_A_COLOR)
  201.                {
  202.                   param1[_loc3_] = _loc4_;
  203.                }
  204.             }
  205.             _loc3_++;
  206.          }
  207.       }
  208.       
  209.       public function isInheritingTextFormatStyle(param1:String) : Boolean
  210.       {
  211.          return inheritingTextFormatStyles[param1] == true;
  212.       }
  213.       
  214.       public function registerParentSizeInvalidatingStyle(param1:String) : void
  215.       {
  216.          parentSizeInvalidatingStyles[param1] = true;
  217.       }
  218.       
  219.       public function registerColorName(param1:String, param2:uint) : void
  220.       {
  221.          colorNames[param1.toLowerCase()] = param2;
  222.       }
  223.       
  224.       public function isParentSizeInvalidatingStyle(param1:String) : Boolean
  225.       {
  226.          return parentSizeInvalidatingStyles[param1] == true;
  227.       }
  228.       
  229.       public function registerInheritingStyle(param1:String) : void
  230.       {
  231.          inheritingStyles[param1] = true;
  232.       }
  233.       
  234.       public function set stylesRoot(param1:Object) : void
  235.       {
  236.          _stylesRoot = param1;
  237.       }
  238.       
  239.       public function get typeSelectorCache() : Object
  240.       {
  241.          return _typeSelectorCache;
  242.       }
  243.       
  244.       public function isParentDisplayListInvalidatingStyle(param1:String) : Boolean
  245.       {
  246.          return parentDisplayListInvalidatingStyles[param1] == true;
  247.       }
  248.       
  249.       public function isSizeInvalidatingStyle(param1:String) : Boolean
  250.       {
  251.          return sizeInvalidatingStyles[param1] == true;
  252.       }
  253.       
  254.       public function styleDeclarationsChanged() : void
  255.       {
  256.          var _loc4_:Object = null;
  257.          var _loc1_:Array = SystemManagerGlobals.topLevelSystemManagers;
  258.          var _loc2_:int = int(_loc1_.length);
  259.          var _loc3_:int = 0;
  260.          while(_loc3_ < _loc2_)
  261.          {
  262.             _loc4_ = _loc1_[_loc3_];
  263.             _loc4_.regenerateStyleCache(true);
  264.             _loc4_.notifyStyleChangeInChildren(null,true);
  265.             _loc3_++;
  266.          }
  267.       }
  268.       
  269.       public function isValidStyleValue(param1:*) : Boolean
  270.       {
  271.          return param1 !== undefined;
  272.       }
  273.       
  274.       public function loadStyleDeclarations(param1:String, param2:Boolean = true, param3:Boolean = false) : IEventDispatcher
  275.       {
  276.          return loadStyleDeclarations2(param1,param2);
  277.       }
  278.       
  279.       public function get inheritingStyles() : Object
  280.       {
  281.          return _inheritingStyles;
  282.       }
  283.       
  284.       public function unloadStyleDeclarations(param1:String, param2:Boolean = true) : void
  285.       {
  286.          var _loc4_:IModuleInfo = null;
  287.          var _loc3_:StyleModuleInfo = styleModules[param1];
  288.          if(_loc3_)
  289.          {
  290.             _loc3_.styleModule.unload();
  291.             _loc4_ = _loc3_.module;
  292.             _loc4_.unload();
  293.             _loc4_.removeEventListener(ModuleEvent.READY,_loc3_.readyHandler);
  294.             _loc4_.removeEventListener(ModuleEvent.ERROR,_loc3_.errorHandler);
  295.             styleModules[param1] = null;
  296.          }
  297.          if(param2)
  298.          {
  299.             styleDeclarationsChanged();
  300.          }
  301.       }
  302.       
  303.       public function getColorName(param1:Object) : uint
  304.       {
  305.          var _loc2_:Number = NaN;
  306.          var _loc3_:* = undefined;
  307.          if(param1 is String)
  308.          {
  309.             if(param1.charAt(0) == "#")
  310.             {
  311.                _loc2_ = Number("0x" + param1.slice(1));
  312.                return isNaN(_loc2_) ? StyleManager.NOT_A_COLOR : uint(_loc2_);
  313.             }
  314.             if(param1.charAt(1) == "x" && param1.charAt(0) == "0")
  315.             {
  316.                _loc2_ = Number(param1);
  317.                return isNaN(_loc2_) ? StyleManager.NOT_A_COLOR : uint(_loc2_);
  318.             }
  319.             _loc3_ = colorNames[param1.toLowerCase()];
  320.             if(_loc3_ === undefined)
  321.             {
  322.                return StyleManager.NOT_A_COLOR;
  323.             }
  324.             return uint(_loc3_);
  325.          }
  326.          return uint(param1);
  327.       }
  328.       
  329.       public function isInheritingStyle(param1:String) : Boolean
  330.       {
  331.          return inheritingStyles[param1] == true;
  332.       }
  333.       
  334.       public function get stylesRoot() : Object
  335.       {
  336.          return _stylesRoot;
  337.       }
  338.       
  339.       public function initProtoChainRoots() : void
  340.       {
  341.          if(FlexVersion.compatibilityVersion < FlexVersion.VERSION_3_0)
  342.          {
  343.             delete _inheritingStyles["textDecoration"];
  344.             delete _inheritingStyles["leading"];
  345.          }
  346.          if(!stylesRoot)
  347.          {
  348.             stylesRoot = _selectors["global"].addStyleToProtoChain({},null);
  349.          }
  350.       }
  351.       
  352.       public function loadStyleDeclarations2(param1:String, param2:Boolean = true, param3:ApplicationDomain = null, param4:SecurityDomain = null) : IEventDispatcher
  353.       {
  354.          var errorHandler:Function;
  355.          var module:IModuleInfo = null;
  356.          var styleEventDispatcher:StyleEventDispatcher = null;
  357.          var timer:Timer = null;
  358.          var timerHandler:Function = null;
  359.          var url:String = param1;
  360.          var update:Boolean = param2;
  361.          var applicationDomain:ApplicationDomain = param3;
  362.          var securityDomain:SecurityDomain = param4;
  363.          module = ModuleManager.getModule(url);
  364.          var readyHandler:Function = function(param1:ModuleEvent):void
  365.          {
  366.             var _loc2_:IStyleModule = IStyleModule(param1.module.factory.create());
  367.             styleModules[param1.module.url].styleModule = _loc2_;
  368.             if(update)
  369.             {
  370.                styleDeclarationsChanged();
  371.             }
  372.          };
  373.          module.addEventListener(ModuleEvent.READY,readyHandler,false,0,true);
  374.          styleEventDispatcher = new StyleEventDispatcher(module);
  375.          errorHandler = function(param1:ModuleEvent):void
  376.          {
  377.             var _loc3_:StyleEvent = null;
  378.             var _loc2_:String = resourceManager.getString("styles","unableToLoad",[param1.errorText,url]);
  379.             if(styleEventDispatcher.willTrigger(StyleEvent.ERROR))
  380.             {
  381.                _loc3_ = new StyleEvent(StyleEvent.ERROR,param1.bubbles,param1.cancelable);
  382.                _loc3_.bytesLoaded = 0;
  383.                _loc3_.bytesTotal = 0;
  384.                _loc3_.errorText = _loc2_;
  385.                styleEventDispatcher.dispatchEvent(_loc3_);
  386.                return;
  387.             }
  388.             throw new Error(_loc2_);
  389.          };
  390.          module.addEventListener(ModuleEvent.ERROR,errorHandler,false,0,true);
  391.          styleModules[url] = new StyleModuleInfo(module,readyHandler,errorHandler);
  392.          timer = new Timer(0);
  393.          timerHandler = function(param1:TimerEvent):void
  394.          {
  395.             timer.removeEventListener(TimerEvent.TIMER,timerHandler);
  396.             timer.stop();
  397.             module.load(applicationDomain,securityDomain);
  398.          };
  399.          timer.addEventListener(TimerEvent.TIMER,timerHandler,false,0,true);
  400.          timer.start();
  401.          return styleEventDispatcher;
  402.       }
  403.       
  404.       public function registerSizeInvalidatingStyle(param1:String) : void
  405.       {
  406.          sizeInvalidatingStyles[param1] = true;
  407.       }
  408.       
  409.       public function clearStyleDeclaration(param1:String, param2:Boolean) : void
  410.       {
  411.          var _loc3_:CSSStyleDeclaration = getStyleDeclaration(param1);
  412.          if(Boolean(_loc3_) && _loc3_.mx_internal::selectorRefCount > 0)
  413.          {
  414.             --_loc3_.mx_internal::selectorRefCount;
  415.          }
  416.          delete _selectors[param1];
  417.          if(param2)
  418.          {
  419.             styleDeclarationsChanged();
  420.          }
  421.       }
  422.       
  423.       public function get selectors() : Array
  424.       {
  425.          var _loc2_:String = null;
  426.          var _loc1_:Array = [];
  427.          for(_loc2_ in _selectors)
  428.          {
  429.             _loc1_.push(_loc2_);
  430.          }
  431.          return _loc1_;
  432.       }
  433.    }
  434. }
  435.  
  436. import flash.events.EventDispatcher;
  437. import mx.events.ModuleEvent;
  438. import mx.events.StyleEvent;
  439. import mx.modules.IModuleInfo;
  440.  
  441. class StyleEventDispatcher extends EventDispatcher
  442. {
  443.    public function StyleEventDispatcher(param1:IModuleInfo)
  444.    {
  445.       super();
  446.       param1.addEventListener(ModuleEvent.ERROR,moduleInfo_errorHandler,false,0,true);
  447.       param1.addEventListener(ModuleEvent.PROGRESS,moduleInfo_progressHandler,false,0,true);
  448.       param1.addEventListener(ModuleEvent.READY,moduleInfo_readyHandler,false,0,true);
  449.    }
  450.    
  451.    private function moduleInfo_progressHandler(param1:ModuleEvent) : void
  452.    {
  453.       var _loc2_:StyleEvent = new StyleEvent(StyleEvent.PROGRESS,param1.bubbles,param1.cancelable);
  454.       _loc2_.bytesLoaded = param1.bytesLoaded;
  455.       _loc2_.bytesTotal = param1.bytesTotal;
  456.       dispatchEvent(_loc2_);
  457.    }
  458.    
  459.    private function moduleInfo_readyHandler(param1:ModuleEvent) : void
  460.    {
  461.       var _loc2_:StyleEvent = new StyleEvent(StyleEvent.COMPLETE);
  462.       dispatchEvent(_loc2_);
  463.    }
  464.    
  465.    private function moduleInfo_errorHandler(param1:ModuleEvent) : void
  466.    {
  467.       var _loc2_:StyleEvent = 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.  
  475. class StyleModuleInfo
  476. {
  477.    public var errorHandler:Function;
  478.    
  479.    public var readyHandler:Function;
  480.    
  481.    public var module:IModuleInfo;
  482.    
  483.    public var styleModule:IStyleModule;
  484.    
  485.    public function StyleModuleInfo(param1:IModuleInfo, param2:Function, param3:Function)
  486.    {
  487.       super();
  488.       this.module = param1;
  489.       this.readyHandler = param2;
  490.       this.errorHandler = param3;
  491.    }
  492. }
  493.