| OLD | NEW |
| 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 710 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 721 } | 721 } |
| 722 } | 722 } |
| 723 | 723 |
| 724 // Similar to how we apply clearance. Go ahead and boost height() to be the
place where we're going to position the child. | 724 // Similar to how we apply clearance. Go ahead and boost height() to be the
place where we're going to position the child. |
| 725 setLogicalHeight(logicalHeight() + (result - oldTop)); | 725 setLogicalHeight(logicalHeight() + (result - oldTop)); |
| 726 | 726 |
| 727 // Return the final adjusted logical top. | 727 // Return the final adjusted logical top. |
| 728 return result; | 728 return result; |
| 729 } | 729 } |
| 730 | 730 |
| 731 static inline LayoutUnit calculateMinimumPageHeight(const ComputedStyle& style,
RootInlineBox* lastLine, LayoutUnit lineTop, LayoutUnit lineBottom) | 731 static inline LayoutUnit calculateMinimumPageHeight(const ComputedStyle& style,
const RootInlineBox& lastLine) |
| 732 { | 732 { |
| 733 // We may require a certain minimum number of lines per page in order to sat
isfy | 733 // We may require a certain minimum number of lines per page in order to sat
isfy |
| 734 // orphans and widows, and that may affect the minimum page height. | 734 // orphans and widows, and that may affect the minimum page height. |
| 735 unsigned lineCount = std::max<unsigned>(style.hasAutoOrphans() ? 1 : style.o
rphans(), style.widows()); | 735 unsigned lineCount = std::max<unsigned>(style.hasAutoOrphans() ? 1 : style.o
rphans(), style.widows()); |
| 736 if (lineCount > 1) { | 736 const RootInlineBox* firstLine = &lastLine; |
| 737 RootInlineBox* line = lastLine; | 737 for (unsigned i = 1; i < lineCount && firstLine->prevRootBox(); i++) |
| 738 for (unsigned i = 1; i < lineCount && line->prevRootBox(); i++) | 738 firstLine = firstLine->prevRootBox(); |
| 739 line = line->prevRootBox(); | 739 return lastLine.lineBottomWithLeading() - firstLine->lineTopWithLeading(); |
| 740 | |
| 741 // FIXME: Paginating using line overflow isn't all fine. See FIXME in | |
| 742 // adjustLinePositionForPagination() for more details. | |
| 743 LayoutRect overflow = line->logicalVisualOverflowRect(line->lineTop(), l
ine->lineBottom()); | |
| 744 lineTop = std::min(line->lineTopWithLeading(), overflow.y()); | |
| 745 } | |
| 746 return lineBottom - lineTop; | |
| 747 } | 740 } |
| 748 | 741 |
| 749 void LayoutBlockFlow::adjustLinePositionForPagination(RootInlineBox& lineBox, La
youtUnit& delta) | 742 void LayoutBlockFlow::adjustLinePositionForPagination(RootInlineBox& lineBox, La
youtUnit& delta) |
| 750 { | 743 { |
| 751 // FIXME: For now we paginate using line overflow. This ensures that lines d
on't overlap at all when we | 744 // TODO(mstensho): Pay attention to line overflow. It should be painted in t
he same column as |
| 752 // put a strut between them for pagination purposes. However, this really is
n't the desired layout, since | 745 // the rest of the line, possibly overflowing the column. We currently only
allow overflow above |
| 753 // the line on the top of the next page will appear too far down relative to
the same kind of line at the top | 746 // the first column. We clip at all other column boundaries, and that's how
it has to be for |
| 754 // of the first column. | 747 // now. The paint we have to do when a column has overflow has to be special
. We need to exclude |
| 755 // | |
| 756 // The layout we would like to see is one where the lineTopWithLeading is at
the top of the column, and any line overflow | |
| 757 // simply spills out above the top of the column. This effect would match wh
at happens at the top of the first column. | |
| 758 // We can't achieve this layout, however, until we stop columns from clippin
g to the column bounds (thus allowing | |
| 759 // for overflow to occur), and then cache visible overflow for each column r
ect. | |
| 760 // | |
| 761 // Furthermore, the paint we have to do when a column has overflow has to be
special. We need to exclude | |
| 762 // content that paints in a previous column (and content that paints in the
following column). | 748 // content that paints in a previous column (and content that paints in the
following column). |
| 763 // | 749 // |
| 764 // For now we'll at least honor the lineTopWithLeading when paginating if it
is above the logical top overflow. This will | |
| 765 // at least make positive leading work in typical cases. | |
| 766 // | |
| 767 // FIXME: Another problem with simply moving lines is that the available lin
e width may change (because of floats). | 750 // FIXME: Another problem with simply moving lines is that the available lin
e width may change (because of floats). |
| 768 // 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 | 751 // 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 |
| 769 // line and all following lines. | 752 // line and all following lines. |
| 770 LayoutRect logicalVisualOverflow = lineBox.logicalVisualOverflowRect(lineBox
.lineTop(), lineBox.lineBottom()); | 753 LayoutUnit logicalOffset = lineBox.lineTopWithLeading(); |
| 771 LayoutUnit logicalOffset = std::min(lineBox.lineTopWithLeading(), logicalVis
ualOverflow.y()); | 754 LayoutUnit lineHeight = lineBox.lineBottomWithLeading() - logicalOffset; |
| 772 LayoutUnit logicalBottom = std::max(lineBox.lineBottomWithLeading(), logical
VisualOverflow.maxY()); | 755 updateMinimumPageHeight(logicalOffset, calculateMinimumPageHeight(styleRef()
, lineBox)); |
| 773 LayoutUnit lineHeight = logicalBottom - logicalOffset; | |
| 774 updateMinimumPageHeight(logicalOffset, calculateMinimumPageHeight(styleRef()
, &lineBox, logicalOffset, logicalBottom)); | |
| 775 logicalOffset += delta; | 756 logicalOffset += delta; |
| 776 lineBox.setPaginationStrut(0); | 757 lineBox.setPaginationStrut(LayoutUnit()); |
| 777 lineBox.setIsFirstAfterPageBreak(false); | 758 lineBox.setIsFirstAfterPageBreak(false); |
| 778 LayoutUnit pageLogicalHeight = pageLogicalHeightForOffset(logicalOffset); | 759 LayoutUnit pageLogicalHeight = pageLogicalHeightForOffset(logicalOffset); |
| 779 if (!pageLogicalHeight) | 760 if (!pageLogicalHeight) |
| 780 return; | 761 return; |
| 781 LayoutUnit remainingLogicalHeight = pageRemainingLogicalHeightForOffset(logi
calOffset, ExcludePageBoundary); | 762 LayoutUnit remainingLogicalHeight = pageRemainingLogicalHeightForOffset(logi
calOffset, ExcludePageBoundary); |
| 782 | 763 |
| 783 int lineIndex = lineCount(&lineBox); | 764 int lineIndex = lineCount(&lineBox); |
| 784 if (remainingLogicalHeight < lineHeight || (shouldBreakAtLineToAvoidWidow()
&& lineBreakToAvoidWidow() == lineIndex)) { | 765 if (remainingLogicalHeight < lineHeight || (shouldBreakAtLineToAvoidWidow()
&& lineBreakToAvoidWidow() == lineIndex)) { |
| 785 if (shouldBreakAtLineToAvoidWidow() && lineBreakToAvoidWidow() == lineIn
dex) { | 766 if (shouldBreakAtLineToAvoidWidow() && lineBreakToAvoidWidow() == lineIn
dex) { |
| 786 clearShouldBreakAtLineToAvoidWidow(); | 767 clearShouldBreakAtLineToAvoidWidow(); |
| 787 setDidBreakAtLineToAvoidWidow(); | 768 setDidBreakAtLineToAvoidWidow(); |
| 788 } | 769 } |
| 789 if (lineHeight > pageLogicalHeight) { | |
| 790 // Split the top margin in order to avoid splitting the visible part
of the line. | |
| 791 remainingLogicalHeight -= std::min(lineHeight - pageLogicalHeight, s
td::max<LayoutUnit>(0, logicalVisualOverflow.y() - lineBox.lineTopWithLeading())
); | |
| 792 } | |
| 793 LayoutUnit totalLogicalHeight = lineHeight + std::max<LayoutUnit>(0, log
icalOffset); | 770 LayoutUnit totalLogicalHeight = lineHeight + std::max<LayoutUnit>(0, log
icalOffset); |
| 794 LayoutUnit pageLogicalHeightAtNewOffset = pageLogicalHeightForOffset(log
icalOffset + remainingLogicalHeight); | 771 LayoutUnit pageLogicalHeightAtNewOffset = pageLogicalHeightForOffset(log
icalOffset + remainingLogicalHeight); |
| 795 setPageBreak(logicalOffset, lineHeight - remainingLogicalHeight); | 772 setPageBreak(logicalOffset, lineHeight - remainingLogicalHeight); |
| 796 if (((lineBox == firstRootBox() && totalLogicalHeight < pageLogicalHeigh
tAtNewOffset) || (!style()->hasAutoOrphans() && style()->orphans() >= lineIndex)
) | 773 if (((lineBox == firstRootBox() && totalLogicalHeight < pageLogicalHeigh
tAtNewOffset) || (!style()->hasAutoOrphans() && style()->orphans() >= lineIndex)
) |
| 797 && !isOutOfFlowPositioned() && !isTableCell()) { | 774 && !isOutOfFlowPositioned() && !isTableCell()) { |
| 798 setPaginationStrut(remainingLogicalHeight + std::max<LayoutUnit>(0,
logicalOffset)); | 775 setPaginationStrut(remainingLogicalHeight + std::max<LayoutUnit>(0,
logicalOffset)); |
| 799 } else { | 776 } else { |
| 800 delta += remainingLogicalHeight; | 777 delta += remainingLogicalHeight; |
| 801 lineBox.setPaginationStrut(remainingLogicalHeight); | 778 lineBox.setPaginationStrut(remainingLogicalHeight); |
| 802 lineBox.setIsFirstAfterPageBreak(true); | 779 lineBox.setIsFirstAfterPageBreak(true); |
| (...skipping 2264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3067 FrameView* frameView = document().view(); | 3044 FrameView* frameView = document().view(); |
| 3068 LayoutUnit top = (style()->position() == FixedPosition) ? 0 : frameView->scr
ollOffset().height(); | 3045 LayoutUnit top = (style()->position() == FixedPosition) ? 0 : frameView->scr
ollOffset().height(); |
| 3069 int visibleHeight = frameView->visibleContentRect(IncludeScrollbars).height(
); | 3046 int visibleHeight = frameView->visibleContentRect(IncludeScrollbars).height(
); |
| 3070 if (size().height() < visibleHeight) | 3047 if (size().height() < visibleHeight) |
| 3071 top += (visibleHeight - size().height()) / 2; | 3048 top += (visibleHeight - size().height()) / 2; |
| 3072 setY(top); | 3049 setY(top); |
| 3073 dialog->setCentered(top); | 3050 dialog->setCentered(top); |
| 3074 } | 3051 } |
| 3075 | 3052 |
| 3076 } // namespace blink | 3053 } // namespace blink |
| OLD | NEW |