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 "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"
35 class HTMLFormElement;
37 class HTMLImageElement FINAL : public HTMLElement, public CanvasImageSource {
39 static PassRefPtrWillBeRawPtr<HTMLImageElement> create(Document&);
40 static PassRefPtrWillBeRawPtr<HTMLImageElement> create(Document&, HTMLFormElement*);
41 static PassRefPtrWillBeRawPtr<HTMLImageElement> createForJSConstructor(Document&, int width, int height);
43 virtual ~HTMLImageElement();
45 int width(bool ignorePendingStylesheets = false);
46 int height(bool ignorePendingStylesheets = false);
48 int naturalWidth() const;
49 int naturalHeight() const;
50 const AtomicString& currentSrc() const;
52 bool isServerMap() const;
54 const AtomicString& altText() const;
56 CompositeOperator compositeOperator() const { return m_compositeOperator; }
58 ImageResource* cachedImage() const { return m_imageLoader.image(); }
59 void setImageResource(ImageResource* i) { m_imageLoader.setImage(i); };
61 void setLoadManually(bool loadManually) { m_imageLoader.setLoadManually(loadManually); }
63 const AtomicString& alt() const;
68 void setSrc(const String&);
75 bool complete() const;
77 bool hasPendingActivity() const { return m_imageLoader.hasPendingActivity(); }
79 virtual bool canContainRangeEndPoint() const OVERRIDE { return false; }
81 void addClient(ImageLoaderClient* client) { m_imageLoader.addClient(client); }
82 void removeClient(ImageLoaderClient* client) { m_imageLoader.removeClient(client); }
84 virtual const AtomicString imageSourceURL() const OVERRIDE;
86 virtual HTMLFormElement* formOwner() const OVERRIDE;
87 void formRemovedFromTree(const Node& formRoot);
89 // CanvasImageSourceImplementations
90 virtual PassRefPtr<Image> getSourceImageForCanvas(SourceImageMode, SourceImageStatus*) const;
91 virtual bool wouldTaintOrigin(SecurityOrigin*) const OVERRIDE;
92 virtual FloatSize sourceSize() const OVERRIDE;
93 virtual FloatSize defaultDestinationSize() const OVERRIDE;
96 explicit HTMLImageElement(Document&, HTMLFormElement* = 0);
98 virtual void didMoveToNewDocument(Document& oldDocument) OVERRIDE;
101 virtual bool areAuthorShadowsAllowed() const OVERRIDE { return false; }
103 virtual void parseAttribute(const QualifiedName&, const AtomicString&) OVERRIDE;
104 virtual bool isPresentationAttribute(const QualifiedName&) const OVERRIDE;
105 virtual void collectStyleForPresentationAttribute(const QualifiedName&, const AtomicString&, MutableStylePropertySet*) OVERRIDE;
107 virtual void attach(const AttachContext& = AttachContext()) OVERRIDE;
108 virtual RenderObject* createRenderer(RenderStyle*) OVERRIDE;
110 virtual bool canStartSelection() const OVERRIDE;
112 virtual bool isURLAttribute(const Attribute&) const OVERRIDE;
113 virtual bool hasLegalLinkAttribute(const QualifiedName&) const OVERRIDE;
114 virtual const QualifiedName& subResourceAttributeName() const OVERRIDE;
116 virtual bool draggable() const OVERRIDE;
118 virtual InsertionNotificationRequest insertedInto(ContainerNode*) OVERRIDE;
119 virtual void removedFrom(ContainerNode*) OVERRIDE;
120 virtual bool shouldRegisterAsNamedItem() const OVERRIDE { return true; }
121 virtual bool shouldRegisterAsExtraNamedItem() const OVERRIDE { return true; }
122 virtual bool isInteractiveContent() const OVERRIDE;
123 virtual Image* imageContents() OVERRIDE;
125 void resetFormOwner();
127 HTMLImageLoader m_imageLoader;
128 // m_form should be a strong reference in Oilpan.
129 WeakPtr<HTMLFormElement> m_form;
130 CompositeOperator m_compositeOperator;
131 AtomicString m_bestFitImageURL;
132 float m_imageDevicePixelRatio;
133 bool m_formWasSetByParser;