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 "FormNamedItem.h"
28 #include "GraphicsTypes.h"
29 #include "HTMLElement.h"
30 #include "HTMLImageLoader.h"
34 class HTMLFormElement;
35 struct ImageCandidate;
37 class HTMLImageElement : public HTMLElement, public FormNamedItem {
38 friend class HTMLFormElement;
40 static Ref<HTMLImageElement> create(Document&);
41 static Ref<HTMLImageElement> create(const QualifiedName&, Document&, HTMLFormElement*);
42 static Ref<HTMLImageElement> createForJSConstructor(Document&, const int* optionalWidth, const int* optionalHeight);
44 virtual ~HTMLImageElement();
46 int width(bool ignorePendingStylesheets = false);
47 int height(bool ignorePendingStylesheets = false);
49 int naturalWidth() const;
50 int naturalHeight() const;
51 const AtomicString& currentSrc() const { return m_currentSrc; }
53 bool isServerMap() const;
55 const AtomicString& altText() const;
57 CompositeOperator compositeOperator() const { return m_compositeOperator; }
59 CachedImage* cachedImage() const { return m_imageLoader.image(); }
61 void setLoadManually(bool loadManually) { m_imageLoader.setLoadManually(loadManually); }
63 bool matchesLowercasedUsemap(const AtomicStringImpl&) const;
65 const AtomicString& alt() const;
70 void setSrc(const String&);
77 bool complete() const;
80 virtual bool willRespondToMouseClickEvents() override;
83 bool hasPendingActivity() const { return m_imageLoader.hasPendingActivity(); }
85 virtual bool canContainRangeEndPoint() const override { return false; }
87 virtual const AtomicString& imageSourceURL() const override;
89 bool hasShadowControls() const { return m_experimentalImageMenuEnabled; }
92 HTMLImageElement(const QualifiedName&, Document&, HTMLFormElement* = 0);
94 virtual void didMoveToNewDocument(Document* oldDocument) override;
97 virtual void parseAttribute(const QualifiedName&, const AtomicString&) override;
98 virtual bool isPresentationAttribute(const QualifiedName&) const override;
99 virtual void collectStyleForPresentationAttribute(const QualifiedName&, const AtomicString&, MutableStyleProperties&) override;
101 virtual void didAttachRenderers() override;
102 virtual RenderPtr<RenderElement> createElementRenderer(Ref<RenderStyle>&&, const RenderTreePosition&) override;
103 void setBestFitURLAndDPRFromImageCandidate(const ImageCandidate&);
105 virtual bool canStartSelection() const override;
107 virtual bool isURLAttribute(const Attribute&) const override;
108 virtual bool attributeContainsURL(const Attribute&) const override;
109 virtual String completeURLsInAttributeValue(const URL& base, const Attribute&) const override;
111 virtual bool draggable() const override;
113 virtual void addSubresourceAttributeURLs(ListHashSet<URL>&) const override;
115 virtual InsertionNotificationRequest insertedInto(ContainerNode&) override;
116 virtual void removedFrom(ContainerNode&) override;
118 virtual bool isFormAssociatedElement() const override final { return false; }
119 virtual FormNamedItem* asFormNamedItem() override final { return this; }
120 virtual HTMLImageElement& asHTMLElement() override final { return *this; }
121 virtual const HTMLImageElement& asHTMLElement() const override final { return *this; }
123 void selectImageSource();
125 ImageCandidate bestFitSourceFromPictureElement();
127 HTMLImageLoader m_imageLoader;
128 HTMLFormElement* m_form;
129 HTMLFormElement* m_formSetByParser;
130 CompositeOperator m_compositeOperator;
131 AtomicString m_bestFitImageURL;
132 AtomicString m_currentSrc;
133 AtomicString m_lowercasedUsemap;
134 float m_imageDevicePixelRatio;
135 bool m_experimentalImageMenuEnabled;
136 bool m_hadNameBeforeAttributeChanged { false }; // FIXME: We only need this because parseAttribute() can't see the old value.
138 #if ENABLE(SERVICE_CONTROLS)
139 void updateImageControls();
140 void createImageControls();
141 void destroyImageControls();
142 bool hasImageControls() const;
143 virtual bool childShouldCreateRenderer(const Node&) const override;
146 friend class HTMLPictureElement;