Title: [143749] trunk/Source/WebCore
Revision
143749
Author
[email protected]
Date
2013-02-22 10:20:19 -0800 (Fri, 22 Feb 2013)

Log Message

[TextAutosizing] Refactoring to eliminate boolean parameter.
https://bugs.webkit.org/show_bug.cgi?id=110490

Patch by Anton Vayvod <[email protected]> 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.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (143748 => 143749)


--- trunk/Source/WebCore/ChangeLog	2013-02-22 18:13:31 UTC (rev 143748)
+++ trunk/Source/WebCore/ChangeLog	2013-02-22 18:20:19 UTC (rev 143749)
@@ -1,3 +1,35 @@
+2013-02-22  Anton Vayvod  <[email protected]>
+
+        [TextAutosizing] Refactoring to eliminate boolean parameter.
+        https://bugs.webkit.org/show_bug.cgi?id=110490
+
+        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.
+
 2013-02-22  Carlos Garcia Campos  <[email protected]>
 
         [BlackBerry] Use KURL::protocolIsInHTTPFamily instead of KURL::protocolInHTTPFamily

Modified: trunk/Source/WebCore/rendering/TextAutosizer.cpp (143748 => 143749)


--- trunk/Source/WebCore/rendering/TextAutosizer.cpp	2013-02-22 18:13:31 UTC (rev 143748)
+++ trunk/Source/WebCore/rendering/TextAutosizer.cpp	2013-02-22 18:20:19 UTC (rev 143749)
@@ -141,20 +141,20 @@
     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);
+    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);
 
-        multiplier = logicalClusterWidth / logicalWindowWidth;
-        multiplier *= m_document->settings()->textAutosizingFontScaleFactor();
-        multiplier = std::max(1.0f, multiplier);
-    }
+    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;
@@ -171,11 +171,17 @@
     // 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];
@@ -183,9 +189,13 @@
         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)

Modified: trunk/Source/WebCore/rendering/TextAutosizer.h (143748 => 143749)


--- trunk/Source/WebCore/rendering/TextAutosizer.h	2013-02-22 18:13:31 UTC (rev 143748)
+++ trunk/Source/WebCore/rendering/TextAutosizer.h	2013-02-22 18:20:19 UTC (rev 143749)
@@ -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 @@
 
     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&);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to