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 // 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;
42 RenderImage(Element*);
43 virtual ~RenderImage();
44 virtual void destroy() override;
46 static RenderImage* createAnonymous(Document*);
48 void setImageResource(PassOwnPtr<RenderImageResource>);
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; }
54 bool setImageSizeForAltText(ImageResource* newImage = 0);
58 HTMLMapElement* imageMap() const;
59 void areaElementFocusChanged(HTMLAreaElement*);
61 void setIsGeneratedContent(bool generated = true) { m_isGeneratedContent = generated; }
63 bool isGeneratedContent() const { return m_isGeneratedContent; }
65 String altText() const { return m_altText; }
67 inline void setImageDevicePixelRatio(float factor) { m_imageDevicePixelRatio = factor; }
68 float imageDevicePixelRatio() const { return m_imageDevicePixelRatio; }
70 virtual void intrinsicSizeChanged() override
73 imageChanged(m_imageResource->imagePtr());
77 virtual bool needsPreferredWidthsRecalculation() const override final;
78 virtual RenderBox* embeddedContentBox() const override final;
79 virtual void computeIntrinsicRatioInformation(FloatSize& intrinsicSize, double& intrinsicRatio) const override final;
81 virtual void imageChanged(WrappedImagePtr, const IntRect* = 0) override;
83 virtual void paint(PaintInfo&, const LayoutPoint&) override final;
84 virtual void paintBoxDecorationBackground(PaintInfo&, const LayoutPoint&) override final;
86 virtual void layout() override;
87 virtual bool updateImageLoadingPriorities() override final;
89 virtual bool isOfType(RenderObjectType type) const override { return type == RenderObjectRenderImage || RenderReplaced::isOfType(type); }
92 virtual const char* renderName() const override { return "RenderImage"; }
94 virtual bool isImage() const override { return true; }
96 virtual void paintReplaced(PaintInfo&, const LayoutPoint&) override;
98 virtual bool foregroundIsKnownToBeOpaqueInRect(const LayoutRect& localRect, unsigned maxDepthToTest) const override final;
99 virtual bool computeBackgroundIsKnownToBeObscured() override final;
101 virtual LayoutUnit minimumReplacedHeight() const override;
103 virtual void notifyFinished(Resource*) override final;
104 virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction) override final;
106 virtual bool boxShadowShouldBeAppliedToBackground(BackgroundBleedAvoidance, InlineFlowBox*) const override final;
108 IntSize imageSizeForError(ImageResource*) const;
109 void paintInvalidationOrMarkForLayout(bool imageSizeChanged, const IntRect* = 0);
110 void updateIntrinsicSizeIfNeeded(const LayoutSize&);
111 // Update the size of the image to be rendered. Object-fit may cause this to be different from the CSS box's content rect.
112 void updateInnerContentRect();
114 // Text to display as long as the image isn't available.
116 OwnPtr<RenderImageResource> m_imageResource;
117 bool m_didIncrementVisuallyNonEmptyPixelCount;
118 bool m_isGeneratedContent;
119 float m_imageDevicePixelRatio;
121 friend class RenderImageScaleObserver;
124 DEFINE_RENDER_OBJECT_TYPE_CASTS(RenderImage, isRenderImage());
128 #endif // RenderImage_h