[Text Autosizing] Split isAutosizingCluster into three independent checks
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 8 Feb 2013 16:40:52 +0000 (16:40 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 8 Feb 2013 16:40:52 +0000 (16:40 +0000)
https://bugs.webkit.org/show_bug.cgi?id=109093

Refactoring to create more flexible version of isAutosizingCluster since there're more types
of autosizing cluster now: narrower than the parent cluster, wider than the parent cluster
and the one that doesn't depend on the parent cluster.

Patch by Anton Vayvod <avayvod@chromium.org> on 2013-02-08
Reviewed by Kenneth Rohde Christiansen.

Refactoring, no test changes.

* rendering/TextAutosizer.cpp:

(WebCore::TextAutosizer::isNarrowDescendant):

    Separate check for the container to be of the narrow-descendant type. Was a part of
    isAutosizingCluster().

(WebCore::TextAutosizer::isWiderDescendant):

    Separate check for the container to be of the wider-descendant type. Was a part of
    isAutosizingCluster().

(WebCore::TextAutosizer::isIndependentDescendant):

    Separate check for the container to be autosized separately from the ancestor cluster.
    Checks for conditions independent of the aforementioned cluster.

(WebCore::TextAutosizer::isAutosizingCluster):

    Handy method to check all separate conditions together.

(WebCore::TextAutosizer::processSubtree):
(WebCore::TextAutosizer::processCluster):
(WebCore::TextAutosizer::processContainer):
(WebCore::TextAutosizer::clusterShouldBeAutosized):
(WebCore::TextAutosizer::measureDescendantTextWidth):
(WebCore::TextAutosizer::findFirstTextLeafNotInCluster):

    The methods above were updated to use new functions/arguments.

* rendering/TextAutosizer.h:

    Updated/added method definitions.

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

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

index 911a42d84528b8caa5a64570fa5741fcc6726280..769667167749fc160a9db52f1e6076ff0ea2ba37 100644 (file)
@@ -1,3 +1,50 @@
+2013-02-08  Anton Vayvod  <avayvod@chromium.org>
+
+        [Text Autosizing] Split isAutosizingCluster into three independent checks
+        https://bugs.webkit.org/show_bug.cgi?id=109093
+
+        Refactoring to create more flexible version of isAutosizingCluster since there're more types
+        of autosizing cluster now: narrower than the parent cluster, wider than the parent cluster
+        and the one that doesn't depend on the parent cluster.
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        Refactoring, no test changes.
+
+        * rendering/TextAutosizer.cpp:
+
+        (WebCore::TextAutosizer::isNarrowDescendant):
+
+            Separate check for the container to be of the narrow-descendant type. Was a part of
+            isAutosizingCluster().
+
+        (WebCore::TextAutosizer::isWiderDescendant):
+
+            Separate check for the container to be of the wider-descendant type. Was a part of
+            isAutosizingCluster().
+
+        (WebCore::TextAutosizer::isIndependentDescendant):
+
+            Separate check for the container to be autosized separately from the ancestor cluster.
+            Checks for conditions independent of the aforementioned cluster.
+
+        (WebCore::TextAutosizer::isAutosizingCluster):
+
+            Handy method to check all separate conditions together.
+
+        (WebCore::TextAutosizer::processSubtree):
+        (WebCore::TextAutosizer::processCluster):
+        (WebCore::TextAutosizer::processContainer):
+        (WebCore::TextAutosizer::clusterShouldBeAutosized):
+        (WebCore::TextAutosizer::measureDescendantTextWidth):
+        (WebCore::TextAutosizer::findFirstTextLeafNotInCluster):
+
+            The methods above were updated to use new functions/arguments.
+
+        * rendering/TextAutosizer.h:
+
+            Updated/added method definitions.
+
 2013-02-08  Vsevolod Vlasov  <vsevik@chromium.org>
 
         Web Inspector: Extension sever should use Workspace.projectForType() instead of Workspace.project()
index 91dba1cf5517b749d8e2179960635667f8dedd31..4dea1e3aa7713b3a4ff4df8703537662cc84a661 100644 (file)
@@ -119,7 +119,7 @@ bool TextAutosizer::processSubtree(RenderObject* layoutRoot)
         container = container->containingBlock();
 
     RenderBlock* cluster = container;
-    while (cluster && !isAutosizingCluster(cluster))
+    while (cluster && (!isAutosizingContainer(cluster) || !isIndependentDescendant(cluster)))
         cluster = cluster->containingBlock();
 
     TextAutosizingClusterInfo clusterInfo(cluster);
@@ -235,8 +235,48 @@ bool TextAutosizer::isAutosizingContainer(const RenderObject* renderer)
     return true;
 }
 
-bool TextAutosizer::isAutosizingCluster(const RenderBlock* renderer, TextAutosizingClusterInfo* parentClusterInfo)
+bool TextAutosizer::isNarrowDescendant(const RenderBlock* renderer, TextAutosizingClusterInfo* parentClusterInfo)
+{
+    ASSERT(isAutosizingContainer(renderer));
+
+    // Autosizing containers that are significantly narrower than the |blockContainingAllText| of
+    // their enclosing cluster may be acting as separate columns, hence must be autosized
+    // separately. For example the 2nd div in:
+    // <body>
+    //     <div style="float: right; width: 50%"></div>
+    //     <div style="width: 50%"></div>
+    // <body>
+    // is the left column, and should be autosized differently from the body.
+    // If however the container is only narrower by 150px or less, it's considered part of
+    // the enclosing cluster. This 150px limit is adjusted whenever a descendant container is
+    // less than 50px narrower than the current limit.
+    const float differenceFromMaxWidthDifference = 50;
+    float contentWidth = renderer->contentLogicalWidth();
+    float clusterTextWidth = parentClusterInfo->blockContainingAllText->contentLogicalWidth();
+    float widthDifference = clusterTextWidth - contentWidth;
+
+    if (widthDifference - parentClusterInfo->maxAllowedDifferenceFromTextWidth > differenceFromMaxWidthDifference)
+        return true;
+
+    parentClusterInfo->maxAllowedDifferenceFromTextWidth = std::max(widthDifference, parentClusterInfo->maxAllowedDifferenceFromTextWidth);
+    return false;
+}
+
+bool TextAutosizer::isWiderDescendant(const RenderBlock* renderer, const TextAutosizingClusterInfo* parentClusterInfo)
 {
+    ASSERT(isAutosizingContainer(renderer));
+
+    // Autosizing containers that are wider than the |blockContainingAllText| of their enclosing
+    // cluster are treated the same way as autosizing clusters to be autosized separately.
+    float contentWidth = renderer->contentLogicalWidth();
+    float clusterTextWidth = parentClusterInfo->blockContainingAllText->contentLogicalWidth();
+    return contentWidth > clusterTextWidth;
+}
+
+bool TextAutosizer::isIndependentDescendant(const RenderBlock* renderer)
+{
+    ASSERT(isAutosizingContainer(renderer));
+
     // "Autosizing clusters" are special autosizing containers within which we
     // want to enforce a uniform text size multiplier, in the hopes of making
     // the major sections of the page look internally consistent.
@@ -256,28 +296,6 @@ bool TextAutosizer::isAutosizingCluster(const RenderBlock* renderer, TextAutosiz
     // from the box's parent (we want to avoid having significantly different
     // width blocks within a cluster, since the narrower blocks would end up
     // larger than would otherwise be necessary).
-    // Additionally, any containers that are wider or at least 200px narrower than
-    // the |blockContainingAllText| of their enclosing cluster also become clusters,
-    // since they need special treatment due to their width.
-    ASSERT(isAutosizingContainer(renderer));
-
-    if (parentClusterInfo->blockContainingAllText) {
-        float contentWidth = renderer->contentLogicalWidth();
-        float clusterTextWidth = parentClusterInfo->blockContainingAllText->contentLogicalWidth();
-        if (contentWidth > clusterTextWidth)
-            return true;
-
-        // The upper limit on how many pixels the difference between the renderer width
-        // and its parent cluster width can exceed the current maximum difference by
-        // before the object is considered to be a separate autosizing cluster.
-        const float differenceFromMaxWidthDifference = 50;
-
-        float widthDifference = clusterTextWidth - contentWidth;
-        if (widthDifference - parentClusterInfo->maxAllowedDifferenceFromTextWidth > differenceFromMaxWidthDifference)
-            return true;
-        parentClusterInfo->maxAllowedDifferenceFromTextWidth = std::max(widthDifference, parentClusterInfo->maxAllowedDifferenceFromTextWidth);
-    }
-
     return renderer->isRenderView()
         || renderer->isFloating()
         || renderer->isOutOfFlowPositioned()
@@ -292,10 +310,13 @@ bool TextAutosizer::isAutosizingCluster(const RenderBlock* renderer, TextAutosiz
     // containers, and probably flexboxes...
 }
 
-bool TextAutosizer::isAutosizingCluster(const RenderObject* object)
+bool TextAutosizer::isAutosizingCluster(const RenderBlock* renderer, TextAutosizingClusterInfo* parentClusterInfo)
 {
-    TextAutosizingClusterInfo emptyClusterInfo(0);
-    return isAutosizingContainer(object) && isAutosizingCluster(toRenderBlock(object), &emptyClusterInfo);
+    ASSERT(isAutosizingContainer(renderer));
+
+    return isNarrowDescendant(renderer, parentClusterInfo)
+        || isWiderDescendant(renderer, parentClusterInfo)
+        || isIndependentDescendant(renderer);
 }
 
 bool TextAutosizer::containerShouldBeAutosized(const RenderBlock* container)
@@ -486,7 +507,7 @@ const RenderObject* TextAutosizer::findFirstTextLeafNotInCluster(const RenderObj
     ++depth;
     const RenderObject* child = (direction == FirstToLast) ? parent->firstChild() : parent->lastChild();
     while (child) {
-        if (!isAutosizingCluster(child)) {
+        if (!isAutosizingContainer(child) || !isIndependentDescendant(toRenderBlock(child))) {
             const RenderObject* leaf = findFirstTextLeafNotInCluster(child, depth, direction);
             if (leaf)
                 return leaf;
index 166e056d11bd3f7bd7e62be5e256dd2eb3b84d34..c52301e4ad49edb6e5e47c8bff36aa11dd604fd9 100644 (file)
@@ -67,8 +67,10 @@ private:
     void setMultiplier(RenderObject*, float);
 
     static bool isAutosizingContainer(const RenderObject*);
+    static bool isNarrowDescendant(const RenderBlock*, TextAutosizingClusterInfo* parentClusterInfo);
+    static bool isWiderDescendant(const RenderBlock*, const TextAutosizingClusterInfo* parentClusterInfo);
+    static bool isIndependentDescendant(const RenderBlock*);
     static bool isAutosizingCluster(const RenderBlock*, TextAutosizingClusterInfo* parentClusterInfo);
-    static bool isAutosizingCluster(const RenderObject*);
 
     static bool containerShouldBeAutosized(const RenderBlock* container);
     static bool containerContainsOneOfTags(const RenderBlock* cluster, const Vector<QualifiedName>& tags);