Title: [106015] trunk/Source/WebCore
Revision
106015
Author
kl...@webkit.org
Date
2012-01-26 11:02:27 -0800 (Thu, 26 Jan 2012)

Log Message

Refactor application of additional style attributes for table elements.
<http://webkit.org/b/77095>

Reviewed by Darin Adler.

The primary purpose of this change is to reduce usage of CSSMappedAttributeDeclaration.
Instead of using the mapped attribute decl table for additional table style, just use
regular CSSMutableStyleDeclarations. We cache them all globally, except for the style
that's shared between a table's cells. That one is cached per-table since it depends
on the table's border and padding.

* dom/CSSMappedAttributeDeclaration.cpp:
(WebCore::CSSMappedAttributeDeclaration::~CSSMappedAttributeDeclaration):
* dom/MappedAttributeEntry.h:

    Remove the concept of persistent CSSMappedAttributeDeclarations. The hunk in
    ~CSSMappedAttributeDeclaration was wildly wrong since it would leave stale pointers
    in the decl table, but unreachable since we always leaked one ref to those decls.

* dom/StyledElement.h:
(WebCore::StyledElement::additionalAttributeStyle):
* html/HTMLTableCellElement.cpp:
(WebCore::HTMLTableCellElement::additionalAttributeStyle):
* html/HTMLTableCellElement.h:
(HTMLTableCellElement):
* html/HTMLTableColElement.cpp:
(WebCore::HTMLTableColElement::additionalAttributeStyle):
* html/HTMLTableColElement.h:
(HTMLTableColElement):
* html/HTMLTableElement.cpp:
(WebCore::HTMLTableElement::parseMappedAttribute):
(WebCore::leakBorderStyle):
(WebCore::HTMLTableElement::additionalAttributeStyle):
(WebCore::HTMLTableElement::createSharedCellStyle):
(WebCore::HTMLTableElement::additionalCellStyle):
(WebCore::leakGroupBorderStyle):
(WebCore::HTMLTableElement::additionalGroupStyle):
* html/HTMLTableElement.h:
(HTMLTableElement):
* html/HTMLTableSectionElement.cpp:
(WebCore::HTMLTableSectionElement::additionalAttributeStyle):
* html/HTMLTableSectionElement.h:
(HTMLTableSectionElement):

    Instead of collecting additional style decls into a vector, switch over to a
    "PassRefPtr<CSSMutableStyleDeclaration> additionalAttributeStyle()".
    All style declarations that can be reused for all elements are cached at the return
    sites, leaving only the shared table cell style which we cache on HTMLTableElement.
    Also removed the canHaveAdditionalAttributeStyleDecls() virtual since the default
    additionalAttributeStyle() will just return 0.

* css/CSSStyleSelector.cpp:
(WebCore::CSSStyleSelector::matchAllRules):

    Updated for the new additional style conventions.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (106014 => 106015)


--- trunk/Source/WebCore/ChangeLog	2012-01-26 18:52:06 UTC (rev 106014)
+++ trunk/Source/WebCore/ChangeLog	2012-01-26 19:02:27 UTC (rev 106015)
@@ -1,3 +1,61 @@
+2012-01-26  Andreas Kling  <awesomekl...@apple.com>
+
+        Refactor application of additional style attributes for table elements.
+        <http://webkit.org/b/77095>
+
+        Reviewed by Darin Adler.
+
+        The primary purpose of this change is to reduce usage of CSSMappedAttributeDeclaration.
+        Instead of using the mapped attribute decl table for additional table style, just use
+        regular CSSMutableStyleDeclarations. We cache them all globally, except for the style
+        that's shared between a table's cells. That one is cached per-table since it depends
+        on the table's border and padding.
+
+        * dom/CSSMappedAttributeDeclaration.cpp:
+        (WebCore::CSSMappedAttributeDeclaration::~CSSMappedAttributeDeclaration):
+        * dom/MappedAttributeEntry.h:
+
+            Remove the concept of persistent CSSMappedAttributeDeclarations. The hunk in
+            ~CSSMappedAttributeDeclaration was wildly wrong since it would leave stale pointers
+            in the decl table, but unreachable since we always leaked one ref to those decls.
+
+        * dom/StyledElement.h:
+        (WebCore::StyledElement::additionalAttributeStyle):
+        * html/HTMLTableCellElement.cpp:
+        (WebCore::HTMLTableCellElement::additionalAttributeStyle):
+        * html/HTMLTableCellElement.h:
+        (HTMLTableCellElement):
+        * html/HTMLTableColElement.cpp:
+        (WebCore::HTMLTableColElement::additionalAttributeStyle):
+        * html/HTMLTableColElement.h:
+        (HTMLTableColElement):
+        * html/HTMLTableElement.cpp:
+        (WebCore::HTMLTableElement::parseMappedAttribute):
+        (WebCore::leakBorderStyle):
+        (WebCore::HTMLTableElement::additionalAttributeStyle):
+        (WebCore::HTMLTableElement::createSharedCellStyle):
+        (WebCore::HTMLTableElement::additionalCellStyle):
+        (WebCore::leakGroupBorderStyle):
+        (WebCore::HTMLTableElement::additionalGroupStyle):
+        * html/HTMLTableElement.h:
+        (HTMLTableElement):
+        * html/HTMLTableSectionElement.cpp:
+        (WebCore::HTMLTableSectionElement::additionalAttributeStyle):
+        * html/HTMLTableSectionElement.h:
+        (HTMLTableSectionElement):
+
+            Instead of collecting additional style decls into a vector, switch over to a
+            "PassRefPtr<CSSMutableStyleDeclaration> additionalAttributeStyle()".
+            All style declarations that can be reused for all elements are cached at the return
+            sites, leaving only the shared table cell style which we cache on HTMLTableElement.
+            Also removed the canHaveAdditionalAttributeStyleDecls() virtual since the default
+            additionalAttributeStyle() will just return 0.
+
+        * css/CSSStyleSelector.cpp:
+        (WebCore::CSSStyleSelector::matchAllRules):
+
+            Updated for the new additional style conventions.
+
 2012-01-26  Vsevolod Vlasov  <vse...@chromium.org>
 
         Web Inspector: Scripts panel editor container should be based on UISourceCode objects, not SourceFrames.

Modified: trunk/Source/WebCore/css/CSSStyleSelector.cpp (106014 => 106015)


--- trunk/Source/WebCore/css/CSSStyleSelector.cpp	2012-01-26 18:52:06 UTC (rev 106014)
+++ trunk/Source/WebCore/css/CSSStyleSelector.cpp	2012-01-26 19:02:27 UTC (rev 106015)
@@ -852,19 +852,14 @@
         // Now we check additional mapped declarations.
         // Tables and table cells share an additional mapped rule that must be applied
         // after all attributes, since their mapped style depends on the values of multiple attributes.
-        if (m_styledElement->canHaveAdditionalAttributeStyleDecls()) {
-            Vector<CSSMutableStyleDeclaration*> additionalAttributeStyleDecls;
-            m_styledElement->additionalAttributeStyleDecls(additionalAttributeStyleDecls);
-            if (!additionalAttributeStyleDecls.isEmpty()) {
-                unsigned additionalDeclsSize = additionalAttributeStyleDecls.size();
-                if (result.ranges.firstAuthorRule == -1)
-                    result.ranges.firstAuthorRule = m_matchedDecls.size();
-                result.ranges.lastAuthorRule = m_matchedDecls.size() + additionalDeclsSize - 1;
-                for (unsigned i = 0; i < additionalDeclsSize; ++i)
-                    addMatchedDeclaration(additionalAttributeStyleDecls[i]);
-                result.isCacheable = false;
-            }
+        if (RefPtr<CSSMutableStyleDeclaration> additionalStyle = m_styledElement->additionalAttributeStyle()) {
+            if (result.ranges.firstAuthorRule == -1)
+                result.ranges.firstAuthorRule = m_matchedDecls.size();
+            result.ranges.lastAuthorRule = m_matchedDecls.size();
+            addMatchedDeclaration(additionalStyle.get());
+            result.isCacheable = false;
         }
+
         if (m_styledElement->isHTMLElement()) {
             bool isAuto;
             TextDirection textDirection = toHTMLElement(m_styledElement)->directionalityIfhasDirAutoAttribute(isAuto);

Modified: trunk/Source/WebCore/dom/CSSMappedAttributeDeclaration.cpp (106014 => 106015)


--- trunk/Source/WebCore/dom/CSSMappedAttributeDeclaration.cpp	2012-01-26 18:52:06 UTC (rev 106014)
+++ trunk/Source/WebCore/dom/CSSMappedAttributeDeclaration.cpp	2012-01-26 19:02:27 UTC (rev 106015)
@@ -38,8 +38,7 @@
 
 CSSMappedAttributeDeclaration::~CSSMappedAttributeDeclaration()
 {
-    if (m_entryType != ePersistent)
-        StyledElement::removeMappedAttributeDecl(m_entryType, m_attrName, m_attrValue);
+    StyledElement::removeMappedAttributeDecl(m_entryType, m_attrName, m_attrValue);
 }
 
 void CSSMappedAttributeDeclaration::setMappedImageProperty(StyledElement* element, int propertyId, const String& url)

Modified: trunk/Source/WebCore/dom/MappedAttributeEntry.h (106014 => 106015)


--- trunk/Source/WebCore/dom/MappedAttributeEntry.h	2012-01-26 18:52:06 UTC (rev 106014)
+++ trunk/Source/WebCore/dom/MappedAttributeEntry.h	2012-01-26 19:02:27 UTC (rev 106015)
@@ -31,7 +31,6 @@
 enum MappedAttributeEntry {
       eNone
     , eUniversal
-    , ePersistent
     , eReplaced
     , eBlock
     , eHR

Modified: trunk/Source/WebCore/dom/StyledElement.h (106014 => 106015)


--- trunk/Source/WebCore/dom/StyledElement.h	2012-01-26 18:52:06 UTC (rev 106014)
+++ trunk/Source/WebCore/dom/StyledElement.h	2012-01-26 19:02:27 UTC (rev 106015)
@@ -55,8 +55,7 @@
     static CSSMappedAttributeDeclaration* getMappedAttributeDecl(MappedAttributeEntry, Attribute*);
     static void setMappedAttributeDecl(MappedAttributeEntry, Attribute*, CSSMappedAttributeDeclaration*);
 
-    virtual bool canHaveAdditionalAttributeStyleDecls() const { return false; }
-    virtual void additionalAttributeStyleDecls(Vector<CSSMutableStyleDeclaration*>&) { }
+    virtual PassRefPtr<CSSMutableStyleDeclaration> additionalAttributeStyle() { return 0; }
     void invalidateStyleAttribute();
 
     CSSMutableStyleDeclaration* inlineStyleDecl() const { return attributeMap() ? attributeMap()->inlineStyleDecl() : 0; }

Modified: trunk/Source/WebCore/html/HTMLTableCellElement.cpp (106014 => 106015)


--- trunk/Source/WebCore/html/HTMLTableCellElement.cpp	2012-01-26 18:52:06 UTC (rev 106014)
+++ trunk/Source/WebCore/html/HTMLTableCellElement.cpp	2012-01-26 19:02:27 UTC (rev 106015)
@@ -118,15 +118,14 @@
         HTMLTablePartElement::parseMappedAttribute(attr);
 }
 
-// used by table cells to share style decls created by the enclosing table.
-void HTMLTableCellElement::additionalAttributeStyleDecls(Vector<CSSMutableStyleDeclaration*>& results)
+PassRefPtr<CSSMutableStyleDeclaration> HTMLTableCellElement::additionalAttributeStyle()
 {
     ContainerNode* p = parentNode();
     while (p && !p->hasTagName(tableTag))
         p = p->parentNode();
     if (!p)
-        return;
-    static_cast<HTMLTableElement*>(p)->addSharedCellDecls(results);
+        return 0;
+    return static_cast<HTMLTableElement*>(p)->additionalCellStyle();
 }
 
 bool HTMLTableCellElement::isURLAttribute(Attribute *attr) const

Modified: trunk/Source/WebCore/html/HTMLTableCellElement.h (106014 => 106015)


--- trunk/Source/WebCore/html/HTMLTableCellElement.h	2012-01-26 18:52:06 UTC (rev 106014)
+++ trunk/Source/WebCore/html/HTMLTableCellElement.h	2012-01-26 19:02:27 UTC (rev 106015)
@@ -56,10 +56,8 @@
     virtual bool mapToEntry(const QualifiedName&, MappedAttributeEntry&) const;
     virtual void parseMappedAttribute(Attribute*);
 
-    // used by table cells to share style decls created by the enclosing table.
-    virtual bool canHaveAdditionalAttributeStyleDecls() const { return true; }
-    virtual void additionalAttributeStyleDecls(Vector<CSSMutableStyleDeclaration*>&);
-    
+    virtual PassRefPtr<CSSMutableStyleDeclaration> additionalAttributeStyle() OVERRIDE;
+
     virtual bool isURLAttribute(Attribute*) const;
 
     virtual void addSubresourceAttributeURLs(ListHashSet<KURL>&) const;

Modified: trunk/Source/WebCore/html/HTMLTableColElement.cpp (106014 => 106015)


--- trunk/Source/WebCore/html/HTMLTableColElement.cpp	2012-01-26 18:52:06 UTC (rev 106014)
+++ trunk/Source/WebCore/html/HTMLTableColElement.cpp	2012-01-26 19:02:27 UTC (rev 106015)
@@ -77,17 +77,16 @@
         HTMLTablePartElement::parseMappedAttribute(attr);
 }
 
-// used by table columns and column groups to share style decls created by the enclosing table.
-void HTMLTableColElement::additionalAttributeStyleDecls(Vector<CSSMutableStyleDeclaration*>& results)
+PassRefPtr<CSSMutableStyleDeclaration> HTMLTableColElement::additionalAttributeStyle()
 {
     if (!hasLocalName(colgroupTag))
-        return;
+        return 0;
     ContainerNode* p = parentNode();
     while (p && !p->hasTagName(tableTag))
         p = p->parentNode();
     if (!p)
-        return;
-    static_cast<HTMLTableElement*>(p)->addSharedGroupDecls(false, results);
+        return 0;
+    return static_cast<HTMLTableElement*>(p)->additionalGroupStyle(false);
 }
 
 void HTMLTableColElement::setSpan(int n)

Modified: trunk/Source/WebCore/html/HTMLTableColElement.h (106014 => 106015)


--- trunk/Source/WebCore/html/HTMLTableColElement.h	2012-01-26 18:52:06 UTC (rev 106014)
+++ trunk/Source/WebCore/html/HTMLTableColElement.h	2012-01-26 19:02:27 UTC (rev 106015)
@@ -44,9 +44,8 @@
 
     virtual bool mapToEntry(const QualifiedName&, MappedAttributeEntry&) const;
     virtual void parseMappedAttribute(Attribute*);
-    virtual bool canHaveAdditionalAttributeStyleDecls() const { return true; }
-    virtual void additionalAttributeStyleDecls(Vector<CSSMutableStyleDeclaration*>&);
-   
+    virtual PassRefPtr<CSSMutableStyleDeclaration> additionalAttributeStyle() OVERRIDE;
+
     int m_span;
 };
 

Modified: trunk/Source/WebCore/html/HTMLTableElement.cpp (106014 => 106015)


--- trunk/Source/WebCore/html/HTMLTableElement.cpp	2012-01-26 18:52:06 UTC (rev 106014)
+++ trunk/Source/WebCore/html/HTMLTableElement.cpp	2012-01-26 19:02:27 UTC (rev 106015)
@@ -436,8 +436,7 @@
         HTMLElement::parseMappedAttribute(attr);
 
     if (bordersBefore != cellBorders() || oldPadding != m_padding) {
-        if (oldPadding != m_padding)
-            m_paddingDecl = 0;
+        m_sharedCellStyle = 0;
         bool cellChanged = false;
         for (Node* child = firstChild(); child; child = child->nextSibling())
             cellChanged |= setTableCellsChanged(child);
@@ -446,28 +445,27 @@
     }
 }
 
-void HTMLTableElement::additionalAttributeStyleDecls(Vector<CSSMutableStyleDeclaration*>& results)
+static CSSMutableStyleDeclaration* leakBorderStyle(int value)
 {
+    RefPtr<CSSMutableStyleDeclaration> style = CSSMutableStyleDeclaration::create();
+    style->setProperty(CSSPropertyBorderTopStyle, value);
+    style->setProperty(CSSPropertyBorderBottomStyle, value);
+    style->setProperty(CSSPropertyBorderLeftStyle, value);
+    style->setProperty(CSSPropertyBorderRightStyle, value);
+    return style.release().leakRef();
+}
+
+PassRefPtr<CSSMutableStyleDeclaration> HTMLTableElement::additionalAttributeStyle()
+{
     if ((!m_borderAttr && !m_borderColorAttr) || m_frameAttr)
-        return;
+        return 0;
 
-    AtomicString borderValue = m_borderColorAttr ? "solid" : "outset";
-    CSSMappedAttributeDeclaration* decl = getMappedAttributeDecl(ePersistent, tableborderAttr, borderValue);
-    if (!decl) {
-        decl = CSSMappedAttributeDeclaration::create().leakRef(); // This single ref pins us in the table until the document dies.
-        ASSERT(!decl->useStrictParsing());
-
-        int value = m_borderColorAttr ? CSSValueSolid : CSSValueOutset;
-        decl->setMappedProperty(this, CSSPropertyBorderTopStyle, value);
-        decl->setMappedProperty(this, CSSPropertyBorderBottomStyle, value);
-        decl->setMappedProperty(this, CSSPropertyBorderLeftStyle, value);
-        decl->setMappedProperty(this, CSSPropertyBorderRightStyle, value);
-
-        setMappedAttributeDecl(ePersistent, tableborderAttr, borderValue, decl);
-        decl->setMappedState(ePersistent, tableborderAttr, borderValue);
+    if (m_borderColorAttr) {
+        static CSSMutableStyleDeclaration* solidBorderStyle = leakBorderStyle(CSSValueSolid);
+        return solidBorderStyle;
     }
-
-    results.append(decl);
+    static CSSMutableStyleDeclaration* outsetBorderStyle = leakBorderStyle(CSSValueOutset);
+    return outsetBorderStyle;
 }
 
 HTMLTableElement::CellBorders HTMLTableElement::cellBorders() const
@@ -493,118 +491,92 @@
     return NoBorders;
 }
 
-void HTMLTableElement::addSharedCellDecls(Vector<CSSMutableStyleDeclaration*>& results)
+PassRefPtr<CSSMutableStyleDeclaration> HTMLTableElement::createSharedCellStyle()
 {
-    addSharedCellBordersDecl(results);
-    addSharedCellPaddingDecl(results);
-}
+    RefPtr<CSSMutableStyleDeclaration> style = CSSMutableStyleDeclaration::create();
 
-void HTMLTableElement::addSharedCellBordersDecl(Vector<CSSMutableStyleDeclaration*>& results)
-{
-    CellBorders borders = cellBorders();
+    switch (cellBorders()) {
+    case SolidBordersColsOnly:
+        style->setProperty(CSSPropertyBorderLeftWidth, CSSValueThin);
+        style->setProperty(CSSPropertyBorderRightWidth, CSSValueThin);
+        style->setProperty(CSSPropertyBorderLeftStyle, CSSValueSolid);
+        style->setProperty(CSSPropertyBorderRightStyle, CSSValueSolid);
+        style->setProperty(CSSPropertyBorderColor, "inherit");
+        break;
+    case SolidBordersRowsOnly:
+        style->setProperty(CSSPropertyBorderTopWidth, CSSValueThin);
+        style->setProperty(CSSPropertyBorderBottomWidth, CSSValueThin);
+        style->setProperty(CSSPropertyBorderTopStyle, CSSValueSolid);
+        style->setProperty(CSSPropertyBorderBottomStyle, CSSValueSolid);
+        style->setProperty(CSSPropertyBorderColor, "inherit");
+        break;
+    case SolidBorders:
+        style->setProperty(CSSPropertyBorderWidth, "1px");
+        style->setProperty(CSSPropertyBorderTopStyle, CSSValueSolid);
+        style->setProperty(CSSPropertyBorderBottomStyle, CSSValueSolid);
+        style->setProperty(CSSPropertyBorderLeftStyle, CSSValueSolid);
+        style->setProperty(CSSPropertyBorderRightStyle, CSSValueSolid);
+        style->setProperty(CSSPropertyBorderColor, "inherit");
+        break;
+    case InsetBorders:
+        style->setProperty(CSSPropertyBorderWidth, "1px");
+        style->setProperty(CSSPropertyBorderTopStyle, CSSValueInset);
+        style->setProperty(CSSPropertyBorderBottomStyle, CSSValueInset);
+        style->setProperty(CSSPropertyBorderLeftStyle, CSSValueInset);
+        style->setProperty(CSSPropertyBorderRightStyle, CSSValueInset);
+        style->setProperty(CSSPropertyBorderColor, "inherit");
+        break;
+    case NoBorders:
+        style->setProperty(CSSPropertyBorderWidth, "0");
+        break;
+    }
 
-    static const AtomicString* cellBorderNames[] = { new AtomicString("none"), new AtomicString("solid"), new AtomicString("inset"), new AtomicString("solid-cols"), new AtomicString("solid-rows") };
-    const AtomicString& cellborderValue = *cellBorderNames[borders];
-    CSSMappedAttributeDeclaration* decl = getMappedAttributeDecl(ePersistent, cellborderAttr, cellborderValue);
-    if (!decl) {
-        decl = CSSMappedAttributeDeclaration::create().leakRef(); // This single ref pins us in the table until the document dies.
-        ASSERT(!decl->useStrictParsing());
-
-        switch (borders) {
-            case SolidBordersColsOnly:
-                decl->setMappedProperty(this, CSSPropertyBorderLeftWidth, CSSValueThin);
-                decl->setMappedProperty(this, CSSPropertyBorderRightWidth, CSSValueThin);
-                decl->setMappedProperty(this, CSSPropertyBorderLeftStyle, CSSValueSolid);
-                decl->setMappedProperty(this, CSSPropertyBorderRightStyle, CSSValueSolid);
-                decl->setMappedProperty(this, CSSPropertyBorderColor, "inherit");
-                break;
-            case SolidBordersRowsOnly:
-                decl->setMappedProperty(this, CSSPropertyBorderTopWidth, CSSValueThin);
-                decl->setMappedProperty(this, CSSPropertyBorderBottomWidth, CSSValueThin);
-                decl->setMappedProperty(this, CSSPropertyBorderTopStyle, CSSValueSolid);
-                decl->setMappedProperty(this, CSSPropertyBorderBottomStyle, CSSValueSolid);
-                decl->setMappedProperty(this, CSSPropertyBorderColor, "inherit");
-                break;
-            case SolidBorders:
-                decl->setMappedProperty(this, CSSPropertyBorderWidth, "1px");
-                decl->setMappedProperty(this, CSSPropertyBorderTopStyle, CSSValueSolid);
-                decl->setMappedProperty(this, CSSPropertyBorderBottomStyle, CSSValueSolid);
-                decl->setMappedProperty(this, CSSPropertyBorderLeftStyle, CSSValueSolid);
-                decl->setMappedProperty(this, CSSPropertyBorderRightStyle, CSSValueSolid);
-                decl->setMappedProperty(this, CSSPropertyBorderColor, "inherit");
-                break;
-            case InsetBorders:
-                decl->setMappedProperty(this, CSSPropertyBorderWidth, "1px");
-                decl->setMappedProperty(this, CSSPropertyBorderTopStyle, CSSValueInset);
-                decl->setMappedProperty(this, CSSPropertyBorderBottomStyle, CSSValueInset);
-                decl->setMappedProperty(this, CSSPropertyBorderLeftStyle, CSSValueInset);
-                decl->setMappedProperty(this, CSSPropertyBorderRightStyle, CSSValueInset);
-                decl->setMappedProperty(this, CSSPropertyBorderColor, "inherit");
-                break;
-            case NoBorders:
-                decl->setMappedProperty(this, CSSPropertyBorderWidth, "0");
-                break;
-        }
-
-        setMappedAttributeDecl(ePersistent, cellborderAttr, *cellBorderNames[borders], decl);
-        decl->setMappedState(ePersistent, cellborderAttr, cellborderValue);
+    if (m_padding) {
+        String value = String::number(m_padding) + "px";
+        style->setProperty(CSSPropertyPaddingTop, value);
+        style->setProperty(CSSPropertyPaddingBottom, value);
+        style->setProperty(CSSPropertyPaddingLeft, value);
+        style->setProperty(CSSPropertyPaddingRight, value);
     }
 
-    results.append(decl);
+    return style.release();
 }
 
-void HTMLTableElement::addSharedCellPaddingDecl(Vector<CSSMutableStyleDeclaration*>& results)
+PassRefPtr<CSSMutableStyleDeclaration> HTMLTableElement::additionalCellStyle()
 {
-    if (m_padding == 0)
-        return;
+    if (!m_sharedCellStyle)
+        m_sharedCellStyle = createSharedCellStyle();
+    return m_sharedCellStyle;
+}
 
-    if (!m_paddingDecl) {
-        String paddingValue = String::number(m_padding);
-        m_paddingDecl = getMappedAttributeDecl(eUniversal, cellpaddingAttr, paddingValue);
-        if (!m_paddingDecl) {
-            m_paddingDecl = CSSMappedAttributeDeclaration::create();
-            ASSERT(!m_paddingDecl->useStrictParsing());
-
-            m_paddingDecl->setMappedProperty(this, CSSPropertyPaddingTop, paddingValue);
-            m_paddingDecl->setMappedProperty(this, CSSPropertyPaddingRight, paddingValue);
-            m_paddingDecl->setMappedProperty(this, CSSPropertyPaddingBottom, paddingValue);
-            m_paddingDecl->setMappedProperty(this, CSSPropertyPaddingLeft, paddingValue);
-        }
-        setMappedAttributeDecl(eUniversal, cellpaddingAttr, paddingValue, m_paddingDecl.get());
-        m_paddingDecl->setMappedState(eUniversal, cellpaddingAttr, paddingValue);
+static CSSMutableStyleDeclaration* leakGroupBorderStyle(int rows)
+{
+    RefPtr<CSSMutableStyleDeclaration> style = CSSMutableStyleDeclaration::create();
+    if (rows) {
+        style->setProperty(CSSPropertyBorderTopWidth, CSSValueThin);
+        style->setProperty(CSSPropertyBorderBottomWidth, CSSValueThin);
+        style->setProperty(CSSPropertyBorderTopStyle, CSSValueSolid);
+        style->setProperty(CSSPropertyBorderBottomStyle, CSSValueSolid);
+    } else {
+        style->setProperty(CSSPropertyBorderLeftWidth, CSSValueThin);
+        style->setProperty(CSSPropertyBorderRightWidth, CSSValueThin);
+        style->setProperty(CSSPropertyBorderLeftStyle, CSSValueSolid);
+        style->setProperty(CSSPropertyBorderRightStyle, CSSValueSolid);
     }
-
-    results.append(m_paddingDecl.get());
+    return style.release().leakRef();
 }
 
-void HTMLTableElement::addSharedGroupDecls(bool rows, Vector<CSSMutableStyleDeclaration*>& results)
+PassRefPtr<CSSMutableStyleDeclaration> HTMLTableElement::additionalGroupStyle(bool rows)
 {
     if (m_rulesAttr != GroupsRules)
-        return;
+        return 0;
 
-    AtomicString rulesValue = rows ? "rowgroups" : "colgroups";
-    CSSMappedAttributeDeclaration* decl = getMappedAttributeDecl(ePersistent, rulesAttr, rulesValue);
-    if (!decl) {
-        decl = CSSMappedAttributeDeclaration::create().leakRef(); // This single ref pins us in the table until the document dies.
-        ASSERT(!decl->useStrictParsing());
-
-        if (rows) {
-            decl->setMappedProperty(this, CSSPropertyBorderTopWidth, CSSValueThin);
-            decl->setMappedProperty(this, CSSPropertyBorderBottomWidth, CSSValueThin);
-            decl->setMappedProperty(this, CSSPropertyBorderTopStyle, CSSValueSolid);
-            decl->setMappedProperty(this, CSSPropertyBorderBottomStyle, CSSValueSolid);
-        } else {
-            decl->setMappedProperty(this, CSSPropertyBorderLeftWidth, CSSValueThin);
-            decl->setMappedProperty(this, CSSPropertyBorderRightWidth, CSSValueThin);
-            decl->setMappedProperty(this, CSSPropertyBorderLeftStyle, CSSValueSolid);
-            decl->setMappedProperty(this, CSSPropertyBorderRightStyle, CSSValueSolid);
-        }
-
-        setMappedAttributeDecl(ePersistent, rulesAttr, rulesValue, decl);
-        decl->setMappedState(ePersistent, rulesAttr, rulesValue);
+    if (rows) {
+        static CSSMutableStyleDeclaration* rowBorderStyle = leakGroupBorderStyle(true);
+        return rowBorderStyle;
     }
-
-    results.append(decl);
+    static CSSMutableStyleDeclaration* columnBorderStyle = leakGroupBorderStyle(false);
+    return columnBorderStyle;
 }
 
 void HTMLTableElement::attach()

Modified: trunk/Source/WebCore/html/HTMLTableElement.h (106014 => 106015)


--- trunk/Source/WebCore/html/HTMLTableElement.h	2012-01-26 18:52:06 UTC (rev 106014)
+++ trunk/Source/WebCore/html/HTMLTableElement.h	2012-01-26 19:02:27 UTC (rev 106015)
@@ -66,8 +66,8 @@
 
     virtual void attach();
 
-    void addSharedCellDecls(Vector<CSSMutableStyleDeclaration*>&);
-    void addSharedGroupDecls(bool rows, Vector<CSSMutableStyleDeclaration*>&);
+    PassRefPtr<CSSMutableStyleDeclaration> additionalCellStyle();
+    PassRefPtr<CSSMutableStyleDeclaration> additionalGroupStyle(bool rows);
 
 private:
     HTMLTableElement(const QualifiedName&, Document*);
@@ -76,21 +76,18 @@
     virtual void parseMappedAttribute(Attribute*);
     virtual bool isURLAttribute(Attribute*) const;
 
-    // Used to obtain either a solid or outset border decl and to deal with the frame
-    // and rules attributes.
-    virtual bool canHaveAdditionalAttributeStyleDecls() const { return true; }
-    virtual void additionalAttributeStyleDecls(Vector<CSSMutableStyleDeclaration*>&);
+    // Used to obtain either a solid or outset border decl and to deal with the frame and rules attributes.
+    virtual PassRefPtr<CSSMutableStyleDeclaration> additionalAttributeStyle() OVERRIDE;
 
     virtual void addSubresourceAttributeURLs(ListHashSet<KURL>&) const;
 
-    void addSharedCellBordersDecl(Vector<CSSMutableStyleDeclaration*>&);
-    void addSharedCellPaddingDecl(Vector<CSSMutableStyleDeclaration*>&);
-    
     enum TableRules { UnsetRules, NoneRules, GroupsRules, RowsRules, ColsRules, AllRules };
     enum CellBorders { NoBorders, SolidBorders, InsetBorders, SolidBordersColsOnly, SolidBordersRowsOnly };
 
     CellBorders cellBorders() const;
 
+    PassRefPtr<CSSMutableStyleDeclaration> createSharedCellStyle();
+
     HTMLTableSectionElement* lastBody() const;
 
     bool m_borderAttr;          // Sets a precise border width and creates an outset border for the table and for its cells.
@@ -100,8 +97,8 @@
                                 // are present, to none otherwise).
 
     unsigned short m_padding;
-    RefPtr<CSSMappedAttributeDeclaration> m_paddingDecl;
     OwnPtr<HTMLTableRowsCollection> m_rowsCollection;
+    RefPtr<CSSMutableStyleDeclaration> m_sharedCellStyle;
 };
 
 } //namespace

Modified: trunk/Source/WebCore/html/HTMLTableSectionElement.cpp (106014 => 106015)


--- trunk/Source/WebCore/html/HTMLTableSectionElement.cpp	2012-01-26 18:52:06 UTC (rev 106014)
+++ trunk/Source/WebCore/html/HTMLTableSectionElement.cpp	2012-01-26 19:02:27 UTC (rev 106015)
@@ -47,15 +47,14 @@
     return adoptRef(new HTMLTableSectionElement(tagName, document));
 }
 
-// used by table row groups to share style decls created by the enclosing table.
-void HTMLTableSectionElement::additionalAttributeStyleDecls(Vector<CSSMutableStyleDeclaration*>& results)
+PassRefPtr<CSSMutableStyleDeclaration> HTMLTableSectionElement::additionalAttributeStyle()
 {
     ContainerNode* p = parentNode();
     while (p && !p->hasTagName(tableTag))
         p = p->parentNode();
     if (!p)
-        return;
-    static_cast<HTMLTableElement*>(p)->addSharedGroupDecls(true, results);
+        return 0;
+    return static_cast<HTMLTableElement*>(p)->additionalGroupStyle(true);
 }
 
 // these functions are rather slow, since we need to get the row at

Modified: trunk/Source/WebCore/html/HTMLTableSectionElement.h (106014 => 106015)


--- trunk/Source/WebCore/html/HTMLTableSectionElement.h	2012-01-26 18:52:06 UTC (rev 106014)
+++ trunk/Source/WebCore/html/HTMLTableSectionElement.h	2012-01-26 19:02:27 UTC (rev 106015)
@@ -56,8 +56,7 @@
 private:
     HTMLTableSectionElement(const QualifiedName& tagName, Document*);
 
-    virtual bool canHaveAdditionalAttributeStyleDecls() const { return true; }
-    virtual void additionalAttributeStyleDecls(Vector<CSSMutableStyleDeclaration*>&);
+    virtual PassRefPtr<CSSMutableStyleDeclaration> additionalAttributeStyle() OVERRIDE;
 };
 
 } //namespace
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to