Title: [142287] trunk/Source/WebCore
Revision
142287
Author
[email protected]
Date
2013-02-08 08:40:52 -0800 (Fri, 08 Feb 2013)

Log Message

[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.

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

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (142286 => 142287)


--- trunk/Source/WebCore/ChangeLog	2013-02-08 16:27:26 UTC (rev 142286)
+++ trunk/Source/WebCore/ChangeLog	2013-02-08 16:40:52 UTC (rev 142287)
@@ -1,3 +1,50 @@
+2013-02-08  Anton Vayvod  <[email protected]>
+
+        [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  <[email protected]>
 
         Web Inspector: Extension sever should use Workspace.projectForType() instead of Workspace.project()

Modified: trunk/Source/WebCore/rendering/TextAutosizer.cpp (142286 => 142287)


--- trunk/Source/WebCore/rendering/TextAutosizer.cpp	2013-02-08 16:27:26 UTC (rev 142286)
+++ trunk/Source/WebCore/rendering/TextAutosizer.cpp	2013-02-08 16:40:52 UTC (rev 142287)
@@ -119,7 +119,7 @@
         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 @@
     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 @@
     // 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 @@
     // 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 @@
     ++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;

Modified: trunk/Source/WebCore/rendering/TextAutosizer.h (142286 => 142287)


--- trunk/Source/WebCore/rendering/TextAutosizer.h	2013-02-08 16:27:26 UTC (rev 142286)
+++ trunk/Source/WebCore/rendering/TextAutosizer.h	2013-02-08 16:40:52 UTC (rev 142287)
@@ -67,8 +67,10 @@
     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);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to