Commit bcce4080 authored by weinig@apple.com's avatar weinig@apple.com

2009-02-04 Sam Weinig <sam@webkit.org>

        Reviewed by David Hyatt.

        Add toRenderImage methods for casting RenderObjects to RenderImages.  The methods will assert if the object
        is not a RenderImage.  Also add a toRenderImage method that takes a RenderImage but returns void and that
        is unimplemented.  This method will catch anyone trying to do a cast when the object is already a RenderImage.

        * html/HTMLAnchorElement.cpp:
        (WebCore::HTMLAnchorElement::defaultEventHandler):
        * html/HTMLEmbedElement.cpp:
        (WebCore::HTMLEmbedElement::attach):
        * html/HTMLImageElement.cpp:
        (WebCore::HTMLImageElement::parseMappedAttribute):
        (WebCore::HTMLImageElement::attach):
        * html/HTMLInputElement.cpp:
        (WebCore::HTMLInputElement::parseMappedAttribute):
        (WebCore::HTMLInputElement::attach):
        * html/HTMLObjectElement.cpp:
        (WebCore::HTMLObjectElement::attach):
        * html/HTMLVideoElement.cpp:
        (WebCore::HTMLVideoElement::attach):
        * loader/ImageLoader.cpp:
        (WebCore::ImageLoader::setImage):
        (WebCore::ImageLoader::updateFromElement):
        (WebCore::ImageLoader::notifyFinished):
        * page/AccessibilityRenderObject.cpp:
        (WebCore::AccessibilityRenderObject::accessibilityIsIgnored):
        (WebCore::AccessibilityRenderObject::addChildren):
        * page/DragController.cpp:
        (WebCore::getCachedImage):
        (WebCore::getImage):
        * platform/mac/PasteboardMac.mm:
        (WebCore::Pasteboard::writeImage):
        * rendering/RenderImage.h:
        (WebCore::toRenderImage):
        * wml/WMLImageElement.cpp:
        (WebCore::WMLImageElement::parseMappedAttribute):
        (WebCore::WMLImageElement::attach):



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@40638 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 7a16abc9
2009-02-04 Sam Weinig <sam@webkit.org>
Reviewed by David Hyatt.
Add toRenderImage methods for casting RenderObjects to RenderImages. The methods will assert if the object
is not a RenderImage. Also add a toRenderImage method that takes a RenderImage but returns void and that
is unimplemented. This method will catch anyone trying to do a cast when the object is already a RenderImage.
* html/HTMLAnchorElement.cpp:
(WebCore::HTMLAnchorElement::defaultEventHandler):
* html/HTMLEmbedElement.cpp:
(WebCore::HTMLEmbedElement::attach):
* html/HTMLImageElement.cpp:
(WebCore::HTMLImageElement::parseMappedAttribute):
(WebCore::HTMLImageElement::attach):
* html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::parseMappedAttribute):
(WebCore::HTMLInputElement::attach):
* html/HTMLObjectElement.cpp:
(WebCore::HTMLObjectElement::attach):
* html/HTMLVideoElement.cpp:
(WebCore::HTMLVideoElement::attach):
* loader/ImageLoader.cpp:
(WebCore::ImageLoader::setImage):
(WebCore::ImageLoader::updateFromElement):
(WebCore::ImageLoader::notifyFinished):
* page/AccessibilityRenderObject.cpp:
(WebCore::AccessibilityRenderObject::accessibilityIsIgnored):
(WebCore::AccessibilityRenderObject::addChildren):
* page/DragController.cpp:
(WebCore::getCachedImage):
(WebCore::getImage):
* platform/mac/PasteboardMac.mm:
(WebCore::Pasteboard::writeImage):
* rendering/RenderImage.h:
(WebCore::toRenderImage):
* wml/WMLImageElement.cpp:
(WebCore::WMLImageElement::parseMappedAttribute):
(WebCore::WMLImageElement::attach):
2009-02-04 Jungshik Shin <jshin@chromium.org>
Reviewed by Eric Seidel and Dave Hyatt.
......@@ -199,7 +199,7 @@ void HTMLAnchorElement::defaultEventHandler(Event* evt)
if (evt->target()->toNode()->hasTagName(imgTag)) {
HTMLImageElement* img = static_cast<HTMLImageElement*>(evt->target()->toNode());
if (img && img->isServerMap()) {
RenderImage* r = static_cast<RenderImage*>(img->renderer());
RenderImage* r = toRenderImage(img->renderer());
if (r && e) {
// FIXME: broken with transforms
FloatPoint absPos = r->localToAbsolute();
......
......@@ -164,7 +164,7 @@ void HTMLEmbedElement::attach()
m_imageLoader->updateFromElement();
if (renderer())
static_cast<RenderImage*>(renderer())->setCachedImage(m_imageLoader->image());
toRenderImage(renderer())->setCachedImage(m_imageLoader->image());
}
}
......
......@@ -80,7 +80,7 @@ void HTMLImageElement::parseMappedAttribute(MappedAttribute* attr)
const QualifiedName& attrName = attr->name();
if (attrName == altAttr) {
if (renderer() && renderer()->isImage())
static_cast<RenderImage*>(renderer())->updateAltText();
toRenderImage(renderer())->updateAltText();
} else if (attrName == srcAttr)
m_imageLoader.updateFromElementIgnoringPreviousError();
else if (attrName == widthAttr)
......@@ -166,7 +166,7 @@ void HTMLImageElement::attach()
HTMLElement::attach();
if (renderer() && renderer()->isImage()) {
RenderImage* imageObj = static_cast<RenderImage*>(renderer());
RenderImage* imageObj = toRenderImage(renderer());
if (imageObj->hasImage())
return;
imageObj->setCachedImage(m_imageLoader.image());
......
......@@ -562,7 +562,7 @@ void HTMLInputElement::parseMappedAttribute(MappedAttribute *attr)
InputElement::parseSizeAttribute(m_data, attr);
else if (attr->name() == altAttr) {
if (renderer() && inputType() == IMAGE)
static_cast<RenderImage*>(renderer())->updateAltText();
toRenderImage(renderer())->updateAltText();
} else if (attr->name() == srcAttr) {
if (renderer() && inputType() == IMAGE) {
if (!m_imageLoader)
......@@ -692,7 +692,7 @@ void HTMLInputElement::attach()
m_imageLoader.set(new HTMLImageLoader(this));
m_imageLoader->updateFromElement();
if (renderer()) {
RenderImage* imageObj = static_cast<RenderImage*>(renderer());
RenderImage* imageObj = toRenderImage(renderer());
imageObj->setCachedImage(m_imageLoader->image());
// If we have no image at all because we have no src attribute, set
......
......@@ -156,7 +156,7 @@ void HTMLObjectElement::attach()
return;
if (renderer())
static_cast<RenderImage*>(renderer())->setCachedImage(m_imageLoader->image());
toRenderImage(renderer())->setCachedImage(m_imageLoader->image());
}
}
......
......@@ -68,7 +68,7 @@ void HTMLVideoElement::attach()
m_imageLoader.set(new HTMLImageLoader(this));
m_imageLoader->updateFromElement();
if (renderer() && renderer()->isImage()) {
RenderImage* imageRenderer = static_cast<RenderImage*>(renderer());
RenderImage* imageRenderer = toRenderImage(renderer());
imageRenderer->setCachedImage(m_imageLoader->image());
}
}
......
......@@ -65,7 +65,7 @@ void ImageLoader::setImage(CachedImage* newImage)
if (!renderer->isImage())
return;
static_cast<RenderImage*>(renderer)->resetAnimation();
toRenderImage(renderer)->resetAnimation();
}
}
......@@ -123,7 +123,7 @@ void ImageLoader::updateFromElement()
if (!renderer->isImage())
return;
static_cast<RenderImage*>(renderer)->resetAnimation();
toRenderImage(renderer)->resetAnimation();
}
}
......@@ -146,7 +146,7 @@ void ImageLoader::notifyFinished(CachedResource*)
if (!renderer->isImage())
return;
static_cast<RenderImage*>(renderer)->setCachedImage(m_image.get());
toRenderImage(renderer)->setCachedImage(m_image.get());
}
}
......
......@@ -1203,7 +1203,7 @@ bool AccessibilityRenderObject::accessibilityIsIgnored() const
}
// check for one-dimensional image
RenderImage* image = static_cast<RenderImage*>(m_renderer);
RenderImage* image = toRenderImage(m_renderer);
if (image->height() <= 1 || image->width() <= 1)
return true;
......@@ -2332,7 +2332,7 @@ void AccessibilityRenderObject::addChildren()
// for a RenderImage, add the <area> elements as individual accessibility objects
if (m_renderer->isRenderImage()) {
HTMLMapElement* map = static_cast<RenderImage*>(m_renderer)->imageMap();
HTMLMapElement* map = toRenderImage(m_renderer)->imageMap();
if (map) {
for (Node* current = map->firstChild(); current; current = current->traverseNextNode(map)) {
......
......@@ -531,7 +531,7 @@ static CachedImage* getCachedImage(Element* element)
RenderObject* renderer = element->renderer();
if (!renderer || !renderer->isImage())
return 0;
RenderImage* image = static_cast<RenderImage*>(renderer);
RenderImage* image = toRenderImage(renderer);
return image->cachedImage();
}
......@@ -542,7 +542,7 @@ static Image* getImage(Element* element)
if (!renderer || !renderer->isImage())
return 0;
RenderImage* image = static_cast<RenderImage*>(renderer);
RenderImage* image = toRenderImage(renderer);
if (image->cachedImage() && !image->cachedImage()->errorOccurred())
return image->cachedImage()->image();
return 0;
......
......@@ -278,7 +278,7 @@ void Pasteboard::writeImage(Node* node, const KURL& url, const String& title)
ASSERT(cocoaURL);
ASSERT(node->renderer() && node->renderer()->isImage());
RenderImage* renderer = static_cast<RenderImage*>(node->renderer());
RenderImage* renderer = toRenderImage(node->renderer());
CachedImage* cachedImage = static_cast<CachedImage*>(renderer->cachedImage());
ASSERT(cachedImage);
......
......@@ -102,6 +102,21 @@ protected:
friend class RenderImageScaleObserver;
};
inline RenderImage* toRenderImage(RenderObject* o)
{
ASSERT(!o || o->isRenderImage());
return static_cast<RenderImage*>(o);
}
inline const RenderImage* toRenderImage(const RenderObject* o)
{
ASSERT(!o || o->isRenderImage());
return static_cast<const RenderImage*>(o);
}
// This will catch anyone doing an unnecessary cast.
void toRenderImage(const RenderImage*);
} // namespace WebCore
#endif // RenderImage_h
......@@ -70,7 +70,7 @@ void WMLImageElement::parseMappedAttribute(MappedAttribute* attr)
if (attrName == HTMLNames::altAttr) {
if (renderer() && renderer()->isImage())
static_cast<RenderImage*>(renderer())->updateAltText();
toRenderImage(renderer())->updateAltText();
} else if (attrName == HTMLNames::srcAttr || attrName == localsrcAttr)
m_imageLoader.updateFromElementIgnoringPreviousError();
else if (attrName == HTMLNames::widthAttr)
......@@ -94,7 +94,7 @@ void WMLImageElement::attach()
WMLElement::attach();
if (renderer() && renderer()->isImage()) {
RenderImage* imageObj = static_cast<RenderImage*>(renderer());
RenderImage* imageObj = toRenderImage(renderer());
if (imageObj->hasImage())
return;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment