File indexing completed on 2024-04-28 15:23:30

0001 /*
0002  * This file is part of the DOM implementation for KDE.
0003  *
0004  * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
0005  *           (C) 1999 Antti Koivisto (koivisto@kde.org)
0006  *
0007  * This library is free software; you can redistribute it and/or
0008  * modify it under the terms of the GNU Library General Public
0009  * License as published by the Free Software Foundation; either
0010  * version 2 of the License, or (at your option) any later version.
0011  *
0012  * This library is distributed in the hope that it will be useful,
0013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0015  * Library General Public License for more details.
0016  *
0017  * You should have received a copy of the GNU Library General Public License
0018  * along with this library; see the file COPYING.LIB.  If not, write to
0019  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0020  * Boston, MA 02110-1301, USA.
0021  *
0022  */
0023 #ifndef HTML_IMAGEIMPL_H
0024 #define HTML_IMAGEIMPL_H
0025 
0026 #include "html/html_inlineimpl.h"
0027 #include "misc/khtmllayout.h"
0028 #include "misc/loader_client.h"
0029 #include "rendering/render_object.h"
0030 
0031 #include <QRegion>
0032 
0033 namespace DOM
0034 {
0035 
0036 class DOMString;
0037 class HTMLFormElementImpl;
0038 class HTMLCollectionImpl;
0039 
0040 class HTMLImageElementImpl
0041     : public HTMLElementImpl, public khtml::CachedObjectClient
0042 {
0043     friend class HTMLFormElementImpl;
0044 public:
0045     HTMLImageElementImpl(DocumentImpl *doc, HTMLFormElementImpl *f = nullptr);
0046     ~HTMLImageElementImpl();
0047 
0048     Id id() const override;
0049 
0050     void parseAttribute(AttributeImpl *) override;
0051 
0052     void attach() override;
0053     void removedFromDocument() override;
0054     void insertedIntoDocument() override;
0055     void addId(const DOMString &id) override;
0056     void removeId(const DOMString &id) override;
0057 
0058     long width() const;
0059     long height() const;
0060     void setWidth(long width);
0061     void setHeight(long height);
0062 
0063     long x() const;
0064     long y() const;
0065 
0066     bool isServerMap() const
0067     {
0068         return (ismap && !usemap.length());
0069     }
0070     /** Return the image for this element.
0071      *  This has to convert the pixmap into an image first.
0072      *  This will return undefined results if complete() is not true.
0073      */
0074     QImage currentImage() const;
0075     /** Return the pixmap for this element.
0076      *  This will return undefined results if complete() is not true.
0077      */
0078     QPixmap currentPixmap() const;
0079 
0080     DOMString altText() const;
0081 
0082     DOMString imageMap() const
0083     {
0084         return usemap;
0085     }
0086     /** See if the image has been completely downloaded.
0087      * @return True if and only if the image is completely downloaded yet*/
0088     bool complete() const;
0089 
0090     void notifyFinished(khtml::CachedObject *finishedObj) override;
0091     void dispatchLoadEvent();
0092 
0093     khtml::CachedImage *image()
0094     {
0095         return m_image;
0096     }
0097 
0098     // This returns true if this image has (or ever had!) cross-domain data; which will make
0099     // it unsafe to getImageData() it in canvas;
0100     bool isUnsafe() const
0101     {
0102         return unsafe;
0103     }
0104 protected:
0105     DOMString usemap;
0106     bool ismap;
0107     bool loadEventSent;
0108     bool unsafe;
0109     khtml::CachedImage  *m_image;
0110     HTMLFormElementImpl *m_form;
0111     DOMString            m_name;
0112 };
0113 
0114 //------------------------------------------------------------------
0115 
0116 class HTMLAreaElementImpl : public HTMLAnchorElementImpl
0117 {
0118 public:
0119 
0120     enum Shape { Default, Poly, Rect, Circle, Unknown };
0121 
0122     HTMLAreaElementImpl(DocumentImpl *doc);
0123     ~HTMLAreaElementImpl();
0124 
0125     Id id() const override;
0126 
0127     void parseAttribute(AttributeImpl *attr) override;
0128 
0129     bool isDefault() const
0130     {
0131         return shape == Default;
0132     }
0133 
0134     bool mapMouseEvent(int x_, int y_, int width_, int height_,
0135                        khtml::RenderObject::NodeInfo &info);
0136 
0137     QRect getRect() const override;
0138 
0139     QRegion cachedRegion() const
0140     {
0141         return region;
0142     }
0143 
0144 protected:
0145     QRegion getRegion(int width_, int height) const;
0146     QRegion region;
0147     khtml::Length *m_coords;
0148     int m_coordsLen;
0149     int lastw, lasth;
0150     KDE_BF_ENUM(Shape) shape  : 3;
0151     bool nohref  : 1;
0152 };
0153 
0154 // -------------------------------------------------------------------------
0155 
0156 class HTMLMapElementImpl : public HTMLElementImpl
0157 {
0158 public:
0159     HTMLMapElementImpl(DocumentImpl *doc);
0160 
0161     ~HTMLMapElementImpl();
0162 
0163     Id id() const override;
0164 
0165     virtual DOMString getName() const
0166     {
0167         return name;
0168     }
0169 
0170     void parseAttribute(AttributeImpl *attr) override;
0171 
0172     bool mapMouseEvent(int x_, int y_, int width_, int height_,
0173                        khtml::RenderObject::NodeInfo &info);
0174 
0175     HTMLCollectionImpl *areas();
0176 private:
0177 
0178     QString name;
0179 };
0180 
0181 } //namespace
0182 
0183 #endif