RenderImage.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
  3. * (C) 1999 Antti Koivisto (koivisto@kde.org)
  4. * (C) 2006 Allan Sandfeld Jensen (kde@carewolf.com)
  5. * (C) 2006 Samuel Weinig (sam.weinig@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. #ifndef RenderImage_h
  25. #define RenderImage_h
  26. #include "RenderImageResource.h"
  27. #include "RenderReplaced.h"
  28. namespace WebCore {
  29. class HTMLAreaElement;
  30. class HTMLMapElement;
  31. class RenderImage : public RenderReplaced {
  32. public:
  33. RenderImage(Element*);
  34. virtual ~RenderImage();
  35. static RenderImage* createAnonymous(Document*);
  36. void setImageResource(PassOwnPtr<RenderImageResource>);
  37. RenderImageResource* imageResource() { return m_imageResource.get(); }
  38. const RenderImageResource* imageResource() const { return m_imageResource.get(); }
  39. CachedImage* cachedImage() const { return m_imageResource ? m_imageResource->cachedImage() : 0; }
  40. bool setImageSizeForAltText(CachedImage* newImage = 0);
  41. void updateAltText();
  42. HTMLMapElement* imageMap() const;
  43. void areaElementFocusChanged(HTMLAreaElement*);
  44. void highQualityRepaintTimerFired(Timer<RenderImage>*);
  45. void setIsGeneratedContent(bool generated = true) { m_isGeneratedContent = generated; }
  46. bool isGeneratedContent() const { return m_isGeneratedContent; }
  47. String altText() const { return m_altText; }
  48. protected:
  49. virtual bool needsPreferredWidthsRecalculation() const;
  50. virtual RenderBox* embeddedContentBox() const;
  51. virtual void computeIntrinsicRatioInformation(FloatSize& intrinsicSize, double& intrinsicRatio, bool& isPercentageIntrinsicSize) const;
  52. virtual bool foregroundIsKnownToBeOpaqueInRect(const LayoutRect& localRect, unsigned maxDepthToTest) const OVERRIDE;
  53. virtual void styleDidChange(StyleDifference, const RenderStyle*);
  54. virtual void imageChanged(WrappedImagePtr, const IntRect* = 0);
  55. virtual void paintIntoRect(GraphicsContext*, const LayoutRect&);
  56. virtual void paint(PaintInfo&, const LayoutPoint&);
  57. virtual void layout();
  58. virtual void intrinsicSizeChanged()
  59. {
  60. if (m_imageResource)
  61. imageChanged(m_imageResource->imagePtr());
  62. }
  63. private:
  64. virtual const char* renderName() const { return "RenderImage"; }
  65. virtual bool isImage() const { return true; }
  66. virtual bool isRenderImage() const { return true; }
  67. virtual void paintReplaced(PaintInfo&, const LayoutPoint&);
  68. virtual bool computeBackgroundIsKnownToBeObscured() OVERRIDE;
  69. virtual LayoutUnit minimumReplacedHeight() const OVERRIDE;
  70. virtual void notifyFinished(CachedResource*);
  71. virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction) OVERRIDE;
  72. virtual bool boxShadowShouldBeAppliedToBackground(BackgroundBleedAvoidance, InlineFlowBox*) const OVERRIDE;
  73. IntSize imageSizeForError(CachedImage*) const;
  74. void imageDimensionsChanged(bool imageSizeChanged, const IntRect* = 0);
  75. bool updateIntrinsicSizeIfNeeded(const LayoutSize&, bool imageSizeChanged);
  76. void paintAreaElementFocusRing(PaintInfo&);
  77. // Text to display as long as the image isn't available.
  78. String m_altText;
  79. OwnPtr<RenderImageResource> m_imageResource;
  80. bool m_needsToSetSizeForAltText;
  81. bool m_didIncrementVisuallyNonEmptyPixelCount;
  82. bool m_isGeneratedContent;
  83. friend class RenderImageScaleObserver;
  84. };
  85. inline RenderImage* toRenderImage(RenderObject* object)
  86. {
  87. ASSERT_WITH_SECURITY_IMPLICATION(!object || object->isRenderImage());
  88. return static_cast<RenderImage*>(object);
  89. }
  90. inline const RenderImage* toRenderImage(const RenderObject* object)
  91. {
  92. ASSERT_WITH_SECURITY_IMPLICATION(!object || object->isRenderImage());
  93. return static_cast<const RenderImage*>(object);
  94. }
  95. // This will catch anyone doing an unnecessary cast.
  96. void toRenderImage(const RenderImage*);
  97. } // namespace WebCore
  98. #endif // RenderImage_h