Changeset 138111 in webkit
- Timestamp:
- Dec 18, 2012 8:33:14 PM (11 years ago)
- Location:
- trunk
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r138107 r138111 1 2012-12-18 Anton Vayvod <avayvod@chromium.org> 2 3 Text Autosizing: containers wider than their enclosing clusters should be autosized as separate clusters 4 https://bugs.webkit.org/show_bug.cgi?id=103627 5 6 Reviewed by Julien Chaffraix. 7 8 Modified existing tests to reflect the new autosizing approach to handling of the elements that are 9 wider than the lowest common ancestor of the text nodes of the enclosing autosizing cluster. 10 11 * fast/text-autosizing/cluster-wide-in-narrow-expected.html: 12 * fast/text-autosizing/cluster-wide-in-narrow.html: 13 * fast/text-autosizing/wide-child-expected.html: 14 * fast/text-autosizing/wide-child.html: 15 * fast/text-autosizing/wide-in-narrow-overflow-scroll-expected.html: 16 * fast/text-autosizing/wide-in-narrow-overflow-scroll.html: 17 1 18 2012-12-18 Filip Pizlo <fpizlo@apple.com> 2 19 -
trunk/LayoutTests/fast/text-autosizing/cluster-wide-in-narrow-expected.html
r129195 r138111 18 18 </div> 19 19 20 <div style="width: 800px; font-size: 1.25rem">21 This text should be autosized to just 20px computed font-size (16 * 400/320), since despite its width:800px it is part of the 400px wide rootcluster.<br>20 <div style="width: 600px; font-size: 1.875rem"> 21 This text should be autosized to 30px computed font-size (16 * 600/320), since its width:600px makes it wider than the lowest common ancestor of its enclosing cluster, hence it will itself become a cluster.<br> 22 22 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 23 23 </div> 24 24 25 25 <div style="font-size: 1.25rem"> 26 This text should similarly be autosized to 20px.<br>26 This text should be autosized to 20px computed font-size (16 * 400 / 320), since it's not an autosizing cluster itself and its parent element is the enclosing autosizing cluster which is 400px wide.<br> 27 27 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 28 28 </div> -
trunk/LayoutTests/fast/text-autosizing/cluster-wide-in-narrow.html
r129195 r138111 27 27 </div> 28 28 29 <div style="width: 800px">30 This text should be autosized to just 20px computed font-size (16 * 400/320), since despite its width:800px it is part of the 400px wide rootcluster.<br>29 <div style="width: 600px"> 30 This text should be autosized to 30px computed font-size (16 * 600/320), since its width:600px makes it wider than the lowest common ancestor of its enclosing cluster, hence it will itself become a cluster.<br> 31 31 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 32 32 </div> 33 33 34 34 <div> 35 This text should similarly be autosized to 20px.<br>35 This text should be autosized to 20px computed font-size (16 * 400 / 320), since it's not an autosizing cluster itself and its parent element is the enclosing autosizing cluster which is 400px wide.<br> 36 36 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 37 37 </div> -
trunk/LayoutTests/fast/text-autosizing/wide-child-expected.html
r136047 r138111 13 13 14 14 <div style="width: 320px; font-size: 1rem"> 15 15 This text should not be autosized, as this div is the lowest common ancestor of the root cluster, and this div is narrow.<br> 16 16 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 17 <div style="width: 800px"> 18 This text should not be autosized since it doesn't affect the width of the parent block which is used to calculate the autosizing multiplier.<br> 19 FIXME: Ideally this text should be autosized. Will need to be fixed later.<br> 17 <div style="width: 800px; font-size: 2.5rem"> 18 This text should be autosized to 40px computed font size (16 * 800/320) since it's wider than the lowest common ancestor of its enclosing cluster so it becomes a cluster itself.<br> 20 19 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 21 20 </div> -
trunk/LayoutTests/fast/text-autosizing/wide-child.html
r136047 r138111 25 25 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 26 26 <div style="width: 800px"> 27 This text should not be autosized since it doesn't affect the width of the parent block which is used to calculate the autosizing multiplier.<br> 28 FIXME: Ideally this text should be autosized. Will need to be fixed later.<br> 27 This text should be autosized to 40px computed font size (16 * 800/320) since it's wider than the lowest common ancestor of its enclosing cluster so it becomes a cluster itself.<br> 29 28 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 30 29 </div> -
trunk/LayoutTests/fast/text-autosizing/wide-in-narrow-overflow-scroll-expected.html
r136047 r138111 13 13 14 14 <div style="width: 400px"> 15 <div style="overflow-x: scroll"> 16 <div style="width: 800px; font-size: 1.25rem"> 17 This text should be autosized to 20px computed font size (16 * 400/320), since this is part of the root cluster, whose text descendants are all contained within the 400px wide grandparent of this div.<br> 15 <div style="overflow-x: scroll"> 16 <div style="width: 800px; font-size: 2.5rem"> 17 This text should be autosized to 40px computed font size (16 * 800/320) since it's wider than the lowest common ancestor of its enclosing cluster so it becomes a cluster itself.<br> 18 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 19 </div> 20 </div> 21 22 <div style="font-size: 1.25rem"> 23 This text should be autosized to 20px computed font size (16 * 400/320).<br> 18 24 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 19 25 </div> 20 </div>21 22 <div style="font-size: 1.25rem">23 This text should be autosized to 20px computed font size (16 * 400/320).<br>24 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.25 </div>26 26 </div> 27 27 -
trunk/LayoutTests/fast/text-autosizing/wide-in-narrow-overflow-scroll.html
r136047 r138111 22 22 23 23 <div style="width: 400px"> 24 <div style="overflow-x: scroll"> 25 <div style="width: 800px"> 26 This text should be autosized to 20px computed font size (16 * 400/320), since this is part of the root cluster, whose text descendants are all contained within the 400px wide grandparent of this div.<br> 24 <div style="overflow-x: scroll"> 25 <div style="width: 800px"> 26 This text should be autosized to 40px computed font size (16 * 800/320) since it's wider than the lowest common ancestor of its enclosing cluster so it becomes a cluster itself.<br> 27 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 28 </div> 29 </div> 30 31 <div> 32 This text should be autosized to 20px computed font size (16 * 400/320).<br> 27 33 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 28 34 </div> 29 </div>30 31 <div>32 This text should be autosized to 20px computed font size (16 * 400/320).<br>33 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.34 </div>35 35 </div> 36 36 -
trunk/Source/WebCore/ChangeLog
r138110 r138111 1 2012-12-18 Anton Vayvod <avayvod@chromium.org> 2 3 Text Autosizing: containers wider than their enclosing clusters should be autosized as separate clusters 4 https://bugs.webkit.org/show_bug.cgi?id=103627 5 6 Reviewed by Julien Chaffraix. 7 8 Some blocks of texts might be wider than their parent clusters and need to be autosized separately. 9 10 isAutosizingCluster() now checks for the width of the container being greater than the width of the lowest 11 common ancestor of the text nodes of the enclosing cluster. This block containing all text is passed to all 12 tree traversal methods. 13 An overloaded version is added for cases when we don't have the lowest common ancestor yet. 14 15 The change fixes several cases covered by existing tests. 16 17 * rendering/TextAutosizer.cpp: 18 (WebCore::TextAutosizer::processSubtree): 19 20 Calls processCluster with a new number of arguments. 21 22 (WebCore::TextAutosizer::processCluster): 23 24 Passes block containing all text nodes into processContainer. Assertion removed since it can no longer be 25 checked without passing an additional parameter (the parent block containing all text) to the function 26 for the sake of this assertion only. 27 28 (WebCore::TextAutosizer::processContainer): 29 30 |parentBlockContainingAllText| parameter passed into isAutosizingCluster. 31 32 (WebCore::TextAutosizer::isAutosizingCluster(const RenderBlock*, const RenderBlock*)): 33 34 The overloaded method that is used when the render block checked is already known to be an autosizing 35 container and there's full information necessary to determine if it's a cluster like the parent block 36 containing all text within the enclosing cluster. 37 Considers a block a cluster if it is wider than its parent block containing all text within enclosing 38 cluster. 39 40 (WebCore::TextAutosizer::isAutosizingCluster(const RenderObject*)): 41 42 The overloaded method that checks for the given object to be an autosizing container first (for 43 convenience of the caller) and doesn't require information about the parent cluster. Used when such 44 information is not available, for example, in the process of retrieving the information for the parent 45 cluster or when looking for the root cluster in the tree. 46 47 (WebCore::TextAutosizer::clusterShouldBeAutosized): 48 49 Passes new parameter to measureDescendantTextWidth. 50 51 (WebCore::TextAutosizer::measureDescendantTextWidth): 52 53 Uses blockContainingAllText parameter to pass to isAutosizingCluster. 54 55 (WebCore::TextAutosizer::findDeepestBlockContainingAllText): 56 57 Assertion removed since it can no longer be checked without passing an additional parameter (the 58 parent block containing all text) to the function for the sake of this assertion only. 59 60 (WebCore::TextAutosizer::findFirstTextLeafNotInCluster): 61 Uses shorter isAutosizingCluster call. 62 1 63 2012-12-18 Alexey Proskuryakov <ap@apple.com> 2 64 -
trunk/Source/WebCore/rendering/TextAutosizer.cpp
r137764 r138111 27 27 #include "Document.h" 28 28 #include "InspectorInstrumentation.h" 29 #include "IntSize.h" 29 30 #include "RenderObject.h" 30 31 #include "RenderStyle.h" … … 86 87 87 88 RenderBlock* cluster = container; 88 while (cluster && (!isAutosizingContainer(cluster) || !isAutosizingCluster(cluster)))89 while (cluster && !isAutosizingCluster(cluster)) 89 90 cluster = cluster->containingBlock(); 90 91 … … 95 96 void TextAutosizer::processCluster(RenderBlock* cluster, RenderBlock* container, RenderObject* subtreeRoot, const TextAutosizingWindowInfo& windowInfo) 96 97 { 97 ASSERT(isAutosizingCluster(cluster));98 99 98 // Many pages set a max-width on their content. So especially for the 100 99 // RenderView, instead of just taking the width of |cluster| we find … … 102 101 // the cluster (i.e. the deepest wrapper block that contains all the text), 103 102 // and use its width instead. 104 const RenderBlock* lowestCommonAncestor= findDeepestBlockContainingAllText(cluster);105 float commonAncestorWidth = lowestCommonAncestor->contentLogicalWidth();103 const RenderBlock* blockContainingAllText = findDeepestBlockContainingAllText(cluster); 104 float textWidth = blockContainingAllText->contentLogicalWidth(); 106 105 107 106 float multiplier = 1; 108 if (clusterShouldBeAutosized( lowestCommonAncestor, commonAncestorWidth)) {107 if (clusterShouldBeAutosized(blockContainingAllText, textWidth)) { 109 108 int logicalWindowWidth = cluster->isHorizontalWritingMode() ? windowInfo.windowSize.width() : windowInfo.windowSize.height(); 110 109 int logicalLayoutWidth = cluster->isHorizontalWritingMode() ? windowInfo.minLayoutSize.width() : windowInfo.minLayoutSize.height(); 111 110 // Ignore box width in excess of the layout width, to avoid extreme multipliers. 112 float logicalClusterWidth = std::min<float>( commonAncestorWidth, logicalLayoutWidth);111 float logicalClusterWidth = std::min<float>(textWidth, logicalLayoutWidth); 113 112 114 113 multiplier = logicalClusterWidth / logicalWindowWidth; … … 117 116 } 118 117 119 processContainer(multiplier, container, subtreeRoot, windowInfo);120 } 121 122 void TextAutosizer::processContainer(float multiplier, RenderBlock* container, RenderObject* subtreeRoot, const TextAutosizingWindowInfo& windowInfo)118 processContainer(multiplier, container, blockContainingAllText, subtreeRoot, windowInfo); 119 } 120 121 void TextAutosizer::processContainer(float multiplier, RenderBlock* container, const RenderBlock* blockContainingAllText, RenderObject* subtreeRoot, const TextAutosizingWindowInfo& windowInfo) 123 122 { 124 123 ASSERT(isAutosizingContainer(container)); 125 124 126 float localMultiplier = containerShould beAutosized(container) ? multiplier: 1;125 float localMultiplier = containerShouldBeAutosized(container) ? multiplier: 1; 127 126 128 127 RenderObject* descendant = nextInPreOrderSkippingDescendantsOfContainers(subtreeRoot, subtreeRoot); … … 136 135 } else if (isAutosizingContainer(descendant)) { 137 136 RenderBlock* descendantBlock = toRenderBlock(descendant); 138 if (isAutosizingCluster(descendantBlock ))137 if (isAutosizingCluster(descendantBlock, blockContainingAllText)) 139 138 processCluster(descendantBlock, descendantBlock, descendantBlock, windowInfo); 140 139 else 141 processContainer(multiplier, descendantBlock, descendantBlock, windowInfo);140 processContainer(multiplier, descendantBlock, blockContainingAllText, descendantBlock, windowInfo); 142 141 } 143 142 descendant = nextInPreOrderSkippingDescendantsOfContainers(descendant, subtreeRoot); … … 197 196 } 198 197 199 bool TextAutosizer::isAutosizingCluster(const RenderBlock* renderer )198 bool TextAutosizer::isAutosizingCluster(const RenderBlock* renderer, const RenderBlock* parentBlockContainingAllText) 200 199 { 201 200 // "Autosizing clusters" are special autosizing containers within which we 202 201 // want to enforce a uniform text size multiplier, in the hopes of making 203 202 // the major sections of the page look internally consistent. 204 // All their descend ents (including other autosizing containers) must share203 // All their descendants (including other autosizing containers) must share 205 204 // the same multiplier, except for subtrees which are themselves clusters, 206 // and some of their descend ent containers might not be autosized at all205 // and some of their descendant containers might not be autosized at all 207 206 // (for example if their height is constrained). 208 207 // Additionally, clusterShouldBeAutosized requires each cluster to contain a … … 213 212 // flow roots correspond to box containers that behave somewhat 214 213 // independently from their parent (for example they don't overlap floats). 215 // The definition of a flow flowroot also conveniently includes most of the214 // The definition of a flow root also conveniently includes most of the 216 215 // ways that a box and its children can have significantly different width 217 216 // from the box's parent (we want to avoid having significantly different 218 217 // width blocks within a cluster, since the narrower blocks would end up 219 218 // larger than would otherwise be necessary). 219 // Additionally, any containers that are wider than the |blockContainingAllText| 220 // of their enclosing cluster also become clusters, since they need special 221 // treatment due to their width. 220 222 ASSERT(isAutosizingContainer(renderer)); 221 223 … … 228 230 || renderer->hasColumns() 229 231 || renderer->containingBlock()->isHorizontalWritingMode() != renderer->isHorizontalWritingMode() 230 || renderer->style()->isDisplayReplacedType(); 232 || renderer->style()->isDisplayReplacedType() 233 || (parentBlockContainingAllText 234 && renderer->contentLogicalWidth() > parentBlockContainingAllText->contentLogicalWidth()); 231 235 // FIXME: Tables need special handling to multiply all their columns by 232 236 // the same amount even if they're different widths; so do hasColumns() 233 237 // containers, and probably flexboxes... 238 } 239 240 bool TextAutosizer::isAutosizingCluster(const RenderObject* object) 241 { 242 return isAutosizingContainer(object) && isAutosizingCluster(toRenderBlock(object), 0); 234 243 } 235 244 … … 254 263 } 255 264 256 bool TextAutosizer::containerShould beAutosized(const RenderBlock* container)265 bool TextAutosizer::containerShouldBeAutosized(const RenderBlock* container) 257 266 { 258 267 // Don't autosize block-level text that can't wrap (as it's likely to … … 264 273 } 265 274 266 bool TextAutosizer::clusterShouldBeAutosized(const RenderBlock* lowestCommonAncestor, float commonAncestorWidth)275 bool TextAutosizer::clusterShouldBeAutosized(const RenderBlock* blockContainingAllText, float blockWidth) 267 276 { 268 277 // Don't autosize clusters that contain less than 4 lines of text (in … … 277 286 // few lines of text you'll only need to pan across once or twice. 278 287 const float minLinesOfText = 4; 279 float minTextWidth = commonAncestorWidth * minLinesOfText;288 float minTextWidth = blockWidth * minLinesOfText; 280 289 float textWidth = 0; 281 measureDescendantTextWidth( lowestCommonAncestor, minTextWidth, textWidth);290 measureDescendantTextWidth(blockContainingAllText, blockContainingAllText, minTextWidth, textWidth); 282 291 if (textWidth >= minTextWidth) 283 292 return true; … … 285 294 } 286 295 287 void TextAutosizer::measureDescendantTextWidth(const RenderBlock* container, float minTextWidth, float& textWidth)288 { 289 bool skipLocalText = !containerShould beAutosized(container);296 void TextAutosizer::measureDescendantTextWidth(const RenderBlock* container, const RenderBlock* blockContainingAllText, float minTextWidth, float& textWidth) 297 { 298 bool skipLocalText = !containerShouldBeAutosized(container); 290 299 291 300 RenderObject* descendant = nextInPreOrderSkippingDescendantsOfContainers(container, container); … … 295 304 } else if (isAutosizingContainer(descendant)) { 296 305 RenderBlock* descendantBlock = toRenderBlock(descendant); 297 if (!isAutosizingCluster(descendantBlock ))298 measureDescendantTextWidth(descendantBlock, minTextWidth, textWidth);306 if (!isAutosizingCluster(descendantBlock, blockContainingAllText)) 307 measureDescendantTextWidth(descendantBlock, blockContainingAllText, minTextWidth, textWidth); 299 308 } 300 309 if (textWidth >= minTextWidth) … … 322 331 const RenderBlock* TextAutosizer::findDeepestBlockContainingAllText(const RenderBlock* cluster) 323 332 { 324 ASSERT(isAutosizingCluster(cluster));325 326 333 size_t firstDepth = 0; 327 334 const RenderObject* firstTextLeaf = findFirstTextLeafNotInCluster(cluster, firstDepth, FirstToLast); … … 372 379 const RenderObject* child = (direction == FirstToLast) ? parent->firstChild() : parent->lastChild(); 373 380 while (child) { 374 if (!isAutosizingC ontainer(child) || !isAutosizingCluster(toRenderBlock(child))) {381 if (!isAutosizingCluster(child)) { 375 382 const RenderObject* leaf = findFirstTextLeafNotInCluster(child, depth, direction); 376 383 if (leaf) -
trunk/Source/WebCore/rendering/TextAutosizer.h
r137738 r138111 29 29 #if ENABLE(TEXT_AUTOSIZING) 30 30 31 #include "IntSize.h"32 31 #include <wtf/Noncopyable.h> 33 32 #include <wtf/PassOwnPtr.h> 34 #include <wtf/PassRefPtr.h>35 33 36 34 namespace WebCore { … … 39 37 class RenderBlock; 40 38 class RenderObject; 41 class RenderStyle;42 39 class RenderText; 43 40 struct TextAutosizingWindowInfo; … … 64 61 65 62 void processCluster(RenderBlock* cluster, RenderBlock* container, RenderObject* subtreeRoot, const TextAutosizingWindowInfo&); 66 void processContainer(float multiplier, RenderBlock* container, RenderObject* subtreeRoot, const TextAutosizingWindowInfo&);63 void processContainer(float multiplier, RenderBlock* container, const RenderBlock* blockContainingAllText, RenderObject* subtreeRoot, const TextAutosizingWindowInfo&); 67 64 68 65 void setMultiplier(RenderObject*, float); 69 66 70 67 static bool isAutosizingContainer(const RenderObject*); 71 static bool isAutosizingCluster(const RenderBlock*); 68 static bool isAutosizingCluster(const RenderBlock*, const RenderBlock* parentBlockContainingAllText); 69 static bool isAutosizingCluster(const RenderObject*); 72 70 73 static bool containerShould beAutosized(const RenderBlock* container);74 static bool clusterShouldBeAutosized(const RenderBlock* lowestCommonAncestor, float commonAncestorWidth);75 static void measureDescendantTextWidth(const RenderBlock* container, float minTextWidth, float& textWidth);71 static bool containerShouldBeAutosized(const RenderBlock* container); 72 static bool clusterShouldBeAutosized(const RenderBlock* blockContainingAllText, float blockWidth); 73 static void measureDescendantTextWidth(const RenderBlock* container, const RenderBlock* blockContainingAllText, float minTextWidth, float& textWidth); 76 74 77 75 // Use to traverse the tree of descendants, excluding descendants of containers (but returning the containers themselves). 78 static RenderObject* nextInPreOrderSkippingDescendantsOfContainers(const RenderObject* current, const RenderObject* stayWithin);76 static RenderObject* nextInPreOrderSkippingDescendantsOfContainers(const RenderObject*, const RenderObject* stayWithin); 79 77 80 // Finds the lowest common ancestor of the first and the last descendant81 // text node (excluding those belonging to other autosizing clusters).82 78 static const RenderBlock* findDeepestBlockContainingAllText(const RenderBlock* cluster); 83 79
Note: See TracChangeset
for help on using the changeset viewer.