You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by ha...@apache.org on 2019/12/30 22:34:19 UTC

[royale-asjs] branch develop updated: Added getStyle utility function

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

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


The following commit(s) were added to refs/heads/develop by this push:
     new 5d2d95b  Added getStyle utility function
5d2d95b is described below

commit 5d2d95b6ba523a78bb38d85909d396e16d9ede0e
Author: Harbs <ha...@in-tools.com>
AuthorDate: Tue Dec 31 00:34:05 2019 +0200

    Added getStyle utility function
---
 .../royale/org/apache/royale/core/Application.as   | 10 ++++++--
 .../org/apache/royale/core/FilledRectangle.as      |  9 +++++--
 .../main/royale/org/apache/royale/core/UIBase.as   |  5 ++--
 .../main/royale/org/apache/royale/css2/Cursors.as  | 10 ++++++--
 .../html/beads/AbsolutePositioningViewBeadBase.as  | 15 +++++++++---
 .../projects/Core/src/main/royale/CoreClasses.as   |  1 +
 .../org/apache/royale/core/ApplicationBase.as      | 13 +++++-----
 .../apache/royale/core/BrowserResizeListener.as    | 13 ++++++----
 .../org/apache/royale/core/BrowserScroller.as      | 11 ++++++++-
 .../org/apache/royale/core/StyleChangeNotifier.as  |  9 +++----
 .../org/apache/royale/utils/html/getStyle.as       | 28 ++++++++++++++++++++++
 11 files changed, 98 insertions(+), 26 deletions(-)

diff --git a/frameworks/projects/Basic/src/main/royale/org/apache/royale/core/Application.as b/frameworks/projects/Basic/src/main/royale/org/apache/royale/core/Application.as
index efa7459..cbd8037 100644
--- a/frameworks/projects/Basic/src/main/royale/org/apache/royale/core/Application.as
+++ b/frameworks/projects/Basic/src/main/royale/org/apache/royale/core/Application.as
@@ -37,6 +37,11 @@ package org.apache.royale.core
         import org.apache.royale.events.utils.MouseEventConverter;
     }
 
+    COMPILE::JS
+    {
+        import org.apache.royale.utils.html.getStyle;
+    }
+
     //--------------------------------------
     //  Events
     //--------------------------------------
@@ -691,8 +696,9 @@ package org.apache.royale.core
                 
 				var baseView:UIBase = initialView as UIBase;
 				if (!isNaN(baseView.percentWidth) || !isNaN(baseView.percentHeight)) {
-					this.element.style.height = window.innerHeight.toString() + 'px';
-					this.element.style.width = window.innerWidth.toString() + 'px';
+                    var style:CSSStyleDeclaration  = getStyle(this);
+					style.height = window.innerHeight.toString() + 'px';
+					style.width = window.innerWidth.toString() + 'px';
 					this.initialView.dispatchEvent(new Event("sizeChanged")); // kick off layout if % sizes
 				}
 				
diff --git a/frameworks/projects/Basic/src/main/royale/org/apache/royale/core/FilledRectangle.as b/frameworks/projects/Basic/src/main/royale/org/apache/royale/core/FilledRectangle.as
index 3b7b8b5..82a41bc 100644
--- a/frameworks/projects/Basic/src/main/royale/org/apache/royale/core/FilledRectangle.as
+++ b/frameworks/projects/Basic/src/main/royale/org/apache/royale/core/FilledRectangle.as
@@ -22,6 +22,10 @@ package org.apache.royale.core
     {
         import flash.display.Shape;            
     }
+    COMPILE::JS
+    {
+    	import org.apache.royale.utils.html.getStyle;
+    }
 	
 	import org.apache.royale.core.UIBase;
 	
@@ -113,8 +117,9 @@ package org.apache.royale.core
             }
             COMPILE::JS
             {
-                element.style.position = 'absolute';
-                element.style.backgroundColor = '#' + _fillColor.toString(16);
+                var style:CSSStyleDeclaration = getStyle(this);
+                style.position = 'absolute';
+                style.backgroundColor = '#' + _fillColor.toString(16);
                 if (!isNaN(x)) this.x = x;
                 if (!isNaN(y)) this.y = y;
                 if (!isNaN(width)) this.width = width;
diff --git a/frameworks/projects/Basic/src/main/royale/org/apache/royale/core/UIBase.as b/frameworks/projects/Basic/src/main/royale/org/apache/royale/core/UIBase.as
index 512d8fc..ef1d4e6 100644
--- a/frameworks/projects/Basic/src/main/royale/org/apache/royale/core/UIBase.as
+++ b/frameworks/projects/Basic/src/main/royale/org/apache/royale/core/UIBase.as
@@ -39,6 +39,7 @@ package org.apache.royale.core
     {
         import org.apache.royale.html.util.addElementToWrapper;
         import org.apache.royale.utils.CSSUtils;
+        import org.apache.royale.utils.html.getStyle;
     }
 
 	/**
@@ -414,7 +415,7 @@ package org.apache.royale.core
             if (!isNaN(_explicitWidth))
                 return _explicitWidth;
             var pixels:Number;
-            var strpixels:String = element.style.width as String;
+            var strpixels:String = getStyle(this).width as String;
             if(strpixels == null)
                 pixels = NaN;
             else
@@ -510,7 +511,7 @@ package org.apache.royale.core
             if (!isNaN(_explicitHeight))
                 return _explicitHeight;
             var pixels:Number;
-            var strpixels:String = element.style.height as String;
+            var strpixels:String = getStyle(this).height as String;
             if(strpixels == null)
                 pixels = NaN;
             else
diff --git a/frameworks/projects/Basic/src/main/royale/org/apache/royale/css2/Cursors.as b/frameworks/projects/Basic/src/main/royale/org/apache/royale/css2/Cursors.as
index 91de6da..371e109 100644
--- a/frameworks/projects/Basic/src/main/royale/org/apache/royale/css2/Cursors.as
+++ b/frameworks/projects/Basic/src/main/royale/org/apache/royale/css2/Cursors.as
@@ -38,6 +38,10 @@ package org.apache.royale.css2
     COMPILE::JS
     {
         import org.apache.royale.core.WrappedHTMLElement;
+        import org.apache.royale.utils.html.getStyle;
+        import org.apache.royale.core.ElementWrapper;
+        import org.apache.royale.utils.html.getStyle;
+        import org.apache.royale.core.ElementWrapper;
     }
 
     /**
@@ -100,6 +104,7 @@ package org.apache.royale.css2
          *  @playerversion Flash 10.2
          *  @playerversion AIR 2.6
          *  @productversion Royale 0.0
+         *  @royaleignorecoercion org.apache.royale.core.ElementWrapper
          */
 		public static function getCursor(obj:IRenderedObject):String
 		{
@@ -112,12 +117,13 @@ package org.apache.royale.css2
             }
             COMPILE::JS
             {
-                return obj.element.style.cursor;
+                return getStyle(obj as ElementWrapper).cursor;
             }
 		}
 
         /**
          *  @private
+         * @royaleignorecoercion org.apache.royale.core.ElementWrapper
          */
 		public static function setCursor(obj:IRenderedObject, cursor:String):void
 		{
@@ -176,7 +182,7 @@ package org.apache.royale.css2
             }
             COMPILE::JS
             {
-                obj.element.style.cursor = cursor;
+                getStyle(obj as ElementWrapper).cursor = cursor;
             }
 
 		}
diff --git a/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/beads/AbsolutePositioningViewBeadBase.as b/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/beads/AbsolutePositioningViewBeadBase.as
index a6cce3b..0d04956 100644
--- a/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/beads/AbsolutePositioningViewBeadBase.as
+++ b/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/beads/AbsolutePositioningViewBeadBase.as
@@ -22,6 +22,12 @@ package org.apache.royale.html.beads
 	import org.apache.royale.core.IChild;
 	import org.apache.royale.core.IStrand;
 	import org.apache.royale.core.IUIBase;
+	import org.apache.royale.core.ElementWrapper;
+
+	COMPILE::JS
+	{
+		import org.apache.royale.utils.html.getStyle;
+	}
 	
 	/**
 	 * Use AbsolutePositioningViewBeadBase as the base class for custom control view beads.
@@ -77,14 +83,16 @@ package org.apache.royale.html.beads
 		 *  @playerversion Flash 10.2
 		 *  @playerversion AIR 2.6
 		 *  @productversion Royale 0.8
+     * @royaleignorecoercion org.apache.royale.core.ElementWrapper
 		 */
 		public function set strand(value:IStrand):void
 		{
 			_strand = value;
 			
 			COMPILE::JS {
-				if (host.element.style.position != "absolute" && host.element.style.position != "relative") {
-					host.element.style.position = "relative";
+				var style:CSSStyleDeclaration = getStyle(host as ElementWrapper);
+				if (style.position != "absolute" && style.position != "relative") {
+					style.position = "relative";
 				}
 			}
 		}
@@ -97,6 +105,7 @@ package org.apache.royale.html.beads
 		 *  @playerversion Flash 10.2
 		 *  @playerversion AIR 2.6
 		 *  @productversion Royale 0.8
+     * @royaleignorecoercion org.apache.royale.core.ElementWrapper
 		 */
 		public function setAbsolutePosition(child:IChild, x:Number, y:Number):void
 		{
@@ -106,7 +115,7 @@ package org.apache.royale.html.beads
 			childHost.y = y;
 		
 			COMPILE::JS {
-				childHost.element.style.position = "absolute";
+				getStyle(childHost as ElementWrapper).position = "absolute";
 			}
 		}
 	}
diff --git a/frameworks/projects/Core/src/main/royale/CoreClasses.as b/frameworks/projects/Core/src/main/royale/CoreClasses.as
index a2ae8d2..f362139 100644
--- a/frameworks/projects/Core/src/main/royale/CoreClasses.as
+++ b/frameworks/projects/Core/src/main/royale/CoreClasses.as
@@ -327,6 +327,7 @@ internal class CoreClasses
 	COMPILE::JS
 	{
 	import org.apache.royale.utils.css.transitionEventAvailable; transitionEventAvailable;
+	import org.apache.royale.utils.html.getStyle; getStyle;
 	}
 	
 	import org.apache.royale.utils.replaceBead; replaceBead;
diff --git a/frameworks/projects/Core/src/main/royale/org/apache/royale/core/ApplicationBase.as b/frameworks/projects/Core/src/main/royale/org/apache/royale/core/ApplicationBase.as
index cd7d2f7..da84081 100644
--- a/frameworks/projects/Core/src/main/royale/org/apache/royale/core/ApplicationBase.as
+++ b/frameworks/projects/Core/src/main/royale/org/apache/royale/core/ApplicationBase.as
@@ -27,6 +27,7 @@ package org.apache.royale.core
     {
         import org.apache.royale.utils.CSSUtils;
         import org.apache.royale.events.Event;
+        import org.apache.royale.utils.html.getStyle;
     }
 
     [DefaultProperty("beads")]
@@ -124,7 +125,7 @@ package org.apache.royale.core
         public function get width():Number
         {
             var pixels:Number;
-            var strpixels:String = element.style.width as String;
+            var strpixels:String = getStyle(this).width as String;
             if(strpixels == null)
                 pixels = NaN;
             else
@@ -162,7 +163,7 @@ package org.apache.royale.core
         public function get height():Number
         {
             var pixels:Number;
-            var strpixels:String = element.style.height as String;
+            var strpixels:String = getStyle(this).height as String;
             if(strpixels == null)
                 pixels = NaN;
             else
@@ -203,7 +204,7 @@ package org.apache.royale.core
             if (_height != value)
             {
                 _height = value;
-                this.element.style.height = value.toString() + 'px';        
+                getStyle(this).height = value.toString() + 'px';        
                 if (!noEvent)
                     dispatchEvent(new Event("heightChanged"));
             }            
@@ -222,7 +223,7 @@ package org.apache.royale.core
             if (_width != value)
             {
                 _width = value;
-                this.element.style.width = value.toString() + 'px';        
+                getStyle(this).width = value.toString() + 'px';        
                 if (!noEvent)
                     dispatchEvent(new Event("widthChanged"));
             }
@@ -319,7 +320,7 @@ package org.apache.royale.core
         public function set percentWidth(value:Number):void
         {
             this._percentWidth = value;
-            this.element.style.width = value.toString() + '%';
+            getStyle(this).width = value.toString() + '%';
             if (!isNaN(value))
                 this._explicitWidth = NaN;
             dispatchEvent(new Event("percentWidthChanged"));
@@ -350,7 +351,7 @@ package org.apache.royale.core
         public function set percentHeight(value:Number):void
         {
             this._percentHeight = value;
-            this.element.style.height = value.toString() + '%';
+            getStyle(this).height = value.toString() + '%';
             if (!isNaN(value))
                 this._explicitHeight = NaN;
             dispatchEvent(new Event("percentHeightChanged"));
diff --git a/frameworks/projects/Core/src/main/royale/org/apache/royale/core/BrowserResizeListener.as b/frameworks/projects/Core/src/main/royale/org/apache/royale/core/BrowserResizeListener.as
index 5009148..139d5af 100644
--- a/frameworks/projects/Core/src/main/royale/org/apache/royale/core/BrowserResizeListener.as
+++ b/frameworks/projects/Core/src/main/royale/org/apache/royale/core/BrowserResizeListener.as
@@ -22,7 +22,11 @@ COMPILE::SWF
 {
     import flash.events.Event;
     import flash.external.ExternalInterface;
-    import flash.utils.getQualifiedClassName;        
+    import flash.utils.getQualifiedClassName;
+}
+COMPILE::JS
+{
+    import org.apache.royale.utils.html.getStyle;
 }
 
     /**
@@ -130,6 +134,7 @@ COMPILE::SWF
         
 		/**
 		 * @royaleignorecoercion org.apache.royale.core.ILayoutChild
+         * @royaleignorecoercion org.apache.royale.core.ElementWrapper
 		 */
         private function resizeHandler(event:Event):void
         {
@@ -148,10 +153,10 @@ COMPILE::SWF
             COMPILE::JS
             {
                 var initialView:ILayoutChild = app.initialView as ILayoutChild;
-                var element:HTMLElement = app.element;
+                var style:CSSStyleDeclaration = getStyle(app as ElementWrapper);
                 if (!isNaN(initialView.percentWidth) || !isNaN(initialView.percentHeight)) {
-                    element.style.height = window.innerHeight + 'px';
-                    element.style.width = window.innerWidth + 'px';
+                    style.height = window.innerHeight + 'px';
+                    style.width = window.innerWidth + 'px';
                     initialView.dispatchEvent('sizeChanged'); // kick off layout if % sizes
                 }
             }
diff --git a/frameworks/projects/Core/src/main/royale/org/apache/royale/core/BrowserScroller.as b/frameworks/projects/Core/src/main/royale/org/apache/royale/core/BrowserScroller.as
index 65dfe30..98ab1ee 100644
--- a/frameworks/projects/Core/src/main/royale/org/apache/royale/core/BrowserScroller.as
+++ b/frameworks/projects/Core/src/main/royale/org/apache/royale/core/BrowserScroller.as
@@ -23,6 +23,12 @@ package org.apache.royale.core
         import flash.external.ExternalInterface;
         import flash.utils.getQualifiedClassName;
     }    
+
+    COMPILE::JS
+    {
+        import org.apache.royale.utils.html.getStyle;
+    }
+
     import org.apache.royale.events.Event;
     
     /**
@@ -64,6 +70,9 @@ package org.apache.royale.core
             app.addEventListener("viewChanged", viewChangedHandler);
         }
         
+        /**
+         * @royaleignorecoercion org.apache.royale.core.ElementWrapper
+         */
         private function viewChangedHandler(event:Event):void
         {
             COMPILE::SWF
@@ -81,7 +90,7 @@ package org.apache.royale.core
             }
             COMPILE::JS
             {
-                app.element.style.overflow = 'auto';
+                getStyle(app as ElementWrapper).overflow = 'auto';
             }
         }
 
diff --git a/frameworks/projects/Core/src/main/royale/org/apache/royale/core/StyleChangeNotifier.as b/frameworks/projects/Core/src/main/royale/org/apache/royale/core/StyleChangeNotifier.as
index bc2bd0d..0749a37 100644
--- a/frameworks/projects/Core/src/main/royale/org/apache/royale/core/StyleChangeNotifier.as
+++ b/frameworks/projects/Core/src/main/royale/org/apache/royale/core/StyleChangeNotifier.as
@@ -25,6 +25,10 @@ package org.apache.royale.core
 	import org.apache.royale.core.IBead;
 	import org.apache.royale.core.IStrand;
 	import org.apache.royale.core.IStyleableObject;
+	COMPILE::JS
+	{
+		import org.apache.royale.utils.html.getStyle;
+	}
 	
 	/**
 	 * The StyleChangeNotifier can be added to the bead list of any UI component
@@ -73,10 +77,7 @@ package org.apache.royale.core
 			COMPILE::JS {
 				var host:UIHTMLElementWrapper = UIHTMLElementWrapper(_strand);
 				if (host) {
-					var element:WrappedHTMLElement = host.element as WrappedHTMLElement;
-					if (element) {
-						element.style[event.propertyName] = event.newValue;
-					}
+					getStyle(host)[event.propertyName] = event.newValue;
 				}
 			}
 		}
diff --git a/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/html/getStyle.as b/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/html/getStyle.as
new file mode 100644
index 0000000..d0c6edc
--- /dev/null
+++ b/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/html/getStyle.as
@@ -0,0 +1,28 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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.royale.utils.html
+{
+  import org.apache.royale.core.ElementWrapper;
+
+  COMPILE::JS
+  public function getStyle(wrapper:ElementWrapper):CSSStyleDeclaration
+  {
+    return wrapper.element.style;
+  }
+}