| OLD | NEW |
| 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. All r
ight reserved. | 3 * Copyright (C) 2003, 2004, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r
ight reserved. |
| 4 * Copyright (C) 2010 Google Inc. All rights reserved. | 4 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 5 * Copyright (C) 2013 Adobe Systems Incorporated. | 5 * Copyright (C) 2013 Adobe Systems Incorporated. |
| 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 642 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 653 } | 653 } |
| 654 | 654 |
| 655 const ComputedStyle& style = layoutText.styleRef(m_lineInfo.isFirstLine()); | 655 const ComputedStyle& style = layoutText.styleRef(m_lineInfo.isFirstLine()); |
| 656 const Font& font = style.font(); | 656 const Font& font = style.font(); |
| 657 | 657 |
| 658 unsigned lastSpace = m_current.offset(); | 658 unsigned lastSpace = m_current.offset(); |
| 659 float wordSpacing = m_currentStyle->wordSpacing(); | 659 float wordSpacing = m_currentStyle->wordSpacing(); |
| 660 float lastSpaceWordSpacing = 0; | 660 float lastSpaceWordSpacing = 0; |
| 661 float wordSpacingForWordMeasurement = 0; | 661 float wordSpacingForWordMeasurement = 0; |
| 662 | 662 |
| 663 float widthFromLastBreakingOpportunity = m_width.uncommittedWidth(); |
| 663 float charWidth = 0; | 664 float charWidth = 0; |
| 664 // Auto-wrapping text should wrap in the middle of a word only if it could n
ot wrap before the word, | 665 // Auto-wrapping text should wrap in the middle of a word only if it could n
ot wrap before the word, |
| 665 // which is only possible if the word is the first thing on the line, that i
s, if |w| is zero. | 666 // which is only possible if the word is the first thing on the line, that i
s, if |w| is zero. |
| 666 bool breakWords = m_currentStyle->breakWords() && ((m_autoWrap && !m_width.c
ommittedWidth()) || m_currWS == PRE); | 667 bool breakWords = m_currentStyle->breakWords() && ((m_autoWrap && !m_width.c
ommittedWidth()) || m_currWS == PRE); |
| 668 bool midWordBreak = false; |
| 667 bool breakAll = m_currentStyle->wordBreak() == BreakAllWordBreak && m_autoWr
ap; | 669 bool breakAll = m_currentStyle->wordBreak() == BreakAllWordBreak && m_autoWr
ap; |
| 668 bool keepAll = m_currentStyle->wordBreak() == KeepAllWordBreak && m_autoWrap
; | 670 bool keepAll = m_currentStyle->wordBreak() == KeepAllWordBreak && m_autoWrap
; |
| 669 bool prohibitBreakInside = m_currentStyle->hasTextCombine() && layoutText.is
CombineText() && LineLayoutTextCombine(layoutText).isCombined(); | 671 bool prohibitBreakInside = m_currentStyle->hasTextCombine() && layoutText.is
CombineText() && LineLayoutTextCombine(layoutText).isCombined(); |
| 670 | 672 |
| 671 // This is currently only used for word-break: break-all, specifically for t
he case | 673 // This is currently only used for word-break: break-all, specifically for t
he case |
| 672 // where we have a break opportunity within a word, then a string of non-bre
akable | 674 // where we have a break opportunity within a word, then a string of non-bre
akable |
| 673 // content that ends up making our word wider than the current line. | 675 // content that ends up making our word wider than the current line. |
| 674 // See: fast/css3-text/css3-word-break/word-break-all-wrap-with-floats.html | 676 // See: fast/css3-text/css3-word-break/word-break-all-wrap-with-floats.html |
| 675 float widthMeasurementAtLastBreakOpportunity = 0; | 677 float widthMeasurementAtLastBreakOpportunity = 0; |
| 676 | 678 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 719 m_width.setTrailingWhitespaceWidth(0); | 721 m_width.setTrailingWhitespaceWidth(0); |
| 720 } | 722 } |
| 721 | 723 |
| 722 if (c == softHyphenCharacter && m_autoWrap && !hyphenWidth) { | 724 if (c == softHyphenCharacter && m_autoWrap && !hyphenWidth) { |
| 723 hyphenWidth = layoutText.hyphenWidth(font, textDirectionFromUnicode(
m_resolver.position().direction())); | 725 hyphenWidth = layoutText.hyphenWidth(font, textDirectionFromUnicode(
m_resolver.position().direction())); |
| 724 m_width.addUncommittedWidth(hyphenWidth); | 726 m_width.addUncommittedWidth(hyphenWidth); |
| 725 } | 727 } |
| 726 | 728 |
| 727 bool applyWordSpacing = false; | 729 bool applyWordSpacing = false; |
| 728 | 730 |
| 731 // Determine if we should try breaking in the middle of a word. |
| 732 if (breakWords && !midWordBreak && !U16_IS_TRAIL(c)) { |
| 733 widthFromLastBreakingOpportunity += charWidth; |
| 734 bool midWordBreakIsBeforeSurrogatePair = U16_IS_LEAD(c) && m_current
.offset() + 1 < layoutText.textLength() && U16_IS_TRAIL(layoutText.uncheckedChar
acterAt(m_current.offset() + 1)); |
| 735 charWidth = textWidth(layoutText, m_current.offset(), midWordBreakIs
BeforeSurrogatePair ? 2 : 1, font, m_width.committedWidth() + widthFromLastBreak
ingOpportunity, m_collapseWhiteSpace); |
| 736 // Measure up to 2em overflow since ligatures/kerning can shorten |
| 737 // the width as we add more characters. rewindToMidWordBreak() can |
| 738 // measure the accurate mid-word break point then. |
| 739 midWordBreak = m_width.committedWidth() + widthFromLastBreakingOppor
tunity + charWidth > m_width.availableWidth() |
| 740 + 2 * font.getFontDescription().computedSize(); |
| 741 } |
| 742 |
| 729 // Determine if we are in the whitespace between words. | 743 // Determine if we are in the whitespace between words. |
| 730 int nextBreakablePosition = m_current.nextBreakablePosition(); | 744 int nextBreakablePosition = m_current.nextBreakablePosition(); |
| 731 bool betweenWords = c == newlineCharacter || (m_currWS != PRE && !m_atSt
art && m_layoutTextInfo.m_lineBreakIterator.isBreakable(m_current.offset(), next
BreakablePosition, lineBreakType)); | 745 bool betweenWords = c == newlineCharacter || (m_currWS != PRE && !m_atSt
art && m_layoutTextInfo.m_lineBreakIterator.isBreakable(m_current.offset(), next
BreakablePosition, lineBreakType)); |
| 732 m_current.setNextBreakablePosition(nextBreakablePosition); | 746 m_current.setNextBreakablePosition(nextBreakablePosition); |
| 733 | 747 |
| 734 // If we're in the middle of a word or at the start of a new one and can
't break there, then continue to the next character. | 748 // If we're in the middle of a word or at the start of a new one and can
't break there, then continue to the next character. |
| 735 if (!betweenWords) { | 749 if (!betweenWords && !midWordBreak) { |
| 736 if (m_ignoringSpaces) { | 750 if (m_ignoringSpaces) { |
| 737 // Stop ignoring spaces and begin at this | 751 // Stop ignoring spaces and begin at this |
| 738 // new point. | 752 // new point. |
| 739 lastSpaceWordSpacing = applyWordSpacing ? wordSpacing : 0; | 753 lastSpaceWordSpacing = applyWordSpacing ? wordSpacing : 0; |
| 740 wordSpacingForWordMeasurement = (applyWordSpacing && wordMeasure
ments.last().width) ? wordSpacing : 0; | 754 wordSpacingForWordMeasurement = (applyWordSpacing && wordMeasure
ments.last().width) ? wordSpacing : 0; |
| 741 stopIgnoringSpaces(lastSpace); | 755 stopIgnoringSpaces(lastSpace); |
| 742 } | 756 } |
| 743 | 757 |
| 744 prepareForNextCharacter(layoutText, prohibitBreakInside, previousCha
racterIsSpace); | 758 prepareForNextCharacter(layoutText, prohibitBreakInside, previousCha
racterIsSpace); |
| 745 m_atStart = false; | 759 m_atStart = false; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 764 wordSpacingForWordMeasurement = 0; | 778 wordSpacingForWordMeasurement = 0; |
| 765 stoppedIgnoringSpaces = true; | 779 stoppedIgnoringSpaces = true; |
| 766 stopIgnoringSpaces(lastSpace); | 780 stopIgnoringSpaces(lastSpace); |
| 767 } | 781 } |
| 768 | 782 |
| 769 // Update our tally of the width since the last breakable position with
the width of the word we're now at the end of. | 783 // Update our tally of the width since the last breakable position with
the width of the word we're now at the end of. |
| 770 float lastWidthMeasurement; | 784 float lastWidthMeasurement; |
| 771 WordMeasurement& wordMeasurement = calculateWordWidth(wordMeasurements,
layoutText, lastSpace, lastWidthMeasurement, wordSpacingForWordMeasurement, font
, wordTrailingSpaceWidth, c); | 785 WordMeasurement& wordMeasurement = calculateWordWidth(wordMeasurements,
layoutText, lastSpace, lastWidthMeasurement, wordSpacingForWordMeasurement, font
, wordTrailingSpaceWidth, c); |
| 772 lastWidthMeasurement += lastSpaceWordSpacing; | 786 lastWidthMeasurement += lastSpaceWordSpacing; |
| 773 | 787 |
| 774 bool midWordBreak = false; | 788 midWordBreak = false; |
| 775 if (canBreakMidWord && !m_width.fitsOnLine(lastWidthMeasurement) | 789 if (canBreakMidWord && !m_width.fitsOnLine(lastWidthMeasurement) |
| 776 && rewindToMidWordBreak(layoutText, style, font, breakAll, wordMeasu
rement)) { | 790 && rewindToMidWordBreak(layoutText, style, font, breakAll, wordMeasu
rement)) { |
| 777 lastWidthMeasurement = wordMeasurement.width; | 791 lastWidthMeasurement = wordMeasurement.width; |
| 778 midWordBreak = true; | 792 midWordBreak = true; |
| 779 } | 793 } |
| 780 | 794 |
| 781 m_width.addUncommittedWidth(lastWidthMeasurement); | 795 m_width.addUncommittedWidth(lastWidthMeasurement); |
| 782 | 796 |
| 783 // We keep track of the total width contributed by trailing space as we
often want to exclude it when determining | 797 // We keep track of the total width contributed by trailing space as we
often want to exclude it when determining |
| 784 // if a run fits on a line. | 798 // if a run fits on a line. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 809 m_lineBreak.moveTo(m_current.getLineLayoutItem(), m_current.offset()
, m_current.nextBreakablePosition()); | 823 m_lineBreak.moveTo(m_current.getLineLayoutItem(), m_current.offset()
, m_current.nextBreakablePosition()); |
| 810 m_lineBreak.increment(); | 824 m_lineBreak.increment(); |
| 811 m_lineInfo.setPreviousLineBrokeCleanly(true); | 825 m_lineInfo.setPreviousLineBrokeCleanly(true); |
| 812 return true; | 826 return true; |
| 813 } | 827 } |
| 814 | 828 |
| 815 // Auto-wrapping text should not wrap in the middle of a word once it ha
s had an | 829 // Auto-wrapping text should not wrap in the middle of a word once it ha
s had an |
| 816 // opportunity to break after a word. | 830 // opportunity to break after a word. |
| 817 if (m_autoWrap && betweenWords) { | 831 if (m_autoWrap && betweenWords) { |
| 818 m_width.commit(); | 832 m_width.commit(); |
| 833 widthFromLastBreakingOpportunity = 0; |
| 819 m_lineBreak.moveTo(m_current.getLineLayoutItem(), m_current.offset()
, m_current.nextBreakablePosition()); | 834 m_lineBreak.moveTo(m_current.getLineLayoutItem(), m_current.offset()
, m_current.nextBreakablePosition()); |
| 820 breakWords = false; | 835 breakWords = false; |
| 821 canBreakMidWord = breakAll; | 836 canBreakMidWord = breakAll; |
| 822 widthMeasurementAtLastBreakOpportunity = lastWidthMeasurement; | 837 widthMeasurementAtLastBreakOpportunity = lastWidthMeasurement; |
| 823 } | 838 } |
| 824 | 839 |
| 825 if (betweenWords) { | 840 if (betweenWords) { |
| 826 lastSpaceWordSpacing = applyWordSpacing ? wordSpacing : 0; | 841 lastSpaceWordSpacing = applyWordSpacing ? wordSpacing : 0; |
| 827 wordSpacingForWordMeasurement = (applyWordSpacing && wordMeasurement
.width) ? wordSpacing : 0; | 842 wordSpacingForWordMeasurement = (applyWordSpacing && wordMeasurement
.width) ? wordSpacing : 0; |
| 828 lastSpace = m_current.offset(); | 843 lastSpace = m_current.offset(); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 849 m_layoutTextInfo.m_lineBreakIterator.setPriorContext(lastCharacter, secondTo
LastCharacter); | 864 m_layoutTextInfo.m_lineBreakIterator.setPriorContext(lastCharacter, secondTo
LastCharacter); |
| 850 | 865 |
| 851 wordMeasurements.grow(wordMeasurements.size() + 1); | 866 wordMeasurements.grow(wordMeasurements.size() + 1); |
| 852 WordMeasurement& wordMeasurement = wordMeasurements.last(); | 867 WordMeasurement& wordMeasurement = wordMeasurements.last(); |
| 853 wordMeasurement.layoutText = layoutText; | 868 wordMeasurement.layoutText = layoutText; |
| 854 | 869 |
| 855 // IMPORTANT: current.offset() is > layoutText.textLength() here! | 870 // IMPORTANT: current.offset() is > layoutText.textLength() here! |
| 856 float lastWidthMeasurement = 0; | 871 float lastWidthMeasurement = 0; |
| 857 wordMeasurement.startOffset = lastSpace; | 872 wordMeasurement.startOffset = lastSpace; |
| 858 wordMeasurement.endOffset = m_current.offset(); | 873 wordMeasurement.endOffset = m_current.offset(); |
| 859 bool midWordBreak = false; | 874 midWordBreak = false; |
| 860 if (!m_ignoringSpaces) { | 875 if (!m_ignoringSpaces) { |
| 861 lastWidthMeasurement = textWidth(layoutText, lastSpace, m_current.offset
() - lastSpace, font, m_width.currentWidth(), m_collapseWhiteSpace, &wordMeasure
ment.fallbackFonts, &wordMeasurement.glyphBounds); | 876 lastWidthMeasurement = textWidth(layoutText, lastSpace, m_current.offset
() - lastSpace, font, m_width.currentWidth(), m_collapseWhiteSpace, &wordMeasure
ment.fallbackFonts, &wordMeasurement.glyphBounds); |
| 862 wordMeasurement.width = lastWidthMeasurement + wordSpacingForWordMeasure
ment; | 877 wordMeasurement.width = lastWidthMeasurement + wordSpacingForWordMeasure
ment; |
| 863 wordMeasurement.glyphBounds.move(wordSpacingForWordMeasurement, 0); | 878 wordMeasurement.glyphBounds.move(wordSpacingForWordMeasurement, 0); |
| 864 | 879 |
| 865 if (canBreakMidWord && !m_width.fitsOnLine(lastWidthMeasurement) | 880 if (canBreakMidWord && !m_width.fitsOnLine(lastWidthMeasurement) |
| 866 && rewindToMidWordBreak(layoutText, style, font, breakAll, wordMeasu
rement)) { | 881 && rewindToMidWordBreak(layoutText, style, font, breakAll, wordMeasu
rement)) { |
| 867 lastWidthMeasurement = wordMeasurement.width; | 882 lastWidthMeasurement = wordMeasurement.width; |
| 868 midWordBreak = true; | 883 midWordBreak = true; |
| 869 } | 884 } |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1081 | 1096 |
| 1082 if (style.getTextIndentType() == TextIndentHanging) | 1097 if (style.getTextIndentType() == TextIndentHanging) |
| 1083 indentText = indentText == IndentText ? DoNotIndentText : IndentText; | 1098 indentText = indentText == IndentText ? DoNotIndentText : IndentText; |
| 1084 | 1099 |
| 1085 return indentText; | 1100 return indentText; |
| 1086 } | 1101 } |
| 1087 | 1102 |
| 1088 } // namespace blink | 1103 } // namespace blink |
| 1089 | 1104 |
| 1090 #endif // BreakingContextInlineHeaders_h | 1105 #endif // BreakingContextInlineHeaders_h |
| OLD | NEW |