- Revision
- 143318
- Author
- [email protected]
- Date
- 2013-02-19 04:45:26 -0800 (Tue, 19 Feb 2013)
Log Message
[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 <[email protected]> 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 <[email protected]> on 2013-02-19
Reviewed by Kenneth Rohde Christiansen.
* fast/text-autosizing/narrow-descendants-combined-expected.html:
* fast/text-autosizing/narrow-descendants-combined.html:
Modified Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (143317 => 143318)
--- trunk/LayoutTests/ChangeLog 2013-02-19 12:21:12 UTC (rev 143317)
+++ trunk/LayoutTests/ChangeLog 2013-02-19 12:45:26 UTC (rev 143318)
@@ -1,3 +1,17 @@
+2013-02-19 Anton Vayvod <[email protected]>
+
+ [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
+
+ 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|.
+
+ Reviewed by Kenneth Rohde Christiansen.
+
+ * fast/text-autosizing/narrow-descendants-combined-expected.html:
+ * fast/text-autosizing/narrow-descendants-combined.html:
+
2013-02-19 Takashi Toyoshima <[email protected]>
Unreviewed, gardening for chromium.
Modified: trunk/LayoutTests/fast/text-autosizing/narrow-descendants-combined-expected.html (143317 => 143318)
--- trunk/LayoutTests/fast/text-autosizing/narrow-descendants-combined-expected.html 2013-02-19 12:21:12 UTC (rev 143317)
+++ trunk/LayoutTests/fast/text-autosizing/narrow-descendants-combined-expected.html 2013-02-19 12:45:26 UTC (rev 143318)
@@ -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: trunk/LayoutTests/fast/text-autosizing/narrow-descendants-combined.html (143317 => 143318)
--- trunk/LayoutTests/fast/text-autosizing/narrow-descendants-combined.html 2013-02-19 12:21:12 UTC (rev 143317)
+++ trunk/LayoutTests/fast/text-autosizing/narrow-descendants-combined.html 2013-02-19 12:45:26 UTC (rev 143318)
@@ -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: trunk/Source/WebCore/ChangeLog (143317 => 143318)
--- trunk/Source/WebCore/ChangeLog 2013-02-19 12:21:12 UTC (rev 143317)
+++ trunk/Source/WebCore/ChangeLog 2013-02-19 12:45:26 UTC (rev 143318)
@@ -1,3 +1,36 @@
+2013-02-19 Anton Vayvod <[email protected]>
+
+ [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
+
+ 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.
+
+ 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.
+
2013-02-18 Ilya Tikhonovsky <[email protected]>
Web Inspector: Native Memory Instrumentation: show user provided name property of the heap snapshot node.
Modified: trunk/Source/WebCore/rendering/TextAutosizer.cpp (143317 => 143318)
--- trunk/Source/WebCore/rendering/TextAutosizer.cpp 2013-02-19 12:21:12 UTC (rev 143317)
+++ trunk/Source/WebCore/rendering/TextAutosizer.cpp 2013-02-19 12:45:26 UTC (rev 143318)
@@ -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: trunk/Source/WebCore/rendering/TextAutosizer.h (143317 => 143318)
--- trunk/Source/WebCore/rendering/TextAutosizer.h 2013-02-19 12:21:12 UTC (rev 143317)
+++ trunk/Source/WebCore/rendering/TextAutosizer.h 2013-02-19 12:45:26 UTC (rev 143318)
@@ -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;
};