| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 if (block->isRenderView()) | 90 if (block->isRenderView()) |
| 89 prepareRenderViewInfo(toRenderView(block)); | 91 prepareRenderViewInfo(toRenderView(block)); |
| 90 | 92 |
| 91 if (Cluster* cluster = maybeGetOrCreateCluster(block)) | 93 if (Cluster* cluster = maybeGetOrCreateCluster(block)) |
| 92 m_clusterStack.append(cluster); | 94 m_clusterStack.append(cluster); |
| 93 | 95 |
| 94 if (block->childrenInline()) | 96 if (block->childrenInline()) |
| 95 inflate(block); | 97 inflate(block); |
| 96 } | 98 } |
| 97 | 99 |
| 100 void FastTextAutosizer::inflateListItem(RenderListItem* listItem, RenderListMark
er* listItemMarker) |
| 101 { |
| 102 if (!enabled()) |
| 103 return; |
| 104 #ifndef NDEBUG |
| 105 m_blocksThatHaveBegunLayout.add(listItem); |
| 106 #endif |
| 107 |
| 108 Cluster* cluster = currentCluster(); |
| 109 // FIXME: Why is this check needed? |
| 110 if (!cluster) |
| 111 return; |
| 112 |
| 113 // Force the LI to be inside the DBCAT when computing the multiplier. |
| 114 // This guarantees that the DBCAT has entered layout, so we can ask for its
width. |
| 115 // It also makes sense because the list marker is autosized like a text node
. |
| 116 float multiplier = clusterMultiplier(cluster); |
| 117 |
| 118 applyMultiplier(listItem, multiplier); |
| 119 applyMultiplier(listItemMarker, multiplier); |
| 120 } |
| 121 |
| 98 void FastTextAutosizer::endLayout(RenderBlock* block) | 122 void FastTextAutosizer::endLayout(RenderBlock* block) |
| 99 { | 123 { |
| 100 if (!enabled()) | 124 if (!enabled()) |
| 101 return; | 125 return; |
| 102 #ifndef NDEBUG | 126 #ifndef NDEBUG |
| 103 m_blocksThatHaveBegunLayout.remove(block); | 127 m_blocksThatHaveBegunLayout.remove(block); |
| 104 #endif | 128 #endif |
| 105 | 129 |
| 106 Cluster* cluster = currentCluster(); | 130 Cluster* cluster = currentCluster(); |
| 107 if (cluster && cluster->m_root == block) | 131 if (cluster && cluster->m_root == block) |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 float textBlockWidth = deepestBlockWithAllText->contentLogicalWi
dth(); | 319 float textBlockWidth = deepestBlockWithAllText->contentLogicalWi
dth(); |
| 296 float multiplier = min(textBlockWidth, static_cast<float>(m_layo
utWidth)) / m_frameWidth; | 320 float multiplier = min(textBlockWidth, static_cast<float>(m_layo
utWidth)) / m_frameWidth; |
| 297 cluster->m_multiplier = max(m_baseMultiplier * multiplier, 1.0f)
; | 321 cluster->m_multiplier = max(m_baseMultiplier * multiplier, 1.0f)
; |
| 298 } else { | 322 } else { |
| 299 cluster->m_multiplier = 1.0f; | 323 cluster->m_multiplier = 1.0f; |
| 300 } | 324 } |
| 301 } else { | 325 } else { |
| 302 cluster->m_multiplier = cluster->m_parent ? clusterMultiplier(cluste
r->m_parent) : 1.0f; | 326 cluster->m_multiplier = cluster->m_parent ? clusterMultiplier(cluste
r->m_parent) : 1.0f; |
| 303 } | 327 } |
| 304 } | 328 } |
| 329 ASSERT(cluster->m_multiplier); |
| 305 return cluster->m_multiplier; | 330 return cluster->m_multiplier; |
| 306 } | 331 } |
| 307 | 332 |
| 308 // FIXME: Refactor this to look more like FastTextAutosizer::deepestCommonAncest
or. This is copied | 333 // FIXME: Refactor this to look more like FastTextAutosizer::deepestCommonAncest
or. This is copied |
| 309 // from TextAutosizer::findDeepestBlockContainingAllText. | 334 // from TextAutosizer::findDeepestBlockContainingAllText. |
| 310 const RenderBlock* FastTextAutosizer::deepestBlockContainingAllText(Cluster* clu
ster) | 335 const RenderBlock* FastTextAutosizer::deepestBlockContainingAllText(Cluster* clu
ster) |
| 311 { | 336 { |
| 312 if (cluster->m_deepestBlockContainingAllText) | 337 if (cluster->m_deepestBlockContainingAllText) |
| 313 return cluster->m_deepestBlockContainingAllText; | 338 return cluster->m_deepestBlockContainingAllText; |
| 314 | 339 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 // its text node's lowest common ancestor as isAutosizingCluster would have
made them into their | 372 // its text node's lowest common ancestor as isAutosizingCluster would have
made them into their |
| 348 // own independent cluster. | 373 // own independent cluster. |
| 349 const RenderBlock* containingBlock = firstNode->containingBlock(); | 374 const RenderBlock* containingBlock = firstNode->containingBlock(); |
| 350 ASSERT(containingBlock->isDescendantOf(cluster->m_root)); | 375 ASSERT(containingBlock->isDescendantOf(cluster->m_root)); |
| 351 | 376 |
| 352 return cluster->m_deepestBlockContainingAllText = containingBlock; | 377 return cluster->m_deepestBlockContainingAllText = containingBlock; |
| 353 } | 378 } |
| 354 | 379 |
| 355 const RenderObject* FastTextAutosizer::findTextLeaf(const RenderObject* parent,
size_t& depth, TextLeafSearch firstOrLast) | 380 const RenderObject* FastTextAutosizer::findTextLeaf(const RenderObject* parent,
size_t& depth, TextLeafSearch firstOrLast) |
| 356 { | 381 { |
| 382 // List items are treated as text due to the marker. |
| 383 // The actual renderer for the marker (RenderListMarker) may not be in the t
ree yet since it is added during layout. |
| 384 if (parent->isListItem()) |
| 385 return parent; |
| 386 |
| 357 if (parent->isEmpty()) | 387 if (parent->isEmpty()) |
| 358 return parent->isText() ? parent : 0; | 388 return parent->isText() ? parent : 0; |
| 359 | 389 |
| 360 ++depth; | 390 ++depth; |
| 361 const RenderObject* child = (firstOrLast == First) ? parent->firstChild() :
parent->lastChild(); | 391 const RenderObject* child = (firstOrLast == First) ? parent->firstChild() :
parent->lastChild(); |
| 362 while (child) { | 392 while (child) { |
| 363 // Note: At this point clusters may not have been created for these bloc
ks so we cannot rely | 393 // Note: At this point clusters may not have been created for these bloc
ks so we cannot rely |
| 364 // on m_clusters. Instead, we use a best-guess about whether the b
lock will become a cluster. | 394 // on m_clusters. Instead, we use a best-guess about whether the b
lock will become a cluster. |
| 365 if (!TextAutosizer::isAutosizingContainer(child) || !TextAutosizer::isIn
dependentDescendant(toRenderBlock(child))) { | 395 if (!TextAutosizer::isAutosizingContainer(child) || !TextAutosizer::isIn
dependentDescendant(toRenderBlock(child))) { |
| 366 const RenderObject* leaf = findTextLeaf(child, depth, firstOrLast); | 396 const RenderObject* leaf = findTextLeaf(child, depth, firstOrLast); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 } | 478 } |
| 449 | 479 |
| 450 RenderObject* FastTextAutosizer::nextChildSkippingChildrenOfBlocks(const RenderO
bject* current, const RenderObject* stayWithin) | 480 RenderObject* FastTextAutosizer::nextChildSkippingChildrenOfBlocks(const RenderO
bject* current, const RenderObject* stayWithin) |
| 451 { | 481 { |
| 452 if (current == stayWithin || !current->isRenderBlock()) | 482 if (current == stayWithin || !current->isRenderBlock()) |
| 453 return current->nextInPreOrder(stayWithin); | 483 return current->nextInPreOrder(stayWithin); |
| 454 return current->nextInPreOrderAfterChildren(stayWithin); | 484 return current->nextInPreOrderAfterChildren(stayWithin); |
| 455 } | 485 } |
| 456 | 486 |
| 457 } // namespace WebCore | 487 } // namespace WebCore |
| OLD | NEW |