Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 90 if (block->isRenderView()) | 90 if (block->isRenderView()) |
| 91 prepareRenderViewInfo(toRenderView(block)); | 91 prepareRenderViewInfo(toRenderView(block)); |
| 92 | 92 |
| 93 if (Cluster* cluster = maybeGetOrCreateCluster(block)) | 93 if (Cluster* cluster = maybeGetOrCreateCluster(block)) |
| 94 m_clusterStack.append(cluster); | 94 m_clusterStack.append(cluster); |
| 95 | 95 |
| 96 if (block->childrenInline()) | 96 if (block->childrenInline()) |
| 97 inflate(block); | 97 inflate(block); |
| 98 } | 98 } |
| 99 | 99 |
| 100 void FastTextAutosizer::inflateListItem(RenderBlock* listItem, RenderObject* lis tItemMarker) | |
| 101 { | |
| 102 ASSERT(listItem->isListItem()); | |
| 103 ASSERT(listItemMarker->isListMarker()); | |
| 104 | |
| 105 if (!enabled()) | |
| 106 return; | |
| 107 | |
|
pdr.
2014/01/28 04:50:47
currentCluster() can be null here. Probably want t
skobes
2014/01/29 00:13:29
Done, with FIXME to investigate further.
| |
| 108 // Force the LI to be inside the DBCAT when computing the multiplier. | |
| 109 // This guarantees that the DBCAT has entered layout, so we can ask for its width. | |
| 110 // It also makes sense because the list marker is autosized like a text node . | |
| 111 float multiplier = clusterMultiplier(currentCluster(), listItem); | |
|
pdr.
2014/01/28 04:50:47
I like the idea here except for passing listItem i
skobes
2014/01/29 00:13:29
Fixed.
| |
| 112 | |
| 113 applyMultiplier(listItem, multiplier); | |
| 114 applyMultiplier(listItemMarker, multiplier); | |
| 115 } | |
| 116 | |
| 100 void FastTextAutosizer::endLayout(RenderBlock* block) | 117 void FastTextAutosizer::endLayout(RenderBlock* block) |
| 101 { | 118 { |
| 102 if (!enabled()) | 119 if (!enabled()) |
| 103 return; | 120 return; |
| 104 #ifndef NDEBUG | 121 #ifndef NDEBUG |
| 105 m_blocksThatHaveBegunLayout.remove(block); | 122 m_blocksThatHaveBegunLayout.remove(block); |
| 106 #endif | 123 #endif |
| 107 | 124 |
| 108 Cluster* cluster = currentCluster(); | 125 Cluster* cluster = currentCluster(); |
| 109 if (cluster && cluster->m_root == block) | 126 if (cluster && cluster->m_root == block) |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 270 ancestors.add(block); | 287 ancestors.add(block); |
| 271 // The first ancestor that has all of the blocks as children wins. | 288 // The first ancestor that has all of the blocks as children wins. |
| 272 if (ancestors.count(block) == blocks.size()) | 289 if (ancestors.count(block) == blocks.size()) |
| 273 return block; | 290 return block; |
| 274 } | 291 } |
| 275 } | 292 } |
| 276 ASSERT_NOT_REACHED(); | 293 ASSERT_NOT_REACHED(); |
| 277 return 0; | 294 return 0; |
| 278 } | 295 } |
| 279 | 296 |
| 280 float FastTextAutosizer::clusterMultiplier(Cluster* cluster) | 297 float FastTextAutosizer::clusterMultiplier(Cluster* cluster, const RenderBlock* forceInclude) |
| 281 { | 298 { |
| 282 #ifndef NDEBUG | 299 #ifndef NDEBUG |
| 283 ASSERT(m_renderViewInfoPrepared); | 300 ASSERT(m_renderViewInfoPrepared); |
| 284 #endif | 301 #endif |
| 285 if (!cluster->m_multiplier) { | 302 if (!cluster->m_multiplier) { |
| 286 if (TextAutosizer::isIndependentDescendant(cluster->m_root)) { | 303 if (TextAutosizer::isIndependentDescendant(cluster->m_root)) { |
| 287 if (clusterHasEnoughTextToAutosize(cluster)) { | 304 bool enoughText = clusterHasEnoughTextToAutosize(cluster); |
| 288 const RenderBlock* deepestBlockContainingAllText = findDeepestBl ockContainingAllText(cluster->m_root); | 305 if (enoughText) { |
| 306 const RenderBlock* deepestBlockContainingAllText = findDeepestBl ockContainingAllText(cluster->m_root, forceInclude); | |
| 289 #ifndef NDEBUG | 307 #ifndef NDEBUG |
| 290 // This ensures the deepest block containing all text has a vali d contentLogicalWidth. | 308 // This ensures the deepest block containing all text has a vali d contentLogicalWidth. |
| 291 ASSERT(m_blocksThatHaveBegunLayout.contains(deepestBlockContaini ngAllText)); | 309 ASSERT(m_blocksThatHaveBegunLayout.contains(deepestBlockContaini ngAllText)); |
| 292 #endif | 310 #endif |
| 293 // Block width, in CSS pixels. | 311 // Block width, in CSS pixels. |
| 294 float textBlockWidth = deepestBlockContainingAllText->contentLog icalWidth(); | 312 float textBlockWidth = deepestBlockContainingAllText->contentLog icalWidth(); |
| 295 float multiplier = min(textBlockWidth, static_cast<float>(m_layo utWidth)) / m_frameWidth; | 313 float multiplier = min(textBlockWidth, static_cast<float>(m_layo utWidth)) / m_frameWidth; |
| 296 cluster->m_multiplier = max(m_baseMultiplier * multiplier, 1.0f) ; | 314 cluster->m_multiplier = max(m_baseMultiplier * multiplier, 1.0f) ; |
| 297 } else { | 315 } else { |
| 298 cluster->m_multiplier = 1.0f; | 316 cluster->m_multiplier = 1.0f; |
| 299 } | 317 } |
| 300 } else { | 318 } else { |
| 301 cluster->m_multiplier = cluster->m_parent ? clusterMultiplier(cluste r->m_parent) : 1.0f; | 319 cluster->m_multiplier = cluster->m_parent ? clusterMultiplier(cluste r->m_parent) : 1.0f; |
| 302 } | 320 } |
| 303 } | 321 } |
| 322 ASSERT(cluster->m_multiplier); | |
| 304 return cluster->m_multiplier; | 323 return cluster->m_multiplier; |
| 305 } | 324 } |
| 306 | 325 |
| 307 // FIXME: Refactor this to look more like FastTextAutosizer::deepestCommonAncest or. This is copied | 326 // FIXME: Refactor this to look more like FastTextAutosizer::deepestCommonAncest or. This is copied |
| 308 // from TextAutosizer::findDeepestBlockContainingAllText. | 327 // from TextAutosizer::findDeepestBlockContainingAllText. |
| 309 const RenderBlock* FastTextAutosizer::findDeepestBlockContainingAllText(const Re nderBlock* root) | 328 const RenderBlock* FastTextAutosizer::findDeepestBlockContainingAllText(const Re nderBlock* root, const RenderBlock* forceInclude) |
| 310 { | 329 { |
| 311 size_t firstDepth = 0; | 330 size_t firstDepth = 0; |
| 312 const RenderObject* firstTextLeaf = findTextLeaf(root, firstDepth, First); | 331 const RenderObject* firstTextLeaf = findTextLeaf(root, firstDepth, First); |
| 313 if (!firstTextLeaf) | 332 if (!firstTextLeaf) |
| 314 return root; | 333 return root; |
| 315 | 334 |
| 316 size_t lastDepth = 0; | 335 size_t lastDepth = 0; |
| 317 const RenderObject* lastTextLeaf = findTextLeaf(root, lastDepth, Last); | 336 const RenderObject* lastTextLeaf = findTextLeaf(root, lastDepth, Last); |
| 318 ASSERT(lastTextLeaf); | 337 ASSERT(lastTextLeaf); |
| 319 | 338 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 338 if (firstNode->isRenderBlock()) | 357 if (firstNode->isRenderBlock()) |
| 339 return toRenderBlock(firstNode); | 358 return toRenderBlock(firstNode); |
| 340 | 359 |
| 341 // containingBlock() should never leave the cluster, since it only skips anc estors when finding | 360 // containingBlock() should never leave the cluster, since it only skips anc estors when finding |
| 342 // the container of position:absolute/fixed blocks, and those cannot exist b etween a cluster and | 361 // the container of position:absolute/fixed blocks, and those cannot exist b etween a cluster and |
| 343 // its text node's lowest common ancestor as isAutosizingCluster would have made them into their | 362 // its text node's lowest common ancestor as isAutosizingCluster would have made them into their |
| 344 // own independent cluster. | 363 // own independent cluster. |
| 345 const RenderBlock* containingBlock = firstNode->containingBlock(); | 364 const RenderBlock* containingBlock = firstNode->containingBlock(); |
| 346 ASSERT(containingBlock->isDescendantOf(root)); | 365 ASSERT(containingBlock->isDescendantOf(root)); |
| 347 | 366 |
| 367 if (forceInclude && !forceInclude->isDescendantOf(containingBlock)) { | |
| 368 ASSERT(forceInclude->isDescendantOf(root)); | |
| 369 | |
| 370 BlockSet blockSet; | |
| 371 blockSet.add(containingBlock); | |
| 372 blockSet.add(forceInclude); | |
| 373 return deepestCommonAncestor(blockSet); | |
| 374 } | |
| 375 | |
| 348 return containingBlock; | 376 return containingBlock; |
| 349 } | 377 } |
| 350 | 378 |
| 351 const RenderObject* FastTextAutosizer::findTextLeaf(const RenderObject* parent, size_t& depth, TextLeafSearch firstOrLast) | 379 const RenderObject* FastTextAutosizer::findTextLeaf(const RenderObject* parent, size_t& depth, TextLeafSearch firstOrLast) |
| 352 { | 380 { |
| 353 if (parent->isEmpty()) | 381 if (parent->isEmpty()) |
| 354 return parent->isText() ? parent : 0; | 382 return parent->isText() ? parent : 0; |
| 355 | 383 |
| 356 ++depth; | 384 ++depth; |
| 357 const RenderObject* child = (firstOrLast == First) ? parent->firstChild() : parent->lastChild(); | 385 const RenderObject* child = (firstOrLast == First) ? parent->firstChild() : parent->lastChild(); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 421 } | 449 } |
| 422 | 450 |
| 423 RenderObject* FastTextAutosizer::nextChildSkippingChildrenOfBlocks(const RenderO bject* current, const RenderObject* stayWithin) | 451 RenderObject* FastTextAutosizer::nextChildSkippingChildrenOfBlocks(const RenderO bject* current, const RenderObject* stayWithin) |
| 424 { | 452 { |
| 425 if (current == stayWithin || !current->isRenderBlock()) | 453 if (current == stayWithin || !current->isRenderBlock()) |
| 426 return current->nextInPreOrder(stayWithin); | 454 return current->nextInPreOrder(stayWithin); |
| 427 return current->nextInPreOrderAfterChildren(stayWithin); | 455 return current->nextInPreOrderAfterChildren(stayWithin); |
| 428 } | 456 } |
| 429 | 457 |
| 430 } // namespace WebCore | 458 } // namespace WebCore |
| OLD | NEW |