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 blink {
     34 
     35 class HTMLFormElement;
     36 class ImageCandidate;
     37 class MediaQueryList;
     38 
     39 class HTMLImageElement FINAL : public HTMLElement, public CanvasImageSource {
     40     DEFINE_WRAPPERTYPEINFO();
     41 public:
     42     class ViewportChangeListener;
     43 
     44     static PassRefPtrWillBeRawPtr<HTMLImageElement> create(Document&);
     45     static PassRefPtrWillBeRawPtr<HTMLImageElement> create(Document&, HTMLFormElement*, bool createdByParser);
     46     static PassRefPtrWillBeRawPtr<HTMLImageElement> createForJSConstructor(Document&, int width, int height);
     47 
     48     virtual ~HTMLImageElement();
     49     virtual void trace(Visitor*) OVERRIDE;
     50 
     51     int width(bool ignorePendingStylesheets = false);
     52     int height(bool ignorePendingStylesheets = false);
     53 
     54     int naturalWidth() const;
     55     int naturalHeight() const;
     56     const String& currentSrc() const;
     57 
     58     bool isServerMap() const;
     59 
     60     const AtomicString& altText() const;
     61 
     62     CompositeOperator compositeOperator() const { return m_compositeOperator; }
     63 
     64     ImageResource* cachedImage() const { return imageLoader().image(); }
     65     void setImageResource(ImageResource* i) { imageLoader().setImage(i); };
     66 
     67     void setLoadingImageDocument() { imageLoader().setLoadingImageDocument(); }
     68 
     69     void setHeight(int);
     70 
     71     KURL src() const;
     72     void setSrc(const String&);
     73 
     74     void setWidth(int);
     75 
     76     int x() const;
     77     int y() const;
     78 
     79     bool complete() const;
     80 
     81     bool hasPendingActivity() const { return imageLoader().hasPendingActivity(); }
     82 
     83     virtual bool canContainRangeEndPoint() const OVERRIDE { return false; }
     84 
     85     void addClient(ImageLoaderClient* client) { imageLoader().addClient(client); }
     86     void removeClient(ImageLoaderClient* client) { imageLoader().removeClient(client); }
     87 
     88     virtual const AtomicString imageSourceURL() const OVERRIDE;
     89 
     90     virtual HTMLFormElement* formOwner() const OVERRIDE;
     91     void formRemovedFromTree(const Node& formRoot);
     92 
     93     // CanvasImageSourceImplementations
     94     virtual PassRefPtr<Image> getSourceImageForCanvas(SourceImageMode, SourceImageStatus*) const;
     95     virtual bool wouldTaintOrigin(SecurityOrigin*) const OVERRIDE;
     96     virtual FloatSize sourceSize() const OVERRIDE;
     97     virtual FloatSize defaultDestinationSize() const OVERRIDE;
     98     virtual const KURL& sourceURL() const OVERRIDE;
     99 
    100     // public so that HTMLPictureElement can call this as well.
    101     void selectSourceURL(ImageLoader::UpdateFromElementBehavior);
    102 protected:
    103     explicit HTMLImageElement(Document&, HTMLFormElement* = 0, bool createdByParser = false);
    104 
    105     virtual void didMoveToNewDocument(Document& oldDocument) OVERRIDE;
    106 
    107 private:
    108     virtual bool areAuthorShadowsAllowed() const OVERRIDE { return false; }
    109 
    110     virtual void parseAttribute(const QualifiedName&, const AtomicString&) OVERRIDE;
    111     virtual bool isPresentationAttribute(const QualifiedName&) const OVERRIDE;
    112     virtual void collectStyleForPresentationAttribute(const QualifiedName&, const AtomicString&, MutableStylePropertySet*) OVERRIDE;
    113 
    114     virtual void attach(const AttachContext& = AttachContext()) OVERRIDE;
    115     virtual RenderObject* createRenderer(RenderStyle*) OVERRIDE;
    116 
    117     virtual bool canStartSelection() const OVERRIDE;
    118 
    119     virtual bool isURLAttribute(const Attribute&) const OVERRIDE;
    120     virtual bool hasLegalLinkAttribute(const QualifiedName&) const OVERRIDE;
    121     virtual const QualifiedName& subResourceAttributeName() const OVERRIDE;
    122 
    123     virtual bool draggable() const OVERRIDE;
    124 
    125     virtual InsertionNotificationRequest insertedInto(ContainerNode*) OVERRIDE;
    126     virtual void removedFrom(ContainerNode*) OVERRIDE;
    127     virtual bool shouldRegisterAsNamedItem() const OVERRIDE { return true; }
    128     virtual bool shouldRegisterAsExtraNamedItem() const OVERRIDE { return true; }
    129     virtual bool isInteractiveContent() const OVERRIDE;
    130     virtual Image* imageContents() OVERRIDE;
    131 
    132     void resetFormOwner();
    133     ImageCandidate findBestFitImageFromPictureParent();
    134     void setBestFitURLAndDPRFromImageCandidate(const ImageCandidate&);
    135     HTMLImageLoader& imageLoader() const { return *m_imageLoader; }
    136     void notifyViewportChanged();
    137     void createMediaQueryListIfDoesNotExist();
    138 
    139     OwnPtrWillBeMember<HTMLImageLoader> m_imageLoader;
    140     RefPtrWillBeMember<ViewportChangeListener> m_listener;
    141 #if ENABLE(OILPAN)
    142     Member<HTMLFormElement> m_form;
    143 #else
    144     WeakPtr<HTMLFormElement> m_form;
    145 #endif
    146     CompositeOperator m_compositeOperator;
    147     AtomicString m_bestFitImageURL;
    148     float m_imageDevicePixelRatio;
    149     unsigned m_formWasSetByParser : 1;
    150     unsigned m_elementCreatedByParser : 1;
    151     // Intrinsic sizing is viewport dependant if the 'w' descriptor was used for the picked resource.
    152     unsigned m_intrinsicSizingViewportDependant : 1;
    153     // Effective size is viewport dependant if the sizes attribute's effective size used v* length units.
    154     unsigned m_effectiveSizeViewportDependant : 1;
    155 };
    156 
    157 } // namespace blink
    158 
    159 #endif // HTMLImageElement_h
    160