Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 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 COMPUTER, 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 IN..0TERRUPTION) 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 | #include "config.h" |
| 27 | #include "core/rendering/RenderMultiColumnFlowThread.h" |
| 28 | |
| 29 | #include "core/rendering/RenderMultiColumnBlock.h" |
| 30 | #include "core/rendering/RenderMultiColumnSet.h" |
| 31 | |
| 32 | namespace WebCore { |
| 33 | |
| 34 | RenderMultiColumnFlowThread::RenderMultiColumnFlowThread() |
| 35 | { |
| 36 | setFlowThreadState(InsideInFlowThread); |
| 37 | } |
| 38 | |
| 39 | RenderMultiColumnFlowThread::~RenderMultiColumnFlowThread() |
| 40 | { |
| 41 | } |
| 42 | |
| 43 | RenderMultiColumnFlowThread* RenderMultiColumnFlowThread::createAnonymous(Document* document) |
| 44 | { |
| 45 | RenderMultiColumnFlowThread* renderer = new (document->renderArena()) RenderMultiColumnFlowThread(); |
| 46 | renderer->setDocumentForAnonymous(document); |
| 47 | return renderer; |
| 48 | } |
| 49 | |
| 50 | const char* RenderMultiColumnFlowThread::renderName() const |
Ben Murdoch | 02772c6 | 2013-07-26 10:21:05 +0100 | [diff] [blame^] | 51 | { |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 52 | return "RenderMultiColumnFlowThread"; |
| 53 | } |
| 54 | |
| 55 | void RenderMultiColumnFlowThread::computeLogicalHeight(LayoutUnit logicalHeight, LayoutUnit logicalTop, LogicalExtentComputedValues& computedValues) const |
| 56 | { |
| 57 | // We simply remain at our intrinsic height. |
| 58 | computedValues.m_extent = logicalHeight; |
| 59 | computedValues.m_position = logicalTop; |
| 60 | } |
| 61 | |
| 62 | LayoutUnit RenderMultiColumnFlowThread::initialLogicalWidth() const |
| 63 | { |
| 64 | RenderMultiColumnBlock* parentBlock = toRenderMultiColumnBlock(parent()); |
| 65 | return parentBlock->columnWidth(); |
| 66 | } |
| 67 | |
| 68 | void RenderMultiColumnFlowThread::autoGenerateRegionsToBlockOffset(LayoutUnit /*offset*/) |
| 69 | { |
| 70 | // This function ensures we have the correct column set information at all times. |
| 71 | // For a simple multi-column layout in continuous media, only one column set child is required. |
| 72 | // Once a column is nested inside an enclosing pagination context, the number of column sets |
| 73 | // required becomes 2n-1, where n is the total number of nested pagination contexts. For example: |
| 74 | // |
| 75 | // Column layout with no enclosing pagination model = 2 * 1 - 1 = 1 column set. |
| 76 | // Columns inside pages = 2 * 2 - 1 = 3 column sets (bottom of first page, all the subsequent pages, then the last page). |
| 77 | // Columns inside columns inside pages = 2 * 3 - 1 = 5 column sets. |
| 78 | // |
| 79 | // In addition, column spans will force a column set to "split" into before/after sets around the spanning element. |
| 80 | // |
| 81 | // Finally, we will need to deal with columns inside regions. If regions have variable widths, then there will need |
| 82 | // to be unique column sets created inside any region whose width is different from its surrounding regions. This is |
| 83 | // actually pretty similar to the spanning case, in that we break up the column sets whenever the width varies. |
| 84 | // |
| 85 | // FIXME: For now just make one column set. This matches the old multi-column code. |
| 86 | // Right now our goal is just feature parity with the old multi-column code so that we can switch over to the |
| 87 | // new code as soon as possible. |
| 88 | RenderMultiColumnSet* firstSet = toRenderMultiColumnSet(firstRegion()); |
| 89 | if (firstSet) |
| 90 | return; |
Ben Murdoch | 02772c6 | 2013-07-26 10:21:05 +0100 | [diff] [blame^] | 91 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 92 | invalidateRegions(); |
| 93 | |
| 94 | RenderMultiColumnBlock* parentBlock = toRenderMultiColumnBlock(parent()); |
| 95 | firstSet = RenderMultiColumnSet::createAnonymous(this); |
| 96 | firstSet->setStyle(RenderStyle::createAnonymousStyleWithDisplay(parentBlock->style(), BLOCK)); |
| 97 | parentBlock->RenderBlock::addChild(firstSet); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 98 | |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 99 | // Even though we aren't placed yet, we can go ahead and set up our size. At this point we're |
| 100 | // typically in the middle of laying out the thread, attempting to paginate, and we need to do |
| 101 | // some rudimentary "layout" of the set now, so that pagination will work. |
| 102 | firstSet->prepareForLayout(); |
| 103 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 104 | validateRegions(); |
| 105 | } |
| 106 | |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 107 | void RenderMultiColumnFlowThread::setPageBreak(LayoutUnit offset, LayoutUnit spaceShortage) |
| 108 | { |
| 109 | if (RenderMultiColumnSet* multicolSet = toRenderMultiColumnSet(regionAtBlockOffset(offset))) |
| 110 | multicolSet->recordSpaceShortage(spaceShortage); |
| 111 | } |
| 112 | |
| 113 | void RenderMultiColumnFlowThread::updateMinimumPageHeight(LayoutUnit offset, LayoutUnit minHeight) |
| 114 | { |
| 115 | if (RenderMultiColumnSet* multicolSet = toRenderMultiColumnSet(regionAtBlockOffset(offset))) |
| 116 | multicolSet->updateMinimumColumnHeight(minHeight); |
| 117 | } |
| 118 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 119 | } |