1 /* 2 * Copyright (C) 2010, 2011 Apple Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26 #ifndef ColumnInfo_h 27 #define ColumnInfo_h 28 29 #include "platform/LayoutUnit.h" 30 #include "wtf/Vector.h" 31 32 namespace WebCore { 33 34 class ColumnInfo { 35 WTF_MAKE_NONCOPYABLE(ColumnInfo); WTF_MAKE_FAST_ALLOCATED; 36 public: ColumnInfo()37 ColumnInfo() 38 : m_desiredColumnWidth(0) 39 , m_desiredColumnCount(1) 40 , m_progressionAxis(InlineAxis) 41 , m_columnCount(1) 42 , m_columnHeight(0) 43 , m_minimumColumnHeight(0) 44 , m_forcedBreaks(0) 45 , m_maximumDistanceBetweenForcedBreaks(0) 46 , m_forcedBreakOffset(0) 47 { 48 } 49 desiredColumnWidth()50 LayoutUnit desiredColumnWidth() const { return m_desiredColumnWidth; } setDesiredColumnWidth(LayoutUnit width)51 void setDesiredColumnWidth(LayoutUnit width) { m_desiredColumnWidth = width; } 52 desiredColumnCount()53 unsigned desiredColumnCount() const { return m_desiredColumnCount; } setDesiredColumnCount(unsigned count)54 void setDesiredColumnCount(unsigned count) { m_desiredColumnCount = count; } 55 56 enum Axis { InlineAxis, BlockAxis }; 57 progressionAxis()58 Axis progressionAxis() const { return m_progressionAxis; } setProgressionAxis(Axis progressionAxis)59 void setProgressionAxis(Axis progressionAxis) { m_progressionAxis = progressionAxis; } 60 columnCount()61 unsigned columnCount() const { return m_columnCount; } columnHeight()62 LayoutUnit columnHeight() const { return m_columnHeight; } 63 64 // Set our count and height. This is enough info for a RenderBlock to compute page rects 65 // dynamically. setColumnCountAndHeight(int count,LayoutUnit height)66 void setColumnCountAndHeight(int count, LayoutUnit height) 67 { 68 m_columnCount = count; 69 m_columnHeight = height; 70 } setColumnHeight(LayoutUnit height)71 void setColumnHeight(LayoutUnit height) { m_columnHeight = height; } 72 updateMinimumColumnHeight(LayoutUnit height)73 void updateMinimumColumnHeight(LayoutUnit height) { m_minimumColumnHeight = std::max(height, m_minimumColumnHeight); } minimumColumnHeight()74 LayoutUnit minimumColumnHeight() const { return m_minimumColumnHeight; } 75 forcedBreaks()76 int forcedBreaks() const { return m_forcedBreaks; } forcedBreakOffset()77 LayoutUnit forcedBreakOffset() const { return m_forcedBreakOffset; } maximumDistanceBetweenForcedBreaks()78 LayoutUnit maximumDistanceBetweenForcedBreaks() const { return m_maximumDistanceBetweenForcedBreaks; } clearForcedBreaks()79 void clearForcedBreaks() 80 { 81 m_forcedBreaks = 0; 82 m_maximumDistanceBetweenForcedBreaks = 0; 83 m_forcedBreakOffset = 0; 84 } addForcedBreak(LayoutUnit offsetFromFirstPage)85 void addForcedBreak(LayoutUnit offsetFromFirstPage) 86 { 87 ASSERT(!m_columnHeight); 88 LayoutUnit distanceFromLastBreak = offsetFromFirstPage - m_forcedBreakOffset; 89 if (!distanceFromLastBreak) 90 return; 91 m_forcedBreaks++; 92 m_maximumDistanceBetweenForcedBreaks = std::max(m_maximumDistanceBetweenForcedBreaks, distanceFromLastBreak); 93 m_forcedBreakOffset = offsetFromFirstPage; 94 } 95 96 private: 97 LayoutUnit m_desiredColumnWidth; 98 unsigned m_desiredColumnCount; 99 Axis m_progressionAxis; 100 101 unsigned m_columnCount; 102 LayoutUnit m_columnHeight; 103 LayoutUnit m_minimumColumnHeight; 104 int m_forcedBreaks; // FIXME: We will ultimately need to cache more information to balance around forced breaks properly. 105 LayoutUnit m_maximumDistanceBetweenForcedBreaks; 106 LayoutUnit m_forcedBreakOffset; 107 }; 108 109 } 110 111 #endif 112