PageRenderTime 72ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 1ms

/Sample/mx/managers/SystemManager.as

https://github.com/ingydotnet/yaml-oscon2009-talk
ActionScript | 5528 lines | 3054 code | 737 blank | 1737 comment | 672 complexity | 0719829e2997cf363d1a00cbfa8d0c5f MD5 | raw file
  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // ADOBE SYSTEMS INCORPORATED
  4. // Copyright 2003-2007 Adobe Systems Incorporated
  5. // All Rights Reserved.
  6. //
  7. // NOTICE: Adobe permits you to use, modify, and distribute this file
  8. // in accordance with the terms of the license agreement accompanying it.
  9. //
  10. ////////////////////////////////////////////////////////////////////////////////
  11. package mx.managers
  12. {
  13. import flash.display.DisplayObject;
  14. import flash.display.DisplayObjectContainer;
  15. import flash.display.Graphics;
  16. import flash.display.InteractiveObject;
  17. import flash.display.Loader;
  18. import flash.display.LoaderInfo;
  19. import flash.display.MovieClip;
  20. import flash.display.Sprite;
  21. import flash.display.Stage;
  22. import flash.display.StageAlign;
  23. import flash.display.StageScaleMode;
  24. import flash.events.Event;
  25. import flash.events.EventDispatcher;
  26. import flash.events.EventPhase;
  27. import flash.events.IEventDispatcher;
  28. import flash.events.MouseEvent;
  29. import flash.events.TimerEvent;
  30. import flash.geom.Point;
  31. import flash.geom.Rectangle;
  32. import flash.net.getClassByAlias;
  33. import flash.net.registerClassAlias;
  34. import flash.system.ApplicationDomain;
  35. import flash.system.Capabilities;
  36. import flash.text.Font;
  37. import flash.text.TextFormat;
  38. import flash.utils.ByteArray;
  39. import flash.utils.Dictionary;
  40. import flash.utils.Timer;
  41. import flash.utils.getQualifiedClassName;
  42. import mx.core.EmbeddedFontRegistry;
  43. import mx.core.EventPriority;
  44. import mx.core.FlexSprite;
  45. import mx.core.ISWFLoader;
  46. import mx.core.IChildList;
  47. import mx.core.IFlexDisplayObject;
  48. import mx.core.IFlexModuleFactory;
  49. import mx.core.IInvalidating;
  50. import mx.core.IRawChildrenContainer;
  51. import mx.core.ISWFBridgeGroup;
  52. import mx.core.ISWFBridgeProvider;
  53. import mx.core.IUIComponent;
  54. import mx.core.RSLItem;
  55. import mx.core.Singleton;
  56. import mx.core.SWFBridgeGroup;
  57. import mx.core.TextFieldFactory;
  58. import mx.core.mx_internal;
  59. import mx.events.FlexEvent;
  60. import mx.messaging.config.LoaderConfig;
  61. import mx.preloaders.DownloadProgressBar;
  62. import mx.preloaders.Preloader;
  63. import mx.resources.IResourceManager;
  64. import mx.resources.ResourceBundle;
  65. import mx.resources.ResourceManager;
  66. import mx.styles.ISimpleStyleClient;
  67. import mx.styles.IStyleClient;
  68. import mx.styles.StyleManager;
  69. import mx.events.EventListenerRequest;
  70. import mx.events.FlexChangeEvent;
  71. import mx.events.InvalidateRequestData;
  72. import mx.events.InterManagerRequest;
  73. import mx.events.ResizeEvent;
  74. import mx.events.SandboxMouseEvent;
  75. import mx.events.SWFBridgeRequest;
  76. import mx.events.SWFBridgeEvent;
  77. import mx.managers.systemClasses.RemotePopUp;
  78. import mx.managers.systemClasses.EventProxy;
  79. import mx.managers.systemClasses.StageEventProxy;
  80. import mx.managers.systemClasses.PlaceholderData;
  81. import mx.utils.EventUtil;
  82. import mx.utils.NameUtil;
  83. import mx.utils.LoaderUtil;
  84. import mx.utils.ObjectUtil;
  85. import mx.utils.SecurityUtil;
  86. // NOTE: Minimize the non-Flash classes you import here.
  87. // Any dependencies of SystemManager have to load in frame 1,
  88. // before the preloader, or anything else, can be displayed.
  89. use namespace mx_internal;
  90. //--------------------------------------
  91. // Events
  92. //--------------------------------------
  93. /**
  94. * Dispatched when the application has finished initializing
  95. *
  96. * @eventType mx.events.FlexEvent.APPLICATION_COMPLETE
  97. */
  98. [Event(name="applicationComplete", type="mx.events.FlexEvent")]
  99. /**
  100. * Dispatched every 100 milliseconds when there has been no keyboard
  101. * or mouse activity for 1 second.
  102. *
  103. * @eventType mx.events.FlexEvent.IDLE
  104. */
  105. [Event(name="idle", type="mx.events.FlexEvent")]
  106. /**
  107. * Dispatched when the Stage is resized.
  108. *
  109. * @eventType flash.events.Event.RESIZE
  110. */
  111. [Event(name="resize", type="flash.events.Event")]
  112. /**
  113. * The SystemManager class manages an application window.
  114. * Every application that runs on the desktop or in a browser
  115. * has an area where the visuals of the application are
  116. * displayed.
  117. * It may be a window in the operating system
  118. * or an area within the browser. That area is an application window
  119. * and different from an instance of <code>mx.core.Application</code>, which
  120. * is the main, or top-level, window within an application.
  121. *
  122. * <p>Every application has a SystemManager.
  123. * The SystemManager sends an event if
  124. * the size of the application window changes (you cannot change it from
  125. * within the application, but only through interaction with the operating
  126. * system window or browser). It parents all displayable things within the
  127. * application like the main mx.core.Application instance and all popups,
  128. * tooltips, cursors, and so on. Any object parented by the SystemManager is
  129. * considered to be a top-level window, even tooltips and cursors.</p>
  130. *
  131. * <p>The SystemManager also switches focus between top-level windows if there
  132. * are more than one IFocusManagerContainer displayed and users are interacting
  133. * with components within the IFocusManagerContainers. </p>
  134. *
  135. * <p>All keyboard and mouse activity that is not expressly trapped is seen by
  136. * the SystemManager, making it a good place to monitor activity should you need
  137. * to do so.</p>
  138. *
  139. * <p>If an application is loaded into another application, a SystemManager
  140. * will still be created, but will not manage an application window,
  141. * depending on security and domain rules.
  142. * Instead, it will be the <code>content</code> of the <code>Loader</code>
  143. * that loaded it and simply serve as the parent of the sub-application</p>
  144. *
  145. * <p>The SystemManager maintains multiple lists of children, one each for tooltips, cursors,
  146. * popup windows. This is how it ensures that popup windows "float" above the main
  147. * application windows and that tooltips "float" above that and cursors above that.
  148. * If you simply examine the <code>numChildren</code> property or
  149. * call the <code>getChildAt()</code> method on the SystemManager, you are accessing
  150. * the main application window and any other windows that aren't popped up. To get the list
  151. * of all windows, including popups, tooltips and cursors, use
  152. * the <code>rawChildren</code> property.</p>
  153. *
  154. * <p>The SystemManager is the first display class created within an application.
  155. * It is responsible for creating an <code>mx.preloaders.Preloader</code> that displays and
  156. * <code>mx.preloaders.DownloadProgressBar</code> while the application finishes loading,
  157. * then creates the <code>mx.core.Application</code> instance.</p>
  158. */
  159. public class SystemManager extends MovieClip
  160. implements IChildList, IFlexDisplayObject,
  161. IFlexModuleFactory, ISystemManager, ISWFBridgeProvider
  162. {
  163. include "../core/Version.as";
  164. //--------------------------------------------------------------------------
  165. //
  166. // Class constants
  167. //
  168. //--------------------------------------------------------------------------
  169. /**
  170. * @private
  171. * The number of milliseconds that must pass without any user activity
  172. * before SystemManager starts dispatching 'idle' events.
  173. */
  174. private static const IDLE_THRESHOLD:Number = 1000;
  175. /**
  176. * @private
  177. * The number of milliseconds between each 'idle' event.
  178. */
  179. private static const IDLE_INTERVAL:Number = 100;
  180. //--------------------------------------------------------------------------
  181. //
  182. // Class variables
  183. //
  184. //--------------------------------------------------------------------------
  185. /**
  186. * @private
  187. * An array of SystemManager instances loaded as child app domains
  188. */
  189. mx_internal static var allSystemManagers:Dictionary = new Dictionary(true);
  190. /**
  191. * @private
  192. * The last SystemManager instance loaded as child app domains
  193. */
  194. mx_internal static var lastSystemManager:SystemManager;
  195. //--------------------------------------------------------------------------
  196. //
  197. // Class methods
  198. //
  199. //--------------------------------------------------------------------------
  200. /**
  201. * @private
  202. * If a class wants to be notified when the Application instance
  203. * has been initialized, then it registers a callback here.
  204. * By using a callback mechanism, we avoid adding unwanted
  205. * linker dependencies on classes like HistoryManager and DragManager.
  206. */
  207. mx_internal static function registerInitCallback(initFunction:Function):void
  208. {
  209. if (!allSystemManagers || !lastSystemManager)
  210. {
  211. return;
  212. }
  213. var sm:SystemManager = lastSystemManager;
  214. // If this function is called late (after we're done invoking the
  215. // callback functions for the last time), then just invoke
  216. // the callback function immediately.
  217. if (sm.doneExecutingInitCallbacks)
  218. initFunction(sm);
  219. else
  220. sm.initCallbackFunctions.push(initFunction);
  221. }
  222. //--------------------------------------------------------------------------
  223. //
  224. // Constructor
  225. //
  226. //--------------------------------------------------------------------------
  227. /**
  228. * Constructor.
  229. *
  230. * <p>This is the starting point for all Flex applications.
  231. * This class is set to be the root class of a Flex SWF file.
  232. * Flash Player instantiates an instance of this class,
  233. * causing this constructor to be called.</p>
  234. */
  235. public function SystemManager()
  236. {
  237. super();
  238. // Loaded SWFs don't get a stage right away
  239. // and shouldn't override the main SWF's setting anyway.
  240. if (stage)
  241. {
  242. stage.scaleMode = StageScaleMode.NO_SCALE;
  243. stage.align = StageAlign.TOP_LEFT;
  244. }
  245. // If we don't have a stage then we are not top-level,
  246. // unless there are no other top-level managers, in which
  247. // case we got loaded by a non-Flex shell or are sandboxed.
  248. if (SystemManagerGlobals.topLevelSystemManagers.length > 0 && !stage)
  249. topLevel = false;
  250. if (!stage)
  251. isStageRoot = false;
  252. if (topLevel)
  253. SystemManagerGlobals.topLevelSystemManagers.push(this);
  254. lastSystemManager = this;
  255. var compiledLocales:Array = info()["compiledLocales"];
  256. ResourceBundle.mx_internal::locale =
  257. compiledLocales != null && compiledLocales.length > 0 ?
  258. compiledLocales[0] :
  259. "en_US";
  260. executeCallbacks();
  261. // Make sure to stop the playhead on the current frame.
  262. stop();
  263. // Add safeguard in case bug 129782 shows up again.
  264. if (topLevel && currentFrame != 1)
  265. {
  266. throw new Error("The SystemManager constructor was called when the currentFrame was at " + currentFrame +
  267. " Please add this SWF to bug 129782.");
  268. }
  269. // Listen for the last frame (param is 0-indexed) to be executed.
  270. //addFrameScript(totalFrames - 1, frameEndHandler);
  271. if (root && root.loaderInfo)
  272. root.loaderInfo.addEventListener(Event.INIT, initHandler);
  273. }
  274. /**
  275. * @private
  276. */
  277. private function deferredNextFrame():void
  278. {
  279. if (currentFrame + 1 > totalFrames)
  280. return;
  281. if (currentFrame + 1 <= framesLoaded)
  282. {
  283. nextFrame();
  284. }
  285. else
  286. {
  287. // Next frame isn't baked yet, so we'll check back...
  288. nextFrameTimer = new Timer(100);
  289. nextFrameTimer.addEventListener(TimerEvent.TIMER,
  290. nextFrameTimerHandler);
  291. nextFrameTimer.start();
  292. }
  293. }
  294. //--------------------------------------------------------------------------
  295. //
  296. // Variables
  297. //
  298. //--------------------------------------------------------------------------
  299. /**
  300. * @private
  301. * This flag remembers whether we're going to call executeCallbacks again
  302. */
  303. private var doneExecutingInitCallbacks:Boolean = false;
  304. /**
  305. * @private
  306. * This array stores pointers to all the init callback functions for this
  307. * system manager.
  308. * See registerInitCallback() for more information.
  309. */
  310. private var initCallbackFunctions:Array = [];
  311. /**
  312. * @private
  313. */
  314. private var initialized:Boolean = false;
  315. /**
  316. * @private
  317. * Whether we are in the top-level list or not;
  318. * top-level means we are the highest level SystemManager
  319. * for this stage.
  320. */
  321. mx_internal var topLevel:Boolean = true;
  322. /**
  323. * @private
  324. * Whether we are the stage root or not.
  325. * We are only the stage root if we were the root
  326. * of the first SWF that got loaded by the player.
  327. * Otherwise we could be top level but not stage root
  328. * if we are loaded by some other non-Flex shell
  329. * or are sandboxed.
  330. */
  331. private var isStageRoot:Boolean = true;
  332. /**
  333. * @private
  334. * Whether we are the first SWF loaded into a bootstrap
  335. * and therefore, the topLevelRoot
  336. */
  337. private var isBootstrapRoot:Boolean = false;
  338. /**
  339. * @private
  340. * If we're not top level, then we delegate many things
  341. * to the top level SystemManager.
  342. */
  343. private var _topLevelSystemManager:ISystemManager;
  344. /**
  345. * cached value of the stage.
  346. */
  347. private var _stage:Stage;
  348. /**
  349. * Depth of this object in the containment hierarchy.
  350. * This number is used by the measurement and layout code.
  351. */
  352. mx_internal var nestLevel:int = 0;
  353. /**
  354. * @private
  355. */
  356. private var rslSizes:Array = null;
  357. /**
  358. * @private
  359. * A reference to the preloader.
  360. */
  361. private var preloader:Preloader;
  362. /**
  363. * @private
  364. * The mouseCatcher is the 0th child of the SystemManager,
  365. * behind the application, which is child 1.
  366. * It is the same size as the stage and is filled with
  367. * transparent pixels; i.e., they've been drawn, but with alpha 0.
  368. *
  369. * Its purpose is to make every part of the stage
  370. * able to detect the mouse.
  371. * For example, a Button puts a mouseUp handler on the SystemManager
  372. * in order to capture mouseUp events that occur outside the Button.
  373. * But if the children of the SystemManager don't have "drawn-on"
  374. * pixels everywhere, the player won't dispatch the mouseUp.
  375. * We can't simply fill the SystemManager itself with
  376. * transparent pixels, because the player's pixel detection
  377. * logic doesn't look at pixels drawn into the root DisplayObject.
  378. *
  379. * Here is an example of what would happen without the mouseCatcher:
  380. * Run a fixed-size Application (e.g. width="600" height="600")
  381. * in the standalone player. Make the player window larger
  382. * to reveal part of the stage. Press a Button, drag off it
  383. * into the stage area, and release the mouse button.
  384. * Without the mouseCatcher, the Button wouldn't return to its "up" state.
  385. */
  386. private var mouseCatcher:Sprite;
  387. /**
  388. * @private
  389. * The top level window.
  390. */
  391. mx_internal var topLevelWindow:IUIComponent;
  392. /**
  393. * @private
  394. * List of top level windows.
  395. */
  396. private var forms:Array = [];
  397. /**
  398. * @private
  399. * The current top level window.
  400. *
  401. * Will be of type IFocusManagerContainer if the form
  402. * in the top-level system manager's application domain
  403. * or a child of that application domain. Otherwise the
  404. * form will be of type RemotePopUp.
  405. */
  406. private var form:Object;
  407. /**
  408. * @private
  409. * Number of frames since the last mouse or key activity.
  410. */
  411. mx_internal var idleCounter:int = 0;
  412. /**
  413. * @private
  414. * The Timer used to determine when to dispatch idle events.
  415. */
  416. private var idleTimer:Timer;
  417. /**
  418. * @private
  419. * A timer used when it is necessary to wait before incrementing the frame
  420. */
  421. private var nextFrameTimer:Timer = null;
  422. /**
  423. * @private
  424. * Track which frame was last processed
  425. */
  426. private var lastFrame:int;
  427. //--------------------------------------------------------------------------
  428. //
  429. // Overridden properties: DisplayObject
  430. //
  431. //--------------------------------------------------------------------------
  432. //----------------------------------
  433. // height
  434. //----------------------------------
  435. /**
  436. * @private
  437. */
  438. private var _height:Number;
  439. /**
  440. * The height of this object. For the SystemManager
  441. * this should always be the width of the stage unless the application was loaded
  442. * into another application. If the application was not loaded
  443. * into another application, setting this value has no effect.
  444. */
  445. override public function get height():Number
  446. {
  447. return _height;
  448. }
  449. //----------------------------------
  450. // stage
  451. //----------------------------------
  452. /**
  453. * @private
  454. * get the main stage if we're loaded into another swf in the same sandbox
  455. */
  456. override public function get stage():Stage
  457. {
  458. if (_stage)
  459. return _stage;
  460. var s:Stage = super.stage;
  461. if (s)
  462. {
  463. _stage = s;
  464. return s;
  465. }
  466. if (!topLevel && _topLevelSystemManager)
  467. {
  468. _stage = _topLevelSystemManager.stage;
  469. return _stage;
  470. }
  471. // Case for version skew, we are a top level system manager, but
  472. // a child of the top level root system manager and we have access
  473. // to the stage.
  474. if (!isStageRoot && topLevel)
  475. {
  476. var root:DisplayObject = getTopLevelRoot();
  477. if (root)
  478. {
  479. _stage = root.stage;
  480. return _stage;
  481. }
  482. }
  483. return null;
  484. }
  485. //----------------------------------
  486. // width
  487. //----------------------------------
  488. /**
  489. * @private
  490. */
  491. private var _width:Number;
  492. /**
  493. * The width of this object. For the SystemManager
  494. * this should always be the width of the stage unless the application was loaded
  495. * into another application. If the application was not loaded
  496. * into another application, setting this value will have no effect.
  497. */
  498. override public function get width():Number
  499. {
  500. return _width;
  501. }
  502. //--------------------------------------------------------------------------
  503. //
  504. // Overridden properties: DisplayObjectContainer
  505. //
  506. //--------------------------------------------------------------------------
  507. //----------------------------------
  508. // numChildren
  509. //----------------------------------
  510. /**
  511. * The number of non-floating windows. This is the main application window
  512. * plus any other windows added to the SystemManager that are not popups,
  513. * tooltips or cursors.
  514. */
  515. override public function get numChildren():int
  516. {
  517. return noTopMostIndex - applicationIndex;
  518. }
  519. //--------------------------------------------------------------------------
  520. //
  521. // Properties
  522. //
  523. //--------------------------------------------------------------------------
  524. //----------------------------------
  525. // application
  526. //----------------------------------
  527. /**
  528. * The application parented by this SystemManager.
  529. * SystemManagers create an instance of an Application
  530. * even if they are loaded into another Application.
  531. * Thus, this may not match mx.core.Application.application
  532. * if the SWF has been loaded into another application.
  533. * <p>Note that this property is not typed as mx.core.Application
  534. * because of load-time performance considerations
  535. * but can be coerced into an mx.core.Application.</p>
  536. */
  537. public function get application():IUIComponent
  538. {
  539. return IUIComponent(_document);
  540. }
  541. //----------------------------------
  542. // applicationIndex
  543. //----------------------------------
  544. /**
  545. * @private
  546. * Storage for the applicationIndex property.
  547. */
  548. private var _applicationIndex:int = 1;
  549. /**
  550. * @private
  551. * The index of the main mx.core.Application window, which is
  552. * effectively its z-order.
  553. */
  554. mx_internal function get applicationIndex():int
  555. {
  556. return _applicationIndex;
  557. }
  558. /**
  559. * @private
  560. */
  561. mx_internal function set applicationIndex(value:int):void
  562. {
  563. _applicationIndex = value;
  564. }
  565. //----------------------------------
  566. // bridgeToFocusManager
  567. //----------------------------------
  568. /**
  569. * @private
  570. * Map a bridge to a FocusManager.
  571. * This dictionary contains both the focus managers for this document as
  572. * well as focus managers that are in documents contained inside of pop
  573. * ups, if the system manager in that pop up requires a bridge to
  574. * communicate with this system manager.
  575. *
  576. * The returned object is an object of type IFocusManager.
  577. */
  578. private var _bridgeToFocusManager:Dictionary;
  579. /**
  580. * @private
  581. *
  582. * System Managers in child application domains use their parent's
  583. * bridgeToFocusManager's Dictionary. The swfBridgeGroup property
  584. * is maintained in the same way.
  585. */
  586. mx_internal function get bridgeToFocusManager():Dictionary
  587. {
  588. if (topLevel)
  589. return _bridgeToFocusManager;
  590. else if (topLevelSystemManager)
  591. return SystemManager(topLevelSystemManager).bridgeToFocusManager;
  592. return null;
  593. }
  594. mx_internal function set bridgeToFocusManager(bridgeToFMDictionary:Dictionary):void
  595. {
  596. if (topLevel)
  597. _bridgeToFocusManager = bridgeToFMDictionary;
  598. else if (topLevelSystemManager)
  599. SystemManager(topLevelSystemManager).bridgeToFocusManager = bridgeToFMDictionary;
  600. }
  601. //----------------------------------
  602. // cursorChildren
  603. //----------------------------------
  604. /**
  605. * @private
  606. * Storage for the cursorChildren property.
  607. */
  608. private var _cursorChildren:SystemChildrenList;
  609. /**
  610. * @inheritDoc
  611. */
  612. public function get cursorChildren():IChildList
  613. {
  614. if (!topLevel)
  615. return _topLevelSystemManager.cursorChildren;
  616. if (!_cursorChildren)
  617. {
  618. _cursorChildren = new SystemChildrenList(this,
  619. new QName(mx_internal, "toolTipIndex"),
  620. new QName(mx_internal, "cursorIndex"));
  621. }
  622. return _cursorChildren;
  623. }
  624. //----------------------------------
  625. // cursorIndex
  626. //----------------------------------
  627. /**
  628. * @private
  629. * Storage for the toolTipIndex property.
  630. */
  631. private var _cursorIndex:int = 0;
  632. /**
  633. * @private
  634. * The index of the highest child that is a cursor.
  635. */
  636. mx_internal function get cursorIndex():int
  637. {
  638. return _cursorIndex;
  639. }
  640. /**
  641. * @private
  642. */
  643. mx_internal function set cursorIndex(value:int):void
  644. {
  645. var delta:int = value - _cursorIndex;
  646. _cursorIndex = value;
  647. }
  648. //----------------------------------
  649. // document
  650. //----------------------------------
  651. /**
  652. * @private
  653. * Storage for the document property.
  654. */
  655. private var _document:Object;
  656. /**
  657. * @inheritDoc
  658. */
  659. public function get document():Object
  660. {
  661. return _document;
  662. }
  663. /**
  664. * @private
  665. */
  666. public function set document(value:Object):void
  667. {
  668. _document = value;
  669. }
  670. //----------------------------------
  671. // embeddedFontList
  672. //----------------------------------
  673. /**
  674. * @private
  675. * Storage for the fontList property.
  676. */
  677. private var _fontList:Object = null;
  678. /**
  679. * A table of embedded fonts in this application. The
  680. * object is a table indexed by the font name.
  681. */
  682. public function get embeddedFontList():Object
  683. {
  684. if (_fontList == null)
  685. {
  686. _fontList = {};
  687. var o:Object = info()["fonts"];
  688. var p:String;
  689. for (p in o)
  690. {
  691. _fontList[p] = o[p];
  692. }
  693. // FIXME: font rules across SWF boundaries have not been finalized!
  694. // Top level systemManager may not be defined if SWF is loaded
  695. // as a background image in download progress bar.
  696. if (!topLevel && _topLevelSystemManager)
  697. {
  698. var fl:Object = _topLevelSystemManager.embeddedFontList;
  699. for (p in fl)
  700. {
  701. _fontList[p] = fl[p];
  702. }
  703. }
  704. }
  705. return _fontList;
  706. }
  707. //----------------------------------
  708. // explicitHeight
  709. //----------------------------------
  710. /**
  711. * @private
  712. */
  713. private var _explicitHeight:Number;
  714. /**
  715. * The explicit width of this object. For the SystemManager
  716. * this should always be NaN unless the application was loaded
  717. * into another application. If the application was not loaded
  718. * into another application, setting this value has no effect.
  719. */
  720. public function get explicitHeight():Number
  721. {
  722. return _explicitHeight;
  723. }
  724. /**
  725. * @private
  726. */
  727. public function set explicitHeight(value:Number):void
  728. {
  729. _explicitHeight = value;
  730. }
  731. //----------------------------------
  732. // explicitWidth
  733. //----------------------------------
  734. /**
  735. * @private
  736. */
  737. private var _explicitWidth:Number;
  738. /**
  739. * The explicit width of this object. For the SystemManager
  740. * this should always be NaN unless the application was loaded
  741. * into another application. If the application was not loaded
  742. * into another application, setting this value has no effect.
  743. */
  744. public function get explicitWidth():Number
  745. {
  746. return _explicitWidth;
  747. }
  748. /**
  749. * @private
  750. */
  751. public function set explicitWidth(value:Number):void
  752. {
  753. _explicitWidth = value;
  754. }
  755. //----------------------------------
  756. // focusPane
  757. //----------------------------------
  758. /**
  759. * @private
  760. */
  761. private var _focusPane:Sprite;
  762. /**
  763. * @copy mx.core.UIComponent#focusPane
  764. */
  765. public function get focusPane():Sprite
  766. {
  767. return _focusPane;
  768. }
  769. /**
  770. * @private
  771. */
  772. public function set focusPane(value:Sprite):void
  773. {
  774. if (value)
  775. {
  776. addChild(value);
  777. value.x = 0;
  778. value.y = 0;
  779. value.scrollRect = null;
  780. _focusPane = value;
  781. }
  782. else
  783. {
  784. removeChild(_focusPane);
  785. _focusPane = null;
  786. }
  787. }
  788. //----------------------------------
  789. // info
  790. //----------------------------------
  791. /**
  792. * @private
  793. */
  794. public function info():Object
  795. {
  796. return {};
  797. }
  798. //----------------------------------
  799. // measuredHeight
  800. //----------------------------------
  801. /**
  802. * The measuredHeight is the explicit or measuredHeight of
  803. * the main mx.core.Application window
  804. * or the starting height of the SWF if the main window
  805. * has not yet been created or does not exist.
  806. */
  807. public function get measuredHeight():Number
  808. {
  809. return topLevelWindow ?
  810. topLevelWindow.getExplicitOrMeasuredHeight() :
  811. loaderInfo.height;
  812. }
  813. //----------------------------------
  814. // measuredWidth
  815. //----------------------------------
  816. /**
  817. * The measuredWidth is the explicit or measuredWidth of
  818. * the main mx.core.Application window,
  819. * or the starting width of the SWF if the main window
  820. * has not yet been created or does not exist.
  821. */
  822. public function get measuredWidth():Number
  823. {
  824. return topLevelWindow ?
  825. topLevelWindow.getExplicitOrMeasuredWidth() :
  826. loaderInfo.width;
  827. }
  828. //----------------------------------
  829. // noTopMostIndex
  830. //----------------------------------
  831. /**
  832. * @private
  833. * Storage for the noTopMostIndex property.
  834. */
  835. private var _noTopMostIndex:int = 0;
  836. /**
  837. * @private
  838. * The index of the highest child that isn't a topmost/popup window
  839. */
  840. mx_internal function get noTopMostIndex():int
  841. {
  842. return _noTopMostIndex;
  843. }
  844. /**
  845. * @private
  846. */
  847. mx_internal function set noTopMostIndex(value:int):void
  848. {
  849. var delta:int = value - _noTopMostIndex;
  850. _noTopMostIndex = value;
  851. topMostIndex += delta;
  852. }
  853. //----------------------------------
  854. // $numChildren
  855. //----------------------------------
  856. /**
  857. * @private
  858. * This property allows access to the Player's native implementation
  859. * of the numChildren property, which can be useful since components
  860. * can override numChildren and thereby hide the native implementation.
  861. * Note that this "base property" is final and cannot be overridden,
  862. * so you can count on it to reflect what is happening at the player level.
  863. */
  864. mx_internal final function get $numChildren():int
  865. {
  866. return super.numChildren;
  867. }
  868. //----------------------------------
  869. // numModalWindows
  870. //----------------------------------
  871. /**
  872. * @private
  873. * Storage for the numModalWindows property.
  874. */
  875. private var _numModalWindows:int = 0;
  876. /**
  877. * The number of modal windows. Modal windows don't allow
  878. * clicking in another windows which would normally
  879. * activate the FocusManager in that window. The PopUpManager
  880. * modifies this count as it creates and destroys modal windows.
  881. */
  882. public function get numModalWindows():int
  883. {
  884. return _numModalWindows;
  885. }
  886. /**
  887. * @private
  888. */
  889. public function set numModalWindows(value:int):void
  890. {
  891. _numModalWindows = value;
  892. }
  893. //----------------------------------
  894. // preloaderBackgroundAlpha
  895. //----------------------------------
  896. /**
  897. * The background alpha used by the child of the preloader.
  898. */
  899. public function get preloaderBackgroundAlpha():Number
  900. {
  901. return info()["backgroundAlpha"];
  902. }
  903. //----------------------------------
  904. // preloaderBackgroundColor
  905. //----------------------------------
  906. /**
  907. * The background color used by the child of the preloader.
  908. */
  909. public function get preloaderBackgroundColor():uint
  910. {
  911. var value:* = info()["backgroundColor"];
  912. if (value == undefined)
  913. return StyleManager.NOT_A_COLOR;
  914. else
  915. return StyleManager.getColorName(value);
  916. }
  917. //----------------------------------
  918. // preloaderBackgroundImage
  919. //----------------------------------
  920. /**
  921. * The background color used by the child of the preloader.
  922. */
  923. public function get preloaderBackgroundImage():Object
  924. {
  925. return info()["backgroundImage"];
  926. }
  927. //----------------------------------
  928. // preloaderBackgroundSize
  929. //----------------------------------
  930. /**
  931. * The background size used by the child of the preloader.
  932. */
  933. public function get preloaderBackgroundSize():String
  934. {
  935. return info()["backgroundSize"];
  936. }
  937. //----------------------------------
  938. // popUpChildren
  939. //----------------------------------
  940. /**
  941. * @private
  942. * Storage for the popUpChildren property.
  943. */
  944. private var _popUpChildren:SystemChildrenList;
  945. /**
  946. * @inheritDoc
  947. */
  948. public function get popUpChildren():IChildList
  949. {
  950. if (!topLevel)
  951. return _topLevelSystemManager.popUpChildren;
  952. if (!_popUpChildren)
  953. {
  954. _popUpChildren = new SystemChildrenList(this,
  955. new QName(mx_internal, "noTopMostIndex"),
  956. new QName(mx_internal, "topMostIndex"));
  957. }
  958. return _popUpChildren;
  959. }
  960. //----------------------------------
  961. // rawChildren
  962. //----------------------------------
  963. /**
  964. * @private
  965. * Storage for the rawChildren property.
  966. */
  967. private var _rawChildren:SystemRawChildrenList;
  968. /**
  969. * @inheritDoc
  970. */
  971. public function get rawChildren():IChildList
  972. {
  973. //if (!topLevel)
  974. // return _topLevelSystemManager.rawChildren;
  975. if (!_rawChildren)
  976. _rawChildren = new SystemRawChildrenList(this);
  977. return _rawChildren;
  978. }
  979. //--------------------------------------------------------------------------
  980. // sandbox bridge group
  981. //--------------------------------------------------------------------------
  982. /**
  983. * @private
  984. *
  985. * Represents the related parent and child sandboxs this SystemManager may
  986. * communicate with.
  987. */
  988. private var _swfBridgeGroup:ISWFBridgeGroup;
  989. public function get swfBridgeGroup():ISWFBridgeGroup
  990. {
  991. if (topLevel)
  992. return _swfBridgeGroup;
  993. else if (topLevelSystemManager)
  994. return topLevelSystemManager.swfBridgeGroup;
  995. return null;
  996. }
  997. public function set swfBridgeGroup(bridgeGroup:ISWFBridgeGroup):void
  998. {
  999. if (topLevel)
  1000. _swfBridgeGroup = bridgeGroup;
  1001. else if (topLevelSystemManager)
  1002. SystemManager(topLevelSystemManager).swfBridgeGroup = bridgeGroup;
  1003. }
  1004. //--------------------------------------------------------------------------
  1005. // screen
  1006. //--------------------------------------------------------------------------
  1007. /**
  1008. * @private
  1009. * Storage for the screen property.
  1010. */
  1011. private var _screen:Rectangle;
  1012. /**
  1013. * @inheritDoc
  1014. */
  1015. public function get screen():Rectangle
  1016. {
  1017. if (!_screen)
  1018. Stage_resizeHandler();
  1019. if (!isStageRoot)
  1020. {
  1021. Stage_resizeHandler();
  1022. }
  1023. return _screen;
  1024. }
  1025. //----------------------------------
  1026. // toolTipChildren
  1027. //----------------------------------
  1028. /**
  1029. * @private
  1030. * Storage for the toolTipChildren property.
  1031. */
  1032. private var _toolTipChildren:SystemChildrenList;
  1033. /**
  1034. * @inheritDoc
  1035. */
  1036. public function get toolTipChildren():IChildList
  1037. {
  1038. if (!topLevel)
  1039. return _topLevelSystemManager.toolTipChildren;
  1040. if (!_toolTipChildren)
  1041. {
  1042. _toolTipChildren = new SystemChildrenList(this,
  1043. new QName(mx_internal, "topMostIndex"),
  1044. new QName(mx_internal, "toolTipIndex"));
  1045. }
  1046. return _toolTipChildren;
  1047. }
  1048. //----------------------------------
  1049. // toolTipIndex
  1050. //----------------------------------
  1051. /**
  1052. * @private
  1053. * Storage for the toolTipIndex property.
  1054. */
  1055. private var _toolTipIndex:int = 0;
  1056. /**
  1057. * @private
  1058. * The index of the highest child that is a tooltip
  1059. */
  1060. mx_internal function get toolTipIndex():int
  1061. {
  1062. return _toolTipIndex;
  1063. }
  1064. /**
  1065. * @private
  1066. */
  1067. mx_internal function set toolTipIndex(value:int):void
  1068. {
  1069. var delta:int = value - _toolTipIndex;
  1070. _toolTipIndex = value;
  1071. cursorIndex += delta;
  1072. }
  1073. //----------------------------------
  1074. // topLevelSystemManager
  1075. //----------------------------------
  1076. /**
  1077. * Returns the SystemManager responsible for the application window. This will be
  1078. * the same SystemManager unless this application has been loaded into another
  1079. * application.
  1080. */
  1081. public function get topLevelSystemManager():ISystemManager
  1082. {
  1083. if (topLevel)
  1084. return this;
  1085. return _topLevelSystemManager;
  1086. }
  1087. //----------------------------------
  1088. // topMostIndex
  1089. //----------------------------------
  1090. /**
  1091. * @private
  1092. * Storage for the topMostIndex property.
  1093. */
  1094. private var _topMostIndex:int = 0;
  1095. /**
  1096. * @private
  1097. * The index of the highest child that is a topmost/popup window
  1098. */
  1099. mx_internal function get topMostIndex():int
  1100. {
  1101. return _topMostIndex;
  1102. }
  1103. mx_internal function set topMostIndex(value:int):void
  1104. {
  1105. var delta:int = value - _topMostIndex;
  1106. _topMostIndex = value;
  1107. toolTipIndex += delta;
  1108. }
  1109. //--------------------------------------------------------------------------
  1110. //
  1111. // Properties: ISWFBridgeProvider
  1112. //
  1113. //--------------------------------------------------------------------------
  1114. /**
  1115. * @inheritDoc
  1116. */
  1117. public function get swfBridge():IEventDispatcher
  1118. {
  1119. if (swfBridgeGroup)
  1120. return swfBridgeGroup.parentBridge;
  1121. return null;
  1122. }
  1123. /**
  1124. * @inheritDoc
  1125. */
  1126. public function get childAllowsParent():Boolean
  1127. {
  1128. try
  1129. {
  1130. return loaderInfo.childAllowsParent;
  1131. }
  1132. catch (error:Error)
  1133. {
  1134. //Error #2099: The loading object is not sufficiently loaded to provide this information.
  1135. }
  1136. return false; // assume the worst
  1137. }
  1138. /**
  1139. * @inheritDoc
  1140. */
  1141. public function get parentAllowsChild():Boolean
  1142. {
  1143. try
  1144. {
  1145. return loaderInfo.parentAllowsChild;
  1146. }
  1147. catch (error:Error)
  1148. {
  1149. //Error #2099: The loading object is not sufficiently loaded to provide this information.
  1150. }
  1151. return false; // assume the worst
  1152. }
  1153. /**
  1154. * @private
  1155. *
  1156. * true if redipatching a resize event.
  1157. */
  1158. private var isDispatchingResizeEvent:Boolean;
  1159. /**
  1160. * @private
  1161. *
  1162. * Used to locate untrusted forms. Maps string ids to Objects.
  1163. * The object make be the SystemManagerProxy of a form or it may be
  1164. * the bridge to the child application where the object lives.
  1165. */
  1166. private var idToPlaceholder:Object;
  1167. private var eventProxy:EventProxy;
  1168. private var weakReferenceProxies:Dictionary = new Dictionary(true);
  1169. private var strongReferenceProxies:Dictionary = new Dictionary(false);
  1170. //--------------------------------------------------------------------------
  1171. //
  1172. // Overridden methods: EventDispatcher
  1173. //
  1174. //--------------------------------------------------------------------------
  1175. /**
  1176. * @private
  1177. * Only create idle events if someone is listening.
  1178. */
  1179. override public function addEventListener(type:String, listener:Function,
  1180. useCapture:Boolean = false,
  1181. priority:int = 0,
  1182. useWeakReference:Boolean = false):void
  1183. {
  1184. // These two events will dispatched to applications in sandboxes.
  1185. if (type == FlexEvent.RENDER || type == FlexEvent.ENTER_FRAME)
  1186. {
  1187. if (type == FlexEvent.RENDER)
  1188. type = Event.RENDER;
  1189. else
  1190. type = Event.ENTER_FRAME;
  1191. try
  1192. {
  1193. if (stage)
  1194. stage.addEventListener(type, listener, useCapture, priority, useWeakReference);
  1195. else
  1196. super.addEventListener(type, listener, useCapture, priority, useWeakReference);
  1197. }
  1198. catch (error:SecurityError)
  1199. {
  1200. super.addEventListener(type, listener, useCapture, priority, useWeakReference);
  1201. }
  1202. if (stage && type == Event.RENDER)
  1203. stage.invalidate();
  1204. return;
  1205. }
  1206. if (type == MouseEvent.MOUSE_MOVE || type == MouseEvent.MOUSE_UP || type == MouseEvent.MOUSE_DOWN
  1207. || type == Event.ACTIVATE || type == Event.DEACTIVATE)
  1208. {
  1209. // also listen to stage if allowed
  1210. try
  1211. {
  1212. if (stage)
  1213. {
  1214. var newListener:StageEventProxy = new StageEventProxy(listener);
  1215. stage.addEventListener(type, newListener.stageListener, false, priority, useWeakReference);
  1216. if (useWeakReference)
  1217. weakReferenceProxies[listener] = newListener;
  1218. else
  1219. strongReferenceProxies[listener] = newListener;
  1220. }
  1221. }
  1222. catch (error:SecurityError)
  1223. {
  1224. }
  1225. }
  1226. if (hasSWFBridges() || SystemManagerGlobals.topLevelSystemManagers.length > 1)
  1227. {
  1228. if (!eventProxy)
  1229. {
  1230. eventProxy = new EventProxy(this);
  1231. }
  1232. var actualType:String = EventUtil.sandboxMouseEventMap[type];
  1233. if (actualType)
  1234. {
  1235. if (isTopLevelRoot())
  1236. {
  1237. stage.addEventListener(MouseEvent.MOUSE_MOVE, resetMouseCursorTracking, true, EventPriority.CURSOR_MANAGEMENT + 1, true);
  1238. addEventListenerToSandboxes(SandboxMouseEvent.MOUSE_MOVE_SOMEWHERE, resetMouseCursorTracking, true, EventPriority.CURSOR_MANAGEMENT + 1, true);
  1239. }
  1240. else
  1241. {
  1242. super.addEventListener(MouseEvent.MOUSE_MOVE, resetMouseCursorTracking, true, EventPriority.CURSOR_MANAGEMENT + 1, true);
  1243. }
  1244. addEventListenerToSandboxes(type, sandboxMouseListener, useCapture, priority, useWeakReference);
  1245. if (!SystemManagerGlobals.changingListenersInOtherSystemManagers)
  1246. addEventListenerToOtherSystemManagers(type, otherSystemManagerMouseListener, useCapture, priority, useWeakReference)
  1247. if (getSandboxRoot() == this)
  1248. super.addEventListener(actualType, eventProxy.marshalListener,
  1249. useCapture, priority, useWeakReference);
  1250. // Set useCapture to false because we will never see an event
  1251. // marshalled in the capture phase.
  1252. super.addEventListener(type, listener, false, priority, useWeakReference);
  1253. return;
  1254. }
  1255. }
  1256. // When the first listener registers for 'idle' events,
  1257. // create a Timer that will fire every IDLE_INTERVAL.
  1258. if (type == FlexEvent.IDLE && !idleTimer)
  1259. {
  1260. idleTimer = new Timer(IDLE_INTERVAL);
  1261. idleTimer.addEventListener(TimerEvent.TIMER,
  1262. idleTimer_timerHandler);
  1263. idleTimer.start();
  1264. // Make sure we get all activity
  1265. // in case someone calls stopPropagation().
  1266. addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler, true);
  1267. addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler, true);
  1268. }
  1269. super.addEventListener(type, listener, useCapture, priority, useWeakReference);
  1270. }
  1271. /**
  1272. * @private
  1273. *
  1274. * Test if this system manager has any sandbox bridges.
  1275. *
  1276. * @return true if there are sandbox bridges, false otherwise.
  1277. */
  1278. private function hasSWFBridges():Boolean
  1279. {
  1280. if (swfBridgeGroup)
  1281. return true;
  1282. return false;
  1283. }
  1284. /**
  1285. * @private
  1286. */
  1287. override public function removeEventListener(type:String, listener:Function,
  1288. useCapture:Boolean = false):void
  1289. {
  1290. // These two events will dispatched to applications in sandboxes.
  1291. if (type == FlexEvent.RENDER || type == FlexEvent.ENTER_FRAME)
  1292. {
  1293. if (type == FlexEvent.RENDER)
  1294. type = Event.RENDER;
  1295. else
  1296. type = Event.ENTER_FRAME;
  1297. try
  1298. {
  1299. // Remove both listeners in case the system manager was added
  1300. // or removed from the stage after the listener was added.
  1301. if (stage)
  1302. stage.removeEventListener(type, listener, useCapture);
  1303. super.removeEventListener(type, listener, useCapture);
  1304. }
  1305. catch (error:SecurityError)
  1306. {
  1307. super.removeEventListener(type, listener, useCapture);
  1308. }
  1309. return;
  1310. }
  1311. if (type == MouseEvent.MOUSE_MOVE || type == MouseEvent.MOUSE_UP || type == MouseEvent.MOUSE_DOWN
  1312. || type == Event.ACTIVATE || type == Event.DEACTIVATE)
  1313. {
  1314. // also listen to stage if allowed
  1315. try
  1316. {
  1317. if (stage)
  1318. {
  1319. var newListener:StageEventProxy = weakReferenceProxies[listener];
  1320. if (!newListener)
  1321. {
  1322. newListener = strongReferenceProxies[listener];
  1323. if (newListener)
  1324. delete strongReferenceProxies[listener];
  1325. }
  1326. if (newListener)
  1327. stage.removeEventListener(type, newListener.stageListener, false);
  1328. }
  1329. }
  1330. catch (error:SecurityError)
  1331. {
  1332. }
  1333. }
  1334. if (hasSWFBridges() || SystemManagerGlobals.topLevelSystemManagers.length > 1)
  1335. {
  1336. var actualType:String = EventUtil.sandboxMouseEventMap[type];
  1337. if (actualType)
  1338. {
  1339. if (getSandboxRoot() == this && eventProxy)
  1340. super.removeEventListener(actualType, eventProxy.marshalListener,
  1341. useCapture);
  1342. if (!SystemManagerGlobals.changingListenersInOtherSystemManagers)
  1343. removeEventListenerFromOtherSystemManagers(type, otherSystemManagerMouseListener, useCapture);
  1344. removeEventListenerFromSandboxes(type, sandboxMouseListener, useCapture);
  1345. super.removeEventListener(type, listener, false);
  1346. return;
  1347. }
  1348. }
  1349. // When the last listener unregisters for 'idle' events,
  1350. // stop and release the Timer.
  1351. if (type == FlexEvent.IDLE)
  1352. {
  1353. super.removeEventListener(type, listener, useCapture);
  1354. if (!hasEventListener(FlexEvent.IDLE) && idleTimer)
  1355. {
  1356. idleTimer.stop();
  1357. idleTimer = null;
  1358. removeEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
  1359. removeEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
  1360. }
  1361. }
  1362. else
  1363. {
  1364. super.removeEventListener(type, listener, useCapture);
  1365. }
  1366. }
  1367. //--------------------------------------------------------------------------
  1368. //
  1369. // Overridden methods: DisplayObjectContainer
  1370. //
  1371. //--------------------------------------------------------------------------
  1372. /**
  1373. * @private
  1374. */
  1375. override public function addChild(child:DisplayObject):DisplayObject
  1376. {
  1377. // Adjust the partition indexes
  1378. // before the "added" event is dispatched.
  1379. noTopMostIndex++;
  1380. return rawChildren_addChildAt(child, noTopMostIndex - 1);
  1381. }
  1382. /**
  1383. * @private
  1384. */
  1385. override public function addChildAt(child:DisplayObject,
  1386. index:int):DisplayObject
  1387. {
  1388. // Adjust the partition indexes
  1389. // before the "added" event is dispatched.
  1390. noTopMostIndex++;
  1391. return rawChildren_addChildAt(child, applicationIndex + index);
  1392. }
  1393. /**
  1394. * @private
  1395. *
  1396. * Used by SystemManagerProxy to add a mouse catcher as a child.
  1397. */
  1398. mx_internal final function $addChildAt(child:DisplayObject,
  1399. index:int):DisplayObject
  1400. {
  1401. return super.addChildAt(child, index);
  1402. }
  1403. /**
  1404. * @private
  1405. *
  1406. * Companion to $addChildAt.
  1407. */
  1408. mx_internal final function $removeChildAt(index:int):DisplayObject
  1409. {
  1410. return super.removeChildAt(index);
  1411. }
  1412. /**
  1413. * @private
  1414. */
  1415. override public function removeChild(child:DisplayObject):DisplayObject
  1416. {
  1417. // Adjust the partition indexes
  1418. // before the "removed" event is dispatched.
  1419. noTopMostIndex--;
  1420. return rawChildren_removeChild(child);
  1421. }
  1422. /**
  1423. * @private
  1424. */
  1425. override public function removeChildAt(index:int):DisplayObject
  1426. {
  1427. // Adjust the partition indexes
  1428. // before the "removed" event is dispatched.
  1429. noTopMostIndex--;
  1430. return rawChildren_removeChildAt(applicationIndex + index);
  1431. }
  1432. /**
  1433. * @private
  1434. */
  1435. override public function getChildAt(index:int):DisplayObject
  1436. {
  1437. return super.getChildAt(applicationIndex + index)
  1438. }
  1439. /**
  1440. * @private
  1441. */
  1442. override public function getChildByName(name:String):DisplayObject
  1443. {
  1444. return super.getChildByName(name);
  1445. }
  1446. /**
  1447. * @private
  1448. */
  1449. override public function getChildIndex(child:DisplayObject):int
  1450. {
  1451. return super.getChildIndex(child) - applicationIndex;
  1452. }
  1453. /**
  1454. * @private
  1455. */
  1456. override public function setChildIndex(child:DisplayObject, newIndex:int):void
  1457. {
  1458. super.setChildIndex(child, applicationIndex + newIndex)
  1459. }
  1460. /**
  1461. * @private
  1462. */
  1463. override public function getObjectsUnderPoint(point:Point):Array
  1464. {
  1465. var children:Array = [];
  1466. // Get all the children that aren't tooltips and cursors.
  1467. var n:int = topMostIndex;
  1468. for (var i:int = 0; i < n; i++)
  1469. {
  1470. var child:DisplayObject = super.getChildAt(i);
  1471. if (child is DisplayObjectContainer)
  1472. {
  1473. var temp:Array =
  1474. DisplayObjectContainer(child).getObjectsUnderPoint(point);
  1475. if (temp)
  1476. children = children.concat(temp);
  1477. }
  1478. }
  1479. return children;
  1480. }
  1481. /**
  1482. * @private
  1483. */
  1484. override public function contains(child:DisplayObject):Boolean
  1485. {
  1486. if (super.contains(child))
  1487. {
  1488. if (child.parent == this)
  1489. {
  1490. var childIndex:int = super.getChildIndex(child);
  1491. if (childIndex < noTopMostIndex)
  1492. return true;
  1493. }
  1494. else
  1495. {
  1496. for (var i:int = 0; i < noTopMostIndex; i++)
  1497. {
  1498. var myChild:DisplayObject = super.getChildAt(i);
  1499. if (myChild is IRawChildrenContainer)
  1500. {
  1501. if (IRawChildrenContainer(myChild).rawChildren.contains(child))
  1502. return true;
  1503. }
  1504. if (myChild is DisplayObjectContainer)
  1505. {
  1506. if (DisplayObjectContainer(myChild).contains(child))
  1507. return true;
  1508. }
  1509. }
  1510. }
  1511. }
  1512. return false;
  1513. }
  1514. //--------------------------------------------------------------------------
  1515. //
  1516. // Methods: Initialization
  1517. //
  1518. //--------------------------------------------------------------------------
  1519. /**
  1520. * A factory method that requests an instance of a
  1521. * definition known to the module.
  1522. *
  1523. * You can provide an optional set of parameters to let building
  1524. * factories change what they create based on the
  1525. * input. Passing null indicates that the default definition
  1526. * is created, if possible.
  1527. *
  1528. * This method is overridden in the autogenerated subclass.
  1529. *
  1530. * @param params An optional list of arguments. You can pass
  1531. * any number of arguments, which are then stored in an Array
  1532. * called <code>parameters</code>.
  1533. *
  1534. * @return An instance of the module, or <code>null</code>.
  1535. */
  1536. public function create(... params):Object
  1537. {
  1538. var mainClassName:String = info()["mainClassName"];
  1539. if (mainClassName == null)
  1540. {
  1541. var url:String = loaderInfo.loaderURL;
  1542. var dot:int = url.lastIndexOf(".");
  1543. var slash:int = url.lastIndexOf("/");
  1544. mainClassName = url.substring(slash + 1, dot);
  1545. }
  1546. var mainClass:Class = Class(getDefinitionByName(mainClassName));
  1547. return mainClass ? new mainClass() : null;
  1548. }
  1549. /**
  1550. * @private
  1551. * Creates an instance of the preloader, adds it as a child, and runs it.
  1552. * This is needed by FlexBuilder. Do not modify this function.
  1553. */
  1554. mx_internal function initialize():void
  1555. {
  1556. if (isStageRoot)
  1557. {
  1558. _width = stage.stageWidth;
  1559. _height = stage.stageHeight;
  1560. }
  1561. else
  1562. {
  1563. _width = loaderInfo.width;
  1564. _height = loaderInfo.height;
  1565. }
  1566. // Create an instance of the preloader and add it to the stage
  1567. preloader = new Preloader();
  1568. // Listen for preloader events
  1569. // Once the preloader dispatches initStart, then create the application instance
  1570. preloader.addEventListener(FlexEvent.INIT_PROGRESS,
  1571. preloader_initProgressHandler);
  1572. preloader.addEventListener(FlexEvent.PRELOADER_DONE,
  1573. preloader_preloaderDoneHandler);
  1574. // Add the preloader as a child. Use backing variable because when loaded
  1575. // we redirect public API to parent systemmanager
  1576. if (!_popUpChildren)
  1577. {
  1578. _popUpChildren = new SystemChildrenList(
  1579. this, new QName(mx_internal, "noTopMostIndex"), new QName(mx_internal, "topMostIndex"));
  1580. }
  1581. _popUpChildren.addChild(preloader);
  1582. var rsls:Array = info()["rsls"];
  1583. var cdRsls:Array = info()["cdRsls"];
  1584. var usePreloader:Boolean = true;
  1585. if (info()["usePreloader"] != undefined)
  1586. usePreloader = info()["usePreloader"];
  1587. var preloaderDisplayClass:Class = info()["preloader"] as Class;
  1588. if (usePreloader && !preloaderDisplayClass)
  1589. preloaderDisplayClass = DownloadProgressBar;
  1590. // Put cross-domain RSL information in the RSL list.
  1591. var rslList:Array = [];
  1592. var n:int;
  1593. var i:int;
  1594. if (cdRsls && cdRsls.length > 0)
  1595. {
  1596. var crossDomainRSLItem:Class = Class(getDefinitionByName("mx.core::CrossDomainRSLItem"));
  1597. n = cdRsls.length;
  1598. for (i = 0; i < n; i++)
  1599. {
  1600. // If crossDomainRSLItem is null, then this is a compiler error. It should not be null.
  1601. var cdNode:Object = new crossDomainRSLItem(cdRsls[i]["rsls"],
  1602. cdRsls[i]["policyFiles"],
  1603. cdRsls[i]["digests"],
  1604. cdRsls[i]["types"],
  1605. cdRsls[i]["isSigned"],
  1606. LoaderUtil.normalizeURL(this.loaderInfo));
  1607. rslList.push(cdNode);
  1608. }
  1609. }
  1610. // Append RSL information in the RSL list.
  1611. if (rsls != null && rsls.length > 0)
  1612. {
  1613. n = rsls.length;
  1614. for (i = 0; i < n; i++)
  1615. {
  1616. var node:RSLItem = new RSLItem(rsls[i].url, LoaderUtil.normalizeURL(this.loaderInfo));
  1617. rslList.push(node);
  1618. }
  1619. }
  1620. // Register the ResourceManager class with Singleton early
  1621. // so that we can use the ResourceManager in frame 1.
  1622. // Same with EmbfeddedFontRegistry and StyleManager
  1623. // The other managers get registered with Singleton later,
  1624. // in frame 2, by docFrameHandler().
  1625. Singleton.registerClass("mx.resources::IResourceManager",
  1626. Class(getDefinitionByName("mx.resources::ResourceManagerImpl")));
  1627. var resourceManager:IResourceManager = ResourceManager.getInstance();
  1628. var fontRegistry:EmbeddedFontRegistry; // link in the EmbeddedFontRegistry Class
  1629. Singleton.registerClass("mx.core::IEmbeddedFontRegistry",
  1630. Class(getDefinitionByName("mx.core::EmbeddedFontRegistry")));
  1631. Singleton.registerClass("mx.styles::IStyleManager",
  1632. Class(getDefinitionByName("mx.styles::StyleManagerImpl")));
  1633. Singleton.registerClass("mx.styles::IStyleManager2",
  1634. Class(getDefinitionByName("mx.styles::StyleManagerImpl")));
  1635. // The FlashVars of the SWF's HTML wrapper,
  1636. // or the query parameters of the SWF URL,
  1637. // can specify the ResourceManager's localeChain.
  1638. var localeChainList:String =
  1639. loaderInfo.parameters["localeChain"];
  1640. if (localeChainList != null && localeChainList != "")
  1641. resourceManager.localeChain = localeChainList.split(",");
  1642. // They can also specify a comma-separated list of URLs
  1643. // for resource modules to be preloaded during frame 1.
  1644. var resourceModuleURLList:String =
  1645. loaderInfo.parameters["resourceModuleURLs"];
  1646. var resourceModuleURLs:Array =
  1647. resourceModuleURLList ? resourceModuleURLList.split(",") : null;
  1648. // Initialize the preloader.
  1649. preloader.initialize(
  1650. usePreloader,
  1651. preloaderDisplayClass,
  1652. preloaderBackgroundColor,
  1653. preloaderBackgroundAlpha,
  1654. preloaderBackgroundImage,
  1655. preloaderBackgroundSize,
  1656. isStageRoot ? stage.stageWidth : loaderInfo.width,
  1657. isStageRoot ? stage.stageHeight : loaderInfo.height,
  1658. null,
  1659. null,
  1660. rslList,
  1661. resourceModuleURLs);
  1662. }
  1663. /**
  1664. * @private
  1665. * When this is called, we execute all callbacks queued up to this point.
  1666. */
  1667. private function executeCallbacks():void
  1668. {
  1669. // temporary workaround for player bug. The root class should always
  1670. // be parented or we need some other way to determine
  1671. // our application domain
  1672. if (!parent && parentAllowsChild)
  1673. return;
  1674. while (initCallbackFunctions.length > 0)
  1675. {
  1676. var initFunction:Function = initCallbackFunctions.shift();
  1677. initFunction(this);
  1678. }
  1679. }
  1680. //--------------------------------------------------------------------------
  1681. //
  1682. // Methods: Child management
  1683. //
  1684. //--------------------------------------------------------------------------
  1685. /**
  1686. * @private
  1687. */
  1688. mx_internal function addingChild(child:DisplayObject):void
  1689. {
  1690. var newNestLevel:int = 1;
  1691. // non-top level system managers may not be able to reference their parent if
  1692. // they are a proxy for popups.
  1693. if (!topLevel && parent)
  1694. {
  1695. // non-topLevel SystemManagers are buried by Flash.display.Loader and
  1696. // other non-framework layers so we have to figure out the nestlevel
  1697. // by searching up the parent chain.
  1698. var obj:DisplayObjectContainer = parent.parent;
  1699. while (obj)
  1700. {
  1701. if (obj is ILayoutManagerClient)
  1702. {
  1703. newNestLevel = ILayoutManagerClient(obj).nestLevel + 1;
  1704. break;
  1705. }
  1706. obj = obj.parent;
  1707. }
  1708. }
  1709. nestLevel = newNestLevel;
  1710. if (child is IUIComponent)
  1711. IUIComponent(child).systemManager = this;
  1712. // Local variables for certain classes we need to check against below.
  1713. // This is the backdoor way around linking in the class in question.
  1714. var uiComponentClassName:Class =
  1715. Class(getDefinitionByName("mx.core.UIComponent"));
  1716. // If the document property isn't already set on the child,
  1717. // set it to be the same as this component's document.
  1718. // The document setter will recursively set it on any
  1719. // descendants of the child that exist.
  1720. if (child is IUIComponent &&
  1721. !IUIComponent(child).document)
  1722. {
  1723. IUIComponent(child).document = document;
  1724. }
  1725. // Set the nestLevel of the child to be one greater
  1726. // than the nestLevel of this component.
  1727. // The nestLevel setter will recursively set it on any
  1728. // descendants of the child that exist.
  1729. if (child is ILayoutManagerClient)
  1730. ILayoutManagerClient(child).nestLevel = nestLevel + 1;
  1731. if (child is InteractiveObject)
  1732. if (doubleClickEnabled)
  1733. InteractiveObject(child).doubleClickEnabled = true;
  1734. if (child is IUIComponent)
  1735. IUIComponent(child).parentChanged(this);
  1736. // Sets up the inheritingStyles and nonInheritingStyles objects
  1737. // and their proto chains so that getStyle() works.
  1738. // If this object already has some children,
  1739. // then reinitialize the children's proto chains.
  1740. if (child is IStyleClient)
  1741. IStyleClient(child).regenerateStyleCache(true);
  1742. if (child is ISimpleStyleClient)
  1743. ISimpleStyleClient(child).styleChanged(null);
  1744. if (child is IStyleClient)
  1745. IStyleClient(child).notifyStyleChangeInChildren(null, true);
  1746. // Need to check to see if the child is an UIComponent
  1747. // without actually linking in the UIComponent class.
  1748. if (uiComponentClassName && child is uiComponentClassName)
  1749. uiComponentClassName(child).initThemeColor();
  1750. // Inform the component that it's style properties
  1751. // have been fully initialized. Most components won't care,
  1752. // but some need to react to even this early change.
  1753. if (uiComponentClassName && child is uiComponentClassName)
  1754. uiComponentClassName(child).stylesInitialized();
  1755. }
  1756. /**
  1757. * @private
  1758. */
  1759. mx_internal function childAdded(child:DisplayObject):void
  1760. {
  1761. child.dispatchEvent(new FlexEvent(FlexEvent.ADD));
  1762. if (child is IUIComponent)
  1763. IUIComponent(child).initialize(); // calls child.createChildren()
  1764. }
  1765. /**
  1766. * @private
  1767. */
  1768. mx_internal function removingChild(child:DisplayObject):void
  1769. {
  1770. child.dispatchEvent(new FlexEvent(FlexEvent.REMOVE));
  1771. }
  1772. /**
  1773. * @private
  1774. */
  1775. mx_internal function childRemoved(child:DisplayObject):void
  1776. {
  1777. if (child is IUIComponent)
  1778. IUIComponent(child).parentChanged(null);
  1779. }
  1780. //--------------------------------------------------------------------------
  1781. //
  1782. // Methods: Support for rawChildren access
  1783. //
  1784. //--------------------------------------------------------------------------
  1785. /**
  1786. * @private
  1787. */
  1788. mx_internal function rawChildren_addChild(child:DisplayObject):DisplayObject
  1789. {
  1790. addingChild(child);
  1791. super.addChild(child);
  1792. childAdded(child); // calls child.createChildren()
  1793. return child;
  1794. }
  1795. /**
  1796. * @private
  1797. */
  1798. mx_internal function rawChildren_addChildAt(child:DisplayObject,
  1799. index:int):DisplayObject
  1800. {
  1801. addingChild(child);
  1802. super.addChildAt(child, index);
  1803. childAdded(child); // calls child.createChildren()
  1804. return child;
  1805. }
  1806. /**
  1807. * @private
  1808. */
  1809. mx_internal function rawChildren_removeChild(child:DisplayObject):DisplayObject
  1810. {
  1811. removingChild(child);
  1812. super.removeChild(child);
  1813. childRemoved(child);
  1814. return child;
  1815. }
  1816. /**
  1817. * @private
  1818. */
  1819. mx_internal function rawChildren_removeChildAt(index:int):DisplayObject
  1820. {
  1821. var child:DisplayObject = super.getChildAt(index);
  1822. removingChild(child);
  1823. super.removeChildAt(index);
  1824. childRemoved(child);
  1825. return child;
  1826. }
  1827. /**
  1828. * @private
  1829. */
  1830. mx_internal function rawChildren_getChildAt(index:int):DisplayObject
  1831. {
  1832. return super.getChildAt(index);
  1833. }
  1834. /**
  1835. * @private
  1836. */
  1837. mx_internal function rawChildren_getChildByName(name:String):DisplayObject
  1838. {
  1839. return super.getChildByName(name);
  1840. }
  1841. /**
  1842. * @private
  1843. */
  1844. mx_internal function rawChildren_getChildIndex(child:DisplayObject):int
  1845. {
  1846. return super.getChildIndex(child);
  1847. }
  1848. /**
  1849. * @private
  1850. */
  1851. mx_internal function rawChildren_setChildIndex(child:DisplayObject, newIndex:int):void
  1852. {
  1853. super.setChildIndex(child, newIndex);
  1854. }
  1855. /**
  1856. * @private
  1857. */
  1858. mx_internal function rawChildren_getObjectsUnderPoint(pt:Point):Array
  1859. {
  1860. return super.getObjectsUnderPoint(pt);
  1861. }
  1862. /**
  1863. * @private
  1864. */
  1865. mx_internal function rawChildren_contains(child:DisplayObject):Boolean
  1866. {
  1867. return super.contains(child);
  1868. }
  1869. //--------------------------------------------------------------------------
  1870. //
  1871. // Methods: Measurement and Layout
  1872. //
  1873. //--------------------------------------------------------------------------
  1874. /**
  1875. * A convenience method for determining whether to use the
  1876. * explicit or measured width.
  1877. *
  1878. * @return A Number that is the <code>explicitWidth</code> if defined,
  1879. * or the <code>measuredWidth</code> property if not.
  1880. */
  1881. public function getExplicitOrMeasuredWidth():Number
  1882. {
  1883. return !isNaN(explicitWidth) ? explicitWidth : measuredWidth;
  1884. }
  1885. /**
  1886. * A convenience method for determining whether to use the
  1887. * explicit or measured height.
  1888. *
  1889. * @return A Number that is the <code>explicitHeight</code> if defined,
  1890. * or the <code>measuredHeight</code> property if not.
  1891. */
  1892. public function getExplicitOrMeasuredHeight():Number
  1893. {
  1894. return !isNaN(explicitHeight) ? explicitHeight : measuredHeight;
  1895. }
  1896. /**
  1897. * Calling the <code>move()</code> method
  1898. * has no effect as it is directly mapped
  1899. * to the application window or the loader.
  1900. *
  1901. * @param x The new x coordinate.
  1902. *
  1903. * @param y The new y coordinate.
  1904. */
  1905. public function move(x:Number, y:Number):void
  1906. {
  1907. }
  1908. /**
  1909. * Calling the <code>setActualSize()</code> method
  1910. * has no effect if it is directly mapped
  1911. * to the application window and if it is the top-level window.
  1912. * Otherwise attempts to resize itself, clipping children if needed.
  1913. *
  1914. * @param newWidth The new width.
  1915. *
  1916. * @param newHeight The new height.
  1917. */
  1918. public function setActualSize(newWidth:Number, newHeight:Number):void
  1919. {
  1920. if (isStageRoot) return;
  1921. _width = newWidth;
  1922. _height = newHeight;
  1923. // mouseCatcher is a mask if not stage root
  1924. if (mouseCatcher)
  1925. {
  1926. mouseCatcher.width = newWidth;
  1927. mouseCatcher.height = newHeight;
  1928. }
  1929. dispatchEvent(new Event(Event.RESIZE));
  1930. }
  1931. //--------------------------------------------------------------------------
  1932. //
  1933. // Methods: Styles
  1934. //
  1935. //--------------------------------------------------------------------------
  1936. /**
  1937. * @private
  1938. * Call regenerateStyleCache() on all children of this SystemManager.
  1939. * If the recursive parameter is true, continue doing this
  1940. * for all descendants of these children.
  1941. */
  1942. mx_internal function regenerateStyleCache(recursive:Boolean):void
  1943. {
  1944. var foundTopLevelWindow:Boolean = false;
  1945. var n:int = rawChildren.numChildren;
  1946. for (var i:int = 0; i < n; i++)
  1947. {
  1948. var child:IStyleClient =
  1949. rawChildren.getChildAt(i) as IStyleClient;
  1950. if (child)
  1951. child.regenerateStyleCache(recursive);
  1952. if (isTopLevelWindow(DisplayObject(child)))
  1953. foundTopLevelWindow = true;
  1954. // Refetch numChildren because notifyStyleChangedInChildren()
  1955. // can add/delete a child and therefore change numChildren.
  1956. n = rawChildren.numChildren;
  1957. }
  1958. // During startup the top level window isn't added
  1959. // to the child list until late into the startup sequence.
  1960. // Make sure we call regenerateStyleCache()
  1961. // on the top level window even if it isn't a child yet.
  1962. if (!foundTopLevelWindow && topLevelWindow is IStyleClient)
  1963. IStyleClient(topLevelWindow).regenerateStyleCache(recursive);
  1964. }
  1965. /**
  1966. * @private
  1967. * Call styleChanged() and notifyStyleChangeInChildren()
  1968. * on all children of this SystemManager.
  1969. * If the recursive parameter is true, continue doing this
  1970. * for all descendants of these children.
  1971. */
  1972. mx_internal function notifyStyleChangeInChildren(styleProp:String,
  1973. recursive:Boolean):void
  1974. {
  1975. var foundTopLevelWindow:Boolean = false;
  1976. var n:int = rawChildren.numChildren;
  1977. for (var i:int = 0; i < n; i++)
  1978. {
  1979. var child:IStyleClient =
  1980. rawChildren.getChildAt(i) as IStyleClient;
  1981. if (child)
  1982. {
  1983. child.styleChanged(styleProp);
  1984. child.notifyStyleChangeInChildren(styleProp, recursive);
  1985. }
  1986. if (isTopLevelWindow(DisplayObject(child)))
  1987. foundTopLevelWindow = true;
  1988. // Refetch numChildren because notifyStyleChangedInChildren()
  1989. // can add/delete a child and therefore change numChildren.
  1990. n = rawChildren.numChildren;
  1991. }
  1992. // During startup the top level window isn't added
  1993. // to the child list until late into the startup sequence.
  1994. // Make sure we call notifyStyleChangeInChildren()
  1995. // on the top level window even if it isn't a child yet.
  1996. if (!foundTopLevelWindow && topLevelWindow is IStyleClient)
  1997. {
  1998. IStyleClient(topLevelWindow).styleChanged(styleProp);
  1999. IStyleClient(topLevelWindow).notifyStyleChangeInChildren(
  2000. styleProp, recursive);
  2001. }
  2002. }
  2003. //--------------------------------------------------------------------------
  2004. //
  2005. // Methods: Focus
  2006. //
  2007. //--------------------------------------------------------------------------
  2008. /**
  2009. * @inheritDoc
  2010. */
  2011. public function activate(f:IFocusManagerContainer):void
  2012. {
  2013. activateForm(f);
  2014. }
  2015. /**
  2016. * @private
  2017. *
  2018. * New version of activate that does not require a
  2019. * IFocusManagerContainer.
  2020. */
  2021. private function activateForm(f:Object):void
  2022. {
  2023. // trace("SM: activate " + f + " " + forms.length);
  2024. if (form)
  2025. {
  2026. if (form != f && forms.length > 1)
  2027. {
  2028. // Switch the active form.
  2029. if (isRemotePopUp(form))
  2030. {
  2031. if (!areRemotePopUpsEqual(form, f))
  2032. deactivateRemotePopUp(form);
  2033. }
  2034. else
  2035. {
  2036. var z:IFocusManagerContainer = IFocusManagerContainer(form);
  2037. // trace("OLW " + f + " deactivating old form " + z);
  2038. z.focusManager.deactivate();
  2039. }
  2040. }
  2041. }
  2042. form = f;
  2043. // trace("f = " + f);
  2044. if (isRemotePopUp(f))
  2045. {
  2046. activateRemotePopUp(f);
  2047. }
  2048. else if (f.focusManager)
  2049. {
  2050. // trace("has focus manager");
  2051. f.focusManager.activate();
  2052. }
  2053. updateLastActiveForm();
  2054. // trace("END SM: activate " + f);
  2055. }
  2056. /**
  2057. * @inheritDoc
  2058. */
  2059. public function deactivate(f:IFocusManagerContainer):void
  2060. {
  2061. deactivateForm(Object(f));
  2062. }
  2063. /**
  2064. * @private
  2065. *
  2066. * New version of deactivate that works with remote pop ups.
  2067. *
  2068. */
  2069. private function deactivateForm(f:Object):void
  2070. {
  2071. // trace(">>SM: deactivate " + f);
  2072. if (form)
  2073. {
  2074. // If there's more than one form and this is it, find a new form.
  2075. if (form == f && forms.length > 1)
  2076. {
  2077. if (isRemotePopUp(form))
  2078. deactivateRemotePopUp(form);
  2079. else
  2080. form.focusManager.deactivate();
  2081. form = findLastActiveForm(f);
  2082. // make sure we have a valid top level window.
  2083. // This can be null if top level window has been hidden for some reason.
  2084. if (form)
  2085. {
  2086. if (isRemotePopUp(form))
  2087. activateRemotePopUp(form);
  2088. else
  2089. form.focusManager.activate();
  2090. }
  2091. }
  2092. }
  2093. // trace("<<SM: deactivate " + f);
  2094. }
  2095. /**
  2096. * @private
  2097. *
  2098. * @param f form being deactivated
  2099. *
  2100. * @return the next form to activate, excluding the form being deactivated.
  2101. */
  2102. private function findLastActiveForm(f:Object):Object
  2103. {
  2104. var n:int = forms.length;
  2105. for (var i:int = forms.length - 1; i >= 0; i--)
  2106. {
  2107. // Verify the form is visible and enabled
  2108. if (forms[i] != f && canActivatePopUp(forms[i]))
  2109. return forms[i];
  2110. }
  2111. return null; // should never get here
  2112. }
  2113. /**
  2114. * @private
  2115. *
  2116. * @return true if the form can be activated, false otherwise.
  2117. */
  2118. private function canActivatePopUp(f:Object):Boolean
  2119. {
  2120. if (isRemotePopUp(f))
  2121. {
  2122. var remotePopUp:RemotePopUp = RemotePopUp(f);
  2123. var event:SWFBridgeRequest = new SWFBridgeRequest(SWFBridgeRequest.CAN_ACTIVATE_POP_UP_REQUEST,
  2124. false, false, null,
  2125. remotePopUp.window);
  2126. IEventDispatcher(remotePopUp.bridge).dispatchEvent(event);
  2127. return event.data;
  2128. }
  2129. else if (canActivateLocalComponent(f))
  2130. return true;
  2131. return false;
  2132. }
  2133. /**
  2134. * @private
  2135. *
  2136. * Test is a local component can be activated.
  2137. */
  2138. private function canActivateLocalComponent(o:Object):Boolean
  2139. {
  2140. if (o is Sprite && o is IUIComponent &&
  2141. Sprite(o).visible && IUIComponent(o).enabled)
  2142. return true;
  2143. return false;
  2144. }
  2145. /**
  2146. * @private
  2147. *
  2148. * @return true if the form is a RemotePopUp, false if the form is IFocusManagerContainer.
  2149. *
  2150. */
  2151. private static function isRemotePopUp(form:Object):Boolean
  2152. {
  2153. return !(form is IFocusManagerContainer);
  2154. }
  2155. /**
  2156. * @private
  2157. *
  2158. * @return true if form1 and form2 are both of type RemotePopUp and are equal, false otherwise.
  2159. */
  2160. private static function areRemotePopUpsEqual(form1:Object, form2:Object):Boolean
  2161. {
  2162. if (!(form1 is RemotePopUp))
  2163. return false;
  2164. if (!(form2 is RemotePopUp))
  2165. return false;
  2166. var remotePopUp1:RemotePopUp = RemotePopUp(form1);
  2167. var remotePopUp2:RemotePopUp = RemotePopUp(form2);
  2168. if (remotePopUp1.window == remotePopUp2.window &&
  2169. remotePopUp1.bridge && remotePopUp2.bridge)
  2170. return true;
  2171. return false;
  2172. }
  2173. /**
  2174. * @private
  2175. *
  2176. * Find a remote form that is hosted by this system manager.
  2177. *
  2178. * @param window unique id of popUp within a bridged application
  2179. * @param bridge bridge of owning application.
  2180. *
  2181. * @return RemotePopUp if hosted by this system manager, false otherwise.
  2182. */
  2183. private function findRemotePopUp(window:Object, bridge:IEventDispatcher):RemotePopUp
  2184. {
  2185. // remove the placeholder from forms array
  2186. var n:int = forms.length;
  2187. for (var i:int = 0; i < n; i++)
  2188. {
  2189. if (isRemotePopUp(forms[i]))
  2190. {
  2191. var popUp:RemotePopUp = RemotePopUp(forms[i]);
  2192. if (popUp.window == window &&
  2193. popUp.bridge == bridge)
  2194. return popUp;
  2195. }
  2196. }
  2197. return null;
  2198. }
  2199. /**
  2200. * Remote a remote form from the forms array.
  2201. *
  2202. * form Locally created remote form.
  2203. */
  2204. private function removeRemotePopUp(form:RemotePopUp):void
  2205. {
  2206. // remove popup from forms array
  2207. var n:int = forms.length;
  2208. for (var i:int = 0; i < n; i++)
  2209. {
  2210. if (isRemotePopUp(forms[i]))
  2211. {
  2212. if (forms[i].window == form.window &&
  2213. forms[i].bridge == form.bridge)
  2214. {
  2215. if (forms[i] == form)
  2216. deactivateForm(form);
  2217. forms.splice(i, 1);
  2218. break;
  2219. }
  2220. }
  2221. }
  2222. }
  2223. /**
  2224. * @private
  2225. *
  2226. * Activate a form that belongs to a system manager in another
  2227. * sandbox or peer application domain.
  2228. *
  2229. * @param form a RemotePopUp object.
  2230. * */
  2231. private function activateRemotePopUp(form:Object):void
  2232. {
  2233. var request:SWFBridgeRequest = new SWFBridgeRequest(SWFBridgeRequest.ACTIVATE_POP_UP_REQUEST,
  2234. false, false,
  2235. form.bridge,
  2236. form.window);
  2237. var bridge:Object = form.bridge;
  2238. if (bridge)
  2239. bridge.dispatchEvent(request);
  2240. }
  2241. private function deactivateRemotePopUp(form:Object):void
  2242. {
  2243. var request:SWFBridgeRequest = new SWFBridgeRequest(SWFBridgeRequest.DEACTIVATE_POP_UP_REQUEST,
  2244. false, false,
  2245. form.bridge,
  2246. form.window);
  2247. var bridge:Object = form.bridge;
  2248. if (bridge)
  2249. bridge.dispatchEvent(request);
  2250. }
  2251. /**
  2252. * Test if two forms are equal.
  2253. *
  2254. * @param form1 - may be of type a DisplayObjectContainer or a RemotePopUp
  2255. * @param form2 - may be of type a DisplayObjectContainer or a RemotePopUp
  2256. *
  2257. * @return true if the forms are equal, false otherwise.
  2258. */
  2259. private function areFormsEqual(form1:Object, form2:Object):Boolean
  2260. {
  2261. if (form1 == form2)
  2262. return true;
  2263. // if the forms are both remote forms, then compare them, otherwise
  2264. // return false.
  2265. if (form1 is RemotePopUp && form2 is RemotePopUp)
  2266. {
  2267. return areRemotePopUpsEqual(form1, form2);
  2268. }
  2269. return false;
  2270. }
  2271. /**
  2272. * @inheritDoc
  2273. */
  2274. public function addFocusManager(f:IFocusManagerContainer):void
  2275. {
  2276. // trace("OLW: add focus manager" + f);
  2277. forms.push(f);
  2278. // trace("END OLW: add focus manager" + f);
  2279. }
  2280. /**
  2281. * @inheritDoc
  2282. */
  2283. public function removeFocusManager(f:IFocusManagerContainer):void
  2284. {
  2285. // trace("OLW: remove focus manager" + f);
  2286. var n:int = forms.length;
  2287. for (var i:int = 0; i < n; i++)
  2288. {
  2289. if (forms[i] == f)
  2290. {
  2291. if (form == f)
  2292. deactivate(f);
  2293. // If this is a bridged application, send a message to the parent
  2294. // to let them know the form has been deactivated so they can
  2295. // activate a new form.
  2296. dispatchDeactivatedWindowEvent(DisplayObject(f));
  2297. forms.splice(i, 1);
  2298. // trace("END OLW: successful remove focus manager" + f);
  2299. return;
  2300. }
  2301. }
  2302. // trace("END OLW: remove focus manager" + f);
  2303. }
  2304. //--------------------------------------------------------------------------
  2305. //
  2306. // Methods: Other
  2307. //
  2308. //--------------------------------------------------------------------------
  2309. /**
  2310. * @inheritDoc
  2311. */
  2312. public function getDefinitionByName(name:String):Object
  2313. {
  2314. var domain:ApplicationDomain =
  2315. !topLevel && parent is Loader ?
  2316. Loader(parent).contentLoaderInfo.applicationDomain :
  2317. info()["currentDomain"] as ApplicationDomain;
  2318. //trace("SysMgr.getDefinitionByName domain",domain,"currentDomain",info()["currentDomain"]);
  2319. var definition:Object;
  2320. if (domain.hasDefinition(name))
  2321. {
  2322. definition = domain.getDefinition(name);
  2323. //trace("SysMgr.getDefinitionByName got definition",definition,"name",name);
  2324. }
  2325. return definition;
  2326. }
  2327. /**
  2328. * Returns the root DisplayObject of the SWF that contains the code
  2329. * for the given object.
  2330. *
  2331. * @param object Any Object.
  2332. *
  2333. * @return The root DisplayObject
  2334. */
  2335. public static function getSWFRoot(object:Object):DisplayObject
  2336. {
  2337. var className:String = getQualifiedClassName(object);
  2338. for (var p:* in allSystemManagers)
  2339. {
  2340. var sm:ISystemManager = p as ISystemManager;
  2341. var domain:ApplicationDomain = sm.loaderInfo.applicationDomain;
  2342. try
  2343. {
  2344. var cls:Class = Class(domain.getDefinition(className));
  2345. if (object is cls)
  2346. return sm as DisplayObject;
  2347. }
  2348. catch(e:Error)
  2349. {
  2350. }
  2351. }
  2352. return null;
  2353. }
  2354. /**
  2355. * @inheritDoc
  2356. */
  2357. public function isTopLevel():Boolean
  2358. {
  2359. return topLevel;
  2360. }
  2361. /**
  2362. * @inheritDoc
  2363. */
  2364. public function isTopLevelRoot():Boolean
  2365. {
  2366. return isStageRoot || isBootstrapRoot;
  2367. }
  2368. /**
  2369. * Determines if the given DisplayObject is the
  2370. * top-level window.
  2371. *
  2372. * @param object The DisplayObject to test.
  2373. *
  2374. * @return <code>true</code> if the given DisplayObject is the
  2375. * top-level window.
  2376. */
  2377. public function isTopLevelWindow(object:DisplayObject):Boolean
  2378. {
  2379. return object is IUIComponent &&
  2380. IUIComponent(object) == topLevelWindow;
  2381. }
  2382. /**
  2383. * @inheritDoc
  2384. */
  2385. public function isFontFaceEmbedded(textFormat:TextFormat):Boolean
  2386. {
  2387. var fontName:String = textFormat.font;
  2388. var fl:Array = Font.enumerateFonts();
  2389. for (var f:int = 0; f < fl.length; ++f)
  2390. {
  2391. var font:Font = Font(fl[f]);
  2392. if (font.fontName == fontName)
  2393. {
  2394. var style:String = "regular";
  2395. if (textFormat.bold && textFormat.italic)
  2396. style = "boldItalic";
  2397. else if (textFormat.bold)
  2398. style = "bold";
  2399. else if (textFormat.italic)
  2400. style = "italic";
  2401. if (font.fontStyle == style)
  2402. return true;
  2403. }
  2404. }
  2405. if (!fontName ||
  2406. !embeddedFontList ||
  2407. !embeddedFontList[fontName])
  2408. {
  2409. return false;
  2410. }
  2411. var info:Object = embeddedFontList[fontName];
  2412. return !((textFormat.bold && !info.bold) ||
  2413. (textFormat.italic && !info.italic) ||
  2414. (!textFormat.bold && !textFormat.italic &&
  2415. !info.regular));
  2416. }
  2417. /**
  2418. * @private
  2419. *
  2420. * Dispatch an invalidate request to invalidate the size and
  2421. * display list of the parent application.
  2422. */
  2423. private function dispatchInvalidateRequest():void
  2424. {
  2425. var bridge:IEventDispatcher = swfBridgeGroup.parentBridge;
  2426. var request:SWFBridgeRequest = new SWFBridgeRequest(
  2427. SWFBridgeRequest.INVALIDATE_REQUEST,
  2428. false, false,
  2429. bridge,
  2430. InvalidateRequestData.SIZE |
  2431. InvalidateRequestData.DISPLAY_LIST);
  2432. bridge.dispatchEvent(request);
  2433. }
  2434. /**
  2435. * @private
  2436. * Makes the mouseCatcher the same size as the stage,
  2437. * filling it with transparent pixels.
  2438. */
  2439. private function resizeMouseCatcher():void
  2440. {
  2441. if (mouseCatcher)
  2442. {
  2443. try
  2444. {
  2445. var g:Graphics = mouseCatcher.graphics;
  2446. var s:Rectangle = screen;
  2447. g.clear();
  2448. g.beginFill(0x000000, 0);
  2449. g.drawRect(0, 0, s.width, s.height);
  2450. g.endFill();
  2451. }
  2452. catch (e:SecurityError)
  2453. {
  2454. // trace("resizeMouseCatcher: ignoring security error " + e);
  2455. }
  2456. }
  2457. }
  2458. //--------------------------------------------------------------------------
  2459. //
  2460. // Event handlers
  2461. //
  2462. //--------------------------------------------------------------------------
  2463. /**
  2464. * @private
  2465. */
  2466. private function initHandler(event:Event):void
  2467. {
  2468. // we can still be the top level root if we can access our
  2469. // parent and get a positive response to the query or
  2470. // or there is not a listener for the new application event
  2471. // that SWFLoader always adds.
  2472. if (!isStageRoot)
  2473. {
  2474. if (root.loaderInfo.parentAllowsChild)
  2475. {
  2476. try
  2477. {
  2478. if (!parent.dispatchEvent(new Event("mx.managers.SystemManager.isBootstrapRoot", false, true)) ||
  2479. !root.loaderInfo.sharedEvents.hasEventListener(SWFBridgeEvent.BRIDGE_NEW_APPLICATION))
  2480. isBootstrapRoot = true;
  2481. }
  2482. catch (e:Error)
  2483. {
  2484. }
  2485. }
  2486. }
  2487. allSystemManagers[this] = this.loaderInfo.url;
  2488. root.loaderInfo.removeEventListener(Event.INIT, initHandler);
  2489. if (useSWFBridge())
  2490. {
  2491. // create a bridge so we can talk to our parent.
  2492. swfBridgeGroup = new SWFBridgeGroup(this);
  2493. swfBridgeGroup.parentBridge = loaderInfo.sharedEvents;
  2494. addParentBridgeListeners();
  2495. // send message to parent that we are ready.
  2496. // pass up the sandbox bridge to the parent so its knows who we are.
  2497. var bridgeEvent:SWFBridgeEvent = new SWFBridgeEvent(SWFBridgeEvent.BRIDGE_NEW_APPLICATION);
  2498. bridgeEvent.data = swfBridgeGroup.parentBridge;
  2499. swfBridgeGroup.parentBridge.dispatchEvent(bridgeEvent);
  2500. // placeholder popups are started locally
  2501. addEventListener(SWFBridgeRequest.ADD_POP_UP_PLACE_HOLDER_REQUEST, addPlaceholderPopupRequestHandler);
  2502. root.loaderInfo.addEventListener(Event.UNLOAD, unloadHandler, false, 0, true);
  2503. }
  2504. // every SM has to have this listener in case it is the SM for some child AD that contains a manager
  2505. // and the parent ADs don't have that manager.
  2506. var sbRoot:DisplayObject = getSandboxRoot();
  2507. sbRoot.addEventListener(InterManagerRequest.INIT_MANAGER_REQUEST, initManagerHandler, false, 0, true);
  2508. // once managers get initialized, they bounce things off the sandbox root
  2509. if (sbRoot == this)
  2510. {
  2511. addEventListener(InterManagerRequest.SYSTEM_MANAGER_REQUEST, systemManagerHandler);
  2512. addEventListener(InterManagerRequest.DRAG_MANAGER_REQUEST, multiWindowRedispatcher);
  2513. // listened for w/o use of constants because of dependency issues
  2514. //addEventListener(InterDragManagerEvent.DISPATCH_DRAG_EVENT, multiWindowRedispatcher);
  2515. addEventListener("dispatchDragEvent", multiWindowRedispatcher);
  2516. addEventListener(SWFBridgeRequest.ADD_POP_UP_REQUEST, addPopupRequestHandler);
  2517. addEventListener(SWFBridgeRequest.REMOVE_POP_UP_REQUEST, removePopupRequestHandler);
  2518. addEventListener(SWFBridgeRequest.ADD_POP_UP_PLACE_HOLDER_REQUEST, addPlaceholderPopupRequestHandler);
  2519. addEventListener(SWFBridgeRequest.REMOVE_POP_UP_PLACE_HOLDER_REQUEST, removePlaceholderPopupRequestHandler);
  2520. addEventListener(SWFBridgeEvent.BRIDGE_WINDOW_ACTIVATE, activateFormSandboxEventHandler);
  2521. addEventListener(SWFBridgeEvent.BRIDGE_WINDOW_DEACTIVATE, deactivateFormSandboxEventHandler);
  2522. addEventListener(SWFBridgeRequest.HIDE_MOUSE_CURSOR_REQUEST, hideMouseCursorRequestHandler);
  2523. addEventListener(SWFBridgeRequest.SHOW_MOUSE_CURSOR_REQUEST, showMouseCursorRequestHandler);
  2524. addEventListener(SWFBridgeRequest.RESET_MOUSE_CURSOR_REQUEST, resetMouseCursorRequestHandler);
  2525. }
  2526. var docFrame:int = (totalFrames == 1)? 0 : 1;
  2527. addEventListener(Event.ENTER_FRAME, docFrameListener);
  2528. /*
  2529. addFrameScript(docFrame, docFrameHandler);
  2530. for (var f:int = docFrame + 1; f < totalFrames; ++f)
  2531. {
  2532. addFrameScript(f, extraFrameHandler);
  2533. }
  2534. */
  2535. initialize();
  2536. }
  2537. private function docFrameListener(event:Event):void
  2538. {
  2539. if (currentFrame == 2)
  2540. {
  2541. removeEventListener(Event.ENTER_FRAME, docFrameListener);
  2542. if (totalFrames > 2)
  2543. addEventListener(Event.ENTER_FRAME, extraFrameListener);
  2544. docFrameHandler();
  2545. }
  2546. }
  2547. private function extraFrameListener(event:Event):void
  2548. {
  2549. if (lastFrame == currentFrame)
  2550. return;
  2551. lastFrame = currentFrame;
  2552. if (currentFrame + 1 > totalFrames)
  2553. removeEventListener(Event.ENTER_FRAME, extraFrameListener);
  2554. extraFrameHandler();
  2555. }
  2556. /**
  2557. * @private
  2558. * Once the swf has been fully downloaded,
  2559. * advance the playhead to the next frame.
  2560. * This will cause the framescript to run, which runs frameEndHandler().
  2561. */
  2562. private function preloader_initProgressHandler(event:Event):void
  2563. {
  2564. // Advance the next frame
  2565. preloader.removeEventListener(FlexEvent.INIT_PROGRESS,
  2566. preloader_initProgressHandler);
  2567. deferredNextFrame();
  2568. }
  2569. /**
  2570. * @private
  2571. * Remove the preloader and add the application as a child.
  2572. */
  2573. private function preloader_preloaderDoneHandler(event:Event):void
  2574. {
  2575. var app:IUIComponent = topLevelWindow;
  2576. // Once the preloader dispatches the PRELOADER_DONE event, remove the preloader
  2577. // and add the application as the child
  2578. preloader.removeEventListener(FlexEvent.PRELOADER_DONE,
  2579. preloader_preloaderDoneHandler);
  2580. _popUpChildren.removeChild(preloader);
  2581. preloader = null;
  2582. // Add the mouseCatcher as child 0.
  2583. mouseCatcher = new FlexSprite();
  2584. mouseCatcher.name = "mouseCatcher";
  2585. // Must use addChildAt because a creationComplete handler can create a
  2586. // dialog and insert it at 0.
  2587. noTopMostIndex++;
  2588. super.addChildAt(mouseCatcher, 0);
  2589. resizeMouseCatcher();
  2590. if (!topLevel)
  2591. {
  2592. mouseCatcher.visible = false;
  2593. mask = mouseCatcher;
  2594. }
  2595. // Add the application as child 1.
  2596. noTopMostIndex++;
  2597. super.addChildAt(DisplayObject(app), 1);
  2598. // Dispatch the applicationComplete event from the Application
  2599. // and then agaom from the SystemManager
  2600. // (so that loading apps know we're done).
  2601. app.dispatchEvent(new FlexEvent(FlexEvent.APPLICATION_COMPLETE));
  2602. dispatchEvent(new FlexEvent(FlexEvent.APPLICATION_COMPLETE));
  2603. }
  2604. /**
  2605. * @private
  2606. * This is attached as the framescript at the end of frame 2.
  2607. * When this function is called, we know that the application
  2608. * class has been defined and read in by the Player.
  2609. */
  2610. mx_internal function docFrameHandler(event:Event = null):void
  2611. {
  2612. // The ResourceManager has already been registered
  2613. // by initialize() in frame 1.
  2614. // Register other singleton classes.
  2615. // Note: getDefinitionByName() will return null
  2616. // if the class can't be found.
  2617. Singleton.registerClass("mx.managers::IBrowserManager",
  2618. Class(getDefinitionByName("mx.managers::BrowserManagerImpl")));
  2619. Singleton.registerClass("mx.managers::ICursorManager",
  2620. Class(getDefinitionByName("mx.managers::CursorManagerImpl")));
  2621. Singleton.registerClass("mx.managers::IHistoryManager",
  2622. Class(getDefinitionByName("mx.managers::HistoryManagerImpl")));
  2623. Singleton.registerClass("mx.managers::ILayoutManager",
  2624. Class(getDefinitionByName("mx.managers::LayoutManager")));
  2625. Singleton.registerClass("mx.managers::IPopUpManager",
  2626. Class(getDefinitionByName("mx.managers::PopUpManagerImpl")));
  2627. Singleton.registerClass("mx.managers::IToolTipManager2",
  2628. Class(getDefinitionByName("mx.managers::ToolTipManagerImpl")));
  2629. if (Capabilities.playerType == "Desktop")
  2630. {
  2631. Singleton.registerClass("mx.managers::IDragManager",
  2632. Class(getDefinitionByName("mx.managers::NativeDragManagerImpl")));
  2633. // Make this call to create a new instance of the DragManager singleton.
  2634. // This will allow the application to receive NativeDragEvents that originate
  2635. // from the desktop.
  2636. // if this class is not registered, it's most likely because the NativeDragManager is not
  2637. // linked in correctly. all back to old DragManager.
  2638. if (Singleton.getClass("mx.managers::IDragManager") == null)
  2639. Singleton.registerClass("mx.managers::IDragManager",
  2640. Class(getDefinitionByName("mx.managers::DragManagerImpl")));
  2641. }
  2642. else
  2643. {
  2644. Singleton.registerClass("mx.managers::IDragManager",
  2645. Class(getDefinitionByName("mx.managers::DragManagerImpl")));
  2646. }
  2647. var textFieldFactory:TextFieldFactory; // ref to cause TextFieldFactory to be linked in
  2648. Singleton.registerClass("mx.core::ITextFieldFactory",
  2649. Class(getDefinitionByName("mx.core::TextFieldFactory")));
  2650. executeCallbacks();
  2651. doneExecutingInitCallbacks = true;
  2652. var mixinList:Array = info()["mixins"];
  2653. if (mixinList && mixinList.length > 0)
  2654. {
  2655. var n:int = mixinList.length;
  2656. for (var i:int = 0; i < n; ++i)
  2657. {
  2658. // trace("initializing mixin " + mixinList[i]);
  2659. var c:Class = Class(getDefinitionByName(mixinList[i]));
  2660. c["init"](this);
  2661. }
  2662. }
  2663. installCompiledResourceBundles();
  2664. initializeTopLevelWindow(null);
  2665. deferredNextFrame();
  2666. }
  2667. private function installCompiledResourceBundles():void
  2668. {
  2669. var info:Object = this.info();
  2670. var applicationDomain:ApplicationDomain =
  2671. !topLevel && parent is Loader ?
  2672. Loader(parent).contentLoaderInfo.applicationDomain :
  2673. info["currentDomain"];
  2674. var compiledLocales:Array /* of String */ =
  2675. info["compiledLocales"];
  2676. var compiledResourceBundleNames:Array /* of String */ =
  2677. info["compiledResourceBundleNames"];
  2678. var resourceManager:IResourceManager =
  2679. ResourceManager.getInstance();
  2680. resourceManager.installCompiledResourceBundles(
  2681. applicationDomain, compiledLocales, compiledResourceBundleNames);
  2682. // If the localeChain wasn't specified in the FlashVars of the SWF's
  2683. // HTML wrapper, or in the query parameters of the SWF URL,
  2684. // then initialize it to the list of compiled locales,
  2685. // sorted according to the system's preferred locales as reported by
  2686. // Capabilities.languages or Capabilities.language.
  2687. // For example, if the applications was compiled with, say,
  2688. // -locale=en_US,ja_JP and Capabilities.languages reports [ "ja-JP" ],
  2689. // set the localeChain to [ "ja_JP" "en_US" ].
  2690. if (!resourceManager.localeChain)
  2691. resourceManager.initializeLocaleChain(compiledLocales);
  2692. }
  2693. private function extraFrameHandler(event:Event = null):void
  2694. {
  2695. var frameList:Object = info()["frames"];
  2696. if (frameList && frameList[currentLabel])
  2697. {
  2698. var c:Class = Class(getDefinitionByName(frameList[currentLabel]));
  2699. c["frame"](this);
  2700. }
  2701. deferredNextFrame();
  2702. }
  2703. /**
  2704. * @private
  2705. */
  2706. private function nextFrameTimerHandler(event:TimerEvent):void
  2707. {
  2708. if (currentFrame + 1 <= framesLoaded)
  2709. {
  2710. nextFrame();
  2711. nextFrameTimer.removeEventListener(TimerEvent.TIMER, nextFrameTimerHandler);
  2712. // stop the timer
  2713. nextFrameTimer.reset();
  2714. }
  2715. }
  2716. /**
  2717. * @private
  2718. * Instantiates an instance of the top level window
  2719. * and adds it as a child of the SystemManager.
  2720. */
  2721. private function initializeTopLevelWindow(event:Event):void
  2722. {
  2723. initialized = true;
  2724. // Parent may be null if in another sandbox and don't have
  2725. // access to our parent. Add a check for this case.
  2726. if (!parent && parentAllowsChild)
  2727. return;
  2728. if (!topLevel)
  2729. {
  2730. // We are not top-level and don't have a parent. This can happen
  2731. // when the application has already been unloaded by the time
  2732. // we get to this point.
  2733. if (!parent)
  2734. return;
  2735. var obj:DisplayObjectContainer = parent.parent;
  2736. // if there is no grandparent at this point, we might have been removed and
  2737. // are about to be killed so just bail. Other code that runs after
  2738. // this point expects us to be grandparented. Another scenario
  2739. // is that someone loaded us but not into a parented loader, but that
  2740. // is not allowed.
  2741. if (!obj)
  2742. return;
  2743. while (obj)
  2744. {
  2745. if (obj is IUIComponent)
  2746. {
  2747. var sm:ISystemManager = IUIComponent(obj).systemManager;
  2748. if (sm && !sm.isTopLevel())
  2749. sm = sm.topLevelSystemManager;
  2750. _topLevelSystemManager = sm;
  2751. break;
  2752. }
  2753. obj = obj.parent;
  2754. }
  2755. }
  2756. // capture mouse down so we can switch top level windows and activate
  2757. // the right focus manager before the components inside start
  2758. // processing the event
  2759. if (isTopLevelRoot() || getSandboxRoot() == this)
  2760. addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler, true);
  2761. if (isTopLevelRoot() && stage)
  2762. stage.addEventListener(Event.RESIZE, Stage_resizeHandler, false, 0, true);
  2763. else if (topLevel && stage)
  2764. {
  2765. // listen to resizes on the sandbox root
  2766. var sandboxRoot:DisplayObject = getSandboxRoot();
  2767. if (sandboxRoot != this)
  2768. sandboxRoot.addEventListener(Event.RESIZE, Stage_resizeHandler, false, 0, true);
  2769. }
  2770. var app:IUIComponent;
  2771. // Create a new instance of the toplevel class
  2772. document = app = topLevelWindow = IUIComponent(create());
  2773. if (document)
  2774. {
  2775. // Add listener for the creationComplete event
  2776. IEventDispatcher(app).addEventListener(FlexEvent.CREATION_COMPLETE,
  2777. appCreationCompleteHandler);
  2778. // if somebody has set this in our applicationdomain hierarchy, don't overwrite it
  2779. if (!LoaderConfig._url)
  2780. {
  2781. LoaderConfig._url = loaderInfo.url;
  2782. LoaderConfig._parameters = loaderInfo.parameters;
  2783. }
  2784. if (isStageRoot && stage)
  2785. {
  2786. // stageWidth/stageHeight may have changed between initialize() and now,
  2787. // so refresh our _width and _height here.
  2788. _width = stage.stageWidth;
  2789. _height = stage.stageHeight;
  2790. IFlexDisplayObject(app).setActualSize(_width, _height);
  2791. }
  2792. else
  2793. IFlexDisplayObject(app).setActualSize(loaderInfo.width, loaderInfo.height);
  2794. // Wait for the app to finish its initialization sequence
  2795. // before doing an addChild().
  2796. // Otherwise, the measurement/layout code will cause the
  2797. // player to do a bunch of unnecessary screen repaints,
  2798. // which slows application startup time.
  2799. // Pass the application instance to the preloader.
  2800. // Note: preloader can be null when the user chooses
  2801. // Control > Play in the standalone player.
  2802. if (preloader)
  2803. preloader.registerApplication(app);
  2804. // The Application doesn't get added to the SystemManager in the standard way.
  2805. // We want to recursively create the entire application subtree and process
  2806. // it with the LayoutManager before putting the Application on the display list.
  2807. // So here we what would normally happen inside an override of addChild().
  2808. // Leter, when we actually attach the Application instance,
  2809. // we call super.addChild(), which is the bare player method.
  2810. addingChild(DisplayObject(app));
  2811. childAdded(DisplayObject(app)); // calls app.createChildren()
  2812. }
  2813. else
  2814. {
  2815. document = this;
  2816. }
  2817. }
  2818. /**
  2819. * Override this function if you want to perform any logic
  2820. * when the application has finished initializing itself.
  2821. */
  2822. private function appCreationCompleteHandler(event:FlexEvent):void
  2823. {
  2824. if (!topLevel && parent)
  2825. {
  2826. var obj:DisplayObjectContainer = parent.parent;
  2827. while (obj)
  2828. {
  2829. if (obj is IInvalidating)
  2830. {
  2831. IInvalidating(obj).invalidateSize();
  2832. IInvalidating(obj).invalidateDisplayList();
  2833. return;
  2834. }
  2835. obj = obj.parent;
  2836. }
  2837. }
  2838. if (topLevel && useSWFBridge())
  2839. dispatchInvalidateRequest();
  2840. }
  2841. /**
  2842. * @private
  2843. * Keep track of the size and position of the stage.
  2844. */
  2845. private function Stage_resizeHandler(event:Event = null):void
  2846. {
  2847. if (isDispatchingResizeEvent)
  2848. return;
  2849. var w:Number = 0;
  2850. var h:Number = 0;
  2851. var m:Number;
  2852. var n:Number;
  2853. try
  2854. {
  2855. m = loaderInfo.width;
  2856. n = loaderInfo.height;
  2857. }
  2858. catch (error:Error)
  2859. {
  2860. // Error #2099: The loading object is not sufficiently loaded to provide this information.
  2861. // We get this error because an old Event.RESIZE listener with a weak reference
  2862. // is being called but the SWF has been unloaded.
  2863. if (!_screen)
  2864. _screen = new Rectangle();
  2865. return;
  2866. }
  2867. var align:String = StageAlign.TOP_LEFT;
  2868. // If we don't have access to the stage, then use the size of
  2869. // the sandbox root and align to StageAlign.TOP_LEFT.
  2870. try
  2871. {
  2872. if (stage)
  2873. {
  2874. w = stage.stageWidth;
  2875. h = stage.stageHeight;
  2876. align = stage.align;
  2877. }
  2878. }
  2879. catch (error:SecurityError)
  2880. {
  2881. var sandboxScreen:Rectangle = getSandboxScreen();
  2882. w = sandboxScreen.width;
  2883. h = sandboxScreen.height;
  2884. }
  2885. var x:Number = (m - w) / 2;
  2886. var y:Number = (n - h) / 2;
  2887. if (align == StageAlign.TOP)
  2888. {
  2889. y = 0;
  2890. }
  2891. else if (align == StageAlign.BOTTOM)
  2892. {
  2893. y = n - h;
  2894. }
  2895. else if (align == StageAlign.LEFT)
  2896. {
  2897. x = 0;
  2898. }
  2899. else if (align == StageAlign.RIGHT)
  2900. {
  2901. x = m - w;
  2902. }
  2903. else if (align == StageAlign.TOP_LEFT || align == "LT") // player bug 125020
  2904. {
  2905. y = 0;
  2906. x = 0;
  2907. }
  2908. else if (align == StageAlign.TOP_RIGHT)
  2909. {
  2910. y = 0;
  2911. x = m - w;
  2912. }
  2913. else if (align == StageAlign.BOTTOM_LEFT)
  2914. {
  2915. y = n - h;
  2916. x = 0;
  2917. }
  2918. else if (align == StageAlign.BOTTOM_RIGHT)
  2919. {
  2920. y = n - h;
  2921. x = m - w;
  2922. }
  2923. if (!_screen)
  2924. _screen = new Rectangle();
  2925. _screen.x = x;
  2926. _screen.y = y;
  2927. _screen.width = w;
  2928. _screen.height = h;
  2929. if (isStageRoot)
  2930. {
  2931. _width = stage.stageWidth;
  2932. _height = stage.stageHeight;
  2933. }
  2934. if (event)
  2935. {
  2936. resizeMouseCatcher();
  2937. isDispatchingResizeEvent = true;
  2938. dispatchEvent(event);
  2939. isDispatchingResizeEvent = false;
  2940. }
  2941. }
  2942. /**
  2943. * @private
  2944. * Track mouse clicks to see if we change top-level forms.
  2945. */
  2946. private function mouseDownHandler(event:MouseEvent):void
  2947. {
  2948. // trace("SM:mouseDownHandler " + this);
  2949. // Reset the idle counter.
  2950. idleCounter = 0;
  2951. // If an object was clicked that is inside another system manager
  2952. // in a bridged application, activate the current document because
  2953. // the bridge application is considered part of the main application.
  2954. // We also see mouse clicks on dialogs popped up from compatible applications.
  2955. var bridge:IEventDispatcher = getSWFBridgeOfDisplayObject(event.target as DisplayObject);
  2956. if (bridge && bridgeToFocusManager[bridge] == document.focusManager)
  2957. {
  2958. // trace("SM:mouseDownHandler click in a bridged application");
  2959. if (isTopLevelRoot())
  2960. activateForm(document);
  2961. else
  2962. dispatchActivatedApplicationEvent();
  2963. return;
  2964. }
  2965. if (numModalWindows == 0) // no modal windows are up
  2966. {
  2967. if (!isTopLevelRoot() || forms.length > 1)
  2968. {
  2969. var n:int = forms.length;
  2970. var p:DisplayObject = DisplayObject(event.target);
  2971. var isApplication:Boolean = document.rawChildren.contains(p);
  2972. while (p)
  2973. {
  2974. for (var i:int = 0; i < n; i++)
  2975. {
  2976. var form_i:Object = isRemotePopUp(forms[i]) ? forms[i].window : forms[i];
  2977. if (form_i == p)
  2978. {
  2979. var j:int = 0;
  2980. var index:int;
  2981. var newIndex:int;
  2982. var childList:IChildList;
  2983. if (((p != form) && p is IFocusManagerContainer) ||
  2984. (!isTopLevelRoot() && p == form))
  2985. {
  2986. if (isTopLevelRoot())
  2987. activate(IFocusManagerContainer(p));
  2988. if (p == document)
  2989. dispatchActivatedApplicationEvent();
  2990. else if (p is DisplayObject)
  2991. dispatchActivatedWindowEvent(DisplayObject(p));
  2992. }
  2993. if (popUpChildren.contains(p))
  2994. childList = popUpChildren;
  2995. else
  2996. childList = this;
  2997. index = childList.getChildIndex(p);
  2998. newIndex = index;
  2999. //we need to reset n because activating p's
  3000. //FocusManager could have caused
  3001. //forms.length to have changed.
  3002. n = forms.length;
  3003. for (j = 0; j < n; j++)
  3004. {
  3005. var f:DisplayObject;
  3006. var isRemotePopUp:Boolean = isRemotePopUp(forms[j]);
  3007. if (isRemotePopUp)
  3008. {
  3009. if (forms[j].window is String)
  3010. continue;
  3011. f = forms[j].window;
  3012. }
  3013. else
  3014. f = forms[j];
  3015. if (isRemotePopUp)
  3016. {
  3017. var fChildIndex:int = getChildListIndex(childList, f);
  3018. if (fChildIndex > index)
  3019. newIndex = Math.max(fChildIndex, newIndex);
  3020. }
  3021. else if (childList.contains(f))
  3022. if (childList.getChildIndex(f) > index)
  3023. newIndex = Math.max(childList.getChildIndex(f), newIndex);
  3024. }
  3025. if (newIndex > index && !isApplication)
  3026. childList.setChildIndex(p, newIndex);
  3027. return;
  3028. }
  3029. }
  3030. p = p.parent;
  3031. }
  3032. }
  3033. else
  3034. dispatchActivatedApplicationEvent();
  3035. }
  3036. }
  3037. /**
  3038. * @private
  3039. *
  3040. * Get the index of an object in a given child list.
  3041. *
  3042. * @return index of f in childList, -1 if f is not in childList.
  3043. */
  3044. private static function getChildListIndex(childList:IChildList, f:Object):int
  3045. {
  3046. var index:int = -1;
  3047. try
  3048. {
  3049. index = childList.getChildIndex(DisplayObject(f));
  3050. }
  3051. catch (e:ArgumentError)
  3052. {
  3053. // index has been preset to -1 so just continue.
  3054. }
  3055. return index;
  3056. }
  3057. /**
  3058. * @private
  3059. * Track mouse moves in order to determine idle
  3060. */
  3061. private function mouseMoveHandler(event:MouseEvent):void
  3062. {
  3063. // Reset the idle counter.
  3064. idleCounter = 0;
  3065. }
  3066. /**
  3067. * @private
  3068. * Track mouse moves in order to determine idle.
  3069. */
  3070. private function mouseUpHandler(event:MouseEvent):void
  3071. {
  3072. // Reset the idle counter.
  3073. idleCounter = 0;
  3074. }
  3075. /**
  3076. * @private
  3077. * Called every IDLE_INTERVAL after the first listener
  3078. * registers for 'idle' events.
  3079. * After IDLE_THRESHOLD goes by without any user activity,
  3080. * we dispatch an 'idle' event.
  3081. */
  3082. private function idleTimer_timerHandler(event:TimerEvent):void
  3083. {
  3084. idleCounter++;
  3085. if (idleCounter * IDLE_INTERVAL > IDLE_THRESHOLD)
  3086. dispatchEvent(new FlexEvent(FlexEvent.IDLE));
  3087. }
  3088. /**
  3089. * @private
  3090. *
  3091. * Handle request to unload
  3092. * Forward event, and do some cleanup
  3093. */
  3094. private function beforeUnloadHandler(event:Event):void
  3095. {
  3096. if (topLevel && stage)
  3097. {
  3098. var sandboxRoot:DisplayObject = getSandboxRoot();
  3099. if (sandboxRoot != this)
  3100. sandboxRoot.removeEventListener(Event.RESIZE, Stage_resizeHandler);
  3101. }
  3102. removeParentBridgeListeners();
  3103. dispatchEvent(event);
  3104. }
  3105. /**
  3106. * @private
  3107. *
  3108. * Handle request to unload
  3109. * Forward event, and do some cleanup
  3110. */
  3111. private function unloadHandler(event:Event):void
  3112. {
  3113. dispatchEvent(event);
  3114. }
  3115. //--------------------------------------------------------------------------
  3116. //
  3117. // Sandbox Event handlers for messages from children
  3118. //
  3119. //--------------------------------------------------------------------------
  3120. /**
  3121. * @private
  3122. *
  3123. * Add a popup request handler for domain local request and
  3124. * remote domain requests.
  3125. */
  3126. private function addPopupRequestHandler(event:Event):void
  3127. {
  3128. if (event.target != this && event is SWFBridgeRequest)
  3129. return;
  3130. var popUpRequest:SWFBridgeRequest = SWFBridgeRequest.marshal(event);
  3131. // If there is not for mutual trust between us an the child that wants the
  3132. // popup, then don't host the pop up.
  3133. if (event.target != this)
  3134. {
  3135. var bridgeProvider:ISWFBridgeProvider = swfBridgeGroup.getChildBridgeProvider(
  3136. IEventDispatcher(event.target));
  3137. if (!SecurityUtil.hasMutualTrustBetweenParentAndChild(bridgeProvider))
  3138. {
  3139. return;
  3140. }
  3141. }
  3142. var topMost:Boolean;
  3143. // Need to have mutual trust between two application in order
  3144. // for an application to host another application's popup.
  3145. if (swfBridgeGroup.parentBridge &&
  3146. SecurityUtil.hasMutualTrustBetweenParentAndChild(this))
  3147. {
  3148. // ask the parent to host the popup
  3149. popUpRequest.requestor = swfBridgeGroup.parentBridge;
  3150. getSandboxRoot().dispatchEvent(popUpRequest);
  3151. return;
  3152. }
  3153. // add popup as a child of this system manager
  3154. if (!popUpRequest.data.childList || popUpRequest.data.childList == PopUpManagerChildList.PARENT)
  3155. topMost = popUpRequest.data.parent && popUpChildren.contains(popUpRequest.data.parent);
  3156. else
  3157. topMost = (popUpRequest.data.childList == PopUpManagerChildList.POPUP);
  3158. var children:IChildList;
  3159. children = topMost ? popUpChildren : this;
  3160. children.addChild(DisplayObject(popUpRequest.data.window));
  3161. if (popUpRequest.data.modal)
  3162. numModalWindows++;
  3163. // add popup to the list of managed forms
  3164. var remoteForm:RemotePopUp = new RemotePopUp(popUpRequest.data.window, popUpRequest.requestor);
  3165. forms.push(remoteForm);
  3166. if (!isTopLevelRoot() && swfBridgeGroup)
  3167. {
  3168. // We've added the popup as far as it can go.
  3169. // Add a placeholder to the top level root application
  3170. var request:SWFBridgeRequest = new SWFBridgeRequest(SWFBridgeRequest.ADD_POP_UP_PLACE_HOLDER_REQUEST,
  3171. false, false,
  3172. popUpRequest.requestor,
  3173. { window: popUpRequest.data.window });
  3174. request.data.placeHolderId = NameUtil.displayObjectToString(DisplayObject(popUpRequest.data.window));
  3175. dispatchEvent(request);
  3176. }
  3177. }
  3178. /**
  3179. * @private
  3180. *
  3181. * Message from a child system manager to
  3182. * remove the popup that was added by using the
  3183. * addPopupRequestHandler.
  3184. */
  3185. private function removePopupRequestHandler(event:Event):void
  3186. {
  3187. var popUpRequest:SWFBridgeRequest = SWFBridgeRequest.marshal(event);
  3188. if (swfBridgeGroup.parentBridge &&
  3189. SecurityUtil.hasMutualTrustBetweenParentAndChild(this))
  3190. {
  3191. // since there is mutual trust the popup is hosted by the parent.
  3192. popUpRequest.requestor = swfBridgeGroup.parentBridge;
  3193. getSandboxRoot().dispatchEvent(popUpRequest);
  3194. return;
  3195. }
  3196. if (popUpChildren.contains(popUpRequest.data.window))
  3197. popUpChildren.removeChild(popUpRequest.data.window);
  3198. else
  3199. removeChild(DisplayObject(popUpRequest.data.window));
  3200. if (popUpRequest.data.modal)
  3201. numModalWindows--;
  3202. removeRemotePopUp(new RemotePopUp(popUpRequest.data.window, popUpRequest.requestor));
  3203. if (!isTopLevelRoot() && swfBridgeGroup)
  3204. {
  3205. // if we got here we know the parent is untrusted, so remove placeholders
  3206. var request:SWFBridgeRequest = new SWFBridgeRequest(SWFBridgeRequest.REMOVE_POP_UP_PLACE_HOLDER_REQUEST,
  3207. false, false,
  3208. popUpRequest.requestor,
  3209. {placeHolderId: NameUtil.displayObjectToString(popUpRequest.data.window)
  3210. });
  3211. dispatchEvent(request);
  3212. }
  3213. }
  3214. /**
  3215. * @private
  3216. *
  3217. * Handle request to add a popup placeholder.
  3218. * The placeholder represents an untrusted form that is hosted
  3219. * elsewhere.
  3220. */
  3221. private function addPlaceholderPopupRequestHandler(event:Event):void
  3222. {
  3223. var popUpRequest:SWFBridgeRequest = SWFBridgeRequest.marshal(event);
  3224. if (event.target != this && event is SWFBridgeRequest)
  3225. return;
  3226. if (!forwardPlaceholderRequest(popUpRequest, true))
  3227. {
  3228. // Create a RemotePopUp and add it.
  3229. var remoteForm:RemotePopUp = new RemotePopUp(popUpRequest.data.placeHolderId, popUpRequest.requestor);
  3230. forms.push(remoteForm);
  3231. }
  3232. }
  3233. /**
  3234. * @private
  3235. *
  3236. * Handle request to add a popup placeholder.
  3237. * The placeholder represents an untrusted form that is hosted
  3238. * elsewhere.
  3239. */
  3240. private function removePlaceholderPopupRequestHandler(event:Event):void
  3241. {
  3242. var popUpRequest:SWFBridgeRequest = SWFBridgeRequest.marshal(event);
  3243. if (!forwardPlaceholderRequest(popUpRequest, false))
  3244. {
  3245. // remove the placeholder from forms array
  3246. var n:int = forms.length;
  3247. for (var i:int = 0; i < n; i++)
  3248. {
  3249. if (isRemotePopUp(forms[i]))
  3250. {
  3251. if (forms[i].window == popUpRequest.data.placeHolderId &&
  3252. forms[i].bridge == popUpRequest.requestor)
  3253. {
  3254. forms.splice(i, 1);
  3255. break;
  3256. }
  3257. }
  3258. }
  3259. }
  3260. }
  3261. /**
  3262. * Forward a form event update the parent chain.
  3263. * Takes care of removing object references and substituting
  3264. * ids when an untrusted boundry is crossed.
  3265. */
  3266. private function forwardFormEvent(event:SWFBridgeEvent):Boolean
  3267. {
  3268. if (isTopLevelRoot())
  3269. return false;
  3270. var bridge:IEventDispatcher = swfBridgeGroup.parentBridge;
  3271. if (bridge)
  3272. {
  3273. var sbRoot:DisplayObject = getSandboxRoot();
  3274. event.data.notifier = bridge;
  3275. if (sbRoot == this)
  3276. {
  3277. if (!(event.data.window is String))
  3278. event.data.window = NameUtil.displayObjectToString(DisplayObject(event.data.window));
  3279. else
  3280. event.data.window = NameUtil.displayObjectToString(DisplayObject(this)) + "." + event.data.window;
  3281. bridge.dispatchEvent(event);
  3282. }
  3283. else
  3284. {
  3285. if (event.data.window is String)
  3286. event.data.window = NameUtil.displayObjectToString(DisplayObject(this)) + "." + event.data.window;
  3287. sbRoot.dispatchEvent(event);
  3288. }
  3289. }
  3290. return true;
  3291. }
  3292. /**
  3293. * Forward an AddPlaceholder request up the parent chain, if needed.
  3294. *
  3295. * @param request request to either add or remove a pop up placeholder.
  3296. * @param addPlaceholder true if adding a placeholder, false it removing a placeholder.
  3297. * @return true if the request was forwared, false otherwise
  3298. */
  3299. private function forwardPlaceholderRequest(request:SWFBridgeRequest, addPlaceholder:Boolean):Boolean
  3300. {
  3301. // Only the top level root tracks the placeholders.
  3302. // If we are not the top level root then keep passing
  3303. // the message up the parent chain.
  3304. if (isTopLevelRoot())
  3305. return false;
  3306. // If the window object is passed, then this is the first
  3307. // stop on the way up the parent chain.
  3308. var refObj:Object = null;
  3309. var oldId:String = null;
  3310. if (request.data.window)
  3311. {
  3312. refObj = request.data.window;
  3313. // null this ref out so untrusted parent cannot see
  3314. request.data.window = null;
  3315. }
  3316. else
  3317. {
  3318. refObj = request.requestor;
  3319. // prefix the existing id with the id of this object
  3320. oldId = request.data.placeHolderId;
  3321. request.data.placeHolderId = NameUtil.displayObjectToString(this) + "." + request.data.placeHolderId;
  3322. }
  3323. if (addPlaceholder)
  3324. addPlaceholderId(request.data.placeHolderId, oldId, request.requestor, refObj);
  3325. else
  3326. removePlaceholderId(request.data.placeHolderId);
  3327. var sbRoot:DisplayObject = getSandboxRoot();
  3328. var bridge:IEventDispatcher = swfBridgeGroup.parentBridge;
  3329. request.requestor = bridge;
  3330. if (sbRoot == this)
  3331. bridge.dispatchEvent(request);
  3332. else
  3333. sbRoot.dispatchEvent(request);
  3334. return true;
  3335. }
  3336. /**
  3337. * One of the system managers in another sandbox deactivated and sent a message
  3338. * to the top level system manager. In response the top-level system manager
  3339. * needs to find a new form to activate.
  3340. */
  3341. private function deactivateFormSandboxEventHandler(event:Event):void
  3342. {
  3343. // trace("bridgeDeactivateFormEventHandler");
  3344. if (event is SWFBridgeRequest)
  3345. return;
  3346. var bridgeEvent:SWFBridgeEvent = SWFBridgeEvent.marshal(event);
  3347. if (!forwardFormEvent(bridgeEvent))
  3348. {
  3349. // deactivate the form
  3350. if (isRemotePopUp(form) &&
  3351. RemotePopUp(form).window == bridgeEvent.data.window &&
  3352. RemotePopUp(form).bridge == bridgeEvent.data.notifier)
  3353. deactivateForm(form);
  3354. }
  3355. }
  3356. /**
  3357. * A form in one of the system managers in another sandbox has been activated.
  3358. * The form being activate is identified.
  3359. * In response the top-level system manager needs to activate the given form
  3360. * and deactivate the currently active form, if any.
  3361. */
  3362. private function activateFormSandboxEventHandler(event:Event):void
  3363. {
  3364. // trace("bridgeActivateFormEventHandler");
  3365. var bridgeEvent:SWFBridgeEvent = SWFBridgeEvent.marshal(event);
  3366. if (!forwardFormEvent(bridgeEvent))
  3367. // just call activate on the remote form.
  3368. activateForm(new RemotePopUp(bridgeEvent.data.window, bridgeEvent.data.notifier));
  3369. }
  3370. /**
  3371. * One of the system managers in another sandbox activated and sent a message
  3372. * to the top level system manager to deactivate this form. In response the top-level system manager
  3373. * needs to deactivate all other forms except the top level system manager's.
  3374. */
  3375. private function activateApplicationSandboxEventHandler(event:Event):void
  3376. {
  3377. // trace("bridgeActivateApplicationEventHandler");
  3378. if (!isTopLevelRoot())
  3379. {
  3380. swfBridgeGroup.parentBridge.dispatchEvent(event);
  3381. return;
  3382. }
  3383. // An application was activated, active the main document.
  3384. activateForm(document);
  3385. }
  3386. /**
  3387. * @private
  3388. *
  3389. * Re-dispatch events sent over the bridge to listeners on this
  3390. * system manager. PopUpManager is expected to listen to these
  3391. * events.
  3392. */
  3393. private function modalWindowRequestHandler(event:Event):void
  3394. {
  3395. if (event is SWFBridgeRequest)
  3396. return;
  3397. var request:SWFBridgeRequest = SWFBridgeRequest.marshal(event);
  3398. if (!preProcessModalWindowRequest(request, getSandboxRoot()))
  3399. return;
  3400. // Ensure a PopUpManager exists and dispatch the request it is
  3401. // listening for.
  3402. Singleton.getInstance("mx.managers::IPopUpManager");
  3403. dispatchEvent(request);
  3404. }
  3405. /**
  3406. * @private
  3407. *
  3408. * Calculate the visible rectangle of the requesting application in this
  3409. * application. Forward the request to our parent to see this the rectangle
  3410. * is further reduced. Continue up the parent chain until the top level
  3411. * root parent is reached.
  3412. */
  3413. private function getVisibleRectRequestHandler(event:Event):void
  3414. {
  3415. if (event is SWFBridgeRequest)
  3416. return;
  3417. var request:SWFBridgeRequest = SWFBridgeRequest.marshal(event);
  3418. var rect:Rectangle = Rectangle(request.data);
  3419. var owner:DisplayObject = DisplayObject(swfBridgeGroup.getChildBridgeProvider(request.requestor));
  3420. var localRect:Rectangle;
  3421. var forwardRequest:Boolean = true;
  3422. // Check if the request in a pop up. If it is then don't
  3423. // forward the request to our parent because we don't want
  3424. // to reduce the visible rect of the dialog base on the
  3425. // visible rect of applications in the main app.
  3426. if (!DisplayObjectContainer(document).contains(owner))
  3427. forwardRequest = false;
  3428. if (owner is ISWFLoader)
  3429. localRect = ISWFLoader(owner).getVisibleApplicationRect();
  3430. else
  3431. {
  3432. localRect = owner.getBounds(this);
  3433. var pt:Point = localToGlobal(localRect.topLeft);
  3434. localRect.x = pt.x;
  3435. localRect.y = pt.y;
  3436. }
  3437. rect = rect.intersection(localRect); // update rect
  3438. request.data = rect;
  3439. // forward request
  3440. if (forwardRequest && useSWFBridge())
  3441. {
  3442. var bridge:IEventDispatcher = swfBridgeGroup.parentBridge;
  3443. request.requestor = bridge;
  3444. bridge.dispatchEvent(request);
  3445. }
  3446. Object(event).data = request.data; // update request
  3447. }
  3448. /**
  3449. * @private
  3450. *
  3451. * Notify the topLevelRoot that we don't want the mouseCursor shown
  3452. * Forward upward if necessary.
  3453. */
  3454. private function hideMouseCursorRequestHandler(event:Event):void
  3455. {
  3456. if (!isTopLevelRoot() && event is SWFBridgeRequest)
  3457. return;
  3458. var request:SWFBridgeRequest = SWFBridgeRequest.marshal(event);
  3459. // forward request
  3460. if (!isTopLevelRoot())
  3461. {
  3462. var bridge:IEventDispatcher = swfBridgeGroup.parentBridge;
  3463. request.requestor = bridge;
  3464. bridge.dispatchEvent(request);
  3465. }
  3466. else if (eventProxy)
  3467. SystemManagerGlobals.showMouseCursor = false;
  3468. }
  3469. /**
  3470. * @private
  3471. *
  3472. * Ask the topLevelRoot if anybody don't want the mouseCursor shown
  3473. * Forward upward if necessary.
  3474. */
  3475. private function showMouseCursorRequestHandler(event:Event):void
  3476. {
  3477. if (!isTopLevelRoot() && event is SWFBridgeRequest)
  3478. return;
  3479. var request:SWFBridgeRequest = SWFBridgeRequest.marshal(event);
  3480. // forward request
  3481. if (!isTopLevelRoot())
  3482. {
  3483. var bridge:IEventDispatcher = swfBridgeGroup.parentBridge;
  3484. request.requestor = bridge;
  3485. bridge.dispatchEvent(request);
  3486. Object(event).data = request.data; // update request
  3487. }
  3488. else if (eventProxy)
  3489. Object(event).data = SystemManagerGlobals.showMouseCursor;
  3490. }
  3491. /**
  3492. * @private
  3493. *
  3494. * Ask the topLevelRoot if anybody don't want the mouseCursor shown
  3495. * Forward upward if necessary.
  3496. */
  3497. private function resetMouseCursorRequestHandler(event:Event):void
  3498. {
  3499. if (!isTopLevelRoot() && event is SWFBridgeRequest)
  3500. return;
  3501. var request:SWFBridgeRequest = SWFBridgeRequest.marshal(event);
  3502. // forward request
  3503. if (!isTopLevelRoot())
  3504. {
  3505. var bridge:IEventDispatcher = swfBridgeGroup.parentBridge;
  3506. request.requestor = bridge;
  3507. bridge.dispatchEvent(request);
  3508. }
  3509. else if (eventProxy)
  3510. SystemManagerGlobals.showMouseCursor = true;
  3511. }
  3512. private function resetMouseCursorTracking(event:Event):void
  3513. {
  3514. if (isTopLevelRoot())
  3515. {
  3516. SystemManagerGlobals.showMouseCursor = true;
  3517. }
  3518. else if (swfBridgeGroup.parentBridge)
  3519. {
  3520. var cursorRequest:SWFBridgeRequest = new SWFBridgeRequest(SWFBridgeRequest.RESET_MOUSE_CURSOR_REQUEST);
  3521. var bridge:IEventDispatcher = swfBridgeGroup.parentBridge;
  3522. cursorRequest.requestor = bridge;
  3523. bridge.dispatchEvent(cursorRequest);
  3524. }
  3525. }
  3526. //--------------------------------------------------------------------------
  3527. //
  3528. // Sandbox Event handlers for messages from parent
  3529. //
  3530. //--------------------------------------------------------------------------
  3531. /**
  3532. * @private
  3533. *
  3534. * Sent by the SWFLoader to change the size of the application it loaded.
  3535. */
  3536. private function setActualSizeRequestHandler(event:Event):void
  3537. {
  3538. var eObj:Object = Object(event);
  3539. setActualSize(eObj.data.width, eObj.data.height);
  3540. }
  3541. /**
  3542. * @private
  3543. *
  3544. * Get the size of this System Manager.
  3545. * Sent by a SWFLoader.
  3546. */
  3547. private function getSizeRequestHandler(event:Event):void
  3548. {
  3549. var eObj:Object = Object(event);
  3550. eObj.data = { width: measuredWidth, height: measuredHeight};
  3551. }
  3552. /**
  3553. * @private
  3554. *
  3555. * Handle request to activate a particular form.
  3556. *
  3557. */
  3558. private function activateRequestHandler(event:Event):void
  3559. {
  3560. var request:SWFBridgeRequest = SWFBridgeRequest.marshal(event);
  3561. // If data is a String, then we need to parse the id to find
  3562. // the form or the next bridge to pass the message to.
  3563. // If the data is a SystemMangerProxy we can just activate the
  3564. // form.
  3565. var child:Object = request.data;
  3566. var nextId:String = null;
  3567. if (request.data is String)
  3568. {
  3569. var placeholder:PlaceholderData = idToPlaceholder[request.data];
  3570. child = placeholder.data;
  3571. nextId = placeholder.id;
  3572. // check if the dialog is hosted on this system manager
  3573. if (nextId == null)
  3574. {
  3575. var popUp:RemotePopUp = findRemotePopUp(child, placeholder.bridge);
  3576. if (popUp)
  3577. {
  3578. activateRemotePopUp(popUp);
  3579. return;
  3580. }
  3581. }
  3582. }
  3583. if (child is SystemManagerProxy)
  3584. {
  3585. // activate request from the top-level system manager.
  3586. var smp:SystemManagerProxy = SystemManagerProxy(child);
  3587. var f:IFocusManagerContainer = findFocusManagerContainer(smp);
  3588. if (smp && f)
  3589. smp.activateByProxy(f);
  3590. }
  3591. else if (child is IFocusManagerContainer)
  3592. IFocusManagerContainer(child).focusManager.activate();
  3593. else if (child is IEventDispatcher)
  3594. {
  3595. request.data = nextId;
  3596. request.requestor = IEventDispatcher(child);
  3597. IEventDispatcher(child).dispatchEvent(request);
  3598. }
  3599. else
  3600. throw new Error(); // should never get here
  3601. }
  3602. /**
  3603. * @private
  3604. *
  3605. * Handle request to deactivate a particular form.
  3606. *
  3607. */
  3608. private function deactivateRequestHandler(event:Event):void
  3609. {
  3610. var request:SWFBridgeRequest = SWFBridgeRequest.marshal(event);
  3611. var child:Object = request.data;
  3612. var nextId:String = null;
  3613. if (request.data is String)
  3614. {
  3615. var placeholder:PlaceholderData = idToPlaceholder[request.data];
  3616. child = placeholder.data;
  3617. nextId = placeholder.id;
  3618. // check if the dialog is hosted on this system manager
  3619. if (nextId == null)
  3620. {
  3621. var popUp:RemotePopUp = findRemotePopUp(child, placeholder.bridge);
  3622. if (popUp)
  3623. {
  3624. deactivateRemotePopUp(popUp);
  3625. return;
  3626. }
  3627. }
  3628. }
  3629. if (child is SystemManagerProxy)
  3630. {
  3631. // deactivate request from the top-level system manager.
  3632. var smp:SystemManagerProxy = SystemManagerProxy(child);
  3633. var f:IFocusManagerContainer = findFocusManagerContainer(smp);
  3634. if (smp && f)
  3635. smp.deactivateByProxy(f);
  3636. }
  3637. else if (child is IFocusManagerContainer)
  3638. IFocusManagerContainer(child).focusManager.deactivate();
  3639. else if (child is IEventDispatcher)
  3640. {
  3641. request.data = nextId;
  3642. request.requestor = IEventDispatcher(child);
  3643. IEventDispatcher(child).dispatchEvent(request);
  3644. return;
  3645. }
  3646. else
  3647. throw new Error();
  3648. }
  3649. //--------------------------------------------------------------------------
  3650. //
  3651. // Sandbox Event handlers for messages from either the
  3652. // parent or child
  3653. //
  3654. //--------------------------------------------------------------------------
  3655. /**
  3656. * Is the child in event.data this system manager or a child of this
  3657. * system manager?
  3658. *
  3659. * Set the data property to indicate if the display object is a child
  3660. */
  3661. private function isBridgeChildHandler(event:Event):void
  3662. {
  3663. // if we are broadcasting messages, ignore the messages
  3664. // we send to ourselves.
  3665. if (event is SWFBridgeRequest)
  3666. return;
  3667. var eObj:Object = Object(event);
  3668. eObj.data = eObj.data && rawChildren.contains(eObj.data as DisplayObject);
  3669. }
  3670. /**
  3671. * Can this form be activated. The current test is if the given pop up
  3672. * is visible and is enabled.
  3673. *
  3674. * Set the data property to indicate if can be activated
  3675. */
  3676. private function canActivateHandler(event:Event):void
  3677. {
  3678. var eObj:Object = Object(event);
  3679. // If data is a String, then we need to parse the id to find
  3680. // the form or the next bridge to pass the message to.
  3681. // If the data is a SystemMangerProxy we can just activate the
  3682. // form.
  3683. var request:SWFBridgeRequest;
  3684. var child:Object = eObj.data;
  3685. var nextId:String = null;
  3686. if (eObj.data is String)
  3687. {
  3688. var placeholder:PlaceholderData = idToPlaceholder[eObj.data];
  3689. child = placeholder.data;
  3690. nextId = placeholder.id;
  3691. // check if the dialog is hosted on this system manager
  3692. if (nextId == null)
  3693. {
  3694. var popUp:RemotePopUp = findRemotePopUp(child, placeholder.bridge);
  3695. if (popUp)
  3696. {
  3697. request = new SWFBridgeRequest(SWFBridgeRequest.CAN_ACTIVATE_POP_UP_REQUEST,
  3698. false, false,
  3699. IEventDispatcher(popUp.bridge),
  3700. popUp.window);
  3701. if (popUp.bridge)
  3702. {
  3703. popUp.bridge.dispatchEvent(request);
  3704. eObj.data = request.data;
  3705. }
  3706. return;
  3707. }
  3708. }
  3709. }
  3710. if (child is SystemManagerProxy)
  3711. {
  3712. var smp:SystemManagerProxy = SystemManagerProxy(child);
  3713. var f:IFocusManagerContainer = findFocusManagerContainer(smp);
  3714. eObj.data = smp && f && canActivateLocalComponent(f);
  3715. }
  3716. else if (child is IFocusManagerContainer)
  3717. {
  3718. eObj.data = canActivateLocalComponent(child);
  3719. }
  3720. else if (child is IEventDispatcher)
  3721. {
  3722. var bridge:IEventDispatcher = IEventDispatcher(child);
  3723. request = new SWFBridgeRequest(SWFBridgeRequest.CAN_ACTIVATE_POP_UP_REQUEST,
  3724. false, false,
  3725. bridge,
  3726. nextId);
  3727. if (bridge)
  3728. {
  3729. bridge.dispatchEvent(request);
  3730. eObj.data = request.data;
  3731. }
  3732. }
  3733. else
  3734. throw new Error(); // should never get here
  3735. }
  3736. /**
  3737. * @private
  3738. *
  3739. * Test if a display object is in an applcation we want to communicate with over a bridge.
  3740. *
  3741. */
  3742. public function isDisplayObjectInABridgedApplication(displayObject:DisplayObject):Boolean
  3743. {
  3744. return getSWFBridgeOfDisplayObject(displayObject) != null;
  3745. }
  3746. /**
  3747. * @private
  3748. *
  3749. * If a display object is in a bridged application, then return the SWFBridge
  3750. * that is used to communcation with that application. Otherwise return null.
  3751. *
  3752. * @param displayObject The object to test.
  3753. *
  3754. * @return The IEventDispather that represents the SWFBridge that should
  3755. * be used to communicate with this object, if the display object is in a
  3756. * bridge application. If the display object is not in a bridge application,
  3757. * then null is returned.
  3758. *
  3759. */
  3760. private function getSWFBridgeOfDisplayObject(displayObject:DisplayObject):IEventDispatcher
  3761. {
  3762. if (swfBridgeGroup)
  3763. {
  3764. var request:SWFBridgeRequest = new SWFBridgeRequest(SWFBridgeRequest.IS_BRIDGE_CHILD_REQUEST,
  3765. false, false, null, displayObject);
  3766. var children:Array = swfBridgeGroup.getChildBridges();
  3767. var n:int = children.length;
  3768. for (var i:int = 0; i < n; i++)
  3769. {
  3770. var childBridge:IEventDispatcher = IEventDispatcher(children[i]);
  3771. // No need to test a child if it does not trust us, we will never see
  3772. // their display objects.
  3773. // Also, if the we don't trust the child don't send them a display object.
  3774. var bp:ISWFBridgeProvider = swfBridgeGroup.getChildBridgeProvider(childBridge);
  3775. if (SecurityUtil.hasMutualTrustBetweenParentAndChild(bp))
  3776. {
  3777. childBridge.dispatchEvent(request);
  3778. if (request.data == true)
  3779. return childBridge;
  3780. // reset data property
  3781. request.data = displayObject;
  3782. }
  3783. }
  3784. }
  3785. return null;
  3786. }
  3787. /**
  3788. * redispatch certian events to other top-level windows
  3789. */
  3790. private function multiWindowRedispatcher(event:Event):void
  3791. {
  3792. if (!dispatchingToSystemManagers)
  3793. {
  3794. dispatchEventToOtherSystemManagers(event);
  3795. }
  3796. }
  3797. /**
  3798. * Create the requested manager.
  3799. */
  3800. private function initManagerHandler(event:Event):void
  3801. {
  3802. if (!dispatchingToSystemManagers)
  3803. {
  3804. dispatchEventToOtherSystemManagers(event);
  3805. }
  3806. // if we are broadcasting messages, ignore the messages
  3807. // we send to ourselves.
  3808. if (event is InterManagerRequest)
  3809. return;
  3810. // initialize the registered manager implementation
  3811. var name:String = event["name"];
  3812. try
  3813. {
  3814. Singleton.getInstance(name);
  3815. }
  3816. catch (e:Error)
  3817. {
  3818. }
  3819. }
  3820. /**
  3821. * Adds a child to the requested childList.
  3822. *
  3823. * @param layer The child list that the child should be added to. The valid choices are
  3824. * "popUpChildren", "cursorChildren", and "toolTipChildren". The choices match the property
  3825. * names of ISystemManager and that is the list where the child is added.
  3826. *
  3827. * @param child The child to add.
  3828. */
  3829. public function addChildToSandboxRoot(layer:String, child:DisplayObject):void
  3830. {
  3831. if (getSandboxRoot() == this)
  3832. {
  3833. this[layer].addChild(child);
  3834. }
  3835. else
  3836. {
  3837. addingChild(child);
  3838. var me:InterManagerRequest = new InterManagerRequest(InterManagerRequest.SYSTEM_MANAGER_REQUEST);
  3839. me.name = layer + ".addChild";
  3840. me.value = child;
  3841. getSandboxRoot().dispatchEvent(me);
  3842. childAdded(child);
  3843. }
  3844. }
  3845. /**
  3846. * Removes a child from the requested childList.
  3847. *
  3848. * @param layer The child list that the child should be removed from. The valid choices are
  3849. * "popUpChildren", "cursorChildren", and "toolTipChildren". The choices match the property
  3850. * names of ISystemManager and that is the list where the child is removed from.
  3851. *
  3852. * @param child The child to remove.
  3853. */
  3854. public function removeChildFromSandboxRoot(layer:String, child:DisplayObject):void
  3855. {
  3856. if (getSandboxRoot() == this)
  3857. {
  3858. this[layer].removeChild(child);
  3859. }
  3860. else
  3861. {
  3862. removingChild(child);
  3863. var me:InterManagerRequest = new InterManagerRequest(InterManagerRequest.SYSTEM_MANAGER_REQUEST);
  3864. me.name = layer + ".removeChild";
  3865. me.value = child;
  3866. getSandboxRoot().dispatchEvent(me);
  3867. childRemoved(child);
  3868. }
  3869. }
  3870. /**
  3871. * Perform the requested action from a trusted dispatcher.
  3872. */
  3873. private function systemManagerHandler(event:Event):void
  3874. {
  3875. if (event["name"] == "sameSandbox")
  3876. {
  3877. event["value"] = currentSandboxEvent == event["value"];
  3878. return;
  3879. }
  3880. else if (event["name"] == "hasSWFBridges")
  3881. {
  3882. event["value"] = hasSWFBridges();
  3883. return;
  3884. }
  3885. // if we are broadcasting messages, ignore the messages
  3886. // we send to ourselves.
  3887. if (event is InterManagerRequest)
  3888. return;
  3889. // initialize the registered manager implementation
  3890. var name:String = event["name"];
  3891. switch (name)
  3892. {
  3893. case "popUpChildren.addChild":
  3894. popUpChildren.addChild(event["value"]);
  3895. break;
  3896. case "popUpChildren.removeChild":
  3897. popUpChildren.removeChild(event["value"]);
  3898. break;
  3899. case "cursorChildren.addChild":
  3900. cursorChildren.addChild(event["value"]);
  3901. break;
  3902. case "cursorChildren.removeChild":
  3903. cursorChildren.removeChild(event["value"]);
  3904. break;
  3905. case "toolTipChildren.addChild":
  3906. toolTipChildren.addChild(event["value"]);
  3907. break;
  3908. case "toolTipChildren.removeChild":
  3909. toolTipChildren.removeChild(event["value"]);
  3910. break;
  3911. case "screen":
  3912. event["value"] = screen;
  3913. break;
  3914. case "application":
  3915. event["value"] = application;
  3916. break;
  3917. case "isTopLevelRoot":
  3918. event["value"] = isTopLevelRoot();
  3919. break;
  3920. case "getVisibleApplicationRect":
  3921. event["value"] = getVisibleApplicationRect();
  3922. break;
  3923. case "bringToFront":
  3924. if (event["value"].topMost)
  3925. popUpChildren.setChildIndex(DisplayObject(event["value"].popUp), popUpChildren.numChildren - 1);
  3926. else
  3927. setChildIndex(DisplayObject(event["value"].popUp), numChildren - 1);
  3928. break;
  3929. }
  3930. }
  3931. // fake out mouseX/mouseY
  3932. mx_internal var _mouseX:*;
  3933. mx_internal var _mouseY:*;
  3934. /**
  3935. * @private
  3936. */
  3937. override public function get mouseX():Number
  3938. {
  3939. if (_mouseX === undefined)
  3940. return super.mouseX;
  3941. return _mouseX;
  3942. }
  3943. /**
  3944. * @private
  3945. */
  3946. override public function get mouseY():Number
  3947. {
  3948. if (_mouseY === undefined)
  3949. return super.mouseY;
  3950. return _mouseY;
  3951. }
  3952. /**
  3953. * Get the size of our sandbox's screen property.
  3954. *
  3955. * Only the screen property should need to call this function.
  3956. *
  3957. * The function assumes the caller does not have access to the stage.
  3958. *
  3959. */
  3960. private function getSandboxScreen():Rectangle
  3961. {
  3962. // If we don't have access to the stage, use the size of
  3963. // our sandbox root.
  3964. var sandboxRoot:DisplayObject = getSandboxRoot();
  3965. var sandboxScreen:Rectangle;
  3966. if (sandboxRoot == this)
  3967. // we don't have access the stage so use the width and
  3968. // height of the application.
  3969. sandboxScreen = new Rectangle(0, 0, width, height);
  3970. else if (sandboxRoot == topLevelSystemManager)
  3971. {
  3972. var sm:DisplayObject = DisplayObject(topLevelSystemManager);
  3973. sandboxScreen = new Rectangle(0, 0, sm.width, sm.height);
  3974. }
  3975. else
  3976. {
  3977. var me:InterManagerRequest = new InterManagerRequest(InterManagerRequest.SYSTEM_MANAGER_REQUEST, false, false,
  3978. "screen");
  3979. sandboxRoot.dispatchEvent(me);
  3980. // me.value now contains the screen property of the sandbox root.
  3981. sandboxScreen = Rectangle(me.value);
  3982. }
  3983. return sandboxScreen;
  3984. }
  3985. /**
  3986. * The system manager proxy has only one child that is a focus manager container.
  3987. * Iterate thru the children until we find it.
  3988. */
  3989. mx_internal function findFocusManagerContainer(smp:SystemManagerProxy):IFocusManagerContainer
  3990. {
  3991. var children:IChildList = smp.rawChildren;
  3992. var numChildren:int = children.numChildren;
  3993. for (var i:int = 0; i < numChildren; i++)
  3994. {
  3995. var child:DisplayObject = children.getChildAt(i);
  3996. if (child is IFocusManagerContainer)
  3997. {
  3998. return IFocusManagerContainer(child);
  3999. }
  4000. }
  4001. return null;
  4002. }
  4003. /**
  4004. * @private
  4005. *
  4006. * Listen to messages this System Manager needs to service from its children.
  4007. */
  4008. mx_internal function addChildBridgeListeners(bridge:IEventDispatcher):void
  4009. {
  4010. if (!topLevel && topLevelSystemManager)
  4011. {
  4012. SystemManager(topLevelSystemManager).addChildBridgeListeners(bridge);
  4013. return;
  4014. }
  4015. bridge.addEventListener(SWFBridgeRequest.ADD_POP_UP_REQUEST, addPopupRequestHandler);
  4016. bridge.addEventListener(SWFBridgeRequest.REMOVE_POP_UP_REQUEST, removePopupRequestHandler);
  4017. bridge.addEventListener(SWFBridgeRequest.ADD_POP_UP_PLACE_HOLDER_REQUEST, addPlaceholderPopupRequestHandler);
  4018. bridge.addEventListener(SWFBridgeRequest.REMOVE_POP_UP_PLACE_HOLDER_REQUEST, removePlaceholderPopupRequestHandler);
  4019. bridge.addEventListener(SWFBridgeEvent.BRIDGE_WINDOW_ACTIVATE, activateFormSandboxEventHandler);
  4020. bridge.addEventListener(SWFBridgeEvent.BRIDGE_WINDOW_DEACTIVATE, deactivateFormSandboxEventHandler);
  4021. bridge.addEventListener(SWFBridgeEvent.BRIDGE_APPLICATION_ACTIVATE, activateApplicationSandboxEventHandler);
  4022. bridge.addEventListener(EventListenerRequest.ADD_EVENT_LISTENER_REQUEST, eventListenerRequestHandler, false, 0, true);
  4023. bridge.addEventListener(EventListenerRequest.REMOVE_EVENT_LISTENER_REQUEST, eventListenerRequestHandler, false, 0, true);
  4024. bridge.addEventListener(SWFBridgeRequest.CREATE_MODAL_WINDOW_REQUEST, modalWindowRequestHandler);
  4025. bridge.addEventListener(SWFBridgeRequest.SHOW_MODAL_WINDOW_REQUEST, modalWindowRequestHandler);
  4026. bridge.addEventListener(SWFBridgeRequest.HIDE_MODAL_WINDOW_REQUEST, modalWindowRequestHandler);
  4027. bridge.addEventListener(SWFBridgeRequest.GET_VISIBLE_RECT_REQUEST, getVisibleRectRequestHandler);
  4028. bridge.addEventListener(SWFBridgeRequest.HIDE_MOUSE_CURSOR_REQUEST, hideMouseCursorRequestHandler);
  4029. bridge.addEventListener(SWFBridgeRequest.SHOW_MOUSE_CURSOR_REQUEST, showMouseCursorRequestHandler);
  4030. bridge.addEventListener(SWFBridgeRequest.RESET_MOUSE_CURSOR_REQUEST, resetMouseCursorRequestHandler);
  4031. }
  4032. /**
  4033. * @private
  4034. *
  4035. * Remove all child listeners.
  4036. */
  4037. mx_internal function removeChildBridgeListeners(bridge:IEventDispatcher):void
  4038. {
  4039. if (!topLevel && topLevelSystemManager)
  4040. {
  4041. SystemManager(topLevelSystemManager).removeChildBridgeListeners(bridge);
  4042. return;
  4043. }
  4044. bridge.removeEventListener(SWFBridgeRequest.ADD_POP_UP_REQUEST, addPopupRequestHandler);
  4045. bridge.removeEventListener(SWFBridgeRequest.REMOVE_POP_UP_REQUEST, removePopupRequestHandler);
  4046. bridge.removeEventListener(SWFBridgeRequest.ADD_POP_UP_PLACE_HOLDER_REQUEST, addPlaceholderPopupRequestHandler);
  4047. bridge.removeEventListener(SWFBridgeRequest.REMOVE_POP_UP_PLACE_HOLDER_REQUEST, removePlaceholderPopupRequestHandler);
  4048. bridge.removeEventListener(SWFBridgeEvent.BRIDGE_WINDOW_ACTIVATE, activateFormSandboxEventHandler);
  4049. bridge.removeEventListener(SWFBridgeEvent.BRIDGE_WINDOW_DEACTIVATE, deactivateFormSandboxEventHandler);
  4050. bridge.removeEventListener(SWFBridgeEvent.BRIDGE_APPLICATION_ACTIVATE, activateApplicationSandboxEventHandler);
  4051. bridge.removeEventListener(EventListenerRequest.ADD_EVENT_LISTENER_REQUEST, eventListenerRequestHandler);
  4052. bridge.removeEventListener(EventListenerRequest.REMOVE_EVENT_LISTENER_REQUEST, eventListenerRequestHandler);
  4053. bridge.removeEventListener(SWFBridgeRequest.CREATE_MODAL_WINDOW_REQUEST, modalWindowRequestHandler);
  4054. bridge.removeEventListener(SWFBridgeRequest.SHOW_MODAL_WINDOW_REQUEST, modalWindowRequestHandler);
  4055. bridge.removeEventListener(SWFBridgeRequest.HIDE_MODAL_WINDOW_REQUEST, modalWindowRequestHandler);
  4056. bridge.removeEventListener(SWFBridgeRequest.GET_VISIBLE_RECT_REQUEST, getVisibleRectRequestHandler);
  4057. bridge.removeEventListener(SWFBridgeRequest.HIDE_MOUSE_CURSOR_REQUEST, hideMouseCursorRequestHandler);
  4058. bridge.removeEventListener(SWFBridgeRequest.SHOW_MOUSE_CURSOR_REQUEST, showMouseCursorRequestHandler);
  4059. bridge.removeEventListener(SWFBridgeRequest.RESET_MOUSE_CURSOR_REQUEST, resetMouseCursorRequestHandler);
  4060. }
  4061. /**
  4062. * @private
  4063. *
  4064. * Add listeners for events and requests we might receive from our parent if our
  4065. * parent is using a sandbox bridge to communicate with us.
  4066. */
  4067. mx_internal function addParentBridgeListeners():void
  4068. {
  4069. if (!topLevel && topLevelSystemManager)
  4070. {
  4071. SystemManager(topLevelSystemManager).addParentBridgeListeners();
  4072. return;
  4073. }
  4074. var bridge:IEventDispatcher = swfBridgeGroup.parentBridge;
  4075. bridge.addEventListener(SWFBridgeRequest.SET_ACTUAL_SIZE_REQUEST, setActualSizeRequestHandler);
  4076. bridge.addEventListener(SWFBridgeRequest.GET_SIZE_REQUEST, getSizeRequestHandler);
  4077. // need to listener to parent system manager to get broadcast messages.
  4078. bridge.addEventListener(SWFBridgeRequest.ACTIVATE_POP_UP_REQUEST,
  4079. activateRequestHandler);
  4080. bridge.addEventListener(SWFBridgeRequest.DEACTIVATE_POP_UP_REQUEST,
  4081. deactivateRequestHandler);
  4082. bridge.addEventListener(SWFBridgeRequest.IS_BRIDGE_CHILD_REQUEST, isBridgeChildHandler);
  4083. bridge.addEventListener(EventListenerRequest.ADD_EVENT_LISTENER_REQUEST, eventListenerRequestHandler);
  4084. bridge.addEventListener(EventListenerRequest.REMOVE_EVENT_LISTENER_REQUEST, eventListenerRequestHandler);
  4085. bridge.addEventListener(SWFBridgeRequest.CAN_ACTIVATE_POP_UP_REQUEST, canActivateHandler);
  4086. bridge.addEventListener(SWFBridgeEvent.BRIDGE_APPLICATION_UNLOADING, beforeUnloadHandler);
  4087. }
  4088. /**
  4089. * @private
  4090. *
  4091. * remove listeners for events and requests we might receive from our parent if
  4092. * our parent is using a sandbox bridge to communicate with us.
  4093. */
  4094. mx_internal function removeParentBridgeListeners():void
  4095. {
  4096. if (!topLevel && topLevelSystemManager)
  4097. {
  4098. SystemManager(topLevelSystemManager).removeParentBridgeListeners();
  4099. return;
  4100. }
  4101. var bridge:IEventDispatcher = swfBridgeGroup.parentBridge;
  4102. bridge.removeEventListener(SWFBridgeRequest.SET_ACTUAL_SIZE_REQUEST, setActualSizeRequestHandler);
  4103. bridge.removeEventListener(SWFBridgeRequest.GET_SIZE_REQUEST, getSizeRequestHandler);
  4104. // need to listener to parent system manager to get broadcast messages.
  4105. bridge.removeEventListener(SWFBridgeRequest.ACTIVATE_POP_UP_REQUEST,
  4106. activateRequestHandler);
  4107. bridge.removeEventListener(SWFBridgeRequest.DEACTIVATE_POP_UP_REQUEST,
  4108. deactivateRequestHandler);
  4109. bridge.removeEventListener(SWFBridgeRequest.IS_BRIDGE_CHILD_REQUEST, isBridgeChildHandler);
  4110. bridge.removeEventListener(EventListenerRequest.ADD_EVENT_LISTENER_REQUEST, eventListenerRequestHandler);
  4111. bridge.removeEventListener(EventListenerRequest.REMOVE_EVENT_LISTENER_REQUEST, eventListenerRequestHandler);
  4112. bridge.removeEventListener(SWFBridgeRequest.CAN_ACTIVATE_POP_UP_REQUEST, canActivateHandler);
  4113. bridge.removeEventListener(SWFBridgeEvent.BRIDGE_APPLICATION_UNLOADING, beforeUnloadHandler);
  4114. }
  4115. private function getTopLevelSystemManager(parent:DisplayObject):ISystemManager
  4116. {
  4117. var localRoot:DisplayObjectContainer = DisplayObjectContainer(parent.root);
  4118. var sm:ISystemManager;
  4119. // If the parent isn't rooted yet,
  4120. // Or the root is the stage (which is the case in a second AIR window)
  4121. // use the global system manager instance.
  4122. if ((!localRoot || localRoot is Stage) && parent is IUIComponent)
  4123. localRoot = DisplayObjectContainer(IUIComponent(parent).systemManager);
  4124. if (localRoot is ISystemManager)
  4125. {
  4126. sm = ISystemManager(localRoot);
  4127. if (!sm.isTopLevel())
  4128. sm = sm.topLevelSystemManager;
  4129. }
  4130. return sm;
  4131. }
  4132. /**
  4133. * Override parent property to handle the case where the parent is in
  4134. * a differnt sandbox. If the parent is in the same sandbox it is returned.
  4135. * If the parent is in a diffent sandbox, then null is returned.
  4136. *
  4137. */
  4138. override public function get parent():DisplayObjectContainer
  4139. {
  4140. try
  4141. {
  4142. return super.parent;
  4143. }
  4144. catch (e:SecurityError)
  4145. {
  4146. // trace("parent: ignoring security error");
  4147. }
  4148. return null;
  4149. }
  4150. /**
  4151. * Add a bridge to talk to the child owned by <code>owner</code>.
  4152. *
  4153. * @param bridge The bridge used to talk to the parent.
  4154. * @param owner The display object that owns the bridge.
  4155. */
  4156. public function addChildBridge(bridge:IEventDispatcher, owner:DisplayObject):void
  4157. {
  4158. // Is the owner in a pop up? If so let the focus manager manage the
  4159. // bridge instead of the system manager.
  4160. var fm:IFocusManager = null;
  4161. var o:DisplayObject = owner;
  4162. while (o)
  4163. {
  4164. if (o is IFocusManagerContainer)
  4165. {
  4166. fm = IFocusManagerContainer(o).focusManager;
  4167. break;
  4168. }
  4169. o = o.parent;
  4170. }
  4171. if (!fm)
  4172. return;
  4173. if (!swfBridgeGroup)
  4174. swfBridgeGroup = new SWFBridgeGroup(this);
  4175. swfBridgeGroup.addChildBridge(bridge, ISWFBridgeProvider(owner));
  4176. fm.addSWFBridge(bridge, owner);
  4177. if (!bridgeToFocusManager)
  4178. bridgeToFocusManager = new Dictionary();
  4179. bridgeToFocusManager[bridge] = fm;
  4180. addChildBridgeListeners(bridge);
  4181. // dispatch message that we are adding a bridge.
  4182. dispatchEvent(new FlexChangeEvent(FlexChangeEvent.ADD_CHILD_BRIDGE, false, false, bridge));
  4183. }
  4184. /**
  4185. * Remove a child bridge.
  4186. *
  4187. * @param bridge The target bridge to remove.
  4188. */
  4189. public function removeChildBridge(bridge:IEventDispatcher):void
  4190. {
  4191. // dispatch message that we are removing a bridge.
  4192. dispatchEvent(new FlexChangeEvent(FlexChangeEvent.REMOVE_CHILD_BRIDGE, false, false, bridge));
  4193. var fm:IFocusManager = IFocusManager(bridgeToFocusManager[bridge]);
  4194. fm.removeSWFBridge(bridge);
  4195. swfBridgeGroup.removeChildBridge(bridge);
  4196. delete bridgeToFocusManager[bridge];
  4197. removeChildBridgeListeners(bridge);
  4198. }
  4199. /**
  4200. * @inheritDoc
  4201. */
  4202. public function useSWFBridge():Boolean
  4203. {
  4204. if (isStageRoot)
  4205. return false;
  4206. if (!topLevel && topLevelSystemManager)
  4207. return topLevelSystemManager.useSWFBridge();
  4208. var sbRoot:DisplayObject = getSandboxRoot();
  4209. // if we're toplevel and we aren't the sandbox root, we need a bridge
  4210. if (topLevel && sbRoot != this)
  4211. return true;
  4212. // we also need a bridge even if we're the sandbox root
  4213. // but not a stage root, but our parent loader is a bootstrap
  4214. // that is not the stage root
  4215. if (sbRoot == this)
  4216. {
  4217. try
  4218. {
  4219. // check if the loader info is valid.
  4220. root.loaderInfo.parentAllowsChild;
  4221. if (parentAllowsChild && childAllowsParent)
  4222. {
  4223. try
  4224. {
  4225. if (!parent.dispatchEvent(new Event("mx.managers.SystemManager.isStageRoot", false, true)))
  4226. return true;
  4227. }
  4228. catch (e:Error)
  4229. {
  4230. }
  4231. }
  4232. else
  4233. return true;
  4234. }
  4235. catch (e1:Error)
  4236. {
  4237. // we seem to get here when a SWF is being unloaded, has been unparented, but still
  4238. // has a stage and root property, but loaderInfo is invalid.
  4239. return false;
  4240. }
  4241. }
  4242. return false;
  4243. }
  4244. /**
  4245. * Go up the parent chain to get the top level system manager.
  4246. *
  4247. * Returns <code>null</code> if not on the display list or we don't have
  4248. * access to the top-level system manager.
  4249. *
  4250. * @return The root system manager.
  4251. */
  4252. public function getTopLevelRoot():DisplayObject
  4253. {
  4254. // work our say up the parent chain to the root. This way we
  4255. // don't have to rely on this object being added to the stage.
  4256. try
  4257. {
  4258. var sm:ISystemManager = this;
  4259. if (sm.topLevelSystemManager)
  4260. sm = sm.topLevelSystemManager;
  4261. var parent:DisplayObject = DisplayObject(sm).parent;
  4262. var lastParent:DisplayObject = parent;
  4263. while (parent)
  4264. {
  4265. if (parent is Stage)
  4266. return lastParent;
  4267. lastParent = parent;
  4268. parent = parent.parent;
  4269. }
  4270. }
  4271. catch (error:SecurityError)
  4272. {
  4273. }
  4274. return null;
  4275. }
  4276. /**
  4277. * Go up the parent chain to get the top level system manager in this
  4278. * SecurityDomain.
  4279. *
  4280. * @return The root system manager in this SecurityDomain.
  4281. */
  4282. public function getSandboxRoot():DisplayObject
  4283. {
  4284. // work our say up the parent chain to the root. This way we
  4285. // don't have to rely on this object being added to the stage.
  4286. var sm:ISystemManager = this;
  4287. try
  4288. {
  4289. if (sm.topLevelSystemManager)
  4290. sm = sm.topLevelSystemManager;
  4291. var parent:DisplayObject = DisplayObject(sm).parent;
  4292. if (parent is Stage)
  4293. return DisplayObject(sm);
  4294. // test to see if parent is a Bootstrap
  4295. if (parent && !parent.dispatchEvent(new Event("mx.managers.SystemManager.isBootstrapRoot", false, true)))
  4296. return this;
  4297. var lastParent:DisplayObject = this;
  4298. while (parent)
  4299. {
  4300. if (parent is Stage)
  4301. return lastParent;
  4302. // test to see if parent is a Bootstrap
  4303. if (!parent.dispatchEvent(new Event("mx.managers.SystemManager.isBootstrapRoot", false, true)))
  4304. return lastParent;
  4305. // Test if the childAllowsParent so we know there is mutual trust between
  4306. // the sandbox root and this sm.
  4307. // The parentAllowsChild is taken care of by the player because it returns null
  4308. // for the parent if we do not have access.
  4309. if (parent is Loader)
  4310. {
  4311. var loader:Loader = Loader(parent);
  4312. var loaderInfo:LoaderInfo = loader.contentLoaderInfo;
  4313. if (!loaderInfo.childAllowsParent)
  4314. return loaderInfo.content;
  4315. }
  4316. // If an object is listening for system manager request we assume it is a sandbox
  4317. // root. If not, don't assign lastParent to this parent because it may be a
  4318. // non-Flex application. We only want Flex apps to be returned as sandbox roots.
  4319. if (parent.hasEventListener(InterManagerRequest.SYSTEM_MANAGER_REQUEST))
  4320. lastParent = parent;
  4321. parent = parent.parent;
  4322. }
  4323. }
  4324. catch (error:Error)
  4325. {
  4326. // Either we don't have security access to a parent or
  4327. // the swf is unloaded and loaderInfo.childAllowsParent is throwing Error #2099.
  4328. }
  4329. return lastParent != null ? lastParent : DisplayObject(sm);
  4330. }
  4331. /**
  4332. * @inheritDoc
  4333. */
  4334. public function getVisibleApplicationRect(bounds:Rectangle = null):Rectangle
  4335. {
  4336. if (!bounds)
  4337. {
  4338. bounds = getBounds(DisplayObject(this));
  4339. var s:Rectangle = screen;
  4340. var pt:Point = new Point(Math.max(0, bounds.x), Math.max(0, bounds.y));
  4341. pt = localToGlobal(pt);
  4342. bounds.x = pt.x;
  4343. bounds.y = pt.y;
  4344. bounds.width = s.width;
  4345. bounds.height = s.height;
  4346. }
  4347. // send a message to parent for their visible rect.
  4348. if (useSWFBridge())
  4349. {
  4350. var bridge:IEventDispatcher = swfBridgeGroup.parentBridge;
  4351. var request:SWFBridgeRequest = new SWFBridgeRequest(SWFBridgeRequest.GET_VISIBLE_RECT_REQUEST,
  4352. false, false,
  4353. bridge,
  4354. bounds);
  4355. bridge.dispatchEvent(request);
  4356. bounds = Rectangle(request.data);
  4357. }
  4358. return bounds;
  4359. }
  4360. /**
  4361. * @inheritDoc
  4362. */
  4363. public function deployMouseShields(deploy:Boolean):void
  4364. {
  4365. var me:InterManagerRequest = new InterManagerRequest(InterManagerRequest.DRAG_MANAGER_REQUEST, false, false,
  4366. "mouseShield", deploy);
  4367. getSandboxRoot().dispatchEvent(me);
  4368. }
  4369. /**
  4370. * @private
  4371. *
  4372. * Notify parent that a new window has been activated.
  4373. *
  4374. * @param window window that was activated.
  4375. */
  4376. mx_internal function dispatchActivatedWindowEvent(window:DisplayObject):void
  4377. {
  4378. var bridge:IEventDispatcher = swfBridgeGroup ? swfBridgeGroup.parentBridge : null;
  4379. if (bridge)
  4380. {
  4381. var sbRoot:DisplayObject = getSandboxRoot();
  4382. var sendToSbRoot:Boolean = sbRoot != this;
  4383. var bridgeEvent:SWFBridgeEvent = new SWFBridgeEvent(SWFBridgeEvent.BRIDGE_WINDOW_ACTIVATE,
  4384. false, false,
  4385. { notifier: bridge,
  4386. window: sendToSbRoot ? window :
  4387. NameUtil.displayObjectToString(window)
  4388. });
  4389. if (sendToSbRoot)
  4390. sbRoot.dispatchEvent(bridgeEvent);
  4391. else
  4392. bridge.dispatchEvent(bridgeEvent);
  4393. }
  4394. }
  4395. /**
  4396. * @private
  4397. *
  4398. * Notify parent that a window has been deactivated.
  4399. *
  4400. * @param id window display object or id string that was activated. Ids are used if
  4401. * the message is going outside the security domain.
  4402. */
  4403. private function dispatchDeactivatedWindowEvent(window:DisplayObject):void
  4404. {
  4405. var bridge:IEventDispatcher = swfBridgeGroup ? swfBridgeGroup.parentBridge : null;
  4406. if (bridge)
  4407. {
  4408. var sbRoot:DisplayObject = getSandboxRoot();
  4409. var sendToSbRoot:Boolean = sbRoot != this;
  4410. var bridgeEvent:SWFBridgeEvent = new SWFBridgeEvent(SWFBridgeEvent.BRIDGE_WINDOW_DEACTIVATE,
  4411. false,
  4412. false,
  4413. { notifier: bridge,
  4414. window: sendToSbRoot ? window :
  4415. NameUtil.displayObjectToString(window)
  4416. });
  4417. if (sendToSbRoot)
  4418. sbRoot.dispatchEvent(bridgeEvent);
  4419. else
  4420. bridge.dispatchEvent(bridgeEvent);
  4421. }
  4422. }
  4423. /**
  4424. * @private
  4425. *
  4426. * Notify parent that an application has been activated.
  4427. */
  4428. private function dispatchActivatedApplicationEvent():void
  4429. {
  4430. // click on this system manager or one of its sub system managers
  4431. // If in a sandbox tell the top-level system manager we are active.
  4432. var bridge:IEventDispatcher = swfBridgeGroup ? swfBridgeGroup.parentBridge : null;
  4433. if (bridge)
  4434. {
  4435. var bridgeEvent:SWFBridgeEvent = new SWFBridgeEvent(SWFBridgeEvent.BRIDGE_APPLICATION_ACTIVATE,
  4436. false, false);
  4437. bridge.dispatchEvent(bridgeEvent);
  4438. }
  4439. }
  4440. /**
  4441. * Adjust the forms array so it is sorted by last active.
  4442. * The last active form will be at the end of the forms array.
  4443. *
  4444. * This method assumes the form variable has been set before calling
  4445. * this function.
  4446. */
  4447. private function updateLastActiveForm():void
  4448. {
  4449. // find "form" in the forms array and move that entry to
  4450. // the end of the array.
  4451. var n:int = forms.length;
  4452. if (n < 2)
  4453. return; // zero or one forms, no need to update
  4454. var index:int = -1;
  4455. for (var i:int = 0; i < n; i++)
  4456. {
  4457. if (areFormsEqual(form, forms[i]))
  4458. {
  4459. index = i;
  4460. break;
  4461. }
  4462. }
  4463. if (index >= 0)
  4464. {
  4465. forms.splice(index, 1);
  4466. forms.push(form);
  4467. }
  4468. }
  4469. /**
  4470. * @private
  4471. *
  4472. * Add placeholder information to this instance's list of placeholder data.
  4473. */
  4474. private function addPlaceholderId(id:String, previousId:String, bridge:IEventDispatcher,
  4475. placeholder:Object):void
  4476. {
  4477. if (!bridge)
  4478. throw new Error(); // bridge is required.
  4479. if (!idToPlaceholder)
  4480. idToPlaceholder = [];
  4481. idToPlaceholder[id] = new PlaceholderData(previousId, bridge, placeholder);
  4482. }
  4483. private function removePlaceholderId(id:String):void
  4484. {
  4485. delete idToPlaceholder[id];
  4486. }
  4487. private var currentSandboxEvent:Event;
  4488. private var dispatchingToSystemManagers:Boolean = false;
  4489. private function dispatchEventToOtherSystemManagers(event:Event):void
  4490. {
  4491. dispatchingToSystemManagers = true;
  4492. var arr:Array = SystemManagerGlobals.topLevelSystemManagers;
  4493. var n:int = arr.length;
  4494. for (var i:int = 0; i < n; i++)
  4495. {
  4496. if (arr[i] != this)
  4497. {
  4498. arr[i].dispatchEvent(event);
  4499. }
  4500. }
  4501. dispatchingToSystemManagers = false;
  4502. }
  4503. /**
  4504. * @inheritDoc
  4505. */
  4506. public function dispatchEventFromSWFBridges(event:Event, skip:IEventDispatcher = null,
  4507. trackClones:Boolean = false, toOtherSystemManagers:Boolean = false):void
  4508. {
  4509. if (toOtherSystemManagers)
  4510. {
  4511. dispatchEventToOtherSystemManagers(event);
  4512. }
  4513. if (!swfBridgeGroup)
  4514. return;
  4515. var clone:Event;
  4516. // trace(">>dispatchEventFromSWFBridges", this, event.type);
  4517. clone = event.clone();
  4518. if (trackClones)
  4519. currentSandboxEvent = clone;
  4520. var parentBridge:IEventDispatcher = swfBridgeGroup.parentBridge;
  4521. if (parentBridge && parentBridge != skip)
  4522. {
  4523. // Ensure the requestor property has the correct bridge.
  4524. if (clone is SWFBridgeRequest)
  4525. SWFBridgeRequest(clone).requestor = parentBridge;
  4526. parentBridge.dispatchEvent(clone);
  4527. }
  4528. var children:Array = swfBridgeGroup.getChildBridges();
  4529. for (var i:int = 0; i < children.length; i++)
  4530. {
  4531. if (children[i] != skip)
  4532. {
  4533. // trace("send to child", i, event.type);
  4534. clone = event.clone();
  4535. if (trackClones)
  4536. currentSandboxEvent = clone;
  4537. // Ensure the requestor property has the correct bridge.
  4538. if (clone is SWFBridgeRequest)
  4539. SWFBridgeRequest(clone).requestor = IEventDispatcher(children[i]);
  4540. IEventDispatcher(children[i]).dispatchEvent(clone);
  4541. }
  4542. }
  4543. currentSandboxEvent = null;
  4544. // trace("<<dispatchEventFromSWFBridges", this, event.type);
  4545. }
  4546. /**
  4547. * request the parent to add an event listener.
  4548. */
  4549. private function addEventListenerToSandboxes(type:String, listener:Function, useCapture:Boolean = false,
  4550. priority:int=0, useWeakReference:Boolean=false, skip:IEventDispatcher = null):void
  4551. {
  4552. if (!swfBridgeGroup)
  4553. return;
  4554. // trace(">>addEventListenerToSandboxes", this, type);
  4555. var request:EventListenerRequest = new EventListenerRequest(EventListenerRequest.ADD_EVENT_LISTENER_REQUEST, false, false,
  4556. type,
  4557. useCapture,
  4558. priority,
  4559. useWeakReference);
  4560. var parentBridge:IEventDispatcher = swfBridgeGroup.parentBridge;
  4561. if (parentBridge && parentBridge != skip)
  4562. parentBridge.addEventListener(type, listener, false, priority, useWeakReference);
  4563. var children:Array = swfBridgeGroup.getChildBridges();
  4564. for (var i:int; i < children.length; i++)
  4565. {
  4566. var childBridge:IEventDispatcher = IEventDispatcher(children[i]);
  4567. if (childBridge != skip)
  4568. childBridge.addEventListener(type, listener, false, priority, useWeakReference);
  4569. }
  4570. dispatchEventFromSWFBridges(request, skip);
  4571. // trace("<<addEventListenerToSandboxes", this, type);
  4572. }
  4573. /**
  4574. * request the parent to remove an event listener.
  4575. */
  4576. private function removeEventListenerFromSandboxes(type:String, listener:Function,
  4577. useCapture:Boolean = false,
  4578. skip:IEventDispatcher = null):void
  4579. {
  4580. if (!swfBridgeGroup)
  4581. return;
  4582. // trace(">>removeEventListenerToSandboxes", this, type);
  4583. var request:EventListenerRequest = new EventListenerRequest(EventListenerRequest.REMOVE_EVENT_LISTENER_REQUEST, false, false,
  4584. type,
  4585. useCapture);
  4586. var parentBridge:IEventDispatcher = swfBridgeGroup.parentBridge;
  4587. if (parentBridge && parentBridge != skip)
  4588. parentBridge.removeEventListener(type, listener, useCapture);
  4589. var children:Array = swfBridgeGroup.getChildBridges();
  4590. for (var i:int; i < children.length; i++)
  4591. {
  4592. if (children[i] != skip)
  4593. IEventDispatcher(children[i]).removeEventListener(type, listener, useCapture);
  4594. }
  4595. dispatchEventFromSWFBridges(request, skip);
  4596. // trace("<<removeEventListenerToSandboxes", this, type);
  4597. }
  4598. /**
  4599. * request the parent to add an event listener.
  4600. */
  4601. private function addEventListenerToOtherSystemManagers(type:String, listener:Function, useCapture:Boolean = false,
  4602. priority:int=0, useWeakReference:Boolean=false):void
  4603. {
  4604. var arr:Array = SystemManagerGlobals.topLevelSystemManagers;
  4605. if (arr.length < 2)
  4606. return;
  4607. SystemManagerGlobals.changingListenersInOtherSystemManagers = true;
  4608. var n:int = arr.length;
  4609. for (var i:int = 0; i < n; i++)
  4610. {
  4611. if (arr[i] != this)
  4612. {
  4613. arr[i].addEventListener(type, listener, useCapture, priority, useWeakReference);
  4614. }
  4615. }
  4616. SystemManagerGlobals.changingListenersInOtherSystemManagers = false;
  4617. }
  4618. /**
  4619. * request the parent to remove an event listener.
  4620. */
  4621. private function removeEventListenerFromOtherSystemManagers(type:String, listener:Function,
  4622. useCapture:Boolean = false):void
  4623. {
  4624. var arr:Array = SystemManagerGlobals.topLevelSystemManagers;
  4625. if (arr.length < 2)
  4626. return;
  4627. SystemManagerGlobals.changingListenersInOtherSystemManagers = true;
  4628. var n:int = arr.length;
  4629. for (var i:int = 0; i < n; i++)
  4630. {
  4631. if (arr[i] != this)
  4632. {
  4633. arr[i].removeEventListener(type, listener, useCapture);
  4634. }
  4635. }
  4636. SystemManagerGlobals.changingListenersInOtherSystemManagers = false;
  4637. }
  4638. /**
  4639. * @private
  4640. *
  4641. * @return true if the message should be processed, false if
  4642. * no other action is required.
  4643. */
  4644. private function preProcessModalWindowRequest(request:SWFBridgeRequest,
  4645. sbRoot:DisplayObject):Boolean
  4646. {
  4647. // should we process this message?
  4648. if (request.data.skip)
  4649. {
  4650. // skipping this sandbox,
  4651. // but don't skip the next one.
  4652. request.data.skip = false;
  4653. if (useSWFBridge())
  4654. {
  4655. var bridge:IEventDispatcher = swfBridgeGroup.parentBridge;
  4656. request.requestor = bridge;
  4657. bridge.dispatchEvent(request);
  4658. }
  4659. return false;
  4660. }
  4661. // if we are not the sandbox root, dispatch the message to the sandbox root.
  4662. if (this != sbRoot)
  4663. {
  4664. // convert exclude component into a rectangle and forward to parent bridge.
  4665. if (request.type == SWFBridgeRequest.CREATE_MODAL_WINDOW_REQUEST ||
  4666. request.type == SWFBridgeRequest.SHOW_MODAL_WINDOW_REQUEST)
  4667. {
  4668. var exclude:ISWFLoader = swfBridgeGroup.getChildBridgeProvider(request.requestor)
  4669. as ISWFLoader;
  4670. // find the rectangle of the area to exclude
  4671. if (exclude)
  4672. {
  4673. var excludeRect:Rectangle = ISWFLoader(exclude).getVisibleApplicationRect();
  4674. request.data.excludeRect = excludeRect;
  4675. // If the area to exclude is not contain by our document then it is in a
  4676. // pop up. From this point for set the useExclude flag to false to
  4677. // tell our parent not to exclude use from their modal window, only
  4678. // the excludeRect we have just calculated.
  4679. if (!DisplayObjectContainer(document).contains(DisplayObject(exclude)))
  4680. request.data.useExclude = false; // keep the existing excludeRect
  4681. }
  4682. }
  4683. bridge = swfBridgeGroup.parentBridge;
  4684. request.requestor = bridge;
  4685. // The HIDE request does not need to be processed by each
  4686. // application, so dispatch it directly to the sandbox root.
  4687. if (request.type == SWFBridgeRequest.HIDE_MODAL_WINDOW_REQUEST)
  4688. sbRoot.dispatchEvent(request);
  4689. else
  4690. bridge.dispatchEvent(request);
  4691. return false;
  4692. }
  4693. // skip aftering sending the message over a bridge.
  4694. request.data.skip = false;
  4695. return true;
  4696. }
  4697. private function otherSystemManagerMouseListener(event:SandboxMouseEvent):void
  4698. {
  4699. if (dispatchingToSystemManagers)
  4700. return;
  4701. dispatchEventFromSWFBridges(event);
  4702. // ask the sandbox root if it was the original dispatcher of this event
  4703. // if it was then don't dispatch to ourselves because we could have
  4704. // got this event by listening to sandboxRoot ourselves.
  4705. var me:InterManagerRequest = new InterManagerRequest(InterManagerRequest.SYSTEM_MANAGER_REQUEST);
  4706. me.name = "sameSandbox";
  4707. me.value = event;
  4708. getSandboxRoot().dispatchEvent(me);
  4709. if (!me.value)
  4710. dispatchEvent(event);
  4711. }
  4712. private function sandboxMouseListener(event:Event):void
  4713. {
  4714. // trace("sandboxMouseListener", this);
  4715. if (event is SandboxMouseEvent)
  4716. return;
  4717. var marshaledEvent:Event = SandboxMouseEvent.marshal(event);
  4718. dispatchEventFromSWFBridges(marshaledEvent, event.target as IEventDispatcher);
  4719. // ask the sandbox root if it was the original dispatcher of this event
  4720. // if it was then don't dispatch to ourselves because we could have
  4721. // got this event by listening to sandboxRoot ourselves.
  4722. var me:InterManagerRequest = new InterManagerRequest(InterManagerRequest.SYSTEM_MANAGER_REQUEST);
  4723. me.name = "sameSandbox";
  4724. me.value = event;
  4725. getSandboxRoot().dispatchEvent(me);
  4726. if (!me.value)
  4727. dispatchEvent(marshaledEvent);
  4728. }
  4729. private function eventListenerRequestHandler(event:Event):void
  4730. {
  4731. if (event is EventListenerRequest)
  4732. return;
  4733. var actualType:String;
  4734. var request:EventListenerRequest = EventListenerRequest.marshal(event);
  4735. if (event.type == EventListenerRequest.ADD_EVENT_LISTENER_REQUEST)
  4736. {
  4737. if (!eventProxy)
  4738. {
  4739. eventProxy = new EventProxy(this);
  4740. }
  4741. actualType = EventUtil.sandboxMouseEventMap[request.eventType];
  4742. if (actualType)
  4743. {
  4744. if (isTopLevelRoot())
  4745. {
  4746. stage.addEventListener(MouseEvent.MOUSE_MOVE, resetMouseCursorTracking, true, EventPriority.CURSOR_MANAGEMENT + 1, true);
  4747. }
  4748. else
  4749. {
  4750. super.addEventListener(MouseEvent.MOUSE_MOVE, resetMouseCursorTracking, true, EventPriority.CURSOR_MANAGEMENT + 1, true);
  4751. }
  4752. // add listeners in other sandboxes in capture mode so we don't miss anything
  4753. addEventListenerToSandboxes(request.eventType, sandboxMouseListener,
  4754. true, request.priority, request.useWeakReference, event.target as IEventDispatcher);
  4755. addEventListenerToOtherSystemManagers(request.eventType, otherSystemManagerMouseListener,
  4756. true, request.priority, request.useWeakReference);
  4757. if (getSandboxRoot() == this)
  4758. {
  4759. if (isTopLevelRoot() &&
  4760. (actualType == MouseEvent.MOUSE_UP || actualType == MouseEvent.MOUSE_MOVE))
  4761. {
  4762. stage.addEventListener(actualType, eventProxy.marshalListener,
  4763. false, request.priority, request.useWeakReference);
  4764. }
  4765. super.addEventListener(actualType, eventProxy.marshalListener,
  4766. true, request.priority, request.useWeakReference);
  4767. }
  4768. }
  4769. }
  4770. else if (event.type == EventListenerRequest.REMOVE_EVENT_LISTENER_REQUEST)
  4771. {
  4772. actualType = EventUtil.sandboxMouseEventMap[request.eventType];
  4773. if (actualType)
  4774. {
  4775. removeEventListenerFromOtherSystemManagers(request.eventType, otherSystemManagerMouseListener, true);
  4776. removeEventListenerFromSandboxes(request.eventType, sandboxMouseListener,
  4777. true, event.target as IEventDispatcher);
  4778. if (getSandboxRoot() == this)
  4779. {
  4780. if (isTopLevelRoot() &&
  4781. (actualType == MouseEvent.MOUSE_UP || actualType == MouseEvent.MOUSE_MOVE))
  4782. {
  4783. stage.removeEventListener(actualType, eventProxy.marshalListener);
  4784. }
  4785. super.removeEventListener(actualType, eventProxy.marshalListener, true);
  4786. }
  4787. }
  4788. }
  4789. }
  4790. }
  4791. }