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.
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.
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.
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.
28 #include "core/rendering/RenderImageResource.h"
29 #include "core/rendering/RenderReplaced.h"
33 class HTMLAreaElement;
36 class RenderImage : public RenderReplaced {
38 RenderImage(Element*);
39 virtual ~RenderImage();
40 virtual void destroy() OVERRIDE;
42 static RenderImage* createAnonymous(Document*);
44 void setImageResource(PassOwnPtr<RenderImageResource>);
46 RenderImageResource* imageResource() { return m_imageResource.get(); }
47 const RenderImageResource* imageResource() const { return m_imageResource.get(); }
48 ImageResource* cachedImage() const { return m_imageResource ? m_imageResource->cachedImage() : 0; }
50 bool setImageSizeForAltText(ImageResource* newImage = 0);
54 HTMLMapElement* imageMap() const;
55 void areaElementFocusChanged(HTMLAreaElement*);
57 void highQualityRepaintTimerFired(Timer<RenderImage>*);
59 void setIsGeneratedContent(bool generated = true) { m_isGeneratedContent = generated; }
61 bool isGeneratedContent() const { return m_isGeneratedContent; }
63 String altText() const { return m_altText; }
65 inline void setImageDevicePixelRatio(float factor) { m_imageDevicePixelRatio = factor; }
66 float imageDevicePixelRatio() const { return m_imageDevicePixelRatio; }
68 virtual void intrinsicSizeChanged() OVERRIDE
71 imageChanged(m_imageResource->imagePtr());
75 virtual bool needsPreferredWidthsRecalculation() const OVERRIDE FINAL;
76 virtual RenderBox* embeddedContentBox() const OVERRIDE FINAL;
77 virtual void computeIntrinsicRatioInformation(FloatSize& intrinsicSize, double& intrinsicRatio) const OVERRIDE FINAL;
79 virtual void imageChanged(WrappedImagePtr, const IntRect* = 0) OVERRIDE;
81 void paintIntoRect(GraphicsContext*, const LayoutRect&);
82 virtual void paint(PaintInfo&, const LayoutPoint&) OVERRIDE FINAL;
83 virtual void layout() OVERRIDE;
84 virtual bool updateImageLoadingPriorities() OVERRIDE FINAL;
87 virtual const char* renderName() const OVERRIDE { return "RenderImage"; }
89 virtual bool isImage() const OVERRIDE { return true; }
90 virtual bool isRenderImage() const OVERRIDE FINAL { return true; }
92 virtual void paintReplaced(PaintInfo&, const LayoutPoint&) OVERRIDE;
94 virtual bool foregroundIsKnownToBeOpaqueInRect(const LayoutRect& localRect, unsigned maxDepthToTest) const OVERRIDE FINAL;
95 virtual bool computeBackgroundIsKnownToBeObscured() OVERRIDE FINAL;
97 virtual LayoutUnit minimumReplacedHeight() const OVERRIDE;
99 virtual void notifyFinished(Resource*) OVERRIDE FINAL;
100 virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction) OVERRIDE FINAL;
102 virtual bool boxShadowShouldBeAppliedToBackground(BackgroundBleedAvoidance, InlineFlowBox*) const OVERRIDE FINAL;
104 IntSize imageSizeForError(ImageResource*) const;
105 void repaintOrMarkForLayout(bool imageSizeChanged, const IntRect* = 0);
106 void updateIntrinsicSizeIfNeeded(const LayoutSize&);
107 // Update the size of the image to be rendered. Object-fit may cause this to be different from the CSS box's content rect.
108 void updateInnerContentRect();
110 void paintAreaElementFocusRing(PaintInfo&);
112 // Text to display as long as the image isn't available.
114 OwnPtr<RenderImageResource> m_imageResource;
115 bool m_didIncrementVisuallyNonEmptyPixelCount;
116 bool m_isGeneratedContent;
117 float m_imageDevicePixelRatio;
119 friend class RenderImageScaleObserver;
122 DEFINE_RENDER_OBJECT_TYPE_CASTS(RenderImage, isRenderImage());
126 #endif // RenderImage_h