Changeset 15818 for lang/actionscript
- Timestamp:
- 07/15/08 01:20:04 (4 months ago)
- Location:
- lang/actionscript/ascss/src
- Files:
-
- 1 added
- 8 modified
-
KyotoDemo.as (modified) (7 diffs)
-
KyotoDemo.swf (modified) (previous)
-
css/ASCSS.asy (modified) (1 diff)
-
css/CSSRuleSet.as (modified) (3 diffs)
-
css/CSSSelector.as (modified) (2 diffs)
-
css/CSSStyleSelector.as (modified) (3 diffs)
-
cssdom/XMLElementWrapper.as (modified) (8 diffs)
-
kyotodemo/ElementData.as (added)
-
kyotodemo/XMLDocument.as (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/actionscript/ascss/src/KyotoDemo.as
r15769 r15818 5 5 import flash.geom.*; 6 6 import flash.text.*; 7 import flash.utils.*; 7 8 import css.*; 8 9 import cssdom.*; … … 35 36 36 37 private var mDocument:XMLDocument; 38 private var mPrevMatchedDocument:XMLDocument = null; 39 private var mStyleSheet:StyleList; 37 40 38 41 function KyotoDemo() … … 95 98 removeChild(tx); 96 99 addChild(tx); 100 tx.width = 300; 101 tx.height = 300; 97 102 tx.textColor = 0xffffff; 98 103 onXMLChanged(null); … … 134 139 private function onCSSChanged(e:Event):void 135 140 { 141 mStyleSheet = null; 136 142 clearCSSError(); 137 143 var parser:ASCSS = new ASCSS(mCSSField.text, new DebugOutProxy(this)); 138 144 parser.parse(); 139 145 createSelectorMarkers(parser.sheet); 146 mStyleSheet = parser.sheet; 140 147 showSelectorMarkers(); 148 149 doMatching(); 141 150 } 142 151 … … 147 156 try{ 148 157 mDocument = new XMLDocument(mXMLField.text); 158 XMLElementWrapper.createFor(mDocument.root, mDocument); 149 159 } catch(e:Error) { 150 160 outXMLError(e.toString()); … … 152 162 153 163 showElementMarkers(); 164 165 doMatching(); 154 166 } 155 167 … … 243 255 } 244 256 } 257 258 private function doMatching():void 259 { 260 STDOUT.cls(); 261 if (!mDocument || !mStyleSheet) return; 262 263 var list:Array = mDocument.elementMetadatas; 264 265 var sel:CSSStyleSelector; 266 267 mDocument.clearStyleSheets(); 268 mDocument.appendStyleSheet(mStyleSheet as css.StyleSheet); 269 sel = mDocument.createStyleSelector() 270 if (!sel) 271 return; 272 mPrevMatchedDocument = mDocument; 273 for each(var md:ElementData in list) 274 { 275 var elem:IASCSSElement = md.wrapper; 276 sel.initElementAndPseudoState(elem); 277 sel.initForStyleResolve(elem, null); 278 279 var authorStyle:CSSRuleSet = sel.authorStyle; 280 var indexes:Array = [-1, -1]; 281 282 sel.matchRules(authorStyle, indexes); 283 if (!sel.matchedRulesIsEmpty) 284 { 285 for each(var rd:CSSRuleData in sel.matchedRulesList) 286 { 287 STDOUT.puts(rd.selector.dump()); 288 } 289 } 290 } 291 } 245 292 } 246 293 } -
lang/actionscript/ascss/src/css/ASCSS.asy
r15768 r15818 1585 1585 appendStyleObject(rule); 1586 1586 rule.selector = sel; 1587 sel._owner = rule; 1587 1588 rule.declaration = new CSSMutableStyleDeclaration(rule, mParsedProperties); 1588 1589 } -
lang/actionscript/ascss/src/css/CSSRuleSet.as
r10854 r15818 4 4 { 5 5 private var mRuleCount:uint = 0; 6 private var mUniversalRules:CSSRuleDataList; 6 7 7 8 private var m_idRules:Object = {}; … … 20 21 public function getTagRules(key:String):CSSRuleDataList { 21 22 return m_tagRules[key] as CSSRuleDataList; 23 } 24 25 public function getUniversalRules():CSSRuleDataList { 26 return mUniversalRules as CSSRuleDataList; 22 27 } 23 28 … … 64 69 return; 65 70 } 71 else 72 { 73 // Just put it in the universal rule set. 74 if (!mUniversalRules) 75 mUniversalRules = new CSSRuleDataList(mRuleCount++, rule, sel); 76 else 77 mUniversalRules.append(mRuleCount++, rule, sel); 78 } 66 79 } 67 80 -
lang/actionscript/ascss/src/css/CSSSelector.as
r10979 r15818 159 159 } 160 160 161 private var mOwner:CSSStyleRule; 162 161 163 function CSSSelector() 162 164 { … … 168 170 m_relation = Descendant; 169 171 mPseudoType = PseudoNotParsed; 172 } 173 174 public function set _owner(r:CSSStyleRule):void 175 { 176 mOwner = r; 177 } 178 179 public function get _owner():CSSStyleRule 180 { 181 return mOwner; 170 182 } 171 183 -
lang/actionscript/ascss/src/css/CSSStyleSelector.as
r15743 r15818 292 292 293 293 matchRulesForList(rules.getTagRules(mElement.localName), aRuleIndexes); 294 matchRulesForList(rules.getUniversalRules(), aRuleIndexes); 294 295 295 296 // If we didn't match any rules, we're done. … … 318 319 } 319 320 321 public function get matchedRulesList():Array 322 { 323 return mMatchedRules; 324 } 325 320 326 public function matchRulesForList(rules:CSSRuleDataList, aRuleIndexes:Array /* first, last */):void 321 327 { … … 328 334 const localName:String = mElement.localName; 329 335 const selectorLocalName:String = d.selector.m_tag.localName; 330 331 336 if ((localName == selectorLocalName || selectorLocalName == '*') && checkSelector1(d.selector)) 332 337 { -
lang/actionscript/ascss/src/cssdom/XMLElementWrapper.as
r11241 r15818 2 2 { 3 3 import css.*; 4 import flash.utils.*; 4 5 5 public class XMLElementWrapper implements IASCSSStyledElement , IASCSSDocument6 public class XMLElementWrapper implements IASCSSStyledElement 6 7 { 7 8 private var m_usesSiblingRules:Boolean; … … 19 20 private var mMappedElementSheet:CSSStyleSheet; 20 21 private var mStyleSelector:CSSStyleSelector; 22 private var mRenderStyle:RenderStyle; 21 23 22 24 function XMLElementWrapper(x:XML, d:IASCSSDocument) … … 28 30 mClassNames = new ClassNames(); 29 31 readClassNames(x.attribute("class")[0]); 32 } 33 34 public function get renderStyle():RenderStyle 35 { 36 return mRenderStyle; 37 } 38 39 public function get hovered():Boolean 40 { 41 return false; 30 42 } 31 43 … … 46 58 { 47 59 var wrapper:XMLElementWrapper = new XMLElementWrapper(x, d); 60 /* 48 61 if (d == null) 49 62 { … … 52 65 wrapper.mStyleSheets = new StyleSheetList(wrapper); 53 66 } 54 67 */ 55 68 var len:uint = x.children().length(); 56 69 for (var i:uint = 0;i < len;i++) … … 70 83 71 84 return wrapper; 85 } 86 87 public function appendChild(e:IASCSSElement):void 88 { 89 if (!mChildren) 90 mChildren = []; 91 92 mChildren.push(e); 72 93 } 73 94 … … 124 145 return mDoc; 125 146 } 126 147 /* 127 148 public function setUsesSiblingRules(b:Boolean):void 128 149 { … … 165 186 mStyleSheets.add(s); 166 187 } 188 */ 167 189 } 168 190 } -
lang/actionscript/ascss/src/kyotodemo/XMLDocument.as
r15769 r15818 1 1 package kyotodemo 2 2 { 3 public class XMLDocument 3 import cssdom.*; 4 import css.*; 5 6 public class XMLDocument implements IASCSSDocument 4 7 { 5 8 private var mMetadatas:Array; … … 7 10 private var mSource:String; 8 11 private var mLineNo:int; 12 13 private var mStyleSheets:StyleSheetList; 14 private var mMappedElementSheet:CSSStyleSheet; 15 private var mStyleSelector:CSSStyleSelector; 16 // for parser 17 private var m_usesSiblingRules:Boolean; 18 private var m_usesDescendantRules:Boolean; 19 private var m_usesFirstLineRules:Boolean; 20 9 21 function XMLDocument(src:String) 10 22 { 23 mStyleSheets = new StyleSheetList(this); 11 24 mSource = src; 12 25 mMetadatas = []; … … 16 29 mXML = new XML(src); 17 30 18 STDOUT.cls();19 20 31 var pre:Object = /^[^<]+/.exec(src); 21 32 mLineNo = pre ? countBreaks(pre[0]) : 0; 22 33 checkLineno(mXML); 34 } 35 36 public function get root():XML 37 { 38 return mXML; 23 39 } 24 40 … … 28 44 } 29 45 30 private function checkLineno(x:XML, nest:int = 0 ):void46 private function checkLineno(x:XML, nest:int = 0, parent:ElementData = null):void 31 47 { 32 48 var md:ElementData = null; … … 39 55 md = new ElementData(); 40 56 md.x = x; 57 md.wrapper = new XMLElementWrapper(x, this); 41 58 md.nest = nest; 42 59 md.lineno = mLineNo; 43 60 mMetadatas.push(md); 61 62 if (parent && parent.wrapper) { 63 parent.wrapper.appendChild(md.wrapper); 64 md.wrapper.parent = parent.wrapper; 65 } 44 66 } 45 67 … … 47 69 for each(var ch:XML in list) 48 70 { 49 checkLineno(ch, nest + 1 );71 checkLineno(ch, nest + 1, md); 50 72 } 51 73 … … 69 91 return c; 70 92 } 93 94 // Document interface 95 public function isHTMLDocument():Boolean 96 { 97 return false; 98 } 99 100 public function get inCompatMode():Boolean 101 { 102 return true; 103 } 104 105 public function setUsesSiblingRules(b:Boolean):void 106 { 107 m_usesSiblingRules = b; 108 } 109 110 public function setUsesDescendantRules(b:Boolean):void 111 { 112 m_usesDescendantRules = b; 113 } 114 115 public function setUsesFirstLineRules(b:Boolean):void 116 { 117 m_usesFirstLineRules = b; 118 } 119 120 public function createStyleSelector():CSSStyleSelector 121 { 122 mStyleSelector = new CSSStyleSelector(this, userStyleSheet, mStyleSheets, mMappedElementSheet, !inCompatMode, true); 123 return mStyleSelector; 124 } 125 126 public function get userStyleSheet():String 127 { 128 return null; 129 } 130 131 public function getElementById(id:String):IASCSSElement 132 { 133 return null; // not needed for this demo 134 } 135 136 public function appendStyleSheet(s:StyleSheet):void 137 { 138 mStyleSelector = null; 139 mStyleSheets.add(s); 140 } 141 142 public function clearStyleSheets():void 143 { 144 mStyleSelector = null; 145 mStyleSheets = new StyleSheetList(this); 146 } 71 147 } 72 148 }
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)