| 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 20 matching lines...) Expand all Loading... |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 #include "core/rendering/FastTextAutosizer.h" | 32 #include "core/rendering/FastTextAutosizer.h" |
| 33 | 33 |
| 34 #include "core/dom/Document.h" | 34 #include "core/dom/Document.h" |
| 35 #include "core/frame/Frame.h" | 35 #include "core/frame/Frame.h" |
| 36 #include "core/frame/FrameView.h" | 36 #include "core/frame/FrameView.h" |
| 37 #include "core/frame/Settings.h" | 37 #include "core/frame/Settings.h" |
| 38 #include "core/page/Page.h" | 38 #include "core/page/Page.h" |
| 39 #include "core/rendering/InlineIterator.h" | 39 #include "core/rendering/InlineIterator.h" |
| 40 #include "core/rendering/RenderBlock.h" | 40 #include "core/rendering/RenderBlock.h" |
| 41 #include "core/rendering/RenderListItem.h" |
| 42 #include "core/rendering/RenderListMarker.h" |
| 41 #include "core/rendering/RenderView.h" | 43 #include "core/rendering/RenderView.h" |
| 42 #include "core/rendering/TextAutosizer.h" | 44 #include "core/rendering/TextAutosizer.h" |
| 43 | 45 |
| 44 using namespace std; | 46 using namespace std; |
| 45 | 47 |
| 46 namespace WebCore { | 48 namespace WebCore { |
| 47 | 49 |
| 48 FastTextAutosizer::FastTextAutosizer(const Document* document) | 50 FastTextAutosizer::FastTextAutosizer(const Document* document) |
| 49 : m_document(document) | 51 : m_document(document) |
| 50 #ifndef NDEBUG | 52 #ifndef NDEBUG |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 if (block->isRenderView()) | 92 if (block->isRenderView()) |
| 91 prepareRenderViewInfo(toRenderView(block)); | 93 prepareRenderViewInfo(toRenderView(block)); |
| 92 | 94 |
| 93 if (Cluster* cluster = maybeGetOrCreateCluster(block)) | 95 if (Cluster* cluster = maybeGetOrCreateCluster(block)) |
| 94 m_clusterStack.append(cluster); | 96 m_clusterStack.append(cluster); |
| 95 | 97 |
| 96 if (block->childrenInline()) | 98 if (block->childrenInline()) |
| 97 inflate(block); | 99 inflate(block); |
| 98 } | 100 } |
| 99 | 101 |
| 102 void FastTextAutosizer::inflateListItem(RenderListItem* listItem, RenderListMark
er* listItemMarker) |
| 103 { |
| 104 if (!enabled()) |
| 105 return; |
| 106 #ifndef NDEBUG |
| 107 m_blocksThatHaveBegunLayout.add(listItem); |
| 108 #endif |
| 109 |
| 110 Cluster* cluster = currentCluster(); |
| 111 // FIXME: Why is this check needed? |
| 112 if (!cluster) |
| 113 return; |
| 114 |
| 115 // Force the LI to be inside the DBCAT when computing the multiplier. |
| 116 // This guarantees that the DBCAT has entered layout, so we can ask for its
width. |
| 117 // It also makes sense because the list marker is autosized like a text node
. |
| 118 float multiplier = clusterMultiplier(cluster); |
| 119 |
| 120 applyMultiplier(listItem, multiplier); |
| 121 applyMultiplier(listItemMarker, multiplier); |
| 122 } |
| 123 |
| 100 void FastTextAutosizer::endLayout(RenderBlock* block) | 124 void FastTextAutosizer::endLayout(RenderBlock* block) |
| 101 { | 125 { |
| 102 if (!enabled()) | 126 if (!enabled()) |
| 103 return; | 127 return; |
| 104 #ifndef NDEBUG | 128 #ifndef NDEBUG |
| 105 m_blocksThatHaveBegunLayout.remove(block); | 129 m_blocksThatHaveBegunLayout.remove(block); |
| 106 #endif | 130 #endif |
| 107 | 131 |
| 108 Cluster* cluster = currentCluster(); | 132 Cluster* cluster = currentCluster(); |
| 109 if (cluster && cluster->m_root == block) | 133 if (cluster && cluster->m_root == block) |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 float textBlockWidth = deepestBlockContainingAllText->contentLog
icalWidth(); | 318 float textBlockWidth = deepestBlockContainingAllText->contentLog
icalWidth(); |
| 295 float multiplier = min(textBlockWidth, static_cast<float>(m_layo
utWidth)) / m_frameWidth; | 319 float multiplier = min(textBlockWidth, static_cast<float>(m_layo
utWidth)) / m_frameWidth; |
| 296 cluster->m_multiplier = max(m_baseMultiplier * multiplier, 1.0f)
; | 320 cluster->m_multiplier = max(m_baseMultiplier * multiplier, 1.0f)
; |
| 297 } else { | 321 } else { |
| 298 cluster->m_multiplier = 1.0f; | 322 cluster->m_multiplier = 1.0f; |
| 299 } | 323 } |
| 300 } else { | 324 } else { |
| 301 cluster->m_multiplier = cluster->m_parent ? clusterMultiplier(cluste
r->m_parent) : 1.0f; | 325 cluster->m_multiplier = cluster->m_parent ? clusterMultiplier(cluste
r->m_parent) : 1.0f; |
| 302 } | 326 } |
| 303 } | 327 } |
| 328 ASSERT(cluster->m_multiplier); |
| 304 return cluster->m_multiplier; | 329 return cluster->m_multiplier; |
| 305 } | 330 } |
| 306 | 331 |
| 307 // FIXME: Refactor this to look more like FastTextAutosizer::deepestCommonAncest
or. This is copied | 332 // FIXME: Refactor this to look more like FastTextAutosizer::deepestCommonAncest
or. This is copied |
| 308 // from TextAutosizer::findDeepestBlockContainingAllText. | 333 // from TextAutosizer::findDeepestBlockContainingAllText. |
| 309 const RenderBlock* FastTextAutosizer::findDeepestBlockContainingAllText(const Re
nderBlock* root) | 334 const RenderBlock* FastTextAutosizer::findDeepestBlockContainingAllText(const Re
nderBlock* root) |
| 310 { | 335 { |
| 311 size_t firstDepth = 0; | 336 size_t firstDepth = 0; |
| 312 const RenderObject* firstTextLeaf = findTextLeaf(root, firstDepth, First); | 337 const RenderObject* firstTextLeaf = findTextLeaf(root, firstDepth, First); |
| 313 if (!firstTextLeaf) | 338 if (!firstTextLeaf) |
| (...skipping 29 matching lines...) Expand all Loading... |
| 343 // its text node's lowest common ancestor as isAutosizingCluster would have
made them into their | 368 // its text node's lowest common ancestor as isAutosizingCluster would have
made them into their |
| 344 // own independent cluster. | 369 // own independent cluster. |
| 345 const RenderBlock* containingBlock = firstNode->containingBlock(); | 370 const RenderBlock* containingBlock = firstNode->containingBlock(); |
| 346 ASSERT(containingBlock->isDescendantOf(root)); | 371 ASSERT(containingBlock->isDescendantOf(root)); |
| 347 | 372 |
| 348 return containingBlock; | 373 return containingBlock; |
| 349 } | 374 } |
| 350 | 375 |
| 351 const RenderObject* FastTextAutosizer::findTextLeaf(const RenderObject* parent,
size_t& depth, TextLeafSearch firstOrLast) | 376 const RenderObject* FastTextAutosizer::findTextLeaf(const RenderObject* parent,
size_t& depth, TextLeafSearch firstOrLast) |
| 352 { | 377 { |
| 378 // List items are treated as text due to the marker. |
| 379 // The actual renderer for the marker (RenderListMarker) may not be in the t
ree yet since it is added during layout. |
| 380 if (parent->isListItem()) |
| 381 return parent; |
| 382 |
| 353 if (parent->isEmpty()) | 383 if (parent->isEmpty()) |
| 354 return parent->isText() ? parent : 0; | 384 return parent->isText() ? parent : 0; |
| 355 | 385 |
| 356 ++depth; | 386 ++depth; |
| 357 const RenderObject* child = (firstOrLast == First) ? parent->firstChild() :
parent->lastChild(); | 387 const RenderObject* child = (firstOrLast == First) ? parent->firstChild() :
parent->lastChild(); |
| 358 while (child) { | 388 while (child) { |
| 359 // At this point clusters may not have been created for these blocks so
we cannot rely on m_clusters. | 389 // At this point clusters may not have been created for these blocks so
we cannot rely on m_clusters. |
| 360 if (!TextAutosizer::isAutosizingContainer(child) || !TextAutosizer::isIn
dependentDescendant(toRenderBlock(child))) { | 390 if (!TextAutosizer::isAutosizingContainer(child) || !TextAutosizer::isIn
dependentDescendant(toRenderBlock(child))) { |
| 361 const RenderObject* leaf = findTextLeaf(child, depth, firstOrLast); | 391 const RenderObject* leaf = findTextLeaf(child, depth, firstOrLast); |
| 362 if (leaf) | 392 if (leaf) |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 } | 451 } |
| 422 | 452 |
| 423 RenderObject* FastTextAutosizer::nextChildSkippingChildrenOfBlocks(const RenderO
bject* current, const RenderObject* stayWithin) | 453 RenderObject* FastTextAutosizer::nextChildSkippingChildrenOfBlocks(const RenderO
bject* current, const RenderObject* stayWithin) |
| 424 { | 454 { |
| 425 if (current == stayWithin || !current->isRenderBlock()) | 455 if (current == stayWithin || !current->isRenderBlock()) |
| 426 return current->nextInPreOrder(stayWithin); | 456 return current->nextInPreOrder(stayWithin); |
| 427 return current->nextInPreOrderAfterChildren(stayWithin); | 457 return current->nextInPreOrderAfterChildren(stayWithin); |
| 428 } | 458 } |
| 429 | 459 |
| 430 } // namespace WebCore | 460 } // namespace WebCore |
| OLD | NEW |