| OLD | NEW |
| 1 /* | 1 /* |
| 2 * This file is part of the layout object implementation for KHTML. | 2 * This file is part of the layout object implementation for KHTML. |
| 3 * | 3 * |
| 4 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 4 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 5 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 5 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
| 6 * Copyright (C) 2003 Apple Computer, Inc. | 6 * Copyright (C) 2003 Apple Computer, Inc. |
| 7 * | 7 * |
| 8 * This library is free software; you can redistribute it and/or | 8 * This library is free software; you can redistribute it and/or |
| 9 * modify it under the terms of the GNU Library General Public | 9 * modify it under the terms of the GNU Library General Public |
| 10 * License as published by the Free Software Foundation; either | 10 * License as published by the Free Software Foundation; either |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 #include <algorithm> | 36 #include <algorithm> |
| 37 | 37 |
| 38 namespace blink { | 38 namespace blink { |
| 39 | 39 |
| 40 class FlexBoxIterator { | 40 class FlexBoxIterator { |
| 41 public: | 41 public: |
| 42 FlexBoxIterator(LayoutDeprecatedFlexibleBox* parent) | 42 FlexBoxIterator(LayoutDeprecatedFlexibleBox* parent) |
| 43 : m_box(parent), m_largestOrdinal(1) { | 43 : m_box(parent), m_largestOrdinal(1) { |
| 44 if (m_box->style()->boxOrient() == HORIZONTAL && | 44 if (m_box->style()->boxOrient() == HORIZONTAL && |
| 45 !m_box->style()->isLeftToRightDirection()) | 45 !m_box->style()->isLeftToRightDirection()) |
| 46 m_forward = m_box->style()->boxDirection() != EBoxDirection::Normal; | 46 m_forward = m_box->style()->boxDirection() != EBoxDirection::kNormal; |
| 47 else | 47 else |
| 48 m_forward = m_box->style()->boxDirection() == EBoxDirection::Normal; | 48 m_forward = m_box->style()->boxDirection() == EBoxDirection::kNormal; |
| 49 if (!m_forward) { | 49 if (!m_forward) { |
| 50 // No choice, since we're going backwards, we have to find out the highest | 50 // No choice, since we're going backwards, we have to find out the highest |
| 51 // ordinal up front. | 51 // ordinal up front. |
| 52 LayoutBox* child = m_box->firstChildBox(); | 52 LayoutBox* child = m_box->firstChildBox(); |
| 53 while (child) { | 53 while (child) { |
| 54 if (child->style()->boxOrdinalGroup() > m_largestOrdinal) | 54 if (child->style()->boxOrdinalGroup() > m_largestOrdinal) |
| 55 m_largestOrdinal = child->style()->boxOrdinalGroup(); | 55 m_largestOrdinal = child->style()->boxOrdinalGroup(); |
| 56 child = child->nextSiblingBox(); | 56 child = child->nextSiblingBox(); |
| 57 } | 57 } |
| 58 } | 58 } |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 // (crawling into blocks). | 132 // (crawling into blocks). |
| 133 static bool shouldCheckLines(LayoutBlockFlow* blockFlow) { | 133 static bool shouldCheckLines(LayoutBlockFlow* blockFlow) { |
| 134 return !blockFlow->isFloatingOrOutOfFlowPositioned() && | 134 return !blockFlow->isFloatingOrOutOfFlowPositioned() && |
| 135 blockFlow->style()->height().isAuto(); | 135 blockFlow->style()->height().isAuto(); |
| 136 } | 136 } |
| 137 | 137 |
| 138 static int getHeightForLineCount(const LayoutBlockFlow* blockFlow, | 138 static int getHeightForLineCount(const LayoutBlockFlow* blockFlow, |
| 139 int lineCount, | 139 int lineCount, |
| 140 bool includeBottom, | 140 bool includeBottom, |
| 141 int& count) { | 141 int& count) { |
| 142 if (blockFlow->style()->visibility() != EVisibility::Visible) | 142 if (blockFlow->style()->visibility() != EVisibility::kVisible) |
| 143 return -1; | 143 return -1; |
| 144 if (blockFlow->childrenInline()) { | 144 if (blockFlow->childrenInline()) { |
| 145 for (RootInlineBox* box = blockFlow->firstRootBox(); box; | 145 for (RootInlineBox* box = blockFlow->firstRootBox(); box; |
| 146 box = box->nextRootBox()) { | 146 box = box->nextRootBox()) { |
| 147 if (++count == lineCount) | 147 if (++count == lineCount) |
| 148 return (box->lineBottom() + | 148 return (box->lineBottom() + |
| 149 (includeBottom | 149 (includeBottom |
| 150 ? (blockFlow->borderBottom() + blockFlow->paddingBottom()) | 150 ? (blockFlow->borderBottom() + blockFlow->paddingBottom()) |
| 151 : LayoutUnit())) | 151 : LayoutUnit())) |
| 152 .toInt(); | 152 .toInt(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 174 return (normalFlowChildWithoutLines->location().y() + | 174 return (normalFlowChildWithoutLines->location().y() + |
| 175 normalFlowChildWithoutLines->size().height()) | 175 normalFlowChildWithoutLines->size().height()) |
| 176 .toInt(); | 176 .toInt(); |
| 177 | 177 |
| 178 return -1; | 178 return -1; |
| 179 } | 179 } |
| 180 | 180 |
| 181 static RootInlineBox* lineAtIndex(const LayoutBlockFlow* blockFlow, int i) { | 181 static RootInlineBox* lineAtIndex(const LayoutBlockFlow* blockFlow, int i) { |
| 182 ASSERT(i >= 0); | 182 ASSERT(i >= 0); |
| 183 | 183 |
| 184 if (blockFlow->style()->visibility() != EVisibility::Visible) | 184 if (blockFlow->style()->visibility() != EVisibility::kVisible) |
| 185 return nullptr; | 185 return nullptr; |
| 186 | 186 |
| 187 if (blockFlow->childrenInline()) { | 187 if (blockFlow->childrenInline()) { |
| 188 for (RootInlineBox* box = blockFlow->firstRootBox(); box; | 188 for (RootInlineBox* box = blockFlow->firstRootBox(); box; |
| 189 box = box->nextRootBox()) { | 189 box = box->nextRootBox()) { |
| 190 if (!i--) | 190 if (!i--) |
| 191 return box; | 191 return box; |
| 192 } | 192 } |
| 193 return nullptr; | 193 return nullptr; |
| 194 } | 194 } |
| 195 for (LayoutObject* child = blockFlow->firstChild(); child; | 195 for (LayoutObject* child = blockFlow->firstChild(); child; |
| 196 child = child->nextSibling()) { | 196 child = child->nextSibling()) { |
| 197 if (!child->isLayoutBlockFlow()) | 197 if (!child->isLayoutBlockFlow()) |
| 198 continue; | 198 continue; |
| 199 LayoutBlockFlow* childBlockFlow = toLayoutBlockFlow(child); | 199 LayoutBlockFlow* childBlockFlow = toLayoutBlockFlow(child); |
| 200 if (!shouldCheckLines(childBlockFlow)) | 200 if (!shouldCheckLines(childBlockFlow)) |
| 201 continue; | 201 continue; |
| 202 if (RootInlineBox* box = lineAtIndex(childBlockFlow, i)) | 202 if (RootInlineBox* box = lineAtIndex(childBlockFlow, i)) |
| 203 return box; | 203 return box; |
| 204 } | 204 } |
| 205 | 205 |
| 206 return nullptr; | 206 return nullptr; |
| 207 } | 207 } |
| 208 | 208 |
| 209 static int lineCount(const LayoutBlockFlow* blockFlow, | 209 static int lineCount(const LayoutBlockFlow* blockFlow, |
| 210 const RootInlineBox* stopRootInlineBox = nullptr, | 210 const RootInlineBox* stopRootInlineBox = nullptr, |
| 211 bool* found = nullptr) { | 211 bool* found = nullptr) { |
| 212 if (blockFlow->style()->visibility() != EVisibility::Visible) | 212 if (blockFlow->style()->visibility() != EVisibility::kVisible) |
| 213 return 0; | 213 return 0; |
| 214 int count = 0; | 214 int count = 0; |
| 215 if (blockFlow->childrenInline()) { | 215 if (blockFlow->childrenInline()) { |
| 216 for (RootInlineBox* box = blockFlow->firstRootBox(); box; | 216 for (RootInlineBox* box = blockFlow->firstRootBox(); box; |
| 217 box = box->nextRootBox()) { | 217 box = box->nextRootBox()) { |
| 218 count++; | 218 count++; |
| 219 if (box == stopRootInlineBox) { | 219 if (box == stopRootInlineBox) { |
| 220 if (found) | 220 if (found) |
| 221 *found = true; | 221 *found = true; |
| 222 break; | 222 break; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 236 if (recursiveFound) { | 236 if (recursiveFound) { |
| 237 if (found) | 237 if (found) |
| 238 *found = true; | 238 *found = true; |
| 239 break; | 239 break; |
| 240 } | 240 } |
| 241 } | 241 } |
| 242 return count; | 242 return count; |
| 243 } | 243 } |
| 244 | 244 |
| 245 static void clearTruncation(LayoutBlockFlow* blockFlow) { | 245 static void clearTruncation(LayoutBlockFlow* blockFlow) { |
| 246 if (blockFlow->style()->visibility() != EVisibility::Visible) | 246 if (blockFlow->style()->visibility() != EVisibility::kVisible) |
| 247 return; | 247 return; |
| 248 if (blockFlow->childrenInline() && blockFlow->hasMarkupTruncation()) { | 248 if (blockFlow->childrenInline() && blockFlow->hasMarkupTruncation()) { |
| 249 blockFlow->setHasMarkupTruncation(false); | 249 blockFlow->setHasMarkupTruncation(false); |
| 250 for (RootInlineBox* box = blockFlow->firstRootBox(); box; | 250 for (RootInlineBox* box = blockFlow->firstRootBox(); box; |
| 251 box = box->nextRootBox()) | 251 box = box->nextRootBox()) |
| 252 box->clearTruncation(); | 252 box->clearTruncation(); |
| 253 return; | 253 return; |
| 254 } | 254 } |
| 255 for (LayoutObject* obj = blockFlow->firstChild(); obj; | 255 for (LayoutObject* obj = blockFlow->firstChild(); obj; |
| 256 obj = obj->nextSibling()) { | 256 obj = obj->nextSibling()) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 if (marginLeft.isFixed()) | 290 if (marginLeft.isFixed()) |
| 291 margin += marginLeft.value(); | 291 margin += marginLeft.value(); |
| 292 if (marginRight.isFixed()) | 292 if (marginRight.isFixed()) |
| 293 margin += marginRight.value(); | 293 margin += marginRight.value(); |
| 294 return margin; | 294 return margin; |
| 295 } | 295 } |
| 296 | 296 |
| 297 static bool childDoesNotAffectWidthOrFlexing(LayoutObject* child) { | 297 static bool childDoesNotAffectWidthOrFlexing(LayoutObject* child) { |
| 298 // Positioned children and collapsed children don't affect the min/max width. | 298 // Positioned children and collapsed children don't affect the min/max width. |
| 299 return child->isOutOfFlowPositioned() || | 299 return child->isOutOfFlowPositioned() || |
| 300 child->style()->visibility() == EVisibility::Collapse; | 300 child->style()->visibility() == EVisibility::kCollapse; |
| 301 } | 301 } |
| 302 | 302 |
| 303 static LayoutUnit contentWidthForChild(LayoutBox* child) { | 303 static LayoutUnit contentWidthForChild(LayoutBox* child) { |
| 304 if (child->hasOverrideLogicalContentWidth()) | 304 if (child->hasOverrideLogicalContentWidth()) |
| 305 return child->overrideLogicalContentWidth(); | 305 return child->overrideLogicalContentWidth(); |
| 306 return child->logicalWidth() - child->borderAndPaddingLogicalWidth(); | 306 return child->logicalWidth() - child->borderAndPaddingLogicalWidth(); |
| 307 } | 307 } |
| 308 | 308 |
| 309 static LayoutUnit contentHeightForChild(LayoutBox* child) { | 309 static LayoutUnit contentHeightForChild(LayoutBox* child) { |
| 310 if (child->hasOverrideLogicalContentHeight()) | 310 if (child->hasOverrideLogicalContentHeight()) |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 childLayer->setStaticInlinePosition(xPos); | 541 childLayer->setStaticInlinePosition(xPos); |
| 542 if (childLayer->staticBlockPosition() != yPos) { | 542 if (childLayer->staticBlockPosition() != yPos) { |
| 543 childLayer->setStaticBlockPosition(yPos); | 543 childLayer->setStaticBlockPosition(yPos); |
| 544 if (child->style()->hasStaticBlockPosition( | 544 if (child->style()->hasStaticBlockPosition( |
| 545 style()->isHorizontalWritingMode())) | 545 style()->isHorizontalWritingMode())) |
| 546 child->setChildNeedsLayout(MarkOnlyThis); | 546 child->setChildNeedsLayout(MarkOnlyThis); |
| 547 } | 547 } |
| 548 continue; | 548 continue; |
| 549 } | 549 } |
| 550 | 550 |
| 551 if (child->style()->visibility() == EVisibility::Collapse) { | 551 if (child->style()->visibility() == EVisibility::kCollapse) { |
| 552 // visibility: collapsed children do not participate in our positioning. | 552 // visibility: collapsed children do not participate in our positioning. |
| 553 // But we need to lay them down. | 553 // But we need to lay them down. |
| 554 child->layoutIfNeeded(); | 554 child->layoutIfNeeded(); |
| 555 continue; | 555 continue; |
| 556 } | 556 } |
| 557 | 557 |
| 558 SubtreeLayoutScope layoutScope(*child); | 558 SubtreeLayoutScope layoutScope(*child); |
| 559 | 559 |
| 560 // We need to see if this child's height will change, since we make block | 560 // We need to see if this child's height will change, since we make block |
| 561 // elements fill the height of a containing box by default. We cannot | 561 // elements fill the height of a containing box by default. We cannot |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 665 // If we just couldn't grow/shrink any more, then it's time to | 665 // If we just couldn't grow/shrink any more, then it's time to |
| 666 // transition to the next flex group. | 666 // transition to the next flex group. |
| 667 groupRemainingSpace = LayoutUnit(); | 667 groupRemainingSpace = LayoutUnit(); |
| 668 continue; | 668 continue; |
| 669 } | 669 } |
| 670 | 670 |
| 671 // Now distribute the space to objects. | 671 // Now distribute the space to objects. |
| 672 for (LayoutBox* child = iterator.first(); | 672 for (LayoutBox* child = iterator.first(); |
| 673 child && spaceAvailableThisPass && totalFlex; | 673 child && spaceAvailableThisPass && totalFlex; |
| 674 child = iterator.next()) { | 674 child = iterator.next()) { |
| 675 if (child->style()->visibility() == EVisibility::Collapse) | 675 if (child->style()->visibility() == EVisibility::kCollapse) |
| 676 continue; | 676 continue; |
| 677 | 677 |
| 678 if (allowedChildFlex(child, expanding, i)) { | 678 if (allowedChildFlex(child, expanding, i)) { |
| 679 LayoutUnit spaceAdd = | 679 LayoutUnit spaceAdd = |
| 680 LayoutUnit(spaceAvailableThisPass * | 680 LayoutUnit(spaceAvailableThisPass * |
| 681 (child->style()->boxFlex() / totalFlex)); | 681 (child->style()->boxFlex() / totalFlex)); |
| 682 if (spaceAdd) { | 682 if (spaceAdd) { |
| 683 child->setOverrideLogicalContentWidth( | 683 child->setOverrideLogicalContentWidth( |
| 684 contentWidthForChild(child) + spaceAdd); | 684 contentWidthForChild(child) + spaceAdd); |
| 685 flexingChildren = true; | 685 flexingChildren = true; |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 827 continue; | 827 continue; |
| 828 } | 828 } |
| 829 | 829 |
| 830 SubtreeLayoutScope layoutScope(*child); | 830 SubtreeLayoutScope layoutScope(*child); |
| 831 if (!haveLineClamp && | 831 if (!haveLineClamp && |
| 832 (relayoutChildren || (child->isAtomicInlineLevel() && | 832 (relayoutChildren || (child->isAtomicInlineLevel() && |
| 833 (child->style()->width().isPercentOrCalc() || | 833 (child->style()->width().isPercentOrCalc() || |
| 834 child->style()->height().isPercentOrCalc())))) | 834 child->style()->height().isPercentOrCalc())))) |
| 835 layoutScope.setChildNeedsLayout(child); | 835 layoutScope.setChildNeedsLayout(child); |
| 836 | 836 |
| 837 if (child->style()->visibility() == EVisibility::Collapse) { | 837 if (child->style()->visibility() == EVisibility::kCollapse) { |
| 838 // visibility: collapsed children do not participate in our positioning. | 838 // visibility: collapsed children do not participate in our positioning. |
| 839 // But we need to lay them down. | 839 // But we need to lay them down. |
| 840 child->layoutIfNeeded(); | 840 child->layoutIfNeeded(); |
| 841 continue; | 841 continue; |
| 842 } | 842 } |
| 843 | 843 |
| 844 // Compute the child's vertical margins. | 844 // Compute the child's vertical margins. |
| 845 child->computeAndSetBlockDirectionMargins(this); | 845 child->computeAndSetBlockDirectionMargins(this); |
| 846 | 846 |
| 847 // Add in the child's marginTop to our height. | 847 // Add in the child's marginTop to our height. |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1130 LayoutUnit newHeight( | 1130 LayoutUnit newHeight( |
| 1131 getHeightForLineCount(blockChild, numVisibleLines, true, dummyCount)); | 1131 getHeightForLineCount(blockChild, numVisibleLines, true, dummyCount)); |
| 1132 if (newHeight == child->size().height()) | 1132 if (newHeight == child->size().height()) |
| 1133 continue; | 1133 continue; |
| 1134 | 1134 |
| 1135 child->setOverrideLogicalContentHeight(newHeight - | 1135 child->setOverrideLogicalContentHeight(newHeight - |
| 1136 child->borderAndPaddingHeight()); | 1136 child->borderAndPaddingHeight()); |
| 1137 child->forceChildLayout(); | 1137 child->forceChildLayout(); |
| 1138 | 1138 |
| 1139 // FIXME: For now don't support RTL. | 1139 // FIXME: For now don't support RTL. |
| 1140 if (style()->direction() != TextDirection::Ltr) | 1140 if (style()->direction() != TextDirection::kLtr) |
| 1141 continue; | 1141 continue; |
| 1142 | 1142 |
| 1143 // Get the last line | 1143 // Get the last line |
| 1144 RootInlineBox* lastLine = lineAtIndex(blockChild, lineCount - 1); | 1144 RootInlineBox* lastLine = lineAtIndex(blockChild, lineCount - 1); |
| 1145 if (!lastLine) | 1145 if (!lastLine) |
| 1146 continue; | 1146 continue; |
| 1147 | 1147 |
| 1148 RootInlineBox* lastVisibleLine = | 1148 RootInlineBox* lastVisibleLine = |
| 1149 lineAtIndex(blockChild, numVisibleLines - 1); | 1149 lineAtIndex(blockChild, numVisibleLines - 1); |
| 1150 if (!lastVisibleLine) | 1150 if (!lastVisibleLine) |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1265 if (minHeight.isFixed() || minHeight.isAuto()) { | 1265 if (minHeight.isFixed() || minHeight.isAuto()) { |
| 1266 LayoutUnit minHeight(child->style()->minHeight().value()); | 1266 LayoutUnit minHeight(child->style()->minHeight().value()); |
| 1267 LayoutUnit height = contentHeightForChild(child); | 1267 LayoutUnit height = contentHeightForChild(child); |
| 1268 LayoutUnit allowedShrinkage = (minHeight - height).clampPositiveToZero(); | 1268 LayoutUnit allowedShrinkage = (minHeight - height).clampPositiveToZero(); |
| 1269 return allowedShrinkage; | 1269 return allowedShrinkage; |
| 1270 } | 1270 } |
| 1271 return LayoutUnit(); | 1271 return LayoutUnit(); |
| 1272 } | 1272 } |
| 1273 | 1273 |
| 1274 } // namespace blink | 1274 } // namespace blink |
| OLD | NEW |