Repository: flex-asjs Updated Branches: refs/heads/develop 79d45cba0 -> 6436eff40
Updated BasicLayout for SWF platform. Fixed UIButtonBase to behave like UIBase when it sets x and y position. Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/6436eff4 Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/6436eff4 Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/6436eff4 Branch: refs/heads/develop Commit: 6436eff401412ab9fc1d35637a1fc07bc488ff6a Parents: 79d45cb Author: Peter Ent <[email protected]> Authored: Mon Mar 6 16:25:08 2017 -0500 Committer: Peter Ent <[email protected]> Committed: Mon Mar 6 16:25:08 2017 -0500 ---------------------------------------------------------------------- .../flex/org/apache/flex/core/UIButtonBase.as | 28 +- .../flex/html/beads/layouts/BasicLayout.as | 342 +++++-------------- 2 files changed, 100 insertions(+), 270 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/6436eff4/frameworks/projects/HTML/src/main/flex/org/apache/flex/core/UIButtonBase.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/core/UIButtonBase.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/core/UIButtonBase.as index 85fc0fd..ef5c9a1 100644 --- a/frameworks/projects/HTML/src/main/flex/org/apache/flex/core/UIButtonBase.as +++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/core/UIButtonBase.as @@ -98,14 +98,12 @@ package org.apache.flex.core */ override public function set x(value:Number):void { - if (_button.x != value) { - _button.x = _x = value; - if (!style) - style = { left: value }; - else - style.left = value; - dispatchEvent(new Event("xChanged")); - } + _button.x = _x = value; + if (!style) + style = { left: value }; + else + style.left = value; + dispatchEvent(new Event("xChanged")); } private var _y:Number; @@ -115,14 +113,12 @@ package org.apache.flex.core */ override public function set y(value:Number):void { - if (_button.y != value) { - _button.y = _y = value; - if (!style) - style = { top: value }; - else - style.top = value; - dispatchEvent(new Event("yChanged")); - } + _button.y = _y = value; + if (!style) + style = { top: value }; + else + style.top = value; + dispatchEvent(new Event("yChanged")); } /** http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/6436eff4/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 3a7293e..f937e34 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 @@ -31,7 +31,6 @@ package org.apache.flex.html.beads.layouts import org.apache.flex.events.Event; import org.apache.flex.events.IEventDispatcher; import org.apache.flex.utils.CSSUtils; - //import org.apache.flex.utils.dbg.DOMPathUtil; /** * The BasicLayout class is a simple layout @@ -85,9 +84,16 @@ package org.apache.flex.html.beads.layouts { COMPILE::SWF { - //trace(DOMPathUtil.getPath(host), event ? event.type : "fixed size"); - var layoutParent:ILayoutHost = (host as ILayoutParent).getLayoutHost(); - var contentView:IParentIUIBase = layoutParent ? layoutParent.contentView : IParentIUIBase(host); + var viewBead:ILayoutHost = (host as ILayoutParent).getLayoutHost(); + var contentView:IParentIUIBase = viewBead.contentView; + + var hostWidthSizedToContent:Boolean = host.isWidthSizedToContent(); + var hostHeightSizedToContent:Boolean = host.isHeightSizedToContent(); + + var w:Number = hostWidthSizedToContent ? 0 : contentView.width; + var h:Number = hostHeightSizedToContent ? 0 : contentView.height; + + var n:int = contentView.numElements; var gotMargin:Boolean; var marginLeft:Object; @@ -95,278 +101,106 @@ package org.apache.flex.html.beads.layouts 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; - var h:Number = hostHeightSizedToContent ? 0 : contentView.height; - var n:int = contentView.numElements; - var maxWidth:Number = 0; - var maxHeight:Number = 0; - var childData:Array = []; + 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 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 (ilc) - ilc.setX(left); + ilc.setX(left+ml); else - child.x = left; - ww -= left; + child.x = left+ml; + ww -= left + ml; } + + // set the left edge of the child if (!isNaN(top)) { if (ilc) - ilc.setY(top); - else - child.y = top; - hh -= top; - } - if (ilc) - { - if (!hostWidthSizedToContent) - { - if (!isNaN(ilc.percentWidth)) - ilc.setWidth((ww - (isNaN(right) ? 0 : right)) * ilc.percentWidth / 100, true); - } - else - childData[i] = { bottom: bottom, right: right, ww: ww, ilc: ilc, child: child }; - } - if (!isNaN(right)) - { - if (!hostWidthSizedToContent) - { - if (!isNaN(left)) - { - if (ilc) - ilc.setWidth(ww - right, true); - else - child.width = ww - right; - } - else - { - 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.getBottomValue(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) - { - if (!isNaN(ilc.percentHeight)) - ilc.setHeight((hh - (isNaN(bottom) ? 0 : bottom)) * ilc.percentHeight / 100, true); - } + ilc.setY(top+mt); else - { - if (!childData[i]) - childData[i] = { hh: hh, bottom: bottom, ilc: ilc, child: child }; - else - { - childData[i].hh = hh; - childData[i].bottom = bottom; - } - } - } - if (!isNaN(bottom)) - { - if (!hostHeightSizedToContent) - { - if (!isNaN(top)) - { - if (ilc) - ilc.setHeight(hh - bottom, true); - else - child.height = hh - bottom; - } - else - { - if (ilc) - ilc.setY(h - bottom - child.height); - else - child.y = h - bottom - child.height; - } - } - else - { - if (!childData[i]) - childData[i] = { top: top, bottom: bottom, hh:hh, ilc: ilc, child: child }; - else - { - childData[i].top = top; - childData[i].bottom = bottom; - childData[i].hh = hh; - } - } - } - if (!childData[i]) - child.dispatchEvent(new Event("sizeChanged")); - maxWidth = Math.max(maxWidth, child.x + child.width); - maxHeight = Math.max(maxHeight, child.y + child.height); - } - if (hostHeightSizedToContent || hostWidthSizedToContent) - { - for (i = 0; i < n; i++) - { - var data:Object = childData[i]; - if (data) - { - if (hostWidthSizedToContent) - { - if (data.ilc && !isNaN(data.ilc.percentWidth)) - data.ilc.setWidth((data.ww - (isNaN(data.right) ? 0 : data.right)) * data.ilc.percentWidth / 100, true); - 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)) - { - if (data.ilc) - data.ilc.setWidth(data.ww - data.right, true); - else - data.child.width = data.ww - data.right; - } - else - { - if (data.ilc) - data.ilc.setX(maxWidth - data.right - data.child.width); - else - data.child.x = maxWidth - data.right - data.child.width; - } - } - } - if (hostHeightSizedToContent) - { - if (data.ilc && !isNaN(data.ilc.percentHeight)) - data.ilc.setHeight((data.hh - (isNaN(data.bottom) ? 0 : data.bottom)) * data.ilc.percentHeight / 100, true); - if (!isNaN(data.bottom)) - { - if (!isNaN(data.top)) - { - if (data.ilc) - data.ilc.setHeight(data.hh - data.bottom, true); - else - data.child.height = data.hh - data.bottom; - } - else - { - 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")); - } + child.y = top+mt; + hh -= top + mt; } + + // set the right edge of the child + if (!isNaN(right)) + { + if (!hostWidthSizedToContent) + { + if (!isNaN(left)) + { + if (ilc) + ilc.setWidth(ww - right - mr, false); + else + child.width = ww - right - mr; + } + else + { + if (ilc) + ilc.setX( w - right - mr - child.width - mr); + else + child.x = w - right - mr - child.width - mr; + } + } + } + else if (ilc != null && !isNaN(ilc.percentWidth) && !hostWidthSizedToContent) + { + ilc.setWidth((ww - mr - ml) * ilc.percentWidth/100, false); + } + + // set the bottm edge of the child + if (!isNaN(bottom)) + { + if (!hostHeightSizedToContent) + { + if (!isNaN(top)) + { + if (ilc) + ilc.setHeight(hh - bottom - mb, false); + else + child.height = hh - bottom - mb; + } + else + { + if (ilc) + ilc.setY( h - bottom - child.height - mb); + else + child.y = h - bottom - child.height - mb; + } + } + } + else if (ilc != null && !isNaN(ilc.percentHeight) && !hostHeightSizedToContent) + { + ilc.setHeight((hh - mt - mb) * ilc.percentHeight/100, false); + } } host.dispatchEvent( new Event("layoutComplete") );
