Changeset 15905 for lang/actionscript

Show
Ignore:
Timestamp:
07/17/08 00:07:13 (4 months ago)
Author:
gyuque
Message:

implemented nth-child pseudo class

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

Legend:

Unmodified
Added
Removed
  • lang/actionscript/ascss/src/CSSTest.as

    r10809 r15905  
    660660        } 
    661661 
    662         public function isValidPrimitiveValue(aPropID:int, aValueId:int):Boolean 
     662        public function isColorValue(aPropID:int):Boolean 
     663        { 
     664                return false; 
     665        } 
     666 
     667        public function isValidPrimitiveValue(aPropID:int, aValue:Value, aValueId:int, aHost:IPropertyExtensionHost):Boolean 
    663668        { 
    664669                if (aPropID == mAzimuthPropID) 
  • lang/actionscript/ascss/src/KyotoDemo.as

    r15881 r15905  
    127127                        tx.height = 300; 
    128128                        tx.textColor = 0xffffff; 
    129                         tx.visible = false; 
     129//                      tx.visible = false; 
    130130                        onXMLChanged(null); 
    131131                } 
     
    361361 
    362362                        var ed:ElementData, wrapper:XMLElementWrapper 
    363                         STDOUT.cls(); 
    364363 
    365364                        var list:Array = mDocument.elementMetadatas.slice(); 
  • lang/actionscript/ascss/src/css/ASCSS.asy

    r15818 r15905  
    12491249        $$.id = 0; 
    12501250        $$.unit = Value.Function; 
    1251         $$.function = f; 
     1251        $$.parseFunction = f; 
    12521252    } | 
    12531253    FUNCTION maybe_space error { 
     
    12591259        $$.id = 0; 
    12601260        $$.unit = Value.Function; 
    1261         $$.function = f; 
     1261        $$.parseFunction = f; 
    12621262  } 
    12631263  ; 
  • lang/actionscript/ascss/src/css/CSSLexer.as

    r15743 r15905  
    6262                private static const mRxContains:RegExp    = /^\*=/ 
    6363                private static const mRxWhitespace:RegExp  = /^[ \t\r\n\f]+/ 
    64                 private static const mRxSingleChars:RegExp = /^[-+;:{}#.,*>~\[\]=]/ 
     64                private static const mRxSingleChars:RegExp = /^[)-+;:{}#.,*>~\[\]=]/ 
     65                private static const mRxNth:RegExp         = /^((-?[0-9]*n[\+-][0-9]+)|(-?[0-9]*n))/ 
    6566                private static const mRxCommnet:RegExp = new RegExp("^\\/\\*[^*]*\\*+([^/*][^*]*\\*+)*\\/"); 
    6667 
     
    6869                private var mRxIdsel:RegExp; 
    6970                private var mRxIdent:RegExp; 
     71                private var mRxFunction:RegExp; 
    7072                private var mRxString:RegExp; 
    7173                private var mRxNum:RegExp; 
     
    9193                        mRxIdsel    = new RegExp("^#"+RX_IDENT); 
    9294                        mRxIdent    = new RegExp("^"+RX_IDENT); 
     95                        mRxFunction = new RegExp("^"+RX_IDENT+"\\("); 
    9396                        //mRxString   = new RegExp("^"+RX_STRING); 
    9497                        mRxString   = /^"(?:\\.|[^"])*"|^'(?:[^']|\\.)*'/ 
     
    159162                                mTokBody = rxr[1]; 
    160163                        } 
     164                        else if ((rxr = mRxFunction.exec(mCurSource)) != null) 
     165                        { 
     166                                kw = PARSER.FUNCTION; 
     167                                advance = rxr[0].length; 
     168                                mTokBody = rxr[0]; 
     169                        } 
    161170                        else if ((rxr = mRxIdsel.exec(mCurSource)) != null) 
    162171                        { 
     
    195204                                kw = PARSER.PERCENTAGE; 
    196205                                advance = rxr[0].length; mTokBody = rxr[1]; 
     206                        } 
     207                        else if ((rxr = mRxNth.exec(mCurSource)) != null) 
     208                        { 
     209                                kw = PARSER.NTH; 
     210                                advance = rxr[0].length; 
     211                                mTokBody = rxr[0]; 
    197212                        } 
    198213                        else if ((rxr = mRxNum.exec(mCurSource)) != null) 
  • lang/actionscript/ascss/src/css/CSSSelector.as

    r15820 r15905  
    197197                public  var m_match:uint; 
    198198                public  var m_relation:uint; 
     199                public  var m_argument:String; 
    199200                public  var mPseudoType:uint; 
    200201                private var mNext:CSSSelector; 
  • lang/actionscript/ascss/src/css/CSSStyleSelector.as

    r15881 r15905  
    538538 
    539539                        var result:Boolean, n:IASCSSElement; 
     540                        var nthAB:Array = [0, 0]; 
    540541                        if (sel.m_match == CSSSelector.PseudoClass) { 
    541542                                switch (sel.pseudoType()) { 
     
    611612                                                break; 
    612613                                        } 
     614 
     615                                        case CSSSelector.PseudoNthChild: { 
     616                                                // calculate a and b every time we run through checkOneSelector 
     617                                                // this should probably be saved after we calculate it once, but currently 
     618                                                // would require increasing the size of CSSSelector 
     619                                                if (!parseNth(sel.m_argument, nthAB)) 
     620                                                        break; 
     621 
     622                                                if (e.parentNode && e.parentNode.isElementNode) 
     623                                                { 
     624                                                        var count:int = 1; 
     625                                                        n = e.previousSibling; 
     626 
     627                                                        while (n) { 
     628                                                                if (n.isElementNode) { 
     629/* 
     630                                                                        var s:RenderStyle = n.renderStyle; 
     631                                                                        var index:uint = s ? s.childIndex : 0; 
     632                                                                        if (index > 0) { 
     633                                                                                count += index; 
     634                                                                                break; 
     635                                                                        } 
     636*/ 
     637                                                                        count++; 
     638                                                                } 
     639                                                                n = n.previousSibling; 
     640                                                        } 
     641                                                         
     642                                                        if (!mCollectRulesOnly) { 
     643                                                                var childStyle:RenderStyle = (mElement == e) ? mStyle : e.renderStyle; 
     644//                                                              RenderStyle* parentStyle = (m_element == e) ? m_parentStyle : e->parentNode()->renderStyle(); 
     645                                                                if (childStyle) 
     646                                                                        childStyle.childIndex = count; 
     647//                                                              if (parentStyle) 
     648//                                                                      parentStyle->setChildrenAffectedByForwardPositionalRules(); 
     649                                                        } 
     650                                                         
     651                                                        if (matchNth(count, nthAB[0], nthAB[1])) 
     652                                                                return true; 
     653 
     654                                                } 
     655 
     656                                                break; 
     657 
     658 
     659                                        } // case CSSSelector::PseudoNthChild 
    613660                                } 
    614661                                return false; 
     
    633680                } 
    634681 
     682                // a helper function for parsing nth-arguments 
     683                private static function parseNth(nth:String, idx:Array):Boolean 
     684                { 
     685                        if (!nth || nth.length < 1) 
     686                                return false; 
     687                        idx[0] = 0; 
     688                        idx[1] = 0; 
     689                        if (nth == "odd") { 
     690                                idx[0] = 2; 
     691                                idx[1] = 1; 
     692                        } else if (nth == "even") { 
     693                                idx[0] = 2; 
     694                                idx[1] = 0; 
     695                        } else { 
     696                                var n:int = nth.indexOf('n'); 
     697                                if (n != -1) { 
     698                                        if (nth.charAt(0) == '-') { 
     699                                                if (n == 1) 
     700                                                        idx[0] = -1; // -n == -1n 
     701                                                else 
     702                                                        idx[0] = parseInt( nth.substring(0, n) ); 
     703                                        } else if (!n) 
     704                                                idx[0] = 1; // n == 1n 
     705                                        else 
     706                                                idx[0] = parseInt( nth.substring(0, n) ); 
     707                 
     708                                        var p:int = nth.indexOf('+', n); 
     709                                        if (p != -1) 
     710                                                idx[1] = parseInt( nth.substring(p + 1) ); 
     711                                        else { 
     712                                                p = nth.indexOf('-', n); 
     713                                                idx[1] = -parseInt( nth.substring(p + 1) ); 
     714                                        } 
     715                                } else 
     716                                        idx[1] = parseInt(nth); 
     717                        } 
     718                        return true; 
     719                } 
     720 
    635721                public static function htmlAttributeHasCaseInsensitiveValue(attr:QualifiedName):Boolean 
    636722                { 
  • lang/actionscript/ascss/src/css/RenderStyle.as

    r12321 r15905  
    66                private var mAffectedByHoverRules:Boolean = false; 
    77                private var mEmpty:Boolean = true; 
     8                private var mChildIndex:uint = 0; 
    89 
    910                public static const PseudoUnknown:uint = 0; 
     
    4546                } 
    4647 
     48                public function set childIndex(i:uint):void 
     49                { 
     50                        mChildIndex = i; 
     51                } 
     52 
     53                public function get childIndex():uint 
     54                { 
     55                        return mChildIndex; 
     56                } 
     57 
    4758                public function setPropertyById(propId:int, value:CSSValue):void 
    4859                { 
  • lang/actionscript/ascss/src/css/Value.as

    r10659 r15905  
    1919                public var fValue:Number; 
    2020                public var iValue:int; 
     21                public var parseFunction:ParseFunction; 
    2122 
    2223                public function set string(s:String):void