cssstyleselector.cpp

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

CPP
1,879 行
字号
            QString str = value.string();            QString selStr = sel->value.string();	    if (strictParsing && !str.endsWith(selStr)) return false;	    if (!strictParsing) {	        int pos = str.length() - selStr.length();		if (pos < 0 || pos != str.find(selStr, pos, false) )		    return false;	    }            break;        }        case CSSSelector::Hyphen:        {            //kdDebug( 6080 ) << "checking for hyphen match" << endl;            QString str = value.string();            QString selStr = sel->value.string();            if(str.length() < selStr.length()) return false;            // Check if str begins with selStr:            if(str.find(selStr, 0, strictParsing) != 0) return false;            // It does. Check for exact match or following '-':            if(str.length() != selStr.length()                && str[selStr.length()] != '-') return false;            break;        }        case CSSSelector::PseudoClass:        case CSSSelector::PseudoElement:        case CSSSelector::None:            break;        }    }    if(sel->match == CSSSelector::PseudoClass || sel->match == CSSSelector::PseudoElement)    {	switch (sel->pseudoType()) {        // Pseudo classes:	case CSSSelector::PseudoEmpty:            // If e is not closed yet we don't know the number of children            if (!e->closed()) {                e->setRestyleSelfLate();                return false;            }            if (!e->firstChild())                return true;            break;	case CSSSelector::PseudoFirstChild: {	    // first-child matches the first child that is an element!            if (e->parentNode() && e->parentNode()->isElementNode()) {                DOM::NodeImpl* n = e->previousSibling();                while ( n && !n->isElementNode() )                    n = n->previousSibling();                if ( !n )                    return true;            }            break;        }        case CSSSelector::PseudoLastChild: {            // last-child matches the last child that is an element!            if (e->parentNode() && e->parentNode()->isElementNode()) {                if (!e->parentNode()->closed()) {                    e->setRestyleLate();                    static_cast<ElementImpl*>(e->parentNode())->setRestyleChildrenLate();                    return false;                }                DOM::NodeImpl* n = e->nextSibling();                while ( n && !n->isElementNode() )                    n = n->nextSibling();                if ( !n )                    return true;            }            break;        }        case CSSSelector::PseudoOnlyChild: {            // If both first-child and last-child apply, then only-child applies.            if (e->parentNode() && e->parentNode()->isElementNode()) {                if (!e->parentNode()->closed()) {                    e->setRestyleLate();                    static_cast<ElementImpl*>(e->parentNode())->setRestyleChildrenLate();                    return false;                }                DOM::NodeImpl* n = e->previousSibling();                while ( n && !n->isElementNode() )                    n = n->previousSibling();                if ( !n ) {                    n = e->nextSibling();                    while ( n && !n->isElementNode() )                        n = n->nextSibling();                    if ( !n )                        return true;                }            }            break;        }        case CSSSelector::PseudoNthChild: {	    // nth-child matches every (a*n+b)th element!            if (e->parentNode() && e->parentNode()->isElementNode()) {                int count = 1;                DOM::NodeImpl* n = e->previousSibling();                while ( n ) {                    if (n->isElementNode()) count++;                    n = n->previousSibling();                }                kdDebug(6080) << "NthChild " << count << "=" << sel->string_arg << endl;                if (matchNth(count,sel->string_arg.string()))                    return true;            }            break;        }        case CSSSelector::PseudoNthLastChild: {            if (e->parentNode() && e->parentNode()->isElementNode()) {                if (!e->parentNode()->closed()) {                    e->setRestyleLate();                    static_cast<ElementImpl*>(e->parentNode())->setRestyleChildrenLate();                    return false;                }                int count = 1;                DOM::NodeImpl* n = e->nextSibling();                while ( n ) {                    if (n->isElementNode()) count++;                    n = n->nextSibling();                }//                kdDebug(6080) << "NthLastChild " << count << "=" << sel->string_arg << endl;                if (matchNth(count,sel->string_arg.string()))                    return true;            }            break;        }	case CSSSelector::PseudoFirstOfType: {	    // first-of-type matches the first element of its type!            if (e->parentNode() && e->parentNode()->isElementNode()) {                const DOMString& type = e->tagName();                DOM::NodeImpl* n = e->previousSibling();                while ( n ) {                    if (n->isElementNode())                        if (static_cast<ElementImpl*>(n)->tagName() == type) break;                    n = n->previousSibling();                }                if ( !n )                    return true;            }            break;        }        case CSSSelector::PseudoLastOfType: {            // last-child matches the last child that is an element!            if (e->parentNode() && e->parentNode()->isElementNode()) {                if (!e->parentNode()->closed()) {                    e->setRestyleLate();                    static_cast<ElementImpl*>(e->parentNode())->setRestyleChildrenLate();                    return false;                }                const DOMString& type = e->tagName();                DOM::NodeImpl* n = e->nextSibling();                while ( n ) {                    if (n->isElementNode())                        if (static_cast<ElementImpl*>(n)->tagName() == type) break;                    n = n->nextSibling();                }                if ( !n )                    return true;            }            break;        }        case CSSSelector::PseudoOnlyOfType: {            // If both first-of-type and last-of-type apply, then only-of-type applies.            if (e->parentNode() && e->parentNode()->isElementNode()) {                if (!e->parentNode()->closed()) {                    e->setRestyleLate();                    static_cast<ElementImpl*>(e->parentNode())->setRestyleChildrenLate();                    return false;                }                const DOMString& type = e->tagName();                DOM::NodeImpl* n = e->previousSibling();                while ( n && !(n->isElementNode() && static_cast<ElementImpl*>(n)->tagName() == type))                    n = n->previousSibling();                if ( !n ) {                    n = e->nextSibling();                    while ( n && !(n->isElementNode() && static_cast<ElementImpl*>(n)->tagName() == type))                        n = n->nextSibling();                    if ( !n )                        return true;	        }            }	    break;        }        case CSSSelector::PseudoNthOfType: {	    // nth-of-type matches every (a*n+b)th element of this type!            if (e->parentNode() && e->parentNode()->isElementNode()) {                int count = 1;                const DOMString& type = e->tagName();                DOM::NodeImpl* n = e->previousSibling();                while ( n ) {                    if (n->isElementNode() && static_cast<ElementImpl*>(n)->tagName() == type) count++;                    n = n->previousSibling();                }//                kdDebug(6080) << "NthOfType " << count << "=" << sel->string_arg << endl;                if (matchNth(count,sel->string_arg.string()))                    return true;            }            break;        }        case CSSSelector::PseudoNthLastOfType: {            if (e->parentNode() && e->parentNode()->isElementNode()) {                if (!e->parentNode()->closed()) {                    e->setRestyleLate();                    static_cast<ElementImpl*>(e->parentNode())->setRestyleChildrenLate();                    return false;                }                int count = 1;                const DOMString& type = e->tagName();                DOM::NodeImpl* n = e->nextSibling();                while ( n ) {                    if (n->isElementNode() && static_cast<ElementImpl*>(n)->tagName() == type) count++;                    n = n->nextSibling();                }//                kdDebug(6080) << "NthLastOfType " << count << "=" << sel->string_arg << endl;                if (matchNth(count,sel->string_arg.string()))                    return true;            }            break;        }        case CSSSelector::PseudoTarget:            if (e == e->getDocument()->getCSSTarget())                return true;            break;	case CSSSelector::PseudoLink:	    if ( pseudoState == PseudoUnknown )                    checkPseudoState( encodedurl, e );	    if ( pseudoState == PseudoLink )		return true;	    break;	case CSSSelector::PseudoVisited:	    if ( pseudoState == PseudoUnknown )                    checkPseudoState( encodedurl, e );	    if ( pseudoState == PseudoVisited )		return true;	    break;        case CSSSelector::PseudoHover: {	    // If we're in quirks mode, then hover should never match anchors with no	    // href.  This is important for sites like wsj.com.	    if (strictParsing || e->id() != ID_A || e->hasAnchor()) {		if (element == e)		    style->setAffectedByHoverRules(true);		if (e->renderer()) {		    if (element != e)			e->renderer()->style()->setAffectedByHoverRules(true);		    if (e->renderer()->mouseInside())			return true;		}	    }	    break;            }	case CSSSelector::PseudoFocus:	    if (e && e->focused()) {		return true;	    }	    break;	case CSSSelector::PseudoActive:	    // If we're in quirks mode, then :active should never match anchors with no	    // href.	    if (strictParsing || e->id() != ID_A || e->hasAnchor()) {		if (element == e)		    style->setAffectedByActiveRules(true);		else if (e->renderer())		    e->renderer()->style()->setAffectedByActiveRules(true);		if (e->active())		    return true;	    }	    break;        case CSSSelector::PseudoRoot:            if (e == e->getDocument()->documentElement())                return true;            break;        case CSSSelector::PseudoLang: {            DOMString value = e->getAttribute(ATTR_LANG);            if (value.isNull()) return false;            QString langAttr = value.string();            QString langSel = sel->string_arg.string();            if(langAttr.length() < langSel.length()) return false;            if (!strictParsing) {                langAttr = langAttr.lower();                langSel = langSel.lower();            }//             kdDebug(6080) << ":lang " << langAttr << "=" << langSel << "?" << endl;            return (langAttr == langSel || langAttr.startsWith(langSel+"-"));        }        case CSSSelector::PseudoNot: {            // check the simple selector            for (CSSSelector* subSel = sel->simpleSelector; subSel;                 subSel = subSel->tagHistory) {                // :not cannot nest.  I don't really know why this is a restriction in CSS3,                // but it is, so let's honor it.                if (subSel->simpleSelector)                    break;                if (!checkOneSelector(subSel, e))                    return true;            }            break;        }        case CSSSelector::PseudoEnabled: {            if (e->isGenericFormElement()) {                HTMLGenericFormElementImpl *form;                form = static_cast<HTMLGenericFormElementImpl*>(e);                return !form->disabled();            }            break;        }        case CSSSelector::PseudoDisabled: {            if (e->isGenericFormElement()) {                HTMLGenericFormElementImpl *form;                form = static_cast<HTMLGenericFormElementImpl*>(e);                return form->disabled();            }            break;        }        case CSSSelector::PseudoContains: {            if (e->isHTMLElement()) {                if (!e->closed()) {                    e->setRestyleSelfLate();                    return false;                }                HTMLElementImpl *elem;                elem = static_cast<HTMLElementImpl*>(e);                DOMString s = elem->innerText();                QString selStr = sel->string_arg.string();//                kdDebug(6080) << ":contains(\"" << selStr << "\")" << " on \"" << s << "\"" << endl;                return s.string().contains(selStr);            }            break;        }	case CSSSelector::PseudoChecked:	case CSSSelector::PseudoIndeterminate:	    /* not supported for now */	case CSSSelector::PseudoOther:	    break;	// Pseudo-elements:	case CSSSelector::PseudoFirstLine:	    if ( subject ) {		dynamicPseudo=RenderStyle::FIRST_LINE;		return true;	    }	    break;	case CSSSelector::PseudoFirstLetter:	    if ( subject ) {		dynamicPseudo=RenderStyle::FIRST_LETTER;		return true;	    }	    break;	case CSSSelector::PseudoSelection:	    dynamicPseudo = RenderStyle::SELECTION;	    return true;	case CSSSelector::PseudoBefore:	    dynamicPseudo = RenderStyle::BEFORE;	    return true;	case CSSSelector::PseudoAfter:	    dynamicPseudo = RenderStyle::AFTER;	    return true;	case CSSSelector::PseudoNotParsed:	    assert(false);	    break;	}	return false;    }    // ### add the rest of the checks...    return true;}void CSSStyleSelector::clearLists(){    delete [] selectors;    if ( selectorCache ) {        for ( unsigned int i = 0; i < selectors_size; i++ )            delete [] selectorCache[i].props;        delete [] selectorCache;    }

⌨️ 快捷键说明

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