summaryrefslogtreecommitdiffstats
path: root/tdehtml/rendering/render_box.h
blob: 0a65df72eea2a2075a900ea790e6ea9fc23451df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/*
 * This file is part of the DOM implementation for KDE.
 *
 * Copyright (C) 1999-2003 Lars Knoll ([email protected])
 *           (C) 1999 Antti Koivisto ([email protected])
 *           (C) 2002-2003 Apple Computer, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this library; see the file COPYING.LIB.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 *
 */
#ifndef RENDER_BOX_H
#define RENDER_BOX_H

#include "render_container.h"

namespace tdehtml {

enum WidthType { Width, MinWidth, MaxWidth };
enum HeightType { Height, MinHeight, MaxHeight };

class RenderBlock;

class RenderBox : public RenderContainer
{


// combines ElemImpl & PosElImpl (all rendering objects are positioned)
// should contain all border and padding handling

public:
    RenderBox(DOM::NodeImpl* node);
    virtual ~RenderBox();

    virtual const char *renderName() const { return "RenderBox"; }
    virtual bool isBox() const { return true; }

    virtual void setStyle(RenderStyle *style);
    virtual void paint(PaintInfo& i, int _tx, int _ty);

    virtual void close();

    virtual InlineBox* createInlineBox(bool makePlaceHolderBox, bool isRootLineBox);
    virtual void deleteInlineBoxes(RenderArena* arena=0);

    virtual void detach();

    virtual short minWidth() const { return m_minWidth; }
    virtual int maxWidth() const { return m_maxWidth; }

    virtual short contentWidth() const;
    virtual int contentHeight() const;

    virtual bool absolutePosition(int &xPos, int &yPos, bool f = false) const;

    virtual void setPos( int xPos, int yPos );

    virtual int xPos() const { return m_x; }
    virtual int yPos() const { return m_y; }
    virtual short width() const;
    virtual int height() const;

    virtual short marginTop() const { return m_marginTop; }
    virtual short marginBottom() const { return m_marginBottom; }
    virtual short marginLeft() const { return m_marginLeft; }
    virtual short marginRight() const { return m_marginRight; }

    virtual void setWidth( int width );
    virtual void setHeight( int height );

    virtual void position(InlineBox* box, int from, int len, bool reverse);

    virtual int highestPosition(bool includeOverflowInterior=true, bool includeSelf=true) const;
    virtual int lowestPosition(bool includeOverflowInterior=true, bool includeSelf=true) const;
    virtual int rightmostPosition(bool includeOverflowInterior=true, bool includeSelf=true) const;
    virtual int leftmostPosition(bool includeOverflowInterior=true, bool includeSelf=true) const;

    virtual void repaint(Priority p=NormalPriority);

    virtual void repaintRectangle(int x, int y, int w, int h, Priority p=NormalPriority, bool f=false);

    virtual short containingBlockWidth() const;
    void relativePositionOffset(int &tx, int &ty) const;

    virtual void calcWidth();
    virtual void calcHeight();

    virtual short calcReplacedWidth() const;
    virtual int   calcReplacedHeight() const;

    virtual int availableHeight() const;
    virtual int availableWidth() const;

    void calcVerticalMargins();

    virtual RenderLayer* layer() const { return m_layer; }

    void setStaticX(short staticX);
    void setStaticY(int staticY);
    int staticX() const { return m_staticX; }
    int staticY() const { return m_staticY; }

    virtual void caretPos(int offset, int flags, int &_x, int &_y, int &width, int &height);

    void calcHorizontalMargins(const Length& ml, const Length& mr, int cw);
    RenderBlock* createAnonymousBlock();

    virtual int pageTopAfter(int y) const;
    virtual int crossesPageBreak(int t, int b) const;

    int calcBoxWidth(int w) const;
    int calcBoxHeight(int h) const;
    int calcContentWidth(int w) const;
    int calcContentHeight(int h) const;

protected:
    int calcWidthUsing(WidthType widthType, int cw, LengthType& lengthType);
    int calcHeightUsing(const Length& height);
    int calcReplacedWidthUsing(WidthType widthType) const;
    int calcReplacedHeightUsing(HeightType heightType) const;
    int calcPercentageHeight(const Length& height, bool treatAsReplaced = false) const;
    int availableHeightUsing(const Length& h) const;
    int availableWidthUsing(const Length& w) const;
    int calcImplicitHeight() const;
    bool hasImplicitHeight() const {
        return isPositioned() && !style()->top().isVariable() && !style()->bottom().isVariable();
    }

protected:
    virtual void paintBoxDecorations(PaintInfo& paintInfo, int _tx, int _ty);
    void paintRootBoxDecorations( PaintInfo& paintInfo, int _tx, int _ty);

    void paintBackgrounds(TQPainter *p, const TQColor& c, const BackgroundLayer* bgLayer, int clipy, int cliph, int _tx, int _ty, int w, int h);
    void paintBackground(TQPainter *p, const TQColor& c, const BackgroundLayer* bgLayer, int clipy, int cliph, int _tx, int _ty, int w, int h);

    virtual void paintBackgroundExtended(TQPainter* /*p*/, const TQColor& /*c*/, const BackgroundLayer* /*bgLayer*/,
                                         int /*clipy*/, int /*cliph*/, int /*_tx*/, int /*_ty*/,
                                         int /*w*/, int /*height*/, int /*bleft*/, int /*bright*/, int /*pleft*/, int /*pright*/ );

    void outlineBox(TQPainter *p, int _tx, int _ty, const char *color = "red");

    void calcAbsoluteHorizontal();
    void calcAbsoluteVertical();
    void calcAbsoluteHorizontalValues(Length width, const RenderObject* cb, EDirection containerDirection,
                                      const int containerWidth, const int bordersPlusPadding,
                                      const Length left, const Length right, const Length marginLeft, const Length marginRight,
                                      short& widthValue, short& marginLeftValue, short& marginRightValue, short& xPos);
    void calcAbsoluteVerticalValues(Length height, const RenderObject* cb,
                                    const int containerHeight, const int bordersPlusPadding,
                                    const Length top, const Length bottom, const Length marginTop, const Length marginBottom,
                                    int& heightValue, short& marginTopValue, short& marginBottomValue, int& yPos);

    void calcAbsoluteVerticalReplaced();
    void calcAbsoluteHorizontalReplaced();

    TQRect getOverflowClipRect(int tx, int ty);
    TQRect getClipRect(int tx, int ty);

    void restructureParentFlow();


    // the actual height of the contents + borders + padding (border-box)
    int m_height;
    int m_y;

    short m_width;
    short m_x;

    short m_marginTop;
    short m_marginBottom;

    short m_marginLeft;
    short m_marginRight;

    /*
     * the minimum width the element needs, to be able to render
     * its content without clipping
     */
    short m_minWidth;
    /* The maximum width the element can fill horizontally
     * ( = the width of the element with line breaking disabled)
     */
    int m_maxWidth;

    // Cached normal flow values for absolute positioned elements with static left/top values.
    short m_staticX;
    int m_staticY;

    RenderLayer *m_layer;

    /* A box used to represent this object on a line
     * when its inner content isn't contextually relevant
     * (e.g replaced or positioned elements)
     */
    InlineBox *m_placeHolderBox;
};


} //namespace

#endif