1 /*
2  * This file is part of the DOM implementation for KDE.
3  *
4  * Copyright (C) 1999-2003 Lars Knoll (knoll@kde.org)
5  *           (C) 1999 Antti Koivisto (koivisto@kde.org)
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 #ifndef RENDER_IMAGE_H
24 #define RENDER_IMAGE_H
25 
26 #include "html/dtd.h"
27 #include "html/html_elementimpl.h"
28 #include "rendering/render_replaced.h"
29 #include "dom/dom_string.h"
30 
31 #include <QMap>
32 #include <QPixmap>
33 
34 namespace khtmlImLoad
35 {
36 class ImagePainter;
37 }
38 
39 namespace khtml
40 {
41 
42 class CachedObject;
43 
44 class RenderImage : public RenderReplaced
45 {
46 public:
47     RenderImage(DOM::NodeImpl *_element);
48     virtual ~RenderImage();
49 
renderName()50     const char *renderName() const override
51     {
52         return "RenderImage";
53     }
54     void paint(PaintInfo &i, int tx, int ty) override;
55 
56     void layout() override;
57 
58     void updatePixmap(const QRect &, CachedImage *) override;
59 
60     // don't even think about making these methods virtual!
61     //QPixmap pixmap() const;
element()62     DOM::HTMLElementImpl *element() const
63     {
64         return static_cast<DOM::HTMLElementImpl *>(RenderObject::element());
65     }
66 
67     bool complete() const;
68 
contentObject()69     CachedObject *contentObject()
70     {
71         return m_cachedImage;
72     }
73     void setContentObject(CachedObject *);
74 
75     // hook to keep RendeObject::m_inline() up to date
76     void setStyle(RenderStyle *style) override;
77     void updateFromElement() override;
78 
79     bool nodeAtPoint(NodeInfo &info, int x, int y, int tx, int ty, HitTestAction hitTestAction, bool inside) override;
80 
81     bool isWidthSpecified() const;
82     bool isHeightSpecified() const;
83 
84     short calcAspectRatioWidth() const;
85     int   calcAspectRatioHeight() const;
86 
87     short calcReplacedWidth() const override;
88     int   calcReplacedHeight() const override;
89 
selectionState()90     SelectionState selectionState() const override
91     {
92         return KDE_CAST_BF_ENUM(SelectionState, m_selectionState);
93     }
setSelectionState(SelectionState s)94     void setSelectionState(SelectionState s) override
95     {
96         m_selectionState = s;
97     }
98 #if 0
99     virtual void caretPos(int offset, int flags, int &_x, int &_y, int &width, int &height) const;
100 #endif
101 
102 private:
103     void updateImage(CachedImage *new_image);
104     /*
105      * Cache for images that need resizing
106      */
107     //QPixmap resizeCache;
108 
109     // text to display as long as the image isn't available
110     DOM::DOMString alt;
111 
112     CachedImage *m_cachedImage;
113     khtmlImLoad::ImagePainter *m_imagePainter;
114 
115     bool berrorPic : 1;
116     bool bUnfinishedImageFrame : 1;
117     KDE_BF_ENUM(SelectionState) m_selectionState : 3; // FIXME: don't forget to enlarge this as the enum grows
118 };
119 
120 } //namespace
121 
122 #endif
123