cssstyleselector.cpp

来自「将konqueror浏览器移植到ARM9 2410中」· C++ 代码 · 共 1,995 行 · 第 1/5 页

CPP
1,995
字号
    {        CSSProperty *prop = values->at(i);	Source source = regular;	if( prop->m_bImportant ) source = important;	if( prop->nonCSSHint ) source = NonCSSHint;	bool first = false;        // 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:        case CSS_PROP_BACKGROUND_IMAGE:            // these have to be applied first, because other properties use the computed            // values of these porperties.	    first = true;            break;        default:            break;        }	QList<CSSOrderedProperty>::append(new CSSOrderedProperty(prop, selector,								 first, source, specificity,								 count() ));    }}// -------------------------------------------------------------------------------------// this is mostly boring stuff on how to apply a certain rule to the renderstyle...static Length convertToLength( CSSPrimitiveValueImpl *primitiveValue, RenderStyle *style, DOM::DocumentImpl *doc, bool *ok = 0 ){    Length l;    if ( !primitiveValue ) {	if ( *ok )	    *ok = false;    } else {	int type = primitiveValue->primitiveType();	if(type > CSSPrimitiveValue::CSS_PERCENTAGE && type < CSSPrimitiveValue::CSS_DEG)	    l = Length(primitiveValue->computeLength(style, doc), Fixed);	else if(type == CSSPrimitiveValue::CSS_PERCENTAGE)	    l = Length(int(primitiveValue->getFloatValue(CSSPrimitiveValue::CSS_PERCENTAGE)), Percent);	else if(type == CSSPrimitiveValue::CSS_NUMBER)	    l = Length(int(primitiveValue->getFloatValue(CSSPrimitiveValue::CSS_NUMBER)*100), Percent);	else if ( *ok )	    *ok = false;    }    return l;}void khtml::applyRule(khtml::RenderStyle *style, DOM::CSSProperty *prop, DOM::ElementImpl *e){    CSSValueImpl *value = prop->value();    DOM::DocumentImpl *doc = e->ownerDocument();    QPaintDeviceMetrics *paintDeviceMetrics = doc->paintDeviceMetrics();    //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:        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);		// only use slow repaints if we actually have a background pixmap                if( style->backgroundImage() )                    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;	switch(primitiveValue->getIdent())	{	case CSS_VAL_REPEAT:	    style->setBackgroundRepeat( REPEAT );	    break;	case CSS_VAL_REPEAT_X:	    style->setBackgroundRepeat( REPEAT_X );	    break;	case CSS_VAL_REPEAT_Y:	    style->setBackgroundRepeat( REPEAT_Y );	    break;	case CSS_VAL_NO_REPEAT:	    style->setBackgroundRepeat( NO_REPEAT );	    break;	default:	    return;	}    }    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:    case CSS_PROP_OUTLINE_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;            case CSS_PROP_OUTLINE_STYLE:                style->setOutlineStyle(e->parentNode()->style()->outlineStyle());                return;            }        }        if(!primitiveValue) return;	EBorderStyle s = (EBorderStyle) (primitiveValue->getIdent() - CSS_VAL_NONE);        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;        case CSS_PROP_OUTLINE_STYLE:            style->setOutlineStyle(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;        style->setDirection( (EDirection) (primitiveValue->getIdent() - CSS_VAL_LTR) );        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;	int id = primitiveValue->getIdent();	EDisplay d;	if ( id == CSS_VAL_NONE) {	    d = NONE;	} else if ( id == CSS_VAL_RUN_IN || id == CSS_VAL_COMPACT ||		    id == CSS_VAL_MARKER ) {	    // these are not supported at the moment, so we just ignore them.	    return;	} else {	    d = EDisplay(primitiveValue->getIdent() - CSS_VAL_INLINE);	}        style->setDisplay(d);        //kdDebug( 6080 ) << "setting display to " << d << endl;        break;    }    case CSS_PROP_EMPTY_CELLS:        break;    case CSS_PROP_FLOAT:    {        if(value->valueType() == CSSValue::CSS_INHERIT)        {            if(!e->parentNode()) return;            style->setFloating(e->parentNode()->style()->floating());            return;        }        if(!primitiveValue) return;        EFloat f;        switch(primitiveValue->getIdent())        {        case CSS_VAL_LEFT:            f = FLEFT; break;        case CSS_VAL_RIGHT:            f = FRIGHT; break;        case CSS_VAL_NONE:        case CSS_VAL_CENTER:  //Non standart CSS-Value            f = FNONE; break;        default:            return;        }        if (f!=FNONE && style->display()==LIST_ITEM)            style->setDisplay(BLOCK);        style->setFloating(f);        break;    }        break;    case CSS_PROP_FONT_STRETCH:        break;    case CSS_PROP_FONT_STYLE:    {        QFont f = style->font();        if(value->valueType() == CSSValue::CSS_INHERIT)        {            if(!e->parentNode()) return;            f.setItalic(e->parentNode()->style()->font().italic());            style->setFont(f);            return;        }        if(!primitiveValue) return;        switch(primitiveValue->getIdent())        {            // ### oblique is the same as italic for the moment...        case CSS_VAL_OBLIQUE:        case CSS_VAL_ITALIC:            f.setItalic(true);            break;        case CSS_VAL_NORMAL:            f.setItalic(false);            break;        default:            return;        }        //KGlobal::charsets()->setQFont(f, e->ownerDocument()->view()->part()->settings()->charset);        style->setFont(f);        break;    }    case CSS_PROP_FONT_VARIANT:    {        if(value->valueType() == CSSValue::CSS_INHERIT)        {            if(!e->parentNode()) return;            style->setFontVariant(e->parentNode()->style()->fontVariant());            return;        }        if(!primitiveValue) return;        switch(primitiveValue->getIdent()) {	    case CSS_VAL_NORMAL:		style->setFontVariant( FVNORMAL ); break;	    case CSS_VAL_SMALL_CAPS:		style->setFontVariant( SMALL_CAPS ); break;	    default:            return;        }	break;    }    case CSS_PROP_FONT_WEIGHT:    {        QFont f = style->font();        if(value->valueType() == CSSValue::CSS_INHERIT)        {            if(!e->parentNode()) return;            f.setWeight(e->parentNode()->style()->font().weight());            //KGlobal::charsets()->setQFont(f, e->ownerDocument()->view()->part()->settings()->charset);            style->setFont(f);            return;        }        if(!primitiveValue) return;        if(primitiveValue->getIdent())        {            switch(primitiveValue->getIdent())            {                // ### we just support normal and bold fonts at the moment...                // setWeight can actually accept values between 0 and 99...            case CSS_VAL_BOLD:            case CSS_VAL_BOLDER:                f.setWeight(QFont::Bold);                break;            case CSS_VAL_NORMAL:            case CSS_VAL_LIGHTER:                f.setWeight(QFont::Normal);                break;            default:                return;            }        }        else        {            // ### fix parsing of 100-900 values in parser, apply them here        }        //KGlobal::charsets()->setQFont(f, e->ownerDocument()->view()->part()->settings()->charset);

⌨️ 快捷键说明

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