You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by yi...@apache.org on 2016/08/01 10:25:28 UTC

git commit: [flex-asjs] [refs/heads/refactor-sprite] - Use host as style source, now that display object is no longer the host.

Repository: flex-asjs
Updated Branches:
  refs/heads/refactor-sprite 68ceca582 -> e246c2503


Use host as style source, now that display object is no longer the host.


Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/e246c250
Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/e246c250
Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/e246c250

Branch: refs/heads/refactor-sprite
Commit: e246c2503d7d32f934410270df35da9a3b401044
Parents: 68ceca5
Author: yishayw <yi...@hotmail.com>
Authored: Mon Aug 1 13:25:20 2016 +0300
Committer: yishayw <yi...@hotmail.com>
Committed: Mon Aug 1 13:25:20 2016 +0300

----------------------------------------------------------------------
 .../main/flex/org/apache/flex/core/CSSShape.as  |   2 +-
 .../main/flex/org/apache/flex/core/CSSSprite.as | 142 ++++++++++++++++++-
 .../main/flex/org/apache/flex/core/UIBase.as    |   2 +-
 .../org/apache/flex/utils/CSSBorderUtils.as     |   2 +-
 .../org/apache/flex/html/beads/CSSButtonView.as |   2 +-
 .../apache/flex/html/beads/CSSTextButtonView.as |  33 +++--
 .../flex/html/beads/SingleLineBorderBead.as     |   4 +-
 .../flex/html/beads/SolidBackgroundBead.as      |  18 +--
 .../apache/flex/html/beads/TextFieldViewBase.as |   2 +-
 9 files changed, 173 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/e246c250/frameworks/projects/Core/src/main/flex/org/apache/flex/core/CSSShape.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Core/src/main/flex/org/apache/flex/core/CSSShape.as b/frameworks/projects/Core/src/main/flex/org/apache/flex/core/CSSShape.as
index 41e690b..c96ba84 100644
--- a/frameworks/projects/Core/src/main/flex/org/apache/flex/core/CSSShape.as
+++ b/frameworks/projects/Core/src/main/flex/org/apache/flex/core/CSSShape.as
@@ -254,7 +254,7 @@ package org.apache.flex.core
          */
         public function draw(w:Number, h:Number):void
         {
-            CSSBorderUtils.draw(_shape.graphics, w, h, _shape, state, true);            
+            CSSBorderUtils.draw(_shape.graphics, w, h, this, state, true);            
         }
    	}
 }

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/e246c250/frameworks/projects/Core/src/main/flex/org/apache/flex/core/CSSSprite.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Core/src/main/flex/org/apache/flex/core/CSSSprite.as b/frameworks/projects/Core/src/main/flex/org/apache/flex/core/CSSSprite.as
index 9ca030e..c9e0742 100644
--- a/frameworks/projects/Core/src/main/flex/org/apache/flex/core/CSSSprite.as
+++ b/frameworks/projects/Core/src/main/flex/org/apache/flex/core/CSSSprite.as
@@ -18,10 +18,12 @@
 ////////////////////////////////////////////////////////////////////////////////
 package org.apache.flex.core
 {
+    import flash.display.DisplayObject;
     import flash.display.Graphics;
     
     import org.apache.flex.core.IChild;
     import org.apache.flex.events.Event;
+    import org.apache.flex.events.IEventDispatcher;
     import org.apache.flex.utils.CSSBorderUtils;
     
     /**
@@ -35,7 +37,7 @@ package org.apache.flex.core
      *  @productversion FlexJS 0.0
      */
     COMPILE::SWF
-	public class CSSSprite extends HTMLElementWrapper implements IStyleableObject, IChild
+	public class CSSSprite extends HTMLElementWrapper implements IStyleableObject, IChild, IParentIUIBase
 	{
         /**
          *  Constructor.
@@ -156,7 +158,141 @@ package org.apache.flex.core
          */
         public function draw(w:Number, h:Number):void
         {
-            CSSBorderUtils.draw($sprite.graphics, w, h, $sprite, state, true);            
+            CSSBorderUtils.draw($sprite.graphics, w, h,this, state, true);            
         }
-   	}
+		
+		/**
+		 *  @copy org.apache.flex.core.IParent#addElement()
+		 * 
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion FlexJS 0.0
+		 */
+		public function addElement(c:Object, dispatchEvent:Boolean = true):void
+		{
+			if(_elements == null)
+				_elements = [];
+			_elements[_elements.length] = c;
+			$sprite.addChild(c.$displayObject);
+			c.parent = this;
+			if (c is IUIBase)
+			{
+				IUIBase(c).addedToParent();
+			}
+			
+		}
+		
+		/**
+		 *  @copy org.apache.flex.core.IParent#addElementAt()
+		 * 
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion FlexJS 0.0
+		 */
+		public function addElementAt(c:Object, index:int, dispatchEvent:Boolean = true):void
+		{
+			if(_elements == null)
+				_elements = [];
+			_elements.splice(index,0,c);
+			
+			$sprite.addChildAt(c.$displayObject,index);
+			c.parent = this;
+			if (c is IUIBase)
+			{
+				IUIBase(c).addedToParent();
+			}
+		}
+		
+		/**
+		 *  @copy org.apache.flex.core.IParent#getElementAt()
+		 * 
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion FlexJS 0.0
+		 */
+		public function getElementAt(index:int):Object
+		{
+			if(_elements == null)
+				return null;
+			return _elements[index];
+		}        
+		
+		private var _elements:Array;
+		/**
+		 *  @copy org.apache.flex.core.IParent#getElementIndex()
+		 * 
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion FlexJS 0.0
+		 */
+		public function getElementIndex(c:Object):int
+		{
+			if(_elements == null)
+				return -1;
+			return _elements.indexOf(c);
+		}
+		
+		/**
+		 *  @copy org.apache.flex.core.IParent#removeElement()
+		 * 
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion FlexJS 0.0
+		 */
+		public function removeElement(c:Object, dispatchEvent:Boolean = true):void
+		{
+			if(_elements)
+			{
+				var idx:int = _elements.indexOf(c);
+				if(idx>=0)
+					_elements.splice(idx,1);
+				c.parent = null;
+			}
+			$sprite.removeChild(c.$displayObject);
+		}
+		
+		/**
+		 *  @copy org.apache.flex.core.IParent#numElements
+		 * 
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion FlexJS 0.0
+		 */
+		public function get numElements():int
+		{
+			return _elements ? _elements.length : 0;
+		}
+		
+		public function getBeadByType(classOrInterface:Class):IBead
+		{
+			// TODO Auto Generated method stub
+			return null;
+		}
+		
+		public function removeBead(bead:IBead):IBead
+		{
+			// TODO Auto Generated method stub
+			return null;
+		}
+		
+		public function addedToParent():void
+		{
+			// TODO Auto Generated method stub
+			
+		}
+		
+		public function get topMostEventDispatcher():IEventDispatcher
+		{
+			// TODO Auto Generated method stub
+			return null;
+		}
+		
+
+	}
 }

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/e246c250/frameworks/projects/Core/src/main/flex/org/apache/flex/core/UIBase.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Core/src/main/flex/org/apache/flex/core/UIBase.as b/frameworks/projects/Core/src/main/flex/org/apache/flex/core/UIBase.as
index 3516b2b..7a583a1 100644
--- a/frameworks/projects/Core/src/main/flex/org/apache/flex/core/UIBase.as
+++ b/frameworks/projects/Core/src/main/flex/org/apache/flex/core/UIBase.as
@@ -1076,7 +1076,7 @@ package org.apache.flex.core
                 if(_elements == null)
                     _elements = [];
                 _elements[_elements.length] = c;
-                $sprite.addChild(c.$sprite);
+                $sprite.addChild(c.$displayObject);
                 c.parent = this;
                 if (c is IUIBase)
                 {

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/e246c250/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/CSSBorderUtils.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/CSSBorderUtils.as b/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/CSSBorderUtils.as
index ef32e1a..25c9d08 100644
--- a/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/CSSBorderUtils.as
+++ b/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/CSSBorderUtils.as
@@ -64,7 +64,7 @@ package org.apache.flex.utils
 		 *  @productversion FlexJS 0.0
          */
         public static function draw(g:Graphics, width:Number, height:Number,
-                                    host:DisplayObject, state:String = null, 
+                                    host:Object, state:String = null, 
                                     drawBackground:Boolean = false, clear:Boolean = true):void
         {            
             if (clear)

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/e246c250/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/CSSButtonView.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/CSSButtonView.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/CSSButtonView.as
index fcd14cc..7775f03 100644
--- a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/CSSButtonView.as
+++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/CSSButtonView.as
@@ -127,7 +127,7 @@ package org.apache.flex.html.beads
 		    CSSBorderUtils.draw(sprite.graphics, 
 					DisplayObject(_strand).width + pl + pr, 
 					DisplayObject(_strand).height + pt + pb,
-                    _strand as DisplayObject,
+                    _strand,
                     state, true);
 		}
 		

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/e246c250/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/CSSTextButtonView.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/CSSTextButtonView.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/CSSTextButtonView.as
index 996296c..75d3023 100644
--- a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/CSSTextButtonView.as
+++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/CSSTextButtonView.as
@@ -18,7 +18,6 @@
 ////////////////////////////////////////////////////////////////////////////////
 package org.apache.flex.html.beads
 {
-	import flash.display.DisplayObject;
 	import flash.display.Loader;
 	import flash.display.Shape;
 	import flash.display.SimpleButton;
@@ -28,19 +27,19 @@ package org.apache.flex.html.beads
 	import flash.text.TextField;
 	import flash.text.TextFieldType;
 	
-    import org.apache.flex.core.BeadViewBase;
+	import org.apache.flex.core.BeadViewBase;
 	import org.apache.flex.core.CSSTextField;
 	import org.apache.flex.core.IBeadView;
 	import org.apache.flex.core.IStrand;
 	import org.apache.flex.core.ITextModel;
 	import org.apache.flex.core.IUIBase;
+	import org.apache.flex.core.UIButtonBase;
 	import org.apache.flex.core.ValuesManager;
 	import org.apache.flex.events.Event;
 	import org.apache.flex.events.IEventDispatcher;
-	import org.apache.flex.html.TextButton;
 	import org.apache.flex.utils.CSSUtils;
-    import org.apache.flex.utils.SolidBorderUtil;
-    import org.apache.flex.utils.StringTrimmer;
+	import org.apache.flex.utils.SolidBorderUtil;
+	import org.apache.flex.utils.StringTrimmer;
 
     /**
      *  The CSSTextButtonView class is the default view for
@@ -87,6 +86,10 @@ package org.apache.flex.html.beads
 			overSprite.addChild(overTextField.$textField);
 		}
 		
+		private function get host():IUIBase
+		{
+			return _strand as IUIBase;
+		}
 		private var textModel:ITextModel;
 		
 		private var shape:Shape;
@@ -118,10 +121,10 @@ package org.apache.flex.html.beads
             upTextField.parentHandlesPadding = true;
             downTextField.parentHandlesPadding = true;
             overTextField.parentHandlesPadding = true;
-			SimpleButton(value).upState = upSprite;
-			SimpleButton(value).downState = downSprite;
-			SimpleButton(value).overState = overSprite;
-			SimpleButton(value).hitTestState = shape;
+			(value as UIButtonBase).$button.upState = upSprite;
+			(value as UIButtonBase).$button.downState = downSprite;
+			(value as UIButtonBase).$button.overState = overSprite;
+			(value as UIButtonBase).$button.hitTestState = shape;
 			if (textModel.text !== null)
 				text = textModel.text;
 			if (textModel.html !== null)
@@ -202,10 +205,10 @@ package org.apache.flex.html.beads
 			var paddingRight:Object = ValuesManager.valuesImpl.getValue(_strand, "padding-right", state);
 			var paddingTop:Object = ValuesManager.valuesImpl.getValue(_strand, "padding-top", state);
 			var paddingBottom:Object = ValuesManager.valuesImpl.getValue(_strand, "padding-bottom", state);
-            var pl:Number = CSSUtils.getLeftValue(paddingLeft, padding, DisplayObject(_strand).width);
-            var pr:Number = CSSUtils.getRightValue(paddingRight, padding, DisplayObject(_strand).width);
-            var pt:Number = CSSUtils.getTopValue(paddingTop, padding, DisplayObject(_strand).height);
-            var pb:Number = CSSUtils.getBottomValue(paddingBottom, padding, DisplayObject(_strand).height);
+            var pl:Number = CSSUtils.getLeftValue(paddingLeft, padding, host.$displayObject.width);
+            var pr:Number = CSSUtils.getRightValue(paddingRight, padding, host.$displayObject.width);
+            var pt:Number = CSSUtils.getTopValue(paddingTop, padding, host.$displayObject.height);
+            var pb:Number = CSSUtils.getBottomValue(paddingBottom, padding, host.$displayObject.height);
             
 			var backgroundColor:Object = ValuesManager.valuesImpl.getValue(_strand, "background-color", state);
             var bgColor:uint;
@@ -315,8 +318,8 @@ package org.apache.flex.html.beads
 		
 		private function updateHitArea():void
 		{
-			var useWidth:uint = Math.max(DisplayObject(_strand).width, upTextField.textWidth);
-			var useHeight:uint = Math.max(DisplayObject(_strand).height, upTextField.textHeight);
+			var useWidth:uint = Math.max(host.$displayObject.width, upTextField.textWidth);
+			var useHeight:uint = Math.max(host.$displayObject.height, upTextField.textHeight);
 			
 			shape.graphics.clear();
 			shape.graphics.beginFill(0xCCCCCC);

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/e246c250/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/SingleLineBorderBead.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/SingleLineBorderBead.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/SingleLineBorderBead.as
index 03bb682..3663b56 100644
--- a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/SingleLineBorderBead.as
+++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/SingleLineBorderBead.as
@@ -75,7 +75,7 @@ package org.apache.flex.html.beads
 		private function changeHandler(event:Event):void
 		{
             var host:UIBase = UIBase(_strand);
-            var g:Graphics = host.$sprite.graphics;
+            var g:Graphics = (host.$displayObject as Object).graphics as Graphics;
             var w:Number = host.width;
             var h:Number = host.height;
             var state:String;
@@ -85,7 +85,7 @@ package org.apache.flex.html.beads
 			var gd:IGraphicsDrawing = _strand.getBeadByType(IGraphicsDrawing) as IGraphicsDrawing;
 			if( this == gd ) g.clear();
             
-            CSSBorderUtils.draw(g, w, h, host.$sprite, state, false, false);
+            CSSBorderUtils.draw(g, w, h, host, state, false, false);
 		}
 	}
 }

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/e246c250/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/SolidBackgroundBead.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/SolidBackgroundBead.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/SolidBackgroundBead.as
index a162669..6dade4d 100644
--- a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/SolidBackgroundBead.as
+++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/SolidBackgroundBead.as
@@ -18,17 +18,17 @@
 ////////////////////////////////////////////////////////////////////////////////
 package org.apache.flex.html.beads
 {
+    import flash.display.Graphics;
     import flash.display.Sprite;
-	import flash.display.Graphics;
-	
-	import org.apache.flex.core.IBead;
+    
+    import org.apache.flex.core.IBead;
     import org.apache.flex.core.IBeadView;
     import org.apache.flex.core.ILayoutChild;
-	import org.apache.flex.core.IStrand;
-	import org.apache.flex.core.IUIBase;
-	import org.apache.flex.core.ValuesManager;
-	import org.apache.flex.events.Event;
-	import org.apache.flex.events.IEventDispatcher;
+    import org.apache.flex.core.IStrand;
+    import org.apache.flex.core.IUIBase;
+    import org.apache.flex.core.ValuesManager;
+    import org.apache.flex.events.Event;
+    import org.apache.flex.events.IEventDispatcher;
 
     /**
      *  The SolidBackgroundBead class draws a solid filled background.
@@ -177,7 +177,7 @@ package org.apache.flex.html.beads
         
 		private function changeHandler(event:Event):void
 		{
-            var g:Graphics = Sprite(host).graphics;
+            var g:Graphics = (host.$displayObject as Object).graphics as Graphics;
             var w:Number = host.width;
             var h:Number = host.height;
 			

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/e246c250/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/TextFieldViewBase.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/TextFieldViewBase.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/TextFieldViewBase.as
index 6ccbd43..ead9d7b 100644
--- a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/TextFieldViewBase.as
+++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/TextFieldViewBase.as
@@ -95,7 +95,7 @@ package org.apache.flex.html.beads
             IEventDispatcher(_strand).addEventListener("widthChanged", widthChangeHandler);
             IEventDispatcher(_strand).addEventListener("heightChanged", heightChangeHandler);
             IEventDispatcher(_strand).addEventListener("sizeChanged", sizeChangeHandler);
-			UIBase(value).$sprite.addChild(_textField.$textField);
+			UIBase(value).addElement(_textField);
 			if (_textModel.text !== null)
 				text = _textModel.text;
 			if (_textModel.html !== null)