antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 Apple Inc. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * 1. Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * 2. Redistributions in binary form must reproduce the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer in the |
| 11 | * documentation and/or other materials provided with the distribution. |
| 12 | * |
| 13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
| 14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
| 17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 23 | * THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | */ |
| 25 | |
| 26 | #include "config.h" |
| 27 | #include "SimpleLineLayout.h" |
| 28 | |
mmaxfield@apple.com | e4058ae | 2018-11-06 23:06:37 +0000 | [diff] [blame] | 29 | #include "DocumentMarkerController.h" |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 30 | #include "FontCache.h" |
antti@apple.com | 2ec0501 | 2013-10-30 17:40:06 +0000 | [diff] [blame] | 31 | #include "Frame.h" |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 32 | #include "GraphicsContext.h" |
antti@apple.com | 02a025d | 2013-11-13 13:25:32 +0000 | [diff] [blame] | 33 | #include "HTMLTextFormControlElement.h" |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 34 | #include "HitTestLocation.h" |
| 35 | #include "HitTestRequest.h" |
| 36 | #include "HitTestResult.h" |
zalan@apple.com | 89b951f | 2017-01-24 21:38:20 +0000 | [diff] [blame] | 37 | #include "Hyphenation.h" |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 38 | #include "InlineTextBox.h" |
| 39 | #include "LineWidth.h" |
zalan@apple.com | 58cb218 | 2015-12-03 21:59:17 +0000 | [diff] [blame] | 40 | #include "Logging.h" |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 41 | #include "PaintInfo.h" |
| 42 | #include "RenderBlockFlow.h" |
zalan@apple.com | 29a2eb6 | 2014-11-20 18:11:07 +0000 | [diff] [blame] | 43 | #include "RenderChildIterator.h" |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 44 | #include "RenderFragmentedFlow.h" |
zalan@apple.com | 8bf2a91 | 2015-04-10 03:15:50 +0000 | [diff] [blame] | 45 | #include "RenderLineBreak.h" |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 46 | #include "RenderMultiColumnFlow.h" |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 47 | #include "RenderStyle.h" |
| 48 | #include "RenderText.h" |
antti@apple.com | 02a025d | 2013-11-13 13:25:32 +0000 | [diff] [blame] | 49 | #include "RenderTextControl.h" |
zalan@apple.com | 06e2c40 | 2017-03-09 15:25:12 +0000 | [diff] [blame] | 50 | #include "RenderView.h" |
antti@apple.com | 2ec0501 | 2013-10-30 17:40:06 +0000 | [diff] [blame] | 51 | #include "Settings.h" |
zalan@apple.com | f3941b2 | 2014-11-17 23:17:51 +0000 | [diff] [blame] | 52 | #include "SimpleLineLayoutFlowContents.h" |
antti@apple.com | 01a0412 | 2013-11-20 21:23:19 +0000 | [diff] [blame] | 53 | #include "SimpleLineLayoutFunctions.h" |
zalan@apple.com | 6cda0fa | 2018-05-09 00:20:18 +0000 | [diff] [blame] | 54 | #include "SimpleLineLayoutResolver.h" |
zalan@apple.com | 1802def | 2015-02-03 03:08:33 +0000 | [diff] [blame] | 55 | #include "SimpleLineLayoutTextFragmentIterator.h" |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 56 | #include "Text.h" |
| 57 | #include "TextPaintStyle.h" |
mmaxfield@apple.com | 2cc9b8d | 2017-10-11 20:30:16 +0000 | [diff] [blame] | 58 | #include <pal/Logging.h> |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 59 | |
| 60 | namespace WebCore { |
| 61 | namespace SimpleLineLayout { |
| 62 | |
zalan@apple.com | 58cb218 | 2015-12-03 21:59:17 +0000 | [diff] [blame] | 63 | #ifndef NDEBUG |
zalan@apple.com | c1c9760 | 2015-12-07 04:40:35 +0000 | [diff] [blame] | 64 | #define SET_REASON_AND_RETURN_IF_NEEDED(reason, reasons, includeReasons) { \ |
zalan@apple.com | 58cb218 | 2015-12-03 21:59:17 +0000 | [diff] [blame] | 65 | reasons |= reason; \ |
zalan@apple.com | c1c9760 | 2015-12-07 04:40:35 +0000 | [diff] [blame] | 66 | if (includeReasons == IncludeReasons::First) \ |
zalan@apple.com | 58cb218 | 2015-12-03 21:59:17 +0000 | [diff] [blame] | 67 | return reasons; \ |
| 68 | } |
| 69 | #else |
zalan@apple.com | c1c9760 | 2015-12-07 04:40:35 +0000 | [diff] [blame] | 70 | #define SET_REASON_AND_RETURN_IF_NEEDED(reason, reasons, includeReasons) { \ |
| 71 | ASSERT_UNUSED(includeReasons, includeReasons == IncludeReasons::First); \ |
zalan@apple.com | 58cb218 | 2015-12-03 21:59:17 +0000 | [diff] [blame] | 72 | reasons |= reason; \ |
| 73 | return reasons; \ |
| 74 | } |
| 75 | #endif |
| 76 | |
zalan@apple.com | 1ecaa80 | 2017-02-04 16:34:57 +0000 | [diff] [blame] | 77 | |
| 78 | template <typename CharacterType> AvoidanceReasonFlags canUseForCharacter(CharacterType, bool textIsJustified, IncludeReasons); |
| 79 | |
| 80 | template<> AvoidanceReasonFlags canUseForCharacter(UChar character, bool textIsJustified, IncludeReasons includeReasons) |
| 81 | { |
| 82 | AvoidanceReasonFlags reasons = { }; |
| 83 | if (textIsJustified) { |
| 84 | // Include characters up to Latin Extended-B and some punctuation range when text is justified. |
| 85 | bool isLatinIncludingExtendedB = character <= 0x01FF; |
| 86 | bool isPunctuationRange = character >= 0x2010 && character <= 0x2027; |
| 87 | if (!(isLatinIncludingExtendedB || isPunctuationRange)) |
| 88 | SET_REASON_AND_RETURN_IF_NEEDED(FlowHasJustifiedNonLatinText, reasons, includeReasons); |
| 89 | } |
| 90 | |
zalan@apple.com | 9e7bf6e | 2017-02-05 14:41:10 +0000 | [diff] [blame] | 91 | if (U16_IS_SURROGATE(character)) |
| 92 | SET_REASON_AND_RETURN_IF_NEEDED(FlowTextHasSurrogatePair, reasons, includeReasons); |
| 93 | |
zalan@apple.com | 1ecaa80 | 2017-02-04 16:34:57 +0000 | [diff] [blame] | 94 | UCharDirection direction = u_charDirection(character); |
| 95 | if (direction == U_RIGHT_TO_LEFT || direction == U_RIGHT_TO_LEFT_ARABIC |
| 96 | || direction == U_RIGHT_TO_LEFT_EMBEDDING || direction == U_RIGHT_TO_LEFT_OVERRIDE |
| 97 | || direction == U_LEFT_TO_RIGHT_EMBEDDING || direction == U_LEFT_TO_RIGHT_OVERRIDE |
| 98 | || direction == U_POP_DIRECTIONAL_FORMAT || direction == U_BOUNDARY_NEUTRAL) |
| 99 | SET_REASON_AND_RETURN_IF_NEEDED(FlowTextHasDirectionCharacter, reasons, includeReasons); |
| 100 | |
| 101 | return reasons; |
| 102 | } |
| 103 | |
| 104 | template<> AvoidanceReasonFlags canUseForCharacter(LChar, bool, IncludeReasons) |
| 105 | { |
| 106 | return { }; |
| 107 | } |
| 108 | |
antti@apple.com | aa930a6 | 2013-11-08 12:53:19 +0000 | [diff] [blame] | 109 | template <typename CharacterType> |
cdumez@apple.com | 8b7a022 | 2018-12-20 04:41:11 +0000 | [diff] [blame] | 110 | static AvoidanceReasonFlags canUseForText(const CharacterType* text, unsigned length, const FontCascade& fontCascade, Optional<float> lineHeightConstraint, |
zalan@apple.com | 99603d1 | 2017-01-27 19:24:26 +0000 | [diff] [blame] | 111 | bool textIsJustified, IncludeReasons includeReasons) |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 112 | { |
zalan@apple.com | c1c9760 | 2015-12-07 04:40:35 +0000 | [diff] [blame] | 113 | AvoidanceReasonFlags reasons = { }; |
zalan@apple.com | 0508f0f | 2017-02-04 01:42:12 +0000 | [diff] [blame] | 114 | auto& primaryFont = fontCascade.primaryFont(); |
zalan@apple.com | 2c50631 | 2017-04-29 21:16:44 +0000 | [diff] [blame] | 115 | auto& fontMetrics = primaryFont.fontMetrics(); |
| 116 | auto availableSpaceForGlyphAscent = fontMetrics.ascent(); |
| 117 | auto availableSpaceForGlyphDescent = fontMetrics.descent(); |
| 118 | if (lineHeightConstraint) { |
| 119 | auto lineHeightPadding = *lineHeightConstraint - fontMetrics.height(); |
| 120 | availableSpaceForGlyphAscent += lineHeightPadding / 2; |
| 121 | availableSpaceForGlyphDescent += lineHeightPadding / 2; |
| 122 | } |
| 123 | |
antti@apple.com | aa930a6 | 2013-11-08 12:53:19 +0000 | [diff] [blame] | 124 | for (unsigned i = 0; i < length; ++i) { |
zalan@apple.com | 1ecaa80 | 2017-02-04 16:34:57 +0000 | [diff] [blame] | 125 | auto character = text[i]; |
| 126 | if (FontCascade::treatAsSpace(character)) |
antti@apple.com | aa930a6 | 2013-11-08 12:53:19 +0000 | [diff] [blame] | 127 | continue; |
| 128 | |
antti@apple.com | aa930a6 | 2013-11-08 12:53:19 +0000 | [diff] [blame] | 129 | if (character == softHyphen) |
zalan@apple.com | c1c9760 | 2015-12-07 04:40:35 +0000 | [diff] [blame] | 130 | SET_REASON_AND_RETURN_IF_NEEDED(FlowTextHasSoftHyphen, reasons, includeReasons); |
antti@apple.com | aa930a6 | 2013-11-08 12:53:19 +0000 | [diff] [blame] | 131 | |
zalan@apple.com | 9e7bf6e | 2017-02-05 14:41:10 +0000 | [diff] [blame] | 132 | auto characterReasons = canUseForCharacter(character, textIsJustified, includeReasons); |
| 133 | if (characterReasons != NoReason) |
| 134 | SET_REASON_AND_RETURN_IF_NEEDED(characterReasons, reasons, includeReasons); |
| 135 | |
zalan@apple.com | 0508f0f | 2017-02-04 01:42:12 +0000 | [diff] [blame] | 136 | auto glyphData = fontCascade.glyphDataForCharacter(character, false); |
| 137 | if (!glyphData.isValid() || glyphData.font != &primaryFont) |
| 138 | SET_REASON_AND_RETURN_IF_NEEDED(FlowPrimaryFontIsInsufficient, reasons, includeReasons); |
| 139 | |
zalan@apple.com | 2c50631 | 2017-04-29 21:16:44 +0000 | [diff] [blame] | 140 | if (lineHeightConstraint) { |
| 141 | auto bounds = primaryFont.boundsForGlyph(glyphData.glyph); |
| 142 | if (ceilf(-bounds.y()) > availableSpaceForGlyphAscent || ceilf(bounds.maxY()) > availableSpaceForGlyphDescent) |
| 143 | SET_REASON_AND_RETURN_IF_NEEDED(FlowFontHasOverflowGlyph, reasons, includeReasons); |
| 144 | } |
antti@apple.com | aa930a6 | 2013-11-08 12:53:19 +0000 | [diff] [blame] | 145 | } |
zalan@apple.com | 58cb218 | 2015-12-03 21:59:17 +0000 | [diff] [blame] | 146 | return reasons; |
antti@apple.com | aa930a6 | 2013-11-08 12:53:19 +0000 | [diff] [blame] | 147 | } |
commit-queue@webkit.org | 8909786 | 2015-07-14 21:19:50 +0000 | [diff] [blame] | 148 | |
cdumez@apple.com | 8b7a022 | 2018-12-20 04:41:11 +0000 | [diff] [blame] | 149 | static AvoidanceReasonFlags canUseForText(StringView text, const FontCascade& fontCascade, Optional<float> lineHeightConstraint, bool textIsJustified, IncludeReasons includeReasons) |
antti@apple.com | aa930a6 | 2013-11-08 12:53:19 +0000 | [diff] [blame] | 150 | { |
zalan@apple.com | 1ecaa80 | 2017-02-04 16:34:57 +0000 | [diff] [blame] | 151 | if (text.is8Bit()) |
| 152 | return canUseForText(text.characters8(), text.length(), fontCascade, lineHeightConstraint, textIsJustified, includeReasons); |
| 153 | return canUseForText(text.characters16(), text.length(), fontCascade, lineHeightConstraint, textIsJustified, includeReasons); |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 154 | } |
commit-queue@webkit.org | 8909786 | 2015-07-14 21:19:50 +0000 | [diff] [blame] | 155 | |
zalan@apple.com | c1c9760 | 2015-12-07 04:40:35 +0000 | [diff] [blame] | 156 | static AvoidanceReasonFlags canUseForFontAndText(const RenderBlockFlow& flow, IncludeReasons includeReasons) |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 157 | { |
zalan@apple.com | c1c9760 | 2015-12-07 04:40:35 +0000 | [diff] [blame] | 158 | AvoidanceReasonFlags reasons = { }; |
zalan@apple.com | 1cf32e6 | 2015-11-17 21:16:07 +0000 | [diff] [blame] | 159 | // We assume that all lines have metrics based purely on the primary font. |
| 160 | const auto& style = flow.style(); |
zalan@apple.com | 0508f0f | 2017-02-04 01:42:12 +0000 | [diff] [blame] | 161 | auto& fontCascade = style.fontCascade(); |
mmaxfield@apple.com | 0bc9566 | 2017-05-16 01:37:43 +0000 | [diff] [blame] | 162 | if (fontCascade.primaryFont().isInterstitial()) |
zalan@apple.com | c1c9760 | 2015-12-07 04:40:35 +0000 | [diff] [blame] | 163 | SET_REASON_AND_RETURN_IF_NEEDED(FlowIsMissingPrimaryFont, reasons, includeReasons); |
cdumez@apple.com | 8b7a022 | 2018-12-20 04:41:11 +0000 | [diff] [blame] | 164 | Optional<float> lineHeightConstraint; |
simon.fraser@apple.com | 815adf5 | 2019-10-13 16:02:54 +0000 | [diff] [blame] | 165 | if (style.lineBoxContain().contains(LineBoxContain::Glyphs)) |
zalan@apple.com | 99603d1 | 2017-01-27 19:24:26 +0000 | [diff] [blame] | 166 | lineHeightConstraint = lineHeightFromFlow(flow).toFloat(); |
commit-queue@webkit.org | eea2d6a | 2018-05-25 01:42:36 +0000 | [diff] [blame] | 167 | bool flowIsJustified = style.textAlign() == TextAlignMode::Justify; |
zalan@apple.com | 1cf32e6 | 2015-11-17 21:16:07 +0000 | [diff] [blame] | 168 | for (const auto& textRenderer : childrenOfType<RenderText>(flow)) { |
zalan@apple.com | 1ecaa80 | 2017-02-04 16:34:57 +0000 | [diff] [blame] | 169 | // FIXME: Do not return until after checking all children. |
darin@apple.com | 5917cb1 | 2017-11-23 17:32:42 +0000 | [diff] [blame] | 170 | if (textRenderer.text().isEmpty()) |
zalan@apple.com | 1ecaa80 | 2017-02-04 16:34:57 +0000 | [diff] [blame] | 171 | SET_REASON_AND_RETURN_IF_NEEDED(FlowTextIsEmpty, reasons, includeReasons); |
zalan@apple.com | 58cb218 | 2015-12-03 21:59:17 +0000 | [diff] [blame] | 172 | if (textRenderer.isCombineText()) |
zalan@apple.com | c1c9760 | 2015-12-07 04:40:35 +0000 | [diff] [blame] | 173 | SET_REASON_AND_RETURN_IF_NEEDED(FlowTextIsCombineText, reasons, includeReasons); |
zalan@apple.com | 58cb218 | 2015-12-03 21:59:17 +0000 | [diff] [blame] | 174 | if (textRenderer.isCounter()) |
zalan@apple.com | c1c9760 | 2015-12-07 04:40:35 +0000 | [diff] [blame] | 175 | SET_REASON_AND_RETURN_IF_NEEDED(FlowTextIsRenderCounter, reasons, includeReasons); |
zalan@apple.com | 58cb218 | 2015-12-03 21:59:17 +0000 | [diff] [blame] | 176 | if (textRenderer.isQuote()) |
zalan@apple.com | c1c9760 | 2015-12-07 04:40:35 +0000 | [diff] [blame] | 177 | SET_REASON_AND_RETURN_IF_NEEDED(FlowTextIsRenderQuote, reasons, includeReasons); |
zalan@apple.com | 58cb218 | 2015-12-03 21:59:17 +0000 | [diff] [blame] | 178 | if (textRenderer.isTextFragment()) |
zalan@apple.com | c1c9760 | 2015-12-07 04:40:35 +0000 | [diff] [blame] | 179 | SET_REASON_AND_RETURN_IF_NEEDED(FlowTextIsTextFragment, reasons, includeReasons); |
zalan@apple.com | 58cb218 | 2015-12-03 21:59:17 +0000 | [diff] [blame] | 180 | if (textRenderer.isSVGInlineText()) |
zalan@apple.com | c1c9760 | 2015-12-07 04:40:35 +0000 | [diff] [blame] | 181 | SET_REASON_AND_RETURN_IF_NEEDED(FlowTextIsSVGInlineText, reasons, includeReasons); |
zalan@apple.com | 3eb0dd7 | 2017-02-05 18:01:04 +0000 | [diff] [blame] | 182 | if (!textRenderer.canUseSimpleFontCodePath()) { |
| 183 | // No need to check the code path at this point. We already know it can't be simple. |
zalan@apple.com | dcc97ad3 | 2017-02-04 06:03:29 +0000 | [diff] [blame] | 184 | SET_REASON_AND_RETURN_IF_NEEDED(FlowHasComplexFontCodePath, reasons, includeReasons); |
zalan@apple.com | 3eb0dd7 | 2017-02-05 18:01:04 +0000 | [diff] [blame] | 185 | } else { |
commit-queue@webkit.org | b6be03c | 2018-04-09 23:02:29 +0000 | [diff] [blame] | 186 | TextRun run(String(textRenderer.text())); |
zalan@apple.com | 3eb0dd7 | 2017-02-05 18:01:04 +0000 | [diff] [blame] | 187 | run.setCharacterScanForCodePath(false); |
| 188 | if (style.fontCascade().codePath(run) != FontCascade::Simple) |
| 189 | SET_REASON_AND_RETURN_IF_NEEDED(FlowHasComplexFontCodePath, reasons, includeReasons); |
| 190 | } |
zalan@apple.com | 58cb218 | 2015-12-03 21:59:17 +0000 | [diff] [blame] | 191 | |
zalan@apple.com | 1ecaa80 | 2017-02-04 16:34:57 +0000 | [diff] [blame] | 192 | auto textReasons = canUseForText(textRenderer.stringView(), fontCascade, lineHeightConstraint, flowIsJustified, includeReasons); |
zalan@apple.com | 58cb218 | 2015-12-03 21:59:17 +0000 | [diff] [blame] | 193 | if (textReasons != NoReason) |
zalan@apple.com | c1c9760 | 2015-12-07 04:40:35 +0000 | [diff] [blame] | 194 | SET_REASON_AND_RETURN_IF_NEEDED(textReasons, reasons, includeReasons); |
zalan@apple.com | 29a2eb6 | 2014-11-20 18:11:07 +0000 | [diff] [blame] | 195 | } |
zalan@apple.com | 58cb218 | 2015-12-03 21:59:17 +0000 | [diff] [blame] | 196 | return reasons; |
zalan@apple.com | 1cf32e6 | 2015-11-17 21:16:07 +0000 | [diff] [blame] | 197 | } |
| 198 | |
zalan@apple.com | c1c9760 | 2015-12-07 04:40:35 +0000 | [diff] [blame] | 199 | static AvoidanceReasonFlags canUseForStyle(const RenderStyle& style, IncludeReasons includeReasons) |
zalan@apple.com | 1cf32e6 | 2015-11-17 21:16:07 +0000 | [diff] [blame] | 200 | { |
zalan@apple.com | c1c9760 | 2015-12-07 04:40:35 +0000 | [diff] [blame] | 201 | AvoidanceReasonFlags reasons = { }; |
commit-queue@webkit.org | 1a4e667 | 2018-05-21 16:55:45 +0000 | [diff] [blame] | 202 | if (style.textOverflow() == TextOverflow::Ellipsis) |
zalan@apple.com | c1c9760 | 2015-12-07 04:40:35 +0000 | [diff] [blame] | 203 | SET_REASON_AND_RETURN_IF_NEEDED(FlowHasTextOverflow, reasons, includeReasons); |
zalan@apple.com | de4cd16 | 2019-03-28 16:02:24 +0000 | [diff] [blame] | 204 | if (style.textUnderlinePosition() != TextUnderlinePosition::Auto || !style.textUnderlineOffset().isAuto() || !style.textDecorationThickness().isAuto()) |
zalan@apple.com | 114e8aa | 2016-01-02 19:42:22 +0000 | [diff] [blame] | 205 | SET_REASON_AND_RETURN_IF_NEEDED(FlowHasUnsupportedUnderlineDecoration, reasons, includeReasons); |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 206 | // Non-visible overflow should be pretty easy to support. |
commit-queue@webkit.org | 1a4e667 | 2018-05-21 16:55:45 +0000 | [diff] [blame] | 207 | if (style.overflowX() != Overflow::Visible || style.overflowY() != Overflow::Visible) |
zalan@apple.com | 7eff9dd | 2017-02-08 18:33:46 +0000 | [diff] [blame] | 208 | SET_REASON_AND_RETURN_IF_NEEDED(FlowHasOverflowNotVisible, reasons, includeReasons); |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 209 | if (!style.isLeftToRightDirection()) |
zalan@apple.com | c1c9760 | 2015-12-07 04:40:35 +0000 | [diff] [blame] | 210 | SET_REASON_AND_RETURN_IF_NEEDED(FlowIsNotLTR, reasons, includeReasons); |
simon.fraser@apple.com | 815adf5 | 2019-10-13 16:02:54 +0000 | [diff] [blame] | 211 | if (!(style.lineBoxContain().contains(LineBoxContain::Block))) |
zalan@apple.com | c1c9760 | 2015-12-07 04:40:35 +0000 | [diff] [blame] | 212 | SET_REASON_AND_RETURN_IF_NEEDED(FlowHasLineBoxContainProperty, reasons, includeReasons); |
wenson_hsieh@apple.com | 5773fcd | 2020-09-07 02:22:02 +0000 | [diff] [blame] | 213 | if (style.writingMode() != WritingMode::TopToBottom) |
zalan@apple.com | c1c9760 | 2015-12-07 04:40:35 +0000 | [diff] [blame] | 214 | SET_REASON_AND_RETURN_IF_NEEDED(FlowIsNotTopToBottom, reasons, includeReasons); |
commit-queue@webkit.org | 1a4e667 | 2018-05-21 16:55:45 +0000 | [diff] [blame] | 215 | if (style.lineBreak() != LineBreak::Auto) |
zalan@apple.com | c1c9760 | 2015-12-07 04:40:35 +0000 | [diff] [blame] | 216 | SET_REASON_AND_RETURN_IF_NEEDED(FlowHasLineBreak, reasons, includeReasons); |
zalan@apple.com | 58cb218 | 2015-12-03 21:59:17 +0000 | [diff] [blame] | 217 | if (style.unicodeBidi() != UBNormal) |
zalan@apple.com | c1c9760 | 2015-12-07 04:40:35 +0000 | [diff] [blame] | 218 | SET_REASON_AND_RETURN_IF_NEEDED(FlowHasNonNormalUnicodeBiDi, reasons, includeReasons); |
commit-queue@webkit.org | eea2d6a | 2018-05-25 01:42:36 +0000 | [diff] [blame] | 219 | if (style.rtlOrdering() != Order::Logical) |
zalan@apple.com | c1c9760 | 2015-12-07 04:40:35 +0000 | [diff] [blame] | 220 | SET_REASON_AND_RETURN_IF_NEEDED(FlowHasRTLOrdering, reasons, includeReasons); |
commit-queue@webkit.org | eea2d6a | 2018-05-25 01:42:36 +0000 | [diff] [blame] | 221 | if (style.lineAlign() != LineAlign::None) |
zalan@apple.com | c1c9760 | 2015-12-07 04:40:35 +0000 | [diff] [blame] | 222 | SET_REASON_AND_RETURN_IF_NEEDED(FlowHasLineAlignEdges, reasons, includeReasons); |
commit-queue@webkit.org | eea2d6a | 2018-05-25 01:42:36 +0000 | [diff] [blame] | 223 | if (style.lineSnap() != LineSnap::None) |
zalan@apple.com | c1c9760 | 2015-12-07 04:40:35 +0000 | [diff] [blame] | 224 | SET_REASON_AND_RETURN_IF_NEEDED(FlowHasLineSnap, reasons, includeReasons); |
commit-queue@webkit.org | eea2d6a | 2018-05-25 01:42:36 +0000 | [diff] [blame] | 225 | if (style.textEmphasisFill() != TextEmphasisFill::Filled || style.textEmphasisMark() != TextEmphasisMark::None) |
zalan@apple.com | c1c9760 | 2015-12-07 04:40:35 +0000 | [diff] [blame] | 226 | SET_REASON_AND_RETURN_IF_NEEDED(FlowHasTextEmphasisFillOrMark, reasons, includeReasons); |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 227 | if (style.textShadow()) |
zalan@apple.com | c1c9760 | 2015-12-07 04:40:35 +0000 | [diff] [blame] | 228 | SET_REASON_AND_RETURN_IF_NEEDED(FlowHasTextShadow, reasons, includeReasons); |
commit-queue@webkit.org | eea2d6a | 2018-05-25 01:42:36 +0000 | [diff] [blame] | 229 | if (style.hasPseudoStyle(PseudoId::FirstLine)) |
zalan@apple.com | c1c9760 | 2015-12-07 04:40:35 +0000 | [diff] [blame] | 230 | SET_REASON_AND_RETURN_IF_NEEDED(FlowHasPseudoFirstLine, reasons, includeReasons); |
commit-queue@webkit.org | eea2d6a | 2018-05-25 01:42:36 +0000 | [diff] [blame] | 231 | if (style.hasPseudoStyle(PseudoId::FirstLetter)) |
zalan@apple.com | c1c9760 | 2015-12-07 04:40:35 +0000 | [diff] [blame] | 232 | SET_REASON_AND_RETURN_IF_NEEDED(FlowHasPseudoFirstLetter, reasons, includeReasons); |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 233 | if (style.hasTextCombine()) |
zalan@apple.com | c1c9760 | 2015-12-07 04:40:35 +0000 | [diff] [blame] | 234 | SET_REASON_AND_RETURN_IF_NEEDED(FlowHasTextCombine, reasons, includeReasons); |
commit-queue@webkit.org | 1a4e667 | 2018-05-21 16:55:45 +0000 | [diff] [blame] | 235 | if (style.backgroundClip() == FillBox::Text) |
zalan@apple.com | c1c9760 | 2015-12-07 04:40:35 +0000 | [diff] [blame] | 236 | SET_REASON_AND_RETURN_IF_NEEDED(FlowHasTextFillBox, reasons, includeReasons); |
commit-queue@webkit.org | eea2d6a | 2018-05-25 01:42:36 +0000 | [diff] [blame] | 237 | if (style.borderFit() == BorderFit::Lines) |
zalan@apple.com | c1c9760 | 2015-12-07 04:40:35 +0000 | [diff] [blame] | 238 | SET_REASON_AND_RETURN_IF_NEEDED(FlowHasBorderFitLines, reasons, includeReasons); |
commit-queue@webkit.org | 1a4e667 | 2018-05-21 16:55:45 +0000 | [diff] [blame] | 239 | if (style.lineBreak() != LineBreak::Auto) |
zalan@apple.com | c1c9760 | 2015-12-07 04:40:35 +0000 | [diff] [blame] | 240 | SET_REASON_AND_RETURN_IF_NEEDED(FlowHasNonAutoLineBreak, reasons, includeReasons); |
commit-queue@webkit.org | 1a4e667 | 2018-05-21 16:55:45 +0000 | [diff] [blame] | 241 | if (style.nbspMode() != NBSPMode::Normal) |
zalan@apple.com | 7c51fae | 2017-01-20 22:12:02 +0000 | [diff] [blame] | 242 | SET_REASON_AND_RETURN_IF_NEEDED(FlowHasWebKitNBSPMode, reasons, includeReasons); |
mmaxfield@apple.com | 608dd56 | 2020-04-16 05:57:41 +0000 | [diff] [blame] | 243 | // Special handling of text-security:disc is not yet implemented in the simple line layout code path. |
| 244 | // See RenderBlock::updateSecurityDiscCharacters. |
| 245 | if (style.textSecurity() != TextSecurity::None) |
| 246 | SET_REASON_AND_RETURN_IF_NEEDED(FlowHasTextSecurity, reasons, includeReasons); |
commit-queue@webkit.org | eea2d6a | 2018-05-25 01:42:36 +0000 | [diff] [blame] | 247 | if (style.hyphens() == Hyphens::Auto) { |
cdumez@apple.com | 8b7a022 | 2018-12-20 04:41:11 +0000 | [diff] [blame] | 248 | auto textReasons = canUseForText(style.hyphenString(), style.fontCascade(), WTF::nullopt, false, includeReasons); |
zalan@apple.com | d075ea2 | 2017-05-08 18:19:31 +0000 | [diff] [blame] | 249 | if (textReasons != NoReason) |
| 250 | SET_REASON_AND_RETURN_IF_NEEDED(textReasons, reasons, includeReasons); |
| 251 | } |
zalan@apple.com | 58cb218 | 2015-12-03 21:59:17 +0000 | [diff] [blame] | 252 | return reasons; |
zalan@apple.com | 1cf32e6 | 2015-11-17 21:16:07 +0000 | [diff] [blame] | 253 | } |
zalan@apple.com | 62bd3d2 | 2014-11-25 00:10:17 +0000 | [diff] [blame] | 254 | |
zalan@apple.com | 79dc43f | 2017-02-26 07:19:22 +0000 | [diff] [blame] | 255 | AvoidanceReasonFlags canUseForWithReason(const RenderBlockFlow& flow, IncludeReasons includeReasons) |
zalan@apple.com | 1cf32e6 | 2015-11-17 21:16:07 +0000 | [diff] [blame] | 256 | { |
zalan@apple.com | 58cb218 | 2015-12-03 21:59:17 +0000 | [diff] [blame] | 257 | #ifndef NDEBUG |
| 258 | static std::once_flag onceFlag; |
| 259 | std::call_once(onceFlag, [] { |
mmaxfield@apple.com | 2cc9b8d | 2017-10-11 20:30:16 +0000 | [diff] [blame] | 260 | PAL::registerNotifyCallback("com.apple.WebKit.showSimpleLineLayoutCoverage", WTF::Function<void()> { printSimpleLineLayoutCoverage }); |
| 261 | PAL::registerNotifyCallback("com.apple.WebKit.showSimpleLineLayoutReasons", WTF::Function<void()> { printSimpleLineLayoutBlockList }); |
| 262 | PAL::registerNotifyCallback("com.apple.WebKit.toggleSimpleLineLayout", WTF::Function<void()> { toggleSimpleLineLayout }); |
zalan@apple.com | 58cb218 | 2015-12-03 21:59:17 +0000 | [diff] [blame] | 263 | }); |
| 264 | #endif |
zalan@apple.com | c1c9760 | 2015-12-07 04:40:35 +0000 | [diff] [blame] | 265 | AvoidanceReasonFlags reasons = { }; |
zalan@apple.com | a1cff3a | 2017-01-14 18:45:20 +0000 | [diff] [blame] | 266 | if (!flow.settings().simpleLineLayoutEnabled()) |
zalan@apple.com | c1c9760 | 2015-12-07 04:40:35 +0000 | [diff] [blame] | 267 | SET_REASON_AND_RETURN_IF_NEEDED(FeatureIsDisabled, reasons, includeReasons); |
zalan@apple.com | 1cf32e6 | 2015-11-17 21:16:07 +0000 | [diff] [blame] | 268 | if (!flow.parent()) |
zalan@apple.com | c1c9760 | 2015-12-07 04:40:35 +0000 | [diff] [blame] | 269 | SET_REASON_AND_RETURN_IF_NEEDED(FlowHasNoParent, reasons, includeReasons); |
zalan@apple.com | 1cf32e6 | 2015-11-17 21:16:07 +0000 | [diff] [blame] | 270 | if (!flow.firstChild()) |
zalan@apple.com | c1c9760 | 2015-12-07 04:40:35 +0000 | [diff] [blame] | 271 | SET_REASON_AND_RETURN_IF_NEEDED(FlowHasNoChild, reasons, includeReasons); |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 272 | if (flow.fragmentedFlowState() != RenderObject::NotInsideFragmentedFlow) { |
| 273 | auto* fragmentedFlow = flow.enclosingFragmentedFlow(); |
| 274 | if (!is<RenderMultiColumnFlow>(fragmentedFlow)) |
zalan@apple.com | 06e2c40 | 2017-03-09 15:25:12 +0000 | [diff] [blame] | 275 | SET_REASON_AND_RETURN_IF_NEEDED(FlowIsInsideANonMultiColumnThread, reasons, includeReasons); |
hyatt@apple.com | 4e0bf86 | 2017-09-27 20:54:17 +0000 | [diff] [blame] | 276 | auto& columnThread = downcast<RenderMultiColumnFlow>(*fragmentedFlow); |
zalan@apple.com | 06e2c40 | 2017-03-09 15:25:12 +0000 | [diff] [blame] | 277 | if (columnThread.parent() != &flow.view()) |
| 278 | SET_REASON_AND_RETURN_IF_NEEDED(MultiColumnFlowIsNotTopLevel, reasons, includeReasons); |
| 279 | if (columnThread.hasColumnSpanner()) |
| 280 | SET_REASON_AND_RETURN_IF_NEEDED(MultiColumnFlowHasColumnSpanner, reasons, includeReasons); |
| 281 | auto& style = flow.style(); |
commit-queue@webkit.org | 1a4e667 | 2018-05-21 16:55:45 +0000 | [diff] [blame] | 282 | if (style.verticalAlign() != VerticalAlign::Baseline) |
zalan@apple.com | 06e2c40 | 2017-03-09 15:25:12 +0000 | [diff] [blame] | 283 | SET_REASON_AND_RETURN_IF_NEEDED(MultiColumnFlowVerticalAlign, reasons, includeReasons); |
| 284 | if (style.isFloating()) |
| 285 | SET_REASON_AND_RETURN_IF_NEEDED(MultiColumnFlowIsFloating, reasons, includeReasons); |
| 286 | } |
zalan@apple.com | 1cf32e6 | 2015-11-17 21:16:07 +0000 | [diff] [blame] | 287 | if (!flow.isHorizontalWritingMode()) |
zalan@apple.com | c1c9760 | 2015-12-07 04:40:35 +0000 | [diff] [blame] | 288 | SET_REASON_AND_RETURN_IF_NEEDED(FlowHasHorizonalWritingMode, reasons, includeReasons); |
zalan@apple.com | 1cf32e6 | 2015-11-17 21:16:07 +0000 | [diff] [blame] | 289 | if (flow.hasOutline()) |
zalan@apple.com | c1c9760 | 2015-12-07 04:40:35 +0000 | [diff] [blame] | 290 | SET_REASON_AND_RETURN_IF_NEEDED(FlowHasOutline, reasons, includeReasons); |
zalan@apple.com | 1cf32e6 | 2015-11-17 21:16:07 +0000 | [diff] [blame] | 291 | if (flow.isRubyText() || flow.isRubyBase()) |
zalan@apple.com | c1c9760 | 2015-12-07 04:40:35 +0000 | [diff] [blame] | 292 | SET_REASON_AND_RETURN_IF_NEEDED(FlowIsRuby, reasons, includeReasons); |
commit-queue@webkit.org | 02cb000 | 2018-05-28 00:49:21 +0000 | [diff] [blame] | 293 | if (!flow.style().hangingPunctuation().isEmpty()) |
hyatt@apple.com | 41c12c9 | 2016-03-02 22:29:26 +0000 | [diff] [blame] | 294 | SET_REASON_AND_RETURN_IF_NEEDED(FlowHasHangingPunctuation, reasons, includeReasons); |
| 295 | |
zalan@apple.com | 1cf32e6 | 2015-11-17 21:16:07 +0000 | [diff] [blame] | 296 | // Printing does pagination without a flow thread. |
| 297 | if (flow.document().paginated()) |
zalan@apple.com | c1c9760 | 2015-12-07 04:40:35 +0000 | [diff] [blame] | 298 | SET_REASON_AND_RETURN_IF_NEEDED(FlowIsPaginated, reasons, includeReasons); |
zalan@apple.com | c1e7f80 | 2015-12-31 19:27:58 +0000 | [diff] [blame] | 299 | if (flow.firstLineBlock()) |
zalan@apple.com | c1c9760 | 2015-12-07 04:40:35 +0000 | [diff] [blame] | 300 | SET_REASON_AND_RETURN_IF_NEEDED(FlowHasPseudoFirstLine, reasons, includeReasons); |
commit-queue@webkit.org | 1a4e667 | 2018-05-21 16:55:45 +0000 | [diff] [blame] | 301 | if (flow.isAnonymousBlock() && flow.parent()->style().textOverflow() == TextOverflow::Ellipsis) |
zalan@apple.com | c1c9760 | 2015-12-07 04:40:35 +0000 | [diff] [blame] | 302 | SET_REASON_AND_RETURN_IF_NEEDED(FlowHasTextOverflow, reasons, includeReasons); |
zalan@apple.com | 1cf32e6 | 2015-11-17 21:16:07 +0000 | [diff] [blame] | 303 | if (flow.parent()->isDeprecatedFlexibleBox()) |
zalan@apple.com | c1c9760 | 2015-12-07 04:40:35 +0000 | [diff] [blame] | 304 | SET_REASON_AND_RETURN_IF_NEEDED(FlowIsDepricatedFlexBox, reasons, includeReasons); |
zalan@apple.com | 1cf32e6 | 2015-11-17 21:16:07 +0000 | [diff] [blame] | 305 | // FIXME: Placeholders do something strange. |
| 306 | if (is<RenderTextControl>(*flow.parent()) && downcast<RenderTextControl>(*flow.parent()).textFormControlElement().placeholderElement()) |
zalan@apple.com | c1c9760 | 2015-12-07 04:40:35 +0000 | [diff] [blame] | 307 | SET_REASON_AND_RETURN_IF_NEEDED(FlowParentIsPlaceholderElement, reasons, includeReasons); |
zalan@apple.com | 1cf32e6 | 2015-11-17 21:16:07 +0000 | [diff] [blame] | 308 | // FIXME: Implementation of wrap=hard looks into lineboxes. |
rniwa@webkit.org | bda54a0 | 2016-07-18 00:39:37 +0000 | [diff] [blame] | 309 | if (flow.parent()->isTextArea() && flow.parent()->element()->hasAttributeWithoutSynchronization(HTMLNames::wrapAttr)) |
zalan@apple.com | c1c9760 | 2015-12-07 04:40:35 +0000 | [diff] [blame] | 310 | SET_REASON_AND_RETURN_IF_NEEDED(FlowParentIsTextAreaWithWrapping, reasons, includeReasons); |
zalan@apple.com | 1cf32e6 | 2015-11-17 21:16:07 +0000 | [diff] [blame] | 311 | // This currently covers <blockflow>#text</blockflow>, <blockflow>#text<br></blockflow> and mutiple (sibling) RenderText cases. |
| 312 | // The <blockflow><inline>#text</inline></blockflow> case is also popular and should be relatively easy to cover. |
| 313 | for (const auto* child = flow.firstChild(); child;) { |
megan_gardner@apple.com | c66f2b8 | 2020-02-10 19:32:19 +0000 | [diff] [blame] | 314 | if (child->selectionState() != RenderObject::HighlightState::None) |
zalan@apple.com | f433a51 | 2015-12-11 07:31:28 +0000 | [diff] [blame] | 315 | SET_REASON_AND_RETURN_IF_NEEDED(FlowChildIsSelected, reasons, includeReasons); |
zalan@apple.com | 1cf32e6 | 2015-11-17 21:16:07 +0000 | [diff] [blame] | 316 | if (is<RenderText>(*child)) { |
mmaxfield@apple.com | e4058ae | 2018-11-06 23:06:37 +0000 | [diff] [blame] | 317 | const auto& renderText = downcast<RenderText>(*child); |
zalan@apple.com | 095cb60 | 2018-12-17 19:42:55 +0000 | [diff] [blame] | 318 | if (renderText.textNode() && !renderText.document().markers().markersFor(*renderText.textNode()).isEmpty()) |
mmaxfield@apple.com | e4058ae | 2018-11-06 23:06:37 +0000 | [diff] [blame] | 319 | SET_REASON_AND_RETURN_IF_NEEDED(FlowIncludesDocumentMarkers, reasons, includeReasons); |
zalan@apple.com | 1cf32e6 | 2015-11-17 21:16:07 +0000 | [diff] [blame] | 320 | child = child->nextSibling(); |
| 321 | continue; |
| 322 | } |
commit-queue@webkit.org | 1a4e667 | 2018-05-21 16:55:45 +0000 | [diff] [blame] | 323 | if (is<RenderLineBreak>(child) && !downcast<RenderLineBreak>(*child).isWBR() && child->style().clear() == Clear::None) { |
zalan@apple.com | 1cf32e6 | 2015-11-17 21:16:07 +0000 | [diff] [blame] | 324 | child = child->nextSibling(); |
| 325 | continue; |
| 326 | } |
zalan@apple.com | c1c9760 | 2015-12-07 04:40:35 +0000 | [diff] [blame] | 327 | SET_REASON_AND_RETURN_IF_NEEDED(FlowHasNonSupportedChild, reasons, includeReasons); |
zalan@apple.com | 58cb218 | 2015-12-03 21:59:17 +0000 | [diff] [blame] | 328 | break; |
zalan@apple.com | 1cf32e6 | 2015-11-17 21:16:07 +0000 | [diff] [blame] | 329 | } |
zalan@apple.com | c1c9760 | 2015-12-07 04:40:35 +0000 | [diff] [blame] | 330 | auto styleReasons = canUseForStyle(flow.style(), includeReasons); |
zalan@apple.com | 58cb218 | 2015-12-03 21:59:17 +0000 | [diff] [blame] | 331 | if (styleReasons != NoReason) |
zalan@apple.com | c1c9760 | 2015-12-07 04:40:35 +0000 | [diff] [blame] | 332 | SET_REASON_AND_RETURN_IF_NEEDED(styleReasons, reasons, includeReasons); |
zalan@apple.com | 62bd3d2 | 2014-11-25 00:10:17 +0000 | [diff] [blame] | 333 | // We can't use the code path if any lines would need to be shifted below floats. This is because we don't keep per-line y coordinates. |
antti@apple.com | 01a0412 | 2013-11-20 21:23:19 +0000 | [diff] [blame] | 334 | if (flow.containsFloats()) { |
zalan@apple.com | 62bd3d2 | 2014-11-25 00:10:17 +0000 | [diff] [blame] | 335 | float minimumWidthNeeded = std::numeric_limits<float>::max(); |
zalan@apple.com | 57c7fc7 | 2014-11-25 03:47:57 +0000 | [diff] [blame] | 336 | for (const auto& textRenderer : childrenOfType<RenderText>(flow)) { |
zalan@apple.com | 62bd3d2 | 2014-11-25 00:10:17 +0000 | [diff] [blame] | 337 | minimumWidthNeeded = std::min(minimumWidthNeeded, textRenderer.minLogicalWidth()); |
| 338 | |
bjonesbe@adobe.com | 1be249b | 2015-01-09 21:01:53 +0000 | [diff] [blame] | 339 | for (auto& floatingObject : *flow.floatingObjectSet()) { |
| 340 | ASSERT(floatingObject); |
bjonesbe@adobe.com | 1be249b | 2015-01-09 21:01:53 +0000 | [diff] [blame] | 341 | // if a float has a shape, we cannot tell if content will need to be shifted until after we lay it out, |
| 342 | // since the amount of space is not uniform for the height of the float. |
| 343 | if (floatingObject->renderer().shapeOutsideInfo()) |
zalan@apple.com | c1c9760 | 2015-12-07 04:40:35 +0000 | [diff] [blame] | 344 | SET_REASON_AND_RETURN_IF_NEEDED(FlowHasUnsupportedFloat, reasons, includeReasons); |
zalan@apple.com | 64761fe | 2016-03-02 21:42:22 +0000 | [diff] [blame] | 345 | float availableWidth = flow.availableLogicalWidthForLine(floatingObject->y(), DoNotIndentText); |
zalan@apple.com | 57c7fc7 | 2014-11-25 03:47:57 +0000 | [diff] [blame] | 346 | if (availableWidth < minimumWidthNeeded) |
zalan@apple.com | c1c9760 | 2015-12-07 04:40:35 +0000 | [diff] [blame] | 347 | SET_REASON_AND_RETURN_IF_NEEDED(FlowHasUnsupportedFloat, reasons, includeReasons); |
zalan@apple.com | 57c7fc7 | 2014-11-25 03:47:57 +0000 | [diff] [blame] | 348 | } |
antti@apple.com | be9d3e1 | 2014-05-11 09:42:47 +0000 | [diff] [blame] | 349 | } |
antti@apple.com | 01a0412 | 2013-11-20 21:23:19 +0000 | [diff] [blame] | 350 | } |
zalan@apple.com | c1c9760 | 2015-12-07 04:40:35 +0000 | [diff] [blame] | 351 | auto fontAndTextReasons = canUseForFontAndText(flow, includeReasons); |
zalan@apple.com | 58cb218 | 2015-12-03 21:59:17 +0000 | [diff] [blame] | 352 | if (fontAndTextReasons != NoReason) |
zalan@apple.com | c1c9760 | 2015-12-07 04:40:35 +0000 | [diff] [blame] | 353 | SET_REASON_AND_RETURN_IF_NEEDED(fontAndTextReasons, reasons, includeReasons); |
zalan@apple.com | 58cb218 | 2015-12-03 21:59:17 +0000 | [diff] [blame] | 354 | return reasons; |
| 355 | } |
| 356 | |
| 357 | bool canUseFor(const RenderBlockFlow& flow) |
| 358 | { |
zalan@apple.com | c1c9760 | 2015-12-07 04:40:35 +0000 | [diff] [blame] | 359 | return canUseForWithReason(flow, IncludeReasons::First) == NoReason; |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 360 | } |
| 361 | |
zalan@apple.com | fcfec3b | 2020-08-28 20:21:39 +0000 | [diff] [blame] | 362 | bool canUseForAfterStyleChange(const RenderBlockFlow& blockContainer, StyleDifference diff) |
| 363 | { |
| 364 | switch (diff) { |
| 365 | case StyleDifference::Equal: |
| 366 | case StyleDifference::RecompositeLayer: |
| 367 | return true; |
| 368 | case StyleDifference::Repaint: |
| 369 | case StyleDifference::RepaintIfTextOrBorderOrOutline: |
| 370 | case StyleDifference::RepaintLayer: |
| 371 | // FIXME: We could do a more focused style check by matching RendererStyle::changeRequiresRepaint&co. |
| 372 | return canUseForStyle(blockContainer.style(), IncludeReasons::First) == NoReason; |
| 373 | case StyleDifference::LayoutPositionedMovementOnly: |
| 374 | return true; |
| 375 | case StyleDifference::SimplifiedLayout: |
| 376 | case StyleDifference::SimplifiedLayoutAndPositionedMovement: |
| 377 | return canUseForStyle(blockContainer.style(), IncludeReasons::First) == NoReason; |
| 378 | case StyleDifference::Layout: |
| 379 | case StyleDifference::NewStyle: |
| 380 | return canUseFor(blockContainer); |
| 381 | } |
| 382 | ASSERT_NOT_REACHED(); |
| 383 | return canUseFor(blockContainer); |
| 384 | } |
| 385 | |
zalan@apple.com | 539173e | 2017-03-07 21:02:15 +0000 | [diff] [blame] | 386 | static void revertAllRunsOnCurrentLine(Layout::RunVector& runs) |
| 387 | { |
| 388 | while (!runs.isEmpty() && !runs.last().isEndOfLine) |
| 389 | runs.removeLast(); |
| 390 | } |
| 391 | |
zalan@apple.com | e3e6260 | 2017-02-03 21:17:28 +0000 | [diff] [blame] | 392 | static void revertRuns(Layout::RunVector& runs, unsigned positionToRevertTo, float width) |
zalan@apple.com | 99ff630 | 2015-03-18 14:48:01 +0000 | [diff] [blame] | 393 | { |
zalan@apple.com | e3e6260 | 2017-02-03 21:17:28 +0000 | [diff] [blame] | 394 | while (runs.size()) { |
| 395 | auto& lastRun = runs.last(); |
| 396 | if (lastRun.end <= positionToRevertTo) |
| 397 | break; |
| 398 | if (lastRun.start >= positionToRevertTo) { |
| 399 | // Revert this run completely. |
| 400 | width -= (lastRun.logicalRight - lastRun.logicalLeft); |
| 401 | runs.removeLast(); |
| 402 | } else { |
zalan@apple.com | 99ff630 | 2015-03-18 14:48:01 +0000 | [diff] [blame] | 403 | lastRun.logicalRight -= width; |
zalan@apple.com | e3e6260 | 2017-02-03 21:17:28 +0000 | [diff] [blame] | 404 | width = 0; |
| 405 | lastRun.end = positionToRevertTo; |
| 406 | // Partial removal. |
zalan@apple.com | 99ff630 | 2015-03-18 14:48:01 +0000 | [diff] [blame] | 407 | break; |
| 408 | } |
zalan@apple.com | 99ff630 | 2015-03-18 14:48:01 +0000 | [diff] [blame] | 409 | } |
| 410 | } |
| 411 | |
zalan@apple.com | 58dc70b | 2015-01-31 03:37:46 +0000 | [diff] [blame] | 412 | class LineState { |
| 413 | public: |
| 414 | void setAvailableWidth(float width) { m_availableWidth = width; } |
zalan@apple.com | 99ff630 | 2015-03-18 14:48:01 +0000 | [diff] [blame] | 415 | void setCollapedWhitespaceWidth(float width) { m_collapsedWhitespaceWidth = width; } |
zalan@apple.com | 58dc70b | 2015-01-31 03:37:46 +0000 | [diff] [blame] | 416 | void setLogicalLeftOffset(float offset) { m_logicalLeftOffset = offset; } |
zalan@apple.com | 1802def | 2015-02-03 03:08:33 +0000 | [diff] [blame] | 417 | void setOverflowedFragment(const TextFragmentIterator::TextFragment& fragment) { m_overflowedFragment = fragment; } |
zalan@apple.com | 5c6a075 | 2017-02-01 00:01:26 +0000 | [diff] [blame] | 418 | void setNeedsAllFragments() |
| 419 | { |
| 420 | ASSERT(!m_fragments); |
| 421 | m_fragments.emplace(); |
| 422 | } |
zalan@apple.com | 8bfb3f7 | 2017-03-16 22:14:30 +0000 | [diff] [blame] | 423 | void setHyphenationDisabled() { m_hyphenationDisabled = true; } |
| 424 | bool isHyphenationDisabled() const { return m_hyphenationDisabled; } |
zalan@apple.com | 6ab1907 | 2014-10-28 17:57:14 +0000 | [diff] [blame] | 425 | |
zalan@apple.com | 58dc70b | 2015-01-31 03:37:46 +0000 | [diff] [blame] | 426 | float availableWidth() const { return m_availableWidth; } |
| 427 | float logicalLeftOffset() const { return m_logicalLeftOffset; } |
zalan@apple.com | 1802def | 2015-02-03 03:08:33 +0000 | [diff] [blame] | 428 | const TextFragmentIterator::TextFragment& overflowedFragment() const { return m_overflowedFragment; } |
jfernandez@igalia.com | 2c9d125 | 2019-04-08 20:31:05 +0000 | [diff] [blame] | 429 | bool hasTrailingWhitespace() const { return m_lastFragment.type() == TextFragmentIterator::TextFragment::Whitespace && m_lastFragment.length() > 0; } |
| 430 | bool hasWhitespaceFragments() const { return m_lastWhitespaceFragment != WTF::nullopt; } |
zalan@apple.com | 5c6a075 | 2017-02-01 00:01:26 +0000 | [diff] [blame] | 431 | TextFragmentIterator::TextFragment lastFragment() const { return m_lastFragment; } |
zalan@apple.com | 58dc70b | 2015-01-31 03:37:46 +0000 | [diff] [blame] | 432 | bool isWhitespaceOnly() const { return m_trailingWhitespaceWidth && m_runsWidth == m_trailingWhitespaceWidth; } |
| 433 | bool fits(float extra) const { return m_availableWidth >= m_runsWidth + extra; } |
zalan@apple.com | c23decf | 2015-01-28 23:36:46 +0000 | [diff] [blame] | 434 | bool firstCharacterFits() const { return m_firstCharacterFits; } |
zalan@apple.com | 58dc70b | 2015-01-31 03:37:46 +0000 | [diff] [blame] | 435 | float width() const { return m_runsWidth; } |
zalan@apple.com | 6d7b01b | 2016-03-11 04:03:32 +0000 | [diff] [blame] | 436 | std::pair<unsigned, bool> expansionOpportunityCount(unsigned from, unsigned to) const |
| 437 | { |
zalan@apple.com | 5c6a075 | 2017-02-01 00:01:26 +0000 | [diff] [blame] | 438 | ASSERT(m_fragments); |
zalan@apple.com | 6d7b01b | 2016-03-11 04:03:32 +0000 | [diff] [blame] | 439 | // linebreak runs are special. |
| 440 | if (from == to) |
| 441 | return std::make_pair(0, false); |
| 442 | unsigned expansionOpportunityCount = 0; |
| 443 | auto previousFragmentType = TextFragmentIterator::TextFragment::ContentEnd; |
zalan@apple.com | 5c6a075 | 2017-02-01 00:01:26 +0000 | [diff] [blame] | 444 | for (const auto& fragment : *m_fragments) { |
zalan@apple.com | 6d7b01b | 2016-03-11 04:03:32 +0000 | [diff] [blame] | 445 | if (fragment.end() <= from) |
| 446 | continue; |
| 447 | auto currentFragmentType = fragment.type(); |
| 448 | auto expansionOpportunity = this->expansionOpportunity(currentFragmentType, previousFragmentType); |
| 449 | if (expansionOpportunity) |
| 450 | ++expansionOpportunityCount; |
| 451 | previousFragmentType = currentFragmentType; |
| 452 | if (fragment.end() >= to) |
| 453 | return std::make_pair(expansionOpportunityCount, expansionOpportunity); |
| 454 | } |
| 455 | ASSERT_NOT_REACHED(); |
| 456 | return std::make_pair(expansionOpportunityCount, false); |
| 457 | } |
| 458 | |
zalan@apple.com | 99ff630 | 2015-03-18 14:48:01 +0000 | [diff] [blame] | 459 | bool isEmpty() const |
| 460 | { |
zalan@apple.com | 5c6a075 | 2017-02-01 00:01:26 +0000 | [diff] [blame] | 461 | if (!m_lastFragment.isValid()) |
zalan@apple.com | 99ff630 | 2015-03-18 14:48:01 +0000 | [diff] [blame] | 462 | return true; |
| 463 | if (!m_lastCompleteFragment.isEmpty()) |
| 464 | return false; |
zalan@apple.com | 5c6a075 | 2017-02-01 00:01:26 +0000 | [diff] [blame] | 465 | return m_lastFragment.overlapsToNextRenderer(); |
| 466 | } |
| 467 | |
| 468 | static inline unsigned endPositionForCollapsedFragment(const TextFragmentIterator::TextFragment& fragment) |
| 469 | { |
| 470 | return fragment.isCollapsed() ? fragment.start() + 1 : fragment.end(); |
zalan@apple.com | 99ff630 | 2015-03-18 14:48:01 +0000 | [diff] [blame] | 471 | } |
zalan@apple.com | c23decf | 2015-01-28 23:36:46 +0000 | [diff] [blame] | 472 | |
zalan@apple.com | 99ff630 | 2015-03-18 14:48:01 +0000 | [diff] [blame] | 473 | void appendFragmentAndCreateRunIfNeeded(const TextFragmentIterator::TextFragment& fragment, Layout::RunVector& runs) |
zalan@apple.com | 6ab1907 | 2014-10-28 17:57:14 +0000 | [diff] [blame] | 474 | { |
zalan@apple.com | 58dc70b | 2015-01-31 03:37:46 +0000 | [diff] [blame] | 475 | // Adjust end position while collapsing. |
zalan@apple.com | 5c6a075 | 2017-02-01 00:01:26 +0000 | [diff] [blame] | 476 | unsigned endPosition = endPositionForCollapsedFragment(fragment); |
zalan@apple.com | 99ff630 | 2015-03-18 14:48:01 +0000 | [diff] [blame] | 477 | // New line needs new run. |
zalan@apple.com | 5c6a075 | 2017-02-01 00:01:26 +0000 | [diff] [blame] | 478 | if (!m_runsWidth) { |
| 479 | ASSERT(!m_uncompletedWidth); |
antti@apple.com | b8db035 | 2019-09-26 18:25:47 +0000 | [diff] [blame] | 480 | runs.append(Run(fragment.start(), endPosition, m_runsWidth, m_runsWidth + fragment.width(), false, fragment.hasHyphen(), fragment.isLineBreak())); |
zalan@apple.com | 5c6a075 | 2017-02-01 00:01:26 +0000 | [diff] [blame] | 481 | } else { |
zalan@apple.com | 99ff630 | 2015-03-18 14:48:01 +0000 | [diff] [blame] | 482 | // Advance last completed fragment when the previous fragment is all set (including multiple parts across renderers) |
zalan@apple.com | 5c6a075 | 2017-02-01 00:01:26 +0000 | [diff] [blame] | 483 | if ((m_lastFragment.type() != fragment.type()) || !m_lastFragment.overlapsToNextRenderer()) { |
| 484 | m_lastCompleteFragment = m_lastFragment; |
| 485 | m_uncompletedWidth = fragment.width(); |
| 486 | } else |
| 487 | m_uncompletedWidth += fragment.width(); |
zalan@apple.com | 99ff630 | 2015-03-18 14:48:01 +0000 | [diff] [blame] | 488 | // Collapse neighbouring whitespace, if they are across multiple renderers and are not collapsed yet. |
zalan@apple.com | 5c6a075 | 2017-02-01 00:01:26 +0000 | [diff] [blame] | 489 | if (m_lastFragment.isCollapsible() && fragment.isCollapsible()) { |
| 490 | ASSERT(m_lastFragment.isLastInRenderer()); |
| 491 | if (!m_lastFragment.isCollapsed()) { |
| 492 | // Line width needs to be adjusted so that now it takes collapsing into consideration. |
| 493 | m_runsWidth -= (m_lastFragment.width() - m_collapsedWhitespaceWidth); |
zalan@apple.com | 99ff630 | 2015-03-18 14:48:01 +0000 | [diff] [blame] | 494 | } |
| 495 | // This fragment is collapsed completely. No run is needed. |
| 496 | return; |
| 497 | } |
antti@apple.com | 56a81e5 | 2019-10-11 19:03:37 +0000 | [diff] [blame] | 498 | Run& lastRun = runs.last(); |
| 499 | if (m_lastFragment.isLastInRenderer() || m_lastFragment.isCollapsed() || fragment.isLineBreak() || lastRun.isLineBreak) |
antti@apple.com | b8db035 | 2019-09-26 18:25:47 +0000 | [diff] [blame] | 500 | runs.append(Run(fragment.start(), endPosition, m_runsWidth, m_runsWidth + fragment.width(), false, fragment.hasHyphen(), fragment.isLineBreak())); |
zalan@apple.com | 99ff630 | 2015-03-18 14:48:01 +0000 | [diff] [blame] | 501 | else { |
zalan@apple.com | 99ff630 | 2015-03-18 14:48:01 +0000 | [diff] [blame] | 502 | lastRun.end = endPosition; |
| 503 | lastRun.logicalRight += fragment.width(); |
zalan@apple.com | 89b951f | 2017-01-24 21:38:20 +0000 | [diff] [blame] | 504 | ASSERT(!lastRun.hasHyphen); |
| 505 | lastRun.hasHyphen = fragment.hasHyphen(); |
zalan@apple.com | 99ff630 | 2015-03-18 14:48:01 +0000 | [diff] [blame] | 506 | } |
zalan@apple.com | 58dc70b | 2015-01-31 03:37:46 +0000 | [diff] [blame] | 507 | } |
zalan@apple.com | beef486 | 2015-01-31 06:26:02 +0000 | [diff] [blame] | 508 | m_runsWidth += fragment.width(); |
zalan@apple.com | 5c6a075 | 2017-02-01 00:01:26 +0000 | [diff] [blame] | 509 | m_lastFragment = fragment; |
| 510 | if (m_fragments) |
| 511 | (*m_fragments).append(fragment); |
zalan@apple.com | 58dc70b | 2015-01-31 03:37:46 +0000 | [diff] [blame] | 512 | |
jfernandez@igalia.com | 2c9d125 | 2019-04-08 20:31:05 +0000 | [diff] [blame] | 513 | if (fragment.type() == TextFragmentIterator::TextFragment::Whitespace) { |
zalan@apple.com | beef486 | 2015-01-31 06:26:02 +0000 | [diff] [blame] | 514 | m_trailingWhitespaceWidth += fragment.width(); |
jfernandez@igalia.com | 2c9d125 | 2019-04-08 20:31:05 +0000 | [diff] [blame] | 515 | m_lastWhitespaceFragment = fragment; |
| 516 | } else { |
zalan@apple.com | 58dc70b | 2015-01-31 03:37:46 +0000 | [diff] [blame] | 517 | m_trailingWhitespaceWidth = 0; |
zalan@apple.com | 5c6a075 | 2017-02-01 00:01:26 +0000 | [diff] [blame] | 518 | m_lastNonWhitespaceFragment = fragment; |
zalan@apple.com | 58dc70b | 2015-01-31 03:37:46 +0000 | [diff] [blame] | 519 | } |
| 520 | |
| 521 | if (!m_firstCharacterFits) |
zalan@apple.com | beef486 | 2015-01-31 06:26:02 +0000 | [diff] [blame] | 522 | m_firstCharacterFits = fragment.start() + 1 > endPosition || m_runsWidth <= m_availableWidth; |
zalan@apple.com | 3595435 | 2014-11-04 20:08:13 +0000 | [diff] [blame] | 523 | } |
| 524 | |
zalan@apple.com | 99ff630 | 2015-03-18 14:48:01 +0000 | [diff] [blame] | 525 | TextFragmentIterator::TextFragment revertToLastCompleteFragment(Layout::RunVector& runs) |
| 526 | { |
zalan@apple.com | 5c6a075 | 2017-02-01 00:01:26 +0000 | [diff] [blame] | 527 | if (!m_uncompletedWidth) { |
| 528 | ASSERT(m_lastFragment == m_lastCompleteFragment); |
| 529 | return m_lastFragment; |
zalan@apple.com | 99ff630 | 2015-03-18 14:48:01 +0000 | [diff] [blame] | 530 | } |
zalan@apple.com | 5c6a075 | 2017-02-01 00:01:26 +0000 | [diff] [blame] | 531 | ASSERT(m_lastFragment.isValid()); |
| 532 | m_runsWidth -= m_uncompletedWidth; |
zalan@apple.com | e3e6260 | 2017-02-03 21:17:28 +0000 | [diff] [blame] | 533 | revertRuns(runs, endPositionForCollapsedFragment(m_lastCompleteFragment), m_uncompletedWidth); |
zalan@apple.com | 5c6a075 | 2017-02-01 00:01:26 +0000 | [diff] [blame] | 534 | m_uncompletedWidth = 0; |
| 535 | ASSERT(m_lastCompleteFragment.isValid()); |
zalan@apple.com | 99ff630 | 2015-03-18 14:48:01 +0000 | [diff] [blame] | 536 | return m_lastCompleteFragment; |
| 537 | } |
| 538 | |
zalan@apple.com | 58dc70b | 2015-01-31 03:37:46 +0000 | [diff] [blame] | 539 | void removeTrailingWhitespace(Layout::RunVector& runs) |
| 540 | { |
antti@apple.com | 56a81e5 | 2019-10-11 19:03:37 +0000 | [diff] [blame] | 541 | if (!hasTrailingWhitespace()) |
zalan@apple.com | 99ff630 | 2015-03-18 14:48:01 +0000 | [diff] [blame] | 542 | return; |
zalan@apple.com | 539173e | 2017-03-07 21:02:15 +0000 | [diff] [blame] | 543 | if (m_lastNonWhitespaceFragment) { |
| 544 | auto needsReverting = m_lastNonWhitespaceFragment->end() != m_lastFragment.end(); |
| 545 | // Trailing whitespace fragment might actually have zero length. |
| 546 | ASSERT(needsReverting || !m_trailingWhitespaceWidth); |
| 547 | if (needsReverting) { |
| 548 | revertRuns(runs, m_lastNonWhitespaceFragment->end(), m_trailingWhitespaceWidth); |
| 549 | m_runsWidth -= m_trailingWhitespaceWidth; |
| 550 | } |
| 551 | m_trailingWhitespaceWidth = 0; |
| 552 | m_lastFragment = *m_lastNonWhitespaceFragment; |
| 553 | return; |
| 554 | } |
| 555 | // This line is all whitespace. |
| 556 | revertAllRunsOnCurrentLine(runs); |
| 557 | m_runsWidth = 0; |
| 558 | m_trailingWhitespaceWidth = 0; |
| 559 | // FIXME: Make m_lastFragment optional. |
| 560 | m_lastFragment = TextFragmentIterator::TextFragment(); |
zalan@apple.com | 58dc70b | 2015-01-31 03:37:46 +0000 | [diff] [blame] | 561 | } |
zalan@apple.com | 5a09360 | 2015-01-22 21:54:53 +0000 | [diff] [blame] | 562 | |
antti@apple.com | 56a81e5 | 2019-10-11 19:03:37 +0000 | [diff] [blame] | 563 | float trailingWhitespaceWidth() const { return m_trailingWhitespaceWidth; } |
| 564 | |
zalan@apple.com | 5a09360 | 2015-01-22 21:54:53 +0000 | [diff] [blame] | 565 | private: |
zalan@apple.com | 6d7b01b | 2016-03-11 04:03:32 +0000 | [diff] [blame] | 566 | bool expansionOpportunity(TextFragmentIterator::TextFragment::Type currentFragmentType, TextFragmentIterator::TextFragment::Type previousFragmentType) const |
| 567 | { |
| 568 | return (currentFragmentType == TextFragmentIterator::TextFragment::Whitespace |
| 569 | || (currentFragmentType == TextFragmentIterator::TextFragment::NonWhitespace && previousFragmentType == TextFragmentIterator::TextFragment::NonWhitespace)); |
| 570 | } |
| 571 | |
zalan@apple.com | 58dc70b | 2015-01-31 03:37:46 +0000 | [diff] [blame] | 572 | float m_availableWidth { 0 }; |
| 573 | float m_logicalLeftOffset { 0 }; |
zalan@apple.com | 58dc70b | 2015-01-31 03:37:46 +0000 | [diff] [blame] | 574 | float m_runsWidth { 0 }; |
zalan@apple.com | 5c6a075 | 2017-02-01 00:01:26 +0000 | [diff] [blame] | 575 | TextFragmentIterator::TextFragment m_overflowedFragment; |
| 576 | TextFragmentIterator::TextFragment m_lastFragment; |
cdumez@apple.com | 8b7a022 | 2018-12-20 04:41:11 +0000 | [diff] [blame] | 577 | Optional<TextFragmentIterator::TextFragment> m_lastNonWhitespaceFragment; |
jfernandez@igalia.com | 2c9d125 | 2019-04-08 20:31:05 +0000 | [diff] [blame] | 578 | Optional<TextFragmentIterator::TextFragment> m_lastWhitespaceFragment; |
zalan@apple.com | 99ff630 | 2015-03-18 14:48:01 +0000 | [diff] [blame] | 579 | TextFragmentIterator::TextFragment m_lastCompleteFragment; |
zalan@apple.com | 5c6a075 | 2017-02-01 00:01:26 +0000 | [diff] [blame] | 580 | float m_uncompletedWidth { 0 }; |
zalan@apple.com | 58dc70b | 2015-01-31 03:37:46 +0000 | [diff] [blame] | 581 | float m_trailingWhitespaceWidth { 0 }; // Use this to remove trailing whitespace without re-mesuring the text. |
zalan@apple.com | 99ff630 | 2015-03-18 14:48:01 +0000 | [diff] [blame] | 582 | float m_collapsedWhitespaceWidth { 0 }; |
zalan@apple.com | c23decf | 2015-01-28 23:36:46 +0000 | [diff] [blame] | 583 | // Having one character on the line does not necessarily mean it actually fits. |
| 584 | // First character of the first fragment might be forced on to the current line even if it does not fit. |
| 585 | bool m_firstCharacterFits { false }; |
zalan@apple.com | 8bfb3f7 | 2017-03-16 22:14:30 +0000 | [diff] [blame] | 586 | bool m_hyphenationDisabled { false }; |
cdumez@apple.com | 8b7a022 | 2018-12-20 04:41:11 +0000 | [diff] [blame] | 587 | Optional<Vector<TextFragmentIterator::TextFragment, 30>> m_fragments; |
zalan@apple.com | 6ab1907 | 2014-10-28 17:57:14 +0000 | [diff] [blame] | 588 | }; |
| 589 | |
antti@apple.com | 56a81e5 | 2019-10-11 19:03:37 +0000 | [diff] [blame] | 590 | static float computeLineLeft(const LineState& line, TextAlignMode textAlign, float& hangingWhitespaceWidth) |
| 591 | { |
| 592 | float totalWidth = line.width() - hangingWhitespaceWidth; |
| 593 | float remainingWidth = line.availableWidth() - totalWidth; |
| 594 | float left = line.logicalLeftOffset(); |
| 595 | switch (textAlign) { |
| 596 | case TextAlignMode::Left: |
| 597 | case TextAlignMode::WebKitLeft: |
| 598 | case TextAlignMode::Start: |
| 599 | hangingWhitespaceWidth = std::max(0.f, std::min(hangingWhitespaceWidth, remainingWidth)); |
| 600 | return left; |
| 601 | case TextAlignMode::Right: |
| 602 | case TextAlignMode::WebKitRight: |
| 603 | case TextAlignMode::End: |
| 604 | hangingWhitespaceWidth = 0; |
| 605 | return left + std::max<float>(remainingWidth, 0); |
| 606 | case TextAlignMode::Center: |
| 607 | case TextAlignMode::WebKitCenter: |
| 608 | hangingWhitespaceWidth = std::max(0.f, std::min(hangingWhitespaceWidth, (remainingWidth + 1) / 2)); |
| 609 | return left + std::max<float>(remainingWidth / 2, 0); |
| 610 | case TextAlignMode::Justify: |
| 611 | ASSERT_NOT_REACHED(); |
| 612 | break; |
| 613 | } |
| 614 | ASSERT_NOT_REACHED(); |
| 615 | return 0; |
| 616 | } |
| 617 | |
zalan@apple.com | 1802def | 2015-02-03 03:08:33 +0000 | [diff] [blame] | 618 | static bool preWrap(const TextFragmentIterator::Style& style) |
zalan@apple.com | f6bb557 | 2015-01-23 06:26:28 +0000 | [diff] [blame] | 619 | { |
antti@apple.com | 56a81e5 | 2019-10-11 19:03:37 +0000 | [diff] [blame] | 620 | return style.wrapLines && !style.collapseWhitespace && !style.breakSpaces; |
zalan@apple.com | 6ab1907 | 2014-10-28 17:57:14 +0000 | [diff] [blame] | 621 | } |
| 622 | |
zalan@apple.com | 8bfb3f7 | 2017-03-16 22:14:30 +0000 | [diff] [blame] | 623 | static void updateLineConstrains(const RenderBlockFlow& flow, LineState& line, const LineState& previousLine, unsigned& numberOfPrecedingLinesWithHyphen, const TextFragmentIterator::Style& style, bool isFirstLine) |
zalan@apple.com | 6ab1907 | 2014-10-28 17:57:14 +0000 | [diff] [blame] | 624 | { |
zalan@apple.com | 8d1dfe4 | 2015-11-20 19:20:57 +0000 | [diff] [blame] | 625 | bool shouldApplyTextIndent = !flow.isAnonymous() || flow.parent()->firstChild() == &flow; |
zalan@apple.com | 465ab40 | 2015-01-22 23:42:46 +0000 | [diff] [blame] | 626 | LayoutUnit height = flow.logicalHeight(); |
zalan@apple.com | 0941e5f | 2017-12-04 22:52:26 +0000 | [diff] [blame] | 627 | LayoutUnit logicalHeight = flow.minLineHeightForReplacedRenderer(false, 0); |
ross.kirsling@sony.com | a10d10c | 2018-11-23 20:47:11 +0000 | [diff] [blame] | 628 | line.setLogicalLeftOffset(flow.logicalLeftOffsetForLine(height, DoNotIndentText, logicalHeight) + (shouldApplyTextIndent && isFirstLine ? flow.textIndentOffset() : 0_lu)); |
zalan@apple.com | 0941e5f | 2017-12-04 22:52:26 +0000 | [diff] [blame] | 629 | float logicalRightOffset = flow.logicalRightOffsetForLine(height, DoNotIndentText, logicalHeight); |
zalan@apple.com | 58dc70b | 2015-01-31 03:37:46 +0000 | [diff] [blame] | 630 | line.setAvailableWidth(std::max<float>(0, logicalRightOffset - line.logicalLeftOffset())); |
commit-queue@webkit.org | eea2d6a | 2018-05-25 01:42:36 +0000 | [diff] [blame] | 631 | if (style.textAlign == TextAlignMode::Justify) |
zalan@apple.com | 5c6a075 | 2017-02-01 00:01:26 +0000 | [diff] [blame] | 632 | line.setNeedsAllFragments(); |
zalan@apple.com | 8bfb3f7 | 2017-03-16 22:14:30 +0000 | [diff] [blame] | 633 | numberOfPrecedingLinesWithHyphen = (previousLine.isEmpty() || !previousLine.lastFragment().hasHyphen()) ? 0 : numberOfPrecedingLinesWithHyphen + 1; |
| 634 | if (style.hyphenLimitLines && numberOfPrecedingLinesWithHyphen >= *style.hyphenLimitLines) |
| 635 | line.setHyphenationDisabled(); |
zalan@apple.com | c934a4b | 2017-05-16 19:01:15 +0000 | [diff] [blame] | 636 | line.setCollapedWhitespaceWidth(style.font.spaceWidth() + style.wordSpacing); |
zalan@apple.com | 465ab40 | 2015-01-22 23:42:46 +0000 | [diff] [blame] | 637 | } |
| 638 | |
zalan@apple.com | 3101695 | 2017-04-22 14:34:35 +0000 | [diff] [blame] | 639 | struct SplitFragmentData { |
| 640 | unsigned position; |
| 641 | float width; |
| 642 | }; |
cdumez@apple.com | 8b7a022 | 2018-12-20 04:41:11 +0000 | [diff] [blame] | 643 | static Optional<unsigned> hyphenPositionForFragment(SplitFragmentData splitData, const TextFragmentIterator::TextFragment& fragmentToSplit, |
zalan@apple.com | 8bfb3f7 | 2017-03-16 22:14:30 +0000 | [diff] [blame] | 644 | const LineState& line, const TextFragmentIterator& textFragmentIterator, float availableWidth) |
zalan@apple.com | 9d9afbf | 2017-01-26 21:19:38 +0000 | [diff] [blame] | 645 | { |
| 646 | auto& style = textFragmentIterator.style(); |
zalan@apple.com | 8bfb3f7 | 2017-03-16 22:14:30 +0000 | [diff] [blame] | 647 | if (!style.shouldHyphenate || line.isHyphenationDisabled()) |
cdumez@apple.com | 8b7a022 | 2018-12-20 04:41:11 +0000 | [diff] [blame] | 648 | return WTF::nullopt; |
zalan@apple.com | 9d9afbf | 2017-01-26 21:19:38 +0000 | [diff] [blame] | 649 | |
zalan@apple.com | 7baecc1 | 2017-03-14 21:58:39 +0000 | [diff] [blame] | 650 | // FIXME: This is a workaround for webkit.org/b/169613. See maxPrefixWidth computation in tryHyphenating(). |
| 651 | // It does not work properly with non-collapsed leading tabs when font is enlarged. |
| 652 | auto adjustedAvailableWidth = availableWidth - style.hyphenStringWidth; |
zalan@apple.com | 8bfb3f7 | 2017-03-16 22:14:30 +0000 | [diff] [blame] | 653 | if (!line.isEmpty()) |
zalan@apple.com | 3c44203 | 2017-05-08 18:38:20 +0000 | [diff] [blame] | 654 | adjustedAvailableWidth += style.font.spaceWidth(); |
zalan@apple.com | 7baecc1 | 2017-03-14 21:58:39 +0000 | [diff] [blame] | 655 | if (!enoughWidthForHyphenation(adjustedAvailableWidth, style.font.pixelSize())) |
cdumez@apple.com | 8b7a022 | 2018-12-20 04:41:11 +0000 | [diff] [blame] | 656 | return WTF::nullopt; |
zalan@apple.com | 9d9afbf | 2017-01-26 21:19:38 +0000 | [diff] [blame] | 657 | |
| 658 | // We might be able to fit the hyphen at the split position. |
zalan@apple.com | 3101695 | 2017-04-22 14:34:35 +0000 | [diff] [blame] | 659 | auto splitPositionWithHyphen = splitData.position; |
zalan@apple.com | 9d9afbf | 2017-01-26 21:19:38 +0000 | [diff] [blame] | 660 | // Find a splitting position where hyphen surely fits. |
| 661 | unsigned start = fragmentToSplit.start(); |
zalan@apple.com | 3101695 | 2017-04-22 14:34:35 +0000 | [diff] [blame] | 662 | auto leftSideWidth = splitData.width; |
zalan@apple.com | 9d9afbf | 2017-01-26 21:19:38 +0000 | [diff] [blame] | 663 | while (leftSideWidth + style.hyphenStringWidth > availableWidth) { |
| 664 | if (--splitPositionWithHyphen <= start) |
cdumez@apple.com | 8b7a022 | 2018-12-20 04:41:11 +0000 | [diff] [blame] | 665 | return WTF::nullopt; // No space for hyphen. |
zalan@apple.com | 9d9afbf | 2017-01-26 21:19:38 +0000 | [diff] [blame] | 666 | leftSideWidth -= textFragmentIterator.textWidth(splitPositionWithHyphen, splitPositionWithHyphen + 1, 0); |
| 667 | } |
| 668 | ASSERT(splitPositionWithHyphen > start); |
| 669 | return textFragmentIterator.lastHyphenPosition(fragmentToSplit, splitPositionWithHyphen + 1); |
| 670 | } |
| 671 | |
zalan@apple.com | 3101695 | 2017-04-22 14:34:35 +0000 | [diff] [blame] | 672 | static SplitFragmentData split(const TextFragmentIterator::TextFragment& fragment, float availableWidth, |
| 673 | const TextFragmentIterator& textFragmentIterator) |
| 674 | { |
| 675 | ASSERT(availableWidth >= 0); |
| 676 | auto left = fragment.start(); |
| 677 | // Pathological case of (extremely)long string and narrow lines. |
| 678 | // Adjust the range so that we can pick a reasonable midpoint. |
| 679 | auto averageCharacterWidth = fragment.width() / fragment.length(); |
| 680 | auto right = std::min<unsigned>(left + (2 * availableWidth / averageCharacterWidth), fragment.end() - 1); |
| 681 | // Preserve the left width for the final split position so that we don't need to remeasure the left side again. |
| 682 | float leftSideWidth = 0; |
| 683 | while (left < right) { |
| 684 | auto middle = (left + right) / 2; |
| 685 | auto width = textFragmentIterator.textWidth(fragment.start(), middle + 1, 0); |
| 686 | if (width < availableWidth) { |
| 687 | left = middle + 1; |
| 688 | leftSideWidth = width; |
| 689 | } else if (width > availableWidth) |
| 690 | right = middle; |
| 691 | else { |
| 692 | right = middle + 1; |
| 693 | leftSideWidth = width; |
| 694 | break; |
| 695 | } |
| 696 | } |
| 697 | return { right, leftSideWidth }; |
| 698 | } |
| 699 | |
zalan@apple.com | 8bfb3f7 | 2017-03-16 22:14:30 +0000 | [diff] [blame] | 700 | static TextFragmentIterator::TextFragment splitFragmentToFitLine(TextFragmentIterator::TextFragment& fragmentToSplit, |
| 701 | const LineState& line, const TextFragmentIterator& textFragmentIterator) |
zalan@apple.com | 6ab1907 | 2014-10-28 17:57:14 +0000 | [diff] [blame] | 702 | { |
zalan@apple.com | 8bfb3f7 | 2017-03-16 22:14:30 +0000 | [diff] [blame] | 703 | auto availableWidth = line.availableWidth() - line.width(); |
zalan@apple.com | 3101695 | 2017-04-22 14:34:35 +0000 | [diff] [blame] | 704 | auto splitFragmentData = split(fragmentToSplit, availableWidth, textFragmentIterator); |
cdumez@apple.com | 8b7a022 | 2018-12-20 04:41:11 +0000 | [diff] [blame] | 705 | Optional<unsigned> hyphenPosition = WTF::nullopt; |
zalan@apple.com | 89b951f | 2017-01-24 21:38:20 +0000 | [diff] [blame] | 706 | // Does first character fit this line? |
zalan@apple.com | 3101695 | 2017-04-22 14:34:35 +0000 | [diff] [blame] | 707 | if (splitFragmentData.position == fragmentToSplit.start()) { |
zalan@apple.com | 8bfb3f7 | 2017-03-16 22:14:30 +0000 | [diff] [blame] | 708 | // Keep at least one character on empty lines. |
| 709 | if (line.isEmpty()) |
zalan@apple.com | 3101695 | 2017-04-22 14:34:35 +0000 | [diff] [blame] | 710 | splitFragmentData.width = textFragmentIterator.textWidth(fragmentToSplit.start(), ++splitFragmentData.position, 0); |
| 711 | } else { |
| 712 | hyphenPosition = hyphenPositionForFragment(splitFragmentData, fragmentToSplit, line, textFragmentIterator, availableWidth); |
| 713 | if (hyphenPosition) { |
| 714 | splitFragmentData.position = *hyphenPosition; |
| 715 | splitFragmentData.width = textFragmentIterator.textWidth(fragmentToSplit.start(), splitFragmentData.position, 0); |
| 716 | } |
| 717 | } |
| 718 | // If the right side surely does not fit the (next)line, we don't need the width to be kerning/ligature adjusted. |
| 719 | // Part of it gets re-measured as the left side during next split. |
| 720 | // This saves measuring long chunk of text repeatedly (see pathological case at ::split). |
| 721 | auto rightSideWidth = fragmentToSplit.width() - splitFragmentData.width; |
| 722 | if (rightSideWidth < 2 * availableWidth) |
| 723 | rightSideWidth = textFragmentIterator.textWidth(splitFragmentData.position, fragmentToSplit.end(), 0); |
zalan@apple.com | 210419f | 2017-05-14 21:16:42 +0000 | [diff] [blame] | 724 | return hyphenPosition ? fragmentToSplit.splitWithHyphen(splitFragmentData.position, textFragmentIterator.style().hyphenStringWidth, |
| 725 | splitFragmentData.width, rightSideWidth) : fragmentToSplit.split(splitFragmentData.position, splitFragmentData.width, rightSideWidth); |
zalan@apple.com | 6ab1907 | 2014-10-28 17:57:14 +0000 | [diff] [blame] | 726 | } |
| 727 | |
zalan@apple.com | 8bf2a91 | 2015-04-10 03:15:50 +0000 | [diff] [blame] | 728 | enum PreWrapLineBreakRule { Preserve, Ignore }; |
| 729 | |
| 730 | static TextFragmentIterator::TextFragment consumeLineBreakIfNeeded(const TextFragmentIterator::TextFragment& fragment, TextFragmentIterator& textFragmentIterator, LineState& line, Layout::RunVector& runs, |
| 731 | PreWrapLineBreakRule preWrapLineBreakRule = PreWrapLineBreakRule::Preserve) |
| 732 | { |
| 733 | if (!fragment.isLineBreak()) |
| 734 | return fragment; |
| 735 | |
zalan@apple.com | 79e83ab | 2017-05-15 14:21:54 +0000 | [diff] [blame] | 736 | bool isHardLinebreak = fragment.type() == TextFragmentIterator::TextFragment::HardLineBreak; |
zalan@apple.com | 8bf2a91 | 2015-04-10 03:15:50 +0000 | [diff] [blame] | 737 | // <br> always produces a run. (required by testing output) |
zalan@apple.com | 79e83ab | 2017-05-15 14:21:54 +0000 | [diff] [blame] | 738 | if (isHardLinebreak) |
zalan@apple.com | 8bf2a91 | 2015-04-10 03:15:50 +0000 | [diff] [blame] | 739 | line.appendFragmentAndCreateRunIfNeeded(fragment, runs); |
zalan@apple.com | 79e83ab | 2017-05-15 14:21:54 +0000 | [diff] [blame] | 740 | |
| 741 | auto& style = textFragmentIterator.style(); |
| 742 | if (style.preserveNewline && preWrapLineBreakRule == PreWrapLineBreakRule::Preserve) { |
| 743 | if (!isHardLinebreak) |
| 744 | return fragment; |
| 745 | } |
zalan@apple.com | 8bf2a91 | 2015-04-10 03:15:50 +0000 | [diff] [blame] | 746 | return textFragmentIterator.nextTextFragment(); |
| 747 | } |
| 748 | |
| 749 | static TextFragmentIterator::TextFragment skipWhitespaceIfNeeded(const TextFragmentIterator::TextFragment& fragment, TextFragmentIterator& textFragmentIterator) |
| 750 | { |
| 751 | if (!textFragmentIterator.style().collapseWhitespace) |
| 752 | return fragment; |
| 753 | |
| 754 | TextFragmentIterator::TextFragment firstNonWhitespaceFragment = fragment; |
| 755 | while (firstNonWhitespaceFragment.type() == TextFragmentIterator::TextFragment::Whitespace) |
| 756 | firstNonWhitespaceFragment = textFragmentIterator.nextTextFragment(); |
| 757 | return firstNonWhitespaceFragment; |
| 758 | } |
| 759 | |
| 760 | static TextFragmentIterator::TextFragment firstFragment(TextFragmentIterator& textFragmentIterator, LineState& currentLine, const LineState& previousLine, Layout::RunVector& runs) |
zalan@apple.com | ee6297d | 2015-01-27 17:01:07 +0000 | [diff] [blame] | 761 | { |
zalan@apple.com | 79e83ab | 2017-05-15 14:21:54 +0000 | [diff] [blame] | 762 | // Handle overflow fragment from previous line. |
| 763 | auto overflowedFragment = previousLine.overflowedFragment(); |
| 764 | if (overflowedFragment.isEmpty()) |
| 765 | return skipWhitespaceIfNeeded(textFragmentIterator.nextTextFragment(), textFragmentIterator); |
zalan@apple.com | ee6297d | 2015-01-27 17:01:07 +0000 | [diff] [blame] | 766 | |
zalan@apple.com | 79e83ab | 2017-05-15 14:21:54 +0000 | [diff] [blame] | 767 | if (overflowedFragment.type() != TextFragmentIterator::TextFragment::Whitespace) |
| 768 | return overflowedFragment; |
| 769 | |
| 770 | // Leading whitespace handling. |
| 771 | auto& style = textFragmentIterator.style(); |
jfernandez@igalia.com | 2c9d125 | 2019-04-08 20:31:05 +0000 | [diff] [blame] | 772 | if (style.breakSpaces) { |
| 773 | // Leading whitespace created after breaking the previous line. |
| 774 | // Breaking before the first space after a word is only allowed in combination with break-all or break-word. |
| 775 | if (style.breakFirstWordOnOverflow || previousLine.hasTrailingWhitespace()) |
| 776 | return overflowedFragment; |
| 777 | } |
zalan@apple.com | 79e83ab | 2017-05-15 14:21:54 +0000 | [diff] [blame] | 778 | // Special overflow pre-wrap whitespace handling: skip the overflowed whitespace (even when style says not-collapsible) |
| 779 | // if we manage to fit at least one character on the previous line. |
antti@apple.com | 56a81e5 | 2019-10-11 19:03:37 +0000 | [diff] [blame] | 780 | if ((style.collapseWhitespace || style.wrapLines) && previousLine.firstCharacterFits()) { |
zalan@apple.com | 8bf2a91 | 2015-04-10 03:15:50 +0000 | [diff] [blame] | 781 | // If skipping the whitespace puts us on a newline, skip the newline too as we already wrapped the line. |
zalan@apple.com | 79e83ab | 2017-05-15 14:21:54 +0000 | [diff] [blame] | 782 | auto firstFragmentCandidate = consumeLineBreakIfNeeded(textFragmentIterator.nextTextFragment(), textFragmentIterator, currentLine, runs, |
antti@apple.com | 56a81e5 | 2019-10-11 19:03:37 +0000 | [diff] [blame] | 783 | preWrap(style) ? PreWrapLineBreakRule::Ignore : PreWrapLineBreakRule::Preserve); |
zalan@apple.com | 79e83ab | 2017-05-15 14:21:54 +0000 | [diff] [blame] | 784 | return skipWhitespaceIfNeeded(firstFragmentCandidate, textFragmentIterator); |
zalan@apple.com | ee6297d | 2015-01-27 17:01:07 +0000 | [diff] [blame] | 785 | } |
zalan@apple.com | 79e83ab | 2017-05-15 14:21:54 +0000 | [diff] [blame] | 786 | return skipWhitespaceIfNeeded(overflowedFragment, textFragmentIterator); |
zalan@apple.com | ee6297d | 2015-01-27 17:01:07 +0000 | [diff] [blame] | 787 | } |
| 788 | |
zalan@apple.com | 99ff630 | 2015-03-18 14:48:01 +0000 | [diff] [blame] | 789 | static void forceFragmentToLine(LineState& line, TextFragmentIterator& textFragmentIterator, Layout::RunVector& runs, const TextFragmentIterator::TextFragment& fragment) |
| 790 | { |
| 791 | line.appendFragmentAndCreateRunIfNeeded(fragment, runs); |
| 792 | // Check if there are more fragments to add to the current line. |
zalan@apple.com | 99ff630 | 2015-03-18 14:48:01 +0000 | [diff] [blame] | 793 | auto nextFragment = textFragmentIterator.nextTextFragment(); |
zalan@apple.com | 8bf2a91 | 2015-04-10 03:15:50 +0000 | [diff] [blame] | 794 | if (fragment.overlapsToNextRenderer()) { |
| 795 | while (true) { |
| 796 | if (nextFragment.type() != fragment.type()) |
| 797 | break; |
| 798 | line.appendFragmentAndCreateRunIfNeeded(nextFragment, runs); |
| 799 | // Does it overlap to the next segment? |
| 800 | if (!nextFragment.overlapsToNextRenderer()) |
| 801 | return; |
| 802 | nextFragment = textFragmentIterator.nextTextFragment(); |
| 803 | } |
zalan@apple.com | 99ff630 | 2015-03-18 14:48:01 +0000 | [diff] [blame] | 804 | } |
zalan@apple.com | 8bf2a91 | 2015-04-10 03:15:50 +0000 | [diff] [blame] | 805 | // When the forced fragment is followed by either whitespace and/or line break, consume them too, otherwise we end up with an extra whitespace and/or line break. |
| 806 | nextFragment = skipWhitespaceIfNeeded(nextFragment, textFragmentIterator); |
| 807 | nextFragment = consumeLineBreakIfNeeded(nextFragment, textFragmentIterator, line, runs); |
zalan@apple.com | 99ff630 | 2015-03-18 14:48:01 +0000 | [diff] [blame] | 808 | line.setOverflowedFragment(nextFragment); |
| 809 | } |
| 810 | |
zalan@apple.com | 1802def | 2015-02-03 03:08:33 +0000 | [diff] [blame] | 811 | static bool createLineRuns(LineState& line, const LineState& previousLine, Layout::RunVector& runs, TextFragmentIterator& textFragmentIterator) |
zalan@apple.com | 6ab1907 | 2014-10-28 17:57:14 +0000 | [diff] [blame] | 812 | { |
zalan@apple.com | 1802def | 2015-02-03 03:08:33 +0000 | [diff] [blame] | 813 | const auto& style = textFragmentIterator.style(); |
zalan@apple.com | 7dae8407 | 2016-01-13 17:08:35 +0000 | [diff] [blame] | 814 | bool lineCanBeWrapped = style.wrapLines || style.breakFirstWordOnOverflow || style.breakAnyWordOnOverflow; |
zalan@apple.com | 8bf2a91 | 2015-04-10 03:15:50 +0000 | [diff] [blame] | 815 | auto fragment = firstFragment(textFragmentIterator, line, previousLine, runs); |
zalan@apple.com | 1802def | 2015-02-03 03:08:33 +0000 | [diff] [blame] | 816 | while (fragment.type() != TextFragmentIterator::TextFragment::ContentEnd) { |
zalan@apple.com | 79e83ab | 2017-05-15 14:21:54 +0000 | [diff] [blame] | 817 | // Hard and soft linebreaks. |
zalan@apple.com | 8bf2a91 | 2015-04-10 03:15:50 +0000 | [diff] [blame] | 818 | if (fragment.isLineBreak()) { |
zalan@apple.com | ee6297d | 2015-01-27 17:01:07 +0000 | [diff] [blame] | 819 | // Add the new line fragment only if there's nothing on the line. (otherwise the extra new line character would show up at the end of the content.) |
zalan@apple.com | aeb7081 | 2020-01-05 19:23:13 +0000 | [diff] [blame] | 820 | if (line.isEmpty() || fragment.type() == TextFragmentIterator::TextFragment::HardLineBreak || preWrap(style) || style.preserveNewline) { |
commit-queue@webkit.org | eea2d6a | 2018-05-25 01:42:36 +0000 | [diff] [blame] | 821 | if (style.textAlign == TextAlignMode::Right || style.textAlign == TextAlignMode::WebKitRight) |
zalan@apple.com | 8bf2a91 | 2015-04-10 03:15:50 +0000 | [diff] [blame] | 822 | line.removeTrailingWhitespace(runs); |
zalan@apple.com | 99ff630 | 2015-03-18 14:48:01 +0000 | [diff] [blame] | 823 | line.appendFragmentAndCreateRunIfNeeded(fragment, runs); |
zalan@apple.com | 8bf2a91 | 2015-04-10 03:15:50 +0000 | [diff] [blame] | 824 | } |
zalan@apple.com | 62e7088 | 2015-01-24 01:13:44 +0000 | [diff] [blame] | 825 | break; |
| 826 | } |
zalan@apple.com | beef486 | 2015-01-31 06:26:02 +0000 | [diff] [blame] | 827 | if (lineCanBeWrapped && !line.fits(fragment.width())) { |
zalan@apple.com | 62e7088 | 2015-01-24 01:13:44 +0000 | [diff] [blame] | 828 | // Overflow wrapping behaviour: |
| 829 | // 1. Whitesapce collapse on: whitespace is skipped. Jump to next line. |
| 830 | // 2. Whitespace collapse off: whitespace is wrapped. |
| 831 | // 3. First, non-whitespace fragment is either wrapped or kept on the line. (depends on overflow-wrap) |
zalan@apple.com | 7dae8407 | 2016-01-13 17:08:35 +0000 | [diff] [blame] | 832 | // 5. Non-whitespace fragment when there's already another fragment on the line either gets wrapped (word-break: break-all) |
| 833 | // or gets pushed to the next line. |
zalan@apple.com | 99ff630 | 2015-03-18 14:48:01 +0000 | [diff] [blame] | 834 | bool emptyLine = line.isEmpty(); |
zalan@apple.com | 62e7088 | 2015-01-24 01:13:44 +0000 | [diff] [blame] | 835 | // Whitespace fragment. |
zalan@apple.com | 1802def | 2015-02-03 03:08:33 +0000 | [diff] [blame] | 836 | if (fragment.type() == TextFragmentIterator::TextFragment::Whitespace) { |
zalan@apple.com | 79e83ab | 2017-05-15 14:21:54 +0000 | [diff] [blame] | 837 | if (style.collapseWhitespace) { |
| 838 | // Push collapased whitespace to the next line. |
| 839 | line.setOverflowedFragment(fragment); |
| 840 | break; |
zalan@apple.com | 62e7088 | 2015-01-24 01:13:44 +0000 | [diff] [blame] | 841 | } |
jfernandez@igalia.com | d6823fd | 2019-04-29 19:56:56 +0000 | [diff] [blame] | 842 | if (style.breakSpaces && line.hasWhitespaceFragments() && fragment.length() == 1) { |
jfernandez@igalia.com | 2c9d125 | 2019-04-08 20:31:05 +0000 | [diff] [blame] | 843 | // Breaking before the first space after a word is not allowed if there are previous breaking opportunities in the line. |
| 844 | textFragmentIterator.revertToEndOfFragment(line.revertToLastCompleteFragment(runs)); |
| 845 | break; |
| 846 | } |
antti@apple.com | 56a81e5 | 2019-10-11 19:03:37 +0000 | [diff] [blame] | 847 | if (preWrap(style)) { |
| 848 | line.appendFragmentAndCreateRunIfNeeded(fragment, runs); |
| 849 | fragment = textFragmentIterator.nextTextFragment(line.width()); |
| 850 | if (fragment.isLineBreak()) |
| 851 | continue; |
| 852 | line.setOverflowedFragment(fragment); |
| 853 | break; |
| 854 | } |
zalan@apple.com | 79e83ab | 2017-05-15 14:21:54 +0000 | [diff] [blame] | 855 | // Split the whitespace; left part stays on this line, right is pushed to next line. |
| 856 | line.setOverflowedFragment(splitFragmentToFitLine(fragment, line, textFragmentIterator)); |
| 857 | line.appendFragmentAndCreateRunIfNeeded(fragment, runs); |
zalan@apple.com | 62e7088 | 2015-01-24 01:13:44 +0000 | [diff] [blame] | 858 | break; |
zalan@apple.com | 6ab1907 | 2014-10-28 17:57:14 +0000 | [diff] [blame] | 859 | } |
zalan@apple.com | 62e7088 | 2015-01-24 01:13:44 +0000 | [diff] [blame] | 860 | // Non-whitespace fragment. (!style.wrapLines: bug138102(preserve existing behavior) |
zalan@apple.com | 7dae8407 | 2016-01-13 17:08:35 +0000 | [diff] [blame] | 861 | if (((emptyLine && style.breakFirstWordOnOverflow) || style.breakAnyWordOnOverflow) || !style.wrapLines) { |
zalan@apple.com | ee6297d | 2015-01-27 17:01:07 +0000 | [diff] [blame] | 862 | // Split the fragment; (modified)fragment stays on this line, overflowedFragment is pushed to next line. |
zalan@apple.com | 8bfb3f7 | 2017-03-16 22:14:30 +0000 | [diff] [blame] | 863 | line.setOverflowedFragment(splitFragmentToFitLine(fragment, line, textFragmentIterator)); |
zalan@apple.com | 99ff630 | 2015-03-18 14:48:01 +0000 | [diff] [blame] | 864 | line.appendFragmentAndCreateRunIfNeeded(fragment, runs); |
zalan@apple.com | 62e7088 | 2015-01-24 01:13:44 +0000 | [diff] [blame] | 865 | break; |
| 866 | } |
zalan@apple.com | 99ff630 | 2015-03-18 14:48:01 +0000 | [diff] [blame] | 867 | ASSERT(fragment.type() == TextFragmentIterator::TextFragment::NonWhitespace); |
zalan@apple.com | 89b951f | 2017-01-24 21:38:20 +0000 | [diff] [blame] | 868 | // Find out if this non-whitespace fragment has a hyphen where we can break. |
| 869 | if (style.shouldHyphenate) { |
| 870 | auto fragmentToSplit = fragment; |
| 871 | // Split and check if we actually ended up with a hyphen. |
zalan@apple.com | 8bfb3f7 | 2017-03-16 22:14:30 +0000 | [diff] [blame] | 872 | auto overflowFragment = splitFragmentToFitLine(fragmentToSplit, line, textFragmentIterator); |
zalan@apple.com | 89b951f | 2017-01-24 21:38:20 +0000 | [diff] [blame] | 873 | if (fragmentToSplit.hasHyphen()) { |
| 874 | line.setOverflowedFragment(overflowFragment); |
| 875 | line.appendFragmentAndCreateRunIfNeeded(fragmentToSplit, runs); |
| 876 | break; |
| 877 | } |
| 878 | // No hyphen, no split. |
| 879 | } |
| 880 | // Non-breakable non-whitespace first fragment. Add it to the current line. -it overflows though. |
zalan@apple.com | 62e7088 | 2015-01-24 01:13:44 +0000 | [diff] [blame] | 881 | if (emptyLine) { |
zalan@apple.com | 99ff630 | 2015-03-18 14:48:01 +0000 | [diff] [blame] | 882 | forceFragmentToLine(line, textFragmentIterator, runs, fragment); |
zalan@apple.com | 62e7088 | 2015-01-24 01:13:44 +0000 | [diff] [blame] | 883 | break; |
| 884 | } |
| 885 | // Non-breakable non-whitespace fragment when there's already content on the line. Push it to the next line. |
zalan@apple.com | 5c6a075 | 2017-02-01 00:01:26 +0000 | [diff] [blame] | 886 | ASSERT(line.lastFragment().isValid()); |
| 887 | if (line.lastFragment().overlapsToNextRenderer()) { |
zalan@apple.com | 99ff630 | 2015-03-18 14:48:01 +0000 | [diff] [blame] | 888 | // Check if this fragment is a continuation of a previous segment. In such cases, we need to remove them all. |
zalan@apple.com | 5c6a075 | 2017-02-01 00:01:26 +0000 | [diff] [blame] | 889 | textFragmentIterator.revertToEndOfFragment(line.revertToLastCompleteFragment(runs)); |
zalan@apple.com | 99ff630 | 2015-03-18 14:48:01 +0000 | [diff] [blame] | 890 | break; |
| 891 | } |
zalan@apple.com | 58dc70b | 2015-01-31 03:37:46 +0000 | [diff] [blame] | 892 | line.setOverflowedFragment(fragment); |
zalan@apple.com | 6ab1907 | 2014-10-28 17:57:14 +0000 | [diff] [blame] | 893 | break; |
| 894 | } |
zalan@apple.com | 99ff630 | 2015-03-18 14:48:01 +0000 | [diff] [blame] | 895 | line.appendFragmentAndCreateRunIfNeeded(fragment, runs); |
zalan@apple.com | ee6297d | 2015-01-27 17:01:07 +0000 | [diff] [blame] | 896 | // Find the next text fragment. |
zalan@apple.com | 1802def | 2015-02-03 03:08:33 +0000 | [diff] [blame] | 897 | fragment = textFragmentIterator.nextTextFragment(line.width()); |
zalan@apple.com | 6ab1907 | 2014-10-28 17:57:14 +0000 | [diff] [blame] | 898 | } |
zalan@apple.com | 99ff630 | 2015-03-18 14:48:01 +0000 | [diff] [blame] | 899 | return (fragment.type() == TextFragmentIterator::TextFragment::ContentEnd && line.overflowedFragment().isEmpty()) || line.overflowedFragment().type() == TextFragmentIterator::TextFragment::ContentEnd; |
zalan@apple.com | 3595435 | 2014-11-04 20:08:13 +0000 | [diff] [blame] | 900 | } |
| 901 | |
zalan@apple.com | 6d7b01b | 2016-03-11 04:03:32 +0000 | [diff] [blame] | 902 | static ExpansionBehavior expansionBehavior(bool isAfterExpansion, bool lastRunOnLine) |
zalan@apple.com | 3595435 | 2014-11-04 20:08:13 +0000 | [diff] [blame] | 903 | { |
zalan@apple.com | 6d7b01b | 2016-03-11 04:03:32 +0000 | [diff] [blame] | 904 | ExpansionBehavior expansionBehavior; |
mmaxfield@apple.com | c01fa5a | 2020-08-06 18:03:01 +0000 | [diff] [blame] | 905 | expansionBehavior = isAfterExpansion ? ForbidLeftExpansion : AllowLeftExpansion; |
| 906 | expansionBehavior |= lastRunOnLine ? ForbidRightExpansion : AllowRightExpansion; |
zalan@apple.com | 6d7b01b | 2016-03-11 04:03:32 +0000 | [diff] [blame] | 907 | return expansionBehavior; |
| 908 | } |
| 909 | |
zalan@apple.com | 2be8679 | 2016-04-07 14:55:54 +0000 | [diff] [blame] | 910 | static void justifyRuns(const LineState& line, Layout::RunVector& runs, unsigned firstRunIndex) |
zalan@apple.com | 6d7b01b | 2016-03-11 04:03:32 +0000 | [diff] [blame] | 911 | { |
zalan@apple.com | ee6297d | 2015-01-27 17:01:07 +0000 | [diff] [blame] | 912 | ASSERT(runs.size()); |
zalan@apple.com | 6d7b01b | 2016-03-11 04:03:32 +0000 | [diff] [blame] | 913 | auto widthToDistribute = line.availableWidth() - line.width(); |
| 914 | if (widthToDistribute <= 0) |
| 915 | return; |
| 916 | |
zalan@apple.com | 6d7b01b | 2016-03-11 04:03:32 +0000 | [diff] [blame] | 917 | auto lastRunIndex = runs.size() - 1; |
| 918 | ASSERT(firstRunIndex <= lastRunIndex); |
| 919 | Vector<std::pair<unsigned, ExpansionBehavior>> expansionOpportunityList; |
| 920 | unsigned expansionOpportunityCountOnThisLine = 0; |
| 921 | auto isAfterExpansion = true; |
| 922 | for (auto i = firstRunIndex; i <= lastRunIndex; ++i) { |
| 923 | const auto& run = runs.at(i); |
| 924 | unsigned opportunityCountInRun = 0; |
| 925 | std::tie(opportunityCountInRun, isAfterExpansion) = line.expansionOpportunityCount(run.start, run.end); |
| 926 | expansionOpportunityList.append(std::make_pair(opportunityCountInRun, expansionBehavior(isAfterExpansion, i == lastRunIndex))); |
| 927 | expansionOpportunityCountOnThisLine += opportunityCountInRun; |
| 928 | } |
| 929 | if (!expansionOpportunityCountOnThisLine) |
| 930 | return; |
| 931 | |
| 932 | ASSERT(expansionOpportunityList.size() == lastRunIndex - firstRunIndex + 1); |
| 933 | auto expansion = widthToDistribute / expansionOpportunityCountOnThisLine; |
| 934 | float accumulatedExpansion = 0; |
| 935 | for (auto i = firstRunIndex; i <= lastRunIndex; ++i) { |
| 936 | auto& run = runs.at(i); |
| 937 | unsigned opportunityCountInRun; |
| 938 | std::tie(opportunityCountInRun, run.expansionBehavior) = expansionOpportunityList.at(i - firstRunIndex); |
| 939 | run.expansion = opportunityCountInRun * expansion; |
| 940 | run.logicalLeft += accumulatedExpansion; |
| 941 | run.logicalRight += (accumulatedExpansion + run.expansion); |
| 942 | accumulatedExpansion += run.expansion; |
| 943 | } |
| 944 | } |
| 945 | |
commit-queue@webkit.org | eea2d6a | 2018-05-25 01:42:36 +0000 | [diff] [blame] | 946 | static TextAlignMode textAlignForLine(const TextFragmentIterator::Style& style, bool lastLine) |
zalan@apple.com | 2be8679 | 2016-04-07 14:55:54 +0000 | [diff] [blame] | 947 | { |
commit-queue@webkit.org | eea2d6a | 2018-05-25 01:42:36 +0000 | [diff] [blame] | 948 | // Fallback to TextAlignMode::Left (START) alignment for non-collapsable content and for the last line before a forced break or the end of the block. |
zalan@apple.com | 2be8679 | 2016-04-07 14:55:54 +0000 | [diff] [blame] | 949 | auto textAlign = style.textAlign; |
commit-queue@webkit.org | eea2d6a | 2018-05-25 01:42:36 +0000 | [diff] [blame] | 950 | if (textAlign == TextAlignMode::Justify && (!style.collapseWhitespace || lastLine)) |
| 951 | textAlign = TextAlignMode::Left; |
zalan@apple.com | 2be8679 | 2016-04-07 14:55:54 +0000 | [diff] [blame] | 952 | return textAlign; |
| 953 | } |
| 954 | |
cdumez@apple.com | 8b7a022 | 2018-12-20 04:41:11 +0000 | [diff] [blame] | 955 | static void closeLineEndingAndAdjustRuns(LineState& line, Layout::RunVector& runs, Optional<unsigned> lastRunIndexOfPreviousLine, unsigned& lineCount, |
zalan@apple.com | 2be8679 | 2016-04-07 14:55:54 +0000 | [diff] [blame] | 956 | const TextFragmentIterator& textFragmentIterator, bool lastLineInFlow) |
zalan@apple.com | 6d7b01b | 2016-03-11 04:03:32 +0000 | [diff] [blame] | 957 | { |
| 958 | if (!runs.size() || (lastRunIndexOfPreviousLine && runs.size() - 1 == lastRunIndexOfPreviousLine.value())) |
| 959 | return; |
antti@apple.com | 56a81e5 | 2019-10-11 19:03:37 +0000 | [diff] [blame] | 960 | |
| 961 | const auto& style = textFragmentIterator.style(); |
| 962 | |
| 963 | if (style.collapseWhitespace) |
| 964 | line.removeTrailingWhitespace(runs); |
| 965 | |
zalan@apple.com | ee6297d | 2015-01-27 17:01:07 +0000 | [diff] [blame] | 966 | if (!runs.size()) |
| 967 | return; |
antti@apple.com | 56a81e5 | 2019-10-11 19:03:37 +0000 | [diff] [blame] | 968 | |
zalan@apple.com | 3595435 | 2014-11-04 20:08:13 +0000 | [diff] [blame] | 969 | // Adjust runs' position by taking line's alignment into account. |
zalan@apple.com | 2be8679 | 2016-04-07 14:55:54 +0000 | [diff] [blame] | 970 | auto firstRunIndex = lastRunIndexOfPreviousLine ? lastRunIndexOfPreviousLine.value() + 1 : 0; |
zalan@apple.com | 6d7b01b | 2016-03-11 04:03:32 +0000 | [diff] [blame] | 971 | auto lineLogicalLeft = line.logicalLeftOffset(); |
zalan@apple.com | 5c6a075 | 2017-02-01 00:01:26 +0000 | [diff] [blame] | 972 | auto textAlign = textAlignForLine(style, lastLineInFlow || (line.lastFragment().isValid() && line.lastFragment().type() == TextFragmentIterator::TextFragment::HardLineBreak)); |
antti@apple.com | 56a81e5 | 2019-10-11 19:03:37 +0000 | [diff] [blame] | 973 | |
| 974 | // https://www.w3.org/TR/css-text-3/#white-space-phase-2 |
| 975 | bool shouldHangTrailingWhitespace = style.wrapLines && line.trailingWhitespaceWidth(); |
| 976 | auto hangingWhitespaceWidth = shouldHangTrailingWhitespace ? line.trailingWhitespaceWidth() : 0; |
| 977 | |
| 978 | if (textAlign == TextAlignMode::Justify) { |
zalan@apple.com | 2be8679 | 2016-04-07 14:55:54 +0000 | [diff] [blame] | 979 | justifyRuns(line, runs, firstRunIndex); |
antti@apple.com | 56a81e5 | 2019-10-11 19:03:37 +0000 | [diff] [blame] | 980 | hangingWhitespaceWidth = 0; |
| 981 | } else |
| 982 | lineLogicalLeft = computeLineLeft(line, textAlign, hangingWhitespaceWidth); |
| 983 | |
zalan@apple.com | 6d7b01b | 2016-03-11 04:03:32 +0000 | [diff] [blame] | 984 | for (auto i = firstRunIndex; i < runs.size(); ++i) { |
| 985 | runs[i].logicalLeft += lineLogicalLeft; |
| 986 | runs[i].logicalRight += lineLogicalLeft; |
zalan@apple.com | 6ab1907 | 2014-10-28 17:57:14 +0000 | [diff] [blame] | 987 | } |
antti@apple.com | 56a81e5 | 2019-10-11 19:03:37 +0000 | [diff] [blame] | 988 | |
| 989 | if (shouldHangTrailingWhitespace && hangingWhitespaceWidth < line.trailingWhitespaceWidth()) |
| 990 | runs.last().logicalRight = runs.last().logicalRight - (line.trailingWhitespaceWidth() - hangingWhitespaceWidth); |
| 991 | |
zalan@apple.com | ee6297d | 2015-01-27 17:01:07 +0000 | [diff] [blame] | 992 | runs.last().isEndOfLine = true; |
zalan@apple.com | 3595435 | 2014-11-04 20:08:13 +0000 | [diff] [blame] | 993 | ++lineCount; |
zalan@apple.com | 6ab1907 | 2014-10-28 17:57:14 +0000 | [diff] [blame] | 994 | } |
| 995 | |
zalan@apple.com | 484bc67 | 2014-11-17 21:14:57 +0000 | [diff] [blame] | 996 | static void createTextRuns(Layout::RunVector& runs, RenderBlockFlow& flow, unsigned& lineCount) |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 997 | { |
antti@apple.com | 01a0412 | 2013-11-20 21:23:19 +0000 | [diff] [blame] | 998 | LayoutUnit borderAndPaddingBefore = flow.borderAndPaddingBefore(); |
| 999 | LayoutUnit lineHeight = lineHeightFromFlow(flow); |
zalan@apple.com | ee6297d | 2015-01-27 17:01:07 +0000 | [diff] [blame] | 1000 | LineState line; |
zalan@apple.com | 8bfb3f7 | 2017-03-16 22:14:30 +0000 | [diff] [blame] | 1001 | unsigned numberOfPrecedingLinesWithHyphen = 0; |
zalan@apple.com | 3595435 | 2014-11-04 20:08:13 +0000 | [diff] [blame] | 1002 | bool isEndOfContent = false; |
zalan@apple.com | 1802def | 2015-02-03 03:08:33 +0000 | [diff] [blame] | 1003 | TextFragmentIterator textFragmentIterator = TextFragmentIterator(flow); |
cdumez@apple.com | 8b7a022 | 2018-12-20 04:41:11 +0000 | [diff] [blame] | 1004 | Optional<unsigned> lastRunIndexOfPreviousLine; |
zalan@apple.com | 6ab1907 | 2014-10-28 17:57:14 +0000 | [diff] [blame] | 1005 | do { |
antti@apple.com | 01a0412 | 2013-11-20 21:23:19 +0000 | [diff] [blame] | 1006 | flow.setLogicalHeight(lineHeight * lineCount + borderAndPaddingBefore); |
zalan@apple.com | ee6297d | 2015-01-27 17:01:07 +0000 | [diff] [blame] | 1007 | LineState previousLine = line; |
zalan@apple.com | ee6297d | 2015-01-27 17:01:07 +0000 | [diff] [blame] | 1008 | line = LineState(); |
zalan@apple.com | 8bfb3f7 | 2017-03-16 22:14:30 +0000 | [diff] [blame] | 1009 | updateLineConstrains(flow, line, previousLine, numberOfPrecedingLinesWithHyphen, textFragmentIterator.style(), !lineCount); |
zalan@apple.com | 1802def | 2015-02-03 03:08:33 +0000 | [diff] [blame] | 1010 | isEndOfContent = createLineRuns(line, previousLine, runs, textFragmentIterator); |
zalan@apple.com | 6d7b01b | 2016-03-11 04:03:32 +0000 | [diff] [blame] | 1011 | closeLineEndingAndAdjustRuns(line, runs, lastRunIndexOfPreviousLine, lineCount, textFragmentIterator, isEndOfContent); |
| 1012 | if (runs.size()) |
| 1013 | lastRunIndexOfPreviousLine = runs.size() - 1; |
zalan@apple.com | 3595435 | 2014-11-04 20:08:13 +0000 | [diff] [blame] | 1014 | } while (!isEndOfContent); |
antti@apple.com | aa930a6 | 2013-11-08 12:53:19 +0000 | [diff] [blame] | 1015 | } |
| 1016 | |
antti@apple.com | ba6789f | 2019-09-23 15:54:58 +0000 | [diff] [blame] | 1017 | Ref<Layout> create(RenderBlockFlow& flow) |
antti@apple.com | aa930a6 | 2013-11-08 12:53:19 +0000 | [diff] [blame] | 1018 | { |
antti@apple.com | aa930a6 | 2013-11-08 12:53:19 +0000 | [diff] [blame] | 1019 | unsigned lineCount = 0; |
zalan@apple.com | eb1c030 | 2014-11-05 03:47:45 +0000 | [diff] [blame] | 1020 | Layout::RunVector runs; |
zalan@apple.com | 484bc67 | 2014-11-17 21:14:57 +0000 | [diff] [blame] | 1021 | createTextRuns(runs, flow, lineCount); |
zalan@apple.com | 6cda0fa | 2018-05-09 00:20:18 +0000 | [diff] [blame] | 1022 | return Layout::create(runs, lineCount, flow); |
antti@apple.com | afe9c57 | 2013-10-29 20:25:44 +0000 | [diff] [blame] | 1023 | } |
| 1024 | |
antti@apple.com | ba6789f | 2019-09-23 15:54:58 +0000 | [diff] [blame] | 1025 | Ref<Layout> Layout::create(const RunVector& runVector, unsigned lineCount, const RenderBlockFlow& blockFlow) |
antti@apple.com | afe9c57 | 2013-10-29 20:25:44 +0000 | [diff] [blame] | 1026 | { |
| 1027 | void* slot = WTF::fastMalloc(sizeof(Layout) + sizeof(Run) * runVector.size()); |
antti@apple.com | ba6789f | 2019-09-23 15:54:58 +0000 | [diff] [blame] | 1028 | return adoptRef(*new (NotNull, slot) Layout(runVector, lineCount, blockFlow)); |
antti@apple.com | afe9c57 | 2013-10-29 20:25:44 +0000 | [diff] [blame] | 1029 | } |
| 1030 | |
zalan@apple.com | 6cda0fa | 2018-05-09 00:20:18 +0000 | [diff] [blame] | 1031 | Layout::Layout(const RunVector& runVector, unsigned lineCount, const RenderBlockFlow& blockFlow) |
antti@apple.com | 09c8351 | 2013-10-30 14:12:32 +0000 | [diff] [blame] | 1032 | : m_lineCount(lineCount) |
| 1033 | , m_runCount(runVector.size()) |
zalan@apple.com | 6cda0fa | 2018-05-09 00:20:18 +0000 | [diff] [blame] | 1034 | , m_blockFlowRenderer(blockFlow) |
antti@apple.com | afe9c57 | 2013-10-29 20:25:44 +0000 | [diff] [blame] | 1035 | { |
antti@apple.com | 09c8351 | 2013-10-30 14:12:32 +0000 | [diff] [blame] | 1036 | memcpy(m_runs, runVector.data(), m_runCount * sizeof(Run)); |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 1037 | } |
| 1038 | |
zalan@apple.com | 6cda0fa | 2018-05-09 00:20:18 +0000 | [diff] [blame] | 1039 | const RunResolver& Layout::runResolver() const |
| 1040 | { |
| 1041 | if (!m_runResolver) |
ysuzuki@apple.com | 1d8e24d | 2019-08-19 06:59:40 +0000 | [diff] [blame] | 1042 | m_runResolver = makeUnique<RunResolver>(m_blockFlowRenderer, *this); |
zalan@apple.com | 6cda0fa | 2018-05-09 00:20:18 +0000 | [diff] [blame] | 1043 | return *m_runResolver; |
| 1044 | } |
| 1045 | |
commit-queue@webkit.org | 01b4c14 | 2018-04-11 20:29:49 +0000 | [diff] [blame] | 1046 | Layout::~Layout() |
| 1047 | { |
| 1048 | simpleLineLayoutWillBeDeleted(*this); |
| 1049 | } |
| 1050 | |
antti@apple.com | 940f587 | 2013-10-24 20:31:11 +0000 | [diff] [blame] | 1051 | } |
| 1052 | } |