Title: [141901] trunk
Revision
141901
Author
[email protected]
Date
2013-02-05 10:36:33 -0800 (Tue, 05 Feb 2013)

Log Message

TextAutosizing: adjust the maximum difference between cluster text width and its descendant
width.
https://bugs.webkit.org/show_bug.cgi?id=108411

Source/WebCore:

Currently, if a render object is more than 200 CSS units shorter than its parent cluster, it
becomes a separate autosizing cluster (see https://bugs.webkit.org/show_bug.cgi?id=105188).
This doesn't work well for layouts when narrow nodes are related, like nested comments:
deeper comments are all shorter than the parent cluster and become autosized differently. To
avoid that the difference that makes a shorter descendant a new autosizing cluster is
adjusted each time the width difference is not greater than 50 CSS units from the previous
one. This allows nested comments, for example, to remain a part of the parent cluster and be
autosized with the same multiplier.

Patch by Anton Vayvod <[email protected]> on 2013-02-05
Reviewed by Kenneth Rohde Christiansen.

Tests:
        fast/text-autosizing/nested-child.html

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

    Added a new field to store the current maximum width difference for the cluster.

(WebCore::TextAutosizer::isAutosizingCluster):

    Uses the new field to determine if the current node is a separate cluster,
    updates the maximum allowed width difference between the cluster and its descendant.

(WebCore::TextAutosizer::processContainer):
(WebCore::TextAutosizer::clusterShouldBeAutosized):
(WebCore::TextAutosizer::measureDescendantTextWidth):

    Non-const reference passed to the methods above.

* rendering/TextAutosizer.h: updated method parameters.

LayoutTests:

Patch by Anton Vayvod <[email protected]> on 2013-02-05
Reviewed by Kenneth Rohde Christiansen.

Tests that certain width difference doesn't make descendants separate clusters.

* fast/text-autosizing/nested-child-expected.html: Added.
* fast/text-autosizing/nested-child.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (141900 => 141901)


--- trunk/LayoutTests/ChangeLog	2013-02-05 18:30:44 UTC (rev 141900)
+++ trunk/LayoutTests/ChangeLog	2013-02-05 18:36:33 UTC (rev 141901)
@@ -1,3 +1,16 @@
+2013-02-05  Anton Vayvod  <[email protected]>
+
+        TextAutosizing: adjust the maximum difference between cluster text width and its descendant
+        width.
+        https://bugs.webkit.org/show_bug.cgi?id=108411
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        Tests that certain width difference doesn't make descendants separate clusters.
+
+        * fast/text-autosizing/nested-child-expected.html: Added.
+        * fast/text-autosizing/nested-child.html: Added.
+
 2013-02-05  Ádám Kallai  <[email protected]>
 
         [Qt] Unreviewed gardening. Skip failing test.

Added: trunk/LayoutTests/fast/text-autosizing/nested-child-expected.html (0 => 141901)


--- trunk/LayoutTests/fast/text-autosizing/nested-child-expected.html	                        (rev 0)
+++ trunk/LayoutTests/fast/text-autosizing/nested-child-expected.html	2013-02-05 18:36:33 UTC (rev 141901)
@@ -0,0 +1,28 @@
+<!DOCTYPE html>
+<html>
+<head>
+
+<meta name="viewport" content="width=800">
+<style>
+html { font-size: 16px; }
+body { width: 800px; margin: 0; overflow-y: hidden; }
+</style>
+
+</head>
+<body>
+
+<div style="font-size: 2.5rem">
+    <div style="width: 600px">
+        This text should be autosized to 40px computed font-size as it is a part of the same cluster as the parent div.<br>
+        Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
+    </div>
+    <div style="width: 550px">
+        This text should be autosized to 40px computed font-size, since it's only 50px narrower than the previous child and therefore remains the part of the same cluster.
+    </div>
+    <div style="width: 320px; font-size: 1rem">
+        This text is not autosized since it's too narrow and is considered to be a separate autosizing cluster.
+    </div>
+</div>
+
+</body>
+</html>

Added: trunk/LayoutTests/fast/text-autosizing/nested-child.html (0 => 141901)


--- trunk/LayoutTests/fast/text-autosizing/nested-child.html	                        (rev 0)
+++ trunk/LayoutTests/fast/text-autosizing/nested-child.html	2013-02-05 18:36:33 UTC (rev 141901)
@@ -0,0 +1,37 @@
+<!DOCTYPE html>
+<html>
+<head>
+
+<meta name="viewport" content="width=800">
+<style>
+html { font-size: 16px; }
+body { width: 800px; margin: 0; overflow-y: hidden; }
+</style>
+
+<script>
+if (window.internals) {
+    window.internals.settings.setTextAutosizingEnabled(true);
+    window.internals.settings.setTextAutosizingWindowSizeOverride(320, 480);
+} else if (window.console && console.warn) {
+    console.warn("This test depends on the Text Autosizing setting being true, so run it in DumpRenderTree, or manually enable Text Autosizing, and either use a mobile device with 320px device-width (like Nexus S or iPhone), or define HACK_FORCE_TEXT_AUTOSIZING_ON_DESKTOP.");
+}
+</script>
+
+</head>
+<body>
+
+<div>
+    <div style="width: 600px">
+        This text should be autosized to 40px computed font-size as it is a part of the same cluster as the parent div.<br>
+        Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
+    </div>
+    <div style="width: 550px">
+        This text should be autosized to 40px computed font-size, since it's only 50px narrower than the previous child and therefore remains the part of the same cluster.
+    </div>
+    <div style="width: 320px">
+        This text is not autosized since it's too narrow and is considered to be a separate autosizing cluster.
+    </div>
+</div>
+
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (141900 => 141901)


--- trunk/Source/WebCore/ChangeLog	2013-02-05 18:30:44 UTC (rev 141900)
+++ trunk/Source/WebCore/ChangeLog	2013-02-05 18:36:33 UTC (rev 141901)
@@ -1,3 +1,41 @@
+2013-02-05  Anton Vayvod  <[email protected]>
+
+        TextAutosizing: adjust the maximum difference between cluster text width and its descendant
+        width.
+        https://bugs.webkit.org/show_bug.cgi?id=108411
+
+        Currently, if a render object is more than 200 CSS units shorter than its parent cluster, it
+        becomes a separate autosizing cluster (see https://bugs.webkit.org/show_bug.cgi?id=105188).
+        This doesn't work well for layouts when narrow nodes are related, like nested comments:
+        deeper comments are all shorter than the parent cluster and become autosized differently. To
+        avoid that the difference that makes a shorter descendant a new autosizing cluster is
+        adjusted each time the width difference is not greater than 50 CSS units from the previous
+        one. This allows nested comments, for example, to remain a part of the parent cluster and be
+        autosized with the same multiplier.
+        
+        Reviewed by Kenneth Rohde Christiansen.
+
+        Tests:
+                fast/text-autosizing/nested-child.html
+
+        * rendering/TextAutosizer.cpp:
+        (WebCore::TextAutosizingClusterInfo::TextAutosizingClusterInfo):
+
+            Added a new field to store the current maximum width difference for the cluster.
+
+        (WebCore::TextAutosizer::isAutosizingCluster):
+
+            Uses the new field to determine if the current node is a separate cluster,
+            updates the maximum allowed width difference between the cluster and its descendant.
+
+        (WebCore::TextAutosizer::processContainer):
+        (WebCore::TextAutosizer::clusterShouldBeAutosized):
+        (WebCore::TextAutosizer::measureDescendantTextWidth):
+
+            Non-const reference passed to the methods above.
+
+        * rendering/TextAutosizer.h: updated method parameters.
+
 2013-02-05  Tony Gentilcore  <[email protected]>
 
         Continue making XSSAuditor thread safe: Remove dependency on parser's sourceForToken and TextResourceDecoder

Modified: trunk/Source/WebCore/rendering/TextAutosizer.cpp (141900 => 141901)


--- trunk/Source/WebCore/rendering/TextAutosizer.cpp	2013-02-05 18:30:44 UTC (rev 141900)
+++ trunk/Source/WebCore/rendering/TextAutosizer.cpp	2013-02-05 18:36:33 UTC (rev 141901)
@@ -51,11 +51,16 @@
     explicit TextAutosizingClusterInfo(RenderBlock* root)
         : root(root)
         , blockContainingAllText(0)
+        , maxAllowedDifferenceFromTextWidth(150)
     {
     }
 
     RenderBlock* root;
     const RenderBlock* blockContainingAllText;
+
+    // Upper limit on the difference between the width of the cluster's block containing all
+    // text and that of a narrow child before the child becomes a separate cluster.
+    float maxAllowedDifferenceFromTextWidth;
 };
 
 
@@ -147,7 +152,7 @@
     processContainer(multiplier, container, clusterInfo, subtreeRoot, windowInfo);
 }
 
-void TextAutosizer::processContainer(float multiplier, RenderBlock* container, const TextAutosizingClusterInfo* clusterInfo, RenderObject* subtreeRoot, const TextAutosizingWindowInfo& windowInfo)
+void TextAutosizer::processContainer(float multiplier, RenderBlock* container, TextAutosizingClusterInfo* clusterInfo, RenderObject* subtreeRoot, const TextAutosizingWindowInfo& windowInfo)
 {
     ASSERT(isAutosizingContainer(container));
 
@@ -230,7 +235,7 @@
     return true;
 }
 
-bool TextAutosizer::isAutosizingCluster(const RenderBlock* renderer, const TextAutosizingClusterInfo* parentClusterInfo)
+bool TextAutosizer::isAutosizingCluster(const RenderBlock* renderer, TextAutosizingClusterInfo* parentClusterInfo)
 {
     // "Autosizing clusters" are special autosizing containers within which we
     // want to enforce a uniform text size multiplier, in the hopes of making
@@ -256,15 +261,21 @@
     // since they need special treatment due to their width.
     ASSERT(isAutosizingContainer(renderer));
 
-    // Upper limit on the difference between the width of the parent block containing all
-    // text and that of a narrow child before the child becomes a cluster.
-    const float maxWidthDifference = 200;
-
     if (parentClusterInfo->blockContainingAllText) {
         float contentWidth = renderer->contentLogicalWidth();
         float clusterTextWidth = parentClusterInfo->blockContainingAllText->contentLogicalWidth();
-        if (contentWidth > clusterTextWidth || (clusterTextWidth - contentWidth) > maxWidthDifference)
+        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()
@@ -378,7 +389,7 @@
     return false;
 }
 
-bool TextAutosizer::clusterShouldBeAutosized(const TextAutosizingClusterInfo* clusterInfo, float blockWidth)
+bool TextAutosizer::clusterShouldBeAutosized(TextAutosizingClusterInfo* clusterInfo, float blockWidth)
 {
     // Don't autosize clusters that contain less than 4 lines of text (in
     // practice less lines are required, since measureDescendantTextWidth
@@ -399,7 +410,7 @@
     return false;
 }
 
-void TextAutosizer::measureDescendantTextWidth(const RenderBlock* container, const TextAutosizingClusterInfo* clusterInfo, float minTextWidth, float& textWidth)
+void TextAutosizer::measureDescendantTextWidth(const RenderBlock* container, TextAutosizingClusterInfo* clusterInfo, float minTextWidth, float& textWidth)
 {
     bool skipLocalText = !containerShouldBeAutosized(container);
 

Modified: trunk/Source/WebCore/rendering/TextAutosizer.h (141900 => 141901)


--- trunk/Source/WebCore/rendering/TextAutosizer.h	2013-02-05 18:30:44 UTC (rev 141900)
+++ trunk/Source/WebCore/rendering/TextAutosizer.h	2013-02-05 18:36:33 UTC (rev 141901)
@@ -62,20 +62,20 @@
     explicit TextAutosizer(Document*);
 
     void processCluster(TextAutosizingClusterInfo*, RenderBlock* container, RenderObject* subtreeRoot, const TextAutosizingWindowInfo&);
-    void processContainer(float multiplier, RenderBlock* container, const TextAutosizingClusterInfo*, RenderObject* subtreeRoot, const TextAutosizingWindowInfo&);
+    void processContainer(float multiplier, RenderBlock* container, TextAutosizingClusterInfo*, RenderObject* subtreeRoot, const TextAutosizingWindowInfo&);
 
     void setMultiplier(RenderObject*, float);
 
     static bool isAutosizingContainer(const RenderObject*);
-    static bool isAutosizingCluster(const RenderBlock*, const TextAutosizingClusterInfo* parentClusterInfo);
+    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);
     static bool containerIsRowOfLinks(const RenderObject* container);
     static bool contentHeightIsConstrained(const RenderBlock* container);
-    static bool clusterShouldBeAutosized(const TextAutosizingClusterInfo*, float blockWidth);
-    static void measureDescendantTextWidth(const RenderBlock* container, const TextAutosizingClusterInfo*, float minTextWidth, float& textWidth);
+    static bool clusterShouldBeAutosized(TextAutosizingClusterInfo*, float blockWidth);
+    static void measureDescendantTextWidth(const RenderBlock* container, TextAutosizingClusterInfo*, float minTextWidth, float& textWidth);
 
     // Use to traverse the tree of descendants, excluding descendants of containers (but returning the containers themselves).
     static RenderObject* nextInPreOrderSkippingDescendantsOfContainers(const RenderObject*, const RenderObject* stayWithin);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to