- Revision
- 131666
- Author
- [email protected]
- Date
- 2012-10-17 16:35:27 -0700 (Wed, 17 Oct 2012)
Log Message
Use virtual dispatch to create ContentData renderers
https://bugs.webkit.org/show_bug.cgi?id=99646
Patch by Elliott Sprehn <[email protected]> on 2012-10-17
Reviewed by Eric Seidel.
ContentData are conceptually very similar to Nodes and we can use
the same createRenderer pattern on them to simplify creating
renderers for generated content. Now each ContentData class knows
how to create its own renderer.
Previously we switched over the StyleContentType which required a
case for CONTENT_NONE and made the code look like it could return
null, but this case is actually impossible because no ContentData
class ever has a type of CONTENT_NONE and no null checks are really
needed.
This is the final step in removing dependence on StyleContentType.
No new tests needed, this is just a refactor.
* rendering/RenderObjectChildList.cpp: Remove createRendererForBeforeAfterContent.
(WebCore::RenderObjectChildList::updateBeforeAfterContent):
* rendering/style/ContentData.cpp:
(WebCore::ImageContentData::createRenderer):
(WebCore):
(WebCore::TextContentData::createRenderer):
(WebCore::CounterContentData::createRenderer):
(WebCore::QuoteContentData::createRenderer):
* rendering/style/ContentData.h: Added a new virtual method createRenderer.
(WebCore):
(ContentData):
(ImageContentData):
(TextContentData):
(CounterContentData):
(QuoteContentData):
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (131665 => 131666)
--- trunk/Source/WebCore/ChangeLog 2012-10-17 23:33:51 UTC (rev 131665)
+++ trunk/Source/WebCore/ChangeLog 2012-10-17 23:35:27 UTC (rev 131666)
@@ -1,3 +1,41 @@
+2012-10-17 Elliott Sprehn <[email protected]>
+
+ Use virtual dispatch to create ContentData renderers
+ https://bugs.webkit.org/show_bug.cgi?id=99646
+
+ Reviewed by Eric Seidel.
+
+ ContentData are conceptually very similar to Nodes and we can use
+ the same createRenderer pattern on them to simplify creating
+ renderers for generated content. Now each ContentData class knows
+ how to create its own renderer.
+
+ Previously we switched over the StyleContentType which required a
+ case for CONTENT_NONE and made the code look like it could return
+ null, but this case is actually impossible because no ContentData
+ class ever has a type of CONTENT_NONE and no null checks are really
+ needed.
+
+ This is the final step in removing dependence on StyleContentType.
+
+ No new tests needed, this is just a refactor.
+
+ * rendering/RenderObjectChildList.cpp: Remove createRendererForBeforeAfterContent.
+ (WebCore::RenderObjectChildList::updateBeforeAfterContent):
+ * rendering/style/ContentData.cpp:
+ (WebCore::ImageContentData::createRenderer):
+ (WebCore):
+ (WebCore::TextContentData::createRenderer):
+ (WebCore::CounterContentData::createRenderer):
+ (WebCore::QuoteContentData::createRenderer):
+ * rendering/style/ContentData.h: Added a new virtual method createRenderer.
+ (WebCore):
+ (ContentData):
+ (ImageContentData):
+ (TextContentData):
+ (CounterContentData):
+ (QuoteContentData):
+
2012-10-17 Julien Chaffraix <[email protected]>
RenderLayer subtrees without any self-painting layer shouldn't be walked during hit testing
Modified: trunk/Source/WebCore/rendering/RenderObjectChildList.cpp (131665 => 131666)
--- trunk/Source/WebCore/rendering/RenderObjectChildList.cpp 2012-10-17 23:33:51 UTC (rev 131665)
+++ trunk/Source/WebCore/rendering/RenderObjectChildList.cpp 2012-10-17 23:35:27 UTC (rev 131666)
@@ -31,16 +31,11 @@
#include "ContentData.h"
#include "RenderBlock.h"
#include "RenderCounter.h"
-#include "RenderImage.h"
-#include "RenderImageResourceStyleImage.h"
-#include "RenderInline.h"
#include "RenderLayer.h"
#include "RenderListItem.h"
#include "RenderNamedFlowThread.h"
-#include "RenderQuote.h"
#include "RenderRegion.h"
#include "RenderStyle.h"
-#include "RenderTextFragment.h"
#include "RenderView.h"
namespace WebCore {
@@ -305,40 +300,6 @@
}
}
-static RenderObject* createRendererForBeforeAfterContent(RenderObject* owner, const ContentData* content, RenderStyle* pseudoElementStyle)
-{
- RenderObject* renderer = 0;
- switch (content->type()) {
- case CONTENT_NONE:
- break;
- case CONTENT_TEXT:
- renderer = new (owner->renderArena()) RenderTextFragment(owner->document() /* anonymous object */, static_cast<const TextContentData*>(content)->text().impl());
- renderer->setStyle(pseudoElementStyle);
- break;
- case CONTENT_OBJECT: {
- RenderImage* image = new (owner->renderArena()) RenderImage(owner->document()); // anonymous object
- RefPtr<RenderStyle> style = RenderStyle::create();
- style->inheritFrom(pseudoElementStyle);
- image->setStyle(style.release());
- if (const StyleImage* styleImage = static_cast<const ImageContentData*>(content)->image())
- image->setImageResource(RenderImageResourceStyleImage::create(const_cast<StyleImage*>(styleImage)));
- else
- image->setImageResource(RenderImageResource::create());
- renderer = image;
- break;
- }
- case CONTENT_COUNTER:
- renderer = new (owner->renderArena()) RenderCounter(owner->document(), *static_cast<const CounterContentData*>(content)->counter());
- renderer->setStyle(pseudoElementStyle);
- break;
- case CONTENT_QUOTE:
- renderer = new (owner->renderArena()) RenderQuote(owner->document(), static_cast<const QuoteContentData*>(content)->quote());
- renderer->setStyle(pseudoElementStyle);
- break;
- }
- return renderer;
-}
-
static RenderObject* ensureBeforeAfterContainer(RenderObject* owner, PseudoId type, RenderStyle* pseudoElementStyle, Node* generatingNode, RenderObject* insertBefore)
{
// Make a generated box that might be any display type now that we are able to drill down into children
@@ -465,21 +426,19 @@
else {
// Walk our list of generated content and create render objects for each.
for (const ContentData* content = pseudoElementStyle->contentData(); content; content = content->next()) {
- RenderObject* renderer = createRendererForBeforeAfterContent(owner, content, pseudoElementStyle);
+ RenderObject* renderer = content->createRenderer(owner->document(), pseudoElementStyle);
- if (renderer) {
+ if (!generatedContentContainer) {
+ generatedContentContainer = ensureBeforeAfterContainer(owner, type, pseudoElementStyle, styledObject->node(), insertBefore);
if (!generatedContentContainer) {
- generatedContentContainer = ensureBeforeAfterContainer(owner, type, pseudoElementStyle, styledObject->node(), insertBefore);
- if (!generatedContentContainer) {
- renderer->destroy();
- return;
- }
- }
- if (generatedContentContainer->isChildAllowed(renderer, pseudoElementStyle))
- generatedContentContainer->addChild(renderer);
- else
renderer->destroy();
+ return;
+ }
}
+ if (generatedContentContainer->isChildAllowed(renderer, pseudoElementStyle))
+ generatedContentContainer->addChild(renderer);
+ else
+ renderer->destroy();
}
}
Modified: trunk/Source/WebCore/rendering/style/ContentData.cpp (131665 => 131666)
--- trunk/Source/WebCore/rendering/style/ContentData.cpp 2012-10-17 23:33:51 UTC (rev 131665)
+++ trunk/Source/WebCore/rendering/style/ContentData.cpp 2012-10-17 23:35:27 UTC (rev 131666)
@@ -22,6 +22,15 @@
#include "config.h"
#include "ContentData.h"
+#include "RenderCounter.h"
+#include "RenderImage.h"
+#include "RenderImageResource.h"
+#include "RenderImageResourceStyleImage.h"
+#include "RenderQuote.h"
+#include "RenderStyle.h"
+#include "RenderTextFragment.h"
+#include "StyleInheritedData.h"
+
namespace WebCore {
PassOwnPtr<ContentData> ContentData::create(PassRefPtr<StyleImage> image)
@@ -58,4 +67,41 @@
return result.release();
}
+RenderObject* ImageContentData::createRenderer(Document* doc, RenderStyle* pseudoStyle) const
+{
+ RenderImage* image = new (doc->renderArena()) RenderImage(doc);
+ // Images are special and must inherit the pseudoStyle so the width and height of
+ // the pseudo element don't change the size of the image. In all other cases we
+ // can just share the style.
+ RefPtr<RenderStyle> style = RenderStyle::create();
+ style->inheritFrom(pseudoStyle);
+ image->setStyle(style.release());
+ if (m_image)
+ image->setImageResource(RenderImageResourceStyleImage::create(m_image.get()));
+ else
+ image->setImageResource(RenderImageResource::create());
+ return image;
+}
+
+RenderObject* TextContentData::createRenderer(Document* doc, RenderStyle* pseudoStyle) const
+{
+ RenderObject* renderer = new (doc->renderArena()) RenderTextFragment(doc, m_text.impl());
+ renderer->setStyle(pseudoStyle);
+ return renderer;
+}
+
+RenderObject* CounterContentData::createRenderer(Document* doc, RenderStyle* pseudoStyle) const
+{
+ RenderObject* renderer = new (doc->renderArena()) RenderCounter(doc, *m_counter);
+ renderer->setStyle(pseudoStyle);
+ return renderer;
+}
+
+RenderObject* QuoteContentData::createRenderer(Document* doc, RenderStyle* pseudoStyle) const
+{
+ RenderObject* renderer = new (doc->renderArena()) RenderQuote(doc, m_quote);
+ renderer->setStyle(pseudoStyle);
+ return renderer;
+}
+
} // namespace WebCore
Modified: trunk/Source/WebCore/rendering/style/ContentData.h (131665 => 131666)
--- trunk/Source/WebCore/rendering/style/ContentData.h 2012-10-17 23:33:51 UTC (rev 131665)
+++ trunk/Source/WebCore/rendering/style/ContentData.h 2012-10-17 23:35:27 UTC (rev 131666)
@@ -32,7 +32,9 @@
namespace WebCore {
-class StyleImage;
+class Document;
+class RenderObject;
+class RenderStyle;
class ContentData {
WTF_MAKE_FAST_ALLOCATED;
@@ -49,6 +51,8 @@
virtual bool isQuote() const { return false; }
virtual bool isText() const { return false; }
+ virtual RenderObject* createRenderer(Document*, RenderStyle*) const = 0;
+
virtual StyleContentType type() const = 0;
virtual PassOwnPtr<ContentData> clone() const;
@@ -70,6 +74,8 @@
StyleImage* image() { return m_image.get(); }
void setImage(PassRefPtr<StyleImage> image) { m_image = image; }
+ virtual RenderObject* createRenderer(Document*, RenderStyle*) const OVERRIDE;
+
virtual bool equals(const ContentData& data) const OVERRIDE
{
if (!data.isImage())
@@ -100,6 +106,8 @@
const String& text() const { return m_text; }
void setText(const String& text) { m_text = text; }
+ virtual RenderObject* createRenderer(Document*, RenderStyle*) const OVERRIDE;
+
virtual bool equals(const ContentData& data) const OVERRIDE
{
if (!data.isText())
@@ -126,6 +134,8 @@
const CounterContent* counter() const { return m_counter.get(); }
void setCounter(PassOwnPtr<CounterContent> counter) { m_counter = counter; }
+ virtual RenderObject* createRenderer(Document*, RenderStyle*) const OVERRIDE;
+
private:
CounterContentData(PassOwnPtr<CounterContent> counter)
: m_counter(counter)
@@ -156,6 +166,8 @@
QuoteType quote() const { return m_quote; }
void setQuote(QuoteType quote) { m_quote = quote; }
+ virtual RenderObject* createRenderer(Document*, RenderStyle*) const OVERRIDE;
+
virtual bool equals(const ContentData& data) const OVERRIDE
{
if (!data.isQuote())