18e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project/* 28e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * This file is part of the render object implementation for KHTML. 38e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * 48e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 58e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * (C) 1999 Antti Koivisto (koivisto@kde.org) 68e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * Copyright (C) 2003 Apple Computer, Inc. 78e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * 88e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * This library is free software; you can redistribute it and/or 98e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * modify it under the terms of the GNU Library General Public 108e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * License as published by the Free Software Foundation; either 118e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * version 2 of the License, or (at your option) any later version. 128e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * 138e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * This library is distributed in the hope that it will be useful, 148e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * but WITHOUT ANY WARRANTY; without even the implied warranty of 158e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 168e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * Library General Public License for more details. 178e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * 188e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * You should have received a copy of the GNU Library General Public License 198e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * along with this library; see the file COPYING.LIB. If not, write to 208e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 218e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * Boston, MA 02110-1301, USA. 228e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * 238e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project */ 248e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 258e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include "config.h" 268e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include "RenderFlexibleBox.h" 278e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 288e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include "RenderLayer.h" 298e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include "RenderView.h" 30ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch#include "TextRun.h" 31635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project#include <wtf/StdLibExtras.h> 322fc2651226baac27029e38c9d6ef883fa32084dbSteve Block#include <wtf/unicode/CharacterNames.h> 338e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 348e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#ifdef ANDROID_LAYOUT 358e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include "Document.h" 368e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include "Settings.h" 378e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#endif 388e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 398e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectusing namespace std; 408e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 418e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectnamespace WebCore { 428e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 438e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectclass FlexBoxIterator { 448e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectpublic: 450bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch FlexBoxIterator(RenderFlexibleBox* parent) 46f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block : m_box(parent) 47f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block , m_lastOrdinal(1) 480bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch { 49f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block if (m_box->style()->boxOrient() == HORIZONTAL && !m_box->style()->isLeftToRightDirection()) 50f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block m_forward = m_box->style()->boxDirection() != BNORMAL; 518e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project else 52f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block m_forward = m_box->style()->boxDirection() == BNORMAL; 53f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block if (!m_forward) { 548e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // No choice, since we're going backwards, we have to find out the highest ordinal up front. 55f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block RenderBox* child = m_box->firstChildBox(); 568e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project while (child) { 57f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block if (child->style()->boxOrdinalGroup() > m_lastOrdinal) 58f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block m_lastOrdinal = child->style()->boxOrdinalGroup(); 59635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project child = child->nextSiblingBox(); 608e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 618e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 62f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block 638e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project reset(); 648e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 658e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 660bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch void reset() 670bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch { 68f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block m_currentChild = 0; 69f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block m_currentOrdinal = m_forward ? 0 : m_lastOrdinal + 1; 708e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 718e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 720bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch RenderBox* first() 730bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch { 748e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project reset(); 758e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project return next(); 768e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 77f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block 780bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch RenderBox* next() 790bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch { 80f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block do { 81f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block if (!m_currentChild) { 82f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block if (m_forward) { 83f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block ++m_currentOrdinal; 84f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block if (m_currentOrdinal > m_lastOrdinal) 858e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project return 0; 86f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block m_currentChild = m_box->firstChildBox(); 878e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } else { 88f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block --m_currentOrdinal; 89f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block if (!m_currentOrdinal) 908e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project return 0; 91f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block m_currentChild = m_box->lastChildBox(); 928e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 938e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 948e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project else 95f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block m_currentChild = m_forward ? m_currentChild->nextSiblingBox() : m_currentChild->previousSiblingBox(); 96f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block if (m_currentChild && m_currentChild->style()->boxOrdinalGroup() > m_lastOrdinal) 97f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block m_lastOrdinal = m_currentChild->style()->boxOrdinalGroup(); 98d7957e4817d6aa730d583fb56e2556bb4e626fb0Steve Block } while (!m_currentChild || (!m_currentChild->isAnonymous() 99d7957e4817d6aa730d583fb56e2556bb4e626fb0Steve Block && (m_currentChild->style()->boxOrdinalGroup() != m_currentOrdinal || m_currentChild->style()->visibility() == COLLAPSE))); 100f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block return m_currentChild; 1018e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 1028e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 1038e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectprivate: 104f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block RenderFlexibleBox* m_box; 105f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block RenderBox* m_currentChild; 106f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block bool m_forward; 107f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block unsigned int m_currentOrdinal; 108f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block unsigned int m_lastOrdinal; 1098e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}; 110f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block 1118e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source ProjectRenderFlexibleBox::RenderFlexibleBox(Node* node) 112f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block : RenderBlock(node) 1138e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{ 1148e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project setChildrenInline(false); // All of our children must be block-level 1158e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project m_flexingChildren = m_stretchingChildren = false; 1168e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project} 1178e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 1188e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source ProjectRenderFlexibleBox::~RenderFlexibleBox() 1198e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{ 1208e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project} 1218e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 122f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Blockstatic int marginWidthForChild(RenderBox* child) 123f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block{ 124f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block // A margin basically has three types: fixed, percentage, and auto (variable). 125f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block // Auto and percentage margins simply become 0 when computing min/max width. 126f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block // Fixed margins can be added in as is. 127f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block Length marginLeft = child->style()->marginLeft(); 128f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block Length marginRight = child->style()->marginRight(); 129f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block int margin = 0; 130f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block if (marginLeft.isFixed()) 131f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block margin += marginLeft.value(); 132f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block if (marginRight.isFixed()) 133f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block margin += marginRight.value(); 134f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block return margin; 135f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block} 136f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block 1378e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectvoid RenderFlexibleBox::calcHorizontalPrefWidths() 1388e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{ 139635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project for (RenderBox* child = firstChildBox(); child; child = child->nextSiblingBox()) { 140f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block // Positioned children and collapsed children don't affect the min/max width. 141635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project if (child->isPositioned() || child->style()->visibility() == COLLAPSE) 1428e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project continue; 1438e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 144f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block int margin = marginWidthForChild(child); 145bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen m_minPreferredLogicalWidth += child->minPreferredLogicalWidth() + margin; 146bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen m_maxPreferredLogicalWidth += child->maxPreferredLogicalWidth() + margin; 147f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block } 1488e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project} 1498e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 1508e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectvoid RenderFlexibleBox::calcVerticalPrefWidths() 1518e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{ 152635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project for (RenderBox* child = firstChildBox(); child; child = child->nextSiblingBox()) { 153f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block // Positioned children and collapsed children don't affect the min/max width. 154635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project if (child->isPositioned() || child->style()->visibility() == COLLAPSE) 1558e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project continue; 1568e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 157f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block int margin = marginWidthForChild(child); 158f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block int width = child->minPreferredLogicalWidth() + margin; 159f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block m_minPreferredLogicalWidth = max(width, m_minPreferredLogicalWidth); 160f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block 161f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block width = child->maxPreferredLogicalWidth() + margin; 162f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block m_maxPreferredLogicalWidth = max(width, m_maxPreferredLogicalWidth); 163f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block } 1648e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project} 1658e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 166bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsenvoid RenderFlexibleBox::computePreferredLogicalWidths() 1678e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{ 168bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen ASSERT(preferredLogicalWidthsDirty()); 1698e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 1708e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (style()->width().isFixed() && style()->width().value() > 0) 171bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth = computeContentBoxLogicalWidth(style()->width().value()); 1728e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project else { 173bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth = 0; 1748e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 1758e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (hasMultipleLines() || isVertical()) 1768e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project calcVerticalPrefWidths(); 1778e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project else 1788e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project calcHorizontalPrefWidths(); 1798e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 180bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen m_maxPreferredLogicalWidth = max(m_minPreferredLogicalWidth, m_maxPreferredLogicalWidth); 1818e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 1828e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 183f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch if (hasOverflowClip() && style()->overflowY() == OSCROLL) { 184f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch layer()->setHasVerticalScrollbar(true); 185f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch int scrollbarWidth = verticalScrollbarWidth(); 186f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch m_maxPreferredLogicalWidth += scrollbarWidth; 187f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch m_minPreferredLogicalWidth += scrollbarWidth; 188f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch } 189f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch 1908e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (style()->minWidth().isFixed() && style()->minWidth().value() > 0) { 191bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen m_maxPreferredLogicalWidth = max(m_maxPreferredLogicalWidth, computeContentBoxLogicalWidth(style()->minWidth().value())); 192bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen m_minPreferredLogicalWidth = max(m_minPreferredLogicalWidth, computeContentBoxLogicalWidth(style()->minWidth().value())); 1938e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 194f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block 1958e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (style()->maxWidth().isFixed() && style()->maxWidth().value() != undefinedLength) { 196bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen m_maxPreferredLogicalWidth = min(m_maxPreferredLogicalWidth, computeContentBoxLogicalWidth(style()->maxWidth().value())); 197bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen m_minPreferredLogicalWidth = min(m_minPreferredLogicalWidth, computeContentBoxLogicalWidth(style()->maxWidth().value())); 1988e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 1998e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 200f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch int borderAndPadding = borderAndPaddingLogicalWidth(); 201f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch m_minPreferredLogicalWidth += borderAndPadding; 202f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch m_maxPreferredLogicalWidth += borderAndPadding; 2038e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 204bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen setPreferredLogicalWidthsDirty(false); 2058e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project} 2068e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 20768513a70bcd92384395513322f1b801e7bf9c729Steve Blockvoid RenderFlexibleBox::layoutBlock(bool relayoutChildren, int /*pageHeight FIXME: Implement */) 2088e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{ 2098e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project ASSERT(needsLayout()); 2108e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 2112bde8e466a4451c7319e3a072d118917957d6554Steve Block if (!relayoutChildren && simplifiedLayout()) 2128e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project return; 2138e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 2148f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian LayoutRepainter repainter(*this, checkForRepaintDuringLayout()); 2156b70adc33054f8aee8c54d0f460458a9df11b8a5Russell Brenner LayoutStateMaintainer statePusher(view(), this, IntSize(x(), y()), hasTransform() || hasReflection() || style()->isFlippedBlocksWritingMode()); 2168e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 217635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project int previousWidth = width(); 218635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project int previousHeight = height(); 219f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block 220bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen computeLogicalWidth(); 221bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen computeLogicalHeight(); 222f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block 223231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block m_overflow.clear(); 2248e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 225635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project if (previousWidth != width() || previousHeight != height() || 2268e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project (parent()->isFlexibleBox() && parent()->style()->boxOrient() == HORIZONTAL && 2278e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project parent()->style()->boxAlign() == BSTRETCH)) 2288e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project relayoutChildren = true; 2298e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 2308e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#ifdef ANDROID_LAYOUT 23123e9dd818a876304304944c844be7625f63383c4Shimeng (Simon) Wang checkAndSetRelayoutChildren(&relayoutChildren); 2328e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#endif 233635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project setHeight(0); 2348e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 2358e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project m_flexingChildren = m_stretchingChildren = false; 2368e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 2378e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project initMaxMarginValues(); 2388e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 2398e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // For overflow:scroll blocks, ensure we have both scrollbars in place always. 2408e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (scrollsOverflow()) { 2418e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (style()->overflowX() == OSCROLL) 2428f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian layer()->setHasHorizontalScrollbar(true); 2438e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (style()->overflowY() == OSCROLL) 2448f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian layer()->setHasVerticalScrollbar(true); 2458e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 2468e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 2478e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (isHorizontal()) 2488e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project layoutHorizontalBox(relayoutChildren); 2498e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project else 2508e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project layoutVerticalBox(relayoutChildren); 2518e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 252f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch int oldClientAfterEdge = clientLogicalBottom(); 253bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen computeLogicalHeight(); 254231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block 255635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project if (previousHeight != height()) 2568e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project relayoutChildren = true; 2578e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 2588e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project layoutPositionedObjects(relayoutChildren || isRoot()); 2598e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 260635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project if (!isFloatingOrPositioned() && height() == 0) { 2618e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // We are a block with no border and padding and a computed height 2628e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // of 0. The CSS spec states that zero-height blocks collapse their margins 2638e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // together. 2648e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // When blocks are self-collapsing, we just use the top margin values and set the 2658e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // bottom margin max values to 0. This way we don't factor in the values 2668e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // twice when we collapse with our previous vertically adjacent and 2678e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // following vertically adjacent blocks. 268a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch int pos = maxPositiveMarginBefore(); 269a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch int neg = maxNegativeMarginBefore(); 270a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch if (maxPositiveMarginAfter() > pos) 271a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch pos = maxPositiveMarginAfter(); 272a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch if (maxNegativeMarginAfter() > neg) 273a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch neg = maxNegativeMarginAfter(); 274bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen setMaxMarginBeforeValues(pos, neg); 275bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen setMaxMarginAfterValues(0, 0); 2768e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 277f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block 278f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch computeOverflow(oldClientAfterEdge); 2798e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 280635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project statePusher.pop(); 2818e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 282f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch updateLayerTransform(); 283f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch 284f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch if (view()->layoutState()->pageLogicalHeight()) 2852fc2651226baac27029e38c9d6ef883fa32084dbSteve Block setPageLogicalOffset(view()->layoutState()->pageLogicalOffset(logicalTop())); 28668513a70bcd92384395513322f1b801e7bf9c729Steve Block 2878e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // Update our scrollbars if we're overflow:auto/scroll/hidden now that we know if 2888e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // we overflow or not. 2898e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (hasOverflowClip()) 2908f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian layer()->updateScrollInfoAfterLayout(); 2918e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 2928e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // Repaint with our new bounds if they are different from our old bounds. 2938f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian repainter.repaintAfterLayout(); 294f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block 2958e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project setNeedsLayout(false); 2968e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project} 2978e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 2980bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch// The first walk over our kids is to find out if we have any flexible children. 2990bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdochstatic void gatherFlexChildrenInfo(FlexBoxIterator& iterator, bool relayoutChildren, unsigned int& highestFlexGroup, unsigned int& lowestFlexGroup, bool& haveFlex) 3008e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{ 301f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block for (RenderBox* child = iterator.first(); child; child = iterator.next()) { 3028e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // Check to see if this child flexes. 3038e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (!child->isPositioned() && child->style()->boxFlex() > 0.0f) { 3048e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // We always have to lay out flexible objects again, since the flex distribution 3058e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // may have changed, and we need to reallocate space. 3068e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project child->setOverrideSize(-1); 3078e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (!relayoutChildren) 3088e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project child->setChildNeedsLayout(true, false); 3098e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project haveFlex = true; 3108e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project unsigned int flexGroup = child->style()->boxFlexGroup(); 3118e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (lowestFlexGroup == 0) 3128e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project lowestFlexGroup = flexGroup; 3138e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (flexGroup < lowestFlexGroup) 3148e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project lowestFlexGroup = flexGroup; 3158e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (flexGroup > highestFlexGroup) 3168e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project highestFlexGroup = flexGroup; 3178e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 3188e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 3190bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch} 3200bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch 3210bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdochvoid RenderFlexibleBox::layoutHorizontalBox(bool relayoutChildren) 3220bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch{ 3230bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch int toAdd = borderBottom() + paddingBottom() + horizontalScrollbarHeight(); 3240bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch int yPos = borderTop() + paddingTop(); 3250bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch int xPos = borderLeft() + paddingLeft(); 3260bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch bool heightSpecified = false; 3270bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch int oldHeight = 0; 3280bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch 3290bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch int remainingSpace = 0; 330231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block 3310bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch 3320bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch FlexBoxIterator iterator(this); 3330bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch unsigned int highestFlexGroup = 0; 3340bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch unsigned int lowestFlexGroup = 0; 3350bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch bool haveFlex = false; 3360bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch gatherFlexChildrenInfo(iterator, relayoutChildren, highestFlexGroup, lowestFlexGroup, haveFlex); 3370bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch 3380bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch RenderBlock::startDelayUpdateScrollInfo(); 3390bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch 3408e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // We do 2 passes. The first pass is simply to lay everyone out at 3418e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // their preferred widths. The second pass handles flexing the children. 3428e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project do { 3438e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // Reset our height. 344635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project setHeight(yPos); 345231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block 3468e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project xPos = borderLeft() + paddingLeft(); 347f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block 3488e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // Our first pass is done without flexing. We simply lay the children 3498e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // out within the box. We have to do a layout first in order to determine 3508e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // our box's intrinsic height. 3518e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project int maxAscent = 0, maxDescent = 0; 352f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block for (RenderBox* child = iterator.first(); child; child = iterator.next()) { 3538e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // make sure we relayout children if we need it. 3548e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (relayoutChildren || (child->isReplaced() && (child->style()->width().isPercent() || child->style()->height().isPercent()))) 3558e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project child->setChildNeedsLayout(true, false); 356f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block 357f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block if (child->isPositioned()) 3588e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project continue; 359f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block 3608e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // Compute the child's vertical margins. 361bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen child->computeBlockDirectionMargins(this); 362f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block 363a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch if (!child->needsLayout()) 364a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch child->markForPaginationRelayoutIfNeeded(); 36568513a70bcd92384395513322f1b801e7bf9c729Steve Block 3668e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // Now do the layout. 3678e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project child->layoutIfNeeded(); 368f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block 3698e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // Update our height and overflow height. 3708e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (style()->boxAlign() == BBASELINE) { 3718f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian int ascent = child->firstLineBoxBaseline(); 3728e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (ascent == -1) 3738f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian ascent = child->height() + child->marginBottom(); 3748f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian ascent += child->marginTop(); 3758e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project int descent = (child->marginTop() + child->height() + child->marginBottom()) - ascent; 376f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block 3778e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // Update our maximum ascent. 3788e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project maxAscent = max(maxAscent, ascent); 379f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block 3808e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // Update our maximum descent. 3818e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project maxDescent = max(maxDescent, descent); 382f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block 3838e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // Now update our height. 384635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project setHeight(max(yPos + maxAscent + maxDescent, height())); 3858e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 3868e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project else 387635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project setHeight(max(height(), yPos + child->marginTop() + child->height() + child->marginBottom())); 3888e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 389f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block 3908e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (!iterator.first() && hasLineIfEmpty()) 391a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch setHeight(height() + lineHeight(true, style()->isHorizontalWritingMode() ? HorizontalLine : VerticalLine, PositionOfInteriorLineBoxes)); 392f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block 393635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project setHeight(height() + toAdd); 394f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block 395635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project oldHeight = height(); 396bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen computeLogicalHeight(); 3978e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 3988e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project relayoutChildren = false; 399635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project if (oldHeight != height()) 4008e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project heightSpecified = true; 401f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block 4028e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // Now that our height is actually known, we can place our boxes. 4038e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project m_stretchingChildren = (style()->boxAlign() == BSTRETCH); 404f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block for (RenderBox* child = iterator.first(); child; child = iterator.next()) { 4058e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (child->isPositioned()) { 4068e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project child->containingBlock()->insertPositionedObject(child); 40781bc750723a18f21cd17d1b173cd2a4dda9cea6eBen Murdoch RenderLayer* childLayer = child->layer(); 4082bde8e466a4451c7319e3a072d118917957d6554Steve Block childLayer->setStaticInlinePosition(xPos); 4092bde8e466a4451c7319e3a072d118917957d6554Steve Block if (childLayer->staticBlockPosition() != yPos) { 4102bde8e466a4451c7319e3a072d118917957d6554Steve Block childLayer->setStaticBlockPosition(yPos); 4112bde8e466a4451c7319e3a072d118917957d6554Steve Block if (child->style()->hasStaticBlockPosition(style()->isHorizontalWritingMode())) 412643ca7872b450ea4efacab6188849e5aac2ba161Steve Block child->setChildNeedsLayout(true, false); 413643ca7872b450ea4efacab6188849e5aac2ba161Steve Block } 4148e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project continue; 4158e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 416f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block 4178e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // We need to see if this child's height has changed, since we make block elements 4188e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // fill the height of a containing box by default. 4198e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // Now do a layout. 4208e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project int oldChildHeight = child->height(); 421bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen child->computeLogicalHeight(); 4228e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (oldChildHeight != child->height()) 4238e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project child->setChildNeedsLayout(true, false); 424f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block 425a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch if (!child->needsLayout()) 426a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch child->markForPaginationRelayoutIfNeeded(); 42768513a70bcd92384395513322f1b801e7bf9c729Steve Block 4288e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project child->layoutIfNeeded(); 429f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block 4308e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // We can place the child now, using our value of box-align. 4318e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project xPos += child->marginLeft(); 4328e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project int childY = yPos; 4338e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project switch (style()->boxAlign()) { 4348e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project case BCENTER: 435f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block childY += child->marginTop() + max(0, (contentHeight() - (child->height() + child->marginTop() + child->marginBottom())) / 2); 4368e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project break; 4378e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project case BBASELINE: { 4388f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian int ascent = child->firstLineBoxBaseline(); 4398e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (ascent == -1) 4408f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian ascent = child->height() + child->marginBottom(); 4418f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian ascent += child->marginTop(); 4428e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project childY += child->marginTop() + (maxAscent - ascent); 4438e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project break; 4448e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 4458e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project case BEND: 4468e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project childY += contentHeight() - child->marginBottom() - child->height(); 4478e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project break; 4488e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project default: // BSTART 4498e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project childY += child->marginTop(); 4508e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project break; 4518e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 4528e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 4538e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project placeChild(child, xPos, childY); 454f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block 4558e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project xPos += child->width() + child->marginRight(); 4568e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 4578e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 4588e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project remainingSpace = borderLeft() + paddingLeft() + contentWidth() - xPos; 459f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block 4608e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project m_stretchingChildren = false; 4618e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (m_flexingChildren) 4628e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project haveFlex = false; // We're done. 4638e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project else if (haveFlex) { 4648e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // We have some flexible objects. See if we need to grow/shrink them at all. 4658e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (!remainingSpace) 4668e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project break; 4678e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 4688e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // Allocate the remaining space among the flexible objects. If we are trying to 4698e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // grow, then we go from the lowest flex group to the highest flex group. For shrinking, 4708e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // we go from the highest flex group to the lowest group. 4718e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project bool expanding = remainingSpace > 0; 4728e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project unsigned int start = expanding ? lowestFlexGroup : highestFlexGroup; 4738e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project unsigned int end = expanding? highestFlexGroup : lowestFlexGroup; 4748e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project for (unsigned int i = start; i <= end && remainingSpace; i++) { 4758e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // Always start off by assuming the group can get all the remaining space. 4768e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project int groupRemainingSpace = remainingSpace; 4778e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project do { 4788e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // Flexing consists of multiple passes, since we have to change ratios every time an object hits its max/min-width 4798e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // For a given pass, we always start off by computing the totalFlex of all objects that can grow/shrink at all, and 4808e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // computing the allowed growth before an object hits its min/max width (and thus 4818e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // forces a totalFlex recomputation). 4828e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project int groupRemainingSpaceAtBeginning = groupRemainingSpace; 4838e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project float totalFlex = 0.0f; 484f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block for (RenderBox* child = iterator.first(); child; child = iterator.next()) { 4858e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (allowedChildFlex(child, expanding, i)) 4868e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project totalFlex += child->style()->boxFlex(); 4878e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 4888e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project int spaceAvailableThisPass = groupRemainingSpace; 489f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block for (RenderBox* child = iterator.first(); child; child = iterator.next()) { 4908e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project int allowedFlex = allowedChildFlex(child, expanding, i); 4918e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (allowedFlex) { 4928e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project int projectedFlex = (allowedFlex == INT_MAX) ? allowedFlex : (int)(allowedFlex * (totalFlex / child->style()->boxFlex())); 4938e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project spaceAvailableThisPass = expanding ? min(spaceAvailableThisPass, projectedFlex) : max(spaceAvailableThisPass, projectedFlex); 4948e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 4958e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 4968e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 497f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block // The flex groups may not have any flexible objects this time around. 4988e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (!spaceAvailableThisPass || totalFlex == 0.0f) { 4998e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // If we just couldn't grow/shrink any more, then it's time to transition to the next flex group. 5008e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project groupRemainingSpace = 0; 5018e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project continue; 5028e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 5038e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 5048e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // Now distribute the space to objects. 505f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block for (RenderBox* child = iterator.first(); child && spaceAvailableThisPass && totalFlex; child = iterator.next()) { 5068e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (allowedChildFlex(child, expanding, i)) { 5078e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project int spaceAdd = (int)(spaceAvailableThisPass * (child->style()->boxFlex()/totalFlex)); 5088e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (spaceAdd) { 5098e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project child->setOverrideSize(child->overrideWidth() + spaceAdd); 5108e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project m_flexingChildren = true; 5118e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project relayoutChildren = true; 5128e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 5138e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 5148e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project spaceAvailableThisPass -= spaceAdd; 5158e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project remainingSpace -= spaceAdd; 5168e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project groupRemainingSpace -= spaceAdd; 517f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block 5188e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project totalFlex -= child->style()->boxFlex(); 5198e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 5208e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 5218e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (groupRemainingSpace == groupRemainingSpaceAtBeginning) { 522f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block // This is not advancing, avoid getting stuck by distributing the remaining pixels. 5238e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project int spaceAdd = groupRemainingSpace > 0 ? 1 : -1; 524f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block for (RenderBox* child = iterator.first(); child && groupRemainingSpace; child = iterator.next()) { 5258e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (allowedChildFlex(child, expanding, i)) { 5268e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project child->setOverrideSize(child->overrideWidth() + spaceAdd); 5278e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project m_flexingChildren = true; 5288e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project relayoutChildren = true; 5298e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project remainingSpace -= spaceAdd; 5308e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project groupRemainingSpace -= spaceAdd; 5318e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 5328e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 5338e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 5348e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } while (groupRemainingSpace); 5358e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 5368e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 5378e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // We didn't find any children that could grow. 5388e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (haveFlex && !m_flexingChildren) 5398e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project haveFlex = false; 5408e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 5418e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } while (haveFlex); 5428e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 5438e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project m_flexingChildren = false; 5440bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch 5450bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch RenderBlock::finishDelayUpdateScrollInfo(); 5460bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch 547a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch if (remainingSpace > 0 && ((style()->isLeftToRightDirection() && style()->boxPack() != BSTART) 548a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch || (!style()->isLeftToRightDirection() && style()->boxPack() != BEND))) { 5498e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // Children must be repositioned. 5508e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project int offset = 0; 5518e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (style()->boxPack() == BJUSTIFY) { 5528e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // Determine the total number of children. 5538e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project int totalChildren = 0; 554f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block for (RenderBox* child = iterator.first(); child; child = iterator.next()) { 555f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block if (child->isPositioned()) 5568e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project continue; 557f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block ++totalChildren; 5588e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 5598e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 5608e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // Iterate over the children and space them out according to the 5618e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // justification level. 5628e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (totalChildren > 1) { 563f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block --totalChildren; 5648e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project bool firstChild = true; 565f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block for (RenderBox* child = iterator.first(); child; child = iterator.next()) { 566f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block if (child->isPositioned()) 5678e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project continue; 5688e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 5698e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (firstChild) { 5708e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project firstChild = false; 5718e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project continue; 5728e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 5738e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 5748e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project offset += remainingSpace/totalChildren; 5758e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project remainingSpace -= (remainingSpace/totalChildren); 576f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block --totalChildren; 5778e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 578f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block placeChild(child, child->x() + offset, child->y()); 5798e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 5808e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 5818e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } else { 5828e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (style()->boxPack() == BCENTER) 583f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block offset += remainingSpace / 2; 5848e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project else // END for LTR, START for RTL 5858e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project offset += remainingSpace; 586f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block for (RenderBox* child = iterator.first(); child; child = iterator.next()) { 587f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block if (child->isPositioned()) 5888e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project continue; 589f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block 590f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block placeChild(child, child->x() + offset, child->y()); 5918e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 5928e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 5938e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 594f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block 595bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // So that the computeLogicalHeight in layoutBlock() knows to relayout positioned objects because of 5968e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // a height change, we revert our height back to the intrinsic height before returning. 5978e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (heightSpecified) 598635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project setHeight(oldHeight); 5998e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project} 6008e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 6018e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectvoid RenderFlexibleBox::layoutVerticalBox(bool relayoutChildren) 6028e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{ 6038e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project int xPos = borderLeft() + paddingLeft(); 6048e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project int yPos = borderTop() + paddingTop(); 605a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch if (!style()->isLeftToRightDirection()) 606635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project xPos = width() - paddingRight() - borderRight(); 6078e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project int toAdd = borderBottom() + paddingBottom() + horizontalScrollbarHeight(); 6088e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project bool heightSpecified = false; 6098e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project int oldHeight = 0; 6100bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch 6110bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch int remainingSpace = 0; 6120bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch 6130bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch FlexBoxIterator iterator(this); 6148e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project unsigned int highestFlexGroup = 0; 6158e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project unsigned int lowestFlexGroup = 0; 6168e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project bool haveFlex = false; 6170bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch gatherFlexChildrenInfo(iterator, relayoutChildren, highestFlexGroup, lowestFlexGroup, haveFlex); 6180bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch 6198e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // We confine the line clamp ugliness to vertical flexible boxes (thus keeping it out of 6208e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // mainstream block layout); this is not really part of the XUL box model. 621643ca7872b450ea4efacab6188849e5aac2ba161Steve Block bool haveLineClamp = !style()->lineClamp().isNone(); 62268513a70bcd92384395513322f1b801e7bf9c729Steve Block if (haveLineClamp) 62368513a70bcd92384395513322f1b801e7bf9c729Steve Block applyLineClamp(iterator, relayoutChildren); 6248e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 6250bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch RenderBlock::startDelayUpdateScrollInfo(); 6260bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch 6278e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // We do 2 passes. The first pass is simply to lay everyone out at 6288e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // their preferred widths. The second pass handles flexing the children. 6298e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // Our first pass is done without flexing. We simply lay the children 6308e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // out within the box. 6318e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project do { 632635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project setHeight(borderTop() + paddingTop()); 633635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project int minHeight = height() + toAdd; 6348e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 635f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block for (RenderBox* child = iterator.first(); child; child = iterator.next()) { 636f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block // Make sure we relayout children if we need it. 6378e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (!haveLineClamp && (relayoutChildren || (child->isReplaced() && (child->style()->width().isPercent() || child->style()->height().isPercent())))) 6388e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project child->setChildNeedsLayout(true, false); 639f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block 640231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block if (child->isPositioned()) { 6418e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project child->containingBlock()->insertPositionedObject(child); 64281bc750723a18f21cd17d1b173cd2a4dda9cea6eBen Murdoch RenderLayer* childLayer = child->layer(); 6432bde8e466a4451c7319e3a072d118917957d6554Steve Block childLayer->setStaticInlinePosition(borderStart() + paddingStart()); 6442bde8e466a4451c7319e3a072d118917957d6554Steve Block if (childLayer->staticBlockPosition() != height()) { 6452bde8e466a4451c7319e3a072d118917957d6554Steve Block childLayer->setStaticBlockPosition(height()); 6462bde8e466a4451c7319e3a072d118917957d6554Steve Block if (child->style()->hasStaticBlockPosition(style()->isHorizontalWritingMode())) 647643ca7872b450ea4efacab6188849e5aac2ba161Steve Block child->setChildNeedsLayout(true, false); 648643ca7872b450ea4efacab6188849e5aac2ba161Steve Block } 6498e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project continue; 650f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block } 651f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block 6528e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // Compute the child's vertical margins. 653bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen child->computeBlockDirectionMargins(this); 654f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block 6558e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // Add in the child's marginTop to our height. 656635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project setHeight(height() + child->marginTop()); 657f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block 658a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch if (!child->needsLayout()) 659a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch child->markForPaginationRelayoutIfNeeded(); 66068513a70bcd92384395513322f1b801e7bf9c729Steve Block 6618e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // Now do a layout. 6628e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project child->layoutIfNeeded(); 663f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block 6648e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // We can place the child now, using our value of box-align. 6658e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project int childX = borderLeft() + paddingLeft(); 6668e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project switch (style()->boxAlign()) { 6678e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project case BCENTER: 6688e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project case BBASELINE: // Baseline just maps to center for vertical boxes 669f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block childX += child->marginLeft() + max(0, (contentWidth() - (child->width() + child->marginLeft() + child->marginRight())) / 2); 6708e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project break; 6718e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project case BEND: 672a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch if (!style()->isLeftToRightDirection()) 6738e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project childX += child->marginLeft(); 6748e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project else 6758e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project childX += contentWidth() - child->marginRight() - child->width(); 6768e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project break; 6778e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project default: // BSTART/BSTRETCH 678a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch if (style()->isLeftToRightDirection()) 6798e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project childX += child->marginLeft(); 6808e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project else 6818e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project childX += contentWidth() - child->marginRight() - child->width(); 6828e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project break; 6838e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 684f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block 6858e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // Place the child. 686635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project placeChild(child, childX, height()); 687635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project setHeight(height() + child->height() + child->marginBottom()); 6888e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 6898e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 690635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project yPos = height(); 691f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block 6928e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (!iterator.first() && hasLineIfEmpty()) 693a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch setHeight(height() + lineHeight(true, style()->isHorizontalWritingMode() ? HorizontalLine : VerticalLine, PositionOfInteriorLineBoxes)); 694f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block 695635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project setHeight(height() + toAdd); 6968e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 6978e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // Negative margins can cause our height to shrink below our minimal height (border/padding). 6988e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // If this happens, ensure that the computed height is increased to the minimal height. 699635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project if (height() < minHeight) 700635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project setHeight(minHeight); 7018e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 7028e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // Now we have to calc our height, so we know how much space we have remaining. 703635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project oldHeight = height(); 704bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen computeLogicalHeight(); 705635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project if (oldHeight != height()) 7068e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project heightSpecified = true; 7078e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 7088e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project remainingSpace = borderTop() + paddingTop() + contentHeight() - yPos; 709f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block 7108e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (m_flexingChildren) 7118e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project haveFlex = false; // We're done. 7128e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project else if (haveFlex) { 7138e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // We have some flexible objects. See if we need to grow/shrink them at all. 7148e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (!remainingSpace) 7158e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project break; 7168e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 7178e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // Allocate the remaining space among the flexible objects. If we are trying to 7188e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // grow, then we go from the lowest flex group to the highest flex group. For shrinking, 7198e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // we go from the highest flex group to the lowest group. 7208e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project bool expanding = remainingSpace > 0; 7218e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project unsigned int start = expanding ? lowestFlexGroup : highestFlexGroup; 7228e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project unsigned int end = expanding? highestFlexGroup : lowestFlexGroup; 7238e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project for (unsigned int i = start; i <= end && remainingSpace; i++) { 7248e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // Always start off by assuming the group can get all the remaining space. 7258e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project int groupRemainingSpace = remainingSpace; 7268e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project do { 7278e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // Flexing consists of multiple passes, since we have to change ratios every time an object hits its max/min-width 7288e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // For a given pass, we always start off by computing the totalFlex of all objects that can grow/shrink at all, and 7298e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // computing the allowed growth before an object hits its min/max width (and thus 7308e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // forces a totalFlex recomputation). 7318e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project int groupRemainingSpaceAtBeginning = groupRemainingSpace; 7328e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project float totalFlex = 0.0f; 733f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block for (RenderBox* child = iterator.first(); child; child = iterator.next()) { 7348e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (allowedChildFlex(child, expanding, i)) 7358e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project totalFlex += child->style()->boxFlex(); 7368e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 7378e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project int spaceAvailableThisPass = groupRemainingSpace; 738f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block for (RenderBox* child = iterator.first(); child; child = iterator.next()) { 7398e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project int allowedFlex = allowedChildFlex(child, expanding, i); 7408e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (allowedFlex) { 7418e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project int projectedFlex = (allowedFlex == INT_MAX) ? allowedFlex : (int)(allowedFlex * (totalFlex / child->style()->boxFlex())); 7428e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project spaceAvailableThisPass = expanding ? min(spaceAvailableThisPass, projectedFlex) : max(spaceAvailableThisPass, projectedFlex); 7438e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 7448e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 7458e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 746f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block // The flex groups may not have any flexible objects this time around. 7478e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (!spaceAvailableThisPass || totalFlex == 0.0f) { 7488e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // If we just couldn't grow/shrink any more, then it's time to transition to the next flex group. 7498e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project groupRemainingSpace = 0; 7508e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project continue; 7518e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 752f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block 7538e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // Now distribute the space to objects. 754f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block for (RenderBox* child = iterator.first(); child && spaceAvailableThisPass && totalFlex; child = iterator.next()) { 7558e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (allowedChildFlex(child, expanding, i)) { 7568e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project int spaceAdd = (int)(spaceAvailableThisPass * (child->style()->boxFlex()/totalFlex)); 7578e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (spaceAdd) { 7588e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project child->setOverrideSize(child->overrideHeight() + spaceAdd); 7598e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project m_flexingChildren = true; 7608e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project relayoutChildren = true; 7618e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 7628e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 7638e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project spaceAvailableThisPass -= spaceAdd; 7648e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project remainingSpace -= spaceAdd; 7658e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project groupRemainingSpace -= spaceAdd; 766f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block 7678e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project totalFlex -= child->style()->boxFlex(); 7688e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 7698e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 7708e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (groupRemainingSpace == groupRemainingSpaceAtBeginning) { 771f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block // This is not advancing, avoid getting stuck by distributing the remaining pixels. 7728e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project int spaceAdd = groupRemainingSpace > 0 ? 1 : -1; 773f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block for (RenderBox* child = iterator.first(); child && groupRemainingSpace; child = iterator.next()) { 7748e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (allowedChildFlex(child, expanding, i)) { 7758e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project child->setOverrideSize(child->overrideHeight() + spaceAdd); 7768e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project m_flexingChildren = true; 7778e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project relayoutChildren = true; 7788e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project remainingSpace -= spaceAdd; 7798e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project groupRemainingSpace -= spaceAdd; 7808e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 7818e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 7828e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 7838e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } while (groupRemainingSpace); 7848e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 7858e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 7868e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // We didn't find any children that could grow. 7878e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (haveFlex && !m_flexingChildren) 7888e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project haveFlex = false; 789f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block } 7908e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } while (haveFlex); 7918e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 7920bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch RenderBlock::finishDelayUpdateScrollInfo(); 7930bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch 7948e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (style()->boxPack() != BSTART && remainingSpace > 0) { 7958e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // Children must be repositioned. 7968e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project int offset = 0; 7978e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (style()->boxPack() == BJUSTIFY) { 7988e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // Determine the total number of children. 7998e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project int totalChildren = 0; 800f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block for (RenderBox* child = iterator.first(); child; child = iterator.next()) { 801f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block if (child->isPositioned()) 8028e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project continue; 803f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block 804f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block ++totalChildren; 8058e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 806f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block 8078e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // Iterate over the children and space them out according to the 8088e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // justification level. 8098e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (totalChildren > 1) { 810f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block --totalChildren; 8118e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project bool firstChild = true; 812f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block for (RenderBox* child = iterator.first(); child; child = iterator.next()) { 813f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block if (child->isPositioned()) 8148e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project continue; 815f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block 8168e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (firstChild) { 8178e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project firstChild = false; 8188e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project continue; 8198e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 8208e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 8218e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project offset += remainingSpace/totalChildren; 8228e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project remainingSpace -= (remainingSpace/totalChildren); 823f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block --totalChildren; 824f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block placeChild(child, child->x(), child->y() + offset); 8258e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 8268e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 8278e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } else { 8288e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (style()->boxPack() == BCENTER) 829f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block offset += remainingSpace / 2; 8308e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project else // END 8318e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project offset += remainingSpace; 832f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block for (RenderBox* child = iterator.first(); child; child = iterator.next()) { 833f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block if (child->isPositioned()) 8348e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project continue; 835f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block placeChild(child, child->x(), child->y() + offset); 8368e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 8378e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 8388e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 8398e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 840bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen // So that the computeLogicalHeight in layoutBlock() knows to relayout positioned objects because of 8418e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // a height change, we revert our height back to the intrinsic height before returning. 8428e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (heightSpecified) 843f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block setHeight(oldHeight); 8448e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project} 8458e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 84668513a70bcd92384395513322f1b801e7bf9c729Steve Blockvoid RenderFlexibleBox::applyLineClamp(FlexBoxIterator& iterator, bool relayoutChildren) 84768513a70bcd92384395513322f1b801e7bf9c729Steve Block{ 84868513a70bcd92384395513322f1b801e7bf9c729Steve Block int maxLineCount = 0; 849a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch for (RenderBox* child = iterator.first(); child; child = iterator.next()) { 850a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch if (child->isPositioned()) 851a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch continue; 852a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch 853a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch if (relayoutChildren || (child->isReplaced() && (child->style()->width().isPercent() || child->style()->height().isPercent())) 854e14391e94c850b8bd03680c23b38978db68687a8John Reck || (child->style()->height().isAuto() && child->isBlockFlow())) { 855a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch child->setChildNeedsLayout(true, false); 856a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch 857a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch // Dirty all the positioned objects. 858a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch if (child->isRenderBlock()) { 859a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch toRenderBlock(child)->markPositionedObjectsForLayout(); 860a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch toRenderBlock(child)->clearTruncation(); 86168513a70bcd92384395513322f1b801e7bf9c729Steve Block } 86268513a70bcd92384395513322f1b801e7bf9c729Steve Block } 863a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch child->layoutIfNeeded(); 864a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch if (child->style()->height().isAuto() && child->isBlockFlow()) 865a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch maxLineCount = max(maxLineCount, toRenderBlock(child)->lineCount()); 86668513a70bcd92384395513322f1b801e7bf9c729Steve Block } 867a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch 868a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch // Get the number of lines and then alter all block flow children with auto height to use the 86968513a70bcd92384395513322f1b801e7bf9c729Steve Block // specified height. We always try to leave room for at least one line. 87068513a70bcd92384395513322f1b801e7bf9c729Steve Block LineClampValue lineClamp = style()->lineClamp(); 87168513a70bcd92384395513322f1b801e7bf9c729Steve Block int numVisibleLines = lineClamp.isPercentage() ? max(1, (maxLineCount + 1) * lineClamp.value() / 100) : lineClamp.value(); 872a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch if (numVisibleLines >= maxLineCount) 873a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch return; 874a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch 875a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch for (RenderBox* child = iterator.first(); child; child = iterator.next()) { 876a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch if (child->isPositioned() || !child->style()->height().isAuto() || !child->isBlockFlow()) 877a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch continue; 878f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block 879a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch RenderBlock* blockChild = toRenderBlock(child); 880a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch int lineCount = blockChild->lineCount(); 881a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch if (lineCount <= numVisibleLines) 882a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch continue; 883f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block 884a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch int newHeight = blockChild->heightForLineCount(numVisibleLines); 885a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch if (newHeight == child->height()) 886a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch continue; 887f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block 888a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch child->setChildNeedsLayout(true, false); 889a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch child->setOverrideSize(newHeight); 890a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch m_flexingChildren = true; 891a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch child->layoutIfNeeded(); 892a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch m_flexingChildren = false; 893a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch child->setOverrideSize(-1); 894a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch 895a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch // FIXME: For now don't support RTL. 896a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch if (style()->direction() != LTR) 897a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch continue; 898a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch 899a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch // Get the last line 900f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block RootInlineBox* lastLine = blockChild->lineAtIndex(lineCount - 1); 901a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch if (!lastLine) 902a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch continue; 903a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch 904f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block RootInlineBox* lastVisibleLine = blockChild->lineAtIndex(numVisibleLines - 1); 905a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch if (!lastVisibleLine) 906a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch continue; 907a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch 908a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch const UChar ellipsisAndSpace[2] = { horizontalEllipsis, ' ' }; 909a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch DEFINE_STATIC_LOCAL(AtomicString, ellipsisAndSpaceStr, (ellipsisAndSpace, 2)); 910a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch DEFINE_STATIC_LOCAL(AtomicString, ellipsisStr, (&horizontalEllipsis, 1)); 911a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch const Font& font = style(numVisibleLines == 1)->font(); 912a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch 913f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block // 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 914a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch int totalWidth; 915a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch InlineBox* anchorBox = lastLine->lastChild(); 9162daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch if (anchorBox && anchorBox->renderer()->style()->isLink()) 917a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch totalWidth = anchorBox->logicalWidth() + font.width(TextRun(ellipsisAndSpace, 2)); 918a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch else { 919a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch anchorBox = 0; 920a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch totalWidth = font.width(TextRun(&horizontalEllipsis, 1)); 92168513a70bcd92384395513322f1b801e7bf9c729Steve Block } 922a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch 923a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch // See if this width can be accommodated on the last visible line 924a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch RenderBlock* destBlock = toRenderBlock(lastVisibleLine->renderer()); 925a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch RenderBlock* srcBlock = toRenderBlock(lastLine->renderer()); 926f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block 927a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch // FIXME: Directions of src/destBlock could be different from our direction and from one another. 928a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch if (!srcBlock->style()->isLeftToRightDirection()) 929a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch continue; 930a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch 931a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch bool leftToRight = destBlock->style()->isLeftToRightDirection(); 932a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch if (!leftToRight) 933a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch continue; 934a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch 935a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch int blockRightEdge = destBlock->logicalRightOffsetForLine(lastVisibleLine->y(), false); 936a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch int blockLeftEdge = destBlock->logicalLeftOffsetForLine(lastVisibleLine->y(), false); 937a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch 938a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch int blockEdge = leftToRight ? blockRightEdge : blockLeftEdge; 93981bc750723a18f21cd17d1b173cd2a4dda9cea6eBen Murdoch if (!lastVisibleLine->lineCanAccommodateEllipsis(leftToRight, blockEdge, lastVisibleLine->x() + lastVisibleLine->logicalWidth(), totalWidth)) 940a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch continue; 941a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch 942a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch // Let the truncation code kick in. 943a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch lastVisibleLine->placeEllipsis(anchorBox ? ellipsisAndSpaceStr : ellipsisStr, leftToRight, blockLeftEdge, blockRightEdge, totalWidth, anchorBox); 944a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch destBlock->setHasMarkupTruncation(true); 94568513a70bcd92384395513322f1b801e7bf9c729Steve Block } 94668513a70bcd92384395513322f1b801e7bf9c729Steve Block} 94768513a70bcd92384395513322f1b801e7bf9c729Steve Block 948635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Projectvoid RenderFlexibleBox::placeChild(RenderBox* child, int x, int y) 9498e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{ 950635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project IntRect oldRect(child->x(), child->y() , child->width(), child->height()); 9518e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 9528e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // Place the child. 953635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project child->setLocation(x, y); 9548e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 9558e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // If the child moved, we have to repaint it as well as any floating/positioned 9568e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // descendants. An exception is if we need a layout. In this case, we know we're going to 9578e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // repaint ourselves (and the child) anyway. 9588e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (!selfNeedsLayout() && child->checkForRepaintDuringLayout()) 9598e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project child->repaintDuringLayoutIfMoved(oldRect); 9608e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project} 9618e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 962635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Projectint RenderFlexibleBox::allowedChildFlex(RenderBox* child, bool expanding, unsigned int group) 9638e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{ 9648e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (child->isPositioned() || child->style()->boxFlex() == 0.0f || child->style()->boxFlexGroup() != group) 9658e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project return 0; 966f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block 9678e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (expanding) { 9688e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (isHorizontal()) { 9698e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // FIXME: For now just handle fixed values. 970f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block int maxWidth = INT_MAX; 971f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block int width = child->overrideWidth() - child->borderAndPaddingWidth(); 972f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block if (!child->style()->maxWidth().isUndefined() && child->style()->maxWidth().isFixed()) 973f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block maxWidth = child->style()->maxWidth().value(); 9748e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project else if (child->style()->maxWidth().type() == Intrinsic) 975f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block maxWidth = child->maxPreferredLogicalWidth(); 9768e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project else if (child->style()->maxWidth().type() == MinIntrinsic) 977f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block maxWidth = child->minPreferredLogicalWidth(); 978f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block if (maxWidth == INT_MAX) 979f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block return maxWidth; 980f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block return max(0, maxWidth - width); 9818e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } else { 9828e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // FIXME: For now just handle fixed values. 983f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block int maxHeight = INT_MAX; 984f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block int height = child->overrideHeight() - child->borderAndPaddingHeight(); 985f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block if (!child->style()->maxHeight().isUndefined() && child->style()->maxHeight().isFixed()) 986f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block maxHeight = child->style()->maxHeight().value(); 987f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block if (maxHeight == INT_MAX) 988f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block return maxHeight; 989f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block return max(0, maxHeight - height); 9908e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 9918e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 9928e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 9938e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // FIXME: For now just handle fixed values. 9948e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (isHorizontal()) { 995f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block int minWidth = child->minPreferredLogicalWidth(); 996f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block int width = child->overrideWidth() - child->borderAndPaddingWidth(); 9978e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (child->style()->minWidth().isFixed()) 998f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block minWidth = child->style()->minWidth().value(); 9998e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project else if (child->style()->minWidth().type() == Intrinsic) 1000f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block minWidth = child->maxPreferredLogicalWidth(); 10018e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project else if (child->style()->minWidth().type() == MinIntrinsic) 1002f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block minWidth = child->minPreferredLogicalWidth(); 1003f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block 1004f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block int allowedShrinkage = min(0, minWidth - width); 10058e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project return allowedShrinkage; 10068e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } else { 10078e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (child->style()->minHeight().isFixed()) { 1008f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block int minHeight = child->style()->minHeight().value(); 1009f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block int height = child->overrideHeight() - child->borderAndPaddingHeight(); 1010f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block int allowedShrinkage = min(0, minHeight - height); 10118e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project return allowedShrinkage; 10128e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 10138e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 1014f36dc73e3362e8a55ed9f8a0baa460d24a937c51Steve Block 10158e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project return 0; 10168e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project} 10178e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 10188e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectconst char *RenderFlexibleBox::renderName() const 10198e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{ 10208e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (isFloating()) 10218e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project return "RenderFlexibleBox (floating)"; 10228e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (isPositioned()) 10238e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project return "RenderFlexibleBox (positioned)"; 1024231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block if (isAnonymous()) 1025231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block return "RenderFlexibleBox (generated)"; 10268e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (isRelPositioned()) 10278e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project return "RenderFlexibleBox (relative positioned)"; 10288e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project return "RenderFlexibleBox"; 10298e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project} 10308e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 10318e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project} // namespace WebCore 1032