Changeset 142866 in webkit
- Timestamp:
- Feb 14, 2013 4:09:18 AM (11 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r142861 r142866 1 2013-02-14 Anton Vayvod <avayvod@chromium.org> 2 3 [Text Autosizing] Process narrow descendants with the same multiplier for the font size. 4 https://bugs.webkit.org/show_bug.cgi?id=109573 5 6 Test to verify that all narrow descendants of a cluster are autosized with the same 7 multiplier. 8 9 Reviewed by Julien Chaffraix. 10 11 * fast/text-autosizing/narrow-descendants-combined-expected.html: Added. 12 * fast/text-autosizing/narrow-descendants-combined.html: Added. 13 1 14 2013-02-14 Aivo Paas <aivopaas@gmail.com> 2 15 -
trunk/Source/WebCore/ChangeLog
r142865 r142866 1 2013-02-14 Anton Vayvod <avayvod@chromium.org> 2 3 [Text Autosizing] Process narrow descendants with the same multiplier for the font size. 4 https://bugs.webkit.org/show_bug.cgi?id=109573 5 6 Reviewed by Julien Chaffraix. 7 8 Combine narrow descendants of the same autosizing cluster into a group that is autosized 9 with the same multiplier. 10 11 For example, on sites with a sidebar, sometimes the paragraphs next to the sidebar will have 12 a large margin individually applied (via a CSS selector), causing them all to individually 13 appear narrower than their enclosing blockContainingAllText. Rather than making each of 14 these paragraphs into a separate cluster, we want them all to share the same multiplier, as 15 if they were a single cluster. 16 17 Test: fast/text-autosizing/narrow-descendants-combined.html 18 19 * rendering/TextAutosizer.cpp: 20 (WebCore::TextAutosizer::processClusterInternal): 21 22 Common implementation for processCluster() and processCompositeCluster that accepts the 23 text width and whether the cluster should be autosized as parameters instead of 24 calculating it inline. 25 26 (WebCore::TextAutosizer::processCluster): 27 28 Calculates the text width for a single cluster and whether it should be autosized, then 29 calls processClusterInternal() to apply the multiplier and process the cluster's 30 descendants. 31 32 (WebCore::TextAutosizer::processCompositeCluster): 33 34 Calculates the text width for a group of renderers and if the group should be autosized, 35 then calls processClusterInternal() repeatedly with the same multiplier to apply it and 36 process all the descendants of the group. 37 38 (WebCore::TextAutosizer::clusterShouldBeAutosized): 39 40 Calls the multiple renderers version to avoid code duplication. 41 42 (WebCore::TextAutosizer::compositeClusterShouldBeAutosized): 43 44 The multiple renderers version of clusterShouldBeAutosized. 45 46 * rendering/TextAutosizer.h: 47 48 Updated method declarations. 49 1 50 2013-02-14 Andrey Adaikin <aandrey@chromium.org> 2 51 -
trunk/Source/WebCore/rendering/TextAutosizer.cpp
r142534 r142866 134 134 } 135 135 136 void TextAutosizer::processCluster(TextAutosizingClusterInfo& clusterInfo, RenderBlock* container, RenderObject* subtreeRoot, const TextAutosizingWindowInfo& windowInfo) 137 { 138 // Many pages set a max-width on their content. So especially for the 139 // RenderView, instead of just taking the width of |cluster| we find 140 // the lowest common ancestor of the first and last descendant text node of 141 // the cluster (i.e. the deepest wrapper block that contains all the text), 142 // and use its width instead. 143 clusterInfo.blockContainingAllText = findDeepestBlockContainingAllText(clusterInfo.root); 144 float textWidth = clusterInfo.blockContainingAllText->contentLogicalWidth(); 145 136 void TextAutosizer::processClusterInternal(TextAutosizingClusterInfo& clusterInfo, RenderBlock* container, RenderObject* subtreeRoot, const TextAutosizingWindowInfo& windowInfo, float textWidth, bool shouldBeAutosized) 137 { 146 138 float multiplier = 1; 147 if ( clusterShouldBeAutosized(clusterInfo, textWidth)) {139 if (shouldBeAutosized) { 148 140 int logicalWindowWidth = clusterInfo.root->isHorizontalWritingMode() ? windowInfo.windowSize.width() : windowInfo.windowSize.height(); 149 141 int logicalLayoutWidth = clusterInfo.root->isHorizontalWritingMode() ? windowInfo.minLayoutSize.width() : windowInfo.minLayoutSize.height(); … … 158 150 processContainer(multiplier, container, clusterInfo, subtreeRoot, windowInfo); 159 151 160 Vector<TextAutosizingClusterInfo>& narrowDescendants = clusterInfo.narrowDescendants; 161 for (size_t i = 0; i < narrowDescendants.size(); ++i) { 162 TextAutosizingClusterInfo& descendantClusterInfo = narrowDescendants[i]; 163 processCluster(descendantClusterInfo, descendantClusterInfo.root, descendantClusterInfo.root, windowInfo); 164 } 152 processCompositeCluster(clusterInfo.narrowDescendants, windowInfo); 153 } 154 155 void TextAutosizer::processCluster(TextAutosizingClusterInfo& clusterInfo, RenderBlock* container, RenderObject* subtreeRoot, const TextAutosizingWindowInfo& windowInfo) 156 { 157 // Many pages set a max-width on their content. So especially for the RenderView, instead of 158 // 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 160 // text), and use its width instead. 161 clusterInfo.blockContainingAllText = findDeepestBlockContainingAllText(clusterInfo.root); 162 float textWidth = clusterInfo.blockContainingAllText->contentLogicalWidth(); 163 processClusterInternal(clusterInfo, container, subtreeRoot, windowInfo, textWidth, clusterShouldBeAutosized(clusterInfo, textWidth)); 164 } 165 166 void TextAutosizer::processCompositeCluster(Vector<TextAutosizingClusterInfo>& clusterInfos, const TextAutosizingWindowInfo& windowInfo) 167 { 168 float maxTextWidth = 0; 169 for (size_t i = 0; i < clusterInfos.size(); ++i) { 170 TextAutosizingClusterInfo& clusterInfo = clusterInfos[i]; 171 clusterInfo.blockContainingAllText = findDeepestBlockContainingAllText(clusterInfo.root); 172 maxTextWidth = max<float>(maxTextWidth, clusterInfo.blockContainingAllText->contentLogicalWidth()); 173 } 174 175 bool shouldBeAutosized = compositeClusterShouldBeAutosized(clusterInfos, maxTextWidth); 176 for (size_t i = 0; i < clusterInfos.size(); ++i) 177 processClusterInternal(clusterInfos[i], clusterInfos[i].root, clusterInfos[i].root, windowInfo, maxTextWidth, shouldBeAutosized); 165 178 } 166 179 … … 429 442 bool TextAutosizer::clusterShouldBeAutosized(TextAutosizingClusterInfo& clusterInfo, float blockWidth) 430 443 { 444 Vector<TextAutosizingClusterInfo> clusterInfos(1, clusterInfo); 445 return compositeClusterShouldBeAutosized(clusterInfos, blockWidth); 446 } 447 448 bool TextAutosizer::compositeClusterShouldBeAutosized(Vector<TextAutosizingClusterInfo>& clusterInfos, float blockWidth) 449 { 431 450 // Don't autosize clusters that contain less than 4 lines of text (in 432 451 // practice less lines are required, since measureDescendantTextWidth … … 439 458 // in and pan from side to side to read each line, since if there are very 440 459 // few lines of text you'll only need to pan across once or twice. 460 float totalTextWidth = 0; 441 461 const float minLinesOfText = 4; 442 462 float minTextWidth = blockWidth * minLinesOfText; 443 float textWidth = 0; 444 measureDescendantTextWidth(clusterInfo.blockContainingAllText, clusterInfo, minTextWidth, textWidth); 445 if (textWidth >= minTextWidth) 446 return true; 463 for (size_t i = 0; i < clusterInfos.size(); ++i) { 464 measureDescendantTextWidth(clusterInfos[i].blockContainingAllText, clusterInfos[i], minTextWidth, totalTextWidth); 465 if (totalTextWidth >= minTextWidth) 466 return true; 467 } 447 468 return false; 448 469 } -
trunk/Source/WebCore/rendering/TextAutosizer.h
r142367 r142866 62 62 explicit TextAutosizer(Document*); 63 63 64 void processClusterInternal(TextAutosizingClusterInfo&, RenderBlock* container, RenderObject* subtreeRoot, const TextAutosizingWindowInfo&, float textWidth, bool shouldBeAutosized); 64 65 void processCluster(TextAutosizingClusterInfo&, RenderBlock* container, RenderObject* subtreeRoot, const TextAutosizingWindowInfo&); 66 void processCompositeCluster(Vector<TextAutosizingClusterInfo>&, const TextAutosizingWindowInfo&); 65 67 void processContainer(float multiplier, RenderBlock* container, TextAutosizingClusterInfo&, RenderObject* subtreeRoot, const TextAutosizingWindowInfo&); 66 68 … … 78 80 static bool contentHeightIsConstrained(const RenderBlock* container); 79 81 static bool clusterShouldBeAutosized(TextAutosizingClusterInfo&, float blockWidth); 82 static bool compositeClusterShouldBeAutosized(Vector<TextAutosizingClusterInfo>&, float blockWidth); 80 83 static void measureDescendantTextWidth(const RenderBlock* container, TextAutosizingClusterInfo&, float minTextWidth, float& textWidth); 81 84
Note: See TracChangeset
for help on using the changeset viewer.