flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aha...@apache.org
Subject git commit: [flex-asjs] [refs/heads/develop] - handle spans better in html
Date Mon, 25 May 2015 06:42:30 GMT
Repository: flex-asjs
Updated Branches:
  refs/heads/develop 5bc08dcf2 -> 096b3fd9e


handle spans better in html


Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/096b3fd9
Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/096b3fd9
Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/096b3fd9

Branch: refs/heads/develop
Commit: 096b3fd9eb743d0f0c772ce3b73787e09d682156
Parents: 5bc08dc
Author: Alex Harui <aharui@apache.org>
Authored: Sun May 24 23:42:22 2015 -0700
Committer: Alex Harui <aharui@apache.org>
Committed: Sun May 24 23:42:22 2015 -0700

----------------------------------------------------------------------
 .../apache/flex/html/beads/TextFieldViewBase.as | 58 +++++++++++++++++++-
 1 file changed, 56 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/096b3fd9/frameworks/projects/HTML/as/src/org/apache/flex/html/beads/TextFieldViewBase.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/HTML/as/src/org/apache/flex/html/beads/TextFieldViewBase.as
b/frameworks/projects/HTML/as/src/org/apache/flex/html/beads/TextFieldViewBase.as
index 2378b78..0bcae7f 100644
--- a/frameworks/projects/HTML/as/src/org/apache/flex/html/beads/TextFieldViewBase.as
+++ b/frameworks/projects/HTML/as/src/org/apache/flex/html/beads/TextFieldViewBase.as
@@ -20,10 +20,11 @@ package org.apache.flex.html.beads
 {
 	import flash.display.DisplayObject;
 	import flash.display.DisplayObjectContainer;
+	import flash.text.StyleSheet;
 	
 	import org.apache.flex.core.CSSTextField;
 	import org.apache.flex.core.IBeadView;
-    import org.apache.flex.core.ILayoutChild;
+	import org.apache.flex.core.ILayoutChild;
 	import org.apache.flex.core.IStrand;
 	import org.apache.flex.core.ITextModel;
 	import org.apache.flex.core.IUIBase;
@@ -189,10 +190,63 @@ package org.apache.flex.html.beads
          */
         public function set html(value:String):void
 		{
-			_textField.htmlText = value;
+			convertToTextFieldHTML(value);
             autoSizeIfNeeded();
 		}
 		
+        private function convertToTextFieldHTML(input:String):void
+        {
+            var classCount:int = 0;
+            var ss:StyleSheet;
+            var c:int = input.indexOf("<span");
+            while (c != -1)
+            {
+                var c1:int = input.indexOf(">", c);
+                if (c1 == -1)
+                {
+                    trace("did not parse span correctly");
+                    return;
+                }
+                var tag:String = input.substring(c, c1 + 1);
+                var c2:int = tag.indexOf("style=");
+                if (c2 != -1)
+                {
+                    var quote:String = tag.charAt(c2 + 6);
+                    var c3:int = tag.indexOf(quote, c2 + 7);
+                    if (c3 != -1)
+                    {
+                        var styles:String = tag.substring(c2 + 7, c3);
+                        if (!ss)
+                            ss = new StyleSheet();
+                        var styleObject:Object = {};
+                        var list:Array = styles.split(";");
+                        for each (var pair:String in list)
+                        {
+                            var parts:Array = pair.split(":");
+                            var name:String = parts[0];
+                            var c4:int = name.indexOf("-");
+                            if (c4 != -1)
+                            {
+                                var firstChar:String = name.charAt(c4 + 1);
+                                firstChar = firstChar.toUpperCase();
+                                var tail:String = name.substring(c4 + 2);
+                                name = name.substring(0, c4) + firstChar + tail;
+                            }
+                            styleObject[name] = parts[1];
+                        }
+                        var className:String = "css" + classCount++;
+                        ss.setStyle("." + className, styleObject);
+                        var newTag:String = "<span class='" + className + "'>";
+                        input = input.replace(tag, newTag);
+                        c1 += newTag.length - tag.length;
+                    }
+                }
+                c = input.indexOf("<span", c1);
+            }
+            _textField.styleSheet = ss;   
+            _textField.htmlText = input;
+        }
+        
 		private function textChangeHandler(event:Event):void
 		{
 			text = _textModel.text;


Mime
View raw message