cssstyleselector.cpp

来自「monqueror一个很具有参考价值的源玛」· C++ 代码 · 共 1,977 行 · 第 1/5 页

CPP
1,977
字号
    int d = r1->selector->specificity() - r2->selector->specificity();    if(d) return d;    return r1->index - r2->index;}void CSSStyleSelectorList::append(StyleSheetImpl *sheet){    if(!sheet || !sheet->isCSSStyleSheet()) return;    int len = sheet->length();    for(int i = 0; i< len; i++)    {        StyleBaseImpl *item = sheet->item(i);        if(item->isStyleRule())        {            CSSStyleRuleImpl *r = static_cast<CSSStyleRuleImpl *>(item);            QList<CSSSelector> *s = r->selector();            for(int j = 0; j < (int)s->count(); j++)            {                CSSOrderedRule *rule = new CSSOrderedRule(r, s->at(j), count());                QList<CSSOrderedRule>::append(rule);                //kdDebug( 6080 ) << "appending StyleRule!" << endl;            }        }        else if(item->isImportRule())        {            CSSImportRuleImpl *import = static_cast<CSSImportRuleImpl *>(item);            // ### check media type            StyleSheetImpl *importedSheet = import->styleSheet();            append(importedSheet);        }        // ### include media, import rules and other    }    sort();}void CSSStyleSelectorList::append(CSSStyleRuleImpl *rule){    QList<CSSSelector> *s = rule->selector();    for(int j = 0; j < (int)s->count(); j++)    {        CSSOrderedRule *r = new CSSOrderedRule(rule, s->at(j), count());        inSort(r);    }}void CSSStyleSelectorList::collect(CSSOrderedPropertyList *propsToApply, DOM::ElementImpl *e,                                   int offset, int important ){    int i;    int num = count();    for(i = 0; i< num; i++)    {        if(at(i)->checkSelector(e))        {            //kdDebug( 6080 ) << "found matching rule for element " << e->id() << endl;            CSSStyleDeclarationImpl *decl = at(i)->rule->declaration();            propsToApply->append(decl, offset + i, important);        }    }}// -------------------------------------------------------------------------CSSOrderedPropertyList::CSSOrderedPropertyList(){    setAutoDelete(true);}int CSSOrderedPropertyList::compareItems(QCollection::Item i1, QCollection::Item i2){    return static_cast<CSSOrderedProperty *>(i1)->priority        - static_cast<CSSOrderedProperty *>(i2)->priority;}void CSSOrderedPropertyList::append(DOM::CSSStyleDeclarationImpl *decl, int offset, int important){    QList<CSSProperty> *values = decl->values();    if(!values) return;    int len = values->count();    for(int i = 0; i < len; i++)    {        int thisOffset = offset;        CSSProperty *prop = values->at(i);        if(prop->m_bImportant) thisOffset += important;        // give special priority to font-xxx, color properties        switch(prop->m_id)        {        case CSS_PROP_FONT_SIZE:        case CSS_PROP_FONT:        case CSS_PROP_COLOR:            // these have to be applied first, because other properties use the computed            // values of these porperties.            break;        default:            // don't use 0x80000000, that is negative usually            thisOffset += 0x40000000;            break;        }        append(prop, thisOffset);    }}void CSSOrderedPropertyList::append(DOM::CSSProperty *prop, int priority){    QList<CSSOrderedProperty>::append(new CSSOrderedProperty(prop, priority));}// -------------------------------------------------------------------------------------// this is mostly boring stuff on how to apply a certain rule to the renderstyle...void khtml::applyRule(khtml::RenderStyle *style, DOM::CSSProperty *prop, DOM::ElementImpl *e, MGHTMLPart* part){    CSSValueImpl *value = prop->value();    //kdDebug( 6080 ) << "applying property " << prop->m_id << endl;    CSSPrimitiveValueImpl *primitiveValue = 0;    if(value->isPrimitiveValue()) primitiveValue = static_cast<CSSPrimitiveValueImpl *>(value);    Length l;    bool apply = false;    // here follows a long list, defining how to aplly certain properties to the style object.    // rather boring stuff...    switch(prop->m_id)    {// ident only properties    case CSS_PROP_BACKGROUND_ATTACHMENT://        kdDebug(0) << "background attachment" << endl;        if(value->valueType() == CSSValue::CSS_INHERIT)        {            if(!e->parentNode()) return;            style->setBackgroundAttachment(e->parentNode()->style()->backgroundAttachment());            return;        }        if(!primitiveValue) break;        switch(primitiveValue->getIdent())        {        case CSS_VAL_FIXED:            {                style->setBackgroundAttachment(false);                DocumentImpl *doc = e->ownerDocument();                if(doc && doc->view())                    doc->view()->useSlowRepaints();                break;            }        case CSS_VAL_SCROLL:            style->setBackgroundAttachment(true);            break;        default:            return;        }    case CSS_PROP_BACKGROUND_REPEAT:    {        if(value->valueType() == CSSValue::CSS_INHERIT) {            if(!e->parentNode()) return;            style->setBackgroundRepeat(e->parentNode()->style()->backgroundRepeat());            return;        }        if(!primitiveValue) return;        EBackgroundRepeat r = REPEAT;        switch(primitiveValue->getIdent())        {        case CSS_VAL_REPEAT:            r = REPEAT; break;        case CSS_VAL_REPEAT_X://	  kdDebug(0) << "repeat-x!!!!!!!!!!!" << endl;            r = REPEAT_X; break;        case CSS_VAL_REPEAT_Y:            r = REPEAT_Y; break;        case CSS_VAL_NO_REPEAT:            r = NO_REPEAT; break;        default:            return;        }        style->setBackgroundRepeat(r);        break;    }    case CSS_PROP_BORDER_COLLAPSE:        if(value->valueType() == CSSValue::CSS_INHERIT)        {            if(!e->parentNode()) return;            style->setBorderCollapse(e->parentNode()->style()->borderCollapse());            break;        }        if(!primitiveValue) break;        switch(primitiveValue->getIdent())        {        case CSS_VAL_COLLAPSE:            style->setBorderCollapse(true);            break;        case CSS_VAL_SCROLL:            style->setBorderCollapse(false);            break;        default:            return;        }    case CSS_PROP_BORDER_TOP_STYLE:    case CSS_PROP_BORDER_RIGHT_STYLE:    case CSS_PROP_BORDER_BOTTOM_STYLE:    case CSS_PROP_BORDER_LEFT_STYLE:    {        if(value->valueType() == CSSValue::CSS_INHERIT)        {            if(!e->parentNode()) return;            switch(prop->m_id)            {            case CSS_PROP_BORDER_TOP_STYLE:                style->setBorderTopStyle(e->parentNode()->style()->borderTopStyle());                return;            case CSS_PROP_BORDER_RIGHT_STYLE:                style->setBorderRightStyle(e->parentNode()->style()->borderRightStyle());                return;            case CSS_PROP_BORDER_BOTTOM_STYLE:                style->setBorderBottomStyle(e->parentNode()->style()->borderBottomStyle());                return;            case CSS_PROP_BORDER_LEFT_STYLE:                style->setBorderLeftStyle(e->parentNode()->style()->borderLeftStyle());                return;            }        }        if(!primitiveValue) return;        EBorderStyle s = BNONE;        switch(primitiveValue->getIdent())        {        case CSS_VAL_NONE:            s = BNONE; break;        case CSS_VAL_HIDDEN:            s = BHIDDEN; break;        case CSS_VAL_DOTTED:            s = DOTTED; break;        case CSS_VAL_DASHED:            s = DASHED; break;        case CSS_VAL_SOLID:            s = SOLID; break;        case CSS_VAL_DOUBLE:            s = DOUBLE; break;        case CSS_VAL_GROOVE:            s = GROOVE; break;        case CSS_VAL_RIDGE:            s = RIDGE; break;        case CSS_VAL_INSET:            s = INSET; break;        case CSS_VAL_OUTSET:            s = OUTSET; break;        default:            return;        }        switch(prop->m_id)        {        case CSS_PROP_BORDER_TOP_STYLE:            style->setBorderTopStyle(s); return;        case CSS_PROP_BORDER_RIGHT_STYLE:            style->setBorderRightStyle(s); return;        case CSS_PROP_BORDER_BOTTOM_STYLE:            style->setBorderBottomStyle(s); return;        case CSS_PROP_BORDER_LEFT_STYLE:            style->setBorderLeftStyle(s); return;        default:            return;        }        return;    }    case CSS_PROP_CAPTION_SIDE:    {        if(value->valueType() == CSSValue::CSS_INHERIT)        {            if(!e->parentNode()) return;            style->setCaptionSide(e->parentNode()->style()->captionSide());            break;        }        if(!primitiveValue) break;        ECaptionSide c = CAPTOP;        switch(primitiveValue->getIdent())        {        case CSS_VAL_LEFT:            c = CAPLEFT; break;        case CSS_VAL_RIGHT:            c = CAPRIGHT; break;        case CSS_VAL_TOP:            c = CAPTOP; break;        case CSS_VAL_BOTTOM:            c = CAPBOTTOM; break;        default:            return;        }        style->setCaptionSide(c);        return;    }    case CSS_PROP_CLEAR:    {        if(value->valueType() == CSSValue::CSS_INHERIT)        {            if(!e->parentNode()) return;            style->setClear(e->parentNode()->style()->clear());            break;        }        if(!primitiveValue) break;        EClear c = CNONE;        switch(primitiveValue->getIdent())        {        case CSS_VAL_LEFT:            c = CLEFT; break;        case CSS_VAL_RIGHT:            c = CRIGHT; break;        case CSS_VAL_BOTH:            c = CBOTH; break;        default:            return;        }        style->setClear(c);        return;    }    case CSS_PROP_DIRECTION:    {        if(value->valueType() == CSSValue::CSS_INHERIT)        {            if(!e->parentNode()) return;            style->setDirection(e->parentNode()->style()->direction());            break;        }        if(!primitiveValue) break;        EDirection d = LTR;        switch(primitiveValue->getIdent())        {        case CSS_VAL_LTR:            d = LTR; break;        case CSS_VAL_RTL:            d = RTL; break;        default:            return;        }        style->setDirection(d);        return;    }    case CSS_PROP_DISPLAY:    {        if(value->valueType() == CSSValue::CSS_INHERIT)        {            if(!e->parentNode()) return;            style->setDisplay(e->parentNode()->style()->display());            break;        }        if(!primitiveValue) break;        EDisplay d = INLINE;        switch(primitiveValue->getIdent())        {        case CSS_VAL_INLINE:            break;        case CSS_VAL_BLOCK:            d = BLOCK; break;        case CSS_VAL_LIST_ITEM:            d = LIST_ITEM; break;        case CSS_VAL_RUN_IN:            // ### we don't support run-in and compact so let's completely ignore the vlaues.            return;            d = RUN_IN; break;        case CSS_VAL_COMPACT:            return;            d = COMPACT; break;        case CSS_VAL_MARKER:            return;            d = MARKER; break;        case CSS_VAL_TABLE:            d = TABLE; break;        case CSS_VAL_INLINE_TABLE:            d = INLINE_TABLE; break;        case CSS_VAL_TABLE_ROW_GROUP:            d = TABLE_ROW_GROUP; break;        case CSS_VAL_TABLE_HEADER_GROUP:            d = TABLE_HEADER_GROUP; break;        case CSS_VAL_TABLE_FOOTER_GROUP:            d = TABLE_FOOTER_GROUP; break;        case CSS_VAL_TABLE_ROW:            d = TABLE_ROW; break;        case CSS_VAL_TABLE_COLUMN_GROUP:            d = TABLE_COLUMN_GROUP; break;        case CSS_VAL_TABLE_COLUMN:            d = TABLE_COLUMN; break;        case CSS_VAL_TABLE_CELL:            d = TABLE_CELL; break;        case CSS_VAL_TABLE_CAPTION:            d = TABLE_CAPTION; break;        case CSS_VAL_NONE:            d = NONE; break;        default:            break;        }        //kdDebug( 6080 ) << "setting display to " << d << endl;        style->setDisplay(d);

⌨️ 快捷键说明

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