cssparser.cpp

来自「konqueror3 embedded版本, KDE环境下的当家浏览器的嵌入式版」· C++ 代码 · 共 1,746 行 · 第 1/5 页

CPP
1,746
字号
        b = (unitflags & FNumber);        if ( !b && ( (unitflags & FLength) && (value->fValue == 0 || !strict ) ) ) {            value->unit = CSSPrimitiveValue::CSS_PX;            b = true;        }        if ( !b && ( unitflags & FInteger ) &&             (value->fValue - (int)value->fValue) < 0.001 )            b = true;        break;    case CSSPrimitiveValue::CSS_PERCENTAGE:        b = (unitflags & FPercent);        break;    case Value::Q_EMS:    case CSSPrimitiveValue::CSS_EMS:    case CSSPrimitiveValue::CSS_EXS:    case CSSPrimitiveValue::CSS_PX:    case CSSPrimitiveValue::CSS_CM:    case CSSPrimitiveValue::CSS_MM:    case CSSPrimitiveValue::CSS_IN:    case CSSPrimitiveValue::CSS_PT:    case CSSPrimitiveValue::CSS_PC:        b = (unitflags & FLength);        break;    case CSSPrimitiveValue::CSS_MS:    case CSSPrimitiveValue::CSS_S:        b = (unitflags & FTime);        break;    case CSSPrimitiveValue::CSS_DEG:    case CSSPrimitiveValue::CSS_RAD:    case CSSPrimitiveValue::CSS_GRAD:    case CSSPrimitiveValue::CSS_HZ:    case CSSPrimitiveValue::CSS_KHZ:    case CSSPrimitiveValue::CSS_DIMENSION:    default:        break;    }    return b;}bool CSSParser::parseValue( int propId, bool important, int expected ){    if ( !valueList ) return false;    Value *value = valueList->current();    if ( !value )        return false;    int id = value->id;    if ( id == CSS_VAL_INHERIT && expected == 1 ) {        addProperty( propId, new CSSInheritedValueImpl(), important );        return true;    } else if (id == CSS_VAL_INITIAL && expected == 1 ) {        addProperty(propId, new CSSInitialValueImpl(), important);        return true;    }    bool valid_primitive = false;    CSSValueImpl *parsedValue = 0;    switch(propId) {        /* The comment to the left defines all valid value of this properties as defined         * in CSS 2, Appendix F. Property index         */        /* All the CSS properties are not supported by the renderer at the moment.         * Note that all the CSS2 Aural properties are only checked, if CSS_AURAL is defined         * (see parseAuralValues). As we don't support them at all this seems reasonable.         */    case CSS_PROP_SIZE:                 // <length>{1,2} | auto | portrait | landscape | inherit//     case CSS_PROP_PAGE:                 // <identifier> | auto // ### CHECK        // ### To be done        if (id)            valid_primitive = true;        break;    case CSS_PROP_UNICODE_BIDI:         // normal | embed | bidi-override | inherit        if ( id == CSS_VAL_NORMAL ||             id == CSS_VAL_EMBED ||             id == CSS_VAL_BIDI_OVERRIDE )            valid_primitive = true;        break;    case CSS_PROP_POSITION:             // static | relative | absolute | fixed | inherit        if ( id == CSS_VAL_STATIC ||             id == CSS_VAL_RELATIVE ||             id == CSS_VAL_ABSOLUTE ||              id == CSS_VAL_FIXED )            valid_primitive = true;        break;    case CSS_PROP_PAGE_BREAK_AFTER:     // auto | always | avoid | left | right | inherit    case CSS_PROP_PAGE_BREAK_BEFORE:    // auto | always | avoid | left | right | inherit        if ( id == CSS_VAL_AUTO ||             id == CSS_VAL_ALWAYS ||             id == CSS_VAL_AVOID ||              id == CSS_VAL_LEFT ||              id == CSS_VAL_RIGHT )            valid_primitive = true;        break;    case CSS_PROP_PAGE_BREAK_INSIDE:    // avoid | auto | inherit        if ( id == CSS_VAL_AUTO ||             id == CSS_VAL_AVOID )            valid_primitive = true;        break;    case CSS_PROP_EMPTY_CELLS:          // show | hide | inherit        if ( id == CSS_VAL_SHOW ||             id == CSS_VAL_HIDE )            valid_primitive = true;        break;    case CSS_PROP_QUOTES:               // [<string> <string>]+ | none | inherit        if (id == CSS_VAL_NONE) {            valid_primitive = true;        } else {            QuotesValueImpl *quotes = new QuotesValueImpl;            bool is_valid = true;            QString open, close;            Value *val=valueList->current();            while (val) {                if (val->unit == CSSPrimitiveValue::CSS_STRING)                    open = qString(val->string);                else {                    is_valid = false;                    break;                }                valueList->next();                val=valueList->current();                if (val && val->unit == CSSPrimitiveValue::CSS_STRING)                    close = qString(val->string);                else {                    is_valid = false;                    break;                }                quotes->addLevel(open, close);                valueList->next();                val=valueList->current();            }            if (is_valid)                parsedValue = quotes;            //valueList->next();        }        break;    case CSS_PROP_CONTENT:     //  normal | none | inherit |        // [ <string> | <uri> | <counter> | attr(X) | open-quote | close-quote | no-open-quote | no-close-quote ]+        if ( id == CSS_VAL_NORMAL || id == CSS_VAL_NONE)            valid_primitive = true;        else            return parseContent( propId, important );        break;    case CSS_PROP_WHITE_SPACE:          // normal | pre | nowrap | pre-wrap | pre-line | inherit        if ( id == CSS_VAL_NORMAL ||             id == CSS_VAL_PRE ||             id == CSS_VAL_PRE_WRAP ||             id == CSS_VAL_PRE_LINE ||             id == CSS_VAL_NOWRAP )            valid_primitive = true;        break;    case CSS_PROP_CLIP:                 // <shape> | auto | inherit        if ( id == CSS_VAL_AUTO )            valid_primitive = true;        else if ( value->unit == Value::Function )            return parseShape( propId, important );        break;    /* Start of supported CSS properties with validation. This is needed for parseShortHand to work     * correctly and allows optimization in khtml::applyRule(..)     */    case CSS_PROP_CAPTION_SIDE:         // top | bottom | left | right | inherit        // Left and right were deprecated in CSS 2.1 and never supported by KHTML        if ( /* id == CSS_VAL_LEFT || id == CSS_VAL_RIGHT || */            id == CSS_VAL_TOP || id == CSS_VAL_BOTTOM)            valid_primitive = true;        break;    case CSS_PROP_BORDER_COLLAPSE:      // collapse | separate | inherit        if ( id == CSS_VAL_COLLAPSE || id == CSS_VAL_SEPARATE )            valid_primitive = true;        break;    case CSS_PROP_VISIBILITY:           // visible | hidden | collapse | inherit        if (id == CSS_VAL_VISIBLE || id == CSS_VAL_HIDDEN || id == CSS_VAL_COLLAPSE)            valid_primitive = true;        break;    case CSS_PROP_OVERFLOW:             // visible | hidden | scroll | auto | marquee | inherit        if (id == CSS_VAL_VISIBLE || id == CSS_VAL_HIDDEN || id == CSS_VAL_SCROLL || id == CSS_VAL_AUTO ||            id == CSS_VAL_MARQUEE)            valid_primitive = true;        break;    case CSS_PROP_LIST_STYLE_POSITION:  // inside | outside | inherit        if ( id == CSS_VAL_INSIDE || id == CSS_VAL_OUTSIDE )            valid_primitive = true;        break;    case CSS_PROP_LIST_STYLE_TYPE:        // disc | circle | square | decimal | decimal-leading-zero | lower-roman |        // upper-roman | lower-greek | lower-alpha | lower-latin | upper-alpha |        // upper-latin | hebrew | armenian | georgian | cjk-ideographic | hiragana |        // katakana | hiragana-iroha | katakana-iroha | none | inherit        if ((id >= CSS_VAL_DISC && id <= CSS_VAL__KHTML_CLOSE_QUOTE) || id == CSS_VAL_NONE)            valid_primitive = true;        break;    case CSS_PROP_DISPLAY:        // inline | block | list-item | run-in | inline-block | -khtml-ruler | table |        // inline-table | table-row-group | table-header-group | table-footer-group | table-row |        // table-column-group | table-column | table-cell | table-caption | none | inherit        if ((id >= CSS_VAL_INLINE && id <= CSS_VAL_TABLE_CAPTION) || id == CSS_VAL_NONE)            valid_primitive = true;        break;    case CSS_PROP_DIRECTION:            // ltr | rtl | inherit        if ( id == CSS_VAL_LTR || id == CSS_VAL_RTL )            valid_primitive = true;        break;    case CSS_PROP_TEXT_TRANSFORM:       // capitalize | uppercase | lowercase | none | inherit        if ((id >= CSS_VAL_CAPITALIZE && id <= CSS_VAL_LOWERCASE) || id == CSS_VAL_NONE)            valid_primitive = true;        break;    case CSS_PROP_FLOAT:                // left | right | none | khtml_left | khtml_right | inherit + center for buggy CSS        if ( id == CSS_VAL_LEFT || id == CSS_VAL_RIGHT || id == CSS_VAL__KHTML_LEFT ||             id == CSS_VAL__KHTML_RIGHT ||id == CSS_VAL_NONE || id == CSS_VAL_CENTER)            valid_primitive = true;        break;    case CSS_PROP_CLEAR:                // none | left | right | both | inherit        if ( id == CSS_VAL_NONE || id == CSS_VAL_LEFT ||             id == CSS_VAL_RIGHT|| id == CSS_VAL_BOTH)            valid_primitive = true;        break;    case CSS_PROP_TEXT_ALIGN:        // left | right | center | justify | khtml_left | khtml_right | khtml_center | <string> | inherit        if ( ( id >= CSS_VAL__KHTML_AUTO && id <= CSS_VAL__KHTML_CENTER ) ||             value->unit == CSSPrimitiveValue::CSS_STRING )            valid_primitive = true;        break;    case CSS_PROP_OUTLINE_STYLE:        // <border-style> | inherit    case CSS_PROP_BORDER_TOP_STYLE:     //// <border-style> | inherit    case CSS_PROP_BORDER_RIGHT_STYLE:   //   Defined as:    none | hidden | dotted | dashed |    case CSS_PROP_BORDER_BOTTOM_STYLE:  //   solid | double | groove | ridge | inset | outset | -khtml-native    case CSS_PROP_BORDER_LEFT_STYLE:    ////        if (id >= CSS_VAL__KHTML_NATIVE && id <= CSS_VAL_DOUBLE)            valid_primitive = true;        break;    case CSS_PROP_FONT_WEIGHT:  // normal | bold | bolder | lighter | 100 | 200 | 300 | 400 |        // 500 | 600 | 700 | 800 | 900 | inherit        if (id >= CSS_VAL_NORMAL && id <= CSS_VAL_900) {            // Allready correct id            valid_primitive = true;        } else if ( validUnit( value, FInteger|FNonNeg, false ) ) {            int weight = (int)value->fValue;            if ( (weight % 100) )                break;            weight /= 100;            if ( weight >= 1 && weight <= 9 ) {                id = CSS_VAL_100 + weight - 1;                valid_primitive = true;            }        }        break;    case CSS_PROP_BORDER_SPACING:    {        const int properties[2] = { CSS_PROP__KHTML_BORDER_HORIZONTAL_SPACING,                                    CSS_PROP__KHTML_BORDER_VERTICAL_SPACING };        int num = valueList->numValues;        if (num == 1) {            if (!parseValue(properties[0], important)) return false;            CSSValueImpl* value = parsedProperties[numParsedProperties-1]->value();            addProperty(properties[1], value, important);            return true;        }        else if (num == 2) {            if (!parseValue(properties[0], important, 2)) return false;            if (!parseValue(properties[1], important, 1)) return false;            return true;        }        return false;    }    case CSS_PROP__KHTML_BORDER_HORIZONTAL_SPACING:    case CSS_PROP__KHTML_BORDER_VERTICAL_SPACING:        valid_primitive = validUnit(value, FLength|FNonNeg, strict&(!nonCSSHint));        break;    case CSS_PROP_SCROLLBAR_FACE_COLOR:         // IE5.5    case CSS_PROP_SCROLLBAR_SHADOW_COLOR:       // IE5.5    case CSS_PROP_SCROLLBAR_HIGHLIGHT_COLOR:    // IE5.5    case CSS_PROP_SCROLLBAR_3DLIGHT_COLOR:      // IE5.5    case CSS_PROP_SCROLLBAR_DARKSHADOW_COLOR:   // IE5.5    case CSS_PROP_SCROLLBAR_TRACK_COLOR:        // IE5.5    case CSS_PROP_SCROLLBAR_ARROW_COLOR:        // IE5.5    case CSS_PROP_SCROLLBAR_BASE_COLOR:         // IE5.5        if ( strict )            break;        /* nobreak */    case CSS_PROP_OUTLINE_COLOR:        // <color> | invert | inherit        // outline has "invert" as additional keyword.        if ( propId == CSS_PROP_OUTLINE_COLOR && id == CSS_VAL_INVERT ) {            valid_primitive = true;            break;        }        /* nobreak */    case CSS_PROP_BACKGROUND_COLOR:     // <color> | inherit    case CSS_PROP_BORDER_TOP_COLOR:     // <color> | inherit    case CSS_PROP_BORDER_RIGHT_COLOR:   // <color> | inherit    case CSS_PROP_BORDER_BOTTOM_COLOR:  // <color> | inherit    case CSS_PROP_BORDER_LEFT_COLOR:    // <color> | inherit    case CSS_PROP_COLOR:                // <color> | inherit        if ( id == CSS_VAL__KHTML_TEXT || id == CSS_VAL_MENU ||             (id >= CSS_VAL_AQUA && id <= CSS_VAL_WINDOWTEXT ) ||             id == CSS_VAL_TRANSPARENT ||             (id >= CSS_VAL_GREY && id < CSS_VAL__KHTML_TEXT && (nonCSSHint|!strict) ) ) {            valid_primitive = true;        } else {            parsedValue = parseColor();            if ( parsedValue )                valueList->next();        }        break;    case CSS_PROP_CURSOR:        //  [ auto | crosshair | default | pointer | progress | move | e-resize | ne-resize |        // nw-resize | n-resize | se-resize | sw-resize | s-resize | w-resize | text |        // wait | help ] ] | inherit    // MSIE 5 compatibility :/        if ( !strict && id == CSS_VAL_HAND ) {            id = CSS_VAL_POINTER;            valid_primitive = true;        } else if ( id >= CSS_VAL_AUTO && id <= CSS_VAL_HELP )            valid_primitive = true;        break;    case CSS_PROP_BACKGROUND_ATTACHMENT:    case CSS_PROP_BACKGROUND_IMAGE:    case CSS_PROP_BACKGROUND_POSITION:    case CSS_PROP_BACKGROUND_POSITION_X:    case CSS_PROP_BACKGROUND_POSITION_Y:    case CSS_PROP_BACKGROUND_REPEAT: {

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?