Home | History | Annotate | Download | only in html
      1 /*
      2  * Copyright (C) 1999 Lars Knoll (knoll (at) kde.org)
      3  *           (C) 1999 Antti Koivisto (koivisto (at) 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 "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"
     32 
     33 namespace WebCore {
     34 
     35 class HTMLFormElement;
     36 class ImageCandidate;
     37 
     38 class HTMLImageElement FINAL : public HTMLElement, public CanvasImageSource {
     39 public:
     40     static PassRefPtrWillBeRawPtr<HTMLImageElement> create(Document&);
     41     static PassRefPtrWillBeRawPtr<HTMLImageElement> create(Document&, HTMLFormElement*, bool createdByParser);
     42     static PassRefPtrWillBeRawPtr<HTMLImageElement> createForJSConstructor(Document&, int width, int height);
     43 
     44     virtual ~HTMLImageElement();
     45     virtual void trace(Visitor*) OVERRIDE;
     46 
     47     int width(bool ignorePendingStylesheets = false);
     48     int height(bool ignorePendingStylesheets = false);
     49 
     50     int naturalWidth() const;
     51     int naturalHeight() const;
     52     const String& currentSrc() const;
     53 
     54     bool isServerMap() const;
     55 
     56     const AtomicString& altText() const;
     57 
     58     CompositeOperator compositeOperator() const { return m_compositeOperator; }
     59 
     60     ImageResource* cachedImage() const { return imageLoader().image(); }
     61     void setImageResource(ImageResource* i) { imageLoader().setImage(i); };
     62 
     63     void setLoadManually(bool loadManually) { imageLoader().setLoadManually(loadManually); }
     64 
     65     const AtomicString& alt() const;
     66 
     67     void setHeight(int);
     68 
     69     KURL src() const;
     70     void setSrc(const String&);
     71 
     72     void setWidth(int);
     73 
     74     int x() const;
     75     int y() const;
     76 
     77     bool complete() const;
     78 
     79     bool hasPendingActivity() const { return imageLoader().hasPendingActivity(); }
     80 
     81     virtual bool canContainRangeEndPoint() const OVERRIDE { return false; }
     82 
     83     void addClient(ImageLoaderClient* client) { imageLoader().addClient(client); }
     84     void removeClient(ImageLoaderClient* client) { imageLoader().removeClient(client); }
     85 
     86     virtual const AtomicString imageSourceURL() const OVERRIDE;
     87 
     88     virtual HTMLFormElement* formOwner() const OVERRIDE;
     89     void formRemovedFromTree(const Node& formRoot);
     90 
     91     // CanvasImageSourceImplementations
     92     virtual PassRefPtr<Image> getSourceImageForCanvas(SourceImageMode, SourceImageStatus*) const;
     93     virtual bool wouldTaintOrigin(SecurityOrigin*) const OVERRIDE;
     94     virtual FloatSize sourceSize() const OVERRIDE;
     95     virtual FloatSize defaultDestinationSize() const OVERRIDE;
     96     virtual const KURL& sourceURL() const OVERRIDE;
     97 
     98     enum UpdateFromElementBehavior {
     99         UpdateNormal,
    100         UpdateIgnorePreviousError
    101     };
    102     // public so that HTMLPictureElement can call this as well.
    103     void selectSourceURL(UpdateFromElementBehavior);
    104 protected:
    105     explicit HTMLImageElement(Document&, HTMLFormElement* = 0, bool createdByParser = false);
    106 
    107     virtual void didMoveToNewDocument(Document& oldDocument) OVERRIDE;
    108 
    109 private:
    110     virtual bool areAuthorShadowsAllowed() const OVERRIDE { return false; }
    111 
    112     virtual void parseAttribute(const QualifiedName&, const AtomicString&) OVERRIDE;
    113     virtual bool isPresentationAttribute(const QualifiedName&) const OVERRIDE;
    114     virtual void collectStyleForPresentationAttribute(const QualifiedName&, const AtomicString&, MutableStylePropertySet*) OVERRIDE;
    115 
    116     virtual void attach(const AttachContext& = AttachContext()) OVERRIDE;
    117     virtual RenderObject* createRenderer(RenderStyle*) OVERRIDE;
    118 
    119     virtual bool canStartSelection() const OVERRIDE;
    120 
    121     virtual bool isURLAttribute(const Attribute&) const OVERRIDE;
    122     virtual bool hasLegalLinkAttribute(const QualifiedName&) const OVERRIDE;
    123     virtual const QualifiedName& subResourceAttributeName() const OVERRIDE;
    124 
    125     virtual bool draggable() const OVERRIDE;
    126 
    127     virtual InsertionNotificationRequest insertedInto(ContainerNode*) OVERRIDE;
    128     virtual void removedFrom(ContainerNode*) OVERRIDE;
    129     virtual bool shouldRegisterAsNamedItem() const OVERRIDE { return true; }
    130     virtual bool shouldRegisterAsExtraNamedItem() const OVERRIDE { return true; }
    131     virtual bool isInteractiveContent() const OVERRIDE;
    132     virtual Image* imageContents() OVERRIDE;
    133 
    134     void resetFormOwner();
    135     ImageCandidate findBestFitImageFromPictureParent();
    136     void setBestFitURLAndDPRFromImageCandidate(const ImageCandidate&);
    137     HTMLImageLoader& imageLoader() const { return *m_imageLoader; }
    138 
    139     OwnPtrWillBeMember<HTMLImageLoader> m_imageLoader;
    140 #if ENABLE(OILPAN)
    141     Member<HTMLFormElement> m_form;
    142 #else
    143     WeakPtr<HTMLFormElement> m_form;
    144 #endif
    145     CompositeOperator m_compositeOperator;
    146     AtomicString m_bestFitImageURL;
    147     float m_imageDevicePixelRatio;
    148     bool m_formWasSetByParser;
    149     bool m_elementCreatedByParser;
    150 };
    151 
    152 } //namespace
    153 
    154 #endif
    155