18abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)/* 28abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) * Copyright (C) 2013 Google Inc. All rights reserved. 38abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) * 48abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) * Redistribution and use in source and binary forms, with or without 58abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) * modification, are permitted provided that the following conditions are 68abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) * met: 78abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) * 88abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) * * Redistributions of source code must retain the above copyright 98abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) * notice, this list of conditions and the following disclaimer. 108abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) * * Redistributions in binary form must reproduce the above 118abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) * copyright notice, this list of conditions and the following disclaimer 128abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) * in the documentation and/or other materials provided with the 138abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) * distribution. 148abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) * * Neither the name of Google Inc. nor the names of its 158abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) * contributors may be used to endorse or promote products derived from 168abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) * this software without specific prior written permission. 178abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) * 188abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 198abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 208abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 218abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 228abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 238abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 248abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 258abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 268abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 278abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 288abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 298abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) */ 308abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 318abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)#include "config.h" 328abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)#include "core/rendering/RenderBlockFlow.h" 338abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 3409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "core/accessibility/AXObjectCache.h" 351e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)#include "core/frame/FrameView.h" 3609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "core/rendering/FastTextAutosizer.h" 37f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)#include "core/rendering/HitTestLocation.h" 388abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)#include "core/rendering/LayoutRepainter.h" 3909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "core/rendering/RenderFlowThread.h" 408abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)#include "core/rendering/RenderLayer.h" 41d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)#include "core/rendering/RenderMultiColumnFlowThread.h" 4219cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles)#include "core/rendering/RenderText.h" 438abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)#include "core/rendering/RenderView.h" 4409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "core/rendering/line/LineWidth.h" 4519cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles)#include "core/rendering/svg/SVGTextRunRenderingContext.h" 4609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "platform/text/BidiTextRun.h" 478abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 488abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)using namespace std; 498abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 508abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)namespace WebCore { 518abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 52f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)bool RenderBlockFlow::s_canPropagateFloatIntoSibling = false; 53f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 549bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)struct SameSizeAsMarginInfo { 559bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) uint16_t bitfields; 569bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) LayoutUnit margins[2]; 579bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)}; 589bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 599bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)COMPILE_ASSERT(sizeof(RenderBlockFlow::MarginValues) == sizeof(LayoutUnit[4]), MarginValues_should_stay_small); 609bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 619bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)class MarginInfo { 629bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // Collapsing flags for whether we can collapse our margins with our children's margins. 639bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) bool m_canCollapseWithChildren : 1; 649bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) bool m_canCollapseMarginBeforeWithChildren : 1; 659bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) bool m_canCollapseMarginAfterWithChildren : 1; 6609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) bool m_canCollapseMarginAfterWithLastChild: 1; 679bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 689bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // Whether or not we are a quirky container, i.e., do we collapse away top and bottom 699bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // margins in our container. Table cells and the body are the common examples. We 709bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // also have a custom style property for Safari RSS to deal with TypePad blog articles. 719bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) bool m_quirkContainer : 1; 729bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 739bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // This flag tracks whether we are still looking at child margins that can all collapse together at the beginning of a block. 749bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // They may or may not collapse with the top margin of the block (|m_canCollapseTopWithChildren| tells us that), but they will 759bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // always be collapsing with one another. This variable can remain set to true through multiple iterations 769bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // as long as we keep encountering self-collapsing blocks. 779bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) bool m_atBeforeSideOfBlock : 1; 789bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 799bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // This flag is set when we know we're examining bottom margins and we know we're at the bottom of the block. 809bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) bool m_atAfterSideOfBlock : 1; 819bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 829bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // These variables are used to detect quirky margins that we need to collapse away (in table cells 839bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // and in the body element). 849bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) bool m_hasMarginBeforeQuirk : 1; 859bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) bool m_hasMarginAfterQuirk : 1; 869bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) bool m_determinedMarginBeforeQuirk : 1; 879bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 889bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) bool m_discardMargin : 1; 899bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 909bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // These flags track the previous maximal positive and negative margins. 919bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) LayoutUnit m_positiveMargin; 929bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) LayoutUnit m_negativeMargin; 939bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 949bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)public: 959bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) MarginInfo(RenderBlockFlow*, LayoutUnit beforeBorderPadding, LayoutUnit afterBorderPadding); 969bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 979bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) void setAtBeforeSideOfBlock(bool b) { m_atBeforeSideOfBlock = b; } 989bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) void setAtAfterSideOfBlock(bool b) { m_atAfterSideOfBlock = b; } 999bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) void clearMargin() 1009bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) { 1019bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) m_positiveMargin = 0; 1029bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) m_negativeMargin = 0; 1039bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } 1049bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) void setHasMarginBeforeQuirk(bool b) { m_hasMarginBeforeQuirk = b; } 1059bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) void setHasMarginAfterQuirk(bool b) { m_hasMarginAfterQuirk = b; } 1069bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) void setDeterminedMarginBeforeQuirk(bool b) { m_determinedMarginBeforeQuirk = b; } 1079bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) void setPositiveMargin(LayoutUnit p) { ASSERT(!m_discardMargin); m_positiveMargin = p; } 1089bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) void setNegativeMargin(LayoutUnit n) { ASSERT(!m_discardMargin); m_negativeMargin = n; } 1099bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) void setPositiveMarginIfLarger(LayoutUnit p) 1109bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) { 1119bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) ASSERT(!m_discardMargin); 1129bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (p > m_positiveMargin) 1139bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) m_positiveMargin = p; 1149bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } 1159bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) void setNegativeMarginIfLarger(LayoutUnit n) 1169bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) { 1179bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) ASSERT(!m_discardMargin); 1189bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (n > m_negativeMargin) 1199bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) m_negativeMargin = n; 1209bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } 1219bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 1229bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) void setMargin(LayoutUnit p, LayoutUnit n) { ASSERT(!m_discardMargin); m_positiveMargin = p; m_negativeMargin = n; } 1239bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) void setCanCollapseMarginAfterWithChildren(bool collapse) { m_canCollapseMarginAfterWithChildren = collapse; } 12409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) void setCanCollapseMarginAfterWithLastChild(bool collapse) { m_canCollapseMarginAfterWithLastChild = collapse; } 1259bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) void setDiscardMargin(bool value) { m_discardMargin = value; } 1269bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 1279bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) bool atBeforeSideOfBlock() const { return m_atBeforeSideOfBlock; } 1289bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) bool canCollapseWithMarginBefore() const { return m_atBeforeSideOfBlock && m_canCollapseMarginBeforeWithChildren; } 1299bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) bool canCollapseWithMarginAfter() const { return m_atAfterSideOfBlock && m_canCollapseMarginAfterWithChildren; } 1309bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) bool canCollapseMarginBeforeWithChildren() const { return m_canCollapseMarginBeforeWithChildren; } 1319bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) bool canCollapseMarginAfterWithChildren() const { return m_canCollapseMarginAfterWithChildren; } 13209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) bool canCollapseMarginAfterWithLastChild() const { return m_canCollapseMarginAfterWithLastChild; } 1339bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) bool quirkContainer() const { return m_quirkContainer; } 1349bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) bool determinedMarginBeforeQuirk() const { return m_determinedMarginBeforeQuirk; } 1359bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) bool hasMarginBeforeQuirk() const { return m_hasMarginBeforeQuirk; } 1369bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) bool hasMarginAfterQuirk() const { return m_hasMarginAfterQuirk; } 1379bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) LayoutUnit positiveMargin() const { return m_positiveMargin; } 1389bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) LayoutUnit negativeMargin() const { return m_negativeMargin; } 1399bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) bool discardMargin() const { return m_discardMargin; } 1409bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) LayoutUnit margin() const { return m_positiveMargin - m_negativeMargin; } 1419bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)}; 1429bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)static bool inNormalFlow(RenderBox* child) 1439bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles){ 1449bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) RenderBlock* curr = child->containingBlock(); 1459bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) RenderView* renderView = child->view(); 1469bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) while (curr && curr != renderView) { 1479bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (curr->hasColumns() || curr->isRenderFlowThread()) 1489bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) return true; 1499bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (curr->isFloatingOrOutOfFlowPositioned()) 1509bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) return false; 1519bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) curr = curr->containingBlock(); 1529bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } 1539bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) return true; 1549bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)} 1559bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 1568abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)RenderBlockFlow::RenderBlockFlow(ContainerNode* node) 1578abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) : RenderBlock(node) 1588abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles){ 1599bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) COMPILE_ASSERT(sizeof(MarginInfo) == sizeof(SameSizeAsMarginInfo), MarginInfo_should_stay_small); 1608abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)} 1618abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 1628abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)RenderBlockFlow::~RenderBlockFlow() 1638abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles){ 1648abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)} 1658abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 166a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)RenderBlockFlow* RenderBlockFlow::createAnonymous(Document* document) 167a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles){ 168a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) RenderBlockFlow* renderer = new RenderBlockFlow(0); 169a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) renderer->setDocumentForAnonymous(document); 170a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) return renderer; 171a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)} 172a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 173d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)RenderObject* RenderBlockFlow::layoutSpecialExcludedChild(bool relayoutChildren, SubtreeLayoutScope& layoutScope) 174d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles){ 175d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) RenderMultiColumnFlowThread* flowThread = multiColumnFlowThread(); 176d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) if (!flowThread) 177d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) return 0; 178d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) setLogicalTopForChild(flowThread, borderBefore() + paddingBefore()); 179d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) flowThread->layoutColumns(relayoutChildren, layoutScope); 180d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) determineLogicalLeftPositionForChild(flowThread); 181d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) return flowThread; 182d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)} 183d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) 184d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)bool RenderBlockFlow::updateLogicalWidthAndColumnWidth() 185d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles){ 186d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) bool relayoutChildren = RenderBlock::updateLogicalWidthAndColumnWidth(); 187d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) if (RenderMultiColumnFlowThread* flowThread = multiColumnFlowThread()) { 188d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles) if (flowThread->needsNewWidth()) 189d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) return true; 190d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) } 191d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) return relayoutChildren; 192d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)} 193d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) 19409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)void RenderBlockFlow::checkForPaginationLogicalHeightChange(LayoutUnit& pageLogicalHeight, bool& pageLogicalHeightChanged, bool& hasSpecifiedPageLogicalHeight) 19551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){ 196d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) if (RenderMultiColumnFlowThread* flowThread = multiColumnFlowThread()) { 19710f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch LogicalExtentComputedValues computedValues; 19810f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch computeLogicalHeight(LayoutUnit(), logicalTop(), computedValues); 19910f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch LayoutUnit columnHeight = computedValues.m_extent - borderAndPaddingLogicalHeight() - scrollbarLogicalHeight(); 20010f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch pageLogicalHeightChanged = columnHeight != flowThread->columnHeightAvailable(); 20110f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch flowThread->setColumnHeightAvailable(std::max<LayoutUnit>(columnHeight, 0)); 202d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) } else if (hasColumns()) { 203d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) ColumnInfo* colInfo = columnInfo(); 204d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) 20509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (!pageLogicalHeight) { 20609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) LayoutUnit oldLogicalHeight = logicalHeight(); 20709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) setLogicalHeight(0); 20809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) // We need to go ahead and set our explicit page height if one exists, so that we can 20909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) // avoid doing two layout passes. 21009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) updateLogicalHeight(); 21109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) LayoutUnit columnHeight = contentLogicalHeight(); 21209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (columnHeight > 0) { 21309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) pageLogicalHeight = columnHeight; 21409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) hasSpecifiedPageLogicalHeight = true; 21509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) } 21609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) setLogicalHeight(oldLogicalHeight); 21709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) } 21809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (colInfo->columnHeight() != pageLogicalHeight && everHadLayout()) { 21909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) colInfo->setColumnHeight(pageLogicalHeight); 22009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) pageLogicalHeightChanged = true; 22109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) } 22251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 22309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (!hasSpecifiedPageLogicalHeight && !pageLogicalHeight) 22409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) colInfo->clearForcedBreaks(); 22509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) } else if (isRenderFlowThread()) { 22607a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch RenderFlowThread* flowThread = toRenderFlowThread(this); 22707a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch 22807a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch // FIXME: This is a hack to always make sure we have a page logical height, if said height 22907a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch // is known. The page logical height thing in LayoutState is meaningless for flow 23007a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch // thread-based pagination (page height isn't necessarily uniform throughout the flow 23107a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch // thread), but as long as it is used universally as a means to determine whether page 23207a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch // height is known or not, we need this. Page height is unknown when column balancing is 23307a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch // enabled and flow thread height is still unknown (i.e. during the first layout pass). When 23407a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch // it's unknown, we need to prevent the pagination code from assuming page breaks everywhere 23507a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch // and thereby eating every top margin. It should be trivial to clean up and get rid of this 23607a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch // hack once the old multicol implementation is gone. 23707a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch pageLogicalHeight = flowThread->isPageLogicalHeightKnown() ? LayoutUnit(1) : LayoutUnit(0); 23807a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch 23907a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch pageLogicalHeightChanged = flowThread->pageLogicalSizeChanged(); 24009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) } 24151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)} 24251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 24309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)bool RenderBlockFlow::shouldRelayoutForPagination(LayoutUnit& pageLogicalHeight, LayoutUnit layoutOverflowLogicalBottom) const 244a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles){ 245a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // FIXME: We don't balance properly at all in the presence of forced page breaks. We need to understand what 246a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // the distance between forced page breaks is so that we can avoid making the minimum column height too tall. 247a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) ColumnInfo* colInfo = columnInfo(); 24809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) LayoutUnit columnHeight = pageLogicalHeight; 24909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) const int minColumnCount = colInfo->forcedBreaks() + 1; 25009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) const int desiredColumnCount = colInfo->desiredColumnCount(); 25109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (minColumnCount >= desiredColumnCount) { 25209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) // The forced page breaks are in control of the balancing. Just set the column height to the 25309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) // maximum page break distance. 25409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (!pageLogicalHeight) { 25509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) LayoutUnit distanceBetweenBreaks = max<LayoutUnit>(colInfo->maximumDistanceBetweenForcedBreaks(), 256d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) view()->layoutState()->pageLogicalOffset(*this, borderBefore() + paddingBefore() + layoutOverflowLogicalBottom) - colInfo->forcedBreakOffset()); 25709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) columnHeight = max(colInfo->minimumColumnHeight(), distanceBetweenBreaks); 258a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) } 25909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) } else if (layoutOverflowLogicalBottom > boundedMultiply(pageLogicalHeight, desiredColumnCount)) { 26009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) // Now that we know the intrinsic height of the columns, we have to rebalance them. 26143e7502580f146aa5b3db8267ba6dbb5c733a489Torne (Richard Coles) columnHeight = max<LayoutUnit>(colInfo->minimumColumnHeight(), ceilf(layoutOverflowLogicalBottom.toFloat() / desiredColumnCount)); 26209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) } 263a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 26409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (columnHeight && columnHeight != pageLogicalHeight) { 26509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) pageLogicalHeight = columnHeight; 26609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return true; 267a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) } 268a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 26909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return false; 27009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)} 27109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 27209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)void RenderBlockFlow::setColumnCountAndHeight(unsigned count, LayoutUnit pageLogicalHeight) 27309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){ 27409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) ColumnInfo* colInfo = columnInfo(); 275a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) if (pageLogicalHeight) 27609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) colInfo->setColumnCountAndHeight(count, pageLogicalHeight); 277a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 278a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) if (columnCount(colInfo)) { 279a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) setLogicalHeight(borderBefore() + paddingBefore() + colInfo->columnHeight() + borderAfter() + paddingAfter() + scrollbarLogicalHeight()); 280a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) m_overflow.clear(); 281a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) } 28209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)} 283a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 28409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)bool RenderBlockFlow::isSelfCollapsingBlock() const 28509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){ 28609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) m_hasOnlySelfCollapsingChildren = RenderBlock::isSelfCollapsingBlock(); 28709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return m_hasOnlySelfCollapsingChildren; 288a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)} 289a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 29009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)void RenderBlockFlow::layoutBlock(bool relayoutChildren) 2918abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles){ 2928abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) ASSERT(needsLayout()); 29309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) ASSERT(isInlineBlockOrInlineTable() || !isInline()); 2948abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 29509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) // If we are self-collapsing with self-collapsing descendants this will get set to save us burrowing through our 29609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) // descendants every time in |isSelfCollapsingBlock|. We reset it here so that |isSelfCollapsingBlock| attempts to burrow 29709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) // at least once and so that it always gives a reliable result reflecting the latest layout. 29809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) m_hasOnlySelfCollapsingChildren = false; 2998abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 3008abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) if (!relayoutChildren && simplifiedLayout()) 3018abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) return; 3028abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 30310f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch SubtreeLayoutScope layoutScope(*this); 30409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 30509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) // Multiple passes might be required for column and pagination based layout 30609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) // In the case of the old column code the number of passes will only be two 30709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) // however, in the newer column code the number of passes could equal the 30809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) // number of columns. 30909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) bool done = false; 31009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) LayoutUnit pageLogicalHeight = 0; 3115d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles) LayoutRepainter repainter(*this, checkForPaintInvalidationDuringLayout()); 31209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) while (!done) 31309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) done = layoutBlockFlow(relayoutChildren, pageLogicalHeight, layoutScope); 31407a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch 31507a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch fitBorderToLinesIfNeeded(); 31607a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch 31707a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch RenderView* renderView = view(); 31807a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch if (renderView->layoutState()->pageLogicalHeight()) 31907a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch setPageLogicalOffset(renderView->layoutState()->pageLogicalOffset(*this, logicalTop())); 32007a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch 32176c265b59aa821ccbf8c75ab2bb0d036e97d2956Torne (Richard Coles) updateLayerTransformAfterLayout(); 32207a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch 32307a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch // Update our scroll information if we're overflow:auto/scroll/hidden now that we know if 32407a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch // we overflow or not. 32507a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch updateScrollInfoAfterLayout(); 32607a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch 32707a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch // Repaint with our new bounds if they are different from our old bounds. 32807a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch bool didFullRepaint = repainter.repaintAfterLayout(); 32907a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch if (!didFullRepaint && m_repaintLogicalTop != m_repaintLogicalBottom && (style()->visibility() == VISIBLE || enclosingLayer()->hasVisibleContent())) { 33007a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch if (RuntimeEnabledFeatures::repaintAfterLayoutEnabled()) 331f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles) setShouldInvalidateOverflowForPaint(true); 33207a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch else 3335d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles) invalidatePaintForOverflow(); 33407a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch } 33507a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch clearNeedsLayout(); 33609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)} 33709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 33809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)inline bool RenderBlockFlow::layoutBlockFlow(bool relayoutChildren, LayoutUnit &pageLogicalHeight, SubtreeLayoutScope& layoutScope) 33909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){ 340d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) LayoutUnit oldLeft = logicalLeft(); 3418abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) if (updateLogicalWidthAndColumnWidth()) 3428abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) relayoutChildren = true; 3438abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 3441e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) rebuildFloatsFromIntruding(); 3458abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 3468abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) bool pageLogicalHeightChanged = false; 3478abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) bool hasSpecifiedPageLogicalHeight = false; 3488abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) checkForPaginationLogicalHeightChange(pageLogicalHeight, pageLogicalHeightChanged, hasSpecifiedPageLogicalHeight); 349a9984bf9ddc3cf73fdae3f29134a2bab379e7029Ben Murdoch if (pageLogicalHeightChanged) 350a9984bf9ddc3cf73fdae3f29134a2bab379e7029Ben Murdoch relayoutChildren = true; 3518abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 3525d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles) LayoutState state(*this, locationOffset(), pageLogicalHeight, pageLogicalHeightChanged, columnInfo()); 3538abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 3548abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) // We use four values, maxTopPos, maxTopNeg, maxBottomPos, and maxBottomNeg, to track 3558abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) // our current maximal positive and negative margins. These values are used when we 3568abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) // are collapsed with adjacent blocks, so for example, if you have block A and B 3578abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) // collapsing together, then you'd take the maximal positive margin from both A and B 3588abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) // and subtract it from the maximal negative margin from both A and B to get the 3598abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) // true collapsed margin. This algorithm is recursive, so when we finish layout() 3608abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) // our block knows its current maximal positive/negative values. 3618abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) // 3628abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) // Start out by setting our margin values to our current margins. Table cells have 3638abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) // no margins, so we don't fill in the values for table cells. 36409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (!isTableCell()) { 3658abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) initMaxMarginValues(); 36609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) setHasMarginBeforeQuirk(style()->hasMarginBeforeQuirk()); 36709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) setHasMarginAfterQuirk(style()->hasMarginAfterQuirk()); 3688abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) setPaginationStrut(0); 3698abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) } 3708abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 37109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) LayoutUnit beforeEdge = borderBefore() + paddingBefore(); 37209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) LayoutUnit afterEdge = borderAfter() + paddingAfter() + scrollbarLogicalHeight(); 37309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) LayoutUnit previousHeight = logicalHeight(); 37409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) setLogicalHeight(beforeEdge); 3758abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 376a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) m_repaintLogicalTop = 0; 377a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) m_repaintLogicalBottom = 0; 3788abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) if (!firstChild() && !isAnonymousBlock()) 3798abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) setChildrenInline(true); 38009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 381d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) FastTextAutosizer::LayoutScope fastTextAutosizerLayoutScope(this); 38209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 3838abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) if (childrenInline()) 38409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) layoutInlineChildren(relayoutChildren, m_repaintLogicalTop, m_repaintLogicalBottom, afterEdge); 3858abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) else 38610f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch layoutBlockChildren(relayoutChildren, layoutScope, beforeEdge, afterEdge); 3878abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 3888abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) // Expand our intrinsic height to encompass floats. 38909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (lowestFloatLogicalBottom() > (logicalHeight() - afterEdge) && createsBlockFormattingContext()) 39009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) setLogicalHeight(lowestFloatLogicalBottom() + afterEdge); 3918abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 392d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) if (RenderMultiColumnFlowThread* flowThread = multiColumnFlowThread()) { 393d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) if (flowThread->recalculateColumnHeights()) { 39409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) setChildNeedsLayout(MarkOnlyThis); 39509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return false; 39609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) } 39709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) } else if (hasColumns()) { 39809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) OwnPtr<RenderOverflow> savedOverflow = m_overflow.release(); 39909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (childrenInline()) 40009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) addOverflowFromInlineChildren(); 40109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) else 40209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) addOverflowFromBlockChildren(); 40309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) LayoutUnit layoutOverflowLogicalBottom = (isHorizontalWritingMode() ? layoutOverflowRect().maxY() : layoutOverflowRect().maxX()) - borderBefore() - paddingBefore(); 40409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) m_overflow = savedOverflow.release(); 40509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 40609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (!hasSpecifiedPageLogicalHeight && shouldRelayoutForPagination(pageLogicalHeight, layoutOverflowLogicalBottom)) { 40709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) setEverHadLayout(true); 40809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return false; 40909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) } 41009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 41143e7502580f146aa5b3db8267ba6dbb5c733a489Torne (Richard Coles) setColumnCountAndHeight(ceilf(layoutOverflowLogicalBottom.toFloat() / pageLogicalHeight.toFloat()), pageLogicalHeight.toFloat()); 41209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) } 41309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 41409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (shouldBreakAtLineToAvoidWidow()) { 41509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) setEverHadLayout(true); 41609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return false; 417bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) } 4188abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 4198abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) // Calculate our new height. 4208abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) LayoutUnit oldHeight = logicalHeight(); 4218abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) LayoutUnit oldClientAfterEdge = clientLogicalBottom(); 4228abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 4238abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) updateLogicalHeight(); 4248abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) LayoutUnit newHeight = logicalHeight(); 42510f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch if (oldHeight > newHeight && !childrenInline()) { 42610f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch // One of our children's floats may have become an overhanging float for us. 42710f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch for (RenderObject* child = lastChild(); child; child = child->previousSibling()) { 42810f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch if (child->isRenderBlockFlow() && !child->isFloatingOrOutOfFlowPositioned()) { 42910f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch RenderBlockFlow* block = toRenderBlockFlow(child); 43010f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch if (block->lowestFloatLogicalBottom() + block->logicalTop() <= newHeight) 43110f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch break; 43210f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch addOverhangingFloats(block, false); 4338abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) } 4348abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) } 4358abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) } 4368abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 4378abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) bool heightChanged = (previousHeight != newHeight); 4388abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) if (heightChanged) 4398abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) relayoutChildren = true; 4408abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 4416f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch layoutPositionedObjects(relayoutChildren || isDocumentElement(), oldLeft != logicalLeft() ? ForcedLayoutAfterContainingBlockMoved : DefaultLayout); 4428abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 44307a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch computeRegionRangeForBlock(flowThreadContainingBlock()); 4448abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 4458abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) // Add overflow from children (unless we're multi-column, since in that case all our child overflow is clipped anyway). 4468abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) computeOverflow(oldClientAfterEdge); 4478abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 44809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return true; 4498abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)} 4508abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 451d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)void RenderBlockFlow::determineLogicalLeftPositionForChild(RenderBox* child, ApplyLayoutDeltaMode applyDelta) 452d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles){ 453d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) LayoutUnit startPosition = borderStart() + paddingStart(); 454d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) if (style()->shouldPlaceBlockDirectionScrollbarOnLogicalLeft()) 455d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) startPosition -= verticalScrollbarWidth(); 456d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) LayoutUnit totalAvailableLogicalWidth = borderAndPaddingLogicalWidth() + availableLogicalWidth(); 457d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) 458d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) // Add in our start margin. 459d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) LayoutUnit childMarginStart = marginStartForChild(child); 460d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) LayoutUnit newPosition = startPosition + childMarginStart; 461d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) 462d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) // Some objects (e.g., tables, horizontal rules, overflow:auto blocks) avoid floats. They need 463d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) // to shift over as necessary to dodge any floats that might get in the way. 464d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) if (child->avoidsFloats() && containsFloats() && !flowThreadContainingBlock()) 465d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) newPosition += computeStartPositionDeltaForChildAvoidingFloats(child, marginStartForChild(child)); 466d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) 467d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) setLogicalLeftForChild(child, style()->isLeftToRightDirection() ? newPosition : totalAvailableLogicalWidth - newPosition - logicalWidthForChild(child), applyDelta); 468d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)} 469d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) 470d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)void RenderBlockFlow::setLogicalLeftForChild(RenderBox* child, LayoutUnit logicalLeft, ApplyLayoutDeltaMode applyDelta) 471d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles){ 472d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) if (isHorizontalWritingMode()) { 473d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) if (applyDelta == ApplyLayoutDelta && !RuntimeEnabledFeatures::repaintAfterLayoutEnabled()) 474d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) view()->addLayoutDelta(LayoutSize(child->x() - logicalLeft, 0)); 475d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) child->setX(logicalLeft); 476d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) } else { 477d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) if (applyDelta == ApplyLayoutDelta && !RuntimeEnabledFeatures::repaintAfterLayoutEnabled()) 478d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) view()->addLayoutDelta(LayoutSize(0, child->y() - logicalLeft)); 479d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) child->setY(logicalLeft); 480d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) } 481d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)} 482d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) 483d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)void RenderBlockFlow::setLogicalTopForChild(RenderBox* child, LayoutUnit logicalTop, ApplyLayoutDeltaMode applyDelta) 484d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles){ 485d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) if (isHorizontalWritingMode()) { 486d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) if (applyDelta == ApplyLayoutDelta && !RuntimeEnabledFeatures::repaintAfterLayoutEnabled()) 487d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) view()->addLayoutDelta(LayoutSize(0, child->y() - logicalTop)); 488d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) child->setY(logicalTop); 489d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) } else { 490d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) if (applyDelta == ApplyLayoutDelta && !RuntimeEnabledFeatures::repaintAfterLayoutEnabled()) 491d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) view()->addLayoutDelta(LayoutSize(child->x() - logicalTop, 0)); 492d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) child->setX(logicalTop); 493d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) } 494d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)} 495d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) 49610f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdochvoid RenderBlockFlow::layoutBlockChild(RenderBox* child, MarginInfo& marginInfo, LayoutUnit& previousFloatLogicalBottom) 4979bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles){ 4989bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) LayoutUnit oldPosMarginBefore = maxPositiveMarginBefore(); 4999bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) LayoutUnit oldNegMarginBefore = maxNegativeMarginBefore(); 5009bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 5019bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // The child is a normal flow object. Compute the margins we will use for collapsing now. 5029bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) child->computeAndSetBlockDirectionMargins(this); 5039bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 5049bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // Try to guess our correct logical top position. In most cases this guess will 5059bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // be correct. Only if we're wrong (when we compute the real logical top position) 5069bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // will we have to potentially relayout. 5079bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) LayoutUnit estimateWithoutPagination; 5089bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) LayoutUnit logicalTopEstimate = estimateLogicalTopPosition(child, marginInfo, estimateWithoutPagination); 5099bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 5109bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // Cache our old rect so that we can dirty the proper repaint rects if the child moves. 5119bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) LayoutRect oldRect = child->frameRect(); 5129bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) LayoutUnit oldLogicalTop = logicalTopForChild(child); 5139bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 5145d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)#if ASSERT_ENABLED 51509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) LayoutSize oldLayoutDelta = RuntimeEnabledFeatures::repaintAfterLayoutEnabled() ? LayoutSize() : view()->layoutDelta(); 5169bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)#endif 5179bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // Go ahead and position the child as though it didn't collapse with the top. 5189bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) setLogicalTopForChild(child, logicalTopEstimate, ApplyLayoutDelta); 5199bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 5209bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) RenderBlock* childRenderBlock = child->isRenderBlock() ? toRenderBlock(child) : 0; 521f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) RenderBlockFlow* childRenderBlockFlow = (childRenderBlock && child->isRenderBlockFlow()) ? toRenderBlockFlow(child) : 0; 5229bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) bool markDescendantsWithFloats = false; 5239bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (logicalTopEstimate != oldLogicalTop && !child->avoidsFloats() && childRenderBlock && childRenderBlock->containsFloats()) { 5249bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) markDescendantsWithFloats = true; 5259bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } else if (UNLIKELY(logicalTopEstimate.mightBeSaturated())) { 5269bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // logicalTopEstimate, returned by estimateLogicalTopPosition, might be saturated for 5279bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // very large elements. If it does the comparison with oldLogicalTop might yield a 5289bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // false negative as adding and removing margins, borders etc from a saturated number 5299bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // might yield incorrect results. If this is the case always mark for layout. 5309bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) markDescendantsWithFloats = true; 5319bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } else if (!child->avoidsFloats() || child->shrinkToAvoidFloats()) { 5329bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // If an element might be affected by the presence of floats, then always mark it for 5339bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // layout. 5349bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) LayoutUnit fb = max(previousFloatLogicalBottom, lowestFloatLogicalBottom()); 5359bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (fb > logicalTopEstimate) 5369bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) markDescendantsWithFloats = true; 5379bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } 5389bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 539f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (childRenderBlockFlow) { 5409bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (markDescendantsWithFloats) 541f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) childRenderBlockFlow->markAllDescendantsWithFloatsForLayout(); 5429bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (!child->isWritingModeRoot()) 543f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) previousFloatLogicalBottom = max(previousFloatLogicalBottom, oldLogicalTop + childRenderBlockFlow->lowestFloatLogicalBottom()); 5449bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } 5459bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 54610f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch SubtreeLayoutScope layoutScope(*child); 5479bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (!child->needsLayout()) 5489bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) child->markForPaginationRelayoutIfNeeded(layoutScope); 5499bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 5509bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) bool childHadLayout = child->everHadLayout(); 5519bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) bool childNeededLayout = child->needsLayout(); 5529bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (childNeededLayout) 5539bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) child->layout(); 5549bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 5559bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // Cache if we are at the top of the block right now. 5569bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) bool atBeforeSideOfBlock = marginInfo.atBeforeSideOfBlock(); 55709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) bool childIsSelfCollapsing = child->isSelfCollapsingBlock(); 5589bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 5599bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // Now determine the correct ypos based off examination of collapsing margin 5609bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // values. 56109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) LayoutUnit logicalTopBeforeClear = collapseMargins(child, marginInfo, childIsSelfCollapsing); 5629bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 5639bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // Now check for clear. 56409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) LayoutUnit logicalTopAfterClear = clearFloatsIfNeeded(child, marginInfo, oldPosMarginBefore, oldNegMarginBefore, logicalTopBeforeClear, childIsSelfCollapsing); 5659bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 5669bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) bool paginated = view()->layoutState()->isPaginated(); 5679bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (paginated) { 5689bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) logicalTopAfterClear = adjustBlockChildForPagination(logicalTopAfterClear, estimateWithoutPagination, child, 5699bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) atBeforeSideOfBlock && logicalTopBeforeClear == logicalTopAfterClear); 5709bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } 5719bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 5729bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) setLogicalTopForChild(child, logicalTopAfterClear, ApplyLayoutDelta); 5739bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 5749bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // Now we have a final top position. See if it really does end up being different from our estimate. 5759bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // clearFloatsIfNeeded can also mark the child as needing a layout even though we didn't move. This happens 5769bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // when collapseMargins dynamically adds overhanging floats because of a child with negative margins. 5779bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (logicalTopAfterClear != logicalTopEstimate || child->needsLayout() || (paginated && childRenderBlock && childRenderBlock->shouldBreakAtLineToAvoidWidow())) { 57810f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch SubtreeLayoutScope layoutScope(*child); 5799bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (child->shrinkToAvoidFloats()) { 5809bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // The child's width depends on the line width. 5819bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // When the child shifts to clear an item, its width can 5829bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // change (because it has more available line width). 5839bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // So go ahead and mark the item as dirty. 5849bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) layoutScope.setChildNeedsLayout(child); 5859bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } 5869bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 5879bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (childRenderBlock) { 5889bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (!child->avoidsFloats() && childRenderBlock->containsFloats()) 589f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) childRenderBlockFlow->markAllDescendantsWithFloatsForLayout(); 5909bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (!child->needsLayout()) 5919bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) child->markForPaginationRelayoutIfNeeded(layoutScope); 5929bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } 5939bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 5949bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // Our guess was wrong. Make the child lay itself out again. 5959bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) child->layoutIfNeeded(); 5969bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } 5979bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 59809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) // If we previously encountered a self-collapsing sibling of this child that had clearance then 59909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) // we set this bit to ensure we would not collapse the child's margins, and those of any subsequent 60009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) // self-collapsing siblings, with our parent. If this child is not self-collapsing then it can 60109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) // collapse its margins with the parent so reset the bit. 60209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (!marginInfo.canCollapseMarginAfterWithLastChild() && !childIsSelfCollapsing) 60309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) marginInfo.setCanCollapseMarginAfterWithLastChild(true); 60409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 6059bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // We are no longer at the top of the block if we encounter a non-empty child. 6069bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // This has to be done after checking for clear, so that margins can be reset if a clear occurred. 60709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (marginInfo.atBeforeSideOfBlock() && !childIsSelfCollapsing) 6089bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) marginInfo.setAtBeforeSideOfBlock(false); 6099bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 6109bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // Now place the child in the correct left position 6119bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) determineLogicalLeftPositionForChild(child, ApplyLayoutDelta); 6129bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 61306f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles) LayoutSize childOffset = child->location() - oldRect.location(); 61406f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles) 6159bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // Update our height now that the child has been placed in the correct position. 6169bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) setLogicalHeight(logicalHeight() + logicalHeightForChild(child)); 6179bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (mustSeparateMarginAfterForChild(child)) { 6189bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) setLogicalHeight(logicalHeight() + marginAfterForChild(child)); 6199bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) marginInfo.clearMargin(); 6209bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } 6219bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // If the child has overhanging floats that intrude into following siblings (or possibly out 6229bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // of this block), then the parent gets notified of the floats now. 62310f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch if (childRenderBlockFlow) 62410f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch addOverhangingFloats(childRenderBlockFlow, !childNeededLayout); 6259bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 6269bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (childOffset.width() || childOffset.height()) { 62709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (!RuntimeEnabledFeatures::repaintAfterLayoutEnabled()) 62809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) view()->addLayoutDelta(childOffset); 6299bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 6309bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // If the child moved, we have to repaint it as well as any floating/positioned 6319bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // descendants. An exception is if we need a layout. In this case, we know we're going to 6329bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // repaint ourselves (and the child) anyway. 633a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) if (RuntimeEnabledFeatures::repaintAfterLayoutEnabled() && childHadLayout && !selfNeedsLayout()) 634a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) child->repaintOverhangingFloats(true); 6355d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles) else if (childHadLayout && !selfNeedsLayout() && child->checkForPaintInvalidationDuringLayout()) 6369bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) child->repaintDuringLayoutIfMoved(oldRect); 6379bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } 6389bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 6395d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles) if (!childHadLayout && child->checkForPaintInvalidation()) { 640a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) if (!RuntimeEnabledFeatures::repaintAfterLayoutEnabled()) 6415d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles) child->paintInvalidationForWholeRenderer(); 6429bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) child->repaintOverhangingFloats(true); 6439bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } 6449bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 6459bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (paginated) { 6469bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // Check for an after page/column break. 6479bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) LayoutUnit newHeight = applyAfterBreak(child, logicalHeight(), marginInfo); 6489bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (newHeight != height()) 6499bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) setLogicalHeight(newHeight); 6509bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } 6519bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 65209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (!RuntimeEnabledFeatures::repaintAfterLayoutEnabled()) { 65309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) ASSERT(view()->layoutDeltaMatches(oldLayoutDelta)); 65409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) } 6559bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)} 6569bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 6579bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)LayoutUnit RenderBlockFlow::adjustBlockChildForPagination(LayoutUnit logicalTopAfterClear, LayoutUnit estimateWithoutPagination, RenderBox* child, bool atBeforeSideOfBlock) 6589bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles){ 6599bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) RenderBlock* childRenderBlock = child->isRenderBlock() ? toRenderBlock(child) : 0; 6609bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 6619bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (estimateWithoutPagination != logicalTopAfterClear) { 6629bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // Our guess prior to pagination movement was wrong. Before we attempt to paginate, let's try again at the new 6639bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // position. 6649bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) setLogicalHeight(logicalTopAfterClear); 6659bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) setLogicalTopForChild(child, logicalTopAfterClear, ApplyLayoutDelta); 6669bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 6679bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (child->shrinkToAvoidFloats()) { 6689bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // The child's width depends on the line width. 6699bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // When the child shifts to clear an item, its width can 6709bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // change (because it has more available line width). 6719bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // So go ahead and mark the item as dirty. 6729bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) child->setChildNeedsLayout(MarkOnlyThis); 6739bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } 6749bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 67510f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch SubtreeLayoutScope layoutScope(*child); 6769bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 6779bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (childRenderBlock) { 6789bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (!child->avoidsFloats() && childRenderBlock->containsFloats()) 679f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) toRenderBlockFlow(childRenderBlock)->markAllDescendantsWithFloatsForLayout(); 6809bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (!child->needsLayout()) 6819bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) child->markForPaginationRelayoutIfNeeded(layoutScope); 6829bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } 6839bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 6849bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // Our guess was wrong. Make the child lay itself out again. 6859bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) child->layoutIfNeeded(); 6869bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } 6879bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 6889bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) LayoutUnit oldTop = logicalTopAfterClear; 6899bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 6909bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // If the object has a page or column break value of "before", then we should shift to the top of the next page. 6919bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) LayoutUnit result = applyBeforeBreak(child, logicalTopAfterClear); 6929bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 6939bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // For replaced elements and scrolled elements, we want to shift them to the next page if they don't fit on the current one. 6949bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) LayoutUnit logicalTopBeforeUnsplittableAdjustment = result; 6959bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) LayoutUnit logicalTopAfterUnsplittableAdjustment = adjustForUnsplittableChild(child, result); 6969bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 6979bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) LayoutUnit paginationStrut = 0; 6989bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) LayoutUnit unsplittableAdjustmentDelta = logicalTopAfterUnsplittableAdjustment - logicalTopBeforeUnsplittableAdjustment; 699d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles) LayoutUnit childLogicalHeight = child->logicalHeight(); 700d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles) if (unsplittableAdjustmentDelta) { 701d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles) setPageBreak(result, childLogicalHeight - unsplittableAdjustmentDelta); 7029bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) paginationStrut = unsplittableAdjustmentDelta; 703d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles) } else if (childRenderBlock && childRenderBlock->paginationStrut()) { 7049bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) paginationStrut = childRenderBlock->paginationStrut(); 705d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles) } 7069bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 7079bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (paginationStrut) { 7089bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // We are willing to propagate out to our parent block as long as we were at the top of the block prior 7099bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // to collapsing our margins, and as long as we didn't clear or move as a result of other pagination. 7109bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (atBeforeSideOfBlock && oldTop == result && !isOutOfFlowPositioned() && !isTableCell()) { 7119bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // FIXME: Should really check if we're exceeding the page height before propagating the strut, but we don't 7129bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // have all the information to do so (the strut only has the remaining amount to push). Gecko gets this wrong too 7139bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // and pushes to the next page anyway, so not too concerned about it. 7149bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) setPaginationStrut(result + paginationStrut); 7159bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (childRenderBlock) 7169bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) childRenderBlock->setPaginationStrut(0); 7179bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } else { 7189bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) result += paginationStrut; 7199bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } 7209bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } 7219bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 722d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles) if (!unsplittableAdjustmentDelta) { 723d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles) if (LayoutUnit pageLogicalHeight = pageLogicalHeightForOffset(result)) { 724d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles) LayoutUnit remainingLogicalHeight = pageRemainingLogicalHeightForOffset(result, ExcludePageBoundary); 725d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles) LayoutUnit spaceShortage = childLogicalHeight - remainingLogicalHeight; 726d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles) if (spaceShortage > 0) { 727d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles) // If the child crosses a column boundary, report a break, in case nothing inside it 728d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles) // has already done so. The column balancer needs to know how much it has to stretch 729d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles) // the columns to make more content fit. If no breaks are reported (but do occur), 730d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles) // the balancer will have no clue. Only measure the space after the last column 731d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles) // boundary, in case it crosses more than one. 732d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles) LayoutUnit spaceShortageInLastColumn = intMod(spaceShortage, pageLogicalHeight); 733d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles) setPageBreak(result, spaceShortageInLastColumn ? spaceShortageInLastColumn : spaceShortage); 734d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles) } else if (remainingLogicalHeight == pageLogicalHeight && offsetFromLogicalTopOfFirstPage() + child->logicalTop()) { 735d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles) // We're at the very top of a page or column, and it's not the first one. This child 736d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles) // may turn out to be the smallest piece of content that causes a page break, so we 737d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles) // need to report it. 738d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles) setPageBreak(result, childLogicalHeight); 739d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles) } 740d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles) } 741d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles) } 742d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles) 7439bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // Similar to how we apply clearance. Go ahead and boost height() to be the place where we're going to position the child. 7449bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) setLogicalHeight(logicalHeight() + (result - oldTop)); 7459bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 7469bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // Return the final adjusted logical top. 7479bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) return result; 7489bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)} 7499bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 7501e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)void RenderBlockFlow::rebuildFloatsFromIntruding() 7518abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles){ 7528abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) if (m_floatingObjects) 7538abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) m_floatingObjects->setHorizontalWritingMode(isHorizontalWritingMode()); 7548abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 7558abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) HashSet<RenderBox*> oldIntrudingFloatSet; 7568abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) if (!childrenInline() && m_floatingObjects) { 7578abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); 7588abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) FloatingObjectSetIterator end = floatingObjectSet.end(); 7598abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) for (FloatingObjectSetIterator it = floatingObjectSet.begin(); it != end; ++it) { 760d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles) FloatingObject* floatingObject = it->get(); 7618abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) if (!floatingObject->isDescendant()) 7628abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) oldIntrudingFloatSet.add(floatingObject->renderer()); 7638abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) } 7648abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) } 7658abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 7668abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) // Inline blocks are covered by the isReplaced() check in the avoidFloats method. 767c4de9692585dd12fa75b760eebef04fa43fc1ae6Bo Liu if (avoidsFloats() || isDocumentElement() || isRenderView() || isFloatingOrOutOfFlowPositioned() || isTableCell()) { 7688abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) if (m_floatingObjects) { 7698abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) m_floatingObjects->clear(); 7708abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) } 7718abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) if (!oldIntrudingFloatSet.isEmpty()) 7728abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) markAllDescendantsWithFloatsForLayout(); 7738abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) return; 7748abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) } 7758abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 7768abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) RendererToFloatInfoMap floatMap; 7778abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 7788abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) if (m_floatingObjects) { 7799bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (childrenInline()) 7809bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) m_floatingObjects->moveAllToFloatInfoMap(floatMap); 7819bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) else 7829bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) m_floatingObjects->clear(); 7838abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) } 7848abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 785f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // We should not process floats if the parent node is not a RenderBlockFlow. Otherwise, we will add 7868abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) // floats in an invalid context. This will cause a crash arising from a bad cast on the parent. 7878abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) // See <rdar://problem/8049753>, where float property is applied on a text node in a SVG. 788f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (!parent() || !parent()->isRenderBlockFlow()) 7898abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) return; 7908abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 791f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu // Attempt to locate a previous sibling with overhanging floats. We skip any elements that 792f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu // may have shifted to avoid floats, and any objects whose floats cannot interact with objects 793f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu // outside it (i.e. objects that create a new block formatting context). 794f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) RenderBlockFlow* parentBlockFlow = toRenderBlockFlow(parent()); 7958abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) bool parentHasFloats = false; 7968abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) RenderObject* prev = previousSibling(); 797c4de9692585dd12fa75b760eebef04fa43fc1ae6Bo Liu while (prev && (!prev->isBox() || !prev->isRenderBlock() || toRenderBlock(prev)->avoidsFloats() || toRenderBlock(prev)->createsBlockFormattingContext())) { 7988abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) if (prev->isFloating()) 7998abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) parentHasFloats = true; 8008abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) prev = prev->previousSibling(); 8018abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) } 8028abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 803a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // First add in floats from the parent. Self-collapsing blocks let their parent track any floats that intrude into 804a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // them (as opposed to floats they contain themselves) so check for those here too. 8058abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) LayoutUnit logicalTopOffset = logicalTop(); 80610f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch bool parentHasIntrudingFloats = !parentHasFloats && (!prev || toRenderBlockFlow(prev)->isSelfCollapsingBlock()) && parentBlockFlow->lowestFloatLogicalBottom() > logicalTopOffset; 80710f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch if (parentHasFloats || parentHasIntrudingFloats) 808f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) addIntrudingFloats(parentBlockFlow, parentBlockFlow->logicalLeftOffsetForContent(), logicalTopOffset); 8098abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 81010f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch // Add overhanging floats from the previous RenderBlockFlow, but only if it has a float that intrudes into our space. 8118abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) if (prev) { 81210f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch RenderBlockFlow* blockFlow = toRenderBlockFlow(prev); 81310f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch logicalTopOffset -= blockFlow->logicalTop(); 81410f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch if (blockFlow->lowestFloatLogicalBottom() > logicalTopOffset) 81510f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch addIntrudingFloats(blockFlow, 0, logicalTopOffset); 8168abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) } 8178abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 8188abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) if (childrenInline()) { 8198abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) LayoutUnit changeLogicalTop = LayoutUnit::max(); 8208abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) LayoutUnit changeLogicalBottom = LayoutUnit::min(); 8218abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) if (m_floatingObjects) { 8228abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); 8238abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) FloatingObjectSetIterator end = floatingObjectSet.end(); 8248abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) for (FloatingObjectSetIterator it = floatingObjectSet.begin(); it != end; ++it) { 825d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles) FloatingObject* floatingObject = it->get(); 826f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) FloatingObject* oldFloatingObject = floatMap.get(floatingObject->renderer()); 827f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) LayoutUnit logicalBottom = logicalBottomForFloat(floatingObject); 8288abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) if (oldFloatingObject) { 829f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) LayoutUnit oldLogicalBottom = logicalBottomForFloat(oldFloatingObject); 830f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (logicalWidthForFloat(floatingObject) != logicalWidthForFloat(oldFloatingObject) || logicalLeftForFloat(floatingObject) != logicalLeftForFloat(oldFloatingObject)) { 8318abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) changeLogicalTop = 0; 8328abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) changeLogicalBottom = max(changeLogicalBottom, max(logicalBottom, oldLogicalBottom)); 8338abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) } else { 8348abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) if (logicalBottom != oldLogicalBottom) { 8358abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) changeLogicalTop = min(changeLogicalTop, min(logicalBottom, oldLogicalBottom)); 8368abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) changeLogicalBottom = max(changeLogicalBottom, max(logicalBottom, oldLogicalBottom)); 8378abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) } 838f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) LayoutUnit logicalTop = logicalTopForFloat(floatingObject); 839f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) LayoutUnit oldLogicalTop = logicalTopForFloat(oldFloatingObject); 8408abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) if (logicalTop != oldLogicalTop) { 8418abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) changeLogicalTop = min(changeLogicalTop, min(logicalTop, oldLogicalTop)); 8428abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) changeLogicalBottom = max(changeLogicalBottom, max(logicalTop, oldLogicalTop)); 8438abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) } 8448abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) } 8458abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 8468abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) if (oldFloatingObject->originatingLine() && !selfNeedsLayout()) { 8478abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) ASSERT(oldFloatingObject->originatingLine()->renderer() == this); 8488abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) oldFloatingObject->originatingLine()->markDirty(); 8498abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) } 850d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles) 851d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles) floatMap.remove(floatingObject->renderer()); 8528abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) } else { 8538abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) changeLogicalTop = 0; 8548abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) changeLogicalBottom = max(changeLogicalBottom, logicalBottom); 8558abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) } 8568abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) } 8578abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) } 8588abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 8598abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) RendererToFloatInfoMap::iterator end = floatMap.end(); 8608abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) for (RendererToFloatInfoMap::iterator it = floatMap.begin(); it != end; ++it) { 861d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles) OwnPtr<FloatingObject>& floatingObject = it->value; 8628abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) if (!floatingObject->isDescendant()) { 8638abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) changeLogicalTop = 0; 864d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles) changeLogicalBottom = max(changeLogicalBottom, logicalBottomForFloat(floatingObject.get())); 8658abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) } 8668abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) } 8678abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 8688abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) markLinesDirtyInBlockRange(changeLogicalTop, changeLogicalBottom); 8698abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) } else if (!oldIntrudingFloatSet.isEmpty()) { 8708abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) // If there are previously intruding floats that no longer intrude, then children with floats 8718abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) // should also get layout because they might need their floating object lists cleared. 8728abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) if (m_floatingObjects->set().size() < oldIntrudingFloatSet.size()) { 8738abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) markAllDescendantsWithFloatsForLayout(); 8748abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) } else { 8758abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); 8768abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) FloatingObjectSetIterator end = floatingObjectSet.end(); 8778abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) for (FloatingObjectSetIterator it = floatingObjectSet.begin(); it != end && !oldIntrudingFloatSet.isEmpty(); ++it) 8788abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) oldIntrudingFloatSet.remove((*it)->renderer()); 8798abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) if (!oldIntrudingFloatSet.isEmpty()) 8808abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) markAllDescendantsWithFloatsForLayout(); 8818abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) } 8828abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) } 8838abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)} 8848abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 88510f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdochvoid RenderBlockFlow::layoutBlockChildren(bool relayoutChildren, SubtreeLayoutScope& layoutScope, LayoutUnit beforeEdge, LayoutUnit afterEdge) 8868abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles){ 8878abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) dirtyForLayoutFromPercentageHeightDescendants(layoutScope); 8888abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 8898abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) // The margin struct caches all our current margin collapsing state. The compact struct caches state when we encounter compacts, 8908abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) MarginInfo marginInfo(this, beforeEdge, afterEdge); 8918abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 8928abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) // Fieldsets need to find their legend and position it inside the border of the object. 8938abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) // The legend then gets skipped during normal layout. The same is true for ruby text. 8948abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) // It doesn't get included in the normal layout process but is instead skipped. 8958abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) RenderObject* childToExclude = layoutSpecialExcludedChild(relayoutChildren, layoutScope); 8968abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 8978abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) LayoutUnit previousFloatLogicalBottom = 0; 8988abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 8998abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) RenderBox* next = firstChildBox(); 90009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) RenderBox* lastNormalFlowChild = 0; 9018abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 9028abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) while (next) { 9038abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) RenderBox* child = next; 9048abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) next = child->nextSiblingBox(); 9058abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 906a9984bf9ddc3cf73fdae3f29134a2bab379e7029Ben Murdoch // FIXME: this should only be set from clearNeedsLayout crbug.com/361250 907a9984bf9ddc3cf73fdae3f29134a2bab379e7029Ben Murdoch child->setLayoutDidGetCalled(true); 908a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 9098abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) if (childToExclude == child) 9108abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) continue; // Skip this child, since it will be positioned by the specialized subclass (fieldsets and ruby runs). 9118abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 9128abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) updateBlockChildDirtyBitsBeforeLayout(relayoutChildren, child); 9138abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 9148abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) if (child->isOutOfFlowPositioned()) { 9158abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) child->containingBlock()->insertPositionedObject(child); 9168abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) adjustPositionedBlock(child, marginInfo); 9178abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) continue; 9188abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) } 9198abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) if (child->isFloating()) { 9208abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) insertFloatingObject(child); 9218abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) adjustFloatingBlock(marginInfo); 9228abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) continue; 9238abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) } 9248abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 9258abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) // Lay out the child. 92610f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch layoutBlockChild(child, marginInfo, previousFloatLogicalBottom); 92709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) lastNormalFlowChild = child; 9288abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) } 9298abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 9308abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) // Now do the handling of the bottom of the block, adding in our bottom border/padding and 9318abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) // determining the correct collapsed bottom margin information. 93209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) handleAfterSideOfBlock(lastNormalFlowChild, beforeEdge, afterEdge, marginInfo); 9338abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)} 9348abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 9359bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)// Our MarginInfo state used when laying out block children. 9369bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)MarginInfo::MarginInfo(RenderBlockFlow* blockFlow, LayoutUnit beforeBorderPadding, LayoutUnit afterBorderPadding) 93709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) : m_canCollapseMarginAfterWithLastChild(true) 93809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) , m_atBeforeSideOfBlock(true) 9399bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) , m_atAfterSideOfBlock(false) 9409bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) , m_hasMarginBeforeQuirk(false) 9419bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) , m_hasMarginAfterQuirk(false) 9429bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) , m_determinedMarginBeforeQuirk(false) 9439bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) , m_discardMargin(false) 9449bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles){ 9459bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) RenderStyle* blockStyle = blockFlow->style(); 9469bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) ASSERT(blockFlow->isRenderView() || blockFlow->parent()); 94709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) m_canCollapseWithChildren = !blockFlow->createsBlockFormattingContext() && !blockFlow->isRenderFlowThread() && !blockFlow->isRenderView(); 9489bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 9499bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) m_canCollapseMarginBeforeWithChildren = m_canCollapseWithChildren && !beforeBorderPadding && blockStyle->marginBeforeCollapse() != MSEPARATE; 9509bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 9519bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // If any height other than auto is specified in CSS, then we don't collapse our bottom 9529bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // margins with our children's margins. To do otherwise would be to risk odd visual 9539bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // effects when the children overflow out of the parent block and yet still collapse 9549bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // with it. We also don't collapse if we have any bottom border/padding. 9559bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) m_canCollapseMarginAfterWithChildren = m_canCollapseWithChildren && !afterBorderPadding 9569bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) && (blockStyle->logicalHeight().isAuto() && !blockStyle->logicalHeight().value()) && blockStyle->marginAfterCollapse() != MSEPARATE; 9579bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 9589bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) m_quirkContainer = blockFlow->isTableCell() || blockFlow->isBody(); 9599bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 9609bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) m_discardMargin = m_canCollapseMarginBeforeWithChildren && blockFlow->mustDiscardMarginBefore(); 9619bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 9629bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) m_positiveMargin = (m_canCollapseMarginBeforeWithChildren && !blockFlow->mustDiscardMarginBefore()) ? blockFlow->maxPositiveMarginBefore() : LayoutUnit(); 9639bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) m_negativeMargin = (m_canCollapseMarginBeforeWithChildren && !blockFlow->mustDiscardMarginBefore()) ? blockFlow->maxNegativeMarginBefore() : LayoutUnit(); 9649bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)} 9659bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 9669bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)RenderBlockFlow::MarginValues RenderBlockFlow::marginValuesForChild(RenderBox* child) const 9679bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles){ 9689bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) LayoutUnit childBeforePositive = 0; 9699bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) LayoutUnit childBeforeNegative = 0; 9709bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) LayoutUnit childAfterPositive = 0; 9719bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) LayoutUnit childAfterNegative = 0; 9729bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 9739bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) LayoutUnit beforeMargin = 0; 9749bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) LayoutUnit afterMargin = 0; 9759bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 9769bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) RenderBlockFlow* childRenderBlockFlow = child->isRenderBlockFlow() ? toRenderBlockFlow(child) : 0; 9779bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 9789bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // If the child has the same directionality as we do, then we can just return its 9799bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // margins in the same direction. 9809bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (!child->isWritingModeRoot()) { 9819bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (childRenderBlockFlow) { 9829bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) childBeforePositive = childRenderBlockFlow->maxPositiveMarginBefore(); 9839bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) childBeforeNegative = childRenderBlockFlow->maxNegativeMarginBefore(); 9849bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) childAfterPositive = childRenderBlockFlow->maxPositiveMarginAfter(); 9859bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) childAfterNegative = childRenderBlockFlow->maxNegativeMarginAfter(); 9869bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } else { 9879bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) beforeMargin = child->marginBefore(); 9889bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) afterMargin = child->marginAfter(); 9899bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } 9909bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } else if (child->isHorizontalWritingMode() == isHorizontalWritingMode()) { 9919bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // The child has a different directionality. If the child is parallel, then it's just 9929bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // flipped relative to us. We can use the margins for the opposite edges. 9939bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (childRenderBlockFlow) { 9949bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) childBeforePositive = childRenderBlockFlow->maxPositiveMarginAfter(); 9959bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) childBeforeNegative = childRenderBlockFlow->maxNegativeMarginAfter(); 9969bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) childAfterPositive = childRenderBlockFlow->maxPositiveMarginBefore(); 9979bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) childAfterNegative = childRenderBlockFlow->maxNegativeMarginBefore(); 9989bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } else { 9999bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) beforeMargin = child->marginAfter(); 10009bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) afterMargin = child->marginBefore(); 10019bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } 10029bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } else { 10039bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // The child is perpendicular to us, which means its margins don't collapse but are on the 10049bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // "logical left/right" sides of the child box. We can just return the raw margin in this case. 10059bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) beforeMargin = marginBeforeForChild(child); 10069bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) afterMargin = marginAfterForChild(child); 10079bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } 10089bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 10099bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // Resolve uncollapsing margins into their positive/negative buckets. 10109bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (beforeMargin) { 10119bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (beforeMargin > 0) 10129bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) childBeforePositive = beforeMargin; 10139bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) else 10149bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) childBeforeNegative = -beforeMargin; 10159bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } 10169bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (afterMargin) { 10179bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (afterMargin > 0) 10189bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) childAfterPositive = afterMargin; 10199bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) else 10209bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) childAfterNegative = -afterMargin; 10219bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } 10229bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 10239bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) return RenderBlockFlow::MarginValues(childBeforePositive, childBeforeNegative, childAfterPositive, childAfterNegative); 10249bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)} 10259bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 102609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)LayoutUnit RenderBlockFlow::collapseMargins(RenderBox* child, MarginInfo& marginInfo, bool childIsSelfCollapsing) 10279bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles){ 10289bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) bool childDiscardMarginBefore = mustDiscardMarginBeforeForChild(child); 10299bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) bool childDiscardMarginAfter = mustDiscardMarginAfterForChild(child); 10309bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 10319bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // The child discards the before margin when the the after margin has discard in the case of a self collapsing block. 10329bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) childDiscardMarginBefore = childDiscardMarginBefore || (childDiscardMarginAfter && childIsSelfCollapsing); 10339bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 10349bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // Get the four margin values for the child and cache them. 10359bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) const RenderBlockFlow::MarginValues childMargins = marginValuesForChild(child); 10369bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 10379bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // Get our max pos and neg top margins. 10389bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) LayoutUnit posTop = childMargins.positiveMarginBefore(); 10399bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) LayoutUnit negTop = childMargins.negativeMarginBefore(); 10409bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 10419bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // For self-collapsing blocks, collapse our bottom margins into our 10429bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // top to get new posTop and negTop values. 10439bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (childIsSelfCollapsing) { 10449bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) posTop = max(posTop, childMargins.positiveMarginAfter()); 10459bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) negTop = max(negTop, childMargins.negativeMarginAfter()); 10469bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } 10479bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 10489bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // See if the top margin is quirky. We only care if this child has 10499bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // margins that will collapse with us. 10509bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) bool topQuirk = hasMarginBeforeQuirk(child); 10519bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 10529bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (marginInfo.canCollapseWithMarginBefore()) { 10539bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (!childDiscardMarginBefore && !marginInfo.discardMargin()) { 10549bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // This child is collapsing with the top of the 10559bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // block. If it has larger margin values, then we need to update 10569bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // our own maximal values. 10579bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (!document().inQuirksMode() || !marginInfo.quirkContainer() || !topQuirk) 10589bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) setMaxMarginBeforeValues(max(posTop, maxPositiveMarginBefore()), max(negTop, maxNegativeMarginBefore())); 10599bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 10609bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // The minute any of the margins involved isn't a quirk, don't 10619bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // collapse it away, even if the margin is smaller (www.webreference.com 10629bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // has an example of this, a <dt> with 0.8em author-specified inside 10639bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // a <dl> inside a <td>. 10649bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (!marginInfo.determinedMarginBeforeQuirk() && !topQuirk && (posTop - negTop)) { 10659bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) setHasMarginBeforeQuirk(false); 10669bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) marginInfo.setDeterminedMarginBeforeQuirk(true); 10679bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } 10689bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 10699bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (!marginInfo.determinedMarginBeforeQuirk() && topQuirk && !marginBefore()) { 10709bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // We have no top margin and our top child has a quirky margin. 10719bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // We will pick up this quirky margin and pass it through. 10729bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // This deals with the <td><div><p> case. 10739bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // Don't do this for a block that split two inlines though. You do 10749bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // still apply margins in this case. 10759bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) setHasMarginBeforeQuirk(true); 10769bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } 10779bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } else { 10789bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // The before margin of the container will also discard all the margins it is collapsing with. 10799bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) setMustDiscardMarginBefore(); 10809bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } 10819bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } 10829bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 10839bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // Once we find a child with discardMarginBefore all the margins collapsing with us must also discard. 10849bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (childDiscardMarginBefore) { 10859bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) marginInfo.setDiscardMargin(true); 10869bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) marginInfo.clearMargin(); 10879bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } 10889bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 10899bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (marginInfo.quirkContainer() && marginInfo.atBeforeSideOfBlock() && (posTop - negTop)) 10909bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) marginInfo.setHasMarginBeforeQuirk(topQuirk); 10919bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 10929bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) LayoutUnit beforeCollapseLogicalTop = logicalHeight(); 10939bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) LayoutUnit logicalTop = beforeCollapseLogicalTop; 1094a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 1095a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) LayoutUnit clearanceForSelfCollapsingBlock; 1096a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) RenderObject* prev = child->previousSibling(); 109709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) RenderBlockFlow* previousBlockFlow = prev && prev->isRenderBlockFlow() && !prev->isFloatingOrOutOfFlowPositioned() ? toRenderBlockFlow(prev) : 0; 1098a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // If the child's previous sibling is a self-collapsing block that cleared a float then its top border edge has been set at the bottom border edge 1099a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // of the float. Since we want to collapse the child's top margin with the self-collapsing block's top and bottom margins we need to adjust our parent's height to match the 1100a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // margin top of the self-collapsing block. If the resulting collapsed margin leaves the child still intruding into the float then we will want to clear it. 110109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (!marginInfo.canCollapseWithMarginBefore() && previousBlockFlow && previousBlockFlow->isSelfCollapsingBlock()) { 110209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) clearanceForSelfCollapsingBlock = previousBlockFlow->marginOffsetForSelfCollapsingBlock(); 1103a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) setLogicalHeight(logicalHeight() - clearanceForSelfCollapsingBlock); 1104a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) } 1105a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 11069bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (childIsSelfCollapsing) { 11079bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // For a self collapsing block both the before and after margins get discarded. The block doesn't contribute anything to the height of the block. 11089bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // Also, the child's top position equals the logical height of the container. 11099bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (!childDiscardMarginBefore && !marginInfo.discardMargin()) { 11109bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // This child has no height. We need to compute our 11119bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // position before we collapse the child's margins together, 11129bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // so that we can get an accurate position for the zero-height block. 11139bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) LayoutUnit collapsedBeforePos = max(marginInfo.positiveMargin(), childMargins.positiveMarginBefore()); 11149bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) LayoutUnit collapsedBeforeNeg = max(marginInfo.negativeMargin(), childMargins.negativeMarginBefore()); 11159bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) marginInfo.setMargin(collapsedBeforePos, collapsedBeforeNeg); 11169bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 11179bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // Now collapse the child's margins together, which means examining our 11189bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // bottom margin values as well. 11199bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) marginInfo.setPositiveMarginIfLarger(childMargins.positiveMarginAfter()); 11209bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) marginInfo.setNegativeMarginIfLarger(childMargins.negativeMarginAfter()); 11219bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 11229bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (!marginInfo.canCollapseWithMarginBefore()) { 11239bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // We need to make sure that the position of the self-collapsing block 11249bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // is correct, since it could have overflowing content 11259bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // that needs to be positioned correctly (e.g., a block that 11269bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // had a specified height of 0 but that actually had subcontent). 11279bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) logicalTop = logicalHeight() + collapsedBeforePos - collapsedBeforeNeg; 11289bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } 11299bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } 11309bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } else { 11319bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (mustSeparateMarginBeforeForChild(child)) { 11329bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) ASSERT(!marginInfo.discardMargin() || (marginInfo.discardMargin() && !marginInfo.margin())); 11339bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // If we are at the before side of the block and we collapse, ignore the computed margin 11349bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // and just add the child margin to the container height. This will correctly position 11359bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // the child inside the container. 11369bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) LayoutUnit separateMargin = !marginInfo.canCollapseWithMarginBefore() ? marginInfo.margin() : LayoutUnit(0); 11379bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) setLogicalHeight(logicalHeight() + separateMargin + marginBeforeForChild(child)); 11389bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) logicalTop = logicalHeight(); 11399bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } else if (!marginInfo.discardMargin() && (!marginInfo.atBeforeSideOfBlock() 11409bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) || (!marginInfo.canCollapseMarginBeforeWithChildren() 11419bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) && (!document().inQuirksMode() || !marginInfo.quirkContainer() || !marginInfo.hasMarginBeforeQuirk())))) { 11429bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // We're collapsing with a previous sibling's margins and not 11439bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // with the top of the block. 11449bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) setLogicalHeight(logicalHeight() + max(marginInfo.positiveMargin(), posTop) - max(marginInfo.negativeMargin(), negTop)); 11459bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) logicalTop = logicalHeight(); 11469bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } 11479bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 11489bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) marginInfo.setDiscardMargin(childDiscardMarginAfter); 11499bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 11509bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (!marginInfo.discardMargin()) { 11519bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) marginInfo.setPositiveMargin(childMargins.positiveMarginAfter()); 11529bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) marginInfo.setNegativeMargin(childMargins.negativeMarginAfter()); 11539bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } else { 11549bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) marginInfo.clearMargin(); 11559bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } 11569bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 11579bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (marginInfo.margin()) 11589bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) marginInfo.setHasMarginAfterQuirk(hasMarginAfterQuirk(child)); 11599bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } 11609bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 11619bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // If margins would pull us past the top of the next page, then we need to pull back and pretend like the margins 11629bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // collapsed into the page edge. 11639bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) LayoutState* layoutState = view()->layoutState(); 116409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (layoutState->isPaginated() && layoutState->pageLogicalHeight() && logicalTop > beforeCollapseLogicalTop) { 11659bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) LayoutUnit oldLogicalTop = logicalTop; 11669bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) logicalTop = min(logicalTop, nextPageLogicalTop(beforeCollapseLogicalTop)); 11679bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) setLogicalHeight(logicalHeight() + (logicalTop - oldLogicalTop)); 11689bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } 11699bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 117009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (previousBlockFlow) { 1171a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // If |child| is a self-collapsing block it may have collapsed into a previous sibling and although it hasn't reduced the height of the parent yet 1172a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // any floats from the parent will now overhang. 1173a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) LayoutUnit oldLogicalHeight = logicalHeight(); 1174a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) setLogicalHeight(logicalTop); 117510f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch if (!previousBlockFlow->avoidsFloats() && (previousBlockFlow->logicalTop() + previousBlockFlow->lowestFloatLogicalBottom()) > logicalTop) 117609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) addOverhangingFloats(previousBlockFlow, false); 1177a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) setLogicalHeight(oldLogicalHeight); 1178a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 1179a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // If |child|'s previous sibling is a self-collapsing block that cleared a float and margin collapsing resulted in |child| moving up 1180a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // into the margin area of the self-collapsing block then the float it clears is now intruding into |child|. Layout again so that we can look for 1181a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // floats in the parent that overhang |child|'s new logical top. 1182a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) bool logicalTopIntrudesIntoFloat = clearanceForSelfCollapsingBlock > 0 && logicalTop < beforeCollapseLogicalTop; 1183a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) if (logicalTopIntrudesIntoFloat && containsFloats() && !child->avoidsFloats() && lowestFloatLogicalBottom() > logicalTop) 11845d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles) child->setNeedsLayoutAndFullPaintInvalidation(); 11859bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } 11869bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 11879bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) return logicalTop; 11889bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)} 11899bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 11909bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)void RenderBlockFlow::adjustPositionedBlock(RenderBox* child, const MarginInfo& marginInfo) 11919bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles){ 11929bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) bool isHorizontal = isHorizontalWritingMode(); 11939bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) bool hasStaticBlockPosition = child->style()->hasStaticBlockPosition(isHorizontal); 11949bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 11959bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) LayoutUnit logicalTop = logicalHeight(); 11969bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) updateStaticInlinePositionForChild(child, logicalTop); 11979bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 11989bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (!marginInfo.canCollapseWithMarginBefore()) { 11999bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // Positioned blocks don't collapse margins, so add the margin provided by 12009bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // the container now. The child's own margin is added later when calculating its logical top. 12019bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) LayoutUnit collapsedBeforePos = marginInfo.positiveMargin(); 12029bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) LayoutUnit collapsedBeforeNeg = marginInfo.negativeMargin(); 12039bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) logicalTop += collapsedBeforePos - collapsedBeforeNeg; 12049bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } 12059bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 12069bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) RenderLayer* childLayer = child->layer(); 12079bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (childLayer->staticBlockPosition() != logicalTop) { 12089bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) childLayer->setStaticBlockPosition(logicalTop); 12099bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (hasStaticBlockPosition) 12109bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) child->setChildNeedsLayout(MarkOnlyThis); 12119bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } 12129bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)} 12139bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 121409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)LayoutUnit RenderBlockFlow::computeStartPositionDeltaForChildAvoidingFloats(const RenderBox* child, LayoutUnit childMarginStart) 121509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){ 121609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) LayoutUnit startPosition = startOffsetForContent(); 121709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 121809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) // Add in our start margin. 121909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) LayoutUnit oldPosition = startPosition + childMarginStart; 122009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) LayoutUnit newPosition = oldPosition; 122109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 122209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) LayoutUnit blockOffset = logicalTopForChild(child); 122309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) LayoutUnit startOff = startOffsetForLine(blockOffset, false, logicalHeightForChild(child)); 122409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 122509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (style()->textAlign() != WEBKIT_CENTER && !child->style()->marginStartUsing(style()).isAuto()) { 122609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (childMarginStart < 0) 122709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) startOff += childMarginStart; 122809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) newPosition = max(newPosition, startOff); // Let the float sit in the child's margin if it can fit. 122909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) } else if (startOff != startPosition) { 123009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) newPosition = startOff + childMarginStart; 123109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) } 123209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 123309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return newPosition - oldPosition; 123409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)} 123509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 123609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)LayoutUnit RenderBlockFlow::clearFloatsIfNeeded(RenderBox* child, MarginInfo& marginInfo, LayoutUnit oldTopPosMargin, LayoutUnit oldTopNegMargin, LayoutUnit yPos, bool childIsSelfCollapsing) 12379bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles){ 12389bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) LayoutUnit heightIncrease = getClearDelta(child, yPos); 12399bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (!heightIncrease) 12409bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) return yPos; 12419bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 124209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (childIsSelfCollapsing) { 12439bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) bool childDiscardMargin = mustDiscardMarginBeforeForChild(child) || mustDiscardMarginAfterForChild(child); 12449bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 12459bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // For self-collapsing blocks that clear, they can still collapse their 12469bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // margins with following siblings. Reset the current margins to represent 12479bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // the self-collapsing block's margins only. 12489bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // If DISCARD is specified for -webkit-margin-collapse, reset the margin values. 1249a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) RenderBlockFlow::MarginValues childMargins = marginValuesForChild(child); 12509bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (!childDiscardMargin) { 12519bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) marginInfo.setPositiveMargin(max(childMargins.positiveMarginBefore(), childMargins.positiveMarginAfter())); 12529bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) marginInfo.setNegativeMargin(max(childMargins.negativeMarginBefore(), childMargins.negativeMarginAfter())); 12539bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } else { 12549bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) marginInfo.clearMargin(); 12559bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } 12569bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) marginInfo.setDiscardMargin(childDiscardMargin); 12579bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 12589bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // CSS2.1 states: 12599bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // "If the top and bottom margins of an element with clearance are adjoining, its margins collapse with 12609bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // the adjoining margins of following siblings but that resulting margin does not collapse with the bottom margin of the parent block." 126109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) // So the parent's bottom margin cannot collapse through this block or any subsequent self-collapsing blocks. Set a bit to ensure 126209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) // this happens; it will get reset if we encounter an in-flow sibling that is not self-collapsing. 126309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) marginInfo.setCanCollapseMarginAfterWithLastChild(false); 12649bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 1265a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // For now set the border-top of |child| flush with the bottom border-edge of the float so it can layout any floating or positioned children of 1266a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // its own at the correct vertical position. If subsequent siblings attempt to collapse with |child|'s margins in |collapseMargins| we will 1267a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // adjust the height of the parent to |child|'s margin top (which if it is positive sits up 'inside' the float it's clearing) so that all three 1268a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // margins can collapse at the correct vertical position. 1269a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // Per CSS2.1 we need to ensure that any negative margin-top clears |child| beyond the bottom border-edge of the float so that the top border edge of the child 1270a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // (i.e. its clearance) is at a position that satisfies the equation: "the amount of clearance is set so that clearance + margin-top = [height of float], 1271a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // i.e., clearance = [height of float] - margin-top". 1272a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) setLogicalHeight(child->logicalTop() + childMargins.negativeMarginBefore()); 12739bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } else { 12749bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // Increase our height by the amount we had to clear. 12759bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) setLogicalHeight(logicalHeight() + heightIncrease); 12769bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } 12779bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 12789bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (marginInfo.canCollapseWithMarginBefore()) { 12799bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // We can no longer collapse with the top of the block since a clear 12809bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // occurred. The empty blocks collapse into the cleared block. 12819bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) setMaxMarginBeforeValues(oldTopPosMargin, oldTopNegMargin); 12829bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) marginInfo.setAtBeforeSideOfBlock(false); 12839bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 12849bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // In case the child discarded the before margin of the block we need to reset the mustDiscardMarginBefore flag to the initial value. 12859bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) setMustDiscardMarginBefore(style()->marginBeforeCollapse() == MDISCARD); 12869bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } 12879bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 1288a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) return yPos + heightIncrease; 12899bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)} 12909bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 12919bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)void RenderBlockFlow::setCollapsedBottomMargin(const MarginInfo& marginInfo) 12929bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles){ 12939bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (marginInfo.canCollapseWithMarginAfter() && !marginInfo.canCollapseWithMarginBefore()) { 12949bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // Update the after side margin of the container to discard if the after margin of the last child also discards and we collapse with it. 12959bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // Don't update the max margin values because we won't need them anyway. 12969bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (marginInfo.discardMargin()) { 12979bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) setMustDiscardMarginAfter(); 12989bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) return; 12999bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } 13009bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 13019bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // Update our max pos/neg bottom margins, since we collapsed our bottom margins 13029bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // with our children. 13039bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) setMaxMarginAfterValues(max(maxPositiveMarginAfter(), marginInfo.positiveMargin()), max(maxNegativeMarginAfter(), marginInfo.negativeMargin())); 13049bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 13059bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (!marginInfo.hasMarginAfterQuirk()) 13069bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) setHasMarginAfterQuirk(false); 13079bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 13089bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (marginInfo.hasMarginAfterQuirk() && !marginAfter()) { 13099bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // We have no bottom margin and our last child has a quirky margin. 13109bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // We will pick up this quirky margin and pass it through. 13119bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // This deals with the <td><div><p> case. 13129bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) setHasMarginAfterQuirk(true); 13139bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } 13149bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } 13159bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)} 13169bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 13179bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)void RenderBlockFlow::marginBeforeEstimateForChild(RenderBox* child, LayoutUnit& positiveMarginBefore, LayoutUnit& negativeMarginBefore, bool& discardMarginBefore) const 13189bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles){ 13199bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // Give up if in quirks mode and we're a body/table cell and the top margin of the child box is quirky. 13209bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // Give up if the child specified -webkit-margin-collapse: separate that prevents collapsing. 13219bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // FIXME: Use writing mode independent accessor for marginBeforeCollapse. 132207a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch if ((document().inQuirksMode() && hasMarginBeforeQuirk(child) && (isTableCell() || isBody())) || child->style()->marginBeforeCollapse() == MSEPARATE) 13239bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) return; 13249bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 13259bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // The margins are discarded by a child that specified -webkit-margin-collapse: discard. 13269bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // FIXME: Use writing mode independent accessor for marginBeforeCollapse. 13279bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (child->style()->marginBeforeCollapse() == MDISCARD) { 13289bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) positiveMarginBefore = 0; 13299bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) negativeMarginBefore = 0; 13309bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) discardMarginBefore = true; 13319bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) return; 13329bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } 13339bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 13349bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) LayoutUnit beforeChildMargin = marginBeforeForChild(child); 13359bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) positiveMarginBefore = max(positiveMarginBefore, beforeChildMargin); 13369bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) negativeMarginBefore = max(negativeMarginBefore, -beforeChildMargin); 13379bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 13389bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (!child->isRenderBlockFlow()) 13399bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) return; 13409bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 13419bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) RenderBlockFlow* childBlockFlow = toRenderBlockFlow(child); 13429bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (childBlockFlow->childrenInline() || childBlockFlow->isWritingModeRoot()) 13439bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) return; 13449bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 13459bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) MarginInfo childMarginInfo(childBlockFlow, childBlockFlow->borderBefore() + childBlockFlow->paddingBefore(), childBlockFlow->borderAfter() + childBlockFlow->paddingAfter()); 13469bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (!childMarginInfo.canCollapseMarginBeforeWithChildren()) 13479bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) return; 13489bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 13499bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) RenderBox* grandchildBox = childBlockFlow->firstChildBox(); 13509bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) for ( ; grandchildBox; grandchildBox = grandchildBox->nextSiblingBox()) { 13519bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (!grandchildBox->isFloatingOrOutOfFlowPositioned()) 13529bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) break; 13539bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } 13549bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 13559bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // Give up if there is clearance on the box, since it probably won't collapse into us. 13569bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (!grandchildBox || grandchildBox->style()->clear() != CNONE) 13579bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) return; 13589bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 13599bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // Make sure to update the block margins now for the grandchild box so that we're looking at current values. 13609bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (grandchildBox->needsLayout()) { 13619bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) grandchildBox->computeAndSetBlockDirectionMargins(this); 13629bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (grandchildBox->isRenderBlock()) { 13639bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) RenderBlock* grandchildBlock = toRenderBlock(grandchildBox); 13649bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) grandchildBlock->setHasMarginBeforeQuirk(grandchildBox->style()->hasMarginBeforeQuirk()); 13659bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) grandchildBlock->setHasMarginAfterQuirk(grandchildBox->style()->hasMarginAfterQuirk()); 13669bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } 13679bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } 13689bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 13699bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // Collapse the margin of the grandchild box with our own to produce an estimate. 13709bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) childBlockFlow->marginBeforeEstimateForChild(grandchildBox, positiveMarginBefore, negativeMarginBefore, discardMarginBefore); 13719bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)} 13729bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 13739bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)LayoutUnit RenderBlockFlow::estimateLogicalTopPosition(RenderBox* child, const MarginInfo& marginInfo, LayoutUnit& estimateWithoutPagination) 13749bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles){ 13759bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // FIXME: We need to eliminate the estimation of vertical position, because when it's wrong we sometimes trigger a pathological 13769bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // relayout if there are intruding floats. 13779bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) LayoutUnit logicalTopEstimate = logicalHeight(); 13789bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (!marginInfo.canCollapseWithMarginBefore()) { 13799bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) LayoutUnit positiveMarginBefore = 0; 13809bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) LayoutUnit negativeMarginBefore = 0; 13819bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) bool discardMarginBefore = false; 13829bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (child->selfNeedsLayout()) { 13839bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // Try to do a basic estimation of how the collapse is going to go. 13849bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) marginBeforeEstimateForChild(child, positiveMarginBefore, negativeMarginBefore, discardMarginBefore); 13859bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } else { 13869bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // Use the cached collapsed margin values from a previous layout. Most of the time they 13879bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // will be right. 13889bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) RenderBlockFlow::MarginValues marginValues = marginValuesForChild(child); 13899bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) positiveMarginBefore = max(positiveMarginBefore, marginValues.positiveMarginBefore()); 13909bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) negativeMarginBefore = max(negativeMarginBefore, marginValues.negativeMarginBefore()); 13919bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) discardMarginBefore = mustDiscardMarginBeforeForChild(child); 13929bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } 13939bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 13949bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // Collapse the result with our current margins. 13959bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (!discardMarginBefore) 13969bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) logicalTopEstimate += max(marginInfo.positiveMargin(), positiveMarginBefore) - max(marginInfo.negativeMargin(), negativeMarginBefore); 13979bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } 13989bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 13999bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // Adjust logicalTopEstimate down to the next page if the margins are so large that we don't fit on the current 14009bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // page. 14019bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) LayoutState* layoutState = view()->layoutState(); 140209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (layoutState->isPaginated() && layoutState->pageLogicalHeight() && logicalTopEstimate > logicalHeight()) 14039bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) logicalTopEstimate = min(logicalTopEstimate, nextPageLogicalTop(logicalHeight())); 14049bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 14059bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) logicalTopEstimate += getClearDelta(child, logicalTopEstimate); 14069bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 14079bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) estimateWithoutPagination = logicalTopEstimate; 14089bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 14099bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (layoutState->isPaginated()) { 14109bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // If the object has a page or column break value of "before", then we should shift to the top of the next page. 14119bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) logicalTopEstimate = applyBeforeBreak(child, logicalTopEstimate); 14129bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 14139bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // For replaced elements and scrolled elements, we want to shift them to the next page if they don't fit on the current one. 14149bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) logicalTopEstimate = adjustForUnsplittableChild(child, logicalTopEstimate); 14159bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 14169bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (!child->selfNeedsLayout() && child->isRenderBlock()) 14179bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) logicalTopEstimate += toRenderBlock(child)->paginationStrut(); 14189bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } 14199bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 14209bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) return logicalTopEstimate; 14219bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)} 14229bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 1423a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)LayoutUnit RenderBlockFlow::marginOffsetForSelfCollapsingBlock() 1424a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles){ 1425a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) ASSERT(isSelfCollapsingBlock()); 1426a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) RenderBlockFlow* parentBlock = toRenderBlockFlow(parent()); 1427a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) if (parentBlock && style()->clear() && parentBlock->getClearDelta(this, logicalHeight())) 1428a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) return marginValuesForChild(this).positiveMarginBefore(); 1429a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) return LayoutUnit(); 1430a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)} 1431a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 14329bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)void RenderBlockFlow::adjustFloatingBlock(const MarginInfo& marginInfo) 14339bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles){ 14349bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // The float should be positioned taking into account the bottom margin 14359bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // of the previous flow. We add that margin into the height, get the 14369bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // float positioned properly, and then subtract the margin out of the 14379bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // height again. In the case of self-collapsing blocks, we always just 14389bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // use the top margins, since the self-collapsing block collapsed its 14399bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // own bottom margin into its top margin. 14409bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // 14419bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // Note also that the previous flow may collapse its margin into the top of 14429bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // our block. If this is the case, then we do not add the margin in to our 14439bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // height when computing the position of the float. This condition can be tested 14449bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // for by simply calling canCollapseWithMarginBefore. See 14459bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // http://www.hixie.ch/tests/adhoc/css/box/block/margin-collapse/046.html for 14469bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // an example of this scenario. 14479bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) LayoutUnit marginOffset = marginInfo.canCollapseWithMarginBefore() ? LayoutUnit() : marginInfo.margin(); 14489bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) setLogicalHeight(logicalHeight() + marginOffset); 14499bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) positionNewFloats(); 14509bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) setLogicalHeight(logicalHeight() - marginOffset); 14519bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)} 14529bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 145309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)void RenderBlockFlow::handleAfterSideOfBlock(RenderBox* lastChild, LayoutUnit beforeSide, LayoutUnit afterSide, MarginInfo& marginInfo) 14549bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles){ 14559bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) marginInfo.setAtAfterSideOfBlock(true); 14569bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 1457a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // If our last child was a self-collapsing block with clearance then our logical height is flush with the 1458a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // bottom edge of the float that the child clears. The correct vertical position for the margin-collapsing we want 1459a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // to perform now is at the child's margin-top - so adjust our height to that position. 146009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (lastChild && lastChild->isRenderBlockFlow() && lastChild->isSelfCollapsingBlock()) 146109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) setLogicalHeight(logicalHeight() - toRenderBlockFlow(lastChild)->marginOffsetForSelfCollapsingBlock()); 146209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 146309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (marginInfo.canCollapseMarginAfterWithChildren() && !marginInfo.canCollapseMarginAfterWithLastChild()) 146409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) marginInfo.setCanCollapseMarginAfterWithChildren(false); 1465a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 14669bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // If we can't collapse with children then go ahead and add in the bottom margin. 14679bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (!marginInfo.discardMargin() && (!marginInfo.canCollapseWithMarginAfter() && !marginInfo.canCollapseWithMarginBefore() 14689bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) && (!document().inQuirksMode() || !marginInfo.quirkContainer() || !marginInfo.hasMarginAfterQuirk()))) 14699bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) setLogicalHeight(logicalHeight() + marginInfo.margin()); 14709bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 14719bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // Now add in our bottom border/padding. 14729bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) setLogicalHeight(logicalHeight() + afterSide); 14739bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 14749bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // Negative margins can cause our height to shrink below our minimal height (border/padding). 14759bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // If this happens, ensure that the computed height is increased to the minimal height. 14769bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) setLogicalHeight(max(logicalHeight(), beforeSide + afterSide)); 14779bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 14789bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // Update our bottom collapsed margin info. 14799bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) setCollapsedBottomMargin(marginInfo); 14809bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)} 14819bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 14829bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)void RenderBlockFlow::setMustDiscardMarginBefore(bool value) 14839bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles){ 14849bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (style()->marginBeforeCollapse() == MDISCARD) { 14859bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) ASSERT(value); 14869bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) return; 14879bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } 14889bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 14899bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (!m_rareData && !value) 14909bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) return; 14919bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 14929bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (!m_rareData) 14939bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) m_rareData = adoptPtr(new RenderBlockFlowRareData(this)); 14949bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 14959bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) m_rareData->m_discardMarginBefore = value; 14969bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)} 14979bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 14989bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)void RenderBlockFlow::setMustDiscardMarginAfter(bool value) 14999bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles){ 15009bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (style()->marginAfterCollapse() == MDISCARD) { 15019bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) ASSERT(value); 15029bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) return; 15039bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } 15049bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 15059bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (!m_rareData && !value) 15069bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) return; 15079bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 15089bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (!m_rareData) 15099bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) m_rareData = adoptPtr(new RenderBlockFlowRareData(this)); 15109bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 15119bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) m_rareData->m_discardMarginAfter = value; 15129bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)} 15139bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 15149bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)bool RenderBlockFlow::mustDiscardMarginBefore() const 15159bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles){ 15169bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) return style()->marginBeforeCollapse() == MDISCARD || (m_rareData && m_rareData->m_discardMarginBefore); 15179bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)} 15189bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 15199bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)bool RenderBlockFlow::mustDiscardMarginAfter() const 15209bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles){ 15219bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) return style()->marginAfterCollapse() == MDISCARD || (m_rareData && m_rareData->m_discardMarginAfter); 15229bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)} 15239bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 15249bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)bool RenderBlockFlow::mustDiscardMarginBeforeForChild(const RenderBox* child) const 15259bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles){ 15269bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) ASSERT(!child->selfNeedsLayout()); 15279bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (!child->isWritingModeRoot()) 15289bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) return child->isRenderBlockFlow() ? toRenderBlockFlow(child)->mustDiscardMarginBefore() : (child->style()->marginBeforeCollapse() == MDISCARD); 15299bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (child->isHorizontalWritingMode() == isHorizontalWritingMode()) 15309bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) return child->isRenderBlockFlow() ? toRenderBlockFlow(child)->mustDiscardMarginAfter() : (child->style()->marginAfterCollapse() == MDISCARD); 15319bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 15329bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // FIXME: We return false here because the implementation is not geometrically complete. We have values only for before/after, not start/end. 15339bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // In case the boxes are perpendicular we assume the property is not specified. 15349bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) return false; 15359bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)} 15369bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 15379bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)bool RenderBlockFlow::mustDiscardMarginAfterForChild(const RenderBox* child) const 15389bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles){ 15399bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) ASSERT(!child->selfNeedsLayout()); 15409bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (!child->isWritingModeRoot()) 15419bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) return child->isRenderBlockFlow() ? toRenderBlockFlow(child)->mustDiscardMarginAfter() : (child->style()->marginAfterCollapse() == MDISCARD); 15429bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (child->isHorizontalWritingMode() == isHorizontalWritingMode()) 15439bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) return child->isRenderBlockFlow() ? toRenderBlockFlow(child)->mustDiscardMarginBefore() : (child->style()->marginBeforeCollapse() == MDISCARD); 15449bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 15459bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // FIXME: See |mustDiscardMarginBeforeForChild| above. 15469bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) return false; 15479bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)} 15489bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 15499bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)void RenderBlockFlow::setMaxMarginBeforeValues(LayoutUnit pos, LayoutUnit neg) 15509bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles){ 15519bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (!m_rareData) { 15529bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (pos == RenderBlockFlowRareData::positiveMarginBeforeDefault(this) && neg == RenderBlockFlowRareData::negativeMarginBeforeDefault(this)) 15539bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) return; 15549bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) m_rareData = adoptPtr(new RenderBlockFlowRareData(this)); 15559bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } 15569bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) m_rareData->m_margins.setPositiveMarginBefore(pos); 15579bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) m_rareData->m_margins.setNegativeMarginBefore(neg); 15589bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)} 15599bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 15609bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)void RenderBlockFlow::setMaxMarginAfterValues(LayoutUnit pos, LayoutUnit neg) 15619bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles){ 15629bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (!m_rareData) { 15639bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (pos == RenderBlockFlowRareData::positiveMarginAfterDefault(this) && neg == RenderBlockFlowRareData::negativeMarginAfterDefault(this)) 15649bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) return; 15659bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) m_rareData = adoptPtr(new RenderBlockFlowRareData(this)); 15669bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } 15679bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) m_rareData->m_margins.setPositiveMarginAfter(pos); 15689bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) m_rareData->m_margins.setNegativeMarginAfter(neg); 15699bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)} 15709bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 15719bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)bool RenderBlockFlow::mustSeparateMarginBeforeForChild(const RenderBox* child) const 15729bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles){ 15739bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) ASSERT(!child->selfNeedsLayout()); 15749bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) const RenderStyle* childStyle = child->style(); 15759bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (!child->isWritingModeRoot()) 15769bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) return childStyle->marginBeforeCollapse() == MSEPARATE; 15779bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (child->isHorizontalWritingMode() == isHorizontalWritingMode()) 15789bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) return childStyle->marginAfterCollapse() == MSEPARATE; 15799bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 15809bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // FIXME: See |mustDiscardMarginBeforeForChild| above. 15819bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) return false; 15829bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)} 15839bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 15849bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)bool RenderBlockFlow::mustSeparateMarginAfterForChild(const RenderBox* child) const 15859bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles){ 15869bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) ASSERT(!child->selfNeedsLayout()); 15879bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) const RenderStyle* childStyle = child->style(); 15889bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (!child->isWritingModeRoot()) 15899bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) return childStyle->marginAfterCollapse() == MSEPARATE; 15909bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) if (child->isHorizontalWritingMode() == isHorizontalWritingMode()) 15919bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) return childStyle->marginBeforeCollapse() == MSEPARATE; 15929bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 15939bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // FIXME: See |mustDiscardMarginBeforeForChild| above. 15949bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) return false; 15959bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)} 15969bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 15979bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)LayoutUnit RenderBlockFlow::applyBeforeBreak(RenderBox* child, LayoutUnit logicalOffset) 15989bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles){ 15999bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // FIXME: Add page break checking here when we support printing. 16009bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) RenderFlowThread* flowThread = flowThreadContainingBlock(); 160109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) bool isInsideMulticolFlowThread = flowThread; 160209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) bool checkColumnBreaks = isInsideMulticolFlowThread || view()->layoutState()->isPaginatingColumns(); 160307a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch bool checkPageBreaks = !checkColumnBreaks && view()->layoutState()->pageLogicalHeight(); // FIXME: Once columns can print we have to check this. 160409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) bool checkBeforeAlways = (checkColumnBreaks && child->style()->columnBreakBefore() == PBALWAYS) 160509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) || (checkPageBreaks && child->style()->pageBreakBefore() == PBALWAYS); 160609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (checkBeforeAlways && inNormalFlow(child)) { 160709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (checkColumnBreaks) { 160809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (isInsideMulticolFlowThread) { 160909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) LayoutUnit offsetBreakAdjustment = 0; 161009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (flowThread->addForcedRegionBreak(offsetFromLogicalTopOfFirstPage() + logicalOffset, child, true, &offsetBreakAdjustment)) 161109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return logicalOffset + offsetBreakAdjustment; 161209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) } else { 1613d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) view()->layoutState()->addForcedColumnBreak(*child, logicalOffset); 161409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) } 16159bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } 16169bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) return nextPageLogicalTop(logicalOffset, IncludePageBoundary); 16179bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } 16189bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) return logicalOffset; 16199bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)} 16209bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 16219bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)LayoutUnit RenderBlockFlow::applyAfterBreak(RenderBox* child, LayoutUnit logicalOffset, MarginInfo& marginInfo) 16229bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles){ 16239bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // FIXME: Add page break checking here when we support printing. 16249bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) RenderFlowThread* flowThread = flowThreadContainingBlock(); 162509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) bool isInsideMulticolFlowThread = flowThread; 162609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) bool checkColumnBreaks = isInsideMulticolFlowThread || view()->layoutState()->isPaginatingColumns(); 162707a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch bool checkPageBreaks = !checkColumnBreaks && view()->layoutState()->pageLogicalHeight(); // FIXME: Once columns can print we have to check this. 162809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) bool checkAfterAlways = (checkColumnBreaks && child->style()->columnBreakAfter() == PBALWAYS) 162909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) || (checkPageBreaks && child->style()->pageBreakAfter() == PBALWAYS); 163009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (checkAfterAlways && inNormalFlow(child)) { 16319bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) LayoutUnit marginOffset = marginInfo.canCollapseWithMarginBefore() ? LayoutUnit() : marginInfo.margin(); 16329bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 16339bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) // So our margin doesn't participate in the next collapsing steps. 16349bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) marginInfo.clearMargin(); 16359bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 163609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (checkColumnBreaks) { 163709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (isInsideMulticolFlowThread) { 163809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) LayoutUnit offsetBreakAdjustment = 0; 163909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (flowThread->addForcedRegionBreak(offsetFromLogicalTopOfFirstPage() + logicalOffset + marginOffset, child, false, &offsetBreakAdjustment)) 164009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return logicalOffset + marginOffset + offsetBreakAdjustment; 164109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) } else { 1642d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) view()->layoutState()->addForcedColumnBreak(*child, logicalOffset); 164309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) } 16449bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } 16459bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) return nextPageLogicalTop(logicalOffset, IncludePageBoundary); 16469bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) } 16479bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) return logicalOffset; 16489bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)} 16499bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 1650f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)void RenderBlockFlow::addOverflowFromFloats() 1651f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles){ 1652f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (!m_floatingObjects) 1653f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) return; 1654f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 1655f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); 1656f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) FloatingObjectSetIterator end = floatingObjectSet.end(); 1657f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) for (FloatingObjectSetIterator it = floatingObjectSet.begin(); it != end; ++it) { 1658d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles) FloatingObject* floatingObject = it->get(); 1659f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (floatingObject->isDescendant()) 1660f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) addOverflowFromChild(floatingObject->renderer(), IntSize(xPositionForFloatIncludingMargin(floatingObject), yPositionForFloatIncludingMargin(floatingObject))); 1661f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) } 1662f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)} 1663f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 1664f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)void RenderBlockFlow::computeOverflow(LayoutUnit oldClientAfterEdge, bool recomputeFloats) 1665f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles){ 1666f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) RenderBlock::computeOverflow(oldClientAfterEdge, recomputeFloats); 166709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (!hasColumns() && (recomputeFloats || createsBlockFormattingContext() || hasSelfPaintingLayer())) 1668f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) addOverflowFromFloats(); 1669f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)} 1670f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 167109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)RootInlineBox* RenderBlockFlow::createAndAppendRootInlineBox() 167209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){ 167309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) RootInlineBox* rootBox = createRootInlineBox(); 167409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) m_lineBoxes.appendLineBox(rootBox); 167509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 167609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (UNLIKELY(AXObjectCache::accessibilityEnabled()) && m_lineBoxes.firstLineBox() == rootBox) { 167709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (AXObjectCache* cache = document().existingAXObjectCache()) 167809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) cache->recomputeIsIgnored(this); 167909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) } 168009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 168109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return rootBox; 168209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)} 168309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 1684f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)void RenderBlockFlow::deleteLineBoxTree() 1685f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles){ 1686f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (containsFloats()) 1687f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) m_floatingObjects->clearLineBoxTreePointers(); 1688f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) RenderBlock::deleteLineBoxTree(); 1689f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)} 1690f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 1691f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)void RenderBlockFlow::markAllDescendantsWithFloatsForLayout(RenderBox* floatToRemove, bool inLayout) 1692f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles){ 1693f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (!everHadLayout() && !containsFloats()) 1694f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) return; 1695f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 1696f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) MarkingBehavior markParents = inLayout ? MarkOnlyThis : MarkContainingBlockChain; 1697f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) setChildNeedsLayout(markParents); 1698f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 1699f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (floatToRemove) 1700f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) removeFloatingObject(floatToRemove); 1701f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 1702f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // Iterate over our children and mark them as needed. 1703f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (!childrenInline()) { 1704f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) for (RenderObject* child = firstChild(); child; child = child->nextSibling()) { 1705f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if ((!floatToRemove && child->isFloatingOrOutOfFlowPositioned()) || !child->isRenderBlock()) 1706f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) continue; 1707f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (!child->isRenderBlockFlow()) { 1708f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) RenderBlock* childBlock = toRenderBlock(child); 1709f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (childBlock->shrinkToAvoidFloats() && childBlock->everHadLayout()) 1710f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) childBlock->setChildNeedsLayout(markParents); 1711f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) continue; 1712f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) } 1713f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) RenderBlockFlow* childBlockFlow = toRenderBlockFlow(child); 1714f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if ((floatToRemove ? childBlockFlow->containsFloat(floatToRemove) : childBlockFlow->containsFloats()) || childBlockFlow->shrinkToAvoidFloats()) 1715f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) childBlockFlow->markAllDescendantsWithFloatsForLayout(floatToRemove, inLayout); 1716f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) } 1717f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) } 1718f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)} 1719f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 1720f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)void RenderBlockFlow::markSiblingsWithFloatsForLayout(RenderBox* floatToRemove) 1721f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles){ 1722f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (!m_floatingObjects) 1723f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) return; 1724f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 1725f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); 1726f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) FloatingObjectSetIterator end = floatingObjectSet.end(); 1727f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 1728f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) for (RenderObject* next = nextSibling(); next; next = next->nextSibling()) { 1729c4de9692585dd12fa75b760eebef04fa43fc1ae6Bo Liu if (!next->isRenderBlockFlow() || next->isFloatingOrOutOfFlowPositioned() || toRenderBlock(next)->avoidsFloats()) 1730f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) continue; 1731f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 1732f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) RenderBlockFlow* nextBlock = toRenderBlockFlow(next); 1733f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) for (FloatingObjectSetIterator it = floatingObjectSet.begin(); it != end; ++it) { 1734f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) RenderBox* floatingBox = (*it)->renderer(); 1735f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (floatToRemove && floatingBox != floatToRemove) 1736f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) continue; 1737f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (nextBlock->containsFloat(floatingBox)) 1738f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) nextBlock->markAllDescendantsWithFloatsForLayout(floatingBox); 1739f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) } 1740f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) } 1741f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)} 1742f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 1743f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)LayoutUnit RenderBlockFlow::getClearDelta(RenderBox* child, LayoutUnit logicalTop) 1744f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles){ 1745f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // There is no need to compute clearance if we have no floats. 1746f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (!containsFloats()) 1747f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) return 0; 1748f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 1749f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // At least one float is present. We need to perform the clearance computation. 1750f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) bool clearSet = child->style()->clear() != CNONE; 1751f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) LayoutUnit logicalBottom = 0; 1752f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) switch (child->style()->clear()) { 1753f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) case CNONE: 1754f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) break; 1755f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) case CLEFT: 1756f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) logicalBottom = lowestFloatLogicalBottom(FloatingObject::FloatLeft); 1757f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) break; 1758f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) case CRIGHT: 1759f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) logicalBottom = lowestFloatLogicalBottom(FloatingObject::FloatRight); 1760f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) break; 1761f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) case CBOTH: 1762f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) logicalBottom = lowestFloatLogicalBottom(); 1763f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) break; 1764f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) } 1765f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 1766f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // We also clear floats if we are too big to sit on the same line as a float (and wish to avoid floats by default). 1767f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) LayoutUnit result = clearSet ? max<LayoutUnit>(0, logicalBottom - logicalTop) : LayoutUnit(); 1768f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (!result && child->avoidsFloats()) { 1769f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) LayoutUnit newLogicalTop = logicalTop; 1770f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) while (true) { 1771f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) LayoutUnit availableLogicalWidthAtNewLogicalTopOffset = availableLogicalWidthForLine(newLogicalTop, false, logicalHeightForChild(child)); 177209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (availableLogicalWidthAtNewLogicalTopOffset == availableLogicalWidthForContent()) 1773f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) return newLogicalTop - logicalTop; 1774f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 177509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) LayoutRect borderBox = child->borderBoxRect(); 1776f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) LayoutUnit childLogicalWidthAtOldLogicalTopOffset = isHorizontalWritingMode() ? borderBox.width() : borderBox.height(); 1777f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 1778f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // FIXME: None of this is right for perpendicular writing-mode children. 1779f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) LayoutUnit childOldLogicalWidth = child->logicalWidth(); 1780f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) LayoutUnit childOldMarginLeft = child->marginLeft(); 1781f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) LayoutUnit childOldMarginRight = child->marginRight(); 1782f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) LayoutUnit childOldLogicalTop = child->logicalTop(); 1783f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 1784f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) child->setLogicalTop(newLogicalTop); 1785f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) child->updateLogicalWidth(); 178609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) borderBox = child->borderBoxRect(); 1787f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) LayoutUnit childLogicalWidthAtNewLogicalTopOffset = isHorizontalWritingMode() ? borderBox.width() : borderBox.height(); 1788f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 1789f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) child->setLogicalTop(childOldLogicalTop); 1790f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) child->setLogicalWidth(childOldLogicalWidth); 1791f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) child->setMarginLeft(childOldMarginLeft); 1792f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) child->setMarginRight(childOldMarginRight); 1793f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 1794f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (childLogicalWidthAtNewLogicalTopOffset <= availableLogicalWidthAtNewLogicalTopOffset) { 1795f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // Even though we may not be moving, if the logical width did shrink because of the presence of new floats, then 1796f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // we need to force a relayout as though we shifted. This happens because of the dynamic addition of overhanging floats 1797f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // from previous siblings when negative margins exist on a child (see the addOverhangingFloats call at the end of collapseMargins). 1798f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (childLogicalWidthAtOldLogicalTopOffset != childLogicalWidthAtNewLogicalTopOffset) 1799f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) child->setChildNeedsLayout(MarkOnlyThis); 1800f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) return newLogicalTop - logicalTop; 1801f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) } 1802f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 1803f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) newLogicalTop = nextFloatLogicalBottomBelow(newLogicalTop); 1804f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) ASSERT(newLogicalTop >= logicalTop); 1805f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (newLogicalTop < logicalTop) 1806f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) break; 1807f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) } 1808f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) ASSERT_NOT_REACHED(); 1809f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) } 1810f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) return result; 1811f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)} 1812f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 1813f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)void RenderBlockFlow::createFloatingObjects() 1814f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles){ 1815f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) m_floatingObjects = adoptPtr(new FloatingObjects(this, isHorizontalWritingMode())); 1816f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)} 1817f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 1818aafa69cb17c9d6606c07663ade5f81388a2c5986Ben Murdochvoid RenderBlockFlow::styleWillChange(StyleDifference diff, const RenderStyle& newStyle) 1819f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles){ 1820f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) RenderStyle* oldStyle = style(); 1821c4de9692585dd12fa75b760eebef04fa43fc1ae6Bo Liu s_canPropagateFloatIntoSibling = oldStyle ? !isFloatingOrOutOfFlowPositioned() && !avoidsFloats() : false; 182210f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch if (oldStyle && parent() && diff.needsFullLayout() && oldStyle->position() != newStyle.position() 1823aafa69cb17c9d6606c07663ade5f81388a2c5986Ben Murdoch && containsFloats() && !isFloating() && !isOutOfFlowPositioned() && newStyle.hasOutOfFlowPosition()) 1824f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) markAllDescendantsWithFloatsForLayout(); 1825f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 1826f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) RenderBlock::styleWillChange(diff, newStyle); 1827f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)} 1828f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 1829f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)void RenderBlockFlow::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle) 1830f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles){ 1831f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) RenderBlock::styleDidChange(diff, oldStyle); 1832f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 1833f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // After our style changed, if we lose our ability to propagate floats into next sibling 1834f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // blocks, then we need to find the top most parent containing that overhanging float and 1835f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // then mark its descendants with floats for layout and clear all floats from its next 1836f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // sibling blocks that exist in our floating objects list. See bug 56299 and 62875. 1837c4de9692585dd12fa75b760eebef04fa43fc1ae6Bo Liu bool canPropagateFloatIntoSibling = !isFloatingOrOutOfFlowPositioned() && !avoidsFloats(); 183810f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch if (diff.needsFullLayout() && s_canPropagateFloatIntoSibling && !canPropagateFloatIntoSibling && hasOverhangingFloats()) { 1839f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) RenderBlockFlow* parentBlockFlow = this; 1840f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); 1841f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) FloatingObjectSetIterator end = floatingObjectSet.end(); 1842f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 1843f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) for (RenderObject* curr = parent(); curr && !curr->isRenderView(); curr = curr->parent()) { 1844f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (curr->isRenderBlockFlow()) { 1845f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) RenderBlockFlow* currBlock = toRenderBlockFlow(curr); 1846f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 1847f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (currBlock->hasOverhangingFloats()) { 1848f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) for (FloatingObjectSetIterator it = floatingObjectSet.begin(); it != end; ++it) { 1849f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) RenderBox* renderer = (*it)->renderer(); 1850f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (currBlock->hasOverhangingFloat(renderer)) { 1851f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) parentBlockFlow = currBlock; 1852f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) break; 1853f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) } 1854f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) } 1855f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) } 1856f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) } 1857f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) } 1858f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 1859f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) parentBlockFlow->markAllDescendantsWithFloatsForLayout(); 1860f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) parentBlockFlow->markSiblingsWithFloatsForLayout(); 1861f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) } 1862d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) 186310f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch if (diff.needsFullLayout() || !oldStyle) 18646f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch createOrDestroyMultiColumnFlowThreadIfNeeded(); 186551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)} 186651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 186751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)void RenderBlockFlow::updateStaticInlinePositionForChild(RenderBox* child, LayoutUnit logicalTop) 186851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){ 186951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) if (child->style()->isOriginalDisplayInlineType()) 187051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) setStaticInlinePositionForChild(child, logicalTop, startAlignedOffsetForLine(logicalTop, false)); 187151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) else 187209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) setStaticInlinePositionForChild(child, logicalTop, startOffsetForContent()); 187351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)} 187451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 187551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)void RenderBlockFlow::setStaticInlinePositionForChild(RenderBox* child, LayoutUnit blockOffset, LayoutUnit inlinePosition) 187651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){ 187751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) child->layer()->setStaticInlinePosition(inlinePosition); 1878f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)} 1879f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 1880d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)void RenderBlockFlow::addChild(RenderObject* newChild, RenderObject* beforeChild) 1881d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles){ 1882d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles) if (RenderMultiColumnFlowThread* flowThread = multiColumnFlowThread()) { 1883d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles) flowThread->addChild(newChild, beforeChild); 1884d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles) return; 1885d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles) } 1886d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) RenderBlock::addChild(newChild, beforeChild); 1887d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)} 1888d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) 1889f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)void RenderBlockFlow::moveAllChildrenIncludingFloatsTo(RenderBlock* toBlock, bool fullRemoveInsert) 1890f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles){ 1891f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) RenderBlockFlow* toBlockFlow = toRenderBlockFlow(toBlock); 1892f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) moveAllChildrenTo(toBlockFlow, fullRemoveInsert); 1893f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 1894f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // When a portion of the render tree is being detached, anonymous blocks 1895f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // will be combined as their children are deleted. In this process, the 1896f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // anonymous block later in the tree is merged into the one preceeding it. 1897f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // It can happen that the later block (this) contains floats that the 1898f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // previous block (toBlockFlow) did not contain, and thus are not in the 1899f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // floating objects list for toBlockFlow. This can result in toBlockFlow containing 1900f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // floats that are not in it's floating objects list, but are in the 1901f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // floating objects lists of siblings and parents. This can cause problems 1902f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // when the float itself is deleted, since the deletion code assumes that 1903f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // if a float is not in it's containing block's floating objects list, it 1904f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // isn't in any floating objects list. In order to preserve this condition 1905f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // (removing it has serious performance implications), we need to copy the 1906f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // floating objects from the old block (this) to the new block (toBlockFlow). 1907f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // The float's metrics will likely all be wrong, but since toBlockFlow is 1908f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // already marked for layout, this will get fixed before anything gets 1909f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // displayed. 1910f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // See bug https://code.google.com/p/chromium/issues/detail?id=230907 1911f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (m_floatingObjects) { 1912f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (!toBlockFlow->m_floatingObjects) 1913f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) toBlockFlow->createFloatingObjects(); 1914f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 1915f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) const FloatingObjectSet& fromFloatingObjectSet = m_floatingObjects->set(); 1916f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) FloatingObjectSetIterator end = fromFloatingObjectSet.end(); 1917f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 1918f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) for (FloatingObjectSetIterator it = fromFloatingObjectSet.begin(); it != end; ++it) { 1919d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles) FloatingObject* floatingObject = it->get(); 1920f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 1921f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // Don't insert the object again if it's already in the list 1922f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (toBlockFlow->containsFloat(floatingObject->renderer())) 1923f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) continue; 1924f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 1925f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) toBlockFlow->m_floatingObjects->add(floatingObject->unsafeClone()); 1926f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) } 1927f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) } 1928f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 1929f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)} 1930f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 1931f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)void RenderBlockFlow::repaintOverhangingFloats(bool paintAllDescendants) 1932f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles){ 1933f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // Repaint any overhanging floats (if we know we're the one to paint them). 1934f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // Otherwise, bail out. 1935f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (!hasOverhangingFloats()) 1936f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) return; 1937f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 1938f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // FIXME: Avoid disabling LayoutState. At the very least, don't disable it for floats originating 1939f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // in this block. Better yet would be to push extra state for the containers of other floats. 19405d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles) ForceHorriblySlowRectMapping slowRectMapping(*this); 1941f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); 1942f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) FloatingObjectSetIterator end = floatingObjectSet.end(); 1943f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) for (FloatingObjectSetIterator it = floatingObjectSet.begin(); it != end; ++it) { 1944d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles) FloatingObject* floatingObject = it->get(); 1945f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // Only repaint the object if it is overhanging, is not in its own layer, and 1946f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // is our responsibility to paint (m_shouldPaint is set). When paintAllDescendants is true, the latter 1947f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // condition is replaced with being a descendant of us. 1948f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (logicalBottomForFloat(floatingObject) > logicalHeight() 1949f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) && !floatingObject->renderer()->hasSelfPaintingLayer() 1950f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) && (floatingObject->shouldPaint() || (paintAllDescendants && floatingObject->renderer()->isDescendantOf(this)))) { 1951a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 1952a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) RenderBox* floatingRenderer = floatingObject->renderer(); 1953a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) if (RuntimeEnabledFeatures::repaintAfterLayoutEnabled()) 1954f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles) floatingRenderer->setShouldDoFullPaintInvalidationAfterLayout(true); 1955a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) else 19565d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles) floatingRenderer->paintInvalidationForWholeRenderer(); 1957a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 1958a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) floatingRenderer->repaintOverhangingFloats(false); 1959f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) } 1960f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) } 1961f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)} 1962f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 19635d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)void RenderBlockFlow::invalidatePaintForOverflow() 1964a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles){ 1965a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // FIXME: We could tighten up the left and right invalidation points if we let layoutInlineChildren fill them in based off the particular lines 1966a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // it had to lay out. We wouldn't need the hasOverflowClip() hack in that case either. 1967a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) LayoutUnit repaintLogicalLeft = logicalLeftVisualOverflow(); 1968a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) LayoutUnit repaintLogicalRight = logicalRightVisualOverflow(); 1969a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) if (hasOverflowClip()) { 1970a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // If we have clipped overflow, we should use layout overflow as well, since visual overflow from lines didn't propagate to our block's overflow. 1971a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // Note the old code did this as well but even for overflow:visible. The addition of hasOverflowClip() at least tightens up the hack a bit. 1972a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // layoutInlineChildren should be patched to compute the entire repaint rect. 1973a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) repaintLogicalLeft = min(repaintLogicalLeft, logicalLeftLayoutOverflow()); 1974a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) repaintLogicalRight = max(repaintLogicalRight, logicalRightLayoutOverflow()); 1975a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) } 1976a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 1977a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) LayoutRect repaintRect; 1978a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) if (isHorizontalWritingMode()) 1979a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) repaintRect = LayoutRect(repaintLogicalLeft, m_repaintLogicalTop, repaintLogicalRight - repaintLogicalLeft, m_repaintLogicalBottom - m_repaintLogicalTop); 1980a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) else 1981a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) repaintRect = LayoutRect(m_repaintLogicalTop, repaintLogicalLeft, m_repaintLogicalBottom - m_repaintLogicalTop, repaintLogicalRight - repaintLogicalLeft); 1982a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 1983a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // The repaint rect may be split across columns, in which case adjustRectForColumns() will return the union. 1984a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) adjustRectForColumns(repaintRect); 1985a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 1986a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) if (hasOverflowClip()) { 1987a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // Adjust repaint rect for scroll offset 1988a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) repaintRect.move(-scrolledContentOffset()); 1989a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 1990a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // Don't allow this rect to spill out of our overflow box. 1991a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) repaintRect.intersect(LayoutRect(LayoutPoint(), size())); 1992a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) } 1993a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 1994a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // Make sure the rect is still non-empty after intersecting for overflow above 1995a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) if (!repaintRect.isEmpty()) { 1996d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) // Hits in media/event-attributes.html 1997d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) DisableCompositingQueryAsserts disabler; 1998d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) 19995d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles) invalidatePaintRectangle(repaintRect); // We need to do a partial repaint of our content. 2000a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) if (hasReflection()) 20015d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles) invalidatePaintRectangle(reflectedRect(repaintRect)); 2002a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) } 2003a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 2004a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) m_repaintLogicalTop = 0; 2005a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) m_repaintLogicalBottom = 0; 2006a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)} 2007a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 2008f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)void RenderBlockFlow::paintFloats(PaintInfo& paintInfo, const LayoutPoint& paintOffset, bool preservePhase) 2009f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles){ 2010f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (!m_floatingObjects) 2011f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) return; 2012f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2013f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); 2014f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) FloatingObjectSetIterator end = floatingObjectSet.end(); 2015f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) for (FloatingObjectSetIterator it = floatingObjectSet.begin(); it != end; ++it) { 2016d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles) FloatingObject* floatingObject = it->get(); 2017f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // Only paint the object if our m_shouldPaint flag is set. 2018f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (floatingObject->shouldPaint() && !floatingObject->renderer()->hasSelfPaintingLayer()) { 2019f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) PaintInfo currentPaintInfo(paintInfo); 2020f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) currentPaintInfo.phase = preservePhase ? paintInfo.phase : PaintPhaseBlockBackground; 2021f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // FIXME: LayoutPoint version of xPositionForFloatIncludingMargin would make this much cleaner. 2022f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) LayoutPoint childPoint = flipFloatForWritingModeForChild(floatingObject, LayoutPoint(paintOffset.x() + xPositionForFloatIncludingMargin(floatingObject) - floatingObject->renderer()->x(), paintOffset.y() + yPositionForFloatIncludingMargin(floatingObject) - floatingObject->renderer()->y())); 2023f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) floatingObject->renderer()->paint(currentPaintInfo, childPoint); 2024f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (!preservePhase) { 2025f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) currentPaintInfo.phase = PaintPhaseChildBlockBackgrounds; 2026f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) floatingObject->renderer()->paint(currentPaintInfo, childPoint); 2027f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) currentPaintInfo.phase = PaintPhaseFloat; 2028f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) floatingObject->renderer()->paint(currentPaintInfo, childPoint); 2029f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) currentPaintInfo.phase = PaintPhaseForeground; 2030f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) floatingObject->renderer()->paint(currentPaintInfo, childPoint); 2031f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) currentPaintInfo.phase = PaintPhaseOutline; 2032f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) floatingObject->renderer()->paint(currentPaintInfo, childPoint); 2033f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) } 2034f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) } 2035f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) } 2036f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)} 2037f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2038f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)void RenderBlockFlow::clipOutFloatingObjects(RenderBlock* rootBlock, const PaintInfo* paintInfo, const LayoutPoint& rootBlockPhysicalPosition, const LayoutSize& offsetFromRootBlock) 2039f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles){ 2040f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (m_floatingObjects) { 2041f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); 2042f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) FloatingObjectSetIterator end = floatingObjectSet.end(); 2043f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) for (FloatingObjectSetIterator it = floatingObjectSet.begin(); it != end; ++it) { 2044d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles) FloatingObject* floatingObject = it->get(); 2045f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) LayoutRect floatBox(offsetFromRootBlock.width() + xPositionForFloatIncludingMargin(floatingObject), 2046f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) offsetFromRootBlock.height() + yPositionForFloatIncludingMargin(floatingObject), 2047f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) floatingObject->renderer()->width(), floatingObject->renderer()->height()); 2048f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) rootBlock->flipForWritingMode(floatBox); 2049f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) floatBox.move(rootBlockPhysicalPosition.x(), rootBlockPhysicalPosition.y()); 2050f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) paintInfo->context->clipOut(pixelSnappedIntRect(floatBox)); 2051f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) } 2052f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) } 2053f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)} 2054f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2055f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)void RenderBlockFlow::clearFloats(EClear clear) 2056f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles){ 2057f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) positionNewFloats(); 2058f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // set y position 2059f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) LayoutUnit newY = 0; 2060f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) switch (clear) { 2061f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) case CLEFT: 2062f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) newY = lowestFloatLogicalBottom(FloatingObject::FloatLeft); 2063f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) break; 2064f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) case CRIGHT: 2065f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) newY = lowestFloatLogicalBottom(FloatingObject::FloatRight); 2066f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) break; 2067f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) case CBOTH: 2068f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) newY = lowestFloatLogicalBottom(); 2069f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) default: 2070f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) break; 2071f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) } 2072f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (height() < newY) 2073f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) setLogicalHeight(newY); 2074f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)} 2075f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2076f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)bool RenderBlockFlow::containsFloat(RenderBox* renderer) const 2077f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles){ 207851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) return m_floatingObjects && m_floatingObjects->set().contains<FloatingObjectHashTranslator>(renderer); 2079f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)} 2080f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2081f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)void RenderBlockFlow::removeFloatingObjects() 2082f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles){ 2083f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (!m_floatingObjects) 2084f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) return; 2085f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 208607a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch markSiblingsWithFloatsForLayout(); 208707a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch 2088f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) m_floatingObjects->clear(); 2089f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)} 2090f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2091f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)LayoutPoint RenderBlockFlow::flipFloatForWritingModeForChild(const FloatingObject* child, const LayoutPoint& point) const 2092f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles){ 2093f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (!style()->isFlippedBlocksWritingMode()) 2094f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) return point; 2095f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2096f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // This is similar to RenderBox::flipForWritingModeForChild. We have to subtract out our left/top offsets twice, since 2097f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // it's going to get added back in. We hide this complication here so that the calling code looks normal for the unflipped 2098f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // case. 2099f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (isHorizontalWritingMode()) 2100f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) return LayoutPoint(point.x(), point.y() + height() - child->renderer()->height() - 2 * yPositionForFloatIncludingMargin(child)); 2101f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) return LayoutPoint(point.x() + width() - child->renderer()->width() - 2 * xPositionForFloatIncludingMargin(child), point.y()); 2102f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)} 2103f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 210451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)LayoutUnit RenderBlockFlow::logicalLeftOffsetForPositioningFloat(LayoutUnit logicalTop, LayoutUnit fixedOffset, bool applyTextIndent, LayoutUnit* heightRemaining) const 210551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){ 210651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) LayoutUnit offset = fixedOffset; 210751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) if (m_floatingObjects && m_floatingObjects->hasLeftObjects()) 210851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) offset = m_floatingObjects->logicalLeftOffsetForPositioningFloat(fixedOffset, logicalTop, heightRemaining); 210951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) return adjustLogicalLeftOffsetForLine(offset, applyTextIndent); 211051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)} 211151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 211251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)LayoutUnit RenderBlockFlow::logicalRightOffsetForPositioningFloat(LayoutUnit logicalTop, LayoutUnit fixedOffset, bool applyTextIndent, LayoutUnit* heightRemaining) const 211351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){ 211451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) LayoutUnit offset = fixedOffset; 211551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) if (m_floatingObjects && m_floatingObjects->hasRightObjects()) 211651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) offset = m_floatingObjects->logicalRightOffsetForPositioningFloat(fixedOffset, logicalTop, heightRemaining); 211751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) return adjustLogicalRightOffsetForLine(offset, applyTextIndent); 211851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)} 211951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 212009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)LayoutUnit RenderBlockFlow::adjustLogicalLeftOffsetForLine(LayoutUnit offsetFromFloats, bool applyTextIndent) const 212109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){ 212209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) LayoutUnit left = offsetFromFloats; 212309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 212409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (applyTextIndent && style()->isLeftToRightDirection()) 212509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) left += textIndentOffset(); 212609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 212709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return left; 212809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)} 212909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 213009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)LayoutUnit RenderBlockFlow::adjustLogicalRightOffsetForLine(LayoutUnit offsetFromFloats, bool applyTextIndent) const 213109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){ 213209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) LayoutUnit right = offsetFromFloats; 213309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 213409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (applyTextIndent && !style()->isLeftToRightDirection()) 213509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) right -= textIndentOffset(); 213609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 213709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return right; 213809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)} 213909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 2140f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)LayoutPoint RenderBlockFlow::computeLogicalLocationForFloat(const FloatingObject* floatingObject, LayoutUnit logicalTopOffset) const 2141f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles){ 2142f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) RenderBox* childBox = floatingObject->renderer(); 214309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) LayoutUnit logicalLeftOffset = logicalLeftOffsetForContent(); // Constant part of left offset. 2144f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) LayoutUnit logicalRightOffset; // Constant part of right offset. 214507a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch logicalRightOffset = logicalRightOffsetForContent(); 2146f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2147f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) LayoutUnit floatLogicalWidth = min(logicalWidthForFloat(floatingObject), logicalRightOffset - logicalLeftOffset); // The width we look for. 2148f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2149f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) LayoutUnit floatLogicalLeft; 2150f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2151f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) bool insideFlowThread = flowThreadContainingBlock(); 2152f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2153f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (childBox->style()->floating() == LeftFloat) { 2154f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) LayoutUnit heightRemainingLeft = 1; 2155f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) LayoutUnit heightRemainingRight = 1; 215651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) floatLogicalLeft = logicalLeftOffsetForPositioningFloat(logicalTopOffset, logicalLeftOffset, false, &heightRemainingLeft); 215751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) while (logicalRightOffsetForPositioningFloat(logicalTopOffset, logicalRightOffset, false, &heightRemainingRight) - floatLogicalLeft < floatLogicalWidth) { 2158f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) logicalTopOffset += min(heightRemainingLeft, heightRemainingRight); 215951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) floatLogicalLeft = logicalLeftOffsetForPositioningFloat(logicalTopOffset, logicalLeftOffset, false, &heightRemainingLeft); 2160f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (insideFlowThread) { 2161f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // Have to re-evaluate all of our offsets, since they may have changed. 216209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) logicalRightOffset = logicalRightOffsetForContent(); // Constant part of right offset. 216309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) logicalLeftOffset = logicalLeftOffsetForContent(); // Constant part of left offset. 2164f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) floatLogicalWidth = min(logicalWidthForFloat(floatingObject), logicalRightOffset - logicalLeftOffset); 2165f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) } 2166f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) } 2167f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) floatLogicalLeft = max(logicalLeftOffset - borderAndPaddingLogicalLeft(), floatLogicalLeft); 2168f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) } else { 2169f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) LayoutUnit heightRemainingLeft = 1; 2170f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) LayoutUnit heightRemainingRight = 1; 217151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) floatLogicalLeft = logicalRightOffsetForPositioningFloat(logicalTopOffset, logicalRightOffset, false, &heightRemainingRight); 217251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) while (floatLogicalLeft - logicalLeftOffsetForPositioningFloat(logicalTopOffset, logicalLeftOffset, false, &heightRemainingLeft) < floatLogicalWidth) { 2173f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) logicalTopOffset += min(heightRemainingLeft, heightRemainingRight); 217451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) floatLogicalLeft = logicalRightOffsetForPositioningFloat(logicalTopOffset, logicalRightOffset, false, &heightRemainingRight); 2175f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (insideFlowThread) { 2176f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // Have to re-evaluate all of our offsets, since they may have changed. 217709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) logicalRightOffset = logicalRightOffsetForContent(); // Constant part of right offset. 217809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) logicalLeftOffset = logicalLeftOffsetForContent(); // Constant part of left offset. 2179f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) floatLogicalWidth = min(logicalWidthForFloat(floatingObject), logicalRightOffset - logicalLeftOffset); 2180f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) } 2181f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) } 2182f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // Use the original width of the float here, since the local variable 2183f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // |floatLogicalWidth| was capped to the available line width. See 2184f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // fast/block/float/clamped-right-float.html. 2185f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) floatLogicalLeft -= logicalWidthForFloat(floatingObject); 2186f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) } 2187f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2188f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) return LayoutPoint(floatLogicalLeft, logicalTopOffset); 2189f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)} 2190f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2191f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)FloatingObject* RenderBlockFlow::insertFloatingObject(RenderBox* floatBox) 2192f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles){ 2193f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) ASSERT(floatBox->isFloating()); 2194f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2195f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // Create the list of special objects if we don't aleady have one 2196f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (!m_floatingObjects) { 2197f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) createFloatingObjects(); 2198f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) } else { 2199f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // Don't insert the object again if it's already in the list 2200f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); 220151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) FloatingObjectSetIterator it = floatingObjectSet.find<FloatingObjectHashTranslator>(floatBox); 2202f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (it != floatingObjectSet.end()) 2203d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles) return it->get(); 2204f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) } 2205f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2206f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // Create the special object entry & append it to the list 2207f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2208f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) OwnPtr<FloatingObject> newObj = FloatingObject::create(floatBox); 2209f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2210f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // Our location is irrelevant if we're unsplittable or no pagination is in effect. 2211f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // Just go ahead and lay out the float. 2212f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) bool isChildRenderBlock = floatBox->isRenderBlock(); 2213f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (isChildRenderBlock && !floatBox->needsLayout() && view()->layoutState()->pageLogicalHeightChanged()) 2214f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) floatBox->setChildNeedsLayout(MarkOnlyThis); 2215f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2216f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) bool needsBlockDirectionLocationSetBeforeLayout = isChildRenderBlock && view()->layoutState()->needsBlockDirectionLocationSetBeforeLayout(); 2217f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (!needsBlockDirectionLocationSetBeforeLayout || isWritingModeRoot()) { // We are unsplittable if we're a block flow root. 2218f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) floatBox->layoutIfNeeded(); 2219f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) } else { 2220f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) floatBox->updateLogicalWidth(); 2221f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) floatBox->computeAndSetBlockDirectionMargins(this); 2222f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) } 2223f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2224f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) setLogicalWidthForFloat(newObj.get(), logicalWidthForChild(floatBox) + marginStartForChild(floatBox) + marginEndForChild(floatBox)); 2225f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2226f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) return m_floatingObjects->add(newObj.release()); 2227f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)} 2228f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2229f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)void RenderBlockFlow::removeFloatingObject(RenderBox* floatBox) 2230f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles){ 2231f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (m_floatingObjects) { 2232f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); 223351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) FloatingObjectSetIterator it = floatingObjectSet.find<FloatingObjectHashTranslator>(floatBox); 2234f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (it != floatingObjectSet.end()) { 2235d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles) FloatingObject* floatingObject = it->get(); 2236f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (childrenInline()) { 2237f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) LayoutUnit logicalTop = logicalTopForFloat(floatingObject); 2238f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) LayoutUnit logicalBottom = logicalBottomForFloat(floatingObject); 2239f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2240f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // Fix for https://bugs.webkit.org/show_bug.cgi?id=54995. 2241f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (logicalBottom < 0 || logicalBottom < logicalTop || logicalTop == LayoutUnit::max()) { 2242f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) logicalBottom = LayoutUnit::max(); 2243f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) } else { 2244f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // Special-case zero- and less-than-zero-height floats: those don't touch 2245f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // the line that they're on, but it still needs to be dirtied. This is 2246f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // accomplished by pretending they have a height of 1. 2247f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) logicalBottom = max(logicalBottom, logicalTop + 1); 2248f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) } 2249f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (floatingObject->originatingLine()) { 2250f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (!selfNeedsLayout()) { 2251f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) ASSERT(floatingObject->originatingLine()->renderer() == this); 2252f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) floatingObject->originatingLine()->markDirty(); 2253f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) } 22545d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)#if ASSERT_ENABLED 2255f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) floatingObject->setOriginatingLine(0); 2256f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)#endif 2257f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) } 2258f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) markLinesDirtyInBlockRange(0, logicalBottom); 2259f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) } 2260f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) m_floatingObjects->remove(floatingObject); 2261f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) } 2262f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) } 2263f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)} 2264f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2265f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)void RenderBlockFlow::removeFloatingObjectsBelow(FloatingObject* lastFloat, int logicalOffset) 2266f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles){ 2267f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (!containsFloats()) 2268f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) return; 2269f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2270f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); 2271d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles) FloatingObject* curr = floatingObjectSet.last().get(); 2272f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) while (curr != lastFloat && (!curr->isPlaced() || logicalTopForFloat(curr) >= logicalOffset)) { 2273f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) m_floatingObjects->remove(curr); 2274f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (floatingObjectSet.isEmpty()) 2275f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) break; 2276d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles) curr = floatingObjectSet.last().get(); 2277f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) } 2278f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)} 2279f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2280f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)bool RenderBlockFlow::positionNewFloats() 2281f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles){ 2282f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (!m_floatingObjects) 2283f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) return false; 2284f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2285f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); 2286f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (floatingObjectSet.isEmpty()) 2287f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) return false; 2288f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2289f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // If all floats have already been positioned, then we have no work to do. 2290f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (floatingObjectSet.last()->isPlaced()) 2291f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) return false; 2292f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2293f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // Move backwards through our floating object list until we find a float that has 2294f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // already been positioned. Then we'll be able to move forward, positioning all of 2295f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // the new floats that need it. 2296f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) FloatingObjectSetIterator it = floatingObjectSet.end(); 2297f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) --it; // Go to last item. 2298f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) FloatingObjectSetIterator begin = floatingObjectSet.begin(); 2299f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) FloatingObject* lastPlacedFloatingObject = 0; 2300f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) while (it != begin) { 2301f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) --it; 2302f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if ((*it)->isPlaced()) { 2303d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles) lastPlacedFloatingObject = it->get(); 2304f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) ++it; 2305f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) break; 2306f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) } 2307f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) } 2308f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2309f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) LayoutUnit logicalTop = logicalHeight(); 2310f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2311f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // The float cannot start above the top position of the last positioned float. 2312f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (lastPlacedFloatingObject) 2313f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) logicalTop = max(logicalTopForFloat(lastPlacedFloatingObject), logicalTop); 2314f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2315f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) FloatingObjectSetIterator end = floatingObjectSet.end(); 2316f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // Now walk through the set of unpositioned floats and place them. 2317f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) for (; it != end; ++it) { 2318d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles) FloatingObject* floatingObject = it->get(); 2319f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // The containing block is responsible for positioning floats, so if we have floats in our 2320f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // list that come from somewhere else, do not attempt to position them. 2321f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (floatingObject->renderer()->containingBlock() != this) 2322f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) continue; 2323f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2324f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) RenderBox* childBox = floatingObject->renderer(); 2325f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2326323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles) // FIXME Investigate if this can be removed. crbug.com/370006 2327f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles) childBox->setMayNeedPaintInvalidation(true); 2328323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles) 232909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) LayoutUnit childLogicalLeftMargin = style()->isLeftToRightDirection() ? marginStartForChild(childBox) : marginEndForChild(childBox); 2330f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) LayoutRect oldRect = childBox->frameRect(); 2331f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2332f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (childBox->style()->clear() & CLEFT) 2333f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) logicalTop = max(lowestFloatLogicalBottom(FloatingObject::FloatLeft), logicalTop); 2334f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (childBox->style()->clear() & CRIGHT) 2335f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) logicalTop = max(lowestFloatLogicalBottom(FloatingObject::FloatRight), logicalTop); 2336f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2337f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) LayoutPoint floatLogicalLocation = computeLogicalLocationForFloat(floatingObject, logicalTop); 2338f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2339f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) setLogicalLeftForFloat(floatingObject, floatLogicalLocation.x()); 2340f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2341f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) setLogicalLeftForChild(childBox, floatLogicalLocation.x() + childLogicalLeftMargin); 2342f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) setLogicalTopForChild(childBox, floatLogicalLocation.y() + marginBeforeForChild(childBox)); 2343f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 234410f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch SubtreeLayoutScope layoutScope(*childBox); 2345f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) LayoutState* layoutState = view()->layoutState(); 2346f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) bool isPaginated = layoutState->isPaginated(); 2347f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (isPaginated && !childBox->needsLayout()) 2348f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) childBox->markForPaginationRelayoutIfNeeded(layoutScope); 2349f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2350f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) childBox->layoutIfNeeded(); 2351f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2352f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (isPaginated) { 2353f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // If we are unsplittable and don't fit, then we need to move down. 2354f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // We include our margins as part of the unsplittable area. 2355f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) LayoutUnit newLogicalTop = adjustForUnsplittableChild(childBox, floatLogicalLocation.y(), true); 2356f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2357f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // See if we have a pagination strut that is making us move down further. 2358f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // Note that an unsplittable child can't also have a pagination strut, so this is 2359f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // exclusive with the case above. 2360f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) RenderBlock* childBlock = childBox->isRenderBlock() ? toRenderBlock(childBox) : 0; 2361f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (childBlock && childBlock->paginationStrut()) { 2362f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) newLogicalTop += childBlock->paginationStrut(); 2363f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) childBlock->setPaginationStrut(0); 2364f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) } 2365f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2366f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (newLogicalTop != floatLogicalLocation.y()) { 2367f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) floatingObject->setPaginationStrut(newLogicalTop - floatLogicalLocation.y()); 2368f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2369f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) floatLogicalLocation = computeLogicalLocationForFloat(floatingObject, newLogicalTop); 2370f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) setLogicalLeftForFloat(floatingObject, floatLogicalLocation.x()); 2371f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2372f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) setLogicalLeftForChild(childBox, floatLogicalLocation.x() + childLogicalLeftMargin); 2373f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) setLogicalTopForChild(childBox, floatLogicalLocation.y() + marginBeforeForChild(childBox)); 2374f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2375f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (childBlock) 2376f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) childBlock->setChildNeedsLayout(MarkOnlyThis); 2377f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) childBox->layoutIfNeeded(); 2378f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) } 2379f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) } 2380f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2381f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) setLogicalTopForFloat(floatingObject, floatLogicalLocation.y()); 2382f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2383f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) setLogicalHeightForFloat(floatingObject, logicalHeightForChild(childBox) + marginBeforeForChild(childBox) + marginAfterForChild(childBox)); 2384f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2385f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) m_floatingObjects->addPlacedObject(floatingObject); 2386f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 238751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) if (ShapeOutsideInfo* shapeOutside = childBox->shapeOutsideInfo()) 2388d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) shapeOutside->setReferenceBoxLogicalSize(logicalSizeForChild(childBox)); 238951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 2390f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // If the child moved, we have to repaint it. 239109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (!RuntimeEnabledFeatures::repaintAfterLayoutEnabled() 23925d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles) && childBox->checkForPaintInvalidationDuringLayout()) 2393f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) childBox->repaintDuringLayoutIfMoved(oldRect); 2394f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) } 2395f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) return true; 2396f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)} 2397f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2398f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)bool RenderBlockFlow::hasOverhangingFloat(RenderBox* renderer) 2399f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles){ 2400f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (!m_floatingObjects || hasColumns() || !parent()) 2401f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) return false; 2402f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2403f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); 240451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) FloatingObjectSetIterator it = floatingObjectSet.find<FloatingObjectHashTranslator>(renderer); 2405f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (it == floatingObjectSet.end()) 2406f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) return false; 2407f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2408d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles) return logicalBottomForFloat(it->get()) > logicalHeight(); 2409f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)} 2410f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2411f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)void RenderBlockFlow::addIntrudingFloats(RenderBlockFlow* prev, LayoutUnit logicalLeftOffset, LayoutUnit logicalTopOffset) 2412f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles){ 2413f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) ASSERT(!avoidsFloats()); 2414f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2415f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu // If we create our own block formatting context then our contents don't interact with floats outside it, even those from our parent. 2416f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu if (createsBlockFormattingContext()) 2417f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu return; 2418f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu 2419f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // If the parent or previous sibling doesn't have any floats to add, don't bother. 2420f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (!prev->m_floatingObjects) 2421f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) return; 2422f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2423f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) logicalLeftOffset += marginLogicalLeft(); 2424f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2425f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) const FloatingObjectSet& prevSet = prev->m_floatingObjects->set(); 2426f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) FloatingObjectSetIterator prevEnd = prevSet.end(); 2427f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) for (FloatingObjectSetIterator prevIt = prevSet.begin(); prevIt != prevEnd; ++prevIt) { 2428d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles) FloatingObject* floatingObject = prevIt->get(); 2429f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (logicalBottomForFloat(floatingObject) > logicalTopOffset) { 2430f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (!m_floatingObjects || !m_floatingObjects->set().contains(floatingObject)) { 2431f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // We create the floating object list lazily. 2432f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (!m_floatingObjects) 2433f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) createFloatingObjects(); 2434f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2435f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // Applying the child's margin makes no sense in the case where the child was passed in. 2436f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // since this margin was added already through the modification of the |logicalLeftOffset| variable 2437f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // above. |logicalLeftOffset| will equal the margin in this case, so it's already been taken 2438f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // into account. Only apply this code if prev is the parent, since otherwise the left margin 2439f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // will get applied twice. 2440f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) LayoutSize offset = isHorizontalWritingMode() 2441f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) ? LayoutSize(logicalLeftOffset - (prev != parent() ? prev->marginLeft() : LayoutUnit()), logicalTopOffset) 2442f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) : LayoutSize(logicalTopOffset, logicalLeftOffset - (prev != parent() ? prev->marginTop() : LayoutUnit())); 2443f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2444f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) m_floatingObjects->add(floatingObject->copyToNewContainer(offset)); 2445f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) } 2446f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) } 2447f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) } 2448f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)} 2449f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 245010f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdochvoid RenderBlockFlow::addOverhangingFloats(RenderBlockFlow* child, bool makeChildPaintOtherFloats) 2451f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles){ 2452f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // Prevent floats from being added to the canvas by the root element, e.g., <html>. 2453f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu if (!child->containsFloats() || child->isRenderRegion() || child->createsBlockFormattingContext()) 245410f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch return; 2455f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2456f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) LayoutUnit childLogicalTop = child->logicalTop(); 2457f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) LayoutUnit childLogicalLeft = child->logicalLeft(); 2458f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2459f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // Floats that will remain the child's responsibility to paint should factor into its 2460f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // overflow. 2461f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) FloatingObjectSetIterator childEnd = child->m_floatingObjects->set().end(); 2462f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) for (FloatingObjectSetIterator childIt = child->m_floatingObjects->set().begin(); childIt != childEnd; ++childIt) { 2463d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles) FloatingObject* floatingObject = childIt->get(); 2464f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) LayoutUnit logicalBottomForFloat = min(this->logicalBottomForFloat(floatingObject), LayoutUnit::max() - childLogicalTop); 2465f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) LayoutUnit logicalBottom = childLogicalTop + logicalBottomForFloat; 2466f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2467f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (logicalBottom > logicalHeight()) { 2468f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // If the object is not in the list, we add it now. 2469f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (!containsFloat(floatingObject->renderer())) { 2470f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) LayoutSize offset = isHorizontalWritingMode() ? LayoutSize(-childLogicalLeft, -childLogicalTop) : LayoutSize(-childLogicalTop, -childLogicalLeft); 2471f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) bool shouldPaint = false; 2472f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2473f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // The nearest enclosing layer always paints the float (so that zindex and stacking 2474f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // behaves properly). We always want to propagate the desire to paint the float as 2475f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // far out as we can, to the outermost block that overlaps the float, stopping only 2476f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // if we hit a self-painting layer boundary. 2477f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (floatingObject->renderer()->enclosingFloatPaintingLayer() == enclosingFloatPaintingLayer()) { 2478f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) floatingObject->setShouldPaint(false); 2479f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) shouldPaint = true; 2480f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) } 2481f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // We create the floating object list lazily. 2482f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (!m_floatingObjects) 2483f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) createFloatingObjects(); 2484f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2485f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) m_floatingObjects->add(floatingObject->copyToNewContainer(offset, shouldPaint, true)); 2486f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) } 2487f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) } else { 2488f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (makeChildPaintOtherFloats && !floatingObject->shouldPaint() && !floatingObject->renderer()->hasSelfPaintingLayer() 2489f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) && floatingObject->renderer()->isDescendantOf(child) && floatingObject->renderer()->enclosingFloatPaintingLayer() == child->enclosingFloatPaintingLayer()) { 2490f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // The float is not overhanging from this block, so if it is a descendant of the child, the child should 2491f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // paint it (the other case is that it is intruding into the child), unless it has its own layer or enclosing 2492f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // layer. 2493f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // If makeChildPaintOtherFloats is false, it means that the child must already know about all the floats 2494f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // it should paint. 2495f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) floatingObject->setShouldPaint(true); 2496f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) } 2497f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2498f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // Since the float doesn't overhang, it didn't get put into our list. We need to go ahead and add its overflow in to the 2499f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // child now. 2500f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (floatingObject->isDescendant()) 2501f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) child->addOverflowFromChild(floatingObject->renderer(), LayoutSize(xPositionForFloatIncludingMargin(floatingObject), yPositionForFloatIncludingMargin(floatingObject))); 2502f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) } 2503f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) } 2504f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)} 2505f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2506f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)LayoutUnit RenderBlockFlow::lowestFloatLogicalBottom(FloatingObject::Type floatType) const 2507f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles){ 2508f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (!m_floatingObjects) 2509f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) return 0; 2510f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2511f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) return m_floatingObjects->lowestFloatLogicalBottom(floatType); 2512f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)} 2513f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2514f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)LayoutUnit RenderBlockFlow::nextFloatLogicalBottomBelow(LayoutUnit logicalHeight, ShapeOutsideFloatOffsetMode offsetMode) const 2515f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles){ 2516f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (!m_floatingObjects) 2517f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) return logicalHeight; 2518f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 25196f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch LayoutUnit logicalBottom; 2520f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); 2521f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) FloatingObjectSetIterator end = floatingObjectSet.end(); 2522f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) for (FloatingObjectSetIterator it = floatingObjectSet.begin(); it != end; ++it) { 2523d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles) FloatingObject* floatingObject = it->get(); 2524f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) LayoutUnit floatLogicalBottom = logicalBottomForFloat(floatingObject); 2525f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) ShapeOutsideInfo* shapeOutside = floatingObject->renderer()->shapeOutsideInfo(); 2526f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (shapeOutside && (offsetMode == ShapeOutsideFloatShapeOffset)) { 2527f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) LayoutUnit shapeLogicalBottom = logicalTopForFloat(floatingObject) + marginBeforeForChild(floatingObject->renderer()) + shapeOutside->shapeLogicalBottom(); 2528f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // Use the shapeLogicalBottom unless it extends outside of the margin box, in which case it is clipped. 2529f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (shapeLogicalBottom < floatLogicalBottom) 2530f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) floatLogicalBottom = shapeLogicalBottom; 2531f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) } 2532f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (floatLogicalBottom > logicalHeight) 25336f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch logicalBottom = logicalBottom ? min(floatLogicalBottom, logicalBottom) : floatLogicalBottom; 2534f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) } 2535f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 25366f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch return logicalBottom; 2537f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)} 2538f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2539f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)bool RenderBlockFlow::hitTestFloats(const HitTestRequest& request, HitTestResult& result, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset) 2540f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles){ 2541f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (!m_floatingObjects) 2542f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) return false; 2543f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2544f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) LayoutPoint adjustedLocation = accumulatedOffset; 2545f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (isRenderView()) { 2546f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) adjustedLocation += toLayoutSize(toRenderView(this)->frameView()->scrollPosition()); 2547f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) } 2548f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2549f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); 2550f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) FloatingObjectSetIterator begin = floatingObjectSet.begin(); 2551f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) for (FloatingObjectSetIterator it = floatingObjectSet.end(); it != begin;) { 2552f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) --it; 2553d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles) FloatingObject* floatingObject = it->get(); 2554f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (floatingObject->shouldPaint() && !floatingObject->renderer()->hasSelfPaintingLayer()) { 2555f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) LayoutUnit xOffset = xPositionForFloatIncludingMargin(floatingObject) - floatingObject->renderer()->x(); 2556f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) LayoutUnit yOffset = yPositionForFloatIncludingMargin(floatingObject) - floatingObject->renderer()->y(); 2557f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) LayoutPoint childPoint = flipFloatForWritingModeForChild(floatingObject, adjustedLocation + LayoutSize(xOffset, yOffset)); 2558f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (floatingObject->renderer()->hitTest(request, result, locationInContainer, childPoint)) { 2559f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) updateHitTestResult(result, locationInContainer.point() - toLayoutSize(childPoint)); 2560f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) return true; 2561f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) } 2562f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) } 2563f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) } 2564f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2565f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) return false; 2566f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)} 2567f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2568f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)void RenderBlockFlow::adjustForBorderFit(LayoutUnit x, LayoutUnit& left, LayoutUnit& right) const 2569f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles){ 2570f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) RenderBlock::adjustForBorderFit(x, left, right); 2571f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (m_floatingObjects && style()->visibility() == VISIBLE) { 2572f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); 2573f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) FloatingObjectSetIterator end = floatingObjectSet.end(); 2574f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) for (FloatingObjectSetIterator it = floatingObjectSet.begin(); it != end; ++it) { 2575d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles) FloatingObject* floatingObject = it->get(); 2576f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // Only examine the object if our m_shouldPaint flag is set. 2577f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (floatingObject->shouldPaint()) { 2578f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) LayoutUnit floatLeft = xPositionForFloatIncludingMargin(floatingObject) - floatingObject->renderer()->x(); 2579f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) LayoutUnit floatRight = floatLeft + floatingObject->renderer()->width(); 2580f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) left = min(left, floatLeft); 2581f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) right = max(right, floatRight); 2582f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) } 2583f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) } 2584f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) } 2585f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)} 2586f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 258751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)LayoutUnit RenderBlockFlow::logicalLeftFloatOffsetForLine(LayoutUnit logicalTop, LayoutUnit fixedOffset, LayoutUnit logicalHeight) const 2588f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles){ 2589f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (m_floatingObjects && m_floatingObjects->hasLeftObjects()) 259051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) return m_floatingObjects->logicalLeftOffset(fixedOffset, logicalTop, logicalHeight); 2591f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2592f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) return fixedOffset; 2593f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)} 2594f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 259551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)LayoutUnit RenderBlockFlow::logicalRightFloatOffsetForLine(LayoutUnit logicalTop, LayoutUnit fixedOffset, LayoutUnit logicalHeight) const 2596f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles){ 2597f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) if (m_floatingObjects && m_floatingObjects->hasRightObjects()) 259851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) return m_floatingObjects->logicalRightOffset(fixedOffset, logicalTop, logicalHeight); 2599f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 2600f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) return fixedOffset; 2601f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)} 2602f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 260351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)GapRects RenderBlockFlow::inlineSelectionGaps(RenderBlock* rootBlock, const LayoutPoint& rootBlockPhysicalPosition, const LayoutSize& offsetFromRootBlock, 260451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) LayoutUnit& lastLogicalTop, LayoutUnit& lastLogicalLeft, LayoutUnit& lastLogicalRight, const PaintInfo* paintInfo) 260551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){ 260651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) GapRects result; 260751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 260851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) bool containsStart = selectionState() == SelectionStart || selectionState() == SelectionBoth; 260951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 261051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) if (!firstLineBox()) { 261151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) if (containsStart) { 261251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) // Go ahead and update our lastLogicalTop to be the bottom of the block. <hr>s or empty blocks with height can trip this 261351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) // case. 261451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) lastLogicalTop = rootBlock->blockDirectionOffset(offsetFromRootBlock) + logicalHeight(); 261551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) lastLogicalLeft = logicalLeftSelectionOffset(rootBlock, logicalHeight()); 261651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) lastLogicalRight = logicalRightSelectionOffset(rootBlock, logicalHeight()); 261751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) } 261851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) return result; 261951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) } 262051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 262151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) RootInlineBox* lastSelectedLine = 0; 262251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) RootInlineBox* curr; 262351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) for (curr = firstRootBox(); curr && !curr->hasSelectedChildren(); curr = curr->nextRootBox()) { } 262451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 262551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) // Now paint the gaps for the lines. 262651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) for (; curr && curr->hasSelectedChildren(); curr = curr->nextRootBox()) { 262751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) LayoutUnit selTop = curr->selectionTopAdjustedForPrecedingBlock(); 262851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) LayoutUnit selHeight = curr->selectionHeightAdjustedForPrecedingBlock(); 262951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 263051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) if (!containsStart && !lastSelectedLine && selectionState() != SelectionStart && selectionState() != SelectionBoth) { 263151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) result.uniteCenter(blockSelectionGap(rootBlock, rootBlockPhysicalPosition, offsetFromRootBlock, lastLogicalTop, 263251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) lastLogicalLeft, lastLogicalRight, selTop, paintInfo)); 263351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) } 263451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 263551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) LayoutRect logicalRect(curr->logicalLeft(), selTop, curr->logicalWidth(), selTop + selHeight); 263651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) logicalRect.move(isHorizontalWritingMode() ? offsetFromRootBlock : offsetFromRootBlock.transposedSize()); 263751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) LayoutRect physicalRect = rootBlock->logicalRectToPhysicalRect(rootBlockPhysicalPosition, logicalRect); 263851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) if (!paintInfo || (isHorizontalWritingMode() && physicalRect.y() < paintInfo->rect.maxY() && physicalRect.maxY() > paintInfo->rect.y()) 263951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) || (!isHorizontalWritingMode() && physicalRect.x() < paintInfo->rect.maxX() && physicalRect.maxX() > paintInfo->rect.x())) 264051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) result.unite(curr->lineSelectionGap(rootBlock, rootBlockPhysicalPosition, offsetFromRootBlock, selTop, selHeight, paintInfo)); 264151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 264251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) lastSelectedLine = curr; 264351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) } 264451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 264551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) if (containsStart && !lastSelectedLine) { 264651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) // VisibleSelection must start just after our last line. 264751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) lastSelectedLine = lastRootBox(); 264851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) } 264951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 265051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) if (lastSelectedLine && selectionState() != SelectionEnd && selectionState() != SelectionBoth) { 265151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) // Go ahead and update our lastY to be the bottom of the last selected line. 265251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) lastLogicalTop = rootBlock->blockDirectionOffset(offsetFromRootBlock) + lastSelectedLine->selectionBottom(); 265351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) lastLogicalLeft = logicalLeftSelectionOffset(rootBlock, lastSelectedLine->selectionBottom()); 265451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) lastLogicalRight = logicalRightSelectionOffset(rootBlock, lastSelectedLine->selectionBottom()); 265551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) } 265651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) return result; 265751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)} 265851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 265909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)LayoutUnit RenderBlockFlow::logicalLeftSelectionOffset(RenderBlock* rootBlock, LayoutUnit position) 266009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){ 266109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) LayoutUnit logicalLeft = logicalLeftOffsetForLine(position, false); 266209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (logicalLeft == logicalLeftOffsetForContent()) 266309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return RenderBlock::logicalLeftSelectionOffset(rootBlock, position); 266409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 266509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) RenderBlock* cb = this; 266609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) while (cb != rootBlock) { 266709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) logicalLeft += cb->logicalLeft(); 266809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) cb = cb->containingBlock(); 266909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) } 267009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return logicalLeft; 267109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)} 267209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 267309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)LayoutUnit RenderBlockFlow::logicalRightSelectionOffset(RenderBlock* rootBlock, LayoutUnit position) 267409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){ 267509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) LayoutUnit logicalRight = logicalRightOffsetForLine(position, false); 267609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (logicalRight == logicalRightOffsetForContent()) 267709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return RenderBlock::logicalRightSelectionOffset(rootBlock, position); 267809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 267909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) RenderBlock* cb = this; 268009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) while (cb != rootBlock) { 268109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) logicalRight += cb->logicalLeft(); 268209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) cb = cb->containingBlock(); 268309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) } 268409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return logicalRight; 268509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)} 268609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 268719cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles)template <typename CharacterType> 268809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)static inline TextRun constructTextRunInternal(RenderObject* context, const Font& font, const CharacterType* characters, int length, RenderStyle* style, TextDirection direction, TextRun::ExpansionBehavior expansion) 268919cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles){ 269019cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles) ASSERT(style); 269119cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles) 269209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) TextDirection textDirection = direction; 269319cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles) bool directionalOverride = style->rtlOrdering() == VisualOrder; 269419cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles) 269519cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles) TextRun run(characters, length, 0, 0, expansion, textDirection, directionalOverride); 269619cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles) if (textRunNeedsRenderingContext(font)) 269719cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles) run.setRenderingContext(SVGTextRunRenderingContext::create(context)); 269819cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles) 269919cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles) return run; 270019cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles)} 270119cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles) 270219cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles)template <typename CharacterType> 270309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)static inline TextRun constructTextRunInternal(RenderObject* context, const Font& font, const CharacterType* characters, int length, RenderStyle* style, TextDirection direction, TextRun::ExpansionBehavior expansion, TextRunFlags flags) 270419cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles){ 270519cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles) ASSERT(style); 270619cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles) 270709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) TextDirection textDirection = direction; 270819cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles) bool directionalOverride = style->rtlOrdering() == VisualOrder; 270919cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles) if (flags != DefaultTextRunFlags) { 271019cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles) if (flags & RespectDirection) 271119cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles) textDirection = style->direction(); 271219cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles) if (flags & RespectDirectionOverride) 271319cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles) directionalOverride |= isOverride(style->unicodeBidi()); 271419cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles) } 271509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 271619cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles) TextRun run(characters, length, 0, 0, expansion, textDirection, directionalOverride); 271719cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles) if (textRunNeedsRenderingContext(font)) 271819cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles) run.setRenderingContext(SVGTextRunRenderingContext::create(context)); 271919cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles) 272019cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles) return run; 272119cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles)} 272219cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles) 272309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)TextRun RenderBlockFlow::constructTextRun(RenderObject* context, const Font& font, const LChar* characters, int length, RenderStyle* style, TextDirection direction, TextRun::ExpansionBehavior expansion) 272419cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles){ 272509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return constructTextRunInternal(context, font, characters, length, style, direction, expansion); 272619cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles)} 272719cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles) 272809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)TextRun RenderBlockFlow::constructTextRun(RenderObject* context, const Font& font, const UChar* characters, int length, RenderStyle* style, TextDirection direction, TextRun::ExpansionBehavior expansion) 272919cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles){ 273009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return constructTextRunInternal(context, font, characters, length, style, direction, expansion); 273119cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles)} 273219cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles) 273309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)TextRun RenderBlockFlow::constructTextRun(RenderObject* context, const Font& font, const RenderText* text, RenderStyle* style, TextDirection direction, TextRun::ExpansionBehavior expansion) 273419cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles){ 273519cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles) if (text->is8Bit()) 273609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return constructTextRunInternal(context, font, text->characters8(), text->textLength(), style, direction, expansion); 273709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return constructTextRunInternal(context, font, text->characters16(), text->textLength(), style, direction, expansion); 273819cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles)} 273919cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles) 274009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)TextRun RenderBlockFlow::constructTextRun(RenderObject* context, const Font& font, const RenderText* text, unsigned offset, unsigned length, RenderStyle* style, TextDirection direction, TextRun::ExpansionBehavior expansion) 274119cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles){ 274219cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles) ASSERT(offset + length <= text->textLength()); 274319cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles) if (text->is8Bit()) 274409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return constructTextRunInternal(context, font, text->characters8() + offset, length, style, direction, expansion); 274509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return constructTextRunInternal(context, font, text->characters16() + offset, length, style, direction, expansion); 274619cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles)} 274719cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles) 274809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)TextRun RenderBlockFlow::constructTextRun(RenderObject* context, const Font& font, const String& string, RenderStyle* style, TextDirection direction, TextRun::ExpansionBehavior expansion, TextRunFlags flags) 274919cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles){ 275019cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles) unsigned length = string.length(); 275119cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles) if (!length) 275209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return constructTextRunInternal(context, font, static_cast<const LChar*>(0), length, style, direction, expansion, flags); 275319cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles) if (string.is8Bit()) 275409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return constructTextRunInternal(context, font, string.characters8(), length, style, direction, expansion, flags); 275509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return constructTextRunInternal(context, font, string.characters16(), length, style, direction, expansion, flags); 275651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)} 275751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 275809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)TextRun RenderBlockFlow::constructTextRun(RenderObject* context, const Font& font, const String& string, RenderStyle* style, TextRun::ExpansionBehavior expansion, TextRunFlags flags) 275951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){ 276009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) bool hasStrongDirectionality; 276109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return constructTextRun(context, font, string, style, 276209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) determineDirectionality(string, hasStrongDirectionality), 276309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) expansion, flags); 276451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)} 276551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 2766d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)TextRun RenderBlockFlow::constructTextRun(RenderObject* context, const Font& font, const RenderText* text, unsigned offset, unsigned length, RenderStyle* style, TextRun::ExpansionBehavior expansion) 2767d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles){ 2768d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) ASSERT(offset + length <= text->textLength()); 2769d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) TextRun run = text->is8Bit() 2770d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) ? constructTextRunInternal(context, font, text->characters8() + offset, length, style, LTR, expansion) 2771d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) : constructTextRunInternal(context, font, text->characters16() + offset, length, style, LTR, expansion); 2772d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) bool hasStrongDirectionality; 2773d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) run.setDirection(directionForRun(run, hasStrongDirectionality)); 2774d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) return run; 2775d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)} 2776d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) 277709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)RootInlineBox* RenderBlockFlow::createRootInlineBox() 277851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){ 2779d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) return new RootInlineBox(*this); 2780d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)} 2781d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) 27826f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdochvoid RenderBlockFlow::createOrDestroyMultiColumnFlowThreadIfNeeded() 2783d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles){ 27846f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch if (!document().regionBasedColumnsEnabled()) 2785d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) return; 2786d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) 27876f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch bool needsFlowThread = style()->specifiesColumns(); 27886f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch if (needsFlowThread != static_cast<bool>(multiColumnFlowThread())) { 27896f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch if (needsFlowThread) { 27906f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch RenderMultiColumnFlowThread* flowThread = RenderMultiColumnFlowThread::createAnonymous(document(), style()); 27916f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch addChild(flowThread); 27926f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch flowThread->populate(); 27936f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch RenderBlockFlowRareData& rareData = ensureRareData(); 27946f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch ASSERT(!rareData.m_multiColumnFlowThread); 27956f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch rareData.m_multiColumnFlowThread = flowThread; 27966f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch } else { 27976f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch multiColumnFlowThread()->evacuateAndDestroy(); 27986f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch ASSERT(!multiColumnFlowThread()); 27996f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch } 28006f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch } 280151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)} 280251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 280351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)RenderBlockFlow::RenderBlockFlowRareData& RenderBlockFlow::ensureRareData() 280451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){ 280551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) if (m_rareData) 280651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) return *m_rareData; 280751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 280851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) m_rareData = adoptPtr(new RenderBlockFlowRareData(this)); 280951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) return *m_rareData; 281051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)} 281151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 28128abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)} // namespace WebCore 2813