Home | History | Annotate | Download | only in rendering
      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 "core/rendering/RenderImageResource.h"
     29 #include "core/rendering/RenderReplaced.h"
     30 
     31 namespace WebCore {
     32 
     33 class HTMLAreaElement;
     34 class HTMLMapElement;
     35 
     36 class RenderImage : public RenderReplaced {
     37 public:
     38     RenderImage(Element*);
     39     virtual ~RenderImage();
     40 
     41     static RenderImage* createAnonymous(Document*);
     42 
     43     void setImageResource(PassOwnPtr<RenderImageResource>);
     44 
     45     RenderImageResource* imageResource() { return m_imageResource.get(); }
     46     const RenderImageResource* imageResource() const { return m_imageResource.get(); }
     47     ImageResource* cachedImage() const { return m_imageResource ? m_imageResource->cachedImage() : 0; }
     48 
     49     bool setImageSizeForAltText(ImageResource* newImage = 0);
     50 
     51     void updateAltText();
     52 
     53     HTMLMapElement* imageMap() const;
     54     void areaElementFocusChanged(HTMLAreaElement*);
     55 
     56     void highQualityRepaintTimerFired(Timer<RenderImage>*);
     57 
     58     void setIsGeneratedContent(bool generated = true) { m_isGeneratedContent = generated; }
     59 
     60     bool isGeneratedContent() const { return m_isGeneratedContent; }
     61 
     62     String altText() const { return m_altText; }
     63 
     64 protected:
     65     virtual bool needsPreferredWidthsRecalculation() const OVERRIDE FINAL;
     66     virtual RenderBox* embeddedContentBox() const OVERRIDE FINAL;
     67     virtual void computeIntrinsicRatioInformation(FloatSize& intrinsicSize, double& intrinsicRatio, bool& isPercentageIntrinsicSize) const OVERRIDE FINAL;
     68 
     69     virtual void styleDidChange(StyleDifference, const RenderStyle*) OVERRIDE FINAL;
     70 
     71     virtual void imageChanged(WrappedImagePtr, const IntRect* = 0);
     72 
     73     void paintIntoRect(GraphicsContext*, const LayoutRect&);
     74     virtual void paint(PaintInfo&, const LayoutPoint&) OVERRIDE FINAL;
     75     virtual void layout();
     76 
     77     virtual void intrinsicSizeChanged()
     78     {
     79         if (m_imageResource)
     80             imageChanged(m_imageResource->imagePtr());
     81     }
     82 
     83 private:
     84     virtual const char* renderName() const { return "RenderImage"; }
     85 
     86     virtual bool isImage() const { return true; }
     87     virtual bool isRenderImage() const OVERRIDE FINAL { return true; }
     88 
     89     virtual void paintReplaced(PaintInfo&, const LayoutPoint&);
     90 
     91     virtual bool foregroundIsKnownToBeOpaqueInRect(const LayoutRect& localRect, unsigned maxDepthToTest) const OVERRIDE FINAL;
     92     virtual bool computeBackgroundIsKnownToBeObscured() OVERRIDE FINAL;
     93 
     94     virtual LayoutUnit minimumReplacedHeight() const OVERRIDE;
     95 
     96     virtual void notifyFinished(Resource*) OVERRIDE FINAL;
     97     virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction) OVERRIDE FINAL;
     98 
     99     virtual bool boxShadowShouldBeAppliedToBackground(BackgroundBleedAvoidance, InlineFlowBox*) const OVERRIDE FINAL;
    100 
    101     IntSize imageSizeForError(ImageResource*) const;
    102     void imageDimensionsChanged(bool imageSizeChanged, const IntRect* = 0);
    103     bool updateIntrinsicSizeIfNeeded(const LayoutSize&, bool imageSizeChanged);
    104 
    105     void paintAreaElementFocusRing(PaintInfo&);
    106 
    107     // Text to display as long as the image isn't available.
    108     String m_altText;
    109     OwnPtr<RenderImageResource> m_imageResource;
    110     bool m_needsToSetSizeForAltText;
    111     bool m_didIncrementVisuallyNonEmptyPixelCount;
    112     bool m_isGeneratedContent;
    113 
    114     friend class RenderImageScaleObserver;
    115 };
    116 
    117 inline RenderImage* toRenderImage(RenderObject* object)
    118 {
    119     ASSERT_WITH_SECURITY_IMPLICATION(!object || object->isRenderImage());
    120     return static_cast<RenderImage*>(object);
    121 }
    122 
    123 inline const RenderImage* toRenderImage(const RenderObject* object)
    124 {
    125     ASSERT_WITH_SECURITY_IMPLICATION(!object || object->isRenderImage());
    126     return static_cast<const RenderImage*>(object);
    127 }
    128 
    129 // This will catch anyone doing an unnecessary cast.
    130 void toRenderImage(const RenderImage*);
    131 
    132 } // namespace WebCore
    133 
    134 #endif // RenderImage_h
    135