flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aha...@apache.org
Subject [02/15] git commit: [flex-asjs] [refs/heads/develop] - handle margin:auto instead of horizontalCenter. This required shadow x/y properties on the base classes so we know when someone sets a position constraint vs when the layout code temporarily does it
Date Fri, 07 Aug 2015 17:11:58 GMT
handle margin:auto instead of horizontalCenter.  This required shadow x/y properties on the
base classes so we know when someone sets a position constraint vs when the layout code temporarily
does it


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

Branch: refs/heads/develop
Commit: baa8bd66bc741131f7f42b5bd1fc67e272ce7a8c
Parents: d8c2c3d
Author: Alex Harui <aharui@apache.org>
Authored: Thu Aug 6 16:24:20 2015 -0700
Committer: Alex Harui <aharui@apache.org>
Committed: Fri Aug 7 10:00:56 2015 -0700

----------------------------------------------------------------------
 .../as/src/org/apache/flex/core/ILayoutChild.as |  24 +++
 .../Core/as/src/org/apache/flex/core/UIBase.as  |  58 ++++++++
 .../as/src/org/apache/flex/core/UIButtonBase.as |  50 ++++++-
 .../org/apache/flex/core/BindableCSSStyles.as   |   6 -
 .../src/org/apache/flex/core/SimpleCSSStyles.as |   3 -
 .../flex/html/beads/layouts/BasicLayout.as      | 147 +++++++++++++++++--
 6 files changed, 266 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/baa8bd66/frameworks/projects/Core/as/src/org/apache/flex/core/ILayoutChild.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Core/as/src/org/apache/flex/core/ILayoutChild.as b/frameworks/projects/Core/as/src/org/apache/flex/core/ILayoutChild.as
index 4ec5b59..8109b4d 100755
--- a/frameworks/projects/Core/as/src/org/apache/flex/core/ILayoutChild.as
+++ b/frameworks/projects/Core/as/src/org/apache/flex/core/ILayoutChild.as
@@ -106,6 +106,30 @@ package org.apache.flex.core
         function setWidth(value:Number, noEvent:Boolean = false):void;
         
         /**
+         * Sets the X value of the component without setting the 'left' style
+         * 
+         *  @param value The new x value.
+         * 
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion FlexJS 0.0
+         */
+        function setX(value:Number):void;
+        
+        /**
+         * Sets the Y value of the component without setting the 'top' style
+         * 
+         *  @param value The new y value.
+         * 
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion FlexJS 0.0
+         */
+        function setY(value:Number):void;
+        
+        /**
          * Sets the width and height of the component 
          * without setting explicitWidth or explicitHeight.
          * It also sends one change event.  If both

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/baa8bd66/frameworks/projects/Core/as/src/org/apache/flex/core/UIBase.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Core/as/src/org/apache/flex/core/UIBase.as b/frameworks/projects/Core/as/src/org/apache/flex/core/UIBase.as
index 0fde64e..a017e38 100644
--- a/frameworks/projects/Core/as/src/org/apache/flex/core/UIBase.as
+++ b/frameworks/projects/Core/as/src/org/apache/flex/core/UIBase.as
@@ -491,6 +491,60 @@ package org.apache.flex.core
             return (top === undefined || bottom === undefined);          
         }
 		
+        private var _x:Number;
+        
+        /**
+         *  @private
+         */
+        override public function set x(value:Number):void
+        {
+            super.x = _x = value;
+            if (!style)
+                style = { left: value };
+            else
+                style.left = value;
+        }
+        
+        /**
+         *  @copy org.apache.flex.core.ILayoutChild#setX
+         *  
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion FlexJS 0.0
+         */
+        public function setX(value:Number):void
+        {
+            super.x = value;
+        }
+        
+        private var _y:Number;
+        
+        /**
+         *  @private
+         */
+        override public function set y(value:Number):void
+        {
+            super.y = _y = value;
+            if (!style)
+                style = { top: value };
+            else
+                style.top = value;
+        }
+        
+        /**
+         *  @copy org.apache.flex.core.ILayoutChild#setY
+         *  
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion FlexJS 0.0
+         */
+        public function setY(value:Number):void
+        {
+            super.y = value;
+        }
+        
 		/**
 		 * @private
 		 */
@@ -631,6 +685,10 @@ package org.apache.flex.core
                 }
                 else
                     _styles = value;
+                if (!isNaN(_y))
+                    _styles.top = _y;
+                if (!isNaN(_x))
+                    _styles.left = _x;
                 dispatchEvent(new Event("stylesChanged"));
             }
         }

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/baa8bd66/frameworks/projects/Core/as/src/org/apache/flex/core/UIButtonBase.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Core/as/src/org/apache/flex/core/UIButtonBase.as b/frameworks/projects/Core/as/src/org/apache/flex/core/UIButtonBase.as
index 4656329..889c60a 100644
--- a/frameworks/projects/Core/as/src/org/apache/flex/core/UIButtonBase.as
+++ b/frameworks/projects/Core/as/src/org/apache/flex/core/UIButtonBase.as
@@ -76,24 +76,40 @@ package org.apache.flex.core
             MouseEventConverter.setupInstanceConverters(this);
 		}
 				
+        private var _x:Number;
+        
 		/**
 		 *  @private
 		 */
 		override public function set x(value:Number):void
 		{
 			if (super.x != value) {
-				super.x = value;
+				super.x = _x = value;
+                if (!style)
+                    style = { left: value };
+                else
+                    style.left = value;
 				dispatchEvent(new Event("xChanged"));
 			}
 		}
 		
-		/**
+        private var _y:Number;
+
+        /**
 		 *  @private
 		 */
 		override public function set y(value:Number):void
 		{
 			if (super.y != value) {
-				super.y = value;
+				super.y = _y = value;
+                if (!style)
+                    style = { top: value };
+                else
+                    style.top = value;
+                if (!isNaN(_y))
+                    _styles.top = _y;
+                if (!isNaN(_x))
+                    _styles.left = _x;
 				dispatchEvent(new Event("yChanged"));
 			}
 		}
@@ -437,7 +453,33 @@ package org.apache.flex.core
         {
             return (isNaN(_explicitWidth) && isNaN(_percentWidth));
         }
-		
+		        
+        /**
+         *  @copy org.apache.flex.core.ILayoutChild#setX
+         *  
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion FlexJS 0.0
+         */
+        public function setX(value:Number):void
+        {
+            super.x = value;
+        }
+                
+        /**
+         *  @copy org.apache.flex.core.ILayoutChild#setY
+         *  
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion FlexJS 0.0
+         */
+        public function setY(value:Number):void
+        {
+            super.y = value;
+        }
+        
 		/**
 		 * @private
 		 */

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/baa8bd66/frameworks/projects/Core/asjs/src/org/apache/flex/core/BindableCSSStyles.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Core/asjs/src/org/apache/flex/core/BindableCSSStyles.as b/frameworks/projects/Core/asjs/src/org/apache/flex/core/BindableCSSStyles.as
index 1fc9306..9f8ac05 100644
--- a/frameworks/projects/Core/asjs/src/org/apache/flex/core/BindableCSSStyles.as
+++ b/frameworks/projects/Core/asjs/src/org/apache/flex/core/BindableCSSStyles.as
@@ -76,12 +76,6 @@ package org.apache.flex.core
         [Bindable]
         public var marginBottom:*;
         [Bindable]
-        public var horizontalCenter:*;
-        [Bindable]
-        public var verticalCenter:*;
-        [Bindable]
-        public var horizontalAlign:*;
-        [Bindable]
         public var verticalAlign:*;
         [Bindable]
         public var fontFamily:*;

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/baa8bd66/frameworks/projects/Core/asjs/src/org/apache/flex/core/SimpleCSSStyles.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Core/asjs/src/org/apache/flex/core/SimpleCSSStyles.as b/frameworks/projects/Core/asjs/src/org/apache/flex/core/SimpleCSSStyles.as
index 9e064df..b9bfef0 100644
--- a/frameworks/projects/Core/asjs/src/org/apache/flex/core/SimpleCSSStyles.as
+++ b/frameworks/projects/Core/asjs/src/org/apache/flex/core/SimpleCSSStyles.as
@@ -60,9 +60,6 @@ package org.apache.flex.core
         public var marginRight:*;
         public var marginTop:*;
         public var marginBottom:*;
-        public var horizontalCenter:*;
-        public var verticalCenter:*;
-        public var horizontalAlign:*;
         public var verticalAlign:*;
         public var fontFamily:*;
         public var fontSize:*;

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/baa8bd66/frameworks/projects/HTML/as/src/org/apache/flex/html/beads/layouts/BasicLayout.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/HTML/as/src/org/apache/flex/html/beads/layouts/BasicLayout.as
b/frameworks/projects/HTML/as/src/org/apache/flex/html/beads/layouts/BasicLayout.as
index bfdf68f..2c96fab 100644
--- a/frameworks/projects/HTML/as/src/org/apache/flex/html/beads/layouts/BasicLayout.as
+++ b/frameworks/projects/HTML/as/src/org/apache/flex/html/beads/layouts/BasicLayout.as
@@ -28,7 +28,8 @@ package org.apache.flex.html.beads.layouts
 	import org.apache.flex.core.ValuesManager;
 	import org.apache.flex.events.Event;
 	import org.apache.flex.events.IEventDispatcher;
-    import org.apache.flex.utils.dbg.DOMPathUtil;
+    import org.apache.flex.utils.CSSUtils;
+	import org.apache.flex.utils.dbg.DOMPathUtil;
 
     /**
      *  The BasicLayout class is a simple layout
@@ -82,6 +83,16 @@ package org.apache.flex.html.beads.layouts
 			var layoutParent:ILayoutParent = host.getBeadByType(ILayoutParent) as ILayoutParent;
 			var contentView:IParentIUIBase = layoutParent ? layoutParent.contentView : IParentIUIBase(host);
 			
+            var gotMargin:Boolean;
+            var marginLeft:Object;
+            var marginRight:Object;
+            var marginTop:Object;
+            var marginBottom:Object;
+            var margin:Object;
+            var ml:Number;
+            var mr:Number;
+            var mt:Number;
+            var mb:Number;
             var hostWidthSizedToContent:Boolean = host.isWidthSizedToContent();
             var hostHeightSizedToContent:Boolean = host.isHeightSizedToContent();
             var w:Number = hostWidthSizedToContent ? 0 : contentView.width;
@@ -100,17 +111,23 @@ package org.apache.flex.html.beads.layouts
                 var ww:Number = w;
                 var hh:Number = h;
                 
+                var ilc:ILayoutChild = child as ILayoutChild;
                 if (!isNaN(left))
                 {
-                    child.x = left;
+                    if (ilc)
+                        ilc.setX(left);
+                    else
+                        child.x = left;
                     ww -= left;
                 }
                 if (!isNaN(top))
                 {
-                    child.y = top;
+                    if (ilc)
+                        ilc.setY(top);
+                    else
+                        child.y = top;
                     hh -= top;
                 }
-                var ilc:ILayoutChild = child as ILayoutChild;
                 if (ilc)
                 {
                     if (!hostWidthSizedToContent)
@@ -133,11 +150,101 @@ package org.apache.flex.html.beads.layouts
                                 child.width = ww - right;
                         }
                         else
-                            child.x = w - right - child.width;
+                        {
+                            if (ilc)
+                                ilc.setX( w - right - child.width);
+                            else
+                                child.x = w - right - child.width;
+                        }
                     }
                     else
                         childData[i] = { ww: ww, left: left, right: right, ilc: ilc, child:
child };
                 }
+                
+                if (isNaN(right) && isNaN(left))
+                {
+                    margin = ValuesManager.valuesImpl.getValue(child, "margin");
+                    gotMargin = true;
+                    marginLeft = ValuesManager.valuesImpl.getValue(child, "margin-left");
+                    marginRight = ValuesManager.valuesImpl.getValue(child, "margin-right");
+                    var horizontalCenter:Boolean = 
+                        (marginLeft == "auto" && marginRight == "auto") ||
+                        (margin is String && margin == "auto") ||
+                        (margin is Array && 
+                            ((margin.length < 4 && margin[1] == "auto") ||
+                             (margin.length == 4 && margin[1] == "auto" &&
margin[3] == "auto")));
+                    if (!hostWidthSizedToContent)
+                    {
+                        if (!horizontalCenter)
+                        {
+                            mr = CSSUtils.getRightValue(marginRight, margin, ww);
+                            ml = CSSUtils.getLeftValue(marginLeft, margin, ww);
+                            if (ilc)
+                                ilc.setX(ml);
+                            else
+                                child.x = ml;
+                            if (ilc && isNaN(ilc.percentWidth) && isNaN(ilc.explicitWidth))
+                                child.width = ww - child.x - mr;
+                        }
+                        else
+                        {
+                            if (ilc)
+                                ilc.setX((ww - child.width) / 2);
+                            else
+                                child.x = (ww - child.width) / 2;    
+                        }
+                    }
+                    else 
+                    {
+                        if (!horizontalCenter)
+                        {
+                            mr = CSSUtils.getRightValue(marginRight, margin, ww);
+                            ml = CSSUtils.getLeftValue(marginLeft, margin, ww);
+                            if (ilc)
+                                ilc.setX(ml);
+                            else
+                                child.x = ml;
+                            if (ilc && isNaN(ilc.percentWidth) && isNaN(ilc.explicitWidth))
+                                childData[i] = { ww: ww, left: ml, right: mr, ilc: ilc, child:
child };
+                        }
+                        else
+                        {
+                            childData[i] = { ww: ww, center: true, ilc: ilc, child: child
};                            
+                        }
+                    }
+
+                }
+                if (isNaN(top) && isNaN(bottom))
+                {
+                    if (!gotMargin)
+                        margin = ValuesManager.valuesImpl.getValue(child, "margin");
+                    marginTop = ValuesManager.valuesImpl.getValue(child, "margin-top");
+                    marginBottom = ValuesManager.valuesImpl.getValue(child, "margin-bottom");
+                    mt = CSSUtils.getTopValue(marginTop, margin, hh);
+                    mb = CSSUtils.getTopValue(marginBottom, margin, hh);
+                    if (ilc)
+                        ilc.setY(mt);
+                    else
+                        child.y = mt;
+                    /* browsers don't use margin-bottom to stretch things vertically
+                    if (!hostHeightSizedToContent)
+                    {
+                        if (ilc && isNaN(ilc.percentHeight) && isNaN(ilc.explicitHeight))
+                            child.height = hh - child.y - mb;
+                    }
+                    else
+                    {
+                        if (!childData[i])
+                            childData[i] = { hh: hh, bottom: mb, ilc: ilc, child: child };
+                        else
+                        {
+                            childData[i].hh = hh;
+                            childData[i].bottom = mb;
+                        }
+                    }
+                    */
+                }
+                
                 if (ilc)
                 {
                     if (!hostHeightSizedToContent)
@@ -168,7 +275,12 @@ package org.apache.flex.html.beads.layouts
                                 child.height = hh - bottom;
                         }
                         else
-                            child.y = h - bottom - child.height;
+                        {
+                            if (ilc)
+                                ilc.setY(h - bottom - child.height);
+                            else
+                                child.y = h - bottom - child.height;
+                        }
                     }
                     else
                     {
@@ -198,7 +310,14 @@ package org.apache.flex.html.beads.layouts
                         {
                             if (data.ilc && !isNaN(data.ilc.percentWidth))
                                 data.ilc.setWidth((data.ww - (isNaN(data.right) ? 0 : data.right))
* data.ilc.percentWidth / 100, true);
-                            if (!isNaN(data.right))
+                            if (data.center)
+                            {
+                                if (data.ilc)
+                                    data.ilc.setX((data.ww - data.child.width) / 2);
+                                else
+                                    data.child.x = (data.ww - data.child.width) / 2; 
+                            }
+                            else if (!isNaN(data.right))
                             {
                                 if (!isNaN(data.left))
                                 {
@@ -208,7 +327,12 @@ package org.apache.flex.html.beads.layouts
                                         data.child.width = data.ww - data.right;
                                 }
                                 else
-                                    data.child.x = maxWidth - data.right - data.child.width;
+                                {
+                                    if (data.ilc)
+                                        data.ilc.setX(maxWidth - data.right - data.child.width);
+                                    else
+                                        data.child.x = maxWidth - data.right - data.child.width;
+                                }
                             }
                         }
                         if (hostHeightSizedToContent)
@@ -225,7 +349,12 @@ package org.apache.flex.html.beads.layouts
                                         data.child.height = data.hh - data.bottom;
                                 }
                                 else
-                                    data.child.y = maxHeight - data.bottom - data.child.height;
+                                {
+                                    if (data.ilc)
+                                        data.ilc.setY(maxHeight - data.bottom - data.child.height);
+                                    else
+                                        data.child.y = maxHeight - data.bottom - data.child.height;
+                                }
                             }
                         }
                         child.dispatchEvent(new Event("sizeChanged"));


Mime
View raw message