| | 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 | } |