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 "GraphicsTypes.h"
28 #include "HTMLElement.h"
29 #include "HTMLImageLoader.h"
30 
31 namespace WebCore {
32 
33 class HTMLFormElement;
34 
35 class HTMLImageElement : public HTMLElement {
36     friend class HTMLFormElement;
37 public:
38     static PassRefPtr<HTMLImageElement> create(Document*);
39     static PassRefPtr<HTMLImageElement> create(const QualifiedName&, Document*, HTMLFormElement*);
40     static PassRefPtr<HTMLImageElement> createForJSConstructor(Document*, const int* optionalWidth, const int* optionalHeight);
41 
42     virtual ~HTMLImageElement();
43 
44     int width(bool ignorePendingStylesheets = false) const;
45     int height(bool ignorePendingStylesheets = false) const;
46 
47     int naturalWidth() const;
48     int naturalHeight() const;
49 
isServerMap()50     bool isServerMap() const { return ismap && usemap.isEmpty(); }
51 
52     String altText() const;
53 
compositeOperator()54     CompositeOperator compositeOperator() const { return m_compositeOperator; }
55 
cachedImage()56     CachedImage* cachedImage() const { return m_imageLoader.image(); }
setCachedImage(CachedImage * i)57     void setCachedImage(CachedImage* i) { m_imageLoader.setImage(i); };
58 
setLoadManually(bool loadManually)59     void setLoadManually(bool loadManually) { m_imageLoader.setLoadManually(loadManually); }
60 
61     const AtomicString& alt() const;
62 
63     void setHeight(int);
64 
65     KURL src() const;
66     void setSrc(const String&);
67 
68     void setWidth(int);
69 
70     int x() const;
71     int y() const;
72 
73     bool complete() const;
74 
haveFiredLoadEvent()75     bool haveFiredLoadEvent() const { return m_imageLoader.haveFiredLoadEvent(); }
hasPendingActivity()76     bool hasPendingActivity() const { return !m_imageLoader.haveFiredLoadEvent(); }
77 
78 protected:
79     HTMLImageElement(const QualifiedName&, Document*, HTMLFormElement* = 0);
80 
81     virtual void willMoveToNewOwnerDocument();
82 
83 private:
84     virtual bool mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const;
85     virtual void parseMappedAttribute(Attribute*);
86 
87     virtual void attach();
88     virtual RenderObject* createRenderer(RenderArena*, RenderStyle*);
89 
canStartSelection()90     virtual bool canStartSelection() const { return false; }
91 
92     virtual bool isURLAttribute(Attribute*) const;
93 
94     virtual bool draggable() const;
95 
96     virtual void addSubresourceAttributeURLs(ListHashSet<KURL>&) const;
97 
98     virtual void insertedIntoDocument();
99     virtual void removedFromDocument();
100     virtual void insertedIntoTree(bool deep);
101     virtual void removedFromTree(bool deep);
102 
103     HTMLImageLoader m_imageLoader;
104     String usemap;
105     bool ismap;
106     HTMLFormElement* m_form;
107     AtomicString m_name;
108     AtomicString m_id;
109     CompositeOperator m_compositeOperator;
110 };
111 
112 } //namespace
113 
114 #endif
115