render_flow.h 8.84 KB
Newer Older
1
/*
kocienda's avatar
kocienda committed
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
 * This file is part of the DOM implementation for KDE.
 *
 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
 *           (C) 1999 Antti Koivisto (koivisto@kde.org)
 *
 * 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., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 *
 */
#ifndef RENDER_FLOW_H
#define RENDER_FLOW_H

#include <qsortedlist.h>

#include "render_box.h"
#include "bidi.h"

namespace khtml {

/**
 * all geometry managing stuff is only in the block elements.
 *
 * Inline elements don't layout themselves, but the whole paragraph
 * gets layouted by the surrounding block element. This is, because
 * one needs to know the whole paragraph to calculate bidirectional
 * behaviour of text, so putting the layouting routines in the inline
 * elements is impossible.
 */
class RenderFlow : public RenderBox
{

public:
46
    RenderFlow(DOM::NodeImpl* node);
kocienda's avatar
kocienda committed
47 48 49

    virtual ~RenderFlow();

50
    virtual const char *renderName() const 
51 52 53 54 55
    {
        if (isFloating())
            return "Block (Floating)";
        if (isPositioned())
            return "Block (Positioned)";
56 57
        if (isAnonymousBox()) 
            return "Block (Anonymous)";
58 59 60
        if (isInline()) {
            if (isRelPositioned())
                return "Inline (Rel Positioned)";
61
            return "Inline";
62 63 64
        }
        if (isRelPositioned())
            return "Block (Rel Positioned)";
65 66 67
        return "Block";
    };
    
kocienda's avatar
kocienda committed
68 69 70 71
    virtual void setStyle(RenderStyle *style);

    virtual bool isFlow() const { return true; }
    virtual bool childrenInline() const { return m_childrenInline; }
72 73
    virtual void setChildrenInline(bool b) { m_childrenInline = b; }
    
kocienda's avatar
kocienda committed
74 75
    virtual bool isRendered() const { return true; }

76
    virtual RenderFlow* continuation() const { return m_continuation; }
77
    void setContinuation(RenderFlow* c) { m_continuation = c; }
78 79 80 81 82 83 84
    RenderFlow* continuationBefore(RenderObject* beforeChild);
    
    void splitInlines(RenderFlow* fromBlock, RenderFlow* toBlock, RenderFlow* middleBlock,
                      RenderObject* beforeChild, RenderFlow* oldCont);
    void splitFlow(RenderObject* beforeChild, RenderFlow* newBlockBox, RenderFlow* oldCont);
    void addChildWithContinuation(RenderObject* newChild, RenderObject* beforeChild);
    void addChildToFlow(RenderObject* newChild, RenderObject* beforeChild);
85
    void removeChild(RenderObject *oldChild);
86
    
87
    void makeChildrenNonInline(RenderObject *box2Start = 0);
kocienda's avatar
kocienda committed
88 89 90

    // overrides RenderObject

91 92 93 94
    virtual void paint(QPainter *, int x, int y, int w, int h,
                       int tx, int ty, int paintPhase);
    virtual void paintObject(QPainter *, int x, int y, int w, int h,
                             int tx, int ty, int paintPhase);
95 96 97
    void paintFloats(QPainter *p, int _x, int _y,
                     int _w, int _h, int _tx, int _ty);
                                       
kocienda's avatar
kocienda committed
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
    virtual void layout( );

    virtual void close();

    virtual void addChild(RenderObject *newChild, RenderObject *beforeChild = 0);

    virtual unsigned short lineWidth(int y) const;

    virtual int lowestPosition() const;
    virtual int rightmostPosition() const;

    int rightOffset() const;
    int rightRelOffset(int y, int fixedOffset, int *heightRemaining = 0) const;
    int rightOffset(int y) const { return rightRelOffset(y, rightOffset()); }

    int leftOffset() const;
    int leftRelOffset(int y, int fixedOffset, int *heightRemaining = 0) const;
    int leftOffset(int y) const { return leftRelOffset(y, leftOffset()); }

117
#ifndef NDEBUG
kocienda's avatar
kocienda committed
118
    virtual void printTree(int indent=0) const;
119 120 121
    virtual void dump(QTextStream *stream, QString ind = "") const;
#endif

122
    virtual bool nodeAtPoint(NodeInfo& info, int x, int y, int tx, int ty, bool inside=false);
kocienda's avatar
kocienda committed
123 124 125 126 127

protected:

    virtual void newLine();

128
    void layoutBlockChildren( bool relayoutChildren );
129
    void layoutInlineChildren( bool relayoutChildren );
130
    void layoutSpecialObjects( bool relayoutChildren );
kocienda's avatar
kocienda committed
131 132 133 134 135 136 137

public:
    int floatBottom() const;
    inline int leftBottom();
    inline int rightBottom();
    bool checkClear(RenderObject *child);

138 139 140 141
    // used to calculate offsetWidth/Height.  Overridden by inlines (render_flow) to return
    // the remaining width on a given line (and the height of a single line).
    virtual short offsetWidth() const;
    virtual int offsetHeight() const;
142 143 144
    virtual int offsetLeft() const;
    virtual int offsetTop() const;
    
145 146
    void insertSpecialObject(RenderObject *o);

kocienda's avatar
kocienda committed
147 148 149 150 151 152 153 154
    // from BiDiParagraph
    virtual void closeParagraph() { positionNewFloats(); }

    void removeSpecialObject(RenderObject *o);
    // called from lineWidth, to position the floats added in the last line.
    void positionNewFloats();
    void clearFloats();
    virtual void calcMinMaxWidth();
155 156 157
    void calcInlineMinMaxWidth();
    void calcBlockMinMaxWidth();
    
kocienda's avatar
kocienda committed
158 159 160 161 162 163
    virtual bool containsSpecial() { return specialObjects!=0; }
    virtual bool hasOverhangingFloats() { return floatBottom() > m_height; }

    void addOverHangingFloats( RenderFlow *flow, int xoffset, int yoffset, bool child = false );

    // implementation of the following functions is in bidi.cpp
164
    void bidiReorderLine(const BidiIterator &start, const BidiIterator &end);
165
    BidiIterator findNextLineBreak(BidiIterator &start, QPtrList<BidiIterator>& midpoints);
kocienda's avatar
kocienda committed
166

167
    // The height (and width) of a block when you include overflow spillage out of the bottom
168 169 170
    // of the block (e.g., a <div style="height:25px"> that has a 100px tall image inside
    // it would have an overflow height of borderTop() + paddingTop() + 100px.
    virtual int overflowHeight() const { return m_overflowHeight; }
171
    virtual int overflowWidth() const { return m_overflowWidth; }
172
    
173
    virtual bool isSelfCollapsingBlock() const { return m_height == 0; }
174 175
    virtual bool isTopMarginQuirk() const { return m_topMarginQuirk; }
    virtual bool isBottomMarginQuirk() const { return m_bottomMarginQuirk; }
176
    
177 178 179 180 181 182 183 184 185 186 187 188 189
    virtual short maxTopMargin(bool positive) const {
        if (positive)
            return m_maxTopPosMargin;
        else
            return m_maxTopNegMargin;
    }
    virtual short maxBottomMargin(bool positive) const {
        if (positive)
            return m_maxBottomPosMargin;
        else
            return m_maxBottomNegMargin;
    }

kocienda's avatar
kocienda committed
190 191 192 193 194 195
protected:

    struct SpecialObject {
        enum Type {
            FloatLeft,
            FloatRight,
196 197
            Positioned
        };
198 199

        SpecialObject(Type _type) {
200 201 202 203 204 205
            node = 0;
            startY = 0;
            endY = 0;
            type = _type;
            left = 0;
            width = 0;
206
            count = 0;
207
            noPaint = false;
208
        }
209
        
kocienda's avatar
kocienda committed
210 211 212 213 214 215
        RenderObject* node;
        int startY;
        int endY;
        short left;
        short width;
        short count;
darin's avatar
darin committed
216
        Type type : 2; // left or right aligned
217
        bool noPaint: 1;
218
        
kocienda's avatar
kocienda committed
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237
        bool operator==(const SpecialObject& ) const
        {
            return false;
        }
        bool operator<(const SpecialObject& o) const
        {
            if(node->style()->zIndex() == o.node->style()->zIndex())
                return count < o.count;
            return node->style()->zIndex() < o.node->style()->zIndex();
        }
    };

    QSortedList<SpecialObject>* specialObjects;

private:
    bool m_childrenInline : 1;
    bool m_pre            : 1;
    bool firstLine        : 1; // used in inline layouting
    EClear m_clearStatus  : 2; // used during layuting of paragraphs
238
     
239 240 241 242
    short m_maxTopPosMargin;
    short m_maxTopNegMargin;
    short m_maxBottomPosMargin;
    short m_maxBottomNegMargin;
243 244
    bool m_topMarginQuirk;
    bool m_bottomMarginQuirk;
245
    
246 247 248
    // How much content overflows out of our block vertically or horizontally (all we support
    // for now is spillage out of the bottom and the right, which are the common cases).
    // XXX Generalize to work with top and left as well.
249
    int m_overflowHeight;
250
    int m_overflowWidth;
251 252 253 254 255 256
    
    // An inline can be split with blocks occurring in between the inline content.
    // When this occurs we need a pointer to our next object.  We can basically be
    // split into a sequence of inlines and blocks.  The continuation will either be
    // an anonymous block (that houses other blocks) or it will be an inline flow.
    RenderFlow* m_continuation;
kocienda's avatar
kocienda committed
257 258
};

259
    
kocienda's avatar
kocienda committed
260 261 262
}; //namespace

#endif