home *** CD-ROM | disk | FTP | other *** search
/ Computer Active 2010 August / CA08.iso / Multimedija / shufflr.air / ShufflrClient.swf / scripts / mx / managers / FocusManager.as < prev    next >
Encoding:
Text File  |  2010-06-23  |  51.9 KB  |  1,537 lines

  1. package mx.managers
  2. {
  3.    import flash.display.DisplayObject;
  4.    import flash.display.DisplayObjectContainer;
  5.    import flash.display.InteractiveObject;
  6.    import flash.display.Sprite;
  7.    import flash.events.Event;
  8.    import flash.events.FocusEvent;
  9.    import flash.events.IEventDispatcher;
  10.    import flash.events.KeyboardEvent;
  11.    import flash.events.MouseEvent;
  12.    import flash.system.Capabilities;
  13.    import flash.text.TextField;
  14.    import flash.ui.Keyboard;
  15.    import mx.core.FlexSprite;
  16.    import mx.core.IButton;
  17.    import mx.core.IChildList;
  18.    import mx.core.IRawChildrenContainer;
  19.    import mx.core.ISWFBridgeProvider;
  20.    import mx.core.ISWFLoader;
  21.    import mx.core.IToggleButton;
  22.    import mx.core.IUIComponent;
  23.    import mx.core.SWFBridgeGroup;
  24.    import mx.core.mx_internal;
  25.    import mx.events.FlexEvent;
  26.    import mx.events.FocusRequestDirection;
  27.    import mx.events.SWFBridgeEvent;
  28.    import mx.events.SWFBridgeRequest;
  29.    
  30.    use namespace mx_internal;
  31.    
  32.    public class FocusManager implements IFocusManager
  33.    {
  34.       mx_internal static const VERSION:String = "3.5.0.12683";
  35.       
  36.       private static const FROM_INDEX_UNSPECIFIED:int = -2;
  37.       
  38.       private var lastActiveFocusManager:FocusManager;
  39.       
  40.       private var _showFocusIndicator:Boolean = false;
  41.       
  42.       private var focusableCandidates:Array;
  43.       
  44.       private var LARGE_TAB_INDEX:int = 99999;
  45.       
  46.       private var browserFocusComponent:InteractiveObject;
  47.       
  48.       private var calculateCandidates:Boolean = true;
  49.       
  50.       private var _lastFocus:IFocusManagerComponent;
  51.       
  52.       private var lastAction:String;
  53.       
  54.       private var focusSetLocally:Boolean;
  55.       
  56.       private var focusableObjects:Array;
  57.       
  58.       private var swfBridgeGroup:SWFBridgeGroup;
  59.       
  60.       private var defButton:IButton;
  61.       
  62.       private var _form:IFocusManagerContainer;
  63.       
  64.       private var popup:Boolean;
  65.       
  66.       private var focusChanged:Boolean;
  67.       
  68.       private var _defaultButtonEnabled:Boolean = true;
  69.       
  70.       private var activated:Boolean = false;
  71.       
  72.       private var _defaultButton:IButton;
  73.       
  74.       private var fauxFocus:DisplayObject;
  75.       
  76.       private var _focusPane:Sprite;
  77.       
  78.       private var skipBridge:IEventDispatcher;
  79.       
  80.       public var browserMode:Boolean;
  81.       
  82.       public function FocusManager(param1:IFocusManagerContainer, param2:Boolean = false)
  83.       {
  84.          var sm:ISystemManager = null;
  85.          var bridge:IEventDispatcher = null;
  86.          var container:IFocusManagerContainer = param1;
  87.          var popup:Boolean = param2;
  88.          super();
  89.          this.popup = popup;
  90.          browserMode = Capabilities.playerType == "ActiveX" && !popup;
  91.          container.focusManager = this;
  92.          _form = container;
  93.          focusableObjects = [];
  94.          focusPane = new FlexSprite();
  95.          focusPane.name = "focusPane";
  96.          addFocusables(DisplayObject(container));
  97.          container.addEventListener(Event.ADDED,addedHandler);
  98.          container.addEventListener(Event.REMOVED,removedHandler);
  99.          container.addEventListener(FlexEvent.SHOW,showHandler);
  100.          container.addEventListener(FlexEvent.HIDE,hideHandler);
  101.          if(container.systemManager is SystemManager)
  102.          {
  103.             if(container != SystemManager(container.systemManager).application)
  104.             {
  105.                container.addEventListener(FlexEvent.CREATION_COMPLETE,creationCompleteHandler);
  106.             }
  107.          }
  108.          try
  109.          {
  110.             container.systemManager.addFocusManager(container);
  111.             sm = mx_internal::form.systemManager;
  112.             swfBridgeGroup = new SWFBridgeGroup(sm);
  113.             if(!popup)
  114.             {
  115.                swfBridgeGroup.parentBridge = sm.swfBridgeGroup.parentBridge;
  116.             }
  117.             if(sm.useSWFBridge())
  118.             {
  119.                sm.addEventListener(SWFBridgeEvent.BRIDGE_APPLICATION_UNLOADING,removeFromParentBridge);
  120.                bridge = swfBridgeGroup.parentBridge;
  121.                if(bridge)
  122.                {
  123.                   bridge.addEventListener(SWFBridgeRequest.MOVE_FOCUS_REQUEST,focusRequestMoveHandler);
  124.                   bridge.addEventListener(SWFBridgeRequest.SET_SHOW_FOCUS_INDICATOR_REQUEST,setShowFocusIndicatorRequestHandler);
  125.                }
  126.                if(Boolean(bridge) && !(mx_internal::form.systemManager is SystemManagerProxy))
  127.                {
  128.                   bridge.addEventListener(SWFBridgeRequest.ACTIVATE_FOCUS_REQUEST,focusRequestActivateHandler);
  129.                   bridge.addEventListener(SWFBridgeRequest.DEACTIVATE_FOCUS_REQUEST,focusRequestDeactivateHandler);
  130.                   bridge.addEventListener(SWFBridgeEvent.BRIDGE_FOCUS_MANAGER_ACTIVATE,bridgeEventActivateHandler);
  131.                }
  132.                container.addEventListener(Event.ADDED_TO_STAGE,addedToStageHandler);
  133.             }
  134.          }
  135.          catch(e:Error)
  136.          {
  137.          }
  138.       }
  139.       
  140.       private function dispatchSetShowFocusIndicatorRequest(param1:Boolean, param2:IEventDispatcher) : void
  141.       {
  142.          var _loc3_:SWFBridgeRequest = new SWFBridgeRequest(SWFBridgeRequest.SET_SHOW_FOCUS_INDICATOR_REQUEST,false,false,null,param1);
  143.          dispatchEventFromSWFBridges(_loc3_,param2);
  144.       }
  145.       
  146.       private function creationCompleteHandler(param1:FlexEvent) : void
  147.       {
  148.          var _loc2_:DisplayObject = DisplayObject(mx_internal::form);
  149.          if(_loc2_.parent && _loc2_.visible && !activated)
  150.          {
  151.             mx_internal::form.systemManager.activate(mx_internal::form);
  152.          }
  153.       }
  154.       
  155.       private function addFocusables(param1:DisplayObject, param2:Boolean = false) : void
  156.       {
  157.          var addToFocusables:Boolean = false;
  158.          var focusable:IFocusManagerComponent = null;
  159.          var doc:DisplayObjectContainer = null;
  160.          var rawChildren:IChildList = null;
  161.          var i:int = 0;
  162.          var o:DisplayObject = param1;
  163.          var skipTopLevel:Boolean = param2;
  164.          if(o is IFocusManagerComponent && !skipTopLevel)
  165.          {
  166.             addToFocusables = false;
  167.             if(o is IFocusManagerComponent)
  168.             {
  169.                focusable = IFocusManagerComponent(o);
  170.                if(focusable.focusEnabled)
  171.                {
  172.                   if(Boolean(focusable.tabEnabled) && isTabVisible(o))
  173.                   {
  174.                      addToFocusables = true;
  175.                   }
  176.                }
  177.             }
  178.             if(addToFocusables)
  179.             {
  180.                if(focusableObjects.indexOf(o) == -1)
  181.                {
  182.                   focusableObjects.push(o);
  183.                   calculateCandidates = true;
  184.                }
  185.                o.addEventListener("tabEnabledChange",tabEnabledChangeHandler);
  186.                o.addEventListener("tabIndexChange",tabIndexChangeHandler);
  187.             }
  188.          }
  189.          if(o is DisplayObjectContainer)
  190.          {
  191.             doc = DisplayObjectContainer(o);
  192.             o.addEventListener("tabChildrenChange",tabChildrenChangeHandler);
  193.             if(doc.tabChildren)
  194.             {
  195.                if(o is IRawChildrenContainer)
  196.                {
  197.                   rawChildren = IRawChildrenContainer(o).rawChildren;
  198.                   i = 0;
  199.                   while(i < rawChildren.numChildren)
  200.                   {
  201.                      try
  202.                      {
  203.                         addFocusables(rawChildren.getChildAt(i));
  204.                      }
  205.                      catch(error:SecurityError)
  206.                      {
  207.                      }
  208.                      i++;
  209.                   }
  210.                }
  211.                else
  212.                {
  213.                   i = 0;
  214.                   while(i < doc.numChildren)
  215.                   {
  216.                      try
  217.                      {
  218.                         addFocusables(doc.getChildAt(i));
  219.                      }
  220.                      catch(error:SecurityError)
  221.                      {
  222.                      }
  223.                      i++;
  224.                   }
  225.                }
  226.             }
  227.          }
  228.       }
  229.       
  230.       private function tabEnabledChangeHandler(param1:Event) : void
  231.       {
  232.          calculateCandidates = true;
  233.          var _loc2_:InteractiveObject = InteractiveObject(param1.target);
  234.          var _loc3_:int = int(focusableObjects.length);
  235.          var _loc4_:int = 0;
  236.          while(_loc4_ < _loc3_)
  237.          {
  238.             if(focusableObjects[_loc4_] == _loc2_)
  239.             {
  240.                break;
  241.             }
  242.             _loc4_++;
  243.          }
  244.          if(_loc2_.tabEnabled)
  245.          {
  246.             if(_loc4_ == _loc3_ && isTabVisible(_loc2_))
  247.             {
  248.                if(focusableObjects.indexOf(_loc2_) == -1)
  249.                {
  250.                   focusableObjects.push(_loc2_);
  251.                }
  252.             }
  253.          }
  254.          else if(_loc4_ < _loc3_)
  255.          {
  256.             focusableObjects.splice(_loc4_,1);
  257.          }
  258.       }
  259.       
  260.       private function mouseFocusChangeHandler(param1:FocusEvent) : void
  261.       {
  262.          var _loc2_:TextField = null;
  263.          if(param1.relatedObject == null && "isRelatedObjectInaccessible" in param1 && param1["isRelatedObjectInaccessible"] == true)
  264.          {
  265.             return;
  266.          }
  267.          if(param1.relatedObject is TextField)
  268.          {
  269.             _loc2_ = param1.relatedObject as TextField;
  270.             if(_loc2_.type == "input" || _loc2_.selectable)
  271.             {
  272.                return;
  273.             }
  274.          }
  275.          param1.preventDefault();
  276.       }
  277.       
  278.       public function addSWFBridge(param1:IEventDispatcher, param2:DisplayObject) : void
  279.       {
  280.          if(!param2)
  281.          {
  282.             return;
  283.          }
  284.          var _loc3_:ISystemManager = _form.systemManager;
  285.          if(focusableObjects.indexOf(param2) == -1)
  286.          {
  287.             focusableObjects.push(param2);
  288.             calculateCandidates = true;
  289.          }
  290.          swfBridgeGroup.addChildBridge(param1,ISWFBridgeProvider(param2));
  291.          param1.addEventListener(SWFBridgeRequest.MOVE_FOCUS_REQUEST,focusRequestMoveHandler);
  292.          param1.addEventListener(SWFBridgeRequest.SET_SHOW_FOCUS_INDICATOR_REQUEST,setShowFocusIndicatorRequestHandler);
  293.          param1.addEventListener(SWFBridgeEvent.BRIDGE_FOCUS_MANAGER_ACTIVATE,bridgeEventActivateHandler);
  294.       }
  295.       
  296.       private function getChildIndex(param1:DisplayObjectContainer, param2:DisplayObject) : int
  297.       {
  298.          var parent:DisplayObjectContainer = param1;
  299.          var child:DisplayObject = param2;
  300.          try
  301.          {
  302.             return parent.getChildIndex(child);
  303.          }
  304.          catch(e:Error)
  305.          {
  306.             if(parent is IRawChildrenContainer)
  307.             {
  308.                return IRawChildrenContainer(parent).rawChildren.getChildIndex(child);
  309.             }
  310.             throw e;
  311.          }
  312.       }
  313.       
  314.       private function bridgeEventActivateHandler(param1:Event) : void
  315.       {
  316.          if(param1 is SWFBridgeEvent)
  317.          {
  318.             return;
  319.          }
  320.          lastActiveFocusManager = null;
  321.          _lastFocus = null;
  322.          dispatchActivatedFocusManagerEvent(IEventDispatcher(param1.target));
  323.       }
  324.       
  325.       private function focusOutHandler(param1:FocusEvent) : void
  326.       {
  327.          var _loc2_:InteractiveObject = InteractiveObject(param1.target);
  328.       }
  329.       
  330.       private function isValidFocusCandidate(param1:DisplayObject, param2:String) : Boolean
  331.       {
  332.          var _loc3_:IFocusManagerGroup = null;
  333.          if(!isEnabledAndVisible(param1))
  334.          {
  335.             return false;
  336.          }
  337.          if(param1 is IFocusManagerGroup)
  338.          {
  339.             _loc3_ = IFocusManagerGroup(param1);
  340.             if(param2 == _loc3_.groupName)
  341.             {
  342.                return false;
  343.             }
  344.          }
  345.          return true;
  346.       }
  347.       
  348.       private function defaultButtonKeyHandler(param1:KeyboardEvent) : void
  349.       {
  350.          var _loc2_:ISystemManager = mx_internal::form.systemManager;
  351.          if(_loc2_.isDisplayObjectInABridgedApplication(DisplayObject(param1.target)))
  352.          {
  353.             return;
  354.          }
  355.          if(defaultButtonEnabled && param1.keyCode == Keyboard.ENTER && defaultButton && Boolean(defButton.enabled))
  356.          {
  357.             mx_internal::sendDefaultButtonEvent();
  358.          }
  359.       }
  360.       
  361.       private function removeFocusables(param1:DisplayObject, param2:Boolean) : void
  362.       {
  363.          var _loc3_:int = 0;
  364.          if(param1 is DisplayObjectContainer)
  365.          {
  366.             if(!param2)
  367.             {
  368.                param1.removeEventListener("tabChildrenChange",tabChildrenChangeHandler);
  369.             }
  370.             _loc3_ = 0;
  371.             while(_loc3_ < focusableObjects.length)
  372.             {
  373.                if(isParent(DisplayObjectContainer(param1),focusableObjects[_loc3_]))
  374.                {
  375.                   if(focusableObjects[_loc3_] == _lastFocus)
  376.                   {
  377.                      _lastFocus.drawFocus(false);
  378.                      _lastFocus = null;
  379.                   }
  380.                   focusableObjects[_loc3_].removeEventListener("tabEnabledChange",tabEnabledChangeHandler);
  381.                   focusableObjects[_loc3_].removeEventListener("tabIndexChange",tabIndexChangeHandler);
  382.                   focusableObjects.splice(_loc3_,1);
  383.                   _loc3_--;
  384.                   focusableCandidates = [];
  385.                   calculateCandidates = true;
  386.                }
  387.                _loc3_++;
  388.             }
  389.          }
  390.       }
  391.       
  392.       private function addedHandler(param1:Event) : void
  393.       {
  394.          var _loc2_:DisplayObject = DisplayObject(param1.target);
  395.          if(_loc2_.stage)
  396.          {
  397.             addFocusables(DisplayObject(param1.target));
  398.          }
  399.       }
  400.       
  401.       private function tabChildrenChangeHandler(param1:Event) : void
  402.       {
  403.          if(param1.target != param1.currentTarget)
  404.          {
  405.             return;
  406.          }
  407.          calculateCandidates = true;
  408.          var _loc2_:DisplayObjectContainer = DisplayObjectContainer(param1.target);
  409.          if(_loc2_.tabChildren)
  410.          {
  411.             addFocusables(_loc2_,true);
  412.          }
  413.          else
  414.          {
  415.             removeFocusables(_loc2_,true);
  416.          }
  417.       }
  418.       
  419.       private function sortByDepth(param1:DisplayObject, param2:DisplayObject) : Number
  420.       {
  421.          var _loc5_:int = 0;
  422.          var _loc6_:String = null;
  423.          var _loc7_:String = null;
  424.          var _loc3_:String = "";
  425.          var _loc4_:String = "";
  426.          var _loc8_:String = "0000";
  427.          var _loc9_:DisplayObject = DisplayObject(param1);
  428.          var _loc10_:DisplayObject = DisplayObject(param2);
  429.          while(_loc9_ != DisplayObject(mx_internal::form) && Boolean(_loc9_.parent))
  430.          {
  431.             _loc5_ = getChildIndex(_loc9_.parent,_loc9_);
  432.             _loc6_ = _loc5_.toString(16);
  433.             if(_loc6_.length < 4)
  434.             {
  435.                _loc7_ = _loc8_.substring(0,4 - _loc6_.length) + _loc6_;
  436.             }
  437.             _loc3_ = _loc7_ + _loc3_;
  438.             _loc9_ = _loc9_.parent;
  439.          }
  440.          while(_loc10_ != DisplayObject(mx_internal::form) && Boolean(_loc10_.parent))
  441.          {
  442.             _loc5_ = getChildIndex(_loc10_.parent,_loc10_);
  443.             _loc6_ = _loc5_.toString(16);
  444.             if(_loc6_.length < 4)
  445.             {
  446.                _loc7_ = _loc8_.substring(0,4 - _loc6_.length) + _loc6_;
  447.             }
  448.             _loc4_ = _loc7_ + _loc4_;
  449.             _loc10_ = _loc10_.parent;
  450.          }
  451.          return _loc3_ > _loc4_ ? 1 : (_loc3_ < _loc4_ ? -1 : 0);
  452.       }
  453.       
  454.       mx_internal function sendDefaultButtonEvent() : void
  455.       {
  456.          defButton.dispatchEvent(new MouseEvent("click"));
  457.       }
  458.       
  459.       public function getFocus() : IFocusManagerComponent
  460.       {
  461.          var _loc1_:InteractiveObject = mx_internal::form.systemManager.stage.focus;
  462.          return findFocusManagerComponent(_loc1_);
  463.       }
  464.       
  465.       private function deactivateHandler(param1:Event) : void
  466.       {
  467.       }
  468.       
  469.       private function setFocusToBottom() : void
  470.       {
  471.          setFocusToNextIndex(focusableObjects.length,true);
  472.       }
  473.       
  474.       private function tabIndexChangeHandler(param1:Event) : void
  475.       {
  476.          calculateCandidates = true;
  477.       }
  478.       
  479.       private function sortFocusableObjects() : void
  480.       {
  481.          var _loc3_:InteractiveObject = null;
  482.          focusableCandidates = [];
  483.          var _loc1_:int = int(focusableObjects.length);
  484.          var _loc2_:int = 0;
  485.          while(_loc2_ < _loc1_)
  486.          {
  487.             _loc3_ = focusableObjects[_loc2_];
  488.             if(_loc3_.tabIndex && !isNaN(Number(_loc3_.tabIndex)) && _loc3_.tabIndex > 0)
  489.             {
  490.                sortFocusableObjectsTabIndex();
  491.                return;
  492.             }
  493.             focusableCandidates.push(_loc3_);
  494.             _loc2_++;
  495.          }
  496.          focusableCandidates.sort(sortByDepth);
  497.       }
  498.       
  499.       private function keyFocusChangeHandler(param1:FocusEvent) : void
  500.       {
  501.          var _loc2_:ISystemManager = mx_internal::form.systemManager;
  502.          if(_loc2_.isDisplayObjectInABridgedApplication(DisplayObject(param1.target)))
  503.          {
  504.             return;
  505.          }
  506.          showFocusIndicator = true;
  507.          focusChanged = false;
  508.          if(param1.keyCode == Keyboard.TAB && !param1.isDefaultPrevented())
  509.          {
  510.             if(browserFocusComponent)
  511.             {
  512.                if(browserFocusComponent.tabIndex == LARGE_TAB_INDEX)
  513.                {
  514.                   browserFocusComponent.tabIndex = -1;
  515.                }
  516.                browserFocusComponent = null;
  517.                if(SystemManager(mx_internal::form.systemManager).useSWFBridge())
  518.                {
  519.                   moveFocusToParent(param1.shiftKey);
  520.                   if(focusChanged)
  521.                   {
  522.                      param1.preventDefault();
  523.                   }
  524.                }
  525.                return;
  526.             }
  527.             setFocusToNextObject(param1);
  528.             if(focusChanged)
  529.             {
  530.                param1.preventDefault();
  531.             }
  532.          }
  533.       }
  534.       
  535.       private function getNextFocusManagerComponent2(param1:Boolean = false, param2:DisplayObject = null, param3:int = -2) : FocusInfo
  536.       {
  537.          var _loc10_:DisplayObject = null;
  538.          var _loc11_:String = null;
  539.          var _loc12_:IFocusManagerGroup = null;
  540.          if(focusableObjects.length == 0)
  541.          {
  542.             return null;
  543.          }
  544.          if(calculateCandidates)
  545.          {
  546.             sortFocusableObjects();
  547.             calculateCandidates = false;
  548.          }
  549.          var _loc4_:int = param3;
  550.          if(param3 == FROM_INDEX_UNSPECIFIED)
  551.          {
  552.             _loc10_ = param2;
  553.             if(!_loc10_)
  554.             {
  555.                _loc10_ = mx_internal::form.systemManager.stage.focus;
  556.             }
  557.             _loc10_ = DisplayObject(findFocusManagerComponent2(InteractiveObject(_loc10_)));
  558.             _loc11_ = "";
  559.             if(_loc10_ is IFocusManagerGroup)
  560.             {
  561.                _loc12_ = IFocusManagerGroup(_loc10_);
  562.                _loc11_ = _loc12_.groupName;
  563.             }
  564.             _loc4_ = getIndexOfFocusedObject(_loc10_);
  565.          }
  566.          var _loc5_:Boolean = false;
  567.          var _loc6_:int = _loc4_;
  568.          if(_loc4_ == -1)
  569.          {
  570.             if(param1)
  571.             {
  572.                _loc4_ = int(focusableCandidates.length);
  573.             }
  574.             _loc5_ = true;
  575.          }
  576.          var _loc7_:int = getIndexOfNextObject(_loc4_,param1,_loc5_,_loc11_);
  577.          var _loc8_:Boolean = false;
  578.          if(param1)
  579.          {
  580.             if(_loc7_ >= _loc4_)
  581.             {
  582.                _loc8_ = true;
  583.             }
  584.          }
  585.          else if(_loc7_ <= _loc4_)
  586.          {
  587.             _loc8_ = true;
  588.          }
  589.          var _loc9_:FocusInfo = new FocusInfo();
  590.          _loc9_.displayObject = findFocusManagerComponent2(focusableCandidates[_loc7_]);
  591.          _loc9_.wrapped = _loc8_;
  592.          return _loc9_;
  593.       }
  594.       
  595.       private function getIndexOfFocusedObject(param1:DisplayObject) : int
  596.       {
  597.          var _loc4_:IUIComponent = null;
  598.          if(!param1)
  599.          {
  600.             return -1;
  601.          }
  602.          var _loc2_:int = int(focusableCandidates.length);
  603.          var _loc3_:int = 0;
  604.          _loc3_ = 0;
  605.          while(_loc3_ < _loc2_)
  606.          {
  607.             if(focusableCandidates[_loc3_] == param1)
  608.             {
  609.                return _loc3_;
  610.             }
  611.             _loc3_++;
  612.          }
  613.          _loc3_ = 0;
  614.          while(_loc3_ < _loc2_)
  615.          {
  616.             _loc4_ = focusableCandidates[_loc3_] as IUIComponent;
  617.             if((Boolean(_loc4_)) && Boolean(_loc4_.owns(param1)))
  618.             {
  619.                return _loc3_;
  620.             }
  621.             _loc3_++;
  622.          }
  623.          return -1;
  624.       }
  625.       
  626.       private function focusRequestActivateHandler(param1:Event) : void
  627.       {
  628.          skipBridge = IEventDispatcher(param1.target);
  629.          activate();
  630.          skipBridge = null;
  631.       }
  632.       
  633.       private function removeFromParentBridge(param1:Event) : void
  634.       {
  635.          var _loc3_:IEventDispatcher = null;
  636.          var _loc2_:ISystemManager = mx_internal::form.systemManager;
  637.          if(_loc2_.useSWFBridge())
  638.          {
  639.             _loc2_.removeEventListener(SWFBridgeEvent.BRIDGE_APPLICATION_UNLOADING,removeFromParentBridge);
  640.             _loc3_ = swfBridgeGroup.parentBridge;
  641.             if(_loc3_)
  642.             {
  643.                _loc3_.removeEventListener(SWFBridgeRequest.MOVE_FOCUS_REQUEST,focusRequestMoveHandler);
  644.                _loc3_.removeEventListener(SWFBridgeRequest.SET_SHOW_FOCUS_INDICATOR_REQUEST,setShowFocusIndicatorRequestHandler);
  645.             }
  646.             if(Boolean(_loc3_) && !(mx_internal::form.systemManager is SystemManagerProxy))
  647.             {
  648.                _loc3_.removeEventListener(SWFBridgeRequest.ACTIVATE_FOCUS_REQUEST,focusRequestActivateHandler);
  649.                _loc3_.removeEventListener(SWFBridgeRequest.DEACTIVATE_FOCUS_REQUEST,focusRequestDeactivateHandler);
  650.                _loc3_.removeEventListener(SWFBridgeEvent.BRIDGE_FOCUS_MANAGER_ACTIVATE,bridgeEventActivateHandler);
  651.             }
  652.          }
  653.       }
  654.       
  655.       private function getParentBridge() : IEventDispatcher
  656.       {
  657.          if(swfBridgeGroup)
  658.          {
  659.             return swfBridgeGroup.parentBridge;
  660.          }
  661.          return null;
  662.       }
  663.       
  664.       private function setFocusToComponent(param1:Object, param2:Boolean) : void
  665.       {
  666.          var _loc3_:SWFBridgeRequest = null;
  667.          var _loc4_:IEventDispatcher = null;
  668.          focusChanged = false;
  669.          if(param1)
  670.          {
  671.             if(param1 is ISWFLoader && Boolean(ISWFLoader(param1).swfBridge))
  672.             {
  673.                _loc3_ = new SWFBridgeRequest(SWFBridgeRequest.MOVE_FOCUS_REQUEST,false,true,null,param2 ? FocusRequestDirection.BOTTOM : FocusRequestDirection.TOP);
  674.                _loc4_ = ISWFLoader(param1).swfBridge;
  675.                if(_loc4_)
  676.                {
  677.                   _loc4_.dispatchEvent(_loc3_);
  678.                   focusChanged = _loc3_.data;
  679.                }
  680.             }
  681.             else if(param1 is IFocusManagerComplexComponent)
  682.             {
  683.                IFocusManagerComplexComponent(param1).assignFocus(param2 ? "bottom" : "top");
  684.                focusChanged = true;
  685.             }
  686.             else if(param1 is IFocusManagerComponent)
  687.             {
  688.                setFocus(IFocusManagerComponent(param1));
  689.                focusChanged = true;
  690.             }
  691.          }
  692.       }
  693.       
  694.       private function focusRequestMoveHandler(param1:Event) : void
  695.       {
  696.          var _loc3_:DisplayObject = null;
  697.          if(param1 is SWFBridgeRequest)
  698.          {
  699.             return;
  700.          }
  701.          focusSetLocally = false;
  702.          var _loc2_:SWFBridgeRequest = SWFBridgeRequest.marshal(param1);
  703.          if(_loc2_.data == FocusRequestDirection.TOP || _loc2_.data == FocusRequestDirection.BOTTOM)
  704.          {
  705.             if(focusableObjects.length == 0)
  706.             {
  707.                moveFocusToParent(_loc2_.data == FocusRequestDirection.TOP ? false : true);
  708.                param1["data"] = focusChanged;
  709.                return;
  710.             }
  711.             if(_loc2_.data == FocusRequestDirection.TOP)
  712.             {
  713.                setFocusToTop();
  714.             }
  715.             else
  716.             {
  717.                setFocusToBottom();
  718.             }
  719.             param1["data"] = focusChanged;
  720.          }
  721.          else
  722.          {
  723.             _loc3_ = DisplayObject(_form.systemManager.swfBridgeGroup.getChildBridgeProvider(IEventDispatcher(param1.target)));
  724.             moveFocus(_loc2_.data as String,_loc3_);
  725.             param1["data"] = focusChanged;
  726.          }
  727.          if(focusSetLocally)
  728.          {
  729.             dispatchActivatedFocusManagerEvent(null);
  730.             lastActiveFocusManager = this;
  731.          }
  732.       }
  733.       
  734.       public function get nextTabIndex() : int
  735.       {
  736.          return getMaxTabIndex() + 1;
  737.       }
  738.       
  739.       private function dispatchActivatedFocusManagerEvent(param1:IEventDispatcher = null) : void
  740.       {
  741.          if(lastActiveFocusManager == this)
  742.          {
  743.             return;
  744.          }
  745.          var _loc2_:SWFBridgeEvent = new SWFBridgeEvent(SWFBridgeEvent.BRIDGE_FOCUS_MANAGER_ACTIVATE);
  746.          dispatchEventFromSWFBridges(_loc2_,param1);
  747.       }
  748.       
  749.       private function focusRequestDeactivateHandler(param1:Event) : void
  750.       {
  751.          skipBridge = IEventDispatcher(param1.target);
  752.          deactivate();
  753.          skipBridge = null;
  754.       }
  755.       
  756.       public function get focusPane() : Sprite
  757.       {
  758.          return _focusPane;
  759.       }
  760.       
  761.       private function keyDownHandler(param1:KeyboardEvent) : void
  762.       {
  763.          var _loc3_:DisplayObject = null;
  764.          var _loc4_:String = null;
  765.          var _loc5_:int = 0;
  766.          var _loc6_:int = 0;
  767.          var _loc7_:IFocusManagerGroup = null;
  768.          var _loc2_:ISystemManager = mx_internal::form.systemManager;
  769.          if(_loc2_.isDisplayObjectInABridgedApplication(DisplayObject(param1.target)))
  770.          {
  771.             return;
  772.          }
  773.          if(_loc2_ is SystemManager)
  774.          {
  775.             SystemManager(_loc2_).mx_internal::idleCounter = 0;
  776.          }
  777.          if(param1.keyCode == Keyboard.TAB)
  778.          {
  779.             lastAction = "KEY";
  780.             if(calculateCandidates)
  781.             {
  782.                sortFocusableObjects();
  783.                calculateCandidates = false;
  784.             }
  785.          }
  786.          if(browserMode)
  787.          {
  788.             if(param1.keyCode == Keyboard.TAB && focusableCandidates.length > 0)
  789.             {
  790.                _loc3_ = fauxFocus;
  791.                if(!_loc3_)
  792.                {
  793.                   _loc3_ = mx_internal::form.systemManager.stage.focus;
  794.                }
  795.                _loc3_ = DisplayObject(findFocusManagerComponent2(InteractiveObject(_loc3_)));
  796.                _loc4_ = "";
  797.                if(_loc3_ is IFocusManagerGroup)
  798.                {
  799.                   _loc7_ = IFocusManagerGroup(_loc3_);
  800.                   _loc4_ = _loc7_.groupName;
  801.                }
  802.                _loc5_ = getIndexOfFocusedObject(_loc3_);
  803.                _loc6_ = getIndexOfNextObject(_loc5_,param1.shiftKey,false,_loc4_);
  804.                if(param1.shiftKey)
  805.                {
  806.                   if(_loc6_ >= _loc5_)
  807.                   {
  808.                      browserFocusComponent = getBrowserFocusComponent(param1.shiftKey);
  809.                      if(browserFocusComponent.tabIndex == -1)
  810.                      {
  811.                         browserFocusComponent.tabIndex = 0;
  812.                      }
  813.                   }
  814.                }
  815.                else if(_loc6_ <= _loc5_)
  816.                {
  817.                   browserFocusComponent = getBrowserFocusComponent(param1.shiftKey);
  818.                   if(browserFocusComponent.tabIndex == -1)
  819.                   {
  820.                      browserFocusComponent.tabIndex = LARGE_TAB_INDEX;
  821.                   }
  822.                }
  823.             }
  824.          }
  825.       }
  826.       
  827.       private function mouseDownHandler(param1:MouseEvent) : void
  828.       {
  829.          if(param1.isDefaultPrevented())
  830.          {
  831.             return;
  832.          }
  833.          var _loc2_:ISystemManager = mx_internal::form.systemManager;
  834.          var _loc3_:DisplayObject = getTopLevelFocusTarget(InteractiveObject(param1.target));
  835.          if(!_loc3_)
  836.          {
  837.             return;
  838.          }
  839.          showFocusIndicator = false;
  840.          if((_loc3_ != _lastFocus || lastAction == "ACTIVATE") && !(_loc3_ is TextField))
  841.          {
  842.             setFocus(IFocusManagerComponent(_loc3_));
  843.          }
  844.          else if(_lastFocus)
  845.          {
  846.             if(!_lastFocus && _loc3_ is IEventDispatcher && SystemManager(mx_internal::form.systemManager).useSWFBridge())
  847.             {
  848.                IEventDispatcher(_loc3_).dispatchEvent(new FocusEvent(FocusEvent.FOCUS_IN));
  849.             }
  850.          }
  851.          lastAction = "MOUSEDOWN";
  852.          dispatchActivatedFocusManagerEvent(null);
  853.          lastActiveFocusManager = this;
  854.       }
  855.       
  856.       private function focusInHandler(param1:FocusEvent) : void
  857.       {
  858.          var _loc4_:IButton = null;
  859.          var _loc2_:InteractiveObject = InteractiveObject(param1.target);
  860.          var _loc3_:ISystemManager = mx_internal::form.systemManager;
  861.          if(_loc3_.isDisplayObjectInABridgedApplication(DisplayObject(param1.target)))
  862.          {
  863.             return;
  864.          }
  865.          if(isParent(DisplayObjectContainer(mx_internal::form),_loc2_))
  866.          {
  867.             _lastFocus = findFocusManagerComponent(InteractiveObject(_loc2_));
  868.             if(_lastFocus is IButton && !(_lastFocus is IToggleButton))
  869.             {
  870.                _loc4_ = _lastFocus as IButton;
  871.                if(defButton)
  872.                {
  873.                   defButton.emphasized = false;
  874.                   defButton = _loc4_;
  875.                   _loc4_.emphasized = true;
  876.                }
  877.             }
  878.             else if(Boolean(defButton) && defButton != _defaultButton)
  879.             {
  880.                defButton.emphasized = false;
  881.                defButton = _defaultButton;
  882.                if(_defaultButton)
  883.                {
  884.                   _defaultButton.emphasized = true;
  885.                }
  886.             }
  887.          }
  888.       }
  889.       
  890.       public function toString() : String
  891.       {
  892.          return Object(mx_internal::form).toString() + ".focusManager";
  893.       }
  894.       
  895.       public function deactivate() : void
  896.       {
  897.          var _loc1_:ISystemManager = mx_internal::form.systemManager;
  898.          if(_loc1_)
  899.          {
  900.             if(_loc1_.isTopLevelRoot())
  901.             {
  902.                _loc1_.stage.removeEventListener(FocusEvent.MOUSE_FOCUS_CHANGE,mouseFocusChangeHandler);
  903.                _loc1_.stage.removeEventListener(FocusEvent.KEY_FOCUS_CHANGE,keyFocusChangeHandler);
  904.                _loc1_.stage.removeEventListener(Event.ACTIVATE,activateHandler);
  905.                _loc1_.stage.removeEventListener(Event.DEACTIVATE,deactivateHandler);
  906.             }
  907.             else
  908.             {
  909.                _loc1_.removeEventListener(FocusEvent.MOUSE_FOCUS_CHANGE,mouseFocusChangeHandler);
  910.                _loc1_.removeEventListener(FocusEvent.KEY_FOCUS_CHANGE,keyFocusChangeHandler);
  911.                _loc1_.removeEventListener(Event.ACTIVATE,activateHandler);
  912.                _loc1_.removeEventListener(Event.DEACTIVATE,deactivateHandler);
  913.             }
  914.          }
  915.          mx_internal::form.removeEventListener(FocusEvent.FOCUS_IN,focusInHandler,true);
  916.          mx_internal::form.removeEventListener(FocusEvent.FOCUS_OUT,focusOutHandler,true);
  917.          mx_internal::form.removeEventListener(MouseEvent.MOUSE_DOWN,mouseDownHandler);
  918.          mx_internal::form.removeEventListener(KeyboardEvent.KEY_DOWN,defaultButtonKeyHandler);
  919.          mx_internal::form.removeEventListener(KeyboardEvent.KEY_DOWN,keyDownHandler,true);
  920.          activated = false;
  921.          dispatchEventFromSWFBridges(new SWFBridgeRequest(SWFBridgeRequest.DEACTIVATE_FOCUS_REQUEST),skipBridge);
  922.       }
  923.       
  924.       private function findFocusManagerComponent2(param1:InteractiveObject) : DisplayObject
  925.       {
  926.          var o:InteractiveObject = param1;
  927.          try
  928.          {
  929.             while(o)
  930.             {
  931.                if(o is IFocusManagerComponent && Boolean(IFocusManagerComponent(o).focusEnabled) || o is ISWFLoader)
  932.                {
  933.                   return o;
  934.                }
  935.                o = o.parent;
  936.             }
  937.          }
  938.          catch(error:SecurityError)
  939.          {
  940.          }
  941.          return null;
  942.       }
  943.       
  944.       private function getIndexOfNextObject(param1:int, param2:Boolean, param3:Boolean, param4:String) : int
  945.       {
  946.          var _loc7_:DisplayObject = null;
  947.          var _loc8_:IFocusManagerGroup = null;
  948.          var _loc9_:int = 0;
  949.          var _loc10_:DisplayObject = null;
  950.          var _loc11_:IFocusManagerGroup = null;
  951.          var _loc5_:int = int(focusableCandidates.length);
  952.          var _loc6_:int = param1;
  953.          while(true)
  954.          {
  955.             if(param2)
  956.             {
  957.                param1--;
  958.             }
  959.             else
  960.             {
  961.                param1++;
  962.             }
  963.             if(param3)
  964.             {
  965.                if(param2 && param1 < 0)
  966.                {
  967.                   break;
  968.                }
  969.                if(!param2 && param1 == _loc5_)
  970.                {
  971.                   break;
  972.                }
  973.             }
  974.             else
  975.             {
  976.                param1 = (param1 + _loc5_) % _loc5_;
  977.                if(_loc6_ == param1)
  978.                {
  979.                   break;
  980.                }
  981.                if(_loc6_ == -1)
  982.                {
  983.                   _loc6_ = param1;
  984.                }
  985.             }
  986.             if(isValidFocusCandidate(focusableCandidates[param1],param4))
  987.             {
  988.                _loc7_ = DisplayObject(findFocusManagerComponent2(focusableCandidates[param1]));
  989.                if(_loc7_ is IFocusManagerGroup)
  990.                {
  991.                   _loc8_ = IFocusManagerGroup(_loc7_);
  992.                   _loc9_ = 0;
  993.                   while(_loc9_ < focusableCandidates.length)
  994.                   {
  995.                      _loc10_ = focusableCandidates[_loc9_];
  996.                      if(_loc10_ is IFocusManagerGroup)
  997.                      {
  998.                         _loc11_ = IFocusManagerGroup(_loc10_);
  999.                         if(_loc11_.groupName == _loc8_.groupName && _loc11_.selected)
  1000.                         {
  1001.                            if(InteractiveObject(_loc10_).tabIndex != InteractiveObject(_loc7_).tabIndex && !_loc8_.selected)
  1002.                            {
  1003.                               return getIndexOfNextObject(param1,param2,param3,param4);
  1004.                            }
  1005.                            param1 = _loc9_;
  1006.                            break;
  1007.                         }
  1008.                      }
  1009.                      _loc9_++;
  1010.                   }
  1011.                }
  1012.                return param1;
  1013.             }
  1014.          }
  1015.          return param1;
  1016.       }
  1017.       
  1018.       public function moveFocus(param1:String, param2:DisplayObject = null) : void
  1019.       {
  1020.          if(param1 == FocusRequestDirection.TOP)
  1021.          {
  1022.             setFocusToTop();
  1023.             return;
  1024.          }
  1025.          if(param1 == FocusRequestDirection.BOTTOM)
  1026.          {
  1027.             setFocusToBottom();
  1028.             return;
  1029.          }
  1030.          var _loc3_:KeyboardEvent = new KeyboardEvent(KeyboardEvent.KEY_DOWN);
  1031.          _loc3_.keyCode = Keyboard.TAB;
  1032.          _loc3_.shiftKey = param1 == FocusRequestDirection.FORWARD ? false : true;
  1033.          fauxFocus = param2;
  1034.          keyDownHandler(_loc3_);
  1035.          var _loc4_:FocusEvent = new FocusEvent(FocusEvent.KEY_FOCUS_CHANGE);
  1036.          _loc4_.keyCode = Keyboard.TAB;
  1037.          _loc4_.shiftKey = param1 == FocusRequestDirection.FORWARD ? false : true;
  1038.          keyFocusChangeHandler(_loc4_);
  1039.          fauxFocus = null;
  1040.       }
  1041.       
  1042.       private function getMaxTabIndex() : int
  1043.       {
  1044.          var _loc4_:Number = NaN;
  1045.          var _loc1_:Number = 0;
  1046.          var _loc2_:int = int(focusableObjects.length);
  1047.          var _loc3_:int = 0;
  1048.          while(_loc3_ < _loc2_)
  1049.          {
  1050.             _loc4_ = Number(focusableObjects[_loc3_].tabIndex);
  1051.             if(!isNaN(_loc4_))
  1052.             {
  1053.                _loc1_ = Math.max(_loc1_,_loc4_);
  1054.             }
  1055.             _loc3_++;
  1056.          }
  1057.          return _loc1_;
  1058.       }
  1059.       
  1060.       private function isParent(param1:DisplayObjectContainer, param2:DisplayObject) : Boolean
  1061.       {
  1062.          if(param1 is IRawChildrenContainer)
  1063.          {
  1064.             return IRawChildrenContainer(param1).rawChildren.contains(param2);
  1065.          }
  1066.          return param1.contains(param2);
  1067.       }
  1068.       
  1069.       private function showHandler(param1:Event) : void
  1070.       {
  1071.          mx_internal::form.systemManager.activate(mx_internal::form);
  1072.       }
  1073.       
  1074.       mx_internal function set form(param1:IFocusManagerContainer) : void
  1075.       {
  1076.          _form = param1;
  1077.       }
  1078.       
  1079.       public function setFocus(param1:IFocusManagerComponent) : void
  1080.       {
  1081.          param1.setFocus();
  1082.          focusSetLocally = true;
  1083.       }
  1084.       
  1085.       public function findFocusManagerComponent(param1:InteractiveObject) : IFocusManagerComponent
  1086.       {
  1087.          return findFocusManagerComponent2(param1) as IFocusManagerComponent;
  1088.       }
  1089.       
  1090.       public function removeSWFBridge(param1:IEventDispatcher) : void
  1091.       {
  1092.          var _loc4_:int = 0;
  1093.          var _loc2_:ISystemManager = _form.systemManager;
  1094.          var _loc3_:DisplayObject = DisplayObject(swfBridgeGroup.getChildBridgeProvider(param1));
  1095.          if(_loc3_)
  1096.          {
  1097.             _loc4_ = int(focusableObjects.indexOf(_loc3_));
  1098.             if(_loc4_ != -1)
  1099.             {
  1100.                focusableObjects.splice(_loc4_,1);
  1101.                calculateCandidates = true;
  1102.             }
  1103.             param1.removeEventListener(SWFBridgeRequest.MOVE_FOCUS_REQUEST,focusRequestMoveHandler);
  1104.             param1.removeEventListener(SWFBridgeRequest.SET_SHOW_FOCUS_INDICATOR_REQUEST,setShowFocusIndicatorRequestHandler);
  1105.             param1.removeEventListener(SWFBridgeEvent.BRIDGE_FOCUS_MANAGER_ACTIVATE,bridgeEventActivateHandler);
  1106.             swfBridgeGroup.removeChildBridge(param1);
  1107.             return;
  1108.          }
  1109.          throw new Error();
  1110.       }
  1111.       
  1112.       private function sortFocusableObjectsTabIndex() : void
  1113.       {
  1114.          var _loc3_:IFocusManagerComponent = null;
  1115.          focusableCandidates = [];
  1116.          var _loc1_:int = int(focusableObjects.length);
  1117.          var _loc2_:int = 0;
  1118.          while(_loc2_ < _loc1_)
  1119.          {
  1120.             _loc3_ = focusableObjects[_loc2_] as IFocusManagerComponent;
  1121.             if(_loc3_ && _loc3_.tabIndex && !isNaN(Number(_loc3_.tabIndex)) || focusableObjects[_loc2_] is ISWFLoader)
  1122.             {
  1123.                focusableCandidates.push(focusableObjects[_loc2_]);
  1124.             }
  1125.             _loc2_++;
  1126.          }
  1127.          focusableCandidates.sort(sortByTabIndex);
  1128.       }
  1129.       
  1130.       public function set defaultButton(param1:IButton) : void
  1131.       {
  1132.          var _loc2_:IButton = !!param1 ? IButton(param1) : null;
  1133.          if(_loc2_ != _defaultButton)
  1134.          {
  1135.             if(_defaultButton)
  1136.             {
  1137.                _defaultButton.emphasized = false;
  1138.             }
  1139.             if(defButton)
  1140.             {
  1141.                defButton.emphasized = false;
  1142.             }
  1143.             _defaultButton = _loc2_;
  1144.             if(_lastFocus && _lastFocus is IButton && !(_lastFocus is IToggleButton))
  1145.             {
  1146.                defButton = _lastFocus as IButton;
  1147.                defButton.emphasized = true;
  1148.             }
  1149.             else
  1150.             {
  1151.                defButton = _loc2_;
  1152.                if(_loc2_)
  1153.                {
  1154.                   _loc2_.emphasized = true;
  1155.                }
  1156.             }
  1157.          }
  1158.       }
  1159.       
  1160.       private function setFocusToNextObject(param1:FocusEvent) : void
  1161.       {
  1162.          focusChanged = false;
  1163.          if(focusableObjects.length == 0)
  1164.          {
  1165.             return;
  1166.          }
  1167.          var _loc2_:FocusInfo = getNextFocusManagerComponent2(param1.shiftKey,fauxFocus);
  1168.          if(!popup && (_loc2_.wrapped || !_loc2_.displayObject))
  1169.          {
  1170.             if(getParentBridge())
  1171.             {
  1172.                moveFocusToParent(param1.shiftKey);
  1173.                return;
  1174.             }
  1175.          }
  1176.          if(!_loc2_.displayObject)
  1177.          {
  1178.             param1.preventDefault();
  1179.             return;
  1180.          }
  1181.          setFocusToComponent(_loc2_.displayObject,param1.shiftKey);
  1182.       }
  1183.       
  1184.       private function getTopLevelFocusTarget(param1:InteractiveObject) : InteractiveObject
  1185.       {
  1186.          while(param1 != InteractiveObject(mx_internal::form))
  1187.          {
  1188.             if(param1 is IFocusManagerComponent && Boolean(IFocusManagerComponent(param1).focusEnabled) && Boolean(IFocusManagerComponent(param1).mouseFocusEnabled) && (param1 is IUIComponent ? IUIComponent(param1).enabled : true))
  1189.             {
  1190.                return param1;
  1191.             }
  1192.             if(param1.parent is ISWFLoader)
  1193.             {
  1194.                if(ISWFLoader(param1.parent).swfBridge)
  1195.                {
  1196.                   return null;
  1197.                }
  1198.             }
  1199.             param1 = param1.parent;
  1200.             if(param1 == null)
  1201.             {
  1202.                break;
  1203.             }
  1204.          }
  1205.          return null;
  1206.       }
  1207.       
  1208.       private function addedToStageHandler(param1:Event) : void
  1209.       {
  1210.          _form.removeEventListener(Event.ADDED_TO_STAGE,addedToStageHandler);
  1211.          if(focusableObjects.length == 0)
  1212.          {
  1213.             addFocusables(DisplayObject(_form));
  1214.             calculateCandidates = true;
  1215.          }
  1216.       }
  1217.       
  1218.       private function hideHandler(param1:Event) : void
  1219.       {
  1220.          mx_internal::form.systemManager.deactivate(mx_internal::form);
  1221.       }
  1222.       
  1223.       private function isEnabledAndVisible(param1:DisplayObject) : Boolean
  1224.       {
  1225.          var _loc2_:DisplayObjectContainer = DisplayObject(mx_internal::form).parent;
  1226.          while(param1 != _loc2_)
  1227.          {
  1228.             if(param1 is IUIComponent)
  1229.             {
  1230.                if(!IUIComponent(param1).enabled)
  1231.                {
  1232.                   return false;
  1233.                }
  1234.             }
  1235.             if(!param1.visible)
  1236.             {
  1237.                return false;
  1238.             }
  1239.             param1 = param1.parent;
  1240.          }
  1241.          return true;
  1242.       }
  1243.       
  1244.       public function hideFocus() : void
  1245.       {
  1246.          if(showFocusIndicator)
  1247.          {
  1248.             showFocusIndicator = false;
  1249.             if(_lastFocus)
  1250.             {
  1251.                _lastFocus.drawFocus(false);
  1252.             }
  1253.          }
  1254.       }
  1255.       
  1256.       private function getBrowserFocusComponent(param1:Boolean) : InteractiveObject
  1257.       {
  1258.          var _loc3_:int = 0;
  1259.          var _loc2_:InteractiveObject = mx_internal::form.systemManager.stage.focus;
  1260.          if(!_loc2_)
  1261.          {
  1262.             _loc3_ = param1 ? 0 : int(focusableCandidates.length - 1);
  1263.             _loc2_ = focusableCandidates[_loc3_];
  1264.          }
  1265.          return _loc2_;
  1266.       }
  1267.       
  1268.       public function get showFocusIndicator() : Boolean
  1269.       {
  1270.          return _showFocusIndicator;
  1271.       }
  1272.       
  1273.       private function moveFocusToParent(param1:Boolean) : Boolean
  1274.       {
  1275.          var _loc2_:SWFBridgeRequest = new SWFBridgeRequest(SWFBridgeRequest.MOVE_FOCUS_REQUEST,false,true,null,param1 ? FocusRequestDirection.BACKWARD : FocusRequestDirection.FORWARD);
  1276.          var _loc3_:IEventDispatcher = _form.systemManager.swfBridgeGroup.parentBridge;
  1277.          _loc3_.dispatchEvent(_loc2_);
  1278.          focusChanged = _loc2_.data;
  1279.          return focusChanged;
  1280.       }
  1281.       
  1282.       public function set focusPane(param1:Sprite) : void
  1283.       {
  1284.          _focusPane = param1;
  1285.       }
  1286.       
  1287.       mx_internal function get form() : IFocusManagerContainer
  1288.       {
  1289.          return _form;
  1290.       }
  1291.       
  1292.       private function removedHandler(param1:Event) : void
  1293.       {
  1294.          var _loc2_:int = 0;
  1295.          var _loc3_:DisplayObject = DisplayObject(param1.target);
  1296.          if(_loc3_ is IFocusManagerComponent)
  1297.          {
  1298.             _loc2_ = 0;
  1299.             while(_loc2_ < focusableObjects.length)
  1300.             {
  1301.                if(_loc3_ == focusableObjects[_loc2_])
  1302.                {
  1303.                   if(_loc3_ == _lastFocus)
  1304.                   {
  1305.                      _lastFocus.drawFocus(false);
  1306.                      _lastFocus = null;
  1307.                   }
  1308.                   _loc3_.removeEventListener("tabEnabledChange",tabEnabledChangeHandler);
  1309.                   _loc3_.removeEventListener("tabIndexChange",tabIndexChangeHandler);
  1310.                   focusableObjects.splice(_loc2_,1);
  1311.                   focusableCandidates = [];
  1312.                   calculateCandidates = true;
  1313.                   break;
  1314.                }
  1315.                _loc2_++;
  1316.             }
  1317.          }
  1318.          removeFocusables(_loc3_,false);
  1319.       }
  1320.       
  1321.       private function dispatchEventFromSWFBridges(param1:Event, param2:IEventDispatcher = null) : void
  1322.       {
  1323.          var _loc3_:Event = null;
  1324.          var _loc7_:IEventDispatcher = null;
  1325.          var _loc4_:ISystemManager = mx_internal::form.systemManager;
  1326.          if(!popup)
  1327.          {
  1328.             _loc7_ = swfBridgeGroup.parentBridge;
  1329.             if((Boolean(_loc7_)) && _loc7_ != param2)
  1330.             {
  1331.                _loc3_ = param1.clone();
  1332.                if(_loc3_ is SWFBridgeRequest)
  1333.                {
  1334.                   SWFBridgeRequest(_loc3_).requestor = _loc7_;
  1335.                }
  1336.                _loc7_.dispatchEvent(_loc3_);
  1337.             }
  1338.          }
  1339.          var _loc5_:Array = swfBridgeGroup.getChildBridges();
  1340.          var _loc6_:int = 0;
  1341.          while(_loc6_ < _loc5_.length)
  1342.          {
  1343.             if(_loc5_[_loc6_] != param2)
  1344.             {
  1345.                _loc3_ = param1.clone();
  1346.                if(_loc3_ is SWFBridgeRequest)
  1347.                {
  1348.                   SWFBridgeRequest(_loc3_).requestor = IEventDispatcher(_loc5_[_loc6_]);
  1349.                }
  1350.                IEventDispatcher(_loc5_[_loc6_]).dispatchEvent(_loc3_);
  1351.             }
  1352.             _loc6_++;
  1353.          }
  1354.       }
  1355.       
  1356.       public function get defaultButton() : IButton
  1357.       {
  1358.          return _defaultButton;
  1359.       }
  1360.       
  1361.       private function activateHandler(param1:Event) : void
  1362.       {
  1363.          if(Boolean(_lastFocus) && !browserMode)
  1364.          {
  1365.             _lastFocus.setFocus();
  1366.          }
  1367.          lastAction = "ACTIVATE";
  1368.       }
  1369.       
  1370.       public function showFocus() : void
  1371.       {
  1372.          if(!showFocusIndicator)
  1373.          {
  1374.             showFocusIndicator = true;
  1375.             if(_lastFocus)
  1376.             {
  1377.                _lastFocus.drawFocus(true);
  1378.             }
  1379.          }
  1380.       }
  1381.       
  1382.       public function getNextFocusManagerComponent(param1:Boolean = false) : IFocusManagerComponent
  1383.       {
  1384.          return getNextFocusManagerComponent2(param1,fauxFocus).displayObject as IFocusManagerComponent;
  1385.       }
  1386.       
  1387.       private function setShowFocusIndicatorRequestHandler(param1:Event) : void
  1388.       {
  1389.          if(param1 is SWFBridgeRequest)
  1390.          {
  1391.             return;
  1392.          }
  1393.          var _loc2_:SWFBridgeRequest = SWFBridgeRequest.marshal(param1);
  1394.          _showFocusIndicator = _loc2_.data;
  1395.          dispatchSetShowFocusIndicatorRequest(_showFocusIndicator,IEventDispatcher(param1.target));
  1396.       }
  1397.       
  1398.       private function setFocusToTop() : void
  1399.       {
  1400.          setFocusToNextIndex(-1,false);
  1401.       }
  1402.       
  1403.       private function isTabVisible(param1:DisplayObject) : Boolean
  1404.       {
  1405.          var _loc2_:DisplayObject = DisplayObject(mx_internal::form.systemManager);
  1406.          if(!_loc2_)
  1407.          {
  1408.             return false;
  1409.          }
  1410.          var _loc3_:DisplayObjectContainer = param1.parent;
  1411.          while(Boolean(_loc3_) && _loc3_ != _loc2_)
  1412.          {
  1413.             if(!_loc3_.tabChildren)
  1414.             {
  1415.                return false;
  1416.             }
  1417.             _loc3_ = _loc3_.parent;
  1418.          }
  1419.          return true;
  1420.       }
  1421.       
  1422.       mx_internal function get lastFocus() : IFocusManagerComponent
  1423.       {
  1424.          return _lastFocus;
  1425.       }
  1426.       
  1427.       public function set defaultButtonEnabled(param1:Boolean) : void
  1428.       {
  1429.          _defaultButtonEnabled = param1;
  1430.       }
  1431.       
  1432.       public function get defaultButtonEnabled() : Boolean
  1433.       {
  1434.          return _defaultButtonEnabled;
  1435.       }
  1436.       
  1437.       public function set showFocusIndicator(param1:Boolean) : void
  1438.       {
  1439.          var _loc2_:* = _showFocusIndicator != param1;
  1440.          _showFocusIndicator = param1;
  1441.          if(_loc2_ && !popup && Boolean(mx_internal::form.systemManager.swfBridgeGroup))
  1442.          {
  1443.             dispatchSetShowFocusIndicatorRequest(param1,null);
  1444.          }
  1445.       }
  1446.       
  1447.       private function sortByTabIndex(param1:InteractiveObject, param2:InteractiveObject) : int
  1448.       {
  1449.          var _loc3_:int = param1.tabIndex;
  1450.          var _loc4_:int = param2.tabIndex;
  1451.          if(_loc3_ == -1)
  1452.          {
  1453.             _loc3_ = int.MAX_VALUE;
  1454.          }
  1455.          if(_loc4_ == -1)
  1456.          {
  1457.             _loc4_ = int.MAX_VALUE;
  1458.          }
  1459.          return _loc3_ > _loc4_ ? 1 : (_loc3_ < _loc4_ ? -1 : int(sortByDepth(DisplayObject(param1),DisplayObject(param2))));
  1460.       }
  1461.       
  1462.       public function activate() : void
  1463.       {
  1464.          if(activated)
  1465.          {
  1466.             return;
  1467.          }
  1468.          var _loc1_:ISystemManager = mx_internal::form.systemManager;
  1469.          if(_loc1_)
  1470.          {
  1471.             if(_loc1_.isTopLevelRoot())
  1472.             {
  1473.                _loc1_.stage.addEventListener(FocusEvent.MOUSE_FOCUS_CHANGE,mouseFocusChangeHandler,false,0,true);
  1474.                _loc1_.stage.addEventListener(FocusEvent.KEY_FOCUS_CHANGE,keyFocusChangeHandler,false,0,true);
  1475.                _loc1_.stage.addEventListener(Event.ACTIVATE,activateHandler,false,0,true);
  1476.                _loc1_.stage.addEventListener(Event.DEACTIVATE,deactivateHandler,false,0,true);
  1477.             }
  1478.             else
  1479.             {
  1480.                _loc1_.addEventListener(FocusEvent.MOUSE_FOCUS_CHANGE,mouseFocusChangeHandler,false,0,true);
  1481.                _loc1_.addEventListener(FocusEvent.KEY_FOCUS_CHANGE,keyFocusChangeHandler,false,0,true);
  1482.                _loc1_.addEventListener(Event.ACTIVATE,activateHandler,false,0,true);
  1483.                _loc1_.addEventListener(Event.DEACTIVATE,deactivateHandler,false,0,true);
  1484.             }
  1485.          }
  1486.          mx_internal::form.addEventListener(FocusEvent.FOCUS_IN,focusInHandler,true);
  1487.          mx_internal::form.addEventListener(FocusEvent.FOCUS_OUT,focusOutHandler,true);
  1488.          mx_internal::form.addEventListener(MouseEvent.MOUSE_DOWN,mouseDownHandler);
  1489.          mx_internal::form.addEventListener(KeyboardEvent.KEY_DOWN,defaultButtonKeyHandler);
  1490.          mx_internal::form.addEventListener(KeyboardEvent.KEY_DOWN,keyDownHandler,true);
  1491.          activated = true;
  1492.          if(_lastFocus)
  1493.          {
  1494.             setFocus(_lastFocus);
  1495.          }
  1496.          dispatchEventFromSWFBridges(new SWFBridgeRequest(SWFBridgeRequest.ACTIVATE_FOCUS_REQUEST),skipBridge);
  1497.       }
  1498.       
  1499.       private function setFocusToNextIndex(param1:int, param2:Boolean) : void
  1500.       {
  1501.          if(focusableObjects.length == 0)
  1502.          {
  1503.             return;
  1504.          }
  1505.          if(calculateCandidates)
  1506.          {
  1507.             sortFocusableObjects();
  1508.             calculateCandidates = false;
  1509.          }
  1510.          var _loc3_:FocusInfo = getNextFocusManagerComponent2(param2,null,param1);
  1511.          if(!popup && _loc3_.wrapped)
  1512.          {
  1513.             if(getParentBridge())
  1514.             {
  1515.                moveFocusToParent(param2);
  1516.                return;
  1517.             }
  1518.          }
  1519.          setFocusToComponent(_loc3_.displayObject,param2);
  1520.       }
  1521.    }
  1522. }
  1523.  
  1524. import flash.display.DisplayObject;
  1525.  
  1526. class FocusInfo
  1527. {
  1528.    public var displayObject:DisplayObject;
  1529.    
  1530.    public var wrapped:Boolean;
  1531.    
  1532.    public function FocusInfo()
  1533.    {
  1534.       super();
  1535.    }
  1536. }
  1537.