2 * This file is part of the HTML widget for KDE.
4 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
5 * (C) 2006 Germain Garand (germain@ebooksfrance.org)
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.
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.
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.
23 #ifndef render_replaced_h
24 #define render_replaced_h
26 #include "rendering/render_block.h"
27 #include <QtCore/QObject>
28 #include <QAbstractScrollArea>
42 class RenderReplaced
: public RenderBox
45 RenderReplaced(DOM::NodeImpl
* node
);
47 virtual const char *renderName() const { return "RenderReplaced"; }
48 virtual bool isRenderReplaced() const { return true; }
50 virtual bool childAllowed() const { return false; }
52 virtual void calcMinMaxWidth();
54 virtual short intrinsicWidth() const { return m_intrinsicWidth
; }
55 virtual int intrinsicHeight() const { return m_intrinsicHeight
; }
57 void setIntrinsicWidth(int w
) { m_intrinsicWidth
= w
; }
58 void setIntrinsicHeight(int h
) { m_intrinsicHeight
= h
; }
60 // Return before, after (offset set to max), or inside the replaced element,
62 virtual FindSelectionResult
checkSelectionPoint( int _x
, int _y
, int _tx
, int _ty
,
63 DOM::NodeImpl
*& node
, int & offset
,
66 virtual long caretMinOffset() const;
67 virtual long caretMaxOffset() const;
68 virtual unsigned long caretMaxRenderedOffset() const;
69 virtual DOM::Position
positionForCoordinates(int x
, int y
);
72 short m_intrinsicWidth
;
73 short m_intrinsicHeight
;
76 class RenderWidget
: public QObject
, public RenderReplaced
, public khtml::Shared
<RenderWidget
>
80 RenderWidget(DOM::NodeImpl
* node
);
81 virtual ~RenderWidget();
83 virtual void setStyle(RenderStyle
*style
);
84 virtual void paint( PaintInfo
& i
, int tx
, int ty
);
85 virtual bool isWidget() const { return true; }
87 virtual bool isFrame() const { return false; }
89 virtual void detach( );
90 virtual void layout( );
92 virtual void updateFromElement();
93 virtual void handleFocusOut() {}
95 QWidget
*widget() const { return m_widget
; }
96 KHTMLView
* view() const { return m_view
; }
100 bool needsMask() const { return m_needsMask
; }
102 static void paintWidget(PaintInfo
& pI
, QWidget
*widget
, int tx
, int ty
, QPixmap
* buffer
[] = 0);
103 virtual bool handleEvent(const DOM::EventImpl
& ev
);
104 bool isRedirectedWidget() const;
105 bool isDisabled() const { return m_widget
&& !m_widget
->isEnabled(); }
109 virtual void dump(QTextStream
&stream
, const QString
&ind
) const;
113 void slotWidgetDestructed();
116 // Should be called by subclasses to ensure we don't memory-manage this..
117 void setDoesNotOwnWidget() { m_ownsWidget
= false; }
119 virtual void paintBoxDecorations(PaintInfo
& paintInfo
, int _tx
, int _ty
);
120 virtual void paintOneBackground(QPainter
*p
, const QColor
& c
, const BackgroundLayer
* bgLayer
, QRect clipr
, int _tx
, int _ty
, int w
, int height
);
122 virtual bool canHaveBorder() const { return false; }
123 virtual bool includesPadding() const { return false; }
125 bool shouldPaintBorder() const {
126 // Don't paint borders if the border-style is native
127 // or borders are not supported on this widget
128 return shouldPaintBackgroundOrBorder() && canHaveBorder() &&
129 (style()->borderLeftStyle() != BNATIVE
||
130 style()->borderRightStyle() != BNATIVE
||
131 style()->borderTopStyle() != BNATIVE
||
132 style()->borderBottomStyle() != BNATIVE
);
134 virtual bool acceptsSyntheticEvents() const { return true; }
137 bool event( QEvent
*e
);
139 bool eventFilter(QObject
* /*o*/, QEvent
* e
);
140 void setQWidget(QWidget
*widget
);
141 void resizeWidget( int w
, int h
);
145 QPointer
<QWidget
> m_underMouse
;
146 QPixmap
*m_buffer
[2];
148 //Because we mess with normal detach due to ref/deref,
149 //we need to keep track of the arena ourselves
150 //so it doesn't get yanked from us, etc.
151 SharedPtr
<RenderArena
> m_arena
;
157 virtual int borderTop() const { return canHaveBorder() ? RenderReplaced::borderTop() : 0; }
158 virtual int borderBottom() const { return canHaveBorder() ? RenderReplaced::borderBottom() : 0; }
159 virtual int borderLeft() const { return canHaveBorder() ? RenderReplaced::borderLeft() : 0; }
160 virtual int borderRight() const { return canHaveBorder() ? RenderReplaced::borderRight() : 0; }
162 class EventPropagator
: public QWidget
{
164 void sendEvent(QEvent
*e
);
168 class KHTMLWidgetPrivate
171 KHTMLWidgetPrivate(): m_rw(0), m_redirected(false) {}
172 QPoint
absolutePos();
173 KHTMLView
* rootViewPos(QPoint
& pos
);
174 RenderWidget
* renderWidget() const { return m_rw
; }
175 void setRenderWidget(RenderWidget
* rw
) { m_rw
= rw
; }
176 bool isRedirected() const { return m_redirected
; }
177 void setIsRedirected( bool b
);
178 void setPos( const QPoint
& p
) { m_pos
= p
; }
185 extern bool allowWidgetPaintEvents
;