Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 1ECEE200C22 for ; Tue, 21 Feb 2017 16:25:30 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 1D9A7160B68; Tue, 21 Feb 2017 15:25:30 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id BC27E160B3E for ; Tue, 21 Feb 2017 16:25:28 +0100 (CET) Received: (qmail 97077 invoked by uid 500); 21 Feb 2017 15:25:27 -0000 Mailing-List: contact commits-help@flex.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@flex.apache.org Delivered-To: mailing list commits@flex.apache.org Received: (qmail 97069 invoked by uid 99); 21 Feb 2017 15:25:27 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 21 Feb 2017 15:25:27 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id A3AE6DFEF5; Tue, 21 Feb 2017 15:25:27 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: carlosrovira@apache.org To: commits@flex.apache.org Date: Tue, 21 Feb 2017 15:25:27 -0000 Message-Id: <185e8d4e5573475ba231408163306f04@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [01/15] git commit: [flex-asjs] [refs/heads/feature/spriteflexjs-refactor] - Adding StyleChangeNotifier and StyleChangeEvent to Core. Replacing SolidBackgroundWithChangeListenerBead with a simplified, SWF-only, version. [Forced Update!] archived-at: Tue, 21 Feb 2017 15:25:30 -0000 Repository: flex-asjs Updated Branches: refs/heads/feature/spriteflexjs-refactor a6cb0b48c -> 3aeda903d (forced update) Adding StyleChangeNotifier and StyleChangeEvent to Core. Replacing SolidBackgroundWithChangeListenerBead with a simplified, SWF-only, version. Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/839d5dc6 Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/839d5dc6 Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/839d5dc6 Branch: refs/heads/feature/spriteflexjs-refactor Commit: 839d5dc6b6135d671ca008cd4a55b1546c8962a6 Parents: 6096099 Author: Peter Ent Authored: Thu Feb 16 10:11:25 2017 -0500 Committer: Peter Ent Committed: Thu Feb 16 10:11:25 2017 -0500 ---------------------------------------------------------------------- .../projects/Core/src/main/flex/CoreClasses.as | 2 + .../org/apache/flex/core/StyleChangeNotifier.as | 82 ++++++++++++ .../org/apache/flex/events/StyleChangeEvent.as | 79 ++++++++++++ .../Core/src/main/resources/basic-manifest.xml | 2 + .../projects/HTML/src/main/flex/HTMLClasses.as | 2 +- .../flex/html/beads/SolidBackgroundBead.as | 21 ++-- .../SolidBackgroundWithChangeListenerBead.as | 124 ++----------------- .../HTML/src/main/resources/basic-manifest.xml | 1 - 8 files changed, 188 insertions(+), 125 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/839d5dc6/frameworks/projects/Core/src/main/flex/CoreClasses.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Core/src/main/flex/CoreClasses.as b/frameworks/projects/Core/src/main/flex/CoreClasses.as index 7ce401b..690d84c 100644 --- a/frameworks/projects/Core/src/main/flex/CoreClasses.as +++ b/frameworks/projects/Core/src/main/flex/CoreClasses.as @@ -107,9 +107,11 @@ internal class CoreClasses import org.apache.flex.core.IViewportScroller; IViewportScroller; } import org.apache.flex.core.SimpleStatesImpl; SimpleStatesImpl; + import org.apache.flex.core.StyleChangeNotifier; StyleChangeNotifier; import org.apache.flex.events.CustomEvent; CustomEvent; import org.apache.flex.events.Event; Event; import org.apache.flex.events.ProgressEvent; ProgressEvent; + import org.apache.flex.events.StyleChangeEvent; StyleChangeEvent; import org.apache.flex.events.EventDispatcher; EventDispatcher; import org.apache.flex.events.IEventDispatcher; IEventDispatcher; import org.apache.flex.events.MouseEvent; MouseEvent; http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/839d5dc6/frameworks/projects/Core/src/main/flex/org/apache/flex/core/StyleChangeNotifier.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Core/src/main/flex/org/apache/flex/core/StyleChangeNotifier.as b/frameworks/projects/Core/src/main/flex/org/apache/flex/core/StyleChangeNotifier.as new file mode 100644 index 0000000..41ce7e7 --- /dev/null +++ b/frameworks/projects/Core/src/main/flex/org/apache/flex/core/StyleChangeNotifier.as @@ -0,0 +1,82 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.events.IEventDispatcher; + import org.apache.flex.events.Event; + import org.apache.flex.events.ValueChangeEvent; + import org.apache.flex.events.StyleChangeEvent; + import org.apache.flex.core.IBead; + import org.apache.flex.core.IStrand; + import org.apache.flex.core.IStyleableObject; + + /** + * The StyleChangeNotifier can be added to the bead list of any UI component + * that needs to react to dynamic changes to its styles. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class StyleChangeNotifier implements IBead + { + 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; + + var style:Object = IStyleableObject(value).style as IEventDispatcher; + if (style) { + IEventDispatcher(style).addEventListener(ValueChangeEvent.VALUE_CHANGE, handleStyleChange); + } + } + + /** + * @private + * @flexjsignorecoercion org.apache.flex.core.WrappedHTMLElement + * @flexjsignorecoercion UIHTMLElementWrapper + */ + private function handleStyleChange(event:ValueChangeEvent):void + { + COMPILE::SWF { + var styleEvent:StyleChangeEvent = StyleChangeEvent.createChangeEvent(_strand, event.propertyName, event.oldValue, event.newValue); + IEventDispatcher(_strand).dispatchEvent(styleEvent); + } + COMPILE::JS { + var host:UIHTMLElementWrapper = UIHTMLElementWrapper(_strand); + if (host) { + var element:WrappedHTMLElement = host.element as WrappedHTMLElement; + if (element) { + element.style[event.propertyName] = event.newValue; + } + } + } + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/839d5dc6/frameworks/projects/Core/src/main/flex/org/apache/flex/events/StyleChangeEvent.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Core/src/main/flex/org/apache/flex/events/StyleChangeEvent.as b/frameworks/projects/Core/src/main/flex/org/apache/flex/events/StyleChangeEvent.as new file mode 100644 index 0000000..00ec257 --- /dev/null +++ b/frameworks/projects/Core/src/main/flex/org/apache/flex/events/StyleChangeEvent.as @@ -0,0 +1,79 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.events +{ + + /** + * Instances of the StyleChangeEvent class are dispatched by the StyleChangeNotifier + * when it detects changes to a component's style. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class StyleChangeEvent extends ValueChangeEvent + { + /** + * Constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function StyleChangeEvent(type:String, bubbles:Boolean=false, cancelable:Boolean=false, + oldValue:Object = null, newValue:Object = null) + { + super(type, bubbles, cancelable, oldValue, newValue); + } + + /** + * The default event type. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public static const STYLE_CHANGE:String = "styleChange"; + + /** + * A convenience method to create an instance of the StyleChangeEvent. + * + * @param source The source of the object. + * @param name The name of the style being changed. + * @param oldValue The value before it was changed. + * @param newValue The value after it was changed. + * @return An instance of the StyleChangeEvent. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public static function createChangeEvent(source:Object, name:String, oldValue:Object, newValue:Object):StyleChangeEvent + { + var event:StyleChangeEvent = new StyleChangeEvent(STYLE_CHANGE, false, false, oldValue, newValue); + event.propertyName = name; + event.source = source; + return event; + } + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/839d5dc6/frameworks/projects/Core/src/main/resources/basic-manifest.xml ---------------------------------------------------------------------- diff --git a/frameworks/projects/Core/src/main/resources/basic-manifest.xml b/frameworks/projects/Core/src/main/resources/basic-manifest.xml index 5e15a52..398c03e 100644 --- a/frameworks/projects/Core/src/main/resources/basic-manifest.xml +++ b/frameworks/projects/Core/src/main/resources/basic-manifest.xml @@ -42,5 +42,7 @@ + + http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/839d5dc6/frameworks/projects/HTML/src/main/flex/HTMLClasses.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/flex/HTMLClasses.as b/frameworks/projects/HTML/src/main/flex/HTMLClasses.as index f269f6d..68f94c6 100644 --- a/frameworks/projects/HTML/src/main/flex/HTMLClasses.as +++ b/frameworks/projects/HTML/src/main/flex/HTMLClasses.as @@ -80,10 +80,10 @@ internal class HTMLClasses import org.apache.flex.html.beads.SingleLineBorderBead; SingleLineBorderBead; } import org.apache.flex.html.beads.SpinnerView; SpinnerView; - import org.apache.flex.html.beads.SolidBackgroundWithChangeListenerBead; SolidBackgroundWithChangeListenerBead; COMPILE::SWF { import org.apache.flex.html.beads.SolidBackgroundBead; SolidBackgroundBead; + import org.apache.flex.html.beads.SolidBackgroundWithChangeListenerBead; SolidBackgroundWithChangeListenerBead; import org.apache.flex.html.beads.TextButtonMeasurementBead; TextButtonMeasurementBead; import org.apache.flex.html.beads.TextFieldLabelMeasurementBead; TextFieldLabelMeasurementBead; import org.apache.flex.html.beads.TextAreaView; TextAreaView; http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/839d5dc6/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/SolidBackgroundBead.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/SolidBackgroundBead.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/SolidBackgroundBead.as index 6dade4d..6ea9701 100644 --- a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/SolidBackgroundBead.as +++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/SolidBackgroundBead.as @@ -78,6 +78,13 @@ package org.apache.flex.html.beads IEventDispatcher(host).addEventListener("sizeChanged", changeHandler); IEventDispatcher(host).addEventListener("initComplete", changeHandler); + setupStyle(); + + changeHandler(null); + } + + protected function setupStyle():void + { var bgColor:Object = ValuesManager.valuesImpl.getValue(host, "background-color"); if ((bgColor is String) && (bgColor == "transparent")) { bgColor = null; @@ -91,13 +98,11 @@ package org.apache.flex.html.beads if( bgAlpha != null ) { opacity = Number(bgAlpha); } - - var corner:Object = ValuesManager.valuesImpl.getValue(host, "border-radius"); - if( corner != null ) { - borderRadius = Number(corner); - } - - changeHandler(null); + + var corner:Object = ValuesManager.valuesImpl.getValue(host, "border-radius"); + if( corner != null ) { + borderRadius = Number(corner); + } } private var _backgroundColor:uint; @@ -175,7 +180,7 @@ package org.apache.flex.html.beads changeHandler(null); } - private function changeHandler(event:Event):void + protected function changeHandler(event:Event):void { var g:Graphics = (host.$displayObject as Object).graphics as Graphics; var w:Number = host.width; http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/839d5dc6/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/SolidBackgroundWithChangeListenerBead.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/SolidBackgroundWithChangeListenerBead.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/SolidBackgroundWithChangeListenerBead.as index c0be00c..80462c9 100644 --- a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/SolidBackgroundWithChangeListenerBead.as +++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/SolidBackgroundWithChangeListenerBead.as @@ -20,35 +20,20 @@ package org.apache.flex.html.beads { import org.apache.flex.events.IEventDispatcher; import org.apache.flex.events.Event; - import org.apache.flex.events.ValueChangeEvent; - import org.apache.flex.utils.CSSUtils; - - COMPILE::SWF { - import org.apache.flex.core.IStrand; - import org.apache.flex.core.BindableCSSStyles; - import org.apache.flex.html.beads.SolidBackgroundBead; - } - - COMPILE::JS { - import org.apache.flex.core.WrappedHTMLElement; - import org.apache.flex.core.IBead; + import org.apache.flex.events.StyleChangeEvent; import org.apache.flex.core.IStrand; import org.apache.flex.core.UIBase; - } + import org.apache.flex.html.beads.SolidBackgroundBead; /** - * Same as SolidBackgroundBead except it adds an event listener on a bindable style - * (eg, BindableCSSStyles) to detect changes in some of its properties and then - * apply those changes to itself. - * - * Usage: + * Same as SolidBackgroundBead except it listens for StyleChangeEvent events + * and reacts by refreshing the background of its strand. * * @langversion 3.0 * @playerversion Flash 10.2 * @playerversion AIR 2.6 * @productversion FlexJS 0.0 */ - COMPILE::SWF public class SolidBackgroundWithChangeListenerBead extends SolidBackgroundBead { /** @@ -70,108 +55,17 @@ package org.apache.flex.html.beads override public function set strand(value:IStrand):void { super.strand = value; - } - - private var _style:IEventDispatcher; - - /** - * The bindable style to use as the source of the changes. - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public function get style():IEventDispatcher - { - return _style; - } - public function set style(value:IEventDispatcher):void - { - _style = value; - if (_style) { - _style.addEventListener(ValueChangeEvent.VALUE_CHANGE, handleStyleChange); - } - } - - /** - * @private - */ - private function handleStyleChange(event:ValueChangeEvent):void - { - if (event.propertyName == "backgroundColor") { - var valueAsNumber:uint; - if (event.newValue is String) { - valueAsNumber = CSSUtils.toColor(event.newValue); - } else { - valueAsNumber = event.newValue as uint; - } - this[event.propertyName] = valueAsNumber; - } - } - } - - COMPILE::JS - public class SolidBackgroundWithChangeListenerBead implements IBead - { - 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; - } - - private var _style:IEventDispatcher; - - /** - * The bindable style to use as the source of the changes. - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public function get style():IEventDispatcher - { - return _style; - } - public function set style(value:IEventDispatcher):void - { - _style = value; - if (_style) { - _style.addEventListener(ValueChangeEvent.VALUE_CHANGE, handleStyleChange); - } + IEventDispatcher(value).addEventListener(StyleChangeEvent.STYLE_CHANGE, handleStyleChange); + } /** * @private - * @flexjsignorecoercion org.apache.flex.core.WrappedHTMLElement - * @flexjsignorecoercion UIBase */ - private function handleStyleChange(event:ValueChangeEvent):void + private function handleStyleChange(event:StyleChangeEvent):void { - var host:UIBase = UIBase(_strand); - var element:WrappedHTMLElement = host.element as WrappedHTMLElement; - - // For HTML/CSS, the color change value should be expressed as a hex string. It - // can be other things, but using element.style.backgroundColor requires a hex string. - if (event.propertyName === "backgroundColor") { - var valueAsString:String; - if (event.newValue is Number) { - valueAsString = CSSUtils.attributeFromColor(event.newValue as uint); - } else { - valueAsString = event.newValue as String; - } - element.style.backgroundColor = valueAsString; - } + setupStyle(); + changeHandler(null); } } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/839d5dc6/frameworks/projects/HTML/src/main/resources/basic-manifest.xml ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/resources/basic-manifest.xml b/frameworks/projects/HTML/src/main/resources/basic-manifest.xml index 52499e9..e3a27f3 100644 --- a/frameworks/projects/HTML/src/main/resources/basic-manifest.xml +++ b/frameworks/projects/HTML/src/main/resources/basic-manifest.xml @@ -143,7 +143,6 @@ -