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 blink {
     32 
     33 class HTMLAreaElement;
     34 class HTMLMapElement;
     35 
     36 class RenderImage : public RenderReplaced {
     37 public:
     38     // These are the paddings to use when displaying either alt text or an image.
     39     static const unsigned short paddingWidth = 4;
     40     static const unsigned short paddingHeight = 4;
     41 
     42     RenderImage(Element*);
     43     virtual ~RenderImage();
     44     virtual void destroy() OVERRIDE;
     45 
     46     static RenderImage* createAnonymous(Document*);
     47 
     48     void setImageResource(PassOwnPtr<RenderImageResource>);
     49 
     50     RenderImageResource* imageResource() { return m_imageResource.get(); }
     51     const RenderImageResource* imageResource() const { return m_imageResource.get(); }
     52     ImageResource* cachedImage() const { return m_imageResource ? m_imageResource->cachedImage() : 0; }
     53 
     54     bool setImageSizeForAltText(ImageResource* newImage = 0);
     55 
     56     void updateAltText();
     57 
     58     HTMLMapElement* imageMap() const;
     59     void areaElementFocusChanged(HTMLAreaElement*);
     60 
     61     void highQualityRepaintTimerFired(Timer<RenderImage>*);
     62 
     63     void setIsGeneratedContent(bool generated = true) { m_isGeneratedContent = generated; }
     64 
     65     bool isGeneratedContent() const { return m_isGeneratedContent; }
     66 
     67     String altText() const { return m_altText; }
     68 
     69     inline void setImageDevicePixelRatio(float factor) { m_imageDevicePixelRatio = factor; }
     70     float imageDevicePixelRatio() const { return m_imageDevicePixelRatio; }
     71 
     72     virtual void intrinsicSizeChanged() OVERRIDE
     73     {
     74         if (m_imageResource)
     75             imageChanged(m_imageResource->imagePtr());
     76     }
     77 
     78 protected:
     79     virtual bool needsPreferredWidthsRecalculation() const OVERRIDE FINAL;
     80     virtual RenderBox* embeddedContentBox() const OVERRIDE FINAL;
     81     virtual void computeIntrinsicRatioInformation(FloatSize& intrinsicSize, double& intrinsicRatio) const OVERRIDE FINAL;
     82 
     83     virtual void imageChanged(WrappedImagePtr, const IntRect* = 0) OVERRIDE;
     84 
     85     virtual void paint(PaintInfo&, const LayoutPoint&) OVERRIDE FINAL;
     86     virtual void layout() OVERRIDE;
     87     virtual bool updateImageLoadingPriorities() OVERRIDE FINAL;
     88 
     89 private:
     90     virtual const char* renderName() const OVERRIDE { return "RenderImage"; }
     91 
     92     virtual bool isImage() const OVERRIDE { return true; }
     93     virtual bool isRenderImage() const OVERRIDE FINAL { return true; }
     94 
     95     virtual void paintReplaced(PaintInfo&, const LayoutPoint&) OVERRIDE;
     96 
     97     virtual bool foregroundIsKnownToBeOpaqueInRect(const LayoutRect& localRect, unsigned maxDepthToTest) const OVERRIDE FINAL;
     98     virtual bool computeBackgroundIsKnownToBeObscured() OVERRIDE FINAL;
     99 
    100     virtual LayoutUnit minimumReplacedHeight() const OVERRIDE;
    101 
    102     virtual void notifyFinished(Resource*) OVERRIDE FINAL;
    103     virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction) OVERRIDE FINAL;
    104 
    105     virtual bool boxShadowShouldBeAppliedToBackground(BackgroundBleedAvoidance, InlineFlowBox*) const OVERRIDE FINAL;
    106 
    107     IntSize imageSizeForError(ImageResource*) const;
    108     void paintInvalidationOrMarkForLayout(bool imageSizeChanged, const IntRect* = 0);
    109     void updateIntrinsicSizeIfNeeded(const LayoutSize&);
    110     // Update the size of the image to be rendered. Object-fit may cause this to be different from the CSS box's content rect.
    111     void updateInnerContentRect();
    112 
    113     // Text to display as long as the image isn't available.
    114     String m_altText;
    115     OwnPtr<RenderImageResource> m_imageResource;
    116     bool m_didIncrementVisuallyNonEmptyPixelCount;
    117     bool m_isGeneratedContent;
    118     float m_imageDevicePixelRatio;
    119 
    120     friend class RenderImageScaleObserver;
    121 };
    122 
    123 DEFINE_RENDER_OBJECT_TYPE_CASTS(RenderImage, isRenderImage());
    124 
    125 } // namespace blink
    126 
    127 #endif // RenderImage_h
    128