Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(693)

Side by Side Diff: third_party/WebKit/Source/core/layout/LayoutDeprecatedFlexibleBox.cpp

Issue 1647313003: Continue converting to explicit LayoutUnit constructors (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@explicitContstructors
Patch Set: Add TODO Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 { 140 {
141 } 141 }
142 142
143 static LayoutUnit marginWidthForChild(LayoutBox* child) 143 static LayoutUnit marginWidthForChild(LayoutBox* child)
144 { 144 {
145 // A margin basically has three types: fixed, percentage, and auto (variable ). 145 // A margin basically has three types: fixed, percentage, and auto (variable ).
146 // Auto and percentage margins simply become 0 when computing min/max width. 146 // Auto and percentage margins simply become 0 when computing min/max width.
147 // Fixed margins can be added in as is. 147 // Fixed margins can be added in as is.
148 Length marginLeft = child->style()->marginLeft(); 148 Length marginLeft = child->style()->marginLeft();
149 Length marginRight = child->style()->marginRight(); 149 Length marginRight = child->style()->marginRight();
150 LayoutUnit margin = 0; 150 LayoutUnit margin;
151 if (marginLeft.isFixed()) 151 if (marginLeft.isFixed())
152 margin += marginLeft.value(); 152 margin += marginLeft.value();
153 if (marginRight.isFixed()) 153 if (marginRight.isFixed())
154 margin += marginRight.value(); 154 margin += marginRight.value();
155 return margin; 155 return margin;
156 } 156 }
157 157
158 static bool childDoesNotAffectWidthOrFlexing(LayoutObject* child) 158 static bool childDoesNotAffectWidthOrFlexing(LayoutObject* child)
159 { 159 {
160 // Positioned children and collapsed children don't affect the min/max width . 160 // Positioned children and collapsed children don't affect the min/max width .
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 continue; 204 continue;
205 205
206 LayoutUnit margin = marginWidthForChild(child); 206 LayoutUnit margin = marginWidthForChild(child);
207 minLogicalWidth += child->minPreferredLogicalWidth() + margin; 207 minLogicalWidth += child->minPreferredLogicalWidth() + margin;
208 maxLogicalWidth += child->maxPreferredLogicalWidth() + margin; 208 maxLogicalWidth += child->maxPreferredLogicalWidth() + margin;
209 } 209 }
210 } 210 }
211 211
212 maxLogicalWidth = std::max(minLogicalWidth, maxLogicalWidth); 212 maxLogicalWidth = std::max(minLogicalWidth, maxLogicalWidth);
213 213
214 LayoutUnit scrollbarWidth = intrinsicScrollbarLogicalWidth(); 214 LayoutUnit scrollbarWidth(intrinsicScrollbarLogicalWidth());
215 maxLogicalWidth += scrollbarWidth; 215 maxLogicalWidth += scrollbarWidth;
216 minLogicalWidth += scrollbarWidth; 216 minLogicalWidth += scrollbarWidth;
217 } 217 }
218 218
219 void LayoutDeprecatedFlexibleBox::layoutBlock(bool relayoutChildren) 219 void LayoutDeprecatedFlexibleBox::layoutBlock(bool relayoutChildren)
220 { 220 {
221 ASSERT(needsLayout()); 221 ASSERT(needsLayout());
222 222
223 if (!relayoutChildren && simplifiedLayout()) 223 if (!relayoutChildren && simplifiedLayout())
224 return; 224 return;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 } 290 }
291 } 291 }
292 } 292 }
293 293
294 void LayoutDeprecatedFlexibleBox::layoutHorizontalBox(bool relayoutChildren) 294 void LayoutDeprecatedFlexibleBox::layoutHorizontalBox(bool relayoutChildren)
295 { 295 {
296 LayoutUnit toAdd = borderBottom() + paddingBottom() + horizontalScrollbarHei ght(); 296 LayoutUnit toAdd = borderBottom() + paddingBottom() + horizontalScrollbarHei ght();
297 LayoutUnit yPos = borderTop() + paddingTop(); 297 LayoutUnit yPos = borderTop() + paddingTop();
298 LayoutUnit xPos = borderLeft() + paddingLeft(); 298 LayoutUnit xPos = borderLeft() + paddingLeft();
299 bool heightSpecified = false; 299 bool heightSpecified = false;
300 LayoutUnit oldHeight = 0; 300 LayoutUnit oldHeight;
301 301
302 LayoutUnit remainingSpace = 0; 302 LayoutUnit remainingSpace;
303 303
304 304
305 FlexBoxIterator iterator(this); 305 FlexBoxIterator iterator(this);
306 unsigned highestFlexGroup = 0; 306 unsigned highestFlexGroup = 0;
307 unsigned lowestFlexGroup = 0; 307 unsigned lowestFlexGroup = 0;
308 bool haveFlex = false, flexingChildren = false; 308 bool haveFlex = false, flexingChildren = false;
309 gatherFlexChildrenInfo(iterator, relayoutChildren, highestFlexGroup, lowestF lexGroup, haveFlex); 309 gatherFlexChildrenInfo(iterator, relayoutChildren, highestFlexGroup, lowestF lexGroup, haveFlex);
310 310
311 LayoutBlock::startDelayUpdateScrollInfo(); 311 LayoutBlock::startDelayUpdateScrollInfo();
312 312
313 // We do 2 passes. The first pass is simply to lay everyone out at 313 // We do 2 passes. The first pass is simply to lay everyone out at
314 // their preferred widths. The second pass handles flexing the children. 314 // their preferred widths. The second pass handles flexing the children.
315 do { 315 do {
316 // Reset our height. 316 // Reset our height.
317 setHeight(yPos); 317 setHeight(yPos);
318 318
319 xPos = borderLeft() + paddingLeft(); 319 xPos = borderLeft() + paddingLeft();
320 320
321 // Our first pass is done without flexing. We simply lay the children 321 // Our first pass is done without flexing. We simply lay the children
322 // out within the box. We have to do a layout first in order to determi ne 322 // out within the box. We have to do a layout first in order to determi ne
323 // our box's intrinsic height. 323 // our box's intrinsic height.
324 LayoutUnit maxAscent = 0, maxDescent = 0; 324 LayoutUnit maxAscent;
325 LayoutUnit maxDescent;
325 for (LayoutBox* child = iterator.first(); child; child = iterator.next() ) { 326 for (LayoutBox* child = iterator.first(); child; child = iterator.next() ) {
326 if (child->isOutOfFlowPositioned()) 327 if (child->isOutOfFlowPositioned())
327 continue; 328 continue;
328 329
329 SubtreeLayoutScope layoutScope(*child); 330 SubtreeLayoutScope layoutScope(*child);
330 // TODO(jchaffraix): It seems incorrect to check isAtomicInlineLevel in this file. 331 // TODO(jchaffraix): It seems incorrect to check isAtomicInlineLevel in this file.
331 // We probably want to check if the element is replaced. 332 // We probably want to check if the element is replaced.
332 if (relayoutChildren || (child->isAtomicInlineLevel() && (child->sty le()->width().hasPercent() || child->style()->height().hasPercent()))) 333 if (relayoutChildren || (child->isAtomicInlineLevel() && (child->sty le()->width().hasPercent() || child->style()->height().hasPercent())))
333 layoutScope.setChildNeedsLayout(child); 334 layoutScope.setChildNeedsLayout(child);
334 335
335 // Compute the child's vertical margins. 336 // Compute the child's vertical margins.
336 child->computeAndSetBlockDirectionMargins(this); 337 child->computeAndSetBlockDirectionMargins(this);
337 338
338 if (!child->needsLayout()) 339 if (!child->needsLayout())
339 child->markForPaginationRelayoutIfNeeded(layoutScope); 340 child->markForPaginationRelayoutIfNeeded(layoutScope);
340 341
341 // Now do the layout. 342 // Now do the layout.
342 child->layoutIfNeeded(); 343 child->layoutIfNeeded();
343 344
344 // Update our height and overflow height. 345 // Update our height and overflow height.
345 if (style()->boxAlign() == BBASELINE) { 346 if (style()->boxAlign() == BBASELINE) {
346 LayoutUnit ascent = child->firstLineBoxBaseline(); 347 LayoutUnit ascent(child->firstLineBoxBaseline());
347 if (ascent == -1) 348 if (ascent == -1)
348 ascent = child->size().height() + child->marginBottom(); 349 ascent = child->size().height() + child->marginBottom();
349 ascent += child->marginTop(); 350 ascent += child->marginTop();
350 LayoutUnit descent = (child->size().height() + child->marginHeig ht()) - ascent; 351 LayoutUnit descent = (child->size().height() + child->marginHeig ht()) - ascent;
351 352
352 // Update our maximum ascent. 353 // Update our maximum ascent.
353 maxAscent = std::max(maxAscent, ascent); 354 maxAscent = std::max(maxAscent, ascent);
354 355
355 // Update our maximum descent. 356 // Update our maximum descent.
356 maxDescent = std::max(maxDescent, descent); 357 maxDescent = std::max(maxDescent, descent);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 if (!child->needsLayout()) 413 if (!child->needsLayout())
413 child->markForPaginationRelayoutIfNeeded(layoutScope); 414 child->markForPaginationRelayoutIfNeeded(layoutScope);
414 415
415 child->layoutIfNeeded(); 416 child->layoutIfNeeded();
416 417
417 // We can place the child now, using our value of box-align. 418 // We can place the child now, using our value of box-align.
418 xPos += child->marginLeft(); 419 xPos += child->marginLeft();
419 LayoutUnit childY = yPos; 420 LayoutUnit childY = yPos;
420 switch (style()->boxAlign()) { 421 switch (style()->boxAlign()) {
421 case BCENTER: 422 case BCENTER:
422 childY += child->marginTop() + ((contentHeight() - (child->size( ).height() + child->marginHeight())) / 2).clampToZero(); 423 childY += child->marginTop() + ((contentHeight() - (child->size( ).height() + child->marginHeight())) / 2).clampNegativeToZero();
423 break; 424 break;
424 case BBASELINE: { 425 case BBASELINE: {
425 LayoutUnit ascent = child->firstLineBoxBaseline(); 426 LayoutUnit ascent(child->firstLineBoxBaseline());
426 if (ascent == -1) 427 if (ascent == -1)
427 ascent = child->size().height() + child->marginBottom(); 428 ascent = child->size().height() + child->marginBottom();
428 ascent += child->marginTop(); 429 ascent += child->marginTop();
429 childY += child->marginTop() + (maxAscent - ascent); 430 childY += child->marginTop() + (maxAscent - ascent);
430 break; 431 break;
431 } 432 }
432 case BEND: 433 case BEND:
433 childY += contentHeight() - child->marginBottom() - child->size( ).height(); 434 childY += contentHeight() - child->marginBottom() - child->size( ).height();
434 break; 435 break;
435 default: // BSTART 436 default: // BSTART
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 LayoutUnit allowedFlex = allowedChildFlex(child, expandi ng, i); 478 LayoutUnit allowedFlex = allowedChildFlex(child, expandi ng, i);
478 if (allowedFlex) { 479 if (allowedFlex) {
479 LayoutUnit projectedFlex = (allowedFlex == LayoutUni t::max()) ? allowedFlex : LayoutUnit(allowedFlex * (totalFlex / child->style()-> boxFlex())); 480 LayoutUnit projectedFlex = (allowedFlex == LayoutUni t::max()) ? allowedFlex : LayoutUnit(allowedFlex * (totalFlex / child->style()-> boxFlex()));
480 spaceAvailableThisPass = expanding ? std::min(spaceA vailableThisPass, projectedFlex) : std::max(spaceAvailableThisPass, projectedFle x); 481 spaceAvailableThisPass = expanding ? std::min(spaceA vailableThisPass, projectedFlex) : std::max(spaceAvailableThisPass, projectedFle x);
481 } 482 }
482 } 483 }
483 484
484 // The flex groups may not have any flexible objects this ti me around. 485 // The flex groups may not have any flexible objects this ti me around.
485 if (!spaceAvailableThisPass || totalFlex == 0.0f) { 486 if (!spaceAvailableThisPass || totalFlex == 0.0f) {
486 // If we just couldn't grow/shrink any more, then it's t ime to transition to the next flex group. 487 // If we just couldn't grow/shrink any more, then it's t ime to transition to the next flex group.
487 groupRemainingSpace = 0; 488 groupRemainingSpace = LayoutUnit();
488 continue; 489 continue;
489 } 490 }
490 491
491 // Now distribute the space to objects. 492 // Now distribute the space to objects.
492 for (LayoutBox* child = iterator.first(); child && spaceAvai lableThisPass && totalFlex; child = iterator.next()) { 493 for (LayoutBox* child = iterator.first(); child && spaceAvai lableThisPass && totalFlex; child = iterator.next()) {
493 if (child->style()->visibility() == COLLAPSE) 494 if (child->style()->visibility() == COLLAPSE)
494 continue; 495 continue;
495 496
496 if (allowedChildFlex(child, expanding, i)) { 497 if (allowedChildFlex(child, expanding, i)) {
497 LayoutUnit spaceAdd = LayoutUnit(spaceAvailableThisP ass * (child->style()->boxFlex() / totalFlex)); 498 LayoutUnit spaceAdd = LayoutUnit(spaceAvailableThisP ass * (child->style()->boxFlex() / totalFlex));
498 if (spaceAdd) { 499 if (spaceAdd) {
499 child->setOverrideLogicalContentWidth(contentWid thForChild(child) + spaceAdd); 500 child->setOverrideLogicalContentWidth(contentWid thForChild(child) + spaceAdd);
500 flexingChildren = true; 501 flexingChildren = true;
501 relayoutChildren = true; 502 relayoutChildren = true;
502 } 503 }
503 504
504 spaceAvailableThisPass -= spaceAdd; 505 spaceAvailableThisPass -= spaceAdd;
505 remainingSpace -= spaceAdd; 506 remainingSpace -= spaceAdd;
506 groupRemainingSpace -= spaceAdd; 507 groupRemainingSpace -= spaceAdd;
507 508
508 totalFlex -= child->style()->boxFlex(); 509 totalFlex -= child->style()->boxFlex();
509 } 510 }
510 } 511 }
511 if (groupRemainingSpace == groupRemainingSpaceAtBeginning) { 512 if (groupRemainingSpace == groupRemainingSpaceAtBeginning) {
512 // This is not advancing, avoid getting stuck by distrib uting the remaining pixels. 513 // This is not advancing, avoid getting stuck by distrib uting the remaining pixels.
513 LayoutUnit spaceAdd = groupRemainingSpace > 0 ? 1 : -1; 514 LayoutUnit spaceAdd = LayoutUnit(groupRemainingSpace > 0 ? 1 : -1);
514 for (LayoutBox* child = iterator.first(); child && group RemainingSpace; child = iterator.next()) { 515 for (LayoutBox* child = iterator.first(); child && group RemainingSpace; child = iterator.next()) {
515 if (allowedChildFlex(child, expanding, i)) { 516 if (allowedChildFlex(child, expanding, i)) {
516 child->setOverrideLogicalContentWidth(contentWid thForChild(child) + spaceAdd); 517 child->setOverrideLogicalContentWidth(contentWid thForChild(child) + spaceAdd);
517 flexingChildren = true; 518 flexingChildren = true;
518 relayoutChildren = true; 519 relayoutChildren = true;
519 remainingSpace -= spaceAdd; 520 remainingSpace -= spaceAdd;
520 groupRemainingSpace -= spaceAdd; 521 groupRemainingSpace -= spaceAdd;
521 } 522 }
522 } 523 }
523 } 524 }
524 } while (absoluteValue(groupRemainingSpace) >= 1); 525 } while (absoluteValue(groupRemainingSpace) >= 1);
525 } 526 }
526 527
527 // We didn't find any children that could grow. 528 // We didn't find any children that could grow.
528 if (haveFlex && !flexingChildren) 529 if (haveFlex && !flexingChildren)
529 haveFlex = false; 530 haveFlex = false;
530 } 531 }
531 } while (haveFlex); 532 } while (haveFlex);
532 533
533 LayoutBlock::finishDelayUpdateScrollInfo(); 534 LayoutBlock::finishDelayUpdateScrollInfo();
534 535
535 if (remainingSpace > 0 && ((style()->isLeftToRightDirection() && style()->bo xPack() != Start) 536 if (remainingSpace > 0 && ((style()->isLeftToRightDirection() && style()->bo xPack() != Start)
536 || (!style()->isLeftToRightDirection() && style()->boxPack() != End))) { 537 || (!style()->isLeftToRightDirection() && style()->boxPack() != End))) {
537 // Children must be repositioned. 538 // Children must be repositioned.
538 LayoutUnit offset = 0; 539 LayoutUnit offset;
539 if (style()->boxPack() == Justify) { 540 if (style()->boxPack() == Justify) {
540 // Determine the total number of children. 541 // Determine the total number of children.
541 int totalChildren = 0; 542 int totalChildren = 0;
542 for (LayoutBox* child = iterator.first(); child; child = iterator.ne xt()) { 543 for (LayoutBox* child = iterator.first(); child; child = iterator.ne xt()) {
543 if (childDoesNotAffectWidthOrFlexing(child)) 544 if (childDoesNotAffectWidthOrFlexing(child))
544 continue; 545 continue;
545 ++totalChildren; 546 ++totalChildren;
546 } 547 }
547 548
548 // Iterate over the children and space them out according to the 549 // Iterate over the children and space them out according to the
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 // a height change, we revert our height back to the intrinsic height before returning. 585 // a height change, we revert our height back to the intrinsic height before returning.
585 if (heightSpecified) 586 if (heightSpecified)
586 setHeight(oldHeight); 587 setHeight(oldHeight);
587 } 588 }
588 589
589 void LayoutDeprecatedFlexibleBox::layoutVerticalBox(bool relayoutChildren) 590 void LayoutDeprecatedFlexibleBox::layoutVerticalBox(bool relayoutChildren)
590 { 591 {
591 LayoutUnit yPos = borderTop() + paddingTop(); 592 LayoutUnit yPos = borderTop() + paddingTop();
592 LayoutUnit toAdd = borderBottom() + paddingBottom() + horizontalScrollbarHei ght(); 593 LayoutUnit toAdd = borderBottom() + paddingBottom() + horizontalScrollbarHei ght();
593 bool heightSpecified = false; 594 bool heightSpecified = false;
594 LayoutUnit oldHeight = 0; 595 LayoutUnit oldHeight;
595 596
596 LayoutUnit remainingSpace = 0; 597 LayoutUnit remainingSpace;
597 598
598 FlexBoxIterator iterator(this); 599 FlexBoxIterator iterator(this);
599 unsigned highestFlexGroup = 0; 600 unsigned highestFlexGroup = 0;
600 unsigned lowestFlexGroup = 0; 601 unsigned lowestFlexGroup = 0;
601 bool haveFlex = false, flexingChildren = false; 602 bool haveFlex = false, flexingChildren = false;
602 gatherFlexChildrenInfo(iterator, relayoutChildren, highestFlexGroup, lowestF lexGroup, haveFlex); 603 gatherFlexChildrenInfo(iterator, relayoutChildren, highestFlexGroup, lowestF lexGroup, haveFlex);
603 604
604 // We confine the line clamp ugliness to vertical flexible boxes (thus keepi ng it out of 605 // We confine the line clamp ugliness to vertical flexible boxes (thus keepi ng it out of
605 // mainstream block layout); this is not really part of the XUL box model. 606 // mainstream block layout); this is not really part of the XUL box model.
606 bool haveLineClamp = !style()->lineClamp().isNone(); 607 bool haveLineClamp = !style()->lineClamp().isNone();
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
651 child->markForPaginationRelayoutIfNeeded(layoutScope); 652 child->markForPaginationRelayoutIfNeeded(layoutScope);
652 653
653 // Now do a layout. 654 // Now do a layout.
654 child->layoutIfNeeded(); 655 child->layoutIfNeeded();
655 656
656 // We can place the child now, using our value of box-align. 657 // We can place the child now, using our value of box-align.
657 LayoutUnit childX = borderLeft() + paddingLeft(); 658 LayoutUnit childX = borderLeft() + paddingLeft();
658 switch (style()->boxAlign()) { 659 switch (style()->boxAlign()) {
659 case BCENTER: 660 case BCENTER:
660 case BBASELINE: // Baseline just maps to center for vertical boxes 661 case BBASELINE: // Baseline just maps to center for vertical boxes
661 childX += child->marginLeft() + std::max<LayoutUnit>(LayoutUnit( ), (contentWidth() - (child->size().width() + child->marginWidth())) / 2); 662 childX += child->marginLeft() + ((contentWidth() - (child->size( ).width() + child->marginWidth())) / 2).clampNegativeToZero();
662 break; 663 break;
663 case BEND: 664 case BEND:
664 if (!style()->isLeftToRightDirection()) 665 if (!style()->isLeftToRightDirection())
665 childX += child->marginLeft(); 666 childX += child->marginLeft();
666 else 667 else
667 childX += contentWidth() - child->marginRight() - child->siz e().width(); 668 childX += contentWidth() - child->marginRight() - child->siz e().width();
668 break; 669 break;
669 default: // BSTART/BSTRETCH 670 default: // BSTART/BSTRETCH
670 if (style()->isLeftToRightDirection()) 671 if (style()->isLeftToRightDirection())
671 childX += child->marginLeft(); 672 childX += child->marginLeft();
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
731 LayoutUnit allowedFlex = allowedChildFlex(child, expandi ng, i); 732 LayoutUnit allowedFlex = allowedChildFlex(child, expandi ng, i);
732 if (allowedFlex) { 733 if (allowedFlex) {
733 LayoutUnit projectedFlex = (allowedFlex == LayoutUni t::max()) ? allowedFlex : static_cast<LayoutUnit>(allowedFlex * (totalFlex / chi ld->style()->boxFlex())); 734 LayoutUnit projectedFlex = (allowedFlex == LayoutUni t::max()) ? allowedFlex : static_cast<LayoutUnit>(allowedFlex * (totalFlex / chi ld->style()->boxFlex()));
734 spaceAvailableThisPass = expanding ? std::min(spaceA vailableThisPass, projectedFlex) : std::max(spaceAvailableThisPass, projectedFle x); 735 spaceAvailableThisPass = expanding ? std::min(spaceA vailableThisPass, projectedFlex) : std::max(spaceAvailableThisPass, projectedFle x);
735 } 736 }
736 } 737 }
737 738
738 // The flex groups may not have any flexible objects this ti me around. 739 // The flex groups may not have any flexible objects this ti me around.
739 if (!spaceAvailableThisPass || totalFlex == 0.0f) { 740 if (!spaceAvailableThisPass || totalFlex == 0.0f) {
740 // If we just couldn't grow/shrink any more, then it's t ime to transition to the next flex group. 741 // If we just couldn't grow/shrink any more, then it's t ime to transition to the next flex group.
741 groupRemainingSpace = 0; 742 groupRemainingSpace = LayoutUnit();
742 continue; 743 continue;
743 } 744 }
744 745
745 // Now distribute the space to objects. 746 // Now distribute the space to objects.
746 for (LayoutBox* child = iterator.first(); child && spaceAvai lableThisPass && totalFlex; child = iterator.next()) { 747 for (LayoutBox* child = iterator.first(); child && spaceAvai lableThisPass && totalFlex; child = iterator.next()) {
747 if (allowedChildFlex(child, expanding, i)) { 748 if (allowedChildFlex(child, expanding, i)) {
748 LayoutUnit spaceAdd = static_cast<LayoutUnit>(spaceA vailableThisPass * (child->style()->boxFlex() / totalFlex)); 749 LayoutUnit spaceAdd = static_cast<LayoutUnit>(spaceA vailableThisPass * (child->style()->boxFlex() / totalFlex));
749 if (spaceAdd) { 750 if (spaceAdd) {
750 child->setOverrideLogicalContentHeight(contentHe ightForChild(child) + spaceAdd); 751 child->setOverrideLogicalContentHeight(contentHe ightForChild(child) + spaceAdd);
751 flexingChildren = true; 752 flexingChildren = true;
752 relayoutChildren = true; 753 relayoutChildren = true;
753 } 754 }
754 755
755 spaceAvailableThisPass -= spaceAdd; 756 spaceAvailableThisPass -= spaceAdd;
756 remainingSpace -= spaceAdd; 757 remainingSpace -= spaceAdd;
757 groupRemainingSpace -= spaceAdd; 758 groupRemainingSpace -= spaceAdd;
758 759
759 totalFlex -= child->style()->boxFlex(); 760 totalFlex -= child->style()->boxFlex();
760 } 761 }
761 } 762 }
762 if (groupRemainingSpace == groupRemainingSpaceAtBeginning) { 763 if (groupRemainingSpace == groupRemainingSpaceAtBeginning) {
763 // This is not advancing, avoid getting stuck by distrib uting the remaining pixels. 764 // This is not advancing, avoid getting stuck by distrib uting the remaining pixels.
764 LayoutUnit spaceAdd = groupRemainingSpace > 0 ? 1 : -1; 765 LayoutUnit spaceAdd = LayoutUnit(groupRemainingSpace > 0 ? 1 : -1);
765 for (LayoutBox* child = iterator.first(); child && group RemainingSpace; child = iterator.next()) { 766 for (LayoutBox* child = iterator.first(); child && group RemainingSpace; child = iterator.next()) {
766 if (allowedChildFlex(child, expanding, i)) { 767 if (allowedChildFlex(child, expanding, i)) {
767 child->setOverrideLogicalContentHeight(contentHe ightForChild(child) + spaceAdd); 768 child->setOverrideLogicalContentHeight(contentHe ightForChild(child) + spaceAdd);
768 flexingChildren = true; 769 flexingChildren = true;
769 relayoutChildren = true; 770 relayoutChildren = true;
770 remainingSpace -= spaceAdd; 771 remainingSpace -= spaceAdd;
771 groupRemainingSpace -= spaceAdd; 772 groupRemainingSpace -= spaceAdd;
772 } 773 }
773 } 774 }
774 } 775 }
775 } while (absoluteValue(groupRemainingSpace) >= 1); 776 } while (absoluteValue(groupRemainingSpace) >= 1);
776 } 777 }
777 778
778 // We didn't find any children that could grow. 779 // We didn't find any children that could grow.
779 if (haveFlex && !flexingChildren) 780 if (haveFlex && !flexingChildren)
780 haveFlex = false; 781 haveFlex = false;
781 } 782 }
782 } while (haveFlex); 783 } while (haveFlex);
783 784
784 LayoutBlock::finishDelayUpdateScrollInfo(); 785 LayoutBlock::finishDelayUpdateScrollInfo();
785 786
786 if (style()->boxPack() != Start && remainingSpace > 0) { 787 if (style()->boxPack() != Start && remainingSpace > 0) {
787 // Children must be repositioned. 788 // Children must be repositioned.
788 LayoutUnit offset = 0; 789 LayoutUnit offset;
789 if (style()->boxPack() == Justify) { 790 if (style()->boxPack() == Justify) {
790 // Determine the total number of children. 791 // Determine the total number of children.
791 int totalChildren = 0; 792 int totalChildren = 0;
792 for (LayoutBox* child = iterator.first(); child; child = iterator.ne xt()) { 793 for (LayoutBox* child = iterator.first(); child; child = iterator.ne xt()) {
793 if (childDoesNotAffectWidthOrFlexing(child)) 794 if (childDoesNotAffectWidthOrFlexing(child))
794 continue; 795 continue;
795 796
796 ++totalChildren; 797 ++totalChildren;
797 } 798 }
798 799
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
869 870
870 for (LayoutBox* child = iterator.first(); child; child = iterator.next()) { 871 for (LayoutBox* child = iterator.first(); child; child = iterator.next()) {
871 if (childDoesNotAffectWidthOrFlexing(child) || !child->style()->height() .isAuto() || !child->isLayoutBlock()) 872 if (childDoesNotAffectWidthOrFlexing(child) || !child->style()->height() .isAuto() || !child->isLayoutBlock())
872 continue; 873 continue;
873 874
874 LayoutBlock* blockChild = toLayoutBlock(child); 875 LayoutBlock* blockChild = toLayoutBlock(child);
875 int lineCount = blockChild->lineCount(); 876 int lineCount = blockChild->lineCount();
876 if (lineCount <= numVisibleLines) 877 if (lineCount <= numVisibleLines)
877 continue; 878 continue;
878 879
879 LayoutUnit newHeight = blockChild->heightForLineCount(numVisibleLines); 880 LayoutUnit newHeight(blockChild->heightForLineCount(numVisibleLines));
880 if (newHeight == child->size().height()) 881 if (newHeight == child->size().height())
881 continue; 882 continue;
882 883
883 child->setOverrideLogicalContentHeight(newHeight - child->borderAndPaddi ngHeight()); 884 child->setOverrideLogicalContentHeight(newHeight - child->borderAndPaddi ngHeight());
884 child->forceChildLayout(); 885 child->forceChildLayout();
885 886
886 // FIXME: For now don't support RTL. 887 // FIXME: For now don't support RTL.
887 if (style()->direction() != LTR) 888 if (style()->direction() != LTR)
888 continue; 889 continue;
889 890
(...skipping 22 matching lines...) Expand all
912 if (!leftToRight) 913 if (!leftToRight)
913 continue; 914 continue;
914 915
915 LayoutUnit blockRightEdge = destBlock.logicalRightOffsetForLine(lastVisi bleLine->y(), DoNotIndentText); 916 LayoutUnit blockRightEdge = destBlock.logicalRightOffsetForLine(lastVisi bleLine->y(), DoNotIndentText);
916 if (!lastVisibleLine->lineCanAccommodateEllipsis(leftToRight, blockRight Edge, lastVisibleLine->x() + lastVisibleLine->logicalWidth(), totalWidth)) 917 if (!lastVisibleLine->lineCanAccommodateEllipsis(leftToRight, blockRight Edge, lastVisibleLine->x() + lastVisibleLine->logicalWidth(), totalWidth))
917 continue; 918 continue;
918 919
919 // Let the truncation code kick in. 920 // Let the truncation code kick in.
920 // FIXME: the text alignment should be recomputed after the width change s due to truncation. 921 // FIXME: the text alignment should be recomputed after the width change s due to truncation.
921 LayoutUnit blockLeftEdge = destBlock.logicalLeftOffsetForLine(lastVisibl eLine->y(), DoNotIndentText); 922 LayoutUnit blockLeftEdge = destBlock.logicalLeftOffsetForLine(lastVisibl eLine->y(), DoNotIndentText);
922 lastVisibleLine->placeEllipsis(ellipsisStr, leftToRight, blockLeftEdge, blockRightEdge, totalWidth); 923 lastVisibleLine->placeEllipsis(ellipsisStr, leftToRight, blockLeftEdge, blockRightEdge, LayoutUnit(totalWidth));
923 destBlock.setHasMarkupTruncation(true); 924 destBlock.setHasMarkupTruncation(true);
924 } 925 }
925 } 926 }
926 927
927 void LayoutDeprecatedFlexibleBox::clearLineClamp() 928 void LayoutDeprecatedFlexibleBox::clearLineClamp()
928 { 929 {
929 FlexBoxIterator iterator(this); 930 FlexBoxIterator iterator(this);
930 for (LayoutBox* child = iterator.first(); child; child = iterator.next()) { 931 for (LayoutBox* child = iterator.first(); child; child = iterator.next()) {
931 if (childDoesNotAffectWidthOrFlexing(child)) 932 if (childDoesNotAffectWidthOrFlexing(child))
932 continue; 933 continue;
(...skipping 16 matching lines...) Expand all
949 // FIXME Investigate if this can be removed based on other flags. crbug.com/ 370010 950 // FIXME Investigate if this can be removed based on other flags. crbug.com/ 370010
950 child->setMayNeedPaintInvalidation(); 951 child->setMayNeedPaintInvalidation();
951 952
952 // Place the child. 953 // Place the child.
953 child->setLocation(location); 954 child->setLocation(location);
954 } 955 }
955 956
956 LayoutUnit LayoutDeprecatedFlexibleBox::allowedChildFlex(LayoutBox* child, bool expanding, unsigned group) 957 LayoutUnit LayoutDeprecatedFlexibleBox::allowedChildFlex(LayoutBox* child, bool expanding, unsigned group)
957 { 958 {
958 if (childDoesNotAffectWidthOrFlexing(child) || child->style()->boxFlex() == 0.0f || child->style()->boxFlexGroup() != group) 959 if (childDoesNotAffectWidthOrFlexing(child) || child->style()->boxFlex() == 0.0f || child->style()->boxFlexGroup() != group)
959 return 0; 960 return LayoutUnit();
960 961
961 if (expanding) { 962 if (expanding) {
962 if (isHorizontal()) { 963 if (isHorizontal()) {
963 // FIXME: For now just handle fixed values. 964 // FIXME: For now just handle fixed values.
964 LayoutUnit maxWidth = LayoutUnit::max(); 965 LayoutUnit maxWidth = LayoutUnit::max();
965 LayoutUnit width = contentWidthForChild(child); 966 LayoutUnit width = contentWidthForChild(child);
966 if (child->style()->maxWidth().isFixed()) 967 if (child->style()->maxWidth().isFixed())
967 maxWidth = child->style()->maxWidth().value(); 968 maxWidth = LayoutUnit(child->style()->maxWidth().value());
968 if (maxWidth == LayoutUnit::max()) 969 if (maxWidth == LayoutUnit::max())
969 return maxWidth; 970 return maxWidth;
970 return std::max<LayoutUnit>(0, maxWidth - width); 971 return (maxWidth - width).clampNegativeToZero();
971 } 972 }
972 // FIXME: For now just handle fixed values. 973 // FIXME: For now just handle fixed values.
973 LayoutUnit maxHeight = LayoutUnit::max(); 974 LayoutUnit maxHeight = LayoutUnit::max();
974 LayoutUnit height = contentHeightForChild(child); 975 LayoutUnit height = contentHeightForChild(child);
975 if (child->style()->maxHeight().isFixed()) 976 if (child->style()->maxHeight().isFixed())
976 maxHeight = child->style()->maxHeight().value(); 977 maxHeight = LayoutUnit(child->style()->maxHeight().value());
977 if (maxHeight == LayoutUnit::max()) 978 if (maxHeight == LayoutUnit::max())
978 return maxHeight; 979 return maxHeight;
979 return std::max<LayoutUnit>(0, maxHeight - height); 980 return (maxHeight - height).clampNegativeToZero();
980 } 981 }
981 982
982 // FIXME: For now just handle fixed values. 983 // FIXME: For now just handle fixed values.
983 if (isHorizontal()) { 984 if (isHorizontal()) {
984 LayoutUnit minWidth = child->minPreferredLogicalWidth(); 985 LayoutUnit minWidth = child->minPreferredLogicalWidth();
985 LayoutUnit width = contentWidthForChild(child); 986 LayoutUnit width = contentWidthForChild(child);
986 if (child->style()->minWidth().isFixed()) 987 if (child->style()->minWidth().isFixed())
987 minWidth = child->style()->minWidth().value(); 988 minWidth = LayoutUnit(child->style()->minWidth().value());
988 else if (child->style()->minWidth().type() == Auto) 989 else if (child->style()->minWidth().type() == Auto)
989 minWidth = 0; 990 minWidth = LayoutUnit();
990 991
991 LayoutUnit allowedShrinkage = std::min<LayoutUnit>(0, minWidth - width); 992 LayoutUnit allowedShrinkage = (minWidth - width).clampPositiveToZero();
992 return allowedShrinkage; 993 return allowedShrinkage;
993 } 994 }
994 Length minHeight = child->style()->minHeight(); 995 Length minHeight = child->style()->minHeight();
995 if (minHeight.isFixed() || minHeight.isAuto()) { 996 if (minHeight.isFixed() || minHeight.isAuto()) {
996 LayoutUnit minHeight = child->style()->minHeight().value(); 997 LayoutUnit minHeight(child->style()->minHeight().value());
997 LayoutUnit height = contentHeightForChild(child); 998 LayoutUnit height = contentHeightForChild(child);
998 LayoutUnit allowedShrinkage = std::min<LayoutUnit>(0, minHeight - height ); 999 LayoutUnit allowedShrinkage = (minHeight - height).clampPositiveToZero() ;
999 return allowedShrinkage; 1000 return allowedShrinkage;
1000 } 1001 }
1001 return 0; 1002 return LayoutUnit();
1002 } 1003 }
1003 1004
1004 } // namespace blink 1005 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698