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

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

Issue 2786753002: Fix text-align: center/right when line wraps at atomic inline and spaces (Closed)
Patch Set: Rebase Created 3 years, 8 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 * Copyright (C) 2000 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 2000 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2003, 2004, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. 3 * Copyright (C) 2003, 2004, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc.
4 * All right reserved. 4 * All right reserved.
5 * Copyright (C) 2010 Google Inc. All rights reserved. 5 * Copyright (C) 2010 Google Inc. All rights reserved.
6 * 6 *
7 * This library is free software; you can redistribute it and/or 7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public 8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either 9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version. 10 * version 2 of the License, or (at your option) any later version.
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 return ETextAlign::kJustify; 376 return ETextAlign::kJustify;
377 case TextAlignLastAuto: 377 case TextAlignLastAuto:
378 if (alignment == ETextAlign::kJustify) 378 if (alignment == ETextAlign::kJustify)
379 return ETextAlign::kStart; 379 return ETextAlign::kStart;
380 return alignment; 380 return alignment;
381 } 381 }
382 382
383 return alignment; 383 return alignment;
384 } 384 }
385 385
386 static bool textAlignmentNeedsTrailingSpace(ETextAlign textAlign,
387 const ComputedStyle& style) {
388 switch (textAlign) {
389 case ETextAlign::kLeft:
390 case ETextAlign::kWebkitLeft:
391 return false;
392 case ETextAlign::kRight:
393 case ETextAlign::kWebkitRight:
394 case ETextAlign::kCenter:
395 case ETextAlign::kWebkitCenter:
396 case ETextAlign::kJustify:
397 return style.collapseWhiteSpace();
398 case ETextAlign::kStart:
399 return style.collapseWhiteSpace() && !style.isLeftToRightDirection();
400 case ETextAlign::kEnd:
401 return style.collapseWhiteSpace() && style.isLeftToRightDirection();
402 }
403 NOTREACHED();
404 return false;
405 }
406
386 static void updateLogicalWidthForLeftAlignedBlock( 407 static void updateLogicalWidthForLeftAlignedBlock(
387 bool isLeftToRightDirection, 408 bool isLeftToRightDirection,
388 BidiRun* trailingSpaceRun, 409 BidiRun* trailingSpaceRun,
389 LayoutUnit& logicalLeft, 410 LayoutUnit& logicalLeft,
390 LayoutUnit totalLogicalWidth, 411 LayoutUnit totalLogicalWidth,
391 LayoutUnit availableLogicalWidth) { 412 LayoutUnit availableLogicalWidth) {
392 // The direction of the block should determine what happens with wide lines. 413 // The direction of the block should determine what happens with wide lines.
393 // In particular with RTL blocks, wide lines should still spill out to the 414 // In particular with RTL blocks, wide lines should still spill out to the
394 // left. 415 // left.
395 if (isLeftToRightDirection) { 416 if (isLeftToRightDirection) {
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
745 766
746 void LayoutBlockFlow::computeInlineDirectionPositionsForLine( 767 void LayoutBlockFlow::computeInlineDirectionPositionsForLine(
747 RootInlineBox* lineBox, 768 RootInlineBox* lineBox,
748 const LineInfo& lineInfo, 769 const LineInfo& lineInfo,
749 BidiRun* firstRun, 770 BidiRun* firstRun,
750 BidiRun* trailingSpaceRun, 771 BidiRun* trailingSpaceRun,
751 bool reachedEnd, 772 bool reachedEnd,
752 GlyphOverflowAndFallbackFontsMap& textBoxDataMap, 773 GlyphOverflowAndFallbackFontsMap& textBoxDataMap,
753 VerticalPositionCache& verticalPositionCache, 774 VerticalPositionCache& verticalPositionCache,
754 const WordMeasurements& wordMeasurements) { 775 const WordMeasurements& wordMeasurements) {
755 ETextAlign textAlign =
756 textAlignmentForLine(!reachedEnd && !lineBox->endsWithBreak());
757 776
758 // CSS 2.1: "'Text-indent' only affects a line if it is the first formatted 777 // CSS 2.1: "'Text-indent' only affects a line if it is the first formatted
759 // line of an element. For example, the first line of an anonymous block 778 // line of an element. For example, the first line of an anonymous block
760 // box is only affected if it is the first child of its parent element." 779 // box is only affected if it is the first child of its parent element."
761 // CSS3 "text-indent", "each-line" affects the first line of the block 780 // CSS3 "text-indent", "each-line" affects the first line of the block
762 // container as well as each line after a forced line break, but does not 781 // container as well as each line after a forced line break, but does not
763 // affect lines after a soft wrap break. 782 // affect lines after a soft wrap break.
764 bool isFirstLine = 783 bool isFirstLine =
765 lineInfo.isFirstLine() && 784 lineInfo.isFirstLine() &&
766 !(isAnonymousBlock() && parent()->slowFirstChild() != this); 785 !(isAnonymousBlock() && parent()->slowFirstChild() != this);
(...skipping 10 matching lines...) Expand all
777 bool needsWordSpacing; 796 bool needsWordSpacing;
778 797
779 if (firstRun && firstRun->m_lineLayoutItem.isAtomicInlineLevel()) { 798 if (firstRun && firstRun->m_lineLayoutItem.isAtomicInlineLevel()) {
780 LineLayoutBox layoutBox(firstRun->m_lineLayoutItem); 799 LineLayoutBox layoutBox(firstRun->m_lineLayoutItem);
781 updateLogicalInlinePositions(this, lineLogicalLeft, lineLogicalRight, 800 updateLogicalInlinePositions(this, lineLogicalLeft, lineLogicalRight,
782 availableLogicalWidth, isFirstLine, indentText, 801 availableLogicalWidth, isFirstLine, indentText,
783 layoutBox.logicalHeight()); 802 layoutBox.logicalHeight());
784 } 803 }
785 804
786 computeInlineDirectionPositionsForSegment( 805 computeInlineDirectionPositionsForSegment(
787 lineBox, lineInfo, textAlign, lineLogicalLeft, availableLogicalWidth, 806 lineBox, lineInfo, lineLogicalLeft, availableLogicalWidth, firstRun,
788 firstRun, trailingSpaceRun, textBoxDataMap, verticalPositionCache, 807 trailingSpaceRun, textBoxDataMap, verticalPositionCache,
789 wordMeasurements); 808 wordMeasurements);
790 // The widths of all runs are now known. We can now place every inline box 809 // The widths of all runs are now known. We can now place every inline box
791 // (and compute accurate widths for the inline flow boxes). 810 // (and compute accurate widths for the inline flow boxes).
792 needsWordSpacing = lineBox->isLeftToRightDirection() ? false : true; 811 needsWordSpacing = lineBox->isLeftToRightDirection() ? false : true;
793 lineBox->placeBoxesInInlineDirection(lineLogicalLeft, needsWordSpacing); 812 lineBox->placeBoxesInInlineDirection(lineLogicalLeft, needsWordSpacing);
794 } 813 }
795 814
796 BidiRun* LayoutBlockFlow::computeInlineDirectionPositionsForSegment( 815 BidiRun* LayoutBlockFlow::computeInlineDirectionPositionsForSegment(
797 RootInlineBox* lineBox, 816 RootInlineBox* lineBox,
798 const LineInfo& lineInfo, 817 const LineInfo& lineInfo,
799 ETextAlign textAlign,
800 LayoutUnit& logicalLeft, 818 LayoutUnit& logicalLeft,
801 LayoutUnit& availableLogicalWidth, 819 LayoutUnit& availableLogicalWidth,
802 BidiRun* firstRun, 820 BidiRun* firstRun,
803 BidiRun* trailingSpaceRun, 821 BidiRun* trailingSpaceRun,
804 GlyphOverflowAndFallbackFontsMap& textBoxDataMap, 822 GlyphOverflowAndFallbackFontsMap& textBoxDataMap,
805 VerticalPositionCache& verticalPositionCache, 823 VerticalPositionCache& verticalPositionCache,
806 const WordMeasurements& wordMeasurements) { 824 const WordMeasurements& wordMeasurements) {
807 bool needsWordSpacing = true; 825 bool needsWordSpacing = true;
808 LayoutUnit totalLogicalWidth = lineBox->getFlowSpacingLogicalWidth(); 826 LayoutUnit totalLogicalWidth = lineBox->getFlowSpacingLogicalWidth();
809 bool isAfterExpansion = true; 827 bool isAfterExpansion = true;
810 ExpansionOpportunities expansions; 828 ExpansionOpportunities expansions;
811 LayoutObject* previousObject = nullptr; 829 LayoutObject* previousObject = nullptr;
830 ETextAlign textAlign = lineInfo.textAlign();
812 TextJustify textJustify = style()->getTextJustify(); 831 TextJustify textJustify = style()->getTextJustify();
813 832
814 BidiRun* r = firstRun; 833 BidiRun* r = firstRun;
815 size_t wordMeasurementsIndex = 0; 834 size_t wordMeasurementsIndex = 0;
816 for (; r; r = r->next()) { 835 for (; r; r = r->next()) {
817 if (!r->m_box || r->m_lineLayoutItem.isOutOfFlowPositioned() || 836 if (!r->m_box || r->m_lineLayoutItem.isOutOfFlowPositioned() ||
818 r->m_box->isLineBreak()) { 837 r->m_box->isLineBreak()) {
819 continue; // Positioned objects are only participating to figure out 838 continue; // Positioned objects are only participating to figure out
820 // their correct static x position. They have no effect on the 839 // their correct static x position. They have no effect on the
821 // width. Similarly, line break boxes have no effect on the 840 // width. Similarly, line break boxes have no effect on the
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
1153 : NoVisualOverride); 1172 : NoVisualOverride);
1154 if (isNewUBAParagraph && 1173 if (isNewUBAParagraph &&
1155 styleToUse.getUnicodeBidi() == UnicodeBidi::kPlaintext && 1174 styleToUse.getUnicodeBidi() == UnicodeBidi::kPlaintext &&
1156 !resolver.context()->parent()) { 1175 !resolver.context()->parent()) {
1157 TextDirection direction = determinePlaintextDirectionality( 1176 TextDirection direction = determinePlaintextDirectionality(
1158 resolver.position().root(), resolver.position().getLineLayoutItem(), 1177 resolver.position().root(), resolver.position().getLineLayoutItem(),
1159 resolver.position().offset()); 1178 resolver.position().offset());
1160 resolver.setStatus( 1179 resolver.setStatus(
1161 BidiStatus(direction, isOverride(styleToUse.getUnicodeBidi()))); 1180 BidiStatus(direction, isOverride(styleToUse.getUnicodeBidi())));
1162 } 1181 }
1182
1183 ETextAlign textAlign = textAlignmentForLine(
1184 !endOfLine.atEnd() &&
1185 !layoutState.lineInfo().previousLineBrokeCleanly());
1186 layoutState.lineInfo().setTextAlign(textAlign);
1187 resolver.setNeedsTrailingSpace(
1188 textAlignmentNeedsTrailingSpace(textAlign, styleToUse));
1189
1163 // FIXME: This ownership is reversed. We should own the BidiRunList and 1190 // FIXME: This ownership is reversed. We should own the BidiRunList and
1164 // pass it to createBidiRunsForLine. 1191 // pass it to createBidiRunsForLine.
1165 BidiRunList<BidiRun>& bidiRuns = resolver.runs(); 1192 BidiRunList<BidiRun>& bidiRuns = resolver.runs();
1166 constructBidiRunsForLine( 1193 constructBidiRunsForLine(
1167 resolver, bidiRuns, endOfLine, override, 1194 resolver, bidiRuns, endOfLine, override,
1168 layoutState.lineInfo().previousLineBrokeCleanly(), isNewUBAParagraph); 1195 layoutState.lineInfo().previousLineBrokeCleanly(), isNewUBAParagraph);
1169 ASSERT(resolver.position() == endOfLine); 1196 ASSERT(resolver.position() == endOfLine);
1170 1197
1171 BidiRun* trailingSpaceRun = resolver.trailingSpaceRun(); 1198 BidiRun* trailingSpaceRun = resolver.trailingSpaceRun();
1172 1199
(...skipping 1418 matching lines...) Expand 10 before | Expand all | Expand 10 after
2591 2618
2592 bool LayoutBlockFlow::paintedOutputOfObjectHasNoEffectRegardlessOfSize() const { 2619 bool LayoutBlockFlow::paintedOutputOfObjectHasNoEffectRegardlessOfSize() const {
2593 // LayoutBlockFlow is in charge of paint invalidation of the first line. 2620 // LayoutBlockFlow is in charge of paint invalidation of the first line.
2594 if (firstLineBox()) 2621 if (firstLineBox())
2595 return false; 2622 return false;
2596 2623
2597 return LayoutBlock::paintedOutputOfObjectHasNoEffectRegardlessOfSize(); 2624 return LayoutBlock::paintedOutputOfObjectHasNoEffectRegardlessOfSize();
2598 } 2625 }
2599 2626
2600 } // namespace blink 2627 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/layout/LayoutBlockFlow.h ('k') | third_party/WebKit/Source/core/layout/line/InlineIterator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698