Repository: flex-asjs Updated Branches: refs/heads/feature/chart-work d2fe8c192 -> 4f0765d01
Refactor layout classes, moving common code into a base class (LayoutBase). Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/4f0765d0 Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/4f0765d0 Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/4f0765d0 Branch: refs/heads/feature/chart-work Commit: 4f0765d01e176de9d1057a4c6791dd3837d06557 Parents: d2fe8c1 Author: Peter Ent <p...@apache.org> Authored: Fri Mar 31 10:08:19 2017 -0400 Committer: Peter Ent <p...@apache.org> Committed: Fri Mar 31 10:08:19 2017 -0400 ---------------------------------------------------------------------- .../flex/org/apache/flex/core/LayoutBase.as | 166 +++++++++++++++++++ .../flex/html/beads/layouts/BasicLayout.as | 104 ++++-------- .../flex/html/beads/layouts/ButtonBarLayout.as | 26 +-- .../FlexibleFirstChildHorizontalLayout.as | 66 ++------ .../html/beads/layouts/HorizontalFlexLayout.as | 44 +---- .../html/beads/layouts/HorizontalFlowLayout.as | 31 +--- .../flex/html/beads/layouts/HorizontalLayout.as | 56 ++----- .../layouts/OneFlexibleChildHorizontalLayout.as | 61 +------ .../layouts/OneFlexibleChildVerticalLayout.as | 61 +------ .../flex/html/beads/layouts/TileLayout.as | 31 +--- .../html/beads/layouts/VerticalColumnLayout.as | 66 ++------ .../html/beads/layouts/VerticalFlexLayout.as | 40 +---- .../flex/html/beads/layouts/VerticalLayout.as | 65 ++------ 13 files changed, 305 insertions(+), 512 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/4f0765d0/frameworks/projects/HTML/src/main/flex/org/apache/flex/core/LayoutBase.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/core/LayoutBase.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/core/LayoutBase.as new file mode 100644 index 0000000..dde6448 --- /dev/null +++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/core/LayoutBase.as @@ -0,0 +1,166 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.flex.core +{ + + import org.apache.flex.core.IBeadLayout; + import org.apache.flex.core.ILayoutChild; + import org.apache.flex.core.ILayoutHost; + import org.apache.flex.core.ILayoutParent; + import org.apache.flex.core.ILayoutView; + import org.apache.flex.core.IParent; + import org.apache.flex.core.IStrand; + import org.apache.flex.core.ValuesManager; + import org.apache.flex.utils.CSSUtils; + + /** + * This class is the base class for most, if not all, layouts. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.8 + */ + public class LayoutBase implements IBeadLayout + { + /** + * Constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.8 + */ + public function LayoutBase() + { + } + + /** + * The strand/host container is also an ILayoutChild because + * it can have its size dictated by the host's parent which is + * important to know for layout optimization. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.8 + */ + protected var host:ILayoutChild; + + /** + * @copy org.apache.flex.core.IBead#strand + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.8 + * + * @flexjsignorecoercion org.apache.flex.core.ILayoutChild + */ + public function set strand(value:IStrand):void + { + host = value as ILayoutChild; + } + + /** + * Returns an object of margins for the given child. + * + * @param child Object The element whose margins are required. + * @param hostWidth Number The usable width dimension of the host. + * @param hostHeight Number The usable height dimension of the host. + * + * @return Object A structure of {top:Number, left:Number, bottom:Number, right:Number} + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.8 + */ + protected function childMargins(child:Object, hostWidth:Number, hostHeight:Number):Object + { + var margin:Object = ValuesManager.valuesImpl.getValue(child, "margin"); + var marginLeft:Object = ValuesManager.valuesImpl.getValue(child, "margin-left"); + var marginTop:Object = ValuesManager.valuesImpl.getValue(child, "margin-top"); + var marginRight:Object = ValuesManager.valuesImpl.getValue(child, "margin-right"); + var marginBottom:Object = ValuesManager.valuesImpl.getValue(child, "margin-bottom"); + var ml:Number = CSSUtils.getLeftValue(marginLeft, margin, hostWidth); + var mr:Number = CSSUtils.getRightValue(marginRight, margin, hostWidth); + var mt:Number = CSSUtils.getTopValue(marginTop, margin, hostHeight); + var mb:Number = CSSUtils.getBottomValue(marginBottom, margin, hostHeight); + if (marginLeft == "auto") + ml = 0; + if (marginRight == "auto") + mr = 0; + + return {left:ml, top:mt, right:mr, bottom:mb}; + } + + /** + * Returns an object containing the child's positioning values. + * + * @param child Object The element whose positions are required. + * + * @return Object A structure of {top:Number, left:Number, bottom:Number, right:Number} + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.8 + */ + protected function childPositions(child:Object):Object + { + var left:Number = ValuesManager.valuesImpl.getValue(child, "left"); + var right:Number = ValuesManager.valuesImpl.getValue(child, "right"); + var top:Number = ValuesManager.valuesImpl.getValue(child, "top"); + var bottom:Number = ValuesManager.valuesImpl.getValue(child, "bottom"); + + return {top:top, left:left, bottom:bottom, right:right}; + } + + /** + * Returns the ILayoutView for the host. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.8 + * + * @flexjsignorecoercion org.apache.flex.core.ILayoutParent + */ + protected function get layoutView():ILayoutView + { + var viewBead:ILayoutHost = (host as ILayoutParent).getLayoutHost(); + return viewBead.contentView; + } + + /** + * @copy org.apache.flex.core.IBeadLayout#layout + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.8 + */ + public function layout():Boolean + { + // override in subclass + return false; + } + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/4f0765d0/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/BasicLayout.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/BasicLayout.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/BasicLayout.as index 3aad370..72c42d8 100644 --- a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/BasicLayout.as +++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/BasicLayout.as @@ -18,7 +18,8 @@ //////////////////////////////////////////////////////////////////////////////// package org.apache.flex.html.beads.layouts { - + import org.apache.flex.core.LayoutBase; + import org.apache.flex.core.IBeadLayout; import org.apache.flex.core.ILayoutChild; import org.apache.flex.core.ILayoutHost; @@ -44,7 +45,7 @@ package org.apache.flex.html.beads.layouts * @playerversion AIR 2.6 * @productversion FlexJS 0.0 */ - public class BasicLayout implements IBeadLayout + public class BasicLayout extends LayoutBase implements IBeadLayout { /** * Constructor. @@ -56,24 +57,7 @@ package org.apache.flex.html.beads.layouts */ public function BasicLayout() { - } - - // the strand/host container is also an ILayoutChild because - // can have its size dictated by the host's parent which is - // important to know for layout optimization - private var host:ILayoutChild; - - /** - * @copy org.apache.flex.core.IBead#strand - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public function set strand(value:IStrand):void - { - host = value as ILayoutChild; + super(); } /** @@ -81,12 +65,11 @@ package org.apache.flex.html.beads.layouts * @flexjsignorecoercion org.apache.flex.core.ILayoutHost * @flexjsignorecoercion org.apache.flex.core.UIBase */ - public function layout():Boolean + override public function layout():Boolean { COMPILE::SWF { - var viewBead:ILayoutHost = (host as ILayoutParent).getLayoutHost(); - var contentView:ILayoutView = viewBead.contentView; + var contentView:ILayoutView = layoutView; var hostWidthSizedToContent:Boolean = host.isWidthSizedToContent(); var hostHeightSizedToContent:Boolean = host.isHeightSizedToContent(); @@ -96,111 +79,88 @@ package org.apache.flex.html.beads.layouts var n:int = contentView.numElements; - var gotMargin:Boolean; - var marginLeft:Object; - var marginRight:Object; - var marginTop:Object; - var marginBottom:Object; - var margin:Object; - for (var i:int = 0; i < n; i++) { var child:IUIBase = contentView.getElementAt(i) as IUIBase; if (child == null || !child.visible) continue; - var left:Number = ValuesManager.valuesImpl.getValue(child, "left"); - var right:Number = ValuesManager.valuesImpl.getValue(child, "right"); - var top:Number = ValuesManager.valuesImpl.getValue(child, "top"); - var bottom:Number = ValuesManager.valuesImpl.getValue(child, "bottom"); + var positions:Object = childPositions(child); + var margins:Object = childMargins(child, contentView.width, contentView.height); var ww:Number = w; var hh:Number = h; - margin = ValuesManager.valuesImpl.getValue(child, "margin"); - marginLeft = ValuesManager.valuesImpl.getValue(child, "margin-left"); - marginTop = ValuesManager.valuesImpl.getValue(child, "margin-top"); - marginRight = ValuesManager.valuesImpl.getValue(child, "margin-right"); - marginBottom = ValuesManager.valuesImpl.getValue(child, "margin-bottom"); - var ml:Number = CSSUtils.getLeftValue(marginLeft, margin, contentView.width); - var mr:Number = CSSUtils.getRightValue(marginRight, margin, contentView.width); - var mt:Number = CSSUtils.getTopValue(marginTop, margin, contentView.height); - var mb:Number = CSSUtils.getBottomValue(marginBottom, margin, contentView.height); - if (marginLeft == "auto") - ml = 0; - if (marginRight == "auto") - mr = 0; - var ilc:ILayoutChild = child as ILayoutChild; // set the top edge of the child - if (!isNaN(left)) + if (!isNaN(positions.left)) { if (ilc) - ilc.setX(left+ml); + ilc.setX(positions.left+margins.left); else - child.x = left+ml; - ww -= left + ml; + child.x = positions.left+margins.left; + ww -= positions.left + margins.left; } // set the left edge of the child - if (!isNaN(top)) + if (!isNaN(positions.top)) { if (ilc) - ilc.setY(top+mt); + ilc.setY(positions.top+margins.top); else - child.y = top+mt; - hh -= top + mt; + child.y = positions.top+margins.top; + hh -= positions.top + margins.top; } // set the right edge of the child - if (!isNaN(right)) + if (!isNaN(positions.right)) { if (!hostWidthSizedToContent) { - if (!isNaN(left)) + if (!isNaN(positions.left)) { if (ilc) - ilc.setWidth(ww - right - mr, false); + ilc.setWidth(ww - positions.right - margins.right, false); else - child.width = ww - right - mr; + child.width = ww - positions.right - margins.right; } else { if (ilc) - ilc.setX( w - right - mr - child.width - mr); + ilc.setX( w - positions.right - margins.left - child.width - margins.right); else - child.x = w - right - mr - child.width - mr; + child.x = w - positions.right - margins.left - child.width - margins.right; } } } else if (ilc != null && !isNaN(ilc.percentWidth) && !hostWidthSizedToContent) { - ilc.setWidth((ww - mr - ml) * ilc.percentWidth/100, false); + ilc.setWidth((ww - margins.right - margins.left) * ilc.percentWidth/100, false); } // set the bottm edge of the child - if (!isNaN(bottom)) + if (!isNaN(positions.bottom)) { if (!hostHeightSizedToContent) { - if (!isNaN(top)) + if (!isNaN(positions.top)) { if (ilc) - ilc.setHeight(hh - bottom - mb, false); + ilc.setHeight(hh - positions.bottom - margins.bottom, false); else - child.height = hh - bottom - mb; + child.height = hh - positions.bottom - margins.bottom; } else { if (ilc) - ilc.setY( h - bottom - child.height - mb); + ilc.setY( h - positions.bottom - child.height - margins.bottom); else - child.y = h - bottom - child.height - mb; + child.y = h - positions.bottom - child.height - margins.bottom; } } } else if (ilc != null && !isNaN(ilc.percentHeight) && !hostHeightSizedToContent) { - ilc.setHeight((hh - mt - mb) * ilc.percentHeight/100, false); + ilc.setHeight((hh - margins.top - margins.bottom) * ilc.percentHeight/100, false); } } @@ -212,9 +172,7 @@ package org.apache.flex.html.beads.layouts { var i:int var n:int; - - var viewBead:ILayoutHost = (host as ILayoutParent).getLayoutHost(); - var contentView:ILayoutView = viewBead.contentView; + var contentView:ILayoutView = layoutView; n = contentView.numElements; http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/4f0765d0/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/ButtonBarLayout.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/ButtonBarLayout.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/ButtonBarLayout.as index 4771942..75d1ee7 100644 --- a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/ButtonBarLayout.as +++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/ButtonBarLayout.as @@ -18,6 +18,7 @@ //////////////////////////////////////////////////////////////////////////////// package org.apache.flex.html.beads.layouts { + import org.apache.flex.core.LayoutBase; import org.apache.flex.core.IBeadLayout; import org.apache.flex.core.ILayoutHost; import org.apache.flex.core.ILayoutView; @@ -47,7 +48,7 @@ package org.apache.flex.html.beads.layouts * @playerversion AIR 2.6 * @productversion FlexJS 0.0 */ - public class ButtonBarLayout implements IBeadLayout + public class ButtonBarLayout extends LayoutBase implements IBeadLayout { /** * constructor. @@ -59,21 +60,7 @@ package org.apache.flex.html.beads.layouts */ public function ButtonBarLayout() { - } - - private var _strand:IStrand; - - /** - * @copy org.apache.flex.core.IBead#strand - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public function set strand(value:IStrand):void - { - _strand = value; + super(); } private var _widthType:Number = ButtonBarModel.PIXEL_WIDTHS; @@ -100,12 +87,11 @@ package org.apache.flex.html.beads.layouts /** * @copy org.apache.flex.core.IBeadLayout#layout */ - public function layout():Boolean + override public function layout():Boolean { - var layoutHost:ILayoutHost = (_strand as ILayoutParent).getLayoutHost(); - var contentView:ILayoutView = layoutHost.contentView; + var contentView:ILayoutView = layoutView; - var model:ButtonBarModel = _strand.getBeadByType(ButtonBarModel) as ButtonBarModel; + var model:ButtonBarModel = (host as IStrand).getBeadByType(ButtonBarModel) as ButtonBarModel; if (model) { buttonWidths = model.buttonWidths; _widthType = model.widthType; http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/4f0765d0/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/FlexibleFirstChildHorizontalLayout.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/FlexibleFirstChildHorizontalLayout.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/FlexibleFirstChildHorizontalLayout.as index c82cab5..6af7d8a 100644 --- a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/FlexibleFirstChildHorizontalLayout.as +++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/FlexibleFirstChildHorizontalLayout.as @@ -18,6 +18,7 @@ //////////////////////////////////////////////////////////////////////////////// package org.apache.flex.html.beads.layouts { + import org.apache.flex.core.LayoutBase; import org.apache.flex.core.IBeadLayout; import org.apache.flex.core.ILayoutChild; import org.apache.flex.core.ILayoutView; @@ -50,7 +51,7 @@ package org.apache.flex.html.beads.layouts * @playerversion AIR 2.6 * @productversion FlexJS 0.0 */ - public class FlexibleFirstChildHorizontalLayout implements IBeadLayout + public class FlexibleFirstChildHorizontalLayout extends LayoutBase implements IBeadLayout { /** * Constructor. @@ -62,24 +63,7 @@ package org.apache.flex.html.beads.layouts */ public function FlexibleFirstChildHorizontalLayout() { - } - - // the strand/host container is also an ILayoutChild because - // can have its size dictated by the host's parent which is - // important to know for layout optimization - private var host:ILayoutChild; - - /** - * @copy org.apache.flex.core.IBead#strand - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public function set strand(value:IStrand):void - { - host = value as ILayoutChild; + super(); } private var _maxWidth:Number; @@ -132,10 +116,9 @@ package org.apache.flex.html.beads.layouts * @copy org.apache.flex.core.IBeadLayout#layout */ COMPILE::SWF - public function layout():Boolean + override public function layout():Boolean { - var layoutHost:ILayoutHost = (host as ILayoutParent).getLayoutHost(); - var contentView:ILayoutView = layoutHost.contentView; + var contentView:ILayoutView = layoutView; var n:Number = contentView.numElements; if (n == 0) return false; @@ -149,11 +132,6 @@ package org.apache.flex.html.beads.layouts var ilc:ILayoutChild; var data:Object; var canAdjust:Boolean = false; - var marginLeft:Object; - var marginRight:Object; - var marginTop:Object; - var marginBottom:Object; - var margin:Object; var paddingMetrics:Rectangle = CSSContainerUtils.getPaddingMetrics(host); var borderMetrics:Rectangle = CSSContainerUtils.getBorderMetrics(host); @@ -166,25 +144,12 @@ package org.apache.flex.html.beads.layouts { var child:IUIBase = contentView.getElementAt(i) as IUIBase; if (child == null || !child.visible) continue; - var top:Number = ValuesManager.valuesImpl.getValue(child, "top"); - var bottom:Number = ValuesManager.valuesImpl.getValue(child, "bottom"); - margin = ValuesManager.valuesImpl.getValue(child, "margin"); - marginLeft = ValuesManager.valuesImpl.getValue(child, "margin-left"); - marginTop = ValuesManager.valuesImpl.getValue(child, "margin-top"); - marginRight = ValuesManager.valuesImpl.getValue(child, "margin-right"); - marginBottom = ValuesManager.valuesImpl.getValue(child, "margin-bottom"); - var ml:Number = CSSUtils.getLeftValue(marginLeft, margin, hostWidth); - var mr:Number = CSSUtils.getRightValue(marginRight, margin, hostWidth); - var mt:Number = CSSUtils.getTopValue(marginTop, margin, hostHeight); - var mb:Number = CSSUtils.getBottomValue(marginBottom, margin, hostHeight); - if (marginLeft == "auto") - ml = 0; - if (marginRight == "auto") - mr = 0; + var positions:Object = childPositions(child); + var margins:Object = childMargins(child, hostWidth, hostHeight); ilc = child as ILayoutChild; - var childYpos:Number = ypos + mt; // default y position + var childYpos:Number = ypos + margins.top; // default y position if (!hostSizedToContent) { var childHeight:Number = child.height; @@ -193,7 +158,7 @@ package org.apache.flex.html.beads.layouts ilc.setHeight(childHeight); } // the following code middle-aligns the child - childYpos = hostHeight/2 - (childHeight + mt + mb)/2; + childYpos = hostHeight/2 - (childHeight + margins.top + margins.bottom)/2; } if (ilc) { @@ -203,11 +168,11 @@ package org.apache.flex.html.beads.layouts } if (i > 0) { - xpos -= child.width + mr; + xpos -= child.width + margins.right; adjustedWidth = child.width; } else { - adjustedWidth = xpos - (borderMetrics.left + paddingMetrics.left + ml + mr); - xpos = borderMetrics.left + paddingMetrics.left + ml; + adjustedWidth = xpos - (borderMetrics.left + paddingMetrics.left + margins.left + margins.right); + xpos = borderMetrics.left + paddingMetrics.left + margins.left; } if (ilc) { @@ -221,17 +186,16 @@ package org.apache.flex.html.beads.layouts child.width = adjustedWidth; } - xpos -= ml; + xpos -= margins.left; } return true; } COMPILE::JS - public function layout():Boolean + override public function layout():Boolean { - var viewBead:ILayoutHost = (host as ILayoutParent).getLayoutHost(); - var contentView:ILayoutView = viewBead.contentView; + var contentView:ILayoutView = layoutView; // set the display on the contentView contentView.element.style["display"] = "flex"; http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/4f0765d0/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/HorizontalFlexLayout.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/HorizontalFlexLayout.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/HorizontalFlexLayout.as index 473bfe3..eb30512 100644 --- a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/HorizontalFlexLayout.as +++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/HorizontalFlexLayout.as @@ -18,7 +18,7 @@ //////////////////////////////////////////////////////////////////////////////// package org.apache.flex.html.beads.layouts { - import org.apache.flex.html.beads.layouts.HorizontalLayout; +// import org.apache.flex.html.beads.layouts.HorizontalLayout; import org.apache.flex.core.ILayoutChild; import org.apache.flex.core.ILayoutHost; @@ -53,17 +53,6 @@ package org.apache.flex.html.beads.layouts super(); } - // the strand/host container is also an ILayoutChild because - // can have its size dictated by the host's parent which is - // important to know for layout optimization - private var host:ILayoutChild; - - override public function set strand(value:IStrand):void - { - super.strand = value; - host = value as ILayoutChild; - } - private var _grow:Number = -1; /** @@ -115,10 +104,7 @@ package org.apache.flex.html.beads.layouts override public function layout():Boolean { COMPILE::SWF { - //return super.layout(); - // this is where the layout is calculated - var layoutHost:ILayoutHost = (host as ILayoutParent).getLayoutHost(); - var contentView:ILayoutView = layoutHost.contentView; + var contentView:ILayoutView = layoutView; var n:Number = contentView.numElements; if (n == 0) return false; @@ -134,11 +120,6 @@ package org.apache.flex.html.beads.layouts var ilc:ILayoutChild; var data:Object; var canAdjust:Boolean = false; - var marginLeft:Object; - var marginRight:Object; - var marginTop:Object; - var marginBottom:Object; - var margin:Object; //trace("HorizontalFlexLayout for "+UIBase(host).id+" with remainingWidth: "+remainingWidth); @@ -177,24 +158,14 @@ package org.apache.flex.html.beads.layouts } if (growValue == 0 && useWidth > 0) remainingWidth -= useWidth; - margin = ValuesManager.valuesImpl.getValue(child, "margin"); - marginLeft = ValuesManager.valuesImpl.getValue(child, "margin-left"); - marginTop = ValuesManager.valuesImpl.getValue(child, "margin-top"); - marginRight = ValuesManager.valuesImpl.getValue(child, "margin-right"); - marginBottom = ValuesManager.valuesImpl.getValue(child, "margin-bottom"); - var ml:Number = CSSUtils.getLeftValue(marginLeft, margin, contentView.width); - var mr:Number = CSSUtils.getRightValue(marginRight, margin, contentView.width); - var mt:Number = CSSUtils.getTopValue(marginTop, margin, contentView.height); - var mb:Number = CSSUtils.getBottomValue(marginBottom, margin, contentView.height); - if (marginLeft == "auto") - ml = 0; - if (marginRight == "auto") - mr = 0; + var margins:Object = childMargins(child, contentView.width, contentView.height); if (maxWidth < useWidth) maxWidth = useWidth; if (maxHeight < useHeight) maxHeight = useHeight; - childData.push({width:useWidth, height:useHeight, mt:mt, ml:ml, mr:mr, mb:mb, grow:growValue, canAdjust:canAdjust}); + childData.push({width:useWidth, height:useHeight, + mt:margins.top, ml:margins.left, mr:margins.right, mb:margins.bottom, + grow:growValue, canAdjust:canAdjust}); } var xpos:Number = 0; @@ -250,8 +221,7 @@ package org.apache.flex.html.beads.layouts } COMPILE::JS { - var viewBead:ILayoutHost = (host as ILayoutParent).getLayoutHost(); - var contentView:ILayoutView = viewBead.contentView; + var contentView:ILayoutView = layoutView; // set the display on the contentView contentView.element.style["display"] = "flex"; http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/4f0765d0/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/HorizontalFlowLayout.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/HorizontalFlowLayout.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/HorizontalFlowLayout.as index 8209278..84484cb 100644 --- a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/HorizontalFlowLayout.as +++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/HorizontalFlowLayout.as @@ -18,6 +18,7 @@ //////////////////////////////////////////////////////////////////////////////// package org.apache.flex.html.beads.layouts { + import org.apache.flex.core.LayoutBase; import org.apache.flex.core.IBeadLayout; import org.apache.flex.core.ILayoutHost; import org.apache.flex.core.ILayoutParent; @@ -44,7 +45,7 @@ package org.apache.flex.html.beads.layouts * @playerversion AIR 2.6 * @productversion FlexJS 0.0 */ - public class HorizontalFlowLayout implements IBeadLayout + public class HorizontalFlowLayout extends LayoutBase implements IBeadLayout { /** * constructor. @@ -56,21 +57,7 @@ package org.apache.flex.html.beads.layouts */ public function HorizontalFlowLayout() { - } - - private var _strand:IStrand; - - /** - * @copy org.apache.flex.core.IBead#strand - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public function set strand(value:IStrand):void - { - _strand = value; + super(); } private var _defaultColumnCount:Number = 4; @@ -174,14 +161,11 @@ package org.apache.flex.html.beads.layouts /** * @copy org.apache.flex.core.IBeadLayout#layout */ - public function layout():Boolean + override public function layout():Boolean { COMPILE::SWF { - // this is where the layout is calculated - var host:UIBase = _strand as UIBase; - var p:ILayoutHost = (host as ILayoutParent).getLayoutHost(); - var area:UIBase = p.contentView as UIBase; + var area:UIBase = layoutView as UIBase; var n:Number = area.numElements; if (n == 0) return false; @@ -239,9 +223,8 @@ package org.apache.flex.html.beads.layouts var useWidth:Number; var useHeight:Number; - var host:UIBase = _strand as UIBase; - var viewBead:ILayoutHost = (host as ILayoutParent).getLayoutHost(); - var area:IParentIUIBase = viewBead.contentView as IParentIUIBase; + var area:IParentIUIBase = layoutView as IParentIUIBase; + children = area.internalChildren(); n = children.length; if (n === 0) return false; http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/4f0765d0/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/HorizontalLayout.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/HorizontalLayout.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/HorizontalLayout.as index 44f60bd..b58497a 100644 --- a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/HorizontalLayout.as +++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/HorizontalLayout.as @@ -18,6 +18,8 @@ //////////////////////////////////////////////////////////////////////////////// package org.apache.flex.html.beads.layouts { + import org.apache.flex.core.LayoutBase; + import org.apache.flex.core.IBeadLayout; import org.apache.flex.core.IBeadModel; import org.apache.flex.core.ILayoutChild; @@ -51,7 +53,7 @@ package org.apache.flex.html.beads.layouts * @playerversion AIR 2.6 * @productversion FlexJS 0.0 */ - public class HorizontalLayout implements IBeadLayout + public class HorizontalLayout extends LayoutBase implements IBeadLayout { /** * Constructor. @@ -63,13 +65,9 @@ package org.apache.flex.html.beads.layouts */ public function HorizontalLayout() { + super(); } - // the strand/host container is also an ILayoutChild because - // can have its size dictated by the host's parent which is - // important to know for layout optimization - private var host:ILayoutChild; - /** * @copy org.apache.flex.core.IBead#strand * @@ -80,9 +78,10 @@ package org.apache.flex.html.beads.layouts * @flexjsignorecoercion HTMLElement * @flexjsignorecoercion org.apache.flex.core.IUIBase */ - public function set strand(value:IStrand):void + override public function set strand(value:IStrand):void { - host = value as ILayoutChild; + super.strand = value; + COMPILE::JS { var base:IUIBase = value as IUIBase; @@ -97,12 +96,11 @@ package org.apache.flex.html.beads.layouts * @flexjsignorecoercion org.apache.flex.core.ILayoutHost * @flexjsignorecoercion org.apache.flex.core.WrappedHTMLElement */ - public function layout():Boolean + override public function layout():Boolean { COMPILE::SWF { - var layoutHost:ILayoutHost = (host as ILayoutParent).getLayoutHost(); - var contentView:ILayoutView = layoutHost.contentView; + var contentView:ILayoutView = layoutView; var n:Number = contentView.numElements; if (n == 0) return false; @@ -116,11 +114,6 @@ package org.apache.flex.html.beads.layouts var ilc:ILayoutChild; var data:Object; var canAdjust:Boolean = false; - var marginLeft:Object; - var marginRight:Object; - var marginTop:Object; - var marginBottom:Object; - var margin:Object; var paddingMetrics:Rectangle = CSSContainerUtils.getPaddingMetrics(host); var borderMetrics:Rectangle = CSSContainerUtils.getBorderMetrics(host); @@ -133,33 +126,20 @@ package org.apache.flex.html.beads.layouts { var child:IUIBase = contentView.getElementAt(i) as IUIBase; if (child == null || !child.visible) continue; - var top:Number = ValuesManager.valuesImpl.getValue(child, "top"); - var bottom:Number = ValuesManager.valuesImpl.getValue(child, "bottom"); - margin = ValuesManager.valuesImpl.getValue(child, "margin"); - marginLeft = ValuesManager.valuesImpl.getValue(child, "margin-left"); - marginTop = ValuesManager.valuesImpl.getValue(child, "margin-top"); - marginRight = ValuesManager.valuesImpl.getValue(child, "margin-right"); - marginBottom = ValuesManager.valuesImpl.getValue(child, "margin-bottom"); - var ml:Number = CSSUtils.getLeftValue(marginLeft, margin, hostWidth); - var mr:Number = CSSUtils.getRightValue(marginRight, margin, hostWidth); - var mt:Number = CSSUtils.getTopValue(marginTop, margin, hostHeight); - var mb:Number = CSSUtils.getBottomValue(marginBottom, margin, hostHeight); - if (marginLeft == "auto") - ml = 0; - if (marginRight == "auto") - mr = 0; + var positions:Object = childPositions(child); + var margins:Object = childMargins(child, hostWidth, hostHeight); ilc = child as ILayoutChild; - xpos += ml; + xpos += margins.left; - var childYpos:Number = ypos + mt; // default y position + var childYpos:Number = ypos + margins.top; // default y position if (!hostSizedToContent) { var childHeight:Number = child.height; if (ilc != null && !isNaN(ilc.percentHeight)) { childHeight = (hostHeight-borderMetrics.top-borderMetrics.bottom-paddingMetrics.top-paddingMetrics.bottom) * ilc.percentHeight/100.0; - ilc.setHeight(childHeight - mt - mb); + ilc.setHeight(childHeight - margins.top - margins.bottom); } // the following code middle-aligns the child, but since HTML does not // do this normally, this code is commented. (Use HorizontalFlexLayout for @@ -173,7 +153,7 @@ package org.apache.flex.html.beads.layouts if (!isNaN(ilc.percentWidth)) { var newWidth:Number = (contentView.width-borderMetrics.left-borderMetrics.right-paddingMetrics.left-paddingMetrics.right) * ilc.percentWidth / 100; - ilc.setWidth(newWidth - mr - ml); + ilc.setWidth(newWidth - margins.right - margins.left); } } else { @@ -181,7 +161,7 @@ package org.apache.flex.html.beads.layouts child.y = childYpos; } - xpos += child.width + mr; + xpos += child.width + margins.right; } return true; @@ -192,9 +172,7 @@ package org.apache.flex.html.beads.layouts var children:Array; var i:int; var n:int; - - var viewBead:ILayoutHost = (host as ILayoutParent).getLayoutHost(); - var contentView:IParentIUIBase = viewBead.contentView as IParentIUIBase; + var contentView:IParentIUIBase = layoutView as IParentIUIBase; contentView.element.style["white-space"] = "nowrap"; http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/4f0765d0/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/OneFlexibleChildHorizontalLayout.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/OneFlexibleChildHorizontalLayout.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/OneFlexibleChildHorizontalLayout.as index c163807..5707428 100644 --- a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/OneFlexibleChildHorizontalLayout.as +++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/OneFlexibleChildHorizontalLayout.as @@ -18,6 +18,7 @@ //////////////////////////////////////////////////////////////////////////////// package org.apache.flex.html.beads.layouts { + import org.apache.flex.core.LayoutBase; import org.apache.flex.core.IDocument; import org.apache.flex.core.ILayoutChild; import org.apache.flex.core.ILayoutHost; @@ -46,7 +47,7 @@ package org.apache.flex.html.beads.layouts * @playerversion AIR 2.6 * @productversion FlexJS 0.0 */ - public class OneFlexibleChildHorizontalLayout implements IOneFlexibleChildLayout, IDocument + public class OneFlexibleChildHorizontalLayout extends LayoutBase implements IOneFlexibleChildLayout, IDocument { /** * Constructor. @@ -58,6 +59,7 @@ package org.apache.flex.html.beads.layouts */ public function OneFlexibleChildHorizontalLayout() { + super(); } @@ -65,11 +67,6 @@ package org.apache.flex.html.beads.layouts private var actualChild:ILayoutChild; - // the strand/host container is also an ILayoutChild because - // can have its size dictated by the host's parent which is - // important to know for layout optimization - private var host:ILayoutChild; - /** * @private * The document. @@ -97,19 +94,6 @@ package org.apache.flex.html.beads.layouts _flexibleChild = value; } - /** - * @copy org.apache.flex.core.IBead#strand - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public function set strand(value:IStrand):void - { - host = value as ILayoutChild; - } - private var _maxWidth:Number; /** @@ -160,10 +144,9 @@ package org.apache.flex.html.beads.layouts * @copy org.apache.flex.core.IBeadLayout#layout */ COMPILE::JS - public function layout():Boolean + override public function layout():Boolean { - var viewBead:ILayoutHost = (host as ILayoutParent).getLayoutHost(); - var contentView:ILayoutView = viewBead.contentView; + var contentView:ILayoutView = layoutView; actualChild = document[flexibleChild]; @@ -185,30 +168,9 @@ package org.apache.flex.html.beads.layouts } COMPILE::SWF - protected function childMargins(child:Object, hostWidth:Number, hostHeight:Number):Object - { - var margin:Object = ValuesManager.valuesImpl.getValue(child, "margin"); - var marginLeft:Object = ValuesManager.valuesImpl.getValue(child, "margin-left"); - var marginTop:Object = ValuesManager.valuesImpl.getValue(child, "margin-top"); - var marginRight:Object = ValuesManager.valuesImpl.getValue(child, "margin-right"); - var marginBottom:Object = ValuesManager.valuesImpl.getValue(child, "margin-bottom"); - var ml:Number = CSSUtils.getLeftValue(marginLeft, margin, hostWidth); - var mr:Number = CSSUtils.getRightValue(marginRight, margin, hostWidth); - var mt:Number = CSSUtils.getTopValue(marginTop, margin, hostHeight); - var mb:Number = CSSUtils.getBottomValue(marginBottom, margin, hostHeight); - if (marginLeft == "auto") - ml = 0; - if (marginRight == "auto") - mr = 0; - - return {left:ml, top:mt, right:mr, bottom:mb}; - } - - COMPILE::SWF - public function layout():Boolean + override public function layout():Boolean { - var layoutHost:ILayoutHost = (host as ILayoutParent).getLayoutHost(); - var contentView:ILayoutView = layoutHost.contentView; + var contentView:ILayoutView = layoutView; var actualChild:IUIBase = document.hasOwnProperty(flexibleChild) ? document[flexibleChild] : null; var n:Number = contentView.numElements; @@ -223,15 +185,6 @@ package org.apache.flex.html.beads.layouts var ilc:ILayoutChild; var data:Object; var canAdjust:Boolean = false; - 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 margins:Object; var paddingMetrics:Rectangle = CSSContainerUtils.getPaddingMetrics(host); http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/4f0765d0/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/OneFlexibleChildVerticalLayout.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/OneFlexibleChildVerticalLayout.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/OneFlexibleChildVerticalLayout.as index 21d9059..a183cad 100644 --- a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/OneFlexibleChildVerticalLayout.as +++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/OneFlexibleChildVerticalLayout.as @@ -18,6 +18,7 @@ //////////////////////////////////////////////////////////////////////////////// package org.apache.flex.html.beads.layouts { + import org.apache.flex.core.LayoutBase; import org.apache.flex.core.IDocument; import org.apache.flex.core.ILayoutChild; import org.apache.flex.core.ILayoutHost; @@ -47,7 +48,7 @@ package org.apache.flex.html.beads.layouts * @playerversion AIR 2.6 * @productversion FlexJS 0.0 */ - public class OneFlexibleChildVerticalLayout implements IOneFlexibleChildLayout, IDocument + public class OneFlexibleChildVerticalLayout extends LayoutBase implements IOneFlexibleChildLayout, IDocument { /** * Constructor. @@ -59,6 +60,7 @@ package org.apache.flex.html.beads.layouts */ public function OneFlexibleChildVerticalLayout() { + super(); } @@ -66,11 +68,6 @@ package org.apache.flex.html.beads.layouts private var actualChild:ILayoutChild; - // the strand/host container is also an ILayoutChild because - // can have its size dictated by the host's parent which is - // important to know for layout optimization - private var host:ILayoutChild; - /** * @private * The document. @@ -98,19 +95,6 @@ package org.apache.flex.html.beads.layouts _flexibleChild = value; } - /** - * @copy org.apache.flex.core.IBead#strand - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public function set strand(value:IStrand):void - { - host = value as ILayoutChild; - } - private var _maxWidth:Number; /** @@ -157,34 +141,13 @@ package org.apache.flex.html.beads.layouts _maxHeight = value; } - COMPILE::SWF - protected function childMargins(child:Object, hostWidth:Number, hostHeight:Number):Object - { - var margin:Object = ValuesManager.valuesImpl.getValue(child, "margin"); - var marginLeft:Object = ValuesManager.valuesImpl.getValue(child, "margin-left"); - var marginTop:Object = ValuesManager.valuesImpl.getValue(child, "margin-top"); - var marginRight:Object = ValuesManager.valuesImpl.getValue(child, "margin-right"); - var marginBottom:Object = ValuesManager.valuesImpl.getValue(child, "margin-bottom"); - var ml:Number = CSSUtils.getLeftValue(marginLeft, margin, hostWidth); - var mr:Number = CSSUtils.getRightValue(marginRight, margin, hostWidth); - var mt:Number = CSSUtils.getTopValue(marginTop, margin, hostHeight); - var mb:Number = CSSUtils.getBottomValue(marginBottom, margin, hostHeight); - if (marginLeft == "auto") - ml = 0; - if (marginRight == "auto") - mr = 0; - - return {left:ml, top:mt, right:mr, bottom:mb}; - } - /** * @copy org.apache.flex.core.IBeadLayout#layout */ COMPILE::JS - public function layout():Boolean + override public function layout():Boolean { - var viewBead:ILayoutHost = (host as ILayoutParent).getLayoutHost(); - var contentView:ILayoutView = viewBead.contentView; + var contentView:ILayoutView = layoutView; actualChild = document[flexibleChild]; @@ -206,10 +169,9 @@ package org.apache.flex.html.beads.layouts } COMPILE::SWF - public function layout():Boolean + override public function layout():Boolean { - var layoutHost:ILayoutHost = (host as ILayoutParent).getLayoutHost(); - var contentView:ILayoutView = layoutHost.contentView; + var contentView:ILayoutView = layoutView; var actualChild:IUIBase = document.hasOwnProperty(flexibleChild) ? document[flexibleChild] : null; var n:Number = contentView.numElements; @@ -224,15 +186,6 @@ package org.apache.flex.html.beads.layouts var ilc:ILayoutChild; var data:Object; var canAdjust:Boolean = false; - 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 margins:Object; var paddingMetrics:Rectangle = CSSContainerUtils.getPaddingMetrics(host); http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/4f0765d0/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/TileLayout.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/TileLayout.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/TileLayout.as index 8f3c265..773bc4f 100644 --- a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/TileLayout.as +++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/TileLayout.as @@ -18,6 +18,7 @@ //////////////////////////////////////////////////////////////////////////////// package org.apache.flex.html.beads.layouts { + import org.apache.flex.core.LayoutBase; import org.apache.flex.core.IBeadLayout; import org.apache.flex.core.ILayoutHost; import org.apache.flex.core.ILayoutView; @@ -41,7 +42,7 @@ package org.apache.flex.html.beads.layouts * @playerversion AIR 2.6 * @productversion FlexJS 0.0 */ - public class TileLayout implements IBeadLayout + public class TileLayout extends LayoutBase implements IBeadLayout { /** * constructor. @@ -53,21 +54,7 @@ package org.apache.flex.html.beads.layouts */ public function TileLayout() { - } - - private var _strand:IStrand; - - /** - * @copy org.apache.flex.core.IBead#strand - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public function set strand(value:IStrand):void - { - _strand = value; + super(); } private var _numColumns:Number = 4; @@ -132,14 +119,11 @@ package org.apache.flex.html.beads.layouts /** * @copy org.apache.flex.core.IBeadLayout#layout */ - public function layout():Boolean + override public function layout():Boolean { COMPILE::SWF { - // this is where the layout is calculated - var host:UIBase = _strand as UIBase; - var p:ILayoutHost = (host as ILayoutParent).getLayoutHost(); - var area:UIBase = p.contentView as UIBase; + var area:UIBase = layoutView as UIBase; var xpos:Number = 0; var ypos:Number = 0; @@ -207,9 +191,8 @@ package org.apache.flex.html.beads.layouts var useWidth:Number; var useHeight:Number; - var host:UIBase = _strand as UIBase; - var viewBead:ILayoutHost = (host as ILayoutParent).getLayoutHost(); - var contentView:IParentIUIBase = viewBead.contentView as IParentIUIBase; + var contentView:IParentIUIBase = layoutView as IParentIUIBase; + children = contentView.internalChildren(); n = children.length; if (n === 0) return false; http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/4f0765d0/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/VerticalColumnLayout.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/VerticalColumnLayout.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/VerticalColumnLayout.as index bac2dc8..e489d85 100644 --- a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/VerticalColumnLayout.as +++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/VerticalColumnLayout.as @@ -18,6 +18,7 @@ //////////////////////////////////////////////////////////////////////////////// package org.apache.flex.html.beads.layouts { + import org.apache.flex.core.LayoutBase; import org.apache.flex.core.IBeadLayout; import org.apache.flex.core.IContainer; import org.apache.flex.core.ILayoutHost; @@ -45,7 +46,7 @@ package org.apache.flex.html.beads.layouts * @playerversion AIR 2.6 * @productversion FlexJS 0.0 */ - public class VerticalColumnLayout implements IBeadLayout + public class VerticalColumnLayout extends LayoutBase implements IBeadLayout { /** * constructor @@ -57,21 +58,7 @@ package org.apache.flex.html.beads.layouts */ public function VerticalColumnLayout() { - } - - private var _strand:IStrand; - - /** - * @copy org.apache.flex.core.IBead#strand - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public function set strand(value:IStrand):void - { - _strand = value; + super(); } @@ -97,11 +84,10 @@ package org.apache.flex.html.beads.layouts /** * @copy org.apache.flex.core.IBeadLayout#layout */ - public function layout():Boolean + override public function layout():Boolean { - var host:UIBase = UIBase(_strand); - var layoutParent:ILayoutHost = (host as ILayoutParent).getLayoutHost(); - var contentView:ILayoutView = layoutParent.contentView; + var contentView:ILayoutView = layoutView; + var padding:Rectangle = CSSContainerUtils.getPaddingMetrics(host); var sw:Number = host.width; var sh:Number = host.height; @@ -117,15 +103,6 @@ package org.apache.flex.html.beads.layouts for (i = 0; i < numColumns; i++) columns[i] = 0; - 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 n:int = contentView.numElements; var rowData:Object = { rowHeight: 0 }; @@ -133,29 +110,22 @@ package org.apache.flex.html.beads.layouts for (i = 0; i < n; i++) { e = contentView.getElementAt(i) as IUIBase; if (e == null || !e.visible) continue; - margin = ValuesManager.valuesImpl.getValue(e, "margin"); - marginLeft = ValuesManager.valuesImpl.getValue(e, "margin-left"); - marginTop = ValuesManager.valuesImpl.getValue(e, "margin-top"); - marginRight = ValuesManager.valuesImpl.getValue(e, "margin-right"); - marginBottom = ValuesManager.valuesImpl.getValue(e, "margin-bottom"); - mt = CSSUtils.getTopValue(marginTop, margin, sh); - mb = CSSUtils.getBottomValue(marginBottom, margin, sh); - mr = CSSUtils.getRightValue(marginRight, margin, sw); - ml = CSSUtils.getLeftValue(marginLeft, margin, sw); - data.push({ mt: mt, mb: mb, mr: mr, ml: ml}); + var margins:Object = childMargins(e, sw, sh); + + data.push({ mt: margins.top, mb: margins.bottom, mr: margins.right, ml: margins.left}); var thisPrefWidth:int = 0; if (e is IStrand) { var measure:IMeasurementBead = e.getBeadByType(IMeasurementBead) as IMeasurementBead; if (measure) - thisPrefWidth = measure.measuredWidth + ml + mr; + thisPrefWidth = measure.measuredWidth + margins.left + margins.right; else - thisPrefWidth = e.width + ml + mr; + thisPrefWidth = e.width + margins.left + margins.right; } else - thisPrefWidth = e.width + ml + mr; + thisPrefWidth = e.width + margins.left + margins.right; - rowData.rowHeight = Math.max(rowData.rowHeight, e.height + mt + mb); + rowData.rowHeight = Math.max(rowData.rowHeight, e.height + margins.top + margins.bottom); columns[col] = Math.max(columns[col], thisPrefWidth); col = col + 1; if (col == numColumns) @@ -176,7 +146,7 @@ package org.apache.flex.html.beads.layouts { e = contentView.getElementAt(i) as IUIBase; if (e == null || !e.visible) continue; - e.x = curx + ml; + e.x = curx + data[i].ml; e.y = cury + data[i].mt; curx += columns[col++]; maxHeight = Math.max(maxHeight, e.y + e.height + data[i].mb); @@ -189,14 +159,6 @@ package org.apache.flex.html.beads.layouts curx = padding.left; } } - if (!hasWidth && n > 0 && !isNaN(maxWidth)) - { - UIBase(contentView).setWidth(maxWidth, true); - } - if (!hasHeight && n > 0 && !isNaN(maxHeight)) - { - UIBase(contentView).setHeight(maxHeight, true); - } return true; } } http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/4f0765d0/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/VerticalFlexLayout.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/VerticalFlexLayout.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/VerticalFlexLayout.as index e8d9a41..d98e300 100644 --- a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/VerticalFlexLayout.as +++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/VerticalFlexLayout.as @@ -18,7 +18,7 @@ //////////////////////////////////////////////////////////////////////////////// package org.apache.flex.html.beads.layouts { - import org.apache.flex.html.beads.layouts.VerticalLayout; + //import org.apache.flex.html.beads.layouts.VerticalLayout; import org.apache.flex.core.ILayoutChild; import org.apache.flex.core.ILayoutHost; @@ -53,17 +53,6 @@ package org.apache.flex.html.beads.layouts super(); } - // the strand/host container is also an ILayoutChild because - // can have its size dictated by the host's parent which is - // important to know for layout optimization - private var host:ILayoutChild; - - override public function set strand(value:IStrand):void - { - super.strand = value; - host = value as ILayoutChild; - } - private var _grow:Number = -1; /** @@ -115,7 +104,6 @@ package org.apache.flex.html.beads.layouts override public function layout():Boolean { COMPILE::SWF { - //return super.layout(); var layoutHost:ILayoutHost = (host as ILayoutParent).getLayoutHost(); var contentView:ILayoutView = layoutHost.contentView; @@ -133,11 +121,6 @@ package org.apache.flex.html.beads.layouts var ilc:ILayoutChild; var data:Object; var canAdjust:Boolean = false; - var marginLeft:Object; - var marginRight:Object; - var marginTop:Object; - var marginBottom:Object; - var margin:Object; //trace("VerticalFlexLayout for "+UIBase(host).id+" with remainingHeight: "+remainingHeight); @@ -176,24 +159,14 @@ package org.apache.flex.html.beads.layouts } if (growValue == 0 && useHeight > 0) remainingHeight -= useHeight; - margin = ValuesManager.valuesImpl.getValue(child, "margin"); - marginLeft = ValuesManager.valuesImpl.getValue(child, "margin-left"); - marginTop = ValuesManager.valuesImpl.getValue(child, "margin-top"); - marginRight = ValuesManager.valuesImpl.getValue(child, "margin-right"); - marginBottom = ValuesManager.valuesImpl.getValue(child, "margin-bottom"); - var ml:Number = CSSUtils.getLeftValue(marginLeft, margin, contentView.width); - var mr:Number = CSSUtils.getRightValue(marginRight, margin, contentView.width); - var mt:Number = CSSUtils.getTopValue(marginTop, margin, contentView.height); - var mb:Number = CSSUtils.getBottomValue(marginBottom, margin, contentView.height); - if (marginLeft == "auto") - ml = 0; - if (marginRight == "auto") - mr = 0; + var margins:Object = childMargins(child, contentView.width, contentView.height); if (maxWidth < useWidth) maxWidth = useWidth; if (maxHeight < useHeight) maxHeight = useHeight; - childData.push({width:useWidth, height:useHeight, mt:mt, ml:ml, mr:mr, mb:mb, grow:growValue, canAdjust:canAdjust}); + childData.push({width:useWidth, height:useHeight, + mt:margins.top, ml:margins.left, mr:margins.right, mb:margins.bottom, + grow:growValue, canAdjust:canAdjust}); } var xpos:Number = 0; @@ -249,8 +222,7 @@ package org.apache.flex.html.beads.layouts } COMPILE::JS { - var viewBead:ILayoutHost = (host as ILayoutParent).getLayoutHost(); - var contentView:ILayoutView = viewBead.contentView; + var contentView:ILayoutView = layoutView; contentView.element.style["display"] = "flex"; contentView.element.style["flex-flow"] = "column"; http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/4f0765d0/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/VerticalLayout.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/VerticalLayout.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/VerticalLayout.as index ca442d9..c4279a4 100644 --- a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/VerticalLayout.as +++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/VerticalLayout.as @@ -18,6 +18,8 @@ //////////////////////////////////////////////////////////////////////////////// package org.apache.flex.html.beads.layouts { + import org.apache.flex.core.LayoutBase; + import org.apache.flex.core.IBeadLayout; import org.apache.flex.core.IBeadModel; import org.apache.flex.core.ILayoutChild; @@ -49,7 +51,7 @@ package org.apache.flex.html.beads.layouts * @playerversion AIR 2.6 * @productversion FlexJS 0.0 */ - public class VerticalLayout implements IBeadLayout + public class VerticalLayout extends LayoutBase implements IBeadLayout { /** * Constructor. @@ -61,24 +63,7 @@ package org.apache.flex.html.beads.layouts */ public function VerticalLayout() { - } - - // the strand/host container is also an ILayoutChild because - // can have its size dictated by the host's parent which is - // important to know for layout optimization - private var host:ILayoutChild; - - /** - * @copy org.apache.flex.core.IBead#strand - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public function set strand(value:IStrand):void - { - host = value as ILayoutChild; + super(); } /** @@ -90,12 +75,11 @@ package org.apache.flex.html.beads.layouts * @productversion FlexJS 0.0 * @flexjsignorecoercion org.apache.flex.core.ILayoutHost */ - public function layout():Boolean + override public function layout():Boolean { COMPILE::SWF { - var layoutHost:ILayoutHost = (host as ILayoutParent).getLayoutHost(); - var contentView:ILayoutView = layoutHost.contentView; + var contentView:ILayoutView = layoutView; var n:Number = contentView.numElements; if (n == 0) return false; @@ -109,11 +93,6 @@ package org.apache.flex.html.beads.layouts var ilc:ILayoutChild; var data:Object; var canAdjust:Boolean = false; - var marginLeft:Object; - var marginRight:Object; - var marginTop:Object; - var marginBottom:Object; - var margin:Object; var paddingMetrics:Rectangle = CSSContainerUtils.getPaddingMetrics(host); var borderMetrics:Rectangle = CSSContainerUtils.getBorderMetrics(host); @@ -126,33 +105,20 @@ package org.apache.flex.html.beads.layouts { var child:IUIBase = contentView.getElementAt(i) as IUIBase; if (child == null || !child.visible) continue; - var top:Number = ValuesManager.valuesImpl.getValue(child, "top"); - var bottom:Number = ValuesManager.valuesImpl.getValue(child, "bottom"); - margin = ValuesManager.valuesImpl.getValue(child, "margin"); - marginLeft = ValuesManager.valuesImpl.getValue(child, "margin-left"); - marginTop = ValuesManager.valuesImpl.getValue(child, "margin-top"); - marginRight = ValuesManager.valuesImpl.getValue(child, "margin-right"); - marginBottom = ValuesManager.valuesImpl.getValue(child, "margin-bottom"); - var ml:Number = CSSUtils.getLeftValue(marginLeft, margin, hostWidth); - var mr:Number = CSSUtils.getRightValue(marginRight, margin, hostWidth); - var mt:Number = CSSUtils.getTopValue(marginTop, margin, hostHeight); - var mb:Number = CSSUtils.getBottomValue(marginBottom, margin, hostHeight); - if (marginLeft == "auto") - ml = 0; - if (marginRight == "auto") - mr = 0; + var positions:Object = childPositions(child); + var margins:Object = childMargins(child, hostWidth, hostHeight); ilc = child as ILayoutChild; - ypos += mt; + ypos += margins.top; - var childXpos:Number = xpos + ml; // default x position + var childXpos:Number = xpos + margins.left; // default x position if (!hostSizedToContent) { var childWidth:Number = child.width; if (ilc != null && !isNaN(ilc.percentWidth)) { childWidth = (hostWidth-borderMetrics.left-borderMetrics.right-paddingMetrics.left-paddingMetrics.right) * ilc.percentWidth/100.0; - ilc.setWidth(childWidth - mr - ml); + ilc.setWidth(childWidth - margins.right - margins.left); } // the following code center-aligns the child, but since HTML does not // do this normally, this code is commented. (Use VerticalFlexLayout for @@ -166,7 +132,7 @@ package org.apache.flex.html.beads.layouts if (!isNaN(ilc.percentHeight)) { var newHeight:Number = (contentView.height-borderMetrics.top-borderMetrics.bottom-paddingMetrics.top-paddingMetrics.bottom) * ilc.percentHeight / 100; - ilc.setHeight(newHeight - mt - mb); + ilc.setHeight(newHeight - margins.top - margins.bottom); } } else { @@ -174,7 +140,7 @@ package org.apache.flex.html.beads.layouts child.y = ypos; } - ypos += child.height + mb; + ypos += child.height + margins.bottom; } return true; @@ -184,9 +150,8 @@ package org.apache.flex.html.beads.layouts var children:Array; var i:int; var n:int; - - var viewBead:ILayoutHost = (host as ILayoutParent).getLayoutHost(); - var contentView:IParentIUIBase = viewBead.contentView as IParentIUIBase; + var contentView:IParentIUIBase = layoutView as IParentIUIBase; + children = contentView.internalChildren(); n = children.length; for (i = 0; i < n; i++)