Repository: flex-asjs Updated Branches: refs/heads/spark 1f6418c46 -> 416f7be35
Added WebBrowser component. For SWF, it uses HTMLLoader. For JS, it uses iFrame. In the Mobile project, a special view bead uses StageWebView. Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/b212a985 Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/b212a985 Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/b212a985 Branch: refs/heads/spark Commit: b212a985710b09d80323febb2e91fa4e274c3b7e Parents: 1f6418c Author: Peter Ent <[email protected]> Authored: Tue Feb 9 16:50:52 2016 -0500 Committer: Alex Harui <[email protected]> Committed: Tue Feb 23 21:44:19 2016 -0800 ---------------------------------------------------------------------- .../projects/HTML/src/main/flex/HTMLClasses.as | 3 + .../flex/org/apache/flex/html/WebBrowser.as | 145 ++++++++++++++ .../apache/flex/html/beads/WebBrowserView.as | 198 +++++++++++++++++++ .../flex/html/beads/models/WebBrowserModel.as | 100 ++++++++++ .../HTML/src/main/resources/basic-manifest.xml | 2 + .../HTML/src/main/resources/defaults.css | 6 + .../Mobile/src/main/flex/MobileClasses.as | 4 + .../flex/mobile/beads/MobileWebBrowserView.as | 129 ++++++++++++ 8 files changed, 587 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/b212a985/frameworks/projects/HTML/src/main/flex/HTMLClasses.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/flex/HTMLClasses.as b/frameworks/projects/HTML/src/main/flex/HTMLClasses.as index 052ab95..80073e7 100644 --- a/frameworks/projects/HTML/src/main/flex/HTMLClasses.as +++ b/frameworks/projects/HTML/src/main/flex/HTMLClasses.as @@ -163,6 +163,9 @@ internal class HTMLClasses import org.apache.flex.html.MXMLBeadViewBase; MXMLBeadViewBase; import org.apache.flex.html.beads.TitleBarView; TitleBarView; import org.apache.flex.html.beads.TitleBarMeasurementBead; TitleBarMeasurementBead; + + import org.apache.flex.html.beads.WebBrowserView; WebBrowserView; + import org.apache.flex.html.beads.models.WebBrowserModel; WebBrowserModel; COMPILE::AS3 { http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/b212a985/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/WebBrowser.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/WebBrowser.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/WebBrowser.as new file mode 100644 index 0000000..009a508 --- /dev/null +++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/WebBrowser.as @@ -0,0 +1,145 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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::AS3 { + import flash.events.Event; + import flash.html.HTMLLoader; + import flash.net.URLRequest; + + import org.apache.flex.events.utils.IHandlesOriginalEvent; + } + COMPILE::JS + { + import org.apache.flex.core.WrappedHTMLElement; + } + + import org.apache.flex.core.UIBase + import org.apache.flex.html.beads.models.WebBrowserModel; + + /** + * Dispatched whenever the WebBrowser's location has been changed. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + [Event(name="locationChanged", type="org.apache.flex.events.Event")] + + /** + * The WebBrowser provides a space in which to display a web page within + * a FlexJS application. Use the url property to change the location of + * the web page being displayed. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + COMPILE::AS3 + public class WebBrowser extends UIBase implements IHandlesOriginalEvent + { + /** + * Constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function WebBrowser() + { + super(); + } + + /** + * The location of the web page to display. Security restrictions may + * apply. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get url():String + { + return (model as WebBrowserModel).url; + } + + public function set url(value:String):void + { + (model as WebBrowserModel).url = value; + } + } + + COMPILE::JS + public class WebBrowser extends UIBase + { + /** + * Constructor + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function WebBrowser() + { + super(); + } + + /** + * @flexjsignorecoercion org.apache.flex.core.WrappedHTMLElement + */ + override protected function createElement():WrappedHTMLElement + { + element = document.createElement('iframe') as WrappedHTMLElement; + element.flexjs_wrapper = this; + + var iframe:HTMLIFrameElement = element as HTMLIFrameElement; + iframe.frameBorder = "0"; + iframe.src = "JavaScript:''"; + iframe.sandbox = "allow-top-navigation allow-forms allow-scripts"; + + positioner = element; + + return element; + } + + /** + * The location of the web page to display. Security restrictions may + * apply. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get url():String + { + return (model as WebBrowserModel).url; + } + + public function set url(value:String):void + { + (model as WebBrowserModel).url = value; + } + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/b212a985/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/WebBrowserView.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/WebBrowserView.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/WebBrowserView.as new file mode 100644 index 0000000..cb14971 --- /dev/null +++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/WebBrowserView.as @@ -0,0 +1,198 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.beads +{ + COMPILE::AS3 { + import flash.events.Event; + import flash.html.HTMLLoader; + import flash.net.URLRequest; + } + + import org.apache.flex.core.IBeadView; + import org.apache.flex.core.IStrand; + import org.apache.flex.core.IUIBase; + import org.apache.flex.core.UIBase; + import org.apache.flex.events.Event; + import org.apache.flex.events.IEventDispatcher; + import org.apache.flex.html.beads.models.WebBrowserModel; + + /** + * The WebBrowserView creates an instance of HTMLLoader to load + * web pages into AIR application. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + COMPILE::AS3 + public class WebBrowserView implements IBeadView + { + /** + * constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function WebBrowserView() + { + loader = new HTMLLoader(); + loader.placeLoadStringContentInApplicationSandbox = false; + + loader.addEventListener(flash.events.LocationChangeEvent.LOCATION_CHANGE, handleLocationChange); + } + + private var _strand:IStrand; + + private var loader:HTMLLoader; + + /** + * @private + */ + public function get host():IUIBase + { + return _strand as IUIBase; + } + + /** + * @copy org.apache.flex.core.IBead#strand + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function set strand(value:IStrand):void + { + _strand = value; + + (host as UIBase).addEventListener("widthChanged", handleSizeChange); + (host as UIBase).addEventListener("heightChanged", handleSizeChange); + + var model:IEventDispatcher = (host as UIBase).model as IEventDispatcher; + model.addEventListener("urlChanged", loadPage); + + loader.x = 0; + loader.y = 0; + loader.width = host.width; + loader.height = host.height; + (host as UIBase).addElement(loader); + } + + /** + * @private + */ + private function loadPage(event:org.apache.flex.events.Event):void + { + var model:WebBrowserModel = (host as UIBase).model as WebBrowserModel; + loader.load(new URLRequest(model.url)); + } + + /** + * @private + */ + private function handleSizeChange(event:org.apache.flex.events.Event):void + { + loader.width = host.width; + loader.height = host.height; + } + + /** + * @private + */ + private function handleLocationChange(event:flash.events.LocationChangeEvent):void + { + var model:WebBrowserModel = (host as UIBase).model as WebBrowserModel; + model.setURL(loader.location); + host.dispatchEvent(new org.apache.flex.events.Event("locationChanged")); + } + } + + COMPILE::JS + public class WebBrowserView implements IBeadView + { + /** + * Constructor + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function WebBrowserView() + { + + } + + private var _strand:IStrand; + + /** + * @private + */ + public function get host():IUIBase + { + return _strand as IUIBase; + } + + /** + * @copy org.apache.flex.core.IBead#strand + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function set strand(value:IStrand):void + { + _strand = value; + + var model:IEventDispatcher = (host as UIBase).model as IEventDispatcher; + model.addEventListener("urlChanged", loadPage); + + var iframe:HTMLIFrameElement = (host as UIBase).element as HTMLIFrameElement; + iframe.addEventListener("pageshow", handlePageShow, false); + } + + /** + * @private + */ + private function loadPage(event:Event):void + { + var model:WebBrowserModel = (host as UIBase).model as WebBrowserModel; + + var iframe:HTMLIFrameElement = (host as UIBase).element as HTMLIFrameElement; + iframe.src = model.url; + } + + /** + * @private + */ + private function handlePageShow(event:Event):void + { + var model:WebBrowserModel = (host as UIBase).model as WebBrowserModel; + var iframe:HTMLIFrameElement = (host as UIBase).element as HTMLIFrameElement; + + model.setURL(iframe.src); + host.dispatchEvent(new org.apache.flex.events.Event("locationChanged")); + } + } +} + http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/b212a985/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/models/WebBrowserModel.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/models/WebBrowserModel.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/models/WebBrowserModel.as new file mode 100644 index 0000000..fbd823a --- /dev/null +++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/models/WebBrowserModel.as @@ -0,0 +1,100 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.beads.models +{ + import org.apache.flex.core.IBeadModel; + import org.apache.flex.core.IStrand; + import org.apache.flex.events.Event; + import org.apache.flex.events.EventDispatcher; + + /** + * The WebBrowserModel class bead defines the data associated with an org.apache.flex.html.WebBrowser + * component. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class WebBrowserModel extends EventDispatcher implements IBeadModel + { + /** + * constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function WebBrowserModel() + { + super(); + } + + private var _strand:IStrand; + + /** + * @copy org.apache.flex.core.IBead#strand + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function set strand(value:IStrand):void + { + _strand = value; + } + + private var _url:String; + + /** + * The URL to load into the WebBrowser. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get url():String + { + return _url; + } + public function set url(value:String):void + { + if (value != _url) { + _url = value; + dispatchEvent( new Event("urlChanged") ); + } + } + + /** + * Sets the URL value without dispatching an event. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function setURL(value:String):void + { + _url = value; + } + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/b212a985/frameworks/projects/HTML/src/main/resources/basic-manifest.xml ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/resources/basic-manifest.xml b/frameworks/projects/HTML/src/main/resources/basic-manifest.xml index 23dcccc..3b72af6 100644 --- a/frameworks/projects/HTML/src/main/resources/basic-manifest.xml +++ b/frameworks/projects/HTML/src/main/resources/basic-manifest.xml @@ -101,5 +101,7 @@ <component id="MXMLBeadViewBase" class="org.apache.flex.html.MXMLBeadViewBase"/> <component id="Border" class="org.apache.flex.html.supportClasses.Border"/> + + <component id="WebBrowser" class="org.apache.flex.html.WebBrowser" /> </componentPackage> http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/b212a985/frameworks/projects/HTML/src/main/resources/defaults.css ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/resources/defaults.css b/frameworks/projects/HTML/src/main/resources/defaults.css index bb8ca6e..13d7418 100644 --- a/frameworks/projects/HTML/src/main/resources/defaults.css +++ b/frameworks/projects/HTML/src/main/resources/defaults.css @@ -336,6 +336,12 @@ ViewBase IViewportModel: ClassReference("org.apache.flex.html.beads.models.ViewportModel"); } +WebBrowser +{ + IBeadView: ClassReference("org.apache.flex.html.beads.WebBrowserView"); + IBeadModel: ClassReference("org.apache.flex.html.beads.models.WebBrowserModel"); +} + /* Global Style Declaration */ global http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/b212a985/frameworks/projects/Mobile/src/main/flex/MobileClasses.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Mobile/src/main/flex/MobileClasses.as b/frameworks/projects/Mobile/src/main/flex/MobileClasses.as index fc933aa..8643954 100644 --- a/frameworks/projects/Mobile/src/main/flex/MobileClasses.as +++ b/frameworks/projects/Mobile/src/main/flex/MobileClasses.as @@ -37,6 +37,10 @@ internal class MobileClasses import org.apache.flex.mobile.chrome.TabBar; TabBar; import org.apache.flex.mobile.chrome.ToolBar; ToolBar; import org.apache.flex.mobile.models.ViewManagerModel; ViewManagerModel; + + COMPILE::AS3 { + import org.apache.flex.mobile.beads.MobileWebBrowserView; MobileWebBrowserView; + } } } http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/b212a985/frameworks/projects/Mobile/src/main/flex/org/apache/flex/mobile/beads/MobileWebBrowserView.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Mobile/src/main/flex/org/apache/flex/mobile/beads/MobileWebBrowserView.as b/frameworks/projects/Mobile/src/main/flex/org/apache/flex/mobile/beads/MobileWebBrowserView.as new file mode 100644 index 0000000..686d94f --- /dev/null +++ b/frameworks/projects/Mobile/src/main/flex/org/apache/flex/mobile/beads/MobileWebBrowserView.as @@ -0,0 +1,129 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.mobile.beads +{ + import flash.events.Event; + import flash.media.StageWebView; + import flash.geom.Rectangle; + import flash.geom.Point; + + import org.apache.flex.core.IBeadView; + import org.apache.flex.core.IStrand; + import org.apache.flex.core.IUIBase; + import org.apache.flex.core.UIBase; + import org.apache.flex.events.Event; + import org.apache.flex.events.IEventDispatcher; + import org.apache.flex.html.beads.models.WebBrowserModel; + + /** + * The MobileWebBrowserView creates an instance of StageWebView to load + * web pages into a mobile application. This class is available only + * for AS3 compiled mode. Note that StageWebView is attached directly to + * the stage and may obscure other components. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class MobileWebBrowserView implements IBeadView + { + /** + * constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function MobileWebBrowserView() + { + stageWebView = new StageWebView(); + + stageWebView.addEventListener(flash.events.Event.COMPLETE, handleLocationChange); + } + + private var _strand:IStrand; + + private var stageWebView:StageWebView; + + /** + * @private + */ + public function get host():IUIBase + { + return _strand as IUIBase; + } + + /** + * @copy org.apache.flex.core.IBead#strand + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function set strand(value:IStrand):void + { + _strand = value; + + (host as UIBase).addEventListener("widthChanged", handleSizeChange); + (host as UIBase).addEventListener("heightChanged", handleSizeChange); + + var model:IEventDispatcher = (host as UIBase).model as IEventDispatcher; + model.addEventListener("urlChanged", loadPage); + + stageWebView.stage = (host as UIBase).stage; + + var hostOrigin:Point = new Point(0,0); + var hostPosition:Point = (host as UIBase).localToGlobal(hostOrigin); + stageWebView.viewPort = new Rectangle( hostPosition.x, hostPosition.y, host.width, host.height ); + } + + /** + * @private + */ + private function loadPage(event:org.apache.flex.events.Event):void + { + var model:WebBrowserModel = (host as UIBase).model as WebBrowserModel; + stageWebView.loadURL(model.url); + } + + /** + * @private + */ + private function handleSizeChange(event:org.apache.flex.events.Event):void + { + var hostOrigin:Point = new Point(0,0); + var hostPosition:Point = (host as UIBase).localToGlobal(hostOrigin); + stageWebView.viewPort = new Rectangle( hostPosition.x, hostPosition.y, host.width, host.height ); + } + + /** + * @private + */ + private function handleLocationChange(event:flash.events.Event):void + { + var model:WebBrowserModel = (host as UIBase).model as WebBrowserModel; + model.setURL(stageWebView.location); + host.dispatchEvent(new org.apache.flex.events.Event("locationChanged")); + } + } +} +
