- Revision
- 201104
- Author
- cdu...@apple.com
- Date
- 2016-05-18 15:27:47 -0700 (Wed, 18 May 2016)
Log Message
Clean up / Modernize TextAutoSizingValue::adjustNodeSizes()
https://bugs.webkit.org/show_bug.cgi?id=157861
Reviewed by Alex Christensen.
Clean up / Modernize TextAutoSizingValue::adjustNodeSizes(), and
use tighter typing for autosizing nodes.
* dom/Document.cpp:
(WebCore::Document::addAutoSizingNode):
* dom/Document.h:
* rendering/RenderBlockFlow.cpp:
(WebCore::RenderBlockFlow::adjustComputedFontSizes):
* rendering/TextAutoSizing.cpp:
(WebCore::TextAutoSizingValue::addNode):
(WebCore::TextAutoSizingValue::adjustNodeSizes):
(WebCore::TextAutoSizingValue::reset):
* rendering/TextAutoSizing.h:
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (201103 => 201104)
--- trunk/Source/WebCore/ChangeLog 2016-05-18 22:25:01 UTC (rev 201103)
+++ trunk/Source/WebCore/ChangeLog 2016-05-18 22:27:47 UTC (rev 201104)
@@ -1,3 +1,24 @@
+2016-05-18 Chris Dumez <cdu...@apple.com>
+
+ Clean up / Modernize TextAutoSizingValue::adjustNodeSizes()
+ https://bugs.webkit.org/show_bug.cgi?id=157861
+
+ Reviewed by Alex Christensen.
+
+ Clean up / Modernize TextAutoSizingValue::adjustNodeSizes(), and
+ use tighter typing for autosizing nodes.
+
+ * dom/Document.cpp:
+ (WebCore::Document::addAutoSizingNode):
+ * dom/Document.h:
+ * rendering/RenderBlockFlow.cpp:
+ (WebCore::RenderBlockFlow::adjustComputedFontSizes):
+ * rendering/TextAutoSizing.cpp:
+ (WebCore::TextAutoSizingValue::addNode):
+ (WebCore::TextAutoSizingValue::adjustNodeSizes):
+ (WebCore::TextAutoSizingValue::reset):
+ * rendering/TextAutoSizing.h:
+
2016-05-18 Simon Fraser <simon.fra...@apple.com>
Remove logging inadvertently committed in r201090.
Modified: trunk/Source/WebCore/dom/Document.cpp (201103 => 201104)
--- trunk/Source/WebCore/dom/Document.cpp 2016-05-18 22:25:01 UTC (rev 201103)
+++ trunk/Source/WebCore/dom/Document.cpp 2016-05-18 22:27:47 UTC (rev 201104)
@@ -5279,11 +5279,11 @@
#if ENABLE(IOS_TEXT_AUTOSIZING)
-void Document::addAutoSizingNode(Node* node, float candidateSize)
+void Document::addAutoSizingNode(Text& node, float candidateSize)
{
- LOG(TextAutosizing, " addAutoSizingNode %p candidateSize=%f", node, candidateSize);
+ LOG(TextAutosizing, " addAutoSizingNode %p candidateSize=%f", &node, candidateSize);
- TextAutoSizingKey key(&node->renderer()->style());
+ TextAutoSizingKey key(&node.renderer()->style());
auto addResult = m_textAutoSizedNodes.ensure(WTFMove(key), [] {
return TextAutoSizingValue::create();
});
Modified: trunk/Source/WebCore/dom/Document.h (201103 => 201104)
--- trunk/Source/WebCore/dom/Document.h 2016-05-18 22:25:01 UTC (rev 201103)
+++ trunk/Source/WebCore/dom/Document.h 2016-05-18 22:27:47 UTC (rev 201104)
@@ -1692,7 +1692,7 @@
#if ENABLE(IOS_TEXT_AUTOSIZING)
public:
- void addAutoSizingNode(Node*, float size);
+ void addAutoSizingNode(Text&, float size);
void validateAutoSizingNodes();
void resetAutoSizingNodes();
Modified: trunk/Source/WebCore/rendering/RenderBlockFlow.cpp (201103 => 201104)
--- trunk/Source/WebCore/rendering/RenderBlockFlow.cpp 2016-05-18 22:25:01 UTC (rev 201103)
+++ trunk/Source/WebCore/rendering/RenderBlockFlow.cpp 2016-05-18 22:27:47 UTC (rev 201104)
@@ -3810,7 +3810,7 @@
float lineTextMultiplier = lineCount == ONE_LINE ? oneLineTextMultiplier(specifiedSize) : textMultiplier(specifiedSize);
candidateNewSize = roundf(std::min(minFontSize, specifiedSize * lineTextMultiplier));
if (candidateNewSize > specifiedSize && candidateNewSize != fontDescription.computedSize() && text.textNode() && oldStyle.textSizeAdjust().isAuto())
- document().addAutoSizingNode(text.textNode(), candidateNewSize);
+ document().addAutoSizingNode(*text.textNode(), candidateNewSize);
}
}
}
Modified: trunk/Source/WebCore/rendering/TextAutoSizing.cpp (201103 => 201104)
--- trunk/Source/WebCore/rendering/TextAutoSizing.cpp 2016-05-18 22:25:01 UTC (rev 201103)
+++ trunk/Source/WebCore/rendering/TextAutoSizing.cpp 2016-05-18 22:27:47 UTC (rev 201104)
@@ -62,29 +62,27 @@
return m_autoSizedNodes.size();
}
-void TextAutoSizingValue::addNode(Node* node, float size)
+void TextAutoSizingValue::addNode(Text& node, float size)
{
- ASSERT(node);
- downcast<RenderText>(*node->renderer()).setCandidateComputedTextSize(size);
- m_autoSizedNodes.add(node);
+ node.renderer()->setCandidateComputedTextSize(size);
+ m_autoSizedNodes.add(&node);
}
#define MAX_SCALE_INCREASE 1.7f
bool TextAutoSizingValue::adjustNodeSizes()
{
- bool objectsRemoved = false;
+ bool didRemoveObjects = false;
// Remove stale nodes. Nodes may have had their renderers detached. We'll
// also need to remove the style from the documents m_textAutoSizedNodes
// collection. Return true indicates we need to do that removal.
- Vector<RefPtr<Node> > nodesForRemoval;
- for (auto& autoSizingNode : m_autoSizedNodes) {
- auto* text = downcast<RenderText>(autoSizingNode->renderer());
+ Vector<Text*> nodesForRemoval;
+ for (auto& node : m_autoSizedNodes) {
+ auto* text = node->renderer();
if (!text || !text->style().textSizeAdjust().isAuto() || !text->candidateComputedTextSize()) {
- // remove node.
- nodesForRemoval.append(autoSizingNode);
- objectsRemoved = true;
+ nodesForRemoval.append(node.get());
+ didRemoveObjects = true;
}
}
@@ -94,83 +92,89 @@
// If we only have one piece of text with the style on the page don't
// adjust it's size.
if (m_autoSizedNodes.size() <= 1)
- return objectsRemoved;
+ return didRemoveObjects;
// Compute average size
float cumulativeSize = 0;
- for (auto& autoSizingNode : m_autoSizedNodes) {
- RenderText& renderText = downcast<RenderText>(*autoSizingNode->renderer());
- cumulativeSize += renderText.candidateComputedTextSize();
- }
+ for (auto& node : m_autoSizedNodes)
+ cumulativeSize += node->renderer()->candidateComputedTextSize();
float averageSize = roundf(cumulativeSize / m_autoSizedNodes.size());
// Adjust sizes
bool firstPass = true;
- for (auto& autoSizingNode : m_autoSizedNodes) {
- auto* text = downcast<RenderText>(autoSizingNode->renderer());
- if (text && text->style().fontDescription().computedSize() != averageSize) {
- float specifiedSize = text->style().fontDescription().specifiedSize();
- float scaleChange = averageSize / specifiedSize;
- if (scaleChange > MAX_SCALE_INCREASE && firstPass) {
- firstPass = false;
- averageSize = roundf(specifiedSize * MAX_SCALE_INCREASE);
- scaleChange = averageSize / specifiedSize;
- }
+ for (auto& node : m_autoSizedNodes) {
+ auto* text = node->renderer();
+ if (!text || text->style().fontDescription().computedSize() == averageSize)
+ continue;
- LOG(TextAutosizing, " adjust node size %p firstPass=%d averageSize=%f scaleChange=%f", autoSizingNode.get(), firstPass, averageSize, scaleChange);
+ float specifiedSize = text->style().fontDescription().specifiedSize();
+ float scaleChange = averageSize / specifiedSize;
+ if (scaleChange > MAX_SCALE_INCREASE && firstPass) {
+ firstPass = false;
+ averageSize = roundf(specifiedSize * MAX_SCALE_INCREASE);
+ scaleChange = averageSize / specifiedSize;
+ }
- auto style = cloneRenderStyleWithState(text->style());
- auto fontDescription = style.fontDescription();
- fontDescription.setComputedSize(averageSize);
+ LOG(TextAutosizing, " adjust node size %p firstPass=%d averageSize=%f scaleChange=%f", node.get(), firstPass, averageSize, scaleChange);
+
+ auto* parentRenderer = text->parent();
+
+ auto style = cloneRenderStyleWithState(text->style());
+ auto fontDescription = style.fontDescription();
+ fontDescription.setComputedSize(averageSize);
+ style.setFontDescription(fontDescription);
+ style.fontCascade().update(&node->document().fontSelector());
+ parentRenderer->setStyle(WTFMove(style));
+
+ if (parentRenderer->isAnonymousBlock())
+ parentRenderer = parentRenderer->parent();
+
+ // If we have a list we should resize ListMarkers separately.
+ if (is<RenderListMarker>(*parentRenderer->firstChild())) {
+ auto& listMarkerRenderer = downcast<RenderListMarker>(*parentRenderer->firstChild());
+ auto style = cloneRenderStyleWithState(listMarkerRenderer.style());
style.setFontDescription(fontDescription);
- style.fontCascade().update(&autoSizingNode->document().fontSelector());
- text->parent()->setStyle(WTFMove(style));
+ style.fontCascade().update(&node->document().fontSelector());
+ listMarkerRenderer.setStyle(WTFMove(style));
+ }
- RenderElement* parentRenderer = text->parent();
- if (parentRenderer->isAnonymousBlock())
- parentRenderer = parentRenderer->parent();
+ // Resize the line height of the parent.
+ auto& parentStyle = parentRenderer->style();
+ Length lineHeightLength = parentStyle.specifiedLineHeight();
- // If we have a list we should resize ListMarkers separately.
- RenderObject* listMarkerRenderer = parentRenderer->firstChild();
- if (listMarkerRenderer->isListMarker()) {
- auto style = cloneRenderStyleWithState(listMarkerRenderer->style());
- style.setFontDescription(fontDescription);
- style.fontCascade().update(&autoSizingNode->document().fontSelector());
- downcast<RenderListMarker>(*listMarkerRenderer).setStyle(WTFMove(style));
- }
+ int specifiedLineHeight;
+ if (lineHeightLength.isPercent())
+ specifiedLineHeight = minimumValueForLength(lineHeightLength, fontDescription.specifiedSize());
+ else
+ specifiedLineHeight = lineHeightLength.value();
- // Resize the line height of the parent.
- auto& parentStyle = parentRenderer->style();
- Length lineHeightLength = parentStyle.specifiedLineHeight();
+ int lineHeight = specifiedLineHeight * scaleChange;
+ if (lineHeightLength.isFixed() && lineHeightLength.value() == lineHeight)
+ continue;
- int specifiedLineHeight = 0;
- if (lineHeightLength.isPercent())
- specifiedLineHeight = minimumValueForLength(lineHeightLength, fontDescription.specifiedSize());
- else
- specifiedLineHeight = lineHeightLength.value();
-
- int lineHeight = specifiedLineHeight * scaleChange;
- if (!lineHeightLength.isFixed() || lineHeightLength.value() != lineHeight) {
- auto newParentStyle = cloneRenderStyleWithState(parentStyle);
- newParentStyle.setLineHeight(Length(lineHeight, Fixed));
- newParentStyle.setSpecifiedLineHeight(lineHeightLength);
- newParentStyle.setFontDescription(fontDescription);
- newParentStyle.fontCascade().update(&autoSizingNode->document().fontSelector());
- parentRenderer->setStyle(WTFMove(newParentStyle));
- }
- }
+ auto newParentStyle = cloneRenderStyleWithState(parentStyle);
+ newParentStyle.setLineHeight(Length(lineHeight, Fixed));
+ newParentStyle.setSpecifiedLineHeight(lineHeightLength);
+ newParentStyle.setFontDescription(fontDescription);
+ newParentStyle.fontCascade().update(&node->document().fontSelector());
+ parentRenderer->setStyle(WTFMove(newParentStyle));
}
- return objectsRemoved;
+ return didRemoveObjects;
}
void TextAutoSizingValue::reset()
{
- for (auto& autoSizingNode : m_autoSizedNodes) {
- auto* text = downcast<RenderText>(autoSizingNode->renderer());
+ for (auto& node : m_autoSizedNodes) {
+ auto* text = node->renderer();
if (!text)
continue;
+
+ auto* parentRenderer = text->parent();
+ if (!parentRenderer)
+ continue;
+
// Reset the font size back to the original specified size
auto fontDescription = text->style().fontDescription();
float originalSize = fontDescription.specifiedSize();
@@ -178,26 +182,24 @@
fontDescription.setComputedSize(originalSize);
auto style = cloneRenderStyleWithState(text->style());
style.setFontDescription(fontDescription);
- style.fontCascade().update(&autoSizingNode->document().fontSelector());
- text->parent()->setStyle(WTFMove(style));
+ style.fontCascade().update(&node->document().fontSelector());
+ parentRenderer->setStyle(WTFMove(style));
}
+
// Reset the line height of the parent.
- RenderElement* parentRenderer = text->parent();
- if (!parentRenderer)
- continue;
-
if (parentRenderer->isAnonymousBlock())
parentRenderer = parentRenderer->parent();
auto& parentStyle = parentRenderer->style();
Length originalLineHeight = parentStyle.specifiedLineHeight();
- if (originalLineHeight != parentStyle.lineHeight()) {
- auto newParentStyle = cloneRenderStyleWithState(parentStyle);
- newParentStyle.setLineHeight(originalLineHeight);
- newParentStyle.setFontDescription(fontDescription);
- newParentStyle.fontCascade().update(&autoSizingNode->document().fontSelector());
- parentRenderer->setStyle(WTFMove(newParentStyle));
- }
+ if (originalLineHeight == parentStyle.lineHeight())
+ continue;
+
+ auto newParentStyle = cloneRenderStyleWithState(parentStyle);
+ newParentStyle.setLineHeight(originalLineHeight);
+ newParentStyle.setFontDescription(fontDescription);
+ newParentStyle.fontCascade().update(&node->document().fontSelector());
+ parentRenderer->setStyle(WTFMove(newParentStyle));
}
}
Modified: trunk/Source/WebCore/rendering/TextAutoSizing.h (201103 => 201104)
--- trunk/Source/WebCore/rendering/TextAutoSizing.h 2016-05-18 22:25:01 UTC (rev 201103)
+++ trunk/Source/WebCore/rendering/TextAutoSizing.h 2016-05-18 22:27:47 UTC (rev 201104)
@@ -36,7 +36,7 @@
namespace WebCore {
class Document;
-class Node;
+class Text;
class TextAutoSizingKey {
public:
@@ -78,13 +78,13 @@
return adoptRef(*new TextAutoSizingValue);
}
- void addNode(Node*, float size);
+ void addNode(Text&, float size);
bool adjustNodeSizes();
int numNodes() const;
void reset();
private:
TextAutoSizingValue() { }
- HashSet<RefPtr<Node> > m_autoSizedNodes;
+ HashSet<RefPtr<Text>> m_autoSizedNodes;
};
} // namespace WebCore