Changeset 9619 for lang

Show
Ignore:
Timestamp:
04/17/08 18:13:36 (5 years ago)
Author:
gyuque
Message:

ascss: updated test

Location:
lang/actionscript/ascss/src
Files:
9 added
2 modified

Legend:

Unmodified
Added
Removed
  • lang/actionscript/ascss/src/CSSTest-config.xml

    r9538 r9619  
    22 <default-frame-rate>10</default-frame-rate> 
    33 <default-size> 
    4   <width>640</width> 
    5   <height>480</height> 
     4  <width>800</width> 
     5  <height>600</height> 
    66 </default-size> 
    7  <default-background-color>0x000000</default-background-color> 
     7 <default-background-color>0x222222</default-background-color> 
    88</flex-config> 
  • lang/actionscript/ascss/src/CSSTest.as

    r9538 r9619  
    33        import flash.display.*; 
    44        import flash.text.*; 
    5         import css.ASCSS; 
     5        import css.*; 
     6        import ascsstest.*; 
    67        public class CSSTest extends Sprite 
    78        { 
     
    910                private var mTextOut:TextField; 
    1011                private var mCSS:ASCSS; 
     12                private var mVLayer:Sprite; 
     13                private var mELayer:Sprite; 
    1114 
    12                 public static const T_CSS:String = "body {\n background-color: #f0f5f0;\n color: transparent;\n}"; 
     15                public static const T_CSS:String =  
     16"h1 {\n"+ 
     17" background-color: transparent;\n"+ 
     18" color: #507a93;\n"+ 
     19"}\n\n"+ 
     20".foo p, em {\n"+ 
     21" color: #26f;\n"+ 
     22"}" 
     23; 
    1324 
    1425                function CSSTest() 
    1526                { 
     27                        var g:Graphics = graphics; 
     28                        g.beginFill(0x333333); 
     29                        g.drawRect(-500, 0, 1300, 500); 
     30                        g.endFill(); 
     31 
     32                        mELayer = new Sprite(); 
     33                        addChild(mELayer); 
     34 
     35                        mVLayer = new Sprite(); 
     36                        addChild(mVLayer); 
     37 
    1638                        mTextOut = new TextField(); 
    17                         mTextOut.width  = 640; 
    18                         mTextOut.height = 480; 
     39                        mTextOut.width  = 800; 
     40                        mTextOut.height = 100; 
     41                        mTextOut.y = 500; 
    1942                        mTextOut.textColor = 0xffffff; 
    2043                        addChild(mTextOut); 
    2144                        theInstance = this; 
    22  
     45puts(T_CSS); 
    2346                        mCSS = new ASCSS(T_CSS); 
    2447                        mCSS.parse(); 
     48 
     49                        var sheet:StyleList = mCSS.sheet; 
     50                        var sv:StyleListVisual = new StyleListVisual(sheet); 
     51                        sv.edgeLayer = mELayer; 
     52                        mVLayer.addChild(sv); 
     53 
     54                        sv.x = 10; 
     55                        sv.y = 10; 
     56 
     57                        generateStyleListChildren(sheet, sv); 
     58 
     59                        sv.calcSize(false); 
     60                        sv.calcMaxWidth(); 
     61                        sv.locate(); 
     62                        mELayer.graphics.clear(); 
     63                        sv.renderEdge(mELayer, 0xffffff); 
     64                } 
     65 
     66                private function generateStyleListChildren(sl:StyleList, sv:StyleListVisual):void 
     67                { 
     68                        var ch:StyleBase; 
     69                        var len:uint = sl.length; 
     70                        var children:Array = []; 
     71 
     72                        for (var i:uint = 0;i < len;i++) 
     73                        { 
     74                                ch = sl.item(i); 
     75 
     76                                if (ch is CSSRule) 
     77                                { 
     78                                        var v:RuleVisual = new RuleVisual(CSSRule(ch)); 
     79                                        mVLayer.addChild(v); 
     80 
     81                                        if (ch is CSSStyleRule) 
     82                                                generateStyleRuleChildren(CSSStyleRule(ch), v); 
     83 
     84                                        children.push(v); 
     85                                } 
     86                        } 
     87 
     88                        chain(sv, children); 
     89                } 
     90 
     91                private function generateStyleRuleChildren(sr:CSSStyleRule, sv:RuleVisual):void 
     92                { 
     93                        var v:SelectorVisual; 
     94                        var nx:CSSSelector = sr.selector; 
     95                        var children:Array = []; 
     96 
     97                        while(nx != null) 
     98                        { 
     99                                v = new SelectorVisual(nx); 
     100                                mVLayer.addChild(v); 
     101                                children.push(v); 
     102 
     103                                generateSelectorChildren(nx, v); 
     104 
     105                                nx = nx.next; 
     106                        } 
     107 
     108                        if (sr.declaration != null) 
     109                        { 
     110                                var dv:DeclarationVisual = new DeclarationVisual(sr.declaration); 
     111                                mVLayer.addChild(dv); 
     112                                children.push(dv); 
     113 
     114                                if (sr.declaration is CSSMutableStyleDeclaration) 
     115                                        generateMutableDeclarationChildren(CSSMutableStyleDeclaration(sr.declaration), dv); 
     116                        } 
     117 
     118                        chain(sv, children); 
     119                } 
     120 
     121 
     122                private function generateSelectorChildren(ss:CSSSelector, sv:SelectorVisual):void 
     123                { 
     124                        if (ss.mTagHistory != null) 
     125                        { 
     126                                var v:SelectorVisual = new SelectorVisual(ss.mTagHistory); 
     127                                mVLayer.addChild(v); 
     128                                sv.firstChild = v; 
     129                        } 
     130                } 
     131 
     132                private function generateMutableDeclarationChildren(sd:CSSMutableStyleDeclaration, sv:DeclarationVisual):void 
     133                { 
     134                        var len:uint = sd.length; 
     135                        var children:Array = []; 
     136                        for (var i:uint;i < len;i++) 
     137                        { 
     138                                var v:PropertyVisual = new PropertyVisual(sd.rawItem(i)); 
     139                                mVLayer.addChild(v); 
     140                                children.push(v); 
     141 
     142                                generatePropertyChildren(sd.rawItem(i), v); 
     143                        } 
     144 
     145                        chain(sv, children); 
     146                } 
     147 
     148                private function generatePropertyChildren(cp:CSSProperty, pv:PropertyVisual):void 
     149                { 
     150                        var val:CSSValue = cp.value; 
     151                        if (val == null) 
     152                                return; 
     153 
     154                        var v:ValueVisual = new ValueVisual(val); 
     155                        mVLayer.addChild(v); 
     156                        pv.firstChild = v; 
     157                } 
     158 
     159                private function chain(parent:StyleVisualBase, children:Array /* of StyleVisualBase */):void 
     160                { 
     161                        var prev:StyleVisualBase = null; 
     162                        for each(var ch:StyleVisualBase in children) 
     163                        { 
     164                                if (prev == null) 
     165                                        parent.firstChild = ch; 
     166                                else 
     167                                        prev.nextSibling = ch; 
     168 
     169                                prev = ch; 
     170                        } 
    25171                } 
    26172