Use is<>() / downcast<>() for Image subclasses
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 10 Oct 2014 23:32:45 +0000 (23:32 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 10 Oct 2014 23:32:45 +0000 (23:32 +0000)
https://bugs.webkit.org/show_bug.cgi?id=137625

Reviewed by Andreas Kling.

Use is<>() / downcast<>() for Image subclasses.

Source/WebCore:

No new tests, no behavior change.

* accessibility/AccessibilityRenderObject.cpp:
(WebCore::AccessibilityRenderObject::remoteSVGRootElement):
* loader/cache/CachedImage.cpp:
(WebCore::CachedImage::imageSizeForRenderer):
(WebCore::CachedImage::createImage):
* platform/graphics/BitmapImage.h:
* platform/graphics/Image.h:
* platform/mac/DragImageMac.mm:
(WebCore::createDragImageFromImage):
* rendering/RenderImage.cpp:
(WebCore::RenderImage::embeddedContentBox):
* svg/graphics/SVGImage.h:

Source/WebKit2:

* WebProcess/Plugins/PluginView.cpp:
(WebKit::PluginView::pluginSnapshotTimerFired):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@174623 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/accessibility/AccessibilityRenderObject.cpp
Source/WebCore/loader/cache/CachedImage.cpp
Source/WebCore/platform/graphics/BitmapImage.h
Source/WebCore/platform/graphics/Image.h
Source/WebCore/platform/mac/DragImageMac.mm
Source/WebCore/rendering/RenderImage.cpp
Source/WebCore/svg/graphics/SVGImage.h
Source/WebKit2/ChangeLog
Source/WebKit2/WebProcess/Plugins/PluginView.cpp

index 9e50b5f..758d745 100644 (file)
@@ -1,5 +1,29 @@
 2014-10-10  Chris Dumez  <cdumez@apple.com>
 
+        Use is<>() / downcast<>() for Image subclasses
+        https://bugs.webkit.org/show_bug.cgi?id=137625
+
+        Reviewed by Andreas Kling.
+
+        Use is<>() / downcast<>() for Image subclasses.
+
+        No new tests, no behavior change.
+
+        * accessibility/AccessibilityRenderObject.cpp:
+        (WebCore::AccessibilityRenderObject::remoteSVGRootElement):
+        * loader/cache/CachedImage.cpp:
+        (WebCore::CachedImage::imageSizeForRenderer):
+        (WebCore::CachedImage::createImage):
+        * platform/graphics/BitmapImage.h:
+        * platform/graphics/Image.h:
+        * platform/mac/DragImageMac.mm:
+        (WebCore::createDragImageFromImage):
+        * rendering/RenderImage.cpp:
+        (WebCore::RenderImage::embeddedContentBox):
+        * svg/graphics/SVGImage.h:
+
+2014-10-10  Chris Dumez  <cdumez@apple.com>
+
         Use is<>() / downcast<>() for RenderElement
         https://bugs.webkit.org/show_bug.cgi?id=137622
 
index ccb4083..cda2eb1 100644 (file)
@@ -2867,11 +2867,10 @@ AccessibilitySVGRoot* AccessibilityRenderObject::remoteSVGRootElement() const
         return nullptr;
     
     Image* image = cachedImage->image();
-    if (!image || !image->isSVGImage())
+    if (!is<SVGImage>(image))
         return nullptr;
     
-    SVGImage* svgImage = static_cast<SVGImage*>(image);
-    FrameView* frameView = svgImage->frameView();
+    FrameView* frameView = downcast<SVGImage>(*image).frameView();
     if (!frameView)
         return nullptr;
     Frame& frame = frameView->frame();
index 6a1d2b4..b0fda18 100644 (file)
@@ -271,17 +271,17 @@ LayoutSize CachedImage::imageSizeForRenderer(const RenderObject* renderer, float
     LayoutSize imageSize(m_image->size());
 
 #if ENABLE(CSS_IMAGE_ORIENTATION)
-    if (renderer && m_image->isBitmapImage()) {
+    if (renderer && is<BitmapImage>(*m_image)) {
         ImageOrientationDescription orientationDescription(renderer->shouldRespectImageOrientation(), renderer->style().imageOrientation());
         if (orientationDescription.respectImageOrientation() == RespectImageOrientation)
-            imageSize = LayoutSize(toBitmapImage(m_image.get())->sizeRespectingOrientation(orientationDescription));
+            imageSize = LayoutSize(downcast<BitmapImage>(*m_image).sizeRespectingOrientation(orientationDescription));
     }
 #else
-    if (m_image->isBitmapImage() && (renderer && renderer->shouldRespectImageOrientation() == RespectImageOrientation))
-        imageSize = LayoutSize(toBitmapImage(m_image.get())->sizeRespectingOrientation());
+    if (is<BitmapImage>(*m_image) && (renderer && renderer->shouldRespectImageOrientation() == RespectImageOrientation))
+        imageSize = LayoutSize(downcast<BitmapImage>(*m_image).sizeRespectingOrientation());
 #endif // ENABLE(CSS_IMAGE_ORIENTATION)
 
-    else if (m_image->isSVGImage() && sizeType == UsedSize) {
+    else if (is<SVGImage>(*m_image) && sizeType == UsedSize) {
         imageSize = LayoutSize(m_svgImageCache->imageSizeForRenderer(renderer));
     }
 
@@ -343,7 +343,7 @@ inline void CachedImage::createImage()
         m_image = svgImage.release();
     } else {
         m_image = BitmapImage::create(this);
-        toBitmapImage(m_image.get())->setAllowSubsampling(m_loader && m_loader->frameLoader()->frame().settings().imageSubsamplingEnabled());
+        downcast<BitmapImage>(*m_image).setAllowSubsampling(m_loader && m_loader->frameLoader()->frame().settings().imageSubsamplingEnabled());
     }
 
     if (m_image) {
index 9e45bb9..a0a0f24 100644 (file)
@@ -335,8 +335,8 @@ private:
     RefPtr<Image> m_cachedImage;
 };
 
-IMAGE_TYPE_CASTS(BitmapImage)
+} // namespace WebCore
 
-}
+SPECIALIZE_TYPE_TRAITS_IMAGE(BitmapImage)
 
-#endif
+#endif // BitmapImage_h
index 42617ed..8985719 100644 (file)
@@ -38,6 +38,7 @@
 #include <wtf/RefCounted.h>
 #include <wtf/RefPtr.h>
 #include <wtf/RetainPtr.h>
+#include <wtf/TypeCasts.h>
 #include <wtf/text/WTFString.h>
 
 #if USE(APPKIT)
@@ -202,9 +203,11 @@ private:
     FloatSize m_space;
 };
 
-#define IMAGE_TYPE_CASTS(ToClassName) \
-    TYPE_CASTS_BASE(ToClassName, Image, image, image->is##ToClassName(), image.is##ToClassName())
+} // namespace WebCore
 
-}
+#define SPECIALIZE_TYPE_TRAITS_IMAGE(ToClassName) \
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::ToClassName) \
+    static bool isType(const WebCore::Image& image) { return image.is##ToClassName(); } \
+SPECIALIZE_TYPE_TRAITS_END()
 
-#endif
+#endif // Image_h
index 9d0303d..173d081 100644 (file)
@@ -84,13 +84,13 @@ RetainPtr<NSImage> createDragImageFromImage(Image* image, ImageOrientationDescri
 {
     FloatSize size = image->size();
 
-    if (image->isBitmapImage()) {
+    if (is<BitmapImage>(*image)) {
         ImageOrientation orientation;
-        BitmapImage* bitmapImage = toBitmapImage(image);
-        IntSize sizeRespectingOrientation = bitmapImage->sizeRespectingOrientation(description);
+        BitmapImage& bitmapImage = downcast<BitmapImage>(*image);
+        IntSize sizeRespectingOrientation = bitmapImage.sizeRespectingOrientation(description);
 
         if (description.respectImageOrientation() == RespectImageOrientation)
-            orientation = bitmapImage->orientationForCurrentFrame();
+            orientation = bitmapImage.orientationForCurrentFrame();
 
         if (orientation != DefaultImageOrientation) {
             // Construct a correctly-rotated copy of the image to use as the drag image.
index 6b0bdae..75e46f2 100644 (file)
@@ -750,10 +750,10 @@ bool RenderImage::needsPreferredWidthsRecalculation() const
 RenderBox* RenderImage::embeddedContentBox() const
 {
     CachedImage* cachedImage = imageResource().cachedImage();
-    if (cachedImage && cachedImage->image() && cachedImage->image()->isSVGImage())
-        return static_cast<SVGImage*>(cachedImage->image())->embeddedContentBox();
+    if (cachedImage && is<SVGImage>(cachedImage->image()))
+        return downcast<SVGImage>(*cachedImage->image()).embeddedContentBox();
 
-    return 0;
+    return nullptr;
 }
 
 } // namespace WebCore
index 63d76bc..3e54b19 100644 (file)
@@ -106,8 +106,8 @@ private:
 
 bool isInSVGImage(const Element*);
 
-IMAGE_TYPE_CASTS(SVGImage)
+} // namespace WebCore
 
-}
+SPECIALIZE_TYPE_TRAITS_IMAGE(SVGImage)
 
 #endif // SVGImage_h
index c7f49e6..9bfd1ad 100644 (file)
@@ -1,5 +1,17 @@
 2014-10-10  Chris Dumez  <cdumez@apple.com>
 
+        Use is<>() / downcast<>() for Image subclasses
+        https://bugs.webkit.org/show_bug.cgi?id=137625
+
+        Reviewed by Andreas Kling.
+
+        Use is<>() / downcast<>() for Image subclasses.
+
+        * WebProcess/Plugins/PluginView.cpp:
+        (WebKit::PluginView::pluginSnapshotTimerFired):
+
+2014-10-10  Chris Dumez  <cdumez@apple.com>
+
         Use is<>() / downcast<>() for GraphicsLayer subclasses
         https://bugs.webkit.org/show_bug.cgi?id=137595
 
index 6e812cd..0208071 100644 (file)
@@ -1729,7 +1729,7 @@ void PluginView::pluginSnapshotTimerFired()
 
         if (snapshotImage) {
 #if ENABLE(PRIMARY_SNAPSHOTTED_PLUGIN_HEURISTIC)
-            bool snapshotIsAlmostSolidColor = isAlmostSolidColor(toBitmapImage(snapshotImage.get()));
+            bool snapshotIsAlmostSolidColor = isAlmostSolidColor(downcast<BitmapImage>(snapshotImage.get()));
             snapshotFound = !snapshotIsAlmostSolidColor;
 #endif