Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / Source / core / html / HTMLImageElement.h
blob1d5dd11e709e87368df5cfff71e67a154ba56293
1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * Copyright (C) 2004, 2008, 2010 Apple Inc. All rights reserved.
5 * Copyright (C) 2010 Google Inc. All rights reserved.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
24 #ifndef HTMLImageElement_h
25 #define HTMLImageElement_h
27 #include "core/CoreExport.h"
28 #include "core/fetch/FetchRequest.h"
29 #include "core/html/HTMLElement.h"
30 #include "core/html/HTMLImageLoader.h"
31 #include "core/html/canvas/CanvasImageSource.h"
32 #include "platform/graphics/GraphicsTypes.h"
33 #include "platform/network/ResourceResponse.h"
34 #include "wtf/WeakPtr.h"
36 namespace blink {
38 class HTMLFormElement;
39 class ImageCandidate;
40 class ShadowRoot;
42 class CORE_EXPORT HTMLImageElement final : public HTMLElement, public CanvasImageSource {
43 DEFINE_WRAPPERTYPEINFO();
44 public:
45 class ViewportChangeListener;
47 static PassRefPtrWillBeRawPtr<HTMLImageElement> create(Document&);
48 static PassRefPtrWillBeRawPtr<HTMLImageElement> create(Document&, HTMLFormElement*, bool createdByParser);
49 static PassRefPtrWillBeRawPtr<HTMLImageElement> createForJSConstructor(Document&);
50 static PassRefPtrWillBeRawPtr<HTMLImageElement> createForJSConstructor(Document&, int width);
51 static PassRefPtrWillBeRawPtr<HTMLImageElement> createForJSConstructor(Document&, int width, int height);
53 ~HTMLImageElement() override;
54 DECLARE_VIRTUAL_TRACE();
56 int width();
57 int height();
59 int naturalWidth() const;
60 int naturalHeight() const;
61 const String& currentSrc() const;
63 bool isServerMap() const;
65 String altText() const final;
67 ImageResource* cachedImage() const { return imageLoader().image(); }
68 void setImageResource(ImageResource* i) { imageLoader().setImage(i); }
70 void setLoadingImageDocument() { imageLoader().setLoadingImageDocument(); }
72 void setHeight(int);
74 KURL src() const;
75 void setSrc(const String&);
77 void setWidth(int);
79 int x() const;
80 int y() const;
82 bool complete() const;
84 bool hasPendingActivity() const { return imageLoader().hasPendingActivity(); }
86 bool canContainRangeEndPoint() const override { return false; }
88 void addClient(ImageLoaderClient* client) { imageLoader().addClient(client); }
89 void removeClient(ImageLoaderClient* client) { imageLoader().removeClient(client); }
91 const AtomicString imageSourceURL() const override;
93 HTMLFormElement* formOwner() const override;
94 void formRemovedFromTree(const Node& formRoot);
95 virtual void ensureFallbackContent();
96 virtual void ensureFallbackForGeneratedContent();
97 virtual void ensurePrimaryContent();
99 // CanvasImageSource implementation
100 PassRefPtr<Image> getSourceImageForCanvas(SourceImageStatus*) const override;
101 bool wouldTaintOrigin(SecurityOrigin*) const override;
102 FloatSize elementSize() const override;
103 FloatSize defaultDestinationSize() const override;
104 const KURL& sourceURL() const override;
105 bool isOpaque() const override;
107 // public so that HTMLPictureElement can call this as well.
108 void selectSourceURL(ImageLoader::UpdateFromElementBehavior);
109 void reattachFallbackContent();
110 void setUseFallbackContent();
111 void setIsFallbackImage() { m_isFallbackImage = true; }
113 FetchRequest::ResourceWidth resourceWidth();
114 float sourceSize(Element&);
116 void forceReload() const;
118 protected:
119 explicit HTMLImageElement(Document&, HTMLFormElement* = 0, bool createdByParser = false);
121 void didMoveToNewDocument(Document& oldDocument) override;
122 virtual bool useFallbackContent() const { return m_useFallbackContent; }
124 void didAddUserAgentShadowRoot(ShadowRoot&) override;
125 PassRefPtr<ComputedStyle> customStyleForLayoutObject() override;
126 private:
127 bool areAuthorShadowsAllowed() const override { return false; }
129 void parseAttribute(const QualifiedName&, const AtomicString&) override;
130 bool isPresentationAttribute(const QualifiedName&) const override;
131 void collectStyleForPresentationAttribute(const QualifiedName&, const AtomicString&, MutableStylePropertySet*) override;
133 void attach(const AttachContext& = AttachContext()) override;
134 LayoutObject* createLayoutObject(const ComputedStyle&) override;
136 bool canStartSelection() const override { return false; }
138 bool isURLAttribute(const Attribute&) const override;
139 bool hasLegalLinkAttribute(const QualifiedName&) const override;
140 const QualifiedName& subResourceAttributeName() const override;
142 bool draggable() const override;
144 InsertionNotificationRequest insertedInto(ContainerNode*) override;
145 void removedFrom(ContainerNode*) override;
146 bool shouldRegisterAsNamedItem() const override { return true; }
147 bool shouldRegisterAsExtraNamedItem() const override { return true; }
148 bool isInteractiveContent() const override;
149 Image* imageContents() override;
151 void resetFormOwner();
152 ImageCandidate findBestFitImageFromPictureParent();
153 void setBestFitURLAndDPRFromImageCandidate(const ImageCandidate&);
154 HTMLImageLoader& imageLoader() const { return *m_imageLoader; }
155 void notifyViewportChanged();
156 void createMediaQueryListIfDoesNotExist();
158 OwnPtrWillBeMember<HTMLImageLoader> m_imageLoader;
159 RefPtrWillBeMember<ViewportChangeListener> m_listener;
160 WeakPtrWillBeMember<HTMLFormElement> m_form;
161 AtomicString m_bestFitImageURL;
162 float m_imageDevicePixelRatio;
163 unsigned m_formWasSetByParser : 1;
164 unsigned m_elementCreatedByParser : 1;
165 // Intrinsic sizing is viewport dependant if the 'w' descriptor was used for the picked resource.
166 unsigned m_intrinsicSizingViewportDependant : 1;
167 unsigned m_useFallbackContent : 1;
168 unsigned m_isFallbackImage : 1;
170 ReferrerPolicy m_referrerPolicy;
173 } // namespace blink
175 #endif // HTMLImageElement_h