Home | History | Annotate | Download | only in rendering
      1 /*
      2  * Copyright (C) 1999 Lars Knoll (knoll (at) kde.org)
      3  *           (C) 2000 Simon Hausmann <hausmann (at) 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 
     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 
     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 
     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 FLATTEN_FRAMESET
     74     void setGridNeedsLayout() { m_gridCalculated = false; }
     75 #endif
     76     bool flattenFrameSet() const;
     77 
     78 private:
     79     static const int noSplit = -1;
     80 
     81     class GridAxis : public Noncopyable {
     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     void setIsResizing(bool);
    107 
    108     void layOutAxis(GridAxis&, const Length*, int availableSpace);
    109     void computeEdgeInfo();
    110     void fillFromEdgeInfo(const FrameEdgeInfo& edgeInfo, int r, int c);
    111     void positionFrames();
    112     void positionFramesWithFlattening();
    113 
    114     int splitPosition(const GridAxis&, int split) const;
    115     int hitTestSplit(const GridAxis&, int position) const;
    116 
    117     void startResizing(GridAxis&, int position);
    118     void continueResizing(GridAxis&, int position);
    119 
    120     void paintRowBorder(const PaintInfo&, const IntRect&);
    121     void paintColumnBorder(const PaintInfo&, const IntRect&);
    122 
    123     RenderObjectChildList m_children;
    124 
    125     GridAxis m_rows;
    126     GridAxis m_cols;
    127 
    128     bool m_isResizing;
    129     bool m_isChildResizing;
    130 #ifdef FLATTEN_FRAMESET
    131     bool m_gridCalculated;
    132 #endif
    133 };
    134 
    135 
    136 inline RenderFrameSet* toRenderFrameSet(RenderObject* object)
    137 {
    138     ASSERT(!object || object->isFrameSet());
    139     return static_cast<RenderFrameSet*>(object);
    140 }
    141 
    142 // This will catch anyone doing an unnecessary cast.
    143 void toRenderFrameSet(const RenderFrameSet*);
    144 
    145 } // namespace WebCore
    146 
    147 #endif // RenderFrameSet_h
    148