darin | 55ae73e | 2007-05-11 15:47:28 +0000 | [diff] [blame] | 1 | /* |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 2 | * Copyright (C) 2000 Lars Knoll (knoll@kde.org) |
mitz@apple.com | 86470c8 | 2011-01-27 01:39:27 +0000 | [diff] [blame] | 3 | * Copyright (C) 2003, 2004, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All right reserved. |
eric@webkit.org | ddbec0aa | 2010-01-06 01:13:11 +0000 | [diff] [blame] | 4 | * Copyright (C) 2010 Google Inc. All rights reserved. |
commit-queue@webkit.org | 1776140 | 2013-04-17 18:48:56 +0000 | [diff] [blame] | 5 | * Copyright (C) 2013 ChangSeok Oh <shivamidow@gmail.com> |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 6 | * |
| 7 | * This library is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU Library General Public |
| 9 | * License as published by the Free Software Foundation; either |
| 10 | * version 2 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * This library is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * Library General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Library General Public License |
| 18 | * along with this library; see the file COPYING.LIB. If not, write to |
ddkilzer | c8eccec | 2007-09-26 02:29:57 +0000 | [diff] [blame] | 19 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 20 | * Boston, MA 02110-1301, USA. |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 21 | * |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 22 | */ |
darin | be4c67d | 2005-12-19 19:53:12 +0000 | [diff] [blame] | 23 | |
mjs | b64c50a | 2005-10-03 21:13:12 +0000 | [diff] [blame] | 24 | #include "config.h" |
darin | 36d1136 | 2006-04-11 16:30:21 +0000 | [diff] [blame] | 25 | |
mitz@apple.com | 4c1ff32 | 2009-07-13 00:54:12 +0000 | [diff] [blame] | 26 | #include "BidiResolver.h" |
bjonesbe@adobe.com | 6747809 | 2013-09-09 22:18:17 +0000 | [diff] [blame] | 27 | #include "FloatingObjects.h" |
mitz@apple.com | b210765 | 2010-06-21 16:54:52 +0000 | [diff] [blame] | 28 | #include "Hyphenation.h" |
hyatt@apple.com | 71eeb44 | 2010-02-11 20:05:51 +0000 | [diff] [blame] | 29 | #include "InlineIterator.h" |
eseidel | 3a6d132 | 2006-01-09 03:14:50 +0000 | [diff] [blame] | 30 | #include "InlineTextBox.h" |
zoltan@webkit.org | fefa141 | 2013-09-12 16:57:55 +0000 | [diff] [blame] | 31 | #include "LineInfo.h" |
zoltan@webkit.org | 4c74e8d | 2013-09-13 17:59:12 +0000 | [diff] [blame] | 32 | #include "LineLayoutState.h" |
ggaren | ec11e5b | 2007-02-25 02:14:54 +0000 | [diff] [blame] | 33 | #include "Logging.h" |
darin | 36d1136 | 2006-04-11 16:30:21 +0000 | [diff] [blame] | 34 | #include "RenderArena.h" |
hyatt@apple.com | 4d046b7 | 2011-01-31 20:39:09 +0000 | [diff] [blame] | 35 | #include "RenderCombineText.h" |
esprehn@chromium.org | 7745ffb | 2013-02-19 21:51:19 +0000 | [diff] [blame] | 36 | #include "RenderCounter.h" |
hyatt@apple.com | a10d30e | 2011-09-22 22:28:21 +0000 | [diff] [blame] | 37 | #include "RenderFlowThread.h" |
hyatt@apple.com | c3c7e90 | 2009-01-28 21:48:33 +0000 | [diff] [blame] | 38 | #include "RenderInline.h" |
eric@webkit.org | b35848a | 2010-06-10 08:33:22 +0000 | [diff] [blame] | 39 | #include "RenderLayer.h" |
antti@apple.com | 8d8ae71 | 2013-09-18 18:04:32 +0000 | [diff] [blame] | 40 | #include "RenderLineBreak.h" |
mjs | d26b297 | 2007-02-13 13:09:04 +0000 | [diff] [blame] | 41 | #include "RenderListMarker.h" |
zoltan@webkit.org | b7a7346 | 2013-02-22 19:53:35 +0000 | [diff] [blame] | 42 | #include "RenderRegion.h" |
mitz@apple.com | ddb5987 | 2011-04-05 05:21:16 +0000 | [diff] [blame] | 43 | #include "RenderRubyRun.h" |
hyatt | d804834 | 2006-05-31 01:48:18 +0000 | [diff] [blame] | 44 | #include "RenderView.h" |
hyatt@apple.com | cc1737c | 2010-09-16 20:20:02 +0000 | [diff] [blame] | 45 | #include "Settings.h" |
dbates@webkit.org | f6f05a9 | 2010-05-17 04:58:25 +0000 | [diff] [blame] | 46 | #include "TrailingFloatsRootInlineBox.h" |
hyatt@apple.com | 4a9c625a | 2010-11-17 20:55:40 +0000 | [diff] [blame] | 47 | #include "VerticalPositionCache.h" |
darin | 36d1136 | 2006-04-11 16:30:21 +0000 | [diff] [blame] | 48 | #include "break_lines.h" |
slewis@apple.com | a7615ca | 2008-07-12 05:51:33 +0000 | [diff] [blame] | 49 | #include <wtf/RefCountedLeakCounter.h> |
bolsinga@apple.com | 97e42c4 | 2008-11-15 04:47:20 +0000 | [diff] [blame] | 50 | #include <wtf/StdLibExtras.h> |
darin | 91298e5 | 2006-06-12 01:10:17 +0000 | [diff] [blame] | 51 | #include <wtf/Vector.h> |
paroga@webkit.org | 10c9e1b | 2011-01-29 17:04:51 +0000 | [diff] [blame] | 52 | #include <wtf/unicode/CharacterNames.h> |
hyatt | 8c371e5 | 2004-06-16 01:19:26 +0000 | [diff] [blame] | 53 | |
betravis@adobe.com | ed90c98 | 2013-06-05 23:05:57 +0000 | [diff] [blame] | 54 | #if ENABLE(CSS_SHAPES) |
betravis@adobe.com | cf7cba6 | 2013-06-10 21:23:45 +0000 | [diff] [blame] | 55 | #include "ShapeInsideInfo.h" |
commit-queue@webkit.org | b354051 | 2012-08-24 18:48:49 +0000 | [diff] [blame] | 56 | #endif |
| 57 | |
zimmermann@webkit.org | b40815c | 2010-06-18 11:18:44 +0000 | [diff] [blame] | 58 | #if ENABLE(SVG) |
zimmermann@webkit.org | 6e96afd | 2010-09-10 15:35:50 +0000 | [diff] [blame] | 59 | #include "RenderSVGInlineText.h" |
zimmermann@webkit.org | b40815c | 2010-06-18 11:18:44 +0000 | [diff] [blame] | 60 | #include "SVGRootInlineBox.h" |
| 61 | #endif |
| 62 | |
darin | 7bd7095 | 2006-04-13 07:07:34 +0000 | [diff] [blame] | 63 | using namespace std; |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 64 | using namespace WTF; |
| 65 | using namespace Unicode; |
darin | 7bd7095 | 2006-04-13 07:07:34 +0000 | [diff] [blame] | 66 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 67 | namespace WebCore { |
mjs | fe301d7 | 2003-10-02 18:46:18 +0000 | [diff] [blame] | 68 | |
hyatt | 1d5d87b | 2007-04-24 04:55:54 +0000 | [diff] [blame] | 69 | // We don't let our line box tree for a single line get any deeper than this. |
| 70 | const unsigned cMaxLineDepth = 200; |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 71 | |
zoltan@webkit.org | 8b422c8 | 2013-09-20 21:17:43 +0000 | [diff] [blame] | 72 | struct RenderTextInfo { |
| 73 | // Destruction of m_layout requires TextLayout to be a complete type, so the constructor and destructor are made non-inline to avoid compilation errors. |
| 74 | RenderTextInfo(); |
| 75 | ~RenderTextInfo(); |
| 76 | |
| 77 | RenderText* m_text; |
| 78 | OwnPtr<TextLayout> m_layout; |
| 79 | LazyLineBreakIterator m_lineBreakIterator; |
| 80 | const Font* m_font; |
| 81 | }; |
| 82 | |
| 83 | class LineBreaker { |
| 84 | public: |
| 85 | LineBreaker(RenderBlock* block) |
| 86 | : m_block(block) |
| 87 | { |
| 88 | reset(); |
| 89 | } |
| 90 | |
| 91 | InlineIterator nextLineBreak(InlineBidiResolver&, LineInfo&, RenderTextInfo&, FloatingObject* lastFloatFromPreviousLine, unsigned consecutiveHyphenatedLines, WordMeasurements&); |
| 92 | |
| 93 | bool lineWasHyphenated() { return m_hyphenated; } |
| 94 | const Vector<RenderBox*>& positionedObjects() { return m_positionedObjects; } |
| 95 | EClear clear() { return m_clear; } |
| 96 | private: |
| 97 | void reset(); |
| 98 | |
| 99 | InlineIterator nextSegmentBreak(InlineBidiResolver&, LineInfo&, RenderTextInfo&, FloatingObject* lastFloatFromPreviousLine, unsigned consecutiveHyphenatedLines, WordMeasurements&); |
| 100 | void skipTrailingWhitespace(InlineIterator&, const LineInfo&); |
| 101 | void skipLeadingWhitespace(InlineBidiResolver&, LineInfo&, FloatingObject* lastFloatFromPreviousLine, LineWidth&); |
| 102 | |
| 103 | RenderBlock* m_block; |
| 104 | bool m_hyphenated; |
| 105 | EClear m_clear; |
| 106 | Vector<RenderBox*> m_positionedObjects; |
| 107 | }; |
| 108 | |
betravis@adobe.com | ed90c98 | 2013-06-05 23:05:57 +0000 | [diff] [blame] | 109 | #if ENABLE(CSS_SHAPES) |
betravis@adobe.com | cf7cba6 | 2013-06-10 21:23:45 +0000 | [diff] [blame] | 110 | ShapeInsideInfo* RenderBlock::layoutShapeInsideInfo() const |
commit-queue@webkit.org | 3b26f3d | 2012-09-25 18:22:39 +0000 | [diff] [blame] | 111 | { |
akling@apple.com | 691cf5c | 2013-08-24 16:33:15 +0000 | [diff] [blame] | 112 | ShapeInsideInfo* shapeInsideInfo = view().layoutState()->shapeInsideInfo(); |
betravis@adobe.com | 1e4305c | 2013-04-05 17:30:27 +0000 | [diff] [blame] | 113 | |
betravis@adobe.com | cf7cba6 | 2013-06-10 21:23:45 +0000 | [diff] [blame] | 114 | if (!shapeInsideInfo && flowThreadContainingBlock() && allowsShapeInsideInfoSharing()) { |
zoltan@webkit.org | 68678b7 | 2013-09-20 20:53:44 +0000 | [diff] [blame] | 115 | LayoutUnit lineHeight = this->lineHeight(false, isHorizontalWritingMode() ? HorizontalLine : VerticalLine, PositionOfInteriorLineBoxes); |
zoltan@webkit.org | bd3dabd | 2013-05-13 19:11:33 +0000 | [diff] [blame] | 116 | // regionAtBlockOffset returns regions like an array first={0,N-1}, second={N,M-1}, ... |
zoltan@webkit.org | 68678b7 | 2013-09-20 20:53:44 +0000 | [diff] [blame] | 117 | LayoutUnit offset = logicalHeight() + lineHeight - LayoutUnit(1); |
betravis@adobe.com | a53af34 | 2013-03-01 21:02:16 +0000 | [diff] [blame] | 118 | RenderRegion* region = regionAtBlockOffset(offset); |
betravis@adobe.com | 1e4305c | 2013-04-05 17:30:27 +0000 | [diff] [blame] | 119 | if (region) |
betravis@adobe.com | cf7cba6 | 2013-06-10 21:23:45 +0000 | [diff] [blame] | 120 | shapeInsideInfo = region->shapeInsideInfo(); |
zoltan@webkit.org | b7a7346 | 2013-02-22 19:53:35 +0000 | [diff] [blame] | 121 | } |
betravis@adobe.com | 1e4305c | 2013-04-05 17:30:27 +0000 | [diff] [blame] | 122 | |
zoltan@webkit.org | b7a7346 | 2013-02-22 19:53:35 +0000 | [diff] [blame] | 123 | return shapeInsideInfo; |
commit-queue@webkit.org | 3b26f3d | 2012-09-25 18:22:39 +0000 | [diff] [blame] | 124 | } |
| 125 | #endif |
| 126 | |
antti@apple.com | 3ab7ef3 | 2013-09-29 20:50:01 +0000 | [diff] [blame] | 127 | static inline LayoutUnit borderPaddingMarginStart(const RenderInline& child) |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 128 | { |
antti@apple.com | 3ab7ef3 | 2013-09-29 20:50:01 +0000 | [diff] [blame] | 129 | return child.marginStart() + child.paddingStart() + child.borderStart(); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 130 | } |
| 131 | |
antti@apple.com | 3ab7ef3 | 2013-09-29 20:50:01 +0000 | [diff] [blame] | 132 | static inline LayoutUnit borderPaddingMarginEnd(const RenderInline& child) |
rniwa@webkit.org | 33a346a | 2011-04-06 17:06:14 +0000 | [diff] [blame] | 133 | { |
antti@apple.com | 3ab7ef3 | 2013-09-29 20:50:01 +0000 | [diff] [blame] | 134 | return child.marginEnd() + child.paddingEnd() + child.borderEnd(); |
rniwa@webkit.org | 33a346a | 2011-04-06 17:06:14 +0000 | [diff] [blame] | 135 | } |
| 136 | |
robert@webkit.org | fea9b8d | 2013-05-24 16:18:16 +0000 | [diff] [blame] | 137 | static inline bool shouldAddBorderPaddingMargin(RenderObject* child) |
robert@webkit.org | 6dc9a23 | 2012-10-08 18:44:03 +0000 | [diff] [blame] | 138 | { |
robert@webkit.org | fea9b8d | 2013-05-24 16:18:16 +0000 | [diff] [blame] | 139 | // When deciding whether we're at the edge of an inline, adjacent collapsed whitespace is the same as no sibling at all. |
| 140 | return !child || (child->isText() && !toRenderText(child)->textLength()); |
robert@webkit.org | 6dc9a23 | 2012-10-08 18:44:03 +0000 | [diff] [blame] | 141 | } |
| 142 | |
robert@webkit.org | e10af55 | 2013-04-15 18:23:37 +0000 | [diff] [blame] | 143 | static RenderObject* previousInFlowSibling(RenderObject* child) |
| 144 | { |
| 145 | child = child->previousSibling(); |
| 146 | while (child && child->isOutOfFlowPositioned()) |
| 147 | child = child->previousSibling(); |
| 148 | return child; |
| 149 | } |
| 150 | |
robert@webkit.org | fea9b8d | 2013-05-24 16:18:16 +0000 | [diff] [blame] | 151 | static LayoutUnit inlineLogicalWidth(RenderObject* child, bool checkStartEdge = true, bool checkEndEdge = true) |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 152 | { |
hyatt | 1d5d87b | 2007-04-24 04:55:54 +0000 | [diff] [blame] | 153 | unsigned lineDepth = 1; |
eae@chromium.org | ee8613e | 2011-11-12 01:12:58 +0000 | [diff] [blame] | 154 | LayoutUnit extraWidth = 0; |
antti@apple.com | 3ab7ef3 | 2013-09-29 20:50:01 +0000 | [diff] [blame] | 155 | RenderElement* parent = child->parent(); |
robert@webkit.org | fc89282 | 2013-04-08 18:38:26 +0000 | [diff] [blame] | 156 | while (parent->isRenderInline() && lineDepth++ < cMaxLineDepth) { |
antti@apple.com | 3ab7ef3 | 2013-09-29 20:50:01 +0000 | [diff] [blame] | 157 | const RenderInline& parentAsRenderInline = toRenderInline(*parent); |
eae@chromium.org | 039c76a | 2013-04-02 23:17:18 +0000 | [diff] [blame] | 158 | if (!isEmptyInline(parentAsRenderInline)) { |
robert@webkit.org | fea9b8d | 2013-05-24 16:18:16 +0000 | [diff] [blame] | 159 | checkStartEdge = checkStartEdge && shouldAddBorderPaddingMargin(previousInFlowSibling(child)); |
| 160 | if (checkStartEdge) |
eae@chromium.org | 039c76a | 2013-04-02 23:17:18 +0000 | [diff] [blame] | 161 | extraWidth += borderPaddingMarginStart(parentAsRenderInline); |
robert@webkit.org | fea9b8d | 2013-05-24 16:18:16 +0000 | [diff] [blame] | 162 | checkEndEdge = checkEndEdge && shouldAddBorderPaddingMargin(child->nextSibling()); |
| 163 | if (checkEndEdge) |
eae@chromium.org | 039c76a | 2013-04-02 23:17:18 +0000 | [diff] [blame] | 164 | extraWidth += borderPaddingMarginEnd(parentAsRenderInline); |
robert@webkit.org | fea9b8d | 2013-05-24 16:18:16 +0000 | [diff] [blame] | 165 | if (!checkStartEdge && !checkEndEdge) |
eae@chromium.org | 039c76a | 2013-04-02 23:17:18 +0000 | [diff] [blame] | 166 | return extraWidth; |
| 167 | } |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 168 | child = parent; |
| 169 | parent = child->parent(); |
| 170 | } |
| 171 | return extraWidth; |
| 172 | } |
| 173 | |
leviw@chromium.org | e7812f3 | 2012-02-07 23:46:40 +0000 | [diff] [blame] | 174 | static void determineDirectionality(TextDirection& dir, InlineIterator iter) |
leviw@chromium.org | 7781b6a | 2011-06-27 22:01:38 +0000 | [diff] [blame] | 175 | { |
| 176 | while (!iter.atEnd()) { |
| 177 | if (iter.atParagraphSeparator()) |
| 178 | return; |
| 179 | if (UChar current = iter.current()) { |
| 180 | Direction charDirection = direction(current); |
| 181 | if (charDirection == LeftToRight) { |
| 182 | dir = LTR; |
| 183 | return; |
| 184 | } |
| 185 | if (charDirection == RightToLeft || charDirection == RightToLeftArabic) { |
| 186 | dir = RTL; |
| 187 | return; |
| 188 | } |
| 189 | } |
| 190 | iter.increment(); |
| 191 | } |
| 192 | } |
| 193 | |
hyatt@apple.com | b3466af | 2009-06-13 06:04:40 +0000 | [diff] [blame] | 194 | static void checkMidpoints(LineMidpointState& lineMidpointState, InlineIterator& lBreak) |
hyatt | fe99c87 | 2003-07-31 22:25:29 +0000 | [diff] [blame] | 195 | { |
| 196 | // Check to see if our last midpoint is a start point beyond the line break. If so, |
hyatt | dca76e9 | 2005-11-02 08:52:50 +0000 | [diff] [blame] | 197 | // shave it off the list, and shave off a trailing space if the previous end point doesn't |
| 198 | // preserve whitespace. |
eric@webkit.org | 8c25a59 | 2011-03-29 13:18:11 +0000 | [diff] [blame] | 199 | if (lBreak.m_obj && lineMidpointState.numMidpoints && !(lineMidpointState.numMidpoints % 2)) { |
hyatt@apple.com | 1a5ffd8 | 2009-06-13 17:20:30 +0000 | [diff] [blame] | 200 | InlineIterator* midpoints = lineMidpointState.midpoints.data(); |
| 201 | InlineIterator& endpoint = midpoints[lineMidpointState.numMidpoints - 2]; |
| 202 | const InlineIterator& startpoint = midpoints[lineMidpointState.numMidpoints - 1]; |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 203 | InlineIterator currpoint = endpoint; |
hyatt | fe99c87 | 2003-07-31 22:25:29 +0000 | [diff] [blame] | 204 | while (!currpoint.atEnd() && currpoint != startpoint && currpoint != lBreak) |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 205 | currpoint.increment(); |
hyatt | fe99c87 | 2003-07-31 22:25:29 +0000 | [diff] [blame] | 206 | if (currpoint == lBreak) { |
| 207 | // We hit the line break before the start point. Shave off the start point. |
hyatt@apple.com | 1a5ffd8 | 2009-06-13 17:20:30 +0000 | [diff] [blame] | 208 | lineMidpointState.numMidpoints--; |
eric@webkit.org | 8c25a59 | 2011-03-29 13:18:11 +0000 | [diff] [blame] | 209 | if (endpoint.m_obj->style()->collapseWhiteSpace()) |
eric@webkit.org | 86a865a | 2011-03-29 15:30:41 +0000 | [diff] [blame] | 210 | endpoint.m_pos--; |
hyatt | fe99c87 | 2003-07-31 22:25:29 +0000 | [diff] [blame] | 211 | } |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 212 | } |
hyatt | fe99c87 | 2003-07-31 22:25:29 +0000 | [diff] [blame] | 213 | } |
| 214 | |
leviw@chromium.org | 0e7d89e | 2013-02-23 00:00:27 +0000 | [diff] [blame] | 215 | // Don't call this directly. Use one of the descriptive helper functions below. |
| 216 | static void deprecatedAddMidpoint(LineMidpointState& lineMidpointState, const InlineIterator& midpoint) |
hyatt | 85586af | 2003-02-19 23:22:42 +0000 | [diff] [blame] | 217 | { |
hyatt@apple.com | 1a5ffd8 | 2009-06-13 17:20:30 +0000 | [diff] [blame] | 218 | if (lineMidpointState.midpoints.size() <= lineMidpointState.numMidpoints) |
| 219 | lineMidpointState.midpoints.grow(lineMidpointState.numMidpoints + 10); |
hyatt | 85586af | 2003-02-19 23:22:42 +0000 | [diff] [blame] | 220 | |
hyatt@apple.com | 1a5ffd8 | 2009-06-13 17:20:30 +0000 | [diff] [blame] | 221 | InlineIterator* midpoints = lineMidpointState.midpoints.data(); |
| 222 | midpoints[lineMidpointState.numMidpoints++] = midpoint; |
hyatt | 85586af | 2003-02-19 23:22:42 +0000 | [diff] [blame] | 223 | } |
| 224 | |
leviw@chromium.org | 0e7d89e | 2013-02-23 00:00:27 +0000 | [diff] [blame] | 225 | static inline void startIgnoringSpaces(LineMidpointState& lineMidpointState, const InlineIterator& midpoint) |
| 226 | { |
| 227 | ASSERT(!(lineMidpointState.numMidpoints % 2)); |
| 228 | deprecatedAddMidpoint(lineMidpointState, midpoint); |
| 229 | } |
| 230 | |
| 231 | static inline void stopIgnoringSpaces(LineMidpointState& lineMidpointState, const InlineIterator& midpoint) |
| 232 | { |
| 233 | ASSERT(lineMidpointState.numMidpoints % 2); |
| 234 | deprecatedAddMidpoint(lineMidpointState, midpoint); |
| 235 | } |
| 236 | |
| 237 | // When ignoring spaces, this needs to be called for objects that need line boxes such as RenderInlines or |
| 238 | // hard line breaks to ensure that they're not ignored. |
| 239 | static inline void ensureLineBoxInsideIgnoredSpaces(LineMidpointState& lineMidpointState, RenderObject* renderer) |
| 240 | { |
| 241 | InlineIterator midpoint(0, renderer, 0); |
| 242 | stopIgnoringSpaces(lineMidpointState, midpoint); |
| 243 | startIgnoringSpaces(lineMidpointState, midpoint); |
| 244 | } |
| 245 | |
| 246 | // Adding a pair of midpoints before a character will split it out into a new line box. |
| 247 | static inline void ensureCharacterGetsLineBox(LineMidpointState& lineMidpointState, InlineIterator& textParagraphSeparator) |
| 248 | { |
| 249 | InlineIterator midpoint(0, textParagraphSeparator.m_obj, textParagraphSeparator.m_pos); |
| 250 | startIgnoringSpaces(lineMidpointState, InlineIterator(0, textParagraphSeparator.m_obj, textParagraphSeparator.m_pos - 1)); |
| 251 | stopIgnoringSpaces(lineMidpointState, InlineIterator(0, textParagraphSeparator.m_obj, textParagraphSeparator.m_pos)); |
| 252 | } |
| 253 | |
eric@webkit.org | 5bee294 | 2011-04-08 02:12:31 +0000 | [diff] [blame] | 254 | static inline BidiRun* createRun(int start, int end, RenderObject* obj, InlineBidiResolver& resolver) |
| 255 | { |
| 256 | return new (obj->renderArena()) BidiRun(start, end, obj, resolver.context(), resolver.dir()); |
| 257 | } |
| 258 | |
| 259 | void RenderBlock::appendRunsForObject(BidiRunList<BidiRun>& runs, int start, int end, RenderObject* obj, InlineBidiResolver& resolver) |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 260 | { |
leviw@chromium.org | d8df17d | 2012-05-24 21:47:47 +0000 | [diff] [blame] | 261 | if (start > end || shouldSkipCreatingRunsForObject(obj)) |
hyatt | eb003b8 | 2002-11-15 22:35:10 +0000 | [diff] [blame] | 262 | return; |
hyatt | 85586af | 2003-02-19 23:22:42 +0000 | [diff] [blame] | 263 | |
hyatt@apple.com | b3466af | 2009-06-13 06:04:40 +0000 | [diff] [blame] | 264 | LineMidpointState& lineMidpointState = resolver.midpointState(); |
hyatt@apple.com | 1a5ffd8 | 2009-06-13 17:20:30 +0000 | [diff] [blame] | 265 | bool haveNextMidpoint = (lineMidpointState.currentMidpoint < lineMidpointState.numMidpoints); |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 266 | InlineIterator nextMidpoint; |
hyatt | 85586af | 2003-02-19 23:22:42 +0000 | [diff] [blame] | 267 | if (haveNextMidpoint) |
hyatt@apple.com | 1a5ffd8 | 2009-06-13 17:20:30 +0000 | [diff] [blame] | 268 | nextMidpoint = lineMidpointState.midpoints[lineMidpointState.currentMidpoint]; |
| 269 | if (lineMidpointState.betweenMidpoints) { |
eric@webkit.org | 8c25a59 | 2011-03-29 13:18:11 +0000 | [diff] [blame] | 270 | if (!(haveNextMidpoint && nextMidpoint.m_obj == obj)) |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 271 | return; |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 272 | // This is a new start point. Stop ignoring objects and |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 273 | // adjust our start. |
hyatt@apple.com | 1a5ffd8 | 2009-06-13 17:20:30 +0000 | [diff] [blame] | 274 | lineMidpointState.betweenMidpoints = false; |
eric@webkit.org | 86a865a | 2011-03-29 15:30:41 +0000 | [diff] [blame] | 275 | start = nextMidpoint.m_pos; |
hyatt@apple.com | 1a5ffd8 | 2009-06-13 17:20:30 +0000 | [diff] [blame] | 276 | lineMidpointState.currentMidpoint++; |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 277 | if (start < end) |
eric@webkit.org | 5bee294 | 2011-04-08 02:12:31 +0000 | [diff] [blame] | 278 | return appendRunsForObject(runs, start, end, obj, resolver); |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 279 | } else { |
eric@webkit.org | 8c25a59 | 2011-03-29 13:18:11 +0000 | [diff] [blame] | 280 | if (!haveNextMidpoint || (obj != nextMidpoint.m_obj)) { |
eric@webkit.org | 5bee294 | 2011-04-08 02:12:31 +0000 | [diff] [blame] | 281 | runs.addRun(createRun(start, end, obj, resolver)); |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 282 | return; |
| 283 | } |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 284 | |
hyatt | 78b8513 | 2004-03-29 20:07:45 +0000 | [diff] [blame] | 285 | // An end midpoint has been encountered within our object. We |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 286 | // need to go ahead and append a run with our endpoint. |
eric@webkit.org | 86a865a | 2011-03-29 15:30:41 +0000 | [diff] [blame] | 287 | if (static_cast<int>(nextMidpoint.m_pos + 1) <= end) { |
hyatt@apple.com | 1a5ffd8 | 2009-06-13 17:20:30 +0000 | [diff] [blame] | 288 | lineMidpointState.betweenMidpoints = true; |
| 289 | lineMidpointState.currentMidpoint++; |
eric@webkit.org | 86a865a | 2011-03-29 15:30:41 +0000 | [diff] [blame] | 290 | if (nextMidpoint.m_pos != UINT_MAX) { // UINT_MAX means stop at the object and don't include any of it. |
| 291 | if (static_cast<int>(nextMidpoint.m_pos + 1) > start) |
eric@webkit.org | 5bee294 | 2011-04-08 02:12:31 +0000 | [diff] [blame] | 292 | runs.addRun(createRun(start, nextMidpoint.m_pos + 1, obj, resolver)); |
| 293 | return appendRunsForObject(runs, nextMidpoint.m_pos + 1, end, obj, resolver); |
hyatt | c64f9fc | 2003-03-14 01:25:59 +0000 | [diff] [blame] | 294 | } |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 295 | } else |
eric@webkit.org | 5bee294 | 2011-04-08 02:12:31 +0000 | [diff] [blame] | 296 | runs.addRun(createRun(start, end, obj, resolver)); |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 297 | } |
| 298 | } |
| 299 | |
hyatt@apple.com | c92b735 | 2009-02-12 01:35:08 +0000 | [diff] [blame] | 300 | static inline InlineBox* createInlineBoxForRenderer(RenderObject* obj, bool isRootLineBox, bool isOnlyRun = false) |
| 301 | { |
| 302 | if (isRootLineBox) |
eric@webkit.org | 49b9d95 | 2009-07-03 01:29:07 +0000 | [diff] [blame] | 303 | return toRenderBlock(obj)->createAndAppendRootInlineBox(); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 304 | |
antti@apple.com | 9d8157e | 2013-09-17 15:13:37 +0000 | [diff] [blame] | 305 | if (obj->isText()) |
| 306 | return toRenderText(obj)->createInlineTextBox(); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 307 | |
hyatt@apple.com | c92b735 | 2009-02-12 01:35:08 +0000 | [diff] [blame] | 308 | if (obj->isBox()) |
| 309 | return toRenderBox(obj)->createInlineBox(); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 310 | |
antti@apple.com | 3014ac0 | 2013-09-18 14:33:55 +0000 | [diff] [blame] | 311 | if (obj->isLineBreak()) { |
antti@apple.com | 8d8ae71 | 2013-09-18 18:04:32 +0000 | [diff] [blame] | 312 | InlineBox* inlineBox = toRenderLineBreak(obj)->createInlineBox(); |
antti@apple.com | 9d8157e | 2013-09-17 15:13:37 +0000 | [diff] [blame] | 313 | // We only treat a box as text for a <br> if we are on a line by ourself or in strict mode |
| 314 | // (Note the use of strict mode. In "almost strict" mode, we don't treat the box for <br> as text.) |
antti@apple.com | 3014ac0 | 2013-09-18 14:33:55 +0000 | [diff] [blame] | 315 | inlineBox->setBehavesLikeText(isOnlyRun || obj->document().inNoQuirksMode() || obj->isLineBreakOpportunity()); |
antti@apple.com | 9d8157e | 2013-09-17 15:13:37 +0000 | [diff] [blame] | 316 | return inlineBox; |
| 317 | } |
| 318 | |
eric@webkit.org | 49b9d95 | 2009-07-03 01:29:07 +0000 | [diff] [blame] | 319 | return toRenderInline(obj)->createAndAppendInlineFlowBox(); |
hyatt@apple.com | c92b735 | 2009-02-12 01:35:08 +0000 | [diff] [blame] | 320 | } |
| 321 | |
esprehn@chromium.org | 7745ffb | 2013-02-19 21:51:19 +0000 | [diff] [blame] | 322 | // FIXME: Don't let counters mark themselves as needing pref width recalcs during layout |
| 323 | // so we don't need this hack. |
| 324 | static inline void updateCounterIfNeeded(RenderText* o) |
| 325 | { |
| 326 | if (!o->preferredLogicalWidthsDirty() || !o->isCounter()) |
| 327 | return; |
| 328 | toRenderCounter(o)->updateCounter(); |
| 329 | } |
| 330 | |
hyatt@apple.com | c92b735 | 2009-02-12 01:35:08 +0000 | [diff] [blame] | 331 | static inline void dirtyLineBoxesForRenderer(RenderObject* o, bool fullLayout) |
| 332 | { |
| 333 | if (o->isText()) { |
commit-queue@webkit.org | d639fb7 | 2012-09-01 19:46:16 +0000 | [diff] [blame] | 334 | RenderText* renderText = toRenderText(o); |
esprehn@chromium.org | 7745ffb | 2013-02-19 21:51:19 +0000 | [diff] [blame] | 335 | updateCounterIfNeeded(renderText); |
commit-queue@webkit.org | d639fb7 | 2012-09-01 19:46:16 +0000 | [diff] [blame] | 336 | renderText->dirtyLineBoxes(fullLayout); |
antti@apple.com | 3014ac0 | 2013-09-18 14:33:55 +0000 | [diff] [blame] | 337 | } else if (o->isLineBreak()) |
antti@apple.com | 8d8ae71 | 2013-09-18 18:04:32 +0000 | [diff] [blame] | 338 | toRenderLineBreak(o)->dirtyLineBoxes(fullLayout); |
antti@apple.com | 9d8157e | 2013-09-17 15:13:37 +0000 | [diff] [blame] | 339 | else |
hyatt@apple.com | c92b735 | 2009-02-12 01:35:08 +0000 | [diff] [blame] | 340 | toRenderInline(o)->dirtyLineBoxes(fullLayout); |
| 341 | } |
| 342 | |
xji@chromium.org | b0ad6eb82 | 2011-02-01 20:02:06 +0000 | [diff] [blame] | 343 | static bool parentIsConstructedOrHaveNext(InlineFlowBox* parentBox) |
| 344 | { |
| 345 | do { |
| 346 | if (parentBox->isConstructed() || parentBox->nextOnLine()) |
| 347 | return true; |
| 348 | parentBox = parentBox->parent(); |
| 349 | } while (parentBox); |
| 350 | return false; |
| 351 | } |
| 352 | |
commit-queue@webkit.org | ccad924 | 2012-12-05 20:17:30 +0000 | [diff] [blame] | 353 | InlineFlowBox* RenderBlock::createLineBoxes(RenderObject* obj, const LineInfo& lineInfo, InlineBox* childBox, bool startNewSegment) |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 354 | { |
| 355 | // See if we have an unconstructed line box for this object that is also |
| 356 | // the last item on the line. |
hyatt | 1d5d87b | 2007-04-24 04:55:54 +0000 | [diff] [blame] | 357 | unsigned lineDepth = 1; |
hyatt | 1d5d87b | 2007-04-24 04:55:54 +0000 | [diff] [blame] | 358 | InlineFlowBox* parentBox = 0; |
| 359 | InlineFlowBox* result = 0; |
hyatt@apple.com | 7d4066a | 2011-03-29 17:56:09 +0000 | [diff] [blame] | 360 | bool hasDefaultLineBoxContain = style()->lineBoxContain() == RenderStyle::initialLineBoxContain(); |
hyatt | 1d5d87b | 2007-04-24 04:55:54 +0000 | [diff] [blame] | 361 | do { |
inferno@chromium.org | 14b0414 | 2013-02-04 18:43:03 +0000 | [diff] [blame] | 362 | ASSERT_WITH_SECURITY_IMPLICATION(obj->isRenderInline() || obj == this); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 363 | |
hyatt@apple.com | a61b8a3 | 2011-04-06 18:20:52 +0000 | [diff] [blame] | 364 | RenderInline* inlineFlow = (obj != this) ? toRenderInline(obj) : 0; |
| 365 | |
hyatt | 1d5d87b | 2007-04-24 04:55:54 +0000 | [diff] [blame] | 366 | // Get the last box we made for this render object. |
hyatt@apple.com | a61b8a3 | 2011-04-06 18:20:52 +0000 | [diff] [blame] | 367 | parentBox = inlineFlow ? inlineFlow->lastLineBox() : toRenderBlock(obj)->lastLineBox(); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 368 | |
xji@chromium.org | b0ad6eb82 | 2011-02-01 20:02:06 +0000 | [diff] [blame] | 369 | // If this box or its ancestor is constructed then it is from a previous line, and we need |
| 370 | // to make a new box for our line. If this box or its ancestor is unconstructed but it has |
hyatt | 1d5d87b | 2007-04-24 04:55:54 +0000 | [diff] [blame] | 371 | // something following it on the line, then we know we have to make a new box |
| 372 | // as well. In this situation our inline has actually been split in two on |
| 373 | // the same line (this can happen with very fancy language mixtures). |
| 374 | bool constructedNewBox = false; |
hyatt@apple.com | a61b8a3 | 2011-04-06 18:20:52 +0000 | [diff] [blame] | 375 | bool allowedToConstructNewBox = !hasDefaultLineBoxContain || !inlineFlow || inlineFlow->alwaysCreateLineBoxes(); |
commit-queue@webkit.org | ccad924 | 2012-12-05 20:17:30 +0000 | [diff] [blame] | 376 | bool mustCreateBoxesToRoot = startNewSegment && !(parentBox && parentBox->isRootInlineBox()); |
| 377 | bool canUseExistingParentBox = parentBox && !parentIsConstructedOrHaveNext(parentBox) && !mustCreateBoxesToRoot; |
hyatt@apple.com | a61b8a3 | 2011-04-06 18:20:52 +0000 | [diff] [blame] | 378 | if (allowedToConstructNewBox && !canUseExistingParentBox) { |
hyatt | 1d5d87b | 2007-04-24 04:55:54 +0000 | [diff] [blame] | 379 | // We need to make a new box for this render object. Once |
| 380 | // made, we need to place it at the end of the current line. |
hyatt@apple.com | c92b735 | 2009-02-12 01:35:08 +0000 | [diff] [blame] | 381 | InlineBox* newBox = createInlineBoxForRenderer(obj, obj == this); |
inferno@chromium.org | 14b0414 | 2013-02-04 18:43:03 +0000 | [diff] [blame] | 382 | ASSERT_WITH_SECURITY_IMPLICATION(newBox->isInlineFlowBox()); |
jchaffraix@webkit.org | 8f1781d | 2011-06-24 21:22:54 +0000 | [diff] [blame] | 383 | parentBox = toInlineFlowBox(newBox); |
antti@apple.com | b0608f6 | 2013-09-28 18:30:16 +0000 | [diff] [blame] | 384 | parentBox->setIsFirstLine(lineInfo.isFirstLine()); |
hyatt@apple.com | 2a5eb21 | 2011-03-22 23:21:54 +0000 | [diff] [blame] | 385 | parentBox->setIsHorizontal(isHorizontalWritingMode()); |
hyatt@apple.com | 7d4066a | 2011-03-29 17:56:09 +0000 | [diff] [blame] | 386 | if (!hasDefaultLineBoxContain) |
| 387 | parentBox->clearDescendantsHaveSameLineHeightAndBaseline(); |
hyatt | 1d5d87b | 2007-04-24 04:55:54 +0000 | [diff] [blame] | 388 | constructedNewBox = true; |
| 389 | } |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 390 | |
hyatt@apple.com | a61b8a3 | 2011-04-06 18:20:52 +0000 | [diff] [blame] | 391 | if (constructedNewBox || canUseExistingParentBox) { |
| 392 | if (!result) |
| 393 | result = parentBox; |
hyatt | 1d5d87b | 2007-04-24 04:55:54 +0000 | [diff] [blame] | 394 | |
hyatt@apple.com | a61b8a3 | 2011-04-06 18:20:52 +0000 | [diff] [blame] | 395 | // If we have hit the block itself, then |box| represents the root |
| 396 | // inline box for the line, and it doesn't have to be appended to any parent |
| 397 | // inline. |
| 398 | if (childBox) |
| 399 | parentBox->addToLine(childBox); |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 400 | |
hyatt@apple.com | a61b8a3 | 2011-04-06 18:20:52 +0000 | [diff] [blame] | 401 | if (!constructedNewBox || obj == this) |
| 402 | break; |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 403 | |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 404 | childBox = parentBox; |
hyatt@apple.com | a61b8a3 | 2011-04-06 18:20:52 +0000 | [diff] [blame] | 405 | } |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 406 | |
hyatt | 1d5d87b | 2007-04-24 04:55:54 +0000 | [diff] [blame] | 407 | // If we've exceeded our line depth, then jump straight to the root and skip all the remaining |
| 408 | // intermediate inline flows. |
| 409 | obj = (++lineDepth >= cMaxLineDepth) ? this : obj->parent(); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 410 | |
hyatt | 1d5d87b | 2007-04-24 04:55:54 +0000 | [diff] [blame] | 411 | } while (true); |
| 412 | |
| 413 | return result; |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 414 | } |
| 415 | |
msaboff@apple.com | 776c286c7 | 2012-10-15 16:56:29 +0000 | [diff] [blame] | 416 | template <typename CharacterType> |
| 417 | static inline bool endsWithASCIISpaces(const CharacterType* characters, unsigned pos, unsigned end) |
| 418 | { |
| 419 | while (isASCIISpace(characters[pos])) { |
| 420 | pos++; |
| 421 | if (pos >= end) |
| 422 | return true; |
| 423 | } |
| 424 | return false; |
| 425 | } |
| 426 | |
yael.aharon@nokia.com | 15c605d | 2011-04-14 05:35:54 +0000 | [diff] [blame] | 427 | static bool reachedEndOfTextRenderer(const BidiRunList<BidiRun>& bidiRuns) |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 428 | { |
yael.aharon@nokia.com | 15c605d | 2011-04-14 05:35:54 +0000 | [diff] [blame] | 429 | BidiRun* run = bidiRuns.logicallyLastRun(); |
| 430 | if (!run) |
| 431 | return true; |
msaboff@apple.com | 776c286c7 | 2012-10-15 16:56:29 +0000 | [diff] [blame] | 432 | unsigned pos = run->stop(); |
yael.aharon@nokia.com | 15c605d | 2011-04-14 05:35:54 +0000 | [diff] [blame] | 433 | RenderObject* r = run->m_object; |
antti@apple.com | 9d8157e | 2013-09-17 15:13:37 +0000 | [diff] [blame] | 434 | if (!r->isText()) |
yael.aharon@nokia.com | 15c605d | 2011-04-14 05:35:54 +0000 | [diff] [blame] | 435 | return false; |
| 436 | RenderText* renderText = toRenderText(r); |
msaboff@apple.com | 776c286c7 | 2012-10-15 16:56:29 +0000 | [diff] [blame] | 437 | unsigned length = renderText->textLength(); |
| 438 | if (pos >= length) |
yael.aharon@nokia.com | 15c605d | 2011-04-14 05:35:54 +0000 | [diff] [blame] | 439 | return true; |
| 440 | |
msaboff@apple.com | 776c286c7 | 2012-10-15 16:56:29 +0000 | [diff] [blame] | 441 | if (renderText->is8Bit()) |
| 442 | return endsWithASCIISpaces(renderText->characters8(), pos, length); |
| 443 | return endsWithASCIISpaces(renderText->characters16(), pos, length); |
yael.aharon@nokia.com | 15c605d | 2011-04-14 05:35:54 +0000 | [diff] [blame] | 444 | } |
| 445 | |
leviw@chromium.org | f009c8e | 2011-05-03 20:49:15 +0000 | [diff] [blame] | 446 | RootInlineBox* RenderBlock::constructLine(BidiRunList<BidiRun>& bidiRuns, const LineInfo& lineInfo) |
yael.aharon@nokia.com | 15c605d | 2011-04-14 05:35:54 +0000 | [diff] [blame] | 447 | { |
| 448 | ASSERT(bidiRuns.firstRun()); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 449 | |
inferno@chromium.org | e29694f | 2010-10-07 22:00:02 +0000 | [diff] [blame] | 450 | bool rootHasSelectedChildren = false; |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 451 | InlineFlowBox* parentBox = 0; |
robert@webkit.org | 8cbab14 | 2011-12-30 20:58:29 +0000 | [diff] [blame] | 452 | int runCount = bidiRuns.runCount() - lineInfo.runsFromLeadingWhitespace(); |
yael.aharon@nokia.com | 15c605d | 2011-04-14 05:35:54 +0000 | [diff] [blame] | 453 | for (BidiRun* r = bidiRuns.firstRun(); r; r = r->next()) { |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 454 | // Create a box for our object. |
robert@webkit.org | 8cbab14 | 2011-12-30 20:58:29 +0000 | [diff] [blame] | 455 | bool isOnlyRun = (runCount == 1); |
| 456 | if (runCount == 2 && !r->m_object->isListMarker()) |
yael.aharon@nokia.com | 15c605d | 2011-04-14 05:35:54 +0000 | [diff] [blame] | 457 | isOnlyRun = (!style()->isLeftToRightDirection() ? bidiRuns.lastRun() : bidiRuns.firstRun())->m_object->isListMarker(); |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 458 | |
robert@webkit.org | 56e5a9f | 2012-02-17 21:10:42 +0000 | [diff] [blame] | 459 | if (lineInfo.isEmpty()) |
| 460 | continue; |
| 461 | |
hyatt@apple.com | c92b735 | 2009-02-12 01:35:08 +0000 | [diff] [blame] | 462 | InlineBox* box = createInlineBoxForRenderer(r->m_object, false, isOnlyRun); |
mitz@apple.com | 576e84e | 2008-04-24 19:09:48 +0000 | [diff] [blame] | 463 | r->m_box = box; |
| 464 | |
mitz@apple.com | aa6ce3d | 2009-04-10 01:00:20 +0000 | [diff] [blame] | 465 | ASSERT(box); |
| 466 | if (!box) |
| 467 | continue; |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 468 | |
akling@apple.com | 0b8172b7 | 2013-08-31 18:34:23 +0000 | [diff] [blame] | 469 | if (!rootHasSelectedChildren && box->renderer().selectionState() != RenderObject::SelectionNone) |
inferno@chromium.org | e29694f | 2010-10-07 22:00:02 +0000 | [diff] [blame] | 470 | rootHasSelectedChildren = true; |
| 471 | |
mitz@apple.com | aa6ce3d | 2009-04-10 01:00:20 +0000 | [diff] [blame] | 472 | // If we have no parent box yet, or if the run is not simply a sibling, |
| 473 | // then we need to construct inline boxes as necessary to properly enclose the |
commit-queue@webkit.org | ccad924 | 2012-12-05 20:17:30 +0000 | [diff] [blame] | 474 | // run's inline box. Segments can only be siblings at the root level, as |
| 475 | // they are positioned separately. |
betravis@adobe.com | ed90c98 | 2013-06-05 23:05:57 +0000 | [diff] [blame] | 476 | #if ENABLE(CSS_SHAPES) |
commit-queue@webkit.org | ccad924 | 2012-12-05 20:17:30 +0000 | [diff] [blame] | 477 | bool runStartsSegment = r->m_startsSegment; |
| 478 | #else |
| 479 | bool runStartsSegment = false; |
| 480 | #endif |
akling@apple.com | 0b8172b7 | 2013-08-31 18:34:23 +0000 | [diff] [blame] | 481 | if (!parentBox || &parentBox->renderer() != r->m_object->parent() || runStartsSegment) |
mitz@apple.com | aa6ce3d | 2009-04-10 01:00:20 +0000 | [diff] [blame] | 482 | // Create new inline boxes all the way back to the appropriate insertion point. |
commit-queue@webkit.org | ccad924 | 2012-12-05 20:17:30 +0000 | [diff] [blame] | 483 | parentBox = createLineBoxes(r->m_object->parent(), lineInfo, box, runStartsSegment); |
hyatt@apple.com | 7d4066a | 2011-03-29 17:56:09 +0000 | [diff] [blame] | 484 | else { |
| 485 | // Append the inline box to this line. |
| 486 | parentBox->addToLine(box); |
| 487 | } |
mitz@apple.com | 576e84e | 2008-04-24 19:09:48 +0000 | [diff] [blame] | 488 | |
macpherson@chromium.org | 258babf | 2011-06-10 06:20:58 +0000 | [diff] [blame] | 489 | bool visuallyOrdered = r->m_object->style()->rtlOrdering() == VisualOrder; |
xji@chromium.org | 6b0c017 | 2011-02-14 19:21:12 +0000 | [diff] [blame] | 490 | box->setBidiLevel(r->level()); |
mitz@apple.com | aa6ce3d | 2009-04-10 01:00:20 +0000 | [diff] [blame] | 491 | |
| 492 | if (box->isInlineTextBox()) { |
jchaffraix@webkit.org | 8f1781d | 2011-06-24 21:22:54 +0000 | [diff] [blame] | 493 | InlineTextBox* text = toInlineTextBox(box); |
mitz@apple.com | aa6ce3d | 2009-04-10 01:00:20 +0000 | [diff] [blame] | 494 | text->setStart(r->m_start); |
| 495 | text->setLen(r->m_stop - r->m_start); |
rniwa@webkit.org | 296fcae | 2012-03-29 09:48:42 +0000 | [diff] [blame] | 496 | text->setDirOverride(r->dirOverride(visuallyOrdered)); |
mitz@apple.com | b210765 | 2010-06-21 16:54:52 +0000 | [diff] [blame] | 497 | if (r->m_hasHyphen) |
| 498 | text->setHasHyphen(true); |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 499 | } |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | // We should have a root inline box. It should be unconstructed and |
| 503 | // be the last continuation of our line list. |
ggaren | f9f32ae | 2007-03-26 20:08:53 +0000 | [diff] [blame] | 504 | ASSERT(lastLineBox() && !lastLineBox()->isConstructed()); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 505 | |
inferno@chromium.org | e29694f | 2010-10-07 22:00:02 +0000 | [diff] [blame] | 506 | // Set the m_selectedChildren flag on the root inline box if one of the leaf inline box |
| 507 | // from the bidi runs walk above has a selection state. |
| 508 | if (rootHasSelectedChildren) |
akling@apple.com | dbf7030 | 2013-09-09 02:11:06 +0000 | [diff] [blame] | 509 | lastLineBox()->root().setHasSelectedChildren(true); |
inferno@chromium.org | e29694f | 2010-10-07 22:00:02 +0000 | [diff] [blame] | 510 | |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 511 | // Set bits on our inline flow boxes that indicate which sides should |
| 512 | // paint borders/margins/padding. This knowledge will ultimately be used when |
| 513 | // we determine the horizontal positions and widths of all the inline boxes on |
| 514 | // the line. |
yael.aharon@nokia.com | 15c605d | 2011-04-14 05:35:54 +0000 | [diff] [blame] | 515 | bool isLogicallyLastRunWrapped = bidiRuns.logicallyLastRun()->m_object && bidiRuns.logicallyLastRun()->m_object->isText() ? !reachedEndOfTextRenderer(bidiRuns) : true; |
leviw@chromium.org | f009c8e | 2011-05-03 20:49:15 +0000 | [diff] [blame] | 516 | lastLineBox()->determineSpacingForFlowBoxes(lineInfo.isLastLine(), isLogicallyLastRunWrapped, bidiRuns.logicallyLastRun()->m_object); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 517 | |
| 518 | // Now mark the line boxes as being constructed. |
| 519 | lastLineBox()->setConstructed(); |
| 520 | |
| 521 | // Return the last line. |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 522 | return lastRootBox(); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 523 | } |
| 524 | |
mitz@apple.com | 390fa32 | 2011-02-24 23:07:06 +0000 | [diff] [blame] | 525 | ETextAlign RenderBlock::textAlignmentForLine(bool endsWithSoftBreak) const |
| 526 | { |
| 527 | ETextAlign alignment = style()->textAlign(); |
| 528 | if (!endsWithSoftBreak && alignment == JUSTIFY) |
rniwa@webkit.org | af7f7a4 | 2012-06-15 21:54:44 +0000 | [diff] [blame] | 529 | alignment = TASTART; |
mitz@apple.com | 390fa32 | 2011-02-24 23:07:06 +0000 | [diff] [blame] | 530 | |
| 531 | return alignment; |
| 532 | } |
| 533 | |
rniwa@webkit.org | cda6dbd | 2011-03-28 09:19:50 +0000 | [diff] [blame] | 534 | static void updateLogicalWidthForLeftAlignedBlock(bool isLeftToRightDirection, BidiRun* trailingSpaceRun, float& logicalLeft, float& totalLogicalWidth, float availableLogicalWidth) |
| 535 | { |
| 536 | // The direction of the block should determine what happens with wide lines. |
| 537 | // In particular with RTL blocks, wide lines should still spill out to the left. |
| 538 | if (isLeftToRightDirection) { |
| 539 | if (totalLogicalWidth > availableLogicalWidth && trailingSpaceRun) |
| 540 | trailingSpaceRun->m_box->setLogicalWidth(max<float>(0, trailingSpaceRun->m_box->logicalWidth() - totalLogicalWidth + availableLogicalWidth)); |
| 541 | return; |
| 542 | } |
| 543 | |
| 544 | if (trailingSpaceRun) |
| 545 | trailingSpaceRun->m_box->setLogicalWidth(0); |
| 546 | else if (totalLogicalWidth > availableLogicalWidth) |
| 547 | logicalLeft -= (totalLogicalWidth - availableLogicalWidth); |
| 548 | } |
| 549 | |
| 550 | static void updateLogicalWidthForRightAlignedBlock(bool isLeftToRightDirection, BidiRun* trailingSpaceRun, float& logicalLeft, float& totalLogicalWidth, float availableLogicalWidth) |
| 551 | { |
| 552 | // Wide lines spill out of the block based off direction. |
| 553 | // So even if text-align is right, if direction is LTR, wide lines should overflow out of the right |
| 554 | // side of the block. |
| 555 | if (isLeftToRightDirection) { |
| 556 | if (trailingSpaceRun) { |
| 557 | totalLogicalWidth -= trailingSpaceRun->m_box->logicalWidth(); |
| 558 | trailingSpaceRun->m_box->setLogicalWidth(0); |
| 559 | } |
| 560 | if (totalLogicalWidth < availableLogicalWidth) |
| 561 | logicalLeft += availableLogicalWidth - totalLogicalWidth; |
| 562 | return; |
| 563 | } |
| 564 | |
| 565 | if (totalLogicalWidth > availableLogicalWidth && trailingSpaceRun) { |
| 566 | trailingSpaceRun->m_box->setLogicalWidth(max<float>(0, trailingSpaceRun->m_box->logicalWidth() - totalLogicalWidth + availableLogicalWidth)); |
| 567 | totalLogicalWidth -= trailingSpaceRun->m_box->logicalWidth(); |
| 568 | } else |
| 569 | logicalLeft += availableLogicalWidth - totalLogicalWidth; |
| 570 | } |
| 571 | |
| 572 | static void updateLogicalWidthForCenterAlignedBlock(bool isLeftToRightDirection, BidiRun* trailingSpaceRun, float& logicalLeft, float& totalLogicalWidth, float availableLogicalWidth) |
| 573 | { |
| 574 | float trailingSpaceWidth = 0; |
| 575 | if (trailingSpaceRun) { |
| 576 | totalLogicalWidth -= trailingSpaceRun->m_box->logicalWidth(); |
| 577 | trailingSpaceWidth = min(trailingSpaceRun->m_box->logicalWidth(), (availableLogicalWidth - totalLogicalWidth + 1) / 2); |
| 578 | trailingSpaceRun->m_box->setLogicalWidth(max<float>(0, trailingSpaceWidth)); |
| 579 | } |
| 580 | if (isLeftToRightDirection) |
| 581 | logicalLeft += max<float>((availableLogicalWidth - totalLogicalWidth) / 2, 0); |
| 582 | else |
| 583 | logicalLeft += totalLogicalWidth > availableLogicalWidth ? (availableLogicalWidth - totalLogicalWidth) : (availableLogicalWidth - totalLogicalWidth) / 2 - trailingSpaceWidth; |
| 584 | } |
| 585 | |
leviw@chromium.org | d70a007 | 2011-05-03 23:28:11 +0000 | [diff] [blame] | 586 | void RenderBlock::setMarginsForRubyRun(BidiRun* run, RenderRubyRun* renderer, RenderObject* previousObject, const LineInfo& lineInfo) |
| 587 | { |
| 588 | int startOverhang; |
| 589 | int endOverhang; |
| 590 | RenderObject* nextObject = 0; |
| 591 | for (BidiRun* runWithNextObject = run->next(); runWithNextObject; runWithNextObject = runWithNextObject->next()) { |
simon.fraser@apple.com | 2f07185 | 2012-06-25 00:11:30 +0000 | [diff] [blame] | 592 | if (!runWithNextObject->m_object->isOutOfFlowPositioned() && !runWithNextObject->m_box->isLineBreak()) { |
leviw@chromium.org | d70a007 | 2011-05-03 23:28:11 +0000 | [diff] [blame] | 593 | nextObject = runWithNextObject->m_object; |
| 594 | break; |
| 595 | } |
| 596 | } |
| 597 | renderer->getOverhang(lineInfo.isFirstLine(), renderer->style()->isLeftToRightDirection() ? previousObject : nextObject, renderer->style()->isLeftToRightDirection() ? nextObject : previousObject, startOverhang, endOverhang); |
| 598 | setMarginStartForChild(renderer, -startOverhang); |
| 599 | setMarginEndForChild(renderer, -endOverhang); |
| 600 | } |
| 601 | |
rniwa@webkit.org | fe811f2 | 2013-06-07 17:59:01 +0000 | [diff] [blame] | 602 | static inline float measureHyphenWidth(RenderText* renderer, const Font& font, HashSet<const SimpleFontData*>* fallbackFonts = 0) |
commit-queue@webkit.org | e60bb90 | 2011-09-08 19:18:43 +0000 | [diff] [blame] | 603 | { |
antti@apple.com | 78e5677 | 2013-09-29 04:34:37 +0000 | [diff] [blame] | 604 | const RenderStyle& style = *renderer->style(); |
| 605 | return font.width(RenderBlock::constructTextRun(renderer, font, style.hyphenString().string(), style), fallbackFonts); |
commit-queue@webkit.org | e60bb90 | 2011-09-08 19:18:43 +0000 | [diff] [blame] | 606 | } |
| 607 | |
enrica@apple.com | 885c84d | 2012-10-10 05:48:51 +0000 | [diff] [blame] | 608 | class WordMeasurement { |
| 609 | public: |
| 610 | WordMeasurement() |
| 611 | : renderer(0) |
| 612 | , width(0) |
| 613 | , startOffset(0) |
| 614 | , endOffset(0) |
| 615 | { |
| 616 | } |
| 617 | |
| 618 | RenderText* renderer; |
| 619 | float width; |
| 620 | int startOffset; |
| 621 | int endOffset; |
| 622 | HashSet<const SimpleFontData*> fallbackFonts; |
| 623 | }; |
| 624 | |
antti@apple.com | 3ab7ef3 | 2013-09-29 20:50:01 +0000 | [diff] [blame] | 625 | static inline const RenderStyle& lineStyle(const RenderElement& renderer, const LineInfo& lineInfo) |
antti@apple.com | b0608f6 | 2013-09-28 18:30:16 +0000 | [diff] [blame] | 626 | { |
| 627 | return lineInfo.isFirstLine() ? *renderer.firstLineStyle() : *renderer.style(); |
| 628 | } |
| 629 | |
leviw@chromium.org | d70a007 | 2011-05-03 23:28:11 +0000 | [diff] [blame] | 630 | static inline void setLogicalWidthForTextRun(RootInlineBox* lineBox, BidiRun* run, RenderText* renderer, float xPos, const LineInfo& lineInfo, |
rniwa@webkit.org | fe811f2 | 2013-06-07 17:59:01 +0000 | [diff] [blame] | 631 | GlyphOverflowAndFallbackFontsMap& textBoxDataMap, VerticalPositionCache& verticalPositionCache, WordMeasurements& wordMeasurements) |
leviw@chromium.org | d70a007 | 2011-05-03 23:28:11 +0000 | [diff] [blame] | 632 | { |
| 633 | HashSet<const SimpleFontData*> fallbackFonts; |
| 634 | GlyphOverflow glyphOverflow; |
antti@apple.com | b0608f6 | 2013-09-28 18:30:16 +0000 | [diff] [blame] | 635 | |
| 636 | const Font& font = lineStyle(*renderer->parent(), lineInfo).font(); |
leviw@chromium.org | d70a007 | 2011-05-03 23:28:11 +0000 | [diff] [blame] | 637 | // Always compute glyph overflow if the block's line-box-contain value is "glyphs". |
| 638 | if (lineBox->fitsToGlyphs()) { |
| 639 | // If we don't stick out of the root line's font box, then don't bother computing our glyph overflow. This optimization |
| 640 | // will keep us from computing glyph bounds in nearly all cases. |
| 641 | bool includeRootLine = lineBox->includesRootLineBoxFontOrLeading(); |
| 642 | int baselineShift = lineBox->verticalPositionForBox(run->m_box, verticalPositionCache); |
enrica@apple.com | 885c84d | 2012-10-10 05:48:51 +0000 | [diff] [blame] | 643 | int rootDescent = includeRootLine ? font.fontMetrics().descent() : 0; |
| 644 | int rootAscent = includeRootLine ? font.fontMetrics().ascent() : 0; |
| 645 | int boxAscent = font.fontMetrics().ascent() - baselineShift; |
| 646 | int boxDescent = font.fontMetrics().descent() + baselineShift; |
leviw@chromium.org | d70a007 | 2011-05-03 23:28:11 +0000 | [diff] [blame] | 647 | if (boxAscent > rootDescent || boxDescent > rootAscent) |
| 648 | glyphOverflow.computeBounds = true; |
| 649 | } |
| 650 | |
leviw@chromium.org | d32486e | 2012-03-16 10:52:56 +0000 | [diff] [blame] | 651 | LayoutUnit hyphenWidth = 0; |
antti@apple.com | b0608f6 | 2013-09-28 18:30:16 +0000 | [diff] [blame] | 652 | if (toInlineTextBox(run->m_box)->hasHyphen()) |
rniwa@webkit.org | fe811f2 | 2013-06-07 17:59:01 +0000 | [diff] [blame] | 653 | hyphenWidth = measureHyphenWidth(renderer, font, &fallbackFonts); |
antti@apple.com | b0608f6 | 2013-09-28 18:30:16 +0000 | [diff] [blame] | 654 | |
enrica@apple.com | 885c84d | 2012-10-10 05:48:51 +0000 | [diff] [blame] | 655 | float measuredWidth = 0; |
| 656 | |
enrica@apple.com | 885c84d | 2012-10-10 05:48:51 +0000 | [diff] [blame] | 657 | bool kerningIsEnabled = font.typesettingFeatures() & Kerning; |
leviw@chromium.org | d70f4cc | 2013-03-28 21:03:44 +0000 | [diff] [blame] | 658 | bool canUseSimpleFontCodePath = renderer->canUseSimpleFontCodePath(); |
enrica@apple.com | 885c84d | 2012-10-10 05:48:51 +0000 | [diff] [blame] | 659 | |
| 660 | // Since we don't cache glyph overflows, we need to re-measure the run if |
| 661 | // the style is linebox-contain: glyph. |
| 662 | |
leviw@chromium.org | d70f4cc | 2013-03-28 21:03:44 +0000 | [diff] [blame] | 663 | if (!lineBox->fitsToGlyphs() && canUseSimpleFontCodePath) { |
enrica@apple.com | 885c84d | 2012-10-10 05:48:51 +0000 | [diff] [blame] | 664 | int lastEndOffset = run->m_start; |
| 665 | for (size_t i = 0, size = wordMeasurements.size(); i < size && lastEndOffset < run->m_stop; ++i) { |
rniwa@webkit.org | fe811f2 | 2013-06-07 17:59:01 +0000 | [diff] [blame] | 666 | WordMeasurement& wordMeasurement = wordMeasurements[i]; |
| 667 | if (wordMeasurement.width <= 0 || wordMeasurement.startOffset == wordMeasurement.endOffset) |
enrica@apple.com | 885c84d | 2012-10-10 05:48:51 +0000 | [diff] [blame] | 668 | continue; |
| 669 | if (wordMeasurement.renderer != renderer || wordMeasurement.startOffset != lastEndOffset || wordMeasurement.endOffset > run->m_stop) |
| 670 | continue; |
| 671 | |
| 672 | lastEndOffset = wordMeasurement.endOffset; |
| 673 | if (kerningIsEnabled && lastEndOffset == run->m_stop) { |
dino@apple.com | 7c50e7c | 2013-03-18 18:01:05 +0000 | [diff] [blame] | 674 | int wordLength = lastEndOffset - wordMeasurement.startOffset; |
rniwa@webkit.org | fe811f2 | 2013-06-07 17:59:01 +0000 | [diff] [blame] | 675 | GlyphOverflow overflow; |
| 676 | measuredWidth += renderer->width(wordMeasurement.startOffset, wordLength, xPos + measuredWidth, lineInfo.isFirstLine(), |
| 677 | &wordMeasurement.fallbackFonts, &overflow); |
dino@apple.com | d0b8925 | 2013-05-10 18:20:28 +0000 | [diff] [blame] | 678 | UChar c = renderer->characterAt(wordMeasurement.startOffset); |
| 679 | if (i > 0 && wordLength == 1 && (c == ' ' || c == '\t')) |
enrica@apple.com | 885c84d | 2012-10-10 05:48:51 +0000 | [diff] [blame] | 680 | measuredWidth += renderer->style()->wordSpacing(); |
| 681 | } else |
| 682 | measuredWidth += wordMeasurement.width; |
| 683 | if (!wordMeasurement.fallbackFonts.isEmpty()) { |
| 684 | HashSet<const SimpleFontData*>::const_iterator end = wordMeasurement.fallbackFonts.end(); |
| 685 | for (HashSet<const SimpleFontData*>::const_iterator it = wordMeasurement.fallbackFonts.begin(); it != end; ++it) |
| 686 | fallbackFonts.add(*it); |
| 687 | } |
| 688 | } |
| 689 | if (measuredWidth && lastEndOffset != run->m_stop) { |
| 690 | // If we don't have enough cached data, we'll measure the run again. |
| 691 | measuredWidth = 0; |
| 692 | fallbackFonts.clear(); |
| 693 | } |
| 694 | } |
enrica@apple.com | 885c84d | 2012-10-10 05:48:51 +0000 | [diff] [blame] | 695 | |
| 696 | if (!measuredWidth) |
| 697 | measuredWidth = renderer->width(run->m_start, run->m_stop - run->m_start, xPos, lineInfo.isFirstLine(), &fallbackFonts, &glyphOverflow); |
| 698 | |
| 699 | run->m_box->setLogicalWidth(measuredWidth + hyphenWidth); |
leviw@chromium.org | d70a007 | 2011-05-03 23:28:11 +0000 | [diff] [blame] | 700 | if (!fallbackFonts.isEmpty()) { |
antti@apple.com | 843ff0c | 2013-09-18 06:30:30 +0000 | [diff] [blame] | 701 | ASSERT(run->m_box->behavesLikeText()); |
caio.oliveira@openbossa.org | 4c11ee0 | 2012-03-29 18:48:23 +0000 | [diff] [blame] | 702 | GlyphOverflowAndFallbackFontsMap::iterator it = textBoxDataMap.add(toInlineTextBox(run->m_box), make_pair(Vector<const SimpleFontData*>(), GlyphOverflow())).iterator; |
benjamin@webkit.org | ee55405 | 2012-10-07 23:12:07 +0000 | [diff] [blame] | 703 | ASSERT(it->value.first.isEmpty()); |
| 704 | copyToVector(fallbackFonts, it->value.first); |
leviw@chromium.org | d70a007 | 2011-05-03 23:28:11 +0000 | [diff] [blame] | 705 | run->m_box->parent()->clearDescendantsHaveSameLineHeightAndBaseline(); |
| 706 | } |
| 707 | if ((glyphOverflow.top || glyphOverflow.bottom || glyphOverflow.left || glyphOverflow.right)) { |
antti@apple.com | 843ff0c | 2013-09-18 06:30:30 +0000 | [diff] [blame] | 708 | ASSERT(run->m_box->behavesLikeText()); |
caio.oliveira@openbossa.org | 4c11ee0 | 2012-03-29 18:48:23 +0000 | [diff] [blame] | 709 | GlyphOverflowAndFallbackFontsMap::iterator it = textBoxDataMap.add(toInlineTextBox(run->m_box), make_pair(Vector<const SimpleFontData*>(), GlyphOverflow())).iterator; |
benjamin@webkit.org | ee55405 | 2012-10-07 23:12:07 +0000 | [diff] [blame] | 710 | it->value.second = glyphOverflow; |
leviw@chromium.org | d70a007 | 2011-05-03 23:28:11 +0000 | [diff] [blame] | 711 | run->m_box->clearKnownToHaveNoOverflow(); |
| 712 | } |
| 713 | } |
| 714 | |
| 715 | static inline void computeExpansionForJustifiedText(BidiRun* firstRun, BidiRun* trailingSpaceRun, Vector<unsigned, 16>& expansionOpportunities, unsigned expansionOpportunityCount, float& totalLogicalWidth, float availableLogicalWidth) |
| 716 | { |
mitz@apple.com | c7a1a51 | 2011-05-08 16:27:31 +0000 | [diff] [blame] | 717 | if (!expansionOpportunityCount || availableLogicalWidth <= totalLogicalWidth) |
| 718 | return; |
| 719 | |
| 720 | size_t i = 0; |
| 721 | for (BidiRun* r = firstRun; r; r = r->next()) { |
betravis@adobe.com | ed90c98 | 2013-06-05 23:05:57 +0000 | [diff] [blame] | 722 | #if ENABLE(CSS_SHAPES) |
commit-queue@webkit.org | ccad924 | 2012-12-05 20:17:30 +0000 | [diff] [blame] | 723 | // This method is called once per segment, do not move past the current segment. |
| 724 | if (r->m_startsSegment) |
| 725 | break; |
| 726 | #endif |
mitz@apple.com | c7a1a51 | 2011-05-08 16:27:31 +0000 | [diff] [blame] | 727 | if (!r->m_box || r == trailingSpaceRun) |
| 728 | continue; |
| 729 | |
| 730 | if (r->m_object->isText()) { |
| 731 | unsigned opportunitiesInRun = expansionOpportunities[i++]; |
leviw@chromium.org | d70a007 | 2011-05-03 23:28:11 +0000 | [diff] [blame] | 732 | |
mitz@apple.com | c7a1a51 | 2011-05-08 16:27:31 +0000 | [diff] [blame] | 733 | ASSERT(opportunitiesInRun <= expansionOpportunityCount); |
| 734 | |
| 735 | // Only justify text if whitespace is collapsed. |
| 736 | if (r->m_object->style()->collapseWhiteSpace()) { |
jchaffraix@webkit.org | 8f1781d | 2011-06-24 21:22:54 +0000 | [diff] [blame] | 737 | InlineTextBox* textBox = toInlineTextBox(r->m_box); |
mitz@apple.com | c7a1a51 | 2011-05-08 16:27:31 +0000 | [diff] [blame] | 738 | int expansion = (availableLogicalWidth - totalLogicalWidth) * opportunitiesInRun / expansionOpportunityCount; |
| 739 | textBox->setExpansion(expansion); |
| 740 | totalLogicalWidth += expansion; |
leviw@chromium.org | d70a007 | 2011-05-03 23:28:11 +0000 | [diff] [blame] | 741 | } |
mitz@apple.com | c7a1a51 | 2011-05-08 16:27:31 +0000 | [diff] [blame] | 742 | expansionOpportunityCount -= opportunitiesInRun; |
| 743 | if (!expansionOpportunityCount) |
| 744 | break; |
leviw@chromium.org | d70a007 | 2011-05-03 23:28:11 +0000 | [diff] [blame] | 745 | } |
| 746 | } |
| 747 | } |
| 748 | |
robert@webkit.org | fc7763c | 2011-09-03 18:28:57 +0000 | [diff] [blame] | 749 | void RenderBlock::updateLogicalWidthForAlignment(const ETextAlign& textAlign, BidiRun* trailingSpaceRun, float& logicalLeft, float& totalLogicalWidth, float& availableLogicalWidth, int expansionOpportunityCount) |
| 750 | { |
| 751 | // Armed with the total width of the line (without justification), |
| 752 | // we now examine our text-align property in order to determine where to position the |
| 753 | // objects horizontally. The total width of the line can be increased if we end up |
| 754 | // justifying text. |
| 755 | switch (textAlign) { |
| 756 | case LEFT: |
| 757 | case WEBKIT_LEFT: |
| 758 | updateLogicalWidthForLeftAlignedBlock(style()->isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth); |
| 759 | break; |
rniwa@webkit.org | af7f7a4 | 2012-06-15 21:54:44 +0000 | [diff] [blame] | 760 | case RIGHT: |
| 761 | case WEBKIT_RIGHT: |
| 762 | updateLogicalWidthForRightAlignedBlock(style()->isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth); |
| 763 | break; |
| 764 | case CENTER: |
| 765 | case WEBKIT_CENTER: |
| 766 | updateLogicalWidthForCenterAlignedBlock(style()->isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth); |
| 767 | break; |
robert@webkit.org | fc7763c | 2011-09-03 18:28:57 +0000 | [diff] [blame] | 768 | case JUSTIFY: |
| 769 | adjustInlineDirectionLineBounds(expansionOpportunityCount, logicalLeft, availableLogicalWidth); |
| 770 | if (expansionOpportunityCount) { |
| 771 | if (trailingSpaceRun) { |
| 772 | totalLogicalWidth -= trailingSpaceRun->m_box->logicalWidth(); |
| 773 | trailingSpaceRun->m_box->setLogicalWidth(0); |
| 774 | } |
| 775 | break; |
| 776 | } |
rniwa@webkit.org | af7f7a4 | 2012-06-15 21:54:44 +0000 | [diff] [blame] | 777 | // Fall through |
robert@webkit.org | fc7763c | 2011-09-03 18:28:57 +0000 | [diff] [blame] | 778 | case TASTART: |
| 779 | if (style()->isLeftToRightDirection()) |
| 780 | updateLogicalWidthForLeftAlignedBlock(style()->isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth); |
| 781 | else |
| 782 | updateLogicalWidthForRightAlignedBlock(style()->isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth); |
| 783 | break; |
| 784 | case TAEND: |
| 785 | if (style()->isLeftToRightDirection()) |
| 786 | updateLogicalWidthForRightAlignedBlock(style()->isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth); |
| 787 | else |
| 788 | updateLogicalWidthForLeftAlignedBlock(style()->isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth); |
| 789 | break; |
| 790 | } |
| 791 | } |
| 792 | |
antti@apple.com | 78e5677 | 2013-09-29 04:34:37 +0000 | [diff] [blame] | 793 | static IndentTextOrNot requiresIndent(bool isFirstLine, bool isAfterHardLineBreak, const RenderStyle& style) |
commit-queue@webkit.org | ab781b0 | 2013-04-03 01:32:24 +0000 | [diff] [blame] | 794 | { |
commit-queue@webkit.org | 1eb0787 | 2013-04-18 04:25:46 +0000 | [diff] [blame] | 795 | IndentTextOrNot shouldIndentText = DoNotIndentText; |
commit-queue@webkit.org | ab781b0 | 2013-04-03 01:32:24 +0000 | [diff] [blame] | 796 | if (isFirstLine) |
commit-queue@webkit.org | 1eb0787 | 2013-04-18 04:25:46 +0000 | [diff] [blame] | 797 | shouldIndentText = IndentText; |
commit-queue@webkit.org | ab781b0 | 2013-04-03 01:32:24 +0000 | [diff] [blame] | 798 | #if ENABLE(CSS3_TEXT) |
zandobersek@gmail.com | 8178731 | 2013-09-29 05:42:35 +0000 | [diff] [blame] | 799 | else if (isAfterHardLineBreak && style.textIndentLine() == TextIndentEachLine) |
commit-queue@webkit.org | 1eb0787 | 2013-04-18 04:25:46 +0000 | [diff] [blame] | 800 | shouldIndentText = IndentText; |
| 801 | |
zandobersek@gmail.com | 8178731 | 2013-09-29 05:42:35 +0000 | [diff] [blame] | 802 | if (style.textIndentType() == TextIndentHanging) |
commit-queue@webkit.org | 1eb0787 | 2013-04-18 04:25:46 +0000 | [diff] [blame] | 803 | shouldIndentText = shouldIndentText == IndentText ? DoNotIndentText : IndentText; |
commit-queue@webkit.org | ab781b0 | 2013-04-03 01:32:24 +0000 | [diff] [blame] | 804 | #else |
| 805 | UNUSED_PARAM(isAfterHardLineBreak); |
| 806 | UNUSED_PARAM(style); |
| 807 | #endif |
commit-queue@webkit.org | 1eb0787 | 2013-04-18 04:25:46 +0000 | [diff] [blame] | 808 | return shouldIndentText; |
commit-queue@webkit.org | ab781b0 | 2013-04-03 01:32:24 +0000 | [diff] [blame] | 809 | } |
| 810 | |
| 811 | static void updateLogicalInlinePositions(RenderBlock* block, float& lineLogicalLeft, float& lineLogicalRight, float& availableLogicalWidth, bool firstLine, IndentTextOrNot shouldIndentText, LayoutUnit boxLogicalHeight) |
robert@webkit.org | 0903cf5 | 2012-12-11 18:14:16 +0000 | [diff] [blame] | 812 | { |
zoltan@webkit.org | 68678b7 | 2013-09-20 20:53:44 +0000 | [diff] [blame] | 813 | LayoutUnit lineLogicalHeight = block->minLineHeightForReplacedRenderer(firstLine, boxLogicalHeight); |
commit-queue@webkit.org | ab781b0 | 2013-04-03 01:32:24 +0000 | [diff] [blame] | 814 | lineLogicalLeft = block->pixelSnappedLogicalLeftOffsetForLine(block->logicalHeight(), shouldIndentText == IndentText, lineLogicalHeight); |
| 815 | lineLogicalRight = block->pixelSnappedLogicalRightOffsetForLine(block->logicalHeight(), shouldIndentText == IndentText, lineLogicalHeight); |
robert@webkit.org | 0903cf5 | 2012-12-11 18:14:16 +0000 | [diff] [blame] | 816 | availableLogicalWidth = lineLogicalRight - lineLogicalLeft; |
| 817 | } |
| 818 | |
leviw@chromium.org | f009c8e | 2011-05-03 20:49:15 +0000 | [diff] [blame] | 819 | void RenderBlock::computeInlineDirectionPositionsForLine(RootInlineBox* lineBox, const LineInfo& lineInfo, BidiRun* firstRun, BidiRun* trailingSpaceRun, bool reachedEnd, |
enrica@apple.com | 885c84d | 2012-10-10 05:48:51 +0000 | [diff] [blame] | 820 | GlyphOverflowAndFallbackFontsMap& textBoxDataMap, VerticalPositionCache& verticalPositionCache, WordMeasurements& wordMeasurements) |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 821 | { |
mitz@apple.com | 390fa32 | 2011-02-24 23:07:06 +0000 | [diff] [blame] | 822 | ETextAlign textAlign = textAlignmentForLine(!reachedEnd && !lineBox->endsWithBreak()); |
robert@webkit.org | 4f76df9 | 2012-07-03 17:41:35 +0000 | [diff] [blame] | 823 | |
robert@webkit.org | 328ecd0 | 2012-08-09 21:12:44 +0000 | [diff] [blame] | 824 | // CSS 2.1: "'Text-indent' only affects a line if it is the first formatted line of an element. For example, the first line of an anonymous block |
| 825 | // box is only affected if it is the first child of its parent element." |
commit-queue@webkit.org | ab781b0 | 2013-04-03 01:32:24 +0000 | [diff] [blame] | 826 | // CSS3 "text-indent", "-webkit-each-line" affects the first line of the block container as well as each line after a forced line break, |
| 827 | // but does not affect lines after a soft wrap break. |
| 828 | bool isFirstLine = lineInfo.isFirstLine() && !(isAnonymousBlock() && parent()->firstChild() != this); |
| 829 | bool isAfterHardLineBreak = lineBox->prevRootBox() && lineBox->prevRootBox()->endsWithBreak(); |
antti@apple.com | 78e5677 | 2013-09-29 04:34:37 +0000 | [diff] [blame] | 830 | IndentTextOrNot shouldIndentText = requiresIndent(isFirstLine, isAfterHardLineBreak, *style()); |
robert@webkit.org | 0903cf5 | 2012-12-11 18:14:16 +0000 | [diff] [blame] | 831 | float lineLogicalLeft; |
| 832 | float lineLogicalRight; |
commit-queue@webkit.org | ccad924 | 2012-12-05 20:17:30 +0000 | [diff] [blame] | 833 | float availableLogicalWidth; |
commit-queue@webkit.org | ab781b0 | 2013-04-03 01:32:24 +0000 | [diff] [blame] | 834 | updateLogicalInlinePositions(this, lineLogicalLeft, lineLogicalRight, availableLogicalWidth, isFirstLine, shouldIndentText, 0); |
commit-queue@webkit.org | ccad924 | 2012-12-05 20:17:30 +0000 | [diff] [blame] | 835 | bool needsWordSpacing; |
betravis@adobe.com | ed90c98 | 2013-06-05 23:05:57 +0000 | [diff] [blame] | 836 | #if ENABLE(CSS_SHAPES) |
betravis@adobe.com | cf7cba6 | 2013-06-10 21:23:45 +0000 | [diff] [blame] | 837 | ShapeInsideInfo* shapeInsideInfo = layoutShapeInsideInfo(); |
| 838 | if (shapeInsideInfo && shapeInsideInfo->hasSegments()) { |
commit-queue@webkit.org | ccad924 | 2012-12-05 20:17:30 +0000 | [diff] [blame] | 839 | BidiRun* segmentStart = firstRun; |
betravis@adobe.com | cf7cba6 | 2013-06-10 21:23:45 +0000 | [diff] [blame] | 840 | const SegmentList& segments = shapeInsideInfo->segments(); |
commit-queue@webkit.org | ccad924 | 2012-12-05 20:17:30 +0000 | [diff] [blame] | 841 | float logicalLeft = max<float>(roundToInt(segments[0].logicalLeft), lineLogicalLeft); |
| 842 | float logicalRight = min<float>(floorToInt(segments[0].logicalRight), lineLogicalRight); |
| 843 | float startLogicalLeft = logicalLeft; |
| 844 | float endLogicalRight = logicalLeft; |
| 845 | float minLogicalLeft = logicalLeft; |
| 846 | float maxLogicalRight = logicalLeft; |
| 847 | lineBox->beginPlacingBoxRangesInInlineDirection(logicalLeft); |
| 848 | for (size_t i = 0; i < segments.size(); i++) { |
| 849 | if (i) { |
| 850 | logicalLeft = max<float>(roundToInt(segments[i].logicalLeft), lineLogicalLeft); |
| 851 | logicalRight = min<float>(floorToInt(segments[i].logicalRight), lineLogicalRight); |
| 852 | } |
| 853 | availableLogicalWidth = logicalRight - logicalLeft; |
| 854 | BidiRun* newSegmentStart = computeInlineDirectionPositionsForSegment(lineBox, lineInfo, textAlign, logicalLeft, availableLogicalWidth, segmentStart, trailingSpaceRun, textBoxDataMap, verticalPositionCache, wordMeasurements); |
| 855 | needsWordSpacing = false; |
| 856 | endLogicalRight = lineBox->placeBoxRangeInInlineDirection(segmentStart->m_box, newSegmentStart ? newSegmentStart->m_box : 0, logicalLeft, minLogicalLeft, maxLogicalRight, needsWordSpacing, textBoxDataMap); |
| 857 | if (!newSegmentStart || !newSegmentStart->next()) |
| 858 | break; |
| 859 | ASSERT(newSegmentStart->m_startsSegment); |
| 860 | // Discard the empty segment start marker bidi runs |
| 861 | segmentStart = newSegmentStart->next(); |
| 862 | } |
| 863 | lineBox->endPlacingBoxRangesInInlineDirection(startLogicalLeft, endLogicalRight, minLogicalLeft, maxLogicalRight); |
| 864 | return; |
commit-queue@webkit.org | b354051 | 2012-08-24 18:48:49 +0000 | [diff] [blame] | 865 | } |
| 866 | #endif |
robert@webkit.org | 0903cf5 | 2012-12-11 18:14:16 +0000 | [diff] [blame] | 867 | |
| 868 | if (firstRun && firstRun->m_object->isReplaced()) { |
| 869 | RenderBox* renderBox = toRenderBox(firstRun->m_object); |
commit-queue@webkit.org | ab781b0 | 2013-04-03 01:32:24 +0000 | [diff] [blame] | 870 | updateLogicalInlinePositions(this, lineLogicalLeft, lineLogicalRight, availableLogicalWidth, isFirstLine, shouldIndentText, renderBox->logicalHeight()); |
robert@webkit.org | 0903cf5 | 2012-12-11 18:14:16 +0000 | [diff] [blame] | 871 | } |
| 872 | |
| 873 | computeInlineDirectionPositionsForSegment(lineBox, lineInfo, textAlign, lineLogicalLeft, availableLogicalWidth, firstRun, trailingSpaceRun, textBoxDataMap, verticalPositionCache, wordMeasurements); |
commit-queue@webkit.org | ccad924 | 2012-12-05 20:17:30 +0000 | [diff] [blame] | 874 | // The widths of all runs are now known. We can now place every inline box (and |
| 875 | // compute accurate widths for the inline flow boxes). |
| 876 | needsWordSpacing = false; |
| 877 | lineBox->placeBoxesInInlineDirection(lineLogicalLeft, needsWordSpacing, textBoxDataMap); |
| 878 | } |
mitz@apple.com | 390fa32 | 2011-02-24 23:07:06 +0000 | [diff] [blame] | 879 | |
robert@webkit.org | 0903cf5 | 2012-12-11 18:14:16 +0000 | [diff] [blame] | 880 | BidiRun* RenderBlock::computeInlineDirectionPositionsForSegment(RootInlineBox* lineBox, const LineInfo& lineInfo, ETextAlign textAlign, float& logicalLeft, |
commit-queue@webkit.org | ccad924 | 2012-12-05 20:17:30 +0000 | [diff] [blame] | 881 | float& availableLogicalWidth, BidiRun* firstRun, BidiRun* trailingSpaceRun, GlyphOverflowAndFallbackFontsMap& textBoxDataMap, VerticalPositionCache& verticalPositionCache, |
| 882 | WordMeasurements& wordMeasurements) |
| 883 | { |
darin | 06dcb9c | 2005-08-15 04:31:09 +0000 | [diff] [blame] | 884 | bool needsWordSpacing = false; |
mitz@apple.com | 390fa32 | 2011-02-24 23:07:06 +0000 | [diff] [blame] | 885 | float totalLogicalWidth = lineBox->getFlowSpacingLogicalWidth(); |
mitz@apple.com | 86470c8 | 2011-01-27 01:39:27 +0000 | [diff] [blame] | 886 | unsigned expansionOpportunityCount = 0; |
| 887 | bool isAfterExpansion = true; |
| 888 | Vector<unsigned, 16> expansionOpportunities; |
mitz@apple.com | ddb5987 | 2011-04-05 05:21:16 +0000 | [diff] [blame] | 889 | RenderObject* previousObject = 0; |
mitz@apple.com | 815ef2f | 2008-02-25 17:11:56 +0000 | [diff] [blame] | 890 | |
commit-queue@webkit.org | ccad924 | 2012-12-05 20:17:30 +0000 | [diff] [blame] | 891 | BidiRun* r = firstRun; |
| 892 | for (; r; r = r->next()) { |
betravis@adobe.com | ed90c98 | 2013-06-05 23:05:57 +0000 | [diff] [blame] | 893 | #if ENABLE(CSS_SHAPES) |
commit-queue@webkit.org | ccad924 | 2012-12-05 20:17:30 +0000 | [diff] [blame] | 894 | // Once we have reached the start of the next segment, we have finished |
| 895 | // computing the positions for this segment's contents. |
| 896 | if (r->m_startsSegment) |
| 897 | break; |
| 898 | #endif |
simon.fraser@apple.com | 2f07185 | 2012-06-25 00:11:30 +0000 | [diff] [blame] | 899 | if (!r->m_box || r->m_object->isOutOfFlowPositioned() || r->m_box->isLineBreak()) |
hyatt | 98ee7e4 | 2003-05-14 01:39:15 +0000 | [diff] [blame] | 900 | continue; // Positioned objects are only participating to figure out their |
| 901 | // correct static x position. They have no effect on the width. |
hyatt | 0c05e10 | 2006-04-14 08:15:00 +0000 | [diff] [blame] | 902 | // Similarly, line break boxes have no effect on the width. |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 903 | if (r->m_object->isText()) { |
darin@apple.com | 36744d6 | 2009-01-25 20:23:04 +0000 | [diff] [blame] | 904 | RenderText* rt = toRenderText(r->m_object); |
mitz@apple.com | c13ea5f | 2008-04-18 21:18:26 +0000 | [diff] [blame] | 905 | if (textAlign == JUSTIFY && r != trailingSpaceRun) { |
mitz@apple.com | 8096893 | 2011-03-26 00:46:26 +0000 | [diff] [blame] | 906 | if (!isAfterExpansion) |
jchaffraix@webkit.org | 8f1781d | 2011-06-24 21:22:54 +0000 | [diff] [blame] | 907 | toInlineTextBox(r->m_box)->setCanHaveLeadingExpansion(true); |
msaboff@apple.com | 776c286c7 | 2012-10-15 16:56:29 +0000 | [diff] [blame] | 908 | unsigned opportunitiesInRun; |
| 909 | if (rt->is8Bit()) |
| 910 | opportunitiesInRun = Font::expansionOpportunityCount(rt->characters8() + r->m_start, r->m_stop - r->m_start, r->m_box->direction(), isAfterExpansion); |
| 911 | else |
| 912 | opportunitiesInRun = Font::expansionOpportunityCount(rt->characters16() + r->m_start, r->m_stop - r->m_start, r->m_box->direction(), isAfterExpansion); |
mitz@apple.com | 86470c8 | 2011-01-27 01:39:27 +0000 | [diff] [blame] | 913 | expansionOpportunities.append(opportunitiesInRun); |
| 914 | expansionOpportunityCount += opportunitiesInRun; |
mitz@apple.com | 815ef2f | 2008-02-25 17:11:56 +0000 | [diff] [blame] | 915 | } |
| 916 | |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 917 | if (int length = rt->textLength()) { |
msaboff@apple.com | 776c286c7 | 2012-10-15 16:56:29 +0000 | [diff] [blame] | 918 | if (!r->m_start && needsWordSpacing && isSpaceOrNewline(rt->characterAt(r->m_start))) |
antti@apple.com | b0608f6 | 2013-09-28 18:30:16 +0000 | [diff] [blame] | 919 | totalLogicalWidth += lineStyle(*rt->parent(), lineInfo).font().wordSpacing(); |
msaboff@apple.com | 776c286c7 | 2012-10-15 16:56:29 +0000 | [diff] [blame] | 920 | needsWordSpacing = !isSpaceOrNewline(rt->characterAt(r->m_stop - 1)) && r->m_stop == length; |
darin | 06dcb9c | 2005-08-15 04:31:09 +0000 | [diff] [blame] | 921 | } |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 922 | |
enrica@apple.com | 885c84d | 2012-10-10 05:48:51 +0000 | [diff] [blame] | 923 | setLogicalWidthForTextRun(lineBox, r, rt, totalLogicalWidth, lineInfo, textBoxDataMap, verticalPositionCache, wordMeasurements); |
mitz@apple.com | 86470c8 | 2011-01-27 01:39:27 +0000 | [diff] [blame] | 924 | } else { |
| 925 | isAfterExpansion = false; |
| 926 | if (!r->m_object->isRenderInline()) { |
| 927 | RenderBox* renderBox = toRenderBox(r->m_object); |
leviw@chromium.org | d70a007 | 2011-05-03 23:28:11 +0000 | [diff] [blame] | 928 | if (renderBox->isRubyRun()) |
| 929 | setMarginsForRubyRun(r, toRenderRubyRun(renderBox), previousObject, lineInfo); |
mitz@apple.com | 86470c8 | 2011-01-27 01:39:27 +0000 | [diff] [blame] | 930 | r->m_box->setLogicalWidth(logicalWidthForChild(renderBox)); |
| 931 | totalLogicalWidth += marginStartForChild(renderBox) + marginEndForChild(renderBox); |
| 932 | } |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 933 | } |
hyatt | 4b38169 | 2003-03-10 21:11:59 +0000 | [diff] [blame] | 934 | |
hyatt@apple.com | 546a248 | 2010-10-07 21:16:49 +0000 | [diff] [blame] | 935 | totalLogicalWidth += r->m_box->logicalWidth(); |
mitz@apple.com | ddb5987 | 2011-04-05 05:21:16 +0000 | [diff] [blame] | 936 | previousObject = r->m_object; |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 937 | } |
| 938 | |
mitz@apple.com | 86470c8 | 2011-01-27 01:39:27 +0000 | [diff] [blame] | 939 | if (isAfterExpansion && !expansionOpportunities.isEmpty()) { |
| 940 | expansionOpportunities.last()--; |
| 941 | expansionOpportunityCount--; |
| 942 | } |
| 943 | |
robert@webkit.org | fc7763c | 2011-09-03 18:28:57 +0000 | [diff] [blame] | 944 | updateLogicalWidthForAlignment(textAlign, trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth, expansionOpportunityCount); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 945 | |
leviw@chromium.org | d70a007 | 2011-05-03 23:28:11 +0000 | [diff] [blame] | 946 | computeExpansionForJustifiedText(firstRun, trailingSpaceRun, expansionOpportunities, expansionOpportunityCount, totalLogicalWidth, availableLogicalWidth); |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 947 | |
commit-queue@webkit.org | ccad924 | 2012-12-05 20:17:30 +0000 | [diff] [blame] | 948 | return r; |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 949 | } |
| 950 | |
hyatt@apple.com | 4a9c625a | 2010-11-17 20:55:40 +0000 | [diff] [blame] | 951 | void RenderBlock::computeBlockDirectionPositionsForLine(RootInlineBox* lineBox, BidiRun* firstRun, GlyphOverflowAndFallbackFontsMap& textBoxDataMap, |
| 952 | VerticalPositionCache& verticalPositionCache) |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 953 | { |
hyatt@apple.com | 4a9c625a | 2010-11-17 20:55:40 +0000 | [diff] [blame] | 954 | setLogicalHeight(lineBox->alignBoxesInBlockDirection(logicalHeight(), textBoxDataMap, verticalPositionCache)); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 955 | |
| 956 | // Now make sure we place replaced render objects correctly. |
mitz@apple.com | 887f359 | 2008-02-25 22:03:08 +0000 | [diff] [blame] | 957 | for (BidiRun* r = firstRun; r; r = r->next()) { |
mitz@apple.com | aa6ce3d | 2009-04-10 01:00:20 +0000 | [diff] [blame] | 958 | ASSERT(r->m_box); |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 959 | if (!r->m_box) |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 960 | continue; // Skip runs with no line boxes. |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 961 | |
hyatt | 98ee7e4 | 2003-05-14 01:39:15 +0000 | [diff] [blame] | 962 | // Align positioned boxes with the top of the line box. This is |
| 963 | // a reasonable approximation of an appropriate y position. |
simon.fraser@apple.com | 2f07185 | 2012-06-25 00:11:30 +0000 | [diff] [blame] | 964 | if (r->m_object->isOutOfFlowPositioned()) |
hyatt@apple.com | 35d2ad5 | 2010-10-20 18:17:36 +0000 | [diff] [blame] | 965 | r->m_box->setLogicalTop(logicalHeight()); |
hyatt | 98ee7e4 | 2003-05-14 01:39:15 +0000 | [diff] [blame] | 966 | |
| 967 | // Position is used to properly position both replaced elements and |
| 968 | // to update the static normal flow x/y of positioned elements. |
hyatt@apple.com | 6a551ad | 2009-02-11 22:43:12 +0000 | [diff] [blame] | 969 | if (r->m_object->isText()) |
| 970 | toRenderText(r->m_object)->positionLineBox(r->m_box); |
| 971 | else if (r->m_object->isBox()) |
| 972 | toRenderBox(r->m_object)->positionLineBox(r->m_box); |
antti@apple.com | 3014ac0 | 2013-09-18 14:33:55 +0000 | [diff] [blame] | 973 | else if (r->m_object->isLineBreak()) |
antti@apple.com | 8d8ae71 | 2013-09-18 18:04:32 +0000 | [diff] [blame] | 974 | toRenderLineBreak(r->m_object)->replaceInlineBoxWrapper(r->m_box); |
hyatt | 98ee7e4 | 2003-05-14 01:39:15 +0000 | [diff] [blame] | 975 | } |
mitz@apple.com | a927be6 | 2008-03-21 05:30:19 +0000 | [diff] [blame] | 976 | // Positioned objects and zero-length text nodes destroy their boxes in |
| 977 | // position(), which unnecessarily dirties the line. |
| 978 | lineBox->markDirty(false); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 979 | } |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 980 | |
mitz@apple.com | c13ea5f | 2008-04-18 21:18:26 +0000 | [diff] [blame] | 981 | static inline bool isCollapsibleSpace(UChar character, RenderText* renderer) |
| 982 | { |
| 983 | if (character == ' ' || character == '\t' || character == softHyphen) |
| 984 | return true; |
| 985 | if (character == '\n') |
| 986 | return !renderer->style()->preserveNewline(); |
| 987 | if (character == noBreakSpace) |
| 988 | return renderer->style()->nbspMode() == SPACE; |
| 989 | return false; |
| 990 | } |
| 991 | |
hyatt@apple.com | 14e332d | 2011-03-25 21:57:07 +0000 | [diff] [blame] | 992 | |
| 993 | static void setStaticPositions(RenderBlock* block, RenderBox* child) |
| 994 | { |
| 995 | // FIXME: The math here is actually not really right. It's a best-guess approximation that |
| 996 | // will work for the common cases |
akling@apple.com | c096ce4 | 2013-09-23 23:55:20 +0000 | [diff] [blame] | 997 | RenderElement* containerBlock = child->container(); |
eae@chromium.org | ee8613e | 2011-11-12 01:12:58 +0000 | [diff] [blame] | 998 | LayoutUnit blockHeight = block->logicalHeight(); |
hyatt@apple.com | 14e332d | 2011-03-25 21:57:07 +0000 | [diff] [blame] | 999 | if (containerBlock->isRenderInline()) { |
| 1000 | // A relative positioned inline encloses us. In this case, we also have to determine our |
| 1001 | // position as though we were an inline. Set |staticInlinePosition| and |staticBlockPosition| on the relative positioned |
| 1002 | // inline so that we can obtain the value later. |
robert@webkit.org | 82903f4 | 2012-08-28 19:18:40 +0000 | [diff] [blame] | 1003 | toRenderInline(containerBlock)->layer()->setStaticInlinePosition(block->startAlignedOffsetForLine(blockHeight, false)); |
hyatt@apple.com | 14e332d | 2011-03-25 21:57:07 +0000 | [diff] [blame] | 1004 | toRenderInline(containerBlock)->layer()->setStaticBlockPosition(blockHeight); |
| 1005 | } |
robert@webkit.org | 83f864f | 2013-01-23 20:15:12 +0000 | [diff] [blame] | 1006 | block->updateStaticInlinePositionForChild(child, blockHeight); |
hyatt@apple.com | 14e332d | 2011-03-25 21:57:07 +0000 | [diff] [blame] | 1007 | child->layer()->setStaticBlockPosition(blockHeight); |
| 1008 | } |
| 1009 | |
msaboff@apple.com | 142fc20 | 2012-10-18 18:03:14 +0000 | [diff] [blame] | 1010 | template <typename CharacterType> |
| 1011 | static inline int findFirstTrailingSpace(RenderText* lastText, const CharacterType* characters, int start, int stop) |
| 1012 | { |
| 1013 | int firstSpace = stop; |
| 1014 | while (firstSpace > start) { |
| 1015 | UChar current = characters[firstSpace - 1]; |
| 1016 | if (!isCollapsibleSpace(current, lastText)) |
| 1017 | break; |
| 1018 | firstSpace--; |
| 1019 | } |
| 1020 | |
| 1021 | return firstSpace; |
| 1022 | } |
| 1023 | |
eric@webkit.org | 5bee294 | 2011-04-08 02:12:31 +0000 | [diff] [blame] | 1024 | inline BidiRun* RenderBlock::handleTrailingSpaces(BidiRunList<BidiRun>& bidiRuns, BidiContext* currentContext) |
eric@webkit.org | 0894bb8 | 2011-04-03 08:29:40 +0000 | [diff] [blame] | 1025 | { |
eric@webkit.org | 5bee294 | 2011-04-08 02:12:31 +0000 | [diff] [blame] | 1026 | if (!bidiRuns.runCount() |
| 1027 | || !bidiRuns.logicallyLastRun()->m_object->style()->breakOnlyAfterWhiteSpace() |
| 1028 | || !bidiRuns.logicallyLastRun()->m_object->style()->autoWrap()) |
eric@webkit.org | 0894bb8 | 2011-04-03 08:29:40 +0000 | [diff] [blame] | 1029 | return 0; |
| 1030 | |
eric@webkit.org | 5bee294 | 2011-04-08 02:12:31 +0000 | [diff] [blame] | 1031 | BidiRun* trailingSpaceRun = bidiRuns.logicallyLastRun(); |
eric@webkit.org | 0894bb8 | 2011-04-03 08:29:40 +0000 | [diff] [blame] | 1032 | RenderObject* lastObject = trailingSpaceRun->m_object; |
| 1033 | if (!lastObject->isText()) |
| 1034 | return 0; |
| 1035 | |
| 1036 | RenderText* lastText = toRenderText(lastObject); |
msaboff@apple.com | 142fc20 | 2012-10-18 18:03:14 +0000 | [diff] [blame] | 1037 | int firstSpace; |
| 1038 | if (lastText->is8Bit()) |
| 1039 | firstSpace = findFirstTrailingSpace(lastText, lastText->characters8(), trailingSpaceRun->start(), trailingSpaceRun->stop()); |
| 1040 | else |
| 1041 | firstSpace = findFirstTrailingSpace(lastText, lastText->characters16(), trailingSpaceRun->start(), trailingSpaceRun->stop()); |
| 1042 | |
eric@webkit.org | 0894bb8 | 2011-04-03 08:29:40 +0000 | [diff] [blame] | 1043 | if (firstSpace == trailingSpaceRun->stop()) |
| 1044 | return 0; |
| 1045 | |
| 1046 | TextDirection direction = style()->direction(); |
eric@webkit.org | 5bee294 | 2011-04-08 02:12:31 +0000 | [diff] [blame] | 1047 | bool shouldReorder = trailingSpaceRun != (direction == LTR ? bidiRuns.lastRun() : bidiRuns.firstRun()); |
eric@webkit.org | 0894bb8 | 2011-04-03 08:29:40 +0000 | [diff] [blame] | 1048 | if (firstSpace != trailingSpaceRun->start()) { |
eric@webkit.org | 5bee294 | 2011-04-08 02:12:31 +0000 | [diff] [blame] | 1049 | BidiContext* baseContext = currentContext; |
eric@webkit.org | 0894bb8 | 2011-04-03 08:29:40 +0000 | [diff] [blame] | 1050 | while (BidiContext* parent = baseContext->parent()) |
| 1051 | baseContext = parent; |
| 1052 | |
| 1053 | BidiRun* newTrailingRun = new (renderArena()) BidiRun(firstSpace, trailingSpaceRun->m_stop, trailingSpaceRun->m_object, baseContext, OtherNeutral); |
| 1054 | trailingSpaceRun->m_stop = firstSpace; |
| 1055 | if (direction == LTR) |
eric@webkit.org | 5bee294 | 2011-04-08 02:12:31 +0000 | [diff] [blame] | 1056 | bidiRuns.addRun(newTrailingRun); |
eric@webkit.org | 0894bb8 | 2011-04-03 08:29:40 +0000 | [diff] [blame] | 1057 | else |
eric@webkit.org | 5bee294 | 2011-04-08 02:12:31 +0000 | [diff] [blame] | 1058 | bidiRuns.prependRun(newTrailingRun); |
eric@webkit.org | 0894bb8 | 2011-04-03 08:29:40 +0000 | [diff] [blame] | 1059 | trailingSpaceRun = newTrailingRun; |
| 1060 | return trailingSpaceRun; |
| 1061 | } |
| 1062 | if (!shouldReorder) |
| 1063 | return trailingSpaceRun; |
| 1064 | |
| 1065 | if (direction == LTR) { |
eric@webkit.org | 5bee294 | 2011-04-08 02:12:31 +0000 | [diff] [blame] | 1066 | bidiRuns.moveRunToEnd(trailingSpaceRun); |
eric@webkit.org | 0894bb8 | 2011-04-03 08:29:40 +0000 | [diff] [blame] | 1067 | trailingSpaceRun->m_level = 0; |
| 1068 | } else { |
eric@webkit.org | 5bee294 | 2011-04-08 02:12:31 +0000 | [diff] [blame] | 1069 | bidiRuns.moveRunToBeginning(trailingSpaceRun); |
eric@webkit.org | 0894bb8 | 2011-04-03 08:29:40 +0000 | [diff] [blame] | 1070 | trailingSpaceRun->m_level = 1; |
| 1071 | } |
| 1072 | return trailingSpaceRun; |
| 1073 | } |
| 1074 | |
mitz@apple.com | d17e8c0 | 2011-04-16 21:59:36 +0000 | [diff] [blame] | 1075 | void RenderBlock::appendFloatingObjectToLastLine(FloatingObject* floatingObject) |
| 1076 | { |
bjonesbe@adobe.com | a9c6666 | 2013-08-14 20:30:14 +0000 | [diff] [blame] | 1077 | ASSERT(!floatingObject->originatingLine()); |
| 1078 | floatingObject->setOriginatingLine(lastRootBox()); |
darin@apple.com | 7cad704 | 2013-09-24 05:53:55 +0000 | [diff] [blame] | 1079 | lastRootBox()->appendFloat(&floatingObject->renderer()); |
mitz@apple.com | d17e8c0 | 2011-04-16 21:59:36 +0000 | [diff] [blame] | 1080 | } |
| 1081 | |
eric@webkit.org | a26de04 | 2011-09-08 18:46:01 +0000 | [diff] [blame] | 1082 | // FIXME: This should be a BidiStatus constructor or create method. |
rniwa@webkit.org | c275acf | 2012-03-05 23:09:22 +0000 | [diff] [blame] | 1083 | static inline BidiStatus statusWithDirection(TextDirection textDirection, bool isOverride) |
eric@webkit.org | a26de04 | 2011-09-08 18:46:01 +0000 | [diff] [blame] | 1084 | { |
| 1085 | WTF::Unicode::Direction direction = textDirection == LTR ? LeftToRight : RightToLeft; |
rniwa@webkit.org | c275acf | 2012-03-05 23:09:22 +0000 | [diff] [blame] | 1086 | RefPtr<BidiContext> context = BidiContext::create(textDirection == LTR ? 0 : 1, direction, isOverride, FromStyleOrDOM); |
eric@webkit.org | a26de04 | 2011-09-08 18:46:01 +0000 | [diff] [blame] | 1087 | |
| 1088 | // This copies BidiStatus and may churn the ref on BidiContext. I doubt it matters. |
| 1089 | return BidiStatus(direction, direction, direction, context.release()); |
| 1090 | } |
| 1091 | |
| 1092 | // FIXME: BidiResolver should have this logic. |
commit-queue@webkit.org | ccad924 | 2012-12-05 20:17:30 +0000 | [diff] [blame] | 1093 | static inline void constructBidiRunsForSegment(InlineBidiResolver& topResolver, BidiRunList<BidiRun>& bidiRuns, const InlineIterator& endOfRuns, VisualDirectionOverride override, bool previousLineBrokeCleanly) |
eric@webkit.org | a26de04 | 2011-09-08 18:46:01 +0000 | [diff] [blame] | 1094 | { |
| 1095 | // FIXME: We should pass a BidiRunList into createBidiRunsForLine instead |
| 1096 | // of the resolver owning the runs. |
| 1097 | ASSERT(&topResolver.runs() == &bidiRuns); |
betravis@adobe.com | 9e5e824 | 2013-04-19 23:28:26 +0000 | [diff] [blame] | 1098 | ASSERT(topResolver.position() != endOfRuns); |
commit-queue@webkit.org | 30cc291 | 2011-12-15 04:19:24 +0000 | [diff] [blame] | 1099 | RenderObject* currentRoot = topResolver.position().root(); |
commit-queue@webkit.org | ccad924 | 2012-12-05 20:17:30 +0000 | [diff] [blame] | 1100 | topResolver.createBidiRunsForLine(endOfRuns, override, previousLineBrokeCleanly); |
eric@webkit.org | a26de04 | 2011-09-08 18:46:01 +0000 | [diff] [blame] | 1101 | |
| 1102 | while (!topResolver.isolatedRuns().isEmpty()) { |
| 1103 | // It does not matter which order we resolve the runs as long as we resolve them all. |
| 1104 | BidiRun* isolatedRun = topResolver.isolatedRuns().last(); |
| 1105 | topResolver.isolatedRuns().removeLast(); |
| 1106 | |
commit-queue@webkit.org | 30cc291 | 2011-12-15 04:19:24 +0000 | [diff] [blame] | 1107 | RenderObject* startObj = isolatedRun->object(); |
| 1108 | |
eric@webkit.org | a26de04 | 2011-09-08 18:46:01 +0000 | [diff] [blame] | 1109 | // Only inlines make sense with unicode-bidi: isolate (blocks are already isolated). |
commit-queue@webkit.org | 30cc291 | 2011-12-15 04:19:24 +0000 | [diff] [blame] | 1110 | // FIXME: Because enterIsolate is not passed a RenderObject, we have to crawl up the |
| 1111 | // tree to see which parent inline is the isolate. We could change enterIsolate |
| 1112 | // to take a RenderObject and do this logic there, but that would be a layering |
| 1113 | // violation for BidiResolver (which knows nothing about RenderObject). |
leviw@chromium.org | e7812f3 | 2012-02-07 23:46:40 +0000 | [diff] [blame] | 1114 | RenderInline* isolatedInline = toRenderInline(containingIsolate(startObj, currentRoot)); |
eric@webkit.org | a26de04 | 2011-09-08 18:46:01 +0000 | [diff] [blame] | 1115 | InlineBidiResolver isolatedResolver; |
leviw@chromium.org | e7812f3 | 2012-02-07 23:46:40 +0000 | [diff] [blame] | 1116 | EUnicodeBidi unicodeBidi = isolatedInline->style()->unicodeBidi(); |
| 1117 | TextDirection direction; |
| 1118 | if (unicodeBidi == Plaintext) |
| 1119 | determineDirectionality(direction, InlineIterator(isolatedInline, isolatedRun->object(), 0)); |
| 1120 | else { |
rniwa@webkit.org | 4d4bd33 | 2012-08-20 21:34:11 +0000 | [diff] [blame] | 1121 | ASSERT(unicodeBidi == Isolate || unicodeBidi == IsolateOverride); |
leviw@chromium.org | e7812f3 | 2012-02-07 23:46:40 +0000 | [diff] [blame] | 1122 | direction = isolatedInline->style()->direction(); |
| 1123 | } |
rniwa@webkit.org | c275acf | 2012-03-05 23:09:22 +0000 | [diff] [blame] | 1124 | isolatedResolver.setStatus(statusWithDirection(direction, isOverride(unicodeBidi))); |
eric@webkit.org | a26de04 | 2011-09-08 18:46:01 +0000 | [diff] [blame] | 1125 | |
| 1126 | // FIXME: The fact that we have to construct an Iterator here |
| 1127 | // currently prevents this code from moving into BidiResolver. |
leviw@chromium.org | e7812f3 | 2012-02-07 23:46:40 +0000 | [diff] [blame] | 1128 | if (!bidiFirstSkippingEmptyInlines(isolatedInline, &isolatedResolver)) |
rniwa@webkit.org | 2343fab | 2011-11-25 20:21:06 +0000 | [diff] [blame] | 1129 | continue; |
leviw@chromium.org | e7812f3 | 2012-02-07 23:46:40 +0000 | [diff] [blame] | 1130 | |
commit-queue@webkit.org | 30cc291 | 2011-12-15 04:19:24 +0000 | [diff] [blame] | 1131 | // The starting position is the beginning of the first run within the isolate that was identified |
| 1132 | // during the earlier call to createBidiRunsForLine. This can be but is not necessarily the |
| 1133 | // first run within the isolate. |
leviw@chromium.org | e7812f3 | 2012-02-07 23:46:40 +0000 | [diff] [blame] | 1134 | InlineIterator iter = InlineIterator(isolatedInline, startObj, isolatedRun->m_start); |
commit-queue@webkit.org | 30cc291 | 2011-12-15 04:19:24 +0000 | [diff] [blame] | 1135 | isolatedResolver.setPositionIgnoringNestedIsolates(iter); |
eric@webkit.org | a26de04 | 2011-09-08 18:46:01 +0000 | [diff] [blame] | 1136 | |
commit-queue@webkit.org | 30cc291 | 2011-12-15 04:19:24 +0000 | [diff] [blame] | 1137 | // We stop at the next end of line; we may re-enter this isolate in the next call to constructBidiRuns(). |
eric@webkit.org | a26de04 | 2011-09-08 18:46:01 +0000 | [diff] [blame] | 1138 | // FIXME: What should end and previousLineBrokeCleanly be? |
| 1139 | // rniwa says previousLineBrokeCleanly is just a WinIE hack and could always be false here? |
commit-queue@webkit.org | ccad924 | 2012-12-05 20:17:30 +0000 | [diff] [blame] | 1140 | isolatedResolver.createBidiRunsForLine(endOfRuns, NoVisualOverride, previousLineBrokeCleanly); |
eric@webkit.org | a26de04 | 2011-09-08 18:46:01 +0000 | [diff] [blame] | 1141 | // Note that we do not delete the runs from the resolver. |
rniwa@webkit.org | d0ad888 | 2012-05-23 07:37:07 +0000 | [diff] [blame] | 1142 | // We're not guaranteed to get any BidiRuns in the previous step. If we don't, we allow the placeholder |
leviw@chromium.org | f0d6f36 | 2012-05-23 04:00:47 +0000 | [diff] [blame] | 1143 | // itself to be turned into an InlineBox. We can't remove it here without potentially losing track of |
| 1144 | // the logically last run. |
| 1145 | if (isolatedResolver.runs().runCount()) |
| 1146 | bidiRuns.replaceRunWithRuns(isolatedRun, isolatedResolver.runs()); |
eric@webkit.org | a26de04 | 2011-09-08 18:46:01 +0000 | [diff] [blame] | 1147 | |
| 1148 | // If we encountered any nested isolate runs, just move them |
| 1149 | // to the top resolver's list for later processing. |
| 1150 | if (!isolatedResolver.isolatedRuns().isEmpty()) { |
andersca@apple.com | 9201299 | 2013-05-05 19:03:49 +0000 | [diff] [blame] | 1151 | topResolver.isolatedRuns().appendVector(isolatedResolver.isolatedRuns()); |
eric@webkit.org | a26de04 | 2011-09-08 18:46:01 +0000 | [diff] [blame] | 1152 | isolatedResolver.isolatedRuns().clear(); |
commit-queue@webkit.org | 1968a43 | 2013-09-11 19:23:58 +0000 | [diff] [blame] | 1153 | currentRoot = isolatedInline; |
eric@webkit.org | a26de04 | 2011-09-08 18:46:01 +0000 | [diff] [blame] | 1154 | } |
| 1155 | } |
| 1156 | } |
| 1157 | |
commit-queue@webkit.org | ccad924 | 2012-12-05 20:17:30 +0000 | [diff] [blame] | 1158 | static inline void constructBidiRunsForLine(const RenderBlock* block, InlineBidiResolver& topResolver, BidiRunList<BidiRun>& bidiRuns, const InlineIterator& endOfLine, VisualDirectionOverride override, bool previousLineBrokeCleanly) |
| 1159 | { |
betravis@adobe.com | ed90c98 | 2013-06-05 23:05:57 +0000 | [diff] [blame] | 1160 | #if !ENABLE(CSS_SHAPES) |
commit-queue@webkit.org | ccad924 | 2012-12-05 20:17:30 +0000 | [diff] [blame] | 1161 | UNUSED_PARAM(block); |
| 1162 | constructBidiRunsForSegment(topResolver, bidiRuns, endOfLine, override, previousLineBrokeCleanly); |
| 1163 | #else |
betravis@adobe.com | cf7cba6 | 2013-06-10 21:23:45 +0000 | [diff] [blame] | 1164 | ShapeInsideInfo* shapeInsideInfo = block->layoutShapeInsideInfo(); |
| 1165 | if (!shapeInsideInfo || !shapeInsideInfo->hasSegments()) { |
commit-queue@webkit.org | ccad924 | 2012-12-05 20:17:30 +0000 | [diff] [blame] | 1166 | constructBidiRunsForSegment(topResolver, bidiRuns, endOfLine, override, previousLineBrokeCleanly); |
| 1167 | return; |
| 1168 | } |
| 1169 | |
betravis@adobe.com | cf7cba6 | 2013-06-10 21:23:45 +0000 | [diff] [blame] | 1170 | const SegmentRangeList& segmentRanges = shapeInsideInfo->segmentRanges(); |
commit-queue@webkit.org | ccad924 | 2012-12-05 20:17:30 +0000 | [diff] [blame] | 1171 | ASSERT(segmentRanges.size()); |
| 1172 | |
| 1173 | for (size_t i = 0; i < segmentRanges.size(); i++) { |
betravis@adobe.com | 28fba07 | 2013-03-12 23:27:35 +0000 | [diff] [blame] | 1174 | LineSegmentIterator iterator = segmentRanges[i].start; |
| 1175 | InlineIterator segmentStart(iterator.root, iterator.object, iterator.offset); |
| 1176 | iterator = segmentRanges[i].end; |
| 1177 | InlineIterator segmentEnd(iterator.root, iterator.object, iterator.offset); |
commit-queue@webkit.org | ccad924 | 2012-12-05 20:17:30 +0000 | [diff] [blame] | 1178 | if (i) { |
| 1179 | ASSERT(segmentStart.m_obj); |
| 1180 | BidiRun* segmentMarker = createRun(segmentStart.m_pos, segmentStart.m_pos, segmentStart.m_obj, topResolver); |
| 1181 | segmentMarker->m_startsSegment = true; |
| 1182 | bidiRuns.addRun(segmentMarker); |
| 1183 | // Do not collapse midpoints between segments |
| 1184 | topResolver.midpointState().betweenMidpoints = false; |
| 1185 | } |
betravis@adobe.com | 9e5e824 | 2013-04-19 23:28:26 +0000 | [diff] [blame] | 1186 | if (segmentStart == segmentEnd) |
| 1187 | continue; |
commit-queue@webkit.org | ccad924 | 2012-12-05 20:17:30 +0000 | [diff] [blame] | 1188 | topResolver.setPosition(segmentStart, numberOfIsolateAncestors(segmentStart)); |
| 1189 | constructBidiRunsForSegment(topResolver, bidiRuns, segmentEnd, override, previousLineBrokeCleanly); |
| 1190 | } |
| 1191 | #endif |
| 1192 | } |
| 1193 | |
eric@webkit.org | 45e33a5 | 2011-05-04 11:51:09 +0000 | [diff] [blame] | 1194 | // This function constructs line boxes for all of the text runs in the resolver and computes their position. |
enrica@apple.com | 885c84d | 2012-10-10 05:48:51 +0000 | [diff] [blame] | 1195 | RootInlineBox* RenderBlock::createLineBoxesFromBidiRuns(BidiRunList<BidiRun>& bidiRuns, const InlineIterator& end, LineInfo& lineInfo, VerticalPositionCache& verticalPositionCache, BidiRun* trailingSpaceRun, WordMeasurements& wordMeasurements) |
eric@webkit.org | 45e33a5 | 2011-05-04 11:51:09 +0000 | [diff] [blame] | 1196 | { |
| 1197 | if (!bidiRuns.runCount()) |
| 1198 | return 0; |
| 1199 | |
| 1200 | // FIXME: Why is this only done when we had runs? |
| 1201 | lineInfo.setLastLine(!end.m_obj); |
| 1202 | |
| 1203 | RootInlineBox* lineBox = constructLine(bidiRuns, lineInfo); |
| 1204 | if (!lineBox) |
| 1205 | return 0; |
| 1206 | |
| 1207 | lineBox->setEndsWithBreak(lineInfo.previousLineBrokeCleanly()); |
| 1208 | |
| 1209 | #if ENABLE(SVG) |
| 1210 | bool isSVGRootInlineBox = lineBox->isSVGRootInlineBox(); |
| 1211 | #else |
| 1212 | bool isSVGRootInlineBox = false; |
| 1213 | #endif |
| 1214 | |
| 1215 | GlyphOverflowAndFallbackFontsMap textBoxDataMap; |
| 1216 | |
| 1217 | // Now we position all of our text runs horizontally. |
| 1218 | if (!isSVGRootInlineBox) |
enrica@apple.com | 885c84d | 2012-10-10 05:48:51 +0000 | [diff] [blame] | 1219 | computeInlineDirectionPositionsForLine(lineBox, lineInfo, bidiRuns.firstRun(), trailingSpaceRun, end.atEnd(), textBoxDataMap, verticalPositionCache, wordMeasurements); |
eric@webkit.org | 45e33a5 | 2011-05-04 11:51:09 +0000 | [diff] [blame] | 1220 | |
| 1221 | // Now position our text runs vertically. |
| 1222 | computeBlockDirectionPositionsForLine(lineBox, bidiRuns.firstRun(), textBoxDataMap, verticalPositionCache); |
| 1223 | |
| 1224 | #if ENABLE(SVG) |
| 1225 | // SVG text layout code computes vertical & horizontal positions on its own. |
| 1226 | // Note that we still need to execute computeVerticalPositionsForLine() as |
| 1227 | // it calls InlineTextBox::positionLineBox(), which tracks whether the box |
| 1228 | // contains reversed text or not. If we wouldn't do that editing and thus |
| 1229 | // text selection in RTL boxes would not work as expected. |
| 1230 | if (isSVGRootInlineBox) { |
| 1231 | ASSERT(isSVGText()); |
| 1232 | static_cast<SVGRootInlineBox*>(lineBox)->computePerCharacterLayoutInformation(); |
| 1233 | } |
| 1234 | #endif |
| 1235 | |
| 1236 | // Compute our overflow now. |
| 1237 | lineBox->computeOverflow(lineBox->lineTop(), lineBox->lineBottom(), textBoxDataMap); |
| 1238 | |
| 1239 | #if PLATFORM(MAC) |
| 1240 | // Highlight acts as an overflow inflation. |
| 1241 | if (style()->highlight() != nullAtom) |
| 1242 | lineBox->addHighlightOverflow(); |
| 1243 | #endif |
| 1244 | return lineBox; |
| 1245 | } |
| 1246 | |
akling@apple.com | 7ce905d | 2013-09-17 11:05:01 +0000 | [diff] [blame] | 1247 | static void deleteLineRange(LineLayoutState& layoutState, RenderArena& arena, RootInlineBox* startLine, RootInlineBox* stopLine = 0) |
eric@webkit.org | 455d90e | 2011-05-09 22:27:27 +0000 | [diff] [blame] | 1248 | { |
| 1249 | RootInlineBox* boxToDelete = startLine; |
| 1250 | while (boxToDelete && boxToDelete != stopLine) { |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1251 | layoutState.updateRepaintRangeFromBox(boxToDelete); |
eric@webkit.org | e2532d9 | 2011-05-16 23:10:49 +0000 | [diff] [blame] | 1252 | // Note: deleteLineRange(renderArena(), firstRootBox()) is not identical to deleteLineBoxTree(). |
| 1253 | // deleteLineBoxTree uses nextLineBox() instead of nextRootBox() when traversing. |
eric@webkit.org | 455d90e | 2011-05-09 22:27:27 +0000 | [diff] [blame] | 1254 | RootInlineBox* next = boxToDelete->nextRootBox(); |
| 1255 | boxToDelete->deleteLine(arena); |
| 1256 | boxToDelete = next; |
| 1257 | } |
| 1258 | } |
| 1259 | |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1260 | void RenderBlock::layoutRunsAndFloats(LineLayoutState& layoutState, bool hasInlineChild) |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1261 | { |
| 1262 | // We want to skip ahead to the first dirty line |
| 1263 | InlineBidiResolver resolver; |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1264 | RootInlineBox* startLine = determineStartPosition(layoutState, resolver); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1265 | |
mitz@apple.com | 10ed3cb | 2011-09-07 20:59:39 +0000 | [diff] [blame] | 1266 | unsigned consecutiveHyphenatedLines = 0; |
| 1267 | if (startLine) { |
| 1268 | for (RootInlineBox* line = startLine->prevRootBox(); line && line->isHyphenated(); line = line->prevRootBox()) |
| 1269 | consecutiveHyphenatedLines++; |
| 1270 | } |
| 1271 | |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1272 | // FIXME: This would make more sense outside of this function, but since |
| 1273 | // determineStartPosition can change the fullLayout flag we have to do this here. Failure to call |
| 1274 | // determineStartPosition first will break fast/repaint/line-flow-with-floats-9.html. |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1275 | if (layoutState.isFullLayout() && hasInlineChild && !selfNeedsLayout()) { |
antti@apple.com | ca2a8ff | 2013-10-04 04:04:35 +0000 | [diff] [blame] | 1276 | setNeedsLayout(MarkOnlyThis); // Mark as needing a full layout to force us to repaint. |
akling@apple.com | 691cf5c | 2013-08-24 16:33:15 +0000 | [diff] [blame] | 1277 | if (!view().doingFullRepaint() && hasLayer()) { |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1278 | // Because we waited until we were already inside layout to discover |
| 1279 | // that the block really needed a full layout, we missed our chance to repaint the layer |
| 1280 | // before layout started. Luckily the layer has cached the repaint rect for its original |
| 1281 | // position and size, and so we can use that to make a repaint happen now. |
leviw@chromium.org | 52066f3 | 2012-09-12 19:17:03 +0000 | [diff] [blame] | 1282 | repaintUsingContainer(containerForRepaint(), pixelSnappedIntRect(layer()->repaintRect())); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1283 | } |
| 1284 | } |
| 1285 | |
mihnea@adobe.com | 9946779 | 2013-03-19 09:09:04 +0000 | [diff] [blame] | 1286 | if (containsFloats()) |
darin@apple.com | 7cad704 | 2013-09-24 05:53:55 +0000 | [diff] [blame] | 1287 | layoutState.setLastFloat(m_floatingObjects->set().last().get()); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1288 | |
| 1289 | // We also find the first clean line and extract these lines. We will add them back |
| 1290 | // if we determine that we're able to synchronize after handling all our dirty lines. |
| 1291 | InlineIterator cleanLineStart; |
| 1292 | BidiStatus cleanLineBidiStatus; |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1293 | if (!layoutState.isFullLayout() && startLine) |
| 1294 | determineEndPosition(layoutState, startLine, cleanLineStart, cleanLineBidiStatus); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1295 | |
| 1296 | if (startLine) { |
commit-queue@webkit.org | 49ad473 | 2011-07-15 07:23:01 +0000 | [diff] [blame] | 1297 | if (!layoutState.usesRepaintBounds()) |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1298 | layoutState.setRepaintRange(logicalHeight()); |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1299 | deleteLineRange(layoutState, renderArena(), startLine); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1300 | } |
| 1301 | |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1302 | if (!layoutState.isFullLayout() && lastRootBox() && lastRootBox()->endsWithBreak()) { |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1303 | // If the last line before the start line ends with a line break that clear floats, |
| 1304 | // adjust the height accordingly. |
| 1305 | // A line break can be either the first or the last object on a line, depending on its direction. |
| 1306 | if (InlineBox* lastLeafChild = lastRootBox()->lastLeafChild()) { |
akling@apple.com | 0b8172b7 | 2013-08-31 18:34:23 +0000 | [diff] [blame] | 1307 | RenderObject* lastObject = &lastLeafChild->renderer(); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1308 | if (!lastObject->isBR()) |
akling@apple.com | 0b8172b7 | 2013-08-31 18:34:23 +0000 | [diff] [blame] | 1309 | lastObject = &lastRootBox()->firstLeafChild()->renderer(); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1310 | if (lastObject->isBR()) { |
| 1311 | EClear clear = lastObject->style()->clear(); |
| 1312 | if (clear != CNONE) |
| 1313 | newLine(clear); |
| 1314 | } |
| 1315 | } |
| 1316 | } |
| 1317 | |
mitz@apple.com | 10ed3cb | 2011-09-07 20:59:39 +0000 | [diff] [blame] | 1318 | layoutRunsAndFloatsInRange(layoutState, resolver, cleanLineStart, cleanLineBidiStatus, consecutiveHyphenatedLines); |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1319 | linkToEndLineIfNeeded(layoutState); |
| 1320 | repaintDirtyFloats(layoutState.floats()); |
| 1321 | } |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1322 | |
zoltan@webkit.org | 8b422c8 | 2013-09-20 21:17:43 +0000 | [diff] [blame] | 1323 | RenderTextInfo::RenderTextInfo() |
mitz@apple.com | 6a85960 | 2012-08-27 15:31:56 +0000 | [diff] [blame] | 1324 | : m_text(0) |
mitz@apple.com | d4c153d | 2012-09-16 23:36:41 +0000 | [diff] [blame] | 1325 | , m_font(0) |
mitz@apple.com | 6a85960 | 2012-08-27 15:31:56 +0000 | [diff] [blame] | 1326 | { |
| 1327 | } |
| 1328 | |
zoltan@webkit.org | 8b422c8 | 2013-09-20 21:17:43 +0000 | [diff] [blame] | 1329 | RenderTextInfo::~RenderTextInfo() |
mitz@apple.com | 6a85960 | 2012-08-27 15:31:56 +0000 | [diff] [blame] | 1330 | { |
| 1331 | } |
| 1332 | |
commit-queue@webkit.org | 4055b2e | 2012-12-06 19:05:15 +0000 | [diff] [blame] | 1333 | // Before restarting the layout loop with a new logicalHeight, remove all floats that were added and reset the resolver. |
| 1334 | inline const InlineIterator& RenderBlock::restartLayoutRunsAndFloatsInRange(LayoutUnit oldLogicalHeight, LayoutUnit newLogicalHeight, FloatingObject* lastFloatFromPreviousLine, InlineBidiResolver& resolver, const InlineIterator& oldEnd) |
| 1335 | { |
| 1336 | removeFloatingObjectsBelow(lastFloatFromPreviousLine, oldLogicalHeight); |
| 1337 | setLogicalHeight(newLogicalHeight); |
| 1338 | resolver.setPositionIgnoringNestedIsolates(oldEnd); |
| 1339 | return oldEnd; |
| 1340 | } |
| 1341 | |
betravis@adobe.com | ed90c98 | 2013-06-05 23:05:57 +0000 | [diff] [blame] | 1342 | #if ENABLE(CSS_SHAPES) |
betravis@adobe.com | 9e5e824 | 2013-04-19 23:28:26 +0000 | [diff] [blame] | 1343 | static inline float firstPositiveWidth(const WordMeasurements& wordMeasurements) |
| 1344 | { |
| 1345 | for (size_t i = 0; i < wordMeasurements.size(); ++i) { |
| 1346 | if (wordMeasurements[i].width > 0) |
| 1347 | return wordMeasurements[i].width; |
| 1348 | } |
| 1349 | return 0; |
| 1350 | } |
| 1351 | |
betravis@adobe.com | cf7cba6 | 2013-06-10 21:23:45 +0000 | [diff] [blame] | 1352 | static inline LayoutUnit adjustLogicalLineTop(ShapeInsideInfo* shapeInsideInfo, InlineIterator start, InlineIterator end, const WordMeasurements& wordMeasurements) |
betravis@adobe.com | 9e5e824 | 2013-04-19 23:28:26 +0000 | [diff] [blame] | 1353 | { |
betravis@adobe.com | cf7cba6 | 2013-06-10 21:23:45 +0000 | [diff] [blame] | 1354 | if (!shapeInsideInfo || end != start) |
betravis@adobe.com | 9e5e824 | 2013-04-19 23:28:26 +0000 | [diff] [blame] | 1355 | return 0; |
| 1356 | |
| 1357 | float minWidth = firstPositiveWidth(wordMeasurements); |
| 1358 | ASSERT(minWidth || wordMeasurements.isEmpty()); |
betravis@adobe.com | cf7cba6 | 2013-06-10 21:23:45 +0000 | [diff] [blame] | 1359 | if (minWidth > 0 && shapeInsideInfo->adjustLogicalLineTop(minWidth)) |
| 1360 | return shapeInsideInfo->logicalLineTop(); |
betravis@adobe.com | 9e5e824 | 2013-04-19 23:28:26 +0000 | [diff] [blame] | 1361 | |
betravis@adobe.com | cf7cba6 | 2013-06-10 21:23:45 +0000 | [diff] [blame] | 1362 | return shapeInsideInfo->shapeLogicalBottom(); |
betravis@adobe.com | 9e5e824 | 2013-04-19 23:28:26 +0000 | [diff] [blame] | 1363 | } |
zoltan@webkit.org | bd3dabd | 2013-05-13 19:11:33 +0000 | [diff] [blame] | 1364 | |
zoltan@webkit.org | 758f6ce | 2013-06-18 22:31:57 +0000 | [diff] [blame] | 1365 | static inline void pushShapeContentOverflowBelowTheContentBox(RenderBlock* block, ShapeInsideInfo* shapeInsideInfo, LayoutUnit lineTop, LayoutUnit lineHeight) |
zoltan@webkit.org | 3a337ba | 2013-06-17 20:23:58 +0000 | [diff] [blame] | 1366 | { |
zoltan@webkit.org | 758f6ce | 2013-06-18 22:31:57 +0000 | [diff] [blame] | 1367 | ASSERT(shapeInsideInfo); |
zoltan@webkit.org | 3a337ba | 2013-06-17 20:23:58 +0000 | [diff] [blame] | 1368 | |
| 1369 | LayoutUnit logicalLineBottom = lineTop + lineHeight; |
zoltan@webkit.org | b20fd7c | 2013-07-19 17:46:08 +0000 | [diff] [blame] | 1370 | LayoutUnit shapeLogicalBottom = shapeInsideInfo->shapeLogicalBottom(); |
zoltan@webkit.org | 2296409 | 2013-09-12 22:55:59 +0000 | [diff] [blame] | 1371 | LayoutUnit shapeContainingBlockLogicalHeight = shapeInsideInfo->shapeContainingBlockLogicalHeight(); |
zoltan@webkit.org | 758f6ce | 2013-06-18 22:31:57 +0000 | [diff] [blame] | 1372 | |
zoltan@webkit.org | 2296409 | 2013-09-12 22:55:59 +0000 | [diff] [blame] | 1373 | bool isOverflowPositionedAlready = (shapeContainingBlockLogicalHeight - shapeInsideInfo->owner()->borderAndPaddingAfter() + lineHeight) <= lineTop; |
zoltan@webkit.org | 758f6ce | 2013-06-18 22:31:57 +0000 | [diff] [blame] | 1374 | |
zoltan@webkit.org | b20fd7c | 2013-07-19 17:46:08 +0000 | [diff] [blame] | 1375 | // If the last line overlaps with the shape, we don't need the segments anymore |
| 1376 | if (lineTop < shapeLogicalBottom && shapeLogicalBottom < logicalLineBottom) |
| 1377 | shapeInsideInfo->clearSegments(); |
| 1378 | |
zoltan@webkit.org | 2296409 | 2013-09-12 22:55:59 +0000 | [diff] [blame] | 1379 | if (logicalLineBottom <= shapeLogicalBottom || !shapeContainingBlockLogicalHeight || isOverflowPositionedAlready) |
zoltan@webkit.org | 3a337ba | 2013-06-17 20:23:58 +0000 | [diff] [blame] | 1380 | return; |
| 1381 | |
zoltan@webkit.org | 2296409 | 2013-09-12 22:55:59 +0000 | [diff] [blame] | 1382 | LayoutUnit newLogicalHeight = block->logicalHeight() + (shapeContainingBlockLogicalHeight - (lineTop + shapeInsideInfo->owner()->borderAndPaddingAfter())); |
zoltan@webkit.org | 3a337ba | 2013-06-17 20:23:58 +0000 | [diff] [blame] | 1383 | block->setLogicalHeight(newLogicalHeight); |
zoltan@webkit.org | 3a337ba | 2013-06-17 20:23:58 +0000 | [diff] [blame] | 1384 | } |
| 1385 | |
betravis@adobe.com | 5fd027a | 2013-09-03 22:14:51 +0000 | [diff] [blame] | 1386 | void RenderBlock::updateShapeAndSegmentsForCurrentLine(ShapeInsideInfo*& shapeInsideInfo, const LayoutSize& logicalOffsetFromShapeContainer, LineLayoutState& layoutState) |
zoltan@webkit.org | bd3dabd | 2013-05-13 19:11:33 +0000 | [diff] [blame] | 1387 | { |
zoltan@webkit.org | 758bf02 | 2013-06-13 21:09:43 +0000 | [diff] [blame] | 1388 | if (layoutState.flowThread()) |
zoltan@webkit.org | 758f6ce | 2013-06-18 22:31:57 +0000 | [diff] [blame] | 1389 | return updateShapeAndSegmentsForCurrentLineInFlowThread(shapeInsideInfo, layoutState); |
zoltan@webkit.org | 758bf02 | 2013-06-13 21:09:43 +0000 | [diff] [blame] | 1390 | |
zoltan@webkit.org | 758f6ce | 2013-06-18 22:31:57 +0000 | [diff] [blame] | 1391 | if (!shapeInsideInfo) |
zoltan@webkit.org | bd3dabd | 2013-05-13 19:11:33 +0000 | [diff] [blame] | 1392 | return; |
| 1393 | |
betravis@adobe.com | 5fd027a | 2013-09-03 22:14:51 +0000 | [diff] [blame] | 1394 | LayoutUnit lineTop = logicalHeight() + logicalOffsetFromShapeContainer.height(); |
| 1395 | LayoutUnit lineLeft = logicalOffsetFromShapeContainer.width(); |
zoltan@webkit.org | 3a337ba | 2013-06-17 20:23:58 +0000 | [diff] [blame] | 1396 | LayoutUnit lineHeight = this->lineHeight(layoutState.lineInfo().isFirstLine(), isHorizontalWritingMode() ? HorizontalLine : VerticalLine, PositionOfInteriorLineBoxes); |
zoltan@webkit.org | bd3dabd | 2013-05-13 19:11:33 +0000 | [diff] [blame] | 1397 | |
zoltan@webkit.org | 3a337ba | 2013-06-17 20:23:58 +0000 | [diff] [blame] | 1398 | // FIXME: Bug 95361: It is possible for a line to grow beyond lineHeight, in which case these segments may be incorrect. |
zoltan@webkit.org | e1a0c95 | 2013-09-18 03:27:35 +0000 | [diff] [blame] | 1399 | shapeInsideInfo->updateSegmentsForLine(LayoutSize(lineLeft, lineTop), lineHeight); |
zoltan@webkit.org | 3a337ba | 2013-06-17 20:23:58 +0000 | [diff] [blame] | 1400 | |
zoltan@webkit.org | 758f6ce | 2013-06-18 22:31:57 +0000 | [diff] [blame] | 1401 | pushShapeContentOverflowBelowTheContentBox(this, shapeInsideInfo, lineTop, lineHeight); |
zoltan@webkit.org | 758bf02 | 2013-06-13 21:09:43 +0000 | [diff] [blame] | 1402 | } |
zoltan@webkit.org | d07fc73 | 2013-05-20 19:00:22 +0000 | [diff] [blame] | 1403 | |
zoltan@webkit.org | 758f6ce | 2013-06-18 22:31:57 +0000 | [diff] [blame] | 1404 | void RenderBlock::updateShapeAndSegmentsForCurrentLineInFlowThread(ShapeInsideInfo*& shapeInsideInfo, LineLayoutState& layoutState) |
zoltan@webkit.org | 758bf02 | 2013-06-13 21:09:43 +0000 | [diff] [blame] | 1405 | { |
| 1406 | ASSERT(layoutState.flowThread()); |
zoltan@webkit.org | ee0f407 | 2013-05-21 21:04:27 +0000 | [diff] [blame] | 1407 | |
zoltan@webkit.org | 758bf02 | 2013-06-13 21:09:43 +0000 | [diff] [blame] | 1408 | LayoutUnit lineHeight = this->lineHeight(layoutState.lineInfo().isFirstLine(), isHorizontalWritingMode() ? HorizontalLine : VerticalLine, PositionOfInteriorLineBoxes); |
zoltan@webkit.org | ee0f407 | 2013-05-21 21:04:27 +0000 | [diff] [blame] | 1409 | |
zoltan@webkit.org | 758bf02 | 2013-06-13 21:09:43 +0000 | [diff] [blame] | 1410 | RenderRegion* currentRegion = regionAtBlockOffset(logicalHeight()); |
| 1411 | if (!currentRegion) |
| 1412 | return; |
zoltan@webkit.org | ee0f407 | 2013-05-21 21:04:27 +0000 | [diff] [blame] | 1413 | |
zoltan@webkit.org | 758bf02 | 2013-06-13 21:09:43 +0000 | [diff] [blame] | 1414 | shapeInsideInfo = currentRegion->shapeInsideInfo(); |
zoltan@webkit.org | ee0f407 | 2013-05-21 21:04:27 +0000 | [diff] [blame] | 1415 | |
zoltan@webkit.org | 758bf02 | 2013-06-13 21:09:43 +0000 | [diff] [blame] | 1416 | LayoutUnit logicalLineTopInFlowThread = logicalHeight() + offsetFromLogicalTopOfFirstPage(); |
| 1417 | LayoutUnit logicalLineBottomInFlowThread = logicalLineTopInFlowThread + lineHeight; |
| 1418 | LayoutUnit logicalRegionTopInFlowThread = currentRegion->logicalTopForFlowThreadContent(); |
zoltan@webkit.org | 8e79cc2 | 2013-06-14 00:39:36 +0000 | [diff] [blame] | 1419 | LayoutUnit logicalRegionBottomInFlowThread = logicalRegionTopInFlowThread + currentRegion->logicalHeight() - currentRegion->borderAndPaddingBefore() - currentRegion->borderAndPaddingAfter(); |
zoltan@webkit.org | ee0f407 | 2013-05-21 21:04:27 +0000 | [diff] [blame] | 1420 | |
zoltan@webkit.org | 758bf02 | 2013-06-13 21:09:43 +0000 | [diff] [blame] | 1421 | // We only want to deal regions with shapes, so we look up for the next region whether it has a shape |
| 1422 | if (!shapeInsideInfo && !currentRegion->isLastRegion()) { |
| 1423 | LayoutUnit deltaToNextRegion = logicalHeight() + logicalRegionBottomInFlowThread - logicalLineTopInFlowThread; |
| 1424 | RenderRegion* lookupForNextRegion = regionAtBlockOffset(logicalHeight() + deltaToNextRegion); |
| 1425 | if (!lookupForNextRegion->shapeInsideInfo()) |
| 1426 | return; |
| 1427 | } |
| 1428 | |
| 1429 | LayoutUnit shapeBottomInFlowThread = LayoutUnit::max(); |
| 1430 | if (shapeInsideInfo) |
| 1431 | shapeBottomInFlowThread = shapeInsideInfo->shapeLogicalBottom() + currentRegion->logicalTopForFlowThreadContent(); |
| 1432 | |
| 1433 | // If the line is between two shapes/regions we position the line to the top of the next shape/region |
| 1434 | RenderRegion* nextRegion = regionAtBlockOffset(logicalHeight() + lineHeight); |
| 1435 | if ((currentRegion != nextRegion && (logicalLineBottomInFlowThread > logicalRegionBottomInFlowThread)) || (!currentRegion->isLastRegion() && shapeBottomInFlowThread < logicalLineBottomInFlowThread)) { |
| 1436 | LayoutUnit deltaToNextRegion = logicalRegionBottomInFlowThread - logicalLineTopInFlowThread; |
| 1437 | nextRegion = regionAtBlockOffset(logicalHeight() + deltaToNextRegion); |
| 1438 | |
| 1439 | ASSERT(currentRegion != nextRegion); |
| 1440 | |
| 1441 | shapeInsideInfo = nextRegion->shapeInsideInfo(); |
| 1442 | setLogicalHeight(logicalHeight() + deltaToNextRegion); |
| 1443 | |
| 1444 | currentRegion = nextRegion; |
| 1445 | |
| 1446 | logicalLineTopInFlowThread = logicalHeight() + offsetFromLogicalTopOfFirstPage(); |
| 1447 | logicalLineBottomInFlowThread = logicalLineTopInFlowThread + lineHeight; |
| 1448 | logicalRegionTopInFlowThread = currentRegion->logicalTopForFlowThreadContent(); |
zoltan@webkit.org | 8e79cc2 | 2013-06-14 00:39:36 +0000 | [diff] [blame] | 1449 | logicalRegionBottomInFlowThread = logicalRegionTopInFlowThread + currentRegion->logicalHeight() - currentRegion->borderAndPaddingBefore() - currentRegion->borderAndPaddingAfter(); |
zoltan@webkit.org | 758bf02 | 2013-06-13 21:09:43 +0000 | [diff] [blame] | 1450 | } |
| 1451 | |
| 1452 | if (!shapeInsideInfo) |
| 1453 | return; |
| 1454 | |
| 1455 | // We position the first line to the top of the shape in the region or to the previously adjusted position in the shape |
| 1456 | if (logicalLineBottomInFlowThread <= (logicalRegionTopInFlowThread + lineHeight) || (logicalLineTopInFlowThread - logicalRegionTopInFlowThread) < (layoutState.adjustedLogicalLineTop() - currentRegion->borderAndPaddingBefore())) { |
| 1457 | LayoutUnit shapeTopOffset = layoutState.adjustedLogicalLineTop(); |
| 1458 | if (!shapeTopOffset) |
| 1459 | shapeTopOffset = shapeInsideInfo->shapeLogicalTop(); |
| 1460 | |
| 1461 | LayoutUnit shapePositionInFlowThread = currentRegion->logicalTopForFlowThreadContent() + shapeTopOffset; |
| 1462 | LayoutUnit shapeTopLineTopDelta = shapePositionInFlowThread - logicalLineTopInFlowThread - currentRegion->borderAndPaddingBefore(); |
| 1463 | |
| 1464 | setLogicalHeight(logicalHeight() + shapeTopLineTopDelta); |
| 1465 | logicalLineTopInFlowThread += shapeTopLineTopDelta; |
| 1466 | layoutState.setAdjustedLogicalLineTop(0); |
| 1467 | } |
| 1468 | |
| 1469 | LayoutUnit lineTop = logicalLineTopInFlowThread - currentRegion->logicalTopForFlowThreadContent() + currentRegion->borderAndPaddingBefore(); |
betravis@adobe.com | 5fd027a | 2013-09-03 22:14:51 +0000 | [diff] [blame] | 1470 | |
| 1471 | // FIXME: 118571 - Shape inside on a region does not yet take into account its padding for nested flow blocks |
zoltan@webkit.org | e1a0c95 | 2013-09-18 03:27:35 +0000 | [diff] [blame] | 1472 | shapeInsideInfo->updateSegmentsForLine(LayoutSize(0, lineTop), lineHeight); |
zoltan@webkit.org | 758bf02 | 2013-06-13 21:09:43 +0000 | [diff] [blame] | 1473 | |
zoltan@webkit.org | 3a337ba | 2013-06-17 20:23:58 +0000 | [diff] [blame] | 1474 | if (currentRegion->isLastRegion()) |
zoltan@webkit.org | 758f6ce | 2013-06-18 22:31:57 +0000 | [diff] [blame] | 1475 | pushShapeContentOverflowBelowTheContentBox(this, shapeInsideInfo, lineTop, lineHeight); |
zoltan@webkit.org | bd3dabd | 2013-05-13 19:11:33 +0000 | [diff] [blame] | 1476 | } |
| 1477 | |
betravis@adobe.com | cf7cba6 | 2013-06-10 21:23:45 +0000 | [diff] [blame] | 1478 | bool RenderBlock::adjustLogicalLineTopAndLogicalHeightIfNeeded(ShapeInsideInfo* shapeInsideInfo, LayoutUnit absoluteLogicalTop, LineLayoutState& layoutState, InlineBidiResolver& resolver, FloatingObject* lastFloatFromPreviousLine, InlineIterator& end, WordMeasurements& wordMeasurements) |
zoltan@webkit.org | bd3dabd | 2013-05-13 19:11:33 +0000 | [diff] [blame] | 1479 | { |
betravis@adobe.com | cf7cba6 | 2013-06-10 21:23:45 +0000 | [diff] [blame] | 1480 | LayoutUnit adjustedLogicalLineTop = adjustLogicalLineTop(shapeInsideInfo, resolver.position(), end, wordMeasurements); |
zoltan@webkit.org | 2b977c0 | 2013-10-03 18:24:59 +0000 | [diff] [blame] | 1481 | |
| 1482 | if (shapeInsideInfo && !wordMeasurements.size() && containsFloats()) { |
| 1483 | lastFloatFromPreviousLine = m_floatingObjects->set().last().get(); |
| 1484 | LayoutUnit floatLogicalTopOffset = shapeInsideInfo->computeFirstFitPositionForFloat(lastFloatFromPreviousLine->logicalSize(isHorizontalWritingMode())); |
| 1485 | if (logicalHeight() < floatLogicalTopOffset) |
| 1486 | adjustedLogicalLineTop = floatLogicalTopOffset; |
| 1487 | } |
| 1488 | |
zoltan@webkit.org | bd3dabd | 2013-05-13 19:11:33 +0000 | [diff] [blame] | 1489 | if (!adjustedLogicalLineTop) |
| 1490 | return false; |
| 1491 | |
| 1492 | LayoutUnit newLogicalHeight = adjustedLogicalLineTop - absoluteLogicalTop; |
zoltan@webkit.org | 758bf02 | 2013-06-13 21:09:43 +0000 | [diff] [blame] | 1493 | |
| 1494 | if (layoutState.flowThread()) { |
| 1495 | layoutState.setAdjustedLogicalLineTop(adjustedLogicalLineTop); |
zoltan@webkit.org | ee0f407 | 2013-05-21 21:04:27 +0000 | [diff] [blame] | 1496 | newLogicalHeight = logicalHeight(); |
zoltan@webkit.org | 758bf02 | 2013-06-13 21:09:43 +0000 | [diff] [blame] | 1497 | } |
| 1498 | |
zoltan@webkit.org | bd3dabd | 2013-05-13 19:11:33 +0000 | [diff] [blame] | 1499 | end = restartLayoutRunsAndFloatsInRange(logicalHeight(), newLogicalHeight, lastFloatFromPreviousLine, resolver, end); |
| 1500 | return true; |
| 1501 | } |
betravis@adobe.com | 9e5e824 | 2013-04-19 23:28:26 +0000 | [diff] [blame] | 1502 | #endif |
| 1503 | |
mitz@apple.com | 10ed3cb | 2011-09-07 20:59:39 +0000 | [diff] [blame] | 1504 | void RenderBlock::layoutRunsAndFloatsInRange(LineLayoutState& layoutState, InlineBidiResolver& resolver, const InlineIterator& cleanLineStart, const BidiStatus& cleanLineBidiStatus, unsigned consecutiveHyphenatedLines) |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1505 | { |
mihnea@adobe.com | 3bebbf2 | 2012-01-19 09:22:59 +0000 | [diff] [blame] | 1506 | RenderStyle* styleToUse = style(); |
akling@apple.com | 691cf5c | 2013-08-24 16:33:15 +0000 | [diff] [blame] | 1507 | bool paginated = view().layoutState() && view().layoutState()->isPaginated(); |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1508 | LineMidpointState& lineMidpointState = resolver.midpointState(); |
| 1509 | InlineIterator end = resolver.position(); |
| 1510 | bool checkForEndLineMatch = layoutState.endLine(); |
mitz@apple.com | 6a85960 | 2012-08-27 15:31:56 +0000 | [diff] [blame] | 1511 | RenderTextInfo renderTextInfo; |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1512 | VerticalPositionCache verticalPositionCache; |
| 1513 | |
leviw@chromium.org | 1a50869 | 2011-05-05 00:01:11 +0000 | [diff] [blame] | 1514 | LineBreaker lineBreaker(this); |
| 1515 | |
betravis@adobe.com | ed90c98 | 2013-06-05 23:05:57 +0000 | [diff] [blame] | 1516 | #if ENABLE(CSS_SHAPES) |
betravis@adobe.com | 5fd027a | 2013-09-03 22:14:51 +0000 | [diff] [blame] | 1517 | LayoutSize logicalOffsetFromShapeContainer; |
betravis@adobe.com | cf7cba6 | 2013-06-10 21:23:45 +0000 | [diff] [blame] | 1518 | ShapeInsideInfo* shapeInsideInfo = layoutShapeInsideInfo(); |
| 1519 | if (shapeInsideInfo) { |
| 1520 | ASSERT(shapeInsideInfo->owner() == this || allowsShapeInsideInfoSharing()); |
| 1521 | if (shapeInsideInfo != this->shapeInsideInfo()) { |
commit-queue@webkit.org | 5fe2dfd | 2012-10-26 19:57:52 +0000 | [diff] [blame] | 1522 | // FIXME Bug 100284: If subsequent LayoutStates are pushed, we will have to add |
| 1523 | // their offsets from the original shape-inside container. |
betravis@adobe.com | 5fd027a | 2013-09-03 22:14:51 +0000 | [diff] [blame] | 1524 | logicalOffsetFromShapeContainer = logicalOffsetFromShapeAncestorContainer(shapeInsideInfo->owner()); |
commit-queue@webkit.org | 3b26f3d | 2012-09-25 18:22:39 +0000 | [diff] [blame] | 1525 | } |
| 1526 | // Begin layout at the logical top of our shape inside. |
betravis@adobe.com | 5fd027a | 2013-09-03 22:14:51 +0000 | [diff] [blame] | 1527 | if (logicalHeight() + logicalOffsetFromShapeContainer.height() < shapeInsideInfo->shapeLogicalTop()) { |
| 1528 | LayoutUnit logicalHeight = shapeInsideInfo->shapeLogicalTop() - logicalOffsetFromShapeContainer.height(); |
zoltan@webkit.org | d07fc73 | 2013-05-20 19:00:22 +0000 | [diff] [blame] | 1529 | if (layoutState.flowThread()) |
betravis@adobe.com | cf7cba6 | 2013-06-10 21:23:45 +0000 | [diff] [blame] | 1530 | logicalHeight -= shapeInsideInfo->owner()->borderAndPaddingBefore(); |
zoltan@webkit.org | d07fc73 | 2013-05-20 19:00:22 +0000 | [diff] [blame] | 1531 | setLogicalHeight(logicalHeight); |
| 1532 | } |
commit-queue@webkit.org | 3b26f3d | 2012-09-25 18:22:39 +0000 | [diff] [blame] | 1533 | } |
commit-queue@webkit.org | b354051 | 2012-08-24 18:48:49 +0000 | [diff] [blame] | 1534 | #endif |
| 1535 | |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1536 | while (!end.atEnd()) { |
| 1537 | // FIXME: Is this check necessary before the first iteration or can it be moved to the end? |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1538 | if (checkForEndLineMatch) { |
| 1539 | layoutState.setEndLineMatched(matchedEndLine(layoutState, resolver, cleanLineStart, cleanLineBidiStatus)); |
rniwa@webkit.org | 7daa12d | 2011-12-02 02:39:14 +0000 | [diff] [blame] | 1540 | if (layoutState.endLineMatched()) { |
| 1541 | resolver.setPosition(InlineIterator(resolver.position().root(), 0, 0), 0); |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1542 | break; |
rniwa@webkit.org | 7daa12d | 2011-12-02 02:39:14 +0000 | [diff] [blame] | 1543 | } |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1544 | } |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1545 | |
| 1546 | lineMidpointState.reset(); |
| 1547 | |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1548 | layoutState.lineInfo().setEmpty(true); |
robert@webkit.org | 8cbab14 | 2011-12-30 20:58:29 +0000 | [diff] [blame] | 1549 | layoutState.lineInfo().resetRunsFromLeadingWhitespace(); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1550 | |
rniwa@webkit.org | 53d106b | 2011-11-30 22:33:20 +0000 | [diff] [blame] | 1551 | const InlineIterator oldEnd = end; |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1552 | bool isNewUBAParagraph = layoutState.lineInfo().previousLineBrokeCleanly(); |
darin@apple.com | 7cad704 | 2013-09-24 05:53:55 +0000 | [diff] [blame] | 1553 | FloatingObject* lastFloatFromPreviousLine = (containsFloats()) ? m_floatingObjects->set().last().get() : 0; |
zoltan@webkit.org | 3bd77f5 | 2013-04-23 18:23:36 +0000 | [diff] [blame] | 1554 | |
betravis@adobe.com | ed90c98 | 2013-06-05 23:05:57 +0000 | [diff] [blame] | 1555 | #if ENABLE(CSS_SHAPES) |
betravis@adobe.com | 5fd027a | 2013-09-03 22:14:51 +0000 | [diff] [blame] | 1556 | updateShapeAndSegmentsForCurrentLine(shapeInsideInfo, logicalOffsetFromShapeContainer, layoutState); |
commit-queue@webkit.org | b354051 | 2012-08-24 18:48:49 +0000 | [diff] [blame] | 1557 | #endif |
enrica@apple.com | 885c84d | 2012-10-10 05:48:51 +0000 | [diff] [blame] | 1558 | WordMeasurements wordMeasurements; |
| 1559 | end = lineBreaker.nextLineBreak(resolver, layoutState.lineInfo(), renderTextInfo, lastFloatFromPreviousLine, consecutiveHyphenatedLines, wordMeasurements); |
glenn@skynav.com | 61b1abf | 2013-04-02 23:28:32 +0000 | [diff] [blame] | 1560 | renderTextInfo.m_lineBreakIterator.resetPriorContext(); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1561 | if (resolver.position().atEnd()) { |
leviw@chromium.org | e7812f3 | 2012-02-07 23:46:40 +0000 | [diff] [blame] | 1562 | // FIXME: We shouldn't be creating any runs in nextLineBreak to begin with! |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1563 | // Once BidiRunList is separated from BidiResolver this will not be needed. |
| 1564 | resolver.runs().deleteRuns(); |
| 1565 | resolver.markCurrentRunEmpty(); // FIXME: This can probably be replaced by an ASSERT (or just removed). |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1566 | layoutState.setCheckForFloatsFromLastLine(true); |
rniwa@webkit.org | 7daa12d | 2011-12-02 02:39:14 +0000 | [diff] [blame] | 1567 | resolver.setPosition(InlineIterator(resolver.position().root(), 0, 0), 0); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1568 | break; |
| 1569 | } |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1570 | |
betravis@adobe.com | ed90c98 | 2013-06-05 23:05:57 +0000 | [diff] [blame] | 1571 | #if ENABLE(CSS_SHAPES) |
betravis@adobe.com | 5fd027a | 2013-09-03 22:14:51 +0000 | [diff] [blame] | 1572 | if (adjustLogicalLineTopAndLogicalHeightIfNeeded(shapeInsideInfo, logicalOffsetFromShapeContainer.height(), layoutState, resolver, lastFloatFromPreviousLine, end, wordMeasurements)) |
commit-queue@webkit.org | 4055b2e | 2012-12-06 19:05:15 +0000 | [diff] [blame] | 1573 | continue; |
commit-queue@webkit.org | 4055b2e | 2012-12-06 19:05:15 +0000 | [diff] [blame] | 1574 | #endif |
betravis@adobe.com | 9e5e824 | 2013-04-19 23:28:26 +0000 | [diff] [blame] | 1575 | ASSERT(end != resolver.position()); |
| 1576 | |
eric@webkit.org | 45e33a5 | 2011-05-04 11:51:09 +0000 | [diff] [blame] | 1577 | // This is a short-cut for empty lines. |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1578 | if (layoutState.lineInfo().isEmpty()) { |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1579 | if (lastRootBox()) |
| 1580 | lastRootBox()->setLineBreakInfo(end.m_obj, end.m_pos, resolver.status()); |
| 1581 | } else { |
mihnea@adobe.com | 3bebbf2 | 2012-01-19 09:22:59 +0000 | [diff] [blame] | 1582 | VisualDirectionOverride override = (styleToUse->rtlOrdering() == VisualOrder ? (styleToUse->direction() == LTR ? VisualLeftToRightOverride : VisualRightToLeftOverride) : NoVisualOverride); |
leviw@chromium.org | 7781b6a | 2011-06-27 22:01:38 +0000 | [diff] [blame] | 1583 | |
mihnea@adobe.com | 3bebbf2 | 2012-01-19 09:22:59 +0000 | [diff] [blame] | 1584 | if (isNewUBAParagraph && styleToUse->unicodeBidi() == Plaintext && !resolver.context()->parent()) { |
| 1585 | TextDirection direction = styleToUse->direction(); |
leviw@chromium.org | e7812f3 | 2012-02-07 23:46:40 +0000 | [diff] [blame] | 1586 | determineDirectionality(direction, resolver.position()); |
rniwa@webkit.org | c275acf | 2012-03-05 23:09:22 +0000 | [diff] [blame] | 1587 | resolver.setStatus(BidiStatus(direction, isOverride(styleToUse->unicodeBidi()))); |
leviw@chromium.org | 7781b6a | 2011-06-27 22:01:38 +0000 | [diff] [blame] | 1588 | } |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1589 | // FIXME: This ownership is reversed. We should own the BidiRunList and pass it to createBidiRunsForLine. |
| 1590 | BidiRunList<BidiRun>& bidiRuns = resolver.runs(); |
commit-queue@webkit.org | ccad924 | 2012-12-05 20:17:30 +0000 | [diff] [blame] | 1591 | constructBidiRunsForLine(this, resolver, bidiRuns, end, override, layoutState.lineInfo().previousLineBrokeCleanly()); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1592 | ASSERT(resolver.position() == end); |
| 1593 | |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1594 | BidiRun* trailingSpaceRun = !layoutState.lineInfo().previousLineBrokeCleanly() ? handleTrailingSpaces(bidiRuns, resolver.context()) : 0; |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1595 | |
mitz@apple.com | 10ed3cb | 2011-09-07 20:59:39 +0000 | [diff] [blame] | 1596 | if (bidiRuns.runCount() && lineBreaker.lineWasHyphenated()) { |
eric@webkit.org | 45e33a5 | 2011-05-04 11:51:09 +0000 | [diff] [blame] | 1597 | bidiRuns.logicallyLastRun()->m_hasHyphen = true; |
mitz@apple.com | 10ed3cb | 2011-09-07 20:59:39 +0000 | [diff] [blame] | 1598 | consecutiveHyphenatedLines++; |
| 1599 | } else |
| 1600 | consecutiveHyphenatedLines = 0; |
eric@webkit.org | 45e33a5 | 2011-05-04 11:51:09 +0000 | [diff] [blame] | 1601 | |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1602 | // Now that the runs have been ordered, we create the line boxes. |
| 1603 | // At the same time we figure out where border/padding/margin should be applied for |
| 1604 | // inline flow boxes. |
| 1605 | |
eae@chromium.org | ee8613e | 2011-11-12 01:12:58 +0000 | [diff] [blame] | 1606 | LayoutUnit oldLogicalHeight = logicalHeight(); |
enrica@apple.com | 885c84d | 2012-10-10 05:48:51 +0000 | [diff] [blame] | 1607 | RootInlineBox* lineBox = createLineBoxesFromBidiRuns(bidiRuns, end, layoutState.lineInfo(), verticalPositionCache, trailingSpaceRun, wordMeasurements); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1608 | |
| 1609 | bidiRuns.deleteRuns(); |
| 1610 | resolver.markCurrentRunEmpty(); // FIXME: This can probably be replaced by an ASSERT (or just removed). |
| 1611 | |
| 1612 | if (lineBox) { |
| 1613 | lineBox->setLineBreakInfo(end.m_obj, end.m_pos, resolver.status()); |
commit-queue@webkit.org | 49ad473 | 2011-07-15 07:23:01 +0000 | [diff] [blame] | 1614 | if (layoutState.usesRepaintBounds()) |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1615 | layoutState.updateRepaintRangeFromBox(lineBox); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1616 | |
| 1617 | if (paginated) { |
eae@chromium.org | ee8613e | 2011-11-12 01:12:58 +0000 | [diff] [blame] | 1618 | LayoutUnit adjustment = 0; |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 1619 | // FIXME-BLOCKFLOW: Remove this type conversion once the owning function moves. |
| 1620 | toRenderBlockFlow(this)->adjustLinePositionForPagination(lineBox, adjustment, layoutState.flowThread()); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1621 | if (adjustment) { |
eae@chromium.org | ee8613e | 2011-11-12 01:12:58 +0000 | [diff] [blame] | 1622 | LayoutUnit oldLineWidth = availableLogicalWidthForLine(oldLogicalHeight, layoutState.lineInfo().isFirstLine()); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1623 | lineBox->adjustBlockDirectionPosition(adjustment); |
commit-queue@webkit.org | 49ad473 | 2011-07-15 07:23:01 +0000 | [diff] [blame] | 1624 | if (layoutState.usesRepaintBounds()) |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1625 | layoutState.updateRepaintRangeFromBox(lineBox); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1626 | |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1627 | if (availableLogicalWidthForLine(oldLogicalHeight + adjustment, layoutState.lineInfo().isFirstLine()) != oldLineWidth) { |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1628 | // We have to delete this line, remove all floats that got added, and let line layout re-run. |
| 1629 | lineBox->deleteLine(renderArena()); |
commit-queue@webkit.org | 4055b2e | 2012-12-06 19:05:15 +0000 | [diff] [blame] | 1630 | end = restartLayoutRunsAndFloatsInRange(oldLogicalHeight, oldLogicalHeight + adjustment, lastFloatFromPreviousLine, resolver, oldEnd); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1631 | continue; |
| 1632 | } |
| 1633 | |
hyatt@apple.com | 7ce0d42 | 2011-08-30 16:57:37 +0000 | [diff] [blame] | 1634 | setLogicalHeight(lineBox->lineBottomWithLeading()); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1635 | } |
commit-queue@webkit.org | be554b2 | 2012-11-26 20:00:49 +0000 | [diff] [blame] | 1636 | |
hyatt@apple.com | fd6f22e | 2013-03-01 21:44:06 +0000 | [diff] [blame] | 1637 | if (layoutState.flowThread()) |
commit-queue@webkit.org | be554b2 | 2012-11-26 20:00:49 +0000 | [diff] [blame] | 1638 | lineBox->setContainingRegion(regionAtBlockOffset(lineBox->lineTopWithLeading())); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1639 | } |
| 1640 | } |
robert@webkit.org | 402c151 | 2013-02-07 18:48:39 +0000 | [diff] [blame] | 1641 | } |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1642 | |
robert@webkit.org | 402c151 | 2013-02-07 18:48:39 +0000 | [diff] [blame] | 1643 | for (size_t i = 0; i < lineBreaker.positionedObjects().size(); ++i) |
| 1644 | setStaticPositions(this, lineBreaker.positionedObjects()[i]); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1645 | |
robert@webkit.org | 402c151 | 2013-02-07 18:48:39 +0000 | [diff] [blame] | 1646 | if (!layoutState.lineInfo().isEmpty()) { |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1647 | layoutState.lineInfo().setFirstLine(false); |
leviw@chromium.org | 1a50869 | 2011-05-05 00:01:11 +0000 | [diff] [blame] | 1648 | newLine(lineBreaker.clear()); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1649 | } |
| 1650 | |
| 1651 | if (m_floatingObjects && lastRootBox()) { |
hyatt@apple.com | 46c65b3 | 2011-08-09 19:13:45 +0000 | [diff] [blame] | 1652 | const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); |
darin@apple.com | 7cad704 | 2013-09-24 05:53:55 +0000 | [diff] [blame] | 1653 | auto it = floatingObjectSet.begin(); |
| 1654 | auto end = floatingObjectSet.end(); |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1655 | if (layoutState.lastFloat()) { |
darin@apple.com | 7cad704 | 2013-09-24 05:53:55 +0000 | [diff] [blame] | 1656 | auto lastFloatIterator = floatingObjectSet.find<FloatingObject&, FloatingObjectHashTranslator>(*layoutState.lastFloat()); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1657 | ASSERT(lastFloatIterator != end); |
| 1658 | ++lastFloatIterator; |
| 1659 | it = lastFloatIterator; |
| 1660 | } |
| 1661 | for (; it != end; ++it) { |
darin@apple.com | 7cad704 | 2013-09-24 05:53:55 +0000 | [diff] [blame] | 1662 | FloatingObject* f = it->get(); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1663 | appendFloatingObjectToLastLine(f); |
darin@apple.com | 7cad704 | 2013-09-24 05:53:55 +0000 | [diff] [blame] | 1664 | ASSERT(&f->renderer() == layoutState.floats()[layoutState.floatIndex()].object); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1665 | // If a float's geometry has changed, give up on syncing with clean lines. |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1666 | if (layoutState.floats()[layoutState.floatIndex()].rect != f->frameRect()) |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1667 | checkForEndLineMatch = false; |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1668 | layoutState.setFloatIndex(layoutState.floatIndex() + 1); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1669 | } |
darin@apple.com | 7cad704 | 2013-09-24 05:53:55 +0000 | [diff] [blame] | 1670 | layoutState.setLastFloat(!floatingObjectSet.isEmpty() ? floatingObjectSet.last().get() : nullptr); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1671 | } |
| 1672 | |
| 1673 | lineMidpointState.reset(); |
rniwa@webkit.org | 53d106b | 2011-11-30 22:33:20 +0000 | [diff] [blame] | 1674 | resolver.setPosition(end, numberOfIsolateAncestors(end)); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1675 | } |
dino@apple.com | fde5fdf | 2012-12-10 21:22:44 +0000 | [diff] [blame] | 1676 | |
abucur@adobe.com | fc49713 | 2013-10-04 08:49:21 +0000 | [diff] [blame^] | 1677 | // In case we already adjusted the line positions during this layout to avoid widows |
| 1678 | // then we need to ignore the possibility of having a new widows situation. |
| 1679 | // Otherwise, we risk leaving empty containers which is against the block fragmentation principles. |
| 1680 | // FIXME-BLOCKFLOW: Remove this type conversion once the owning function moves. |
| 1681 | if (paginated && !style()->hasAutoWidows() && !toRenderBlockFlow(this)->didBreakAtLineToAvoidWidow()) { |
dino@apple.com | fde5fdf | 2012-12-10 21:22:44 +0000 | [diff] [blame] | 1682 | // Check the line boxes to make sure we didn't create unacceptable widows. |
| 1683 | // However, we'll prioritize orphans - so nothing we do here should create |
| 1684 | // a new orphan. |
| 1685 | |
| 1686 | RootInlineBox* lineBox = lastRootBox(); |
| 1687 | |
| 1688 | // Count from the end of the block backwards, to see how many hanging |
| 1689 | // lines we have. |
| 1690 | RootInlineBox* firstLineInBlock = firstRootBox(); |
| 1691 | int numLinesHanging = 1; |
| 1692 | while (lineBox && lineBox != firstLineInBlock && !lineBox->isFirstAfterPageBreak()) { |
| 1693 | ++numLinesHanging; |
| 1694 | lineBox = lineBox->prevRootBox(); |
| 1695 | } |
| 1696 | |
| 1697 | // If there were no breaks in the block, we didn't create any widows. |
jchaffraix@webkit.org | 0f22514 | 2013-01-28 22:28:21 +0000 | [diff] [blame] | 1698 | if (!lineBox || !lineBox->isFirstAfterPageBreak() || lineBox == firstLineInBlock) |
dino@apple.com | fde5fdf | 2012-12-10 21:22:44 +0000 | [diff] [blame] | 1699 | return; |
| 1700 | |
| 1701 | if (numLinesHanging < style()->widows()) { |
| 1702 | // We have detected a widow. Now we need to work out how many |
| 1703 | // lines there are on the previous page, and how many we need |
| 1704 | // to steal. |
| 1705 | int numLinesNeeded = style()->widows() - numLinesHanging; |
| 1706 | RootInlineBox* currentFirstLineOfNewPage = lineBox; |
| 1707 | |
| 1708 | // Count the number of lines in the previous page. |
| 1709 | lineBox = lineBox->prevRootBox(); |
| 1710 | int numLinesInPreviousPage = 1; |
| 1711 | while (lineBox && lineBox != firstLineInBlock && !lineBox->isFirstAfterPageBreak()) { |
| 1712 | ++numLinesInPreviousPage; |
| 1713 | lineBox = lineBox->prevRootBox(); |
| 1714 | } |
| 1715 | |
| 1716 | // If there was an explicit value for orphans, respect that. If not, we still |
| 1717 | // shouldn't create a situation where we make an orphan bigger than the initial value. |
| 1718 | // This means that setting widows implies we also care about orphans, but given |
| 1719 | // the specification says the initial orphan value is non-zero, this is ok. The |
| 1720 | // author is always free to set orphans explicitly as well. |
| 1721 | int orphans = style()->hasAutoOrphans() ? style()->initialOrphans() : style()->orphans(); |
| 1722 | int numLinesAvailable = numLinesInPreviousPage - orphans; |
| 1723 | if (numLinesAvailable <= 0) |
| 1724 | return; |
| 1725 | |
| 1726 | int numLinesToTake = min(numLinesAvailable, numLinesNeeded); |
| 1727 | // Wind back from our first widowed line. |
| 1728 | lineBox = currentFirstLineOfNewPage; |
| 1729 | for (int i = 0; i < numLinesToTake; ++i) |
| 1730 | lineBox = lineBox->prevRootBox(); |
| 1731 | |
| 1732 | // We now want to break at this line. Remember for next layout and trigger relayout. |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 1733 | // FIXME-BLOCKFLOW: Remove this type conversion once the owning function moves. |
| 1734 | toRenderBlockFlow(this)->setBreakAtLineToAvoidWidow(lineCount(lineBox)); |
dino@apple.com | fde5fdf | 2012-12-10 21:22:44 +0000 | [diff] [blame] | 1735 | markLinesDirtyInBlockRange(lastRootBox()->lineBottomWithLeading(), lineBox->lineBottomWithLeading(), lineBox); |
| 1736 | } |
| 1737 | } |
abucur@adobe.com | fc49713 | 2013-10-04 08:49:21 +0000 | [diff] [blame^] | 1738 | |
| 1739 | // FIXME-BLOCKFLOW: Remove this type conversion once the owning function moves. |
| 1740 | toRenderBlockFlow(this)->clearDidBreakAtLineToAvoidWidow(); |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1741 | } |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1742 | |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1743 | void RenderBlock::linkToEndLineIfNeeded(LineLayoutState& layoutState) |
| 1744 | { |
| 1745 | if (layoutState.endLine()) { |
| 1746 | if (layoutState.endLineMatched()) { |
akling@apple.com | 691cf5c | 2013-08-24 16:33:15 +0000 | [diff] [blame] | 1747 | bool paginated = view().layoutState() && view().layoutState()->isPaginated(); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1748 | // Attach all the remaining lines, and then adjust their y-positions as needed. |
eae@chromium.org | ee8613e | 2011-11-12 01:12:58 +0000 | [diff] [blame] | 1749 | LayoutUnit delta = logicalHeight() - layoutState.endLineLogicalTop(); |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1750 | for (RootInlineBox* line = layoutState.endLine(); line; line = line->nextRootBox()) { |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1751 | line->attachLine(); |
| 1752 | if (paginated) { |
| 1753 | delta -= line->paginationStrut(); |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 1754 | // FIXME-BLOCKFLOW: Remove this type conversion once the owning function moves. |
| 1755 | toRenderBlockFlow(this)->adjustLinePositionForPagination(line, delta, layoutState.flowThread()); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1756 | } |
| 1757 | if (delta) { |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1758 | layoutState.updateRepaintRangeFromBox(line, delta); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1759 | line->adjustBlockDirectionPosition(delta); |
| 1760 | } |
hyatt@apple.com | fd6f22e | 2013-03-01 21:44:06 +0000 | [diff] [blame] | 1761 | if (layoutState.flowThread()) |
commit-queue@webkit.org | be554b2 | 2012-11-26 20:00:49 +0000 | [diff] [blame] | 1762 | line->setContainingRegion(regionAtBlockOffset(line->lineTopWithLeading())); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1763 | if (Vector<RenderBox*>* cleanLineFloats = line->floatsPtr()) { |
| 1764 | Vector<RenderBox*>::iterator end = cleanLineFloats->end(); |
| 1765 | for (Vector<RenderBox*>::iterator f = cleanLineFloats->begin(); f != end; ++f) { |
mitz@apple.com | 0c4ce9f | 2011-05-04 02:20:02 +0000 | [diff] [blame] | 1766 | FloatingObject* floatingObject = insertFloatingObject(*f); |
bjonesbe@adobe.com | a9c6666 | 2013-08-14 20:30:14 +0000 | [diff] [blame] | 1767 | ASSERT(!floatingObject->originatingLine()); |
| 1768 | floatingObject->setOriginatingLine(line); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1769 | setLogicalHeight(logicalTopForChild(*f) - marginBeforeForChild(*f) + delta); |
| 1770 | positionNewFloats(); |
| 1771 | } |
| 1772 | } |
| 1773 | } |
hyatt@apple.com | 7ce0d42 | 2011-08-30 16:57:37 +0000 | [diff] [blame] | 1774 | setLogicalHeight(lastRootBox()->lineBottomWithLeading()); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1775 | } else { |
| 1776 | // Delete all the remaining lines. |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1777 | deleteLineRange(layoutState, renderArena(), layoutState.endLine()); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1778 | } |
| 1779 | } |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1780 | |
| 1781 | if (m_floatingObjects && (layoutState.checkForFloatsFromLastLine() || positionNewFloats()) && lastRootBox()) { |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1782 | // In case we have a float on the last line, it might not be positioned up to now. |
| 1783 | // This has to be done before adding in the bottom border/padding, or the float will |
| 1784 | // include the padding incorrectly. -dwh |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1785 | if (layoutState.checkForFloatsFromLastLine()) { |
leviw@chromium.org | d32486e | 2012-03-16 10:52:56 +0000 | [diff] [blame] | 1786 | LayoutUnit bottomVisualOverflow = lastRootBox()->logicalBottomVisualOverflow(); |
| 1787 | LayoutUnit bottomLayoutOverflow = lastRootBox()->logicalBottomLayoutOverflow(); |
akling@apple.com | 0b8172b7 | 2013-08-31 18:34:23 +0000 | [diff] [blame] | 1788 | TrailingFloatsRootInlineBox* trailingFloatsLineBox = new (renderArena()) TrailingFloatsRootInlineBox(*this); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1789 | m_lineBoxes.appendLineBox(trailingFloatsLineBox); |
| 1790 | trailingFloatsLineBox->setConstructed(); |
| 1791 | GlyphOverflowAndFallbackFontsMap textBoxDataMap; |
| 1792 | VerticalPositionCache verticalPositionCache; |
leviw@chromium.org | d32486e | 2012-03-16 10:52:56 +0000 | [diff] [blame] | 1793 | LayoutUnit blockLogicalHeight = logicalHeight(); |
hyatt@apple.com | a8b5b82 | 2011-09-07 18:48:07 +0000 | [diff] [blame] | 1794 | trailingFloatsLineBox->alignBoxesInBlockDirection(blockLogicalHeight, textBoxDataMap, verticalPositionCache); |
| 1795 | trailingFloatsLineBox->setLineTopBottomPositions(blockLogicalHeight, blockLogicalHeight, blockLogicalHeight, blockLogicalHeight); |
hyatt@apple.com | 0c6cd7a | 2011-09-22 20:50:41 +0000 | [diff] [blame] | 1796 | trailingFloatsLineBox->setPaginatedLineWidth(availableLogicalWidthForContent(blockLogicalHeight)); |
leviw@chromium.org | d32486e | 2012-03-16 10:52:56 +0000 | [diff] [blame] | 1797 | LayoutRect logicalLayoutOverflow(0, blockLogicalHeight, 1, bottomLayoutOverflow - blockLogicalHeight); |
| 1798 | LayoutRect logicalVisualOverflow(0, blockLogicalHeight, 1, bottomVisualOverflow - blockLogicalHeight); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1799 | trailingFloatsLineBox->setOverflowFromLogicalRects(logicalLayoutOverflow, logicalVisualOverflow, trailingFloatsLineBox->lineTop(), trailingFloatsLineBox->lineBottom()); |
hyatt@apple.com | fd6f22e | 2013-03-01 21:44:06 +0000 | [diff] [blame] | 1800 | if (layoutState.flowThread()) |
commit-queue@webkit.org | be554b2 | 2012-11-26 20:00:49 +0000 | [diff] [blame] | 1801 | trailingFloatsLineBox->setContainingRegion(regionAtBlockOffset(trailingFloatsLineBox->lineTopWithLeading())); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1802 | } |
| 1803 | |
hyatt@apple.com | 46c65b3 | 2011-08-09 19:13:45 +0000 | [diff] [blame] | 1804 | const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); |
darin@apple.com | 7cad704 | 2013-09-24 05:53:55 +0000 | [diff] [blame] | 1805 | auto it = floatingObjectSet.begin(); |
| 1806 | auto end = floatingObjectSet.end(); |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1807 | if (layoutState.lastFloat()) { |
darin@apple.com | 7cad704 | 2013-09-24 05:53:55 +0000 | [diff] [blame] | 1808 | auto lastFloatIterator = floatingObjectSet.find<FloatingObject&, FloatingObjectHashTranslator>(*layoutState.lastFloat()); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1809 | ASSERT(lastFloatIterator != end); |
| 1810 | ++lastFloatIterator; |
| 1811 | it = lastFloatIterator; |
| 1812 | } |
| 1813 | for (; it != end; ++it) |
darin@apple.com | 7cad704 | 2013-09-24 05:53:55 +0000 | [diff] [blame] | 1814 | appendFloatingObjectToLastLine(it->get()); |
| 1815 | layoutState.setLastFloat(!floatingObjectSet.isEmpty() ? floatingObjectSet.last().get() : nullptr); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1816 | } |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1817 | } |
| 1818 | |
| 1819 | void RenderBlock::repaintDirtyFloats(Vector<FloatWithRect>& floats) |
| 1820 | { |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1821 | size_t floatCount = floats.size(); |
| 1822 | // Floats that did not have layout did not repaint when we laid them out. They would have |
| 1823 | // painted by now if they had moved, but if they stayed at (0, 0), they still need to be |
| 1824 | // painted. |
| 1825 | for (size_t i = 0; i < floatCount; ++i) { |
| 1826 | if (!floats[i].everHadLayout) { |
| 1827 | RenderBox* f = floats[i].object; |
| 1828 | if (!f->x() && !f->y() && f->checkForRepaintDuringLayout()) |
| 1829 | f->repaint(); |
| 1830 | } |
| 1831 | } |
| 1832 | } |
| 1833 | |
hyatt@apple.com | c9b1aef | 2013-09-09 20:23:21 +0000 | [diff] [blame] | 1834 | void RenderBlockFlow::layoutInlineChildren(bool relayoutChildren, LayoutUnit& repaintLogicalTop, LayoutUnit& repaintLogicalBottom) |
jamesr@google.com | 19548ad | 2010-04-02 23:21:35 +0000 | [diff] [blame] | 1835 | { |
zoltan@webkit.org | 8e79cc2 | 2013-06-14 00:39:36 +0000 | [diff] [blame] | 1836 | setLogicalHeight(borderAndPaddingBefore()); |
hyatt@apple.com | ee7af1d | 2012-01-17 19:16:24 +0000 | [diff] [blame] | 1837 | |
| 1838 | // Lay out our hypothetical grid line as though it occurs at the top of the block. |
akling@apple.com | 691cf5c | 2013-08-24 16:33:15 +0000 | [diff] [blame] | 1839 | if (view().layoutState() && view().layoutState()->lineGrid() == this) |
hyatt@apple.com | ee7af1d | 2012-01-17 19:16:24 +0000 | [diff] [blame] | 1840 | layoutLineGridBox(); |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1841 | |
hyatt@apple.com | fd6f22e | 2013-03-01 21:44:06 +0000 | [diff] [blame] | 1842 | RenderFlowThread* flowThread = flowThreadContainingBlock(); |
| 1843 | bool clearLinesForPagination = firstLineBox() && flowThread && !flowThread->hasRegions(); |
commit-queue@webkit.org | 93cdd63 | 2012-12-07 00:33:56 +0000 | [diff] [blame] | 1844 | |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1845 | // Figure out if we should clear out our line boxes. |
| 1846 | // FIXME: Handle resize eventually! |
commit-queue@webkit.org | 93cdd63 | 2012-12-07 00:33:56 +0000 | [diff] [blame] | 1847 | bool isFullLayout = !firstLineBox() || selfNeedsLayout() || relayoutChildren || clearLinesForPagination; |
hyatt@apple.com | fd6f22e | 2013-03-01 21:44:06 +0000 | [diff] [blame] | 1848 | LineLayoutState layoutState(isFullLayout, repaintLogicalTop, repaintLogicalBottom, flowThread); |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1849 | |
| 1850 | if (isFullLayout) |
akling@apple.com | 06262e0 | 2013-09-08 11:02:24 +0000 | [diff] [blame] | 1851 | lineBoxes().deleteLineBoxes(renderArena()); |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1852 | |
commit-queue@webkit.org | 0779731 | 2013-02-22 18:58:19 +0000 | [diff] [blame] | 1853 | // Text truncation kicks in in two cases: |
| 1854 | // 1) If your overflow isn't visible and your text-overflow-mode isn't clip. |
| 1855 | // 2) If you're an anonymous block with a block parent that satisfies #1. |
hyatt | ed77ad8 | 2004-06-15 07:21:23 +0000 | [diff] [blame] | 1856 | // FIXME: CSS3 says that descendants that are clipped must also know how to truncate. This is insanely |
commit-queue@webkit.org | 0779731 | 2013-02-22 18:58:19 +0000 | [diff] [blame] | 1857 | // difficult to figure out in general (especially in the middle of doing layout), so we only handle the |
| 1858 | // simple case of an anonymous block truncating when it's parent is clipped. |
| 1859 | bool hasTextOverflow = (style()->textOverflow() && hasOverflowClip()) |
| 1860 | || (isAnonymousBlock() && parent() && parent()->isRenderBlock() && parent()->style()->textOverflow() && parent()->hasOverflowClip()); |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1861 | |
hyatt | ed77ad8 | 2004-06-15 07:21:23 +0000 | [diff] [blame] | 1862 | // Walk all the lines and delete our ellipsis line boxes if they exist. |
| 1863 | if (hasTextOverflow) |
| 1864 | deleteEllipsisLineBoxes(); |
| 1865 | |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 1866 | if (firstChild()) { |
inferno@chromium.org | 1356312 | 2012-08-16 20:50:05 +0000 | [diff] [blame] | 1867 | // In full layout mode, clear the line boxes of children upfront. Otherwise, |
| 1868 | // siblings can run into stale root lineboxes during layout. Then layout |
| 1869 | // the replaced elements later. In partial layout mode, line boxes are not |
| 1870 | // deleted and only dirtied. In that case, we can layout the replaced |
| 1871 | // elements at the same time. |
abarth@webkit.org | 31d23df | 2010-04-05 21:52:09 +0000 | [diff] [blame] | 1872 | bool hasInlineChild = false; |
inferno@chromium.org | 1356312 | 2012-08-16 20:50:05 +0000 | [diff] [blame] | 1873 | Vector<RenderBox*> replacedChildren; |
eric@webkit.org | 3351047 | 2011-06-04 19:34:29 +0000 | [diff] [blame] | 1874 | for (InlineWalker walker(this); !walker.atEnd(); walker.advance()) { |
| 1875 | RenderObject* o = walker.current(); |
abucur@adobe.com | 33159da | 2013-08-13 07:44:32 +0000 | [diff] [blame] | 1876 | |
commit-queue@webkit.org | cf45df9 | 2010-09-14 13:25:06 +0000 | [diff] [blame] | 1877 | if (!hasInlineChild && o->isInline()) |
| 1878 | hasInlineChild = true; |
| 1879 | |
simon.fraser@apple.com | 2f07185 | 2012-06-25 00:11:30 +0000 | [diff] [blame] | 1880 | if (o->isReplaced() || o->isFloating() || o->isOutOfFlowPositioned()) { |
abarth@webkit.org | 31d23df | 2010-04-05 21:52:09 +0000 | [diff] [blame] | 1881 | RenderBox* box = toRenderBox(o); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1882 | |
commit-queue@webkit.org | b6cbe4f | 2012-02-28 16:01:19 +0000 | [diff] [blame] | 1883 | if (relayoutChildren || box->hasRelativeDimensions()) |
antti@apple.com | ca2a8ff | 2013-10-04 04:04:35 +0000 | [diff] [blame] | 1884 | box->setChildNeedsLayout(MarkOnlyThis); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1885 | |
zimmermann@webkit.org | ac68af4 | 2011-06-15 08:02:37 +0000 | [diff] [blame] | 1886 | // If relayoutChildren is set and the child has percentage padding or an embedded content box, we also need to invalidate the childs pref widths. |
| 1887 | if (relayoutChildren && box->needsPreferredWidthsRecalculation()) |
eric@webkit.org | 218b4e0 | 2012-03-28 19:25:02 +0000 | [diff] [blame] | 1888 | o->setPreferredLogicalWidthsDirty(true, MarkOnlyThis); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1889 | |
simon.fraser@apple.com | 2f07185 | 2012-06-25 00:11:30 +0000 | [diff] [blame] | 1890 | if (o->isOutOfFlowPositioned()) |
abarth@webkit.org | 31d23df | 2010-04-05 21:52:09 +0000 | [diff] [blame] | 1891 | o->containingBlock()->insertPositionedObject(box); |
hyatt@apple.com | cc1737c | 2010-09-16 20:20:02 +0000 | [diff] [blame] | 1892 | else if (o->isFloating()) |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1893 | layoutState.floats().append(FloatWithRect(box)); |
inferno@chromium.org | 1356312 | 2012-08-16 20:50:05 +0000 | [diff] [blame] | 1894 | else if (isFullLayout || o->needsLayout()) { |
| 1895 | // Replaced element. |
| 1896 | box->dirtyLineBoxes(isFullLayout); |
| 1897 | if (isFullLayout) |
| 1898 | replacedChildren.append(box); |
| 1899 | else |
| 1900 | o->layoutIfNeeded(); |
abarth@webkit.org | 31d23df | 2010-04-05 21:52:09 +0000 | [diff] [blame] | 1901 | } |
antti@apple.com | 3014ac0 | 2013-09-18 14:33:55 +0000 | [diff] [blame] | 1902 | } else if (o->isTextOrLineBreak() || (o->isRenderInline() && !walker.atEndOfInline())) { |
antti@apple.com | 9d8157e | 2013-09-17 15:13:37 +0000 | [diff] [blame] | 1903 | if (o->isRenderInline()) |
inferno@chromium.org | 88a424d | 2011-08-09 18:18:36 +0000 | [diff] [blame] | 1904 | toRenderInline(o)->updateAlwaysCreateLineBoxes(layoutState.isFullLayout()); |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1905 | if (layoutState.isFullLayout() || o->selfNeedsLayout()) |
| 1906 | dirtyLineBoxesForRenderer(o, layoutState.isFullLayout()); |
antti@apple.com | ca2a8ff | 2013-10-04 04:04:35 +0000 | [diff] [blame] | 1907 | o->clearNeedsLayout(); |
abarth@webkit.org | 31d23df | 2010-04-05 21:52:09 +0000 | [diff] [blame] | 1908 | } |
abarth@webkit.org | 31d23df | 2010-04-05 21:52:09 +0000 | [diff] [blame] | 1909 | } |
| 1910 | |
inferno@chromium.org | ba2dceb | 2012-08-21 00:09:47 +0000 | [diff] [blame] | 1911 | for (size_t i = 0; i < replacedChildren.size(); i++) |
| 1912 | replacedChildren[i]->layoutIfNeeded(); |
inferno@chromium.org | 1356312 | 2012-08-16 20:50:05 +0000 | [diff] [blame] | 1913 | |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1914 | layoutRunsAndFloats(layoutState, hasInlineChild); |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1915 | } |
hyatt | 85586af | 2003-02-19 23:22:42 +0000 | [diff] [blame] | 1916 | |
mitz@apple.com | 3672d9e | 2010-12-17 19:31:16 +0000 | [diff] [blame] | 1917 | // Expand the last line to accommodate Ruby and emphasis marks. |
| 1918 | int lastLineAnnotationsAdjustment = 0; |
| 1919 | if (lastRootBox()) { |
leviw@chromium.org | d32486e | 2012-03-16 10:52:56 +0000 | [diff] [blame] | 1920 | LayoutUnit lowestAllowedPosition = max(lastRootBox()->lineBottom(), logicalHeight() + paddingAfter()); |
mitz@apple.com | 3672d9e | 2010-12-17 19:31:16 +0000 | [diff] [blame] | 1921 | if (!style()->isFlippedLinesWritingMode()) |
| 1922 | lastLineAnnotationsAdjustment = lastRootBox()->computeUnderAnnotationAdjustment(lowestAllowedPosition); |
| 1923 | else |
| 1924 | lastLineAnnotationsAdjustment = lastRootBox()->computeOverAnnotationAdjustment(lowestAllowedPosition); |
hyatt@apple.com | 5e48ff5 | 2010-11-19 00:43:29 +0000 | [diff] [blame] | 1925 | } |
mitz@apple.com | 3672d9e | 2010-12-17 19:31:16 +0000 | [diff] [blame] | 1926 | |
hyatt | a70560a | 2002-11-20 01:53:20 +0000 | [diff] [blame] | 1927 | // Now add in the bottom border/padding. |
zoltan@webkit.org | 8e79cc2 | 2013-06-14 00:39:36 +0000 | [diff] [blame] | 1928 | setLogicalHeight(logicalHeight() + lastLineAnnotationsAdjustment + borderAndPaddingAfter() + scrollbarLogicalHeight()); |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1929 | |
adele | 7a470a7 | 2006-04-20 22:22:14 +0000 | [diff] [blame] | 1930 | if (!firstLineBox() && hasLineIfEmpty()) |
hyatt@apple.com | 2a5eb21 | 2011-03-22 23:21:54 +0000 | [diff] [blame] | 1931 | setLogicalHeight(logicalHeight() + lineHeight(true, isHorizontalWritingMode() ? HorizontalLine : VerticalLine, PositionOfInteriorLineBoxes)); |
hyatt | ed77ad8 | 2004-06-15 07:21:23 +0000 | [diff] [blame] | 1932 | |
| 1933 | // See if we have any lines that spill out of our block. If we do, then we will possibly need to |
| 1934 | // truncate text. |
| 1935 | if (hasTextOverflow) |
| 1936 | checkLinesForTextOverflow(); |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1937 | } |
| 1938 | |
mitz@apple.com | d9ccfeb | 2011-03-10 01:56:27 +0000 | [diff] [blame] | 1939 | void RenderBlock::checkFloatsInCleanLine(RootInlineBox* line, Vector<FloatWithRect>& floats, size_t& floatIndex, bool& encounteredNewFloat, bool& dirtiedByFloat) |
| 1940 | { |
| 1941 | Vector<RenderBox*>* cleanLineFloats = line->floatsPtr(); |
| 1942 | if (!cleanLineFloats) |
| 1943 | return; |
| 1944 | |
| 1945 | Vector<RenderBox*>::iterator end = cleanLineFloats->end(); |
| 1946 | for (Vector<RenderBox*>::iterator it = cleanLineFloats->begin(); it != end; ++it) { |
| 1947 | RenderBox* floatingBox = *it; |
| 1948 | floatingBox->layoutIfNeeded(); |
tkent@chromium.org | b27646b | 2012-03-08 03:31:25 +0000 | [diff] [blame] | 1949 | LayoutSize newSize(floatingBox->width() + floatingBox->marginWidth(), floatingBox->height() + floatingBox->marginHeight()); |
inferno@chromium.org | a227be6 | 2013-02-11 08:06:45 +0000 | [diff] [blame] | 1950 | ASSERT_WITH_SECURITY_IMPLICATION(floatIndex < floats.size()); |
mitz@apple.com | d9ccfeb | 2011-03-10 01:56:27 +0000 | [diff] [blame] | 1951 | if (floats[floatIndex].object != floatingBox) { |
| 1952 | encounteredNewFloat = true; |
| 1953 | return; |
| 1954 | } |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1955 | |
mitz@apple.com | d9ccfeb | 2011-03-10 01:56:27 +0000 | [diff] [blame] | 1956 | if (floats[floatIndex].rect.size() != newSize) { |
eae@chromium.org | ee8613e | 2011-11-12 01:12:58 +0000 | [diff] [blame] | 1957 | LayoutUnit floatTop = isHorizontalWritingMode() ? floats[floatIndex].rect.y() : floats[floatIndex].rect.x(); |
| 1958 | LayoutUnit floatHeight = isHorizontalWritingMode() ? max(floats[floatIndex].rect.height(), newSize.height()) |
mitz@apple.com | d9ccfeb | 2011-03-10 01:56:27 +0000 | [diff] [blame] | 1959 | : max(floats[floatIndex].rect.width(), newSize.width()); |
eae@chromium.org | 9717cd8 | 2012-11-07 18:33:44 +0000 | [diff] [blame] | 1960 | floatHeight = min(floatHeight, LayoutUnit::max() - floatTop); |
mitz@apple.com | d9ccfeb | 2011-03-10 01:56:27 +0000 | [diff] [blame] | 1961 | line->markDirty(); |
hyatt@apple.com | 7ce0d42 | 2011-08-30 16:57:37 +0000 | [diff] [blame] | 1962 | markLinesDirtyInBlockRange(line->lineBottomWithLeading(), floatTop + floatHeight, line); |
mitz@apple.com | d9ccfeb | 2011-03-10 01:56:27 +0000 | [diff] [blame] | 1963 | floats[floatIndex].rect.setSize(newSize); |
| 1964 | dirtiedByFloat = true; |
| 1965 | } |
| 1966 | floatIndex++; |
| 1967 | } |
| 1968 | } |
| 1969 | |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1970 | RootInlineBox* RenderBlock::determineStartPosition(LineLayoutState& layoutState, InlineBidiResolver& resolver) |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1971 | { |
| 1972 | RootInlineBox* curr = 0; |
| 1973 | RootInlineBox* last = 0; |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1974 | |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1975 | // FIXME: This entire float-checking block needs to be broken into a new function. |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 1976 | bool dirtiedByFloat = false; |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1977 | if (!layoutState.isFullLayout()) { |
hyatt@apple.com | cc1737c | 2010-09-16 20:20:02 +0000 | [diff] [blame] | 1978 | // Paginate all of the clean lines. |
akling@apple.com | 691cf5c | 2013-08-24 16:33:15 +0000 | [diff] [blame] | 1979 | bool paginated = view().layoutState() && view().layoutState()->isPaginated(); |
eae@chromium.org | ee8613e | 2011-11-12 01:12:58 +0000 | [diff] [blame] | 1980 | LayoutUnit paginationDelta = 0; |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 1981 | size_t floatIndex = 0; |
| 1982 | for (curr = firstRootBox(); curr && !curr->isDirty(); curr = curr->nextRootBox()) { |
hyatt@apple.com | cc1737c | 2010-09-16 20:20:02 +0000 | [diff] [blame] | 1983 | if (paginated) { |
hyatt@apple.com | fd6f22e | 2013-03-01 21:44:06 +0000 | [diff] [blame] | 1984 | if (lineWidthForPaginatedLineChanged(curr, 0, layoutState.flowThread())) { |
hyatt@apple.com | 0c6cd7a | 2011-09-22 20:50:41 +0000 | [diff] [blame] | 1985 | curr->markDirty(); |
| 1986 | break; |
| 1987 | } |
hyatt@apple.com | cc1737c | 2010-09-16 20:20:02 +0000 | [diff] [blame] | 1988 | paginationDelta -= curr->paginationStrut(); |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 1989 | // FIXME-BLOCKFLOW: Remove this type conversion once the owning function moves. |
| 1990 | toRenderBlockFlow(this)->adjustLinePositionForPagination(curr, paginationDelta, layoutState.flowThread()); |
hyatt@apple.com | cc1737c | 2010-09-16 20:20:02 +0000 | [diff] [blame] | 1991 | if (paginationDelta) { |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1992 | if (containsFloats() || !layoutState.floats().isEmpty()) { |
hyatt@apple.com | cc1737c | 2010-09-16 20:20:02 +0000 | [diff] [blame] | 1993 | // FIXME: Do better eventually. For now if we ever shift because of pagination and floats are present just go to a full layout. |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1994 | layoutState.markForFullLayout(); |
hyatt@apple.com | cc1737c | 2010-09-16 20:20:02 +0000 | [diff] [blame] | 1995 | break; |
| 1996 | } |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1997 | |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1998 | layoutState.updateRepaintRangeFromBox(curr, paginationDelta); |
hyatt@apple.com | 61bbedf | 2011-01-26 23:10:57 +0000 | [diff] [blame] | 1999 | curr->adjustBlockDirectionPosition(paginationDelta); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 2000 | } |
hyatt@apple.com | fd6f22e | 2013-03-01 21:44:06 +0000 | [diff] [blame] | 2001 | if (layoutState.flowThread()) |
commit-queue@webkit.org | be554b2 | 2012-11-26 20:00:49 +0000 | [diff] [blame] | 2002 | curr->setContainingRegion(regionAtBlockOffset(curr->lineTopWithLeading())); |
hyatt@apple.com | cc1737c | 2010-09-16 20:20:02 +0000 | [diff] [blame] | 2003 | } |
mitz@apple.com | d9ccfeb | 2011-03-10 01:56:27 +0000 | [diff] [blame] | 2004 | |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 2005 | // If a new float has been inserted before this line or before its last known float, just do a full layout. |
| 2006 | bool encounteredNewFloat = false; |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 2007 | checkFloatsInCleanLine(curr, layoutState.floats(), floatIndex, encounteredNewFloat, dirtiedByFloat); |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 2008 | if (encounteredNewFloat) |
| 2009 | layoutState.markForFullLayout(); |
| 2010 | |
| 2011 | if (dirtiedByFloat || layoutState.isFullLayout()) |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 2012 | break; |
| 2013 | } |
| 2014 | // Check if a new float has been inserted after the last known float. |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 2015 | if (!curr && floatIndex < layoutState.floats().size()) |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 2016 | layoutState.markForFullLayout(); |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 2017 | } |
| 2018 | |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 2019 | if (layoutState.isFullLayout()) { |
igor.o@sisa.samsung.com | f6a57df | 2013-04-15 21:25:35 +0000 | [diff] [blame] | 2020 | m_lineBoxes.deleteLineBoxTree(renderArena()); |
| 2021 | curr = 0; |
| 2022 | |
eric@webkit.org | e2532d9 | 2011-05-16 23:10:49 +0000 | [diff] [blame] | 2023 | ASSERT(!firstLineBox() && !lastLineBox()); |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 2024 | } else { |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 2025 | if (curr) { |
| 2026 | // We have a dirty line. |
mjs | 9f78dd9 | 2007-02-12 04:06:07 +0000 | [diff] [blame] | 2027 | if (RootInlineBox* prevRootBox = curr->prevRootBox()) { |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 2028 | // We have a previous line. |
tasak@google.com | fcfd96f | 2012-11-26 07:45:38 +0000 | [diff] [blame] | 2029 | if (!dirtiedByFloat && (!prevRootBox->endsWithBreak() || !prevRootBox->lineBreakObj() || (prevRootBox->lineBreakObj()->isText() && prevRootBox->lineBreakPos() >= toRenderText(prevRootBox->lineBreakObj())->textLength()))) |
mjs | 9f78dd9 | 2007-02-12 04:06:07 +0000 | [diff] [blame] | 2030 | // The previous line didn't break cleanly or broke at a newline |
| 2031 | // that has been deleted, so treat it as dirty too. |
| 2032 | curr = prevRootBox; |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 2033 | } |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 2034 | } else { |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 2035 | // No dirty lines were found. |
| 2036 | // If the last line didn't break cleanly, treat it as dirty. |
| 2037 | if (lastRootBox() && !lastRootBox()->endsWithBreak()) |
| 2038 | curr = lastRootBox(); |
| 2039 | } |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 2040 | |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 2041 | // If we have no dirty lines, then last is just the last root box. |
| 2042 | last = curr ? curr->prevRootBox() : lastRootBox(); |
| 2043 | } |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 2044 | |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 2045 | unsigned numCleanFloats = 0; |
| 2046 | if (!layoutState.floats().isEmpty()) { |
eae@chromium.org | ee8613e | 2011-11-12 01:12:58 +0000 | [diff] [blame] | 2047 | LayoutUnit savedLogicalHeight = logicalHeight(); |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 2048 | // Restore floats from clean lines. |
| 2049 | RootInlineBox* line = firstRootBox(); |
| 2050 | while (line != curr) { |
hyatt@apple.com | d885df7 | 2009-01-22 02:31:52 +0000 | [diff] [blame] | 2051 | if (Vector<RenderBox*>* cleanLineFloats = line->floatsPtr()) { |
| 2052 | Vector<RenderBox*>::iterator end = cleanLineFloats->end(); |
| 2053 | for (Vector<RenderBox*>::iterator f = cleanLineFloats->begin(); f != end; ++f) { |
mitz@apple.com | 0c4ce9f | 2011-05-04 02:20:02 +0000 | [diff] [blame] | 2054 | FloatingObject* floatingObject = insertFloatingObject(*f); |
bjonesbe@adobe.com | a9c6666 | 2013-08-14 20:30:14 +0000 | [diff] [blame] | 2055 | ASSERT(!floatingObject->originatingLine()); |
| 2056 | floatingObject->setOriginatingLine(line); |
hyatt@apple.com | 9a2e7d2 | 2010-10-06 22:13:31 +0000 | [diff] [blame] | 2057 | setLogicalHeight(logicalTopForChild(*f) - marginBeforeForChild(*f)); |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 2058 | positionNewFloats(); |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 2059 | ASSERT(layoutState.floats()[numCleanFloats].object == *f); |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 2060 | numCleanFloats++; |
| 2061 | } |
| 2062 | } |
| 2063 | line = line->nextRootBox(); |
| 2064 | } |
hyatt@apple.com | 9a2e7d2 | 2010-10-06 22:13:31 +0000 | [diff] [blame] | 2065 | setLogicalHeight(savedLogicalHeight); |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 2066 | } |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 2067 | layoutState.setFloatIndex(numCleanFloats); |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 2068 | |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 2069 | layoutState.lineInfo().setFirstLine(!last); |
| 2070 | layoutState.lineInfo().setPreviousLineBrokeCleanly(!last || last->endsWithBreak()); |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 2071 | |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 2072 | if (last) { |
hyatt@apple.com | 7ce0d42 | 2011-08-30 16:57:37 +0000 | [diff] [blame] | 2073 | setLogicalHeight(last->lineBottomWithLeading()); |
rniwa@webkit.org | 53d106b | 2011-11-30 22:33:20 +0000 | [diff] [blame] | 2074 | InlineIterator iter = InlineIterator(this, last->lineBreakObj(), last->lineBreakPos()); |
| 2075 | resolver.setPosition(iter, numberOfIsolateAncestors(iter)); |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 2076 | resolver.setStatus(last->lineBreakBidiStatus()); |
darin | dde0150 | 2005-12-18 22:55:35 +0000 | [diff] [blame] | 2077 | } else { |
leviw@chromium.org | 7781b6a | 2011-06-27 22:01:38 +0000 | [diff] [blame] | 2078 | TextDirection direction = style()->direction(); |
leviw@chromium.org | e7812f3 | 2012-02-07 23:46:40 +0000 | [diff] [blame] | 2079 | if (style()->unicodeBidi() == Plaintext) |
| 2080 | determineDirectionality(direction, InlineIterator(this, bidiFirstSkippingEmptyInlines(this), 0)); |
rniwa@webkit.org | c275acf | 2012-03-05 23:09:22 +0000 | [diff] [blame] | 2081 | resolver.setStatus(BidiStatus(direction, isOverride(style()->unicodeBidi()))); |
rniwa@webkit.org | 53d106b | 2011-11-30 22:33:20 +0000 | [diff] [blame] | 2082 | InlineIterator iter = InlineIterator(this, bidiFirstSkippingEmptyInlines(this, &resolver), 0); |
| 2083 | resolver.setPosition(iter, numberOfIsolateAncestors(iter)); |
darin | dde0150 | 2005-12-18 22:55:35 +0000 | [diff] [blame] | 2084 | } |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 2085 | return curr; |
| 2086 | } |
| 2087 | |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 2088 | void RenderBlock::determineEndPosition(LineLayoutState& layoutState, RootInlineBox* startLine, InlineIterator& cleanLineStart, BidiStatus& cleanLineBidiStatus) |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 2089 | { |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 2090 | ASSERT(!layoutState.endLine()); |
| 2091 | size_t floatIndex = layoutState.floatIndex(); |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 2092 | RootInlineBox* last = 0; |
mitz@apple.com | d9ccfeb | 2011-03-10 01:56:27 +0000 | [diff] [blame] | 2093 | for (RootInlineBox* curr = startLine->nextRootBox(); curr; curr = curr->nextRootBox()) { |
| 2094 | if (!curr->isDirty()) { |
| 2095 | bool encounteredNewFloat = false; |
| 2096 | bool dirtiedByFloat = false; |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 2097 | checkFloatsInCleanLine(curr, layoutState.floats(), floatIndex, encounteredNewFloat, dirtiedByFloat); |
mitz@apple.com | d9ccfeb | 2011-03-10 01:56:27 +0000 | [diff] [blame] | 2098 | if (encounteredNewFloat) |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 2099 | return; |
hyatt | 04420ca | 2004-07-16 00:05:42 +0000 | [diff] [blame] | 2100 | } |
mitz@apple.com | d9ccfeb | 2011-03-10 01:56:27 +0000 | [diff] [blame] | 2101 | if (curr->isDirty()) |
| 2102 | last = 0; |
| 2103 | else if (!last) |
| 2104 | last = curr; |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 2105 | } |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 2106 | |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 2107 | if (!last) |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 2108 | return; |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 2109 | |
mitz@apple.com | d9ccfeb | 2011-03-10 01:56:27 +0000 | [diff] [blame] | 2110 | // At this point, |last| is the first line in a run of clean lines that ends with the last line |
| 2111 | // in the block. |
| 2112 | |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 2113 | RootInlineBox* prev = last->prevRootBox(); |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 2114 | cleanLineStart = InlineIterator(this, prev->lineBreakObj(), prev->lineBreakPos()); |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 2115 | cleanLineBidiStatus = prev->lineBreakBidiStatus(); |
hyatt@apple.com | 7ce0d42 | 2011-08-30 16:57:37 +0000 | [diff] [blame] | 2116 | layoutState.setEndLineLogicalTop(prev->lineBottomWithLeading()); |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 2117 | |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 2118 | for (RootInlineBox* line = last; line; line = line->nextRootBox()) |
| 2119 | line->extractLine(); // Disconnect all line boxes from their render objects while preserving |
| 2120 | // their connections to one another. |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 2121 | |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 2122 | layoutState.setEndLine(last); |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 2123 | } |
| 2124 | |
hyatt@apple.com | a10d30e | 2011-09-22 22:28:21 +0000 | [diff] [blame] | 2125 | bool RenderBlock::checkPaginationAndFloatsAtEndLine(LineLayoutState& layoutState) |
| 2126 | { |
| 2127 | LayoutUnit lineDelta = logicalHeight() - layoutState.endLineLogicalTop(); |
| 2128 | |
akling@apple.com | 691cf5c | 2013-08-24 16:33:15 +0000 | [diff] [blame] | 2129 | bool paginated = view().layoutState() && view().layoutState()->isPaginated(); |
hyatt@apple.com | fd6f22e | 2013-03-01 21:44:06 +0000 | [diff] [blame] | 2130 | if (paginated && layoutState.flowThread()) { |
hyatt@apple.com | a10d30e | 2011-09-22 22:28:21 +0000 | [diff] [blame] | 2131 | // Check all lines from here to the end, and see if the hypothetical new position for the lines will result |
| 2132 | // in a different available line width. |
| 2133 | for (RootInlineBox* lineBox = layoutState.endLine(); lineBox; lineBox = lineBox->nextRootBox()) { |
| 2134 | if (paginated) { |
| 2135 | // This isn't the real move we're going to do, so don't update the line box's pagination |
| 2136 | // strut yet. |
| 2137 | LayoutUnit oldPaginationStrut = lineBox->paginationStrut(); |
| 2138 | lineDelta -= oldPaginationStrut; |
hyatt@apple.com | 2ea5988 | 2013-09-17 16:41:42 +0000 | [diff] [blame] | 2139 | // FIXME-BLOCKFLOW: Remove this type conversion once the owning function moves. |
| 2140 | toRenderBlockFlow(this)->adjustLinePositionForPagination(lineBox, lineDelta, layoutState.flowThread()); |
hyatt@apple.com | a10d30e | 2011-09-22 22:28:21 +0000 | [diff] [blame] | 2141 | lineBox->setPaginationStrut(oldPaginationStrut); |
| 2142 | } |
hyatt@apple.com | fd6f22e | 2013-03-01 21:44:06 +0000 | [diff] [blame] | 2143 | if (lineWidthForPaginatedLineChanged(lineBox, lineDelta, layoutState.flowThread())) |
hyatt@apple.com | a10d30e | 2011-09-22 22:28:21 +0000 | [diff] [blame] | 2144 | return false; |
| 2145 | } |
| 2146 | } |
| 2147 | |
| 2148 | if (!lineDelta || !m_floatingObjects) |
| 2149 | return true; |
| 2150 | |
| 2151 | // See if any floats end in the range along which we want to shift the lines vertically. |
eae@chromium.org | ee8613e | 2011-11-12 01:12:58 +0000 | [diff] [blame] | 2152 | LayoutUnit logicalTop = min(logicalHeight(), layoutState.endLineLogicalTop()); |
hyatt@apple.com | a10d30e | 2011-09-22 22:28:21 +0000 | [diff] [blame] | 2153 | |
| 2154 | RootInlineBox* lastLine = layoutState.endLine(); |
| 2155 | while (RootInlineBox* nextLine = lastLine->nextRootBox()) |
| 2156 | lastLine = nextLine; |
| 2157 | |
leviw@chromium.org | 3957b45 | 2012-05-01 00:06:37 +0000 | [diff] [blame] | 2158 | LayoutUnit logicalBottom = lastLine->lineBottomWithLeading() + absoluteValue(lineDelta); |
hyatt@apple.com | a10d30e | 2011-09-22 22:28:21 +0000 | [diff] [blame] | 2159 | |
| 2160 | const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); |
darin@apple.com | 7cad704 | 2013-09-24 05:53:55 +0000 | [diff] [blame] | 2161 | auto end = floatingObjectSet.end(); |
| 2162 | for (auto it = floatingObjectSet.begin(); it != end; ++it) { |
| 2163 | FloatingObject* f = it->get(); |
bjonesbe@adobe.com | 93de7e7 | 2013-09-04 18:01:27 +0000 | [diff] [blame] | 2164 | if (f->logicalBottom(isHorizontalWritingMode()) >= logicalTop && f->logicalBottom(isHorizontalWritingMode()) < logicalBottom) |
hyatt@apple.com | a10d30e | 2011-09-22 22:28:21 +0000 | [diff] [blame] | 2165 | return false; |
| 2166 | } |
| 2167 | |
| 2168 | return true; |
| 2169 | } |
| 2170 | |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 2171 | bool RenderBlock::matchedEndLine(LineLayoutState& layoutState, const InlineBidiResolver& resolver, const InlineIterator& endLineStart, const BidiStatus& endLineStatus) |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 2172 | { |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 2173 | if (resolver.position() == endLineStart) { |
| 2174 | if (resolver.status() != endLineStatus) |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 2175 | return false; |
hyatt@apple.com | a10d30e | 2011-09-22 22:28:21 +0000 | [diff] [blame] | 2176 | return checkPaginationAndFloatsAtEndLine(layoutState); |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 2177 | } |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 2178 | |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 2179 | // The first clean line doesn't match, but we can check a handful of following lines to try |
| 2180 | // to match back up. |
| 2181 | static int numLines = 8; // The # of lines we're willing to match against. |
hyatt@apple.com | a10d30e | 2011-09-22 22:28:21 +0000 | [diff] [blame] | 2182 | RootInlineBox* originalEndLine = layoutState.endLine(); |
| 2183 | RootInlineBox* line = originalEndLine; |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 2184 | for (int i = 0; i < numLines && line; i++, line = line->nextRootBox()) { |
eric@webkit.org | 86a865a | 2011-03-29 15:30:41 +0000 | [diff] [blame] | 2185 | if (line->lineBreakObj() == resolver.position().m_obj && line->lineBreakPos() == resolver.position().m_pos) { |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 2186 | // We have a match. |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 2187 | if (line->lineBreakBidiStatus() != resolver.status()) |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 2188 | return false; // ...but the bidi state doesn't match. |
hyatt@apple.com | a10d30e | 2011-09-22 22:28:21 +0000 | [diff] [blame] | 2189 | |
| 2190 | bool matched = false; |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 2191 | RootInlineBox* result = line->nextRootBox(); |
hyatt@apple.com | 1fb7d58 | 2011-09-23 20:25:11 +0000 | [diff] [blame] | 2192 | layoutState.setEndLine(result); |
hyatt@apple.com | a10d30e | 2011-09-22 22:28:21 +0000 | [diff] [blame] | 2193 | if (result) { |
hyatt@apple.com | 7ce0d42 | 2011-08-30 16:57:37 +0000 | [diff] [blame] | 2194 | layoutState.setEndLineLogicalTop(line->lineBottomWithLeading()); |
hyatt@apple.com | a10d30e | 2011-09-22 22:28:21 +0000 | [diff] [blame] | 2195 | matched = checkPaginationAndFloatsAtEndLine(layoutState); |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 2196 | } |
| 2197 | |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 2198 | // Now delete the lines that we failed to sync. |
hyatt@apple.com | a10d30e | 2011-09-22 22:28:21 +0000 | [diff] [blame] | 2199 | deleteLineRange(layoutState, renderArena(), originalEndLine, result); |
| 2200 | return matched; |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 2201 | } |
| 2202 | } |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 2203 | |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 2204 | return false; |
| 2205 | } |
| 2206 | |
leviw@chromium.org | f009c8e | 2011-05-03 20:49:15 +0000 | [diff] [blame] | 2207 | static inline bool skipNonBreakingSpace(const InlineIterator& it, const LineInfo& lineInfo) |
kocienda | 9844008 | 2004-10-14 23:51:47 +0000 | [diff] [blame] | 2208 | { |
eric@webkit.org | 8c25a59 | 2011-03-29 13:18:11 +0000 | [diff] [blame] | 2209 | if (it.m_obj->style()->nbspMode() != SPACE || it.current() != noBreakSpace) |
kocienda | 9844008 | 2004-10-14 23:51:47 +0000 | [diff] [blame] | 2210 | return false; |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 2211 | |
hyatt | dca76e9 | 2005-11-02 08:52:50 +0000 | [diff] [blame] | 2212 | // FIXME: This is bad. It makes nbsp inconsistent with space and won't work correctly |
| 2213 | // with m_minWidth/m_maxWidth. |
kocienda | 498d198 | 2004-10-15 21:07:24 +0000 | [diff] [blame] | 2214 | // Do not skip a non-breaking space if it is the first character |
hyatt | dca76e9 | 2005-11-02 08:52:50 +0000 | [diff] [blame] | 2215 | // on a line after a clean line break (or on the first line, since previousLineBrokeCleanly starts off |
| 2216 | // |true|). |
leviw@chromium.org | f009c8e | 2011-05-03 20:49:15 +0000 | [diff] [blame] | 2217 | if (lineInfo.isEmpty() && lineInfo.previousLineBrokeCleanly()) |
kocienda | 498d198 | 2004-10-15 21:07:24 +0000 | [diff] [blame] | 2218 | return false; |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 2219 | |
kocienda | 498d198 | 2004-10-15 21:07:24 +0000 | [diff] [blame] | 2220 | return true; |
kocienda | 9844008 | 2004-10-14 23:51:47 +0000 | [diff] [blame] | 2221 | } |
| 2222 | |
rniwa@webkit.org | 4024842 | 2011-06-15 00:19:39 +0000 | [diff] [blame] | 2223 | enum WhitespacePosition { LeadingWhitespace, TrailingWhitespace }; |
| 2224 | static inline bool shouldCollapseWhiteSpace(const RenderStyle* style, const LineInfo& lineInfo, WhitespacePosition whitespacePosition) |
hyatt | d995321 | 2005-11-03 21:05:59 +0000 | [diff] [blame] | 2225 | { |
rniwa@webkit.org | 4024842 | 2011-06-15 00:19:39 +0000 | [diff] [blame] | 2226 | // CSS2 16.6.1 |
| 2227 | // If a space (U+0020) at the beginning of a line has 'white-space' set to 'normal', 'nowrap', or 'pre-line', it is removed. |
| 2228 | // If a space (U+0020) at the end of a line has 'white-space' set to 'normal', 'nowrap', or 'pre-line', it is also removed. |
| 2229 | // If spaces (U+0020) or tabs (U+0009) at the end of a line have 'white-space' set to 'pre-wrap', UAs may visually collapse them. |
| 2230 | return style->collapseWhiteSpace() |
| 2231 | || (whitespacePosition == TrailingWhitespace && style->whiteSpace() == PRE_WRAP && (!lineInfo.isEmpty() || !lineInfo.previousLineBrokeCleanly())); |
hyatt | d995321 | 2005-11-03 21:05:59 +0000 | [diff] [blame] | 2232 | } |
| 2233 | |
antti@apple.com | 3ab7ef3 | 2013-09-29 20:50:01 +0000 | [diff] [blame] | 2234 | static bool requiresLineBoxForContent(const RenderInline& flow, const LineInfo& lineInfo) |
robert@webkit.org | 56e5a9f | 2012-02-17 21:10:42 +0000 | [diff] [blame] | 2235 | { |
antti@apple.com | 3ab7ef3 | 2013-09-29 20:50:01 +0000 | [diff] [blame] | 2236 | RenderElement* parent = flow.parent(); |
| 2237 | if (flow.document().inNoQuirksMode()) { |
| 2238 | const RenderStyle& flowStyle = lineStyle(flow, lineInfo); |
antti@apple.com | b0608f6 | 2013-09-28 18:30:16 +0000 | [diff] [blame] | 2239 | const RenderStyle& parentStyle = lineStyle(*parent, lineInfo); |
| 2240 | if (flowStyle.lineHeight() != parentStyle.lineHeight() |
| 2241 | || flowStyle.verticalAlign() != parentStyle.verticalAlign() |
| 2242 | || !parentStyle.font().fontMetrics().hasIdenticalAscentDescentAndLineGap(flowStyle.font().fontMetrics())) |
robert@webkit.org | 56e5a9f | 2012-02-17 21:10:42 +0000 | [diff] [blame] | 2243 | return true; |
antti@apple.com | b0608f6 | 2013-09-28 18:30:16 +0000 | [diff] [blame] | 2244 | } |
robert@webkit.org | 56e5a9f | 2012-02-17 21:10:42 +0000 | [diff] [blame] | 2245 | return false; |
| 2246 | } |
| 2247 | |
antti@apple.com | 3ab7ef3 | 2013-09-29 20:50:01 +0000 | [diff] [blame] | 2248 | static bool hasInlineDirectionBordersPaddingOrMargin(const RenderInline& flow) |
robert@webkit.org | 19a9434 | 2013-04-10 18:56:36 +0000 | [diff] [blame] | 2249 | { |
| 2250 | // Where an empty inline is split across anonymous blocks we should only give lineboxes to the 'sides' of the |
| 2251 | // inline that have borders, padding or margin. |
antti@apple.com | 3ab7ef3 | 2013-09-29 20:50:01 +0000 | [diff] [blame] | 2252 | bool shouldApplyStartBorderPaddingOrMargin = !flow.parent()->isAnonymousBlock() || !flow.isInlineElementContinuation(); |
| 2253 | if (shouldApplyStartBorderPaddingOrMargin && (flow.borderStart() || flow.marginStart() || flow.paddingStart())) |
robert@webkit.org | 19a9434 | 2013-04-10 18:56:36 +0000 | [diff] [blame] | 2254 | return true; |
| 2255 | |
antti@apple.com | 3ab7ef3 | 2013-09-29 20:50:01 +0000 | [diff] [blame] | 2256 | bool shouldApplyEndBorderPaddingOrMargin = !flow.parent()->isAnonymousBlock() || flow.isInlineElementContinuation() || !flow.inlineElementContinuation(); |
| 2257 | return shouldApplyEndBorderPaddingOrMargin && (flow.borderEnd() || flow.marginEnd() || flow.paddingEnd()); |
robert@webkit.org | 19a9434 | 2013-04-10 18:56:36 +0000 | [diff] [blame] | 2258 | } |
| 2259 | |
antti@apple.com | 3ab7ef3 | 2013-09-29 20:50:01 +0000 | [diff] [blame] | 2260 | static bool alwaysRequiresLineBox(const RenderInline& flow) |
bdakin | f876bee | 2007-10-30 05:27:09 +0000 | [diff] [blame] | 2261 | { |
| 2262 | // FIXME: Right now, we only allow line boxes for inlines that are truly empty. |
hyatt@apple.com | eb66ef4 | 2008-01-18 22:59:29 +0000 | [diff] [blame] | 2263 | // We need to fix this, though, because at the very least, inlines containing only |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 2264 | // ignorable whitespace should should also have line boxes. |
antti@apple.com | 3ab7ef3 | 2013-09-29 20:50:01 +0000 | [diff] [blame] | 2265 | return isEmptyInline(flow) && hasInlineDirectionBordersPaddingOrMargin(flow); |
bdakin | f876bee | 2007-10-30 05:27:09 +0000 | [diff] [blame] | 2266 | } |
| 2267 | |
rniwa@webkit.org | 4024842 | 2011-06-15 00:19:39 +0000 | [diff] [blame] | 2268 | static bool requiresLineBox(const InlineIterator& it, const LineInfo& lineInfo = LineInfo(), WhitespacePosition whitespacePosition = LeadingWhitespace) |
bdash | ccffb43 | 2007-07-13 11:51:40 +0000 | [diff] [blame] | 2269 | { |
simon.fraser@apple.com | 2f07185 | 2012-06-25 00:11:30 +0000 | [diff] [blame] | 2270 | if (it.m_obj->isFloatingOrOutOfFlowPositioned()) |
bdash | ccffb43 | 2007-07-13 11:51:40 +0000 | [diff] [blame] | 2271 | return false; |
bdakin | f876bee | 2007-10-30 05:27:09 +0000 | [diff] [blame] | 2272 | |
antti@apple.com | 9d8157e | 2013-09-17 15:13:37 +0000 | [diff] [blame] | 2273 | if (it.m_obj->isBR()) |
| 2274 | return true; |
| 2275 | |
antti@apple.com | 3ab7ef3 | 2013-09-29 20:50:01 +0000 | [diff] [blame] | 2276 | bool rendererIsEmptyInline = false; |
| 2277 | if (it.m_obj->isRenderInline()) { |
| 2278 | const RenderInline& inlineRenderer = toRenderInline(*it.m_obj); |
| 2279 | if (!alwaysRequiresLineBox(inlineRenderer) && !requiresLineBoxForContent(inlineRenderer, lineInfo)) |
| 2280 | return false; |
| 2281 | rendererIsEmptyInline = isEmptyInline(inlineRenderer); |
| 2282 | } |
bdakin | f876bee | 2007-10-30 05:27:09 +0000 | [diff] [blame] | 2283 | |
antti@apple.com | 9d8157e | 2013-09-17 15:13:37 +0000 | [diff] [blame] | 2284 | if (!shouldCollapseWhiteSpace(it.m_obj->style(), lineInfo, whitespacePosition)) |
bdash | ccffb43 | 2007-07-13 11:51:40 +0000 | [diff] [blame] | 2285 | return true; |
| 2286 | |
| 2287 | UChar current = it.current(); |
robert@webkit.org | 2b307a7 | 2013-01-24 18:46:11 +0000 | [diff] [blame] | 2288 | bool notJustWhitespace = current != ' ' && current != '\t' && current != softHyphen && (current != '\n' || it.m_obj->preservesNewline()) && !skipNonBreakingSpace(it, lineInfo); |
antti@apple.com | 3ab7ef3 | 2013-09-29 20:50:01 +0000 | [diff] [blame] | 2289 | return notJustWhitespace || rendererIsEmptyInline; |
bdash | ccffb43 | 2007-07-13 11:51:40 +0000 | [diff] [blame] | 2290 | } |
| 2291 | |
leviw@chromium.org | f009c8e | 2011-05-03 20:49:15 +0000 | [diff] [blame] | 2292 | bool RenderBlock::generatesLineBoxesForInlineChild(RenderObject* inlineObj) |
bdash | ccffb43 | 2007-07-13 11:51:40 +0000 | [diff] [blame] | 2293 | { |
| 2294 | ASSERT(inlineObj->parent() == this); |
| 2295 | |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 2296 | InlineIterator it(this, inlineObj, 0); |
rniwa@webkit.org | 4024842 | 2011-06-15 00:19:39 +0000 | [diff] [blame] | 2297 | // FIXME: We should pass correct value for WhitespacePosition. |
leviw@chromium.org | f009c8e | 2011-05-03 20:49:15 +0000 | [diff] [blame] | 2298 | while (!it.atEnd() && !requiresLineBox(it)) |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 2299 | it.increment(); |
bdash | ccffb43 | 2007-07-13 11:51:40 +0000 | [diff] [blame] | 2300 | |
| 2301 | return !it.atEnd(); |
| 2302 | } |
| 2303 | |
mitz@apple.com | bf6e8d3 | 2008-07-25 20:21:06 +0000 | [diff] [blame] | 2304 | // FIXME: The entire concept of the skipTrailingWhitespace function is flawed, since we really need to be building |
leviw@chromium.org | 1a50869 | 2011-05-05 00:01:11 +0000 | [diff] [blame] | 2305 | // line boxes even for containers that may ultimately collapse away. Otherwise we'll never get positioned |
| 2306 | // elements quite right. In other words, we need to build this function's work into the normal line |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 2307 | // object iteration process. |
mitz@apple.com | bf6e8d3 | 2008-07-25 20:21:06 +0000 | [diff] [blame] | 2308 | // NB. this function will insert any floating elements that would otherwise |
| 2309 | // be skipped but it will not position them. |
zoltan@webkit.org | 8b422c8 | 2013-09-20 21:17:43 +0000 | [diff] [blame] | 2310 | void LineBreaker::skipTrailingWhitespace(InlineIterator& iterator, const LineInfo& lineInfo) |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 2311 | { |
rniwa@webkit.org | 4024842 | 2011-06-15 00:19:39 +0000 | [diff] [blame] | 2312 | while (!iterator.atEnd() && !requiresLineBox(iterator, lineInfo, TrailingWhitespace)) { |
eric@webkit.org | 8c25a59 | 2011-03-29 13:18:11 +0000 | [diff] [blame] | 2313 | RenderObject* object = iterator.m_obj; |
simon.fraser@apple.com | 2f07185 | 2012-06-25 00:11:30 +0000 | [diff] [blame] | 2314 | if (object->isOutOfFlowPositioned()) |
leviw@chromium.org | 1a50869 | 2011-05-05 00:01:11 +0000 | [diff] [blame] | 2315 | setStaticPositions(m_block, toRenderBox(object)); |
mitz@apple.com | d67fb21 | 2011-12-19 02:51:46 +0000 | [diff] [blame] | 2316 | else if (object->isFloating()) |
| 2317 | m_block->insertFloatingObject(toRenderBox(object)); |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 2318 | iterator.increment(); |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 2319 | } |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 2320 | } |
bdash | ccffb43 | 2007-07-13 11:51:40 +0000 | [diff] [blame] | 2321 | |
zoltan@webkit.org | 8b422c8 | 2013-09-20 21:17:43 +0000 | [diff] [blame] | 2322 | void LineBreaker::skipLeadingWhitespace(InlineBidiResolver& resolver, LineInfo& lineInfo, |
leviw@chromium.org | 1a50869 | 2011-05-05 00:01:11 +0000 | [diff] [blame] | 2323 | FloatingObject* lastFloatFromPreviousLine, LineWidth& width) |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 2324 | { |
rniwa@webkit.org | 4024842 | 2011-06-15 00:19:39 +0000 | [diff] [blame] | 2325 | while (!resolver.position().atEnd() && !requiresLineBox(resolver.position(), lineInfo, LeadingWhitespace)) { |
eric@webkit.org | 8c25a59 | 2011-03-29 13:18:11 +0000 | [diff] [blame] | 2326 | RenderObject* object = resolver.position().m_obj; |
simon.fraser@apple.com | 2f07185 | 2012-06-25 00:11:30 +0000 | [diff] [blame] | 2327 | if (object->isOutOfFlowPositioned()) { |
leviw@chromium.org | 1a50869 | 2011-05-05 00:01:11 +0000 | [diff] [blame] | 2328 | setStaticPositions(m_block, toRenderBox(object)); |
robert@webkit.org | 8cbab14 | 2011-12-30 20:58:29 +0000 | [diff] [blame] | 2329 | if (object->style()->isOriginalDisplayInlineType()) { |
| 2330 | resolver.runs().addRun(createRun(0, 1, object, resolver)); |
| 2331 | lineInfo.incrementRunsFromLeadingWhitespace(); |
| 2332 | } |
robert@webkit.org | 8de78c6 | 2012-12-07 19:30:51 +0000 | [diff] [blame] | 2333 | } else if (object->isFloating()) { |
| 2334 | // The top margin edge of a self-collapsing block that clears a float intrudes up into it by the height of the margin, |
robert@webkit.org | ab9ec78 | 2013-02-12 21:06:07 +0000 | [diff] [blame] | 2335 | // so in order to place this first child float at the top content edge of the self-collapsing block add the margin back in before placement. |
timothy_horton@apple.com | eefba76 | 2013-08-21 19:50:36 +0000 | [diff] [blame] | 2336 | LayoutUnit marginOffset = (!object->previousSibling() && m_block->isSelfCollapsingBlock() && m_block->style()->clear() && m_block->getClearDelta(m_block, LayoutUnit())) ? m_block->collapsedMarginBeforeForChild(m_block) : LayoutUnit(); |
robert@webkit.org | 8de78c6 | 2012-12-07 19:30:51 +0000 | [diff] [blame] | 2337 | LayoutUnit oldLogicalHeight = m_block->logicalHeight(); |
| 2338 | m_block->setLogicalHeight(oldLogicalHeight + marginOffset); |
mitz@apple.com | d67fb21 | 2011-12-19 02:51:46 +0000 | [diff] [blame] | 2339 | m_block->positionNewFloatOnLine(m_block->insertFloatingObject(toRenderBox(object)), lastFloatFromPreviousLine, lineInfo, width); |
robert@webkit.org | 8de78c6 | 2012-12-07 19:30:51 +0000 | [diff] [blame] | 2340 | m_block->setLogicalHeight(oldLogicalHeight); |
akling@apple.com | 4c166d6 | 2013-09-01 05:29:00 +0000 | [diff] [blame] | 2341 | } else if (object->isText() && object->style()->hasTextCombine() && object->isCombineText() && !toRenderCombineText(*object).isCombined()) { |
| 2342 | toRenderCombineText(*object).combineText(); |
| 2343 | if (toRenderCombineText(*object).isCombined()) |
commit-queue@webkit.org | 8e277fd | 2012-01-19 18:05:33 +0000 | [diff] [blame] | 2344 | continue; |
commit-queue@webkit.org | f6c35c0 | 2012-01-06 20:30:15 +0000 | [diff] [blame] | 2345 | } |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 2346 | resolver.increment(); |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 2347 | } |
mitz@apple.com | 83d2e87 | 2008-10-23 21:56:03 +0000 | [diff] [blame] | 2348 | resolver.commitExplicitEmbedding(); |
kocienda | e40cb94 | 2004-10-05 20:05:38 +0000 | [diff] [blame] | 2349 | } |
| 2350 | |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 2351 | // This is currently just used for list markers and inline flows that have line boxes. Neither should |
| 2352 | // have an effect on whitespace at the start of the line. |
hyatt@apple.com | b3466af | 2009-06-13 06:04:40 +0000 | [diff] [blame] | 2353 | static bool shouldSkipWhitespaceAfterStartObject(RenderBlock* block, RenderObject* o, LineMidpointState& lineMidpointState) |
bdakin | f876bee | 2007-10-30 05:27:09 +0000 | [diff] [blame] | 2354 | { |
eric@webkit.org | d4b9d77 | 2011-08-22 23:34:31 +0000 | [diff] [blame] | 2355 | RenderObject* next = bidiNextSkippingEmptyInlines(block, o); |
robert@webkit.org | dc6fd18 | 2013-04-11 19:17:12 +0000 | [diff] [blame] | 2356 | while (next && next->isFloatingOrOutOfFlowPositioned()) |
| 2357 | next = bidiNextSkippingEmptyInlines(block, next); |
| 2358 | |
antti@apple.com | 9d8157e | 2013-09-17 15:13:37 +0000 | [diff] [blame] | 2359 | if (next && next->isText() && toRenderText(next)->textLength() > 0) { |
darin@apple.com | 36744d6 | 2009-01-25 20:23:04 +0000 | [diff] [blame] | 2360 | RenderText* nextText = toRenderText(next); |
msaboff@apple.com | 776c286c7 | 2012-10-15 16:56:29 +0000 | [diff] [blame] | 2361 | UChar nextChar = nextText->characterAt(0); |
bdakin | f876bee | 2007-10-30 05:27:09 +0000 | [diff] [blame] | 2362 | if (nextText->style()->isCollapsibleWhiteSpace(nextChar)) { |
leviw@chromium.org | 0e7d89e | 2013-02-23 00:00:27 +0000 | [diff] [blame] | 2363 | startIgnoringSpaces(lineMidpointState, InlineIterator(0, o, 0)); |
bdakin | f876bee | 2007-10-30 05:27:09 +0000 | [diff] [blame] | 2364 | return true; |
| 2365 | } |
| 2366 | } |
| 2367 | |
| 2368 | return false; |
| 2369 | } |
| 2370 | |
rniwa@webkit.org | fe811f2 | 2013-06-07 17:59:01 +0000 | [diff] [blame] | 2371 | static ALWAYS_INLINE float textWidth(RenderText* text, unsigned from, unsigned len, const Font& font, float xPos, bool isFixedPitch, bool collapseWhiteSpace, HashSet<const SimpleFontData*>& fallbackFonts, TextLayout* layout = 0) |
mitz@apple.com | 3410644 | 2009-02-01 06:23:39 +0000 | [diff] [blame] | 2372 | { |
antti@apple.com | 78e5677 | 2013-09-29 04:34:37 +0000 | [diff] [blame] | 2373 | const RenderStyle& style = *text->style(); |
| 2374 | |
enrica@apple.com | 885c84d | 2012-10-10 05:48:51 +0000 | [diff] [blame] | 2375 | GlyphOverflow glyphOverflow; |
antti@apple.com | 78e5677 | 2013-09-29 04:34:37 +0000 | [diff] [blame] | 2376 | if (isFixedPitch || (!from && len == text->textLength()) || style.hasTextCombine()) |
rniwa@webkit.org | fe811f2 | 2013-06-07 17:59:01 +0000 | [diff] [blame] | 2377 | return text->width(from, len, font, xPos, &fallbackFonts, &glyphOverflow); |
zimmermann@webkit.org | 544abde | 2011-06-12 12:40:40 +0000 | [diff] [blame] | 2378 | |
mitz@apple.com | 6a85960 | 2012-08-27 15:31:56 +0000 | [diff] [blame] | 2379 | if (layout) |
rniwa@webkit.org | fe811f2 | 2013-06-07 17:59:01 +0000 | [diff] [blame] | 2380 | return Font::width(*layout, from, len, &fallbackFonts); |
mitz@apple.com | 6a85960 | 2012-08-27 15:31:56 +0000 | [diff] [blame] | 2381 | |
antti@apple.com | 78e5677 | 2013-09-29 04:34:37 +0000 | [diff] [blame] | 2382 | TextRun run = RenderBlock::constructTextRun(text, font, text, from, len, style); |
zimmermann@webkit.org | 544abde | 2011-06-12 12:40:40 +0000 | [diff] [blame] | 2383 | run.setCharactersLength(text->textLength() - from); |
| 2384 | ASSERT(run.charactersLength() >= run.length()); |
| 2385 | |
hyatt@apple.com | c2fdbe1 | 2012-04-12 21:06:50 +0000 | [diff] [blame] | 2386 | run.setCharacterScanForCodePath(!text->canUseSimpleFontCodePath()); |
morrita@google.com | 6e818ec | 2012-05-11 03:28:46 +0000 | [diff] [blame] | 2387 | run.setTabSize(!collapseWhiteSpace, text->style()->tabSize()); |
zimmermann@webkit.org | 8a7e7ff | 2011-05-24 15:27:36 +0000 | [diff] [blame] | 2388 | run.setXPos(xPos); |
rniwa@webkit.org | fe811f2 | 2013-06-07 17:59:01 +0000 | [diff] [blame] | 2389 | return font.width(run, &fallbackFonts, &glyphOverflow); |
mitz@apple.com | 3410644 | 2009-02-01 06:23:39 +0000 | [diff] [blame] | 2390 | } |
| 2391 | |
msaboff@apple.com | 776c286c7 | 2012-10-15 16:56:29 +0000 | [diff] [blame] | 2392 | static void tryHyphenating(RenderText* text, const Font& font, const AtomicString& localeIdentifier, unsigned consecutiveHyphenatedLines, int consecutiveHyphenatedLinesLimit, int minimumPrefixLimit, int minimumSuffixLimit, unsigned lastSpace, unsigned pos, float xPos, int availableWidth, bool isFixedPitch, bool collapseWhiteSpace, int lastSpaceWordSpacing, InlineIterator& lineBreak, int nextBreakable, bool& hyphenated) |
mitz@apple.com | b210765 | 2010-06-21 16:54:52 +0000 | [diff] [blame] | 2393 | { |
mitz@apple.com | d56f108 | 2011-03-06 22:44:48 +0000 | [diff] [blame] | 2394 | // Map 'hyphenate-limit-{before,after}: auto;' to 2. |
msaboff@apple.com | 776c286c7 | 2012-10-15 16:56:29 +0000 | [diff] [blame] | 2395 | unsigned minimumPrefixLength; |
| 2396 | unsigned minimumSuffixLength; |
mitz@apple.com | d56f108 | 2011-03-06 22:44:48 +0000 | [diff] [blame] | 2397 | |
msaboff@apple.com | 776c286c7 | 2012-10-15 16:56:29 +0000 | [diff] [blame] | 2398 | if (minimumPrefixLimit < 0) |
| 2399 | minimumPrefixLength = 2; |
| 2400 | else |
| 2401 | minimumPrefixLength = static_cast<unsigned>(minimumPrefixLimit); |
| 2402 | |
| 2403 | if (minimumSuffixLimit < 0) |
mitz@apple.com | d56f108 | 2011-03-06 22:44:48 +0000 | [diff] [blame] | 2404 | minimumSuffixLength = 2; |
msaboff@apple.com | 776c286c7 | 2012-10-15 16:56:29 +0000 | [diff] [blame] | 2405 | else |
| 2406 | minimumSuffixLength = static_cast<unsigned>(minimumSuffixLimit); |
mitz@apple.com | d56f108 | 2011-03-06 22:44:48 +0000 | [diff] [blame] | 2407 | |
| 2408 | if (pos - lastSpace <= minimumSuffixLength) |
| 2409 | return; |
| 2410 | |
mitz@apple.com | 10ed3cb | 2011-09-07 20:59:39 +0000 | [diff] [blame] | 2411 | if (consecutiveHyphenatedLinesLimit >= 0 && consecutiveHyphenatedLines >= static_cast<unsigned>(consecutiveHyphenatedLinesLimit)) |
| 2412 | return; |
| 2413 | |
commit-queue@webkit.org | e60bb90 | 2011-09-08 19:18:43 +0000 | [diff] [blame] | 2414 | int hyphenWidth = measureHyphenWidth(text, font); |
mitz@apple.com | b210765 | 2010-06-21 16:54:52 +0000 | [diff] [blame] | 2415 | |
hyatt@apple.com | 0acc935 | 2011-02-17 19:19:07 +0000 | [diff] [blame] | 2416 | float maxPrefixWidth = availableWidth - xPos - hyphenWidth - lastSpaceWordSpacing; |
mitz@apple.com | 7c67b29 | 2010-09-12 23:04:16 +0000 | [diff] [blame] | 2417 | // If the maximum width available for the prefix before the hyphen is small, then it is very unlikely |
| 2418 | // that an hyphenation opportunity exists, so do not bother to look for it. |
| 2419 | if (maxPrefixWidth <= font.pixelSize() * 5 / 4) |
| 2420 | return; |
| 2421 | |
antti@apple.com | 78e5677 | 2013-09-29 04:34:37 +0000 | [diff] [blame] | 2422 | const RenderStyle& style = *text->style(); |
| 2423 | TextRun run = RenderBlock::constructTextRun(text, font, text, lastSpace, pos - lastSpace, style); |
zimmermann@webkit.org | 544abde | 2011-06-12 12:40:40 +0000 | [diff] [blame] | 2424 | run.setCharactersLength(text->textLength() - lastSpace); |
| 2425 | ASSERT(run.charactersLength() >= run.length()); |
| 2426 | |
antti@apple.com | 78e5677 | 2013-09-29 04:34:37 +0000 | [diff] [blame] | 2427 | run.setTabSize(!collapseWhiteSpace, style.tabSize()); |
zimmermann@webkit.org | 8a7e7ff | 2011-05-24 15:27:36 +0000 | [diff] [blame] | 2428 | run.setXPos(xPos + lastSpaceWordSpacing); |
| 2429 | |
| 2430 | unsigned prefixLength = font.offsetForPosition(run, maxPrefixWidth, false); |
msaboff@apple.com | 776c286c7 | 2012-10-15 16:56:29 +0000 | [diff] [blame] | 2431 | if (prefixLength < minimumPrefixLength) |
mitz@apple.com | b210765 | 2010-06-21 16:54:52 +0000 | [diff] [blame] | 2432 | return; |
| 2433 | |
msaboff@apple.com | 776c286c7 | 2012-10-15 16:56:29 +0000 | [diff] [blame] | 2434 | prefixLength = lastHyphenLocation(text->characters() + lastSpace, pos - lastSpace, min(prefixLength, pos - lastSpace - minimumSuffixLength) + 1, localeIdentifier); |
| 2435 | if (!prefixLength || prefixLength < minimumPrefixLength) |
mitz@apple.com | b210765 | 2010-06-21 16:54:52 +0000 | [diff] [blame] | 2436 | return; |
| 2437 | |
mitz@apple.com | 348878a | 2011-12-11 19:06:56 +0000 | [diff] [blame] | 2438 | // When lastSapce is a space, which it always is except sometimes at the beginning of a line or after collapsed |
| 2439 | // space, it should not count towards hyphenate-limit-before. |
msaboff@apple.com | 776c286c7 | 2012-10-15 16:56:29 +0000 | [diff] [blame] | 2440 | if (prefixLength == minimumPrefixLength) { |
| 2441 | UChar characterAtLastSpace = text->characterAt(lastSpace); |
mitz@apple.com | 348878a | 2011-12-11 19:06:56 +0000 | [diff] [blame] | 2442 | if (characterAtLastSpace == ' ' || characterAtLastSpace == '\n' || characterAtLastSpace == '\t' || characterAtLastSpace == noBreakSpace) |
| 2443 | return; |
| 2444 | } |
| 2445 | |
msaboff@apple.com | 776c286c7 | 2012-10-15 16:56:29 +0000 | [diff] [blame] | 2446 | ASSERT(pos - lastSpace - prefixLength >= minimumSuffixLength); |
mitz@apple.com | d56f108 | 2011-03-06 22:44:48 +0000 | [diff] [blame] | 2447 | |
mitz@apple.com | b210765 | 2010-06-21 16:54:52 +0000 | [diff] [blame] | 2448 | #if !ASSERT_DISABLED |
rniwa@webkit.org | fe811f2 | 2013-06-07 17:59:01 +0000 | [diff] [blame] | 2449 | HashSet<const SimpleFontData*> fallbackFonts; |
| 2450 | float prefixWidth = hyphenWidth + textWidth(text, lastSpace, prefixLength, font, xPos, isFixedPitch, collapseWhiteSpace, fallbackFonts) + lastSpaceWordSpacing; |
mitz@apple.com | b210765 | 2010-06-21 16:54:52 +0000 | [diff] [blame] | 2451 | ASSERT(xPos + prefixWidth <= availableWidth); |
mitz@apple.com | 34b43c7 | 2010-06-21 17:21:22 +0000 | [diff] [blame] | 2452 | #else |
| 2453 | UNUSED_PARAM(isFixedPitch); |
mitz@apple.com | b210765 | 2010-06-21 16:54:52 +0000 | [diff] [blame] | 2454 | #endif |
| 2455 | |
eric@webkit.org | bd14359 | 2011-03-29 17:44:41 +0000 | [diff] [blame] | 2456 | lineBreak.moveTo(text, lastSpace + prefixLength, nextBreakable); |
mitz@apple.com | b210765 | 2010-06-21 16:54:52 +0000 | [diff] [blame] | 2457 | hyphenated = true; |
| 2458 | } |
| 2459 | |
rniwa@webkit.org | 105350c | 2011-05-03 20:33:25 +0000 | [diff] [blame] | 2460 | class TrailingObjects { |
| 2461 | public: |
| 2462 | TrailingObjects(); |
| 2463 | void setTrailingWhitespace(RenderText*); |
| 2464 | void clear(); |
commit-queue@webkit.org | 6af4887 | 2013-04-09 16:46:49 +0000 | [diff] [blame] | 2465 | void appendBoxIfNeeded(RenderBoxModelObject*); |
mitz@apple.com | e98acc9 | 2011-05-22 04:44:27 +0000 | [diff] [blame] | 2466 | |
| 2467 | enum CollapseFirstSpaceOrNot { DoNotCollapseFirstSpace, CollapseFirstSpace }; |
| 2468 | |
| 2469 | void updateMidpointsForTrailingBoxes(LineMidpointState&, const InlineIterator& lBreak, CollapseFirstSpaceOrNot); |
rniwa@webkit.org | 105350c | 2011-05-03 20:33:25 +0000 | [diff] [blame] | 2470 | |
| 2471 | private: |
| 2472 | RenderText* m_whitespace; |
commit-queue@webkit.org | 6af4887 | 2013-04-09 16:46:49 +0000 | [diff] [blame] | 2473 | Vector<RenderBoxModelObject*, 4> m_boxes; |
rniwa@webkit.org | 105350c | 2011-05-03 20:33:25 +0000 | [diff] [blame] | 2474 | }; |
| 2475 | |
| 2476 | TrailingObjects::TrailingObjects() |
| 2477 | : m_whitespace(0) |
| 2478 | { |
| 2479 | } |
| 2480 | |
| 2481 | inline void TrailingObjects::setTrailingWhitespace(RenderText* whitespace) |
| 2482 | { |
| 2483 | ASSERT(whitespace); |
| 2484 | m_whitespace = whitespace; |
| 2485 | } |
| 2486 | |
| 2487 | inline void TrailingObjects::clear() |
| 2488 | { |
| 2489 | m_whitespace = 0; |
ggaren@apple.com | 98109ff | 2013-07-19 17:43:07 +0000 | [diff] [blame] | 2490 | m_boxes.shrink(0); // Use shrink(0) instead of clear() to retain our capacity. |
rniwa@webkit.org | 105350c | 2011-05-03 20:33:25 +0000 | [diff] [blame] | 2491 | } |
| 2492 | |
commit-queue@webkit.org | 6af4887 | 2013-04-09 16:46:49 +0000 | [diff] [blame] | 2493 | inline void TrailingObjects::appendBoxIfNeeded(RenderBoxModelObject* box) |
rniwa@webkit.org | 105350c | 2011-05-03 20:33:25 +0000 | [diff] [blame] | 2494 | { |
| 2495 | if (m_whitespace) |
| 2496 | m_boxes.append(box); |
| 2497 | } |
| 2498 | |
mitz@apple.com | e98acc9 | 2011-05-22 04:44:27 +0000 | [diff] [blame] | 2499 | void TrailingObjects::updateMidpointsForTrailingBoxes(LineMidpointState& lineMidpointState, const InlineIterator& lBreak, CollapseFirstSpaceOrNot collapseFirstSpace) |
rniwa@webkit.org | 105350c | 2011-05-03 20:33:25 +0000 | [diff] [blame] | 2500 | { |
| 2501 | if (!m_whitespace) |
| 2502 | return; |
| 2503 | |
| 2504 | // This object is either going to be part of the last midpoint, or it is going to be the actual endpoint. |
| 2505 | // In both cases we just decrease our pos by 1 level to exclude the space, allowing it to - in effect - collapse into the newline. |
| 2506 | if (lineMidpointState.numMidpoints % 2) { |
| 2507 | // Find the trailing space object's midpoint. |
| 2508 | int trailingSpaceMidpoint = lineMidpointState.numMidpoints - 1; |
inferno@chromium.org | 92ca04e | 2011-08-01 18:03:03 +0000 | [diff] [blame] | 2509 | for ( ; trailingSpaceMidpoint > 0 && lineMidpointState.midpoints[trailingSpaceMidpoint].m_obj != m_whitespace; --trailingSpaceMidpoint) { } |
rniwa@webkit.org | 105350c | 2011-05-03 20:33:25 +0000 | [diff] [blame] | 2510 | ASSERT(trailingSpaceMidpoint >= 0); |
mitz@apple.com | e98acc9 | 2011-05-22 04:44:27 +0000 | [diff] [blame] | 2511 | if (collapseFirstSpace == CollapseFirstSpace) |
| 2512 | lineMidpointState.midpoints[trailingSpaceMidpoint].m_pos--; |
rniwa@webkit.org | 105350c | 2011-05-03 20:33:25 +0000 | [diff] [blame] | 2513 | |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 2514 | // Now make sure every single trailingPositionedBox following the trailingSpaceMidpoint properly stops and starts |
rniwa@webkit.org | 105350c | 2011-05-03 20:33:25 +0000 | [diff] [blame] | 2515 | // ignoring spaces. |
| 2516 | size_t currentMidpoint = trailingSpaceMidpoint + 1; |
| 2517 | for (size_t i = 0; i < m_boxes.size(); ++i) { |
| 2518 | if (currentMidpoint >= lineMidpointState.numMidpoints) { |
| 2519 | // We don't have a midpoint for this box yet. |
leviw@chromium.org | 0e7d89e | 2013-02-23 00:00:27 +0000 | [diff] [blame] | 2520 | ensureLineBoxInsideIgnoredSpaces(lineMidpointState, m_boxes[i]); |
rniwa@webkit.org | 105350c | 2011-05-03 20:33:25 +0000 | [diff] [blame] | 2521 | } else { |
| 2522 | ASSERT(lineMidpointState.midpoints[currentMidpoint].m_obj == m_boxes[i]); |
| 2523 | ASSERT(lineMidpointState.midpoints[currentMidpoint + 1].m_obj == m_boxes[i]); |
| 2524 | } |
| 2525 | currentMidpoint += 2; |
| 2526 | } |
| 2527 | } else if (!lBreak.m_obj) { |
| 2528 | ASSERT(m_whitespace->isText()); |
mitz@apple.com | e98acc9 | 2011-05-22 04:44:27 +0000 | [diff] [blame] | 2529 | ASSERT(collapseFirstSpace == CollapseFirstSpace); |
rniwa@webkit.org | 105350c | 2011-05-03 20:33:25 +0000 | [diff] [blame] | 2530 | // Add a new end midpoint that stops right at the very end. |
| 2531 | unsigned length = m_whitespace->textLength(); |
| 2532 | unsigned pos = length >= 2 ? length - 2 : UINT_MAX; |
| 2533 | InlineIterator endMid(0, m_whitespace, pos); |
leviw@chromium.org | 0e7d89e | 2013-02-23 00:00:27 +0000 | [diff] [blame] | 2534 | startIgnoringSpaces(lineMidpointState, endMid); |
rniwa@webkit.org | 105350c | 2011-05-03 20:33:25 +0000 | [diff] [blame] | 2535 | for (size_t i = 0; i < m_boxes.size(); ++i) { |
leviw@chromium.org | 0e7d89e | 2013-02-23 00:00:27 +0000 | [diff] [blame] | 2536 | ensureLineBoxInsideIgnoredSpaces(lineMidpointState, m_boxes[i]); |
rniwa@webkit.org | 105350c | 2011-05-03 20:33:25 +0000 | [diff] [blame] | 2537 | } |
| 2538 | } |
| 2539 | } |
| 2540 | |
zoltan@webkit.org | 8b422c8 | 2013-09-20 21:17:43 +0000 | [diff] [blame] | 2541 | void LineBreaker::reset() |
kocienda | e40cb94 | 2004-10-05 20:05:38 +0000 | [diff] [blame] | 2542 | { |
leviw@chromium.org | 1a50869 | 2011-05-05 00:01:11 +0000 | [diff] [blame] | 2543 | m_positionedObjects.clear(); |
| 2544 | m_hyphenated = false; |
| 2545 | m_clear = CNONE; |
| 2546 | } |
| 2547 | |
zoltan@webkit.org | 8b422c8 | 2013-09-20 21:17:43 +0000 | [diff] [blame] | 2548 | InlineIterator LineBreaker::nextLineBreak(InlineBidiResolver& resolver, LineInfo& lineInfo, RenderTextInfo& renderTextInfo, FloatingObject* lastFloatFromPreviousLine, unsigned consecutiveHyphenatedLines, WordMeasurements& wordMeasurements) |
leviw@chromium.org | 1a50869 | 2011-05-05 00:01:11 +0000 | [diff] [blame] | 2549 | { |
betravis@adobe.com | ed90c98 | 2013-06-05 23:05:57 +0000 | [diff] [blame] | 2550 | #if !ENABLE(CSS_SHAPES) |
commit-queue@webkit.org | ccad924 | 2012-12-05 20:17:30 +0000 | [diff] [blame] | 2551 | return nextSegmentBreak(resolver, lineInfo, renderTextInfo, lastFloatFromPreviousLine, consecutiveHyphenatedLines, wordMeasurements); |
| 2552 | #else |
betravis@adobe.com | cf7cba6 | 2013-06-10 21:23:45 +0000 | [diff] [blame] | 2553 | ShapeInsideInfo* shapeInsideInfo = m_block->layoutShapeInsideInfo(); |
zoltan@webkit.org | 3bd77f5 | 2013-04-23 18:23:36 +0000 | [diff] [blame] | 2554 | |
betravis@adobe.com | cf7cba6 | 2013-06-10 21:23:45 +0000 | [diff] [blame] | 2555 | if (!shapeInsideInfo || !shapeInsideInfo->lineOverlapsShapeBounds()) |
commit-queue@webkit.org | ccad924 | 2012-12-05 20:17:30 +0000 | [diff] [blame] | 2556 | return nextSegmentBreak(resolver, lineInfo, renderTextInfo, lastFloatFromPreviousLine, consecutiveHyphenatedLines, wordMeasurements); |
| 2557 | |
| 2558 | InlineIterator end = resolver.position(); |
| 2559 | InlineIterator oldEnd = end; |
| 2560 | |
betravis@adobe.com | cf7cba6 | 2013-06-10 21:23:45 +0000 | [diff] [blame] | 2561 | if (!shapeInsideInfo->hasSegments()) { |
betravis@adobe.com | 9e5e824 | 2013-04-19 23:28:26 +0000 | [diff] [blame] | 2562 | end = nextSegmentBreak(resolver, lineInfo, renderTextInfo, lastFloatFromPreviousLine, consecutiveHyphenatedLines, wordMeasurements); |
| 2563 | resolver.setPositionIgnoringNestedIsolates(oldEnd); |
| 2564 | return oldEnd; |
| 2565 | } |
| 2566 | |
betravis@adobe.com | cf7cba6 | 2013-06-10 21:23:45 +0000 | [diff] [blame] | 2567 | const SegmentList& segments = shapeInsideInfo->segments(); |
| 2568 | SegmentRangeList& segmentRanges = shapeInsideInfo->segmentRanges(); |
commit-queue@webkit.org | ccad924 | 2012-12-05 20:17:30 +0000 | [diff] [blame] | 2569 | |
hmuller@adobe.com | 6da7187 | 2013-03-18 16:54:04 +0000 | [diff] [blame] | 2570 | for (unsigned i = 0; i < segments.size() && !end.atEnd(); i++) { |
commit-queue@webkit.org | ccad924 | 2012-12-05 20:17:30 +0000 | [diff] [blame] | 2571 | InlineIterator segmentStart = resolver.position(); |
| 2572 | end = nextSegmentBreak(resolver, lineInfo, renderTextInfo, lastFloatFromPreviousLine, consecutiveHyphenatedLines, wordMeasurements); |
| 2573 | |
| 2574 | ASSERT(segmentRanges.size() == i); |
hmuller@adobe.com | 6da7187 | 2013-03-18 16:54:04 +0000 | [diff] [blame] | 2575 | if (resolver.position().atEnd()) { |
| 2576 | segmentRanges.append(LineSegmentRange(segmentStart, end)); |
| 2577 | break; |
| 2578 | } |
commit-queue@webkit.org | ccad924 | 2012-12-05 20:17:30 +0000 | [diff] [blame] | 2579 | if (resolver.position() == end) { |
| 2580 | // Nothing fit this segment |
betravis@adobe.com | 9e5e824 | 2013-04-19 23:28:26 +0000 | [diff] [blame] | 2581 | end = segmentStart; |
commit-queue@webkit.org | ccad924 | 2012-12-05 20:17:30 +0000 | [diff] [blame] | 2582 | segmentRanges.append(LineSegmentRange(segmentStart, segmentStart)); |
| 2583 | resolver.setPositionIgnoringNestedIsolates(segmentStart); |
| 2584 | } else { |
| 2585 | // Note that resolver.position is already skipping some of the white space at the beginning of the line, |
| 2586 | // so that's why segmentStart might be different than resolver.position(). |
| 2587 | LineSegmentRange range(resolver.position(), end); |
| 2588 | segmentRanges.append(range); |
| 2589 | resolver.setPosition(end, numberOfIsolateAncestors(end)); |
| 2590 | |
| 2591 | if (lineInfo.previousLineBrokeCleanly()) { |
| 2592 | // If we hit a new line break, just stop adding anything to this line. |
| 2593 | break; |
| 2594 | } |
| 2595 | } |
| 2596 | } |
| 2597 | resolver.setPositionIgnoringNestedIsolates(oldEnd); |
| 2598 | return end; |
| 2599 | #endif |
| 2600 | } |
| 2601 | |
akling@apple.com | 4c166d6 | 2013-09-01 05:29:00 +0000 | [diff] [blame] | 2602 | static inline bool iteratorIsBeyondEndOfRenderCombineText(const InlineIterator& iter, RenderCombineText& renderer) |
leviw@chromium.org | 17fe64d | 2013-04-02 23:10:49 +0000 | [diff] [blame] | 2603 | { |
akling@apple.com | 4c166d6 | 2013-09-01 05:29:00 +0000 | [diff] [blame] | 2604 | return iter.m_obj == &renderer && iter.m_pos >= renderer.textLength(); |
leviw@chromium.org | 17fe64d | 2013-04-02 23:10:49 +0000 | [diff] [blame] | 2605 | } |
| 2606 | |
robert@webkit.org | 1f81153 | 2013-06-24 20:09:20 +0000 | [diff] [blame] | 2607 | static inline void commitLineBreakAtCurrentWidth(LineWidth& width, InlineIterator& lBreak, RenderObject* object, unsigned offset = 0, int nextBreak = -1) |
| 2608 | { |
| 2609 | width.commit(); |
| 2610 | lBreak.moveTo(object, offset, nextBreak); |
| 2611 | } |
| 2612 | |
robert@webkit.org | 6ce4b39 | 2013-07-02 19:30:32 +0000 | [diff] [blame] | 2613 | static bool textBeginsWithBreakablePosition(RenderObject* next) |
| 2614 | { |
| 2615 | ASSERT(next->isText()); |
| 2616 | RenderText* nextText = toRenderText(next); |
robert@webkit.org | 6ce4b39 | 2013-07-02 19:30:32 +0000 | [diff] [blame] | 2617 | if (!nextText->textLength()) |
| 2618 | return false; |
| 2619 | UChar c = nextText->characterAt(0); |
| 2620 | return c == ' ' || c == '\t' || (c == '\n' && !nextText->preservesNewline()); |
| 2621 | } |
| 2622 | |
| 2623 | static bool canBreakAtThisPosition(bool autoWrap, LineWidth& width, InlineIterator& lBreak, RenderObject* next, const InlineIterator& current, EWhiteSpace currWS, bool currentCharacterIsSpace, bool autoWrapWasEverTrueOnLine) |
| 2624 | { |
| 2625 | // If we are no-wrap and have found a line-breaking opportunity already then we should take it. |
| 2626 | if (width.committedWidth() && !width.fitsOnLine(currentCharacterIsSpace) && currWS == NOWRAP) |
| 2627 | return true; |
| 2628 | |
| 2629 | // Avoid breaking before empty inlines. |
antti@apple.com | 3ab7ef3 | 2013-09-29 20:50:01 +0000 | [diff] [blame] | 2630 | if (next && next->isRenderInline() && isEmptyInline(toRenderInline(*next))) |
robert@webkit.org | 6ce4b39 | 2013-07-02 19:30:32 +0000 | [diff] [blame] | 2631 | return false; |
| 2632 | |
| 2633 | // Return early if we autowrap and the current character is a space as we will always want to break at such a position. |
| 2634 | if (autoWrap && currentCharacterIsSpace) |
| 2635 | return true; |
| 2636 | |
antti@apple.com | 3014ac0 | 2013-09-18 14:33:55 +0000 | [diff] [blame] | 2637 | if (next && next->isLineBreakOpportunity()) |
| 2638 | return autoWrap; |
| 2639 | |
antti@apple.com | 3ab7ef3 | 2013-09-29 20:50:01 +0000 | [diff] [blame] | 2640 | bool nextIsAutoWrappingText = (next && next->isText() && (autoWrap || next->style()->autoWrap())); |
| 2641 | if (!nextIsAutoWrappingText) |
| 2642 | return autoWrap; |
| 2643 | bool currentIsTextOrEmptyInline = current.m_obj->isText() || (current.m_obj->isRenderInline() && isEmptyInline(toRenderInline(*current.m_obj))); |
| 2644 | if (!currentIsTextOrEmptyInline) |
robert@webkit.org | 6ce4b39 | 2013-07-02 19:30:32 +0000 | [diff] [blame] | 2645 | return autoWrap; |
| 2646 | |
| 2647 | bool canBreakHere = !currentCharacterIsSpace && textBeginsWithBreakablePosition(next); |
| 2648 | |
| 2649 | // See if attempting to fit below floats creates more available width on the line. |
| 2650 | if (!width.fitsOnLine() && !width.committedWidth()) |
| 2651 | width.fitBelowFloats(); |
| 2652 | |
| 2653 | bool canPlaceOnLine = width.fitsOnLine() || !autoWrapWasEverTrueOnLine; |
| 2654 | |
zalan@apple.com | 576a5fb | 2013-07-23 19:47:34 +0000 | [diff] [blame] | 2655 | if (canPlaceOnLine && canBreakHere) |
robert@webkit.org | 6ce4b39 | 2013-07-02 19:30:32 +0000 | [diff] [blame] | 2656 | commitLineBreakAtCurrentWidth(width, lBreak, next); |
| 2657 | |
| 2658 | return canBreakHere; |
| 2659 | } |
| 2660 | |
zoltan@webkit.org | e1a0c95 | 2013-09-18 03:27:35 +0000 | [diff] [blame] | 2661 | #if ENABLE(CSS_SHAPES) |
| 2662 | static void updateSegmentsForShapes(RenderBlock* block, const FloatingObject* lastFloatFromPreviousLine, const WordMeasurements& wordMeasurements, LineWidth& width, bool isFirstLine) |
| 2663 | { |
| 2664 | ASSERT(lastFloatFromPreviousLine); |
| 2665 | |
| 2666 | ShapeInsideInfo* shapeInsideInfo = block->layoutShapeInsideInfo(); |
zoltan@webkit.org | 2b977c0 | 2013-10-03 18:24:59 +0000 | [diff] [blame] | 2667 | if (!lastFloatFromPreviousLine->isPlaced() || !shapeInsideInfo) |
zoltan@webkit.org | e1a0c95 | 2013-09-18 03:27:35 +0000 | [diff] [blame] | 2668 | return; |
| 2669 | |
zoltan@webkit.org | 3b30db7 | 2013-09-24 22:24:39 +0000 | [diff] [blame] | 2670 | bool isHorizontalWritingMode = block->isHorizontalWritingMode(); |
zoltan@webkit.org | 2b977c0 | 2013-10-03 18:24:59 +0000 | [diff] [blame] | 2671 | LayoutUnit logicalOffsetFromShapeContainer = block->logicalOffsetFromShapeAncestorContainer(shapeInsideInfo->owner()).height(); |
zoltan@webkit.org | e1a0c95 | 2013-09-18 03:27:35 +0000 | [diff] [blame] | 2672 | |
zoltan@webkit.org | 2b977c0 | 2013-10-03 18:24:59 +0000 | [diff] [blame] | 2673 | LayoutUnit lineLogicalTop = block->logicalHeight() + logicalOffsetFromShapeContainer; |
zoltan@webkit.org | 3b30db7 | 2013-09-24 22:24:39 +0000 | [diff] [blame] | 2674 | LayoutUnit lineLogicalHeight = block->lineHeight(isFirstLine, isHorizontalWritingMode ? HorizontalLine : VerticalLine, PositionOfInteriorLineBoxes); |
| 2675 | LayoutUnit lineLogicalBottom = lineLogicalTop + lineLogicalHeight; |
zoltan@webkit.org | e1a0c95 | 2013-09-18 03:27:35 +0000 | [diff] [blame] | 2676 | |
zoltan@webkit.org | 3b30db7 | 2013-09-24 22:24:39 +0000 | [diff] [blame] | 2677 | LayoutUnit floatLogicalTop = lastFloatFromPreviousLine->logicalTop(isHorizontalWritingMode); |
| 2678 | LayoutUnit floatLogicalBottom = lastFloatFromPreviousLine->logicalBottom(isHorizontalWritingMode); |
| 2679 | |
| 2680 | bool lineOverlapsWithFloat = (floatLogicalTop < lineLogicalBottom) && (lineLogicalTop < floatLogicalBottom); |
| 2681 | if (!lineOverlapsWithFloat) |
| 2682 | return; |
| 2683 | |
| 2684 | float minSegmentWidth = firstPositiveWidth(wordMeasurements); |
| 2685 | |
| 2686 | LayoutUnit floatLogicalWidth = lastFloatFromPreviousLine->logicalWidth(isHorizontalWritingMode); |
| 2687 | LayoutUnit availableLogicalWidth = block->logicalWidth() - lastFloatFromPreviousLine->logicalRight(isHorizontalWritingMode); |
| 2688 | if (availableLogicalWidth < minSegmentWidth) |
| 2689 | block->setLogicalHeight(floatLogicalBottom); |
| 2690 | |
| 2691 | if (block->logicalHeight() < floatLogicalTop) { |
| 2692 | shapeInsideInfo->adjustLogicalLineTop(minSegmentWidth + floatLogicalWidth); |
zoltan@webkit.org | 2b977c0 | 2013-10-03 18:24:59 +0000 | [diff] [blame] | 2693 | block->setLogicalHeight(shapeInsideInfo->logicalLineTop() - logicalOffsetFromShapeContainer); |
zoltan@webkit.org | e1a0c95 | 2013-09-18 03:27:35 +0000 | [diff] [blame] | 2694 | } |
| 2695 | |
zoltan@webkit.org | 2b977c0 | 2013-10-03 18:24:59 +0000 | [diff] [blame] | 2696 | lineLogicalTop = block->logicalHeight() + logicalOffsetFromShapeContainer; |
| 2697 | |
| 2698 | shapeInsideInfo->updateSegmentsForLine(lineLogicalTop, lineLogicalHeight); |
zoltan@webkit.org | e1a0c95 | 2013-09-18 03:27:35 +0000 | [diff] [blame] | 2699 | width.updateCurrentShapeSegment(); |
| 2700 | width.updateAvailableWidth(); |
| 2701 | } |
| 2702 | #endif |
| 2703 | |
zoltan@webkit.org | 8b422c8 | 2013-09-20 21:17:43 +0000 | [diff] [blame] | 2704 | InlineIterator LineBreaker::nextSegmentBreak(InlineBidiResolver& resolver, LineInfo& lineInfo, RenderTextInfo& renderTextInfo, FloatingObject* lastFloatFromPreviousLine, unsigned consecutiveHyphenatedLines, WordMeasurements& wordMeasurements) |
commit-queue@webkit.org | ccad924 | 2012-12-05 20:17:30 +0000 | [diff] [blame] | 2705 | { |
leviw@chromium.org | 1a50869 | 2011-05-05 00:01:11 +0000 | [diff] [blame] | 2706 | reset(); |
| 2707 | |
| 2708 | ASSERT(resolver.position().root() == m_block); |
mitz@apple.com | 5101732 | 2008-02-26 06:47:43 +0000 | [diff] [blame] | 2709 | |
eric@webkit.org | 86a865a | 2011-03-29 15:30:41 +0000 | [diff] [blame] | 2710 | bool appliedStartWidth = resolver.position().m_pos > 0; |
yael.aharon@nokia.com | 1cfbceb | 2011-06-06 18:32:54 +0000 | [diff] [blame] | 2711 | bool includeEndWidth = true; |
hyatt@apple.com | b3466af | 2009-06-13 06:04:40 +0000 | [diff] [blame] | 2712 | LineMidpointState& lineMidpointState = resolver.midpointState(); |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 2713 | |
antti@apple.com | 78e5677 | 2013-09-29 04:34:37 +0000 | [diff] [blame] | 2714 | LineWidth width(*m_block, lineInfo.isFirstLine(), requiresIndent(lineInfo.isFirstLine(), lineInfo.previousLineBrokeCleanly(), *m_block->style())); |
rniwa@webkit.org | 7881ad0 | 2011-04-07 13:05:35 +0000 | [diff] [blame] | 2715 | |
leviw@chromium.org | f009c8e | 2011-05-03 20:49:15 +0000 | [diff] [blame] | 2716 | skipLeadingWhitespace(resolver, lineInfo, lastFloatFromPreviousLine, width); |
kocienda | e40cb94 | 2004-10-05 20:05:38 +0000 | [diff] [blame] | 2717 | |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 2718 | if (resolver.position().atEnd()) |
| 2719 | return resolver.position(); |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 2720 | |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2721 | // This variable is used only if whitespace isn't set to PRE, and it tells us whether |
| 2722 | // or not we are currently ignoring whitespace. |
| 2723 | bool ignoringSpaces = false; |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 2724 | InlineIterator ignoreStart; |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 2725 | |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2726 | // This variable tracks whether the very last character we saw was a space. We use |
| 2727 | // this to detect when we encounter a second space so we know we have to terminate |
| 2728 | // a run. |
rjw | c9c257d | 2003-01-24 03:46:17 +0000 | [diff] [blame] | 2729 | bool currentCharacterIsSpace = false; |
harrison | e343c41 | 2005-01-18 01:07:26 +0000 | [diff] [blame] | 2730 | bool currentCharacterIsWS = false; |
rniwa@webkit.org | 105350c | 2011-05-03 20:33:25 +0000 | [diff] [blame] | 2731 | TrailingObjects trailingObjects; |
hyatt | 98b1628 | 2004-03-31 18:43:12 +0000 | [diff] [blame] | 2732 | |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 2733 | InlineIterator lBreak = resolver.position(); |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 2734 | |
eric@webkit.org | bd14359 | 2011-03-29 17:44:41 +0000 | [diff] [blame] | 2735 | // FIXME: It is error-prone to split the position object out like this. |
| 2736 | // Teach this code to work with objects instead of this split tuple. |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 2737 | InlineIterator current = resolver.position(); |
| 2738 | RenderObject* last = current.m_obj; |
ddkilzer | e8759ef | 2007-03-25 06:28:19 +0000 | [diff] [blame] | 2739 | bool atStart = true; |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 2740 | |
leviw@chromium.org | f009c8e | 2011-05-03 20:49:15 +0000 | [diff] [blame] | 2741 | bool startingNewParagraph = lineInfo.previousLineBrokeCleanly(); |
| 2742 | lineInfo.setPreviousLineBrokeCleanly(false); |
ddkilzer | 5d01fa2 | 2007-01-29 03:10:37 +0000 | [diff] [blame] | 2743 | |
| 2744 | bool autoWrapWasEverTrueOnLine = false; |
mitz@apple.com | 25beac6 | 2008-02-24 18:48:27 +0000 | [diff] [blame] | 2745 | bool floatsFitOnLine = true; |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 2746 | |
hyatt@apple.com | 6934090 | 2008-01-16 21:24:21 +0000 | [diff] [blame] | 2747 | // Firefox and Opera will allow a table cell to grow to fit an image inside it under |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 2748 | // very specific circumstances (in order to match common WinIE renderings). |
| 2749 | // Not supporting the quirk has caused us to mis-render some real sites. (See Bugzilla 10517.) |
antti@apple.com | 78e5677 | 2013-09-29 04:34:37 +0000 | [diff] [blame] | 2750 | const RenderStyle& blockStyle = *m_block->style(); |
| 2751 | bool allowImagesToBreak = !m_block->document().inQuirksMode() || !m_block->isTableCell() || !blockStyle.logicalWidth().isIntrinsicOrAuto(); |
hyatt@apple.com | 6934090 | 2008-01-16 21:24:21 +0000 | [diff] [blame] | 2752 | |
antti@apple.com | 78e5677 | 2013-09-29 04:34:37 +0000 | [diff] [blame] | 2753 | EWhiteSpace currWS = blockStyle.whiteSpace(); |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 2754 | EWhiteSpace lastWS = currWS; |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 2755 | while (current.m_obj) { |
antti@apple.com | 78e5677 | 2013-09-29 04:34:37 +0000 | [diff] [blame] | 2756 | const RenderStyle& currentStyle = *current.m_obj->style(); |
eric@webkit.org | d4b9d77 | 2011-08-22 23:34:31 +0000 | [diff] [blame] | 2757 | RenderObject* next = bidiNextSkippingEmptyInlines(m_block, current.m_obj); |
yael.aharon@nokia.com | 1cfbceb | 2011-06-06 18:32:54 +0000 | [diff] [blame] | 2758 | if (next && next->parent() && !next->parent()->isDescendantOf(current.m_obj->parent())) |
| 2759 | includeEndWidth = true; |
mitz@apple.com | ddb5987 | 2011-04-05 05:21:16 +0000 | [diff] [blame] | 2760 | |
antti@apple.com | 78e5677 | 2013-09-29 04:34:37 +0000 | [diff] [blame] | 2761 | currWS = current.m_obj->isReplaced() ? current.m_obj->parent()->style()->whiteSpace() : currentStyle.whiteSpace(); |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 2762 | lastWS = last->isReplaced() ? last->parent()->style()->whiteSpace() : last->style()->whiteSpace(); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 2763 | |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 2764 | bool autoWrap = RenderStyle::autoWrap(currWS); |
ddkilzer | 5d01fa2 | 2007-01-29 03:10:37 +0000 | [diff] [blame] | 2765 | autoWrapWasEverTrueOnLine = autoWrapWasEverTrueOnLine || autoWrap; |
zimmermann | ac3781f | 2007-02-04 01:25:03 +0000 | [diff] [blame] | 2766 | |
mjs | d2948ef | 2007-02-26 19:29:04 +0000 | [diff] [blame] | 2767 | #if ENABLE(SVG) |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 2768 | bool preserveNewline = current.m_obj->isSVGInlineText() ? false : RenderStyle::preserveNewline(currWS); |
zimmermann | ac3781f | 2007-02-04 01:25:03 +0000 | [diff] [blame] | 2769 | #else |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 2770 | bool preserveNewline = RenderStyle::preserveNewline(currWS); |
zimmermann | ac3781f | 2007-02-04 01:25:03 +0000 | [diff] [blame] | 2771 | #endif |
| 2772 | |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 2773 | bool collapseWhiteSpace = RenderStyle::collapseWhiteSpace(currWS); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 2774 | |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 2775 | if (current.m_obj->isBR()) { |
rniwa@webkit.org | 5eb8d16 | 2011-04-13 02:13:33 +0000 | [diff] [blame] | 2776 | if (width.fitsOnLine()) { |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 2777 | lBreak.moveToStartOf(current.m_obj); |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 2778 | lBreak.increment(); |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 2779 | |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2780 | // A <br> always breaks a line, so don't let the line be collapsed |
| 2781 | // away. Also, the space at the end of a line with a <br> does not |
hyatt | 01eff98 | 2003-03-14 20:13:23 +0000 | [diff] [blame] | 2782 | // get collapsed away. It only does this if the previous line broke |
| 2783 | // cleanly. Otherwise the <br> has no effect on whether the line is |
| 2784 | // empty or not. |
leviw@chromium.org | f009c8e | 2011-05-03 20:49:15 +0000 | [diff] [blame] | 2785 | if (startingNewParagraph) |
hyatt@apple.com | 5950bd4 | 2011-09-27 20:39:57 +0000 | [diff] [blame] | 2786 | lineInfo.setEmpty(false, m_block, &width); |
rniwa@webkit.org | 105350c | 2011-05-03 20:33:25 +0000 | [diff] [blame] | 2787 | trailingObjects.clear(); |
leviw@chromium.org | f009c8e | 2011-05-03 20:49:15 +0000 | [diff] [blame] | 2788 | lineInfo.setPreviousLineBrokeCleanly(true); |
hyatt | 74eec4d | 2003-03-23 08:02:47 +0000 | [diff] [blame] | 2789 | |
robert@webkit.org | 3c75e50 | 2012-10-21 10:27:50 +0000 | [diff] [blame] | 2790 | // A <br> with clearance always needs a linebox in case the lines below it get dirtied later and |
| 2791 | // need to check for floats to clear - so if we're ignoring spaces, stop ignoring them and add a |
| 2792 | // run for this object. |
antti@apple.com | 78e5677 | 2013-09-29 04:34:37 +0000 | [diff] [blame] | 2793 | if (ignoringSpaces && currentStyle.clear() != CNONE) |
leviw@chromium.org | 0e7d89e | 2013-02-23 00:00:27 +0000 | [diff] [blame] | 2794 | ensureLineBoxInsideIgnoredSpaces(lineMidpointState, current.m_obj); |
robert@webkit.org | 2cb0264 | 2013-09-18 17:58:25 +0000 | [diff] [blame] | 2795 | // If we were preceded by collapsing space and are in a right-aligned container we need to ensure the space gets |
| 2796 | // collapsed away so that it doesn't push the text out from the container's right-hand edge. |
| 2797 | // FIXME: Do this regardless of the container's alignment - will require rebaselining a lot of test results. |
antti@apple.com | 78e5677 | 2013-09-29 04:34:37 +0000 | [diff] [blame] | 2798 | else if (ignoringSpaces && (blockStyle.textAlign() == RIGHT || blockStyle.textAlign() == WEBKIT_RIGHT)) |
robert@webkit.org | 2cb0264 | 2013-09-18 17:58:25 +0000 | [diff] [blame] | 2799 | stopIgnoringSpaces(lineMidpointState, InlineIterator(0, current.m_obj, current.m_pos)); |
robert@webkit.org | 3c75e50 | 2012-10-21 10:27:50 +0000 | [diff] [blame] | 2800 | |
leviw@chromium.org | 1a50869 | 2011-05-05 00:01:11 +0000 | [diff] [blame] | 2801 | if (!lineInfo.isEmpty()) |
antti@apple.com | 78e5677 | 2013-09-29 04:34:37 +0000 | [diff] [blame] | 2802 | m_clear = currentStyle.clear(); |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 2803 | } |
| 2804 | goto end; |
| 2805 | } |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 2806 | |
simon.fraser@apple.com | 2f07185 | 2012-06-25 00:11:30 +0000 | [diff] [blame] | 2807 | if (current.m_obj->isOutOfFlowPositioned()) { |
rniwa@webkit.org | 76aa522 | 2011-05-04 13:03:32 +0000 | [diff] [blame] | 2808 | // If our original display wasn't an inline type, then we can |
| 2809 | // go ahead and determine our static inline position now. |
| 2810 | RenderBox* box = toRenderBox(current.m_obj); |
| 2811 | bool isInlineType = box->style()->isOriginalDisplayInlineType(); |
| 2812 | if (!isInlineType) |
hyatt@apple.com | a5cac3f | 2011-10-12 18:51:17 +0000 | [diff] [blame] | 2813 | m_block->setStaticInlinePositionForChild(box, m_block->logicalHeight(), m_block->startOffsetForContent(m_block->logicalHeight())); |
rniwa@webkit.org | 76aa522 | 2011-05-04 13:03:32 +0000 | [diff] [blame] | 2814 | else { |
| 2815 | // If our original display was an INLINE type, then we can go ahead |
| 2816 | // and determine our static y position now. |
leviw@chromium.org | 1a50869 | 2011-05-05 00:01:11 +0000 | [diff] [blame] | 2817 | box->layer()->setStaticBlockPosition(m_block->logicalHeight()); |
hyatt | 98ee7e4 | 2003-05-14 01:39:15 +0000 | [diff] [blame] | 2818 | } |
rniwa@webkit.org | 76aa522 | 2011-05-04 13:03:32 +0000 | [diff] [blame] | 2819 | |
| 2820 | // If we're ignoring spaces, we have to stop and include this object and |
| 2821 | // then start ignoring spaces again. |
| 2822 | if (isInlineType || current.m_obj->container()->isRenderInline()) { |
leviw@chromium.org | 0e7d89e | 2013-02-23 00:00:27 +0000 | [diff] [blame] | 2823 | if (ignoringSpaces) |
| 2824 | ensureLineBoxInsideIgnoredSpaces(lineMidpointState, current.m_obj); |
rniwa@webkit.org | 76aa522 | 2011-05-04 13:03:32 +0000 | [diff] [blame] | 2825 | trailingObjects.appendBoxIfNeeded(box); |
| 2826 | } else |
leviw@chromium.org | 1a50869 | 2011-05-05 00:01:11 +0000 | [diff] [blame] | 2827 | m_positionedObjects.append(box); |
zalan@apple.com | 6833dd9 | 2013-09-27 12:47:52 +0000 | [diff] [blame] | 2828 | width.addUncommittedWidth(inlineLogicalWidth(current.m_obj), *current.m_obj); |
glenn@skynav.com | 1fa656a | 2013-03-11 03:30:57 +0000 | [diff] [blame] | 2829 | // Reset prior line break context characters. |
glenn@skynav.com | 61b1abf | 2013-04-02 23:28:32 +0000 | [diff] [blame] | 2830 | renderTextInfo.m_lineBreakIterator.resetPriorContext(); |
mitz@apple.com | d67fb21 | 2011-12-19 02:51:46 +0000 | [diff] [blame] | 2831 | } else if (current.m_obj->isFloating()) { |
| 2832 | RenderBox* floatBox = toRenderBox(current.m_obj); |
| 2833 | FloatingObject* f = m_block->insertFloatingObject(floatBox); |
| 2834 | // check if it fits in the current line. |
| 2835 | // If it does, position it now, otherwise, position |
| 2836 | // it after moving to next line (in newLine() func) |
commit-queue@webkit.org | 31a3bc7 | 2013-03-05 18:19:36 +0000 | [diff] [blame] | 2837 | // FIXME: Bug 110372: Properly position multiple stacked floats with non-rectangular shape outside. |
bjonesbe@adobe.com | 93de7e7 | 2013-09-04 18:01:27 +0000 | [diff] [blame] | 2838 | if (floatsFitOnLine && width.fitsOnLineExcludingTrailingWhitespace(f->logicalWidth(m_block->isHorizontalWritingMode()))) { |
mitz@apple.com | d67fb21 | 2011-12-19 02:51:46 +0000 | [diff] [blame] | 2839 | m_block->positionNewFloatOnLine(f, lastFloatFromPreviousLine, lineInfo, width); |
| 2840 | if (lBreak.m_obj == current.m_obj) { |
| 2841 | ASSERT(!lBreak.m_pos); |
| 2842 | lBreak.increment(); |
| 2843 | } |
| 2844 | } else |
| 2845 | floatsFitOnLine = false; |
glenn@skynav.com | 1fa656a | 2013-03-11 03:30:57 +0000 | [diff] [blame] | 2846 | // Update prior line break context characters, using U+FFFD (OBJECT REPLACEMENT CHARACTER) for floating element. |
glenn@skynav.com | 61b1abf | 2013-04-02 23:28:32 +0000 | [diff] [blame] | 2847 | renderTextInfo.m_lineBreakIterator.updatePriorContext(replacementCharacter); |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 2848 | } else if (current.m_obj->isRenderInline()) { |
antti@apple.com | 3ab7ef3 | 2013-09-29 20:50:01 +0000 | [diff] [blame] | 2849 | RenderInline& flowBox = toRenderInline(*current.m_obj); |
bdakin | f876bee | 2007-10-30 05:27:09 +0000 | [diff] [blame] | 2850 | // Right now, we should only encounter empty inlines here. |
antti@apple.com | 3ab7ef3 | 2013-09-29 20:50:01 +0000 | [diff] [blame] | 2851 | ASSERT(isEmptyInline(flowBox)); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 2852 | // Now that some inline flows have line boxes, if we are already ignoring spaces, we need |
| 2853 | // to make sure that we stop to include this object and then start ignoring spaces again. |
| 2854 | // If this object is at the start of the line, we need to behave like list markers and |
bdakin | f876bee | 2007-10-30 05:27:09 +0000 | [diff] [blame] | 2855 | // start ignoring spaces. |
antti@apple.com | 3ab7ef3 | 2013-09-29 20:50:01 +0000 | [diff] [blame] | 2856 | bool requiresLineBox = alwaysRequiresLineBox(flowBox); |
robert@webkit.org | 56e5a9f | 2012-02-17 21:10:42 +0000 | [diff] [blame] | 2857 | if (requiresLineBox || requiresLineBoxForContent(flowBox, lineInfo)) { |
| 2858 | // An empty inline that only has line-height, vertical-align or font-metrics will only get a |
| 2859 | // line box to affect the height of the line if the rest of the line is not empty. |
| 2860 | if (requiresLineBox) |
| 2861 | lineInfo.setEmpty(false, m_block, &width); |
bdakin | f876bee | 2007-10-30 05:27:09 +0000 | [diff] [blame] | 2862 | if (ignoringSpaces) { |
rniwa@webkit.org | 105350c | 2011-05-03 20:33:25 +0000 | [diff] [blame] | 2863 | trailingObjects.clear(); |
leviw@chromium.org | 0e7d89e | 2013-02-23 00:00:27 +0000 | [diff] [blame] | 2864 | ensureLineBoxInsideIgnoredSpaces(lineMidpointState, current.m_obj); |
antti@apple.com | 78e5677 | 2013-09-29 04:34:37 +0000 | [diff] [blame] | 2865 | } else if (blockStyle.collapseWhiteSpace() && resolver.position().m_obj == current.m_obj |
leviw@chromium.org | 1a50869 | 2011-05-05 00:01:11 +0000 | [diff] [blame] | 2866 | && shouldSkipWhitespaceAfterStartObject(m_block, current.m_obj, lineMidpointState)) { |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 2867 | // Like with list markers, we start ignoring spaces to make sure that any |
bdakin | f876bee | 2007-10-30 05:27:09 +0000 | [diff] [blame] | 2868 | // additional spaces we see will be discarded. |
| 2869 | currentCharacterIsSpace = true; |
| 2870 | currentCharacterIsWS = true; |
| 2871 | ignoringSpaces = true; |
commit-queue@webkit.org | 6af4887 | 2013-04-09 16:46:49 +0000 | [diff] [blame] | 2872 | } else { |
antti@apple.com | 3ab7ef3 | 2013-09-29 20:50:01 +0000 | [diff] [blame] | 2873 | trailingObjects.appendBoxIfNeeded(&flowBox); |
bdakin | f876bee | 2007-10-30 05:27:09 +0000 | [diff] [blame] | 2874 | } |
| 2875 | } |
| 2876 | |
zalan@apple.com | 6833dd9 | 2013-09-27 12:47:52 +0000 | [diff] [blame] | 2877 | width.addUncommittedWidth(inlineLogicalWidth(current.m_obj) + borderPaddingMarginStart(flowBox) + borderPaddingMarginEnd(flowBox), *current.m_obj); |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 2878 | } else if (current.m_obj->isReplaced()) { |
| 2879 | RenderBox* replacedBox = toRenderBox(current.m_obj); |
hyatt@apple.com | d885df7 | 2009-01-22 02:31:52 +0000 | [diff] [blame] | 2880 | |
robert@webkit.org | 0903cf5 | 2012-12-11 18:14:16 +0000 | [diff] [blame] | 2881 | if (atStart) |
| 2882 | width.updateAvailableWidth(replacedBox->logicalHeight()); |
| 2883 | |
hyatt | de39634 | 2003-10-29 08:57:20 +0000 | [diff] [blame] | 2884 | // Break on replaced elements if either has normal white-space. |
robert@webkit.org | 1f81153 | 2013-06-24 20:09:20 +0000 | [diff] [blame] | 2885 | if ((autoWrap || RenderStyle::autoWrap(lastWS)) && (!current.m_obj->isImage() || allowImagesToBreak)) |
| 2886 | commitLineBreakAtCurrentWidth(width, lBreak, current.m_obj); |
hyatt | 711fe23 | 2002-11-20 21:25:14 +0000 | [diff] [blame] | 2887 | |
mitz@apple.com | bfdc911 | 2008-02-21 19:59:40 +0000 | [diff] [blame] | 2888 | if (ignoringSpaces) |
leviw@chromium.org | 0e7d89e | 2013-02-23 00:00:27 +0000 | [diff] [blame] | 2889 | stopIgnoringSpaces(lineMidpointState, InlineIterator(0, current.m_obj, 0)); |
mitz@apple.com | bfdc911 | 2008-02-21 19:59:40 +0000 | [diff] [blame] | 2890 | |
hyatt@apple.com | 5950bd4 | 2011-09-27 20:39:57 +0000 | [diff] [blame] | 2891 | lineInfo.setEmpty(false, m_block, &width); |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2892 | ignoringSpaces = false; |
rjw | c9c257d | 2003-01-24 03:46:17 +0000 | [diff] [blame] | 2893 | currentCharacterIsSpace = false; |
harrison | e343c41 | 2005-01-18 01:07:26 +0000 | [diff] [blame] | 2894 | currentCharacterIsWS = false; |
rniwa@webkit.org | 105350c | 2011-05-03 20:33:25 +0000 | [diff] [blame] | 2895 | trailingObjects.clear(); |
hamaji@chromium.org | 382642b | 2009-12-01 07:37:14 +0000 | [diff] [blame] | 2896 | |
bdakin | f876bee | 2007-10-30 05:27:09 +0000 | [diff] [blame] | 2897 | // Optimize for a common case. If we can't find whitespace after the list |
hyatt@apple.com | 0415e5d | 2010-10-07 17:40:25 +0000 | [diff] [blame] | 2898 | // item, then this is all moot. |
eae@chromium.org | ee8613e | 2011-11-12 01:12:58 +0000 | [diff] [blame] | 2899 | LayoutUnit replacedLogicalWidth = m_block->logicalWidthForChild(replacedBox) + m_block->marginStartForChild(replacedBox) + m_block->marginEndForChild(replacedBox) + inlineLogicalWidth(current.m_obj); |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 2900 | if (current.m_obj->isListMarker()) { |
antti@apple.com | 78e5677 | 2013-09-29 04:34:37 +0000 | [diff] [blame] | 2901 | if (blockStyle.collapseWhiteSpace() && shouldSkipWhitespaceAfterStartObject(m_block, current.m_obj, lineMidpointState)) { |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 2902 | // Like with inline flows, we start ignoring spaces to make sure that any |
bdakin | f876bee | 2007-10-30 05:27:09 +0000 | [diff] [blame] | 2903 | // additional spaces we see will be discarded. |
| 2904 | currentCharacterIsSpace = true; |
| 2905 | currentCharacterIsWS = true; |
| 2906 | ignoringSpaces = true; |
hyatt | e85e4a7 | 2002-12-08 02:06:16 +0000 | [diff] [blame] | 2907 | } |
akling@apple.com | 4c166d6 | 2013-09-01 05:29:00 +0000 | [diff] [blame] | 2908 | if (toRenderListMarker(*current.m_obj).isInside()) |
zalan@apple.com | 6833dd9 | 2013-09-27 12:47:52 +0000 | [diff] [blame] | 2909 | width.addUncommittedWidth(replacedLogicalWidth, *current.m_obj); |
justing | 244d3a3 | 2006-04-13 01:31:24 +0000 | [diff] [blame] | 2910 | } else |
zalan@apple.com | 6833dd9 | 2013-09-27 12:47:52 +0000 | [diff] [blame] | 2911 | width.addUncommittedWidth(replacedLogicalWidth, *current.m_obj); |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 2912 | if (current.m_obj->isRubyRun()) |
| 2913 | width.applyOverhang(toRenderRubyRun(current.m_obj), last, next); |
glenn@skynav.com | 1fa656a | 2013-03-11 03:30:57 +0000 | [diff] [blame] | 2914 | // Update prior line break context characters, using U+FFFD (OBJECT REPLACEMENT CHARACTER) for replaced element. |
glenn@skynav.com | 61b1abf | 2013-04-02 23:28:32 +0000 | [diff] [blame] | 2915 | renderTextInfo.m_lineBreakIterator.updatePriorContext(replacementCharacter); |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 2916 | } else if (current.m_obj->isText()) { |
| 2917 | if (!current.m_pos) |
mitz@apple.com | 5101732 | 2008-02-26 06:47:43 +0000 | [diff] [blame] | 2918 | appliedStartWidth = false; |
| 2919 | |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 2920 | RenderText* t = toRenderText(current.m_obj); |
mitz@apple.com | fb8da4e | 2008-02-19 21:13:19 +0000 | [diff] [blame] | 2921 | |
zimmermann@webkit.org | 6e96afd | 2010-09-10 15:35:50 +0000 | [diff] [blame] | 2922 | #if ENABLE(SVG) |
| 2923 | bool isSVGText = t->isSVGInlineText(); |
| 2924 | #endif |
| 2925 | |
robert@webkit.org | c522345 | 2013-06-12 19:20:33 +0000 | [diff] [blame] | 2926 | // If we have left a no-wrap inline and entered an autowrap inline while ignoring spaces |
| 2927 | // then we need to mark the start of the autowrap inline as a potential linebreak now. |
robert@webkit.org | 1f81153 | 2013-06-24 20:09:20 +0000 | [diff] [blame] | 2928 | if (autoWrap && !RenderStyle::autoWrap(lastWS) && ignoringSpaces) |
| 2929 | commitLineBreakAtCurrentWidth(width, lBreak, current.m_obj); |
robert@webkit.org | c522345 | 2013-06-12 19:20:33 +0000 | [diff] [blame] | 2930 | |
akling@apple.com | 4c166d6 | 2013-09-01 05:29:00 +0000 | [diff] [blame] | 2931 | if (t->style()->hasTextCombine() && current.m_obj->isCombineText() && !toRenderCombineText(*current.m_obj).isCombined()) { |
| 2932 | RenderCombineText& combineRenderer = toRenderCombineText(*current.m_obj); |
| 2933 | combineRenderer.combineText(); |
leviw@chromium.org | 17fe64d | 2013-04-02 23:10:49 +0000 | [diff] [blame] | 2934 | // The length of the renderer's text may have changed. Increment stale iterator positions |
| 2935 | if (iteratorIsBeyondEndOfRenderCombineText(lBreak, combineRenderer)) { |
| 2936 | ASSERT(iteratorIsBeyondEndOfRenderCombineText(resolver.position(), combineRenderer)); |
| 2937 | lBreak.increment(); |
| 2938 | resolver.increment(); |
| 2939 | } |
| 2940 | } |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 2941 | |
antti@apple.com | 78e5677 | 2013-09-29 04:34:37 +0000 | [diff] [blame] | 2942 | const RenderStyle& style = lineStyle(*t->parent(), lineInfo); |
antti@apple.com | b0608f6 | 2013-09-28 18:30:16 +0000 | [diff] [blame] | 2943 | const Font& f = style.font(); |
mitz@apple.com | 3410644 | 2009-02-01 06:23:39 +0000 | [diff] [blame] | 2944 | bool isFixedPitch = f.isFixedPitch(); |
antti@apple.com | b0608f6 | 2013-09-28 18:30:16 +0000 | [diff] [blame] | 2945 | bool canHyphenate = style.hyphens() == HyphensAuto && WebCore::canHyphenate(style.locale()); |
weinig | f28a1c3 | 2007-02-14 14:10:31 +0000 | [diff] [blame] | 2946 | |
msaboff@apple.com | 776c286c7 | 2012-10-15 16:56:29 +0000 | [diff] [blame] | 2947 | unsigned lastSpace = current.m_pos; |
antti@apple.com | 78e5677 | 2013-09-29 04:34:37 +0000 | [diff] [blame] | 2948 | float wordSpacing = currentStyle.wordSpacing(); |
hyatt@apple.com | 0acc935 | 2011-02-17 19:19:07 +0000 | [diff] [blame] | 2949 | float lastSpaceWordSpacing = 0; |
enrica@apple.com | 885c84d | 2012-10-10 05:48:51 +0000 | [diff] [blame] | 2950 | float wordSpacingForWordMeasurement = 0; |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 2951 | |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 2952 | float wrapW = width.uncommittedWidth() + inlineLogicalWidth(current.m_obj, !appliedStartWidth, true); |
hyatt@apple.com | 0acc935 | 2011-02-17 19:19:07 +0000 | [diff] [blame] | 2953 | float charWidth = 0; |
antti@apple.com | 78e5677 | 2013-09-29 04:34:37 +0000 | [diff] [blame] | 2954 | bool breakNBSP = autoWrap && currentStyle.nbspMode() == SPACE; |
weinig | f28a1c3 | 2007-02-14 14:10:31 +0000 | [diff] [blame] | 2955 | // Auto-wrapping text should wrap in the middle of a word only if it could not wrap before the word, |
| 2956 | // which is only possible if the word is the first thing on the line, that is, if |w| is zero. |
antti@apple.com | 78e5677 | 2013-09-29 04:34:37 +0000 | [diff] [blame] | 2957 | bool breakWords = currentStyle.breakWords() && ((autoWrap && !width.committedWidth()) || currWS == PRE); |
weinig | f28a1c3 | 2007-02-14 14:10:31 +0000 | [diff] [blame] | 2958 | bool midWordBreak = false; |
antti@apple.com | 78e5677 | 2013-09-29 04:34:37 +0000 | [diff] [blame] | 2959 | bool breakAll = currentStyle.wordBreak() == BreakAllWordBreak && autoWrap; |
hyatt@apple.com | 0acc935 | 2011-02-17 19:19:07 +0000 | [diff] [blame] | 2960 | float hyphenWidth = 0; |
commit-queue@webkit.org | 4f54eff | 2013-03-08 14:32:54 +0000 | [diff] [blame] | 2961 | #if ENABLE(SVG) |
| 2962 | if (isSVGText) { |
| 2963 | breakWords = false; |
| 2964 | breakAll = false; |
| 2965 | } |
| 2966 | #endif |
hyatt | ea474f7 | 2007-04-20 05:02:19 +0000 | [diff] [blame] | 2967 | |
commit-queue@webkit.org | d639fb7 | 2012-09-01 19:46:16 +0000 | [diff] [blame] | 2968 | if (renderTextInfo.m_text != t) { |
esprehn@chromium.org | 7745ffb | 2013-02-19 21:51:19 +0000 | [diff] [blame] | 2969 | updateCounterIfNeeded(t); |
mitz@apple.com | 6a85960 | 2012-08-27 15:31:56 +0000 | [diff] [blame] | 2970 | renderTextInfo.m_text = t; |
mitz@apple.com | d4c153d | 2012-09-16 23:36:41 +0000 | [diff] [blame] | 2971 | renderTextInfo.m_font = &f; |
mitz@apple.com | 6a85960 | 2012-08-27 15:31:56 +0000 | [diff] [blame] | 2972 | renderTextInfo.m_layout = f.createLayout(t, width.currentWidth(), collapseWhiteSpace); |
antti@apple.com | b0608f6 | 2013-09-28 18:30:16 +0000 | [diff] [blame] | 2973 | renderTextInfo.m_lineBreakIterator.resetStringAndReleaseIterator(t->text(), style.locale()); |
mitz@apple.com | d4c153d | 2012-09-16 23:36:41 +0000 | [diff] [blame] | 2974 | } else if (renderTextInfo.m_layout && renderTextInfo.m_font != &f) { |
| 2975 | renderTextInfo.m_font = &f; |
| 2976 | renderTextInfo.m_layout = f.createLayout(t, width.currentWidth(), collapseWhiteSpace); |
mitz@apple.com | 6a85960 | 2012-08-27 15:31:56 +0000 | [diff] [blame] | 2977 | } |
mitz@apple.com | d4c153d | 2012-09-16 23:36:41 +0000 | [diff] [blame] | 2978 | |
mitz@apple.com | 6a85960 | 2012-08-27 15:31:56 +0000 | [diff] [blame] | 2979 | TextLayout* textLayout = renderTextInfo.m_layout.get(); |
| 2980 | |
mitz@apple.com | 8520cd8 | 2012-09-22 01:00:01 +0000 | [diff] [blame] | 2981 | // Non-zero only when kerning is enabled and TextLayout isn't used, in which case we measure |
| 2982 | // words with their trailing space, then subtract its width. |
rniwa@webkit.org | fe811f2 | 2013-06-07 17:59:01 +0000 | [diff] [blame] | 2983 | HashSet<const SimpleFontData*> fallbackFonts; |
antti@apple.com | 78e5677 | 2013-09-29 04:34:37 +0000 | [diff] [blame] | 2984 | float wordTrailingSpaceWidth = (f.typesettingFeatures() & Kerning) && !textLayout ? f.width(RenderBlock::constructTextRun(t, f, &space, 1, style), &fallbackFonts) + wordSpacing : 0; |
mitz@apple.com | 8520cd8 | 2012-09-22 01:00:01 +0000 | [diff] [blame] | 2985 | |
glenn@skynav.com | 61b1abf | 2013-04-02 23:28:32 +0000 | [diff] [blame] | 2986 | UChar lastCharacter = renderTextInfo.m_lineBreakIterator.lastCharacter(); |
| 2987 | UChar secondToLastCharacter = renderTextInfo.m_lineBreakIterator.secondToLastCharacter(); |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 2988 | for (; current.m_pos < t->textLength(); current.fastIncrementInTextNode()) { |
rjw | c9c257d | 2003-01-24 03:46:17 +0000 | [diff] [blame] | 2989 | bool previousCharacterIsSpace = currentCharacterIsSpace; |
harrison | e343c41 | 2005-01-18 01:07:26 +0000 | [diff] [blame] | 2990 | bool previousCharacterIsWS = currentCharacterIsWS; |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 2991 | UChar c = current.current(); |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 2992 | currentCharacterIsSpace = c == ' ' || c == '\t' || (!preserveNewline && (c == '\n')); |
darin | 47ece0d | 2005-09-04 07:42:31 +0000 | [diff] [blame] | 2993 | |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 2994 | if (!collapseWhiteSpace || !currentCharacterIsSpace) |
hyatt@apple.com | 5950bd4 | 2011-09-27 20:39:57 +0000 | [diff] [blame] | 2995 | lineInfo.setEmpty(false, m_block, &width); |
mitz@apple.com | be42956 | 2008-03-07 01:09:51 +0000 | [diff] [blame] | 2996 | |
antti@apple.com | b0608f6 | 2013-09-28 18:30:16 +0000 | [diff] [blame] | 2997 | if (c == softHyphen && autoWrap && !hyphenWidth && style.hyphens() != HyphensNone) { |
rniwa@webkit.org | fe811f2 | 2013-06-07 17:59:01 +0000 | [diff] [blame] | 2998 | hyphenWidth = measureHyphenWidth(t, f, &fallbackFonts); |
zalan@apple.com | 6833dd9 | 2013-09-27 12:47:52 +0000 | [diff] [blame] | 2999 | width.addUncommittedWidth(hyphenWidth, *current.m_obj); |
hyatt | 78b8513 | 2004-03-29 20:07:45 +0000 | [diff] [blame] | 3000 | } |
mitz@apple.com | 20e3445 | 2010-09-28 19:38:15 +0000 | [diff] [blame] | 3001 | |
hyatt | 3aff233 | 2003-01-23 01:15:28 +0000 | [diff] [blame] | 3002 | bool applyWordSpacing = false; |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 3003 | |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 3004 | currentCharacterIsWS = currentCharacterIsSpace || (breakNBSP && c == noBreakSpace); |
harrison | e343c41 | 2005-01-18 01:07:26 +0000 | [diff] [blame] | 3005 | |
weinig | ed111c1 | 2007-07-13 22:45:11 +0000 | [diff] [blame] | 3006 | if ((breakAll || breakWords) && !midWordBreak) { |
| 3007 | wrapW += charWidth; |
mitz@apple.com | 880d8e1 | 2011-08-17 20:52:31 +0000 | [diff] [blame] | 3008 | bool midWordBreakIsBeforeSurrogatePair = U16_IS_LEAD(c) && current.m_pos + 1 < t->textLength() && U16_IS_TRAIL(t->characters()[current.m_pos + 1]); |
rniwa@webkit.org | fe811f2 | 2013-06-07 17:59:01 +0000 | [diff] [blame] | 3009 | charWidth = textWidth(t, current.m_pos, midWordBreakIsBeforeSurrogatePair ? 2 : 1, f, width.committedWidth() + wrapW, isFixedPitch, collapseWhiteSpace, fallbackFonts, textLayout); |
rniwa@webkit.org | 5eb8d16 | 2011-04-13 02:13:33 +0000 | [diff] [blame] | 3010 | midWordBreak = width.committedWidth() + wrapW + charWidth > width.availableWidth(); |
weinig | f28a1c3 | 2007-02-14 14:10:31 +0000 | [diff] [blame] | 3011 | } |
darin | 47ece0d | 2005-09-04 07:42:31 +0000 | [diff] [blame] | 3012 | |
commit-queue@webkit.org | a94b1b3 | 2013-02-26 18:38:39 +0000 | [diff] [blame] | 3013 | bool betweenWords = c == '\n' || (currWS != PRE && !atStart && isBreakable(renderTextInfo.m_lineBreakIterator, current.m_pos, current.m_nextBreakablePosition, breakNBSP) |
antti@apple.com | b0608f6 | 2013-09-28 18:30:16 +0000 | [diff] [blame] | 3014 | && (style.hyphens() != HyphensNone || (current.previousInSameNode() != softHyphen))); |
mitz@apple.com | 20e3445 | 2010-09-28 19:38:15 +0000 | [diff] [blame] | 3015 | |
weinig | ed111c1 | 2007-07-13 22:45:11 +0000 | [diff] [blame] | 3016 | if (betweenWords || midWordBreak) { |
hyatt | 0c05e10 | 2006-04-14 08:15:00 +0000 | [diff] [blame] | 3017 | bool stoppedIgnoringSpaces = false; |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 3018 | if (ignoringSpaces) { |
leviw@chromium.org | a16671e | 2013-02-20 23:44:21 +0000 | [diff] [blame] | 3019 | lastSpaceWordSpacing = 0; |
rjw | c9c257d | 2003-01-24 03:46:17 +0000 | [diff] [blame] | 3020 | if (!currentCharacterIsSpace) { |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 3021 | // Stop ignoring spaces and begin at this |
| 3022 | // new point. |
hyatt | 48710d6 | 2003-08-21 09:17:13 +0000 | [diff] [blame] | 3023 | ignoringSpaces = false; |
enrica@apple.com | 885c84d | 2012-10-10 05:48:51 +0000 | [diff] [blame] | 3024 | wordSpacingForWordMeasurement = 0; |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 3025 | lastSpace = current.m_pos; // e.g., "Foo goo", don't add in any of the ignored spaces. |
leviw@chromium.org | 0e7d89e | 2013-02-23 00:00:27 +0000 | [diff] [blame] | 3026 | stopIgnoringSpaces(lineMidpointState, InlineIterator(0, current.m_obj, current.m_pos)); |
hyatt | 0c05e10 | 2006-04-14 08:15:00 +0000 | [diff] [blame] | 3027 | stoppedIgnoringSpaces = true; |
harrison | e343c41 | 2005-01-18 01:07:26 +0000 | [diff] [blame] | 3028 | } else { |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 3029 | // Just keep ignoring these spaces. |
glenn@skynav.com | 1fa656a | 2013-03-11 03:30:57 +0000 | [diff] [blame] | 3030 | goto nextCharacter; |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 3031 | } |
| 3032 | } |
rjw | c9c257d | 2003-01-24 03:46:17 +0000 | [diff] [blame] | 3033 | |
enrica@apple.com | 885c84d | 2012-10-10 05:48:51 +0000 | [diff] [blame] | 3034 | wordMeasurements.grow(wordMeasurements.size() + 1); |
| 3035 | WordMeasurement& wordMeasurement = wordMeasurements.last(); |
| 3036 | |
| 3037 | wordMeasurement.renderer = t; |
| 3038 | wordMeasurement.endOffset = current.m_pos; |
| 3039 | wordMeasurement.startOffset = lastSpace; |
zoltan@webkit.org | e1a0c95 | 2013-09-18 03:27:35 +0000 | [diff] [blame] | 3040 | |
commit-queue@webkit.org | 1776140 | 2013-04-17 18:48:56 +0000 | [diff] [blame] | 3041 | float additionalTempWidth; |
mitz@apple.com | dc33a5f6 | 2012-11-28 19:43:24 +0000 | [diff] [blame] | 3042 | if (wordTrailingSpaceWidth && c == ' ') |
rniwa@webkit.org | fe811f2 | 2013-06-07 17:59:01 +0000 | [diff] [blame] | 3043 | additionalTempWidth = textWidth(t, lastSpace, current.m_pos + 1 - lastSpace, f, width.currentWidth(), isFixedPitch, collapseWhiteSpace, wordMeasurement.fallbackFonts, textLayout) - wordTrailingSpaceWidth; |
mitz@apple.com | fa13fcc | 2010-01-07 01:41:32 +0000 | [diff] [blame] | 3044 | else |
rniwa@webkit.org | fe811f2 | 2013-06-07 17:59:01 +0000 | [diff] [blame] | 3045 | additionalTempWidth = textWidth(t, lastSpace, current.m_pos - lastSpace, f, width.currentWidth(), isFixedPitch, collapseWhiteSpace, wordMeasurement.fallbackFonts, textLayout); |
| 3046 | |
| 3047 | if (wordMeasurement.fallbackFonts.isEmpty() && !fallbackFonts.isEmpty()) |
| 3048 | wordMeasurement.fallbackFonts.swap(fallbackFonts); |
| 3049 | fallbackFonts.clear(); |
enrica@apple.com | 885c84d | 2012-10-10 05:48:51 +0000 | [diff] [blame] | 3050 | |
commit-queue@webkit.org | 1776140 | 2013-04-17 18:48:56 +0000 | [diff] [blame] | 3051 | wordMeasurement.width = additionalTempWidth + wordSpacingForWordMeasurement; |
| 3052 | additionalTempWidth += lastSpaceWordSpacing; |
zalan@apple.com | 6833dd9 | 2013-09-27 12:47:52 +0000 | [diff] [blame] | 3053 | width.addUncommittedWidth(additionalTempWidth, *current.m_obj); |
commit-queue@webkit.org | 1776140 | 2013-04-17 18:48:56 +0000 | [diff] [blame] | 3054 | |
| 3055 | if (collapseWhiteSpace && previousCharacterIsSpace && currentCharacterIsSpace && additionalTempWidth) |
| 3056 | width.setTrailingWhitespaceWidth(additionalTempWidth); |
| 3057 | |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 3058 | if (!appliedStartWidth) { |
zalan@apple.com | 6833dd9 | 2013-09-27 12:47:52 +0000 | [diff] [blame] | 3059 | width.addUncommittedWidth(inlineLogicalWidth(current.m_obj, true, false), *current.m_obj); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 3060 | appliedStartWidth = true; |
| 3061 | } |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 3062 | |
zoltan@webkit.org | e1a0c95 | 2013-09-18 03:27:35 +0000 | [diff] [blame] | 3063 | #if ENABLE(CSS_SHAPES) |
| 3064 | if (lastFloatFromPreviousLine) |
| 3065 | updateSegmentsForShapes(m_block, lastFloatFromPreviousLine, wordMeasurements, width, lineInfo.isFirstLine()); |
| 3066 | #endif |
enrica@apple.com | 885c84d | 2012-10-10 05:48:51 +0000 | [diff] [blame] | 3067 | applyWordSpacing = wordSpacing && currentCharacterIsSpace; |
hyatt | 3aff233 | 2003-01-23 01:15:28 +0000 | [diff] [blame] | 3068 | |
rniwa@webkit.org | 5eb8d16 | 2011-04-13 02:13:33 +0000 | [diff] [blame] | 3069 | if (!width.committedWidth() && autoWrap && !width.fitsOnLine()) |
rniwa@webkit.org | 4442475 | 2011-04-14 00:58:40 +0000 | [diff] [blame] | 3070 | width.fitBelowFloats(); |
mitz@apple.com | cfd9b7b | 2008-02-24 04:00:21 +0000 | [diff] [blame] | 3071 | |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 3072 | if (autoWrap || breakWords) { |
hyatt | dca76e9 | 2005-11-02 08:52:50 +0000 | [diff] [blame] | 3073 | // If we break only after white-space, consider the current character |
kocienda | e413424 | 2004-10-25 18:48:44 +0000 | [diff] [blame] | 3074 | // as candidate width for this line. |
ap | 932806a | 2006-10-01 09:06:09 +0000 | [diff] [blame] | 3075 | bool lineWasTooWide = false; |
antti@apple.com | 78e5677 | 2013-09-29 04:34:37 +0000 | [diff] [blame] | 3076 | if (width.fitsOnLine() && currentCharacterIsWS && currentStyle.breakOnlyAfterWhiteSpace() && !midWordBreak) { |
rniwa@webkit.org | fe811f2 | 2013-06-07 17:59:01 +0000 | [diff] [blame] | 3077 | float charWidth = textWidth(t, current.m_pos, 1, f, width.currentWidth(), isFixedPitch, collapseWhiteSpace, wordMeasurement.fallbackFonts, textLayout) + (applyWordSpacing ? wordSpacing : 0); |
ap | 932806a | 2006-10-01 09:06:09 +0000 | [diff] [blame] | 3078 | // Check if line is too big even without the extra space |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 3079 | // at the end of the line. If it is not, do nothing. |
| 3080 | // If the line needs the extra whitespace to be too long, |
| 3081 | // then move the line break to the space and skip all |
ap | 932806a | 2006-10-01 09:06:09 +0000 | [diff] [blame] | 3082 | // additional whitespace. |
robert@webkit.org | 7a80c02 | 2013-06-21 21:04:21 +0000 | [diff] [blame] | 3083 | if (!width.fitsOnLineIncludingExtraWidth(charWidth)) { |
ap | 932806a | 2006-10-01 09:06:09 +0000 | [diff] [blame] | 3084 | lineWasTooWide = true; |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 3085 | lBreak.moveTo(current.m_obj, current.m_pos, current.m_nextBreakablePosition); |
leviw@chromium.org | f009c8e | 2011-05-03 20:49:15 +0000 | [diff] [blame] | 3086 | skipTrailingWhitespace(lBreak, lineInfo); |
kocienda | 9dbe9b1 | 2004-10-22 20:07:05 +0000 | [diff] [blame] | 3087 | } |
ap | 932806a | 2006-10-01 09:06:09 +0000 | [diff] [blame] | 3088 | } |
rniwa@webkit.org | 5eb8d16 | 2011-04-13 02:13:33 +0000 | [diff] [blame] | 3089 | if (lineWasTooWide || !width.fitsOnLine()) { |
| 3090 | if (canHyphenate && !width.fitsOnLine()) { |
antti@apple.com | 78e5677 | 2013-09-29 04:34:37 +0000 | [diff] [blame] | 3091 | tryHyphenating(t, f, style.locale(), consecutiveHyphenatedLines, blockStyle.hyphenationLimitLines(), style.hyphenationLimitBefore(), style.hyphenationLimitAfter(), lastSpace, current.m_pos, width.currentWidth() - additionalTempWidth, width.availableWidth(), isFixedPitch, collapseWhiteSpace, lastSpaceWordSpacing, lBreak, current.m_nextBreakablePosition, m_hyphenated); |
leviw@chromium.org | 1a50869 | 2011-05-05 00:01:11 +0000 | [diff] [blame] | 3092 | if (m_hyphenated) |
mitz@apple.com | 67ed70a | 2010-06-22 22:10:10 +0000 | [diff] [blame] | 3093 | goto end; |
| 3094 | } |
leviw@chromium.org | cee2051 | 2011-04-06 12:12:58 +0000 | [diff] [blame] | 3095 | if (lBreak.atTextParagraphSeparator()) { |
leviw@chromium.org | 0e7d89e | 2013-02-23 00:00:27 +0000 | [diff] [blame] | 3096 | if (!stoppedIgnoringSpaces && current.m_pos > 0) |
| 3097 | ensureCharacterGetsLineBox(lineMidpointState, current); |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 3098 | lBreak.increment(); |
leviw@chromium.org | f009c8e | 2011-05-03 20:49:15 +0000 | [diff] [blame] | 3099 | lineInfo.setPreviousLineBrokeCleanly(true); |
enrica@apple.com | 885c84d | 2012-10-10 05:48:51 +0000 | [diff] [blame] | 3100 | wordMeasurement.endOffset = lBreak.m_pos; |
adele | 7fc3e83 | 2006-02-17 09:31:35 +0000 | [diff] [blame] | 3101 | } |
antti@apple.com | b0608f6 | 2013-09-28 18:30:16 +0000 | [diff] [blame] | 3102 | if (lBreak.m_obj && lBreak.m_pos && lBreak.m_obj->isText() && toRenderText(lBreak.m_obj)->textLength() && toRenderText(lBreak.m_obj)->characterAt(lBreak.m_pos - 1) == softHyphen && style.hyphens() != HyphensNone) |
leviw@chromium.org | 1a50869 | 2011-05-05 00:01:11 +0000 | [diff] [blame] | 3103 | m_hyphenated = true; |
enrica@apple.com | 885c84d | 2012-10-10 05:48:51 +0000 | [diff] [blame] | 3104 | if (lBreak.m_pos && lBreak.m_pos != (unsigned)wordMeasurement.endOffset && !wordMeasurement.width) { |
| 3105 | if (charWidth) { |
| 3106 | wordMeasurement.endOffset = lBreak.m_pos; |
| 3107 | wordMeasurement.width = charWidth; |
| 3108 | } |
| 3109 | } |
commit-queue@webkit.org | 63cc2d0 | 2013-01-02 22:52:58 +0000 | [diff] [blame] | 3110 | // Didn't fit. Jump to the end unless there's still an opportunity to collapse whitespace. |
leviw@chromium.org | 0e7d89e | 2013-02-23 00:00:27 +0000 | [diff] [blame] | 3111 | if (ignoringSpaces || !collapseWhiteSpace || !currentCharacterIsSpace || !previousCharacterIsSpace) |
commit-queue@webkit.org | 63cc2d0 | 2013-01-02 22:52:58 +0000 | [diff] [blame] | 3112 | goto end; |
darin | 5400892 | 2006-01-13 16:39:05 +0000 | [diff] [blame] | 3113 | } else { |
weinig | ed111c1 | 2007-07-13 22:45:11 +0000 | [diff] [blame] | 3114 | if (!betweenWords || (midWordBreak && !autoWrap)) |
zalan@apple.com | 6833dd9 | 2013-09-27 12:47:52 +0000 | [diff] [blame] | 3115 | width.addUncommittedWidth(-additionalTempWidth, *current.m_obj); |
mitz@apple.com | 20e3445 | 2010-09-28 19:38:15 +0000 | [diff] [blame] | 3116 | if (hyphenWidth) { |
darin | 5400892 | 2006-01-13 16:39:05 +0000 | [diff] [blame] | 3117 | // Subtract the width of the soft hyphen out since we fit on a line. |
zalan@apple.com | 6833dd9 | 2013-09-27 12:47:52 +0000 | [diff] [blame] | 3118 | width.addUncommittedWidth(-hyphenWidth, *current.m_obj); |
mitz@apple.com | 20e3445 | 2010-09-28 19:38:15 +0000 | [diff] [blame] | 3119 | hyphenWidth = 0; |
| 3120 | } |
darin | 5400892 | 2006-01-13 16:39:05 +0000 | [diff] [blame] | 3121 | } |
rjw | c9c257d | 2003-01-24 03:46:17 +0000 | [diff] [blame] | 3122 | } |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 3123 | |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 3124 | if (c == '\n' && preserveNewline) { |
leviw@chromium.org | 0e7d89e | 2013-02-23 00:00:27 +0000 | [diff] [blame] | 3125 | if (!stoppedIgnoringSpaces && current.m_pos > 0) |
| 3126 | ensureCharacterGetsLineBox(lineMidpointState, current); |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 3127 | lBreak.moveTo(current.m_obj, current.m_pos, current.m_nextBreakablePosition); |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 3128 | lBreak.increment(); |
leviw@chromium.org | f009c8e | 2011-05-03 20:49:15 +0000 | [diff] [blame] | 3129 | lineInfo.setPreviousLineBrokeCleanly(true); |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 3130 | return lBreak; |
| 3131 | } |
hyatt | a9f48e3 | 2003-02-03 22:48:01 +0000 | [diff] [blame] | 3132 | |
weinig | f28a1c3 | 2007-02-14 14:10:31 +0000 | [diff] [blame] | 3133 | if (autoWrap && betweenWords) { |
weinig | ed111c1 | 2007-07-13 22:45:11 +0000 | [diff] [blame] | 3134 | wrapW = 0; |
robert@webkit.org | 1f81153 | 2013-06-24 20:09:20 +0000 | [diff] [blame] | 3135 | commitLineBreakAtCurrentWidth(width, lBreak, current.m_obj, current.m_pos, current.m_nextBreakablePosition); |
weinig | f28a1c3 | 2007-02-14 14:10:31 +0000 | [diff] [blame] | 3136 | // Auto-wrapping text should not wrap in the middle of a word once it has had an |
| 3137 | // opportunity to break after a word. |
| 3138 | breakWords = false; |
hyatt | a9f48e3 | 2003-02-03 22:48:01 +0000 | [diff] [blame] | 3139 | } |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 3140 | |
mitz@apple.com | 8687772 | 2011-08-19 16:29:32 +0000 | [diff] [blame] | 3141 | if (midWordBreak && !U16_IS_TRAIL(c) && !(category(c) & (Mark_NonSpacing | Mark_Enclosing | Mark_SpacingCombining))) { |
darin | 5400892 | 2006-01-13 16:39:05 +0000 | [diff] [blame] | 3142 | // Remember this as a breakable position in case |
| 3143 | // adding the end width forces a break. |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 3144 | lBreak.moveTo(current.m_obj, current.m_pos, current.m_nextBreakablePosition); |
weinig | ed111c1 | 2007-07-13 22:45:11 +0000 | [diff] [blame] | 3145 | midWordBreak &= (breakWords || breakAll); |
| 3146 | } |
| 3147 | |
| 3148 | if (betweenWords) { |
darin | 5400892 | 2006-01-13 16:39:05 +0000 | [diff] [blame] | 3149 | lastSpaceWordSpacing = applyWordSpacing ? wordSpacing : 0; |
enrica@apple.com | 885c84d | 2012-10-10 05:48:51 +0000 | [diff] [blame] | 3150 | wordSpacingForWordMeasurement = (applyWordSpacing && wordMeasurement.width) ? wordSpacing : 0; |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 3151 | lastSpace = current.m_pos; |
darin | 5400892 | 2006-01-13 16:39:05 +0000 | [diff] [blame] | 3152 | } |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 3153 | |
antti@apple.com | 78e5677 | 2013-09-29 04:34:37 +0000 | [diff] [blame] | 3154 | if (!ignoringSpaces && currentStyle.collapseWhiteSpace()) { |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 3155 | // If we encounter a newline, or if we encounter a |
| 3156 | // second space, we need to go ahead and break up this |
| 3157 | // run and enter a mode where we start collapsing spaces. |
hyatt | 98b1628 | 2004-03-31 18:43:12 +0000 | [diff] [blame] | 3158 | if (currentCharacterIsSpace && previousCharacterIsSpace) { |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 3159 | ignoringSpaces = true; |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 3160 | |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 3161 | // We just entered a mode where we are ignoring |
| 3162 | // spaces. Create a midpoint to terminate the run |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 3163 | // before the second space. |
leviw@chromium.org | 0e7d89e | 2013-02-23 00:00:27 +0000 | [diff] [blame] | 3164 | startIgnoringSpaces(lineMidpointState, ignoreStart); |
mitz@apple.com | e98acc9 | 2011-05-22 04:44:27 +0000 | [diff] [blame] | 3165 | trailingObjects.updateMidpointsForTrailingBoxes(lineMidpointState, InlineIterator(), TrailingObjects::DoNotCollapseFirstSpace); |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 3166 | } |
| 3167 | } |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 3168 | } else if (ignoringSpaces) { |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 3169 | // Stop ignoring spaces and begin at this |
| 3170 | // new point. |
| 3171 | ignoringSpaces = false; |
eseidel | d13fe53 | 2005-11-30 02:40:29 +0000 | [diff] [blame] | 3172 | lastSpaceWordSpacing = applyWordSpacing ? wordSpacing : 0; |
enrica@apple.com | 885c84d | 2012-10-10 05:48:51 +0000 | [diff] [blame] | 3173 | wordSpacingForWordMeasurement = (applyWordSpacing && wordMeasurements.last().width) ? wordSpacing : 0; |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 3174 | lastSpace = current.m_pos; // e.g., "Foo goo", don't add in any of the ignored spaces. |
leviw@chromium.org | 0e7d89e | 2013-02-23 00:00:27 +0000 | [diff] [blame] | 3175 | stopIgnoringSpaces(lineMidpointState, InlineIterator(0, current.m_obj, current.m_pos)); |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 3176 | } |
hyatt | 98b1628 | 2004-03-31 18:43:12 +0000 | [diff] [blame] | 3177 | |
zimmermann@webkit.org | cea31466 | 2011-04-05 16:38:10 +0000 | [diff] [blame] | 3178 | #if ENABLE(SVG) |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 3179 | if (isSVGText && current.m_pos > 0) { |
zimmermann@webkit.org | cea31466 | 2011-04-05 16:38:10 +0000 | [diff] [blame] | 3180 | // Force creation of new InlineBoxes for each absolute positioned character (those that start new text chunks). |
leviw@chromium.org | 0e7d89e | 2013-02-23 00:00:27 +0000 | [diff] [blame] | 3181 | if (toRenderSVGInlineText(t)->characterStartsNewTextChunk(current.m_pos)) |
| 3182 | ensureCharacterGetsLineBox(lineMidpointState, current); |
zimmermann@webkit.org | cea31466 | 2011-04-05 16:38:10 +0000 | [diff] [blame] | 3183 | } |
| 3184 | #endif |
| 3185 | |
hyatt | 98b1628 | 2004-03-31 18:43:12 +0000 | [diff] [blame] | 3186 | if (currentCharacterIsSpace && !previousCharacterIsSpace) { |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 3187 | ignoreStart.m_obj = current.m_obj; |
| 3188 | ignoreStart.m_pos = current.m_pos; |
robert@webkit.org | 2cb0264 | 2013-09-18 17:58:25 +0000 | [diff] [blame] | 3189 | // Spaces after right-aligned text and before a line-break get collapsed away completely so that the trailing |
| 3190 | // space doesn't seem to push the text out from the right-hand edge. |
| 3191 | // FIXME: Do this regardless of the container's alignment - will require rebaselining a lot of test results. |
antti@apple.com | 78e5677 | 2013-09-29 04:34:37 +0000 | [diff] [blame] | 3192 | if (next && next->isBR() && (blockStyle.textAlign() == RIGHT || blockStyle.textAlign() == WEBKIT_RIGHT)) { |
robert@webkit.org | 2cb0264 | 2013-09-18 17:58:25 +0000 | [diff] [blame] | 3193 | ignoreStart.m_pos--; |
| 3194 | // If there's just a single trailing space start ignoring it now so it collapses away. |
| 3195 | if (current.m_pos == t->textLength() - 1) |
| 3196 | startIgnoringSpaces(lineMidpointState, ignoreStart); |
| 3197 | } |
hyatt | 98b1628 | 2004-03-31 18:43:12 +0000 | [diff] [blame] | 3198 | } |
harrison | e343c41 | 2005-01-18 01:07:26 +0000 | [diff] [blame] | 3199 | |
| 3200 | if (!currentCharacterIsWS && previousCharacterIsWS) { |
antti@apple.com | 78e5677 | 2013-09-29 04:34:37 +0000 | [diff] [blame] | 3201 | if (autoWrap && currentStyle.breakOnlyAfterWhiteSpace()) |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 3202 | lBreak.moveTo(current.m_obj, current.m_pos, current.m_nextBreakablePosition); |
harrison | e343c41 | 2005-01-18 01:07:26 +0000 | [diff] [blame] | 3203 | } |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 3204 | |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 3205 | if (collapseWhiteSpace && currentCharacterIsSpace && !ignoringSpaces) |
jchaffraix@webkit.org | 3e44dfa | 2011-06-20 23:14:23 +0000 | [diff] [blame] | 3206 | trailingObjects.setTrailingWhitespace(toRenderText(current.m_obj)); |
antti@apple.com | 78e5677 | 2013-09-29 04:34:37 +0000 | [diff] [blame] | 3207 | else if (!currentStyle.collapseWhiteSpace() || !currentCharacterIsSpace) |
rniwa@webkit.org | 105350c | 2011-05-03 20:33:25 +0000 | [diff] [blame] | 3208 | trailingObjects.clear(); |
| 3209 | |
ddkilzer | e8759ef | 2007-03-25 06:28:19 +0000 | [diff] [blame] | 3210 | atStart = false; |
glenn@skynav.com | 1fa656a | 2013-03-11 03:30:57 +0000 | [diff] [blame] | 3211 | nextCharacter: |
glenn@skynav.com | 61b1abf | 2013-04-02 23:28:32 +0000 | [diff] [blame] | 3212 | secondToLastCharacter = lastCharacter; |
| 3213 | lastCharacter = c; |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 3214 | } |
mitz@apple.com | fb8da4e | 2008-02-19 21:13:19 +0000 | [diff] [blame] | 3215 | |
glenn@skynav.com | 61b1abf | 2013-04-02 23:28:32 +0000 | [diff] [blame] | 3216 | renderTextInfo.m_lineBreakIterator.setPriorContext(lastCharacter, secondToLastCharacter); |
glenn@skynav.com | 1fa656a | 2013-03-11 03:30:57 +0000 | [diff] [blame] | 3217 | |
enrica@apple.com | 885c84d | 2012-10-10 05:48:51 +0000 | [diff] [blame] | 3218 | wordMeasurements.grow(wordMeasurements.size() + 1); |
| 3219 | WordMeasurement& wordMeasurement = wordMeasurements.last(); |
| 3220 | wordMeasurement.renderer = t; |
| 3221 | |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 3222 | // IMPORTANT: current.m_pos is > length here! |
rniwa@webkit.org | fe811f2 | 2013-06-07 17:59:01 +0000 | [diff] [blame] | 3223 | float additionalTempWidth = ignoringSpaces ? 0 : textWidth(t, lastSpace, current.m_pos - lastSpace, f, width.currentWidth(), isFixedPitch, collapseWhiteSpace, wordMeasurement.fallbackFonts, textLayout); |
enrica@apple.com | 885c84d | 2012-10-10 05:48:51 +0000 | [diff] [blame] | 3224 | wordMeasurement.startOffset = lastSpace; |
| 3225 | wordMeasurement.endOffset = current.m_pos; |
commit-queue@webkit.org | 1776140 | 2013-04-17 18:48:56 +0000 | [diff] [blame] | 3226 | wordMeasurement.width = ignoringSpaces ? 0 : additionalTempWidth + wordSpacingForWordMeasurement; |
| 3227 | additionalTempWidth += lastSpaceWordSpacing; |
| 3228 | |
| 3229 | float inlineLogicalTempWidth = inlineLogicalWidth(current.m_obj, !appliedStartWidth, includeEndWidth); |
zalan@apple.com | 6833dd9 | 2013-09-27 12:47:52 +0000 | [diff] [blame] | 3230 | width.addUncommittedWidth(additionalTempWidth + inlineLogicalTempWidth, *current.m_obj); |
commit-queue@webkit.org | 1776140 | 2013-04-17 18:48:56 +0000 | [diff] [blame] | 3231 | |
rniwa@webkit.org | fe811f2 | 2013-06-07 17:59:01 +0000 | [diff] [blame] | 3232 | if (wordMeasurement.fallbackFonts.isEmpty() && !fallbackFonts.isEmpty()) |
| 3233 | wordMeasurement.fallbackFonts.swap(fallbackFonts); |
| 3234 | fallbackFonts.clear(); |
| 3235 | |
commit-queue@webkit.org | 1776140 | 2013-04-17 18:48:56 +0000 | [diff] [blame] | 3236 | if (collapseWhiteSpace && currentCharacterIsSpace && additionalTempWidth) |
robert@webkit.org | c522345 | 2013-06-12 19:20:33 +0000 | [diff] [blame] | 3237 | width.setTrailingWhitespaceWidth(additionalTempWidth, inlineLogicalTempWidth); |
commit-queue@webkit.org | 1776140 | 2013-04-17 18:48:56 +0000 | [diff] [blame] | 3238 | |
yael.aharon@nokia.com | 1cfbceb | 2011-06-06 18:32:54 +0000 | [diff] [blame] | 3239 | includeEndWidth = false; |
mitz@apple.com | b210765 | 2010-06-21 16:54:52 +0000 | [diff] [blame] | 3240 | |
rniwa@webkit.org | 5eb8d16 | 2011-04-13 02:13:33 +0000 | [diff] [blame] | 3241 | if (!width.fitsOnLine()) { |
mitz@apple.com | 96cf46d | 2011-03-14 01:09:26 +0000 | [diff] [blame] | 3242 | if (canHyphenate) |
antti@apple.com | 78e5677 | 2013-09-29 04:34:37 +0000 | [diff] [blame] | 3243 | tryHyphenating(t, f, style.locale(), consecutiveHyphenatedLines, blockStyle.hyphenationLimitLines(), style.hyphenationLimitBefore(), style.hyphenationLimitAfter(), lastSpace, current.m_pos, width.currentWidth() - additionalTempWidth, width.availableWidth(), isFixedPitch, collapseWhiteSpace, lastSpaceWordSpacing, lBreak, current.m_nextBreakablePosition, m_hyphenated); |
rniwa@webkit.org | 58925e8 | 2011-04-12 21:32:58 +0000 | [diff] [blame] | 3244 | |
antti@apple.com | b0608f6 | 2013-09-28 18:30:16 +0000 | [diff] [blame] | 3245 | if (!m_hyphenated && lBreak.previousInSameNode() == softHyphen && style.hyphens() != HyphensNone) |
leviw@chromium.org | 1a50869 | 2011-05-05 00:01:11 +0000 | [diff] [blame] | 3246 | m_hyphenated = true; |
rniwa@webkit.org | 58925e8 | 2011-04-12 21:32:58 +0000 | [diff] [blame] | 3247 | |
leviw@chromium.org | 1a50869 | 2011-05-05 00:01:11 +0000 | [diff] [blame] | 3248 | if (m_hyphenated) |
mitz@apple.com | b210765 | 2010-06-21 16:54:52 +0000 | [diff] [blame] | 3249 | goto end; |
| 3250 | } |
antti@apple.com | 3014ac0 | 2013-09-18 14:33:55 +0000 | [diff] [blame] | 3251 | } else if (current.m_obj->isLineBreakOpportunity()) |
| 3252 | commitLineBreakAtCurrentWidth(width, lBreak, current.m_obj); |
| 3253 | else |
weinig | f28a1c3 | 2007-02-14 14:10:31 +0000 | [diff] [blame] | 3254 | ASSERT_NOT_REACHED(); |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 3255 | |
robert@webkit.org | 6ce4b39 | 2013-07-02 19:30:32 +0000 | [diff] [blame] | 3256 | bool canBreakHere = canBreakAtThisPosition(autoWrap, width, lBreak, next, current, currWS, currentCharacterIsSpace, autoWrapWasEverTrueOnLine); |
| 3257 | if (canBreakHere && !width.fitsOnLine(ignoringSpaces)) { |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 3258 | // if we have floats, try to get below them. |
antti@apple.com | 78e5677 | 2013-09-29 04:34:37 +0000 | [diff] [blame] | 3259 | if (currentCharacterIsSpace && !ignoringSpaces && currentStyle.collapseWhiteSpace()) |
rniwa@webkit.org | 105350c | 2011-05-03 20:33:25 +0000 | [diff] [blame] | 3260 | trailingObjects.clear(); |
mitz@apple.com | cfd9b7b | 2008-02-24 04:00:21 +0000 | [diff] [blame] | 3261 | |
rniwa@webkit.org | 58925e8 | 2011-04-12 21:32:58 +0000 | [diff] [blame] | 3262 | if (width.committedWidth()) |
mitz@apple.com | cfd9b7b | 2008-02-24 04:00:21 +0000 | [diff] [blame] | 3263 | goto end; |
| 3264 | |
rniwa@webkit.org | 4442475 | 2011-04-14 00:58:40 +0000 | [diff] [blame] | 3265 | width.fitBelowFloats(); |
hyatt | f14a4a3 | 2002-11-21 22:06:32 +0000 | [diff] [blame] | 3266 | |
hyatt | a14d174 | 2003-01-02 20:25:46 +0000 | [diff] [blame] | 3267 | // |width| may have been adjusted because we got shoved down past a float (thus |
| 3268 | // giving us more room), so we need to retest, and only jump to |
| 3269 | // the end label if we still don't fit on the line. -dwh |
robert@webkit.org | 7a80c02 | 2013-06-21 21:04:21 +0000 | [diff] [blame] | 3270 | if (!width.fitsOnLine(ignoringSpaces)) |
hyatt | a14d174 | 2003-01-02 20:25:46 +0000 | [diff] [blame] | 3271 | goto end; |
antti@apple.com | 78e5677 | 2013-09-29 04:34:37 +0000 | [diff] [blame] | 3272 | } else if (blockStyle.autoWrap() && !width.fitsOnLine() && !width.committedWidth()) { |
robert@webkit.org | 744e01c | 2013-01-02 20:18:15 +0000 | [diff] [blame] | 3273 | // If the container autowraps but the current child does not then we still need to ensure that it |
| 3274 | // wraps and moves below any floats. |
| 3275 | width.fitBelowFloats(); |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 3276 | } |
hyatt | 1d9e29b | 2003-04-10 01:48:53 +0000 | [diff] [blame] | 3277 | |
simon.fraser@apple.com | 2f07185 | 2012-06-25 00:11:30 +0000 | [diff] [blame] | 3278 | if (!current.m_obj->isFloatingOrOutOfFlowPositioned()) { |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 3279 | last = current.m_obj; |
akling@apple.com | 4c166d6 | 2013-09-01 05:29:00 +0000 | [diff] [blame] | 3280 | if (last->isReplaced() && autoWrap && (!last->isImage() || allowImagesToBreak) && (!last->isListMarker() || toRenderListMarker(*last).isInside())) |
robert@webkit.org | 1f81153 | 2013-06-24 20:09:20 +0000 | [diff] [blame] | 3281 | commitLineBreakAtCurrentWidth(width, lBreak, next); |
hyatt | 711fe23 | 2002-11-20 21:25:14 +0000 | [diff] [blame] | 3282 | } |
| 3283 | |
hyatt | a9f48e3 | 2003-02-03 22:48:01 +0000 | [diff] [blame] | 3284 | // Clear out our character space bool, since inline <pre>s don't collapse whitespace |
| 3285 | // with adjacent inline normal/nowrap spans. |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 3286 | if (!collapseWhiteSpace) |
hyatt | a9f48e3 | 2003-02-03 22:48:01 +0000 | [diff] [blame] | 3287 | currentCharacterIsSpace = false; |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 3288 | |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 3289 | current.moveToStartOf(next); |
ddkilzer | e8759ef | 2007-03-25 06:28:19 +0000 | [diff] [blame] | 3290 | atStart = false; |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 3291 | } |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 3292 | |
robert@webkit.org | 7a80c02 | 2013-06-21 21:04:21 +0000 | [diff] [blame] | 3293 | if (width.fitsOnLine(true) || lastWS == NOWRAP) |
eric@webkit.org | bd14359 | 2011-03-29 17:44:41 +0000 | [diff] [blame] | 3294 | lBreak.clear(); |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 3295 | |
| 3296 | end: |
betravis@adobe.com | ed90c98 | 2013-06-05 23:05:57 +0000 | [diff] [blame] | 3297 | #if ENABLE(CSS_SHAPES) |
betravis@adobe.com | cf7cba6 | 2013-06-10 21:23:45 +0000 | [diff] [blame] | 3298 | ShapeInsideInfo* shapeInfo = m_block->layoutShapeInsideInfo(); |
betravis@adobe.com | 9e5e824 | 2013-04-19 23:28:26 +0000 | [diff] [blame] | 3299 | bool segmentAllowsOverflow = !shapeInfo || !shapeInfo->hasSegments(); |
| 3300 | #else |
| 3301 | bool segmentAllowsOverflow = true; |
| 3302 | #endif |
| 3303 | |
akling@apple.com | f294cf0 | 2013-07-17 18:46:39 +0000 | [diff] [blame] | 3304 | if (segmentAllowsOverflow) { |
| 3305 | if (lBreak == resolver.position()) { |
| 3306 | if (!lBreak.m_obj || !lBreak.m_obj->isBR()) { |
| 3307 | // we just add as much as possible |
antti@apple.com | 78e5677 | 2013-09-29 04:34:37 +0000 | [diff] [blame] | 3308 | if (blockStyle.whiteSpace() == PRE && !current.m_pos) { |
akling@apple.com | f294cf0 | 2013-07-17 18:46:39 +0000 | [diff] [blame] | 3309 | lBreak.moveTo(last, last->isText() ? last->length() : 0); |
| 3310 | } else if (lBreak.m_obj) { |
| 3311 | // Don't ever break in the middle of a word if we can help it. |
| 3312 | // There's no room at all. We just have to be on this line, |
| 3313 | // even though we'll spill out. |
| 3314 | lBreak.moveTo(current.m_obj, current.m_pos); |
| 3315 | } |
| 3316 | } |
| 3317 | // make sure we consume at least one char/object. |
| 3318 | if (lBreak == resolver.position()) |
| 3319 | lBreak.increment(); |
zalan@apple.com | 6833dd9 | 2013-09-27 12:47:52 +0000 | [diff] [blame] | 3320 | } else if (!current.m_pos && !width.committedWidth() && current.m_obj && width.uncommittedWidthForObject(*current.m_obj) == width.uncommittedWidth()) { |
akling@apple.com | f294cf0 | 2013-07-17 18:46:39 +0000 | [diff] [blame] | 3321 | // Do not push the current object to the next line, when this line has some content, but it is still considered empty. |
| 3322 | // Empty inline elements like <span></span> can produce such lines and now we just ignore these break opportunities |
| 3323 | // at the start of a line, if no width has been committed yet. |
| 3324 | // Behave as if it was actually empty and consume at least one object. |
| 3325 | lBreak.increment(); |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 3326 | } |
| 3327 | } |
| 3328 | |
hyatt | fe99c87 | 2003-07-31 22:25:29 +0000 | [diff] [blame] | 3329 | // Sanity check our midpoints. |
hyatt@apple.com | b3466af | 2009-06-13 06:04:40 +0000 | [diff] [blame] | 3330 | checkMidpoints(lineMidpointState, lBreak); |
hyatt@apple.com | 63a8df3 | 2011-03-28 19:44:19 +0000 | [diff] [blame] | 3331 | |
mitz@apple.com | e98acc9 | 2011-05-22 04:44:27 +0000 | [diff] [blame] | 3332 | trailingObjects.updateMidpointsForTrailingBoxes(lineMidpointState, lBreak, TrailingObjects::CollapseFirstSpace); |
rjw | c9c257d | 2003-01-24 03:46:17 +0000 | [diff] [blame] | 3333 | |
mjs | 54b6400 | 2003-04-02 02:59:02 +0000 | [diff] [blame] | 3334 | // We might have made lBreak an iterator that points past the end |
| 3335 | // of the object. Do this adjustment to make it point to the start |
| 3336 | // of the next object instead to avoid confusing the rest of the |
| 3337 | // code. |
eric@webkit.org | 86a865a | 2011-03-29 15:30:41 +0000 | [diff] [blame] | 3338 | if (lBreak.m_pos > 0) { |
| 3339 | lBreak.m_pos--; |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 3340 | lBreak.increment(); |
mjs | 54b6400 | 2003-04-02 02:59:02 +0000 | [diff] [blame] | 3341 | } |
| 3342 | |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 3343 | return lBreak; |
| 3344 | } |
| 3345 | |
hyatt@apple.com | 5dc5a31 | 2009-08-18 19:15:19 +0000 | [diff] [blame] | 3346 | void RenderBlock::addOverflowFromInlineChildren() |
hyatt | b4b2087 | 2004-10-20 21:34:01 +0000 | [diff] [blame] | 3347 | { |
eae@chromium.org | 9717cd8 | 2012-11-07 18:33:44 +0000 | [diff] [blame] | 3348 | LayoutUnit endPadding = hasOverflowClip() ? paddingEnd() : LayoutUnit(); |
hyatt@apple.com | 592848f | 2010-12-06 20:03:43 +0000 | [diff] [blame] | 3349 | // FIXME: Need to find another way to do this, since scrollbars could show when we don't want them to. |
antti@apple.com | 8f33508 | 2013-09-09 19:54:33 +0000 | [diff] [blame] | 3350 | if (hasOverflowClip() && !endPadding && element() && element()->isRootEditableElement() && style()->isLeftToRightDirection()) |
hyatt@apple.com | 592848f | 2010-12-06 20:03:43 +0000 | [diff] [blame] | 3351 | endPadding = 1; |
hyatt | b4b2087 | 2004-10-20 21:34:01 +0000 | [diff] [blame] | 3352 | for (RootInlineBox* curr = firstRootBox(); curr; curr = curr->nextRootBox()) { |
hyatt@apple.com | 592848f | 2010-12-06 20:03:43 +0000 | [diff] [blame] | 3353 | addLayoutOverflow(curr->paddedLayoutOverflowRect(endPadding)); |
abucur@adobe.com | 6585d01 | 2013-09-04 08:26:41 +0000 | [diff] [blame] | 3354 | RenderRegion* region = curr->containingRegion(); |
| 3355 | if (region) |
| 3356 | region->addLayoutOverflowForBox(this, curr->paddedLayoutOverflowRect(endPadding)); |
| 3357 | if (!hasOverflowClip()) { |
hyatt@apple.com | 61f2532 | 2011-03-31 20:40:48 +0000 | [diff] [blame] | 3358 | addVisualOverflow(curr->visualOverflowRect(curr->lineTop(), curr->lineBottom())); |
abucur@adobe.com | 6585d01 | 2013-09-04 08:26:41 +0000 | [diff] [blame] | 3359 | if (region) |
| 3360 | region->addVisualOverflowForBox(this, curr->visualOverflowRect(curr->lineTop(), curr->lineBottom())); |
| 3361 | } |
hyatt | b4b2087 | 2004-10-20 21:34:01 +0000 | [diff] [blame] | 3362 | } |
| 3363 | } |
| 3364 | |
hyatt | ed77ad8 | 2004-06-15 07:21:23 +0000 | [diff] [blame] | 3365 | void RenderBlock::deleteEllipsisLineBoxes() |
| 3366 | { |
benjamin@webkit.org | f68b1be | 2012-06-23 02:02:28 +0000 | [diff] [blame] | 3367 | ETextAlign textAlign = style()->textAlign(); |
| 3368 | bool ltr = style()->isLeftToRightDirection(); |
| 3369 | bool firstLine = true; |
| 3370 | for (RootInlineBox* curr = firstRootBox(); curr; curr = curr->nextRootBox()) { |
| 3371 | if (curr->hasEllipsisBox()) { |
| 3372 | curr->clearTruncation(); |
| 3373 | |
| 3374 | // Shift the line back where it belongs if we cannot accomodate an ellipsis. |
| 3375 | float logicalLeft = pixelSnappedLogicalLeftOffsetForLine(curr->lineTop(), firstLine); |
| 3376 | float availableLogicalWidth = logicalRightOffsetForLine(curr->lineTop(), false) - logicalLeft; |
| 3377 | float totalLogicalWidth = curr->logicalWidth(); |
| 3378 | updateLogicalWidthForAlignment(textAlign, 0, logicalLeft, totalLogicalWidth, availableLogicalWidth, 0); |
| 3379 | |
| 3380 | if (ltr) |
| 3381 | curr->adjustLogicalPosition((logicalLeft - curr->logicalLeft()), 0); |
| 3382 | else |
| 3383 | curr->adjustLogicalPosition(-(curr->logicalLeft() - logicalLeft), 0); |
| 3384 | } |
| 3385 | firstLine = false; |
| 3386 | } |
hyatt | ed77ad8 | 2004-06-15 07:21:23 +0000 | [diff] [blame] | 3387 | } |
| 3388 | |
| 3389 | void RenderBlock::checkLinesForTextOverflow() |
| 3390 | { |
| 3391 | // Determine the width of the ellipsis using the current font. |
darin | dbba2bb | 2007-01-11 12:23:49 +0000 | [diff] [blame] | 3392 | // FIXME: CSS3 says this is configurable, also need to use 0x002E (FULL STOP) if horizontal ellipsis is "not renderable" |
zimmermann@webkit.org | 8a7e7ff | 2011-05-24 15:27:36 +0000 | [diff] [blame] | 3393 | const Font& font = style()->font(); |
bolsinga@apple.com | 97e42c4 | 2008-11-15 04:47:20 +0000 | [diff] [blame] | 3394 | DEFINE_STATIC_LOCAL(AtomicString, ellipsisStr, (&horizontalEllipsis, 1)); |
hyatt | 3e99d1c | 2006-02-24 21:13:08 +0000 | [diff] [blame] | 3395 | const Font& firstLineFont = firstLineStyle()->font(); |
antti@apple.com | 78e5677 | 2013-09-29 04:34:37 +0000 | [diff] [blame] | 3396 | int firstLineEllipsisWidth = firstLineFont.width(constructTextRun(this, firstLineFont, &horizontalEllipsis, 1, *firstLineStyle())); |
| 3397 | int ellipsisWidth = (font == firstLineFont) ? firstLineEllipsisWidth : font.width(constructTextRun(this, font, &horizontalEllipsis, 1, *style())); |
hyatt | ed77ad8 | 2004-06-15 07:21:23 +0000 | [diff] [blame] | 3398 | |
| 3399 | // For LTR text truncation, we want to get the right edge of our padding box, and then we want to see |
| 3400 | // if the right edge of a line box exceeds that. For RTL, we use the left edge of the padding box and |
| 3401 | // check the left edge of the line box to see if it is less |
| 3402 | // Include the scrollbar for overflow blocks, which means we want to use "contentWidth()" |
hyatt@apple.com | c0fa163 | 2010-09-30 20:01:33 +0000 | [diff] [blame] | 3403 | bool ltr = style()->isLeftToRightDirection(); |
benjamin@webkit.org | f68b1be | 2012-06-23 02:02:28 +0000 | [diff] [blame] | 3404 | ETextAlign textAlign = style()->textAlign(); |
| 3405 | bool firstLine = true; |
hyatt | ed77ad8 | 2004-06-15 07:21:23 +0000 | [diff] [blame] | 3406 | for (RootInlineBox* curr = firstRootBox(); curr; curr = curr->nextRootBox()) { |
eae@chromium.org | 275da18 | 2012-12-19 23:07:55 +0000 | [diff] [blame] | 3407 | // FIXME: Use pixelSnappedLogicalRightOffsetForLine instead of snapping it ourselves once the column workaround in said method has been fixed. |
| 3408 | // https://bugs.webkit.org/show_bug.cgi?id=105461 |
commit-queue@webkit.org | bbac21e | 2013-06-21 15:45:21 +0000 | [diff] [blame] | 3409 | int blockRightEdge = snapSizeToPixel(logicalRightOffsetForLine(curr->lineTop(), firstLine), curr->x()); |
| 3410 | int blockLeftEdge = pixelSnappedLogicalLeftOffsetForLine(curr->lineTop(), firstLine); |
eae@chromium.org | c491d96 | 2012-12-28 18:32:08 +0000 | [diff] [blame] | 3411 | int lineBoxEdge = ltr ? snapSizeToPixel(curr->x() + curr->logicalWidth(), curr->x()) : snapSizeToPixel(curr->x(), 0); |
dglazkov@chromium.org | 28434e6 | 2009-05-13 22:30:10 +0000 | [diff] [blame] | 3412 | if ((ltr && lineBoxEdge > blockRightEdge) || (!ltr && lineBoxEdge < blockLeftEdge)) { |
hyatt | f918d2d | 2004-06-15 07:24:11 +0000 | [diff] [blame] | 3413 | // This line spills out of our box in the appropriate direction. Now we need to see if the line |
hyatt | ed77ad8 | 2004-06-15 07:21:23 +0000 | [diff] [blame] | 3414 | // can be truncated. In order for truncation to be possible, the line must have sufficient space to |
| 3415 | // accommodate our truncation string, and no replaced elements (images, tables) can overlap the ellipsis |
| 3416 | // space. |
benjamin@webkit.org | f68b1be | 2012-06-23 02:02:28 +0000 | [diff] [blame] | 3417 | |
| 3418 | LayoutUnit width = firstLine ? firstLineEllipsisWidth : ellipsisWidth; |
eae@chromium.org | ee8613e | 2011-11-12 01:12:58 +0000 | [diff] [blame] | 3419 | LayoutUnit blockEdge = ltr ? blockRightEdge : blockLeftEdge; |
benjamin@webkit.org | f68b1be | 2012-06-23 02:02:28 +0000 | [diff] [blame] | 3420 | if (curr->lineCanAccommodateEllipsis(ltr, blockEdge, lineBoxEdge, width)) { |
| 3421 | float totalLogicalWidth = curr->placeEllipsis(ellipsisStr, ltr, blockLeftEdge, blockRightEdge, width); |
| 3422 | |
akling@apple.com | f294cf0 | 2013-07-17 18:46:39 +0000 | [diff] [blame] | 3423 | float logicalLeft = 0; // We are only interested in the delta from the base position. |
commit-queue@webkit.org | bbac21e | 2013-06-21 15:45:21 +0000 | [diff] [blame] | 3424 | float truncatedWidth = pixelSnappedLogicalRightOffsetForLine(curr->lineTop(), firstLine); |
benjamin@webkit.org | f68b1be | 2012-06-23 02:02:28 +0000 | [diff] [blame] | 3425 | updateLogicalWidthForAlignment(textAlign, 0, logicalLeft, totalLogicalWidth, truncatedWidth, 0); |
| 3426 | if (ltr) |
| 3427 | curr->adjustLogicalPosition(logicalLeft, 0); |
| 3428 | else |
| 3429 | curr->adjustLogicalPosition(-(truncatedWidth - (logicalLeft + totalLogicalWidth)), 0); |
| 3430 | } |
hyatt | ed77ad8 | 2004-06-15 07:21:23 +0000 | [diff] [blame] | 3431 | } |
benjamin@webkit.org | f68b1be | 2012-06-23 02:02:28 +0000 | [diff] [blame] | 3432 | firstLine = false; |
hyatt | ed77ad8 | 2004-06-15 07:21:23 +0000 | [diff] [blame] | 3433 | } |
| 3434 | } |
| 3435 | |
hyatt@apple.com | 5950bd4 | 2011-09-27 20:39:57 +0000 | [diff] [blame] | 3436 | bool RenderBlock::positionNewFloatOnLine(FloatingObject* newFloat, FloatingObject* lastFloatFromPreviousLine, LineInfo& lineInfo, LineWidth& width) |
rniwa@webkit.org | 73ce42a | 2011-04-06 14:10:02 +0000 | [diff] [blame] | 3437 | { |
rniwa@webkit.org | 7881ad0 | 2011-04-07 13:05:35 +0000 | [diff] [blame] | 3438 | if (!positionNewFloats()) |
| 3439 | return false; |
rniwa@webkit.org | 73ce42a | 2011-04-06 14:10:02 +0000 | [diff] [blame] | 3440 | |
rniwa@webkit.org | 4442475 | 2011-04-14 00:58:40 +0000 | [diff] [blame] | 3441 | width.shrinkAvailableWidthForNewFloatIfNeeded(newFloat); |
rniwa@webkit.org | 73ce42a | 2011-04-06 14:10:02 +0000 | [diff] [blame] | 3442 | |
hyatt@apple.com | dd78df8 | 2011-09-27 22:11:41 +0000 | [diff] [blame] | 3443 | // We only connect floats to lines for pagination purposes if the floats occur at the start of |
| 3444 | // the line and the previous line had a hard break (so this line is either the first in the block |
| 3445 | // or follows a <br>). |
bjonesbe@adobe.com | a9c6666 | 2013-08-14 20:30:14 +0000 | [diff] [blame] | 3446 | if (!newFloat->paginationStrut() || !lineInfo.previousLineBrokeCleanly() || !lineInfo.isEmpty()) |
rniwa@webkit.org | 7881ad0 | 2011-04-07 13:05:35 +0000 | [diff] [blame] | 3447 | return true; |
rniwa@webkit.org | 73ce42a | 2011-04-06 14:10:02 +0000 | [diff] [blame] | 3448 | |
hyatt@apple.com | 46c65b3 | 2011-08-09 19:13:45 +0000 | [diff] [blame] | 3449 | const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); |
darin@apple.com | 7cad704 | 2013-09-24 05:53:55 +0000 | [diff] [blame] | 3450 | ASSERT(floatingObjectSet.last().get() == newFloat); |
rniwa@webkit.org | 73ce42a | 2011-04-06 14:10:02 +0000 | [diff] [blame] | 3451 | |
bjonesbe@adobe.com | 93de7e7 | 2013-09-04 18:01:27 +0000 | [diff] [blame] | 3452 | LayoutUnit floatLogicalTop = newFloat->logicalTop(isHorizontalWritingMode()); |
bjonesbe@adobe.com | a9c6666 | 2013-08-14 20:30:14 +0000 | [diff] [blame] | 3453 | int paginationStrut = newFloat->paginationStrut(); |
rniwa@webkit.org | 73ce42a | 2011-04-06 14:10:02 +0000 | [diff] [blame] | 3454 | |
hyatt@apple.com | 5950bd4 | 2011-09-27 20:39:57 +0000 | [diff] [blame] | 3455 | if (floatLogicalTop - paginationStrut != logicalHeight() + lineInfo.floatPaginationStrut()) |
rniwa@webkit.org | 7881ad0 | 2011-04-07 13:05:35 +0000 | [diff] [blame] | 3456 | return true; |
rniwa@webkit.org | 73ce42a | 2011-04-06 14:10:02 +0000 | [diff] [blame] | 3457 | |
darin@apple.com | 7cad704 | 2013-09-24 05:53:55 +0000 | [diff] [blame] | 3458 | auto it = floatingObjectSet.end(); |
rniwa@webkit.org | 73ce42a | 2011-04-06 14:10:02 +0000 | [diff] [blame] | 3459 | --it; // Last float is newFloat, skip that one. |
darin@apple.com | 7cad704 | 2013-09-24 05:53:55 +0000 | [diff] [blame] | 3460 | auto begin = floatingObjectSet.begin(); |
rniwa@webkit.org | 73ce42a | 2011-04-06 14:10:02 +0000 | [diff] [blame] | 3461 | while (it != begin) { |
| 3462 | --it; |
darin@apple.com | 7cad704 | 2013-09-24 05:53:55 +0000 | [diff] [blame] | 3463 | FloatingObject* f = it->get(); |
rniwa@webkit.org | 73ce42a | 2011-04-06 14:10:02 +0000 | [diff] [blame] | 3464 | if (f == lastFloatFromPreviousLine) |
| 3465 | break; |
bjonesbe@adobe.com | 93de7e7 | 2013-09-04 18:01:27 +0000 | [diff] [blame] | 3466 | if (f->logicalTop(isHorizontalWritingMode()) == logicalHeight() + lineInfo.floatPaginationStrut()) { |
bjonesbe@adobe.com | a9c6666 | 2013-08-14 20:30:14 +0000 | [diff] [blame] | 3467 | f->setPaginationStrut(paginationStrut + f->paginationStrut()); |
darin@apple.com | 7cad704 | 2013-09-24 05:53:55 +0000 | [diff] [blame] | 3468 | RenderBox* o = &f->renderer(); |
rniwa@webkit.org | 73ce42a | 2011-04-06 14:10:02 +0000 | [diff] [blame] | 3469 | setLogicalTopForChild(o, logicalTopForChild(o) + marginBeforeForChild(o) + paginationStrut); |
| 3470 | if (o->isRenderBlock()) |
antti@apple.com | ca2a8ff | 2013-10-04 04:04:35 +0000 | [diff] [blame] | 3471 | toRenderBlock(o)->setChildNeedsLayout(MarkOnlyThis); |
rniwa@webkit.org | 73ce42a | 2011-04-06 14:10:02 +0000 | [diff] [blame] | 3472 | o->layoutIfNeeded(); |
hyatt@apple.com | 46c65b3 | 2011-08-09 19:13:45 +0000 | [diff] [blame] | 3473 | // Save the old logical top before calling removePlacedObject which will set |
| 3474 | // isPlaced to false. Otherwise it will trigger an assert in logicalTopForFloat. |
bjonesbe@adobe.com | 93de7e7 | 2013-09-04 18:01:27 +0000 | [diff] [blame] | 3475 | LayoutUnit oldLogicalTop = f->logicalTop(isHorizontalWritingMode()); |
hyatt@apple.com | 46c65b3 | 2011-08-09 19:13:45 +0000 | [diff] [blame] | 3476 | m_floatingObjects->removePlacedObject(f); |
bjonesbe@adobe.com | 93de7e7 | 2013-09-04 18:01:27 +0000 | [diff] [blame] | 3477 | f->setLogicalTop(oldLogicalTop + paginationStrut, isHorizontalWritingMode()); |
hyatt@apple.com | 46c65b3 | 2011-08-09 19:13:45 +0000 | [diff] [blame] | 3478 | m_floatingObjects->addPlacedObject(f); |
rniwa@webkit.org | 73ce42a | 2011-04-06 14:10:02 +0000 | [diff] [blame] | 3479 | } |
| 3480 | } |
| 3481 | |
hyatt@apple.com | dd78df8 | 2011-09-27 22:11:41 +0000 | [diff] [blame] | 3482 | // Just update the line info's pagination strut without altering our logical height yet. If the line ends up containing |
| 3483 | // no content, then we don't want to improperly grow the height of the block. |
| 3484 | lineInfo.setFloatPaginationStrut(lineInfo.floatPaginationStrut() + paginationStrut); |
rniwa@webkit.org | 7881ad0 | 2011-04-07 13:05:35 +0000 | [diff] [blame] | 3485 | return true; |
rniwa@webkit.org | 73ce42a | 2011-04-06 14:10:02 +0000 | [diff] [blame] | 3486 | } |
| 3487 | |
robert@webkit.org | 82903f4 | 2012-08-28 19:18:40 +0000 | [diff] [blame] | 3488 | LayoutUnit RenderBlock::startAlignedOffsetForLine(LayoutUnit position, bool firstLine) |
robert@webkit.org | fc7763c | 2011-09-03 18:28:57 +0000 | [diff] [blame] | 3489 | { |
| 3490 | ETextAlign textAlign = style()->textAlign(); |
| 3491 | |
rniwa@webkit.org | af7f7a4 | 2012-06-15 21:54:44 +0000 | [diff] [blame] | 3492 | if (textAlign == TASTART) // FIXME: Handle TAEND here |
robert@webkit.org | fc7763c | 2011-09-03 18:28:57 +0000 | [diff] [blame] | 3493 | return startOffsetForLine(position, firstLine); |
| 3494 | |
| 3495 | // updateLogicalWidthForAlignment() handles the direction of the block so no need to consider it here |
robert@webkit.org | 82903f4 | 2012-08-28 19:18:40 +0000 | [diff] [blame] | 3496 | float totalLogicalWidth = 0; |
| 3497 | float logicalLeft = logicalLeftOffsetForLine(logicalHeight(), false); |
| 3498 | float availableLogicalWidth = logicalRightOffsetForLine(logicalHeight(), false) - logicalLeft; |
benjamin@webkit.org | f68b1be | 2012-06-23 02:02:28 +0000 | [diff] [blame] | 3499 | updateLogicalWidthForAlignment(textAlign, 0, logicalLeft, totalLogicalWidth, availableLogicalWidth, 0); |
robert@webkit.org | 7861a10 | 2011-09-22 17:16:47 +0000 | [diff] [blame] | 3500 | |
| 3501 | if (!style()->isLeftToRightDirection()) |
robert@webkit.org | 82903f4 | 2012-08-28 19:18:40 +0000 | [diff] [blame] | 3502 | return logicalWidth() - logicalLeft; |
robert@webkit.org | fc7763c | 2011-09-03 18:28:57 +0000 | [diff] [blame] | 3503 | return logicalLeft; |
| 3504 | } |
| 3505 | |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 3506 | } |