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 "FormNamedItem.h"
28#include "GraphicsTypes.h"
29#include "HTMLElement.h"
30#include "HTMLImageLoader.h"
31
32namespace WebCore {
33
34class HTMLFormElement;
35struct ImageCandidate;
36
37class HTMLImageElement : public HTMLElement, public FormNamedItem {
38    friend class HTMLFormElement;
39public:
40    static PassRefPtr<HTMLImageElement> create(Document&);
41    static PassRefPtr<HTMLImageElement> create(const QualifiedName&, Document&, HTMLFormElement*);
42    static PassRefPtr<HTMLImageElement> createForJSConstructor(Document&, const int* optionalWidth, const int* optionalHeight);
43
44    virtual ~HTMLImageElement();
45
46    int width(bool ignorePendingStylesheets = false);
47    int height(bool ignorePendingStylesheets = false);
48
49    int naturalWidth() const;
50    int naturalHeight() const;
51#if ENABLE_PICTURE_SIZES
52    const AtomicString& currentSrc() const { return m_currentSrc; }
53#endif
54
55    bool isServerMap() const;
56
57    String altText() const;
58
59    CompositeOperator compositeOperator() const { return m_compositeOperator; }
60
61    CachedImage* cachedImage() const { return m_imageLoader.image(); }
62    void setCachedImage(CachedImage* i) { m_imageLoader.setImage(i); };
63
64    void setLoadManually(bool loadManually) { m_imageLoader.setLoadManually(loadManually); }
65
66    bool matchesLowercasedUsemap(const AtomicStringImpl&) const;
67
68    const AtomicString& alt() const;
69
70    void setHeight(int);
71
72    URL src() const;
73    void setSrc(const String&);
74
75    void setWidth(int);
76
77    int x() const;
78    int y() const;
79
80    bool complete() const;
81
82#if PLATFORM(IOS)
83    virtual bool willRespondToMouseClickEvents() override;
84#endif
85
86    bool hasPendingActivity() const { return m_imageLoader.hasPendingActivity(); }
87
88    virtual bool canContainRangeEndPoint() const override { return false; }
89
90    virtual const AtomicString& imageSourceURL() const override;
91
92    bool hasShadowControls() const { return m_experimentalImageMenuEnabled; }
93
94protected:
95    HTMLImageElement(const QualifiedName&, Document&, HTMLFormElement* = 0);
96
97    virtual void didMoveToNewDocument(Document* oldDocument) override;
98
99private:
100    virtual void parseAttribute(const QualifiedName&, const AtomicString&) override;
101    virtual bool isPresentationAttribute(const QualifiedName&) const override;
102    virtual void collectStyleForPresentationAttribute(const QualifiedName&, const AtomicString&, MutableStyleProperties&) override;
103
104    virtual void didAttachRenderers() override;
105    virtual RenderPtr<RenderElement> createElementRenderer(PassRef<RenderStyle>) override;
106    void setBestFitURLAndDPRFromImageCandidate(const ImageCandidate&);
107
108    virtual bool canStartSelection() const override;
109
110    virtual bool isURLAttribute(const Attribute&) const override;
111
112    virtual bool draggable() const override;
113
114    virtual void addSubresourceAttributeURLs(ListHashSet<URL>&) const override;
115
116    virtual InsertionNotificationRequest insertedInto(ContainerNode&) override;
117    virtual void removedFrom(ContainerNode&) override;
118
119    virtual bool isFormAssociatedElement() const override final { return false; }
120    virtual FormNamedItem* asFormNamedItem() override final { return this; }
121    virtual HTMLImageElement& asHTMLElement() override final { return *this; }
122    virtual const HTMLImageElement& asHTMLElement() const override final { return *this; }
123
124    HTMLImageLoader m_imageLoader;
125    HTMLFormElement* m_form;
126    CompositeOperator m_compositeOperator;
127    AtomicString m_bestFitImageURL;
128#if ENABLE_PICTURE_SIZES
129    AtomicString m_currentSrc;
130#endif
131    AtomicString m_lowercasedUsemap;
132    float m_imageDevicePixelRatio;
133    bool m_experimentalImageMenuEnabled;
134
135#if ENABLE(SERVICE_CONTROLS)
136    void updateImageControls();
137    void createImageControls();
138    void destroyImageControls();
139    bool hasImageControls() const;
140    virtual bool childShouldCreateRenderer(const Node&) const override;
141#endif
142};
143
144NODE_TYPE_CASTS(HTMLImageElement)
145
146} //namespace
147
148#endif
149