1/*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 *           (C) 2000 Simon Hausmann <hausmann@kde.org>
4 * Copyright (C) 2006, 2008 Apple Inc. All rights reserved.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB.  If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 *
21 */
22
23#ifndef RenderFrameSet_h
24#define RenderFrameSet_h
25
26#include "RenderBox.h"
27
28namespace WebCore {
29
30class HTMLFrameSetElement;
31class MouseEvent;
32
33enum FrameEdge { LeftFrameEdge, RightFrameEdge, TopFrameEdge, BottomFrameEdge };
34
35struct FrameEdgeInfo {
36    FrameEdgeInfo(bool preventResize = false, bool allowBorder = true)
37        : m_preventResize(4)
38        , m_allowBorder(4)
39    {
40        m_preventResize.fill(preventResize);
41        m_allowBorder.fill(allowBorder);
42    }
43
44    bool preventResize(FrameEdge edge) const { return m_preventResize[edge]; }
45    bool allowBorder(FrameEdge edge) const { return m_allowBorder[edge]; }
46
47    void setPreventResize(FrameEdge edge, bool preventResize) { m_preventResize[edge] = preventResize; }
48    void setAllowBorder(FrameEdge edge, bool allowBorder) { m_allowBorder[edge] = allowBorder; }
49
50private:
51    Vector<bool> m_preventResize;
52    Vector<bool> m_allowBorder;
53};
54
55class RenderFrameSet : public RenderBox {
56public:
57    RenderFrameSet(HTMLFrameSetElement*);
58    virtual ~RenderFrameSet();
59
60    const RenderObjectChildList* children() const { return &m_children; }
61    RenderObjectChildList* children() { return &m_children; }
62
63    FrameEdgeInfo edgeInfo() const;
64
65    bool userResize(MouseEvent*);
66
67    bool isResizingRow() const;
68    bool isResizingColumn() const;
69
70    bool canResizeRow(const IntPoint&) const;
71    bool canResizeColumn(const IntPoint&) const;
72
73#ifdef ANDROID_FLATTEN_FRAMESET
74    void setGridNeedsLayout() { m_gridCalculated = false; }
75#endif
76
77private:
78    static const int noSplit = -1;
79
80    class GridAxis {
81        WTF_MAKE_NONCOPYABLE(GridAxis);
82    public:
83        GridAxis();
84        void resize(int);
85        Vector<int> m_sizes;
86        Vector<int> m_deltas;
87        Vector<bool> m_preventResize;
88        Vector<bool> m_allowBorder;
89        int m_splitBeingResized;
90        int m_splitResizeOffset;
91    };
92
93    virtual RenderObjectChildList* virtualChildren() { return children(); }
94    virtual const RenderObjectChildList* virtualChildren() const { return children(); }
95
96    virtual const char* renderName() const { return "RenderFrameSet"; }
97    virtual bool isFrameSet() const { return true; }
98
99    virtual void layout();
100    virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, int x, int y, int tx, int ty, HitTestAction);
101    virtual void paint(PaintInfo&, int tx, int ty);
102    virtual bool isChildAllowed(RenderObject*, RenderStyle*) const;
103
104    inline HTMLFrameSetElement* frameSet() const;
105
106    bool flattenFrameSet() const;
107
108    void setIsResizing(bool);
109
110    void layOutAxis(GridAxis&, const Length*, int availableSpace);
111    void computeEdgeInfo();
112    void fillFromEdgeInfo(const FrameEdgeInfo& edgeInfo, int r, int c);
113    void positionFrames();
114    void positionFramesWithFlattening();
115
116    int splitPosition(const GridAxis&, int split) const;
117    int hitTestSplit(const GridAxis&, int position) const;
118
119    void startResizing(GridAxis&, int position);
120    void continueResizing(GridAxis&, int position);
121
122    void paintRowBorder(const PaintInfo&, const IntRect&);
123    void paintColumnBorder(const PaintInfo&, const IntRect&);
124
125    RenderObjectChildList m_children;
126
127    GridAxis m_rows;
128    GridAxis m_cols;
129
130    bool m_isResizing;
131    bool m_isChildResizing;
132#ifdef ANDROID_FLATTEN_FRAMESET
133    bool m_gridCalculated;
134#endif
135};
136
137
138inline RenderFrameSet* toRenderFrameSet(RenderObject* object)
139{
140    ASSERT(!object || object->isFrameSet());
141    return static_cast<RenderFrameSet*>(object);
142}
143
144// This will catch anyone doing an unnecessary cast.
145void toRenderFrameSet(const RenderFrameSet*);
146
147} // namespace WebCore
148
149#endif // RenderFrameSet_h
150