Binary image working on SVG.
Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/f469e189 Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/f469e189 Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/f469e189 Branch: refs/heads/refactor-sprite Commit: f469e1896b4c5aa686a968bcdca9fac510bf81ba Parents: c15d36c Author: yishayw <[email protected]> Authored: Mon Oct 10 11:01:27 2016 +0300 Committer: yishayw <[email protected]> Committed: Mon Oct 10 11:01:27 2016 +0300 ---------------------------------------------------------------------- .../flex/org/apache/flex/core/IBinaryImage.as | 6 +++- .../main/flex/org/apache/flex/core/IImage.as | 2 ++ .../flex/org/apache/flex/core/IImageView.as | 1 - .../main/flex/org/apache/flex/core/ImageBase.as | 7 ++++ .../flex/org/apache/flex/core/ImageViewBase.as | 11 +++++- .../projects/Graphics/.actionScriptProperties | 2 -- .../Graphics/src/main/flex/GraphicsClasses.as | 2 +- .../flex/org/apache/flex/svg/BinaryImage.as | 6 ++++ .../src/main/flex/org/apache/flex/svg/Image.as | 11 ++++++ .../projects/HTML/src/main/flex/HTMLClasses.as | 6 ++-- .../flex/org/apache/flex/html/BinaryImage.as | 5 +++ .../src/main/flex/org/apache/flex/html/Image.as | 9 ++++- .../apache/flex/html/beads/BinaryImageLoader.as | 37 +++++++------------- 13 files changed, 70 insertions(+), 35 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/f469e189/frameworks/projects/Core/src/main/flex/org/apache/flex/core/IBinaryImage.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Core/src/main/flex/org/apache/flex/core/IBinaryImage.as b/frameworks/projects/Core/src/main/flex/org/apache/flex/core/IBinaryImage.as index a93f9db..45640be 100644 --- a/frameworks/projects/Core/src/main/flex/org/apache/flex/core/IBinaryImage.as +++ b/frameworks/projects/Core/src/main/flex/org/apache/flex/core/IBinaryImage.as @@ -1,4 +1,4 @@ -//////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////////// // // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with @@ -42,5 +42,9 @@ package org.apache.flex.core */ function get binary():BinaryData; function set binary(value:BinaryData):void; + + COMPILE::JS + function applyBinaryDataAsString(binaryDataAsString:String):void; + } } http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/f469e189/frameworks/projects/Core/src/main/flex/org/apache/flex/core/IImage.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Core/src/main/flex/org/apache/flex/core/IImage.as b/frameworks/projects/Core/src/main/flex/org/apache/flex/core/IImage.as index 19f8bbc..9f93239 100644 --- a/frameworks/projects/Core/src/main/flex/org/apache/flex/core/IImage.as +++ b/frameworks/projects/Core/src/main/flex/org/apache/flex/core/IImage.as @@ -41,5 +41,7 @@ package org.apache.flex.core */ function get url():String; function set url(value:String):void; + COMPILE::JS + function get imageElement():Element; } } http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/f469e189/frameworks/projects/Core/src/main/flex/org/apache/flex/core/IImageView.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Core/src/main/flex/org/apache/flex/core/IImageView.as b/frameworks/projects/Core/src/main/flex/org/apache/flex/core/IImageView.as index 5993faf..bf0c123 100644 --- a/frameworks/projects/Core/src/main/flex/org/apache/flex/core/IImageView.as +++ b/frameworks/projects/Core/src/main/flex/org/apache/flex/core/IImageView.as @@ -48,7 +48,6 @@ package org.apache.flex.core COMPILE::SWF function get loader():Loader - COMPILE::SWF function setupLoader():void } } http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/f469e189/frameworks/projects/Core/src/main/flex/org/apache/flex/core/ImageBase.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Core/src/main/flex/org/apache/flex/core/ImageBase.as b/frameworks/projects/Core/src/main/flex/org/apache/flex/core/ImageBase.as index 5409a7b..674c23d 100644 --- a/frameworks/projects/Core/src/main/flex/org/apache/flex/core/ImageBase.as +++ b/frameworks/projects/Core/src/main/flex/org/apache/flex/core/ImageBase.as @@ -66,6 +66,13 @@ package org.apache.flex.core { (model as IImageModel).url = value; } + + COMPILE::JS + public function get imageElement():Element + { + return null; + // override this + } } } http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/f469e189/frameworks/projects/Core/src/main/flex/org/apache/flex/core/ImageViewBase.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Core/src/main/flex/org/apache/flex/core/ImageViewBase.as b/frameworks/projects/Core/src/main/flex/org/apache/flex/core/ImageViewBase.as index 8973abe..2bf4570 100644 --- a/frameworks/projects/Core/src/main/flex/org/apache/flex/core/ImageViewBase.as +++ b/frameworks/projects/Core/src/main/flex/org/apache/flex/core/ImageViewBase.as @@ -131,11 +131,20 @@ package org.apache.flex.core }); } + /** + * @flexjsignorecoercion org.apache.flex.core.IImage + */ + COMPILE::JS + protected function get imageElement():Element + { + return (_strand as IImage).imageElement; + } + COMPILE::JS public function setupLoader():void { var host:IUIBase = _strand as IUIBase; - (host.element as HTMLImageElement).addEventListener('load', + imageElement.addEventListener('load', loadHandler, false); host.addEventListener('sizeChanged', sizeChangedHandler); http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/f469e189/frameworks/projects/Graphics/.actionScriptProperties ---------------------------------------------------------------------- diff --git a/frameworks/projects/Graphics/.actionScriptProperties b/frameworks/projects/Graphics/.actionScriptProperties index 5ac78a8..49ec6c7 100644 --- a/frameworks/projects/Graphics/.actionScriptProperties +++ b/frameworks/projects/Graphics/.actionScriptProperties @@ -5,10 +5,8 @@ <libraryPath defaultLinkType="0"> <libraryPathEntry kind="4" path=""> <excludedEntries> - <libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/Core.swc" useDefaultLinkType="false"/> </excludedEntries> </libraryPathEntry> - <libraryPathEntry kind="3" linkType="1" path="/Core/target/Core.swc" useDefaultLinkType="false"/> </libraryPath> <sourceAttachmentPath/> </compiler> http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/f469e189/frameworks/projects/Graphics/src/main/flex/GraphicsClasses.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Graphics/src/main/flex/GraphicsClasses.as b/frameworks/projects/Graphics/src/main/flex/GraphicsClasses.as index b93e577..83ae71f 100644 --- a/frameworks/projects/Graphics/src/main/flex/GraphicsClasses.as +++ b/frameworks/projects/Graphics/src/main/flex/GraphicsClasses.as @@ -35,6 +35,7 @@ internal class GraphicsClasses import org.apache.flex.svg.Circle; Circle; import org.apache.flex.svg.Image; Image; import org.apache.flex.svg.BinaryImage; BinaryImage; + import org.apache.flex.svg.beads.ImageView; ImageView; import org.apache.flex.svg.Path; Path; import org.apache.flex.graphics.SolidColor; SolidColor; import org.apache.flex.graphics.SolidColorStroke; SolidColorStroke; @@ -50,7 +51,6 @@ internal class GraphicsClasses import org.apache.flex.graphics.PathBuilder; PathBuilder; import org.apache.flex.graphics.QuadraticCurve; QuadraticCurve; import org.apache.flex.svg.DOMWrapper; DOMWrapper; - import org.apache.flex.svg.beads.ImageView; ImageView; } http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/f469e189/frameworks/projects/Graphics/src/main/flex/org/apache/flex/svg/BinaryImage.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Graphics/src/main/flex/org/apache/flex/svg/BinaryImage.as b/frameworks/projects/Graphics/src/main/flex/org/apache/flex/svg/BinaryImage.as index c03793c..6413c7c 100644 --- a/frameworks/projects/Graphics/src/main/flex/org/apache/flex/svg/BinaryImage.as +++ b/frameworks/projects/Graphics/src/main/flex/org/apache/flex/svg/BinaryImage.as @@ -83,5 +83,11 @@ package org.apache.flex.svg (model as IBinaryImageModel).binary = value; } + COMPILE::JS + public function applyBinaryDataAsString(binaryDataAsString:String):void + { + (_image as SVGImageElement).setAttributeNS('http://www.w3.org/1999/xlink','href', binaryDataAsString); + } + } } http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/f469e189/frameworks/projects/Graphics/src/main/flex/org/apache/flex/svg/Image.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Graphics/src/main/flex/org/apache/flex/svg/Image.as b/frameworks/projects/Graphics/src/main/flex/org/apache/flex/svg/Image.as index 967e4f9..e84fd94 100644 --- a/frameworks/projects/Graphics/src/main/flex/org/apache/flex/svg/Image.as +++ b/frameworks/projects/Graphics/src/main/flex/org/apache/flex/svg/Image.as @@ -55,15 +55,26 @@ package org.apache.flex.svg COMPILE::JS protected var _image:WrappedHTMLElement; + /** + * @flexjsignorecoercion org.apache.flex.core.WrappedHTMLElement + */ COMPILE::JS protected function addImageElement():void { if (_image == null) { _image = document.createElementNS('http://www.w3.org/2000/svg', 'image') as WrappedHTMLElement; + _image.setAttribute("width", "100%"); + _image.setAttribute("height", "100%"); _image.flexjs_wrapper = this; element.appendChild(_image); } } + + COMPILE::JS + override public function get imageElement():Element + { + return _image; + } } } http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/f469e189/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 d4cb4d2..729e0e1 100644 --- a/frameworks/projects/HTML/src/main/flex/HTMLClasses.as +++ b/frameworks/projects/HTML/src/main/flex/HTMLClasses.as @@ -54,10 +54,10 @@ internal class HTMLClasses import org.apache.flex.html.beads.DropDownListView; DropDownListView; import org.apache.flex.html.beads.CloseButtonView; CloseButtonView; import org.apache.flex.html.beads.ImageAndTextButtonView; ImageAndTextButtonView; - import org.apache.flex.html.beads.ImageView; ImageView; - import org.apache.flex.html.beads.BinaryImageLoader; BinaryImageLoader; - import org.apache.flex.html.beads.models.BinaryImageModel; BinaryImageModel; } + import org.apache.flex.html.beads.ImageView; ImageView; + import org.apache.flex.html.beads.BinaryImageLoader; BinaryImageLoader; + import org.apache.flex.html.beads.models.BinaryImageModel; BinaryImageModel; import org.apache.flex.html.beads.ImageButtonView; ImageButtonView; import org.apache.flex.html.beads.ListView; ListView; COMPILE::SWF http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/f469e189/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/BinaryImage.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/BinaryImage.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/BinaryImage.as index af88de7..899ac3f 100644 --- a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/BinaryImage.as +++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/BinaryImage.as @@ -84,6 +84,11 @@ package org.apache.flex.html (model as IBinaryImageModel).binary = value; } + COMPILE::JS + public function applyBinaryDataAsString(binaryDataAsString:String):void + { + (element as HTMLImageElement).src = binaryDataAsString; + } } } http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/f469e189/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/Image.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/Image.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/Image.as index 20bc6af..0b83b62 100644 --- a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/Image.as +++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/Image.as @@ -55,7 +55,14 @@ package org.apache.flex.html element.flexjs_wrapper = this; return element; - } + } + + COMPILE::JS + override public function get imageElement():Element + { + return element; + } + } } http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/f469e189/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/BinaryImageLoader.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/BinaryImageLoader.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/BinaryImageLoader.as index f912b09..a4adf24 100644 --- a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/BinaryImageLoader.as +++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/BinaryImageLoader.as @@ -18,32 +18,19 @@ //////////////////////////////////////////////////////////////////////////////// package org.apache.flex.html.beads { - COMPILE::SWF - { - import flash.display.Bitmap; - import flash.display.Loader; - import flash.display.LoaderInfo; - import flash.events.IOErrorEvent; - import flash.net.URLRequest; - } + import org.apache.flex.core.IBinaryImageLoader; + import org.apache.flex.core.IBinaryImageModel; + import org.apache.flex.core.IImageView; + import org.apache.flex.core.IStrand; + import org.apache.flex.events.Event; + COMPILE::JS { import goog.events; import org.apache.flex.utils.URLUtils; + import org.apache.flex.core.IBinaryImage; } - import org.apache.flex.core.BeadViewBase; - import org.apache.flex.core.IBeadView; - import org.apache.flex.core.IBinaryImageModel; - 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.utils.BinaryData; - import org.apache.flex.core.IBead; - import org.apache.flex.core.IImageView; - import org.apache.flex.core.IBinaryImageLoader; /** * The ImageView class creates the visual elements of the org.apache.flex.html.Image component. @@ -91,16 +78,16 @@ package org.apache.flex.html.beads /** * @private - * @flexjsignorecoercion HTMLImageELement - * @flexjsignorecoercion BinaryImageModel + * @flexjsignorecoercion Object + * @flexjsignorecoercion UIBase */ private function handleBinaryChange(event:Event):void { var m:IBinaryImageModel = model; + var imageView:IImageView = _strand.getBeadByType(IImageView) as IImageView; COMPILE::SWF { if (m.binary) { - var imageView:IImageView = _strand.getBeadByType(IImageView) as IImageView; imageView.setupLoader(); imageView.loader.loadBytes(m.binary.array); } @@ -108,14 +95,14 @@ package org.apache.flex.html.beads COMPILE::JS { if (m.binary) { - setupLoader(); + imageView.setupLoader(); if(_objectURL) URLUtils.revokeObjectURL(_objectURL); var blob:Blob = new Blob([m.binary.array]); // I don't think we need to specify the type. // var blob = new Blob([response], {type: "image/png"}); _objectURL = URLUtils.createObjectURL(blob); - (host.element as HTMLImageElement).src = _objectURL; + (_strand as IBinaryImage).applyBinaryDataAsString(_objectURL); } } }
