15c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/*
25c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * This file is part of the render object implementation for KHTML.
35c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *
45c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
55c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *           (C) 1999 Antti Koivisto (koivisto@kde.org)
65c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Copyright (C) 2003 Apple Computer, Inc.
75c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *
85c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * This library is free software; you can redistribute it and/or
95c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * modify it under the terms of the GNU Library General Public
105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * License as published by the Free Software Foundation; either
115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * version 2 of the License, or (at your option) any later version.
125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *
135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * This library is distributed in the hope that it will be useful,
145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * but WITHOUT ANY WARRANTY; without even the implied warranty of
155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Library General Public License for more details.
175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *
185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * You should have received a copy of the GNU Library General Public License
195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * along with this library; see the file COPYING.LIB.  If not, write to
205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Boston, MA 02110-1301, USA.
225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *
235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) */
245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#include "config.h"
2653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/rendering/RenderDeprecatedFlexibleBox.h"
275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)#include "core/frame/UseCounter.h"
2953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/rendering/RenderLayer.h"
3053e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/rendering/RenderView.h"
31c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)#include "core/rendering/TextAutosizer.h"
32c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)#include "core/rendering/TextRunConstructor.h"
33a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)#include "platform/fonts/Font.h"
3402772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch#include "wtf/StdLibExtras.h"
3502772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch#include "wtf/unicode/CharacterNames.h"
365c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
37c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)namespace blink {
385c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
395c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)class FlexBoxIterator {
405c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)public:
415c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    FlexBoxIterator(RenderDeprecatedFlexibleBox* parent)
425c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        : m_box(parent)
435c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        , m_largestOrdinal(1)
445c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    {
455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        if (m_box->style()->boxOrient() == HORIZONTAL && !m_box->style()->isLeftToRightDirection())
465c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            m_forward = m_box->style()->boxDirection() != BNORMAL;
475c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        else
485c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            m_forward = m_box->style()->boxDirection() == BNORMAL;
495c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        if (!m_forward) {
505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            // No choice, since we're going backwards, we have to find out the highest ordinal up front.
515c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            RenderBox* child = m_box->firstChildBox();
525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            while (child) {
535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                if (child->style()->boxOrdinalGroup() > m_largestOrdinal)
545c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    m_largestOrdinal = child->style()->boxOrdinalGroup();
555c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                child = child->nextSiblingBox();
565c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            }
575c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        }
585c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
595c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        reset();
605c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
615c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
625c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    void reset()
635c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    {
645c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        m_currentChild = 0;
655c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        m_ordinalIteration = -1;
665c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
675c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
685c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    RenderBox* first()
695c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    {
705c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        reset();
715c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return next();
725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
745c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    RenderBox* next()
755c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    {
765c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        do {
775c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            if (!m_currentChild) {
785c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                ++m_ordinalIteration;
795c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
805c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                if (!m_ordinalIteration)
815c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    m_currentOrdinal = m_forward ? 1 : m_largestOrdinal;
825c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                else {
8351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)                    if (static_cast<size_t>(m_ordinalIteration) >= m_ordinalValues.size() + 1)
845c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                        return 0;
855c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
865c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    // Only copy+sort the values once per layout even if the iterator is reset.
8751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)                    if (m_ordinalValues.size() != m_sortedOrdinalValues.size()) {
885c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                        copyToVector(m_ordinalValues, m_sortedOrdinalValues);
89197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch                        std::sort(m_sortedOrdinalValues.begin(), m_sortedOrdinalValues.end());
905c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    }
915c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    m_currentOrdinal = m_forward ? m_sortedOrdinalValues[m_ordinalIteration - 1] : m_sortedOrdinalValues[m_sortedOrdinalValues.size() - m_ordinalIteration];
925c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                }
935c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
945c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                m_currentChild = m_forward ? m_box->firstChildBox() : m_box->lastChildBox();
955c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            } else
965c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                m_currentChild = m_forward ? m_currentChild->nextSiblingBox() : m_currentChild->previousSiblingBox();
975c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
985c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            if (m_currentChild && notFirstOrdinalValue())
995c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                m_ordinalValues.add(m_currentChild->style()->boxOrdinalGroup());
1005c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        } while (!m_currentChild || (!m_currentChild->isAnonymous()
1015c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                 && m_currentChild->style()->boxOrdinalGroup() != m_currentOrdinal));
1025c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return m_currentChild;
1035c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
1045c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1055c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)private:
1065c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    bool notFirstOrdinalValue()
1075c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    {
1085c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        unsigned int firstOrdinalValue = m_forward ? 1 : m_largestOrdinal;
1095c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return m_currentOrdinal == firstOrdinalValue && m_currentChild->style()->boxOrdinalGroup() != firstOrdinalValue;
1105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
1115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    RenderDeprecatedFlexibleBox* m_box;
1135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    RenderBox* m_currentChild;
1145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    bool m_forward;
1155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    unsigned int m_currentOrdinal;
1165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    unsigned int m_largestOrdinal;
1175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    HashSet<unsigned int> m_ordinalValues;
1185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    Vector<unsigned int> m_sortedOrdinalValues;
1195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    int m_ordinalIteration;
1205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)};
1215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
122c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)RenderDeprecatedFlexibleBox::RenderDeprecatedFlexibleBox(Element& element)
123c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)    : RenderBlock(&element)
1245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
125197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    ASSERT(!childrenInline());
1265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    m_stretchingChildren = false;
127926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    if (!isAnonymous()) {
1288abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)        const KURL& url = document().url();
129926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)        if (url.protocolIs("chrome"))
1301e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)            UseCounter::count(document(), UseCounter::DeprecatedFlexboxChrome);
131926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)        else if (url.protocolIs("chrome-extension"))
1321e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)            UseCounter::count(document(), UseCounter::DeprecatedFlexboxChromeExtension);
133926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)        else
1341e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)            UseCounter::count(document(), UseCounter::DeprecatedFlexboxWebContent);
135926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    }
1365c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
1375c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1385c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)RenderDeprecatedFlexibleBox::~RenderDeprecatedFlexibleBox()
1395c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
1405c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
1415c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1425c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)static LayoutUnit marginWidthForChild(RenderBox* child)
1435c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
1445c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // A margin basically has three types: fixed, percentage, and auto (variable).
1455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // Auto and percentage margins simply become 0 when computing min/max width.
1465c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // Fixed margins can be added in as is.
1475c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    Length marginLeft = child->style()->marginLeft();
1485c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    Length marginRight = child->style()->marginRight();
1495c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    LayoutUnit margin = 0;
1505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (marginLeft.isFixed())
1515c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        margin += marginLeft.value();
1525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (marginRight.isFixed())
1535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        margin += marginRight.value();
1545c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return margin;
1555c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
1565c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1575c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)static bool childDoesNotAffectWidthOrFlexing(RenderObject* child)
1585c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
1595c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // Positioned children and collapsed children don't affect the min/max width.
1605c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return child->isOutOfFlowPositioned() || child->style()->visibility() == COLLAPSE;
1615c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
1625c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1635c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)static LayoutUnit contentWidthForChild(RenderBox* child)
1645c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
1655c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (child->hasOverrideWidth())
1665c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return child->overrideLogicalContentWidth();
1675c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return child->logicalWidth() - child->borderAndPaddingLogicalWidth();
1685c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
1695c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1705c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)static LayoutUnit contentHeightForChild(RenderBox* child)
1715c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
1725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (child->hasOverrideHeight())
1735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return child->overrideLogicalContentHeight();
1745c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return child->logicalHeight() - child->borderAndPaddingLogicalHeight();
1755c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
1765c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
177aafa69cb17c9d6606c07663ade5f81388a2c5986Ben Murdochvoid RenderDeprecatedFlexibleBox::styleWillChange(StyleDifference diff, const RenderStyle& newStyle)
1785c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
1795c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    RenderStyle* oldStyle = style();
180aafa69cb17c9d6606c07663ade5f81388a2c5986Ben Murdoch    if (oldStyle && !oldStyle->lineClamp().isNone() && newStyle.lineClamp().isNone())
1815c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        clearLineClamp();
1825c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1835c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    RenderBlock::styleWillChange(diff, newStyle);
1845c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
1855c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
186926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)void RenderDeprecatedFlexibleBox::computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const
1875c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
188926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    if (hasMultipleLines() || isVertical()) {
189926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)        for (RenderBox* child = firstChildBox(); child; child = child->nextSiblingBox()) {
190926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)            if (childDoesNotAffectWidthOrFlexing(child))
191926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)                continue;
1925c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
193926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)            LayoutUnit margin = marginWidthForChild(child);
194926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)            LayoutUnit width = child->minPreferredLogicalWidth() + margin;
195197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch            minLogicalWidth = std::max(width, minLogicalWidth);
1965c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
197926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)            width = child->maxPreferredLogicalWidth() + margin;
198197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch            maxLogicalWidth = std::max(width, maxLogicalWidth);
199926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)        }
200926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    } else {
201926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)        for (RenderBox* child = firstChildBox(); child; child = child->nextSiblingBox()) {
202926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)            if (childDoesNotAffectWidthOrFlexing(child))
203926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)                continue;
2045c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
205926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)            LayoutUnit margin = marginWidthForChild(child);
206926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)            minLogicalWidth += child->minPreferredLogicalWidth() + margin;
207926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)            maxLogicalWidth += child->maxPreferredLogicalWidth() + margin;
208926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)        }
2095c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
210926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
211197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    maxLogicalWidth = std::max(minLogicalWidth, maxLogicalWidth);
212926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
213926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    LayoutUnit scrollbarWidth = instrinsicScrollbarLogicalWidth();
214926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    maxLogicalWidth += scrollbarWidth;
215926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    minLogicalWidth += scrollbarWidth;
2165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
2175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void RenderDeprecatedFlexibleBox::computePreferredLogicalWidths()
2195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
2205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    ASSERT(preferredLogicalWidthsDirty());
2215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
222926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth = 0;
22310f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch    RenderStyle* styleToUse = style();
22410f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch
22510f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch    if (styleToUse->width().isFixed() && styleToUse->width().value() > 0)
22610f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch        m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth = adjustContentBoxLogicalWidthForBoxSizing(styleToUse->width().value());
227926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    else
228926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)        computeIntrinsicLogicalWidths(m_minPreferredLogicalWidth, m_maxPreferredLogicalWidth);
2295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
23010f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch    if (styleToUse->minWidth().isFixed() && styleToUse->minWidth().value() > 0) {
231197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch        m_maxPreferredLogicalWidth = std::max(m_maxPreferredLogicalWidth, adjustContentBoxLogicalWidthForBoxSizing(styleToUse->minWidth().value()));
232197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch        m_minPreferredLogicalWidth = std::max(m_minPreferredLogicalWidth, adjustContentBoxLogicalWidthForBoxSizing(styleToUse->minWidth().value()));
2335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
2345c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
23510f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch    if (styleToUse->maxWidth().isFixed()) {
236197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch        m_maxPreferredLogicalWidth = std::min(m_maxPreferredLogicalWidth, adjustContentBoxLogicalWidthForBoxSizing(styleToUse->maxWidth().value()));
237197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch        m_minPreferredLogicalWidth = std::min(m_minPreferredLogicalWidth, adjustContentBoxLogicalWidthForBoxSizing(styleToUse->maxWidth().value()));
2385c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
2395c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2405c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    LayoutUnit borderAndPadding = borderAndPaddingLogicalWidth();
2415c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    m_minPreferredLogicalWidth += borderAndPadding;
2425c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    m_maxPreferredLogicalWidth += borderAndPadding;
2435c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
244c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles)    clearPreferredLogicalWidthsDirty();
2455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
2465c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
24709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)void RenderDeprecatedFlexibleBox::layoutBlock(bool relayoutChildren)
2485c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
2495c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    ASSERT(needsLayout());
2505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2515c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (!relayoutChildren && simplifiedLayout())
2525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return;
2535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
25407a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    {
2559e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)        // LayoutState needs this deliberate scope to pop before paint invalidation.
2565d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)        LayoutState state(*this, locationOffset());
2575c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
25807a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch        LayoutSize previousSize = size();
2595c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
26007a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch        updateLogicalWidth();
26107a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch        updateLogicalHeight();
2625c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
263c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)        TextAutosizer::LayoutScope textAutosizerLayoutScope(this);
2645d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)
26507a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch        if (previousSize != size()
26607a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch            || (parent()->isDeprecatedFlexibleBox() && parent()->style()->boxOrient() == HORIZONTAL
26707a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch            && parent()->style()->boxAlign() == BSTRETCH))
26807a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch            relayoutChildren = true;
2695c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
27007a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch        setHeight(0);
2715c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
27207a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch        m_stretchingChildren = false;
2735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
27407a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch        if (isHorizontal())
27507a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch            layoutHorizontalBox(relayoutChildren);
27607a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch        else
27707a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch            layoutVerticalBox(relayoutChildren);
2785c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
27907a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch        LayoutUnit oldClientAfterEdge = clientLogicalBottom();
28007a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch        updateLogicalHeight();
2815c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
28207a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch        if (previousSize.height() != height())
28307a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch            relayoutChildren = true;
2845c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2856f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch        layoutPositionedObjects(relayoutChildren || isDocumentElement());
2865c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
28707a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch        computeOverflow(oldClientAfterEdge);
28807a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    }
2895c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
29076c265b59aa821ccbf8c75ab2bb0d036e97d2956Torne (Richard Coles)    updateLayerTransformAfterLayout();
2915c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2925c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (view()->layoutState()->pageLogicalHeight())
293d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        setPageLogicalOffset(view()->layoutState()->pageLogicalOffset(*this, logicalTop()));
2945c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2955c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // Update our scrollbars if we're overflow:auto/scroll/hidden now that we know if
2965c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // we overflow or not.
2975c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (hasOverflowClip())
298f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)        layer()->scrollableArea()->updateAfterLayout();
2995c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
3003c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch    clearNeedsLayout();
3015c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
3025c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
3035c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// The first walk over our kids is to find out if we have any flexible children.
3045c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)static void gatherFlexChildrenInfo(FlexBoxIterator& iterator, bool relayoutChildren, unsigned int& highestFlexGroup, unsigned int& lowestFlexGroup, bool& haveFlex)
3055c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
3065c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    for (RenderBox* child = iterator.first(); child; child = iterator.next()) {
3075c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        // Check to see if this child flexes.
3085c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        if (!childDoesNotAffectWidthOrFlexing(child) && child->style()->boxFlex() > 0.0f) {
3095c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            // We always have to lay out flexible objects again, since the flex distribution
3105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            // may have changed, and we need to reallocate space.
3115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            child->clearOverrideSize();
3125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            if (!relayoutChildren)
3133c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch                child->setChildNeedsLayout(MarkOnlyThis);
3145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            haveFlex = true;
3155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            unsigned int flexGroup = child->style()->boxFlexGroup();
3165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            if (lowestFlexGroup == 0)
3175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                lowestFlexGroup = flexGroup;
3185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            if (flexGroup < lowestFlexGroup)
3195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                lowestFlexGroup = flexGroup;
3205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            if (flexGroup > highestFlexGroup)
3215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                highestFlexGroup = flexGroup;
3225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        }
3235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
3245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
3255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
3265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void RenderDeprecatedFlexibleBox::layoutHorizontalBox(bool relayoutChildren)
3275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
3285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    LayoutUnit toAdd = borderBottom() + paddingBottom() + horizontalScrollbarHeight();
3295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    LayoutUnit yPos = borderTop() + paddingTop();
3305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    LayoutUnit xPos = borderLeft() + paddingLeft();
3315c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    bool heightSpecified = false;
3325c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    LayoutUnit oldHeight = 0;
3335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
3345c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    LayoutUnit remainingSpace = 0;
3355c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
3365c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
3375c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    FlexBoxIterator iterator(this);
3385c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    unsigned int highestFlexGroup = 0;
3395c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    unsigned int lowestFlexGroup = 0;
3405c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    bool haveFlex = false, flexingChildren = false;
3415c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    gatherFlexChildrenInfo(iterator, relayoutChildren, highestFlexGroup, lowestFlexGroup, haveFlex);
3425c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
3435c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    RenderBlock::startDelayUpdateScrollInfo();
3445c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
3455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // We do 2 passes.  The first pass is simply to lay everyone out at
3465c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // their preferred widths.  The second pass handles flexing the children.
3475c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    do {
3485c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        // Reset our height.
3495c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        setHeight(yPos);
3505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
3515c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        xPos = borderLeft() + paddingLeft();
3525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
3535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        // Our first pass is done without flexing.  We simply lay the children
3545c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        // out within the box.  We have to do a layout first in order to determine
3555c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        // our box's intrinsic height.
3565c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        LayoutUnit maxAscent = 0, maxDescent = 0;
3575c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        for (RenderBox* child = iterator.first(); child; child = iterator.next()) {
3585c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            if (child->isOutOfFlowPositioned())
3595c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                continue;
3605c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
36110f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch            SubtreeLayoutScope layoutScope(*child);
362e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)            if (relayoutChildren || (child->isReplaced() && (child->style()->width().isPercent() || child->style()->height().isPercent())))
363e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)                layoutScope.setChildNeedsLayout(child);
364e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)
3655c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            // Compute the child's vertical margins.
3665c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            child->computeAndSetBlockDirectionMargins(this);
3675c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
3685c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            if (!child->needsLayout())
369e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)                child->markForPaginationRelayoutIfNeeded(layoutScope);
3705c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
3715c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            // Now do the layout.
3725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            child->layoutIfNeeded();
3735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
3745c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            // Update our height and overflow height.
3755c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            if (style()->boxAlign() == BBASELINE) {
3765c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                LayoutUnit ascent = child->firstLineBoxBaseline();
3775c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                if (ascent == -1)
3785c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    ascent = child->height() + child->marginBottom();
3795c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                ascent += child->marginTop();
3805c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                LayoutUnit descent = (child->height() + child->marginHeight()) - ascent;
3815c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
3825c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                // Update our maximum ascent.
383197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch                maxAscent = std::max(maxAscent, ascent);
3845c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
3855c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                // Update our maximum descent.
386197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch                maxDescent = std::max(maxDescent, descent);
3875c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
3885c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                // Now update our height.
389197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch                setHeight(std::max(yPos + maxAscent + maxDescent, height()));
390197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch            } else {
391197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch                setHeight(std::max(height(), yPos + child->height() + child->marginHeight()));
3925c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            }
3935c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        }
3945c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
3955c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        if (!iterator.first() && hasLineIfEmpty())
3965c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            setHeight(height() + lineHeight(true, style()->isHorizontalWritingMode() ? HorizontalLine : VerticalLine, PositionOfInteriorLineBoxes));
3975c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
3985c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        setHeight(height() + toAdd);
3995c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
4005c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        oldHeight = height();
4015c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        updateLogicalHeight();
4025c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
4035c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        relayoutChildren = false;
4045c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        if (oldHeight != height())
4055c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            heightSpecified = true;
4065c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
4075c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        // Now that our height is actually known, we can place our boxes.
4085c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        m_stretchingChildren = (style()->boxAlign() == BSTRETCH);
4095c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        for (RenderBox* child = iterator.first(); child; child = iterator.next()) {
4105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            if (child->isOutOfFlowPositioned()) {
4115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                child->containingBlock()->insertPositionedObject(child);
4125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                RenderLayer* childLayer = child->layer();
41309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)                childLayer->setStaticInlinePosition(xPos);
4145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                if (childLayer->staticBlockPosition() != yPos) {
4155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    childLayer->setStaticBlockPosition(yPos);
4165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    if (child->style()->hasStaticBlockPosition(style()->isHorizontalWritingMode()))
4173c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch                        child->setChildNeedsLayout(MarkOnlyThis);
4185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                }
4195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                continue;
4205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            }
42102772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch
4225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            if (child->style()->visibility() == COLLAPSE) {
4235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                // visibility: collapsed children do not participate in our positioning.
4245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                // But we need to lay them down.
4255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                child->layoutIfNeeded();
4265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                continue;
4275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            }
4285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
42910f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch            SubtreeLayoutScope layoutScope(*child);
4305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
4315c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            // We need to see if this child's height has changed, since we make block elements
4325c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            // fill the height of a containing box by default.
4335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            // Now do a layout.
4345c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            LayoutUnit oldChildHeight = child->height();
4355c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            child->updateLogicalHeight();
4365c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            if (oldChildHeight != child->height())
437e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)                layoutScope.setChildNeedsLayout(child);
4385c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
4395c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            if (!child->needsLayout())
440e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)                child->markForPaginationRelayoutIfNeeded(layoutScope);
4415c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
4425c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            child->layoutIfNeeded();
4435c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
4445c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            // We can place the child now, using our value of box-align.
4455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            xPos += child->marginLeft();
4465c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            LayoutUnit childY = yPos;
4475c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            switch (style()->boxAlign()) {
4485c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                case BCENTER:
449197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch                    childY += child->marginTop() + std::max<LayoutUnit>(0, (contentHeight() - (child->height() + child->marginHeight())) / 2);
4505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    break;
4515c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                case BBASELINE: {
4525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    LayoutUnit ascent = child->firstLineBoxBaseline();
4535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    if (ascent == -1)
4545c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                        ascent = child->height() + child->marginBottom();
4555c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    ascent += child->marginTop();
4565c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    childY += child->marginTop() + (maxAscent - ascent);
4575c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    break;
4585c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                }
4595c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                case BEND:
4605c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    childY += contentHeight() - child->marginBottom() - child->height();
4615c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    break;
4625c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                default: // BSTART
4635c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    childY += child->marginTop();
4645c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    break;
4655c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            }
4665c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
4675c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            placeChild(child, LayoutPoint(xPos, childY));
4685c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
4695c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            xPos += child->width() + child->marginRight();
4705c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        }
4715c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
4725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        remainingSpace = borderLeft() + paddingLeft() + contentWidth() - xPos;
4735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
4745c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        m_stretchingChildren = false;
4755c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        if (flexingChildren)
4765c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            haveFlex = false; // We're done.
4775c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        else if (haveFlex) {
4785c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            // We have some flexible objects.  See if we need to grow/shrink them at all.
4795c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            if (!remainingSpace)
4805c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                break;
4815c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
4825c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            // Allocate the remaining space among the flexible objects.  If we are trying to
4835c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            // grow, then we go from the lowest flex group to the highest flex group.  For shrinking,
4845c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            // we go from the highest flex group to the lowest group.
4855c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            bool expanding = remainingSpace > 0;
4865c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            unsigned int start = expanding ? lowestFlexGroup : highestFlexGroup;
4875c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            unsigned int end = expanding? highestFlexGroup : lowestFlexGroup;
48807a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch            for (unsigned i = start; i <= end && remainingSpace; i++) {
4895c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                // Always start off by assuming the group can get all the remaining space.
4905c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                LayoutUnit groupRemainingSpace = remainingSpace;
4915c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                do {
4925c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    // Flexing consists of multiple passes, since we have to change ratios every time an object hits its max/min-width
4935c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    // For a given pass, we always start off by computing the totalFlex of all objects that can grow/shrink at all, and
4945c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    // computing the allowed growth before an object hits its min/max width (and thus
4955c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    // forces a totalFlex recomputation).
4965c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    LayoutUnit groupRemainingSpaceAtBeginning = groupRemainingSpace;
4975c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    float totalFlex = 0.0f;
4985c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    for (RenderBox* child = iterator.first(); child; child = iterator.next()) {
4995c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                        if (allowedChildFlex(child, expanding, i))
5005c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                            totalFlex += child->style()->boxFlex();
5015c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    }
5025c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    LayoutUnit spaceAvailableThisPass = groupRemainingSpace;
5035c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    for (RenderBox* child = iterator.first(); child; child = iterator.next()) {
5045c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                        LayoutUnit allowedFlex = allowedChildFlex(child, expanding, i);
5055c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                        if (allowedFlex) {
5065c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                            LayoutUnit projectedFlex = (allowedFlex == LayoutUnit::max()) ? allowedFlex : LayoutUnit(allowedFlex * (totalFlex / child->style()->boxFlex()));
507197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch                            spaceAvailableThisPass = expanding ? std::min(spaceAvailableThisPass, projectedFlex) : std::max(spaceAvailableThisPass, projectedFlex);
5085c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                        }
5095c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    }
5105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
5115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    // The flex groups may not have any flexible objects this time around.
5125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    if (!spaceAvailableThisPass || totalFlex == 0.0f) {
5135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                        // If we just couldn't grow/shrink any more, then it's time to transition to the next flex group.
5145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                        groupRemainingSpace = 0;
5155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                        continue;
5165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    }
5175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
5185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    // Now distribute the space to objects.
5195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    for (RenderBox* child = iterator.first(); child && spaceAvailableThisPass && totalFlex; child = iterator.next()) {
5205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                        if (child->style()->visibility() == COLLAPSE)
5215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                            continue;
5225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
5235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                        if (allowedChildFlex(child, expanding, i)) {
5245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                            LayoutUnit spaceAdd = LayoutUnit(spaceAvailableThisPass * (child->style()->boxFlex() / totalFlex));
5255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                            if (spaceAdd) {
5265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                                child->setOverrideLogicalContentWidth(contentWidthForChild(child) + spaceAdd);
5275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                                flexingChildren = true;
5285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                                relayoutChildren = true;
5295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                            }
5305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
5315c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                            spaceAvailableThisPass -= spaceAdd;
5325c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                            remainingSpace -= spaceAdd;
5335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                            groupRemainingSpace -= spaceAdd;
5345c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
5355c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                            totalFlex -= child->style()->boxFlex();
5365c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                        }
5375c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    }
5385c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    if (groupRemainingSpace == groupRemainingSpaceAtBeginning) {
5395c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                        // This is not advancing, avoid getting stuck by distributing the remaining pixels.
5405c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                        LayoutUnit spaceAdd = groupRemainingSpace > 0 ? 1 : -1;
5415c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                        for (RenderBox* child = iterator.first(); child && groupRemainingSpace; child = iterator.next()) {
5425c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                            if (allowedChildFlex(child, expanding, i)) {
5435c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                                child->setOverrideLogicalContentWidth(contentWidthForChild(child) + spaceAdd);
5445c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                                flexingChildren = true;
5455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                                relayoutChildren = true;
5465c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                                remainingSpace -= spaceAdd;
5475c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                                groupRemainingSpace -= spaceAdd;
5485c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                            }
5495c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                        }
5505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    }
5515c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                } while (absoluteValue(groupRemainingSpace) >= 1);
5525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            }
5535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
5545c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            // We didn't find any children that could grow.
5555c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            if (haveFlex && !flexingChildren)
5565c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                haveFlex = false;
5575c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        }
5585c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    } while (haveFlex);
5595c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
5605c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    RenderBlock::finishDelayUpdateScrollInfo();
5615c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
5625c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (remainingSpace > 0 && ((style()->isLeftToRightDirection() && style()->boxPack() != Start)
5635c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        || (!style()->isLeftToRightDirection() && style()->boxPack() != End))) {
5645c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        // Children must be repositioned.
5655c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        LayoutUnit offset = 0;
5665c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        if (style()->boxPack() == Justify) {
5675c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            // Determine the total number of children.
5685c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            int totalChildren = 0;
5695c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            for (RenderBox* child = iterator.first(); child; child = iterator.next()) {
5705c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                if (childDoesNotAffectWidthOrFlexing(child))
5715c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    continue;
5725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                ++totalChildren;
5735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            }
5745c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
5755c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            // Iterate over the children and space them out according to the
5765c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            // justification level.
5775c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            if (totalChildren > 1) {
5785c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                --totalChildren;
5795c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                bool firstChild = true;
5805c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                for (RenderBox* child = iterator.first(); child; child = iterator.next()) {
5815c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    if (childDoesNotAffectWidthOrFlexing(child))
5825c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                        continue;
5835c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
5845c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    if (firstChild) {
5855c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                        firstChild = false;
5865c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                        continue;
5875c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    }
5885c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
5895c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    offset += remainingSpace/totalChildren;
5905c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    remainingSpace -= (remainingSpace/totalChildren);
5915c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    --totalChildren;
5925c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
5935c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    placeChild(child, child->location() + LayoutSize(offset, 0));
5945c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                }
5955c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            }
5965c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        } else {
5975c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            if (style()->boxPack() == Center)
5985c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                offset += remainingSpace / 2;
5995c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            else // END for LTR, START for RTL
6005c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                offset += remainingSpace;
6015c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            for (RenderBox* child = iterator.first(); child; child = iterator.next()) {
6025c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                if (childDoesNotAffectWidthOrFlexing(child))
6035c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    continue;
6045c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
6055c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                placeChild(child, child->location() + LayoutSize(offset, 0));
6065c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            }
6075c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        }
6085c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
6095c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
6105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // So that the computeLogicalHeight in layoutBlock() knows to relayout positioned objects because of
6115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // a height change, we revert our height back to the intrinsic height before returning.
6125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (heightSpecified)
6135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        setHeight(oldHeight);
6145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
6155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
6165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void RenderDeprecatedFlexibleBox::layoutVerticalBox(bool relayoutChildren)
6175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
6185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    LayoutUnit yPos = borderTop() + paddingTop();
6195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    LayoutUnit toAdd = borderBottom() + paddingBottom() + horizontalScrollbarHeight();
6205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    bool heightSpecified = false;
6215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    LayoutUnit oldHeight = 0;
6225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
6235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    LayoutUnit remainingSpace = 0;
6245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
6255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    FlexBoxIterator iterator(this);
6265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    unsigned int highestFlexGroup = 0;
6275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    unsigned int lowestFlexGroup = 0;
6285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    bool haveFlex = false, flexingChildren = false;
6295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    gatherFlexChildrenInfo(iterator, relayoutChildren, highestFlexGroup, lowestFlexGroup, haveFlex);
6305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
6315c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // We confine the line clamp ugliness to vertical flexible boxes (thus keeping it out of
6325c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // mainstream block layout); this is not really part of the XUL box model.
6335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    bool haveLineClamp = !style()->lineClamp().isNone();
6345c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (haveLineClamp)
6355c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        applyLineClamp(iterator, relayoutChildren);
6365c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
6375c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    RenderBlock::startDelayUpdateScrollInfo();
6385c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
6395c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // We do 2 passes.  The first pass is simply to lay everyone out at
6405c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // their preferred widths.  The second pass handles flexing the children.
6415c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // Our first pass is done without flexing.  We simply lay the children
6425c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // out within the box.
6435c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    do {
6445c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        setHeight(borderTop() + paddingTop());
6455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        LayoutUnit minHeight = height() + toAdd;
6465c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
6475c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        for (RenderBox* child = iterator.first(); child; child = iterator.next()) {
6485c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            if (child->isOutOfFlowPositioned()) {
6495c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                child->containingBlock()->insertPositionedObject(child);
6505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                RenderLayer* childLayer = child->layer();
65109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)                childLayer->setStaticInlinePosition(borderStart() + paddingStart());
6525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                if (childLayer->staticBlockPosition() != height()) {
6535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    childLayer->setStaticBlockPosition(height());
6545c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    if (child->style()->hasStaticBlockPosition(style()->isHorizontalWritingMode()))
6553c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch                        child->setChildNeedsLayout(MarkOnlyThis);
6565c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                }
6575c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                continue;
6585c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            }
65902772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch
66010f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch            SubtreeLayoutScope layoutScope(*child);
661e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)            if (!haveLineClamp && (relayoutChildren || (child->isReplaced() && (child->style()->width().isPercent() || child->style()->height().isPercent()))))
662e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)                layoutScope.setChildNeedsLayout(child);
663e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)
6645c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            if (child->style()->visibility() == COLLAPSE) {
6655c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                // visibility: collapsed children do not participate in our positioning.
6665c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                // But we need to lay them down.
6675c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                child->layoutIfNeeded();
6685c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                continue;
6695c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            }
6705c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
6715c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            // Compute the child's vertical margins.
6725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            child->computeAndSetBlockDirectionMargins(this);
6735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
6745c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            // Add in the child's marginTop to our height.
6755c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            setHeight(height() + child->marginTop());
6765c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
6775c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            if (!child->needsLayout())
678e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)                child->markForPaginationRelayoutIfNeeded(layoutScope);
6795c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
6805c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            // Now do a layout.
6815c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            child->layoutIfNeeded();
6825c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
6835c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            // We can place the child now, using our value of box-align.
6845c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            LayoutUnit childX = borderLeft() + paddingLeft();
6855c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            switch (style()->boxAlign()) {
6865c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                case BCENTER:
6875c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                case BBASELINE: // Baseline just maps to center for vertical boxes
688197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch                    childX += child->marginLeft() + std::max<LayoutUnit>(0, (contentWidth() - (child->width() + child->marginWidth())) / 2);
6895c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    break;
6905c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                case BEND:
6915c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    if (!style()->isLeftToRightDirection())
6925c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                        childX += child->marginLeft();
6935c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    else
6945c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                        childX += contentWidth() - child->marginRight() - child->width();
6955c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    break;
6965c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                default: // BSTART/BSTRETCH
6975c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    if (style()->isLeftToRightDirection())
6985c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                        childX += child->marginLeft();
6995c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    else
7005c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                        childX += contentWidth() - child->marginRight() - child->width();
7015c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    break;
7025c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            }
7035c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
7045c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            // Place the child.
7055c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            placeChild(child, LayoutPoint(childX, height()));
7065c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            setHeight(height() + child->height() + child->marginBottom());
7075c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        }
7085c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
7095c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        yPos = height();
7105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
7115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        if (!iterator.first() && hasLineIfEmpty())
7125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            setHeight(height() + lineHeight(true, style()->isHorizontalWritingMode() ? HorizontalLine : VerticalLine, PositionOfInteriorLineBoxes));
7135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
7145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        setHeight(height() + toAdd);
7155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
7165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        // Negative margins can cause our height to shrink below our minimal height (border/padding).
7175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        // If this happens, ensure that the computed height is increased to the minimal height.
7185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        if (height() < minHeight)
7195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            setHeight(minHeight);
7205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
7215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        // Now we have to calc our height, so we know how much space we have remaining.
7225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        oldHeight = height();
7235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        updateLogicalHeight();
7245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        if (oldHeight != height())
7255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            heightSpecified = true;
7265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
7275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        remainingSpace = borderTop() + paddingTop() + contentHeight() - yPos;
7285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
7295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        if (flexingChildren)
7305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            haveFlex = false; // We're done.
7315c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        else if (haveFlex) {
7325c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            // We have some flexible objects.  See if we need to grow/shrink them at all.
7335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            if (!remainingSpace)
7345c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                break;
7355c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
7365c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            // Allocate the remaining space among the flexible objects.  If we are trying to
7375c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            // grow, then we go from the lowest flex group to the highest flex group.  For shrinking,
7385c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            // we go from the highest flex group to the lowest group.
7395c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            bool expanding = remainingSpace > 0;
7405c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            unsigned int start = expanding ? lowestFlexGroup : highestFlexGroup;
7415c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            unsigned int end = expanding? highestFlexGroup : lowestFlexGroup;
74207a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch            for (unsigned i = start; i <= end && remainingSpace; i++) {
7435c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                // Always start off by assuming the group can get all the remaining space.
7445c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                LayoutUnit groupRemainingSpace = remainingSpace;
7455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                do {
7465c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    // Flexing consists of multiple passes, since we have to change ratios every time an object hits its max/min-width
7475c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    // For a given pass, we always start off by computing the totalFlex of all objects that can grow/shrink at all, and
7485c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    // computing the allowed growth before an object hits its min/max width (and thus
7495c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    // forces a totalFlex recomputation).
7505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    LayoutUnit groupRemainingSpaceAtBeginning = groupRemainingSpace;
7515c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    float totalFlex = 0.0f;
7525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    for (RenderBox* child = iterator.first(); child; child = iterator.next()) {
7535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                        if (allowedChildFlex(child, expanding, i))
7545c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                            totalFlex += child->style()->boxFlex();
7555c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    }
7565c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    LayoutUnit spaceAvailableThisPass = groupRemainingSpace;
7575c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    for (RenderBox* child = iterator.first(); child; child = iterator.next()) {
7585c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                        LayoutUnit allowedFlex = allowedChildFlex(child, expanding, i);
7595c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                        if (allowedFlex) {
7605c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                            LayoutUnit projectedFlex = (allowedFlex == LayoutUnit::max()) ? allowedFlex : static_cast<LayoutUnit>(allowedFlex * (totalFlex / child->style()->boxFlex()));
761197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch                            spaceAvailableThisPass = expanding ? std::min(spaceAvailableThisPass, projectedFlex) : std::max(spaceAvailableThisPass, projectedFlex);
7625c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                        }
7635c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    }
7645c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
7655c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    // The flex groups may not have any flexible objects this time around.
7665c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    if (!spaceAvailableThisPass || totalFlex == 0.0f) {
7675c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                        // If we just couldn't grow/shrink any more, then it's time to transition to the next flex group.
7685c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                        groupRemainingSpace = 0;
7695c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                        continue;
7705c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    }
7715c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
7725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    // Now distribute the space to objects.
7735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    for (RenderBox* child = iterator.first(); child && spaceAvailableThisPass && totalFlex; child = iterator.next()) {
7745c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                        if (allowedChildFlex(child, expanding, i)) {
7755c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                            LayoutUnit spaceAdd = static_cast<LayoutUnit>(spaceAvailableThisPass * (child->style()->boxFlex() / totalFlex));
7765c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                            if (spaceAdd) {
7775c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                                child->setOverrideLogicalContentHeight(contentHeightForChild(child) + spaceAdd);
7785c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                                flexingChildren = true;
7795c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                                relayoutChildren = true;
7805c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                            }
7815c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
7825c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                            spaceAvailableThisPass -= spaceAdd;
7835c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                            remainingSpace -= spaceAdd;
7845c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                            groupRemainingSpace -= spaceAdd;
7855c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
7865c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                            totalFlex -= child->style()->boxFlex();
7875c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                        }
7885c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    }
7895c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    if (groupRemainingSpace == groupRemainingSpaceAtBeginning) {
7905c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                        // This is not advancing, avoid getting stuck by distributing the remaining pixels.
7915c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                        LayoutUnit spaceAdd = groupRemainingSpace > 0 ? 1 : -1;
7925c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                        for (RenderBox* child = iterator.first(); child && groupRemainingSpace; child = iterator.next()) {
7935c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                            if (allowedChildFlex(child, expanding, i)) {
7945c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                                child->setOverrideLogicalContentHeight(contentHeightForChild(child) + spaceAdd);
7955c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                                flexingChildren = true;
7965c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                                relayoutChildren = true;
7975c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                                remainingSpace -= spaceAdd;
7985c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                                groupRemainingSpace -= spaceAdd;
7995c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                            }
8005c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                        }
8015c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    }
8025c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                } while (absoluteValue(groupRemainingSpace) >= 1);
8035c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            }
8045c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
8055c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            // We didn't find any children that could grow.
8065c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            if (haveFlex && !flexingChildren)
8075c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                haveFlex = false;
8085c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        }
8095c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    } while (haveFlex);
8105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
8115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    RenderBlock::finishDelayUpdateScrollInfo();
8125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
8135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (style()->boxPack() != Start && remainingSpace > 0) {
8145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        // Children must be repositioned.
8155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        LayoutUnit offset = 0;
8165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        if (style()->boxPack() == Justify) {
8175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            // Determine the total number of children.
8185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            int totalChildren = 0;
8195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            for (RenderBox* child = iterator.first(); child; child = iterator.next()) {
8205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                if (childDoesNotAffectWidthOrFlexing(child))
8215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    continue;
8225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
8235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                ++totalChildren;
8245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            }
8255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
8265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            // Iterate over the children and space them out according to the
8275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            // justification level.
8285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            if (totalChildren > 1) {
8295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                --totalChildren;
8305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                bool firstChild = true;
8315c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                for (RenderBox* child = iterator.first(); child; child = iterator.next()) {
8325c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    if (childDoesNotAffectWidthOrFlexing(child))
8335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                        continue;
8345c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
8355c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    if (firstChild) {
8365c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                        firstChild = false;
8375c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                        continue;
8385c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    }
8395c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
8405c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    offset += remainingSpace/totalChildren;
8415c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    remainingSpace -= (remainingSpace/totalChildren);
8425c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    --totalChildren;
8435c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    placeChild(child, child->location() + LayoutSize(0, offset));
8445c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                }
8455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            }
8465c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        } else {
8475c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            if (style()->boxPack() == Center)
8485c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                offset += remainingSpace / 2;
8495c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            else // END
8505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                offset += remainingSpace;
8515c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            for (RenderBox* child = iterator.first(); child; child = iterator.next()) {
8525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                if (childDoesNotAffectWidthOrFlexing(child))
8535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                    continue;
8545c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                placeChild(child, child->location() + LayoutSize(0, offset));
8555c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            }
8565c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        }
8575c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
8585c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
8595c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // So that the computeLogicalHeight in layoutBlock() knows to relayout positioned objects because of
8605c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // a height change, we revert our height back to the intrinsic height before returning.
8615c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (heightSpecified)
8625c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        setHeight(oldHeight);
8635c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
8645c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
8655c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void RenderDeprecatedFlexibleBox::applyLineClamp(FlexBoxIterator& iterator, bool relayoutChildren)
8665c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
8671e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    UseCounter::count(document(), UseCounter::LineClamp);
868f5e4ad553afbc08dd2e729bb77e937a9a94d5827Torne (Richard Coles)
8695c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    int maxLineCount = 0;
8705c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    for (RenderBox* child = iterator.first(); child; child = iterator.next()) {
8715c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        if (childDoesNotAffectWidthOrFlexing(child))
8725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            continue;
8735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
8745c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        child->clearOverrideSize();
8755c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        if (relayoutChildren || (child->isReplaced() && (child->style()->width().isPercent() || child->style()->height().isPercent()))
8768abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)            || (child->style()->height().isAuto() && child->isRenderBlock())) {
8773c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch            child->setChildNeedsLayout(MarkOnlyThis);
8785c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
8795c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            // Dirty all the positioned objects.
8805c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            if (child->isRenderBlock()) {
8815c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                toRenderBlock(child)->markPositionedObjectsForLayout();
8825c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                toRenderBlock(child)->clearTruncation();
8835c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            }
8845c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        }
8855c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        child->layoutIfNeeded();
8868abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)        if (child->style()->height().isAuto() && child->isRenderBlock())
887197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch            maxLineCount = std::max(maxLineCount, toRenderBlock(child)->lineCount());
8885c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
8895c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
8905c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // Get the number of lines and then alter all block flow children with auto height to use the
8915c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // specified height. We always try to leave room for at least one line.
8925c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    LineClampValue lineClamp = style()->lineClamp();
893197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    int numVisibleLines = lineClamp.isPercentage() ? std::max(1, (maxLineCount + 1) * lineClamp.value() / 100) : lineClamp.value();
8945c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (numVisibleLines >= maxLineCount)
8955c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return;
8965c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
8975c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    for (RenderBox* child = iterator.first(); child; child = iterator.next()) {
8988abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)        if (childDoesNotAffectWidthOrFlexing(child) || !child->style()->height().isAuto() || !child->isRenderBlock())
8995c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            continue;
9005c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
9015c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        RenderBlock* blockChild = toRenderBlock(child);
9025c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        int lineCount = blockChild->lineCount();
9035c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        if (lineCount <= numVisibleLines)
9045c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            continue;
9055c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
9065c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        LayoutUnit newHeight = blockChild->heightForLineCount(numVisibleLines);
9075c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        if (newHeight == child->height())
9085c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            continue;
9095c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
9105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        child->setOverrideLogicalContentHeight(newHeight - child->borderAndPaddingHeight());
911f5e4ad553afbc08dd2e729bb77e937a9a94d5827Torne (Richard Coles)        child->forceChildLayout();
9125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
9135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        // FIXME: For now don't support RTL.
9145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        if (style()->direction() != LTR)
9155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            continue;
9165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
9175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        // Get the last line
9185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        RootInlineBox* lastLine = blockChild->lineAtIndex(lineCount - 1);
9195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        if (!lastLine)
9205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            continue;
9215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
9225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        RootInlineBox* lastVisibleLine = blockChild->lineAtIndex(numVisibleLines - 1);
9235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        if (!lastVisibleLine)
9245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            continue;
9255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
9265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        const UChar ellipsisAndSpace[2] = { horizontalEllipsis, ' ' };
9275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        DEFINE_STATIC_LOCAL(AtomicString, ellipsisAndSpaceStr, (ellipsisAndSpace, 2));
9285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        DEFINE_STATIC_LOCAL(AtomicString, ellipsisStr, (&horizontalEllipsis, 1));
9295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        const Font& font = style(numVisibleLines == 1)->font();
9305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
9315c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        // Get ellipsis width, and if the last child is an anchor, it will go after the ellipsis, so add in a space and the anchor width too
932d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        float totalWidth;
9335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        InlineBox* anchorBox = lastLine->lastChild();
934d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        if (anchorBox && anchorBox->renderer().style()->isLink())
935c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)            totalWidth = anchorBox->logicalWidth() + font.width(constructTextRun(this, font, ellipsisAndSpace, 2, style(), style()->direction()));
9365c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        else {
9375c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            anchorBox = 0;
938c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)            totalWidth = font.width(constructTextRun(this, font, &horizontalEllipsis, 1, style(), style()->direction()));
9395c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        }
9405c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
9415c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        // See if this width can be accommodated on the last visible line
942d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        RenderBlockFlow& destBlock = lastVisibleLine->block();
943d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        RenderBlockFlow& srcBlock = lastLine->block();
9445c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
9455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        // FIXME: Directions of src/destBlock could be different from our direction and from one another.
946d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        if (!srcBlock.style()->isLeftToRightDirection())
9475c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            continue;
9485c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
949d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        bool leftToRight = destBlock.style()->isLeftToRightDirection();
9505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        if (!leftToRight)
9515c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            continue;
9525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
953d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        LayoutUnit blockRightEdge = destBlock.logicalRightOffsetForLine(lastVisibleLine->y(), false);
9545c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        if (!lastVisibleLine->lineCanAccommodateEllipsis(leftToRight, blockRightEdge, lastVisibleLine->x() + lastVisibleLine->logicalWidth(), totalWidth))
9555c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            continue;
9565c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
9575c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        // Let the truncation code kick in.
9585c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        // FIXME: the text alignment should be recomputed after the width changes due to truncation.
959d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        LayoutUnit blockLeftEdge = destBlock.logicalLeftOffsetForLine(lastVisibleLine->y(), false);
960d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        lastVisibleLine->placeEllipsis(anchorBox ? ellipsisAndSpaceStr : ellipsisStr, leftToRight, blockLeftEdge.toFloat(), blockRightEdge.toFloat(), totalWidth, anchorBox);
961d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        destBlock.setHasMarkupTruncation(true);
9625c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
9635c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
9645c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
9655c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void RenderDeprecatedFlexibleBox::clearLineClamp()
9665c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
9675c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    FlexBoxIterator iterator(this);
9685c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    for (RenderBox* child = iterator.first(); child; child = iterator.next()) {
9695c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        if (childDoesNotAffectWidthOrFlexing(child))
9705c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            continue;
9715c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
9725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        child->clearOverrideSize();
9735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        if ((child->isReplaced() && (child->style()->width().isPercent() || child->style()->height().isPercent()))
9748abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)            || (child->style()->height().isAuto() && child->isRenderBlock())) {
9753c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch            child->setChildNeedsLayout();
9765c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
9775c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            if (child->isRenderBlock()) {
9785c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                toRenderBlock(child)->markPositionedObjectsForLayout();
9795c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                toRenderBlock(child)->clearTruncation();
9805c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            }
9815c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        }
9825c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
9835c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
9845c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
9855c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void RenderDeprecatedFlexibleBox::placeChild(RenderBox* child, const LayoutPoint& location)
9865c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
987323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)    // FIXME Investigate if this can be removed based on other flags. crbug.com/370010
988f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    child->setMayNeedPaintInvalidation(true);
989323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)
9905c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // Place the child.
9915c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    child->setLocation(location);
9925c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
9935c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
9945c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)LayoutUnit RenderDeprecatedFlexibleBox::allowedChildFlex(RenderBox* child, bool expanding, unsigned int group)
9955c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
9965c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (childDoesNotAffectWidthOrFlexing(child) || child->style()->boxFlex() == 0.0f || child->style()->boxFlexGroup() != group)
9975c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return 0;
9985c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
9995c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (expanding) {
10005c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        if (isHorizontal()) {
10015c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            // FIXME: For now just handle fixed values.
10025c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            LayoutUnit maxWidth = LayoutUnit::max();
10035c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            LayoutUnit width = contentWidthForChild(child);
10049e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)            if (child->style()->maxWidth().isFixed())
10055c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                maxWidth = child->style()->maxWidth().value();
10065c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            else if (child->style()->maxWidth().type() == Intrinsic)
10075c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                maxWidth = child->maxPreferredLogicalWidth();
10085c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            else if (child->style()->maxWidth().type() == MinIntrinsic)
10095c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                maxWidth = child->minPreferredLogicalWidth();
10105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            if (maxWidth == LayoutUnit::max())
10115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                return maxWidth;
1012197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch            return std::max<LayoutUnit>(0, maxWidth - width);
10135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        } else {
10145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            // FIXME: For now just handle fixed values.
10155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            LayoutUnit maxHeight = LayoutUnit::max();
10165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            LayoutUnit height = contentHeightForChild(child);
10179e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)            if (child->style()->maxHeight().isFixed())
10185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                maxHeight = child->style()->maxHeight().value();
10195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            if (maxHeight == LayoutUnit::max())
10205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)                return maxHeight;
1021197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch            return std::max<LayoutUnit>(0, maxHeight - height);
10225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        }
10235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
10245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
10255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // FIXME: For now just handle fixed values.
10265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (isHorizontal()) {
10275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        LayoutUnit minWidth = child->minPreferredLogicalWidth();
10285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        LayoutUnit width = contentWidthForChild(child);
10295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        if (child->style()->minWidth().isFixed())
10305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            minWidth = child->style()->minWidth().value();
10315c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        else if (child->style()->minWidth().type() == Intrinsic)
10325c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            minWidth = child->maxPreferredLogicalWidth();
10335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        else if (child->style()->minWidth().type() == MinIntrinsic)
10345c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            minWidth = child->minPreferredLogicalWidth();
10355c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        else if (child->style()->minWidth().type() == Auto)
10365c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            minWidth = 0;
10375c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1038197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch        LayoutUnit allowedShrinkage = std::min<LayoutUnit>(0, minWidth - width);
10395c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return allowedShrinkage;
10405c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    } else {
10415c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        Length minHeight = child->style()->minHeight();
10425c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        if (minHeight.isFixed() || minHeight.isAuto()) {
10435c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            LayoutUnit minHeight = child->style()->minHeight().value();
10445c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            LayoutUnit height = contentHeightForChild(child);
1045197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch            LayoutUnit allowedShrinkage = std::min<LayoutUnit>(0, minHeight - height);
10465c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            return allowedShrinkage;
10475c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        }
10485c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
10495c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
10505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return 0;
10515c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
10525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1053926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)const char* RenderDeprecatedFlexibleBox::renderName() const
10545c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
10555c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (isFloating())
10565c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return "RenderDeprecatedFlexibleBox (floating)";
10575c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (isOutOfFlowPositioned())
10585c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return "RenderDeprecatedFlexibleBox (positioned)";
10597242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    // FIXME: Cleanup isPseudoElement duplication with other renderName methods.
10607242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    // crbug.com/415653
10617242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    if (isPseudoElement()) {
10627242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci        if (style()->styleType() == BEFORE)
10637242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci            return "RenderDeprecatedFlexibleBox (pseudo:before)";
10647242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci        if (style()->styleType() == AFTER)
10657242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci            return "RenderDeprecatedFlexibleBox (pseudo:after)";
10667242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci        if (style()->styleType() == BACKDROP)
10677242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci            return "RenderDeprecatedFlexibleBox (pseudo:backdrop)";
10687242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci        ASSERT_NOT_REACHED();
10697242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    }
10705c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (isAnonymous())
10715c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return "RenderDeprecatedFlexibleBox (generated)";
10725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (isRelPositioned())
10735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return "RenderDeprecatedFlexibleBox (relative positioned)";
10745c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return "RenderDeprecatedFlexibleBox";
10755c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
10765c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1077c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)} // namespace blink
1078