1/* 2 * Copyright (C) 2010 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 <wtf/Vector.h> 30#include "IntRect.h" 31 32namespace WebCore { 33 34class ColumnInfo { 35 WTF_MAKE_NONCOPYABLE(ColumnInfo); WTF_MAKE_FAST_ALLOCATED; 36public: 37 ColumnInfo() 38 : m_desiredColumnWidth(0) 39 , m_desiredColumnCount(1) 40 , m_columnCount(1) 41 , m_columnHeight(0) 42 , m_minimumColumnHeight(0) 43 , m_forcedBreaks(0) 44 , m_maximumDistanceBetweenForcedBreaks(0) 45 , m_forcedBreakOffset(0) 46 { } 47 48 int desiredColumnWidth() const { return m_desiredColumnWidth; } 49 void setDesiredColumnWidth(int width) { m_desiredColumnWidth = width; } 50 51 unsigned desiredColumnCount() const { return m_desiredColumnCount; } 52 void setDesiredColumnCount(unsigned count) { m_desiredColumnCount = count; } 53 54 unsigned columnCount() const { return m_columnCount; } 55 int columnHeight() const { return m_columnHeight; } 56 57 // Set our count and height. This is enough info for a RenderBlock to compute page rects 58 // dynamically. 59 void setColumnCountAndHeight(int count, int height) 60 { 61 m_columnCount = count; 62 m_columnHeight = height; 63 } 64 void setColumnHeight(int height) { m_columnHeight = height; } 65 66 void updateMinimumColumnHeight(int height) { m_minimumColumnHeight = std::max(height, m_minimumColumnHeight); } 67 int minimumColumnHeight() const { return m_minimumColumnHeight; } 68 69 int forcedBreaks() const { return m_forcedBreaks; } 70 int forcedBreakOffset() const { return m_forcedBreakOffset; } 71 int maximumDistanceBetweenForcedBreaks() const { return m_maximumDistanceBetweenForcedBreaks; } 72 void clearForcedBreaks() 73 { 74 m_forcedBreaks = 0; 75 m_maximumDistanceBetweenForcedBreaks = 0; 76 m_forcedBreakOffset = 0; 77 } 78 void addForcedBreak(int offsetFromFirstPage) 79 { 80 ASSERT(!m_columnHeight); 81 int distanceFromLastBreak = offsetFromFirstPage - m_forcedBreakOffset; 82 if (!distanceFromLastBreak) 83 return; 84 m_forcedBreaks++; 85 m_maximumDistanceBetweenForcedBreaks = std::max(m_maximumDistanceBetweenForcedBreaks, distanceFromLastBreak); 86 m_forcedBreakOffset = offsetFromFirstPage; 87 } 88 89private: 90 int m_desiredColumnWidth; 91 unsigned m_desiredColumnCount; 92 93 unsigned m_columnCount; 94 int m_columnHeight; 95 int m_minimumColumnHeight; 96 int m_forcedBreaks; // FIXME: We will ultimately need to cache more information to balance around forced breaks properly. 97 int m_maximumDistanceBetweenForcedBreaks; 98 int m_forcedBreakOffset; 99}; 100 101} 102 103#endif 104