Diff
Modified: trunk/Source/WebCore/ChangeLog (101176 => 101177)
--- trunk/Source/WebCore/ChangeLog 2011-11-25 17:47:56 UTC (rev 101176)
+++ trunk/Source/WebCore/ChangeLog 2011-11-25 18:08:38 UTC (rev 101177)
@@ -1,3 +1,48 @@
+2011-11-25 Antti Koivisto <an...@apple.com>
+
+ StyleGeneratedImage should ref CSSImageGeneratorValue
+ https://bugs.webkit.org/show_bug.cgi?id=73074
+
+ Reviewed by Andreas Kling and Nikolas Zimmermann.
+
+ RenderStyle owns a bunch of StyleImage objects. However StyleGeneratedImage does not ref the
+ CSSImageGeneratorValue it holds so we currently rely on the stylesheet to keep the CSSImageGeneratorValues
+ alive as long as RenderStyle stays alive. While this works (RenderStyles are thrown away if stylesheets
+ change) it is not particularly robust or nice.
+
+ - Use RefPtr<CSSImageGeneratorValue> in StyleGeneratedImage
+ - Remove the RefPtr<StyleGeneratedImage> from CSSImageGeneratorValue.
+ There is no good reason to cache StyleGeneratedImage as it is a small and
+ uncommon object. With that the whole back-reference becomes unnecessary.
+ - Switch more places to use (Pass)RefPtr<StyleImage> for consistency.
+
+ * css/CSSImageGeneratorValue.cpp:
+ (WebCore::CSSImageGeneratorValue::CSSImageGeneratorValue):
+ * css/CSSImageGeneratorValue.h:
+ * css/CSSStyleApplyProperty.cpp:
+ * css/CSSStyleSelector.cpp:
+ (WebCore::CSSStyleSelector::applyProperty):
+ (WebCore::CSSStyleSelector::styleImage):
+ (WebCore::CSSStyleSelector::cachedOrPendingFromValue):
+ (WebCore::CSSStyleSelector::generatedOrPendingFromValue):
+ (WebCore::CSSStyleSelector::loadPendingImage):
+ (WebCore::CSSStyleSelector::loadPendingImages):
+ * css/CSSStyleSelector.h:
+ * rendering/style/FillLayer.h:
+ (WebCore::FillLayer::setImage):
+ * rendering/style/NinePieceImage.h:
+ (WebCore::NinePieceImage::NinePieceImage):
+ * rendering/style/StyleGeneratedImage.cpp:
+ (WebCore::StyleGeneratedImage::StyleGeneratedImage):
+ (WebCore::StyleGeneratedImage::cssValue):
+ (WebCore::StyleGeneratedImage::imageSize):
+ (WebCore::StyleGeneratedImage::addClient):
+ (WebCore::StyleGeneratedImage::removeClient):
+ (WebCore::StyleGeneratedImage::image):
+ * rendering/style/StyleGeneratedImage.h:
+ (WebCore::StyleGeneratedImage::create):
+ (WebCore::StyleGeneratedImage::data):
+
2011-11-25 Andreas Kling <kl...@webkit.org>
Remove redundant setStrictParsing(false) calls on CSSMappedAttributeDeclarations.
Modified: trunk/Source/WebCore/css/CSSImageGeneratorValue.cpp (101176 => 101177)
--- trunk/Source/WebCore/css/CSSImageGeneratorValue.cpp 2011-11-25 17:47:56 UTC (rev 101176)
+++ trunk/Source/WebCore/css/CSSImageGeneratorValue.cpp 2011-11-25 18:08:38 UTC (rev 101177)
@@ -31,15 +31,12 @@
#include "CSSGradientValue.h"
#include "Image.h"
#include "RenderObject.h"
-#include "StyleGeneratedImage.h"
-#include "StylePendingImage.h"
#include <wtf/text/WTFString.h>
namespace WebCore {
CSSImageGeneratorValue::CSSImageGeneratorValue(ClassType classType)
: CSSValue(classType)
- , m_accessedImage(false)
{
}
@@ -111,28 +108,6 @@
m_images.add(size, image);
}
-StyleImage* CSSImageGeneratorValue::generatedOrPendingImage()
-{
- if (isPending())
- m_image = StylePendingImage::create(this).get();
- else if (!m_accessedImage) {
- m_accessedImage = true;
- m_image = StyleGeneratedImage::create(this, isFixedSize());
- }
-
- return m_image.get();
-}
-
-StyleGeneratedImage* CSSImageGeneratorValue::generatedImage()
-{
- if (!m_accessedImage) {
- m_accessedImage = true;
- m_image = StyleGeneratedImage::create(this, isFixedSize());
- }
-
- return static_cast<StyleGeneratedImage*>(m_image.get());
-}
-
PassRefPtr<Image> CSSImageGeneratorValue::image(RenderObject* renderer, const IntSize& size)
{
switch (classType()) {
Modified: trunk/Source/WebCore/css/CSSImageGeneratorValue.h (101176 => 101177)
--- trunk/Source/WebCore/css/CSSImageGeneratorValue.h 2011-11-25 17:47:56 UTC (rev 101176)
+++ trunk/Source/WebCore/css/CSSImageGeneratorValue.h 2011-11-25 18:08:38 UTC (rev 101177)
@@ -36,8 +36,6 @@
class CachedResourceLoader;
class Image;
class RenderObject;
-class StyleGeneratedImage;
-class StyleImage;
struct SizeAndCount {
SizeAndCount(IntSize newSize = IntSize(), int newCount = 0)
@@ -60,9 +58,6 @@
void removeClient(RenderObject*);
PassRefPtr<Image> image(RenderObject*, const IntSize&);
- StyleImage* generatedOrPendingImage();
- StyleGeneratedImage* generatedImage();
-
bool isFixedSize() const;
IntSize fixedSize(const RenderObject*);
@@ -77,9 +72,6 @@
void putImage(const IntSize&, PassRefPtr<Image>);
const RenderObjectSizeCountMap& clients() const { return m_clients; }
- RefPtr<StyleImage> m_image;
- bool m_accessedImage;
-
HashCountedSet<IntSize> m_sizes; // A count of how many times a given image size is in use.
RenderObjectSizeCountMap m_clients; // A map from RenderObjects (with entry count) to image sizes.
HashMap<IntSize, RefPtr<Image> > m_images; // A cache of Image objects by image size.
Modified: trunk/Source/WebCore/css/CSSStyleApplyProperty.cpp (101176 => 101177)
--- trunk/Source/WebCore/css/CSSStyleApplyProperty.cpp 2011-11-25 17:47:56 UTC (rev 101176)
+++ trunk/Source/WebCore/css/CSSStyleApplyProperty.cpp 2011-11-25 18:08:38 UTC (rev 101177)
@@ -388,16 +388,28 @@
}
};
+template <typename T>
+struct FillLayerAccessorTypes {
+ typedef T Setter;
+ typedef T Getter;
+};
+
+template <>
+struct FillLayerAccessorTypes<StyleImage*> {
+ typedef PassRefPtr<StyleImage> Setter;
+ typedef StyleImage* Getter;
+};
+
template <typename T,
CSSPropertyID propertyId,
EFillLayerType fillLayerType,
FillLayer* (RenderStyle::*accessLayersFunction)(),
const FillLayer* (RenderStyle::*layersFunction)() const,
bool (FillLayer::*testFunction)() const,
- T (FillLayer::*getFunction)() const,
- void (FillLayer::*setFunction)(T),
+ typename FillLayerAccessorTypes<T>::Getter (FillLayer::*getFunction)() const,
+ void (FillLayer::*setFunction)(typename FillLayerAccessorTypes<T>::Setter),
void (FillLayer::*clearFunction)(),
- T (*initialFunction)(EFillLayerType),
+ typename FillLayerAccessorTypes<T>::Getter (*initialFunction)(EFillLayerType),
void (CSSStyleSelector::*mapFillFunction)(CSSPropertyID, FillLayer*, CSSValue*)>
class ApplyPropertyFillLayer {
public:
Modified: trunk/Source/WebCore/css/CSSStyleSelector.cpp (101176 => 101177)
--- trunk/Source/WebCore/css/CSSStyleSelector.cpp 2011-11-25 17:47:56 UTC (rev 101176)
+++ trunk/Source/WebCore/css/CSSStyleSelector.cpp 2011-11-25 18:08:38 UTC (rev 101177)
@@ -2860,7 +2860,7 @@
for (CSSValueListIterator i = value; i.hasMore(); i.advance()) {
CSSValue* item = i.value();
if (item->isImageGeneratorValue()) {
- m_style->setContent(static_cast<CSSImageGeneratorValue*>(item)->generatedImage(), didSet);
+ m_style->setContent(StyleGeneratedImage::create(static_cast<CSSImageGeneratorValue*>(item)), didSet);
didSet = true;
}
@@ -4288,7 +4288,7 @@
layer->setOrigin(*primitiveValue);
}
-StyleImage* CSSStyleSelector::styleImage(CSSPropertyID property, CSSValue* value)
+PassRefPtr<StyleImage> CSSStyleSelector::styleImage(CSSPropertyID property, CSSValue* value)
{
if (value->isImageValue())
return cachedOrPendingFromValue(property, static_cast<CSSImageValue*>(value));
@@ -4299,20 +4299,21 @@
return 0;
}
-StyleImage* CSSStyleSelector::cachedOrPendingFromValue(CSSPropertyID property, CSSImageValue* value)
+PassRefPtr<StyleImage> CSSStyleSelector::cachedOrPendingFromValue(CSSPropertyID property, CSSImageValue* value)
{
- StyleImage* image = value->cachedOrPendingImage();
+ RefPtr<StyleImage> image = value->cachedOrPendingImage();
if (image && image->isPendingImage())
m_pendingImageProperties.add(property);
- return image;
+ return image.release();
}
-StyleImage* CSSStyleSelector::generatedOrPendingFromValue(CSSPropertyID property, CSSImageGeneratorValue* value)
+PassRefPtr<StyleImage> CSSStyleSelector::generatedOrPendingFromValue(CSSPropertyID property, CSSImageGeneratorValue* value)
{
- StyleImage* image = value->generatedOrPendingImage();
- if (image && image->isPendingImage())
+ if (value->isPending()) {
m_pendingImageProperties.add(property);
- return image;
+ return StylePendingImage::create(value);
+ }
+ return StyleGeneratedImage::create(value);
}
void CSSStyleSelector::mapFillImage(CSSPropertyID property, FillLayer* layer, CSSValue* value)
@@ -5740,7 +5741,7 @@
#endif
-StyleImage* CSSStyleSelector::loadPendingImage(StylePendingImage* pendingImage)
+PassRefPtr<StyleImage> CSSStyleSelector::loadPendingImage(StylePendingImage* pendingImage)
{
CachedResourceLoader* cachedResourceLoader = m_element->document()->cachedResourceLoader();
@@ -5752,7 +5753,7 @@
if (pendingImage->cssImageGeneratorValue()) {
CSSImageGeneratorValue* imageGeneratorValue = pendingImage->cssImageGeneratorValue();
imageGeneratorValue->loadSubimages(cachedResourceLoader);
- return imageGeneratorValue->generatedImage();
+ return StyleGeneratedImage::create(imageGeneratorValue);
}
return 0;
@@ -5770,84 +5771,65 @@
switch (currentProperty) {
case CSSPropertyBackgroundImage: {
for (FillLayer* backgroundLayer = m_style->accessBackgroundLayers(); backgroundLayer; backgroundLayer = backgroundLayer->next()) {
- if (backgroundLayer->image() && backgroundLayer->image()->isPendingImage()) {
- StyleImage* loadedImage = loadPendingImage(static_cast<StylePendingImage*>(backgroundLayer->image()));
- backgroundLayer->setImage(loadedImage);
- }
+ if (backgroundLayer->image() && backgroundLayer->image()->isPendingImage())
+ backgroundLayer->setImage(loadPendingImage(static_cast<StylePendingImage*>(backgroundLayer->image())));
}
break;
}
-
case CSSPropertyContent: {
for (ContentData* contentData = const_cast<ContentData*>(m_style->contentData()); contentData; contentData = contentData->next()) {
if (contentData->isImage()) {
StyleImage* image = static_cast<ImageContentData*>(contentData)->image();
if (image->isPendingImage()) {
- StyleImage* loadedImage = loadPendingImage(static_cast<StylePendingImage*>(image));
+ RefPtr<StyleImage> loadedImage = loadPendingImage(static_cast<StylePendingImage*>(image));
if (loadedImage)
- static_cast<ImageContentData*>(contentData)->setImage(loadedImage);
+ static_cast<ImageContentData*>(contentData)->setImage(loadedImage.release());
}
}
}
break;
}
-
case CSSPropertyCursor: {
if (CursorList* cursorList = m_style->cursors()) {
for (size_t i = 0; i < cursorList->size(); ++i) {
CursorData& currentCursor = cursorList->at(i);
if (StyleImage* image = currentCursor.image()) {
- if (image->isPendingImage()) {
- StyleImage* loadedImage = loadPendingImage(static_cast<StylePendingImage*>(image));
- currentCursor.setImage(loadedImage);
- }
+ if (image->isPendingImage())
+ currentCursor.setImage(loadPendingImage(static_cast<StylePendingImage*>(image)));
}
}
}
break;
}
-
case CSSPropertyListStyleImage: {
- if (m_style->listStyleImage() && m_style->listStyleImage()->isPendingImage()) {
- StyleImage* loadedImage = loadPendingImage(static_cast<StylePendingImage*>(m_style->listStyleImage()));
- m_style->setListStyleImage(loadedImage);
- }
+ if (m_style->listStyleImage() && m_style->listStyleImage()->isPendingImage())
+ m_style->setListStyleImage(loadPendingImage(static_cast<StylePendingImage*>(m_style->listStyleImage())));
break;
}
-
case CSSPropertyBorderImageSource: {
- if (m_style->borderImageSource() && m_style->borderImageSource()->isPendingImage()) {
- StyleImage* loadedImage = loadPendingImage(static_cast<StylePendingImage*>(m_style->borderImageSource()));
- m_style->setBorderImageSource(loadedImage);
- }
+ if (m_style->borderImageSource() && m_style->borderImageSource()->isPendingImage())
+ m_style->setBorderImageSource(loadPendingImage(static_cast<StylePendingImage*>(m_style->borderImageSource())));
break;
}
-
case CSSPropertyWebkitBoxReflect: {
if (StyleReflection* reflection = m_style->boxReflect()) {
const NinePieceImage& maskImage = reflection->mask();
if (maskImage.image() && maskImage.image()->isPendingImage()) {
- StyleImage* loadedImage = loadPendingImage(static_cast<StylePendingImage*>(maskImage.image()));
- reflection->setMask(NinePieceImage(loadedImage, maskImage.imageSlices(), maskImage.fill(), maskImage.borderSlices(), maskImage.outset(), maskImage.horizontalRule(), maskImage.verticalRule()));
+ RefPtr<StyleImage> loadedImage = loadPendingImage(static_cast<StylePendingImage*>(maskImage.image()));
+ reflection->setMask(NinePieceImage(loadedImage.release(), maskImage.imageSlices(), maskImage.fill(), maskImage.borderSlices(), maskImage.outset(), maskImage.horizontalRule(), maskImage.verticalRule()));
}
}
break;
}
-
case CSSPropertyWebkitMaskBoxImageSource: {
- if (m_style->maskBoxImageSource() && m_style->maskBoxImageSource()->isPendingImage()) {
- StyleImage* loadedImage = loadPendingImage(static_cast<StylePendingImage*>(m_style->maskBoxImageSource()));
- m_style->setMaskBoxImageSource(loadedImage);
- }
+ if (m_style->maskBoxImageSource() && m_style->maskBoxImageSource()->isPendingImage())
+ m_style->setMaskBoxImageSource(loadPendingImage(static_cast<StylePendingImage*>(m_style->maskBoxImageSource())));
break;
}
-
case CSSPropertyWebkitMaskImage: {
for (FillLayer* maskLayer = m_style->accessMaskLayers(); maskLayer; maskLayer = maskLayer->next()) {
- if (maskLayer->image() && maskLayer->image()->isPendingImage()) {
- StyleImage* loadedImage = loadPendingImage(static_cast<StylePendingImage*>(maskLayer->image()));
- maskLayer->setImage(loadedImage);
- }
+ if (maskLayer->image() && maskLayer->image()->isPendingImage())
+ maskLayer->setImage(loadPendingImage(static_cast<StylePendingImage*>(maskLayer->image())));
}
break;
}
Modified: trunk/Source/WebCore/css/CSSStyleSelector.h (101176 => 101177)
--- trunk/Source/WebCore/css/CSSStyleSelector.h 2011-11-25 17:47:56 UTC (rev 101176)
+++ trunk/Source/WebCore/css/CSSStyleSelector.h 2011-11-25 18:08:38 UTC (rev 101177)
@@ -294,9 +294,9 @@
public:
static RenderStyle* styleNotYetAvailable() { return s_styleNotYetAvailable; }
- StyleImage* styleImage(CSSPropertyID, CSSValue*);
- StyleImage* cachedOrPendingFromValue(CSSPropertyID, CSSImageValue*);
- StyleImage* generatedOrPendingFromValue(CSSPropertyID, CSSImageGeneratorValue*);
+ PassRefPtr<StyleImage> styleImage(CSSPropertyID, CSSValue*);
+ PassRefPtr<StyleImage> cachedOrPendingFromValue(CSSPropertyID, CSSImageValue*);
+ PassRefPtr<StyleImage> generatedOrPendingFromValue(CSSPropertyID, CSSImageGeneratorValue*);
bool applyPropertyToRegularStyle() const { return m_applyPropertyToRegularStyle; }
bool applyPropertyToVisitedLinkStyle() const { return m_applyPropertyToVisitedLinkStyle; }
@@ -343,7 +343,7 @@
void applySVGProperty(int id, CSSValue*);
#endif
- StyleImage* loadPendingImage(StylePendingImage*);
+ PassRefPtr<StyleImage> loadPendingImage(StylePendingImage*);
void loadPendingImages();
struct MatchedStyleDeclaration {
Modified: trunk/Source/WebCore/rendering/style/FillLayer.h (101176 => 101177)
--- trunk/Source/WebCore/rendering/style/FillLayer.h 2011-11-25 17:47:56 UTC (rev 101176)
+++ trunk/Source/WebCore/rendering/style/FillLayer.h 2011-11-25 18:08:38 UTC (rev 101177)
@@ -92,7 +92,7 @@
bool isCompositeSet() const { return m_compositeSet; }
bool isSizeSet() const { return m_sizeType != SizeNone; }
- void setImage(StyleImage* i) { m_image = i; m_imageSet = true; }
+ void setImage(PassRefPtr<StyleImage> i) { m_image = i; m_imageSet = true; }
void setXPosition(Length l) { m_xPosition = l; m_xPosSet = true; }
void setYPosition(Length l) { m_yPosition = l; m_yPosSet = true; }
void setAttachment(EFillAttachment attachment) { m_attachment = attachment; m_attachmentSet = true; }
Modified: trunk/Source/WebCore/rendering/style/NinePieceImage.h (101176 => 101177)
--- trunk/Source/WebCore/rendering/style/NinePieceImage.h 2011-11-25 17:47:56 UTC (rev 101176)
+++ trunk/Source/WebCore/rendering/style/NinePieceImage.h 2011-11-25 18:08:38 UTC (rev 101177)
@@ -47,7 +47,7 @@
{
}
- NinePieceImage(StyleImage* image, LengthBox imageSlices, bool fill, LengthBox borderSlices, LengthBox outset, ENinePieceImageRule h, ENinePieceImageRule v)
+ NinePieceImage(PassRefPtr<StyleImage> image, LengthBox imageSlices, bool fill, LengthBox borderSlices, LengthBox outset, ENinePieceImageRule h, ENinePieceImageRule v)
: m_image(image)
, m_imageSlices(imageSlices)
, m_borderSlices(borderSlices)
Modified: trunk/Source/WebCore/rendering/style/StyleGeneratedImage.cpp (101176 => 101177)
--- trunk/Source/WebCore/rendering/style/StyleGeneratedImage.cpp 2011-11-25 17:47:56 UTC (rev 101176)
+++ trunk/Source/WebCore/rendering/style/StyleGeneratedImage.cpp 2011-11-25 18:08:38 UTC (rev 101177)
@@ -29,16 +29,23 @@
#include "RenderObject.h"
namespace WebCore {
+
+StyleGeneratedImage::StyleGeneratedImage(PassRefPtr<CSSImageGeneratorValue> value)
+ : m_imageGeneratorValue(value)
+ , m_fixedSize(m_imageGeneratorValue->isFixedSize())
+{
+ m_isGeneratedImage = true;
+}
PassRefPtr<CSSValue> StyleGeneratedImage::cssValue() const
{
- return m_generator;
+ return m_imageGeneratorValue;
}
IntSize StyleGeneratedImage::imageSize(const RenderObject* renderer, float multiplier) const
{
if (m_fixedSize) {
- IntSize fixedSize = m_generator->fixedSize(renderer);
+ IntSize fixedSize = m_imageGeneratorValue->fixedSize(renderer);
if (multiplier == 1.0f)
return fixedSize;
@@ -68,18 +75,18 @@
void StyleGeneratedImage::addClient(RenderObject* renderer)
{
- m_generator->addClient(renderer, IntSize());
+ m_imageGeneratorValue->addClient(renderer, IntSize());
}
void StyleGeneratedImage::removeClient(RenderObject* renderer)
{
- m_generator->removeClient(renderer);
+ m_imageGeneratorValue->removeClient(renderer);
}
PassRefPtr<Image> StyleGeneratedImage::image(RenderObject* renderer, const IntSize& size) const
{
renderer->document()->styleSelector()->setStyle(renderer->style());
- return m_generator->image(renderer, size);
+ return m_imageGeneratorValue->image(renderer, size);
}
}
Modified: trunk/Source/WebCore/rendering/style/StyleGeneratedImage.h (101176 => 101177)
--- trunk/Source/WebCore/rendering/style/StyleGeneratedImage.h 2011-11-25 17:47:56 UTC (rev 101176)
+++ trunk/Source/WebCore/rendering/style/StyleGeneratedImage.h 2011-11-25 18:08:38 UTC (rev 101177)
@@ -33,12 +33,12 @@
class StyleGeneratedImage : public StyleImage {
public:
- static PassRefPtr<StyleGeneratedImage> create(CSSImageGeneratorValue* val, bool fixedSize)
+ static PassRefPtr<StyleGeneratedImage> create(CSSImageGeneratorValue* value)
{
- return adoptRef(new StyleGeneratedImage(val, fixedSize));
+ return adoptRef(new StyleGeneratedImage(value));
}
- virtual WrappedImagePtr data() const { return m_generator; }
+ virtual WrappedImagePtr data() const { return m_imageGeneratorValue.get(); }
virtual PassRefPtr<CSSValue> cssValue() const;
@@ -53,14 +53,9 @@
virtual PassRefPtr<Image> image(RenderObject*, const IntSize&) const;
private:
- StyleGeneratedImage(CSSImageGeneratorValue* val, bool fixedSize)
- : m_generator(val)
- , m_fixedSize(fixedSize)
- {
- m_isGeneratedImage = true;
- }
+ StyleGeneratedImage(PassRefPtr<CSSImageGeneratorValue>);
- CSSImageGeneratorValue* m_generator; // The generator holds a reference to us.
+ RefPtr<CSSImageGeneratorValue> m_imageGeneratorValue;
IntSize m_containerSize;
bool m_fixedSize;
};