Title: [143932] branches/chromium/1410
Revision
143932
Author
pe...@chromium.org
Date
2013-02-25 08:56:39 -0800 (Mon, 25 Feb 2013)

Log Message

Merge 143318
> [Text Autosizing] Combine narrow descendants of a cluster into groups that should be autosized with the same multiplier.
> https://bugs.webkit.org/show_bug.cgi?id=109825
> 
> Source/WebCore:
> 
> Enhancement of the approach introduced in https://bugs.webkit.org/show_bug.cgi?id=109573.
> Instead of using the same text size multiplier for all narrow descendants of any autosizing
> cluster, group the descendants by how much narrower they are than the cluster's
> |blockContainingAllText| and process each group separately with a different multiplier for
> each one.
> For example, we want nested comments on the page to be autosized as a group but separately
> from a sidebar on the same page.
> 
> Patch by Anton Vayvod <avay...@chromium.org> on 2013-02-19
> Reviewed by Kenneth Rohde Christiansen.
> 
> Updated the existing test to verify the patch.
> 
> * rendering/TextAutosizer.cpp:
> (WebCore::TextAutosizer::processClusterInternal):
> 
>     Splits the narrow descendants of the autosizing cluster into groups before processing
>     each group individually.
> 
> (WebCore::TextAutosizer::getNarrowDescendantsGroupedByWidth):
> 
>     Sorts the narrow descendants of the given cluster into groups, combining them by the
>     difference between their content widths. If sorted by width, two consecutive nodes
>     belong to the same group if their width difference is no greater than 100 CSS units.
> 
> * rendering/TextAutosizer.h:
> 
>     New method definitions.
> 
> LayoutTests:
> 
> Verify that narrow descendants are grouped and autosized separately according to the
> difference between the descendant's width and the width of its enclosing cluster's
> |blockContainingAllText|.
> 
> Patch by Anton Vayvod <avay...@chromium.org> on 2013-02-19
> Reviewed by Kenneth Rohde Christiansen.
> 
> * fast/text-autosizing/narrow-descendants-combined-expected.html:
> * fast/text-autosizing/narrow-descendants-combined.html:

TBR=commit-qu...@webkit.org
Review URL: https://codereview.chromium.org/12317102

Modified Paths

Diff

Modified: branches/chromium/1410/LayoutTests/fast/text-autosizing/narrow-descendants-combined-expected.html (143931 => 143932)


--- branches/chromium/1410/LayoutTests/fast/text-autosizing/narrow-descendants-combined-expected.html	2013-02-25 16:56:14 UTC (rev 143931)
+++ branches/chromium/1410/LayoutTests/fast/text-autosizing/narrow-descendants-combined-expected.html	2013-02-25 16:56:39 UTC (rev 143932)
@@ -12,15 +12,20 @@
 <body>
 
 <div style="font-size: 1.25rem">
+    <div style="width: 240px">
+        This text should be autosized to 20px computed font-size as it is combined with the next and the last narrow siblings and the maximum width is 400px.
+    </div>
     <div style="width: 320px">
-        This text should be autosized to 20px computed font-size as it is combined with its narrow siblings and the maximum width is 400px.
+        This text should be autosized to 20px computed font-size as it is combined with the first and the last narrow siblings and the maximum width is 400px.
     </div>
+    <div style="width: 560px; font-size: 1.75rem">
+        This text should be autosized to 28px computed font-size as it is combined into a separate group from its two siblings since it's significantly wider.<br>
+        Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
+    </div>
     <div style="width: 400px">
-        This text should be autosized to 20px computed font-size as it is combined with its narrow siblings and the maximum width is 400px.
+        This text should be autosized to 20px computed font-size as it is combined with the first and the second narrow siblings and the maximum width is 400px.<br>
+        Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
     </div>
-    <div style="width: 240px">
-        This text should be autosized to 20px computed font-size as it is combined with its narrow siblings and the maximum width is 400px.
-    </div>
 </div>
 
 </body>

Modified: branches/chromium/1410/LayoutTests/fast/text-autosizing/narrow-descendants-combined.html (143931 => 143932)


--- branches/chromium/1410/LayoutTests/fast/text-autosizing/narrow-descendants-combined.html	2013-02-25 16:56:14 UTC (rev 143931)
+++ branches/chromium/1410/LayoutTests/fast/text-autosizing/narrow-descendants-combined.html	2013-02-25 16:56:39 UTC (rev 143932)
@@ -21,15 +21,20 @@
 <body>
 
 <div>
+    <div style="width: 240px">
+        This text should be autosized to 20px computed font-size as it is combined with the next and the last narrow siblings and the maximum width is 400px.
+    </div>
     <div style="width: 320px">
-        This text should be autosized to 20px computed font-size as it is combined with its narrow siblings and the maximum width is 400px.
+        This text should be autosized to 20px computed font-size as it is combined with the first and the last narrow siblings and the maximum width is 400px.
     </div>
+    <div style="width: 560px">
+        This text should be autosized to 28px computed font-size as it is combined into a separate group from its two siblings since it's significantly wider.<br>
+        Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
+    </div>
     <div style="width: 400px">
-        This text should be autosized to 20px computed font-size as it is combined with its narrow siblings and the maximum width is 400px.
+        This text should be autosized to 20px computed font-size as it is combined with the first and the second narrow siblings and the maximum width is 400px.<br>
+        Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
     </div>
-    <div style="width: 240px">
-        This text should be autosized to 20px computed font-size as it is combined with its narrow siblings and the maximum width is 400px.
-    </div>
 </div>
 
 </body>

Modified: branches/chromium/1410/Source/WebCore/rendering/TextAutosizer.cpp (143931 => 143932)


--- branches/chromium/1410/Source/WebCore/rendering/TextAutosizer.cpp	2013-02-25 16:56:14 UTC (rev 143931)
+++ branches/chromium/1410/Source/WebCore/rendering/TextAutosizer.cpp	2013-02-25 16:56:39 UTC (rev 143932)
@@ -149,7 +149,10 @@
 
     processContainer(multiplier, container, clusterInfo, subtreeRoot, windowInfo);
 
-    processCompositeCluster(clusterInfo.narrowDescendants, windowInfo);
+    Vector<Vector<TextAutosizingClusterInfo> > narrowDescendantsGroups;
+    getNarrowDescendantsGroupedByWidth(clusterInfo, narrowDescendantsGroups);
+    for (size_t i = 0; i < narrowDescendantsGroups.size(); ++i)
+        processCompositeCluster(narrowDescendantsGroups[i], windowInfo);
 }
 
 void TextAutosizer::processCluster(TextAutosizingClusterInfo& clusterInfo, RenderBlock* container, RenderObject* subtreeRoot, const TextAutosizingWindowInfo& windowInfo)
@@ -556,6 +559,43 @@
     return 0;
 }
 
+namespace {
+
+// Compares the width of the specified cluster's roots in descending order.
+bool clusterWiderThanComparisonFn(const TextAutosizingClusterInfo& first, const TextAutosizingClusterInfo& second)
+{
+    return first.root->contentLogicalWidth() > second.root->contentLogicalWidth();
+}
+
+} // namespace
+
+void TextAutosizer::getNarrowDescendantsGroupedByWidth(const TextAutosizingClusterInfo& parentClusterInfo, Vector<Vector<TextAutosizingClusterInfo> >& groups)
+{
+    ASSERT(parentClusterInfo.blockContainingAllText);
+    ASSERT(groups.isEmpty());
+
+    Vector<TextAutosizingClusterInfo> clusterInfos(parentClusterInfo.narrowDescendants);
+    if (clusterInfos.isEmpty())
+        return;
+
+    std::sort(clusterInfos.begin(), clusterInfos.end(), &clusterWiderThanComparisonFn);
+    groups.grow(1);
+
+    // If the width difference between two consecutive elements of |clusterInfos| is greater than
+    // this empirically determined value, the next element should start a new group.
+    const float maxWidthDifferenceWithinGroup = 100;
+    for (size_t i = 0; i < clusterInfos.size(); ++i) {
+        groups.last().append(clusterInfos[i]);
+
+        if (i + 1 < clusterInfos.size()) {
+            float currentWidth = clusterInfos[i].root->contentLogicalWidth();
+            float nextWidth = clusterInfos[i + 1].root->contentLogicalWidth();
+            if (currentWidth - nextWidth > maxWidthDifferenceWithinGroup)
+                groups.grow(groups.size() + 1);
+        }
+    }
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(TEXT_AUTOSIZING)

Modified: branches/chromium/1410/Source/WebCore/rendering/TextAutosizer.h (143931 => 143932)


--- branches/chromium/1410/Source/WebCore/rendering/TextAutosizer.h	2013-02-25 16:56:14 UTC (rev 143931)
+++ branches/chromium/1410/Source/WebCore/rendering/TextAutosizer.h	2013-02-25 16:56:39 UTC (rev 143932)
@@ -91,6 +91,11 @@
     // belong to any cluster.
     static const RenderObject* findFirstTextLeafNotInCluster(const RenderObject*, size_t& depth, TraversalDirection);
 
+    // Returns groups of narrow descendants of a given autosizing cluster. The groups are combined
+    // by the difference between the width of the descendant and the width of the parent cluster's
+    // |blockContainingAllText|.
+    static void getNarrowDescendantsGroupedByWidth(const TextAutosizingClusterInfo& parentClusterInfo, Vector<Vector<TextAutosizingClusterInfo> >&);
+
     Document* m_document;
 };
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to