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/platform/graphics/GraphicsTypes.h"
     30 
     31 namespace WebCore {
     32 
     33 class HTMLFormElement;
     34 
     35 class HTMLImageElement FINAL : 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);
     45     int height(bool ignorePendingStylesheets = false);
     46 
     47     int naturalWidth() const;
     48     int naturalHeight() const;
     49 
     50     bool isServerMap() const;
     51 
     52     String altText() const;
     53 
     54     CompositeOperator compositeOperator() const { return m_compositeOperator; }
     55 
     56     ImageResource* cachedImage() const { return m_imageLoader.image(); }
     57     void setImageResource(ImageResource* i) { m_imageLoader.setImage(i); };
     58 
     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 
     75     bool hasPendingActivity() const { return m_imageLoader.hasPendingActivity(); }
     76 
     77     virtual bool canContainRangeEndPoint() const { return false; }
     78 
     79     void addClient(ImageLoaderClient* client) { m_imageLoader.addClient(client); }
     80     void removeClient(ImageLoaderClient* client) { m_imageLoader.removeClient(client); }
     81 
     82 protected:
     83     HTMLImageElement(const QualifiedName&, Document*, HTMLFormElement* = 0);
     84 
     85     virtual void didMoveToNewDocument(Document* oldDocument) OVERRIDE;
     86 
     87 private:
     88     virtual bool areAuthorShadowsAllowed() const OVERRIDE { return false; }
     89 
     90     virtual void parseAttribute(const QualifiedName&, const AtomicString&) OVERRIDE;
     91     virtual bool isPresentationAttribute(const QualifiedName&) const OVERRIDE;
     92     virtual void collectStyleForPresentationAttribute(const QualifiedName&, const AtomicString&, MutableStylePropertySet*) OVERRIDE;
     93 
     94     virtual void attach(const AttachContext& = AttachContext()) OVERRIDE;
     95     virtual RenderObject* createRenderer(RenderStyle*);
     96 
     97     virtual bool canStartSelection() const;
     98 
     99     virtual bool isURLAttribute(const Attribute&) const OVERRIDE;
    100 
    101     virtual bool draggable() const;
    102 
    103     virtual void addSubresourceAttributeURLs(ListHashSet<KURL>&) const;
    104 
    105     virtual InsertionNotificationRequest insertedInto(ContainerNode*) OVERRIDE;
    106     virtual void removedFrom(ContainerNode*) OVERRIDE;
    107     virtual bool shouldRegisterAsNamedItem() const OVERRIDE { return true; }
    108     virtual bool shouldRegisterAsExtraNamedItem() const OVERRIDE { return true; }
    109 
    110     virtual Image* imageContents() OVERRIDE;
    111 
    112     HTMLImageLoader m_imageLoader;
    113     HTMLFormElement* m_form;
    114     CompositeOperator m_compositeOperator;
    115 };
    116 
    117 inline HTMLImageElement* toHTMLImageElement(Node* node)
    118 {
    119     ASSERT_WITH_SECURITY_IMPLICATION(!node || node->hasTagName(HTMLNames::imgTag));
    120     return static_cast<HTMLImageElement*>(node);
    121 }
    122 
    123 inline const HTMLImageElement* toHTMLImageElement(const Node* node)
    124 {
    125     ASSERT_WITH_SECURITY_IMPLICATION(!node || node->hasTagName(HTMLNames::imgTag));
    126     return static_cast<const HTMLImageElement*>(node);
    127 }
    128 
    129 } //namespace
    130 
    131 #endif
    132