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 * | 5 * |
6 * This library is free software; you can redistribute it and/or | 6 * This library is free software; you can redistribute it and/or |
7 * modify it under the terms of the GNU Library General Public | 7 * modify it under the terms of the GNU Library General Public |
8 * License as published by the Free Software Foundation; either | 8 * License as published by the Free Software Foundation; either |
9 * version 2 of the License, or (at your option) any later version. | 9 * version 2 of the License, or (at your option) any later version. |
10 * | 10 * |
(...skipping 2600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2611 | 2611 |
2612 // This variable is used only if whitespace isn't set to PRE, and it tells u
s whether | 2612 // This variable is used only if whitespace isn't set to PRE, and it tells u
s whether |
2613 // or not we are currently ignoring whitespace. | 2613 // or not we are currently ignoring whitespace. |
2614 bool ignoringSpaces = false; | 2614 bool ignoringSpaces = false; |
2615 InlineIterator ignoreStart; | 2615 InlineIterator ignoreStart; |
2616 | 2616 |
2617 // This variable tracks whether the very last character we saw was a space.
We use | 2617 // This variable tracks whether the very last character we saw was a space.
We use |
2618 // this to detect when we encounter a second space so we know we have to ter
minate | 2618 // this to detect when we encounter a second space so we know we have to ter
minate |
2619 // a run. | 2619 // a run. |
2620 bool currentCharacterIsSpace = false; | 2620 bool currentCharacterIsSpace = false; |
| 2621 bool currentCharacterShouldCollapseIfPreWap = false; |
2621 TrailingObjects trailingObjects; | 2622 TrailingObjects trailingObjects; |
2622 | 2623 |
2623 InlineIterator lBreak = resolver.position(); | 2624 InlineIterator lBreak = resolver.position(); |
2624 | 2625 |
2625 // FIXME: It is error-prone to split the position object out like this. | 2626 // FIXME: It is error-prone to split the position object out like this. |
2626 // Teach this code to work with objects instead of this split tuple. | 2627 // Teach this code to work with objects instead of this split tuple. |
2627 InlineIterator current = resolver.position(); | 2628 InlineIterator current = resolver.position(); |
2628 RenderObject* last = current.m_obj; | 2629 RenderObject* last = current.m_obj; |
2629 bool atStart = true; | 2630 bool atStart = true; |
2630 | 2631 |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2746 // line box to affect the height of the line if the rest of the
line is not empty. | 2747 // line box to affect the height of the line if the rest of the
line is not empty. |
2747 if (requiresLineBox) | 2748 if (requiresLineBox) |
2748 lineInfo.setEmpty(false, m_block, &width); | 2749 lineInfo.setEmpty(false, m_block, &width); |
2749 if (ignoringSpaces) { | 2750 if (ignoringSpaces) { |
2750 trailingObjects.clear(); | 2751 trailingObjects.clear(); |
2751 ensureLineBoxInsideIgnoredSpaces(lineMidpointState, current.
m_obj); | 2752 ensureLineBoxInsideIgnoredSpaces(lineMidpointState, current.
m_obj); |
2752 } else if (blockStyle->collapseWhiteSpace() && resolver.position
().m_obj == current.m_obj | 2753 } else if (blockStyle->collapseWhiteSpace() && resolver.position
().m_obj == current.m_obj |
2753 && shouldSkipWhitespaceAfterStartObject(m_block, current.m_o
bj, lineMidpointState)) { | 2754 && shouldSkipWhitespaceAfterStartObject(m_block, current.m_o
bj, lineMidpointState)) { |
2754 // Like with list markers, we start ignoring spaces to make
sure that any | 2755 // Like with list markers, we start ignoring spaces to make
sure that any |
2755 // additional spaces we see will be discarded. | 2756 // additional spaces we see will be discarded. |
2756 currentCharacterIsSpace = true; | 2757 currentCharacterShouldCollapseIfPreWap = currentCharacterIsS
pace = true; |
2757 ignoringSpaces = true; | 2758 ignoringSpaces = true; |
2758 } | 2759 } |
2759 } | 2760 } |
2760 | 2761 |
2761 width.addUncommittedWidth(inlineLogicalWidth(current.m_obj) + border
PaddingMarginStart(flowBox) + borderPaddingMarginEnd(flowBox)); | 2762 width.addUncommittedWidth(inlineLogicalWidth(current.m_obj) + border
PaddingMarginStart(flowBox) + borderPaddingMarginEnd(flowBox)); |
2762 } else if (current.m_obj->isReplaced()) { | 2763 } else if (current.m_obj->isReplaced()) { |
2763 RenderBox* replacedBox = toRenderBox(current.m_obj); | 2764 RenderBox* replacedBox = toRenderBox(current.m_obj); |
2764 | 2765 |
2765 if (atStart) | 2766 if (atStart) |
2766 width.updateAvailableWidth(replacedBox->logicalHeight()); | 2767 width.updateAvailableWidth(replacedBox->logicalHeight()); |
2767 | 2768 |
2768 // Break on replaced elements if either has normal white-space. | 2769 // Break on replaced elements if either has normal white-space. |
2769 if ((autoWrap || RenderStyle::autoWrap(lastWS)) && (!current.m_obj->
isImage() || allowImagesToBreak)) { | 2770 if ((autoWrap || RenderStyle::autoWrap(lastWS)) && (!current.m_obj->
isImage() || allowImagesToBreak)) { |
2770 width.commit(); | 2771 width.commit(); |
2771 lBreak.moveToStartOf(current.m_obj); | 2772 lBreak.moveToStartOf(current.m_obj); |
2772 } | 2773 } |
2773 | 2774 |
2774 if (ignoringSpaces) | 2775 if (ignoringSpaces) |
2775 stopIgnoringSpaces(lineMidpointState, InlineIterator(0, current.
m_obj, 0)); | 2776 stopIgnoringSpaces(lineMidpointState, InlineIterator(0, current.
m_obj, 0)); |
2776 | 2777 |
2777 lineInfo.setEmpty(false, m_block, &width); | 2778 lineInfo.setEmpty(false, m_block, &width); |
2778 ignoringSpaces = false; | 2779 ignoringSpaces = false; |
2779 currentCharacterIsSpace = false; | 2780 currentCharacterShouldCollapseIfPreWap = currentCharacterIsSpace = f
alse; |
2780 trailingObjects.clear(); | 2781 trailingObjects.clear(); |
2781 | 2782 |
2782 // Optimize for a common case. If we can't find whitespace after the
list | 2783 // Optimize for a common case. If we can't find whitespace after the
list |
2783 // item, then this is all moot. | 2784 // item, then this is all moot. |
2784 LayoutUnit replacedLogicalWidth = m_block->logicalWidthForChild(repl
acedBox) + m_block->marginStartForChild(replacedBox) + m_block->marginEndForChil
d(replacedBox) + inlineLogicalWidth(current.m_obj); | 2785 LayoutUnit replacedLogicalWidth = m_block->logicalWidthForChild(repl
acedBox) + m_block->marginStartForChild(replacedBox) + m_block->marginEndForChil
d(replacedBox) + inlineLogicalWidth(current.m_obj); |
2785 if (current.m_obj->isListMarker()) { | 2786 if (current.m_obj->isListMarker()) { |
2786 if (blockStyle->collapseWhiteSpace() && shouldSkipWhitespaceAfte
rStartObject(m_block, current.m_obj, lineMidpointState)) { | 2787 if (blockStyle->collapseWhiteSpace() && shouldSkipWhitespaceAfte
rStartObject(m_block, current.m_obj, lineMidpointState)) { |
2787 // Like with inline flows, we start ignoring spaces to make
sure that any | 2788 // Like with inline flows, we start ignoring spaces to make
sure that any |
2788 // additional spaces we see will be discarded. | 2789 // additional spaces we see will be discarded. |
2789 currentCharacterIsSpace = true; | 2790 currentCharacterShouldCollapseIfPreWap = currentCharacterIsS
pace = true; |
2790 ignoringSpaces = true; | 2791 ignoringSpaces = true; |
2791 } | 2792 } |
2792 if (toRenderListMarker(current.m_obj)->isInside()) | 2793 if (toRenderListMarker(current.m_obj)->isInside()) |
2793 width.addUncommittedWidth(replacedLogicalWidth); | 2794 width.addUncommittedWidth(replacedLogicalWidth); |
2794 } else | 2795 } else |
2795 width.addUncommittedWidth(replacedLogicalWidth); | 2796 width.addUncommittedWidth(replacedLogicalWidth); |
2796 if (current.m_obj->isRubyRun()) | 2797 if (current.m_obj->isRubyRun()) |
2797 width.applyOverhang(toRenderRubyRun(current.m_obj), last, next); | 2798 width.applyOverhang(toRenderRubyRun(current.m_obj), last, next); |
2798 // Update prior line break context characters, using U+FFFD (OBJECT
REPLACEMENT CHARACTER) for replaced element. | 2799 // Update prior line break context characters, using U+FFFD (OBJECT
REPLACEMENT CHARACTER) for replaced element. |
2799 renderTextInfo.m_lineBreakIterator.updatePriorContext(replacementCha
racter); | 2800 renderTextInfo.m_lineBreakIterator.updatePriorContext(replacementCha
racter); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2863 TextLayout* textLayout = renderTextInfo.m_layout.get(); | 2864 TextLayout* textLayout = renderTextInfo.m_layout.get(); |
2864 | 2865 |
2865 // Non-zero only when kerning is enabled and TextLayout isn't used,
in which case we measure | 2866 // Non-zero only when kerning is enabled and TextLayout isn't used,
in which case we measure |
2866 // words with their trailing space, then subtract its width. | 2867 // words with their trailing space, then subtract its width. |
2867 float wordTrailingSpaceWidth = (f.typesettingFeatures() & Kerning) &
& !textLayout ? f.width(constructTextRun(t, f, &space, 1, style)) + wordSpacing
: 0; | 2868 float wordTrailingSpaceWidth = (f.typesettingFeatures() & Kerning) &
& !textLayout ? f.width(constructTextRun(t, f, &space, 1, style)) + wordSpacing
: 0; |
2868 | 2869 |
2869 UChar lastCharacter = renderTextInfo.m_lineBreakIterator.lastCharact
er(); | 2870 UChar lastCharacter = renderTextInfo.m_lineBreakIterator.lastCharact
er(); |
2870 UChar secondToLastCharacter = renderTextInfo.m_lineBreakIterator.sec
ondToLastCharacter(); | 2871 UChar secondToLastCharacter = renderTextInfo.m_lineBreakIterator.sec
ondToLastCharacter(); |
2871 for (; current.m_pos < t->textLength(); current.fastIncrementInTextN
ode()) { | 2872 for (; current.m_pos < t->textLength(); current.fastIncrementInTextN
ode()) { |
2872 bool previousCharacterIsSpace = currentCharacterIsSpace; | 2873 bool previousCharacterIsSpace = currentCharacterIsSpace; |
| 2874 bool previousCharacterShouldCollapseIfPreWap = currentCharacterS
houldCollapseIfPreWap; |
2873 UChar c = current.current(); | 2875 UChar c = current.current(); |
2874 currentCharacterIsSpace = c == ' ' || c == '\t' || (!preserveNew
line && (c == '\n')); | 2876 currentCharacterShouldCollapseIfPreWap = currentCharacterIsSpace
= c == ' ' || c == '\t' || (!preserveNewline && (c == '\n')); |
2875 | 2877 |
2876 if (!collapseWhiteSpace || !currentCharacterIsSpace) | 2878 if (!collapseWhiteSpace || !currentCharacterIsSpace) |
2877 lineInfo.setEmpty(false, m_block, &width); | 2879 lineInfo.setEmpty(false, m_block, &width); |
2878 | 2880 |
2879 if (c == softHyphen && autoWrap && !hyphenWidth && style->hyphen
s() != HyphensNone) { | 2881 if (c == softHyphen && autoWrap && !hyphenWidth && style->hyphen
s() != HyphensNone) { |
2880 hyphenWidth = measureHyphenWidth(t, f); | 2882 hyphenWidth = measureHyphenWidth(t, f); |
2881 width.addUncommittedWidth(hyphenWidth); | 2883 width.addUncommittedWidth(hyphenWidth); |
2882 } | 2884 } |
2883 | 2885 |
2884 bool applyWordSpacing = false; | 2886 bool applyWordSpacing = false; |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3050 if (toRenderSVGInlineText(t)->characterStartsNewTextChunk(cu
rrent.m_pos)) | 3052 if (toRenderSVGInlineText(t)->characterStartsNewTextChunk(cu
rrent.m_pos)) |
3051 ensureCharacterGetsLineBox(lineMidpointState, current); | 3053 ensureCharacterGetsLineBox(lineMidpointState, current); |
3052 } | 3054 } |
3053 #endif | 3055 #endif |
3054 | 3056 |
3055 if (currentCharacterIsSpace && !previousCharacterIsSpace) { | 3057 if (currentCharacterIsSpace && !previousCharacterIsSpace) { |
3056 ignoreStart.m_obj = current.m_obj; | 3058 ignoreStart.m_obj = current.m_obj; |
3057 ignoreStart.m_pos = current.m_pos; | 3059 ignoreStart.m_pos = current.m_pos; |
3058 } | 3060 } |
3059 | 3061 |
3060 if (!currentCharacterIsSpace && previousCharacterIsSpace) { | 3062 if (!currentCharacterIsSpace && previousCharacterShouldCollapseI
fPreWap) { |
3061 if (autoWrap && currentStyle->breakOnlyAfterWhiteSpace()) | 3063 if (autoWrap && currentStyle->breakOnlyAfterWhiteSpace()) |
3062 lBreak.moveTo(current.m_obj, current.m_pos, current.m_ne
xtBreakablePosition); | 3064 lBreak.moveTo(current.m_obj, current.m_pos, current.m_ne
xtBreakablePosition); |
3063 } | 3065 } |
3064 | 3066 |
3065 if (collapseWhiteSpace && currentCharacterIsSpace && !ignoringSp
aces) | 3067 if (collapseWhiteSpace && currentCharacterIsSpace && !ignoringSp
aces) |
3066 trailingObjects.setTrailingWhitespace(toRenderText(current.m
_obj)); | 3068 trailingObjects.setTrailingWhitespace(toRenderText(current.m
_obj)); |
3067 else if (!currentStyle->collapseWhiteSpace() || !currentCharacte
rIsSpace) | 3069 else if (!currentStyle->collapseWhiteSpace() || !currentCharacte
rIsSpace) |
3068 trailingObjects.clear(); | 3070 trailingObjects.clear(); |
3069 | 3071 |
3070 atStart = false; | 3072 atStart = false; |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3378 lineGridBox->alignBoxesInBlockDirection(logicalHeight(), textBoxDataMap, ver
ticalPositionCache); | 3380 lineGridBox->alignBoxesInBlockDirection(logicalHeight(), textBoxDataMap, ver
ticalPositionCache); |
3379 | 3381 |
3380 setLineGridBox(lineGridBox); | 3382 setLineGridBox(lineGridBox); |
3381 | 3383 |
3382 // FIXME: If any of the characteristics of the box change compared to the ol
d one, then we need to do a deep dirtying | 3384 // FIXME: If any of the characteristics of the box change compared to the ol
d one, then we need to do a deep dirtying |
3383 // (similar to what happens when the page height changes). Ideally, though,
we only do this if someone is actually snapping | 3385 // (similar to what happens when the page height changes). Ideally, though,
we only do this if someone is actually snapping |
3384 // to this grid. | 3386 // to this grid. |
3385 } | 3387 } |
3386 | 3388 |
3387 } | 3389 } |
OLD | NEW |