Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / html / HTMLImageElement.h
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.
6  *
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.
11  *
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.
16  *
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.
21  *
22  */
23
24 #ifndef HTMLImageElement_h
25 #define HTMLImageElement_h
26
27 #include "core/html/HTMLElement.h"
28 #include "core/html/HTMLImageLoader.h"
29 #include "core/html/canvas/CanvasImageSource.h"
30 #include "platform/graphics/GraphicsTypes.h"
31 #include "wtf/WeakPtr.h"
32
33 namespace blink {
34
35 class HTMLFormElement;
36 class ImageCandidate;
37
38 class HTMLImageElement final : public HTMLElement, public CanvasImageSource {
39     DEFINE_WRAPPERTYPEINFO();
40 public:
41     class ViewportChangeListener;
42
43     static PassRefPtrWillBeRawPtr<HTMLImageElement> create(Document&);
44     static PassRefPtrWillBeRawPtr<HTMLImageElement> create(Document&, HTMLFormElement*, bool createdByParser);
45     static PassRefPtrWillBeRawPtr<HTMLImageElement> createForJSConstructor(Document&, int width, int height);
46
47     virtual ~HTMLImageElement();
48     virtual void trace(Visitor*) override;
49
50     int width(bool ignorePendingStylesheets = false);
51     int height(bool ignorePendingStylesheets = false);
52
53     int naturalWidth() const;
54     int naturalHeight() const;
55     const String& currentSrc() const;
56
57     bool isServerMap() const;
58
59     const AtomicString& altText() const;
60
61     ImageResource* cachedImage() const { return imageLoader().image(); }
62     void setImageResource(ImageResource* i) { imageLoader().setImage(i); };
63
64     void setLoadingImageDocument() { imageLoader().setLoadingImageDocument(); }
65
66     void setHeight(int);
67
68     KURL src() const;
69     void setSrc(const String&);
70
71     void setWidth(int);
72
73     int x() const;
74     int y() const;
75
76     bool complete() const;
77
78     bool hasPendingActivity() const { return imageLoader().hasPendingActivity(); }
79
80     virtual bool canContainRangeEndPoint() const override { return false; }
81
82     void addClient(ImageLoaderClient* client) { imageLoader().addClient(client); }
83     void removeClient(ImageLoaderClient* client) { imageLoader().removeClient(client); }
84
85     virtual const AtomicString imageSourceURL() const override;
86
87     virtual HTMLFormElement* formOwner() const override;
88     void formRemovedFromTree(const Node& formRoot);
89
90     // CanvasImageSourceImplementations
91     virtual PassRefPtr<Image> getSourceImageForCanvas(SourceImageMode, SourceImageStatus*) const override;
92     virtual bool wouldTaintOrigin(SecurityOrigin*) const override;
93     virtual FloatSize sourceSize() const override;
94     virtual FloatSize defaultDestinationSize() const override;
95     virtual const KURL& sourceURL() const override;
96
97     // public so that HTMLPictureElement can call this as well.
98     void selectSourceURL(ImageLoader::UpdateFromElementBehavior);
99 protected:
100     explicit HTMLImageElement(Document&, HTMLFormElement* = 0, bool createdByParser = false);
101
102     virtual void didMoveToNewDocument(Document& oldDocument) override;
103
104 private:
105     virtual bool areAuthorShadowsAllowed() const override { return false; }
106
107     virtual void parseAttribute(const QualifiedName&, const AtomicString&) override;
108     virtual bool isPresentationAttribute(const QualifiedName&) const override;
109     virtual void collectStyleForPresentationAttribute(const QualifiedName&, const AtomicString&, MutableStylePropertySet*) override;
110
111     virtual void attach(const AttachContext& = AttachContext()) override;
112     virtual RenderObject* createRenderer(RenderStyle*) override;
113
114     virtual bool canStartSelection() const override;
115
116     virtual bool isURLAttribute(const Attribute&) const override;
117     virtual bool hasLegalLinkAttribute(const QualifiedName&) const override;
118     virtual const QualifiedName& subResourceAttributeName() const override;
119
120     virtual bool draggable() const override;
121
122     virtual InsertionNotificationRequest insertedInto(ContainerNode*) override;
123     virtual void removedFrom(ContainerNode*) override;
124     virtual bool shouldRegisterAsNamedItem() const override { return true; }
125     virtual bool shouldRegisterAsExtraNamedItem() const override { return true; }
126     virtual bool isInteractiveContent() const override;
127     virtual Image* imageContents() override;
128
129     void resetFormOwner();
130     ImageCandidate findBestFitImageFromPictureParent();
131     void setBestFitURLAndDPRFromImageCandidate(const ImageCandidate&);
132     HTMLImageLoader& imageLoader() const { return *m_imageLoader; }
133     void notifyViewportChanged();
134     void createMediaQueryListIfDoesNotExist();
135
136     OwnPtrWillBeMember<HTMLImageLoader> m_imageLoader;
137     RefPtrWillBeMember<ViewportChangeListener> m_listener;
138 #if ENABLE(OILPAN)
139     Member<HTMLFormElement> m_form;
140 #else
141     WeakPtr<HTMLFormElement> m_form;
142 #endif
143     AtomicString m_bestFitImageURL;
144     float m_imageDevicePixelRatio;
145     unsigned m_formWasSetByParser : 1;
146     unsigned m_elementCreatedByParser : 1;
147     // Intrinsic sizing is viewport dependant if the 'w' descriptor was used for the picked resource.
148     unsigned m_intrinsicSizingViewportDependant : 1;
149 };
150
151 } // namespace blink
152
153 #endif // HTMLImageElement_h