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 719 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
730 | 730 |
731 paginatedContentWasLaidOut(newLogicalTop); | 731 paginatedContentWasLaidOut(newLogicalTop); |
732 | 732 |
733 // Similar to how we apply clearance. Go ahead and boost height() to be the
place where we're going to position the child. | 733 // Similar to how we apply clearance. Go ahead and boost height() to be the
place where we're going to position the child. |
734 setLogicalHeight(logicalHeight() + (newLogicalTop - logicalTop)); | 734 setLogicalHeight(logicalHeight() + (newLogicalTop - logicalTop)); |
735 | 735 |
736 // Return the final adjusted logical top. | 736 // Return the final adjusted logical top. |
737 return newLogicalTop; | 737 return newLogicalTop; |
738 } | 738 } |
739 | 739 |
740 static inline bool shouldSetStrutOnBlock(const LayoutBlockFlow& block, const Roo
tInlineBox& lineBox, LayoutUnit lineLogicalOffset, int lineIndex, LayoutUnit rem
ainingLogicalHeight) | 740 static bool shouldSetStrutOnBlock(const LayoutBlockFlow& block, const RootInline
Box& lineBox, LayoutUnit lineLogicalOffset, int lineIndex, LayoutUnit remainingL
ogicalHeight) |
741 { | 741 { |
742 bool wantsStrutOnBlock = false; | 742 bool wantsStrutOnBlock = false; |
743 if (!block.style()->hasAutoOrphans() && block.style()->orphans() >= lineInde
x) { | 743 if (!block.style()->hasAutoOrphans() && block.style()->orphans() >= lineInde
x) { |
744 // Not enough orphans here. Push the entire block to the next column / p
age as an | 744 // Not enough orphans here. Push the entire block to the next column / p
age as an |
745 // attempt to better satisfy the orphans requirement. | 745 // attempt to better satisfy the orphans requirement. |
746 wantsStrutOnBlock = true; | 746 wantsStrutOnBlock = true; |
747 } else if (lineBox == block.firstRootBox() && lineLogicalOffset == block.bor
derAndPaddingBefore()) { | 747 } else if (lineBox == block.firstRootBox() && lineLogicalOffset == block.bor
derAndPaddingBefore()) { |
748 // This is the first line in the block. We can take the whole block with
us to the next page | 748 // This is the first line in the block. We can take the whole block with
us to the next page |
749 // or column, rather than keeping a content-less portion of it in the pr
evious one. Only do | 749 // or column, rather than keeping a content-less portion of it in the pr
evious one. Only do |
750 // this if the line is flush with the content edge of the block, though.
If it isn't, it | 750 // this if the line is flush with the content edge of the block, though.
If it isn't, it |
751 // means that the line was pushed downwards by preceding floats that did
n't fit beside the | 751 // means that the line was pushed downwards by preceding floats that did
n't fit beside the |
752 // line, and we don't want to move all that, since it has already been e
stablished that it | 752 // line, and we don't want to move all that, since it has already been e
stablished that it |
753 // fits nicely where it is. | 753 // fits nicely where it is. |
754 LayoutUnit lineHeight = lineBox.lineBottomWithLeading() - lineBox.lineTo
pWithLeading(); | 754 LayoutUnit lineHeight = lineBox.lineBottomWithLeading() - lineBox.lineTo
pWithLeading(); |
755 LayoutUnit totalLogicalHeight = lineHeight + std::max<LayoutUnit>(0, lin
eLogicalOffset); | 755 LayoutUnit totalLogicalHeight = lineHeight + std::max<LayoutUnit>(0, lin
eLogicalOffset); |
756 LayoutUnit pageLogicalHeightAtNewOffset = block.pageLogicalHeightForOffs
et(lineLogicalOffset + remainingLogicalHeight); | 756 LayoutUnit pageLogicalHeightAtNewOffset = block.pageLogicalHeightForOffs
et(lineLogicalOffset + remainingLogicalHeight); |
757 // It's rather pointless to break before the block if the current line i
sn't going to | 757 // It's rather pointless to break before the block if the current line i
sn't going to |
758 // fit in the same column or page, so check that as well. | 758 // fit in the same column or page, so check that as well. |
759 if (totalLogicalHeight <= pageLogicalHeightAtNewOffset) | 759 if (totalLogicalHeight <= pageLogicalHeightAtNewOffset) |
760 wantsStrutOnBlock = true; | 760 wantsStrutOnBlock = true; |
761 } | 761 } |
762 return wantsStrutOnBlock && block.allowsPaginationStrut(); | 762 return wantsStrutOnBlock && block.allowsPaginationStrut(); |
763 } | 763 } |
764 | 764 |
| 765 static LayoutUnit calculateStrutForPropagation(const LayoutBlockFlow& blockFlow,
LayoutUnit lineLogicalOffset) |
| 766 { |
| 767 LayoutUnit paginationStrut = std::max<LayoutUnit>(LayoutUnit(), lineLogicalO
ffset); |
| 768 if (blockFlow.isFloating()) |
| 769 paginationStrut += blockFlow.marginBefore(); // Floats' margins do not c
ollapse with page or column boundaries. |
| 770 return paginationStrut; |
| 771 } |
| 772 |
765 void LayoutBlockFlow::adjustLinePositionForPagination(RootInlineBox& lineBox, La
youtUnit& delta) | 773 void LayoutBlockFlow::adjustLinePositionForPagination(RootInlineBox& lineBox, La
youtUnit& delta) |
766 { | 774 { |
767 // 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 |
768 // 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 |
769 // 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 |
770 // 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 |
771 // 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). |
772 // | 780 // |
773 // 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). |
774 // 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 23 matching lines...) Expand all Loading... |
798 if (shouldBreakAtLineToAvoidWidow() && lineBreakToAvoidWidow() == lineIn
dex) { | 806 if (shouldBreakAtLineToAvoidWidow() && lineBreakToAvoidWidow() == lineIn
dex) { |
799 clearShouldBreakAtLineToAvoidWidow(); | 807 clearShouldBreakAtLineToAvoidWidow(); |
800 setDidBreakAtLineToAvoidWidow(); | 808 setDidBreakAtLineToAvoidWidow(); |
801 } | 809 } |
802 if (shouldSetStrutOnBlock(*this, lineBox, logicalOffset, lineIndex, rema
iningLogicalHeight)) { | 810 if (shouldSetStrutOnBlock(*this, lineBox, logicalOffset, lineIndex, rema
iningLogicalHeight)) { |
803 // Note that when setting the strut on a block, it may be propagated
to parent blocks | 811 // Note that when setting the strut on a block, it may be propagated
to parent blocks |
804 // later on, if a block's logical top is flush with that of its pare
nt. We don't want | 812 // later on, if a block's logical top is flush with that of its pare
nt. We don't want |
805 // content-less portions (struts) at the beginning of a block before
a break, if it can | 813 // content-less portions (struts) at the beginning of a block before
a break, if it can |
806 // be avoided. After all, that's the reason for setting struts on bl
ocks and not lines | 814 // be avoided. After all, that's the reason for setting struts on bl
ocks and not lines |
807 // in the first place. | 815 // in the first place. |
808 LayoutUnit paginationStrut = remainingLogicalHeight + std::max<Layou
tUnit>(0, logicalOffset); | 816 setPaginationStrutPropagatedFromChild(calculateStrutForPropagation(*
this, remainingLogicalHeight + logicalOffset)); |
809 if (isFloating()) | |
810 paginationStrut += marginBefore(); // Floats' margins do not col
lapse with page or column boundaries. | |
811 setPaginationStrutPropagatedFromChild(paginationStrut); | |
812 } else { | 817 } else { |
813 logicalOffset += remainingLogicalHeight; | 818 logicalOffset += remainingLogicalHeight; |
814 delta += remainingLogicalHeight; | 819 delta += remainingLogicalHeight; |
815 lineBox.setPaginationStrut(remainingLogicalHeight); | 820 lineBox.setPaginationStrut(remainingLogicalHeight); |
816 lineBox.setIsFirstAfterPageBreak(true); | 821 lineBox.setIsFirstAfterPageBreak(true); |
817 } | 822 } |
818 } else if (remainingLogicalHeight == pageLogicalHeight) { | 823 } else if (remainingLogicalHeight == pageLogicalHeight) { |
819 // We're at the very top of a page or column. | 824 // We're at the very top of a page or column. |
820 if (lineBox != firstRootBox()) | 825 if (lineBox != firstRootBox()) |
821 lineBox.setIsFirstAfterPageBreak(true); | 826 lineBox.setIsFirstAfterPageBreak(true); |
| 827 // If this is the first line in the block, and the block has a top borde
r, padding, or (in |
| 828 // case it's a float) margin, we may want to set a strut on the block, s
o that everything |
| 829 // ends up in the next column or page. Setting a strut on the block is a
lso important when |
| 830 // it comes to satisfying orphan requirements. |
| 831 if (shouldSetStrutOnBlock(*this, lineBox, logicalOffset, lineIndex, rema
iningLogicalHeight)) |
| 832 setPaginationStrutPropagatedFromChild(calculateStrutForPropagation(*
this, logicalOffset)); |
| 833 } else if (lineBox == firstRootBox() && allowsPaginationStrut()) { |
| 834 // This is the first line in the block. The block may still start in the
previous column or |
| 835 // page, and if that's the case, attempt to pull it over to where this l
ine is, so that we |
| 836 // don't split the top border, padding, or (in case it's a float) margin
. |
| 837 LayoutUnit totalLogicalOffset = logicalOffset; |
| 838 if (isFloating()) |
| 839 totalLogicalOffset += marginBefore(); // Floats' margins do not coll
apse with page or column boundaries. |
| 840 LayoutUnit strut = remainingLogicalHeight + totalLogicalOffset - pageLog
icalHeight; |
| 841 if (strut > 0) { |
| 842 // The block starts in a previous column or page. Set a strut on the
block if there's |
| 843 // room for the top border, padding and (if it's a float) margin and
the line in one |
| 844 // column or page. |
| 845 if (totalLogicalOffset + lineHeight <= pageLogicalHeight) |
| 846 setPaginationStrutPropagatedFromChild(strut); |
| 847 } |
822 } | 848 } |
823 | 849 |
824 paginatedContentWasLaidOut(logicalOffset); | 850 paginatedContentWasLaidOut(logicalOffset); |
825 } | 851 } |
826 | 852 |
827 LayoutUnit LayoutBlockFlow::adjustForUnsplittableChild(LayoutBox& child, LayoutU
nit logicalOffset) const | 853 LayoutUnit LayoutBlockFlow::adjustForUnsplittableChild(LayoutBox& child, LayoutU
nit logicalOffset) const |
828 { | 854 { |
829 if (child.paginationBreakability() == AllowAnyBreaks) | 855 if (child.paginationBreakability() == AllowAnyBreaks) |
830 return logicalOffset; | 856 return logicalOffset; |
831 LayoutUnit childLogicalHeight = logicalHeightForChild(child); | 857 LayoutUnit childLogicalHeight = logicalHeightForChild(child); |
(...skipping 2229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3061 FrameView* frameView = document().view(); | 3087 FrameView* frameView = document().view(); |
3062 LayoutUnit top = (style()->position() == FixedPosition) ? 0 : frameView->scr
ollOffset().height(); | 3088 LayoutUnit top = (style()->position() == FixedPosition) ? 0 : frameView->scr
ollOffset().height(); |
3063 int visibleHeight = frameView->visibleContentRect(IncludeScrollbars).height(
); | 3089 int visibleHeight = frameView->visibleContentRect(IncludeScrollbars).height(
); |
3064 if (size().height() < visibleHeight) | 3090 if (size().height() < visibleHeight) |
3065 top += (visibleHeight - size().height()) / 2; | 3091 top += (visibleHeight - size().height()) / 2; |
3066 setY(top); | 3092 setY(top); |
3067 dialog->setCentered(top); | 3093 dialog->setCentered(top); |
3068 } | 3094 } |
3069 | 3095 |
3070 } // namespace blink | 3096 } // namespace blink |
OLD | NEW |