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

Side by Side Diff: Source/core/layout/LayoutBlockFlow.cpp

Issue 1277613004: A line that doesn't fit in a column shouldn't pull preceding floats to the next column. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Code review. Add helper function. Created 5 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « LayoutTests/fast/multicol/line-pushed-down-by-float-expected.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 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 725 matching lines...) Expand 10 before | Expand all | Expand 10 after
736 { 736 {
737 // We may require a certain minimum number of lines per page in order to sat isfy 737 // We may require a certain minimum number of lines per page in order to sat isfy
738 // orphans and widows, and that may affect the minimum page height. 738 // orphans and widows, and that may affect the minimum page height.
739 unsigned lineCount = std::max<unsigned>(style.hasAutoOrphans() ? 1 : style.o rphans(), style.widows()); 739 unsigned lineCount = std::max<unsigned>(style.hasAutoOrphans() ? 1 : style.o rphans(), style.widows());
740 const RootInlineBox* firstLine = &lastLine; 740 const RootInlineBox* firstLine = &lastLine;
741 for (unsigned i = 1; i < lineCount && firstLine->prevRootBox(); i++) 741 for (unsigned i = 1; i < lineCount && firstLine->prevRootBox(); i++)
742 firstLine = firstLine->prevRootBox(); 742 firstLine = firstLine->prevRootBox();
743 return lastLine.lineBottomWithLeading() - firstLine->lineTopWithLeading(); 743 return lastLine.lineBottomWithLeading() - firstLine->lineTopWithLeading();
744 } 744 }
745 745
746 static inline bool shouldSetStrutOnBlock(const LayoutBlockFlow& block, const Roo tInlineBox& lineBox, LayoutUnit lineLogicalOffset, int lineIndex, LayoutUnit rem ainingLogicalHeight)
747 {
748 bool wantsStrutOnBlock = false;
749 if (!block.style()->hasAutoOrphans() && block.style()->orphans() >= lineInde x) {
750 // Not enough orphans here. Push the entire block to the next column / p age as an
751 // attempt to better satisfy the orphans requirement.
752 wantsStrutOnBlock = true;
753 } else if (lineBox == block.firstRootBox() && lineLogicalOffset == block.bor derAndPaddingBefore()) {
754 // This is the first line in the block. We can take the whole block with us to the next page
755 // or column, rather than keeping a content-less portion of it in the pr evious one. Only do
756 // this if the line is flush with the content edge of the block, though. If it isn't, it
757 // means that the line was pushed downwards by preceding floats that did n't fit beside the
758 // line, and we don't want to move all that, since it has already been e stablished that it
759 // fits nicely where it is.
760 LayoutUnit lineHeight = lineBox.lineBottomWithLeading() - lineBox.lineTo pWithLeading();
761 LayoutUnit totalLogicalHeight = lineHeight + std::max<LayoutUnit>(0, lin eLogicalOffset);
762 LayoutUnit pageLogicalHeightAtNewOffset = block.pageLogicalHeightForOffs et(lineLogicalOffset + remainingLogicalHeight);
763 // It's rather pointless to break before the block if the current line i sn't going to
764 // fit in the same column or page, so check that as well.
765 if (totalLogicalHeight < pageLogicalHeightAtNewOffset)
766 wantsStrutOnBlock = true;
767 }
768 // If we want to break before the block, one final check is needed, since so me block object
769 // types cannot handle struts.
770 return wantsStrutOnBlock && !block.isOutOfFlowPositioned() && !block.isTable Cell();
771 }
772
746 void LayoutBlockFlow::adjustLinePositionForPagination(RootInlineBox& lineBox, La youtUnit& delta) 773 void LayoutBlockFlow::adjustLinePositionForPagination(RootInlineBox& lineBox, La youtUnit& delta)
747 { 774 {
748 // TODO(mstensho): Pay attention to line overflow. It should be painted in t he same column as 775 // TODO(mstensho): Pay attention to line overflow. It should be painted in t he same column as
749 // the rest of the line, possibly overflowing the column. We currently only allow overflow above 776 // the rest of the line, possibly overflowing the column. We currently only allow overflow above
750 // the first column. We clip at all other column boundaries, and that's how it has to be for 777 // the first column. We clip at all other column boundaries, and that's how it has to be for
751 // now. The paint we have to do when a column has overflow has to be special . We need to exclude 778 // now. The paint we have to do when a column has overflow has to be special . We need to exclude
752 // content that paints in a previous column (and content that paints in the following column). 779 // content that paints in a previous column (and content that paints in the following column).
753 // 780 //
754 // FIXME: Another problem with simply moving lines is that the available lin e width may change (because of floats). 781 // FIXME: Another problem with simply moving lines is that the available lin e width may change (because of floats).
755 // Technically if the location we move the line to has a different line widt h than our old position, then we need to dirty the 782 // Technically if the location we move the line to has a different line widt h than our old position, then we need to dirty the
(...skipping 11 matching lines...) Expand all
767 // Too tall to fit in one page / column. Give up. Don't push to the next page / column. 794 // Too tall to fit in one page / column. Give up. Don't push to the next page / column.
768 // TODO(mstensho): Get rid of this. This is just utter weirdness, but th e other browsers 795 // TODO(mstensho): Get rid of this. This is just utter weirdness, but th e other browsers
769 // also do something slightly similar, although in much more specific ca ses than we do here, 796 // also do something slightly similar, although in much more specific ca ses than we do here,
770 // and printing Google Docs depends on it. 797 // and printing Google Docs depends on it.
771 return; 798 return;
772 } 799 }
773 LayoutUnit remainingLogicalHeight = pageRemainingLogicalHeightForOffset(logi calOffset, ExcludePageBoundary); 800 LayoutUnit remainingLogicalHeight = pageRemainingLogicalHeightForOffset(logi calOffset, ExcludePageBoundary);
774 801
775 int lineIndex = lineCount(&lineBox); 802 int lineIndex = lineCount(&lineBox);
776 if (remainingLogicalHeight < lineHeight || (shouldBreakAtLineToAvoidWidow() && lineBreakToAvoidWidow() == lineIndex)) { 803 if (remainingLogicalHeight < lineHeight || (shouldBreakAtLineToAvoidWidow() && lineBreakToAvoidWidow() == lineIndex)) {
804 // We need to insert a break now, either because there's no room for the line in the
805 // current column / page, or because we have determined that we need a b reak to satisfy
806 // widow requirements.
777 if (shouldBreakAtLineToAvoidWidow() && lineBreakToAvoidWidow() == lineIn dex) { 807 if (shouldBreakAtLineToAvoidWidow() && lineBreakToAvoidWidow() == lineIn dex) {
778 clearShouldBreakAtLineToAvoidWidow(); 808 clearShouldBreakAtLineToAvoidWidow();
779 setDidBreakAtLineToAvoidWidow(); 809 setDidBreakAtLineToAvoidWidow();
780 } 810 }
781 LayoutUnit totalLogicalHeight = lineHeight + std::max<LayoutUnit>(0, log icalOffset);
782 LayoutUnit pageLogicalHeightAtNewOffset = pageLogicalHeightForOffset(log icalOffset + remainingLogicalHeight);
783 setPageBreak(logicalOffset, lineHeight - remainingLogicalHeight); 811 setPageBreak(logicalOffset, lineHeight - remainingLogicalHeight);
784 if (((lineBox == firstRootBox() && totalLogicalHeight < pageLogicalHeigh tAtNewOffset) || (!style()->hasAutoOrphans() && style()->orphans() >= lineIndex) ) 812 if (shouldSetStrutOnBlock(*this, lineBox, logicalOffset, lineIndex, rema iningLogicalHeight)) {
785 && !isOutOfFlowPositioned() && !isTableCell()) { 813 // Note that when setting the strut on a block, it may be propagated to parent blocks
814 // later on, if a block's logical top is flush with that of its pare nt. We don't want
815 // content-less portions (struts) at the beginning of a block before a break, if it can
816 // be avoided. After all, that's the reason for setting struts on bl ocks and not lines
817 // in the first place.
786 setPaginationStrut(remainingLogicalHeight + std::max<LayoutUnit>(0, logicalOffset)); 818 setPaginationStrut(remainingLogicalHeight + std::max<LayoutUnit>(0, logicalOffset));
787 } else { 819 } else {
788 delta += remainingLogicalHeight; 820 delta += remainingLogicalHeight;
789 lineBox.setPaginationStrut(remainingLogicalHeight); 821 lineBox.setPaginationStrut(remainingLogicalHeight);
790 lineBox.setIsFirstAfterPageBreak(true); 822 lineBox.setIsFirstAfterPageBreak(true);
791 } 823 }
792 } else if (remainingLogicalHeight == pageLogicalHeight) { 824 } else if (remainingLogicalHeight == pageLogicalHeight) {
793 // We're at the very top of a page or column. 825 // We're at the very top of a page or column.
794 if (lineBox != firstRootBox()) 826 if (lineBox != firstRootBox())
795 lineBox.setIsFirstAfterPageBreak(true); 827 lineBox.setIsFirstAfterPageBreak(true);
(...skipping 2227 matching lines...) Expand 10 before | Expand all | Expand 10 after
3023 FrameView* frameView = document().view(); 3055 FrameView* frameView = document().view();
3024 LayoutUnit top = (style()->position() == FixedPosition) ? 0 : frameView->scr ollOffset().height(); 3056 LayoutUnit top = (style()->position() == FixedPosition) ? 0 : frameView->scr ollOffset().height();
3025 int visibleHeight = frameView->visibleContentRect(IncludeScrollbars).height( ); 3057 int visibleHeight = frameView->visibleContentRect(IncludeScrollbars).height( );
3026 if (size().height() < visibleHeight) 3058 if (size().height() < visibleHeight)
3027 top += (visibleHeight - size().height()) / 2; 3059 top += (visibleHeight - size().height()) / 2;
3028 setY(top); 3060 setY(top);
3029 dialog->setCentered(top); 3061 dialog->setCentered(top);
3030 } 3062 }
3031 3063
3032 } // namespace blink 3064 } // namespace blink
OLDNEW
« no previous file with comments | « LayoutTests/fast/multicol/line-pushed-down-by-float-expected.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698