[SCM] WebKit Debian packaging branch, debian/unstable, updated. debian/1.1.15-1-40151-g37bb677

hyatt hyatt at 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sat Sep 26 08:25:25 UTC 2009


The following commit has been merged in the debian/unstable branch:
commit 157cb8a6ad02f4d3d459f0c39211bba6899f603d
Author: hyatt <hyatt at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Thu Feb 5 01:45:17 2004 +0000

    	Improve rule matching in the style system.  Filter out most rules up front, so that only a small
    	number of rules need to be walked for any given element.  Yields a ~4-5% improvement on the PLT.
    
            Reviewed by kocienda
    
            * khtml/css/css_base.cpp:
            (StyleBaseImpl::setParsedValue):
            (CSSSelector::specificity):
            (CSSSelector::extractPseudoType):
            (CSSSelector::operator == ):
            * khtml/css/css_base.h:
            (DOM::CSSSelector::CSSSelector):
            (DOM::CSSSelector::~CSSSelector):
            (DOM::CSSSelector::append):
            (DOM::CSSSelector::next):
            (DOM::CSSSelector::):
            (DOM::StyleBaseImpl::StyleBaseImpl):
            * khtml/css/css_ruleimpl.cpp:
            (CSSStyleRuleImpl::selectorText):
            (CSSRuleListImpl::insertRule):
            * khtml/css/css_ruleimpl.h:
            (DOM::CSSStyleRuleImpl::setSelector):
            (DOM::CSSStyleRuleImpl::selector):
            * khtml/css/css_stylesheetimpl.cpp:
            * khtml/css/css_stylesheetimpl.h:
            * khtml/css/css_valueimpl.cpp:
            (CSSStyleDeclarationImpl::getPropertyCSSValue):
            (CSSStyleDeclarationImpl::removeProperty):
            (CSSStyleDeclarationImpl::setProperty):
            (CSSStyleDeclarationImpl::setStringProperty):
            (CSSStyleDeclarationImpl::setImageProperty):
            (CSSStyleDeclarationImpl::setLengthProperty):
            (CSSStyleDeclarationImpl::cssText):
            (CSSStyleDeclarationImpl::setCssText):
            * khtml/css/css_valueimpl.h:
            (DOM::CSSStyleDeclarationImpl::node):
            (DOM::CSSProperty::CSSProperty):
            (DOM::CSSProperty::id):
            (DOM::CSSProperty::isImportant):
            * khtml/css/cssparser.cpp:
            (CSSParser::CSSParser):
            (ParseString::lower):
            (CSSParser::parseValue):
            (CSSParser::parseDeclaration):
            (CSSParser::addProperty):
            (CSSParser::parseShadow):
            * khtml/css/cssparser.h:
            * khtml/css/cssstyleselector.cpp:
            (khtml::):
            (khtml::CSSStyleSelector::CSSStyleSelector):
            (khtml::CSSStyleSelector::init):
            (khtml::CSSStyleSelector::~CSSStyleSelector):
            (khtml::CSSStyleSelector::loadDefaultStyle):
            (khtml::CSSStyleSelector::addMatchedRule):
            (khtml::CSSStyleSelector::addMatchedDeclaration):
            (khtml::CSSStyleSelector::matchRules):
            (khtml::CSSStyleSelector::matchRulesForList):
            (khtml::operator >):
            (khtml::operator <=):
            (khtml::CSSStyleSelector::sortMatchedRules):
            (khtml::CSSStyleSelector::initForStyleResolve):
            (khtml::CSSStyleSelector::styleForElement):
            (khtml::CSSStyleSelector::pseudoStyleForElement):
            (khtml::checkPseudoState):
            (khtml::CSSStyleSelector::checkSelector):
            (khtml::CSSStyleSelector::checkOneSelector):
            (khtml::CSSRuleSet::CSSRuleSet):
            (khtml::CSSRuleSet::addToRuleSet):
            (khtml::CSSRuleSet::addRule):
            (khtml::CSSRuleSet::addRulesFromSheet):
            (khtml::CSSStyleSelector::applyDeclarations):
            (khtml::CSSStyleSelector::applyProperty):
            (khtml::CSSStyleSelector::smallerFontSize):
            (khtml::CSSStyleSelector::getColorFromPrimitiveValue):
            * khtml/css/cssstyleselector.h:
            (khtml::):
            (khtml::CSSRuleData::m_next):
            (khtml::CSSRuleData::~CSSRuleData):
            (khtml::CSSRuleData::position):
            (khtml::CSSRuleData::rule):
            (khtml::CSSRuleData::selector):
            (khtml::CSSRuleData::next):
            (khtml::CSSRuleDataList::CSSRuleDataList):
            (khtml::CSSRuleDataList::~CSSRuleDataList):
            (khtml::CSSRuleDataList::first):
            (khtml::CSSRuleDataList::last):
            (khtml::CSSRuleDataList::append):
            (khtml::CSSRuleSet::~CSSRuleSet):
            (khtml::CSSRuleSet::getIDRules):
            (khtml::CSSRuleSet::getClassRules):
            (khtml::CSSRuleSet::getTagRules):
            (khtml::CSSRuleSet::getUniversalRules):
            * khtml/css/cssvalues.c:
            (hash_val):
            (findValue):
            * khtml/css/cssvalues.h:
            * khtml/css/cssvalues.in:
            * khtml/css/html4.css:
            * khtml/css/parser.cpp:
            * khtml/css/parser.h:
            * khtml/css/parser.y:
            * khtml/dom/dom_element.cpp:
            (Element::style):
            * khtml/html/html_baseimpl.cpp:
            (HTMLBodyElementImpl::HTMLBodyElementImpl):
            (HTMLBodyElementImpl::~HTMLBodyElementImpl):
            (HTMLBodyElementImpl::createLinkDecl):
            (HTMLBodyElementImpl::parseAttribute):
            * khtml/html/html_baseimpl.h:
            * khtml/html/html_elementimpl.cpp:
            (HTMLNamedAttrMapImpl::parseClassAttribute):
            (HTMLElementImpl::HTMLElementImpl):
            (HTMLElementImpl::~HTMLElementImpl):
            (HTMLElementImpl::createInlineStyleDecl):
            (HTMLElementImpl::createMappedAttributeDecl):
            (HTMLElementImpl::parseAttribute):
            (HTMLElementImpl::getClassList):
            (HTMLElementImpl::addCSSProperty):
            (HTMLElementImpl::addCSSStringProperty):
            (HTMLElementImpl::addCSSImageProperty):
            (HTMLElementImpl::addCSSLength):
            (HTMLElementImpl::addHTMLColor):
            (HTMLElementImpl::removeCSSProperty):
            * khtml/html/html_elementimpl.h:
            (DOM::HTMLNamedAttrMapImpl::getClassList):
            (DOM::HTMLElementImpl::inlineStyleDecl):
            (DOM::HTMLElementImpl::attributeStyleDecl):
            (DOM::HTMLElementImpl::getInlineStyleDecl):
            * khtml/html/html_tableimpl.cpp:
            (HTMLTableElementImpl::createSharedCellDecls):
            (HTMLTableCellElementImpl::additionalAttributeStyleDecl):
            * khtml/html/html_tableimpl.h:
            * khtml/xml/dom_atomicstring.cpp:
            (DOM::AtomicString::add):
            (DOM::AtomicString::remove):
            * khtml/xml/dom_docimpl.cpp:
            (DocumentImpl::DocumentImpl):
            (DocumentImpl::resetLinkColor):
            (DocumentImpl::resetVisitedLinkColor):
            (DocumentImpl::resetActiveLinkColor):
            (DocumentImpl::recalcStyleSelector):
            * khtml/xml/dom_docimpl.h:
            (DOM::DocumentImpl::linkColor):
            (DOM::DocumentImpl::visitedLinkColor):
            (DOM::DocumentImpl::activeLinkColor):
            (DOM::DocumentImpl::setLinkColor):
            (DOM::DocumentImpl::setVisitedLinkColor):
            (DOM::DocumentImpl::setActiveLinkColor):
            * khtml/xml/dom_elementimpl.cpp:
            (ElementImpl::ElementImpl):
            (ElementImpl::~ElementImpl):
            (ElementImpl::getClassList):
            (ElementImpl::getIDAttribute):
            (ElementImpl::cloneNode):
            (XMLElementImpl::cloneNode):
            * khtml/xml/dom_elementimpl.h:
            (DOM::ElementImpl::inlineStyleDecl):
            (DOM::ElementImpl::attributeStyleDecl):
            (DOM::ElementImpl::getInlineStyleDecl):
            (DOM::ElementImpl::additionalAttributeStyleDecl):
            (DOM::NamedAttrMapImpl::id):
            (DOM::NamedAttrMapImpl::setID):
            * khtml/xml/dom_stringimpl.cpp:
            (DOM::DOMStringImpl::DOMStringImpl):
            (DOM::DOMStringImpl::~DOMStringImpl):
            (DOM::DOMStringImpl::append):
            (DOM::DOMStringImpl::insert):
            (DOM::DOMStringImpl::truncate):
            (DOM::DOMStringImpl::remove):
            (DOM::DOMStringImpl::split):
            * khtml/xml/dom_stringimpl.h:
            (DOM::DOMStringImpl::DOMStringImpl):
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@6037 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog-2005-08-23 b/WebCore/ChangeLog-2005-08-23
index 373cde2..bbbab5d 100644
--- a/WebCore/ChangeLog-2005-08-23
+++ b/WebCore/ChangeLog-2005-08-23
@@ -1,5 +1,180 @@
 2004-02-04  David Hyatt  <hyatt at apple.com>
 
+	Improve rule matching in the style system.  Filter out most rules up front, so that only a small
+	number of rules need to be walked for any given element.  Yields a ~4-5% improvement on the PLT.
+	
+        Reviewed by kocienda
+
+        * khtml/css/css_base.cpp:
+        (StyleBaseImpl::setParsedValue):
+        (CSSSelector::specificity):
+        (CSSSelector::extractPseudoType):
+        (CSSSelector::operator == ):
+        * khtml/css/css_base.h:
+        (DOM::CSSSelector::CSSSelector):
+        (DOM::CSSSelector::~CSSSelector):
+        (DOM::CSSSelector::append):
+        (DOM::CSSSelector::next):
+        (DOM::CSSSelector::):
+        (DOM::StyleBaseImpl::StyleBaseImpl):
+        * khtml/css/css_ruleimpl.cpp:
+        (CSSStyleRuleImpl::selectorText):
+        (CSSRuleListImpl::insertRule):
+        * khtml/css/css_ruleimpl.h:
+        (DOM::CSSStyleRuleImpl::setSelector):
+        (DOM::CSSStyleRuleImpl::selector):
+        * khtml/css/css_stylesheetimpl.cpp:
+        * khtml/css/css_stylesheetimpl.h:
+        * khtml/css/css_valueimpl.cpp:
+        (CSSStyleDeclarationImpl::getPropertyCSSValue):
+        (CSSStyleDeclarationImpl::removeProperty):
+        (CSSStyleDeclarationImpl::setProperty):
+        (CSSStyleDeclarationImpl::setStringProperty):
+        (CSSStyleDeclarationImpl::setImageProperty):
+        (CSSStyleDeclarationImpl::setLengthProperty):
+        (CSSStyleDeclarationImpl::cssText):
+        (CSSStyleDeclarationImpl::setCssText):
+        * khtml/css/css_valueimpl.h:
+        (DOM::CSSStyleDeclarationImpl::node):
+        (DOM::CSSProperty::CSSProperty):
+        (DOM::CSSProperty::id):
+        (DOM::CSSProperty::isImportant):
+        * khtml/css/cssparser.cpp:
+        (CSSParser::CSSParser):
+        (ParseString::lower):
+        (CSSParser::parseValue):
+        (CSSParser::parseDeclaration):
+        (CSSParser::addProperty):
+        (CSSParser::parseShadow):
+        * khtml/css/cssparser.h:
+        * khtml/css/cssstyleselector.cpp:
+        (khtml::):
+        (khtml::CSSStyleSelector::CSSStyleSelector):
+        (khtml::CSSStyleSelector::init):
+        (khtml::CSSStyleSelector::~CSSStyleSelector):
+        (khtml::CSSStyleSelector::loadDefaultStyle):
+        (khtml::CSSStyleSelector::addMatchedRule):
+        (khtml::CSSStyleSelector::addMatchedDeclaration):
+        (khtml::CSSStyleSelector::matchRules):
+        (khtml::CSSStyleSelector::matchRulesForList):
+        (khtml::operator >):
+        (khtml::operator <=):
+        (khtml::CSSStyleSelector::sortMatchedRules):
+        (khtml::CSSStyleSelector::initForStyleResolve):
+        (khtml::CSSStyleSelector::styleForElement):
+        (khtml::CSSStyleSelector::pseudoStyleForElement):
+        (khtml::checkPseudoState):
+        (khtml::CSSStyleSelector::checkSelector):
+        (khtml::CSSStyleSelector::checkOneSelector):
+        (khtml::CSSRuleSet::CSSRuleSet):
+        (khtml::CSSRuleSet::addToRuleSet):
+        (khtml::CSSRuleSet::addRule):
+        (khtml::CSSRuleSet::addRulesFromSheet):
+        (khtml::CSSStyleSelector::applyDeclarations):
+        (khtml::CSSStyleSelector::applyProperty):
+        (khtml::CSSStyleSelector::smallerFontSize):
+        (khtml::CSSStyleSelector::getColorFromPrimitiveValue):
+        * khtml/css/cssstyleselector.h:
+        (khtml::):
+        (khtml::CSSRuleData::m_next):
+        (khtml::CSSRuleData::~CSSRuleData):
+        (khtml::CSSRuleData::position):
+        (khtml::CSSRuleData::rule):
+        (khtml::CSSRuleData::selector):
+        (khtml::CSSRuleData::next):
+        (khtml::CSSRuleDataList::CSSRuleDataList):
+        (khtml::CSSRuleDataList::~CSSRuleDataList):
+        (khtml::CSSRuleDataList::first):
+        (khtml::CSSRuleDataList::last):
+        (khtml::CSSRuleDataList::append):
+        (khtml::CSSRuleSet::~CSSRuleSet):
+        (khtml::CSSRuleSet::getIDRules):
+        (khtml::CSSRuleSet::getClassRules):
+        (khtml::CSSRuleSet::getTagRules):
+        (khtml::CSSRuleSet::getUniversalRules):
+        * khtml/css/cssvalues.c:
+        (hash_val):
+        (findValue):
+        * khtml/css/cssvalues.h:
+        * khtml/css/cssvalues.in:
+        * khtml/css/html4.css:
+        * khtml/css/parser.cpp:
+        * khtml/css/parser.h:
+        * khtml/css/parser.y:
+        * khtml/dom/dom_element.cpp:
+        (Element::style):
+        * khtml/html/html_baseimpl.cpp:
+        (HTMLBodyElementImpl::HTMLBodyElementImpl):
+        (HTMLBodyElementImpl::~HTMLBodyElementImpl):
+        (HTMLBodyElementImpl::createLinkDecl):
+        (HTMLBodyElementImpl::parseAttribute):
+        * khtml/html/html_baseimpl.h:
+        * khtml/html/html_elementimpl.cpp:
+        (HTMLNamedAttrMapImpl::parseClassAttribute):
+        (HTMLElementImpl::HTMLElementImpl):
+        (HTMLElementImpl::~HTMLElementImpl):
+        (HTMLElementImpl::createInlineStyleDecl):
+        (HTMLElementImpl::createMappedAttributeDecl):
+        (HTMLElementImpl::parseAttribute):
+        (HTMLElementImpl::getClassList):
+        (HTMLElementImpl::addCSSProperty):
+        (HTMLElementImpl::addCSSStringProperty):
+        (HTMLElementImpl::addCSSImageProperty):
+        (HTMLElementImpl::addCSSLength):
+        (HTMLElementImpl::addHTMLColor):
+        (HTMLElementImpl::removeCSSProperty):
+        * khtml/html/html_elementimpl.h:
+        (DOM::HTMLNamedAttrMapImpl::getClassList):
+        (DOM::HTMLElementImpl::inlineStyleDecl):
+        (DOM::HTMLElementImpl::attributeStyleDecl):
+        (DOM::HTMLElementImpl::getInlineStyleDecl):
+        * khtml/html/html_tableimpl.cpp:
+        (HTMLTableElementImpl::createSharedCellDecls):
+        (HTMLTableCellElementImpl::additionalAttributeStyleDecl):
+        * khtml/html/html_tableimpl.h:
+        * khtml/xml/dom_atomicstring.cpp:
+        (DOM::AtomicString::add):
+        (DOM::AtomicString::remove):
+        * khtml/xml/dom_docimpl.cpp:
+        (DocumentImpl::DocumentImpl):
+        (DocumentImpl::resetLinkColor):
+        (DocumentImpl::resetVisitedLinkColor):
+        (DocumentImpl::resetActiveLinkColor):
+        (DocumentImpl::recalcStyleSelector):
+        * khtml/xml/dom_docimpl.h:
+        (DOM::DocumentImpl::linkColor):
+        (DOM::DocumentImpl::visitedLinkColor):
+        (DOM::DocumentImpl::activeLinkColor):
+        (DOM::DocumentImpl::setLinkColor):
+        (DOM::DocumentImpl::setVisitedLinkColor):
+        (DOM::DocumentImpl::setActiveLinkColor):
+        * khtml/xml/dom_elementimpl.cpp:
+        (ElementImpl::ElementImpl):
+        (ElementImpl::~ElementImpl):
+        (ElementImpl::getClassList):
+        (ElementImpl::getIDAttribute):
+        (ElementImpl::cloneNode):
+        (XMLElementImpl::cloneNode):
+        * khtml/xml/dom_elementimpl.h:
+        (DOM::ElementImpl::inlineStyleDecl):
+        (DOM::ElementImpl::attributeStyleDecl):
+        (DOM::ElementImpl::getInlineStyleDecl):
+        (DOM::ElementImpl::additionalAttributeStyleDecl):
+        (DOM::NamedAttrMapImpl::id):
+        (DOM::NamedAttrMapImpl::setID):
+        * khtml/xml/dom_stringimpl.cpp:
+        (DOM::DOMStringImpl::DOMStringImpl):
+        (DOM::DOMStringImpl::~DOMStringImpl):
+        (DOM::DOMStringImpl::append):
+        (DOM::DOMStringImpl::insert):
+        (DOM::DOMStringImpl::truncate):
+        (DOM::DOMStringImpl::remove):
+        (DOM::DOMStringImpl::split):
+        * khtml/xml/dom_stringimpl.h:
+        (DOM::DOMStringImpl::DOMStringImpl):
+
+2004-02-04  David Hyatt  <hyatt at apple.com>
+
 	Fix line-height regression on altavista.
 
         * khtml/rendering/render_br.cpp:
diff --git a/WebCore/khtml/css/css_base.cpp b/WebCore/khtml/css/css_base.cpp
index 56f0573..5b8a73b 100644
--- a/WebCore/khtml/css/css_base.cpp
+++ b/WebCore/khtml/css/css_base.cpp
@@ -76,12 +76,12 @@ DOMString StyleBaseImpl::baseURL()
 }
 
 void StyleBaseImpl::setParsedValue(int propId, const CSSValueImpl *parsedValue,
-				   bool important, bool nonCSSHint, QPtrList<CSSProperty> *propList)
+				   bool important, QPtrList<CSSProperty> *propList)
 {
     QPtrListIterator<CSSProperty> propIt(*propList);
     propIt.toLast(); // just remove the top one - not sure what should happen if we have multiple instances of the property
     while (propIt.current() &&
-           ( propIt.current()->m_id != propId || propIt.current()->nonCSSHint != nonCSSHint ||
+           ( propIt.current()->m_id != propId ||
              propIt.current()->m_bImportant != important) )
         --propIt;
     if (propIt.current())
@@ -91,8 +91,7 @@ void StyleBaseImpl::setParsedValue(int propId, const CSSValueImpl *parsedValue,
     prop->m_id = propId;
     prop->setValue((CSSValueImpl *) parsedValue);
     prop->m_bImportant = important;
-    prop->nonCSSHint = nonCSSHint;
-
+    
     propList->append(prop);
 #ifdef CSS_DEBUG
     kdDebug( 6080 ) << "added property: " << getPropertyName(propId).string()
@@ -132,9 +131,8 @@ void CSSSelector::print(void)
 
 unsigned int CSSSelector::specificity()
 {
-    if ( nonCSSHint )
-        return 0;
-
+    // FIXME: Pseudo-elements and pseudo-classes do not have the same specificity. This function
+    // isn't quite correct.
     int s = ((localNamePart(tag) == anyLocalName) ? 0 : 1);
     switch(match)
     {
@@ -167,6 +165,7 @@ void CSSSelector::extractPseudoType() const
     
     static AtomicString active("active");
     static AtomicString after("after");
+    static AtomicString anyLink("-khtml-any-link");
     static AtomicString before("before");
     static AtomicString empty("empty");
     static AtomicString firstChild("first-child");
@@ -189,6 +188,8 @@ void CSSSelector::extractPseudoType() const
         _pseudoType = PseudoActive;
     else if (value == after)
         _pseudoType = PseudoAfter;
+    else if (value == anyLink)
+        _pseudoType = PseudoAnyLink;
     else if (value == before)
         _pseudoType = PseudoBefore;
     else if (value == empty)
@@ -234,7 +235,6 @@ bool CSSSelector::operator == ( const CSSSelector &other )
     while ( sel1 && sel2 ) {
 	if ( sel1->tag != sel2->tag || sel1->attr != sel2->attr ||
 	     sel1->relation != sel2->relation || sel1->match != sel2->match ||
-	     sel1->nonCSSHint != sel2->nonCSSHint ||
 	     sel1->value != sel2->value ||
              sel1->pseudoType() != sel2->pseudoType())
 	    return false;
diff --git a/WebCore/khtml/css/css_base.h b/WebCore/khtml/css/css_base.h
index e307386..a5b18d2 100644
--- a/WebCore/khtml/css/css_base.h
+++ b/WebCore/khtml/css/css_base.h
@@ -73,16 +73,22 @@ namespace DOM {
     {
     public:
 	CSSSelector()
-	    : tagHistory(0), simpleSelector(0), attr(0), tag(anyQName),
-              relation( Descendant ), match( None ), nonCSSHint( false ), 
+	    : tagHistory(0), simpleSelector(0), nextSelector(0), attr(0), tag(anyQName),
+              relation( Descendant ), match( None ),
               pseudoId( 0 ), _pseudoType(PseudoNotParsed)
         {}
 
 	~CSSSelector() {
 	    delete tagHistory;
             delete simpleSelector;
+            delete nextSelector;
 	}
 
+        void append(CSSSelector* n) {
+            if (!nextSelector) nextSelector = n; else nextSelector->append(n);
+        }
+        CSSSelector* next() { return nextSelector; }
+
 	/**
 	 * Print debug output for this selector
 	 */
@@ -136,6 +142,7 @@ namespace DOM {
 	    PseudoFirstLetter,
 	    PseudoLink,
 	    PseudoVisited,
+            PseudoAnyLink,
 	    PseudoHover,
 	    PseudoFocus,
 	    PseudoActive,
@@ -156,14 +163,14 @@ namespace DOM {
 	    }
 
 	mutable DOM::AtomicString value;
-	CSSSelector *tagHistory;
+	CSSSelector* tagHistory;
         CSSSelector* simpleSelector; // Used for :not.
+        CSSSelector* nextSelector; // used for ,-chained selectors
 	Q_UINT32     attr;
 	Q_UINT32     tag;
 
         Relation relation     : 2;
 	Match 	 match         : 4;
-	bool	nonCSSHint : 1;
 	unsigned int pseudoId : 3;
 	mutable PseudoType _pseudoType : 5;
 
@@ -175,9 +182,9 @@ namespace DOM {
     class StyleBaseImpl : public khtml::TreeShared<StyleBaseImpl>
     {
     public:
-	StyleBaseImpl()  { m_parent = 0; hasInlinedDecl = false; strictParsing = true; multiLength = false; }
+	StyleBaseImpl()  { m_parent = 0; strictParsing = true; multiLength = false; }
 	StyleBaseImpl(StyleBaseImpl *p) {
-	    m_parent = p; hasInlinedDecl = false;
+	    m_parent = p;
 	    strictParsing = (m_parent ? m_parent->useStrictParsing() : true);
 	    multiLength = false;
 	}
@@ -209,7 +216,7 @@ namespace DOM {
 	void setParent(StyleBaseImpl *parent) { m_parent = parent; }
 
 	static void setParsedValue(int propId, const CSSValueImpl *parsedValue,
-				   bool important, bool nonCSSHint, QPtrList<CSSProperty> *propList);
+				   bool important, QPtrList<CSSProperty> *propList);
 
 	virtual bool parseString(const DOMString &/*cssString*/, bool = false) { return false; }
 
@@ -221,7 +228,6 @@ namespace DOM {
 	StyleSheetImpl* stylesheet();
 
     protected:
-	bool hasInlinedDecl : 1;
 	bool strictParsing : 1;
 	bool multiLength : 1;
     };
diff --git a/WebCore/khtml/css/css_ruleimpl.cpp b/WebCore/khtml/css/css_ruleimpl.cpp
index 080ab05..918cb34 100644
--- a/WebCore/khtml/css/css_ruleimpl.cpp
+++ b/WebCore/khtml/css/css_ruleimpl.cpp
@@ -320,12 +320,9 @@ CSSStyleRuleImpl::~CSSStyleRuleImpl()
 
 DOM::DOMString CSSStyleRuleImpl::selectorText() const
 {
-    if ( m_selector && m_selector->first() ) {
-        // ### m_selector will be a single selector hopefully. so ->first() will disappear
-        CSSSelector* cs = m_selector->first();
-        //cs->print(); // debug
-        return cs->selectorText();
-    }
+    // FIXME: Handle all the selectors in the chain for comma-separated selectors.
+    if (m_selector)
+        return m_selector->selectorText();
     return DOMString();
 }
 
@@ -349,15 +346,6 @@ void CSSStyleRuleImpl::setDeclaration( CSSStyleDeclarationImpl *style)
     }
 }
 
-void CSSStyleRuleImpl::setNonCSSHints()
-{
-    CSSSelector *s = m_selector->first();
-    while ( s ) {
-	s->nonCSSHint = true;
-	s = m_selector->next();
-    }
-}
-
 void CSSRuleListImpl::deleteRule ( unsigned long index )
 {
     CSSRuleImpl *rule = m_lstCSSRules.take( index );
@@ -384,4 +372,3 @@ unsigned long CSSRuleListImpl::insertRule( CSSRuleImpl *rule,
     // ### Should throw INDEX_SIZE_ERR exception instead! (TODO)
     return 0;
 }
-
diff --git a/WebCore/khtml/css/css_ruleimpl.h b/WebCore/khtml/css/css_ruleimpl.h
index 96521d6..330aa2d 100644
--- a/WebCore/khtml/css/css_ruleimpl.h
+++ b/WebCore/khtml/css/css_ruleimpl.h
@@ -30,6 +30,7 @@
 #include "css/css_base.h"
 #include "misc/loader_client.h"
 #include "misc/shared.h"
+#include "css_valueimpl.h"
 
 namespace khtml {
     class CachedCSSStyleSheet;
@@ -191,6 +192,7 @@ protected:
     CSSStyleDeclarationImpl *m_style;
 };
 
+class CSSImportantRuleImpl;
 
 class CSSStyleRuleImpl : public CSSRuleImpl
 {
@@ -208,20 +210,17 @@ public:
 
     virtual bool parseString( const DOMString &string, bool = false );
 
-    void setSelector( QPtrList<CSSSelector> *selector) { m_selector = selector; }
+    void setSelector(CSSSelector* selector) { m_selector = selector; }
     void setDeclaration( CSSStyleDeclarationImpl *style);
 
-    QPtrList<CSSSelector> *selector() { return m_selector; }
+    CSSSelector* selector() { return m_selector; }
     CSSStyleDeclarationImpl *declaration() { return m_style; }
-
-    void setNonCSSHints();
-
+ 
 protected:
     CSSStyleDeclarationImpl *m_style;
-    QPtrList<CSSSelector> *m_selector;
+    CSSSelector* m_selector;
 };
 
-
 class CSSUnknownRuleImpl : public CSSRuleImpl
 {
 public:
diff --git a/WebCore/khtml/css/css_stylesheetimpl.cpp b/WebCore/khtml/css/css_stylesheetimpl.cpp
index 799a300..86e68ff 100644
--- a/WebCore/khtml/css/css_stylesheetimpl.cpp
+++ b/WebCore/khtml/css/css_stylesheetimpl.cpp
@@ -276,17 +276,6 @@ void CSSStyleSheetImpl::checkLoaded()
     if(m_parentNode) m_parentNode->sheetLoaded();
 }
 
-void CSSStyleSheetImpl::setNonCSSHints()
-{
-    StyleBaseImpl *rule = m_lstChildren->first();
-    while(rule) {
-        if(rule->isStyleRule()) {
-            static_cast<CSSStyleRuleImpl *>(rule)->setNonCSSHints();
-        }
-        rule = m_lstChildren->next();
-    }
-}
-
 khtml::DocLoader *CSSStyleSheetImpl::docLoader()
 {
     if ( !m_doc ) // doc is 0 for the user- and default-sheet!
diff --git a/WebCore/khtml/css/css_stylesheetimpl.h b/WebCore/khtml/css/css_stylesheetimpl.h
index 152552c..e2d7b1c 100644
--- a/WebCore/khtml/css/css_stylesheetimpl.h
+++ b/WebCore/khtml/css/css_stylesheetimpl.h
@@ -106,7 +106,6 @@ public:
     virtual bool parseString( const DOMString &string, bool strict = true );
 
     bool isLoading();
-    void setNonCSSHints();
 
     virtual void checkLoaded();
     khtml::DocLoader *docLoader();
diff --git a/WebCore/khtml/css/css_valueimpl.cpp b/WebCore/khtml/css/css_valueimpl.cpp
index 3dc2528..62e7699 100644
--- a/WebCore/khtml/css/css_valueimpl.cpp
+++ b/WebCore/khtml/css/css_valueimpl.cpp
@@ -227,12 +227,12 @@ DOMString CSSStyleDeclarationImpl::getShortHandValue( const int* properties, int
     QPtrListIterator<CSSProperty> lstValuesIt(*m_lstValues);
     CSSProperty *current;
     for ( lstValuesIt.toLast(); (current = lstValuesIt.current()); --lstValuesIt )
-        if (current->m_id == propertyID && !current->nonCSSHint)
+        if (current->m_id == propertyID)
             return current->value();
     return 0;
 }
 
-DOMString CSSStyleDeclarationImpl::removeProperty( int propertyID, bool NonCSSHint )
+DOMString CSSStyleDeclarationImpl::removeProperty(int propertyID, bool notifyChanged)
 {
     if(!m_lstValues) return DOMString();
     DOMString value;
@@ -240,10 +240,11 @@ DOMString CSSStyleDeclarationImpl::removeProperty( int propertyID, bool NonCSSHi
     QPtrListIterator<CSSProperty> lstValuesIt(*m_lstValues);
      CSSProperty *current;
      for ( lstValuesIt.toLast(); (current = lstValuesIt.current()); --lstValuesIt )
-         if (current->m_id == propertyID && NonCSSHint == current->nonCSSHint) {
+         if (current->m_id == propertyID) {
              value = current->value()->cssText();
              m_lstValues->removeRef(current);
-             setChanged();
+             if (notifyChanged)
+                 setChanged();
 	     break;
         }
 
@@ -278,56 +279,57 @@ bool CSSStyleDeclarationImpl::getPropertyPriority( int propertyID ) const
     return false;
 }
 
-bool CSSStyleDeclarationImpl::setProperty(int id, const DOMString &value, bool important, bool nonCSSHint)
+bool CSSStyleDeclarationImpl::setProperty(int id, const DOMString &value, bool important, bool notifyChanged)
 {
     if(!m_lstValues) {
 	m_lstValues = new QPtrList<CSSProperty>;
 	m_lstValues->setAutoDelete(true);
     }
-    removeProperty(id, nonCSSHint );
+    removeProperty(id);
 
     CSSParser parser( strictParsing );
-    bool success = parser.parseValue( this, id, value, important, nonCSSHint );
+    bool success = parser.parseValue(this, id, value, important);
     if(!success)
 	kdDebug( 6080 ) << "CSSStyleDeclarationImpl::setProperty invalid property: [" << getPropertyName(id).string()
 			<< "] value: [" << value.string() << "]"<< endl;
-    else
+    else if (notifyChanged)
         setChanged();
     return success;
 }
 
-void CSSStyleDeclarationImpl::setProperty(int id, int value, bool important, bool nonCSSHint)
+void CSSStyleDeclarationImpl::setProperty(int id, int value, bool important, bool notifyChanged)
 {
     if(!m_lstValues) {
 	m_lstValues = new QPtrList<CSSProperty>;
 	m_lstValues->setAutoDelete(true);
     }
-    removeProperty(id, nonCSSHint );
+    removeProperty(id);
 
     CSSValueImpl * cssValue = new CSSPrimitiveValueImpl(value);
-    setParsedValue(id, cssValue, important, nonCSSHint, m_lstValues);
-    setChanged();
+    setParsedValue(id, cssValue, important, m_lstValues);
+    if (notifyChanged)
+        setChanged();
 }
 
-void CSSStyleDeclarationImpl::setStringProperty(int propertyId, const DOMString &value, CSSPrimitiveValue::UnitTypes type, bool important, bool nonCSSHint)
+void CSSStyleDeclarationImpl::setStringProperty(int propertyId, const DOMString &value, CSSPrimitiveValue::UnitTypes type, bool important)
 {
     if (!m_lstValues) {
 	m_lstValues = new QPtrList<CSSProperty>;
 	m_lstValues->setAutoDelete(true);
     }
-    removeProperty(propertyId, nonCSSHint);
-    setParsedValue(propertyId, new CSSPrimitiveValueImpl(value, type), important, nonCSSHint, m_lstValues);
+    removeProperty(propertyId);
+    setParsedValue(propertyId, new CSSPrimitiveValueImpl(value, type), important, m_lstValues);
     setChanged();
 }
 
-void CSSStyleDeclarationImpl::setImageProperty(int propertyId, const DOMString &URL, bool important, bool nonCSSHint)
+void CSSStyleDeclarationImpl::setImageProperty(int propertyId, const DOMString &URL, bool important)
 {
     if (!m_lstValues) {
 	m_lstValues = new QPtrList<CSSProperty>;
 	m_lstValues->setAutoDelete(true);
     }
-    removeProperty(propertyId, nonCSSHint);
-    setParsedValue(propertyId, new CSSImageValueImpl(URL, this), important, nonCSSHint, m_lstValues);
+    removeProperty(propertyId);
+    setParsedValue(propertyId, new CSSImageValueImpl(URL, this), important, m_lstValues);
     setChanged();
 }
 
@@ -338,17 +340,17 @@ void CSSStyleDeclarationImpl::setProperty ( const DOMString &propertyString)
 	m_lstValues->setAutoDelete( true );
     }
 
-    CSSParser parser( strictParsing );
-    parser.parseDeclaration( this, propertyString, false );
+    CSSParser parser(strictParsing);
+    parser.parseDeclaration(this, propertyString);
     setChanged();
 }
 
-void CSSStyleDeclarationImpl::setLengthProperty(int id, const DOM::DOMString &value, bool important, bool nonCSSHint, bool _multiLength )
+void CSSStyleDeclarationImpl::setLengthProperty(int id, const DOM::DOMString &value, bool important, bool _multiLength )
 {
     bool parseMode = strictParsing;
     strictParsing = false;
     multiLength = _multiLength;
-    setProperty( id, value, important, nonCSSHint);
+    setProperty( id, value, important);
     strictParsing = parseMode;
     multiLength = false;
 }
@@ -378,40 +380,24 @@ DOM::DOMString CSSStyleDeclarationImpl::cssText() const
     if ( m_lstValues) {
 	QPtrListIterator<CSSProperty> lstValuesIt(*m_lstValues);
 	CSSProperty *current;
-	for ( lstValuesIt.toFirst(); (current = lstValuesIt.current()); ++lstValuesIt ) {
-	    if (!current->nonCSSHint) {
-		result += current->cssText();
-	    }
-	}
+	for ( lstValuesIt.toFirst(); (current = lstValuesIt.current()); ++lstValuesIt )
+	    result += current->cssText();
     }
 
     return result;
 }
 
-void CSSStyleDeclarationImpl::setCssText(DOM::DOMString text)
+void CSSStyleDeclarationImpl::setCssText(const DOM::DOMString& text)
 {
-    if (m_lstValues) {
-	QPtrList<CSSProperty> nonCSSHints;
-
-	{
-	    // make sure to destruct iterator before reassigning list contents
-	    QPtrListIterator<CSSProperty> lstValuesIt(*m_lstValues);
-	    CSSProperty *current;
-	    for ( lstValuesIt.toFirst(); (current = lstValuesIt.current()); ++lstValuesIt ) {
-		if (current->nonCSSHint) {
-		    nonCSSHints.append(new CSSProperty(*current));
-		}
-	    }
-	}
-
-	*m_lstValues = nonCSSHints;
-    } else {
+    if (m_lstValues)
+        m_lstValues->clear();
+    else {
 	m_lstValues = new QPtrList<CSSProperty>;
-	m_lstValues->setAutoDelete( true );
+	m_lstValues->setAutoDelete(true);
     }
 
-    CSSParser parser( strictParsing );
-    parser.parseDeclaration( this, text, false );
+    CSSParser parser(strictParsing);
+    parser.parseDeclaration(this, text);
     setChanged();
 }
 
diff --git a/WebCore/khtml/css/css_valueimpl.h b/WebCore/khtml/css/css_valueimpl.h
index 0acb364..912e2ba 100644
--- a/WebCore/khtml/css/css_valueimpl.h
+++ b/WebCore/khtml/css/css_valueimpl.h
@@ -56,21 +56,21 @@ public:
 
     unsigned long length() const;
     CSSRuleImpl *parentRule() const;
-    DOM::DOMString removeProperty( int propertyID, bool NonCSSHints = false );
-    bool setProperty ( int propertyId, const DOM::DOMString &value, bool important = false, bool nonCSSHint = false);
-    void setProperty ( int propertyId, int value, bool important = false, bool nonCSSHint = false);
+    DOM::DOMString removeProperty(int propertyID, bool notifyChanged = true);
+    bool setProperty(int propertyId, const DOM::DOMString &value, bool important = false, bool notifyChanged = true);
+    void setProperty(int propertyId, int value, bool important = false, bool notifyChanged = true);
     // this treats integers as pixels!
     // needed for conversion of html attributes
-    void setLengthProperty(int id, const DOM::DOMString &value, bool important, bool nonCSSHint = true, bool multiLength = false);
-    void setStringProperty(int propertyId, const DOM::DOMString &value, DOM::CSSPrimitiveValue::UnitTypes, bool important = false, bool nonCSSHint = false); // parsed string value
-    void setImageProperty(int propertyId, const DOM::DOMString &URL, bool important = false, bool nonCSSHint = false);
+    void setLengthProperty(int id, const DOM::DOMString &value, bool important,bool multiLength = false);
+    void setStringProperty(int propertyId, const DOM::DOMString &value, DOM::CSSPrimitiveValue::UnitTypes, bool important = false); // parsed string value
+    void setImageProperty(int propertyId, const DOM::DOMString &URL, bool important = false);
 
     // add a whole, unparsed property
     void setProperty ( const DOMString &propertyString);
     DOM::DOMString item ( unsigned long index );
 
     virtual DOM::DOMString cssText() const;
-    void setCssText(DOM::DOMString str);
+    void setCssText(const DOM::DOMString& str);
 
     virtual bool isStyleDeclaration() { return true; }
 
@@ -82,6 +82,7 @@ public:
 
     QPtrList<CSSProperty> *values() { return m_lstValues; }
     void setNode(NodeImpl *_node) { m_node = _node; }
+    NodeImpl* node() { return m_node; }
 
     void setChanged();
 
@@ -360,14 +361,12 @@ public:
     {
 	m_id = -1;
 	m_bImportant = false;
-	nonCSSHint = false;
-        m_value = 0;
+	m_value = 0;
     }
     CSSProperty(const CSSProperty& o)
     {
         m_id = o.m_id;
         m_bImportant = o.m_bImportant;
-        nonCSSHint = o.nonCSSHint;
         m_value = o.m_value;
         if (m_value) m_value->ref();
     }
@@ -383,14 +382,16 @@ public:
 	}
     }
 
+    int id() const { return m_id; }
+    bool isImportant() const { return m_bImportant; }
+    
     CSSValueImpl *value() { return m_value; }
-
+    
     DOM::DOMString cssText() const;
 
     // make sure the following fits in 4 bytes.
-    int  m_id 		: 29;
+    int  m_id 		: 30;
     bool m_bImportant 	: 1;
-    bool nonCSSHint 	: 1;
 protected:
     CSSValueImpl *m_value;
 };
diff --git a/WebCore/khtml/css/cssparser.cpp b/WebCore/khtml/css/cssparser.cpp
index 7050a80..4605088 100644
--- a/WebCore/khtml/css/cssparser.cpp
+++ b/WebCore/khtml/css/cssparser.cpp
@@ -99,7 +99,6 @@ CSSParser::CSSParser( bool strictParsing )
     rule = 0;
     id = 0;
     important = false;
-    nonCSSHint = false;
     inParseShortHand = false;
     
     defaultNamespace = anyNamespace;
@@ -131,7 +130,7 @@ CSSParser::~CSSParser()
 void ParseString::lower()
 {
     for (int i = 0; i < length; i++)
-        string[i] = QChar(string[i]).lower();
+        string[i] = QChar(string[i]).lower().unicode();
 }
 
 void CSSParser::parseSheet( CSSStyleSheetImpl *sheet, const DOMString &string )
@@ -197,11 +196,11 @@ CSSRuleImpl *CSSParser::parseRule( DOM::CSSStyleSheetImpl *sheet, const DOM::DOM
 }
 
 bool CSSParser::parseValue( DOM::CSSStyleDeclarationImpl *declaration, int _id, const DOM::DOMString &string,
-			    bool _important, bool _nonCSSHint )
+			    bool _important)
 {
 #ifdef CSS_DEBUG
     kdDebug( 6080 ) << "CSSParser::parseValue: id=" << _id << " important=" << _important
-		    << " nonCSSHint=" << _nonCSSHint << " value='" << string.string() << "'" << endl;
+		    << " value='" << string.string() << "'" << endl;
 #endif
 
     styleElement = declaration->stylesheet();
@@ -224,8 +223,7 @@ bool CSSParser::parseValue( DOM::CSSStyleDeclarationImpl *declaration, int _id,
 
     id = _id;
     important = _important;
-    nonCSSHint = _nonCSSHint;
-
+    
     CSSParser *old = currentParser;
     currentParser = this;
     cssyyparse( this );
@@ -238,7 +236,7 @@ bool CSSParser::parseValue( DOM::CSSStyleDeclarationImpl *declaration, int _id,
     if ( numParsedProperties ) {
 	ok = true;
 	for ( int i = 0; i < numParsedProperties; i++ ) {
-	    declaration->removeProperty(parsedProperties[i]->m_id, nonCSSHint);
+	    declaration->removeProperty(parsedProperties[i]->m_id);
 	    declaration->values()->append( parsedProperties[i] );
 	}
 	numParsedProperties = 0;
@@ -247,12 +245,10 @@ bool CSSParser::parseValue( DOM::CSSStyleDeclarationImpl *declaration, int _id,
     return ok;
 }
 
-bool CSSParser::parseDeclaration( DOM::CSSStyleDeclarationImpl *declaration, const DOM::DOMString &string,
-				  bool _nonCSSHint )
+bool CSSParser::parseDeclaration( DOM::CSSStyleDeclarationImpl *declaration, const DOM::DOMString &string )
 {
 #ifdef CSS_DEBUG
-    kdDebug( 6080 ) << "CSSParser::parseDeclaration: nonCSSHint=" << nonCSSHint
-		    << " value='" << string.string() << "'" << endl;
+    kdDebug( 6080 ) << "CSSParser::parseDeclaration:value='" << string.string() << "'" << endl;
 #endif
 
     styleElement = declaration->stylesheet();
@@ -273,8 +269,6 @@ bool CSSParser::parseDeclaration( DOM::CSSStyleDeclarationImpl *declaration, con
     yytext = yy_c_buf_p = data;
     yy_hold_char = *yy_c_buf_p;
 
-    nonCSSHint = _nonCSSHint;
-
     CSSParser *old = currentParser;
     currentParser = this;
     cssyyparse( this );
@@ -287,7 +281,7 @@ bool CSSParser::parseDeclaration( DOM::CSSStyleDeclarationImpl *declaration, con
     if ( numParsedProperties ) {
 	ok = true;
 	for ( int i = 0; i < numParsedProperties; i++ ) {
-	    declaration->removeProperty(parsedProperties[i]->m_id, false);
+	    declaration->removeProperty(parsedProperties[i]->m_id);
 	    declaration->values()->append( parsedProperties[i] );
 	}
 	numParsedProperties = 0;
@@ -302,7 +296,6 @@ void CSSParser::addProperty( int propId, CSSValueImpl *value, bool important )
     prop->m_id = propId;
     prop->setValue( value );
     prop->m_bImportant = important;
-    prop->nonCSSHint = nonCSSHint;
 
     if ( numParsedProperties >= maxParsedProperties ) {
 	maxParsedProperties += 32;
@@ -706,7 +699,7 @@ bool CSSParser::parseValue( int propId, bool important )
 
     case CSS_PROP_BACKGROUND_POSITION_X:
     case CSS_PROP_BACKGROUND_POSITION_Y:
-	valid_primitive = validUnit( value, FPercent|FLength, strict&(!nonCSSHint) );
+	valid_primitive = validUnit( value, FPercent|FLength, strict );
 	break;
 
     case CSS_PROP_BORDER_SPACING: {
@@ -728,7 +721,7 @@ bool CSSParser::parseValue( int propId, bool important )
     }
     case CSS_PROP__KHTML_BORDER_HORIZONTAL_SPACING:
     case CSS_PROP__KHTML_BORDER_VERTICAL_SPACING:
-        valid_primitive = validUnit(value, FLength|FNonNeg, strict&(!nonCSSHint));
+        valid_primitive = validUnit(value, FLength|FNonNeg, strict);
         break;
     case CSS_PROP_SCROLLBAR_FACE_COLOR:         // IE5.5
     case CSS_PROP_SCROLLBAR_SHADOW_COLOR:       // IE5.5
@@ -758,7 +751,7 @@ bool CSSParser::parseValue( int propId, bool important )
             valid_primitive = true; // Always allow this, even when strict parsing is on,
                                     // since we use this in our UA sheets.
 	else if ( id >= CSS_VAL_AQUA && id <= CSS_VAL_WINDOWTEXT || id == CSS_VAL_MENU ||
-	     (id >= CSS_VAL_GREY && id < CSS_VAL__KHTML_TEXT && (nonCSSHint|!strict)) ) {
+	     (id >= CSS_VAL_GREY && id < CSS_VAL__KHTML_TEXT && !strict) ) {
 	    valid_primitive = true;
 	} else {
 	    parsedValue = parseColor();
@@ -811,7 +804,7 @@ bool CSSParser::parseValue( int propId, bool important )
 	if (id == CSS_VAL_THIN || id == CSS_VAL_MEDIUM || id == CSS_VAL_THICK)
 	    valid_primitive = true;
         else
-            valid_primitive = ( validUnit( value, FLength, strict&(!nonCSSHint) ) );
+            valid_primitive = ( validUnit( value, FLength, strict ) );
 	break;
 
     case CSS_PROP_LETTER_SPACING:       // normal | <length> | inherit
@@ -819,7 +812,7 @@ bool CSSParser::parseValue( int propId, bool important )
 	if ( id == CSS_VAL_NORMAL )
 	    valid_primitive = true;
 	else
-            valid_primitive = validUnit( value, FLength, strict&(!nonCSSHint) );
+            valid_primitive = validUnit( value, FLength, strict );
 	break;
 
     case CSS_PROP_TEXT_INDENT:          // <length> | <percentage> | inherit
@@ -827,7 +820,7 @@ bool CSSParser::parseValue( int propId, bool important )
     case CSS_PROP_PADDING_RIGHT:        //   Which is defined as
     case CSS_PROP_PADDING_BOTTOM:       //   <length> | <percentage>
     case CSS_PROP_PADDING_LEFT:         ////
-	valid_primitive = ( !id && validUnit( value, FLength|FPercent, strict&(!nonCSSHint) ) );
+	valid_primitive = ( !id && validUnit( value, FLength|FPercent, strict ) );
 	break;
 
     case CSS_PROP_MAX_HEIGHT:           // <length> | <percentage> | none | inherit
@@ -839,7 +832,7 @@ bool CSSParser::parseValue( int propId, bool important )
 	/* nobreak */
     case CSS_PROP_MIN_HEIGHT:           // <length> | <percentage> | inherit
     case CSS_PROP_MIN_WIDTH:            // <length> | <percentage> | inherit
-    	valid_primitive = ( !id && validUnit( value, FLength|FPercent|FNonNeg, strict&(!nonCSSHint) ) );
+    	valid_primitive = ( !id && validUnit( value, FLength|FPercent|FNonNeg, strict ) );
 	break;
 
     case CSS_PROP_FONT_SIZE:
@@ -847,7 +840,7 @@ bool CSSParser::parseValue( int propId, bool important )
 	if (id >= CSS_VAL_XX_SMALL && id <= CSS_VAL_LARGER)
 	    valid_primitive = true;
 	else
-	    valid_primitive = ( validUnit( value, FLength|FPercent, strict&(!nonCSSHint) ) );
+	    valid_primitive = ( validUnit( value, FLength|FPercent, strict ) );
 	break;
 
     case CSS_PROP_FONT_STYLE:           // normal | italic | oblique | inherit
@@ -867,7 +860,7 @@ bool CSSParser::parseValue( int propId, bool important )
 	if ( id >= CSS_VAL_BASELINE && id <= CSS_VAL__KHTML_BASELINE_MIDDLE )
 	    valid_primitive = true;
 	else
-	    valid_primitive = ( !id && validUnit( value, FLength|FPercent, strict&(!nonCSSHint) ) );
+	    valid_primitive = ( !id && validUnit( value, FLength|FPercent, strict ) );
 	break;
 
     case CSS_PROP_HEIGHT:               // <length> | <percentage> | auto | inherit
@@ -876,7 +869,7 @@ bool CSSParser::parseValue( int propId, bool important )
 	    valid_primitive = true;
 	else
 	    // ### handle multilength case where we allow relative units
-	    valid_primitive = ( !id && validUnit( value, FLength|FPercent|FNonNeg, strict&(!nonCSSHint) ) );
+	    valid_primitive = ( !id && validUnit( value, FLength|FPercent|FNonNeg, strict ) );
 	break;
 
     case CSS_PROP_BOTTOM:               // <length> | <percentage> | auto | inherit
@@ -890,7 +883,7 @@ bool CSSParser::parseValue( int propId, bool important )
 	if ( id == CSS_VAL_AUTO )
 	    valid_primitive = true;
 	else
-	    valid_primitive = ( !id && validUnit( value, FLength|FPercent, strict&(!nonCSSHint) ) );
+	    valid_primitive = ( !id && validUnit( value, FLength|FPercent, strict ) );
 	break;
 
     case CSS_PROP_Z_INDEX:              // auto | <integer> | inherit
@@ -910,7 +903,7 @@ bool CSSParser::parseValue( int propId, bool important )
 	if ( id == CSS_VAL_NORMAL )
 	    valid_primitive = true;
 	else
-	    valid_primitive = ( !id && validUnit( value, FNumber|FLength|FPercent, strict&(!nonCSSHint) ) );
+	    valid_primitive = ( !id && validUnit( value, FNumber|FLength|FPercent, strict ) );
 	break;
 #if 0
 	// removed from CSS 2.1
@@ -1021,7 +1014,7 @@ bool CSSParser::parseValue( int propId, bool important )
 #endif
         break;
     case CSS_PROP_OUTLINE_OFFSET:
-        valid_primitive = validUnit(value, FLength, strict&(!nonCSSHint));
+        valid_primitive = validUnit(value, FLength, strict);
         break;
     case CSS_PROP_TEXT_SHADOW: // CSS2 property, dropped in CSS2.1, back in CSS3, so treat as CSS3
         if (id == CSS_VAL_NONE)
@@ -1078,7 +1071,7 @@ bool CSSParser::parseValue( int propId, bool important )
         if (id == CSS_VAL_SMALL || id == CSS_VAL_LARGE || id == CSS_VAL_MEDIUM)
             valid_primitive = true;
         else
-            valid_primitive = validUnit(value, FLength|FPercent, strict&(!nonCSSHint));
+            valid_primitive = validUnit(value, FLength|FPercent, strict);
         break;
     case CSS_PROP__KHTML_MARQUEE_STYLE:
         if (id == CSS_VAL_NONE || id == CSS_VAL_SLIDE || id == CSS_VAL_SCROLL || id == CSS_VAL_ALTERNATE ||
@@ -1089,13 +1082,13 @@ bool CSSParser::parseValue( int propId, bool important )
         if (id == CSS_VAL_INFINITE)
             valid_primitive = true;
         else
-            valid_primitive = validUnit(value, FInteger|FNonNeg, strict&(!nonCSSHint));
+            valid_primitive = validUnit(value, FInteger|FNonNeg, strict);
         break;
     case CSS_PROP__KHTML_MARQUEE_SPEED:
         if (id == CSS_VAL_NORMAL || id == CSS_VAL_SLOW || id == CSS_VAL_FAST)
             valid_primitive = true;
         else
-            valid_primitive = validUnit(value, FTime|FInteger|FNonNeg, strict&(!nonCSSHint));
+            valid_primitive = validUnit(value, FTime|FInteger|FNonNeg, strict);
         break;
     case CSS_PROP__KHTML_USER_MODIFY:	// read-only | read-write
         if (id == CSS_VAL_READ_ONLY || id == CSS_VAL_READ_WRITE)
@@ -1888,7 +1881,7 @@ bool CSSParser::parseShadow( int propId, bool important )
             // The only other type of value that's ok is a color value.
             CSSPrimitiveValueImpl* parsedColor = 0;
             bool isColor = (val->id >= CSS_VAL_AQUA && val->id <= CSS_VAL_WINDOWTEXT || val->id == CSS_VAL_MENU ||
-                            (val->id >= CSS_VAL_GREY && val->id <= CSS_VAL__KHTML_TEXT && (nonCSSHint|!strict)));
+                            (val->id >= CSS_VAL_GREY && val->id <= CSS_VAL__KHTML_TEXT && !strict));
             if (isColor) {
                 if (!context.allowColor)
                     return context.failed();
diff --git a/WebCore/khtml/css/cssparser.h b/WebCore/khtml/css/cssparser.h
index 55d1669..10b82e9 100644
--- a/WebCore/khtml/css/cssparser.h
+++ b/WebCore/khtml/css/cssparser.h
@@ -108,9 +108,8 @@ namespace DOM {
 	void parseSheet( DOM::CSSStyleSheetImpl *sheet, const DOM::DOMString &string );
 	DOM::CSSRuleImpl *parseRule( DOM::CSSStyleSheetImpl *sheet, const DOM::DOMString &string );
 	bool parseValue( DOM::CSSStyleDeclarationImpl *decls, int id, const DOM::DOMString &string,
-			 bool _important, bool _nonCSSHint );
-	bool parseDeclaration( DOM::CSSStyleDeclarationImpl *decls, const DOM::DOMString &string,
-			       bool _nonCSSHint );
+			 bool _important );
+	bool parseDeclaration( DOM::CSSStyleDeclarationImpl *decls, const DOM::DOMString &string );
 
 	static CSSParser *current() { return currentParser; }
 
@@ -139,7 +138,6 @@ namespace DOM {
     public:
 	bool strict;
 	bool important;
-	bool nonCSSHint;
 	int id;
 	DOM::StyleListImpl *styleElement;
 	DOM::CSSRuleImpl *rule;
diff --git a/WebCore/khtml/css/cssstyleselector.cpp b/WebCore/khtml/css/cssstyleselector.cpp
index e4c9a8f..2f2f3eb 100644
--- a/WebCore/khtml/css/cssstyleselector.cpp
+++ b/WebCore/khtml/css/cssstyleselector.cpp
@@ -107,16 +107,16 @@ if (id == propID) \
 
 namespace khtml {
 
-CSSStyleSelectorList *CSSStyleSelector::defaultStyle = 0;
-CSSStyleSelectorList *CSSStyleSelector::defaultQuirksStyle = 0;
-CSSStyleSelectorList *CSSStyleSelector::defaultPrintStyle = 0;
+CSSRuleSet *CSSStyleSelector::defaultStyle = 0;
+CSSRuleSet *CSSStyleSelector::defaultQuirksStyle = 0;
+CSSRuleSet *CSSStyleSelector::defaultPrintStyle = 0;
 CSSStyleSheetImpl *CSSStyleSelector::defaultSheet = 0;
 RenderStyle* CSSStyleSelector::styleNotYetAvailable = 0;
 CSSStyleSheetImpl *CSSStyleSelector::quirksSheet = 0;
 
 static CSSStyleSelector::Encodedurl *encodedurl = 0;
 
-enum PseudoState { PseudoUnknown, PseudoNone, PseudoLink, PseudoVisited};
+enum PseudoState { PseudoUnknown, PseudoNone, PseudoAnyLink, PseudoLink, PseudoVisited};
 static PseudoState pseudoState;
 
 
@@ -131,33 +131,26 @@ CSSStyleSelector::CSSStyleSelector( DocumentImpl* doc, QString userStyleSheet, S
     if(!defaultStyle) loadDefaultStyle(settings);
     m_medium = view ? view->mediaType() : QString("all");
 
-    selectors = 0;
-    selectorCache = 0;
-    properties = 0;
-    userStyle = 0;
-    userSheet = 0;
+    m_userStyle = 0;
+    m_userSheet = 0;
     paintDeviceMetrics = doc->paintDeviceMetrics();
 
+    // FIXME: This sucks! The user sheet is reparsed every time!
     if ( !userStyleSheet.isEmpty() ) {
-        userSheet = new DOM::CSSStyleSheetImpl(doc);
-        userSheet->parseString( DOMString( userStyleSheet ) );
+        m_userSheet = new DOM::CSSStyleSheetImpl(doc);
+        m_userSheet->parseString( DOMString( userStyleSheet ) );
 
-        userStyle = new CSSStyleSelectorList();
-        userStyle->append( userSheet, m_medium );
+        m_userStyle = new CSSRuleSet();
+        m_userStyle->addRulesFromSheet( m_userSheet, m_medium );
     }
 
     // add stylesheets from document
-    authorStyle = new CSSStyleSelectorList();
+    m_authorStyle = new CSSRuleSet();
 
-
-    QPtrListIterator<StyleSheetImpl> it( styleSheets->styleSheets );
-    for ( ; it.current(); ++it ) {
-        if ( it.current()->isCSSStyleSheet() ) {
-            authorStyle->append( static_cast<CSSStyleSheetImpl*>( it.current() ), m_medium );
-        }
-    }
-
-    buildLists();
+    QPtrListIterator<StyleSheetImpl> it(styleSheets->styleSheets);
+    for (; it.current(); ++it)
+        if (it.current()->isCSSStyleSheet())
+            m_authorStyle->addRulesFromSheet(static_cast<CSSStyleSheetImpl*>(it.current()), m_medium);
 
     //kdDebug( 6080 ) << "number of style sheets in document " << authorStyleSheets.count() << endl;
     //kdDebug( 6080 ) << "CSSStyleSelector: author style has " << authorStyle->count() << " elements"<< endl;
@@ -187,8 +180,8 @@ CSSStyleSelector::CSSStyleSelector( CSSStyleSheetImpl *sheet )
     KHTMLView *view = sheet->doc()->view();
     m_medium =  view ? view->mediaType() : QString("all");
 
-    authorStyle = new CSSStyleSelectorList();
-    authorStyle->append( sheet, m_medium );
+    m_authorStyle = new CSSRuleSet();
+    m_authorStyle->addRulesFromSheet( sheet, m_medium );
 }
 
 void CSSStyleSelector::init()
@@ -196,27 +189,14 @@ void CSSStyleSelector::init()
     element = 0;
     settings = 0;
     paintDeviceMetrics = 0;
-    propsToApply = (CSSOrderedProperty **)malloc(128*sizeof(CSSOrderedProperty *));
-    pseudoProps = (CSSOrderedProperty **)malloc(128*sizeof(CSSOrderedProperty *));
-    propsToApplySize = 128;
-    pseudoPropsSize = 128;
+    m_matchedRuleCount = m_matchedDeclCount = m_tmpRuleCount = 0;
 }
 
 CSSStyleSelector::~CSSStyleSelector()
 {
-    clearLists();
-    delete authorStyle;
-    delete userStyle;
-    delete userSheet;
-    free(propsToApply);
-    free(pseudoProps);
-}
-
-void CSSStyleSelector::addSheet( CSSStyleSheetImpl *sheet )
-{
-    KHTMLView *view = sheet->doc()->view();
-    m_medium = view ? view->mediaType() : QString("all");
-    authorStyle->append( sheet, m_medium );
+    delete m_authorStyle;
+    delete m_userStyle;
+    delete m_userSheet;
 }
 
 void CSSStyleSelector::loadDefaultStyle(const KHTMLSettings *s)
@@ -242,11 +222,11 @@ void CSSStyleSelector::loadDefaultStyle(const KHTMLSettings *s)
         defaultSheet->parseString( str );
 
         // Collect only strict-mode rules.
-        defaultStyle = new CSSStyleSelectorList();
-        defaultStyle->append( defaultSheet, "screen" );
-
-        defaultPrintStyle = new CSSStyleSelectorList();
-        defaultPrintStyle->append( defaultSheet, "print" );
+        defaultStyle = new CSSRuleSet();
+        defaultStyle->addRulesFromSheet( defaultSheet, "screen" );
+        
+        defaultPrintStyle = new CSSRuleSet();
+        defaultPrintStyle->addRulesFromSheet( defaultSheet, "print" );
     }
     {
         QFile f(locate( "data", "khtml/css/quirks.css" ) );
@@ -265,8 +245,8 @@ void CSSStyleSelector::loadDefaultStyle(const KHTMLSettings *s)
         quirksSheet->parseString( str );
 
         // Collect only quirks-mode rules.
-        defaultQuirksStyle = new CSSStyleSelectorList();
-        defaultQuirksStyle->append( quirksSheet, "screen" );
+        defaultQuirksStyle = new CSSRuleSet();
+        defaultQuirksStyle->addRulesFromSheet( quirksSheet, "screen" );
     }
 
     //kdDebug() << "CSSStyleSelector: default style has " << defaultStyle->count() << " elements"<< endl;
@@ -286,32 +266,165 @@ void CSSStyleSelector::clear()
     styleNotYetAvailable = 0;
 }
 
-static inline void bubbleSort( CSSOrderedProperty **b, CSSOrderedProperty **e )
+void CSSStyleSelector::addMatchedRule(CSSRuleData* rule)
 {
-    while( b < e ) {
-	bool swapped = FALSE;
-        CSSOrderedProperty **y = e+1;
-	CSSOrderedProperty **x = e;
-        CSSOrderedProperty **swappedPos = 0;
-	do {
-	    if ( !((**(--x)) < (**(--y))) ) {
-		swapped = TRUE;
-                swappedPos = x;
-                CSSOrderedProperty *tmp = *y;
-                *y = *x;
-                *x = tmp;
-	    }
-	} while( x != b );
-	if ( !swapped ) break;
-        b = swappedPos + 1;
+    if (m_matchedRules.size() <= m_matchedRuleCount)
+        m_matchedRules.resize(2*m_matchedRules.size()+1);
+    m_matchedRules[m_matchedRuleCount++] = rule;
+}
+
+void CSSStyleSelector::addMatchedDeclaration(CSSStyleDeclarationImpl* decl)
+{
+    if (m_matchedDecls.size() <= m_matchedDeclCount)
+        m_matchedDecls.resize(2*m_matchedDecls.size()+1);
+    m_matchedDecls[m_matchedDeclCount++] = decl;
+}
+
+void CSSStyleSelector::matchRules(CSSRuleSet* rules, int& firstRuleIndex, int& lastRuleIndex)
+{
+    m_matchedRuleCount = 0;
+    firstRuleIndex = lastRuleIndex = -1;
+    if (!rules || !element) return;
+    
+    // We need to collect the rules for id, class, tag, and everything else into a buffer and
+    // then sort the buffer.
+    if (element->hasID())
+        matchRulesForList(rules->getIDRules(element->getIDAttribute().implementation()),
+                          firstRuleIndex, lastRuleIndex);
+    if (element->hasClass()) {
+        for (const AtomicStringList* singleClass = element->getClassList();
+             singleClass; singleClass = singleClass->next())
+            matchRulesForList(rules->getClassRules(singleClass->string().implementation()),
+                                                   firstRuleIndex, lastRuleIndex);
+    }
+    matchRulesForList(rules->getTagRules((void*)(int)localNamePart(element->id())),
+                      firstRuleIndex, lastRuleIndex);
+    matchRulesForList(rules->getUniversalRules(), firstRuleIndex, lastRuleIndex);
+    
+    // If we didn't match any rules, we're done.
+    if (m_matchedRuleCount == 0) return;
+    
+    // Sort the set of matched rules.
+    sortMatchedRules(0, m_matchedRuleCount);
+    
+    // Now transfer the set of matched rules over to our list of decls.
+    for (unsigned i = 0; i < m_matchedRuleCount; i++)
+        addMatchedDeclaration(m_matchedRules[i]->rule()->declaration());
+}
+
+void CSSStyleSelector::matchRulesForList(CSSRuleDataList* rules,
+                                         int& firstRuleIndex, int& lastRuleIndex)
+{
+    if (!rules) return;
+    for (CSSRuleData* d = rules->first(); d; d = d->next()) {
+        CSSStyleRuleImpl* rule = d->rule();
+        Q_UINT16 cssTagId = localNamePart(element->id());
+        Q_UINT16 tag = localNamePart(d->selector()->tag);
+        if ((cssTagId == tag || tag == anyLocalName) && checkSelector(d->selector(), element)) {
+            // If the rule has no properties to apply, then ignore it.
+            CSSStyleDeclarationImpl* decl = rule->declaration();
+            if (!decl) continue;
+            
+            // If we're matching normal rules, set a pseudo bit if 
+            // we really just matched a pseudo-element.
+            if (dynamicPseudo != RenderStyle::NOPSEUDO && pseudoStyle == RenderStyle::NOPSEUDO)
+                style->setHasPseudoStyle(dynamicPseudo);
+            else  {
+                // Update our first/last rule indices in the matched rules array.
+                lastRuleIndex = m_matchedDeclCount + m_matchedRuleCount;
+                if (firstRuleIndex == -1) firstRuleIndex = m_matchedDeclCount + m_matchedRuleCount;
+
+                // Add this rule to our list of matched rules.
+                addMatchedRule(d);
+            }
+        }
     }
 }
 
+bool operator >(CSSRuleData& r1, CSSRuleData& r2)
+{
+    int spec1 = r1.selector()->specificity();
+    int spec2 = r2.selector()->specificity();
+    return (spec1 == spec2) ? r1.position() > r2.position() : spec1 > spec2; 
+}
+bool operator <=(CSSRuleData& r1, CSSRuleData& r2)
+{
+    return !(r1 > r2);
+}
+
+void CSSStyleSelector::sortMatchedRules(uint start, uint end)
+{
+    if (start >= end || (end-start == 1))
+        return; // Sanity check.
+    
+    if (end - start <= 6) {
+        // Apply a bubble sort for smaller lists.
+        for (uint i = end-1; i > start; i--) {
+            bool sorted = true;
+            for (uint j = start; j < i; j++) {
+                CSSRuleData* elt = m_matchedRules[j];
+                CSSRuleData* elt2 = m_matchedRules[j+1];
+                if (*elt > *elt2) {
+                    sorted = false;
+                    m_matchedRules[j] = elt2;
+                    m_matchedRules[j+1] = elt;
+                }
+            }
+            if (sorted)
+                return;
+        }
+    }
+    else {
+        // Peform a merge sort for larger lists.
+        uint mid = (start+end)/2;
+        sortMatchedRules(start, mid);
+        sortMatchedRules(mid, end);
+        
+        CSSRuleData* elt = m_matchedRules[mid-1];
+        CSSRuleData* elt2 = m_matchedRules[mid];
+        
+        // Handle the fast common case (of equal specificity).  The list may already
+        // be completely sorted.
+        if (*elt <= *elt2)
+            return;
+        
+        // We have to merge sort.  Ensure our merge buffer is big enough to hold
+        // all the items.
+        m_tmpRules.resize(end - start);
+        uint i1 = start;
+        uint i2 = mid;
+        
+        elt = m_matchedRules[i1];
+        elt2 = m_matchedRules[i2];
+        
+        while (i1 < mid || i2 < end) {
+            if (i1 < mid && (i2 == end || *elt <= *elt2)) {
+                m_tmpRules[m_tmpRuleCount++] = elt;
+                i1++;
+                if (i1 < mid)
+                    elt = m_matchedRules[i1];
+            }
+            else {
+                m_tmpRules[m_tmpRuleCount++] = elt2;
+                i2++;
+                if (i2 < end)
+                    elt2 = m_matchedRules[i2];
+            }
+        }
+        
+        for (uint i = start; i < end; i++)
+            m_matchedRules[i] = m_tmpRules[i-start];
+        
+        m_tmpRuleCount = 0;
+    }    
+}
+
 void CSSStyleSelector::initForStyleResolve(ElementImpl* e, RenderStyle* defaultParent)
 {
     // set some variables we will need
     ::encodedurl = &encodedurl;
     pseudoState = PseudoUnknown;
+    pseudoStyle = RenderStyle::NOPSEUDO;
     
     element = e;
     parentNode = e->parentNode();
@@ -326,6 +439,12 @@ void CSSStyleSelector::initForStyleResolve(ElementImpl* e, RenderStyle* defaultP
     paintDeviceMetrics = element->getDocument()->paintDeviceMetrics();
     
     style = 0;
+    
+    m_matchedRuleCount = 0;
+    m_matchedDeclCount = 0;
+    m_tmpRuleCount = 0;
+    
+    fontDirty = false;
 }
 
 RenderStyle* CSSStyleSelector::styleForElement(ElementImpl* e, RenderStyle* defaultParent)
@@ -347,86 +466,88 @@ RenderStyle* CSSStyleSelector::styleForElement(ElementImpl* e, RenderStyle* defa
     else
         parentStyle = style;
     
-    unsigned int numPropsToApply = 0;
+    // 1. First we match rules from the user agent sheet.
+    int firstUARule = -1, lastUARule = -1;
+    matchRules(defaultStyle, firstUARule, lastUARule);
     
-    // try to sort out most style rules as early as possible.
-    Q_UINT16 cssTagId = localNamePart(e->id());
-    int smatch = 0;
-    int schecked = 0;
-
-    for ( unsigned int i = 0; i < selectors_size; i++ ) {
-	Q_UINT16 tag = localNamePart(selectors[i]->tag);
-	if ( cssTagId == tag || tag == anyLocalName ) {
-	    ++schecked;
-
-	    checkSelector( i, e );
-
-	    if ( selectorCache[i].state == Applies ) {
-		++smatch;
-
-		//qDebug("adding property" );
-		for ( unsigned int p = 0; p < selectorCache[i].props_size; p += 2 )
-		    for ( unsigned int j = 0; j < (unsigned int )selectorCache[i].props[p+1]; ++j ) {
-                        if (numPropsToApply >= propsToApplySize ) {
-                            propsToApplySize *= 2;
-			    propsToApply = (CSSOrderedProperty **)realloc( propsToApply, propsToApplySize*sizeof( CSSOrderedProperty * ) );
-			}
-			propsToApply[numPropsToApply++] = properties[selectorCache[i].props[p]+j];
-		    }
-	    }
-            else if (selectorCache[i].state == AppliesPseudo)
-                style->setHasPseudoStyle((RenderStyle::PseudoId)selectors[i]->pseudoId);
-	}
-	else
-	    selectorCache[i].state = Invalid;
-
+    // 2. In quirks mode, we match rules from the quirks user agent sheet.
+    if (!strictParsing)
+        matchRules(defaultQuirksStyle, firstUARule, lastUARule);
+    
+    // 3. If our medium is print, then we match rules from the print sheet.
+    if (m_medium == "print")
+        matchRules(defaultPrintStyle, firstUARule, lastUARule);
+    
+    // 4. Now we check user sheet rules.
+    int firstUserRule = -1, lastUserRule = -1;
+    matchRules(m_userStyle, firstUserRule, lastUserRule);
+    
+    // 5. Now check author rules, beginning first with presentational attributes
+    // mapped from HTML.
+    int firstAuthorRule = -1, lastAuthorRule = -1;
+    CSSStyleDeclarationImpl* attributeDecl = e->attributeStyleDecl();
+    if (attributeDecl) {
+        firstAuthorRule = lastAuthorRule = m_matchedDeclCount;
+        addMatchedDeclaration(attributeDecl);
     }
-
-    //qDebug( "styleForElement( %s )", e->tagName().string().latin1() );
-    //qDebug( "%d selectors, %d checked,  %d match,  %d properties ( of %d )",
-    //selectors_size, schecked, smatch, propsToApply->count(), properties_size );
-
-    // inline style declarations, after all others. non css hints
-    // count as author rules, and come before all other style sheets, see hack in append()
-    numPropsToApply = addInlineDeclarations( e, e->m_styleDecls, numPropsToApply );
-            
-    bubbleSort( propsToApply, propsToApply+numPropsToApply-1 );
     
-    //qDebug("applying properties, count=%d", propsToApply->count() );
-
-    // we can't apply style rules without a view() and a part. This
-    // tends to happen on delayed destruction of widget Renderobjects
-    if ( part ) {
+    // Table cells share an additional mapped rule.
+    attributeDecl = e->additionalAttributeStyleDecl();
+    if (attributeDecl) {
+        if (firstAuthorRule == -1) firstAuthorRule = m_matchedDeclCount;
+        lastAuthorRule = m_matchedDeclCount;
+        addMatchedDeclaration(attributeDecl);
+    }
+    
+    // 6. Check the rules in author sheets next.
+    matchRules(m_authorStyle, firstAuthorRule, lastAuthorRule);
+    
+    // 7. Now check our inline style attribute.
+    CSSStyleDeclarationImpl* inlineDecl = e->inlineStyleDecl();
+    if (inlineDecl) {
+        if (firstAuthorRule == -1) firstAuthorRule = m_matchedDeclCount;
+        lastAuthorRule = m_matchedDeclCount;
+        addMatchedDeclaration(inlineDecl);
+    }
+    
+    // Now we have all of the matched rules in the appropriate order.  Walk the rules and apply
+    // high-priority properties first, i.e., those properties that other properties depend on.
+    // The order is (1) high-priority not important, (2) high-priority important, (3) normal not important
+    // and (4) normal important.
+    applyDeclarations(true, false, 0, m_matchedDeclCount-1);
+    applyDeclarations(true, true, firstAuthorRule, lastAuthorRule);
+    applyDeclarations(true, true, firstUserRule, lastUserRule);
+    applyDeclarations(true, true, firstUARule, lastUARule);
+    
+    // If our font got dirtied, go ahead and update it now.
+    if (fontDirty) {
+        checkForGenericFamilyChange(style, parentStyle);
+        style->htmlFont().update(paintDeviceMetrics);
         fontDirty = false;
-
-        if (numPropsToApply ) {
-            CSSStyleSelector::style = style;
-            for (unsigned int i = 0; i < numPropsToApply; ++i) {
-		if ( fontDirty && propsToApply[i]->priority >= (1 << 30) ) {
-		    // we are past the font properties, time to update to the
-		    // correct font
-		    checkForGenericFamilyChange(style, parentStyle);
-		    CSSStyleSelector::style->htmlFont().update( paintDeviceMetrics );
-		    fontDirty = false;
-		}
-                DOM::CSSProperty *prop = propsToApply[i]->prop;
-                applyRule( prop->m_id, prop->value() );
-	    }
-	    if ( fontDirty ) {
-	        checkForGenericFamilyChange(style, parentStyle);
-		CSSStyleSelector::style->htmlFont().update( paintDeviceMetrics );
-	    }
-        }
-
-        // Clean up our style object's display and text decorations (among other fixups).
-        adjustRenderStyle(style, e);
     }
+    
+    // Now do the normal priority properties.
+    applyDeclarations(false, false, 0, m_matchedDeclCount-1);
+    applyDeclarations(false, true, firstAuthorRule, lastAuthorRule);
+    applyDeclarations(false, true, firstUserRule, lastUserRule);
+    applyDeclarations(false, true, firstUARule, lastUARule);
+    
+    // If our font got dirtied by one of the non-essential font props, 
+    // go ahead and update it a second time.
+    if (fontDirty) {
+        checkForGenericFamilyChange(style, parentStyle);
+        style->htmlFont().update(paintDeviceMetrics);
+        fontDirty = false;
+    }
+    
+    // Clean up our style object's display and text decorations (among other fixups).
+    adjustRenderStyle(style, e);
 
     // Now return the style.
     return style;
 }
 
-RenderStyle* CSSStyleSelector::pseudoStyleForElement(RenderStyle::PseudoId pseudoStyle, 
+RenderStyle* CSSStyleSelector::pseudoStyleForElement(RenderStyle::PseudoId pseudo, 
                                                      ElementImpl* e, RenderStyle* parentStyle)
 {
     if (!e)
@@ -442,37 +563,18 @@ RenderStyle* CSSStyleSelector::pseudoStyleForElement(RenderStyle::PseudoId pseud
     }
     
     initForStyleResolve(e, parentStyle);
+    pseudoStyle = pseudo;
     
-    unsigned int numPseudoProps = 0;
+    // Since we don't use pseudo-elements in any of our quirk/print user agent rules, don't waste time walking
+    // those rules.
     
-    // try to sort out most style rules as early as possible.
-    Q_UINT16 cssTagId = localNamePart(e->id());
-    int schecked = 0;
+    // Check UA, user and author rules.
+    int firstUARule = -1, lastUARule = -1, firstUserRule = -1, lastUserRule = -1, firstAuthorRule = -1, lastAuthorRule = -1;
+    matchRules(defaultStyle, firstUARule, lastUARule);
+    matchRules(m_userStyle, firstUserRule, lastUserRule);
+    matchRules(m_authorStyle, firstAuthorRule, lastAuthorRule);
     
-    for ( unsigned int i = 0; i < selectors_size; i++ ) {
-        Q_UINT16 tag = localNamePart(selectors[i]->tag);
-        if ( cssTagId == tag || tag == anyLocalName ) {
-            ++schecked;
-            
-            checkSelector( i, e, pseudoStyle );
-            
-            if ( selectorCache[i].state == AppliesPseudo ) {
-                for ( unsigned int p = 0; p < selectorCache[i].props_size; p += 2 )
-                    for ( unsigned int j = 0; j < (unsigned int) selectorCache[i].props[p+1]; ++j ) {
-                        if (numPseudoProps >= pseudoPropsSize ) {
-                            pseudoPropsSize *= 2;
-                            pseudoProps = (CSSOrderedProperty **)realloc( pseudoProps, pseudoPropsSize*sizeof( CSSOrderedProperty * ) );
-                        }
-                        pseudoProps[numPseudoProps++] = properties[selectorCache[i].props[p]+j];
-                        properties[selectorCache[i].props[p]+j]->pseudoId = (RenderStyle::PseudoId) selectors[i]->pseudoId;
-                    }
-            }
-        }
-        else
-            selectorCache[i].state = Invalid;
-    }
-    
-    if (numPseudoProps == 0)
+    if (m_matchedDeclCount == 0)
         return 0;
     
     style = new RenderStyle();
@@ -481,38 +583,37 @@ RenderStyle* CSSStyleSelector::pseudoStyleForElement(RenderStyle::PseudoId pseud
     else
         parentStyle = style;
     style->noninherited_flags._styleType = pseudoStyle;
-        
-    bubbleSort( pseudoProps, pseudoProps+numPseudoProps-1 );
-        
-    // we can't apply style rules without a view() and a part. This
-    // tends to happen on delayed destruction of widget Renderobjects
-    if ( part ) {
+    
+    // High-priority properties.
+    applyDeclarations(true, false, 0, m_matchedDeclCount-1);
+    applyDeclarations(true, true, firstAuthorRule, lastAuthorRule);
+    applyDeclarations(true, true, firstUserRule, lastUserRule);
+    applyDeclarations(true, true, firstUARule, lastUARule);
+    
+    // If our font got dirtied, go ahead and update it now.
+    if (fontDirty) {
+        checkForGenericFamilyChange(style, parentStyle);
+        style->htmlFont().update(paintDeviceMetrics);
         fontDirty = false;
-        if ( numPseudoProps ) {
-            fontDirty = false;
-            //qDebug("%d applying %d pseudo props", e->cssTagId(), pseudoProps->count() );
-            for (unsigned int i = 0; i < numPseudoProps; ++i) {
-                if ( fontDirty && pseudoProps[i]->priority >= (1 << 30) ) {
-                    // we are past the font properties, time to update to the
-                    // correct font
-                    style->htmlFont().update( paintDeviceMetrics );
-                    fontDirty = false;
-                }
-                
-               DOM::CSSProperty *prop = pseudoProps[i]->prop;
-               applyRule( prop->m_id, prop->value() );
-            }
-            
-            if ( fontDirty ) {
-                checkForGenericFamilyChange(style, parentStyle);
-                style->htmlFont().update( paintDeviceMetrics );
-            }
-        }
     }
     
-    // Do the post-resolve fixups on the style.
+    // Now do the normal priority properties.
+    applyDeclarations(false, false, 0, m_matchedDeclCount-1);
+    applyDeclarations(false, true, firstAuthorRule, lastAuthorRule);
+    applyDeclarations(false, true, firstUserRule, lastUserRule);
+    applyDeclarations(false, true, firstUARule, lastUARule);
+    
+    // If our font got dirtied by one of the non-essential font props, 
+    // go ahead and update it a second time.
+    if (fontDirty) {
+        checkForGenericFamilyChange(style, parentStyle);
+        style->htmlFont().update(paintDeviceMetrics);
+        fontDirty = false;
+    }
+    
+    // Clean up our style object's display and text decorations (among other fixups).
     adjustRenderStyle(style, 0);
-        
+
     // Now return the style.
     return style;
 }
@@ -593,77 +694,6 @@ void CSSStyleSelector::adjustRenderStyle(RenderStyle* style, DOM::ElementImpl *e
         style->addToTextDecorationsInEffect(style->textDecoration());
 }
 
-unsigned int CSSStyleSelector::addInlineDeclarations(DOM::ElementImpl* e,
-                                                     DOM::CSSStyleDeclarationImpl *decl,
-                                                     unsigned int numProps)
-{
-    CSSStyleDeclarationImpl* addDecls = 0;
-    if (e->id() == ID_TD || e->id() == ID_TH)     // For now only TableCellElement implements the
-        addDecls = e->getAdditionalStyleDecls();  // virtual function for shared cell rules.
-
-    if (!decl && !addDecls)
-        return numProps;
-
-    QPtrList<CSSProperty>* values = decl ? decl->values() : 0;
-    QPtrList<CSSProperty>* addValues = addDecls ? addDecls->values() : 0;
-    if (!values && !addValues)
-        return numProps;
-    
-    int firstLen = values ? values->count() : 0;
-    int secondLen = addValues ? addValues->count() : 0;
-    int totalLen = firstLen + secondLen;
-
-    if (inlineProps.size() < (uint)totalLen)
-        inlineProps.resize(totalLen + 1);
-    
-    if (numProps + totalLen >= propsToApplySize ) {
-        propsToApplySize += propsToApplySize;
-        propsToApply = (CSSOrderedProperty **)realloc( propsToApply, propsToApplySize*sizeof( CSSOrderedProperty * ) );
-    }
-
-    CSSOrderedProperty *array = (CSSOrderedProperty *)inlineProps.data();
-    for(int i = 0; i < totalLen; i++)
-    {
-        if (i == firstLen)
-            values = addValues;
-
-        CSSProperty *prop = values->at(i >= firstLen ? i - firstLen : i);
-	Source source = Inline;
-
-        if( prop->m_bImportant ) source = InlineImportant;
-	if( prop->nonCSSHint ) source = NonCSSHint;
-
-	bool first;
-        // give special priority to font-xxx, color properties
-        switch(prop->m_id)
-        {
-	case CSS_PROP_FONT_STYLE:
-        case CSS_PROP_FONT_SIZE:
-	case CSS_PROP_FONT_WEIGHT:
-	case CSS_PROP_FONT_FAMILY:
-        case CSS_PROP_FONT:
-        case CSS_PROP_COLOR:
-        case CSS_PROP_BACKGROUND_IMAGE:
-	case CSS_PROP_DISPLAY:
-            // these have to be applied first, because other properties use the computed
-            // values of these porperties.
-	    first = true;
-            break;
-        default:
-            first = false;
-            break;
-        }
-
-	array->prop = prop;
-	array->pseudoId = RenderStyle::NOPSEUDO;
-	array->selector = 0;
-        array->position = i;
-	array->priority = (!first << 30) | (source << 24);
-	propsToApply[numProps++] = array++;
-    }
-    return numProps;
-}
-
 static bool subject;
 
 // modified version of the one in kurl.cpp
@@ -704,17 +734,24 @@ static void cleanpath(QString &path)
     //kdDebug() << "checkPseudoState " << path << endl;
 }
 
-static void checkPseudoState( DOM::ElementImpl *e )
+static void checkPseudoState( DOM::ElementImpl *e, bool checkVisited = true )
 {
     if (!e->hasAnchor()) {
         pseudoState = PseudoNone;
         return;
     }
+
     const AtomicString& attr = e->getAttribute(ATTR_HREF);
-    if( attr.isNull() ) {
+    if (attr.isNull()) {
         pseudoState = PseudoNone;
         return;
     }
+    
+    if (!checkVisited) {
+        pseudoState = PseudoAnyLink;
+        return;
+    }
+
     QConstString cu(attr.unicode(), attr.length());
     QString u = cu.string();
     if ( !u.contains("://") ) {
@@ -730,15 +767,12 @@ static void checkPseudoState( DOM::ElementImpl *e )
     pseudoState = KHTMLFactory::vLinks()->contains( u ) ? PseudoVisited : PseudoLink;
 }
 
-void CSSStyleSelector::checkSelector(int selIndex, DOM::ElementImpl *e, RenderStyle::PseudoId pseudo)
+bool CSSStyleSelector::checkSelector(CSSSelector* sel, ElementImpl *e)
 {
     dynamicPseudo = RenderStyle::NOPSEUDO;
     
     NodeImpl *n = e;
 
-    selectorCache[ selIndex ].state = Invalid;
-    CSSSelector *sel = selectors[ selIndex ];
-
     // we have the subject part of the selector
     subject = true;
 
@@ -751,33 +785,34 @@ void CSSStyleSelector::checkSelector(int selIndex, DOM::ElementImpl *e, RenderSt
                                sel->pseudoType() == CSSSelector::PseudoActive)));
     bool affectedByHover = style ? style->affectedByHoverRules() : false;
     bool affectedByActive = style ? style->affectedByActiveRules() : false;
-    bool havePseudo = pseudo != RenderStyle::NOPSEUDO;
+    bool havePseudo = pseudoStyle != RenderStyle::NOPSEUDO;
     
     // first selector has to match
-    if(!checkOneSelector(sel, e)) return;
+    if (!checkOneSelector(sel, e)) return false;
 
     // check the subselectors
     CSSSelector::Relation relation = sel->relation;
     while((sel = sel->tagHistory))
     {
-        if (!n->isElementNode()) return;
+        if (!n->isElementNode()) return false;
         if (relation != CSSSelector::SubSelector) {
             subject = false;
-            if (havePseudo && dynamicPseudo != pseudo)
-                return;
+            if (havePseudo && dynamicPseudo != pseudoStyle)
+                return false;
         }
         
         switch(relation)
         {
         case CSSSelector::Descendant:
         {
+            // FIXME: This match needs to know how to backtrack and be non-deterministic.
             bool found = false;
             while(!found)
             {
 		n = n->parentNode();
-                if(!n || !n->isElementNode()) return;
+                if(!n || !n->isElementNode()) return false;
                 ElementImpl *elem = static_cast<ElementImpl *>(n);
-                if(checkOneSelector(sel, elem)) found = true;
+                if (checkOneSelector(sel, elem)) found = true;
             }
             break;
         }
@@ -786,9 +821,9 @@ void CSSStyleSelector::checkSelector(int selIndex, DOM::ElementImpl *e, RenderSt
             n = n->parentNode();
             if (!strictParsing)
                 while (n && n->implicitNode()) n = n->parentNode();
-            if(!n || !n->isElementNode()) return;
+            if(!n || !n->isElementNode()) return false;
             ElementImpl *elem = static_cast<ElementImpl *>(n);
-            if(!checkOneSelector(sel, elem)) return;
+            if (!checkOneSelector(sel, elem)) return false;
             break;
         }
         case CSSSelector::Sibling:
@@ -796,9 +831,9 @@ void CSSStyleSelector::checkSelector(int selIndex, DOM::ElementImpl *e, RenderSt
             n = n->previousSibling();
 	    while( n && !n->isElementNode() )
 		n = n->previousSibling();
-            if( !n ) return;
+            if( !n ) return false;
             ElementImpl *elem = static_cast<ElementImpl *>(n);
-            if(!checkOneSelector(sel, elem)) return;
+            if (!checkOneSelector(sel, elem)) return false;
             break;
         }
         case CSSSelector::SubSelector:
@@ -811,10 +846,9 @@ void CSSStyleSelector::checkSelector(int selIndex, DOM::ElementImpl *e, RenderSt
 	    //kdDebug() << "CSSOrderedRule::checkSelector" << endl;
 	    ElementImpl *elem = static_cast<ElementImpl *>(n);
 	    // a selector is invalid if something follows :first-xxx
-	    if ( dynamicPseudo != RenderStyle::NOPSEUDO ) {
-		return;
-	    }
-	    if(!checkOneSelector(sel, elem)) return;
+	    if (dynamicPseudo != RenderStyle::NOPSEUDO)
+		return false;
+	    if (!checkOneSelector(sel, elem)) return false;
 	    //kdDebug() << "CSSOrderedRule::checkSelector: passed" << endl;
 	    break;
 	}
@@ -822,31 +856,24 @@ void CSSStyleSelector::checkSelector(int selIndex, DOM::ElementImpl *e, RenderSt
         relation = sel->relation;
     }
 
-    if (subject && havePseudo && dynamicPseudo != pseudo)
-        return;
+    if (subject && havePseudo && dynamicPseudo != pseudoStyle)
+        return false;
     
     // disallow *:hover, *:active, and *:hover:active except for links
     if (onlyHoverActive && subject) {
         if (pseudoState == PseudoUnknown)
-            checkPseudoState( e );
+            checkPseudoState(e);
 
         if (pseudoState == PseudoNone) {
             if (!affectedByHover && style->affectedByHoverRules())
                 style->setAffectedByHoverRules(false);
             if (!affectedByActive && style->affectedByActiveRules())
                 style->setAffectedByActiveRules(false);
-            return;
+            return false;
         }
     }
 
-    if ( dynamicPseudo != RenderStyle::NOPSEUDO ) {
-	selectorCache[selIndex].state = AppliesPseudo;
-	selectors[ selIndex ]->pseudoId = dynamicPseudo;
-    } else
-	selectorCache[ selIndex ].state = Applies;
-    //qDebug( "selector %d applies", selIndex );
-    //selectors[ selIndex ]->print();
-    return;
+    return true;
 }
 
 bool CSSStyleSelector::checkOneSelector(DOM::CSSSelector *sel, DOM::ElementImpl *e)
@@ -870,14 +897,16 @@ bool CSSStyleSelector::checkOneSelector(DOM::CSSSelector *sel, DOM::ElementImpl
     }
 
     if (sel->attr) {
-        if (sel->match == CSSSelector::Class)
-            return e->hasClass() && e->matchesCSSClass(sel->value, strictParsing);
-        else if (sel->match == CSSSelector::Id) {
-            if (!e->hasID()) return false;
-            const AtomicString& value = e->getAttribute(sel->attr);
-            return !((strictParsing && sel->value != value) ||
-                     (!strictParsing && !equalsIgnoreCase(sel->value, value)));
+        if (sel->match == CSSSelector::Class) {
+            if (!e->hasClass())
+                return false;
+            for (const AtomicStringList* c = e->getClassList(); c; c = c->next())
+                if (c->string() == sel->value)
+                    return true;
+            return false;
         }
+        else if (sel->match == CSSSelector::Id)
+            return e->hasID() && e->getIDAttribute() == sel->value;
 
         const AtomicString& value = e->getAttribute(sel->attr);
         if (value.isNull()) return false; // attribute is not set
@@ -1036,14 +1065,20 @@ bool CSSStyleSelector::checkOneSelector(DOM::CSSSelector *sel, DOM::ElementImpl
                 if (e == e->getDocument()->getCSSTarget())
                     return true;
                 break;
+            case CSSSelector::PseudoAnyLink:
+                if (pseudoState == PseudoUnknown)
+                    checkPseudoState(e, false);
+                if (pseudoState == PseudoAnyLink || pseudoState == PseudoLink || pseudoState == PseudoVisited)
+                    return true;
+                break;
             case CSSSelector::PseudoLink:
-                if ( pseudoState == PseudoUnknown )
+                if ( pseudoState == PseudoUnknown || pseudoState == PseudoAnyLink )
                     checkPseudoState( e );
                 if ( pseudoState == PseudoLink )
                     return true;
                 break;
             case CSSSelector::PseudoVisited:
-                if ( pseudoState == PseudoUnknown )
+                if ( pseudoState == PseudoUnknown || pseudoState == PseudoAnyLink )
                     checkPseudoState( e );
                 if ( pseudoState == PseudoVisited )
                     return true;
@@ -1121,205 +1156,101 @@ bool CSSStyleSelector::checkOneSelector(DOM::CSSSelector *sel, DOM::ElementImpl
     return true;
 }
 
-void CSSStyleSelector::clearLists()
-{
-    if ( selectors ) delete [] selectors;
-    if ( selectorCache ) {
-        for ( unsigned int i = 0; i < selectors_size; i++ )
-            if ( selectorCache[i].props )
-                delete [] selectorCache[i].props;
-
-        delete [] selectorCache;
-    }
-    if ( properties ) {
-	CSSOrderedProperty **prop = properties;
-	while ( *prop ) {
-	    delete (*prop);
-	    prop++;
-	}
-        delete [] properties;
-    }
-    selectors = 0;
-    properties = 0;
-    selectorCache = 0;
-}
-
-
-void CSSStyleSelector::buildLists()
-{
-    clearLists();
-    // collect all selectors and Properties in lists. Then transer them to the array for faster lookup.
-
-    QPtrList<CSSSelector> selectorList;
-    CSSOrderedPropertyList propertyList;
-
-    if(m_medium == "print" && defaultPrintStyle)
-      defaultPrintStyle->collect( &selectorList, &propertyList, Default,
-        Default );
-    else if(defaultStyle) defaultStyle->collect( &selectorList, &propertyList,
-      Default, Default );
-      
-    if (!strictParsing && defaultQuirksStyle)
-        defaultQuirksStyle->collect( &selectorList, &propertyList, Default, Default );
-        
-    if(userStyle) userStyle->collect(&selectorList, &propertyList, User, UserImportant );
-    if(authorStyle) authorStyle->collect(&selectorList, &propertyList, Author, AuthorImportant );
-
-    selectors_size = selectorList.count();
-    selectors = new CSSSelector *[selectors_size];
-    CSSSelector *s = selectorList.first();
-    CSSSelector **sel = selectors;
-    while ( s ) {
-	*sel = s;
-	s = selectorList.next();
-	++sel;
-    }
-
-    selectorCache = new SelectorCache[selectors_size];
-    for ( unsigned int i = 0; i < selectors_size; i++ ) {
-        selectorCache[i].state = Unknown;
-        selectorCache[i].props_size = 0;
-        selectorCache[i].props = 0;
-    }
-
-    // presort properties. Should make the sort() calls in styleForElement faster.
-    propertyList.sort();
-    properties_size = propertyList.count() + 1;
-    properties = new CSSOrderedProperty *[ properties_size ];
-    CSSOrderedProperty *p = propertyList.first();
-    CSSOrderedProperty **prop = properties;
-    while ( p ) {
-	*prop = p;
-	p = propertyList.next();
-	++prop;
-    }
-    *prop = 0;
-
-    unsigned int* offsets = new unsigned int[selectors_size];
-    if(properties[0])
-	offsets[properties[0]->selector] = 0;
-    for(unsigned int p = 1; p < properties_size; ++p) {
-
-	if(!properties[p] || (properties[p]->selector != properties[p - 1]->selector)) {
-	    unsigned int sel = properties[p - 1]->selector;
-            int* newprops = new int[selectorCache[sel].props_size+2];
-            for ( unsigned int i=0; i < selectorCache[sel].props_size; i++ )
-                newprops[i] = selectorCache[sel].props[i];
-
-	    newprops[selectorCache[sel].props_size] = offsets[sel];
-	    newprops[selectorCache[sel].props_size+1] = p - offsets[sel];
-            delete [] selectorCache[sel].props;
-            selectorCache[sel].props = newprops;
-            selectorCache[sel].props_size += 2;
-
-	    if(properties[p]) {
-		sel = properties[p]->selector;
-		offsets[sel] = p;
-            }
-        }
-    }
-    delete [] offsets;
-}
-
-
-// ----------------------------------------------------------------------
-
+// -----------------------------------------------------------------
 
-CSSOrderedRule::CSSOrderedRule(DOM::CSSStyleRuleImpl *r, DOM::CSSSelector *s, int _index)
+CSSRuleSet::CSSRuleSet()
 {
-    rule = r;
-    if(rule) r->ref();
-    index = _index;
-    selector = s;
+    m_idRules.setAutoDelete(true);
+    m_classRules.setAutoDelete(true);
+    m_tagRules.setAutoDelete(true);
+    m_universalRules = 0;
+    m_ruleCount = 0;
 }
 
-CSSOrderedRule::~CSSOrderedRule()
+void CSSRuleSet::addToRuleSet(void* hash, QPtrDict<CSSRuleDataList>& dict,
+                              CSSStyleRuleImpl* rule, CSSSelector* sel)
 {
-    if(rule) rule->deref();
+    if (!hash) return;
+    CSSRuleDataList* rules = dict.find(hash);
+    if (!rules) {
+        rules = new CSSRuleDataList(m_ruleCount++, rule, sel);
+        dict.insert(hash, rules);
+    }
+    else
+        rules->append(m_ruleCount++, rule, sel);
 }
 
-// -----------------------------------------------------------------
-
-CSSStyleSelectorList::CSSStyleSelectorList()
-    : QPtrList<CSSOrderedRule>()
-{
-    setAutoDelete(true);
-}
-CSSStyleSelectorList::~CSSStyleSelectorList()
+void CSSRuleSet::addRule(CSSStyleRuleImpl* rule, CSSSelector* sel)
 {
+    if (sel->match == CSSSelector::Id) {
+        addToRuleSet(sel->value.implementation(), m_idRules, rule, sel);
+        return;
+    }
+    if (sel->match == CSSSelector::Class) {
+        addToRuleSet(sel->value.implementation(), m_classRules, rule, sel);
+        return;
+    }
+     
+    Q_UINT16 localName = localNamePart(sel->tag);
+    if (localName != anyLocalName) {
+        addToRuleSet((void*)(int)localName, m_tagRules, rule, sel);
+        return;
+    }
+    
+    // Just put it in the universal rule set.
+    if (!m_universalRules)
+        m_universalRules = new CSSRuleDataList(m_ruleCount++, rule, sel);
+    else
+        m_universalRules->append(m_ruleCount++, rule, sel);
 }
 
-void CSSStyleSelectorList::append( CSSStyleSheetImpl *sheet,
-                                   const DOMString &medium )
+void CSSRuleSet::addRulesFromSheet(CSSStyleSheetImpl *sheet, const DOMString &medium)
 {
-    if(!sheet || !sheet->isCSSStyleSheet()) return;
+    if (!sheet || !sheet->isCSSStyleSheet()) return;
 
-    // No media implies "all", but if a medialist exists it must
+    // No media implies "all", but if a media list exists it must
     // contain our current medium
-    if( sheet->media() && !sheet->media()->contains( medium ) )
-        return; // style sheet not applicable for this medium
+    if (sheet->media() && !sheet->media()->contains(medium))
+        return; // the style sheet doesn't apply
 
     int len = sheet->length();
 
-    for(int i = 0; i< len; i++)
-    {
+    for (int i = 0; i < len; i++) {
         StyleBaseImpl *item = sheet->item(i);
-        if(item->isStyleRule())
-        {
-            CSSStyleRuleImpl *r = static_cast<CSSStyleRuleImpl *>(item);
-            QPtrList<CSSSelector> *s = r->selector();
-            for(int j = 0; j < (int)s->count(); j++)
-            {
-                CSSOrderedRule *rule = new CSSOrderedRule(r, s->at(j), count());
-		QPtrList<CSSOrderedRule>::append(rule);
-                //kdDebug( 6080 ) << "appending StyleRule!" << endl;
-            }
+        if (item->isStyleRule()) {
+            CSSStyleRuleImpl* rule = static_cast<CSSStyleRuleImpl*>(item);
+            for (CSSSelector* s = rule->selector(); s; s = s->next())
+                addRule(rule, s);
         }
-        else if(item->isImportRule())
-        {
+        else if(item->isImportRule()) {
             CSSImportRuleImpl *import = static_cast<CSSImportRuleImpl *>(item);
 
             //kdDebug( 6080 ) << "@import: Media: "
             //                << import->media()->mediaText().string() << endl;
 
-            if( !import->media() || import->media()->contains( medium ) )
-            {
-                CSSStyleSheetImpl *importedSheet = import->styleSheet();
-                append( importedSheet, medium );
-            }
+            if (!import->media() || import->media()->contains(medium))
+                addRulesFromSheet(import->styleSheet(), medium);
         }
-        else if( item->isMediaRule() )
-        {
-            CSSMediaRuleImpl *r = static_cast<CSSMediaRuleImpl *>( item );
+        else if(item->isMediaRule()) {
+            CSSMediaRuleImpl *r = static_cast<CSSMediaRuleImpl*>(item);
             CSSRuleListImpl *rules = r->cssRules();
 
             //DOMString mediaText = media->mediaText();
             //kdDebug( 6080 ) << "@media: Media: "
             //                << r->media()->mediaText().string() << endl;
 
-            if( ( !r->media() || r->media()->contains( medium ) ) && rules)
-            {
-                // Traverse child elements of the @import rule. Since
-                // many elements are not allowed as child we do not use
-                // a recursive call to append() here
-                for( unsigned j = 0; j < rules->length(); j++ )
-                {
+            if ((!r->media() || r->media()->contains(medium)) && rules) {
+                // Traverse child elements of the @media rule.
+                for (unsigned j = 0; j < rules->length(); j++) {
                     //kdDebug( 6080 ) << "*** Rule #" << j << endl;
 
-                    CSSRuleImpl *childItem = rules->item( j );
-                    if( childItem->isStyleRule() )
-                    {
+                    CSSRuleImpl *childItem = rules->item(j);
+                    if (childItem->isStyleRule()) {
                         // It is a StyleRule, so append it to our list
-                        CSSStyleRuleImpl *styleRule =
-                                static_cast<CSSStyleRuleImpl *>( childItem );
-
-                        QPtrList<CSSSelector> *s = styleRule->selector();
-                        for( int j = 0; j < ( int ) s->count(); j++ )
-                        {
-                            CSSOrderedRule *orderedRule = new CSSOrderedRule(
-                                            styleRule, s->at( j ), count() );
-                	    QPtrList<CSSOrderedRule>::append( orderedRule );
-                        }
+                        CSSStyleRuleImpl* rule = static_cast<CSSStyleRuleImpl*>(childItem);
+                        for (CSSSelector* s = rule->selector(); s; s = s->next())
+                            addRule(rule, s);
+                        
                     }
                     else
                     {
@@ -1338,79 +1269,6 @@ void CSSStyleSelectorList::append( CSSStyleSheetImpl *sheet,
     }
 }
 
-
-void CSSStyleSelectorList::collect( QPtrList<CSSSelector> *selectorList, CSSOrderedPropertyList *propList,
-				    Source regular, Source important )
-{
-    CSSOrderedRule *r = first();
-    while( r ) {
-	CSSSelector *sel = selectorList->first();
-	int selectorNum = 0;
-	while( sel ) {
-	    if ( *sel == *(r->selector) )
-		break;
-	    sel = selectorList->next();
-	    selectorNum++;
-	}
-	if ( !sel )
-	    selectorList->append( r->selector );
-//	else
-//	    qDebug("merged one selector");
-	propList->append(r->rule->declaration(), selectorNum, r->selector->specificity(), regular, important );
-	r = next();
-    }
-}
-
-// -------------------------------------------------------------------------
-
-int CSSOrderedPropertyList::compareItems(QPtrCollection::Item i1, QPtrCollection::Item i2)
-{
-    int diff =  static_cast<CSSOrderedProperty *>(i1)->priority
-        - static_cast<CSSOrderedProperty *>(i2)->priority;
-    return diff ? diff : static_cast<CSSOrderedProperty *>(i1)->position
-        - static_cast<CSSOrderedProperty *>(i2)->position;
-}
-
-void CSSOrderedPropertyList::append(DOM::CSSStyleDeclarationImpl *decl, uint selector, uint specificity,
-				    Source regular, Source important )
-{
-    QPtrList<CSSProperty> *values = decl->values();
-    if(!values) return;
-    int len = values->count();
-    for(int i = 0; i < len; i++)
-    {
-        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_STYLE:
-        case CSS_PROP_FONT_SIZE:
-	case CSS_PROP_FONT_WEIGHT:
-	case CSS_PROP_FONT_FAMILY:
-        case CSS_PROP_FONT:
-        case CSS_PROP_COLOR:
-        case CSS_PROP_BACKGROUND_IMAGE:
-	case CSS_PROP_DISPLAY:
-            // these have to be applied first, because other properties use the computed
-            // values of these porperties.
-	    first = true;
-            break;
-        default:
-            break;
-        }
-
-	QPtrList<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...
 
@@ -1583,8 +1441,48 @@ static QColor colorForCSSValue( int css_value )
     return c;
 };
 
+void CSSStyleSelector::applyDeclarations(bool applyFirst, bool isImportant,
+                                         int startIndex, int endIndex)
+{
+    if (startIndex == -1) return;
+    for (int i = startIndex; i <= endIndex; i++) {
+        CSSStyleDeclarationImpl* decl = m_matchedDecls[i];
+        QPtrList<CSSProperty>* props = decl->values();
+        if (props) {
+            QPtrListIterator<CSSProperty> propertyIt(*props);
+            CSSProperty* current;
+            for (propertyIt.toFirst(); (current = propertyIt.current()); ++propertyIt) {
+                // give special priority to font-xxx, color properties
+                if (isImportant == current->isImportant()) {
+                    bool first;
+                    switch(current->id())
+                    {
+                        case CSS_PROP_FONT_STYLE:
+                        case CSS_PROP_FONT_SIZE:
+                        case CSS_PROP_FONT_WEIGHT:
+                        case CSS_PROP_FONT_FAMILY:
+                        case CSS_PROP_FONT:
+                        case CSS_PROP_COLOR:
+                        case CSS_PROP_BACKGROUND_IMAGE:
+                        case CSS_PROP_DISPLAY:
+                            // these have to be applied first, because other properties use the computed
+                            // values of these porperties.
+                            first = true;
+                            break;
+                        default:
+                            first = false;
+                            break;
+                    }
+                    
+                    if (first == applyFirst)
+                        applyProperty(current->id(), current->value());
+                }
+            }
+        }
+    }
+}
 
-void CSSStyleSelector::applyRule( int id, DOM::CSSValueImpl *value )
+void CSSStyleSelector::applyProperty( int id, DOM::CSSValueImpl *value )
 {
     //kdDebug( 6080 ) << "applying property " << prop->m_id << endl;
 
@@ -2214,20 +2112,11 @@ void CSSStyleSelector::applyRule( int id, DOM::CSSValueImpl *value )
                 col = RenderStyle::initialColor();
         }
         else {
-            if(!primitiveValue )
+            if(!primitiveValue)
                 return;
-            int ident = primitiveValue->getIdent();
-            if ( ident ) {
-                if ( ident == CSS_VAL__KHTML_TEXT )
-                    col = element->getDocument()->textColor();
-                else
-                    col = colorForCSSValue( ident );
-            } else if ( primitiveValue->primitiveType() == CSSPrimitiveValue::CSS_RGBCOLOR )
-                    col.setRgb(primitiveValue->getRGBColorValue());
-            else {
-                return;
-            }
+            col = getColorFromPrimitiveValue(primitiveValue);
         }
+
         //kdDebug( 6080 ) << "applying color " << col.isValid() << endl;
         switch(id)
         {
@@ -3139,10 +3028,10 @@ void CSSStyleSelector::applyRule( int id, DOM::CSSValueImpl *value )
             if ( !font->style || !font->variant || !font->weight ||
                  !font->size || !font->lineHeight || !font->family )
                 return;
-            applyRule( CSS_PROP_FONT_STYLE, font->style );
-            applyRule( CSS_PROP_FONT_VARIANT, font->variant );
-            applyRule( CSS_PROP_FONT_WEIGHT, font->weight );
-            applyRule( CSS_PROP_FONT_SIZE, font->size );
+            applyProperty( CSS_PROP_FONT_STYLE, font->style );
+            applyProperty( CSS_PROP_FONT_VARIANT, font->variant );
+            applyProperty( CSS_PROP_FONT_WEIGHT, font->weight );
+            applyProperty( CSS_PROP_FONT_SIZE, font->size );
 
             // Line-height can depend on font().pixelSize(), so we have to update the font
             // before we evaluate line-height, e.g., font: 1em/1em.  FIXME: Still not
@@ -3150,8 +3039,8 @@ void CSSStyleSelector::applyRule( int id, DOM::CSSValueImpl *value )
             if (fontDirty)
                 CSSStyleSelector::style->htmlFont().update( paintDeviceMetrics );
             
-            applyRule( CSS_PROP_LINE_HEIGHT, font->lineHeight );
-            applyRule( CSS_PROP_FONT_FAMILY, font->family );
+            applyProperty( CSS_PROP_LINE_HEIGHT, font->lineHeight );
+            applyProperty( CSS_PROP_FONT_FAMILY, font->family );
         }
         return;
         
@@ -3626,4 +3515,31 @@ float CSSStyleSelector::smallerFontSize(float size, bool quirksMode) const
     return size/1.2;
 }
 
+QColor CSSStyleSelector::getColorFromPrimitiveValue(CSSPrimitiveValueImpl* primitiveValue)
+{
+    QColor col;
+    int ident = primitiveValue->getIdent();
+    if (ident) {
+        if (ident == CSS_VAL__KHTML_TEXT)
+            col = element->getDocument()->textColor();
+        else if (ident == CSS_VAL__KHTML_LINK) {
+            QColor linkColor = element->getDocument()->linkColor();
+            QColor visitedColor = element->getDocument()->visitedLinkColor();
+            if (linkColor == visitedColor)
+                col = linkColor;
+            else {
+                if (pseudoState == PseudoUnknown || pseudoState == PseudoAnyLink)
+                    checkPseudoState(element);
+                col = (pseudoState == PseudoLink) ? linkColor : visitedColor;
+            }
+        }
+        else if (ident == CSS_VAL__KHTML_ACTIVELINK)
+            col = element->getDocument()->activeLinkColor();
+        else
+            col = colorForCSSValue( ident );
+    } else if ( primitiveValue->primitiveType() == CSSPrimitiveValue::CSS_RGBCOLOR )
+        col.setRgb(primitiveValue->getRGBColorValue());
+    return col;    
+}
+
 } // namespace khtml
diff --git a/WebCore/khtml/css/cssstyleselector.h b/WebCore/khtml/css/cssstyleselector.h
index 0246f06..78cd837 100644
--- a/WebCore/khtml/css/cssstyleselector.h
+++ b/WebCore/khtml/css/cssstyleselector.h
@@ -23,10 +23,12 @@
 #ifndef _CSS_cssstyleselector_h_
 #define _CSS_cssstyleselector_h_
 
-#include <qptrlist.h>
+#include <qptrvector.h>
+#include <qptrdict.h>
 
 #include "rendering/render_style.h"
 #include "dom/dom_string.h"
+#include "css/css_ruleimpl.h"
 
 class KHTMLSettings;
 class KHTMLView;
@@ -38,10 +40,8 @@ namespace DOM {
     class NodeImpl;
     class ElementImpl;
     class StyleSheetImpl;
-    class CSSStyleRuleImpl;
     class CSSStyleSheetImpl;
     class CSSSelector;
-    class CSSStyleDeclarationImpl;
     class CSSProperty;
     class StyleSheetListImpl;
     class CSSValueImpl;
@@ -49,28 +49,11 @@ namespace DOM {
 
 namespace khtml
 {
-    class CSSStyleSelectorList;
-    class CSSOrderedRule;
-    class CSSOrderedProperty;
-    class CSSOrderedPropertyList;
+    class CSSRuleData;
+    class CSSRuleDataList;
+    class CSSRuleSet;
     class RenderStyle;
 
-    /*
-     * to remember the source where a rule came from. Differntiates between
-     * important and not important rules. This is ordered in the order they have to be applied
-     * to the RenderStyle.
-     */
-    enum Source {
-	Default = 0,
-	NonCSSHint = 1,
-        User = 2,
-	Author = 3,
-	Inline = 4,
-	AuthorImportant = 5,
-	InlineImportant = 6,
-	UserImportant =7
-    };
-
     /**
      * this class selects a RenderStyle for a given Element based on the
      * collection of styleshets it contains. This is just a vrtual base class
@@ -107,21 +90,16 @@ namespace khtml
 	 * creates a new StyleSelector for a Document.
 	 * goes through all StyleSheets defined in the document and
 	 * creates a list of rules it needs to apply to objects
-	 *
-	 * Also takes into account special cases for HTML documents,
-	 * including the defaultStyle (which is html only)
 	 */
-	CSSStyleSelector( DOM::DocumentImpl* doc, QString userStyleSheet, DOM::StyleSheetListImpl *styleSheets, const KURL &url,
-                          bool _strictParsing );
+	CSSStyleSelector(DOM::DocumentImpl* doc, QString userStyleSheet, 
+                         DOM::StyleSheetListImpl *styleSheets, const KURL &url,
+                         bool _strictParsing);
 	/**
 	 * same as above but for a single stylesheet.
 	 */
-	CSSStyleSelector( DOM::CSSStyleSheetImpl *sheet );
-
+	CSSStyleSelector(DOM::CSSStyleSheetImpl *sheet);
 	~CSSStyleSelector();
 
-	void addSheet( DOM::CSSStyleSheetImpl *sheet );
-
 	static void loadDefaultStyle(const KHTMLSettings *s = 0);
 	static void clear();
 
@@ -151,12 +129,14 @@ namespace khtml
         void setFontSize(FontDef& fontDef, float size);
         float getComputedSizeFromSpecifiedSize(bool isAbsoluteSize, float specifiedSize);
         
+        QColor getColorFromPrimitiveValue(DOM::CSSPrimitiveValueImpl* primitiveValue);
+        
     protected:
 
-	/* checks if the complete selector (which can be build up from a few CSSSelector's
-	    with given relationships matches the given Element */
-        void checkSelector(int selector, DOM::ElementImpl *e, 
-                           RenderStyle::PseudoId pseudo = RenderStyle::NOPSEUDO);
+	/* checks if a compound selector (which can consist of multiple simple selectors)
+           matches the given Element */
+        bool checkSelector(DOM::CSSSelector* selector, DOM::ElementImpl *e);
+        
 	/* checks if the selector matches the given Element */
 	bool checkOneSelector(DOM::CSSSelector *selector, DOM::ElementImpl *e);
 
@@ -164,23 +144,24 @@ namespace khtml
 	   current generic font family has changed. -dwh */
 	void checkForGenericFamilyChange(RenderStyle* aStyle, RenderStyle* aParentStyle);
 
-	/* builds up the selectors and properties lists from the CSSStyleSelectorList's */
-	void buildLists();
-	void clearLists();
-
-        unsigned int addInlineDeclarations(DOM::ElementImpl* e, DOM::CSSStyleDeclarationImpl *decl,
-                                           unsigned int numProps);
-
         void adjustRenderStyle(RenderStyle* style, DOM::ElementImpl *e);
     
+        void matchRules(CSSRuleSet* rules, int& firstRuleIndex, int& lastRuleIndex);
+        void matchRulesForList(CSSRuleDataList* rules,
+                               int& firstRuleIndex, int& lastRuleIndex);
+        void sortMatchedRules(uint firstRuleIndex, uint lastRuleIndex);
+        void addMatchedRule(CSSRuleData* rule);
+        void addMatchedDeclaration(DOM::CSSStyleDeclarationImpl* decl);
+        void applyDeclarations(bool firstPass, bool important, int startIndex, int endIndex);
+        
 	static DOM::CSSStyleSheetImpl *defaultSheet;
         static DOM::CSSStyleSheetImpl *quirksSheet;
-	static CSSStyleSelectorList *defaultStyle;
-        static CSSStyleSelectorList *defaultQuirksStyle;
-	static CSSStyleSelectorList *defaultPrintStyle;
-	CSSStyleSelectorList *authorStyle;
-        CSSStyleSelectorList *userStyle;
-        DOM::CSSStyleSheetImpl *userSheet;
+	static CSSRuleSet* defaultStyle;
+        static CSSRuleSet* defaultQuirksStyle;
+	static CSSRuleSet* defaultPrintStyle;
+	CSSRuleSet* m_authorStyle;
+        CSSRuleSet* m_userStyle;
+        DOM::CSSStyleSheetImpl* m_userSheet;
 
 public:
 	static RenderStyle* styleNotYetAvailable;
@@ -188,45 +169,22 @@ public:
     private:
         void init();
 
-    public: // we need to make the enum public for SelectorCache
-	enum SelectorState {
-	    Unknown = 0,
-	    Applies,
-	    AppliesPseudo,
-	    Invalid
-	};
-
-        enum SelectorMedia {
-            MediaAural = 1,
-            MediaBraille,
-            MediaEmboss,
-            MediaHandheld,
-            MediaPrint,
-            MediaProjection,
-            MediaScreen,
-            MediaTTY,
-            MediaTV
-        };
     protected:
-
-        struct SelectorCache {
-            SelectorState state;
-            unsigned int props_size;
-            int *props;
-        };
-
-	unsigned int selectors_size;
-	DOM::CSSSelector **selectors;
-	SelectorCache *selectorCache;
-	unsigned int properties_size;
-	CSSOrderedProperty **properties;
-	QMemArray<CSSOrderedProperty> inlineProps;
+        // We collect the set of decls that match in |m_matchedDecls|.  We then walk the
+        // set of matched decls four times, once for those properties that others depend on (like font-size),
+        // and then a second time for all the remaining properties.  We then do the same two passes
+        // for any !important rules.
+        QMemArray<DOM::CSSStyleDeclarationImpl*> m_matchedDecls;
+        unsigned m_matchedDeclCount;
+        
+        // A buffer used to hold the set of matched rules for an element, and a temporary buffer used for
+        // merge sorting.
+        QMemArray<CSSRuleData*> m_matchedRules;
+        unsigned m_matchedRuleCount;
+        QMemArray<CSSRuleData*> m_tmpRules;
+        unsigned m_tmpRuleCount;
+        
         QString m_medium;
-	CSSOrderedProperty **propsToApply;
-	CSSOrderedProperty **pseudoProps;
-	unsigned int propsToApplySize;
-	unsigned int pseudoPropsSize;
-
 
 	RenderStyle::PseudoId dynamicPseudo;
 	
@@ -234,6 +192,7 @@ public:
 	RenderStyle *parentStyle;
 	DOM::ElementImpl *element;
 	DOM::NodeImpl *parentNode;
+        RenderStyle::PseudoId pseudoStyle;
 	KHTMLView *view;
 	KHTMLPart *part;
 	const KHTMLSettings *settings;
@@ -241,79 +200,69 @@ public:
         bool fontDirty;
         bool isXMLDoc;
         
-	void applyRule(int id, DOM::CSSValueImpl *value);
+	void applyProperty(int id, DOM::CSSValueImpl *value);
     };
 
-    /*
-     * List of properties that get applied to the Element. We need to collect them first
-     * and then apply them one by one, because we have to change the apply order.
-     * Some properties depend on other one already being applied (for example all properties spezifying
-     * some length need to have already the correct font size. Same applies to color
-     *
-     * While sorting them, we have to take care not to mix up the original order.
-     */
-    class CSSOrderedProperty
-    {
+    class CSSRuleData {
     public:
-	CSSOrderedProperty(DOM::CSSProperty *_prop, uint _selector,
-			   bool first, Source source, unsigned int specificity,
-			   unsigned int _position )
-	    : prop ( _prop ), pseudoId( RenderStyle::NOPSEUDO ), selector( _selector ),
-	      position( _position )
-	{
-	    priority = (!first << 30) | (source << 24) | specificity;
-	}
-
-	bool operator < ( const CSSOrderedProperty &other ) const {
-             if (priority < other.priority) return true;
-             if (priority > other.priority) return false;
-             if (position < other.position) return true;
-             return false;
-	}
-
-	DOM::CSSProperty *prop;
-	RenderStyle::PseudoId pseudoId;
-	unsigned int selector;
-	unsigned int position;
-
-	Q_UINT32 priority;
+        CSSRuleData(uint pos, DOM::CSSStyleRuleImpl* r, DOM::CSSSelector* sel, CSSRuleData* prev = 0)
+        :m_position(pos), m_rule(r), m_selector(sel), m_next(0) { if (prev) prev->m_next = this; }
+        ~CSSRuleData() { delete m_next; }
+
+        uint position() { return m_position; }
+        DOM::CSSStyleRuleImpl* rule() { return m_rule; }
+        DOM::CSSSelector* selector() { return m_selector; }
+        CSSRuleData* next() { return m_next; }
+        
+    private:
+        uint m_position;
+        DOM::CSSStyleRuleImpl* m_rule;
+        DOM::CSSSelector* m_selector;
+        CSSRuleData* m_next;
     };
 
-    /*
-     * This is the list we will collect all properties we need to apply in.
-     * It will get sorted once before applying.
-     */
-    class CSSOrderedPropertyList : public QPtrList<CSSOrderedProperty>
-    {
+    class CSSRuleDataList {
     public:
-	virtual int compareItems(QPtrCollection::Item i1, QPtrCollection::Item i2);
-	void append(DOM::CSSStyleDeclarationImpl *decl, uint selector, uint specificity,
-		    Source regular, Source important );
-    };
+        CSSRuleDataList(uint pos, DOM::CSSStyleRuleImpl* rule, DOM::CSSSelector* sel)
+        { m_first = m_last = new CSSRuleData(pos, rule, sel); }
+        ~CSSRuleDataList() { delete m_first; }
 
-    class CSSOrderedRule
+        CSSRuleData* first() { return m_first; }
+        CSSRuleData* last() { return m_last; }
+        
+        void append(uint pos, DOM::CSSStyleRuleImpl* rule, DOM::CSSSelector* sel) {
+            m_last = new CSSRuleData(pos, rule, sel, m_last);
+        }
+        
+    private:
+        CSSRuleData* m_first;
+        CSSRuleData* m_last;
+    };
+    
+    class CSSRuleSet
     {
     public:
-	CSSOrderedRule(DOM::CSSStyleRuleImpl *r, DOM::CSSSelector *s, int _index);
-	~CSSOrderedRule();
+        CSSRuleSet();
+        ~CSSRuleSet() { delete m_universalRules; }
 
-	DOM::CSSSelector *selector;
-	DOM::CSSStyleRuleImpl *rule;
-	int index;
-    };
+        void addRulesFromSheet(DOM::CSSStyleSheetImpl* sheet, const DOM::DOMString &medium = "screen");
 
-    class CSSStyleSelectorList : public QPtrList<CSSOrderedRule>
-    {
-    public:
-	CSSStyleSelectorList();
-	virtual ~CSSStyleSelectorList();
+        void addRule(DOM::CSSStyleRuleImpl* rule, DOM::CSSSelector* sel);
+        void addToRuleSet(void* hash, QPtrDict<CSSRuleDataList>& dict,
+                          DOM::CSSStyleRuleImpl* rule, DOM::CSSSelector* sel);
 
-	void append( DOM::CSSStyleSheetImpl *sheet,
-                 const DOM::DOMString &medium = "screen" );
+        CSSRuleDataList* getIDRules(void* hash) { return m_idRules.find(hash); }
+        CSSRuleDataList* getClassRules(void* hash) { return m_classRules.find(hash); }
+        CSSRuleDataList* getTagRules(void* hash) { return m_tagRules.find(hash); }
+        CSSRuleDataList* getUniversalRules() { return m_universalRules; }
 
-	void collect( QPtrList<DOM::CSSSelector> *selectorList, CSSOrderedPropertyList *propList,
-		      Source regular, Source important );
+    public:
+        QPtrDict<CSSRuleDataList> m_idRules;
+        QPtrDict<CSSRuleDataList> m_classRules;
+        QPtrDict<CSSRuleDataList> m_tagRules;
+        CSSRuleDataList*          m_universalRules;
+        
+        uint m_ruleCount;
     };
-
 };
 #endif
diff --git a/WebCore/khtml/css/cssvalues.c b/WebCore/khtml/css/cssvalues.c
index c4bf35c..bd53e7b 100644
--- a/WebCore/khtml/css/cssvalues.c
+++ b/WebCore/khtml/css/cssvalues.c
@@ -7,7 +7,7 @@ struct css_value {
     const char *name;
     int id;
 };
-/* maximum key range = 1455, duplicates = 2 */
+/* maximum key range = 1609, duplicates = 1 */
 
 #ifdef __GNUC__
 __inline
@@ -21,32 +21,32 @@ hash_val (register const char *str, register unsigned int len)
 {
   static const unsigned short asso_values[] =
     {
-      1455, 1455, 1455, 1455, 1455, 1455, 1455, 1455, 1455, 1455,
-      1455, 1455, 1455, 1455, 1455, 1455, 1455, 1455, 1455, 1455,
-      1455, 1455, 1455, 1455, 1455, 1455, 1455, 1455, 1455, 1455,
-      1455, 1455, 1455, 1455, 1455, 1455, 1455, 1455, 1455, 1455,
-      1455, 1455, 1455, 1455, 1455,   30, 1455, 1455,    0,   10,
-        15,   20,   25,   30,   35,   40,    5,    0, 1455, 1455,
-      1455, 1455, 1455, 1455, 1455, 1455, 1455, 1455, 1455, 1455,
-      1455, 1455, 1455, 1455, 1455, 1455, 1455, 1455, 1455, 1455,
-      1455, 1455, 1455, 1455, 1455, 1455, 1455, 1455, 1455, 1455,
-      1455, 1455, 1455, 1455, 1455, 1455, 1455,    0,  102,   30,
-        15,  195,  210,  124,   85,   65,    0,   14,    0,  194,
-        25,  120,   28,    5,    4,    5,    0,    9,  100,  131,
-       233,  230,   95, 1455, 1455, 1455, 1455, 1455, 1455, 1455,
-      1455, 1455, 1455, 1455, 1455, 1455, 1455, 1455, 1455, 1455,
-      1455, 1455, 1455, 1455, 1455, 1455, 1455, 1455, 1455, 1455,
-      1455, 1455, 1455, 1455, 1455, 1455, 1455, 1455, 1455, 1455,
-      1455, 1455, 1455, 1455, 1455, 1455, 1455, 1455, 1455, 1455,
-      1455, 1455, 1455, 1455, 1455, 1455, 1455, 1455, 1455, 1455,
-      1455, 1455, 1455, 1455, 1455, 1455, 1455, 1455, 1455, 1455,
-      1455, 1455, 1455, 1455, 1455, 1455, 1455, 1455, 1455, 1455,
-      1455, 1455, 1455, 1455, 1455, 1455, 1455, 1455, 1455, 1455,
-      1455, 1455, 1455, 1455, 1455, 1455, 1455, 1455, 1455, 1455,
-      1455, 1455, 1455, 1455, 1455, 1455, 1455, 1455, 1455, 1455,
-      1455, 1455, 1455, 1455, 1455, 1455, 1455, 1455, 1455, 1455,
-      1455, 1455, 1455, 1455, 1455, 1455, 1455, 1455, 1455, 1455,
-      1455, 1455, 1455, 1455, 1455, 1455
+      1609, 1609, 1609, 1609, 1609, 1609, 1609, 1609, 1609, 1609,
+      1609, 1609, 1609, 1609, 1609, 1609, 1609, 1609, 1609, 1609,
+      1609, 1609, 1609, 1609, 1609, 1609, 1609, 1609, 1609, 1609,
+      1609, 1609, 1609, 1609, 1609, 1609, 1609, 1609, 1609, 1609,
+      1609, 1609, 1609, 1609, 1609,   25, 1609, 1609,    0,   10,
+        15,   20,   25,   30,   35,   45,    5,    0, 1609, 1609,
+      1609, 1609, 1609, 1609, 1609, 1609, 1609, 1609, 1609, 1609,
+      1609, 1609, 1609, 1609, 1609, 1609, 1609, 1609, 1609, 1609,
+      1609, 1609, 1609, 1609, 1609, 1609, 1609, 1609, 1609, 1609,
+      1609, 1609, 1609, 1609, 1609, 1609, 1609,    0,   73,  242,
+        15,    4,   30,  250,  145,   65,    0,  215,    0,  153,
+        40,    5,  200,  120,  135,   10,    0,  154,  113,  201,
+       190,  104,  144, 1609, 1609, 1609, 1609, 1609, 1609, 1609,
+      1609, 1609, 1609, 1609, 1609, 1609, 1609, 1609, 1609, 1609,
+      1609, 1609, 1609, 1609, 1609, 1609, 1609, 1609, 1609, 1609,
+      1609, 1609, 1609, 1609, 1609, 1609, 1609, 1609, 1609, 1609,
+      1609, 1609, 1609, 1609, 1609, 1609, 1609, 1609, 1609, 1609,
+      1609, 1609, 1609, 1609, 1609, 1609, 1609, 1609, 1609, 1609,
+      1609, 1609, 1609, 1609, 1609, 1609, 1609, 1609, 1609, 1609,
+      1609, 1609, 1609, 1609, 1609, 1609, 1609, 1609, 1609, 1609,
+      1609, 1609, 1609, 1609, 1609, 1609, 1609, 1609, 1609, 1609,
+      1609, 1609, 1609, 1609, 1609, 1609, 1609, 1609, 1609, 1609,
+      1609, 1609, 1609, 1609, 1609, 1609, 1609, 1609, 1609, 1609,
+      1609, 1609, 1609, 1609, 1609, 1609, 1609, 1609, 1609, 1609,
+      1609, 1609, 1609, 1609, 1609, 1609, 1609, 1609, 1609, 1609,
+      1609, 1609, 1609, 1609, 1609, 1609
     };
   register int hval = 0;
 
@@ -110,436 +110,459 @@ findValue (register const char *str, register unsigned int len)
 {
   enum
     {
-      TOTAL_KEYWORDS = 254,
+      TOTAL_KEYWORDS = 256,
       MIN_WORD_LENGTH = 2,
       MAX_WORD_LENGTH = 22,
       MIN_HASH_VALUE = 0,
-      MAX_HASH_VALUE = 1454
+      MAX_HASH_VALUE = 1608
     };
 
   static const struct css_value wordlist_value[] =
     {
       {"900", CSS_VAL_900},
-      {"ltr", CSS_VAL_LTR},
-      {"rtl", CSS_VAL_RTL},
+      {"teal", CSS_VAL_TEAL},
       {"800", CSS_VAL_800},
-      {"start", CSS_VAL_START},
       {"100", CSS_VAL_100},
-      {"aqua", CSS_VAL_AQUA},
       {"200", CSS_VAL_200},
       {"300", CSS_VAL_300},
       {"400", CSS_VAL_400},
       {"500", CSS_VAL_500},
+      {"left", CSS_VAL_LEFT},
       {"600", CSS_VAL_600},
-      {"up", CSS_VAL_UP},
-      {"700", CSS_VAL_700},
-      {"katakana", CSS_VAL_KATAKANA},
-      {"static", CSS_VAL_STATIC},
-      {"disc", CSS_VAL_DISC},
-      {"sub", CSS_VAL_SUB},
-      {"hand", CSS_VAL_HAND},
-      {"auto", CSS_VAL_AUTO},
-      {"loud", CSS_VAL_LOUD},
-      {"black", CSS_VAL_BLACK},
-      {"top", CSS_VAL_TOP},
-      {"status-bar", CSS_VAL_STATUS_BAR},
-      {"run-in", CSS_VAL_RUN_IN},
-      {"scroll", CSS_VAL_SCROLL},
-      {"italic", CSS_VAL_ITALIC},
-      {"cross", CSS_VAL_CROSS},
-      {"thin", CSS_VAL_THIN},
-      {"crop", CSS_VAL_CROP},
-      {"thick", CSS_VAL_THICK},
-      {"teal", CSS_VAL_TEAL},
-      {"wait", CSS_VAL_WAIT},
-      {"small", CSS_VAL_SMALL},
-      {"solid", CSS_VAL_SOLID},
-      {"blink", CSS_VAL_BLINK},
-      {"red", CSS_VAL_RED},
+      {"dotted", CSS_VAL_DOTTED},
       {"fast", CSS_VAL_FAST},
-      {"square", CSS_VAL_SQUARE},
-      {"initial", CSS_VAL_INITIAL},
-      {"portrait", CSS_VAL_PORTRAIT},
-      {"pre", CSS_VAL_PRE},
+      {"700", CSS_VAL_700},
       {"end", CSS_VAL_END},
+      {"table", CSS_VAL_TABLE},
+      {"none", CSS_VAL_NONE},
       {"bold", CSS_VAL_BOLD},
-      {"icon", CSS_VAL_ICON},
-      {"super", CSS_VAL_SUPER},
-      {"slow", CSS_VAL_SLOW},
-      {"unfurl", CSS_VAL_UNFURL},
-      {"purple", CSS_VAL_PURPLE},
-      {"scrollbar", CSS_VAL_SCROLLBAR},
-      {"block", CSS_VAL_BLOCK},
-      {"caption", CSS_VAL_CAPTION},
-      {"right", CSS_VAL_RIGHT},
       {"slide", CSS_VAL_SLIDE},
-      {"transparent", CSS_VAL_TRANSPARENT},
+      {"solid", CSS_VAL_SOLID},
       {"inset", CSS_VAL_INSET},
-      {"down", CSS_VAL_DOWN},
-      {"small-caps", CSS_VAL_SMALL_CAPS},
+      {"level", CSS_VAL_LEVEL},
+      {"ltr", CSS_VAL_LTR},
+      {"rtl", CSS_VAL_RTL},
+      {"start", CSS_VAL_START},
+      {"red", CSS_VAL_RED},
+      {"auto", CSS_VAL_AUTO},
+      {"small", CSS_VAL_SMALL},
       {"ahead", CSS_VAL_AHEAD},
-      {"table", CSS_VAL_TABLE},
-      {"landscape", CSS_VAL_LANDSCAPE},
+      {"outset", CSS_VAL_OUTSET},
+      {"loud", CSS_VAL_LOUD},
+      {"alternate", CSS_VAL_ALTERNATE},
+      {"fantasy", CSS_VAL_FANTASY},
+      {"olive", CSS_VAL_OLIVE},
+      {"dashed", CSS_VAL_DASHED},
+      {"text", CSS_VAL_TEXT},
+      {"above", CSS_VAL_ABOVE},
+      {"baseline", CSS_VAL_BASELINE},
       {"avoid", CSS_VAL_AVOID},
-      {"backwards", CSS_VAL_BACKWARDS},
-      {"hiragana", CSS_VAL_HIRAGANA},
-      {"blue", CSS_VAL_BLUE},
+      {"inside", CSS_VAL_INSIDE},
+      {"hand", CSS_VAL_HAND},
+      {"default", CSS_VAL_DEFAULT},
+      {"top", CSS_VAL_TOP},
+      {"inline", CSS_VAL_INLINE},
+      {"slow", CSS_VAL_SLOW},
+      {"lime", CSS_VAL_LIME},
       {"both", CSS_VAL_BOTH},
-      {"help", CSS_VAL_HELP},
-      {"nowrap", CSS_VAL_NOWRAP},
-      {"dashed", CSS_VAL_DASHED},
-      {"crosshair", CSS_VAL_CROSSHAIR},
-      {"stretch", CSS_VAL_STRETCH},
-      {"large", CSS_VAL_LARGE},
-      {"circle", CSS_VAL_CIRCLE},
-      {"larger", CSS_VAL_LARGER},
-      {"outset", CSS_VAL_OUTSET},
-      {"show", CSS_VAL_SHOW},
-      {"normal", CSS_VAL_NORMAL},
-      {"dotted", CSS_VAL_DOTTED},
-      {"navy", CSS_VAL_NAVY},
-      {"katakana-iroha", CSS_VAL_KATAKANA_IROHA},
-      {"gray", CSS_VAL_GRAY},
       {"hide", CSS_VAL_HIDE},
-      {"none", CSS_VAL_NONE},
+      {"blue", CSS_VAL_BLUE},
+      {"bolder", CSS_VAL_BOLDER},
+      {"initial", CSS_VAL_INITIAL},
+      {"bottom", CSS_VAL_BOTTOM},
+      {"sub", CSS_VAL_SUB},
+      {"serif", CSS_VAL_SERIF},
+      {"absolute", CSS_VAL_ABSOLUTE},
+      {"embed", CSS_VAL_EMBED},
+      {"thin", CSS_VAL_THIN},
+      {"double", CSS_VAL_DOUBLE},
+      {"middle", CSS_VAL_MIDDLE},
+      {"outside", CSS_VAL_OUTSIDE},
+      {"navy", CSS_VAL_NAVY},
+      {"down", CSS_VAL_DOWN},
+      {"wait", CSS_VAL_WAIT},
+      {"aqua", CSS_VAL_AQUA},
+      {"move", CSS_VAL_MOVE},
+      {"below", CSS_VAL_BELOW},
+      {"hidden", CSS_VAL_HIDDEN},
+      {"smaller", CSS_VAL_SMALLER},
+      {"fixed", CSS_VAL_FIXED},
+      {"infinite", CSS_VAL_INFINITE},
+      {"yellow", CSS_VAL_YELLOW},
       {"always", CSS_VAL_ALWAYS},
+      {"inline-table", CSS_VAL_INLINE_TABLE},
+      {"static", CSS_VAL_STATIC},
+      {"relative", CSS_VAL_RELATIVE},
+      {"list-item", CSS_VAL_LIST_ITEM},
       {"silver", CSS_VAL_SILVER},
-      {"inside", CSS_VAL_INSIDE},
-      {"inline", CSS_VAL_INLINE},
-      {"collapse", CSS_VAL_COLLAPSE},
-      {"upper-latin", CSS_VAL_UPPER_LATIN},
-      {"invert", CSS_VAL_INVERT},
-      {"vertical", CSS_VAL_VERTICAL},
-      {"smaller", CSS_VAL_SMALLER},
-      {"hidden", CSS_VAL_HIDDEN},
-      {"compact", CSS_VAL_COMPACT},
-      {"ridge", CSS_VAL_RIDGE},
-      {"fuchsia", CSS_VAL_FUCHSIA},
-      {"left", CSS_VAL_LEFT},
-      {"upper-alpha", CSS_VAL_UPPER_ALPHA},
-      {"cursive", CSS_VAL_CURSIVE},
-      {"outside", CSS_VAL_OUTSIDE},
-      {"wider", CSS_VAL_WIDER},
-      {"single", CSS_VAL_SINGLE},
-      {"alternate", CSS_VAL_ALTERNATE},
+      {"read-only", CSS_VAL_READ_ONLY},
+      {"sans-serif", CSS_VAL_SANS_SERIF},
+      {"visible", CSS_VAL_VISIBLE},
+      {"disc", CSS_VAL_DISC},
+      {"normal", CSS_VAL_NORMAL},
+      {"infotext", CSS_VAL_INFOTEXT},
+      {"maroon", CSS_VAL_MAROON},
+      {"pre", CSS_VAL_PRE},
       {"repeat", CSS_VAL_REPEAT},
+      {"lower", CSS_VAL_LOWER},
+      {"table-cell", CSS_VAL_TABLE_CELL},
+      {"help", CSS_VAL_HELP},
       {"menu", CSS_VAL_MENU},
+      {"icon", CSS_VAL_ICON},
       {"separate", CSS_VAL_SEPARATE},
-      {"text", CSS_VAL_TEXT},
-      {"default", CSS_VAL_DEFAULT},
-      {"absolute", CSS_VAL_ABSOLUTE},
-      {"bolder", CSS_VAL_BOLDER},
-      {"pointer", CSS_VAL_POINTER},
-      {"inherit", CSS_VAL_INHERIT},
-      {"double", CSS_VAL_DOUBLE},
-      {"background", CSS_VAL_BACKGROUND},
-      {"center", CSS_VAL_CENTER},
-      {"lower", CSS_VAL_LOWER},
-      {"lime", CSS_VAL_LIME},
+      {"up", CSS_VAL_UP},
+      {"invert", CSS_VAL_INVERT},
+      {"show", CSS_VAL_SHOW},
+      {"justify", CSS_VAL_JUSTIFY},
+      {"overline", CSS_VAL_OVERLINE},
+      {"single", CSS_VAL_SINGLE},
+      {"italic", CSS_VAL_ITALIC},
+      {"condensed", CSS_VAL_CONDENSED},
       {"x-small", CSS_VAL_X_SMALL},
-      {"maroon", CSS_VAL_MAROON},
-      {"orange", CSS_VAL_ORANGE},
-      {"fantasy", CSS_VAL_FANTASY},
-      {"lighter", CSS_VAL_LIGHTER},
-      {"white", CSS_VAL_WHITE},
-      {"capitalize", CSS_VAL_CAPITALIZE},
-      {"serif", CSS_VAL_SERIF},
-      {"olive", CSS_VAL_OLIVE},
-      {"-khtml-auto", CSS_VAL__KHTML_AUTO},
-      {"narrower", CSS_VAL_NARROWER},
-      {"middle", CSS_VAL_MIDDLE},
-      {"window", CSS_VAL_WINDOW},
-      {"forwards", CSS_VAL_FORWARDS},
-      {"level", CSS_VAL_LEVEL},
-      {"multiple", CSS_VAL_MULTIPLE},
+      {"large", CSS_VAL_LARGE},
+      {"e-resize", CSS_VAL_E_RESIZE},
+      {"scroll", CSS_VAL_SCROLL},
+      {"blink", CSS_VAL_BLINK},
+      {"s-resize", CSS_VAL_S_RESIZE},
+      {"se-resize", CSS_VAL_SE_RESIZE},
+      {"cross", CSS_VAL_CROSS},
+      {"reverse", CSS_VAL_REVERSE},
+      {"status-bar", CSS_VAL_STATUS_BAR},
       {"mix", CSS_VAL_MIX},
-      {"uppercase", CSS_VAL_UPPERCASE},
+      {"no-repeat", CSS_VAL_NO_REPEAT},
+      {"white", CSS_VAL_WHITE},
+      {"wider", CSS_VAL_WIDER},
       {"oblique", CSS_VAL_OBLIQUE},
-      {"small-caption", CSS_VAL_SMALL_CAPTION},
-      {"decimal", CSS_VAL_DECIMAL},
+      {"square", CSS_VAL_SQUARE},
+      {"text-top", CSS_VAL_TEXT_TOP},
+      {"center", CSS_VAL_CENTER},
+      {"n-resize", CSS_VAL_N_RESIZE},
+      {"ne-resize", CSS_VAL_NE_RESIZE},
+      {"green", CSS_VAL_GREEN},
+      {"orange", CSS_VAL_ORANGE},
       {"armenian", CSS_VAL_ARMENIAN},
-      {"horizontal", CSS_VAL_HORIZONTAL},
-      {"above", CSS_VAL_ABOVE},
-      {"justify", CSS_VAL_JUSTIFY},
-      {"visible", CSS_VAL_VISIBLE},
+      {"table-row", CSS_VAL_TABLE_ROW},
+      {"pointer", CSS_VAL_POINTER},
+      {"inherit", CSS_VAL_INHERIT},
+      {"text-bottom", CSS_VAL_TEXT_BOTTOM},
       {"underline", CSS_VAL_UNDERLINE},
-      {"bottom", CSS_VAL_BOTTOM},
-      {"green", CSS_VAL_GREEN},
-      {"sans-serif", CSS_VAL_SANS_SERIF},
-      {"below", CSS_VAL_BELOW},
-      {"table-cell", CSS_VAL_TABLE_CELL},
-      {"grey", CSS_VAL_GREY},
-      {"list-item", CSS_VAL_LIST_ITEM},
-      {"higher", CSS_VAL_HIGHER},
-      {"relative", CSS_VAL_RELATIVE},
+      {"run-in", CSS_VAL_RUN_IN},
+      {"collapse", CSS_VAL_COLLAPSE},
+      {"buttontext", CSS_VAL_BUTTONTEXT},
+      {"expanded", CSS_VAL_EXPANDED},
+      {"ridge", CSS_VAL_RIDGE},
+      {"katakana", CSS_VAL_KATAKANA},
+      {"repeat-y", CSS_VAL_REPEAT_Y},
       {"lower-latin", CSS_VAL_LOWER_LATIN},
-      {"table-row", CSS_VAL_TABLE_ROW},
-      {"appworkspace", CSS_VAL_APPWORKSPACE},
-      {"x-large", CSS_VAL_X_LARGE},
-      {"baseline", CSS_VAL_BASELINE},
-      {"lower-alpha", CSS_VAL_LOWER_ALPHA},
-      {"s-resize", CSS_VAL_S_RESIZE},
-      {"table-caption", CSS_VAL_TABLE_CAPTION},
-      {"no-repeat", CSS_VAL_NO_REPEAT},
-      {"block-axis", CSS_VAL_BLOCK_AXIS},
-      {"marquee", CSS_VAL_MARQUEE},
-      {"text-top", CSS_VAL_TEXT_TOP},
-      {"hiragana-iroha", CSS_VAL_HIRAGANA_IROHA},
-      {"move", CSS_VAL_MOVE},
-      {"buttonshadow", CSS_VAL_BUTTONSHADOW},
-      {"n-resize", CSS_VAL_N_RESIZE},
-      {"read-only", CSS_VAL_READ_ONLY},
-      {"condensed", CSS_VAL_CONDENSED},
-      {"-khtml-right", CSS_VAL__KHTML_RIGHT},
-      {"highlight", CSS_VAL_HIGHLIGHT},
-      {"upper-roman", CSS_VAL_UPPER_ROMAN},
-      {"read-write", CSS_VAL_READ_WRITE},
-      {"infinite", CSS_VAL_INFINITE},
-      {"georgian", CSS_VAL_GEORGIAN},
-      {"activecaption", CSS_VAL_ACTIVECAPTION},
-      {"-khtml-nowrap", CSS_VAL__KHTML_NOWRAP},
+      {"decimal", CSS_VAL_DECIMAL},
+      {"gray", CSS_VAL_GRAY},
+      {"grey", CSS_VAL_GREY},
+      {"super", CSS_VAL_SUPER},
+      {"inline-axis", CSS_VAL_INLINE_AXIS},
+      {"landscape", CSS_VAL_LANDSCAPE},
       {"groove", CSS_VAL_GROOVE},
-      {"ultra-condensed", CSS_VAL_ULTRA_CONDENSED},
-      {"inline-block", CSS_VAL_INLINE_BLOCK},
+      {"unfurl", CSS_VAL_UNFURL},
+      {"larger", CSS_VAL_LARGER},
+      {"window", CSS_VAL_WINDOW},
+      {"black", CSS_VAL_BLACK},
+      {"forwards", CSS_VAL_FORWARDS},
+      {"block", CSS_VAL_BLOCK},
+      {"stretch", CSS_VAL_STRETCH},
+      {"horizontal", CSS_VAL_HORIZONTAL},
+      {"portrait", CSS_VAL_PORTRAIT},
       {"medium", CSS_VAL_MEDIUM},
-      {"yellow", CSS_VAL_YELLOW},
-      {"lowercase", CSS_VAL_LOWERCASE},
-      {"repeat-y", CSS_VAL_REPEAT_Y},
-      {"buttontext", CSS_VAL_BUTTONTEXT},
-      {"repeat-x", CSS_VAL_REPEAT_X},
+      {"menutext", CSS_VAL_MENUTEXT},
       {"buttonface", CSS_VAL_BUTTONFACE},
+      {"caption", CSS_VAL_CAPTION},
+      {"open-quote", CSS_VAL_OPEN_QUOTE},
+      {"repeat-x", CSS_VAL_REPEAT_X},
+      {"vertical", CSS_VAL_VERTICAL},
+      {"hebrew", CSS_VAL_HEBREW},
+      {"transparent", CSS_VAL_TRANSPARENT},
       {"xx-small", CSS_VAL_XX_SMALL},
-      {"captiontext", CSS_VAL_CAPTIONTEXT},
-      {"reverse", CSS_VAL_REVERSE},
-      {"embed", CSS_VAL_EMBED},
-      {"inline-table", CSS_VAL_INLINE_TABLE},
-      {"overline", CSS_VAL_OVERLINE},
-      {"table-column", CSS_VAL_TABLE_COLUMN},
-      {"expanded", CSS_VAL_EXPANDED},
-      {"inline-axis", CSS_VAL_INLINE_AXIS},
       {"close-quote", CSS_VAL_CLOSE_QUOTE},
-      {"hebrew", CSS_VAL_HEBREW},
-      {"monospace", CSS_VAL_MONOSPACE},
-      {"fixed", CSS_VAL_FIXED},
+      {"marquee", CSS_VAL_MARQUEE},
+      {"multiple", CSS_VAL_MULTIPLE},
+      {"threedface", CSS_VAL_THREEDFACE},
+      {"nowrap", CSS_VAL_NOWRAP},
+      {"crop", CSS_VAL_CROP},
+      {"read-write", CSS_VAL_READ_WRITE},
       {"w-resize", CSS_VAL_W_RESIZE},
+      {"right", CSS_VAL_RIGHT},
+      {"-khtml-left", CSS_VAL__KHTML_LEFT},
       {"sw-resize", CSS_VAL_SW_RESIZE},
-      {"open-quote", CSS_VAL_OPEN_QUOTE},
-      {"line-through", CSS_VAL_LINE_THROUGH},
+      {"lighter", CSS_VAL_LIGHTER},
+      {"scrollbar", CSS_VAL_SCROLLBAR},
+      {"lowercase", CSS_VAL_LOWERCASE},
+      {"x-large", CSS_VAL_X_LARGE},
+      {"no-open-quote", CSS_VAL_NO_OPEN_QUOTE},
       {"nw-resize", CSS_VAL_NW_RESIZE},
-      {"inactivecaption", CSS_VAL_INACTIVECAPTION},
-      {"ultra-expanded", CSS_VAL_ULTRA_EXPANDED},
-      {"-khtml-left", CSS_VAL__KHTML_LEFT},
-      {"-khtml-text", CSS_VAL__KHTML_TEXT},
-      {"e-resize", CSS_VAL_E_RESIZE},
+      {"semi-condensed", CSS_VAL_SEMI_CONDENSED},
+      {"hiragana", CSS_VAL_HIRAGANA},
+      {"no-close-quote", CSS_VAL_NO_CLOSE_QUOTE},
+      {"small-caps", CSS_VAL_SMALL_CAPS},
+      {"fuchsia", CSS_VAL_FUCHSIA},
+      {"buttonshadow", CSS_VAL_BUTTONSHADOW},
+      {"table-caption", CSS_VAL_TABLE_CAPTION},
+      {"narrower", CSS_VAL_NARROWER},
+      {"monospace", CSS_VAL_MONOSPACE},
+      {"thick", CSS_VAL_THICK},
+      {"threedshadow", CSS_VAL_THREEDSHADOW},
       {"graytext", CSS_VAL_GRAYTEXT},
-      {"se-resize", CSS_VAL_SE_RESIZE},
-      {"-khtml-center", CSS_VAL__KHTML_CENTER},
-      {"cjk-ideographic", CSS_VAL_CJK_IDEOGRAPHIC},
-      {"-khtml-box", CSS_VAL__KHTML_BOX},
-      {"ne-resize", CSS_VAL_NE_RESIZE},
-      {"xx-large", CSS_VAL_XX_LARGE},
-      {"-khtml-body", CSS_VAL__KHTML_BODY},
+      {"circle", CSS_VAL_CIRCLE},
+      {"ultra-condensed", CSS_VAL_ULTRA_CONDENSED},
+      {"purple", CSS_VAL_PURPLE},
+      {"table-column", CSS_VAL_TABLE_COLUMN},
       {"lower-roman", CSS_VAL_LOWER_ROMAN},
-      {"activeborder", CSS_VAL_ACTIVEBORDER},
-      {"infotext", CSS_VAL_INFOTEXT},
-      {"threedshadow", CSS_VAL_THREEDSHADOW},
-      {"menutext", CSS_VAL_MENUTEXT},
-      {"infobackground", CSS_VAL_INFOBACKGROUND},
-      {"threeddarkshadow", CSS_VAL_THREEDDARKSHADOW},
-      {"no-close-quote", CSS_VAL_NO_CLOSE_QUOTE},
-      {"buttonhighlight", CSS_VAL_BUTTONHIGHLIGHT},
-      {"table-row-group", CSS_VAL_TABLE_ROW_GROUP},
-      {"no-open-quote", CSS_VAL_NO_OPEN_QUOTE},
-      {"windowtext", CSS_VAL_WINDOWTEXT},
-      {"inactiveborder", CSS_VAL_INACTIVEBORDER},
-      {"threedface", CSS_VAL_THREEDFACE},
+      {"lower-alpha", CSS_VAL_LOWER_ALPHA},
       {"bidi-override", CSS_VAL_BIDI_OVERRIDE},
-      {"text-bottom", CSS_VAL_TEXT_BOTTOM},
-      {"lower-greek", CSS_VAL_LOWER_GREEK},
-      {"table-column-group", CSS_VAL_TABLE_COLUMN_GROUP},
-      {"highlighttext", CSS_VAL_HIGHLIGHTTEXT},
+      {"capitalize", CSS_VAL_CAPITALIZE},
+      {"windowtext", CSS_VAL_WINDOWTEXT},
+      {"-khtml-auto", CSS_VAL__KHTML_AUTO},
+      {"cursive", CSS_VAL_CURSIVE},
+      {"message-box", CSS_VAL_MESSAGE_BOX},
+      {"semi-expanded", CSS_VAL_SEMI_EXPANDED},
       {"extra-condensed", CSS_VAL_EXTRA_CONDENSED},
+      {"small-caption", CSS_VAL_SMALL_CAPTION},
+      {"higher", CSS_VAL_HIGHER},
+      {"captiontext", CSS_VAL_CAPTIONTEXT},
+      {"crosshair", CSS_VAL_CROSSHAIR},
+      {"georgian", CSS_VAL_GEORGIAN},
+      {"-khtml-text", CSS_VAL__KHTML_TEXT},
+      {"-khtml-body", CSS_VAL__KHTML_BODY},
+      {"inline-block", CSS_VAL_INLINE_BLOCK},
+      {"ultra-expanded", CSS_VAL_ULTRA_EXPANDED},
+      {"activeborder", CSS_VAL_ACTIVEBORDER},
+      {"xx-large", CSS_VAL_XX_LARGE},
+      {"extra-expanded", CSS_VAL_EXTRA_EXPANDED},
+      {"upper-latin", CSS_VAL_UPPER_LATIN},
+      {"block-axis", CSS_VAL_BLOCK_AXIS},
+      {"-khtml-box", CSS_VAL__KHTML_BOX},
+      {"compact", CSS_VAL_COMPACT},
+      {"katakana-iroha", CSS_VAL_KATAKANA_IROHA},
       {"windowframe", CSS_VAL_WINDOWFRAME},
-      {"semi-condensed", CSS_VAL_SEMI_CONDENSED},
+      {"-khtml-link", CSS_VAL__KHTML_LINK},
+      {"backwards", CSS_VAL_BACKWARDS},
+      {"inactiveborder", CSS_VAL_INACTIVEBORDER},
+      {"uppercase", CSS_VAL_UPPERCASE},
+      {"line-through", CSS_VAL_LINE_THROUGH},
+      {"activecaption", CSS_VAL_ACTIVECAPTION},
+      {"lower-greek", CSS_VAL_LOWER_GREEK},
+      {"-khtml-center", CSS_VAL__KHTML_CENTER},
+      {"hiragana-iroha", CSS_VAL_HIRAGANA_IROHA},
+      {"-khtml-baseline-middle", CSS_VAL__KHTML_BASELINE_MIDDLE},
+      {"threeddarkshadow", CSS_VAL_THREEDDARKSHADOW},
+      {"table-footer-group", CSS_VAL_TABLE_FOOTER_GROUP},
+      {"upper-roman", CSS_VAL_UPPER_ROMAN},
+      {"upper-alpha", CSS_VAL_UPPER_ALPHA},
+      {"highlight", CSS_VAL_HIGHLIGHT},
+      {"-khtml-inline-box", CSS_VAL__KHTML_INLINE_BOX},
+      {"inactivecaption", CSS_VAL_INACTIVECAPTION},
+      {"background", CSS_VAL_BACKGROUND},
       {"threedlightshadow", CSS_VAL_THREEDLIGHTSHADOW},
-      {"threedhighlight", CSS_VAL_THREEDHIGHLIGHT},
+      {"-khtml-nowrap", CSS_VAL__KHTML_NOWRAP},
+      {"-khtml-right", CSS_VAL__KHTML_RIGHT},
       {"table-header-group", CSS_VAL_TABLE_HEADER_GROUP},
-      {"extra-expanded", CSS_VAL_EXTRA_EXPANDED},
-      {"inactivecaptiontext", CSS_VAL_INACTIVECAPTIONTEXT},
-      {"semi-expanded", CSS_VAL_SEMI_EXPANDED},
-      {"message-box", CSS_VAL_MESSAGE_BOX},
-      {"-khtml-inline-box", CSS_VAL__KHTML_INLINE_BOX},
-      {"table-footer-group", CSS_VAL_TABLE_FOOTER_GROUP},
       {"decimal-leading-zero", CSS_VAL_DECIMAL_LEADING_ZERO},
+      {"table-row-group", CSS_VAL_TABLE_ROW_GROUP},
+      {"highlighttext", CSS_VAL_HIGHLIGHTTEXT},
+      {"infobackground", CSS_VAL_INFOBACKGROUND},
+      {"inactivecaptiontext", CSS_VAL_INACTIVECAPTIONTEXT},
+      {"-khtml-activelink", CSS_VAL__KHTML_ACTIVELINK},
+      {"buttonhighlight", CSS_VAL_BUTTONHIGHLIGHT},
+      {"threedhighlight", CSS_VAL_THREEDHIGHLIGHT},
+      {"appworkspace", CSS_VAL_APPWORKSPACE},
+      {"table-column-group", CSS_VAL_TABLE_COLUMN_GROUP},
       {"-khtml-xxx-large", CSS_VAL__KHTML_XXX_LARGE},
-      {"-khtml-baseline-middle", CSS_VAL__KHTML_BASELINE_MIDDLE}
+      {"cjk-ideographic", CSS_VAL_CJK_IDEOGRAPHIC}
     };
 
   static const short lookup[] =
     {
-         0,   -1,   -1,   -1, -261,    3, -253,   -2,
-        -1,    4,    5,   -1,   -1,   -1,    6,    7,
-        -1,   -1,   -1,   -1,    8,   -1,   -1,   -1,
-        -1,    9,   -1,   -1,   -1,   -1,   10,   -1,
-        -1,   -1,   -1,   11,   -1,   12,   -1,   -1,
-        13,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
-        -1,   -1,   -1,   -1,   -1,   14,   -1,   -1,
+         0,   -1,   -1,   -1,    1,    2,   -1,   -1,
+        -1,   -1,    3,   -1,   -1,   -1,   -1,    4,
+        -1,   -1,   -1,   -1,    5,   -1,   -1,   -1,
+        -1,    6,   -1,   -1,   -1,   -1,    7,   -1,
+        -1,   -1,    8,    9,   -1,   -1,   -1,   10,
+        11,   -1,   -1,   -1,   -1,   12,   -1,   -1,
         -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+        -1,   -1,   -1,   13,   -1,   -1,   -1,   -1,
+        -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+        -1,   -1,   -1,   -1,   -1,   14,   -1,   -1,
         -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+        -1,   15,   -1,   -1,   -1,   16,   17,   18,
         -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
         -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+        -1,   -1,   -1,   -1,   -1,   -1,   -1,   19,
+        -1,   20,   -1,   -1,   -1,   -1,   -1,   -1,
+        -1,   -1,   -1,   -1,   -1,   -1,   -1, -393,
+      -235,   -2,   -1,   -1,   -1,   -1,   -1,   -1,
+        -1,   23,   -1,   -1,   -1,   -1,   -1,   -1,
+        -1,   -1,   24,   -1,   -1,   -1,   -1,   25,
+        -1,   -1,   -1,   26,   27,   -1,   -1,   -1,
+        -1,   -1,   -1,   -1,   -1,   28,   29,   -1,
+        -1,   -1,   -1,   -1,   -1,   -1,   -1,   30,
+        31,   -1,   -1,   32,   -1,   33,   -1,   -1,
+        -1,   -1,   34,   35,   36,   -1,   37,   38,
+        39,   -1,   -1,   40,   -1,   41,   -1,   -1,
+        -1,   -1,   -1,   -1,   -1,   -1,   42,   -1,
+        43,   -1,   -1,   -1,   -1,   -1,   44,   45,
+        -1,   -1,   -1,   -1,   -1,   46,   -1,   47,
+        48,   -1,   -1,   49,   50,   51,   -1,   -1,
+        -1,   -1,   -1,   -1,   52,   -1,   53,   -1,
+        -1,   54,   55,   56,   57,   58,   -1,   -1,
+        -1,   59,   -1,   -1,   -1,   60,   -1,   -1,
+        -1,   -1,   61,   -1,   -1,   -1,   -1,   -1,
+        -1,   -1,   62,   63,   -1,   -1,   -1,   -1,
+        -1,   -1,   -1,   64,   65,   -1,   -1,   -1,
         -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
-        -1,   -1,   -1,   -1,   15,   -1,   -1,   -1,
+        -1,   -1,   -1,   -1,   -1,   -1,   66,   -1,
+        67,   -1,   -1,   -1,   -1,   68,   -1,   -1,
+        -1,   -1,   69,   70,   71,   72,   -1,   -1,
+        -1,   73,   74,   -1,   -1,   -1,   -1,   75,
+        76,   77,   78,   -1,   79,   80,   81,   -1,
+        -1,   -1,   82,   83,   -1,   -1,   -1,   84,
+        -1,   85,   -1,   -1,   86,   87,   -1,   88,
+        89,   90,   91,   -1,   -1,   92,   -1,   -1,
+        -1,   93,   -1,   94,   -1,   -1,   95,   -1,
+        -1,   96,   -1,   -1,   97,   -1,   -1,   98,
+        -1,   -1,   99,   -1,   -1,   -1,   -1,   -1,
+        -1,   -1,   -1,   -1,   -1,  100,   -1,  101,
+       102,  103,   -1,   -1,   -1,  104,   -1,   -1,
+        -1,  105,  106,   -1,   -1,  107,   -1,  108,
+       109,   -1,   -1,   -1,   -1,  110,   -1,  111,
+        -1,   -1,   -1,   -1,  112,  113,   -1,  114,
+       115,  116,   -1,  117,   -1,   -1,   -1,  118,
+        -1,  119,  120,   -1,   -1,  121,   -1,   -1,
+        -1,   -1,   -1,  122,   -1,   -1,   -1,   -1,
+        -1,  123,   -1,   -1,   -1,   -1,  124,  125,
+        -1,  126,   -1,  127,   -1,  128,   -1,   -1,
+        -1,   -1,  129,   -1,  130,  131,  132,   -1,
+       133,   -1,   -1,  134,   -1,   -1,   -1,  135,
         -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
-        -1,   -1,   -1,   16,   17,   -1,   -1,   -1,
-        -1,   -1,   -1,   -1,   -1,   18,   -1,   -1,
-        -1,   19,   -1,   -1,   -1,   -1,   -1,   -1,
+        -1,  136,   -1,   -1,   -1,  137,   -1,   -1,
+        -1,   -1,   -1,   -1,   -1,   -1,   -1,  138,
+       139,   -1,   -1,   -1,   -1,   -1,   -1,  140,
+       141,  142,   -1,   -1,   -1,   -1,   -1,   -1,
+        -1,   -1,   -1,   -1,  143,   -1,   -1,  144,
+        -1,   -1,  145,  146,   -1,   -1,   -1,  147,
+       148,   -1,   -1,  149,  150,   -1,   -1,   -1,
+       151,  152,   -1,   -1,  153,   -1,   -1,   -1,
+       154,   -1,   -1,   -1,   -1,  155,  156,  157,
+        -1,   -1,  158,   -1,  159,   -1,   -1,   -1,
+       160,  161,  162,   -1,   -1,   -1,   -1,   -1,
+       163,   -1,   -1,  164,   -1,  165,  166,   -1,
+       167,   -1,   -1,   -1,  168,   -1,   -1,   -1,
+        -1,   -1,   -1,  169,   -1,  170,  171,  172,
+       173,  174,   -1,   -1,  175,   -1,   -1,   -1,
         -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
-        20,   -1,   21,   -1,   22,   -1,   -1,   -1,
-        -1,   -1,   -1,   23,   -1,   -1,   24,   25,
-        26,   -1,   -1,   -1,   27,   -1,   -1,   -1,
-        -1,   -1,   -1,   -1,   -1,   -1,   -1,   28,
-        -1,   -1,   -1,   -1,   -1,   -1,   29,   -1,
         -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
-        -1,   -1,   30,   31,   32,   -1,   -1,   33,
-        -1,   -1,   -1,   -1,   -1,   34,   35,   -1,
-        -1,   -1,   -1,   -1,   -1,   -1,   36,   37,
-        -1,   -1,   38,   -1,   39,   40,   -1,   -1,
-        -1,   -1,   -1,   41,   -1,   -1,   -1,   -1,
-        -1,   -1,   -1,   42,   -1,   43,   -1,   -1,
-        44,   45,   -1,   -1,   -1,   -1,   -1,   -1,
+        -1,   -1,   -1,  176,  177,   -1,   -1,   -1,
+       178,   -1,   -1,  179,   -1,   -1,   -1,  180,
+       181,   -1,   -1,   -1,   -1,   -1,  182,   -1,
+       183,   -1,   -1,   -1,   -1,   -1,  184,  185,
+        -1,   -1,   -1,  186,   -1,   -1,   -1,   -1,
+        -1,   -1,   -1,  187,   -1,   -1,   -1,   -1,
+        -1,   -1,   -1,   -1,   -1,   -1,   -1,  188,
+        -1,   -1,   -1,  189,   -1,   -1,   -1,   -1,
+       190,  191,   -1,   -1,   -1,  192,   -1,   -1,
+       193,   -1,   -1,   -1,   -1,   -1,   -1,  194,
         -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
-        46,   47,   -1,   -1,   -1,   -1,   -1,   -1,
-        48,   49,   50,   -1,   51,   -1,   -1,   -1,
-        -1,   -1,   -1,   -1,   -1,   -1,   52,   -1,
-        53,   -1,   -1,   -1,   -1,   -1,   54,   -1,
-        -1,   -1,   55,   56,   57,   -1,   -1,   58,
-        -1,   59,   60,   -1,   61,   62,   -1,   63,
-        -1,   -1,   64,   65, -564, -188,   -2,   -1,
-        -1,   -1,   -1,   68,   -1,   -1,   69,   70,
-        -1,   -1,   -1,   71,   72,   -1,   -1,   73,
-        -1,   74,   -1,   -1,   -1,   -1,   -1,   -1,
-        -1,   -1,   -1,   -1,   -1,   75,   -1,   76,
-        -1,   77,   -1,   -1,   -1,   -1,   -1,   -1,
-        -1,   -1,   -1,   78,   -1,   79,   80,   -1,
-        81,   -1,   -1,   -1,   -1,   82,   83,   -1,
-        -1,   84,   85,   -1,   -1,   -1,   -1,   86,
-        -1,   -1,   87,   -1,   -1,   -1,   -1,   -1,
-        88,   -1,   -1,   -1,   -1,   89,   -1,   -1,
-        -1,   -1,   90,   -1,   -1,   -1,   91,   -1,
-        92,   -1,   93,   94,   95,   96,   -1,   97,
-        98,   99,  100,   -1,   -1,   -1,  101,   -1,
-        -1,   -1,   -1,  102,   -1,   -1,  103,  104,
-        -1,   -1,   -1,  105,  106,  107,   -1,  108,
-        -1,   -1,   -1,   -1,  109,  110,   -1,  111,
-        -1,  112,   -1,  113,   -1,   -1,   -1,   -1,
-        -1,  114,  115,   -1,   -1,   -1,  116,   -1,
-        -1,   -1,   -1,   -1,   -1,   -1,  117,  118,
-        -1,   -1,   -1,   -1,  119,   -1,  120,   -1,
-        -1,  121,   -1,   -1,  122,   -1,  123,  124,
-       125,   -1,  126,  127,  128,   -1,   -1,  129,
-        -1,  130,  131,  132,  133,   -1,  134,   -1,
-       135,  136,   -1,  137,   -1,   -1,   -1,   -1,
-        -1,   -1,   -1,   -1,  138,   -1,   -1,   -1,
-        -1,   -1,  139,   -1,   -1,  140,   -1,  141,
+        -1,   -1,   -1,  195,   -1,   -1,   -1,  196,
+       197,  198,  199,  200,  201,  202,   -1,   -1,
+        -1,  203,   -1,   -1,   -1,   -1,   -1,   -1,
+        -1,   -1,   -1,   -1,  204,   -1,   -1,   -1,
+       205,   -1,  206,  207,   -1,  208,   -1,   -1,
+        -1,   -1,   -1,   -1,   -1,  209,   -1,   -1,
+       210,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+        -1,   -1,   -1,   -1,   -1,   -1,  211,   -1,
+        -1,   -1,   -1,   -1,   -1,   -1,  212,   -1,
+        -1,   -1,   -1,   -1,   -1,   -1,   -1,  213,
+        -1,   -1,  214,   -1,   -1,   -1,   -1,   -1,
         -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
-        -1,   -1,   -1,   -1,  142,  143,   -1,   -1,
-       144,   -1,   -1,   -1,   -1,   -1,   -1,  145,
-       146,   -1,   -1,   -1,  147,   -1,   -1,   -1,
-       148,  149,  150,   -1,   -1,   -1,  151,  152,
         -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
-        -1,   -1,  153,   -1,   -1,   -1,   -1,   -1,
-        -1,   -1,   -1,   -1,   -1,   -1,  154,  155,
-        -1,   -1,  156,  157,   -1,   -1,   -1,   -1,
-        -1,  158,  159,  160,   -1,  161,   -1,  162,
-        -1,   -1,  163,   -1,   -1,   -1,  164,  165,
-        -1,  166,   -1,   -1,  167,   -1,  168,   -1,
-        -1,   -1,   -1,  169,   -1,   -1,   -1,   -1,
-        -1,  170,   -1,   -1,   -1,   -1,   -1,  171,
-        -1,  172,   -1,   -1,   -1,  173,   -1,  174,
+        -1,   -1,   -1,   -1,   -1,   -1,  215,  216,
+        -1,  217,   -1,   -1,   -1,   -1,   -1,  218,
         -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
-        -1,   -1,  175,   -1,   -1,   -1,   -1,   -1,
-        -1,  176,  177,   -1,   -1,  178,   -1,  179,
-        -1,   -1,   -1,   -1,  180,   -1,   -1,  181,
-       182,   -1,   -1,   -1,  183,   -1,   -1,   -1,
-       184,   -1,  185,   -1,  186,  187,   -1,   -1,
-        -1,   -1,   -1,  188,   -1,   -1,   -1,  189,
-       190,   -1,  191,   -1,   -1,  192,  193,   -1,
-       194,  195,  196,   -1,  197,  198,   -1,   -1,
-       199,   -1,   -1,   -1,   -1,  200,  201,   -1,
-       202,   -1,   -1,   -1,   -1,  203,   -1,  204,
+        -1,   -1,  219,   -1,   -1,  220,   -1,   -1,
+        -1,  221,   -1,   -1,   -1,   -1,   -1,   -1,
         -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
-        -1,   -1,   -1,   -1,   -1,   -1,  205,   -1,
-        -1,  206,   -1,   -1,  207,  208,   -1,   -1,
-        -1,   -1,   -1,   -1,   -1,   -1,  209,   -1,
         -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
         -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
-        -1,   -1,   -1,   -1,   -1,  210,   -1,   -1,
-       211,   -1,  212,   -1,   -1,  213,   -1,   -1,
+        -1,   -1,   -1,  222,   -1,   -1,   -1,   -1,
+        -1,   -1,   -1,  223,   -1,   -1,   -1,   -1,
+       224,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
         -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
-        -1,   -1,  214,   -1,   -1,  215,   -1,   -1,
-       216,  217,   -1,   -1,   -1,   -1,   -1,   -1,
-        -1,   -1,   -1,  218,  219,   -1,   -1,  220,
-        -1,   -1,   -1,   -1,   -1,   -1,  221,   -1,
         -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
         -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
-       222,   -1,  223,  224,   -1,   -1,   -1,   -1,
-        -1,   -1,   -1,   -1,   -1,   -1,   -1,  225,
         -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
         -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
-        -1,   -1,   -1,  226,  227,   -1,   -1,   -1,
-        -1,  228,   -1,   -1,   -1,   -1,   -1,   -1,
-        -1,  229,   -1,   -1,   -1,   -1,  230,   -1,
+        -1,   -1,   -1,   -1,   -1,  225,   -1,   -1,
         -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
-        -1,   -1,   -1,  231,   -1,   -1,   -1,   -1,
-       232,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
-        -1,  233,   -1,   -1,   -1,   -1,   -1,   -1,
         -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+       226,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+       227,   -1,  228,   -1,   -1,   -1,   -1,   -1,
+        -1,   -1,   -1,   -1,  229,   -1,   -1,   -1,
         -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
         -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+        -1,   -1,  230,   -1,   -1,   -1,   -1,   -1,
         -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
-        -1,   -1,   -1,   -1,   -1,   -1,   -1,  234,
         -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+        -1,   -1,   -1,   -1,  231,   -1,   -1,   -1,
+        -1,   -1,   -1,   -1,  232,   -1,   -1,   -1,
+        -1,   -1,  233,  234,   -1,   -1,   -1,   -1,
+        -1,   -1,   -1,   -1,   -1,   -1,   -1,  235,
+        -1,  236,   -1,   -1,   -1,   -1,  237,   -1,
         -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
-        -1,   -1,  235,   -1,   -1,   -1,   -1,   -1,
+        -1,  238,   -1,   -1,   -1,   -1,   -1,   -1,
         -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
-        -1,   -1,   -1,   -1,  236,   -1,   -1,   -1,
-        -1,   -1,   -1,   -1,  237,   -1,   -1,   -1,
         -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
         -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
         -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
         -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
-        -1,   -1,   -1,   -1,   -1,  238,   -1,   -1,
+        -1,  239,   -1,   -1,   -1,   -1,   -1,   -1,
+        -1,   -1,   -1,  240,   -1,   -1,   -1,   -1,
+       241,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+        -1,   -1,   -1,   -1,   -1,   -1,  242,   -1,
         -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+        -1,   -1,   -1,   -1,   -1,   -1,  243,   -1,
         -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
-        -1,   -1,   -1,   -1,   -1,   -1,   -1,  239,
-        -1,   -1,  240,   -1,   -1,   -1,   -1,   -1,
+        -1,   -1,   -1,   -1,   -1,   -1,   -1,  244,
         -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
         -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
-        -1,   -1,  241,   -1,   -1,   -1,   -1,   -1,
-        -1,   -1,   -1,   -1,  242,   -1,   -1,  243,
+        -1,   -1,   -1,   -1,  245,   -1,   -1,   -1,
         -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
-       244,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
         -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
         -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
         -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
-       245,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
-       246,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
         -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
-        -1,   -1,   -1,  247,   -1,   -1,   -1,   -1,
+        -1,   -1,   -1,  246,   -1,   -1,   -1,   -1,
+        -1,   -1,   -1,   -1,   -1,  247,   -1,   -1,
         -1,   -1,   -1,  248,   -1,   -1,   -1,   -1,
-        -1,   -1,   -1,   -1,   -1,  249,   -1,   -1,
+        -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+        -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+        -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+        -1,   -1,   -1,  249,   -1,   -1,   -1,   -1,
+        -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+        -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+        -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+        -1,  250,   -1,   -1,   -1,   -1,   -1,   -1,
+        -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+        -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+        -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+       251,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
         -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
         -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
         -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
         -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+        -1,   -1,   -1,   -1,  252,   -1,   -1,   -1,
         -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
         -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
         -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
         -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
         -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
-        -1,   -1,   -1,  250,   -1,   -1,   -1,   -1,
         -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+        -1,  253,   -1,   -1,   -1,   -1,   -1,   -1,
         -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
         -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
         -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
@@ -549,16 +572,15 @@ findValue (register const char *str, register unsigned int len)
         -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
         -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
         -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+        -1,   -1,   -1,  254,   -1,   -1,   -1,   -1,
         -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
         -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
-        -1,   -1,   -1,   -1,   -1,  251,   -1,   -1,
-        -1,   -1,   -1,   -1,   -1,  252,   -1,   -1,
         -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
         -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
         -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
         -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
         -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
-        -1,   -1,   -1,   -1,   -1,   -1,  253
+       255
     };
 
   if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
@@ -675,6 +697,8 @@ static const char * const valueList[] = {
 "white", 
 "yellow", 
 "transparent", 
+"-khtml-link", 
+"-khtml-activelink", 
 "activeborder", 
 "activecaption", 
 "appworkspace", 
diff --git a/WebCore/khtml/css/cssvalues.h b/WebCore/khtml/css/cssvalues.h
index 683f93e..466c89d 100644
--- a/WebCore/khtml/css/cssvalues.h
+++ b/WebCore/khtml/css/cssvalues.h
@@ -87,183 +87,185 @@ DOM::DOMString getValueName(unsigned short id);
 #define CSS_VAL_WHITE 76
 #define CSS_VAL_YELLOW 77
 #define CSS_VAL_TRANSPARENT 78
-#define CSS_VAL_ACTIVEBORDER 79
-#define CSS_VAL_ACTIVECAPTION 80
-#define CSS_VAL_APPWORKSPACE 81
-#define CSS_VAL_BACKGROUND 82
-#define CSS_VAL_BUTTONFACE 83
-#define CSS_VAL_BUTTONHIGHLIGHT 84
-#define CSS_VAL_BUTTONSHADOW 85
-#define CSS_VAL_BUTTONTEXT 86
-#define CSS_VAL_CAPTIONTEXT 87
-#define CSS_VAL_GRAYTEXT 88
-#define CSS_VAL_HIGHLIGHT 89
-#define CSS_VAL_HIGHLIGHTTEXT 90
-#define CSS_VAL_INACTIVEBORDER 91
-#define CSS_VAL_INACTIVECAPTION 92
-#define CSS_VAL_INACTIVECAPTIONTEXT 93
-#define CSS_VAL_INFOBACKGROUND 94
-#define CSS_VAL_INFOTEXT 95
-#define CSS_VAL_MENUTEXT 96
-#define CSS_VAL_SCROLLBAR 97
-#define CSS_VAL_THREEDDARKSHADOW 98
-#define CSS_VAL_THREEDFACE 99
-#define CSS_VAL_THREEDHIGHLIGHT 100
-#define CSS_VAL_THREEDLIGHTSHADOW 101
-#define CSS_VAL_THREEDSHADOW 102
-#define CSS_VAL_WINDOW 103
-#define CSS_VAL_WINDOWFRAME 104
-#define CSS_VAL_WINDOWTEXT 105
-#define CSS_VAL_GREY 106
-#define CSS_VAL__KHTML_TEXT 107
-#define CSS_VAL_REPEAT 108
-#define CSS_VAL_REPEAT_X 109
-#define CSS_VAL_REPEAT_Y 110
-#define CSS_VAL_NO_REPEAT 111
-#define CSS_VAL_BASELINE 112
-#define CSS_VAL_MIDDLE 113
-#define CSS_VAL_SUB 114
-#define CSS_VAL_SUPER 115
-#define CSS_VAL_TEXT_TOP 116
-#define CSS_VAL_TEXT_BOTTOM 117
-#define CSS_VAL_TOP 118
-#define CSS_VAL_BOTTOM 119
-#define CSS_VAL__KHTML_BASELINE_MIDDLE 120
-#define CSS_VAL__KHTML_AUTO 121
-#define CSS_VAL_LEFT 122
-#define CSS_VAL_RIGHT 123
-#define CSS_VAL_CENTER 124
-#define CSS_VAL_JUSTIFY 125
-#define CSS_VAL__KHTML_LEFT 126
-#define CSS_VAL__KHTML_RIGHT 127
-#define CSS_VAL__KHTML_CENTER 128
-#define CSS_VAL_OUTSIDE 129
-#define CSS_VAL_INSIDE 130
-#define CSS_VAL_DISC 131
-#define CSS_VAL_CIRCLE 132
-#define CSS_VAL_SQUARE 133
-#define CSS_VAL_DECIMAL 134
-#define CSS_VAL_DECIMAL_LEADING_ZERO 135
-#define CSS_VAL_LOWER_ROMAN 136
-#define CSS_VAL_UPPER_ROMAN 137
-#define CSS_VAL_LOWER_GREEK 138
-#define CSS_VAL_LOWER_ALPHA 139
-#define CSS_VAL_LOWER_LATIN 140
-#define CSS_VAL_UPPER_ALPHA 141
-#define CSS_VAL_UPPER_LATIN 142
-#define CSS_VAL_HEBREW 143
-#define CSS_VAL_ARMENIAN 144
-#define CSS_VAL_GEORGIAN 145
-#define CSS_VAL_CJK_IDEOGRAPHIC 146
-#define CSS_VAL_HIRAGANA 147
-#define CSS_VAL_KATAKANA 148
-#define CSS_VAL_HIRAGANA_IROHA 149
-#define CSS_VAL_KATAKANA_IROHA 150
-#define CSS_VAL_INLINE 151
-#define CSS_VAL_BLOCK 152
-#define CSS_VAL_LIST_ITEM 153
-#define CSS_VAL_RUN_IN 154
-#define CSS_VAL_COMPACT 155
-#define CSS_VAL_INLINE_BLOCK 156
-#define CSS_VAL_TABLE 157
-#define CSS_VAL_INLINE_TABLE 158
-#define CSS_VAL_TABLE_ROW_GROUP 159
-#define CSS_VAL_TABLE_HEADER_GROUP 160
-#define CSS_VAL_TABLE_FOOTER_GROUP 161
-#define CSS_VAL_TABLE_ROW 162
-#define CSS_VAL_TABLE_COLUMN_GROUP 163
-#define CSS_VAL_TABLE_COLUMN 164
-#define CSS_VAL_TABLE_CELL 165
-#define CSS_VAL_TABLE_CAPTION 166
-#define CSS_VAL__KHTML_BOX 167
-#define CSS_VAL__KHTML_INLINE_BOX 168
-#define CSS_VAL_AUTO 169
-#define CSS_VAL_CROSSHAIR 170
-#define CSS_VAL_DEFAULT 171
-#define CSS_VAL_POINTER 172
-#define CSS_VAL_MOVE 173
-#define CSS_VAL_E_RESIZE 174
-#define CSS_VAL_NE_RESIZE 175
-#define CSS_VAL_NW_RESIZE 176
-#define CSS_VAL_N_RESIZE 177
-#define CSS_VAL_SE_RESIZE 178
-#define CSS_VAL_SW_RESIZE 179
-#define CSS_VAL_S_RESIZE 180
-#define CSS_VAL_W_RESIZE 181
-#define CSS_VAL_TEXT 182
-#define CSS_VAL_WAIT 183
-#define CSS_VAL_HELP 184
-#define CSS_VAL_LTR 185
-#define CSS_VAL_RTL 186
-#define CSS_VAL_CAPITALIZE 187
-#define CSS_VAL_UPPERCASE 188
-#define CSS_VAL_LOWERCASE 189
-#define CSS_VAL_VISIBLE 190
-#define CSS_VAL_COLLAPSE 191
-#define CSS_VAL_ABOVE 192
-#define CSS_VAL_ABSOLUTE 193
-#define CSS_VAL_ALWAYS 194
-#define CSS_VAL_AVOID 195
-#define CSS_VAL_BELOW 196
-#define CSS_VAL_BIDI_OVERRIDE 197
-#define CSS_VAL_BLINK 198
-#define CSS_VAL_BOTH 199
-#define CSS_VAL_CLOSE_QUOTE 200
-#define CSS_VAL_CROP 201
-#define CSS_VAL_CROSS 202
-#define CSS_VAL_EMBED 203
-#define CSS_VAL_FIXED 204
-#define CSS_VAL_HAND 205
-#define CSS_VAL_HIDE 206
-#define CSS_VAL_HIGHER 207
-#define CSS_VAL_INVERT 208
-#define CSS_VAL_LANDSCAPE 209
-#define CSS_VAL_LEVEL 210
-#define CSS_VAL_LINE_THROUGH 211
-#define CSS_VAL_LOUD 212
-#define CSS_VAL_LOWER 213
-#define CSS_VAL_MARQUEE 214
-#define CSS_VAL_MIX 215
-#define CSS_VAL_NO_CLOSE_QUOTE 216
-#define CSS_VAL_NO_OPEN_QUOTE 217
-#define CSS_VAL_NOWRAP 218
-#define CSS_VAL_OPEN_QUOTE 219
-#define CSS_VAL_OVERLINE 220
-#define CSS_VAL_PORTRAIT 221
-#define CSS_VAL_PRE 222
-#define CSS_VAL_RELATIVE 223
-#define CSS_VAL_SCROLL 224
-#define CSS_VAL_SEPARATE 225
-#define CSS_VAL_SHOW 226
-#define CSS_VAL_STATIC 227
-#define CSS_VAL_THICK 228
-#define CSS_VAL_THIN 229
-#define CSS_VAL_UNDERLINE 230
-#define CSS_VAL__KHTML_NOWRAP 231
-#define CSS_VAL_STRETCH 232
-#define CSS_VAL_START 233
-#define CSS_VAL_END 234
-#define CSS_VAL_REVERSE 235
-#define CSS_VAL_HORIZONTAL 236
-#define CSS_VAL_VERTICAL 237
-#define CSS_VAL_INLINE_AXIS 238
-#define CSS_VAL_BLOCK_AXIS 239
-#define CSS_VAL_SINGLE 240
-#define CSS_VAL_MULTIPLE 241
-#define CSS_VAL_FORWARDS 242
-#define CSS_VAL_BACKWARDS 243
-#define CSS_VAL_AHEAD 244
-#define CSS_VAL_UP 245
-#define CSS_VAL_DOWN 246
-#define CSS_VAL_SLOW 247
-#define CSS_VAL_FAST 248
-#define CSS_VAL_INFINITE 249
-#define CSS_VAL_SLIDE 250
-#define CSS_VAL_ALTERNATE 251
-#define CSS_VAL_UNFURL 252
-#define CSS_VAL_READ_ONLY 253
-#define CSS_VAL_READ_WRITE 254
+#define CSS_VAL__KHTML_LINK 79
+#define CSS_VAL__KHTML_ACTIVELINK 80
+#define CSS_VAL_ACTIVEBORDER 81
+#define CSS_VAL_ACTIVECAPTION 82
+#define CSS_VAL_APPWORKSPACE 83
+#define CSS_VAL_BACKGROUND 84
+#define CSS_VAL_BUTTONFACE 85
+#define CSS_VAL_BUTTONHIGHLIGHT 86
+#define CSS_VAL_BUTTONSHADOW 87
+#define CSS_VAL_BUTTONTEXT 88
+#define CSS_VAL_CAPTIONTEXT 89
+#define CSS_VAL_GRAYTEXT 90
+#define CSS_VAL_HIGHLIGHT 91
+#define CSS_VAL_HIGHLIGHTTEXT 92
+#define CSS_VAL_INACTIVEBORDER 93
+#define CSS_VAL_INACTIVECAPTION 94
+#define CSS_VAL_INACTIVECAPTIONTEXT 95
+#define CSS_VAL_INFOBACKGROUND 96
+#define CSS_VAL_INFOTEXT 97
+#define CSS_VAL_MENUTEXT 98
+#define CSS_VAL_SCROLLBAR 99
+#define CSS_VAL_THREEDDARKSHADOW 100
+#define CSS_VAL_THREEDFACE 101
+#define CSS_VAL_THREEDHIGHLIGHT 102
+#define CSS_VAL_THREEDLIGHTSHADOW 103
+#define CSS_VAL_THREEDSHADOW 104
+#define CSS_VAL_WINDOW 105
+#define CSS_VAL_WINDOWFRAME 106
+#define CSS_VAL_WINDOWTEXT 107
+#define CSS_VAL_GREY 108
+#define CSS_VAL__KHTML_TEXT 109
+#define CSS_VAL_REPEAT 110
+#define CSS_VAL_REPEAT_X 111
+#define CSS_VAL_REPEAT_Y 112
+#define CSS_VAL_NO_REPEAT 113
+#define CSS_VAL_BASELINE 114
+#define CSS_VAL_MIDDLE 115
+#define CSS_VAL_SUB 116
+#define CSS_VAL_SUPER 117
+#define CSS_VAL_TEXT_TOP 118
+#define CSS_VAL_TEXT_BOTTOM 119
+#define CSS_VAL_TOP 120
+#define CSS_VAL_BOTTOM 121
+#define CSS_VAL__KHTML_BASELINE_MIDDLE 122
+#define CSS_VAL__KHTML_AUTO 123
+#define CSS_VAL_LEFT 124
+#define CSS_VAL_RIGHT 125
+#define CSS_VAL_CENTER 126
+#define CSS_VAL_JUSTIFY 127
+#define CSS_VAL__KHTML_LEFT 128
+#define CSS_VAL__KHTML_RIGHT 129
+#define CSS_VAL__KHTML_CENTER 130
+#define CSS_VAL_OUTSIDE 131
+#define CSS_VAL_INSIDE 132
+#define CSS_VAL_DISC 133
+#define CSS_VAL_CIRCLE 134
+#define CSS_VAL_SQUARE 135
+#define CSS_VAL_DECIMAL 136
+#define CSS_VAL_DECIMAL_LEADING_ZERO 137
+#define CSS_VAL_LOWER_ROMAN 138
+#define CSS_VAL_UPPER_ROMAN 139
+#define CSS_VAL_LOWER_GREEK 140
+#define CSS_VAL_LOWER_ALPHA 141
+#define CSS_VAL_LOWER_LATIN 142
+#define CSS_VAL_UPPER_ALPHA 143
+#define CSS_VAL_UPPER_LATIN 144
+#define CSS_VAL_HEBREW 145
+#define CSS_VAL_ARMENIAN 146
+#define CSS_VAL_GEORGIAN 147
+#define CSS_VAL_CJK_IDEOGRAPHIC 148
+#define CSS_VAL_HIRAGANA 149
+#define CSS_VAL_KATAKANA 150
+#define CSS_VAL_HIRAGANA_IROHA 151
+#define CSS_VAL_KATAKANA_IROHA 152
+#define CSS_VAL_INLINE 153
+#define CSS_VAL_BLOCK 154
+#define CSS_VAL_LIST_ITEM 155
+#define CSS_VAL_RUN_IN 156
+#define CSS_VAL_COMPACT 157
+#define CSS_VAL_INLINE_BLOCK 158
+#define CSS_VAL_TABLE 159
+#define CSS_VAL_INLINE_TABLE 160
+#define CSS_VAL_TABLE_ROW_GROUP 161
+#define CSS_VAL_TABLE_HEADER_GROUP 162
+#define CSS_VAL_TABLE_FOOTER_GROUP 163
+#define CSS_VAL_TABLE_ROW 164
+#define CSS_VAL_TABLE_COLUMN_GROUP 165
+#define CSS_VAL_TABLE_COLUMN 166
+#define CSS_VAL_TABLE_CELL 167
+#define CSS_VAL_TABLE_CAPTION 168
+#define CSS_VAL__KHTML_BOX 169
+#define CSS_VAL__KHTML_INLINE_BOX 170
+#define CSS_VAL_AUTO 171
+#define CSS_VAL_CROSSHAIR 172
+#define CSS_VAL_DEFAULT 173
+#define CSS_VAL_POINTER 174
+#define CSS_VAL_MOVE 175
+#define CSS_VAL_E_RESIZE 176
+#define CSS_VAL_NE_RESIZE 177
+#define CSS_VAL_NW_RESIZE 178
+#define CSS_VAL_N_RESIZE 179
+#define CSS_VAL_SE_RESIZE 180
+#define CSS_VAL_SW_RESIZE 181
+#define CSS_VAL_S_RESIZE 182
+#define CSS_VAL_W_RESIZE 183
+#define CSS_VAL_TEXT 184
+#define CSS_VAL_WAIT 185
+#define CSS_VAL_HELP 186
+#define CSS_VAL_LTR 187
+#define CSS_VAL_RTL 188
+#define CSS_VAL_CAPITALIZE 189
+#define CSS_VAL_UPPERCASE 190
+#define CSS_VAL_LOWERCASE 191
+#define CSS_VAL_VISIBLE 192
+#define CSS_VAL_COLLAPSE 193
+#define CSS_VAL_ABOVE 194
+#define CSS_VAL_ABSOLUTE 195
+#define CSS_VAL_ALWAYS 196
+#define CSS_VAL_AVOID 197
+#define CSS_VAL_BELOW 198
+#define CSS_VAL_BIDI_OVERRIDE 199
+#define CSS_VAL_BLINK 200
+#define CSS_VAL_BOTH 201
+#define CSS_VAL_CLOSE_QUOTE 202
+#define CSS_VAL_CROP 203
+#define CSS_VAL_CROSS 204
+#define CSS_VAL_EMBED 205
+#define CSS_VAL_FIXED 206
+#define CSS_VAL_HAND 207
+#define CSS_VAL_HIDE 208
+#define CSS_VAL_HIGHER 209
+#define CSS_VAL_INVERT 210
+#define CSS_VAL_LANDSCAPE 211
+#define CSS_VAL_LEVEL 212
+#define CSS_VAL_LINE_THROUGH 213
+#define CSS_VAL_LOUD 214
+#define CSS_VAL_LOWER 215
+#define CSS_VAL_MARQUEE 216
+#define CSS_VAL_MIX 217
+#define CSS_VAL_NO_CLOSE_QUOTE 218
+#define CSS_VAL_NO_OPEN_QUOTE 219
+#define CSS_VAL_NOWRAP 220
+#define CSS_VAL_OPEN_QUOTE 221
+#define CSS_VAL_OVERLINE 222
+#define CSS_VAL_PORTRAIT 223
+#define CSS_VAL_PRE 224
+#define CSS_VAL_RELATIVE 225
+#define CSS_VAL_SCROLL 226
+#define CSS_VAL_SEPARATE 227
+#define CSS_VAL_SHOW 228
+#define CSS_VAL_STATIC 229
+#define CSS_VAL_THICK 230
+#define CSS_VAL_THIN 231
+#define CSS_VAL_UNDERLINE 232
+#define CSS_VAL__KHTML_NOWRAP 233
+#define CSS_VAL_STRETCH 234
+#define CSS_VAL_START 235
+#define CSS_VAL_END 236
+#define CSS_VAL_REVERSE 237
+#define CSS_VAL_HORIZONTAL 238
+#define CSS_VAL_VERTICAL 239
+#define CSS_VAL_INLINE_AXIS 240
+#define CSS_VAL_BLOCK_AXIS 241
+#define CSS_VAL_SINGLE 242
+#define CSS_VAL_MULTIPLE 243
+#define CSS_VAL_FORWARDS 244
+#define CSS_VAL_BACKWARDS 245
+#define CSS_VAL_AHEAD 246
+#define CSS_VAL_UP 247
+#define CSS_VAL_DOWN 248
+#define CSS_VAL_SLOW 249
+#define CSS_VAL_FAST 250
+#define CSS_VAL_INFINITE 251
+#define CSS_VAL_SLIDE 252
+#define CSS_VAL_ALTERNATE 253
+#define CSS_VAL_UNFURL 254
+#define CSS_VAL_READ_ONLY 255
+#define CSS_VAL_READ_WRITE 256
 
-#define CSS_VAL_TOTAL 255
+#define CSS_VAL_TOTAL 257
 #endif
 
diff --git a/WebCore/khtml/css/cssvalues.in b/WebCore/khtml/css/cssvalues.in
index 2ff4a7e..391a721 100644
--- a/WebCore/khtml/css/cssvalues.in
+++ b/WebCore/khtml/css/cssvalues.in
@@ -120,6 +120,8 @@ teal
 white
 yellow
 transparent
+-khtml-link
+-khtml-activelink
 activeborder
 activecaption
 appworkspace
diff --git a/WebCore/khtml/css/html4.css b/WebCore/khtml/css/html4.css
index da57d6f..f138fc8 100644
--- a/WebCore/khtml/css/html4.css
+++ b/WebCore/khtml/css/html4.css
@@ -419,28 +419,14 @@ SUP {
 	font-size: smaller;
 }
 
-/* ### not supported at the moment
-ABBR, ACRONYM { 
-	font-variant: small-caps; 
-	letter-spacing: 0.1em 
-}
-*/
 abbr, 
 acronym {
 	font-style: italic;
 }
 
-*|:focus          { outline: auto 3px #1f5ccf }
-a:link          { color: #0000EE; text-decoration: underline; }
-a:link:active          { color: red }
-a:visited              { color: #551A8B; text-decoration: underline; }
-a:visited:active       { color: red }
-
-/* ### :before is now supported, but we haven't tried reinstating this
-   ### rule that was comment out long ago.
-      BR:before       { content: "\n" }
-*/
-
+:focus          { outline: auto 3px #1f5ccf }
+a:-khtml-any-link { color: -khtml-link; text-decoration: underline; }
+a:-khtml-any-link:active { color: -khtml-activelink; }
 
 /* Bidirectionality settings (do not change) */
 
@@ -497,19 +483,3 @@ wbr {
 }
 
 /* noscript is handled internally, as it depends on the html settings */
-
-/* media rules are commented out for the moment. We'll have to add
- * them later. Lars, 23.12.99
- */
-
-/*
-      @media print {
-        @page         { margin: 10% }
-        H1, H2, H3,
-        H4, H5, H6    { page-break-after: avoid; page-break-inside: avoid }
-        BLOCKQUOTE,
-        PRE           { page-break-inside: avoid }
-        UL, OL, DL    { page-break-before: avoid }
-      }
-
-*/
diff --git a/WebCore/khtml/css/parser.cpp b/WebCore/khtml/css/parser.cpp
index 13fd9a1..28ce175 100644
--- a/WebCore/khtml/css/parser.cpp
+++ b/WebCore/khtml/css/parser.cpp
@@ -141,7 +141,6 @@ static inline int getValueID(const char *tagStr, int len)
 typedef union {
     CSSRuleImpl *rule;
     CSSSelector *selector;
-    QPtrList<CSSSelector> *selectorList;
     bool ok;
     MediaListImpl *mediaList;
     CSSMediaRuleImpl *mediaRule;
@@ -157,7 +156,7 @@ typedef union {
     Value value;
     ValueList *valueList;
 } YYSTYPE;
-#line 106 "parser.y"
+#line 105 "parser.y"
 
 
 static inline int cssyyerror(const char *x ) {
@@ -306,23 +305,23 @@ static const short yyrhs[] = {    69,
 
 #if YYDEBUG != 0
 static const short yyrline[] = { 0,
-   237,   239,   240,   241,   244,   251,   257,   282,   284,   287,
-   289,   290,   293,   295,   300,   301,   304,   306,   316,   318,
-   321,   323,   333,   335,   336,   337,   338,   339,   342,   355,
-   358,   363,   372,   373,   376,   378,   381,   383,   386,   390,
-   394,   398,   402,   407,   413,   427,   429,   438,   460,   464,
-   469,   473,   478,   480,   481,   484,   486,   489,   509,   523,
-   537,   543,   547,   570,   576,   578,   579,   582,   587,   592,
-   597,   604,   613,   624,   641,   646,   651,   661,   667,   674,
-   675,   676,   679,   688,   708,   714,   720,   728,   739,   743,
-   746,   749,   752,   755,   760,   762,   765,   772,   779,   788,
-   792,   797,   800,   806,   814,   818,   821,   827,   833,   838,
-   844,   852,   875,   879,   887,   892,   899,   906,   908,   911,
-   916,   929,   935,   939,   942,   947,   949,   950,   951,   958,
-   959,   960,   961,   962,   963,   965,   970,   972,   973,   974,
-   975,   976,   977,   978,   979,   980,   981,   982,   983,   984,
-   985,   986,   987,   988,   992,  1000,  1015,  1022,  1029,  1037,
-  1063,  1065,  1068,  1070
+   236,   238,   239,   240,   243,   250,   256,   281,   283,   286,
+   288,   289,   292,   294,   299,   300,   303,   305,   315,   317,
+   320,   322,   332,   334,   335,   336,   337,   338,   341,   354,
+   357,   362,   371,   372,   375,   377,   380,   382,   385,   389,
+   393,   397,   401,   406,   412,   426,   428,   437,   459,   463,
+   468,   472,   477,   479,   480,   483,   485,   488,   508,   520,
+   534,   540,   544,   567,   573,   575,   576,   579,   584,   589,
+   594,   601,   610,   621,   638,   643,   647,   657,   663,   673,
+   674,   675,   678,   690,   710,   716,   722,   730,   741,   745,
+   748,   751,   754,   757,   762,   764,   767,   774,   781,   790,
+   794,   799,   802,   808,   816,   820,   823,   829,   835,   840,
+   846,   854,   877,   881,   889,   894,   901,   908,   910,   913,
+   918,   931,   937,   941,   944,   949,   951,   952,   953,   960,
+   961,   962,   963,   964,   965,   967,   972,   974,   975,   976,
+   977,   978,   979,   980,   981,   982,   983,   984,   985,   986,
+   987,   988,   989,   990,   994,  1002,  1017,  1024,  1031,  1039,
+  1065,  1067,  1070,  1072
 };
 #endif
 
@@ -1159,20 +1158,20 @@ yyreduce:
   switch (yyn) {
 
 case 5:
-#line 245 "parser.y"
+#line 244 "parser.y"
 {
         CSSParser *p = static_cast<CSSParser *>(parser);
         p->rule = yyvsp[-2].rule;
     ;
     break;}
 case 6:
-#line 252 "parser.y"
+#line 251 "parser.y"
 {
 	/* can be empty */
     ;
     break;}
 case 7:
-#line 258 "parser.y"
+#line 257 "parser.y"
 {
 	CSSParser *p = static_cast<CSSParser *>(parser);
 	if ( yyvsp[-1].valueList ) {
@@ -1197,7 +1196,7 @@ case 7:
     ;
     break;}
 case 14:
-#line 295 "parser.y"
+#line 294 "parser.y"
 {
 #ifdef CSS_DEBUG
      kdDebug( 6080 ) << "charset rule: " << qString(yyvsp[-2].string) << endl;
@@ -1205,7 +1204,7 @@ case 14:
  ;
     break;}
 case 18:
-#line 306 "parser.y"
+#line 305 "parser.y"
 {
      CSSParser *p = static_cast<CSSParser *>(parser);
      if ( yyvsp[-1].rule && p->styleElement && p->styleElement->isCSSStyleSheet() ) {
@@ -1216,7 +1215,7 @@ case 18:
  ;
     break;}
 case 22:
-#line 323 "parser.y"
+#line 322 "parser.y"
 {
      CSSParser *p = static_cast<CSSParser *>(parser);
      if ( yyvsp[-1].rule && p->styleElement && p->styleElement->isCSSStyleSheet() ) {
@@ -1227,7 +1226,7 @@ case 22:
  ;
     break;}
 case 29:
-#line 343 "parser.y"
+#line 342 "parser.y"
 {
 #ifdef CSS_DEBUG
 	kdDebug( 6080 ) << "@import: " << qString(yyvsp[-3].string) << endl;
@@ -1242,19 +1241,19 @@ case 29:
     ;
     break;}
 case 30:
-#line 355 "parser.y"
+#line 354 "parser.y"
 {
         yyval.rule = 0;
     ;
     break;}
 case 31:
-#line 358 "parser.y"
+#line 357 "parser.y"
 {
         yyval.rule = 0;
     ;
     break;}
 case 32:
-#line 364 "parser.y"
+#line 363 "parser.y"
 {
 #ifdef CSS_DEBUG
     kdDebug( 6080 ) << "@namespace: " << qString(yyvsp[-2].string) << endl;
@@ -1265,34 +1264,34 @@ case 32:
 ;
     break;}
 case 35:
-#line 377 "parser.y"
+#line 376 "parser.y"
 { yyval.string.string = 0; ;
     break;}
 case 36:
-#line 378 "parser.y"
+#line 377 "parser.y"
 { yyval.string = yyvsp[-1].string; ;
     break;}
 case 39:
-#line 387 "parser.y"
+#line 386 "parser.y"
 {
         yyval.mediaList = new MediaListImpl();
      ;
     break;}
 case 41:
-#line 395 "parser.y"
+#line 394 "parser.y"
 {
 	yyval.mediaList = 0;
     ;
     break;}
 case 42:
-#line 398 "parser.y"
+#line 397 "parser.y"
 {
 	yyval.mediaList = new MediaListImpl();
 	yyval.mediaList->appendMedium( domString(yyvsp[0].string).lower() );
     ;
     break;}
 case 43:
-#line 402 "parser.y"
+#line 401 "parser.y"
 {
 	yyval.mediaList = yyvsp[-3].mediaList;
         if (yyval.mediaList)
@@ -1300,14 +1299,14 @@ case 43:
     ;
     break;}
 case 44:
-#line 407 "parser.y"
+#line 406 "parser.y"
 {
         delete yyvsp[-1].mediaList;
         yyval.mediaList = 0;
     ;
     break;}
 case 45:
-#line 414 "parser.y"
+#line 413 "parser.y"
 {
 	CSSParser *p = static_cast<CSSParser *>(parser);
 	if ( yyvsp[-4].mediaList && yyvsp[-1].ruleList &&
@@ -1321,11 +1320,11 @@ case 45:
     ;
     break;}
 case 46:
-#line 428 "parser.y"
+#line 427 "parser.y"
 { yyval.ruleList = 0; ;
     break;}
 case 47:
-#line 429 "parser.y"
+#line 428 "parser.y"
 {
       yyval.ruleList = yyvsp[-2].ruleList;
       if ( yyvsp[-1].rule ) {
@@ -1335,123 +1334,121 @@ case 47:
   ;
     break;}
 case 48:
-#line 439 "parser.y"
+#line 438 "parser.y"
 {
       yyval.string = yyvsp[-1].string;
   ;
     break;}
 case 49:
-#line 461 "parser.y"
+#line 460 "parser.y"
 {
       yyval.rule = 0;
     ;
     break;}
 case 50:
-#line 464 "parser.y"
+#line 463 "parser.y"
 {
       yyval.rule = 0;
     ;
     break;}
 case 51:
-#line 470 "parser.y"
+#line 469 "parser.y"
 {
       yyval.rule = 0;
     ;
     break;}
 case 52:
-#line 473 "parser.y"
+#line 472 "parser.y"
 {
       yyval.rule = 0;
     ;
     break;}
 case 53:
-#line 479 "parser.y"
+#line 478 "parser.y"
 { yyval.relation = CSSSelector::Sibling; ;
     break;}
 case 54:
-#line 480 "parser.y"
+#line 479 "parser.y"
 { yyval.relation = CSSSelector::Child; ;
     break;}
 case 55:
-#line 481 "parser.y"
+#line 480 "parser.y"
 { yyval.relation = CSSSelector::Descendant; ;
     break;}
 case 56:
-#line 485 "parser.y"
+#line 484 "parser.y"
 { yyval.val = -1; ;
     break;}
 case 57:
-#line 486 "parser.y"
+#line 485 "parser.y"
 { yyval.val = 1; ;
     break;}
 case 58:
-#line 490 "parser.y"
+#line 489 "parser.y"
 {
 #ifdef CSS_DEBUG
 	kdDebug( 6080 ) << "got ruleset" << endl << "  selector:" << endl;
 #endif
 	CSSParser *p = static_cast<CSSParser *>(parser);
-	if ( yyvsp[-4].selectorList && yyvsp[-1].ok && p->numParsedProperties ) {
-	    CSSStyleRuleImpl *rule = new CSSStyleRuleImpl( p->styleElement );
-	    CSSStyleDeclarationImpl *decl = p->createStyleDeclaration( rule );
-	    rule->setSelector( yyvsp[-4].selectorList );
-	    rule->setDeclaration(decl);
-	    yyval.rule = rule;
+	if ( yyvsp[-4].selector && yyvsp[-1].ok && p->numParsedProperties ) {
+            CSSStyleRuleImpl *rule = new CSSStyleRuleImpl( p->styleElement );
+            CSSStyleDeclarationImpl *decl = p->createStyleDeclaration( rule );
+            rule->setSelector( yyvsp[-4].selector );
+            rule->setDeclaration(decl);
+            yyval.rule = rule;
 	} else {
 	    yyval.rule = 0;
-	    delete yyvsp[-4].selectorList;
+	    delete yyvsp[-4].selector;
 	    p->clearProperties();
 	}
     ;
     break;}
 case 59:
-#line 510 "parser.y"
+#line 509 "parser.y"
 {
 	if ( yyvsp[0].selector ) {
-	    yyval.selectorList = new QPtrList<CSSSelector>;
-            yyval.selectorList->setAutoDelete( true );
+	    yyval.selector = yyvsp[0].selector;
 #ifdef CSS_DEBUG
 	    kdDebug( 6080 ) << "   got simple selector:" << endl;
 	    yyvsp[0].selector->print();
 #endif
-	    yyval.selectorList->append( yyvsp[0].selector );
 	} else {
-	    yyval.selectorList = 0;
+	    yyval.selector = 0;
 	}
     ;
     break;}
 case 60:
-#line 523 "parser.y"
+#line 520 "parser.y"
 {
-	if ( yyvsp[-3].selectorList && yyvsp[0].selector ) {
-	    yyval.selectorList = yyvsp[-3].selectorList;
-	    yyval.selectorList->append( yyvsp[0].selector );
+	if ( yyvsp[-3].selector && yyvsp[0].selector ) {
+	    yyval.selector = yyvsp[-3].selector;
+	    yyval.selector->append( yyvsp[0].selector );
 #ifdef CSS_DEBUG
 	    kdDebug( 6080 ) << "   got simple selector:" << endl;
 	    yyvsp[0].selector->print();
 #endif
 	} else {
-            delete yyvsp[-3].selectorList;
+            delete yyvsp[-3].selector;
             delete yyvsp[0].selector;
-            yyval.selectorList = 0;
+            yyval.selector = 0;
         }
     ;
     break;}
 case 61:
-#line 537 "parser.y"
+#line 534 "parser.y"
 {
-        delete yyvsp[-1].selectorList;
-        yyval.selectorList = 0;
+        delete yyvsp[-1].selector;
+        yyval.selector = 0;
     ;
     break;}
 case 62:
-#line 544 "parser.y"
+#line 541 "parser.y"
 {
 	yyval.selector = yyvsp[0].selector;
     ;
     break;}
 case 63:
-#line 547 "parser.y"
+#line 544 "parser.y"
 {
     	yyval.selector = yyvsp[0].selector;
         if (!yyvsp[-2].selector) {
@@ -1477,33 +1474,33 @@ case 63:
     ;
     break;}
 case 64:
-#line 570 "parser.y"
+#line 567 "parser.y"
 {
         delete yyvsp[-1].selector;
         yyval.selector = 0;
     ;
     break;}
 case 65:
-#line 577 "parser.y"
+#line 574 "parser.y"
 { yyval.string.string = 0; yyval.string.length = 0; ;
     break;}
 case 66:
-#line 578 "parser.y"
+#line 575 "parser.y"
 { static unsigned short star = '*'; yyval.string.string = &star; yyval.string.length = 1; ;
     break;}
 case 67:
-#line 579 "parser.y"
+#line 576 "parser.y"
 { yyval.string = yyvsp[0].string; ;
     break;}
 case 68:
-#line 583 "parser.y"
+#line 580 "parser.y"
 {
 	yyval.selector = new CSSSelector();
 	yyval.selector->tag = yyvsp[-1].element;
     ;
     break;}
 case 69:
-#line 587 "parser.y"
+#line 584 "parser.y"
 {
 	yyval.selector = yyvsp[-1].selector;
 	if ( yyval.selector )
@@ -1511,7 +1508,7 @@ case 69:
     ;
     break;}
 case 70:
-#line 592 "parser.y"
+#line 589 "parser.y"
 {
 	yyval.selector = yyvsp[-1].selector;
         if (yyval.selector)
@@ -1519,7 +1516,7 @@ case 70:
     ;
     break;}
 case 71:
-#line 597 "parser.y"
+#line 594 "parser.y"
 {
         yyval.selector = new CSSSelector();
         yyval.selector->tag = yyvsp[-1].element;
@@ -1529,7 +1526,7 @@ case 71:
     ;
     break;}
 case 72:
-#line 604 "parser.y"
+#line 601 "parser.y"
 {
         yyval.selector = yyvsp[-1].selector;
         if (yyval.selector) {
@@ -1541,7 +1538,7 @@ case 72:
     ;
     break;}
 case 73:
-#line 613 "parser.y"
+#line 610 "parser.y"
 {
         yyval.selector = yyvsp[-1].selector;
         if (yyval.selector) {
@@ -1553,7 +1550,7 @@ case 73:
     ;
     break;}
 case 74:
-#line 625 "parser.y"
+#line 622 "parser.y"
 {
 	CSSParser *p = static_cast<CSSParser *>(parser);
 	DOM::DocumentImpl *doc = p->document();
@@ -1572,20 +1569,19 @@ case 74:
     ;
     break;}
 case 75:
-#line 641 "parser.y"
+#line 638 "parser.y"
 {
 	yyval.element = makeId(static_cast<CSSParser*>(parser)->defaultNamespace, anyLocalName);
     ;
     break;}
 case 76:
-#line 647 "parser.y"
+#line 644 "parser.y"
 {
 	yyval.selector = yyvsp[0].selector;
-	yyval.selector->nonCSSHint = static_cast<CSSParser *>(parser)->nonCSSHint;
     ;
     break;}
 case 77:
-#line 651 "parser.y"
+#line 647 "parser.y"
 {
 	yyval.selector = yyvsp[-1].selector;
         if (yyval.selector) {
@@ -1598,32 +1594,38 @@ case 77:
     ;
     break;}
 case 78:
-#line 661 "parser.y"
+#line 657 "parser.y"
 {
         delete yyvsp[-1].selector;
         yyval.selector = 0;
     ;
     break;}
 case 79:
-#line 668 "parser.y"
+#line 664 "parser.y"
 {
 	yyval.selector = new CSSSelector();
 	yyval.selector->match = CSSSelector::Id;
 	yyval.selector->attr = ATTR_ID;
+        CSSParser *p = static_cast<CSSParser *>(parser);
+        if (!p->strict)
+            yyvsp[0].string.lower();
 	yyval.selector->value = atomicString(yyvsp[0].string);
     ;
     break;}
 case 83:
-#line 680 "parser.y"
+#line 679 "parser.y"
 {
-	yyval.selector = new CSSSelector();
+        yyval.selector = new CSSSelector();
 	yyval.selector->match = CSSSelector::Class;
 	yyval.selector->attr = ATTR_CLASS;
+        CSSParser *p = static_cast<CSSParser *>(parser);
+        if (!p->strict)
+            yyvsp[0].string.lower();
 	yyval.selector->value = atomicString(yyvsp[0].string);
     ;
     break;}
 case 84:
-#line 689 "parser.y"
+#line 691 "parser.y"
 {
 	CSSParser *p = static_cast<CSSParser *>(parser);
 	DOM::DocumentImpl *doc = p->document();
@@ -1643,7 +1645,7 @@ case 84:
     ;
     break;}
 case 85:
-#line 709 "parser.y"
+#line 711 "parser.y"
 {
 	yyval.selector = new CSSSelector();
 	yyval.selector->attr = yyvsp[-1].attribute;
@@ -1651,7 +1653,7 @@ case 85:
     ;
     break;}
 case 86:
-#line 714 "parser.y"
+#line 716 "parser.y"
 {
 	yyval.selector = new CSSSelector();
 	yyval.selector->attr = yyvsp[-5].attribute;
@@ -1660,7 +1662,7 @@ case 86:
     ;
     break;}
 case 87:
-#line 720 "parser.y"
+#line 722 "parser.y"
 {
         yyval.selector = new CSSSelector();
         yyval.selector->attr = yyvsp[-1].attribute;
@@ -1671,7 +1673,7 @@ case 87:
     ;
     break;}
 case 88:
-#line 728 "parser.y"
+#line 730 "parser.y"
 {
         yyval.selector = new CSSSelector();
         yyval.selector->attr = yyvsp[-5].attribute;
@@ -1683,43 +1685,43 @@ case 88:
     ;
     break;}
 case 89:
-#line 740 "parser.y"
+#line 742 "parser.y"
 {
 	yyval.val = CSSSelector::Exact;
     ;
     break;}
 case 90:
-#line 743 "parser.y"
+#line 745 "parser.y"
 {
 	yyval.val = CSSSelector::List;
     ;
     break;}
 case 91:
-#line 746 "parser.y"
+#line 748 "parser.y"
 {
 	yyval.val = CSSSelector::Hyphen;
     ;
     break;}
 case 92:
-#line 749 "parser.y"
+#line 751 "parser.y"
 {
 	yyval.val = CSSSelector::Begin;
     ;
     break;}
 case 93:
-#line 752 "parser.y"
+#line 754 "parser.y"
 {
 	yyval.val = CSSSelector::End;
     ;
     break;}
 case 94:
-#line 755 "parser.y"
+#line 757 "parser.y"
 {
 	yyval.val = CSSSelector::Contain;
     ;
     break;}
 case 97:
-#line 766 "parser.y"
+#line 768 "parser.y"
 {
         yyval.selector = new CSSSelector();
         yyval.selector->match = CSSSelector::Pseudo;
@@ -1728,7 +1730,7 @@ case 97:
     ;
     break;}
 case 98:
-#line 773 "parser.y"
+#line 775 "parser.y"
 {
         yyval.selector = new CSSSelector();
         yyval.selector->match = CSSSelector::Pseudo;
@@ -1737,7 +1739,7 @@ case 98:
     ;
     break;}
 case 99:
-#line 779 "parser.y"
+#line 781 "parser.y"
 {
         yyval.selector = new CSSSelector();
         yyval.selector->match = CSSSelector::Pseudo;
@@ -1747,13 +1749,13 @@ case 99:
     ;
     break;}
 case 100:
-#line 789 "parser.y"
+#line 791 "parser.y"
 {
 	yyval.ok = yyvsp[0].ok;
     ;
     break;}
 case 101:
-#line 792 "parser.y"
+#line 794 "parser.y"
 {
 	yyval.ok = yyvsp[-1].ok;
 	if ( yyvsp[0].ok )
@@ -1761,13 +1763,13 @@ case 101:
     ;
     break;}
 case 102:
-#line 797 "parser.y"
+#line 799 "parser.y"
 {
 	yyval.ok = yyvsp[0].ok;
     ;
     break;}
 case 103:
-#line 800 "parser.y"
+#line 802 "parser.y"
 {
 	yyval.ok = false;
 #ifdef CSS_DEBUG
@@ -1776,7 +1778,7 @@ case 103:
     ;
     break;}
 case 104:
-#line 806 "parser.y"
+#line 808 "parser.y"
 {
 	yyval.ok = false;
 #ifdef CSS_DEBUG
@@ -1785,19 +1787,19 @@ case 104:
     ;
     break;}
 case 105:
-#line 815 "parser.y"
+#line 817 "parser.y"
 {
 	yyval.ok = yyvsp[-2].ok;
     ;
     break;}
 case 106:
-#line 818 "parser.y"
+#line 820 "parser.y"
 {
         yyval.ok = false;
     ;
     break;}
 case 107:
-#line 821 "parser.y"
+#line 823 "parser.y"
 {
 	yyval.ok = false;
 #ifdef CSS_DEBUG
@@ -1806,7 +1808,7 @@ case 107:
     ;
     break;}
 case 108:
-#line 827 "parser.y"
+#line 829 "parser.y"
 {
 	yyval.ok = false;
 #ifdef CSS_DEBUG
@@ -1815,7 +1817,7 @@ case 108:
     ;
     break;}
 case 109:
-#line 833 "parser.y"
+#line 835 "parser.y"
 {
 	yyval.ok = yyvsp[-3].ok;
 	if ( yyvsp[-2].ok )
@@ -1823,7 +1825,7 @@ case 109:
     ;
     break;}
 case 110:
-#line 838 "parser.y"
+#line 840 "parser.y"
 {
 	yyval.ok = yyvsp[-3].ok;
 #ifdef CSS_DEBUG
@@ -1832,7 +1834,7 @@ case 110:
     ;
     break;}
 case 111:
-#line 844 "parser.y"
+#line 846 "parser.y"
 {
 	yyval.ok = yyvsp[-5].ok;
 #ifdef CSS_DEBUG
@@ -1841,7 +1843,7 @@ case 111:
     ;
     break;}
 case 112:
-#line 853 "parser.y"
+#line 855 "parser.y"
 {
 	yyval.ok = false;
 	CSSParser *p = static_cast<CSSParser *>(parser);
@@ -1866,13 +1868,13 @@ case 112:
     ;
     break;}
 case 113:
-#line 876 "parser.y"
+#line 878 "parser.y"
 {
         yyval.ok = false;
     ;
     break;}
 case 114:
-#line 880 "parser.y"
+#line 882 "parser.y"
 {
         /* The default movable type template has letter-spacing: .none;  Handle this by looking for
         error tokens at the start of an expr, recover the expr and then treat as an error, cleaning
@@ -1882,43 +1884,43 @@ case 114:
     ;
     break;}
 case 115:
-#line 888 "parser.y"
+#line 890 "parser.y"
 {
         /* Handle this case: div { text-align: center; !important } Just reduce away the stray !important. */
         yyval.ok = false;
     ;
     break;}
 case 116:
-#line 893 "parser.y"
+#line 895 "parser.y"
 {
         /* div { font-family: } Just reduce away this property with no value. */
         yyval.ok = false;
     ;
     break;}
 case 117:
-#line 900 "parser.y"
+#line 902 "parser.y"
 {
 	QString str = qString(yyvsp[-1].string);
 	yyval.prop_id = getPropertyID( str.lower().latin1(), str.length() );
     ;
     break;}
 case 118:
-#line 907 "parser.y"
+#line 909 "parser.y"
 { yyval.b = true; ;
     break;}
 case 119:
-#line 908 "parser.y"
+#line 910 "parser.y"
 { yyval.b = false; ;
     break;}
 case 120:
-#line 912 "parser.y"
+#line 914 "parser.y"
 {
 	yyval.valueList = new ValueList;
 	yyval.valueList->addValue( yyvsp[0].value );
     ;
     break;}
 case 121:
-#line 916 "parser.y"
+#line 918 "parser.y"
 {
         yyval.valueList = yyvsp[-2].valueList;
 	if ( yyval.valueList ) {
@@ -1934,44 +1936,44 @@ case 121:
     ;
     break;}
 case 122:
-#line 929 "parser.y"
+#line 931 "parser.y"
 {
         delete yyvsp[-1].valueList;
         yyval.valueList = 0;
     ;
     break;}
 case 123:
-#line 936 "parser.y"
+#line 938 "parser.y"
 {
 	yyval.tok = '/';
     ;
     break;}
 case 124:
-#line 939 "parser.y"
+#line 941 "parser.y"
 {
 	yyval.tok = ',';
     ;
     break;}
 case 125:
-#line 942 "parser.y"
+#line 944 "parser.y"
 {
         yyval.tok = 0;
   ;
     break;}
 case 126:
-#line 948 "parser.y"
+#line 950 "parser.y"
 { yyval.value = yyvsp[0].value; ;
     break;}
 case 127:
-#line 949 "parser.y"
+#line 951 "parser.y"
 { yyval.value = yyvsp[0].value; yyval.value.fValue *= yyvsp[-1].val; ;
     break;}
 case 128:
-#line 950 "parser.y"
+#line 952 "parser.y"
 { yyval.value.id = 0; yyval.value.string = yyvsp[-1].string; yyval.value.unit = CSSPrimitiveValue::CSS_STRING; ;
     break;}
 case 129:
-#line 951 "parser.y"
+#line 953 "parser.y"
 {
       QString str = qString( yyvsp[-1].string );
       yyval.value.id = getValueID( str.lower().latin1(), str.length() );
@@ -1980,109 +1982,109 @@ case 129:
   ;
     break;}
 case 130:
-#line 958 "parser.y"
+#line 960 "parser.y"
 { yyval.value.id = 0; yyval.value.string = yyvsp[-1].string; yyval.value.unit = CSSPrimitiveValue::CSS_DIMENSION ;
     break;}
 case 131:
-#line 959 "parser.y"
+#line 961 "parser.y"
 { yyval.value.id = 0; yyval.value.string = yyvsp[-1].string; yyval.value.unit = CSSPrimitiveValue::CSS_DIMENSION ;
     break;}
 case 132:
-#line 960 "parser.y"
+#line 962 "parser.y"
 { yyval.value.id = 0; yyval.value.string = yyvsp[-1].string; yyval.value.unit = CSSPrimitiveValue::CSS_URI; ;
     break;}
 case 133:
-#line 961 "parser.y"
+#line 963 "parser.y"
 { yyval.value.id = 0; yyval.value.iValue = 0; yyval.value.unit = CSSPrimitiveValue::CSS_UNKNOWN;/* ### */ ;
     break;}
 case 134:
-#line 962 "parser.y"
+#line 964 "parser.y"
 { yyval.value.id = 0; yyval.value.string = yyvsp[0].string; yyval.value.unit = CSSPrimitiveValue::CSS_RGBCOLOR; ;
     break;}
 case 135:
-#line 963 "parser.y"
+#line 965 "parser.y"
 { yyval.value.id = 0; yyval.value.string = ParseString(); yyval.value.unit = CSSPrimitiveValue::CSS_RGBCOLOR; ;
     break;}
 case 136:
-#line 965 "parser.y"
+#line 967 "parser.y"
 {
       yyval.value = yyvsp[0].value;
   ;
     break;}
 case 137:
-#line 971 "parser.y"
+#line 973 "parser.y"
 { yyval.value.id = 0; yyval.value.fValue = yyvsp[-1].val; yyval.value.unit = CSSPrimitiveValue::CSS_NUMBER; ;
     break;}
 case 138:
-#line 972 "parser.y"
+#line 974 "parser.y"
 { yyval.value.id = 0; yyval.value.fValue = yyvsp[-1].val; yyval.value.unit = CSSPrimitiveValue::CSS_PERCENTAGE; ;
     break;}
 case 139:
-#line 973 "parser.y"
+#line 975 "parser.y"
 { yyval.value.id = 0; yyval.value.fValue = yyvsp[-1].val; yyval.value.unit = CSSPrimitiveValue::CSS_PX; ;
     break;}
 case 140:
-#line 974 "parser.y"
+#line 976 "parser.y"
 { yyval.value.id = 0; yyval.value.fValue = yyvsp[-1].val; yyval.value.unit = CSSPrimitiveValue::CSS_CM; ;
     break;}
 case 141:
-#line 975 "parser.y"
+#line 977 "parser.y"
 { yyval.value.id = 0; yyval.value.fValue = yyvsp[-1].val; yyval.value.unit = CSSPrimitiveValue::CSS_MM; ;
     break;}
 case 142:
-#line 976 "parser.y"
+#line 978 "parser.y"
 { yyval.value.id = 0; yyval.value.fValue = yyvsp[-1].val; yyval.value.unit = CSSPrimitiveValue::CSS_IN; ;
     break;}
 case 143:
-#line 977 "parser.y"
+#line 979 "parser.y"
 { yyval.value.id = 0; yyval.value.fValue = yyvsp[-1].val; yyval.value.unit = CSSPrimitiveValue::CSS_PT; ;
     break;}
 case 144:
-#line 978 "parser.y"
+#line 980 "parser.y"
 { yyval.value.id = 0; yyval.value.fValue = yyvsp[-1].val; yyval.value.unit = CSSPrimitiveValue::CSS_PC; ;
     break;}
 case 145:
-#line 979 "parser.y"
+#line 981 "parser.y"
 { yyval.value.id = 0; yyval.value.fValue = yyvsp[-1].val; yyval.value.unit = CSSPrimitiveValue::CSS_DEG; ;
     break;}
 case 146:
-#line 980 "parser.y"
+#line 982 "parser.y"
 { yyval.value.id = 0; yyval.value.fValue = yyvsp[-1].val; yyval.value.unit = CSSPrimitiveValue::CSS_RAD; ;
     break;}
 case 147:
-#line 981 "parser.y"
+#line 983 "parser.y"
 { yyval.value.id = 0; yyval.value.fValue = yyvsp[-1].val; yyval.value.unit = CSSPrimitiveValue::CSS_GRAD; ;
     break;}
 case 148:
-#line 982 "parser.y"
+#line 984 "parser.y"
 { yyval.value.id = 0; yyval.value.fValue = yyvsp[-1].val; yyval.value.unit = CSSPrimitiveValue::CSS_MS; ;
     break;}
 case 149:
-#line 983 "parser.y"
+#line 985 "parser.y"
 { yyval.value.id = 0; yyval.value.fValue = yyvsp[-1].val; yyval.value.unit = CSSPrimitiveValue::CSS_S; ;
     break;}
 case 150:
-#line 984 "parser.y"
+#line 986 "parser.y"
 { yyval.value.id = 0; yyval.value.fValue = yyvsp[-1].val; yyval.value.unit = CSSPrimitiveValue::CSS_HZ; ;
     break;}
 case 151:
-#line 985 "parser.y"
+#line 987 "parser.y"
 { yyval.value.id = 0; yyval.value.fValue = yyvsp[-1].val; yyval.value.unit = CSSPrimitiveValue::CSS_KHZ; ;
     break;}
 case 152:
-#line 986 "parser.y"
+#line 988 "parser.y"
 { yyval.value.id = 0; yyval.value.fValue = yyvsp[-1].val; yyval.value.unit = CSSPrimitiveValue::CSS_EMS; ;
     break;}
 case 153:
-#line 987 "parser.y"
+#line 989 "parser.y"
 { yyval.value.id = 0; yyval.value.fValue = yyvsp[-1].val; yyval.value.unit = Value::Q_EMS; ;
     break;}
 case 154:
-#line 988 "parser.y"
+#line 990 "parser.y"
 { yyval.value.id = 0; yyval.value.fValue = yyvsp[-1].val; yyval.value.unit = CSSPrimitiveValue::CSS_EXS; ;
     break;}
 case 155:
-#line 993 "parser.y"
+#line 995 "parser.y"
 {
       Function *f = new Function;
       f->name = yyvsp[-4].string;
@@ -2093,7 +2095,7 @@ case 155:
   ;
     break;}
 case 156:
-#line 1001 "parser.y"
+#line 1003 "parser.y"
 {
       Function *f = new Function;
       f->name = yyvsp[-2].string;
@@ -2104,11 +2106,11 @@ case 156:
   ;
     break;}
 case 157:
-#line 1016 "parser.y"
+#line 1018 "parser.y"
 { yyval.string = yyvsp[-1].string; ;
     break;}
 case 158:
-#line 1023 "parser.y"
+#line 1025 "parser.y"
 {
 	yyval.rule = 0;
 #ifdef CSS_DEBUG
@@ -2117,7 +2119,7 @@ case 158:
     ;
     break;}
 case 159:
-#line 1029 "parser.y"
+#line 1031 "parser.y"
 {
 	yyval.rule = 0;
 #ifdef CSS_DEBUG
@@ -2126,7 +2128,7 @@ case 159:
     ;
     break;}
 case 160:
-#line 1038 "parser.y"
+#line 1040 "parser.y"
 {
 	yyval.rule = 0;
 #ifdef CSS_DEBUG
@@ -2356,6 +2358,6 @@ yyerrhandle:
     }
   return 1;
 }
-#line 1073 "parser.y"
+#line 1075 "parser.y"
 
 
diff --git a/WebCore/khtml/css/parser.h b/WebCore/khtml/css/parser.h
index b059407..3393fab 100644
--- a/WebCore/khtml/css/parser.h
+++ b/WebCore/khtml/css/parser.h
@@ -1,7 +1,6 @@
 typedef union {
     CSSRuleImpl *rule;
     CSSSelector *selector;
-    QPtrList<CSSSelector> *selectorList;
     bool ok;
     MediaListImpl *mediaList;
     CSSMediaRuleImpl *mediaRule;
diff --git a/WebCore/khtml/css/parser.y b/WebCore/khtml/css/parser.y
index 35b1f56..542a56e 100644
--- a/WebCore/khtml/css/parser.y
+++ b/WebCore/khtml/css/parser.y
@@ -86,7 +86,6 @@ static inline int getValueID(const char *tagStr, int len)
 %union {
     CSSRuleImpl *rule;
     CSSSelector *selector;
-    QPtrList<CSSSelector> *selectorList;
     bool ok;
     MediaListImpl *mediaList;
     CSSMediaRuleImpl *mediaRule;
@@ -208,7 +207,7 @@ static int cssyylex( YYSTYPE *yylval ) {
 %type <selector> specifier_list
 %type <selector> simple_selector
 %type <selector> selector
-%type <selectorList> selector_list
+%type <selector> selector_list
 %type <selector> class
 %type <selector> attrib
 %type <selector> pseudo
@@ -493,11 +492,11 @@ ruleset:
 #endif
 	CSSParser *p = static_cast<CSSParser *>(parser);
 	if ( $1 && $4 && p->numParsedProperties ) {
-	    CSSStyleRuleImpl *rule = new CSSStyleRuleImpl( p->styleElement );
-	    CSSStyleDeclarationImpl *decl = p->createStyleDeclaration( rule );
-	    rule->setSelector( $1 );
-	    rule->setDeclaration(decl);
-	    $$ = rule;
+            CSSStyleRuleImpl *rule = new CSSStyleRuleImpl( p->styleElement );
+            CSSStyleDeclarationImpl *decl = p->createStyleDeclaration( rule );
+            rule->setSelector( $1 );
+            rule->setDeclaration(decl);
+            $$ = rule;
 	} else {
 	    $$ = 0;
 	    delete $1;
@@ -509,13 +508,11 @@ ruleset:
 selector_list:
     selector {
 	if ( $1 ) {
-	    $$ = new QPtrList<CSSSelector>;
-            $$->setAutoDelete( true );
+	    $$ = $1;
 #ifdef CSS_DEBUG
 	    kdDebug( 6080 ) << "   got simple selector:" << endl;
 	    $1->print();
 #endif
-	    $$->append( $1 );
 	} else {
 	    $$ = 0;
 	}
@@ -646,7 +643,6 @@ element_name:
 specifier_list:
     specifier {
 	$$ = $1;
-	$$->nonCSSHint = static_cast<CSSParser *>(parser)->nonCSSHint;
     }
     | specifier_list specifier {
 	$$ = $1;
@@ -669,6 +665,9 @@ specifier:
 	$$ = new CSSSelector();
 	$$->match = CSSSelector::Id;
 	$$->attr = ATTR_ID;
+        CSSParser *p = static_cast<CSSParser *>(parser);
+        if (!p->strict)
+            $1.lower();
 	$$->value = atomicString($1);
     }
   | class
@@ -678,9 +677,12 @@ specifier:
 
 class:
     '.' IDENT {
-	$$ = new CSSSelector();
+        $$ = new CSSSelector();
 	$$->match = CSSSelector::Class;
 	$$->attr = ATTR_CLASS;
+        CSSParser *p = static_cast<CSSParser *>(parser);
+        if (!p->strict)
+            $2.lower();
 	$$->value = atomicString($2);
     }
   ;
diff --git a/WebCore/khtml/dom/dom_element.cpp b/WebCore/khtml/dom/dom_element.cpp
index 890ee78..d061287 100644
--- a/WebCore/khtml/dom/dom_element.cpp
+++ b/WebCore/khtml/dom/dom_element.cpp
@@ -293,7 +293,7 @@ bool Element::isHTMLElement() const
 
 CSSStyleDeclaration Element::style()
 {
-    if (impl) return ((ElementImpl *)impl)->styleRules();
+    if (impl) return ((ElementImpl *)impl)->getInlineStyleDecl();
     return 0;
 }
 
diff --git a/WebCore/khtml/html/html_baseimpl.cpp b/WebCore/khtml/html/html_baseimpl.cpp
index 7b121d0..98093eb 100644
--- a/WebCore/khtml/html/html_baseimpl.cpp
+++ b/WebCore/khtml/html/html_baseimpl.cpp
@@ -50,14 +50,14 @@ using namespace khtml;
 
 HTMLBodyElementImpl::HTMLBodyElementImpl(DocumentPtr *doc)
     : HTMLElementImpl(doc),
-    m_bgSet( false ), m_fgSet( false )
+    m_bgSet( false ), m_fgSet( false ), m_linkDecl(0)
 {
-    m_styleSheet = 0;
 }
 
 HTMLBodyElementImpl::~HTMLBodyElementImpl()
 {
-    if(m_styleSheet) m_styleSheet->deref();
+    if (m_linkDecl)
+        m_linkDecl->deref();
 }
 
 NodeImpl::Id HTMLBodyElementImpl::id() const
@@ -65,6 +65,16 @@ NodeImpl::Id HTMLBodyElementImpl::id() const
     return ID_BODY;
 }
 
+void HTMLBodyElementImpl::createLinkDecl()
+{
+    m_linkDecl = new CSSStyleDeclarationImpl(0);
+    m_linkDecl->ref();
+    m_linkDecl->setParent(getDocument()->elementSheet());
+    m_linkDecl->parent()->ref();
+    m_linkDecl->setNode(this);
+    m_linkDecl->setStrictParsing(!getDocument()->inCompatMode());
+}
+
 void HTMLBodyElementImpl::parseAttribute(AttributeImpl *attr)
 {
     switch(attr->id())
@@ -111,22 +121,32 @@ void HTMLBodyElementImpl::parseAttribute(AttributeImpl *attr)
     case ATTR_ALINK:
     case ATTR_LINK:
     {
-        if(!m_styleSheet) {
-            m_styleSheet = new CSSStyleSheetImpl(this,DOMString(),true);
-            m_styleSheet->ref();
+        if (attr->isNull()) {
+            if (attr->id() == ATTR_LINK)
+                getDocument()->resetLinkColor();
+            else if (attr->id() == ATTR_VLINK)
+                getDocument()->resetVisitedLinkColor();
+            else
+                getDocument()->resetActiveLinkColor();
+        }
+        else {
+            if (!m_linkDecl)
+                createLinkDecl();
+            m_linkDecl->setProperty(CSS_PROP_COLOR, attr->value(), false, false);
+            CSSValueImpl* val = m_linkDecl->getPropertyCSSValue(CSS_PROP_COLOR);
+            if (val && val->isPrimitiveValue()) {
+                QColor col = getDocument()->styleSelector()->getColorFromPrimitiveValue(static_cast<CSSPrimitiveValueImpl*>(val));
+                if (attr->id() == ATTR_LINK)
+                    getDocument()->setLinkColor(col);
+                else if (attr->id() == ATTR_VLINK)
+                    getDocument()->setVisitedLinkColor(col);
+                else
+                    getDocument()->setActiveLinkColor(col);
+            }
         }
-        QString aStr;
-	if ( attr->id() == ATTR_LINK )
-	    aStr = "a:link";
-	else if ( attr->id() == ATTR_VLINK )
-	    aStr = "a:visited";
-	else if ( attr->id() == ATTR_ALINK )
-            aStr = "a:link:active, a:visited:active";
-	aStr += " { color: " + attr->value().string() + "; }";
-        m_styleSheet->parseString(aStr, !getDocument()->inCompatMode());
-        m_styleSheet->setNonCSSHints();
+        
         if (attached())
-            getDocument()->updateStyleSelector();
+            getDocument()->recalcStyle(Force);
         break;
     }
     case ATTR_ONLOAD:
diff --git a/WebCore/khtml/html/html_baseimpl.h b/WebCore/khtml/html/html_baseimpl.h
index 3ad3805..ffb2f4b 100644
--- a/WebCore/khtml/html/html_baseimpl.h
+++ b/WebCore/khtml/html/html_baseimpl.h
@@ -58,13 +58,13 @@ public:
 
     virtual void parseAttribute(AttributeImpl *);
     virtual void insertedIntoDocument();
-    
-    CSSStyleSheetImpl *sheet() const { return m_styleSheet; }
+
+    void createLinkDecl();
 
 protected:
-    CSSStyleSheetImpl *m_styleSheet;
     bool m_bgSet;
     bool m_fgSet;
+    CSSStyleDeclarationImpl* m_linkDecl;
 };
 
 // -------------------------------------------------------------------------
diff --git a/WebCore/khtml/html/html_elementimpl.cpp b/WebCore/khtml/html/html_elementimpl.cpp
index a3d0d07..04b406d 100644
--- a/WebCore/khtml/html/html_elementimpl.cpp
+++ b/WebCore/khtml/html/html_elementimpl.cpp
@@ -45,6 +45,7 @@
 #include "css/css_stylesheetimpl.h"
 #include "css/cssproperties.h"
 #include "css/cssvalues.h"
+#include "css/css_ruleimpl.h"
 #include "xml/dom_textimpl.h"
 #include "xml/dom2_eventsimpl.h"
 
@@ -67,12 +68,16 @@ bool HTMLNamedAttrMapImpl::isHTMLAttributeMap() const
     return true;
 }
 
-void HTMLNamedAttrMapImpl::parseClassAttribute(const DOMString& classAttr)
+void HTMLNamedAttrMapImpl::parseClassAttribute(const DOMString& classStr)
 {
     m_classList.clear();
     if (!element->hasClass())
         return;
     
+    DOMString classAttr = element->getDocument()->inCompatMode() ? 
+        (classStr.implementation()->isLower() ? classStr : DOMString(classStr.implementation()->lower())) :
+        classStr;
+    
     if (classAttr.find(' ') == -1)
         m_classList.setString(AtomicString(classAttr));
     else {
@@ -97,30 +102,21 @@ void HTMLNamedAttrMapImpl::parseClassAttribute(const DOMString& classAttr)
     }
 }
 
-bool HTMLNamedAttrMapImpl::matchesCSSClass(const AtomicString& c, bool caseSensitive) const
-{
-    for (const AtomicStringList* curr = &m_classList; curr; curr = curr->next()) {
-        if (caseSensitive) {
-            if (c == curr->string())
-                return true;
-        }
-        else {
-            if (equalsIgnoreCase(c, curr->string()))
-                return true;
-        }
-    }
-    return false;
-}
-
 // ------------------------------------------------------------------
 
 HTMLElementImpl::HTMLElementImpl(DocumentPtr *doc)
     : ElementImpl(doc)
 {
+    m_inlineStyleDecl = 0;
+    m_attributeStyleDecl = 0;    
 }
 
 HTMLElementImpl::~HTMLElementImpl()
 {
+    if (m_inlineStyleDecl)
+        m_inlineStyleDecl->deref();
+    if (m_attributeStyleDecl)
+        m_attributeStyleDecl->deref();
 }
 
 bool HTMLElementImpl::isInline() const
@@ -165,6 +161,26 @@ bool HTMLElementImpl::isInline() const
     }
 }
 
+void HTMLElementImpl::createInlineStyleDecl()
+{
+    m_inlineStyleDecl = new CSSStyleDeclarationImpl(0);
+    m_inlineStyleDecl->ref();
+    m_inlineStyleDecl->setParent(getDocument()->elementSheet());
+    m_inlineStyleDecl->parent()->ref();
+    m_inlineStyleDecl->setNode(this);
+    m_inlineStyleDecl->setStrictParsing(!getDocument()->inCompatMode());
+}
+
+void HTMLElementImpl::createMappedAttributeDecl()
+{
+    m_attributeStyleDecl = new CSSStyleDeclarationImpl(0);
+    m_attributeStyleDecl->ref();
+    m_attributeStyleDecl->setParent(getDocument()->elementSheet());
+    m_attributeStyleDecl->parent()->ref();
+    m_attributeStyleDecl->setNode(this);
+    m_attributeStyleDecl->setStrictParsing(!getDocument()->inCompatMode());
+}
+
 void HTMLElementImpl::parseAttribute(AttributeImpl *attr)
 {
     DOMString indexstring;
@@ -184,6 +200,14 @@ void HTMLElementImpl::parseAttribute(AttributeImpl *attr)
     case ATTR_ID:
         // unique id
         setHasID(!attr->isNull());
+        if (namedAttrMap) {
+            if (attr->isNull())
+                namedAttrMap->setID(nullAtom);
+            else if (getDocument()->inCompatMode() && !attr->value().implementation()->isLower())
+                namedAttrMap->setID(AtomicString(attr->value().implementation()->lower()));
+            else
+                namedAttrMap->setID(attr->value());
+        }
         setChanged();
         break;
     case ATTR_CLASS:
@@ -203,8 +227,8 @@ void HTMLElementImpl::parseAttribute(AttributeImpl *attr)
         // ### the inline sheet ay contain more than 1 property!
         // stylesheet info
         setHasStyle();
-        if(!m_styleDecls) createDecl();
-        m_styleDecls->setProperty(attr->value());
+        if (!m_inlineStyleDecl) createInlineStyleDecl();
+        m_inlineStyleDecl->setProperty(attr->value());
         setChanged();
         break;
     case ATTR_TABINDEX:
@@ -284,36 +308,53 @@ void HTMLElementImpl::createAttributeMap() const
     namedAttrMap->ref();
 }
 
-bool HTMLElementImpl::matchesCSSClass(const AtomicString& c, bool cs) const
+CSSStyleDeclarationImpl* HTMLElementImpl::inlineStyleDecl() const
+{ 
+    return m_inlineStyleDecl;
+}
+
+CSSStyleDeclarationImpl* HTMLElementImpl::attributeStyleDecl() const
+{
+    return m_attributeStyleDecl;
+}
+
+CSSStyleDeclarationImpl* HTMLElementImpl::getInlineStyleDecl()
+{
+    if (!m_inlineStyleDecl)
+        createInlineStyleDecl();
+    return m_inlineStyleDecl;
+}
+
+const AtomicStringList* HTMLElementImpl::getClassList() const
 {
-    return namedAttrMap ? static_cast<HTMLNamedAttrMapImpl*>(namedAttrMap)->matchesCSSClass(c, cs) : false;
+    return namedAttrMap ? static_cast<HTMLNamedAttrMapImpl*>(namedAttrMap)->getClassList() : 0;
 }
 
 void HTMLElementImpl::addCSSProperty(int id, const DOMString &value)
 {
-    if(!m_styleDecls) createDecl();
-    m_styleDecls->setProperty(id, value, false, true);
+    if (!m_attributeStyleDecl) createMappedAttributeDecl();
+    m_attributeStyleDecl->setProperty(id, value, false);
     setChanged();
 }
 
 void HTMLElementImpl::addCSSProperty(int id, int value)
 {
-    if(!m_styleDecls) createDecl();
-    m_styleDecls->setProperty(id, value, false, true);
+    if (!m_attributeStyleDecl) createMappedAttributeDecl();
+    m_attributeStyleDecl->setProperty(id, value, false);
     setChanged();
 }
 
 void HTMLElementImpl::addCSSStringProperty(int id, const DOMString &value, CSSPrimitiveValue::UnitTypes type)
 {
-    if(!m_styleDecls) createDecl();
-    m_styleDecls->setStringProperty(id, value, type, false, true);
+    if (!m_attributeStyleDecl) createMappedAttributeDecl();
+    m_attributeStyleDecl->setStringProperty(id, value, type, false);
     setChanged();
 }
 
 void HTMLElementImpl::addCSSImageProperty(int id, const DOMString &URL)
 {
-    if(!m_styleDecls) createDecl();
-    m_styleDecls->setImageProperty(id, URL, false, true);
+    if (!m_attributeStyleDecl) createMappedAttributeDecl();
+    m_attributeStyleDecl->setImageProperty(id, URL, false);
     setChanged();
 }
 
@@ -321,7 +362,7 @@ void HTMLElementImpl::addCSSLength(int id, const DOMString &value)
 {
     // FIXME: This function should not spin up the CSS parser, but should instead just figure out the correct
     // length unit and make the appropriate parsed value.
-    if(!m_styleDecls) createDecl();
+    if (!m_attributeStyleDecl) createMappedAttributeDecl();
 
     // strip attribute garbage..
     DOMStringImpl* v = value.implementation();
@@ -336,13 +377,13 @@ void HTMLElementImpl::addCSSLength(int id, const DOMString &value)
                 break;
         }
         if ( l != v->l ) {
-            m_styleDecls->setLengthProperty( id, DOMString( v->s, l ), false, true );
+            m_attributeStyleDecl->setLengthProperty(id, DOMString( v->s, l ), false);
             setChanged();
             return;
         }
     }
 
-    m_styleDecls->setLengthProperty(id, value, false, true);
+    m_attributeStyleDecl->setLengthProperty(id, value, false);
     setChanged();
 }
 
@@ -365,13 +406,13 @@ static inline int toHex( const QChar &c ) {
 /* color parsing that tries to match as close as possible IE 6. */
 void HTMLElementImpl::addHTMLColor( int id, const DOMString &c )
 {
-    if(!m_styleDecls) createDecl();
+    if (!m_attributeStyleDecl) createMappedAttributeDecl();
 
     // this is the only case no color gets applied in IE.
     if ( !c.length() )
         return;
 
-    if ( m_styleDecls->setProperty(id, c, false, true) )
+    if ( m_attributeStyleDecl->setProperty(id, c, false) )
         return;
 
     QString color = c.string();
@@ -434,21 +475,21 @@ void HTMLElementImpl::addHTMLColor( int id, const DOMString &c )
 
             color.sprintf("#%02x%02x%02x", colors[0], colors[1], colors[2] );
             // 	    qDebug( "trying to add fixed color string '%s'", color.latin1() );
-            if ( m_styleDecls->setProperty(id, DOMString(color), false, true) )
+            if ( m_attributeStyleDecl->setProperty(id, DOMString(color), false) )
                 return;
         }
     }
-    m_styleDecls->setProperty(id, CSS_VAL_BLACK, false, true);
+    m_attributeStyleDecl->setProperty(id, CSS_VAL_BLACK, false);
 }
 
 void HTMLElementImpl::removeCSSProperty(int id)
 {
-    if(!m_styleDecls)
+    if(!m_attributeStyleDecl)
         return;
-    m_styleDecls->parent()->deref();
-    m_styleDecls->setParent(getDocument()->elementSheet());
-    m_styleDecls->parent()->ref();
-    m_styleDecls->removeProperty(id);
+    m_attributeStyleDecl->parent()->deref();
+    m_attributeStyleDecl->setParent(getDocument()->elementSheet());
+    m_attributeStyleDecl->parent()->ref();
+    m_attributeStyleDecl->removeProperty(id);
     setChanged();
 }
 
diff --git a/WebCore/khtml/html/html_elementimpl.h b/WebCore/khtml/html/html_elementimpl.h
index 9c35b2a..efaa98e 100644
--- a/WebCore/khtml/html/html_elementimpl.h
+++ b/WebCore/khtml/html/html_elementimpl.h
@@ -43,7 +43,7 @@ public:
     virtual bool isHTMLAttributeMap() const;
     
     virtual void parseClassAttribute(const DOMString& classAttr);
-    bool matchesCSSClass(const AtomicString& c, bool caseSensitive) const;
+    const AtomicStringList* getClassList() const { return &m_classList; }
     
 private:
     AtomicStringList m_classList;
@@ -65,7 +65,7 @@ public:
     virtual void parseAttribute(AttributeImpl *token);
     virtual void createAttributeMap() const;
 
-    virtual bool matchesCSSClass(const AtomicString& c, bool caseSensitive) const;
+     virtual const AtomicStringList* getClassList() const;
 
     void addCSSLength(int id, const DOMString &value); // FIXME: value will be parsed by the CSS parser
     void addCSSProperty(int id, const DOMString &value); // value will be parsed by the CSS parser
@@ -90,6 +90,12 @@ public:
 
     virtual void click();
     
+    virtual CSSStyleDeclarationImpl* inlineStyleDecl() const;
+    virtual CSSStyleDeclarationImpl* attributeStyleDecl() const;
+    virtual CSSStyleDeclarationImpl* getInlineStyleDecl();
+    void createInlineStyleDecl();
+    void createMappedAttributeDecl();
+    
 #if APPLE_CHANGES
     virtual bool isGenericFormElement() const { return false; }
 #endif
@@ -99,6 +105,9 @@ public:
 protected:
     // for IMG, OBJECT and APPLET
     void addHTMLAlignment( const DOMString& alignment );
+    
+    CSSStyleDeclarationImpl* m_inlineStyleDecl;
+    CSSStyleDeclarationImpl* m_attributeStyleDecl;
 };
 
 class HTMLGenericElementImpl : public HTMLElementImpl
diff --git a/WebCore/khtml/html/html_tableimpl.cpp b/WebCore/khtml/html/html_tableimpl.cpp
index 920b623..ae951dc 100644
--- a/WebCore/khtml/html/html_tableimpl.cpp
+++ b/WebCore/khtml/html/html_tableimpl.cpp
@@ -94,15 +94,15 @@ DOM::CSSStyleDeclarationImpl* HTMLTableElementImpl::createSharedCellDecls()
         m_sharedCellDecls->setStrictParsing( !getDocument()->inCompatMode() );
 
         if (m_noBorder)
-            m_sharedCellDecls->setProperty(CSS_PROP_BORDER_WIDTH, "0", false, true);
+            m_sharedCellDecls->setProperty(CSS_PROP_BORDER_WIDTH, "0", false);
         else {
-            m_sharedCellDecls->setProperty(CSS_PROP_BORDER_WIDTH, "1px", false, true);
+            m_sharedCellDecls->setProperty(CSS_PROP_BORDER_WIDTH, "1px", false);
             int v = m_solid ? CSS_VAL_SOLID : CSS_VAL_INSET;
-            m_sharedCellDecls->setProperty(CSS_PROP_BORDER_TOP_STYLE, v, false, true);
-            m_sharedCellDecls->setProperty(CSS_PROP_BORDER_BOTTOM_STYLE, v, false, true);
-            m_sharedCellDecls->setProperty(CSS_PROP_BORDER_LEFT_STYLE, v, false, true);
-            m_sharedCellDecls->setProperty(CSS_PROP_BORDER_RIGHT_STYLE, v, false, true);
-            m_sharedCellDecls->setProperty(CSS_PROP_BORDER_COLOR, "inherit", false, true);
+            m_sharedCellDecls->setProperty(CSS_PROP_BORDER_TOP_STYLE, v, false);
+            m_sharedCellDecls->setProperty(CSS_PROP_BORDER_BOTTOM_STYLE, v, false);
+            m_sharedCellDecls->setProperty(CSS_PROP_BORDER_LEFT_STYLE, v, false);
+            m_sharedCellDecls->setProperty(CSS_PROP_BORDER_RIGHT_STYLE, v, false);
+            m_sharedCellDecls->setProperty(CSS_PROP_BORDER_COLOR, "inherit", false);
         }
     }
     
@@ -890,7 +890,7 @@ void HTMLTableCellElementImpl::parseAttribute(AttributeImpl *attr)
 }
 
 // used by table cells to share style decls created by the enclosing table.
-DOM::CSSStyleDeclarationImpl* HTMLTableCellElementImpl::getAdditionalStyleDecls()
+CSSStyleDeclarationImpl* HTMLTableCellElementImpl::additionalAttributeStyleDecl()
 {
     HTMLElementImpl* p = static_cast<HTMLElementImpl*>(parentNode());
     while(p && p->id() != ID_TABLE)
diff --git a/WebCore/khtml/html/html_tableimpl.h b/WebCore/khtml/html/html_tableimpl.h
index b7ff741..813134f 100644
--- a/WebCore/khtml/html/html_tableimpl.h
+++ b/WebCore/khtml/html/html_tableimpl.h
@@ -203,7 +203,7 @@ public:
     virtual void attach();
 
     // used by table cells to share style decls created by the enclosing table.
-    virtual DOM::CSSStyleDeclarationImpl* getAdditionalStyleDecls();
+    virtual CSSStyleDeclarationImpl* additionalAttributeStyleDecl();
     
 protected:
     int _row;
diff --git a/WebCore/khtml/xml/dom_atomicstring.cpp b/WebCore/khtml/xml/dom_atomicstring.cpp
index 45b756f..8b1faf7 100644
--- a/WebCore/khtml/xml/dom_atomicstring.cpp
+++ b/WebCore/khtml/xml/dom_atomicstring.cpp
@@ -134,6 +134,7 @@ DOMStringImpl *AtomicString::add(const char *c)
     
     DOMStringImpl *r = new DOMStringImpl(c, length);
     r->_hash = hash;
+    r->_inTable = true;
     
     _table[i] = r;
     ++_keyCount;
@@ -170,6 +171,7 @@ DOMStringImpl *AtomicString::add(const QChar *s, int length)
     
     DOMStringImpl *r = new DOMStringImpl(s, length);
     r->_hash = hash;
+    r->_inTable = true;
     
     _table[i] = r;
     ++_keyCount;
@@ -182,8 +184,8 @@ DOMStringImpl *AtomicString::add(const QChar *s, int length)
 
 DOMStringImpl *AtomicString::add(DOMStringImpl *r)
 {
-    if (!r)
-        return 0;
+    if (!r || r->_inTable)
+        return r;
 
     if (r->l == 0)
         return DOMStringImpl::empty();
@@ -199,11 +201,13 @@ DOMStringImpl *AtomicString::add(DOMStringImpl *r)
     numCollisions += _table[i] && !equal(_table[i], r);
 #endif
     while (DOMStringImpl *key = _table[i]) {
-        if (equal(key, r))
+        if (equal(key, r)) {
             return key;
+        }
         i = (i + 1) & _tableSizeMask;
     }
 
+    r->_inTable = true;
     _table[i] = r;
     ++_keyCount;
     
@@ -230,7 +234,7 @@ inline void AtomicString::insert(DOMStringImpl *key)
 
 void AtomicString::remove(DOMStringImpl *r)
 {
-    unsigned hash = r->hash();
+    unsigned hash = r->_hash;
     
     DOMStringImpl *key;
     
@@ -240,7 +244,7 @@ void AtomicString::remove(DOMStringImpl *r)
     numCollisions += _table[i] && equal(_table[i], r);
 #endif
     while ((key = _table[i])) {
-        if (equal(key, r))
+        if (key == r)
             break;
         i = (i + 1) & _tableSizeMask;
     }
diff --git a/WebCore/khtml/xml/dom_docimpl.cpp b/WebCore/khtml/xml/dom_docimpl.cpp
index 3dcd01e..100cb3f 100644
--- a/WebCore/khtml/xml/dom_docimpl.cpp
+++ b/WebCore/khtml/xml/dom_docimpl.cpp
@@ -315,6 +315,10 @@ DocumentImpl::DocumentImpl(DOMImplementationImpl *_implementation, KHTMLView *v)
     m_cssTarget = 0;
     m_accessKeyDictValid = false;
     
+    resetLinkColor();
+    resetVisitedLinkColor();
+    resetActiveLinkColor();
+
     m_processingLoadEvent = false;
     m_startTime.restart();
 }
@@ -383,6 +387,20 @@ DocumentImpl::~DocumentImpl()
     }
 }
 
+void DocumentImpl::resetLinkColor()
+{
+    m_linkColor = QColor(0, 0, 238);
+}
+
+void DocumentImpl::resetVisitedLinkColor()
+{
+    m_visitedLinkColor = QColor(85, 26, 139);    
+}
+
+void DocumentImpl::resetActiveLinkColor()
+{
+    m_activeLinkColor.setNamedColor(QString("red"));
+}
 
 DocumentTypeImpl *DocumentImpl::doctype() const
 {
@@ -2201,12 +2219,7 @@ void DocumentImpl::recalcStyleSelector()
                     sheet = 0;
             }
         }
-        else if (n->isHTMLElement() && n->id() == ID_BODY) {
-                // <BODY> element (doesn't contain styles as such but vlink="..." and friends
-                // are treated as style declarations)
-            sheet = static_cast<HTMLBodyElementImpl*>(n)->sheet();
-        }
-            
+
         if (sheet) {
             sheet->ref();
             m_styleSheets->styleSheets.append(sheet);
diff --git a/WebCore/khtml/xml/dom_docimpl.h b/WebCore/khtml/xml/dom_docimpl.h
index 77886a6..ab91dbc 100644
--- a/WebCore/khtml/xml/dom_docimpl.h
+++ b/WebCore/khtml/xml/dom_docimpl.h
@@ -61,7 +61,6 @@ class KWQAccObjectCache;
 namespace khtml {
     class CSSStyleSelector;
     class DocLoader;
-    class CSSStyleSelectorList;
     class RenderImage;
     class EditCommand;
 }
@@ -340,6 +339,16 @@ public:
     void setTextColor( QColor color ) { m_textColor = color; }
     QColor textColor() const { return m_textColor; }
 
+    const QColor& linkColor() const { return m_linkColor; }
+    const QColor& visitedLinkColor() const { return m_visitedLinkColor; }
+    const QColor& activeLinkColor() const { return m_activeLinkColor; }
+    void setLinkColor(const QColor& c) { m_linkColor = c; }
+    void setVisitedLinkColor(const QColor& c) { m_visitedLinkColor = c; }
+    void setActiveLinkColor(const QColor& c) { m_activeLinkColor = c; }
+    void resetLinkColor();
+    void resetVisitedLinkColor();
+    void resetActiveLinkColor();
+    
     // internal
     NodeImpl *findElement( Id id );
 
@@ -559,6 +568,10 @@ protected:
     QPtrList<RegisteredEventListener> m_windowEventListeners;
     QPtrList<NodeImpl> m_maintainsState;
 
+    QColor m_linkColor;
+    QColor m_visitedLinkColor;
+    QColor m_activeLinkColor;
+
     DOMString m_preferredStylesheetSet;
 
     bool m_loadingSheet;
diff --git a/WebCore/khtml/xml/dom_elementimpl.cpp b/WebCore/khtml/xml/dom_elementimpl.cpp
index f7cd0ff..a3b06c7 100644
--- a/WebCore/khtml/xml/dom_elementimpl.cpp
+++ b/WebCore/khtml/xml/dom_elementimpl.cpp
@@ -186,24 +186,16 @@ ElementImpl::ElementImpl(DocumentPtr *doc)
     : NodeBaseImpl(doc)
 {
     namedAttrMap = 0;
-    m_styleDecls = 0;
     m_prefix = 0;
 }
 
 ElementImpl::~ElementImpl()
 {
-    if(namedAttrMap) {
+    if (namedAttrMap) {
         namedAttrMap->detachFromElement();
         namedAttrMap->deref();
     }
 
-    if (m_styleDecls) {
-        m_styleDecls->setNode(0);
-        m_styleDecls->parent()->deref();
-        m_styleDecls->setParent(0);
-        m_styleDecls->deref();
-    }
-
     if (m_prefix)
         m_prefix->deref();
 }
@@ -229,11 +221,34 @@ unsigned short ElementImpl::nodeType() const
     return Node::ELEMENT_NODE;
 }
 
-bool ElementImpl::matchesCSSClass(const AtomicString& c, bool caseSensitive) const
+CSSStyleDeclarationImpl* ElementImpl::inlineStyleDecl() const
 {
-    // Class is not supported on random XML elements.  A language (e.g., HTML, SVG) should indicate
-    // support using a subclass override.
-    return false;
+    return 0;
+}
+
+CSSStyleDeclarationImpl* ElementImpl::attributeStyleDecl() const
+{
+    return 0;
+}
+
+CSSStyleDeclarationImpl* ElementImpl::getInlineStyleDecl()
+{
+    return 0;
+}
+
+CSSStyleDeclarationImpl* ElementImpl::additionalAttributeStyleDecl()
+{
+    return 0;
+}
+
+const AtomicStringList* ElementImpl::getClassList() const
+{
+    return 0;
+}
+
+const AtomicString& ElementImpl::getIDAttribute() const
+{
+    return namedAttrMap ? namedAttrMap->id() : nullAtom;
 }
 
 const AtomicString& ElementImpl::getAttribute(NodeImpl::Id id) const
@@ -313,13 +328,9 @@ NodeImpl *ElementImpl::cloneNode(bool deep)
     if (!clone) return 0;
 
     // clone attributes
-    if(namedAttrMap)
+    if (namedAttrMap)
         *(static_cast<NamedAttrMapImpl*>(clone->attributes())) = *namedAttrMap;
 
-    // clone individual style rules
-    if (m_styleDecls)
-        *(clone->styleRules()) = *m_styleDecls;
-
     if (deep)
         cloneChildNodes(clone);
     return clone;
@@ -542,16 +553,6 @@ bool ElementImpl::childTypeAllowed( unsigned short type )
     }
 }
 
-void ElementImpl::createDecl( )
-{
-    m_styleDecls = new CSSStyleDeclarationImpl(0);
-    m_styleDecls->ref();
-    m_styleDecls->setParent(getDocument()->elementSheet());
-    m_styleDecls->parent()->ref();
-    m_styleDecls->setNode(this);
-    m_styleDecls->setStrictParsing( !getDocument()->inCompatMode() );
-}
-
 void ElementImpl::dispatchAttrRemovalEvent(AttributeImpl *attr)
 {
     if (!getDocument()->hasListenerType(DocumentImpl::DOMATTRMODIFIED_LISTENER))
@@ -709,10 +710,6 @@ NodeImpl *XMLElementImpl::cloneNode ( bool deep )
     if(namedAttrMap)
         *(static_cast<NamedAttrMapImpl*>(clone->attributes())) = *namedAttrMap;
 
-    // clone individual style rules
-    if (m_styleDecls)
-        *(clone->styleRules()) = *m_styleDecls;
-
     if (deep)
         cloneChildNodes(clone);
 
diff --git a/WebCore/khtml/xml/dom_elementimpl.h b/WebCore/khtml/xml/dom_elementimpl.h
index 89ee295..4068d07 100644
--- a/WebCore/khtml/xml/dom_elementimpl.h
+++ b/WebCore/khtml/xml/dom_elementimpl.h
@@ -46,6 +46,7 @@ namespace DOM {
 class ElementImpl;
 class DocumentImpl;
 class NamedAttrMapImpl;
+class AtomicStringList;
 
 // this has no counterpart in DOM, purely internal
 // representation of the nodevalue of an Attr.
@@ -154,8 +155,8 @@ public:
     ~ElementImpl();
 
     // Used to quickly determine whether or not an element has a given CSS class.
-    virtual bool matchesCSSClass(const AtomicString& c, bool caseSensitive) const;
-    
+    virtual const AtomicStringList* getClassList() const;
+    const AtomicString& getIDAttribute() const;
     const AtomicString& getAttribute( NodeImpl::Id id ) const;
     const AtomicString& getAttribute(const DOMString& localName) const { return getAttributeNS(QString::null, localName); }
     const AtomicString& getAttributeNS(const DOMString &namespaceURI,
@@ -201,12 +202,12 @@ public:
     virtual bool childAllowed( NodeImpl *newChild );
     virtual bool childTypeAllowed( unsigned short type );
 
-    DOM::CSSStyleDeclarationImpl *styleRules() {
-      if (!m_styleDecls) createDecl();
-      return m_styleDecls;
-    }
+    virtual CSSStyleDeclarationImpl* inlineStyleDecl() const;
+    virtual CSSStyleDeclarationImpl* attributeStyleDecl() const;
+    virtual CSSStyleDeclarationImpl* getInlineStyleDecl();
+    
     // used by table cells to share style decls created by the enclosing table.
-    virtual DOM::CSSStyleDeclarationImpl* getAdditionalStyleDecls() { return 0; }
+    virtual CSSStyleDeclarationImpl* additionalAttributeStyleDecl();
     
     void dispatchAttrRemovalEvent(AttributeImpl *attr);
     void dispatchAttrAdditionEvent(AttributeImpl *attr);
@@ -226,7 +227,6 @@ public:
 #endif
 protected:
     virtual void createAttributeMap() const;
-    void createDecl();
     DOMString openTagStartToString() const;
 
 private:
@@ -234,8 +234,6 @@ private:
 
 protected: // member variables
     mutable NamedAttrMapImpl *namedAttrMap;
-
-    DOM::CSSStyleDeclarationImpl *m_styleDecls;
     DOMStringImpl *m_prefix;
 };
 
@@ -296,6 +294,9 @@ public:
 
     virtual bool isHTMLAttributeMap() const;
 
+    const AtomicString& id() const { return m_id; }
+    void setID(const AtomicString& _id) { m_id = _id; }
+    
 private:
     // this method is internal, does no error checking at all
     void addAttribute(AttributeImpl* newAttribute);
@@ -308,6 +309,7 @@ protected:
     ElementImpl *element;
     AttributeImpl **attrs;
     uint len;
+    AtomicString m_id;
 };
 
 }; //namespace
diff --git a/WebCore/khtml/xml/dom_stringimpl.cpp b/WebCore/khtml/xml/dom_stringimpl.cpp
index 66c54d2..c8f67a7 100644
--- a/WebCore/khtml/xml/dom_stringimpl.cpp
+++ b/WebCore/khtml/xml/dom_stringimpl.cpp
@@ -44,6 +44,7 @@ DOMStringImpl* DOMStringImpl::empty()
 
 DOMStringImpl::DOMStringImpl(const QChar *str, unsigned int len) {
     _hash = 0;
+    _inTable = false;
     bool havestr = str && len;
     s = QT_ALLOC_QCHAR_VEC( havestr ? len : 1 );
     if(str && len) {
@@ -59,6 +60,7 @@ DOMStringImpl::DOMStringImpl(const QChar *str, unsigned int len) {
 DOMStringImpl::DOMStringImpl(const char *str)
 {
     _hash = 0;
+    _inTable = false;
     if(str && *str)
     {
         l = strlen(str);
@@ -79,6 +81,7 @@ DOMStringImpl::DOMStringImpl(const char *str)
 DOMStringImpl::DOMStringImpl(const char *str, unsigned int len)
 {
     _hash = 0;
+    _inTable = false;
     l = len;
     if (!l || !str)
         return;
@@ -92,6 +95,7 @@ DOMStringImpl::DOMStringImpl(const char *str, unsigned int len)
 
 DOMStringImpl::DOMStringImpl(const QChar &ch) {
     _hash = 0;
+    _inTable = false;
     s = QT_ALLOC_QCHAR_VEC( 1 );
     s[0] = ch;
     l = 1;
@@ -99,13 +103,15 @@ DOMStringImpl::DOMStringImpl(const QChar &ch) {
 
 DOMStringImpl::~DOMStringImpl()
 {
-    if (_hash) AtomicString::remove(this);
-    if(s) QT_DELETE_QCHAR_VEC(s);
+    if (_inTable)
+        AtomicString::remove(this);
+    if (s)
+        QT_DELETE_QCHAR_VEC(s);
 }
 
 void DOMStringImpl::append(DOMStringImpl *str)
 {
-    assert(_hash == 0);
+    assert(!_inTable);
     if(str && str->l != 0)
     {
         int newlen = l+str->l;
@@ -120,7 +126,7 @@ void DOMStringImpl::append(DOMStringImpl *str)
 
 void DOMStringImpl::insert(DOMStringImpl *str, uint pos)
 {
-    assert(_hash == 0);
+    assert(!_inTable);
     if(pos > l)
     {
         append(str);
@@ -141,7 +147,7 @@ void DOMStringImpl::insert(DOMStringImpl *str, uint pos)
 
 void DOMStringImpl::truncate(int len)
 {
-    assert(_hash == 0);
+    assert(!_inTable);
     if(len > (int)l) return;
 
     int nl = len < 1 ? 1 : len;
@@ -154,7 +160,7 @@ void DOMStringImpl::truncate(int len)
 
 void DOMStringImpl::remove(uint pos, int len)
 {
-    assert(_hash == 0);
+    assert(!_inTable);
     if(len <= 0) return;
     if(pos >= l ) return;
     if((unsigned)len > l - pos)
@@ -171,7 +177,7 @@ void DOMStringImpl::remove(uint pos, int len)
 
 DOMStringImpl *DOMStringImpl::split(uint pos)
 {
-    assert(_hash == 0);
+    assert(!_inTable);
     if( pos >=l ) return new DOMStringImpl();
 
     uint newLen = l-pos;
diff --git a/WebCore/khtml/xml/dom_stringimpl.h b/WebCore/khtml/xml/dom_stringimpl.h
index d590c1a..af4eaab 100644
--- a/WebCore/khtml/xml/dom_stringimpl.h
+++ b/WebCore/khtml/xml/dom_stringimpl.h
@@ -37,10 +37,10 @@ class DOMStringImpl : public khtml::Shared<DOMStringImpl>
 {
 private:
     struct WithOneRef { };
-    DOMStringImpl(WithOneRef) { s = 0; l = 0; _hash = 0; ref(); }
+    DOMStringImpl(WithOneRef) { s = 0; l = 0; _hash = 0; _inTable = false; ref(); }
 
 protected:
-    DOMStringImpl() { s = 0, l = 0; _hash = 0; }
+    DOMStringImpl() { s = 0, l = 0; _hash = 0; _inTable = false; }
 public:
     DOMStringImpl(const QChar *str, unsigned int len);
     DOMStringImpl(const char *str);
@@ -87,6 +87,7 @@ public:
     unsigned int l;
     QChar *s;
     mutable unsigned _hash;
+    bool _inTable;
 };
 
 };

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list