<!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>[200593] 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/200593">200593</a></dd>
<dt>Author</dt> <dd>simon.fraser@apple.com</dd>
<dt>Date</dt> <dd>2016-05-09 14:57:43 -0700 (Mon, 09 May 2016)</dd>
</dl>
<h3>Log Message</h3>
<pre>Clean up iOS text autosizing code
https://bugs.webkit.org/show_bug.cgi?id=157489
Reviewed by Zalan Bujtas.
Change the TraverseNextInclusionFunction and HeightTypeTraverseNextInclusionFunction
to take references.
Use downcast<> more.
Whitespace cleanup.
* rendering/RenderBlockFlow.cpp:
(WebCore::isNonBlocksOrNonFixedHeightListItems):
* rendering/RenderElement.cpp:
(WebCore::includeNonFixedHeight):
* rendering/RenderObject.cpp:
(WebCore::RenderObject::traverseNext):
* rendering/RenderObject.h:
* rendering/TextAutoSizing.cpp:
(WebCore::TextAutoSizingValue::adjustNodeSizes):
(WebCore::TextAutoSizingValue::reset):</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorerenderingRenderBlockFlowcpp">trunk/Source/WebCore/rendering/RenderBlockFlow.cpp</a></li>
<li><a href="#trunkSourceWebCorerenderingRenderElementcpp">trunk/Source/WebCore/rendering/RenderElement.cpp</a></li>
<li><a href="#trunkSourceWebCorerenderingRenderObjectcpp">trunk/Source/WebCore/rendering/RenderObject.cpp</a></li>
<li><a href="#trunkSourceWebCorerenderingRenderObjecth">trunk/Source/WebCore/rendering/RenderObject.h</a></li>
<li><a href="#trunkSourceWebCorerenderingTextAutoSizingcpp">trunk/Source/WebCore/rendering/TextAutoSizing.cpp</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (200592 => 200593)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-05-09 21:53:43 UTC (rev 200592)
+++ trunk/Source/WebCore/ChangeLog        2016-05-09 21:57:43 UTC (rev 200593)
</span><span class="lines">@@ -1,3 +1,28 @@
</span><ins>+2016-05-09 Simon Fraser <simon.fraser@apple.com>
+
+ Clean up iOS text autosizing code
+ https://bugs.webkit.org/show_bug.cgi?id=157489
+
+ Reviewed by Zalan Bujtas.
+
+ Change the TraverseNextInclusionFunction and HeightTypeTraverseNextInclusionFunction
+ to take references.
+
+ Use downcast<> more.
+
+ Whitespace cleanup.
+
+ * rendering/RenderBlockFlow.cpp:
+ (WebCore::isNonBlocksOrNonFixedHeightListItems):
+ * rendering/RenderElement.cpp:
+ (WebCore::includeNonFixedHeight):
+ * rendering/RenderObject.cpp:
+ (WebCore::RenderObject::traverseNext):
+ * rendering/RenderObject.h:
+ * rendering/TextAutoSizing.cpp:
+ (WebCore::TextAutoSizingValue::adjustNodeSizes):
+ (WebCore::TextAutoSizingValue::reset):
+
</ins><span class="cx"> 2016-05-09 Anders Carlsson <andersca@apple.com>
</span><span class="cx">
</span><span class="cx"> Add injected bundle SPI for getting favicon and touch icon URLs
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingRenderBlockFlowcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/RenderBlockFlow.cpp (200592 => 200593)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/RenderBlockFlow.cpp        2016-05-09 21:53:43 UTC (rev 200592)
+++ trunk/Source/WebCore/rendering/RenderBlockFlow.cpp        2016-05-09 21:57:43 UTC (rev 200593)
</span><span class="lines">@@ -3739,12 +3739,12 @@
</span><span class="cx"> return count;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-static bool isNonBlocksOrNonFixedHeightListItems(const RenderObject* render)
</del><ins>+static bool isNonBlocksOrNonFixedHeightListItems(const RenderObject& render)
</ins><span class="cx"> {
</span><del>- if (!render->isRenderBlock())
</del><ins>+ if (!render.isRenderBlock())
</ins><span class="cx"> return true;
</span><del>- if (render->isListItem())
- return render->style().height().type() != Fixed;
</del><ins>+ if (render.isListItem())
+ return render.style().height().type() != Fixed;
</ins><span class="cx"> return false;
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -3790,7 +3790,7 @@
</span><span class="cx">
</span><span class="cx"> for (RenderObject* descendent = traverseNext(this, isNonBlocksOrNonFixedHeightListItems); descendent; descendent = descendent->traverseNext(this, isNonBlocksOrNonFixedHeightListItems)) {
</span><span class="cx"> if (isVisibleRenderText(descendent) && resizeTextPermitted(descendent)) {
</span><del>- RenderText& text = downcast<RenderText>(*descendent);
</del><ins>+ auto& text = downcast<RenderText>(*descendent);
</ins><span class="cx"> auto& oldStyle = text.style();
</span><span class="cx"> auto fontDescription = oldStyle.fontDescription();
</span><span class="cx"> float specifiedSize = fontDescription.specifiedSize();
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingRenderElementcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/RenderElement.cpp (200592 => 200593)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/RenderElement.cpp        2016-05-09 21:53:43 UTC (rev 200592)
+++ trunk/Source/WebCore/rendering/RenderElement.cpp        2016-05-09 21:57:43 UTC (rev 200593)
</span><span class="lines">@@ -2169,15 +2169,15 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> #if ENABLE(IOS_TEXT_AUTOSIZING)
</span><del>-static RenderObject::BlockContentHeightType includeNonFixedHeight(const RenderObject* renderer)
</del><ins>+static RenderObject::BlockContentHeightType includeNonFixedHeight(const RenderObject& renderer)
</ins><span class="cx"> {
</span><del>- const RenderStyle& style = renderer->style();
</del><ins>+ const RenderStyle& style = renderer.style();
</ins><span class="cx"> if (style.height().type() == Fixed) {
</span><del>- if (is<RenderBlock>(*renderer)) {
</del><ins>+ if (is<RenderBlock>(renderer)) {
</ins><span class="cx"> // For fixed height styles, if the overflow size of the element spills out of the specified
</span><span class="cx"> // height, assume we can apply text auto-sizing.
</span><span class="cx"> if (style.overflowY() == OVISIBLE
</span><del>- && style.height().value() < downcast<RenderBlock>(renderer)->layoutOverflowRect().maxY())
</del><ins>+ && style.height().value() < downcast<RenderBlock>(renderer).layoutOverflowRect().maxY())
</ins><span class="cx"> return RenderObject::OverflowHeight;
</span><span class="cx"> }
</span><span class="cx"> return RenderObject::FixedHeight;
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingRenderObjectcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/RenderObject.cpp (200592 => 200593)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/RenderObject.cpp        2016-05-09 21:53:43 UTC (rev 200592)
+++ trunk/Source/WebCore/rendering/RenderObject.cpp        2016-05-09 21:57:43 UTC (rev 200593)
</span><span class="lines">@@ -325,7 +325,7 @@
</span><span class="cx">
</span><span class="cx"> // Check for suitable children.
</span><span class="cx"> for (RenderObject* child = firstChildSlow(); child; child = child->nextSibling()) {
</span><del>- overflowType = inclusionFunction(child);
</del><ins>+ overflowType = inclusionFunction(*child);
</ins><span class="cx"> if (overflowType != FixedHeight) {
</span><span class="cx"> currentDepth++;
</span><span class="cx"> if (overflowType == OverflowHeight)
</span><span class="lines">@@ -349,7 +349,7 @@
</span><span class="cx"> if (!n)
</span><span class="cx"> return nullptr;
</span><span class="cx"> for (RenderObject* sibling = n->nextSibling(); sibling; sibling = sibling->nextSibling()) {
</span><del>- overflowType = inclusionFunction(sibling);
</del><ins>+ overflowType = inclusionFunction(*sibling);
</ins><span class="cx"> if (overflowType != FixedHeight) {
</span><span class="cx"> if (overflowType == OverflowHeight)
</span><span class="cx"> newFixedDepth = currentDepth;
</span><span class="lines">@@ -369,7 +369,7 @@
</span><span class="cx"> RenderObject* RenderObject::traverseNext(const RenderObject* stayWithin, TraverseNextInclusionFunction inclusionFunction) const
</span><span class="cx"> {
</span><span class="cx"> for (RenderObject* child = firstChildSlow(); child; child = child->nextSibling()) {
</span><del>- if (inclusionFunction(child)) {
</del><ins>+ if (inclusionFunction(*child)) {
</ins><span class="cx"> ASSERT(!stayWithin || child->isDescendantOf(stayWithin));
</span><span class="cx"> return child;
</span><span class="cx"> }
</span><span class="lines">@@ -379,7 +379,7 @@
</span><span class="cx"> return nullptr;
</span><span class="cx">
</span><span class="cx"> for (RenderObject* sibling = nextSibling(); sibling; sibling = sibling->nextSibling()) {
</span><del>- if (inclusionFunction(sibling)) {
</del><ins>+ if (inclusionFunction(*sibling)) {
</ins><span class="cx"> ASSERT(!stayWithin || sibling->isDescendantOf(stayWithin));
</span><span class="cx"> return sibling;
</span><span class="cx"> }
</span><span class="lines">@@ -391,7 +391,7 @@
</span><span class="cx"> n = n->parent();
</span><span class="cx"> if (n) {
</span><span class="cx"> for (RenderObject* sibling = n->nextSibling(); sibling; sibling = sibling->nextSibling()) {
</span><del>- if (inclusionFunction(sibling)) {
</del><ins>+ if (inclusionFunction(*sibling)) {
</ins><span class="cx"> ASSERT(!stayWithin || !n->nextSibling() || n->nextSibling()->isDescendantOf(stayWithin));
</span><span class="cx"> return sibling;
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingRenderObjecth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/RenderObject.h (200592 => 200593)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/RenderObject.h        2016-05-09 21:53:43 UTC (rev 200592)
+++ trunk/Source/WebCore/rendering/RenderObject.h        2016-05-09 21:57:43 UTC (rev 200593)
</span><span class="lines">@@ -190,8 +190,8 @@
</span><span class="cx"> };
</span><span class="cx">
</span><span class="cx"> RenderObject* traverseNext(const RenderObject* stayWithin) const;
</span><del>- typedef bool (*TraverseNextInclusionFunction)(const RenderObject*);
- typedef BlockContentHeightType (*HeightTypeTraverseNextInclusionFunction)(const RenderObject*);
</del><ins>+ typedef bool (*TraverseNextInclusionFunction)(const RenderObject&);
+ typedef BlockContentHeightType (*HeightTypeTraverseNextInclusionFunction)(const RenderObject&);
</ins><span class="cx">
</span><span class="cx"> RenderObject* traverseNext(const RenderObject* stayWithin, TraverseNextInclusionFunction) const;
</span><span class="cx"> RenderObject* traverseNext(const RenderObject* stayWithin, HeightTypeTraverseNextInclusionFunction, int& currentDepth, int& newFixedDepth) const;
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingTextAutoSizingcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/TextAutoSizing.cpp (200592 => 200593)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/TextAutoSizing.cpp        2016-05-09 21:53:43 UTC (rev 200592)
+++ trunk/Source/WebCore/rendering/TextAutoSizing.cpp        2016-05-09 21:57:43 UTC (rev 200593)
</span><span class="lines">@@ -74,41 +74,41 @@
</span><span class="cx"> bool TextAutoSizingValue::adjustNodeSizes()
</span><span class="cx"> {
</span><span class="cx"> bool objectsRemoved = false;
</span><del>-
</del><ins>+
</ins><span class="cx"> // Remove stale nodes. Nodes may have had their renderers detached. We'll
</span><span class="cx"> // also need to remove the style from the documents m_textAutoSizedNodes
</span><span class="cx"> // collection. Return true indicates we need to do that removal.
</span><span class="cx"> Vector<RefPtr<Node> > nodesForRemoval;
</span><span class="cx"> for (auto& autoSizingNode : m_autoSizedNodes) {
</span><del>- RenderText* text = static_cast<RenderText*>(autoSizingNode->renderer());
</del><ins>+ auto* text = downcast<RenderText>(autoSizingNode->renderer());
</ins><span class="cx"> if (!text || !text->style().textSizeAdjust().isAuto() || !text->candidateComputedTextSize()) {
</span><span class="cx"> // remove node.
</span><span class="cx"> nodesForRemoval.append(autoSizingNode);
</span><span class="cx"> objectsRemoved = true;
</span><span class="cx"> }
</span><span class="cx"> }
</span><del>-
</del><ins>+
</ins><span class="cx"> for (auto& node : nodesForRemoval)
</span><span class="cx"> m_autoSizedNodes.remove(node);
</span><del>-
</del><ins>+
</ins><span class="cx"> // If we only have one piece of text with the style on the page don't
</span><span class="cx"> // adjust it's size.
</span><span class="cx"> if (m_autoSizedNodes.size() <= 1)
</span><span class="cx"> return objectsRemoved;
</span><del>-
</del><ins>+
</ins><span class="cx"> // Compute average size
</span><span class="cx"> float cumulativeSize = 0;
</span><span class="cx"> for (auto& autoSizingNode : m_autoSizedNodes) {
</span><del>- RenderText* renderText = static_cast<RenderText*>(autoSizingNode->renderer());
- cumulativeSize += renderText->candidateComputedTextSize();
</del><ins>+ RenderText& renderText = downcast<RenderText>(*autoSizingNode->renderer());
+ cumulativeSize += renderText.candidateComputedTextSize();
</ins><span class="cx"> }
</span><del>-
</del><ins>+
</ins><span class="cx"> float averageSize = roundf(cumulativeSize / m_autoSizedNodes.size());
</span><del>-
</del><ins>+
</ins><span class="cx"> // Adjust sizes
</span><span class="cx"> bool firstPass = true;
</span><span class="cx"> for (auto& autoSizingNode : m_autoSizedNodes) {
</span><del>- RenderText* text = static_cast<RenderText*>(autoSizingNode->renderer());
</del><ins>+ auto* text = downcast<RenderText>(autoSizingNode->renderer());
</ins><span class="cx"> if (text && text->style().fontDescription().computedSize() != averageSize) {
</span><span class="cx"> float specifiedSize = text->style().fontDescription().specifiedSize();
</span><span class="cx"> float scaleChange = averageSize / specifiedSize;
</span><span class="lines">@@ -126,11 +126,11 @@
</span><span class="cx"> style.setFontDescription(fontDescription);
</span><span class="cx"> style.fontCascade().update(&autoSizingNode->document().fontSelector());
</span><span class="cx"> text->parent()->setStyle(WTFMove(style));
</span><del>-
</del><ins>+
</ins><span class="cx"> RenderElement* parentRenderer = text->parent();
</span><span class="cx"> if (parentRenderer->isAnonymousBlock())
</span><span class="cx"> parentRenderer = parentRenderer->parent();
</span><del>-
</del><ins>+
</ins><span class="cx"> // If we have a list we should resize ListMarkers separately.
</span><span class="cx"> RenderObject* listMarkerRenderer = parentRenderer->firstChild();
</span><span class="cx"> if (listMarkerRenderer->isListMarker()) {
</span><span class="lines">@@ -139,17 +139,17 @@
</span><span class="cx"> style.fontCascade().update(&autoSizingNode->document().fontSelector());
</span><span class="cx"> downcast<RenderListMarker>(*listMarkerRenderer).setStyle(WTFMove(style));
</span><span class="cx"> }
</span><del>-
</del><ins>+
</ins><span class="cx"> // Resize the line height of the parent.
</span><del>- const RenderStyle& parentStyle = parentRenderer->style();
</del><ins>+ auto& parentStyle = parentRenderer->style();
</ins><span class="cx"> Length lineHeightLength = parentStyle.specifiedLineHeight();
</span><del>-
</del><ins>+
</ins><span class="cx"> int specifiedLineHeight = 0;
</span><span class="cx"> if (lineHeightLength.isPercent())
</span><span class="cx"> specifiedLineHeight = minimumValueForLength(lineHeightLength, fontDescription.specifiedSize());
</span><span class="cx"> else
</span><span class="cx"> specifiedLineHeight = lineHeightLength.value();
</span><del>-
</del><ins>+
</ins><span class="cx"> int lineHeight = specifiedLineHeight * scaleChange;
</span><span class="cx"> if (!lineHeightLength.isFixed() || lineHeightLength.value() != lineHeight) {
</span><span class="cx"> auto newParentStyle = cloneRenderStyleWithState(parentStyle);
</span><span class="lines">@@ -161,14 +161,14 @@
</span><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx"> }
</span><del>-
</del><ins>+
</ins><span class="cx"> return objectsRemoved;
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> void TextAutoSizingValue::reset()
</span><span class="cx"> {
</span><span class="cx"> for (auto& autoSizingNode : m_autoSizedNodes) {
</span><del>- RenderText* text = static_cast<RenderText*>(autoSizingNode->renderer());
</del><ins>+ auto* text = downcast<RenderText>(autoSizingNode->renderer());
</ins><span class="cx"> if (!text)
</span><span class="cx"> continue;
</span><span class="cx"> // Reset the font size back to the original specified size
</span><span class="lines">@@ -185,11 +185,11 @@
</span><span class="cx"> RenderElement* parentRenderer = text->parent();
</span><span class="cx"> if (!parentRenderer)
</span><span class="cx"> continue;
</span><del>-
</del><ins>+
</ins><span class="cx"> if (parentRenderer->isAnonymousBlock())
</span><span class="cx"> parentRenderer = parentRenderer->parent();
</span><del>-
- const RenderStyle& parentStyle = parentRenderer->style();
</del><ins>+
+ auto& parentStyle = parentRenderer->style();
</ins><span class="cx"> Length originalLineHeight = parentStyle.specifiedLineHeight();
</span><span class="cx"> if (originalLineHeight != parentStyle.lineHeight()) {
</span><span class="cx"> auto newParentStyle = cloneRenderStyleWithState(parentStyle);
</span></span></pre>
</div>
</div>
</body>
</html>