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 | #pragma once |
25 | |
26 | #include "DecodingOptions.h" |
27 | #include "FormNamedItem.h" |
28 | #include "GraphicsLayer.h" |
29 | #include "GraphicsTypes.h" |
30 | #include "HTMLElement.h" |
31 | #include "HTMLImageLoader.h" |
32 | |
33 | namespace WebCore { |
34 | |
35 | class EditableImageReference; |
36 | class HTMLAttachmentElement; |
37 | class HTMLFormElement; |
38 | class HTMLMapElement; |
39 | |
40 | struct ImageCandidate; |
41 | |
42 | class HTMLImageElement : public HTMLElement, public FormNamedItem { |
43 | WTF_MAKE_ISO_ALLOCATED(HTMLImageElement); |
44 | friend class HTMLFormElement; |
45 | public: |
46 | static Ref<HTMLImageElement> create(Document&); |
47 | static Ref<HTMLImageElement> create(const QualifiedName&, Document&, HTMLFormElement*); |
48 | static Ref<HTMLImageElement> createForJSConstructor(Document&, Optional<unsigned> width, Optional<unsigned> height); |
49 | |
50 | virtual ~HTMLImageElement(); |
51 | |
52 | WEBCORE_EXPORT unsigned width(bool ignorePendingStylesheets = false); |
53 | WEBCORE_EXPORT unsigned height(bool ignorePendingStylesheets = false); |
54 | |
55 | WEBCORE_EXPORT int naturalWidth() const; |
56 | WEBCORE_EXPORT int naturalHeight() const; |
57 | const AtomicString& currentSrc() const { return m_currentSrc; } |
58 | |
59 | bool supportsFocus() const override; |
60 | bool isFocusable() const override; |
61 | |
62 | bool isServerMap() const; |
63 | |
64 | const AtomicString& altText() const; |
65 | |
66 | CompositeOperator compositeOperator() const { return m_compositeOperator; } |
67 | |
68 | CachedImage* cachedImage() const { return m_imageLoader.image(); } |
69 | |
70 | void setLoadManually(bool loadManually) { m_imageLoader.setLoadManually(loadManually); } |
71 | |
72 | bool matchesUsemap(const AtomicStringImpl&) const; |
73 | HTMLMapElement* associatedMapElement() const; |
74 | |
75 | WEBCORE_EXPORT const AtomicString& alt() const; |
76 | |
77 | WEBCORE_EXPORT void setHeight(unsigned); |
78 | |
79 | URL src() const; |
80 | void setSrc(const String&); |
81 | |
82 | WEBCORE_EXPORT void setCrossOrigin(const AtomicString&); |
83 | WEBCORE_EXPORT String crossOrigin() const; |
84 | |
85 | WEBCORE_EXPORT void setWidth(unsigned); |
86 | |
87 | WEBCORE_EXPORT int x() const; |
88 | WEBCORE_EXPORT int y() const; |
89 | |
90 | WEBCORE_EXPORT bool complete() const; |
91 | |
92 | DecodingMode decodingMode() const; |
93 | |
94 | WEBCORE_EXPORT void decode(Ref<DeferredPromise>&&); |
95 | |
96 | #if PLATFORM(IOS_FAMILY) |
97 | bool willRespondToMouseClickEvents() override; |
98 | #endif |
99 | |
100 | #if ENABLE(ATTACHMENT_ELEMENT) |
101 | void setAttachmentElement(Ref<HTMLAttachmentElement>&&); |
102 | RefPtr<HTMLAttachmentElement> attachmentElement() const; |
103 | const String& attachmentIdentifier() const; |
104 | #endif |
105 | |
106 | bool hasPendingActivity() const { return m_imageLoader.hasPendingActivity(); } |
107 | |
108 | bool canContainRangeEndPoint() const override { return false; } |
109 | |
110 | const AtomicString& imageSourceURL() const override; |
111 | |
112 | bool hasShadowControls() const { return m_experimentalImageMenuEnabled; } |
113 | |
114 | HTMLPictureElement* pictureElement() const; |
115 | void setPictureElement(HTMLPictureElement*); |
116 | |
117 | #if USE(SYSTEM_PREVIEW) |
118 | WEBCORE_EXPORT bool isSystemPreviewImage() const; |
119 | #endif |
120 | |
121 | WEBCORE_EXPORT GraphicsLayer::EmbeddedViewID editableImageViewID() const; |
122 | WEBCORE_EXPORT bool hasEditableImageAttribute() const; |
123 | |
124 | void defaultEventHandler(Event&) final; |
125 | |
126 | protected: |
127 | HTMLImageElement(const QualifiedName&, Document&, HTMLFormElement* = 0); |
128 | |
129 | void didMoveToNewDocument(Document& oldDocument, Document& newDocument) override; |
130 | |
131 | private: |
132 | void parseAttribute(const QualifiedName&, const AtomicString&) override; |
133 | bool isPresentationAttribute(const QualifiedName&) const override; |
134 | void collectStyleForPresentationAttribute(const QualifiedName&, const AtomicString&, MutableStyleProperties&) override; |
135 | |
136 | void didAttachRenderers() override; |
137 | RenderPtr<RenderElement> createElementRenderer(RenderStyle&&, const RenderTreePosition&) override; |
138 | void setBestFitURLAndDPRFromImageCandidate(const ImageCandidate&); |
139 | |
140 | bool canStartSelection() const override; |
141 | |
142 | bool isURLAttribute(const Attribute&) const override; |
143 | bool attributeContainsURL(const Attribute&) const override; |
144 | String completeURLsInAttributeValue(const URL& base, const Attribute&) const override; |
145 | |
146 | bool draggable() const override; |
147 | |
148 | void addSubresourceAttributeURLs(ListHashSet<URL>&) const override; |
149 | |
150 | InsertedIntoAncestorResult insertedIntoAncestor(InsertionType, ContainerNode&) override; |
151 | void didFinishInsertingNode() override; |
152 | void removedFromAncestor(RemovalType, ContainerNode&) override; |
153 | |
154 | bool isFormAssociatedElement() const final { return false; } |
155 | FormNamedItem* asFormNamedItem() final { return this; } |
156 | HTMLImageElement& asHTMLElement() final { return *this; } |
157 | const HTMLImageElement& asHTMLElement() const final { return *this; } |
158 | |
159 | void selectImageSource(); |
160 | |
161 | ImageCandidate bestFitSourceFromPictureElement(); |
162 | |
163 | void updateEditableImage(); |
164 | |
165 | void copyNonAttributePropertiesFromElement(const Element&) final; |
166 | |
167 | #if ENABLE(SERVICE_CONTROLS) |
168 | void updateImageControls(); |
169 | void tryCreateImageControls(); |
170 | void destroyImageControls(); |
171 | bool hasImageControls() const; |
172 | bool childShouldCreateRenderer(const Node&) const override; |
173 | #endif |
174 | |
175 | HTMLImageLoader m_imageLoader; |
176 | WeakPtr<HTMLFormElement> m_form; |
177 | WeakPtr<HTMLFormElement> m_formSetByParser; |
178 | |
179 | CompositeOperator m_compositeOperator; |
180 | AtomicString m_bestFitImageURL; |
181 | AtomicString m_currentSrc; |
182 | AtomicString m_parsedUsemap; |
183 | float m_imageDevicePixelRatio; |
184 | bool ; |
185 | bool m_hadNameBeforeAttributeChanged { false }; // FIXME: We only need this because parseAttribute() can't see the old value. |
186 | |
187 | RefPtr<EditableImageReference> m_editableImage; |
188 | WeakPtr<HTMLPictureElement> m_pictureElement; |
189 | |
190 | #if ENABLE(ATTACHMENT_ELEMENT) |
191 | String m_pendingClonedAttachmentID; |
192 | #endif |
193 | |
194 | friend class HTMLPictureElement; |
195 | }; |
196 | |
197 | } //namespace |
198 | |