[Cherry-pick][[Text Autosizing] Refactoring to eliminate boolean parameter.
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 22 Feb 2013 18:20:19 +0000 (18:20 +0000)
committerJaehun Lim <ljaehun.lim@samsung.com>
Thu, 4 Apr 2013 03:19:36 +0000 (12:19 +0900)
[TextAutosizing] Refactoring to eliminate boolean parameter.
https://bugs.webkit.org/show_bug.cgi?id=110490

Patch by Anton Vayvod <avayvod@chromium.org> on 2013-02-22
Reviewed by Julien Chaffraix.

A follow-up to the recent change that introduced a boolean parameter to
processClusterInternal method of TextAutosizer. Boolean parameters are discouraged by the
WebKit style guide. See http://trac.webkit.org/changeset/142866

Refactoring so no new tests.

* rendering/TextAutosizer.cpp:
(WebCore::TextAutosizer::clusterMultiplier):

        Calculates the font size multiplier for the specified cluster.

(WebCore::TextAutosizer::processClusterInternal):

        Accepts the font size multiplier instead of |shouldBeAutosized|.

(WebCore::TextAutosizer::processCluster):
(WebCore::TextAutosizer::processCompositeCluster):

        Both methods above now calculate the multiplier and then pass it to
        processClusterInternal.

* rendering/TextAutosizer.h:

        Updated method declarations.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@143749 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Conflicts:

Source/WebCore/ChangeLog

Source/WebCore/rendering/TextAutosizer.cpp
Source/WebCore/rendering/TextAutosizer.h

index f515943..60f4060 100644 (file)
@@ -146,20 +146,20 @@ bool TextAutosizer::processSubtree(RenderObject* layoutRoot)
     return true;
 }
 
-void TextAutosizer::processClusterInternal(TextAutosizingClusterInfo& clusterInfo, RenderBlock* container, RenderObject* subtreeRoot, const TextAutosizingWindowInfo& windowInfo, float textWidth, bool shouldBeAutosized)
+float TextAutosizer::clusterMultiplier(WritingMode writingMode, const TextAutosizingWindowInfo& windowInfo, float textWidth) const
 {
-    float multiplier = 1;
-    if (shouldBeAutosized) {
-        int logicalWindowWidth = clusterInfo.root->isHorizontalWritingMode() ? windowInfo.windowSize.width() : windowInfo.windowSize.height();
-        int logicalLayoutWidth = clusterInfo.root->isHorizontalWritingMode() ? windowInfo.minLayoutSize.width() : windowInfo.minLayoutSize.height();
-        // Ignore box width in excess of the layout width, to avoid extreme multipliers.
-        float logicalClusterWidth = std::min<float>(textWidth, logicalLayoutWidth);
-
-        multiplier = logicalClusterWidth / logicalWindowWidth;
-        multiplier *= m_document->settings()->textAutosizingFontScaleFactor();
-        multiplier = std::max(1.0f, multiplier);
-    }
+    int logicalWindowWidth = isHorizontalWritingMode(writingMode) ? windowInfo.windowSize.width() : windowInfo.windowSize.height();
+    int logicalLayoutWidth = isHorizontalWritingMode(writingMode) ? windowInfo.minLayoutSize.width() : windowInfo.minLayoutSize.height();
+    // Ignore box width in excess of the layout width, to avoid extreme multipliers.
+    float logicalClusterWidth = std::min<float>(textWidth, logicalLayoutWidth);
+
+    float multiplier = logicalClusterWidth / logicalWindowWidth;
+    multiplier *= m_document->settings()->textAutosizingFontScaleFactor();
+    return std::max(1.0f, multiplier);
+}
 
+void TextAutosizer::processClusterInternal(TextAutosizingClusterInfo& clusterInfo, RenderBlock* container, RenderObject* subtreeRoot, const TextAutosizingWindowInfo& windowInfo, float multiplier)
+{
     processContainer(multiplier, container, clusterInfo, subtreeRoot, windowInfo);
 
     Vector<Vector<TextAutosizingClusterInfo> > narrowDescendantsGroups;
@@ -176,11 +176,17 @@ void TextAutosizer::processCluster(TextAutosizingClusterInfo& clusterInfo, Rende
     // text), and use its width instead.
     clusterInfo.blockContainingAllText = findDeepestBlockContainingAllText(clusterInfo.root);
     float textWidth = clusterInfo.blockContainingAllText->contentLogicalWidth();
-    processClusterInternal(clusterInfo, container, subtreeRoot, windowInfo, textWidth, clusterShouldBeAutosized(clusterInfo, textWidth));
+    float multiplier =  1.0;
+    if (clusterShouldBeAutosized(clusterInfo, textWidth))
+        multiplier = clusterMultiplier(clusterInfo.root->style()->writingMode(), windowInfo, textWidth);
+    processClusterInternal(clusterInfo, container, subtreeRoot, windowInfo, multiplier);
 }
 
 void TextAutosizer::processCompositeCluster(Vector<TextAutosizingClusterInfo>& clusterInfos, const TextAutosizingWindowInfo& windowInfo)
 {
+    if (clusterInfos.isEmpty())
+        return;
+
     float maxTextWidth = 0;
     for (size_t i = 0; i < clusterInfos.size(); ++i) {
         TextAutosizingClusterInfo& clusterInfo = clusterInfos[i];
@@ -188,9 +194,13 @@ void TextAutosizer::processCompositeCluster(Vector<TextAutosizingClusterInfo>& c
         maxTextWidth = max<float>(maxTextWidth, clusterInfo.blockContainingAllText->contentLogicalWidth());
     }
 
-    bool shouldBeAutosized = compositeClusterShouldBeAutosized(clusterInfos, maxTextWidth);
-    for (size_t i = 0; i < clusterInfos.size(); ++i)
-        processClusterInternal(clusterInfos[i], clusterInfos[i].root, clusterInfos[i].root, windowInfo, maxTextWidth, shouldBeAutosized);
+    float multiplier = 1.0;
+    if (compositeClusterShouldBeAutosized(clusterInfos, maxTextWidth))
+        multiplier = clusterMultiplier(clusterInfos[0].root->style()->writingMode(), windowInfo, maxTextWidth);
+    for (size_t i = 0; i < clusterInfos.size(); ++i) {
+        ASSERT(clusterInfos[i].root->style()->writingMode() == clusterInfos[0].root->style()->writingMode());
+        processClusterInternal(clusterInfos[i], clusterInfos[i].root, clusterInfos[i].root, windowInfo, multiplier);
+    }
 }
 
 void TextAutosizer::processContainer(float multiplier, RenderBlock* container, TextAutosizingClusterInfo& clusterInfo, RenderObject* subtreeRoot, const TextAutosizingWindowInfo& windowInfo)
index 1f7f7b7..f1f6753 100644 (file)
@@ -29,6 +29,7 @@
 #if ENABLE(TEXT_AUTOSIZING)
 
 #include "HTMLNames.h"
+#include "WritingMode.h"
 #include <wtf/Noncopyable.h>
 #include <wtf/PassOwnPtr.h>
 
@@ -62,7 +63,9 @@ private:
 
     explicit TextAutosizer(Document*);
 
-    void processClusterInternal(TextAutosizingClusterInfo&, RenderBlock* container, RenderObject* subtreeRoot, const TextAutosizingWindowInfo&, float textWidth, bool shouldBeAutosized);
+    float clusterMultiplier(WritingMode, const TextAutosizingWindowInfo&, float textWidth) const;
+
+    void processClusterInternal(TextAutosizingClusterInfo&, RenderBlock* container, RenderObject* subtreeRoot, const TextAutosizingWindowInfo&, float multiplier);
     void processCluster(TextAutosizingClusterInfo&, RenderBlock* container, RenderObject* subtreeRoot, const TextAutosizingWindowInfo&);
     void processCompositeCluster(Vector<TextAutosizingClusterInfo>&, const TextAutosizingWindowInfo&);
     void processContainer(float multiplier, RenderBlock* container, TextAutosizingClusterInfo&, RenderObject* subtreeRoot, const TextAutosizingWindowInfo&);