This is an automated email from the ASF dual-hosted git repository. aharui pushed a commit to branch develop in repository https://gitbox.apache.org/repos/asf/royale-asjs.git
commit 506bfe69a2b134fe757ccca77b6caef693b32c85 Author: Alex Harui <aha...@apache.org> AuthorDate: Sun Mar 15 10:19:47 2020 -0700 optimize for fewer DG layout passes --- .../org/apache/royale/html/beads/DataGridView.as | 45 ++++++++- .../royale/html/beads/layouts/DataGridLayout.as | 10 +- .../org/apache/royale/charts/beads/ChartView.as | 3 +- .../org/apache/royale/utils/MockLayoutHost.as | 4 +- .../org/apache/royale/utils/MockLayoutParent.as | 3 +- .../MXRoyale/src/main/resources/defaults.css | 7 +- .../MXRoyale/src/main/royale/MXRoyaleClasses.as | 2 + .../beads/AdvancedDataGridHeaderLayout.as | 18 +++- .../mx/containers/beads/PanelInternalContainer.as} | 52 ++++++----- .../containers/beads/PanelInternalContainerView.as | 101 +++++++++++++++++++++ .../main/royale/mx/containers/beads/PanelView.as | 34 ++++++- 11 files changed, 241 insertions(+), 38 deletions(-) diff --git a/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/beads/DataGridView.as b/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/beads/DataGridView.as index 9ee56e7..ff5120f 100644 --- a/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/beads/DataGridView.as +++ b/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/beads/DataGridView.as @@ -28,6 +28,7 @@ package org.apache.royale.html.beads import org.apache.royale.core.IDataGridModel; import org.apache.royale.core.IDataGridPresentationModel; import org.apache.royale.core.IParent; + import org.apache.royale.core.IStrand; import org.apache.royale.core.IUIBase; import org.apache.royale.core.ValuesManager; import org.apache.royale.debugging.assert; @@ -67,6 +68,17 @@ package org.apache.royale.html.beads super(); } + /** + * @royaleignorecoercion org.apache.royale.events.IEventDispatcher + */ + override public function set strand(value:IStrand):void + { + super.strand = value; + host.addEventListener("widthChanged", handleSizeChanges); + host.addEventListener("heightChanged", handleSizeChanges); + host.addEventListener("sizeChanged", handleSizeChanges); + } + private var _header:DataGridButtonBar; private var _listArea:IUIBase; @@ -102,6 +114,8 @@ package org.apache.royale.html.beads handleInitComplete(null); } + private var sawInitComplete:Boolean; + /** * @private * @royaleignorecoercion org.apache.royale.core.IDataGridModel @@ -115,6 +129,8 @@ package org.apache.royale.html.beads */ override protected function handleInitComplete(event:Event):void { + sawInitComplete = event != null; + var host:IDataGrid = _strand as IDataGrid; // see if there is a presentation model already in place. if not, add one. @@ -150,18 +166,21 @@ package org.apache.royale.html.beads handleDataProviderChanged(event); - host.addEventListener("widthChanged", handleSizeChanges); - host.addEventListener("heightChanged", handleSizeChanges); sendStrandEvent(_strand,"dataGridViewCreated"); } + private var sawSizeChanged:Boolean; + /** * @private */ private function handleSizeChanges(event:Event):void { - sendEvent(_header,"layoutChanged"); - sendEvent(_listArea,"layoutChanged"); + sawSizeChanged = true; + if (_header) + sendEvent(_header,"layoutChanged"); + if (_listArea) + sendEvent(_listArea,"layoutChanged"); } /** @@ -273,6 +292,24 @@ package org.apache.royale.html.beads sendStrandEvent(_strand,"layoutNeeded"); } + + /** + * Provides a place for pre-layout actions. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion Royale 0.8 + */ + override public function beforeLayout():Boolean + { + var host:ILayoutChild = _strand as ILayoutChild; + if (host.isWidthSizedToContent() && host.isHeightSizedToContent()) + return sawInitComplete; + return sawSizeChanged; + } + + } } diff --git a/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/beads/layouts/DataGridLayout.as b/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/beads/layouts/DataGridLayout.as index be56f19..d5af909 100644 --- a/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/beads/layouts/DataGridLayout.as +++ b/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/beads/layouts/DataGridLayout.as @@ -23,6 +23,7 @@ package org.apache.royale.html.beads.layouts import org.apache.royale.core.IBeadView; import org.apache.royale.core.IBorderPaddingMarginValuesImpl; import org.apache.royale.core.IDataGridModel; + import org.apache.royale.core.ILayoutHost; import org.apache.royale.core.IStrand; import org.apache.royale.core.IUIBase; import org.apache.royale.core.UIBase; @@ -91,12 +92,16 @@ package org.apache.royale.html.beads.layouts private function handleSizeChanges(event:Event):void { - layout(); + var viewBead:ILayoutHost = uiHost.view as ILayoutHost; + if (viewBead.beforeLayout()) + layout(); } private function handleLayoutNeeded(event:Event):void { - layout(); + var viewBead:ILayoutHost = uiHost.view as ILayoutHost; + if (viewBead.beforeLayout()) + layout(); } protected function getColumnsForLayout():Array @@ -123,6 +128,7 @@ package org.apache.royale.html.beads.layouts * @copy org.apache.royale.core.IBeadLayout#layout * @royaleignorecoercion org.apache.royale.core.IBorderPaddingMarginValuesImpl * @royaleignorecoercion org.apache.royale.core.IDataGridModel + * @royaleignorecoercion org.apache.royale.core.ILayoutHost * @royaleignorecoercion org.apache.royale.core.IUIBase * @royaleignorecoercion org.apache.royale.core.UIBase * @royaleignorecoercion org.apache.royale.html.beads.IDataGridView diff --git a/frameworks/projects/Charts/src/main/royale/org/apache/royale/charts/beads/ChartView.as b/frameworks/projects/Charts/src/main/royale/org/apache/royale/charts/beads/ChartView.as index 9ebec7c..9921d4e 100644 --- a/frameworks/projects/Charts/src/main/royale/org/apache/royale/charts/beads/ChartView.as +++ b/frameworks/projects/Charts/src/main/royale/org/apache/royale/charts/beads/ChartView.as @@ -172,7 +172,7 @@ package org.apache.royale.charts.beads * @productversion Royale 0.0 * @royaleignorecoercion org.apache.royale.core.IBorderPaddingMarginValuesImpl */ - override public function beforeLayout():void + override public function beforeLayout():Boolean { var metrics:EdgeData = (ValuesManager.valuesImpl as IBorderPaddingMarginValuesImpl).getBorderAndPaddingMetrics(_strand as IUIBase); @@ -216,6 +216,7 @@ package org.apache.royale.charts.beads UIBase(horizontalAxisGroup).width = strandWidth - widthAdjustment - metrics.left - metrics.right; UIBase(horizontalAxisGroup).height = heightAdjustment; } + return true; } /** diff --git a/frameworks/projects/Effects/src/main/royale/org/apache/royale/utils/MockLayoutHost.as b/frameworks/projects/Effects/src/main/royale/org/apache/royale/utils/MockLayoutHost.as index 8577659..2dbf228 100644 --- a/frameworks/projects/Effects/src/main/royale/org/apache/royale/utils/MockLayoutHost.as +++ b/frameworks/projects/Effects/src/main/royale/org/apache/royale/utils/MockLayoutHost.as @@ -34,9 +34,9 @@ package org.apache.royale.utils return _contentView; } - public function beforeLayout():void + public function beforeLayout():Boolean { - + return true; } public function afterLayout():void diff --git a/frameworks/projects/Effects/src/main/royale/org/apache/royale/utils/MockLayoutParent.as b/frameworks/projects/Effects/src/main/royale/org/apache/royale/utils/MockLayoutParent.as index 8c26ed2..149190f 100644 --- a/frameworks/projects/Effects/src/main/royale/org/apache/royale/utils/MockLayoutParent.as +++ b/frameworks/projects/Effects/src/main/royale/org/apache/royale/utils/MockLayoutParent.as @@ -50,9 +50,10 @@ package org.apache.royale.utils _source = source; } - public function beforeLayout():void + public function beforeLayout():Boolean { // TODO ?? + return true; } public function afterLayout():void diff --git a/frameworks/projects/MXRoyale/src/main/resources/defaults.css b/frameworks/projects/MXRoyale/src/main/resources/defaults.css index 3abd24c..c0c8494 100644 --- a/frameworks/projects/MXRoyale/src/main/resources/defaults.css +++ b/frameworks/projects/MXRoyale/src/main/resources/defaults.css @@ -262,6 +262,11 @@ containerBeads|FormItemContainer IViewport: ClassReference("org.apache.royale.html.supportClasses.Viewport"); } +containerBeads|PanelInternalContainer +{ + IBeadView: ClassReference("mx.containers.beads.PanelInternalContainerView"); +} + Image { IBeadModel: ClassReference("org.apache.royale.html.beads.models.ImageModel"); @@ -372,7 +377,7 @@ Panel IBeadModel: ClassReference("mx.containers.beads.models.PanelModel"); IBeadView: ClassReference("mx.containers.beads.PanelView"); IPanelLayout: ClassReference("mx.containers.beads.BoxLayout"); - IPanelContentArea: ClassReference("mx.core.Container"); + IPanelContentArea: ClassReference("mx.containers.beads.PanelInternalContainer"); background-color: #FFFFFF; border-width: 1px; border: 1px solid #333333; diff --git a/frameworks/projects/MXRoyale/src/main/royale/MXRoyaleClasses.as b/frameworks/projects/MXRoyale/src/main/royale/MXRoyaleClasses.as index 69857b8..3213775 100644 --- a/frameworks/projects/MXRoyale/src/main/royale/MXRoyaleClasses.as +++ b/frameworks/projects/MXRoyale/src/main/royale/MXRoyaleClasses.as @@ -57,6 +57,8 @@ internal class MXRoyaleClasses import mx.containers.beads.DividedBoxLayout; DividedBoxLayout; import mx.containers.beads.CanvasLayout; CanvasLayout; import mx.containers.beads.layouts.BasicLayout; BasicLayout; + import mx.containers.beads.PanelInternalContainer; PanelInternalContainer; + import mx.containers.beads.PanelInternalContainerView; PanelInternalContainerView; import mx.controls.beads.AlertView; AlertView; import mx.controls.beads.controllers.AlertMouseController; AlertMouseController; import mx.containers.errors.ConstraintError; ConstraintError; diff --git a/frameworks/projects/MXRoyale/src/main/royale/mx/containers/beads/AdvancedDataGridHeaderLayout.as b/frameworks/projects/MXRoyale/src/main/royale/mx/containers/beads/AdvancedDataGridHeaderLayout.as index d78955b..6349291 100644 --- a/frameworks/projects/MXRoyale/src/main/royale/mx/containers/beads/AdvancedDataGridHeaderLayout.as +++ b/frameworks/projects/MXRoyale/src/main/royale/mx/containers/beads/AdvancedDataGridHeaderLayout.as @@ -30,7 +30,9 @@ package mx.containers.beads import org.apache.royale.core.ILayoutView; import org.apache.royale.core.IStyleableObject; import org.apache.royale.core.IStrand; + import org.apache.royale.core.IStrandWithModel; import org.apache.royale.html.beads.models.ButtonBarModel; + import org.apache.royale.events.Event; /* import mx.core.mx_internal; @@ -78,11 +80,21 @@ public class AdvancedDataGridHeaderLayout extends LayoutBase private var _strand:IStrand; + /** + * @royaleignorecoercion org.apache.royale.core.IStrandWithModel + */ override public function set strand(value:IStrand):void { _strand = value; super.strand = value; - + (host as IStrandWithModel).model.addEventListener("dataProviderChanged", dataProviderChangedHandler); + } + + private var sawDPChanged:Boolean; + + private function dataProviderChangedHandler(event:Event):void + { + sawDPChanged = true; } private var _buttonWidths:Array = null; @@ -114,6 +126,10 @@ public class AdvancedDataGridHeaderLayout extends LayoutBase override public function layout():Boolean { + // ignore other lifecycle layouts until the DP is set + if (!sawDPChanged) + return true; + var contentView:ILayoutView = layoutView; var model:ButtonBarModel = (host as IStrand).getBeadByType(ButtonBarModel) as ButtonBarModel; diff --git a/frameworks/projects/Effects/src/main/royale/org/apache/royale/utils/MockLayoutHost.as b/frameworks/projects/MXRoyale/src/main/royale/mx/containers/beads/PanelInternalContainer.as similarity index 62% copy from frameworks/projects/Effects/src/main/royale/org/apache/royale/utils/MockLayoutHost.as copy to frameworks/projects/MXRoyale/src/main/royale/mx/containers/beads/PanelInternalContainer.as index 8577659..6b30ab8 100644 --- a/frameworks/projects/Effects/src/main/royale/org/apache/royale/utils/MockLayoutHost.as +++ b/frameworks/projects/MXRoyale/src/main/royale/mx/containers/beads/PanelInternalContainer.as @@ -16,32 +16,36 @@ // limitations under the License. // //////////////////////////////////////////////////////////////////////////////// -package org.apache.royale.utils + +package mx.containers.beads { - import org.apache.royale.core.ILayoutHost; - import org.apache.royale.core.ILayoutView; - public class MockLayoutHost implements ILayoutHost - { - private var _contentView:ILayoutView; - public function MockLayoutHost(source:ILayoutHost) - { - _contentView = new MockContentView(source.contentView); - } +import mx.core.Container; + +/** + * @private + * The PanelInternalContainer is used to apply a custom view to Panel's internal container. + */ +public class PanelInternalContainer extends Container +{ + //-------------------------------------------------------------------------- + // + // Constructor + // + //-------------------------------------------------------------------------- - public function get contentView():ILayoutView - { - return _contentView; - } - - public function beforeLayout():void - { - - } - - public function afterLayout():void - { - - } + /** + * Constructor. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion Flex 3 + */ + public function PanelInternalContainer() + { + super(); } } + +} diff --git a/frameworks/projects/MXRoyale/src/main/royale/mx/containers/beads/PanelInternalContainerView.as b/frameworks/projects/MXRoyale/src/main/royale/mx/containers/beads/PanelInternalContainerView.as new file mode 100644 index 0000000..955c5d6 --- /dev/null +++ b/frameworks/projects/MXRoyale/src/main/royale/mx/containers/beads/PanelInternalContainerView.as @@ -0,0 +1,101 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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 mx.containers.beads +{ + +import mx.core.Container; + +import org.apache.royale.core.IBead; +import org.apache.royale.core.ILayoutChild; +import org.apache.royale.core.IStrand; +import org.apache.royale.core.UIBase; +import org.apache.royale.html.beads.ContainerView; +import org.apache.royale.events.Event; + +/** + * @private + * The PanelView for emulation. + */ +public class PanelInternalContainerView extends org.apache.royale.html.beads.ContainerView +{ + //-------------------------------------------------------------------------- + // + // Constructor + // + //-------------------------------------------------------------------------- + + /** + * Constructor. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion Flex 3 + */ + public function PanelInternalContainerView() + { + super(); + } + + /** + * Strand setter. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion Royale 0.8 + */ + override public function set strand(value:IStrand):void + { + super.strand = value; + + var container:Container = host as Container; + var panel:Container = container.parent as Container; + panel.addEventListener("widthChanged", handleSizeChanged); + panel.addEventListener("heightChanged", handleSizeChanged); + panel.addEventListener("sizeChanged", handleSizeChanged); + } + + private var sawSizeChanged:Boolean; + + private function handleSizeChanged(event:Event):void + { + sawSizeChanged = true; + } + + /** + * @royaleignorecoercion mx.core.UIComponent + * @royaleignorecoercion org.apache.royale.core.UIBase + * @royaleignorecoercion mx.containers.beads.models.PanelModel + */ + override public function beforeLayout():Boolean + { + var container:Container = host as Container; + var panel:Container = container.parent as Container; + if (!panel.isWidthSizedToContent() || !panel.isHeightSizedToContent()) + { + return sawSizeChanged; + } + return true; + } + +} + +} diff --git a/frameworks/projects/MXRoyale/src/main/royale/mx/containers/beads/PanelView.as b/frameworks/projects/MXRoyale/src/main/royale/mx/containers/beads/PanelView.as index 447cc14..c364279 100644 --- a/frameworks/projects/MXRoyale/src/main/royale/mx/containers/beads/PanelView.as +++ b/frameworks/projects/MXRoyale/src/main/royale/mx/containers/beads/PanelView.as @@ -36,6 +36,8 @@ import org.apache.royale.core.IStrand; import org.apache.royale.core.UIBase; import org.apache.royale.html.beads.PanelView; import org.apache.royale.html.beads.layouts.VerticalFlexLayout; +import org.apache.royale.events.Event; +import org.apache.royale.events.IEventDispatcher; /** * @private @@ -63,13 +65,25 @@ public class PanelView extends org.apache.royale.html.beads.PanelView } /** + * @royaleignorecoercion org.apache.royale.events.IEventDispatcher */ override public function set strand(value:IStrand):void { titleBar = new PanelTitleBar(); + var panel:IEventDispatcher = value as IEventDispatcher; + panel.addEventListener("widthChanged", handleSizeChanged); + panel.addEventListener("heightChanged", handleSizeChanged); + panel.addEventListener("sizeChanged", handleSizeChanged); super.strand = value; - } - + } + + private var sawSizeChanged:Boolean; + + private function handleSizeChanged(event:Event):void + { + sawSizeChanged = true; + } + /** * @royaleignorecoercion mx.core.UIComponent * @royaleignorecoercion org.apache.royale.core.UIBase @@ -131,6 +145,22 @@ public class PanelView extends org.apache.royale.html.beads.PanelView boxLayout.direction = "vertical"; _strand.addBead(boxLayout); } + + /** + * @royaleignorecoercion mx.core.UIComponent + * @royaleignorecoercion org.apache.royale.core.UIBase + * @royaleignorecoercion mx.containers.beads.models.PanelModel + */ + override public function beforeLayout():Boolean + { + var panel:Container = host as Container; + if (!panel.isWidthSizedToContent() || !panel.isHeightSizedToContent()) + { + return sawSizeChanged; + } + return true; + } + } }