1 /* 2 * Copyright (C) 1999 Lars Knoll (knoll (at) kde.org) 3 * (C) 1999 Antti Koivisto (koivisto (at) kde.org) 4 * (C) 2006 Allan Sandfeld Jensen (kde (at) carewolf.com) 5 * (C) 2006 Samuel Weinig (sam.weinig (at) gmail.com) 6 * Copyright (C) 2004, 2005, 2006, 2007, 2009, 2010 Apple Inc. All rights reserved. 7 * 8 * This library is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU Library General Public 10 * License as published by the Free Software Foundation; either 11 * version 2 of the License, or (at your option) any later version. 12 * 13 * This library is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 * Library General Public License for more details. 17 * 18 * You should have received a copy of the GNU Library General Public License 19 * along with this library; see the file COPYING.LIB. If not, write to 20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 21 * Boston, MA 02110-1301, USA. 22 * 23 */ 24 25 #ifndef RenderImage_h 26 #define RenderImage_h 27 28 #include "RenderReplaced.h" 29 30 namespace WebCore { 31 32 class HTMLMapElement; 33 34 class RenderImage : public RenderReplaced { 35 public: 36 RenderImage(Node*); 37 virtual ~RenderImage(); 38 39 bool setImageSizeForAltText(CachedImage* newImage = 0); 40 41 void updateAltText(); 42 43 void setCachedImage(CachedImage*); 44 CachedImage* cachedImage() const { return m_cachedImage.get(); } 45 46 HTMLMapElement* imageMap() const; 47 48 void resetAnimation(); 49 50 virtual bool hasImage() const { return m_cachedImage; } 51 52 void highQualityRepaintTimerFired(Timer<RenderImage>*); 53 54 protected: 55 virtual Image* image(int /* width */ = 0, int /* height */ = 0) { return m_cachedImage ? m_cachedImage->image() : nullImage(); } 56 virtual bool errorOccurred() const { return m_cachedImage && m_cachedImage->errorOccurred(); } 57 58 virtual void imageChanged(WrappedImagePtr, const IntRect* = 0); 59 60 virtual void paintIntoRect(GraphicsContext*, const IntRect&); 61 void paintFocusRings(PaintInfo&, const RenderStyle*); 62 virtual void paint(PaintInfo&, int tx, int ty); 63 64 bool isWidthSpecified() const; 65 bool isHeightSpecified() const; 66 67 virtual void intrinsicSizeChanged() { imageChanged(imagePtr()); } 68 69 private: 70 virtual const char* renderName() const { return "RenderImage"; } 71 72 virtual bool isImage() const { return true; } 73 virtual bool isRenderImage() const { return true; } 74 75 virtual void paintReplaced(PaintInfo&, int tx, int ty); 76 77 virtual int minimumReplacedHeight() const; 78 79 virtual void notifyFinished(CachedResource*); 80 virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, int x, int y, int tx, int ty, HitTestAction); 81 82 virtual int calcReplacedWidth(bool includeMaxWidth = true) const; 83 virtual int calcReplacedHeight() const; 84 85 virtual void calcPrefWidths(); 86 87 virtual bool usesImageContainerSize() const { return m_cachedImage ? m_cachedImage->usesImageContainerSize() : false; } 88 virtual void setImageContainerSize(const IntSize& size) const { if (m_cachedImage) m_cachedImage->setImageContainerSize(size); } 89 virtual bool imageHasRelativeWidth() const { return m_cachedImage ? m_cachedImage->imageHasRelativeWidth() : false; } 90 virtual bool imageHasRelativeHeight() const { return m_cachedImage ? m_cachedImage->imageHasRelativeHeight() : false; } 91 virtual IntSize imageSize(float multiplier) const { return m_cachedImage ? m_cachedImage->imageSize(multiplier) : IntSize(); } 92 virtual WrappedImagePtr imagePtr() const { return m_cachedImage.get(); } 93 94 int calcAspectRatioWidth() const; 95 int calcAspectRatioHeight() const; 96 97 protected: 98 // The image we are rendering. 99 CachedResourceHandle<CachedImage> m_cachedImage; 100 101 private: 102 // Text to display as long as the image isn't available. 103 String m_altText; 104 105 static Image* nullImage(); 106 107 friend class RenderImageScaleObserver; 108 }; 109 110 inline RenderImage* toRenderImage(RenderObject* object) 111 { 112 ASSERT(!object || object->isRenderImage()); 113 return static_cast<RenderImage*>(object); 114 } 115 116 inline const RenderImage* toRenderImage(const RenderObject* object) 117 { 118 ASSERT(!object || object->isRenderImage()); 119 return static_cast<const RenderImage*>(object); 120 } 121 122 // This will catch anyone doing an unnecessary cast. 123 void toRenderImage(const RenderImage*); 124 125 } // namespace WebCore 126 127 #endif // RenderImage_h 128