Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / Source / core / layout / LayoutImage.h
blob1c5a232c8702b26dbebe6ea95105e9841e7339b6
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.
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.
25 #ifndef LayoutImage_h
26 #define LayoutImage_h
28 #include "core/CoreExport.h"
29 #include "core/layout/LayoutImageResource.h"
30 #include "core/layout/LayoutReplaced.h"
32 namespace blink {
34 class HTMLAreaElement;
35 class HTMLMapElement;
37 // LayoutImage is used to display any image type.
39 // There is 2 types of images:
40 // * normal images, e.g. <image>, <picture>.
41 // * content images with "content: url(path/to/image.png)".
42 // We store the type inside m_isGeneratedContent.
44 // The class is image type agnostic as it only manipulates decoded images.
45 // See LayoutImageResource that holds this image.
46 class CORE_EXPORT LayoutImage : public LayoutReplaced {
47 public:
48 // These are the paddings to use when displaying either alt text or an image.
49 static const unsigned short paddingWidth = 4;
50 static const unsigned short paddingHeight = 4;
52 LayoutImage(Element*);
53 ~LayoutImage() override;
55 static LayoutImage* createAnonymous(Document*);
57 void setImageResource(PassOwnPtrWillBeRawPtr<LayoutImageResource>);
59 LayoutImageResource* imageResource() { return m_imageResource.get(); }
60 const LayoutImageResource* imageResource() const { return m_imageResource.get(); }
61 ImageResource* cachedImage() const { return m_imageResource ? m_imageResource->cachedImage() : 0; }
63 HTMLMapElement* imageMap() const;
64 void areaElementFocusChanged(HTMLAreaElement*);
66 void setIsGeneratedContent(bool generated = true) { m_isGeneratedContent = generated; }
68 bool isGeneratedContent() const { return m_isGeneratedContent; }
70 inline void setImageDevicePixelRatio(float factor) { m_imageDevicePixelRatio = factor; }
71 float imageDevicePixelRatio() const { return m_imageDevicePixelRatio; }
73 void intrinsicSizeChanged() override
75 if (m_imageResource)
76 imageChanged(m_imageResource->imagePtr());
79 const char* name() const override { return "LayoutImage"; }
81 protected:
82 bool needsPreferredWidthsRecalculation() const final;
83 LayoutBox* embeddedContentBox() const final;
84 void computeIntrinsicRatioInformation(FloatSize& intrinsicSize, double& intrinsicRatio) const final;
86 void imageChanged(WrappedImagePtr, const IntRect* = nullptr) override;
88 void paint(const PaintInfo&, const LayoutPoint&) final;
90 void layout() override;
91 bool updateImageLoadingPriorities() final;
93 bool isOfType(LayoutObjectType type) const override { return type == LayoutObjectLayoutImage || LayoutReplaced::isOfType(type); }
95 void willBeDestroyed() override;
97 void styleDidChange(StyleDifference, const ComputedStyle* oldStyle) override;
99 private:
100 bool isImage() const override { return true; }
102 void paintReplaced(const PaintInfo&, const LayoutPoint&) override;
104 bool foregroundIsKnownToBeOpaqueInRect(const LayoutRect& localRect, unsigned maxDepthToTest) const final;
105 bool computeBackgroundIsKnownToBeObscured() final;
107 bool backgroundShouldAlwaysBeClipped() const override { return true; }
109 LayoutUnit minimumReplacedHeight() const override;
111 void notifyFinished(Resource*) final;
112 bool nodeAtPoint(HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction) final;
114 bool boxShadowShouldBeAppliedToBackground(BackgroundBleedAvoidance, InlineFlowBox*) const final;
116 void invalidatePaintAndMarkForLayoutIfNeeded();
117 void updateIntrinsicSizeIfNeeded(const LayoutSize&);
118 // Update the size of the image to be rendered. Object-fit may cause this to be different from the CSS box's content rect.
119 void updateInnerContentRect();
121 // This member wraps the associated decoded image.
123 // This field is set using setImageResource above which can be called in
124 // several ways:
125 // * For normal images, from the network stack (ImageLoader) once we have
126 // some image data.
127 // * For generated content, the resource is loaded during style resolution
128 // and thus is stored in ComputedStyle (see ContentData::image) that gets
129 // propagated to the anonymous LayoutImage in LayoutObject::createObject.
130 OwnPtrWillBePersistent<LayoutImageResource> m_imageResource;
131 bool m_didIncrementVisuallyNonEmptyPixelCount;
133 // This field stores whether this image is generated with 'content'.
134 bool m_isGeneratedContent;
135 float m_imageDevicePixelRatio;
138 DEFINE_LAYOUT_OBJECT_TYPE_CASTS(LayoutImage, isLayoutImage());
140 } // namespace blink
142 #endif // LayoutImage_h