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 
28 namespace WebCore {
29 
30 class HTMLFrameSetElement;
31 class MouseEvent;
32 
33 enum FrameEdge { LeftFrameEdge, RightFrameEdge, TopFrameEdge, BottomFrameEdge };
34 
35 struct 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 
preventResizeFrameEdgeInfo44     bool preventResize(FrameEdge edge) const { return m_preventResize[edge]; }
allowBorderFrameEdgeInfo45     bool allowBorder(FrameEdge edge) const { return m_allowBorder[edge]; }
46 
setPreventResizeFrameEdgeInfo47     void setPreventResize(FrameEdge edge, bool preventResize) { m_preventResize[edge] = preventResize; }
setAllowBorderFrameEdgeInfo48     void setAllowBorder(FrameEdge edge, bool allowBorder) { m_allowBorder[edge] = allowBorder; }
49 
50 private:
51     Vector<bool> m_preventResize;
52     Vector<bool> m_allowBorder;
53 };
54 
55 class RenderFrameSet : public RenderBox {
56 public:
57     RenderFrameSet(HTMLFrameSetElement*);
58     virtual ~RenderFrameSet();
59 
children()60     const RenderObjectChildList* children() const { return &m_children; }
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 private:
74     static const int noSplit = -1;
75 
76     class GridAxis {
77         WTF_MAKE_NONCOPYABLE(GridAxis);
78     public:
79         GridAxis();
80         void resize(int);
81         Vector<int> m_sizes;
82         Vector<int> m_deltas;
83         Vector<bool> m_preventResize;
84         Vector<bool> m_allowBorder;
85         int m_splitBeingResized;
86         int m_splitResizeOffset;
87     };
88 
virtualChildren()89     virtual RenderObjectChildList* virtualChildren() { return children(); }
virtualChildren()90     virtual const RenderObjectChildList* virtualChildren() const { return children(); }
91 
renderName()92     virtual const char* renderName() const { return "RenderFrameSet"; }
isFrameSet()93     virtual bool isFrameSet() const { return true; }
94 
95     virtual void layout();
96     virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, int x, int y, int tx, int ty, HitTestAction);
97     virtual void paint(PaintInfo&, int tx, int ty);
98     virtual bool isChildAllowed(RenderObject*, RenderStyle*) const;
99 
100     inline HTMLFrameSetElement* frameSet() const;
101 
102     bool flattenFrameSet() const;
103 
104     void setIsResizing(bool);
105 
106     void layOutAxis(GridAxis&, const Length*, int availableSpace);
107     void computeEdgeInfo();
108     void fillFromEdgeInfo(const FrameEdgeInfo& edgeInfo, int r, int c);
109     void positionFrames();
110     void positionFramesWithFlattening();
111 
112     int splitPosition(const GridAxis&, int split) const;
113     int hitTestSplit(const GridAxis&, int position) const;
114 
115     void startResizing(GridAxis&, int position);
116     void continueResizing(GridAxis&, int position);
117 
118     void paintRowBorder(const PaintInfo&, const IntRect&);
119     void paintColumnBorder(const PaintInfo&, const IntRect&);
120 
121     RenderObjectChildList m_children;
122 
123     GridAxis m_rows;
124     GridAxis m_cols;
125 
126     bool m_isResizing;
127     bool m_isChildResizing;
128 };
129 
130 
toRenderFrameSet(RenderObject * object)131 inline RenderFrameSet* toRenderFrameSet(RenderObject* object)
132 {
133     ASSERT(!object || object->isFrameSet());
134     return static_cast<RenderFrameSet*>(object);
135 }
136 
137 // This will catch anyone doing an unnecessary cast.
138 void toRenderFrameSet(const RenderFrameSet*);
139 
140 } // namespace WebCore
141 
142 #endif // RenderFrameSet_h
143