Kill per-Attribute style declarations.
authorkling@webkit.org <kling@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 4 Feb 2012 12:24:19 +0000 (12:24 +0000)
committerkling@webkit.org <kling@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 4 Feb 2012 12:24:19 +0000 (12:24 +0000)
commit9be783aa7f0391753cb3411b533ac8280e55a4a6
treea550d9f8a43250f9532071dbef4b58364afae6e7
parent6a2766f3494c6b0556657d7f9a9c63501c58006a
Kill per-Attribute style declarations.
<http://webkit.org/b/77204>

Reviewed by Antti Koivisto.

Source/WebCore:

TL;DR summary: Remove the per-Attribute style declarations and replace them by a single
style declaration on StyledElement that acts as a secondary inline style.

The previous design was conceived in the Age of the Old Web(tm) where the majority of
element styling was accomplished via attributes. Nowadays, CSS is a much better tool for
this and we should optimize around that instead.

StyledElements now have an attributeStyle() which contains all the styling from attributes.
parseMappedAttribute() is responsible for adding/removing properties to the attributeStyle
as the corresponding attributes come in/out of the element.

Each Attribute instance shrinks by one pointer, each element that has attributes grows by
one pointer. The styles from individual attributes are no longer shared, so content that
uses a lot of repeating styling attributes will see a slight memory regression from this.
Future improvements to this could enable sharing the attributeStyle between elements that
have the same exact attributes to mitigate some of the damage.

There should be no web-facing behavior change from this, but it does break two things:

- The Inspector feature for displaying per-attribute styles. To keep things manageable,
  this patch simply files all the attribute styles together under an anonymous attribute
  in the Inspector.

- The Obj-C DOM binding for Attr::style() has to be kept for compatibility reasons,
  though it's already deprecated. It will now always return nil, since there's no way to
  retrieve a live style declaration that's specific to a certain Attr.

* css/CSSStyleSelector.cpp:
(WebCore::CSSStyleSelector::matchAllRules):
(WebCore::CSSStyleSelector::canShareStyleWithElement):
* dom/Attr.h:
(WebCore):
(Attr):
(WebCore::Attr::style):
* dom/Attribute.cpp:
(WebCore::Attribute::clone):
* dom/Attribute.h:
(WebCore):
(WebCore::Attribute::create):
(WebCore::Attribute::createMapped):
(Attribute):
(WebCore::Attribute::Attribute):
* dom/CSSMappedAttributeDeclaration.cpp:
(WebCore::CSSMappedAttributeDeclaration::~CSSMappedAttributeDeclaration):
(WebCore::CSSMappedAttributeDeclaration::setMappedProperty):
* dom/CSSMappedAttributeDeclaration.h:
(CSSMappedAttributeDeclaration):
(WebCore::CSSMappedAttributeDeclaration::CSSMappedAttributeDeclaration):
* dom/Element.h:
(Element):
* dom/ElementAttributeData.h:
(ElementAttributeData):
* dom/NamedNodeMap.cpp:
(WebCore::NamedNodeMap::ensureAttributeStyle):
(WebCore):
* dom/NamedNodeMap.h:
(WebCore::NamedNodeMap::attributeStyle):
(NamedNodeMap):
* dom/StyledElement.cpp:
(WebCore):
(WebCore::StyledElement::attributeChanged):
(WebCore::StyledElement::removeCSSProperties):
(WebCore::StyledElement::addCSSProperty):
(WebCore::StyledElement::addCSSImageProperty):
(WebCore::StyledElement::addCSSLength):
(WebCore::StyledElement::addCSSColor):
* dom/StyledElement.h:
(StyledElement):
(WebCore::StyledElement::removeCSSProperty):
(WebCore::StyledElement::attributeStyle):
(WebCore::StyledElement::ensureAttributeStyle):
* html/HTMLBRElement.cpp:
(WebCore::HTMLBRElement::parseMappedAttribute):
* html/HTMLBRElement.h:
(HTMLBRElement):
* html/HTMLBodyElement.cpp:
(WebCore::HTMLBodyElement::parseMappedAttribute):
* html/HTMLBodyElement.h:
(HTMLBodyElement):
* html/HTMLDivElement.cpp:
(WebCore::HTMLDivElement::parseMappedAttribute):
* html/HTMLDivElement.h:
(HTMLDivElement):
* html/HTMLElement.cpp:
(WebCore::HTMLElement::applyBorderAttribute):
(WebCore::HTMLElement::mapLanguageAttributeToLocale):
(WebCore::HTMLElement::parseMappedAttribute):
(WebCore::HTMLElement::removeHTMLAlignment):
(WebCore):
(WebCore::HTMLElement::addHTMLAlignmentToStyledElement):
(WebCore::HTMLElement::setContentEditable):
* html/HTMLElement.h:
(HTMLElement):
* html/HTMLEmbedElement.cpp:
(WebCore::HTMLEmbedElement::parseMappedAttribute):
* html/HTMLEmbedElement.h:
(HTMLEmbedElement):
* html/HTMLFontElement.cpp:
(WebCore::HTMLFontElement::parseMappedAttribute):
* html/HTMLFontElement.h:
(HTMLFontElement):
* html/HTMLFrameSetElement.cpp:
(WebCore::HTMLFrameSetElement::parseMappedAttribute):
* html/HTMLFrameSetElement.h:
(HTMLFrameSetElement):
* html/HTMLHRElement.cpp:
(WebCore::HTMLHRElement::parseMappedAttribute):
* html/HTMLHRElement.h:
(HTMLHRElement):
* html/HTMLIFrameElement.cpp:
(WebCore::HTMLIFrameElement::parseMappedAttribute):
* html/HTMLIFrameElement.h:
(HTMLIFrameElement):
* html/HTMLImageElement.cpp:
(WebCore::HTMLImageElement::parseMappedAttribute):
* html/HTMLImageElement.h:
(HTMLImageElement):
* html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::parseMappedAttribute):
* html/HTMLInputElement.h:
(HTMLInputElement):
* html/HTMLLIElement.cpp:
(WebCore::HTMLLIElement::parseMappedAttribute):
* html/HTMLLIElement.h:
(HTMLLIElement):
* html/HTMLMarqueeElement.cpp:
(WebCore::HTMLMarqueeElement::parseMappedAttribute):
* html/HTMLMarqueeElement.h:
(HTMLMarqueeElement):
* html/HTMLOListElement.cpp:
(WebCore::HTMLOListElement::parseMappedAttribute):
* html/HTMLOListElement.h:
(HTMLOListElement):
* html/HTMLOutputElement.cpp:
* html/HTMLOutputElement.h:
(HTMLOutputElement):
* html/HTMLParagraphElement.cpp:
(WebCore::HTMLParagraphElement::parseMappedAttribute):
* html/HTMLParagraphElement.h:
(HTMLParagraphElement):
* html/HTMLPlugInElement.cpp:
(WebCore::HTMLPlugInElement::parseMappedAttribute):
* html/HTMLPlugInElement.h:
(HTMLPlugInElement):
* html/HTMLPreElement.cpp:
(WebCore::HTMLPreElement::parseMappedAttribute):
* html/HTMLPreElement.h:
(HTMLPreElement):
* html/HTMLTableCaptionElement.cpp:
(WebCore::HTMLTableCaptionElement::parseMappedAttribute):
* html/HTMLTableCaptionElement.h:
(HTMLTableCaptionElement):
* html/HTMLTableCellElement.cpp:
(WebCore::HTMLTableCellElement::parseMappedAttribute):
* html/HTMLTableCellElement.h:
(HTMLTableCellElement):
* html/HTMLTableColElement.cpp:
(WebCore::HTMLTableColElement::parseMappedAttribute):
* html/HTMLTableColElement.h:
(HTMLTableColElement):
* html/HTMLTableElement.cpp:
(WebCore::HTMLTableElement::parseMappedAttribute):
* html/HTMLTableElement.h:
(HTMLTableElement):
* html/HTMLTablePartElement.cpp:
(WebCore):
(WebCore::HTMLTablePartElement::parseMappedAttribute):
* html/HTMLTablePartElement.h:
* html/HTMLTextAreaElement.cpp:
(WebCore::HTMLTextAreaElement::parseMappedAttribute):
* html/HTMLUListElement.cpp:
(WebCore::HTMLUListElement::parseMappedAttribute):
* html/HTMLUListElement.h:
(HTMLUListElement):
* html/HTMLVideoElement.cpp:
(WebCore::HTMLVideoElement::parseMappedAttribute):
* inspector/InspectorCSSAgent.cpp:
(WebCore::InspectorCSSAgent::buildArrayForAttributeStyles):
* mathml/MathMLElement.cpp:
(WebCore::MathMLElement::parseMappedAttribute):
* mathml/MathMLElement.h:
* svg/SVGImageElement.cpp:
(WebCore::SVGImageElement::parseMappedAttribute):
* svg/SVGStyledElement.cpp:
(WebCore::SVGStyledElement::parseMappedAttribute):
(WebCore::SVGStyledElement::getPresentationAttribute):
* svg/SVGStyledElement.h:
(SVGStyledElement):
* svg/SVGTextContentElement.cpp:
(WebCore::SVGTextContentElement::parseMappedAttribute):

LayoutTests:

Rebaselined 3 inspector tests since attribute styles are no longer shown per-attribute.

* inspector/elements/elements-panel-styles-expected.txt:
* inspector/styles/styles-computed-trace-expected.txt:
* inspector/styles/styles-new-API-expected.txt:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@106740 268f45cc-cd09-0410-ab3c-d52691b4dbfc
74 files changed:
LayoutTests/ChangeLog
LayoutTests/inspector/elements/elements-panel-styles-expected.txt
LayoutTests/inspector/styles/styles-computed-trace-expected.txt
LayoutTests/inspector/styles/styles-new-API-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/css/CSSStyleSelector.cpp
Source/WebCore/dom/Attr.h
Source/WebCore/dom/Attribute.cpp
Source/WebCore/dom/Attribute.h
Source/WebCore/dom/CSSMappedAttributeDeclaration.cpp
Source/WebCore/dom/CSSMappedAttributeDeclaration.h
Source/WebCore/dom/Element.h
Source/WebCore/dom/ElementAttributeData.h
Source/WebCore/dom/NamedNodeMap.cpp
Source/WebCore/dom/NamedNodeMap.h
Source/WebCore/dom/StyledElement.cpp
Source/WebCore/dom/StyledElement.h
Source/WebCore/html/HTMLBRElement.cpp
Source/WebCore/html/HTMLBRElement.h
Source/WebCore/html/HTMLBodyElement.cpp
Source/WebCore/html/HTMLBodyElement.h
Source/WebCore/html/HTMLDivElement.cpp
Source/WebCore/html/HTMLDivElement.h
Source/WebCore/html/HTMLElement.cpp
Source/WebCore/html/HTMLElement.h
Source/WebCore/html/HTMLEmbedElement.cpp
Source/WebCore/html/HTMLEmbedElement.h
Source/WebCore/html/HTMLFontElement.cpp
Source/WebCore/html/HTMLFontElement.h
Source/WebCore/html/HTMLFrameSetElement.cpp
Source/WebCore/html/HTMLFrameSetElement.h
Source/WebCore/html/HTMLHRElement.cpp
Source/WebCore/html/HTMLHRElement.h
Source/WebCore/html/HTMLIFrameElement.cpp
Source/WebCore/html/HTMLIFrameElement.h
Source/WebCore/html/HTMLImageElement.cpp
Source/WebCore/html/HTMLImageElement.h
Source/WebCore/html/HTMLInputElement.cpp
Source/WebCore/html/HTMLInputElement.h
Source/WebCore/html/HTMLLIElement.cpp
Source/WebCore/html/HTMLLIElement.h
Source/WebCore/html/HTMLMarqueeElement.cpp
Source/WebCore/html/HTMLMarqueeElement.h
Source/WebCore/html/HTMLOListElement.cpp
Source/WebCore/html/HTMLOListElement.h
Source/WebCore/html/HTMLOutputElement.cpp
Source/WebCore/html/HTMLOutputElement.h
Source/WebCore/html/HTMLParagraphElement.cpp
Source/WebCore/html/HTMLParagraphElement.h
Source/WebCore/html/HTMLPlugInElement.cpp
Source/WebCore/html/HTMLPlugInElement.h
Source/WebCore/html/HTMLPreElement.cpp
Source/WebCore/html/HTMLPreElement.h
Source/WebCore/html/HTMLTableCaptionElement.cpp
Source/WebCore/html/HTMLTableCaptionElement.h
Source/WebCore/html/HTMLTableCellElement.cpp
Source/WebCore/html/HTMLTableCellElement.h
Source/WebCore/html/HTMLTableColElement.cpp
Source/WebCore/html/HTMLTableColElement.h
Source/WebCore/html/HTMLTableElement.cpp
Source/WebCore/html/HTMLTableElement.h
Source/WebCore/html/HTMLTablePartElement.cpp
Source/WebCore/html/HTMLTablePartElement.h
Source/WebCore/html/HTMLTextAreaElement.cpp
Source/WebCore/html/HTMLUListElement.cpp
Source/WebCore/html/HTMLUListElement.h
Source/WebCore/html/HTMLVideoElement.cpp
Source/WebCore/inspector/InspectorCSSAgent.cpp
Source/WebCore/mathml/MathMLElement.cpp
Source/WebCore/mathml/MathMLElement.h
Source/WebCore/svg/SVGImageElement.cpp
Source/WebCore/svg/SVGStyledElement.cpp
Source/WebCore/svg/SVGStyledElement.h
Source/WebCore/svg/SVGTextContentElement.cpp