You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by gr...@apache.org on 2020/10/25 00:34:10 UTC

[royale-asjs] 02/05: LookAlike was not correctly displaying in general case (emulation of BitmapData.draw dragSource, for example). Copying computedStyles fixes that.

This is an automated email from the ASF dual-hosted git repository.

gregdove pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-asjs.git

commit 441661b58d4a8b4567f82928f65f7e50240463df
Author: greg-dove <gr...@gmail.com>
AuthorDate: Sun Oct 25 11:46:01 2020 +1300

    LookAlike was not correctly displaying in general case (emulation of BitmapData.draw dragSource, for example).
    Copying computedStyles fixes that.
---
 .../royale/org/apache/royale/core/Lookalike.as     | 42 +++++++++++++++++++++-
 1 file changed, 41 insertions(+), 1 deletion(-)

diff --git a/frameworks/projects/Basic/src/main/royale/org/apache/royale/core/Lookalike.as b/frameworks/projects/Basic/src/main/royale/org/apache/royale/core/Lookalike.as
index 48f87a5..026e03c 100644
--- a/frameworks/projects/Basic/src/main/royale/org/apache/royale/core/Lookalike.as
+++ b/frameworks/projects/Basic/src/main/royale/org/apache/royale/core/Lookalike.as
@@ -38,6 +38,45 @@ package org.apache.royale.core
     
     public class Lookalike extends UIBase
     {
+
+        /**
+         *
+         * @royaleignorecoercion Element
+         * @royaleignorecoercion HTMLElement
+         * @royaleignorecoercion Node
+         */
+        COMPILE::JS
+        private function deepCloneWithStyles(node:Element):Element{
+            var localNode:Node = node as Node;
+            if (localNode.nodeType != 1) {
+                //some stuff here for IE11:
+                return localNode.nodeType == 3 ? document.createTextNode(localNode.nodeValue) as Element: localNode.cloneNode(true) as Element;
+            }
+            var clone:HTMLElement = localNode.cloneNode(false) as HTMLElement;
+            var style:CSSStyleDeclaration = getComputedStyle(node, null);
+            var cssText:String;
+            if (style.cssText) {
+                cssText = style.cssText;
+            } else {
+                //IE11 needs this fallback
+                cssText = '';
+                for (var i:uint = 0; i < style.length; i++) {
+                    var styleName:String = style[i];
+                    var propval:String = style.getPropertyValue(styleName);
+                    cssText += (styleName + ":" + propval + "; ");
+                }
+            }
+
+            clone.style.cssText = cssText;
+            var child:Node = localNode.firstChild;
+            while(child){
+                clone.appendChild(deepCloneWithStyles(child as Element));
+                child = child.nextSibling;
+            }
+
+            return clone;
+        }
+
         /**
          *  Constructor.
          *  
@@ -58,9 +97,10 @@ package org.apache.royale.core
             }
             COMPILE::JS
             {
-                element = original.element.cloneNode(true) as WrappedHTMLElement;
+                element = deepCloneWithStyles(original.element) as WrappedHTMLElement;
             }
             super();
+            this.typeNames = 'LookALike';
         }
         COMPILE::JS
         override protected function createElement():WrappedHTMLElement