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

  1. package mx.managers
  2. {
  3.    import flash.display.Stage;
  4.    import flash.events.Event;
  5.    import flash.events.EventDispatcher;
  6.    import mx.core.UIComponentGlobals;
  7.    import mx.core.mx_internal;
  8.    import mx.events.DynamicEvent;
  9.    import mx.events.FlexEvent;
  10.    import mx.managers.layoutClasses.PriorityQueue;
  11.    
  12.    use namespace mx_internal;
  13.    
  14.    public class LayoutManager extends EventDispatcher implements ILayoutManager
  15.    {
  16.       private static var instance:LayoutManager;
  17.       
  18.       mx_internal static const VERSION:String = "4.5.0.20967";
  19.       
  20.       private var updateCompleteQueue:PriorityQueue = new PriorityQueue();
  21.       
  22.       private var invalidatePropertiesQueue:PriorityQueue = new PriorityQueue();
  23.       
  24.       private var invalidatePropertiesFlag:Boolean = false;
  25.       
  26.       private var invalidateClientPropertiesFlag:Boolean = false;
  27.       
  28.       private var invalidateSizeQueue:PriorityQueue = new PriorityQueue();
  29.       
  30.       private var invalidateSizeFlag:Boolean = false;
  31.       
  32.       private var invalidateClientSizeFlag:Boolean = false;
  33.       
  34.       private var invalidateDisplayListQueue:PriorityQueue = new PriorityQueue();
  35.       
  36.       private var invalidateDisplayListFlag:Boolean = false;
  37.       
  38.       private var waitedAFrame:Boolean = false;
  39.       
  40.       private var listenersAttached:Boolean = false;
  41.       
  42.       private var originalFrameRate:Number;
  43.       
  44.       private var targetLevel:int = 2147483647;
  45.       
  46.       private var systemManager:ISystemManager;
  47.       
  48.       private var currentObject:ILayoutManagerClient;
  49.       
  50.       private var _usePhasedInstantiation:Boolean = false;
  51.       
  52.       private var _usingBridge:int = -1;
  53.       
  54.       public function LayoutManager()
  55.       {
  56.          super();
  57.          this.systemManager = SystemManagerGlobals.topLevelSystemManagers[0];
  58.       }
  59.       
  60.       public static function getInstance() : LayoutManager
  61.       {
  62.          if(!instance)
  63.          {
  64.             instance = new LayoutManager();
  65.          }
  66.          return instance;
  67.       }
  68.       
  69.       public function get usePhasedInstantiation() : Boolean
  70.       {
  71.          return this._usePhasedInstantiation;
  72.       }
  73.       
  74.       public function set usePhasedInstantiation(param1:Boolean) : void
  75.       {
  76.          var _loc2_:Stage = null;
  77.          if(this._usePhasedInstantiation != param1)
  78.          {
  79.             this._usePhasedInstantiation = param1;
  80.             try
  81.             {
  82.                _loc2_ = this.systemManager.stage;
  83.                if(_loc2_)
  84.                {
  85.                   if(param1)
  86.                   {
  87.                      this.originalFrameRate = _loc2_.frameRate;
  88.                      _loc2_.frameRate = 1000;
  89.                   }
  90.                   else
  91.                   {
  92.                      _loc2_.frameRate = this.originalFrameRate;
  93.                   }
  94.                }
  95.             }
  96.             catch(e:SecurityError)
  97.             {
  98.             }
  99.          }
  100.       }
  101.       
  102.       public function invalidateProperties(param1:ILayoutManagerClient) : void
  103.       {
  104.          if(!this.invalidatePropertiesFlag && Boolean(this.systemManager))
  105.          {
  106.             this.invalidatePropertiesFlag = true;
  107.             if(!this.listenersAttached)
  108.             {
  109.                this.attachListeners(this.systemManager);
  110.             }
  111.          }
  112.          if(this.targetLevel <= param1.nestLevel)
  113.          {
  114.             this.invalidateClientPropertiesFlag = true;
  115.          }
  116.          this.invalidatePropertiesQueue.addObject(param1,param1.nestLevel);
  117.       }
  118.       
  119.       public function invalidateSize(param1:ILayoutManagerClient) : void
  120.       {
  121.          if(!this.invalidateSizeFlag && Boolean(this.systemManager))
  122.          {
  123.             this.invalidateSizeFlag = true;
  124.             if(!this.listenersAttached)
  125.             {
  126.                this.attachListeners(this.systemManager);
  127.             }
  128.          }
  129.          if(this.targetLevel <= param1.nestLevel)
  130.          {
  131.             this.invalidateClientSizeFlag = true;
  132.          }
  133.          this.invalidateSizeQueue.addObject(param1,param1.nestLevel);
  134.       }
  135.       
  136.       public function invalidateDisplayList(param1:ILayoutManagerClient) : void
  137.       {
  138.          if(!this.invalidateDisplayListFlag && Boolean(this.systemManager))
  139.          {
  140.             this.invalidateDisplayListFlag = true;
  141.             if(!this.listenersAttached)
  142.             {
  143.                this.attachListeners(this.systemManager);
  144.             }
  145.          }
  146.          else if(!this.invalidateDisplayListFlag && !this.systemManager)
  147.          {
  148.          }
  149.          this.invalidateDisplayListQueue.addObject(param1,param1.nestLevel);
  150.       }
  151.       
  152.       private function validateProperties() : void
  153.       {
  154.          var _loc1_:ILayoutManagerClient = ILayoutManagerClient(this.invalidatePropertiesQueue.removeSmallest());
  155.          while(_loc1_)
  156.          {
  157.             if(_loc1_.nestLevel)
  158.             {
  159.                this.currentObject = _loc1_;
  160.                _loc1_.validateProperties();
  161.                if(!_loc1_.updateCompletePendingFlag)
  162.                {
  163.                   this.updateCompleteQueue.addObject(_loc1_,_loc1_.nestLevel);
  164.                   _loc1_.updateCompletePendingFlag = true;
  165.                }
  166.             }
  167.             _loc1_ = ILayoutManagerClient(this.invalidatePropertiesQueue.removeSmallest());
  168.          }
  169.          if(this.invalidatePropertiesQueue.isEmpty())
  170.          {
  171.             this.invalidatePropertiesFlag = false;
  172.          }
  173.       }
  174.       
  175.       private function validateSize() : void
  176.       {
  177.          var _loc1_:ILayoutManagerClient = ILayoutManagerClient(this.invalidateSizeQueue.removeLargest());
  178.          while(_loc1_)
  179.          {
  180.             if(_loc1_.nestLevel)
  181.             {
  182.                this.currentObject = _loc1_;
  183.                _loc1_.validateSize();
  184.                if(!_loc1_.updateCompletePendingFlag)
  185.                {
  186.                   this.updateCompleteQueue.addObject(_loc1_,_loc1_.nestLevel);
  187.                   _loc1_.updateCompletePendingFlag = true;
  188.                }
  189.             }
  190.             _loc1_ = ILayoutManagerClient(this.invalidateSizeQueue.removeLargest());
  191.          }
  192.          if(this.invalidateSizeQueue.isEmpty())
  193.          {
  194.             this.invalidateSizeFlag = false;
  195.          }
  196.       }
  197.       
  198.       private function validateDisplayList() : void
  199.       {
  200.          var _loc1_:ILayoutManagerClient = ILayoutManagerClient(this.invalidateDisplayListQueue.removeSmallest());
  201.          while(_loc1_)
  202.          {
  203.             if(_loc1_.nestLevel)
  204.             {
  205.                this.currentObject = _loc1_;
  206.                _loc1_.validateDisplayList();
  207.                if(!_loc1_.updateCompletePendingFlag)
  208.                {
  209.                   this.updateCompleteQueue.addObject(_loc1_,_loc1_.nestLevel);
  210.                   _loc1_.updateCompletePendingFlag = true;
  211.                }
  212.             }
  213.             _loc1_ = ILayoutManagerClient(this.invalidateDisplayListQueue.removeSmallest());
  214.          }
  215.          if(this.invalidateDisplayListQueue.isEmpty())
  216.          {
  217.             this.invalidateDisplayListFlag = false;
  218.          }
  219.       }
  220.       
  221.       private function doPhasedInstantiation() : void
  222.       {
  223.          var _loc1_:ILayoutManagerClient = null;
  224.          if(this.usePhasedInstantiation)
  225.          {
  226.             if(this.invalidatePropertiesFlag)
  227.             {
  228.                this.validateProperties();
  229.                this.systemManager.document.dispatchEvent(new Event("validatePropertiesComplete"));
  230.             }
  231.             else if(this.invalidateSizeFlag)
  232.             {
  233.                this.validateSize();
  234.                this.systemManager.document.dispatchEvent(new Event("validateSizeComplete"));
  235.             }
  236.             else if(this.invalidateDisplayListFlag)
  237.             {
  238.                this.validateDisplayList();
  239.                this.systemManager.document.dispatchEvent(new Event("validateDisplayListComplete"));
  240.             }
  241.          }
  242.          else
  243.          {
  244.             if(this.invalidatePropertiesFlag)
  245.             {
  246.                this.validateProperties();
  247.             }
  248.             if(this.invalidateSizeFlag)
  249.             {
  250.                this.validateSize();
  251.             }
  252.             if(this.invalidateDisplayListFlag)
  253.             {
  254.                this.validateDisplayList();
  255.             }
  256.          }
  257.          if(this.invalidatePropertiesFlag || this.invalidateSizeFlag || this.invalidateDisplayListFlag)
  258.          {
  259.             this.attachListeners(this.systemManager);
  260.          }
  261.          else
  262.          {
  263.             this.usePhasedInstantiation = false;
  264.             this.listenersAttached = false;
  265.             _loc1_ = ILayoutManagerClient(this.updateCompleteQueue.removeLargest());
  266.             while(_loc1_)
  267.             {
  268.                if(!_loc1_.initialized && _loc1_.processedDescriptors)
  269.                {
  270.                   _loc1_.initialized = true;
  271.                }
  272.                if(_loc1_.hasEventListener(FlexEvent.UPDATE_COMPLETE))
  273.                {
  274.                   _loc1_.dispatchEvent(new FlexEvent(FlexEvent.UPDATE_COMPLETE));
  275.                }
  276.                _loc1_.updateCompletePendingFlag = false;
  277.                _loc1_ = ILayoutManagerClient(this.updateCompleteQueue.removeLargest());
  278.             }
  279.             dispatchEvent(new FlexEvent(FlexEvent.UPDATE_COMPLETE));
  280.          }
  281.       }
  282.       
  283.       public function validateNow() : void
  284.       {
  285.          var _loc1_:int = 0;
  286.          if(!this.usePhasedInstantiation)
  287.          {
  288.             _loc1_ = 0;
  289.             while(this.listenersAttached && _loc1_++ < 100)
  290.             {
  291.                this.doPhasedInstantiation();
  292.             }
  293.          }
  294.       }
  295.       
  296.       public function validateClient(param1:ILayoutManagerClient, param2:Boolean = false) : void
  297.       {
  298.          var _loc4_:ILayoutManagerClient = null;
  299.          var _loc3_:ILayoutManagerClient = this.currentObject;
  300.          var _loc5_:int = 0;
  301.          var _loc6_:Boolean = false;
  302.          var _loc7_:int = this.targetLevel;
  303.          if(this.targetLevel == int.MAX_VALUE)
  304.          {
  305.             this.targetLevel = param1.nestLevel;
  306.          }
  307.          while(!_loc6_)
  308.          {
  309.             _loc6_ = true;
  310.             _loc4_ = ILayoutManagerClient(this.invalidatePropertiesQueue.removeSmallestChild(param1));
  311.             while(_loc4_)
  312.             {
  313.                if(_loc4_.nestLevel)
  314.                {
  315.                   this.currentObject = _loc4_;
  316.                   _loc4_.validateProperties();
  317.                   if(!_loc4_.updateCompletePendingFlag)
  318.                   {
  319.                      this.updateCompleteQueue.addObject(_loc4_,_loc4_.nestLevel);
  320.                      _loc4_.updateCompletePendingFlag = true;
  321.                   }
  322.                }
  323.                _loc4_ = ILayoutManagerClient(this.invalidatePropertiesQueue.removeSmallestChild(param1));
  324.             }
  325.             if(this.invalidatePropertiesQueue.isEmpty())
  326.             {
  327.                this.invalidatePropertiesFlag = false;
  328.                this.invalidateClientPropertiesFlag = false;
  329.             }
  330.             _loc4_ = ILayoutManagerClient(this.invalidateSizeQueue.removeLargestChild(param1));
  331.             while(_loc4_)
  332.             {
  333.                if(_loc4_.nestLevel)
  334.                {
  335.                   this.currentObject = _loc4_;
  336.                   _loc4_.validateSize();
  337.                   if(!_loc4_.updateCompletePendingFlag)
  338.                   {
  339.                      this.updateCompleteQueue.addObject(_loc4_,_loc4_.nestLevel);
  340.                      _loc4_.updateCompletePendingFlag = true;
  341.                   }
  342.                }
  343.                if(this.invalidateClientPropertiesFlag)
  344.                {
  345.                   _loc4_ = ILayoutManagerClient(this.invalidatePropertiesQueue.removeSmallestChild(param1));
  346.                   if(_loc4_)
  347.                   {
  348.                      this.invalidatePropertiesQueue.addObject(_loc4_,_loc4_.nestLevel);
  349.                      _loc6_ = false;
  350.                      break;
  351.                   }
  352.                }
  353.                _loc4_ = ILayoutManagerClient(this.invalidateSizeQueue.removeLargestChild(param1));
  354.             }
  355.             if(this.invalidateSizeQueue.isEmpty())
  356.             {
  357.                this.invalidateSizeFlag = false;
  358.                this.invalidateClientSizeFlag = false;
  359.             }
  360.             if(!param2)
  361.             {
  362.                _loc4_ = ILayoutManagerClient(this.invalidateDisplayListQueue.removeSmallestChild(param1));
  363.                while(_loc4_)
  364.                {
  365.                   if(_loc4_.nestLevel)
  366.                   {
  367.                      this.currentObject = _loc4_;
  368.                      _loc4_.validateDisplayList();
  369.                      if(!_loc4_.updateCompletePendingFlag)
  370.                      {
  371.                         this.updateCompleteQueue.addObject(_loc4_,_loc4_.nestLevel);
  372.                         _loc4_.updateCompletePendingFlag = true;
  373.                      }
  374.                   }
  375.                   if(this.invalidateClientPropertiesFlag)
  376.                   {
  377.                      _loc4_ = ILayoutManagerClient(this.invalidatePropertiesQueue.removeSmallestChild(param1));
  378.                      if(_loc4_)
  379.                      {
  380.                         this.invalidatePropertiesQueue.addObject(_loc4_,_loc4_.nestLevel);
  381.                         _loc6_ = false;
  382.                         break;
  383.                      }
  384.                   }
  385.                   if(this.invalidateClientSizeFlag)
  386.                   {
  387.                      _loc4_ = ILayoutManagerClient(this.invalidateSizeQueue.removeLargestChild(param1));
  388.                      if(_loc4_)
  389.                      {
  390.                         this.invalidateSizeQueue.addObject(_loc4_,_loc4_.nestLevel);
  391.                         _loc6_ = false;
  392.                         break;
  393.                      }
  394.                   }
  395.                   _loc4_ = ILayoutManagerClient(this.invalidateDisplayListQueue.removeSmallestChild(param1));
  396.                }
  397.                if(this.invalidateDisplayListQueue.isEmpty())
  398.                {
  399.                   this.invalidateDisplayListFlag = false;
  400.                }
  401.             }
  402.          }
  403.          if(_loc7_ == int.MAX_VALUE)
  404.          {
  405.             this.targetLevel = int.MAX_VALUE;
  406.             if(!param2)
  407.             {
  408.                _loc4_ = ILayoutManagerClient(this.updateCompleteQueue.removeLargestChild(param1));
  409.                while(_loc4_)
  410.                {
  411.                   if(!_loc4_.initialized)
  412.                   {
  413.                      _loc4_.initialized = true;
  414.                   }
  415.                   if(_loc4_.hasEventListener(FlexEvent.UPDATE_COMPLETE))
  416.                   {
  417.                      _loc4_.dispatchEvent(new FlexEvent(FlexEvent.UPDATE_COMPLETE));
  418.                   }
  419.                   _loc4_.updateCompletePendingFlag = false;
  420.                   _loc4_ = ILayoutManagerClient(this.updateCompleteQueue.removeLargestChild(param1));
  421.                }
  422.             }
  423.          }
  424.          this.currentObject = _loc3_;
  425.       }
  426.       
  427.       public function isInvalid() : Boolean
  428.       {
  429.          return this.invalidatePropertiesFlag || this.invalidateSizeFlag || this.invalidateDisplayListFlag;
  430.       }
  431.       
  432.       private function waitAFrame(param1:Event) : void
  433.       {
  434.          this.systemManager.removeEventListener(Event.ENTER_FRAME,this.waitAFrame);
  435.          this.systemManager.addEventListener(Event.ENTER_FRAME,this.doPhasedInstantiationCallback);
  436.          this.waitedAFrame = true;
  437.       }
  438.       
  439.       public function attachListeners(param1:ISystemManager) : void
  440.       {
  441.          if(!this.waitedAFrame)
  442.          {
  443.             param1.addEventListener(Event.ENTER_FRAME,this.waitAFrame);
  444.          }
  445.          else
  446.          {
  447.             param1.addEventListener(Event.ENTER_FRAME,this.doPhasedInstantiationCallback);
  448.             if(!this.usePhasedInstantiation)
  449.             {
  450.                if(Boolean(param1) && (param1.stage || this.usingBridge(param1)))
  451.                {
  452.                   param1.addEventListener(Event.RENDER,this.doPhasedInstantiationCallback);
  453.                   if(param1.stage)
  454.                   {
  455.                      param1.stage.invalidate();
  456.                   }
  457.                }
  458.             }
  459.          }
  460.          this.listenersAttached = true;
  461.       }
  462.       
  463.       private function doPhasedInstantiationCallback(param1:Event) : void
  464.       {
  465.          var callLaterErrorEvent:DynamicEvent = null;
  466.          var event:Event = param1;
  467.          if(UIComponentGlobals.mx_internal::callLaterSuspendCount > 0)
  468.          {
  469.             return;
  470.          }
  471.          this.systemManager.removeEventListener(Event.ENTER_FRAME,this.doPhasedInstantiationCallback);
  472.          this.systemManager.removeEventListener(Event.RENDER,this.doPhasedInstantiationCallback);
  473.          if(!UIComponentGlobals.catchCallLaterExceptions)
  474.          {
  475.             this.doPhasedInstantiation();
  476.          }
  477.          else
  478.          {
  479.             try
  480.             {
  481.                this.doPhasedInstantiation();
  482.             }
  483.             catch(e:Error)
  484.             {
  485.                callLaterErrorEvent = new DynamicEvent("callLaterError");
  486.                callLaterErrorEvent.error = e;
  487.                callLaterErrorEvent.source = this;
  488.                callLaterErrorEvent.object = currentObject;
  489.                systemManager.dispatchEvent(callLaterErrorEvent);
  490.             }
  491.          }
  492.          this.currentObject = null;
  493.       }
  494.       
  495.       private function usingBridge(param1:ISystemManager) : Boolean
  496.       {
  497.          if(this._usingBridge == 0)
  498.          {
  499.             return false;
  500.          }
  501.          if(this._usingBridge == 1)
  502.          {
  503.             return true;
  504.          }
  505.          if(!param1)
  506.          {
  507.             return false;
  508.          }
  509.          var _loc2_:Object = param1.getImplementation("mx.managers::IMarshalSystemManager");
  510.          if(!_loc2_)
  511.          {
  512.             this._usingBridge = 0;
  513.             return false;
  514.          }
  515.          if(_loc2_.useSWFBridge())
  516.          {
  517.             this._usingBridge = 1;
  518.             return true;
  519.          }
  520.          this._usingBridge = 0;
  521.          return false;
  522.       }
  523.    }
  524. }
  525.  
  526.