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, 2011 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 "RenderImageResource.h" 29 #include "RenderReplaced.h" 30 31 namespace WebCore { 32 33 class HTMLAreaElement; 34 class HTMLMapElement; 35 36 class RenderImage : public RenderReplaced { 37 public: 38 RenderImage(Node*); 39 virtual ~RenderImage(); 40 41 void setImageResource(PassOwnPtr<RenderImageResource>); 42 43 RenderImageResource* imageResource() { return m_imageResource.get(); } 44 const RenderImageResource* imageResource() const { return m_imageResource.get(); } 45 CachedImage* cachedImage() const { return m_imageResource ? m_imageResource->cachedImage() : 0; } 46 47 bool setImageSizeForAltText(CachedImage* newImage = 0); 48 49 void updateAltText(); 50 51 HTMLMapElement* imageMap() const; 52 void areaElementFocusChanged(HTMLAreaElement*); 53 54 void highQualityRepaintTimerFired(Timer<RenderImage>*); 55 56 protected: 57 virtual void styleDidChange(StyleDifference, const RenderStyle*); 58 59 virtual void imageChanged(WrappedImagePtr, const IntRect* = 0); 60 61 virtual void paintIntoRect(GraphicsContext*, const IntRect&); 62 virtual void paint(PaintInfo&, int tx, int ty); 63 64 bool isLogicalWidthSpecified() const; 65 bool isLogicalHeightSpecified() const; 66 67 virtual void intrinsicSizeChanged() 68 { 69 if (m_imageResource) 70 imageChanged(m_imageResource->imagePtr()); 71 } 72 73 private: 74 virtual const char* renderName() const { return "RenderImage"; } 75 76 virtual bool isImage() const { return true; } 77 virtual bool isRenderImage() const { return true; } 78 79 virtual void paintReplaced(PaintInfo&, int tx, int ty); 80 81 virtual int minimumReplacedHeight() const; 82 83 virtual void notifyFinished(CachedResource*); 84 virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, int x, int y, int tx, int ty, HitTestAction); 85 86 virtual int computeReplacedLogicalWidth(bool includeMaxWidth = true) const; 87 virtual int computeReplacedLogicalHeight() const; 88 89 IntSize imageSizeForError(CachedImage*) const; 90 void imageDimensionsChanged(bool imageSizeChanged, const IntRect* = 0); 91 92 int calcAspectRatioLogicalWidth() const; 93 int calcAspectRatioLogicalHeight() const; 94 95 void paintAreaElementFocusRing(PaintInfo&); 96 97 // Text to display as long as the image isn't available. 98 String m_altText; 99 OwnPtr<RenderImageResource> m_imageResource; 100 bool m_needsToSetSizeForAltText; 101 102 friend class RenderImageScaleObserver; 103 }; 104 105 inline RenderImage* toRenderImage(RenderObject* object) 106 { 107 ASSERT(!object || object->isRenderImage()); 108 return static_cast<RenderImage*>(object); 109 } 110 111 inline const RenderImage* toRenderImage(const RenderObject* object) 112 { 113 ASSERT(!object || object->isRenderImage()); 114 return static_cast<const RenderImage*>(object); 115 } 116 117 // This will catch anyone doing an unnecessary cast. 118 void toRenderImage(const RenderImage*); 119 120 } // namespace WebCore 121 122 #endif // RenderImage_h 123