UIModule and UIModuleLoader
Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/020c1cb9 Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/020c1cb9 Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/020c1cb9 Branch: refs/heads/develop Commit: 020c1cb9e4a825f228ced241728dd80e4cab8432 Parents: 683db92 Author: Alex Harui <aha...@apache.org> Authored: Tue Aug 15 13:15:50 2017 -0700 Committer: Alex Harui <aha...@apache.org> Committed: Tue Aug 15 13:19:34 2017 -0700 ---------------------------------------------------------------------- .../main/flex/org/apache/flex/html/UIModule.as | 139 +++++++++++ .../flex/org/apache/flex/html/UIModuleLoader.as | 233 +++++++++++++++++++ .../Basic/src/main/resources/basic-manifest.xml | 3 + 3 files changed, 375 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/020c1cb9/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/UIModule.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/UIModule.as b/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/UIModule.as new file mode 100644 index 0000000..4c7784f --- /dev/null +++ b/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/UIModule.as @@ -0,0 +1,139 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +package org.apache.flex.html +{ + COMPILE::SWF + { + import flash.system.ApplicationDomain; + import flash.utils.getQualifiedClassName; + } + import org.apache.flex.core.IFlexInfo; + import org.apache.flex.core.IValuesImpl; + import org.apache.flex.core.ValuesManager; + import org.apache.flex.events.Event; + import org.apache.flex.events.ValueChangeEvent; + + /** + * Indicates that the state change has completed. All properties + * that need to change have been changed, and all transitinos + * that need to run have completed. However, any deferred work + * may not be completed, and the screen may not be updated until + * code stops executing. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + [Event(name="stateChangeComplete", type="org.apache.flex.events.Event")] + + /** + * Indicates that the initialization of the container is complete. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + [Event(name="initComplete", type="org.apache.flex.events.Event")] + + /** + * Indicates that the children of the container is have been added. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + [Event(name="childrenAdded", type="org.apache.flex.events.Event")] + + /** + * The UIModule class is the base class for modules of user + * interface controls in FlexJS. It is usable as the root tag of MXML + * documents and UI controls and containers are added to it. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class UIModule extends Group implements IFlexInfo + { + /** + * Constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function UIModule() + { + super(); + } + + private var _info:Object; + + /** + * An Object containing information generated + * by the compiler that is useful at startup time. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function info():Object + { + COMPILE::SWF + { + if (!_info) + { + var mainClassName:String = getQualifiedClassName(this); + var initClassName:String = "_" + mainClassName + "_FlexInit"; + var c:Class = ApplicationDomain.currentDomain.getDefinition(initClassName) as Class; + _info = c.info(); + } + } + return _info; + } + + /** + * The org.apache.flex.core.IValuesImpl that is + * used by the loading application or module. + * A new instance is not created as the main + * one is shared but this adds the required + * depedencies for the JS compiler optimizer + * and adds the values for this module + * + * @see org.apache.flex.core.SimpleCSSValuesImpl + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function set valuesImpl(value:IValuesImpl):void + { + ValuesManager.valuesImpl.init(this); + } + + + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/020c1cb9/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/UIModuleLoader.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/UIModuleLoader.as b/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/UIModuleLoader.as new file mode 100644 index 0000000..db4acee --- /dev/null +++ b/frameworks/projects/Basic/src/main/flex/org/apache/flex/html/UIModuleLoader.as @@ -0,0 +1,233 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +package org.apache.flex.html +{ + import org.apache.flex.core.IUIBase; + import org.apache.flex.core.UIBase; + import org.apache.flex.utils.PointUtils; + import org.apache.flex.geom.Point; + import org.apache.flex.events.Event; + + COMPILE::SWF + { + import flash.display.Loader; + import flash.display.DisplayObjectContainer; + import flash.events.Event; + import flash.system.LoaderContext; + import flash.system.ApplicationDomain; + import flash.net.URLRequest; + } + + COMPILE::JS + { + import goog.global; + import org.apache.flex.core.WrappedHTMLElement; + } + + /** + * The UIModuleLoader class can load a UIModule. + * + * @toplevel + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class UIModuleLoader extends UIBase + { + /** + * Constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function UIModuleLoader() + { + super(); + } + + private var _modulePath:String; + + /** + * Path or URL of module. This is combined + * with the module name and a platform suffix + * to determine the actual path or URL of the + * module. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get modulePath():String + { + return _modulePath; + } + + /** + * @private. + */ + public function set modulePath(value:String):void + { + _modulePath = value; + } + + private var _moduleName:String; + + public function get moduleName():String + { + return _moduleName; + } + + public function set moduleName(value:String):void + { + _moduleName = value; + } + + COMPILE::SWF + private var swfLoader:Loader; + + COMPILE::JS + private var jsLoader:WrappedHTMLElement; + + COMPILE::JS + private var jsDepsLoader:WrappedHTMLElement; + + override public function addedToParent():void + { + super.addedToParent(); + if (_modulePath) + loadModule(); + } + + /** + * @private + * @flexjsignorecoercion org.apache.flex.core.WrappedHTMLElement + */ + private function createLoader():void + { + COMPILE::SWF { + if (swfLoader != null) { + swfLoader.contentLoaderInfo.removeEventListener("complete", completeHandler); + } + + swfLoader = new Loader(); + swfLoader.contentLoaderInfo.addEventListener("complete", completeHandler); + } + + COMPILE::JS { + var origin:Point = new Point(0,0); + var xlated:Point = PointUtils.localToGlobal(origin, parent); + + if (goog.DEBUG) + { + if (jsDepsLoader == null) { + jsDepsLoader = document.createElement('script') as WrappedHTMLElement; + jsDepsLoader.onload = loadDepsHandler; + document.body.appendChild(jsDepsLoader); + } + } + else + { + if (jsLoader == null) { + jsLoader = document.createElement('script') as WrappedHTMLElement; + jsLoader.onload = loadHandler; + document.body.appendChild(jsLoader); + } + } + } + } + + /** + * Load the module. Will be called automatically if modulePath + * is set as the UIModuleLoader is added to the display list. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function loadModule():void + { + if (moduleInstance) + removeElement(moduleInstance); + + createLoader(); + + COMPILE::SWF { + var url:URLRequest = new URLRequest(modulePath ? modulePath + "/" + moduleName + ".swf" : + moduleName + ".swf"); + var loaderContext:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain, null); + swfLoader.load(url, loaderContext); + if (swfLoader.parent == null) { + addChild(swfLoader); + } + } + + COMPILE::JS { + if (!goog.DEBUG) + jsLoader.setAttribute("src", modulePath ? modulePath + "/" + moduleName + ".js" : + moduleName + ".js"); + else + { + // js-debug module loading requires that the __deps.js file has been tweaked + // so that the path to the module class is correct and that any + // framework js files have been copied into the same tree structure as + // the main apps framework js files + window["goog"]["ENABLE_CHROME_APP_SAFE_SCRIPT_LOADING"] = true; + jsDepsLoader.setAttribute("src", modulePath ? modulePath + "/" + moduleName + "__deps.js" : + moduleName + "__deps.js"); + } + } + } + + private var moduleInstance:IUIBase; + + COMPILE::SWF + protected function completeHandler(event:flash.events.Event):void + { + var c:Class = ApplicationDomain.currentDomain.getDefinition(moduleName) as Class; + moduleInstance = new c() as IUIBase; + addElement(moduleInstance); + } + + COMPILE::JS + protected function loadDepsHandler():void + { + // wait for other scripts to load + if (window[moduleName] == null) + { + setTimeout(loadDepsHandler, 250); + } + else + loadHandler(); + + } + + COMPILE::JS + protected function loadHandler():void + { + var c:Class = window[moduleName]; + moduleInstance = new c() as IUIBase; + addElement(moduleInstance); + } + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/020c1cb9/frameworks/projects/Basic/src/main/resources/basic-manifest.xml ---------------------------------------------------------------------- diff --git a/frameworks/projects/Basic/src/main/resources/basic-manifest.xml b/frameworks/projects/Basic/src/main/resources/basic-manifest.xml index 9df3370..a07fc40 100644 --- a/frameworks/projects/Basic/src/main/resources/basic-manifest.xml +++ b/frameworks/projects/Basic/src/main/resources/basic-manifest.xml @@ -174,4 +174,7 @@ <component id="TableCell" class="org.apache.flex.html.TableCell"/> <component id="TableHeader" class="org.apache.flex.html.TableHeader"/> + <component id="UIModule" class="org.apache.flex.html.UIModule"/> + <component id="UIModuleLoader" class="org.apache.flex.html.UIModuleLoader"/> + </componentPackage>