OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 28 matching lines...) Expand all Loading... |
39 | 39 |
40 namespace WebCore { | 40 namespace WebCore { |
41 | 41 |
42 RenderFlexibleBox::OrderIterator::OrderIterator(const RenderFlexibleBox* flexibl
eBox) | 42 RenderFlexibleBox::OrderIterator::OrderIterator(const RenderFlexibleBox* flexibl
eBox) |
43 : m_flexibleBox(flexibleBox) | 43 : m_flexibleBox(flexibleBox) |
44 , m_currentChild(0) | 44 , m_currentChild(0) |
45 , m_orderValuesIterator(0) | 45 , m_orderValuesIterator(0) |
46 { | 46 { |
47 } | 47 } |
48 | 48 |
49 void RenderFlexibleBox::OrderIterator::setOrderValues(Vector<int>& orderValues) | |
50 { | |
51 reset(); | |
52 m_orderValues.clear(); | |
53 | |
54 if (orderValues.isEmpty()) | |
55 return; | |
56 | |
57 std::sort(orderValues.begin(), orderValues.end()); | |
58 | |
59 | |
60 // This is inefficient if there are many repeated values, but | |
61 // saves a lot of allocations when the values are unique. By far, | |
62 // the common case is that there's exactly one item in the list | |
63 // (the default order value of 0). | |
64 m_orderValues.reserveInitialCapacity(orderValues.size()); | |
65 | |
66 int previous = orderValues[0]; | |
67 m_orderValues.append(previous); | |
68 for (size_t i = 1; i < orderValues.size(); ++i) { | |
69 int current = orderValues[i]; | |
70 if (current == previous) | |
71 continue; | |
72 m_orderValues.append(current); | |
73 previous = current; | |
74 } | |
75 m_orderValues.shrinkToFit(); | |
76 } | |
77 | |
78 RenderBox* RenderFlexibleBox::OrderIterator::first() | 49 RenderBox* RenderFlexibleBox::OrderIterator::first() |
79 { | 50 { |
80 reset(); | 51 reset(); |
81 return next(); | 52 return next(); |
82 } | 53 } |
83 | 54 |
84 RenderBox* RenderFlexibleBox::OrderIterator::next() | 55 RenderBox* RenderFlexibleBox::OrderIterator::next() |
85 { | 56 { |
86 do { | 57 do { |
87 if (!m_currentChild) { | 58 if (!m_currentChild) { |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 RenderFlowThread* flowThread = flowThreadContainingBlock(); | 326 RenderFlowThread* flowThread = flowThreadContainingBlock(); |
356 if (logicalWidthChangedInRegions(flowThread)) | 327 if (logicalWidthChangedInRegions(flowThread)) |
357 relayoutChildren = true; | 328 relayoutChildren = true; |
358 if (updateRegionsAndShapesLogicalSize(flowThread)) | 329 if (updateRegionsAndShapesLogicalSize(flowThread)) |
359 relayoutChildren = true; | 330 relayoutChildren = true; |
360 | 331 |
361 m_numberOfInFlowChildrenOnFirstLine = -1; | 332 m_numberOfInFlowChildrenOnFirstLine = -1; |
362 | 333 |
363 RenderBlock::startDelayUpdateScrollInfo(); | 334 RenderBlock::startDelayUpdateScrollInfo(); |
364 | 335 |
365 Vector<LineContext> lineContexts; | 336 prepareOrderIteratorAndMargins(); |
366 Vector<int> orderValues; | |
367 computeMainAxisPreferredSizes(orderValues); | |
368 m_orderIterator.setOrderValues(orderValues); | |
369 | 337 |
370 ChildFrameRects oldChildRects; | 338 ChildFrameRects oldChildRects; |
371 appendChildFrameRects(oldChildRects); | 339 appendChildFrameRects(oldChildRects); |
| 340 |
| 341 Vector<LineContext> lineContexts; |
372 layoutFlexItems(relayoutChildren, lineContexts); | 342 layoutFlexItems(relayoutChildren, lineContexts); |
373 | 343 |
374 updateLogicalHeight(); | 344 updateLogicalHeight(); |
375 repositionLogicalHeightDependentFlexItems(lineContexts); | 345 repositionLogicalHeightDependentFlexItems(lineContexts); |
376 | 346 |
377 RenderBlock::finishDelayUpdateScrollInfo(); | 347 RenderBlock::finishDelayUpdateScrollInfo(); |
378 | 348 |
379 if (logicalHeight() != previousHeight) | 349 if (logicalHeight() != previousHeight) |
380 relayoutChildren = true; | 350 relayoutChildren = true; |
381 | 351 |
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
932 } | 902 } |
933 | 903 |
934 LayoutUnit RenderFlexibleBox::computeChildMarginValue(Length margin, RenderView*
view) | 904 LayoutUnit RenderFlexibleBox::computeChildMarginValue(Length margin, RenderView*
view) |
935 { | 905 { |
936 // When resolving the margins, we use the content size for resolving percent
and calc (for percents in calc expressions) margins. | 906 // When resolving the margins, we use the content size for resolving percent
and calc (for percents in calc expressions) margins. |
937 // Fortunately, percent margins are always computed with respect to the bloc
k's width, even for margin-top and margin-bottom. | 907 // Fortunately, percent margins are always computed with respect to the bloc
k's width, even for margin-top and margin-bottom. |
938 LayoutUnit availableSize = contentLogicalWidth(); | 908 LayoutUnit availableSize = contentLogicalWidth(); |
939 return minimumValueForLength(margin, availableSize, view); | 909 return minimumValueForLength(margin, availableSize, view); |
940 } | 910 } |
941 | 911 |
942 void RenderFlexibleBox::computeMainAxisPreferredSizes(Vector<int>& orderValues) | 912 void RenderFlexibleBox::prepareOrderIteratorAndMargins() |
943 { | 913 { |
944 RenderView* renderView = view(); | 914 RenderView* renderView = view(); |
945 bool anyChildHasDefaultOrderValue = false; | 915 bool anyChildHasDefaultOrderValue = false; |
946 | 916 |
| 917 m_orderIterator.reset(); |
| 918 m_orderIterator.m_orderValues.resize(0); |
| 919 |
947 for (RenderBox* child = firstChildBox(); child; child = child->nextSiblingBo
x()) { | 920 for (RenderBox* child = firstChildBox(); child; child = child->nextSiblingBo
x()) { |
948 // Avoid growing the vector for the common-case default value of 0. | 921 // Avoid growing the vector for the common-case default value of 0. |
949 if (int order = child->style()->order()) | 922 if (int order = child->style()->order()) |
950 orderValues.append(child->style()->order()); | 923 m_orderIterator.m_orderValues.append(child->style()->order()); |
951 else | 924 else |
952 anyChildHasDefaultOrderValue = true; | 925 anyChildHasDefaultOrderValue = true; |
953 | 926 |
954 if (child->isOutOfFlowPositioned()) | 927 if (child->isOutOfFlowPositioned()) |
955 continue; | 928 continue; |
956 | 929 |
957 // Before running the flex algorithm, 'auto' has a margin of 0. | 930 // Before running the flex algorithm, 'auto' has a margin of 0. |
958 // Also, if we're not auto sizing, we don't do a layout that computes th
e start/end margins. | 931 // Also, if we're not auto sizing, we don't do a layout that computes th
e start/end margins. |
959 if (isHorizontalFlow()) { | 932 if (isHorizontalFlow()) { |
960 child->setMarginLeft(computeChildMarginValue(child->style()->marginL
eft(), renderView)); | 933 child->setMarginLeft(computeChildMarginValue(child->style()->marginL
eft(), renderView)); |
961 child->setMarginRight(computeChildMarginValue(child->style()->margin
Right(), renderView)); | 934 child->setMarginRight(computeChildMarginValue(child->style()->margin
Right(), renderView)); |
962 } else { | 935 } else { |
963 child->setMarginTop(computeChildMarginValue(child->style()->marginTo
p(), renderView)); | 936 child->setMarginTop(computeChildMarginValue(child->style()->marginTo
p(), renderView)); |
964 child->setMarginBottom(computeChildMarginValue(child->style()->margi
nBottom(), renderView)); | 937 child->setMarginBottom(computeChildMarginValue(child->style()->margi
nBottom(), renderView)); |
965 } | 938 } |
966 } | 939 } |
967 | 940 |
968 if (anyChildHasDefaultOrderValue) { | 941 if (anyChildHasDefaultOrderValue) { |
969 // Avoid growing the vector to the default capacity of 16 if we're only
going to put one item in it. | 942 // Avoid growing the vector to the default capacity of 16 if we're only
going to put one item in it. |
970 if (orderValues.isEmpty()) | 943 if (m_orderIterator.m_orderValues.isEmpty()) |
971 orderValues.reserveInitialCapacity(1); | 944 m_orderIterator.m_orderValues.reserveInitialCapacity(1); |
972 orderValues.append(0); | 945 m_orderIterator.m_orderValues.append(0); |
| 946 } else if (m_orderIterator.m_orderValues.isEmpty()) { |
| 947 m_orderIterator.m_orderValues.clear(); |
| 948 return; |
973 } | 949 } |
| 950 |
| 951 std::sort(m_orderIterator.m_orderValues.begin(), m_orderIterator.m_orderValu
es.end()); |
| 952 |
| 953 int previous = m_orderIterator.m_orderValues[0]; |
| 954 int uniqueCount = 1; |
| 955 for (size_t i = 1; i < m_orderIterator.m_orderValues.size(); ++i) { |
| 956 int current = m_orderIterator.m_orderValues[i]; |
| 957 if (current == previous) |
| 958 continue; |
| 959 m_orderIterator.m_orderValues[uniqueCount++] = current; |
| 960 previous = current; |
| 961 } |
| 962 m_orderIterator.m_orderValues.shrinkCapacity(uniqueCount); |
974 } | 963 } |
975 | 964 |
976 LayoutUnit RenderFlexibleBox::adjustChildSizeForMinAndMax(RenderBox* child, Layo
utUnit childSize) | 965 LayoutUnit RenderFlexibleBox::adjustChildSizeForMinAndMax(RenderBox* child, Layo
utUnit childSize) |
977 { | 966 { |
978 Length max = isHorizontalFlow() ? child->style()->maxWidth() : child->style(
)->maxHeight(); | 967 Length max = isHorizontalFlow() ? child->style()->maxWidth() : child->style(
)->maxHeight(); |
979 if (max.isSpecifiedOrIntrinsic()) { | 968 if (max.isSpecifiedOrIntrinsic()) { |
980 LayoutUnit maxExtent = computeMainAxisExtentForChild(child, MaxSize, max
); | 969 LayoutUnit maxExtent = computeMainAxisExtentForChild(child, MaxSize, max
); |
981 if (maxExtent != -1 && childSize > maxExtent) | 970 if (maxExtent != -1 && childSize > maxExtent) |
982 childSize = maxExtent; | 971 childSize = maxExtent; |
983 } | 972 } |
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1494 ASSERT(child); | 1483 ASSERT(child); |
1495 LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisE
xtent; | 1484 LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisE
xtent; |
1496 LayoutUnit originalOffset = lineContexts[lineNumber].crossAxisOffset
- crossAxisStartEdge; | 1485 LayoutUnit originalOffset = lineContexts[lineNumber].crossAxisOffset
- crossAxisStartEdge; |
1497 LayoutUnit newOffset = contentExtent - originalOffset - lineCrossAxi
sExtent; | 1486 LayoutUnit newOffset = contentExtent - originalOffset - lineCrossAxi
sExtent; |
1498 adjustAlignmentForChild(child, newOffset - originalOffset); | 1487 adjustAlignmentForChild(child, newOffset - originalOffset); |
1499 } | 1488 } |
1500 } | 1489 } |
1501 } | 1490 } |
1502 | 1491 |
1503 } | 1492 } |
OLD | NEW |