| 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 | #pragma once |
| 24 | |
| 25 | #include "RenderBox.h" |
| 26 | |
| 27 | namespace WebCore { |
| 28 | |
| 29 | class HTMLFrameSetElement; |
| 30 | class MouseEvent; |
| 31 | class RenderFrame; |
| 32 | |
| 33 | enum FrameEdge { LeftFrameEdge, RightFrameEdge, TopFrameEdge, BottomFrameEdge }; |
| 34 | |
| 35 | struct FrameEdgeInfo { |
| 36 | explicit 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 final : public RenderBox { |
| 56 | WTF_MAKE_ISO_ALLOCATED(RenderFrameSet); |
| 57 | public: |
| 58 | RenderFrameSet(HTMLFrameSetElement&, RenderStyle&&); |
| 59 | virtual ~RenderFrameSet(); |
| 60 | |
| 61 | HTMLFrameSetElement& frameSetElement() const; |
| 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 | void notifyFrameEdgeInfoChanged(); |
| 74 | |
| 75 | private: |
| 76 | void element() const = delete; |
| 77 | |
| 78 | static const int noSplit = -1; |
| 79 | |
| 80 | class GridAxis { |
| 81 | WTF_MAKE_NONCOPYABLE(GridAxis); |
| 82 | public: |
| 83 | GridAxis(); |
| 84 | void resize(int); |
| 85 | |
| 86 | Vector<int> m_sizes; |
| 87 | Vector<int> m_deltas; |
| 88 | Vector<bool> m_preventResize; |
| 89 | Vector<bool> m_allowBorder; |
| 90 | int m_splitBeingResized; |
| 91 | int m_splitResizeOffset; |
| 92 | }; |
| 93 | |
| 94 | const char* renderName() const override { return "RenderFrameSet" ; } |
| 95 | bool isFrameSet() const override { return true; } |
| 96 | |
| 97 | void layout() override; |
| 98 | void paint(PaintInfo&, const LayoutPoint&) override; |
| 99 | bool canHaveChildren() const override { return true; } |
| 100 | bool isChildAllowed(const RenderObject&, const RenderStyle&) const override; |
| 101 | CursorDirective getCursor(const LayoutPoint&, Cursor&) const override; |
| 102 | |
| 103 | bool flattenFrameSet() const; |
| 104 | |
| 105 | void setIsResizing(bool); |
| 106 | |
| 107 | void layOutAxis(GridAxis&, const Length*, int availableSpace); |
| 108 | void computeEdgeInfo(); |
| 109 | void fillFromEdgeInfo(const FrameEdgeInfo& edgeInfo, int r, int c); |
| 110 | void positionFrames(); |
| 111 | void positionFramesWithFlattening(); |
| 112 | |
| 113 | int splitPosition(const GridAxis&, int split) const; |
| 114 | int hitTestSplit(const GridAxis&, int position) const; |
| 115 | |
| 116 | void startResizing(GridAxis&, int position); |
| 117 | void continueResizing(GridAxis&, int position); |
| 118 | |
| 119 | void paintRowBorder(const PaintInfo&, const IntRect&); |
| 120 | void paintColumnBorder(const PaintInfo&, const IntRect&); |
| 121 | |
| 122 | GridAxis m_rows; |
| 123 | GridAxis m_cols; |
| 124 | |
| 125 | bool m_isResizing; |
| 126 | bool m_isChildResizing; |
| 127 | }; |
| 128 | |
| 129 | } // namespace WebCore |
| 130 | |
| 131 | SPECIALIZE_TYPE_TRAITS_RENDER_OBJECT(RenderFrameSet, isFrameSet()) |
| 132 | |