Changeset 10932

Show
Ignore:
Timestamp:
05/02/08 15:16:18 (5 years ago)
Author:
gyuque
Message:

selector specificity calculation

Location:
lang/actionscript/ascss/src
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • lang/actionscript/ascss/src/css/CSSRuleData.as

    r10847 r10932  
    77                private var mRule:CSSStyleRule; 
    88                private var mSelector:CSSSelector; 
     9                private var mPosition:uint; 
    910                function CSSRuleData(pos:uint, r:CSSStyleRule, sel:CSSSelector, prev:CSSRuleData = null) 
    1011                { 
     12                        mPosition = pos; 
    1113                        mSelector = sel; 
    1214                        mRule = r; 
     
    3032                        return mSelector; 
    3133                } 
     34 
     35                public function get position():uint 
     36                { 
     37                        return mPosition; 
     38                } 
    3239        } 
    3340} 
  • lang/actionscript/ascss/src/css/CSSSelector.as

    r10876 r10932  
    224224                        return m_relation; 
    225225                } 
     226 
     227                public function get specificity():uint 
     228                { 
     229                        // FIXME: Pseudo-elements and pseudo-classes do not have the same specificity. This function 
     230                        // isn't quite correct. 
     231                        var s:int = (m_tag.localName == '*' ? 0 : 1); 
     232                        switch (m_match) { 
     233                        case Id: 
     234                                s += 0x10000; 
     235                                break; 
     236                        case Exact: 
     237                        case Class: 
     238                        case Set: 
     239                        case List: 
     240                        case Hyphen: 
     241                        case PseudoClass: 
     242                        case PseudoElement: 
     243                        case Contain: 
     244                        case Begin: 
     245                        case End: 
     246                                s += 0x100; 
     247                        case None: 
     248                                break; 
     249                        } 
     250                         
     251                        if (m_tagHistory) 
     252                                s += m_tagHistory.specificity; 
     253                         
     254                        // make sure it doesn't overflow 
     255                        return s & 0xffffff; 
     256                } 
     257 
    226258        } 
    227259} 
  • lang/actionscript/ascss/src/css/CSSStyleSelector.as

    r10876 r10932  
    55        public class CSSStyleSelector 
    66        { 
     7                private static const FIRST:uint = 0; 
     8                private static const LAST:uint = 1; 
    79                private static var pseudoState:uint; 
    810 
     
    7072                } 
    7173 
     74                private function sortMatchedRules(start:uint, end:uint):void 
     75                { 
     76                        if (start >= end || ((end - start) == 1)) 
     77                                return; // Sanity check. 
     78                         
     79                        if ((end - start) <= 6) { 
     80                        } 
     81                } 
     82 
    7283                public function matchRules(rules:CSSRuleSet, aRuleIndexes:Array /* first, last */):void 
    7384                { 
     
    90101 
    91102                        matchRulesForList(rules.getTagRules(mElement.localName), aRuleIndexes); 
     103 
     104                        // If we didn't match any rules, we're done. 
     105                        if (matchedRulesIsEmpty) 
     106                                return; 
     107 
     108                        // Sort the set of matched rules. 
     109                        sortMatchedRules(0, mMatchedRules.length); 
     110                } 
     111 
     112                private function get matchedRulesIsEmpty():Boolean 
     113                { 
     114                        return mMatchedRules.length < 1; 
    92115                } 
    93116 
     
    119142                                        } else { 
    120143                                                // Update our first/last rule indices in the matched rules array. 
    121                                                 aRuleIndexes[1] = mMatchedDecls.length + mMatchedRules.length; 
    122                                                 if (aRuleIndexes[0] == -1) 
    123                                                         aRuleIndexes[0] = aRuleIndexes[1]; 
     144                                                aRuleIndexes[LAST] = mMatchedDecls.length + mMatchedRules.length; 
     145                                                if (aRuleIndexes[FIRST] == -1) 
     146                                                        aRuleIndexes[FIRST] = aRuleIndexes[LAST]; 
    124147                                                 
    125148SelectTest.puts("selector matched for <"+localName+">"); 
     
    224247                        mMatchedDecls = []; 
    225248                } 
     249 
     250                public static function greaterThan(r1:CSSRuleData, r2:CSSRuleData):Boolean 
     251                { 
     252                        var spec1:int = r1.selector.specificity; 
     253                        var spec2:int = r2.selector.specificity; 
     254                        return (spec1 == spec2) ? (r1.position > r2.position) : (spec1 > spec2);  
     255                } 
     256 
     257                public static function lesseq(r1:CSSRuleData, r2:CSSRuleData):Boolean 
     258                { 
     259                        return !(r1 > r2); 
     260                } 
    226261        } 
    227262}