You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by pe...@apache.org on 2017/02/16 15:11:27 UTC
git commit: [flex-asjs] [refs/heads/develop] - Adding
StyleChangeNotifier and StyleChangeEvent to Core. Replacing
SolidBackgroundWithChangeListenerBead with a simplified, SWF-only, version.
Repository: flex-asjs
Updated Branches:
refs/heads/develop 609609951 -> 839d5dc6b
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/develop
Commit: 839d5dc6b6135d671ca008cd4a55b1546c8962a6
Parents: 6096099
Author: Peter Ent <pe...@apache.org>
Authored: Thu Feb 16 10:11:25 2017 -0500
Committer: Peter Ent <pe...@apache.org>
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 @@
<component id="TransformMoveYModel" class="org.apache.flex.core.TransformMoveYModel" />
<component id="TransformScaleModel" class="org.apache.flex.core.TransformScaleModel" />
+ <component id="StyleChangeNotifier" class="org.apache.flex.core.StyleChangeNotifier"/>
+
<component id="State" class="org.apache.flex.states.State"/>
</componentPackage>
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: <js:SolidBackgroundWithChangeListenerBead style="{bindableCSSStylesbead}" />
+ * 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 @@
<component id="SubAppLoader" class="org.apache.flex.html.SubAppLoader" />
<component id="Border" class="org.apache.flex.html.supportClasses.Border"/>
- <component id="SolidBackgroundWithChangeListenerBead" class="org.apache.flex.html.beads.SolidBackgroundWithChangeListenerBead"/>
<component id="WebBrowser" class="org.apache.flex.html.WebBrowser" />