<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[178939] trunk/Source/WebCore</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/178939">178939</a></dd>
<dt>Author</dt> <dd>zalan@apple.com</dd>
<dt>Date</dt> <dd>2015-01-22 13:54:53 -0800 (Thu, 22 Jan 2015)</dd>
</dl>
<h3>Log Message</h3>
<pre>Simple line layout: Make trailing whitespace handling more explicit.
https://bugs.webkit.org/show_bug.cgi?id=140776
Reviewed by Antti Koivisto.
Differentiate between committed and uncommitted trailing whitespace.
This enables further cleanup in removeTrailingWhitespace().
No change in functionality.
* rendering/SimpleLineLayout.cpp:
(WebCore::SimpleLineLayout::LineState::commitAndCreateRun):
(WebCore::SimpleLineLayout::LineState::addUncommitted):
(WebCore::SimpleLineLayout::LineState::hasWhitespaceOnly):
(WebCore::SimpleLineLayout::LineState::removeTrailingWhitespace):
(WebCore::SimpleLineLayout::removeTrailingWhitespace):
(WebCore::SimpleLineLayout::LineState::LineState): Deleted.
(WebCore::SimpleLineLayout::LineState::removeCommittedTrailingWhitespace): Deleted.
(WebCore::SimpleLineLayout::LineState::resetTrailingWhitespace): Deleted.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorerenderingSimpleLineLayoutcpp">trunk/Source/WebCore/rendering/SimpleLineLayout.cpp</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (178938 => 178939)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2015-01-22 21:40:02 UTC (rev 178938)
+++ trunk/Source/WebCore/ChangeLog        2015-01-22 21:54:53 UTC (rev 178939)
</span><span class="lines">@@ -1,3 +1,25 @@
</span><ins>+2015-01-22 Zalan Bujtas <zalan@apple.com>
+
+ Simple line layout: Make trailing whitespace handling more explicit.
+ https://bugs.webkit.org/show_bug.cgi?id=140776
+
+ Reviewed by Antti Koivisto.
+
+ Differentiate between committed and uncommitted trailing whitespace.
+ This enables further cleanup in removeTrailingWhitespace().
+
+ No change in functionality.
+
+ * rendering/SimpleLineLayout.cpp:
+ (WebCore::SimpleLineLayout::LineState::commitAndCreateRun):
+ (WebCore::SimpleLineLayout::LineState::addUncommitted):
+ (WebCore::SimpleLineLayout::LineState::hasWhitespaceOnly):
+ (WebCore::SimpleLineLayout::LineState::removeTrailingWhitespace):
+ (WebCore::SimpleLineLayout::removeTrailingWhitespace):
+ (WebCore::SimpleLineLayout::LineState::LineState): Deleted.
+ (WebCore::SimpleLineLayout::LineState::removeCommittedTrailingWhitespace): Deleted.
+ (WebCore::SimpleLineLayout::LineState::resetTrailingWhitespace): Deleted.
+
</ins><span class="cx"> 2015-01-22 Alexey Proskuryakov <ap@apple.com>
</span><span class="cx">
</span><span class="cx"> Crash in URL::protocol() after appcache load fails
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingSimpleLineLayoutcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/SimpleLineLayout.cpp (178938 => 178939)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/SimpleLineLayout.cpp        2015-01-22 21:40:02 UTC (rev 178938)
+++ trunk/Source/WebCore/rendering/SimpleLineLayout.cpp        2015-01-22 21:54:53 UTC (rev 178939)
</span><span class="lines">@@ -227,20 +227,6 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> struct LineState {
</span><del>- LineState()
- : availableWidth(0)
- , logicalLeftOffset(0)
- , lineStartRunIndex(0)
- , uncommittedStart(0)
- , uncommittedEnd(0)
- , uncommittedWidth(0)
- , committedWidth(0)
- , committedLogicalRight(0)
- , position(0)
- , trailingWhitespaceWidth(0)
- {
- }
-
</del><span class="cx"> void commitAndCreateRun(Layout::RunVector& lineRuns)
</span><span class="cx"> {
</span><span class="cx"> if (uncommittedStart == uncommittedEnd)
</span><span class="lines">@@ -250,9 +236,13 @@
</span><span class="cx"> // Move uncommitted to committed.
</span><span class="cx"> committedWidth += uncommittedWidth;
</span><span class="cx"> committedLogicalRight += committedWidth;
</span><ins>+ committedTrailingWhitespaceWidth = uncomittedTrailingWhitespaceWidth;
+ committedTrailingWhitespaceLength = uncomittedTrailingWhitespaceLength;
</ins><span class="cx">
</span><span class="cx"> uncommittedStart = uncommittedEnd;
</span><span class="cx"> uncommittedWidth = 0;
</span><ins>+ uncomittedTrailingWhitespaceWidth = 0;
+ uncomittedTrailingWhitespaceLength = 0;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> void addUncommitted(const FlowContents::TextFragment& fragment)
</span><span class="lines">@@ -261,8 +251,8 @@
</span><span class="cx"> uncommittedWidth += fragment.width;
</span><span class="cx"> uncommittedEnd = fragment.end;
</span><span class="cx"> position = uncommittedEnd;
</span><del>- trailingWhitespaceWidth = fragment.type == FlowContents::TextFragment::Whitespace ? fragment.width : 0;
- trailingWhitespaceLength = fragment.type == FlowContents::TextFragment::Whitespace ? uncomittedFragmentLength : 0;
</del><ins>+ uncomittedTrailingWhitespaceWidth = fragment.type == FlowContents::TextFragment::Whitespace ? fragment.width : 0;
+ uncomittedTrailingWhitespaceLength = fragment.type == FlowContents::TextFragment::Whitespace ? uncomittedFragmentLength : 0;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> void addUncommittedWhitespace(float whitespaceWidth)
</span><span class="lines">@@ -280,6 +270,11 @@
</span><span class="cx"> committedLogicalRight = logicalRight;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ bool hasWhitespaceOnly() const
+ {
+ return committedTrailingWhitespaceWidth && committedWidth == committedTrailingWhitespaceWidth;
+ }
+
</ins><span class="cx"> float width() const
</span><span class="cx"> {
</span><span class="cx"> return committedWidth + uncommittedWidth;
</span><span class="lines">@@ -290,35 +285,33 @@
</span><span class="cx"> return availableWidth >= width() + extra;
</span><span class="cx"> }
</span><span class="cx">
</span><del>- void removeCommittedTrailingWhitespace()
</del><ins>+ void removeTrailingWhitespace()
</ins><span class="cx"> {
</span><del>- ASSERT(!uncommittedWidth);
- committedWidth -= trailingWhitespaceWidth;
- committedLogicalRight -= trailingWhitespaceWidth;
</del><ins>+ committedWidth -= committedTrailingWhitespaceWidth;
+ committedLogicalRight -= committedTrailingWhitespaceWidth;
+ committedTrailingWhitespaceWidth = 0;
+ committedTrailingWhitespaceLength = 0;
</ins><span class="cx"> }
</span><span class="cx">
</span><del>- void resetTrailingWhitespace()
- {
- trailingWhitespaceWidth = 0;
- trailingWhitespaceLength = 0;
- }
</del><ins>+ float availableWidth { 0 };
+ float logicalLeftOffset { 0 };
+ unsigned lineStartRunIndex { 0 }; // The run that the line starts with.
+ unsigned position { 0 };
</ins><span class="cx">
</span><del>- float availableWidth;
- float logicalLeftOffset;
- unsigned lineStartRunIndex; // The run that the line starts with.
</del><ins>+ unsigned uncommittedStart { 0 };
+ unsigned uncommittedEnd { 0 };
+ float uncommittedWidth { 0 };
+ float committedWidth { 0 };
</ins><span class="cx">
</span><del>- unsigned uncommittedStart;
- unsigned uncommittedEnd;
- float uncommittedWidth;
- float committedWidth;
- float committedLogicalRight; // Last committed X (coordinate) position.
</del><ins>+ float committedLogicalRight { 0 }; // Last committed X (coordinate) position.
+ float committedTrailingWhitespaceWidth { 0 }; // Use this to remove trailing whitespace without re-mesuring the text.
+ unsigned committedTrailingWhitespaceLength { 0 };
</ins><span class="cx">
</span><del>- unsigned position;
-
- float trailingWhitespaceWidth; // Use this to remove trailing whitespace without re-mesuring the text.
- float trailingWhitespaceLength;
-
</del><span class="cx"> FlowContents::TextFragment oveflowedFragment;
</span><ins>+
+private:
+ float uncomittedTrailingWhitespaceWidth { 0 };
+ unsigned uncomittedTrailingWhitespaceLength { 0 };
</ins><span class="cx"> };
</span><span class="cx">
</span><span class="cx"> static void removeTrailingWhitespace(LineState& lineState, Layout::RunVector& lineRuns, const FlowContents& flowContents)
</span><span class="lines">@@ -326,36 +319,30 @@
</span><span class="cx"> const auto& style = flowContents.style();
</span><span class="cx"> bool preWrap = style.wrapLines && !style.collapseWhitespace;
</span><span class="cx"> // Trailing whitespace gets removed when we either collapse whitespace or pre-wrap is present.
</span><del>- if (!(style.collapseWhitespace || preWrap)) {
- lineState.resetTrailingWhitespace();
</del><ins>+ if (!(style.collapseWhitespace || preWrap))
</ins><span class="cx"> return;
</span><del>- }
</del><span class="cx">
</span><span class="cx"> ASSERT(lineRuns.size());
</span><span class="cx"> Run& lastRun = lineRuns.last();
</span><span class="cx">
</span><span class="cx"> unsigned lastPosition = lineState.position;
</span><span class="cx"> bool trailingPreWrapWhitespaceNeedsToBeRemoved = false;
</span><del>- // When pre-wrap is present, trailing whitespace needs to be removed:
- // 1. from the "next line": when at least the first charater fits. When even the first whitespace is wider that the available width,
- // we don't remove any whitespace at all.
- // 2. from this line: remove whitespace, unless it's the only fragment on the line -so removing the whitesapce would produce an empty line.
</del><span class="cx"> if (preWrap) {
</span><ins>+ // Special overflow pre-wrap fragment handling: Ignore the overflow whitespace fragment if we managed to fit at least one character on this line.
+ // When the line is too short to fit one character (thought it still stays on the line) we keep the overflow whitespace content as it is.
</ins><span class="cx"> if (lineState.oveflowedFragment.type == FlowContents::TextFragment::Whitespace && !lineState.oveflowedFragment.isEmpty() && lineState.availableWidth >= lineState.committedWidth) {
</span><span class="cx"> lineState.position = lineState.oveflowedFragment.end;
</span><span class="cx"> lineState.oveflowedFragment = FlowContents::TextFragment();
</span><span class="cx"> }
</span><del>- if (lineState.trailingWhitespaceLength) {
- // Check if we've got only whitespace on this line.
- trailingPreWrapWhitespaceNeedsToBeRemoved = !(lineState.committedWidth == lineState.trailingWhitespaceWidth);
- }
</del><ins>+ // Remove whitespace, unless it's the only fragment on the line -so removing the whitesapce would produce an empty line.
+ trailingPreWrapWhitespaceNeedsToBeRemoved = !lineState.hasWhitespaceOnly();
</ins><span class="cx"> }
</span><del>- if (lineState.trailingWhitespaceLength && (style.collapseWhitespace || trailingPreWrapWhitespaceNeedsToBeRemoved)) {
- lastRun.logicalRight -= lineState.trailingWhitespaceWidth;
- lastRun.end -= lineState.trailingWhitespaceLength;
</del><ins>+ if (lineState.committedTrailingWhitespaceLength && (style.collapseWhitespace || trailingPreWrapWhitespaceNeedsToBeRemoved)) {
+ lastRun.logicalRight -= lineState.committedTrailingWhitespaceWidth;
+ lastRun.end -= lineState.committedTrailingWhitespaceLength;
</ins><span class="cx"> if (lastRun.start == lastRun.end)
</span><span class="cx"> lineRuns.removeLast();
</span><del>- lineState.removeCommittedTrailingWhitespace();
</del><ins>+ lineState.removeTrailingWhitespace();
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> // If we skipped any whitespace and now the line end is a hard newline, skip the newline too as we are wrapping the line here already.
</span></span></pre>
</div>
</div>
</body>
</html>