Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(289)

Unified Diff: Source/WebCore/rendering/TextAutosizer.cpp

Issue 12317102: Merge 143318 (Closed) Base URL: http://svn.webkit.org/repository/webkit/branches/chromium/1410/
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/WebCore/rendering/TextAutosizer.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/WebCore/rendering/TextAutosizer.cpp
===================================================================
--- Source/WebCore/rendering/TextAutosizer.cpp (revision 143930)
+++ Source/WebCore/rendering/TextAutosizer.cpp (working copy)
@@ -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)
« no previous file with comments | « Source/WebCore/rendering/TextAutosizer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698