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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « Source/WebCore/rendering/TextAutosizer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * Copyright (C) 2012 Apple Inc. All rights reserved. 3 * Copyright (C) 2012 Apple Inc. All rights reserved.
4 * 4 *
5 * This library is free software; you can redistribute it and/or 5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public 6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either 7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version. 8 * version 2 of the License, or (at your option) any later version.
9 * 9 *
10 * This library is distributed in the hope that it will be useful, 10 * This library is distributed in the hope that it will be useful,
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 // Ignore box width in excess of the layout width, to avoid extreme mult ipliers. 142 // Ignore box width in excess of the layout width, to avoid extreme mult ipliers.
143 float logicalClusterWidth = std::min<float>(textWidth, logicalLayoutWidt h); 143 float logicalClusterWidth = std::min<float>(textWidth, logicalLayoutWidt h);
144 144
145 multiplier = logicalClusterWidth / logicalWindowWidth; 145 multiplier = logicalClusterWidth / logicalWindowWidth;
146 multiplier *= m_document->settings()->textAutosizingFontScaleFactor(); 146 multiplier *= m_document->settings()->textAutosizingFontScaleFactor();
147 multiplier = std::max(1.0f, multiplier); 147 multiplier = std::max(1.0f, multiplier);
148 } 148 }
149 149
150 processContainer(multiplier, container, clusterInfo, subtreeRoot, windowInfo ); 150 processContainer(multiplier, container, clusterInfo, subtreeRoot, windowInfo );
151 151
152 processCompositeCluster(clusterInfo.narrowDescendants, windowInfo); 152 Vector<Vector<TextAutosizingClusterInfo> > narrowDescendantsGroups;
153 getNarrowDescendantsGroupedByWidth(clusterInfo, narrowDescendantsGroups);
154 for (size_t i = 0; i < narrowDescendantsGroups.size(); ++i)
155 processCompositeCluster(narrowDescendantsGroups[i], windowInfo);
153 } 156 }
154 157
155 void TextAutosizer::processCluster(TextAutosizingClusterInfo& clusterInfo, Rende rBlock* container, RenderObject* subtreeRoot, const TextAutosizingWindowInfo& wi ndowInfo) 158 void TextAutosizer::processCluster(TextAutosizingClusterInfo& clusterInfo, Rende rBlock* container, RenderObject* subtreeRoot, const TextAutosizingWindowInfo& wi ndowInfo)
156 { 159 {
157 // Many pages set a max-width on their content. So especially for the Render View, instead of 160 // Many pages set a max-width on their content. So especially for the Render View, instead of
158 // just taking the width of |cluster| we find the lowest common ancestor of the first and last 161 // just taking the width of |cluster| we find the lowest common ancestor of the first and last
159 // descendant text node of the cluster (i.e. the deepest wrapper block that contains all the 162 // descendant text node of the cluster (i.e. the deepest wrapper block that contains all the
160 // text), and use its width instead. 163 // text), and use its width instead.
161 clusterInfo.blockContainingAllText = findDeepestBlockContainingAllText(clust erInfo.root); 164 clusterInfo.blockContainingAllText = findDeepestBlockContainingAllText(clust erInfo.root);
162 float textWidth = clusterInfo.blockContainingAllText->contentLogicalWidth(); 165 float textWidth = clusterInfo.blockContainingAllText->contentLogicalWidth();
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 if (leaf) 552 if (leaf)
550 return leaf; 553 return leaf;
551 } 554 }
552 child = (direction == FirstToLast) ? child->nextSibling() : child->previ ousSibling(); 555 child = (direction == FirstToLast) ? child->nextSibling() : child->previ ousSibling();
553 } 556 }
554 --depth; 557 --depth;
555 558
556 return 0; 559 return 0;
557 } 560 }
558 561
562 namespace {
563
564 // Compares the width of the specified cluster's roots in descending order.
565 bool clusterWiderThanComparisonFn(const TextAutosizingClusterInfo& first, const TextAutosizingClusterInfo& second)
566 {
567 return first.root->contentLogicalWidth() > second.root->contentLogicalWidth( );
568 }
569
570 } // namespace
571
572 void TextAutosizer::getNarrowDescendantsGroupedByWidth(const TextAutosizingClust erInfo& parentClusterInfo, Vector<Vector<TextAutosizingClusterInfo> >& groups)
573 {
574 ASSERT(parentClusterInfo.blockContainingAllText);
575 ASSERT(groups.isEmpty());
576
577 Vector<TextAutosizingClusterInfo> clusterInfos(parentClusterInfo.narrowDesce ndants);
578 if (clusterInfos.isEmpty())
579 return;
580
581 std::sort(clusterInfos.begin(), clusterInfos.end(), &clusterWiderThanCompari sonFn);
582 groups.grow(1);
583
584 // If the width difference between two consecutive elements of |clusterInfos | is greater than
585 // this empirically determined value, the next element should start a new gr oup.
586 const float maxWidthDifferenceWithinGroup = 100;
587 for (size_t i = 0; i < clusterInfos.size(); ++i) {
588 groups.last().append(clusterInfos[i]);
589
590 if (i + 1 < clusterInfos.size()) {
591 float currentWidth = clusterInfos[i].root->contentLogicalWidth();
592 float nextWidth = clusterInfos[i + 1].root->contentLogicalWidth();
593 if (currentWidth - nextWidth > maxWidthDifferenceWithinGroup)
594 groups.grow(groups.size() + 1);
595 }
596 }
597 }
598
559 } // namespace WebCore 599 } // namespace WebCore
560 600
561 #endif // ENABLE(TEXT_AUTOSIZING) 601 #endif // ENABLE(TEXT_AUTOSIZING)
OLDNEW
« 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