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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 !layoutObject->style()->isDisplayReplacedType()) | 97 !layoutObject->style()->isDisplayReplacedType()) |
98 return false; | 98 return false; |
99 if (layoutObject->isListItem()) | 99 if (layoutObject->isListItem()) |
100 return (layoutObject->isFloating() || | 100 return (layoutObject->isFloating() || |
101 layoutObject->isOutOfFlowPositioned()); | 101 layoutObject->isOutOfFlowPositioned()); |
102 | 102 |
103 return true; | 103 return true; |
104 } | 104 } |
105 | 105 |
106 static bool isIndependentDescendant(const LayoutBlock* layoutObject) { | 106 static bool isIndependentDescendant(const LayoutBlock* layoutObject) { |
107 ASSERT(isPotentialClusterRoot(layoutObject)); | 107 DCHECK(isPotentialClusterRoot(layoutObject)); |
108 | 108 |
109 LayoutBlock* containingBlock = layoutObject->containingBlock(); | 109 LayoutBlock* containingBlock = layoutObject->containingBlock(); |
110 return layoutObject->isLayoutView() || layoutObject->isFloating() || | 110 return layoutObject->isLayoutView() || layoutObject->isFloating() || |
111 layoutObject->isOutOfFlowPositioned() || layoutObject->isTableCell() || | 111 layoutObject->isOutOfFlowPositioned() || layoutObject->isTableCell() || |
112 layoutObject->isTableCaption() || | 112 layoutObject->isTableCaption() || |
113 layoutObject->isFlexibleBoxIncludingDeprecated() || | 113 layoutObject->isFlexibleBoxIncludingDeprecated() || |
114 (containingBlock && | 114 (containingBlock && |
115 containingBlock->isHorizontalWritingMode() != | 115 containingBlock->isHorizontalWritingMode() != |
116 layoutObject->isHorizontalWritingMode()) || | 116 layoutObject->isHorizontalWritingMode()) || |
117 layoutObject->style()->isDisplayReplacedType() || | 117 layoutObject->style()->isDisplayReplacedType() || |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 m_pageInfo(), | 237 m_pageInfo(), |
238 m_updatePageInfoDeferred(false) { | 238 m_updatePageInfoDeferred(false) { |
239 } | 239 } |
240 | 240 |
241 TextAutosizer::~TextAutosizer() {} | 241 TextAutosizer::~TextAutosizer() {} |
242 | 242 |
243 void TextAutosizer::record(LayoutBlock* block) { | 243 void TextAutosizer::record(LayoutBlock* block) { |
244 if (!m_pageInfo.m_settingEnabled) | 244 if (!m_pageInfo.m_settingEnabled) |
245 return; | 245 return; |
246 | 246 |
247 ASSERT(!m_blocksThatHaveBegunLayout.contains(block)); | 247 #if DCHECK_IS_ON() |
| 248 DCHECK(!m_blocksThatHaveBegunLayout.contains(block)); |
| 249 #endif |
248 if (!classifyBlock(block, INDEPENDENT | EXPLICIT_WIDTH)) { | 250 if (!classifyBlock(block, INDEPENDENT | EXPLICIT_WIDTH)) { |
249 // !everHadLayout() means the object hasn't layout yet | 251 // !everHadLayout() means the object hasn't layout yet |
250 // which means this object is new added. | 252 // which means this object is new added. |
251 // We only deal with new added block here. | 253 // We only deal with new added block here. |
252 // If parent is new added, no need to check its children. | 254 // If parent is new added, no need to check its children. |
253 LayoutObject* parent = getParent(block); | 255 LayoutObject* parent = getParent(block); |
254 if (!block->everHadLayout() && parent && parent->everHadLayout()) | 256 if (!block->everHadLayout() && parent && parent->everHadLayout()) |
255 markSuperclusterForConsistencyCheck(parent); | 257 markSuperclusterForConsistencyCheck(parent); |
256 return; | 258 return; |
257 } | 259 } |
(...skipping 10 matching lines...) Expand all Loading... |
268 return; | 270 return; |
269 LayoutObject* parent = getParent(text); | 271 LayoutObject* parent = getParent(text); |
270 if (parent && parent->everHadLayout()) | 272 if (parent && parent->everHadLayout()) |
271 markSuperclusterForConsistencyCheck(parent); | 273 markSuperclusterForConsistencyCheck(parent); |
272 } | 274 } |
273 | 275 |
274 void TextAutosizer::destroy(LayoutBlock* block) { | 276 void TextAutosizer::destroy(LayoutBlock* block) { |
275 if (!m_pageInfo.m_settingEnabled && !m_fingerprintMapper.hasFingerprints()) | 277 if (!m_pageInfo.m_settingEnabled && !m_fingerprintMapper.hasFingerprints()) |
276 return; | 278 return; |
277 | 279 |
278 ASSERT(!m_blocksThatHaveBegunLayout.contains(block)); | 280 #if DCHECK_IS_ON() |
| 281 DCHECK(!m_blocksThatHaveBegunLayout.contains(block)); |
| 282 #endif |
279 | 283 |
280 if (m_fingerprintMapper.remove(block) && m_firstBlockToBeginLayout) { | 284 if (m_fingerprintMapper.remove(block) && m_firstBlockToBeginLayout) { |
281 // LayoutBlock with a fingerprint was destroyed during layout. | 285 // LayoutBlock with a fingerprint was destroyed during layout. |
282 // Clear the cluster stack and the supercluster map to avoid stale pointers. | 286 // Clear the cluster stack and the supercluster map to avoid stale pointers. |
283 // Speculative fix for http://crbug.com/369485. | 287 // Speculative fix for http://crbug.com/369485. |
284 m_firstBlockToBeginLayout = nullptr; | 288 m_firstBlockToBeginLayout = nullptr; |
285 m_clusterStack.clear(); | 289 m_clusterStack.clear(); |
286 } | 290 } |
287 } | 291 } |
288 | 292 |
(...skipping 27 matching lines...) Expand all Loading... |
316 #if DCHECK_IS_ON() | 320 #if DCHECK_IS_ON() |
317 m_blocksThatHaveBegunLayout.insert(block); | 321 m_blocksThatHaveBegunLayout.insert(block); |
318 #endif | 322 #endif |
319 if (Cluster* cluster = maybeCreateCluster(block)) | 323 if (Cluster* cluster = maybeCreateCluster(block)) |
320 m_clusterStack.push_back(WTF::wrapUnique(cluster)); | 324 m_clusterStack.push_back(WTF::wrapUnique(cluster)); |
321 } | 325 } |
322 } | 326 } |
323 | 327 |
324 void TextAutosizer::beginLayout(LayoutBlock* block, | 328 void TextAutosizer::beginLayout(LayoutBlock* block, |
325 SubtreeLayoutScope* layouter) { | 329 SubtreeLayoutScope* layouter) { |
326 ASSERT(shouldHandleLayout()); | 330 DCHECK(shouldHandleLayout()); |
327 | 331 |
328 if (prepareForLayout(block) == StopLayout) | 332 if (prepareForLayout(block) == StopLayout) |
329 return; | 333 return; |
330 | 334 |
331 // Skip ruby's inner blocks, because these blocks already are inflated. | 335 // Skip ruby's inner blocks, because these blocks already are inflated. |
332 if (block->isRubyRun() || block->isRubyBase() || block->isRubyText()) | 336 if (block->isRubyRun() || block->isRubyBase() || block->isRubyText()) |
333 return; | 337 return; |
334 | 338 |
335 ASSERT(!m_clusterStack.isEmpty() || block->isLayoutView()); | 339 DCHECK(!m_clusterStack.isEmpty() || block->isLayoutView()); |
336 | 340 |
337 if (Cluster* cluster = maybeCreateCluster(block)) | 341 if (Cluster* cluster = maybeCreateCluster(block)) |
338 m_clusterStack.push_back(WTF::wrapUnique(cluster)); | 342 m_clusterStack.push_back(WTF::wrapUnique(cluster)); |
339 | 343 |
340 ASSERT(!m_clusterStack.isEmpty()); | 344 DCHECK(!m_clusterStack.isEmpty()); |
341 | 345 |
342 // Cells in auto-layout tables are handled separately by inflateAutoTable. | 346 // Cells in auto-layout tables are handled separately by inflateAutoTable. |
343 bool isAutoTableCell = | 347 bool isAutoTableCell = |
344 block->isTableCell() && | 348 block->isTableCell() && |
345 !toLayoutTableCell(block)->table()->style()->isFixedTableLayout(); | 349 !toLayoutTableCell(block)->table()->style()->isFixedTableLayout(); |
346 if (!isAutoTableCell && !m_clusterStack.isEmpty()) | 350 if (!isAutoTableCell && !m_clusterStack.isEmpty()) |
347 inflate(block, layouter); | 351 inflate(block, layouter); |
348 } | 352 } |
349 | 353 |
350 void TextAutosizer::inflateAutoTable(LayoutTable* table) { | 354 void TextAutosizer::inflateAutoTable(LayoutTable* table) { |
351 ASSERT(table); | 355 DCHECK(table); |
352 ASSERT(!table->style()->isFixedTableLayout()); | 356 DCHECK(!table->style()->isFixedTableLayout()); |
353 ASSERT(table->containingBlock()); | 357 DCHECK(table->containingBlock()); |
354 | 358 |
355 Cluster* cluster = currentCluster(); | 359 Cluster* cluster = currentCluster(); |
356 if (cluster->m_root != table) | 360 if (cluster->m_root != table) |
357 return; | 361 return; |
358 | 362 |
359 // Pre-inflate cells that have enough text so that their inflated preferred | 363 // Pre-inflate cells that have enough text so that their inflated preferred |
360 // widths will be used for column sizing. | 364 // widths will be used for column sizing. |
361 for (LayoutObject* section = table->firstChild(); section; | 365 for (LayoutObject* section = table->firstChild(); section; |
362 section = section->nextSibling()) { | 366 section = section->nextSibling()) { |
363 if (!section->isTableSection()) | 367 if (!section->isTableSection()) |
364 continue; | 368 continue; |
365 for (LayoutTableRow* row = toLayoutTableSection(section)->firstRow(); row; | 369 for (LayoutTableRow* row = toLayoutTableSection(section)->firstRow(); row; |
366 row = row->nextRow()) { | 370 row = row->nextRow()) { |
367 for (LayoutTableCell* cell = row->firstCell(); cell; | 371 for (LayoutTableCell* cell = row->firstCell(); cell; |
368 cell = cell->nextCell()) { | 372 cell = cell->nextCell()) { |
369 if (!cell->needsLayout()) | 373 if (!cell->needsLayout()) |
370 continue; | 374 continue; |
371 | 375 |
372 beginLayout(cell, nullptr); | 376 beginLayout(cell, nullptr); |
373 inflate(cell, nullptr, DescendToInnerBlocks); | 377 inflate(cell, nullptr, DescendToInnerBlocks); |
374 endLayout(cell); | 378 endLayout(cell); |
375 } | 379 } |
376 } | 380 } |
377 } | 381 } |
378 } | 382 } |
379 | 383 |
380 void TextAutosizer::endLayout(LayoutBlock* block) { | 384 void TextAutosizer::endLayout(LayoutBlock* block) { |
381 ASSERT(shouldHandleLayout()); | 385 DCHECK(shouldHandleLayout()); |
382 | 386 |
383 if (block == m_firstBlockToBeginLayout) { | 387 if (block == m_firstBlockToBeginLayout) { |
384 m_firstBlockToBeginLayout = nullptr; | 388 m_firstBlockToBeginLayout = nullptr; |
385 m_clusterStack.clear(); | 389 m_clusterStack.clear(); |
386 m_stylesRetainedDuringLayout.clear(); | 390 m_stylesRetainedDuringLayout.clear(); |
387 #if DCHECK_IS_ON() | 391 #if DCHECK_IS_ON() |
388 m_blocksThatHaveBegunLayout.clear(); | 392 m_blocksThatHaveBegunLayout.clear(); |
389 #endif | 393 #endif |
390 // Tables can create two layout scopes for the same block so the isEmpty | 394 // Tables can create two layout scopes for the same block so the isEmpty |
391 // check below is needed to guard against endLayout being called twice. | 395 // check below is needed to guard against endLayout being called twice. |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 } | 521 } |
518 | 522 |
519 // If we didn't add any supercluster, we should add one. | 523 // If we didn't add any supercluster, we should add one. |
520 if (lastSupercluster) { | 524 if (lastSupercluster) { |
521 m_fingerprintMapper.getPotentiallyInconsistentSuperclusters().insert( | 525 m_fingerprintMapper.getPotentiallyInconsistentSuperclusters().insert( |
522 lastSupercluster); | 526 lastSupercluster); |
523 } | 527 } |
524 } | 528 } |
525 | 529 |
526 void TextAutosizer::updatePageInfoInAllFrames() { | 530 void TextAutosizer::updatePageInfoInAllFrames() { |
527 ASSERT(!m_document->frame() || m_document->frame()->isMainFrame()); | 531 DCHECK(!m_document->frame() || m_document->frame()->isMainFrame()); |
528 | 532 |
529 for (Frame* frame = m_document->frame(); frame; | 533 for (Frame* frame = m_document->frame(); frame; |
530 frame = frame->tree().traverseNext()) { | 534 frame = frame->tree().traverseNext()) { |
531 if (!frame->isLocalFrame()) | 535 if (!frame->isLocalFrame()) |
532 continue; | 536 continue; |
533 | 537 |
534 Document* document = toLocalFrame(frame)->document(); | 538 Document* document = toLocalFrame(frame)->document(); |
535 // If document is being detached, skip updatePageInfo. | 539 // If document is being detached, skip updatePageInfo. |
536 if (!document || !document->isActive()) | 540 if (!document || !document->isActive()) |
537 continue; | 541 continue; |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
614 } else if (previousPageInfo.m_hasAutosized) { | 618 } else if (previousPageInfo.m_hasAutosized) { |
615 // If we are no longer autosizing the page, we won't do anything during the | 619 // If we are no longer autosizing the page, we won't do anything during the |
616 // next layout. Set all the multipliers back to 1 now. | 620 // next layout. Set all the multipliers back to 1 now. |
617 resetMultipliers(); | 621 resetMultipliers(); |
618 m_pageInfo.m_hasAutosized = false; | 622 m_pageInfo.m_hasAutosized = false; |
619 } | 623 } |
620 } | 624 } |
621 | 625 |
622 IntSize TextAutosizer::windowSize() const { | 626 IntSize TextAutosizer::windowSize() const { |
623 Page* page = m_document->page(); | 627 Page* page = m_document->page(); |
624 ASSERT(page); | 628 DCHECK(page); |
625 return page->visualViewport().size(); | 629 return page->visualViewport().size(); |
626 } | 630 } |
627 | 631 |
628 void TextAutosizer::resetMultipliers() { | 632 void TextAutosizer::resetMultipliers() { |
629 LayoutObject* layoutObject = | 633 LayoutObject* layoutObject = |
630 LayoutAPIShim::layoutObjectFrom(m_document->layoutViewItem()); | 634 LayoutAPIShim::layoutObjectFrom(m_document->layoutViewItem()); |
631 while (layoutObject) { | 635 while (layoutObject) { |
632 if (const ComputedStyle* style = layoutObject->style()) { | 636 if (const ComputedStyle* style = layoutObject->style()) { |
633 if (style->textAutosizingMultiplier() != 1) | 637 if (style->textAutosizingMultiplier() != 1) |
634 applyMultiplier(layoutObject, 1, nullptr, LayoutNeeded); | 638 applyMultiplier(layoutObject, 1, nullptr, LayoutNeeded); |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
792 sizeof data / sizeof(UChar)); | 796 sizeof data / sizeof(UChar)); |
793 } | 797 } |
794 | 798 |
795 TextAutosizer::Cluster* TextAutosizer::maybeCreateCluster(LayoutBlock* block) { | 799 TextAutosizer::Cluster* TextAutosizer::maybeCreateCluster(LayoutBlock* block) { |
796 BlockFlags flags = classifyBlock(block); | 800 BlockFlags flags = classifyBlock(block); |
797 if (!(flags & POTENTIAL_ROOT)) | 801 if (!(flags & POTENTIAL_ROOT)) |
798 return nullptr; | 802 return nullptr; |
799 | 803 |
800 Cluster* parentCluster = | 804 Cluster* parentCluster = |
801 m_clusterStack.isEmpty() ? nullptr : currentCluster(); | 805 m_clusterStack.isEmpty() ? nullptr : currentCluster(); |
802 ASSERT(parentCluster || block->isLayoutView()); | 806 DCHECK(parentCluster || block->isLayoutView()); |
803 | 807 |
804 // If a non-independent block would not alter the SUPPRESSING flag, it doesn't | 808 // If a non-independent block would not alter the SUPPRESSING flag, it doesn't |
805 // need to be a cluster. | 809 // need to be a cluster. |
806 bool parentSuppresses = | 810 bool parentSuppresses = |
807 parentCluster && (parentCluster->m_flags & SUPPRESSING); | 811 parentCluster && (parentCluster->m_flags & SUPPRESSING); |
808 if (!(flags & INDEPENDENT) && !(flags & EXPLICIT_WIDTH) && | 812 if (!(flags & INDEPENDENT) && !(flags & EXPLICIT_WIDTH) && |
809 !!(flags & SUPPRESSING) == parentSuppresses) | 813 !!(flags & SUPPRESSING) == parentSuppresses) |
810 return nullptr; | 814 return nullptr; |
811 | 815 |
812 bool isNewEntry = false; | 816 bool isNewEntry = false; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
856 multiplierFromBlock(clusterWidthProvider(cluster->m_root)); | 860 multiplierFromBlock(clusterWidthProvider(cluster->m_root)); |
857 else | 861 else |
858 cluster->m_multiplier = 1.0f; | 862 cluster->m_multiplier = 1.0f; |
859 } else { | 863 } else { |
860 cluster->m_multiplier = | 864 cluster->m_multiplier = |
861 cluster->m_parent ? clusterMultiplier(cluster->m_parent) : 1.0f; | 865 cluster->m_parent ? clusterMultiplier(cluster->m_parent) : 1.0f; |
862 if (cluster->m_supercluster) | 866 if (cluster->m_supercluster) |
863 cluster->m_supercluster->m_inheritParentMultiplier = InheritMultiplier; | 867 cluster->m_supercluster->m_inheritParentMultiplier = InheritMultiplier; |
864 } | 868 } |
865 | 869 |
866 ASSERT(cluster->m_multiplier); | 870 DCHECK(cluster->m_multiplier); |
867 return cluster->m_multiplier; | 871 return cluster->m_multiplier; |
868 } | 872 } |
869 | 873 |
870 bool TextAutosizer::superclusterHasEnoughTextToAutosize( | 874 bool TextAutosizer::superclusterHasEnoughTextToAutosize( |
871 Supercluster* supercluster, | 875 Supercluster* supercluster, |
872 const LayoutBlock* widthProvider, | 876 const LayoutBlock* widthProvider, |
873 const bool skipLayoutedNodes) { | 877 const bool skipLayoutedNodes) { |
874 if (supercluster->m_hasEnoughTextToAutosize != UnknownAmountOfText) | 878 if (supercluster->m_hasEnoughTextToAutosize != UnknownAmountOfText) |
875 return supercluster->m_hasEnoughTextToAutosize == HasEnoughText; | 879 return supercluster->m_hasEnoughTextToAutosize == HasEnoughText; |
876 | 880 |
(...skipping 13 matching lines...) Expand all Loading... |
890 Supercluster* supercluster = cluster->m_supercluster; | 894 Supercluster* supercluster = cluster->m_supercluster; |
891 if (!supercluster->m_multiplier) { | 895 if (!supercluster->m_multiplier) { |
892 const LayoutBlock* widthProvider = | 896 const LayoutBlock* widthProvider = |
893 maxClusterWidthProvider(cluster->m_supercluster, cluster->m_root); | 897 maxClusterWidthProvider(cluster->m_supercluster, cluster->m_root); |
894 CHECK(widthProvider); | 898 CHECK(widthProvider); |
895 supercluster->m_multiplier = | 899 supercluster->m_multiplier = |
896 superclusterHasEnoughTextToAutosize(supercluster, widthProvider, false) | 900 superclusterHasEnoughTextToAutosize(supercluster, widthProvider, false) |
897 ? multiplierFromBlock(widthProvider) | 901 ? multiplierFromBlock(widthProvider) |
898 : 1.0f; | 902 : 1.0f; |
899 } | 903 } |
900 ASSERT(supercluster->m_multiplier); | 904 DCHECK(supercluster->m_multiplier); |
901 return supercluster->m_multiplier; | 905 return supercluster->m_multiplier; |
902 } | 906 } |
903 | 907 |
904 const LayoutBlock* TextAutosizer::clusterWidthProvider( | 908 const LayoutBlock* TextAutosizer::clusterWidthProvider( |
905 const LayoutBlock* root) const { | 909 const LayoutBlock* root) const { |
906 if (root->isTable() || root->isTableCell()) | 910 if (root->isTable() || root->isTableCell()) |
907 return root; | 911 return root; |
908 | 912 |
909 return deepestBlockContainingAllText(root); | 913 return deepestBlockContainingAllText(root); |
910 } | 914 } |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
967 return width; | 971 return width; |
968 } | 972 } |
969 return 0; | 973 return 0; |
970 } | 974 } |
971 | 975 |
972 float TextAutosizer::multiplierFromBlock(const LayoutBlock* block) { | 976 float TextAutosizer::multiplierFromBlock(const LayoutBlock* block) { |
973 // If block->needsLayout() is false, it does not need to be in | 977 // If block->needsLayout() is false, it does not need to be in |
974 // m_blocksThatHaveBegunLayout. This can happen during layout of a positioned | 978 // m_blocksThatHaveBegunLayout. This can happen during layout of a positioned |
975 // object if the cluster's DBCAT is deeper than the positioned object's | 979 // object if the cluster's DBCAT is deeper than the positioned object's |
976 // containing block, and wasn't marked as needing layout. | 980 // containing block, and wasn't marked as needing layout. |
977 ASSERT(m_blocksThatHaveBegunLayout.contains(block) || !block->needsLayout()); | 981 #if DCHECK_IS_ON() |
978 | 982 DCHECK(m_blocksThatHaveBegunLayout.contains(block) || !block->needsLayout()); |
| 983 #endif |
979 // Block width, in CSS pixels. | 984 // Block width, in CSS pixels. |
980 float blockWidth = widthFromBlock(block); | 985 float blockWidth = widthFromBlock(block); |
981 float layoutWidth = | 986 float layoutWidth = |
982 std::min(blockWidth, static_cast<float>(m_pageInfo.m_layoutWidth)); | 987 std::min(blockWidth, static_cast<float>(m_pageInfo.m_layoutWidth)); |
983 float multiplier = | 988 float multiplier = |
984 m_pageInfo.m_frameWidth ? layoutWidth / m_pageInfo.m_frameWidth : 1.0f; | 989 m_pageInfo.m_frameWidth ? layoutWidth / m_pageInfo.m_frameWidth : 1.0f; |
985 multiplier *= m_pageInfo.m_accessibilityFontScaleFactor * | 990 multiplier *= m_pageInfo.m_accessibilityFontScaleFactor * |
986 m_pageInfo.m_deviceScaleAdjustment; | 991 m_pageInfo.m_deviceScaleAdjustment; |
987 return std::max(multiplier, 1.0f); | 992 return std::max(multiplier, 1.0f); |
988 } | 993 } |
(...skipping 10 matching lines...) Expand all Loading... |
999 // FIXME: Refactor this to look more like TextAutosizer::deepestCommonAncestor. | 1004 // FIXME: Refactor this to look more like TextAutosizer::deepestCommonAncestor. |
1000 const LayoutBlock* TextAutosizer::deepestBlockContainingAllText( | 1005 const LayoutBlock* TextAutosizer::deepestBlockContainingAllText( |
1001 const LayoutBlock* root) const { | 1006 const LayoutBlock* root) const { |
1002 size_t firstDepth = 0; | 1007 size_t firstDepth = 0; |
1003 const LayoutObject* firstTextLeaf = findTextLeaf(root, firstDepth, First); | 1008 const LayoutObject* firstTextLeaf = findTextLeaf(root, firstDepth, First); |
1004 if (!firstTextLeaf) | 1009 if (!firstTextLeaf) |
1005 return root; | 1010 return root; |
1006 | 1011 |
1007 size_t lastDepth = 0; | 1012 size_t lastDepth = 0; |
1008 const LayoutObject* lastTextLeaf = findTextLeaf(root, lastDepth, Last); | 1013 const LayoutObject* lastTextLeaf = findTextLeaf(root, lastDepth, Last); |
1009 ASSERT(lastTextLeaf); | 1014 DCHECK(lastTextLeaf); |
1010 | 1015 |
1011 // Equalize the depths if necessary. Only one of the while loops below will | 1016 // Equalize the depths if necessary. Only one of the while loops below will |
1012 // get executed. | 1017 // get executed. |
1013 const LayoutObject* firstNode = firstTextLeaf; | 1018 const LayoutObject* firstNode = firstTextLeaf; |
1014 const LayoutObject* lastNode = lastTextLeaf; | 1019 const LayoutObject* lastNode = lastTextLeaf; |
1015 while (firstDepth > lastDepth) { | 1020 while (firstDepth > lastDepth) { |
1016 firstNode = firstNode->parent(); | 1021 firstNode = firstNode->parent(); |
1017 --firstDepth; | 1022 --firstDepth; |
1018 } | 1023 } |
1019 while (lastDepth > firstDepth) { | 1024 while (lastDepth > firstDepth) { |
(...skipping 13 matching lines...) Expand all Loading... |
1033 | 1038 |
1034 // containingBlock() should never leave the cluster, since it only skips | 1039 // containingBlock() should never leave the cluster, since it only skips |
1035 // ancestors when finding the container of position:absolute/fixed blocks, and | 1040 // ancestors when finding the container of position:absolute/fixed blocks, and |
1036 // those cannot exist between a cluster and its text node's lowest common | 1041 // those cannot exist between a cluster and its text node's lowest common |
1037 // ancestor as isAutosizingCluster would have made them into their own | 1042 // ancestor as isAutosizingCluster would have made them into their own |
1038 // independent cluster. | 1043 // independent cluster. |
1039 const LayoutBlock* containingBlock = firstNode->containingBlock(); | 1044 const LayoutBlock* containingBlock = firstNode->containingBlock(); |
1040 if (!containingBlock) | 1045 if (!containingBlock) |
1041 return root; | 1046 return root; |
1042 | 1047 |
1043 ASSERT(containingBlock->isDescendantOf(root)); | 1048 DCHECK(containingBlock->isDescendantOf(root)); |
1044 return containingBlock; | 1049 return containingBlock; |
1045 } | 1050 } |
1046 | 1051 |
1047 const LayoutObject* TextAutosizer::findTextLeaf( | 1052 const LayoutObject* TextAutosizer::findTextLeaf( |
1048 const LayoutObject* parent, | 1053 const LayoutObject* parent, |
1049 size_t& depth, | 1054 size_t& depth, |
1050 TextLeafSearch firstOrLast) const { | 1055 TextLeafSearch firstOrLast) const { |
1051 // List items are treated as text due to the marker. | 1056 // List items are treated as text due to the marker. |
1052 if (parent->isListItem()) | 1057 if (parent->isListItem()) |
1053 return parent; | 1058 return parent; |
(...skipping 17 matching lines...) Expand all Loading... |
1071 } | 1076 } |
1072 --depth; | 1077 --depth; |
1073 | 1078 |
1074 return nullptr; | 1079 return nullptr; |
1075 } | 1080 } |
1076 | 1081 |
1077 void TextAutosizer::applyMultiplier(LayoutObject* layoutObject, | 1082 void TextAutosizer::applyMultiplier(LayoutObject* layoutObject, |
1078 float multiplier, | 1083 float multiplier, |
1079 SubtreeLayoutScope* layouter, | 1084 SubtreeLayoutScope* layouter, |
1080 RelayoutBehavior relayoutBehavior) { | 1085 RelayoutBehavior relayoutBehavior) { |
1081 ASSERT(layoutObject); | 1086 DCHECK(layoutObject); |
1082 ComputedStyle& currentStyle = layoutObject->mutableStyleRef(); | 1087 ComputedStyle& currentStyle = layoutObject->mutableStyleRef(); |
1083 if (!currentStyle.getTextSizeAdjust().isAuto()) { | 1088 if (!currentStyle.getTextSizeAdjust().isAuto()) { |
1084 // The accessibility font scale factor is applied by the autosizer so we | 1089 // The accessibility font scale factor is applied by the autosizer so we |
1085 // need to apply that scale factor on top of the text-size-adjust | 1090 // need to apply that scale factor on top of the text-size-adjust |
1086 // multiplier. Only apply the accessibility factor if the autosizer has | 1091 // multiplier. Only apply the accessibility factor if the autosizer has |
1087 // determined a multiplier should be applied so that text-size-adjust:none | 1092 // determined a multiplier should be applied so that text-size-adjust:none |
1088 // does not cause a multiplier to be applied when it wouldn't be otherwise. | 1093 // does not cause a multiplier to be applied when it wouldn't be otherwise. |
1089 bool shouldApplyAccessibilityFontScaleFactor = multiplier > 1; | 1094 bool shouldApplyAccessibilityFontScaleFactor = multiplier > 1; |
1090 multiplier = currentStyle.getTextSizeAdjust().multiplier(); | 1095 multiplier = currentStyle.getTextSizeAdjust().multiplier(); |
1091 if (shouldApplyAccessibilityFontScaleFactor) | 1096 if (shouldApplyAccessibilityFontScaleFactor) |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1131 layoutObject->clearBaseComputedStyle(); | 1136 layoutObject->clearBaseComputedStyle(); |
1132 } | 1137 } |
1133 | 1138 |
1134 bool TextAutosizer::isWiderOrNarrowerDescendant(Cluster* cluster) { | 1139 bool TextAutosizer::isWiderOrNarrowerDescendant(Cluster* cluster) { |
1135 // FIXME: Why do we return true when hasExplicitWidth returns false?? | 1140 // FIXME: Why do we return true when hasExplicitWidth returns false?? |
1136 if (!cluster->m_parent || !hasExplicitWidth(cluster->m_root)) | 1141 if (!cluster->m_parent || !hasExplicitWidth(cluster->m_root)) |
1137 return true; | 1142 return true; |
1138 | 1143 |
1139 const LayoutBlock* parentDeepestBlockContainingAllText = | 1144 const LayoutBlock* parentDeepestBlockContainingAllText = |
1140 deepestBlockContainingAllText(cluster->m_parent); | 1145 deepestBlockContainingAllText(cluster->m_parent); |
1141 ASSERT(m_blocksThatHaveBegunLayout.contains(cluster->m_root)); | 1146 #if DCHECK_IS_ON() |
1142 ASSERT(m_blocksThatHaveBegunLayout.contains( | 1147 DCHECK(m_blocksThatHaveBegunLayout.contains(cluster->m_root)); |
| 1148 DCHECK(m_blocksThatHaveBegunLayout.contains( |
1143 parentDeepestBlockContainingAllText)); | 1149 parentDeepestBlockContainingAllText)); |
| 1150 #endif |
1144 | 1151 |
1145 float contentWidth = cluster->m_root->contentLogicalWidth().toFloat(); | 1152 float contentWidth = cluster->m_root->contentLogicalWidth().toFloat(); |
1146 float clusterTextWidth = | 1153 float clusterTextWidth = |
1147 parentDeepestBlockContainingAllText->contentLogicalWidth().toFloat(); | 1154 parentDeepestBlockContainingAllText->contentLogicalWidth().toFloat(); |
1148 | 1155 |
1149 // Clusters with a root that is wider than the deepestBlockContainingAllText | 1156 // Clusters with a root that is wider than the deepestBlockContainingAllText |
1150 // of their parent autosize independently of their parent. | 1157 // of their parent autosize independently of their parent. |
1151 if (contentWidth > clusterTextWidth) | 1158 if (contentWidth > clusterTextWidth) |
1152 return true; | 1159 return true; |
1153 | 1160 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1186 // have an associated map from block -> fingerprint in m_fingerprints. | 1193 // have an associated map from block -> fingerprint in m_fingerprints. |
1187 ReverseFingerprintMap::iterator end = m_blocksForFingerprint.end(); | 1194 ReverseFingerprintMap::iterator end = m_blocksForFingerprint.end(); |
1188 for (ReverseFingerprintMap::iterator fingerprintIt = | 1195 for (ReverseFingerprintMap::iterator fingerprintIt = |
1189 m_blocksForFingerprint.begin(); | 1196 m_blocksForFingerprint.begin(); |
1190 fingerprintIt != end; ++fingerprintIt) { | 1197 fingerprintIt != end; ++fingerprintIt) { |
1191 Fingerprint fingerprint = fingerprintIt->key; | 1198 Fingerprint fingerprint = fingerprintIt->key; |
1192 BlockSet* blocks = fingerprintIt->value.get(); | 1199 BlockSet* blocks = fingerprintIt->value.get(); |
1193 for (BlockSet::iterator blockIt = blocks->begin(); blockIt != blocks->end(); | 1200 for (BlockSet::iterator blockIt = blocks->begin(); blockIt != blocks->end(); |
1194 ++blockIt) { | 1201 ++blockIt) { |
1195 const LayoutBlock* block = (*blockIt); | 1202 const LayoutBlock* block = (*blockIt); |
1196 ASSERT(m_fingerprints.at(block) == fingerprint); | 1203 DCHECK_EQ(m_fingerprints.at(block), fingerprint); |
1197 } | 1204 } |
1198 } | 1205 } |
1199 } | 1206 } |
1200 #endif | 1207 #endif |
1201 | 1208 |
1202 void TextAutosizer::FingerprintMapper::add(LayoutObject* layoutObject, | 1209 void TextAutosizer::FingerprintMapper::add(LayoutObject* layoutObject, |
1203 Fingerprint fingerprint) { | 1210 Fingerprint fingerprint) { |
1204 remove(layoutObject); | 1211 remove(layoutObject); |
1205 | 1212 |
1206 m_fingerprints.set(layoutObject, fingerprint); | 1213 m_fingerprints.set(layoutObject, fingerprint); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1278 } | 1285 } |
1279 | 1286 |
1280 TextAutosizer::LayoutScope::~LayoutScope() { | 1287 TextAutosizer::LayoutScope::~LayoutScope() { |
1281 if (m_textAutosizer) | 1288 if (m_textAutosizer) |
1282 m_textAutosizer->endLayout(m_block); | 1289 m_textAutosizer->endLayout(m_block); |
1283 } | 1290 } |
1284 | 1291 |
1285 TextAutosizer::TableLayoutScope::TableLayoutScope(LayoutTable* table) | 1292 TextAutosizer::TableLayoutScope::TableLayoutScope(LayoutTable* table) |
1286 : LayoutScope(table) { | 1293 : LayoutScope(table) { |
1287 if (m_textAutosizer) { | 1294 if (m_textAutosizer) { |
1288 ASSERT(m_textAutosizer->shouldHandleLayout()); | 1295 DCHECK(m_textAutosizer->shouldHandleLayout()); |
1289 m_textAutosizer->inflateAutoTable(table); | 1296 m_textAutosizer->inflateAutoTable(table); |
1290 } | 1297 } |
1291 } | 1298 } |
1292 | 1299 |
1293 TextAutosizer::DeferUpdatePageInfo::DeferUpdatePageInfo(Page* page) | 1300 TextAutosizer::DeferUpdatePageInfo::DeferUpdatePageInfo(Page* page) |
1294 : m_mainFrame(page->deprecatedLocalMainFrame()) { | 1301 : m_mainFrame(page->deprecatedLocalMainFrame()) { |
1295 if (TextAutosizer* textAutosizer = m_mainFrame->document()->textAutosizer()) { | 1302 if (TextAutosizer* textAutosizer = m_mainFrame->document()->textAutosizer()) { |
1296 ASSERT(!textAutosizer->m_updatePageInfoDeferred); | 1303 DCHECK(!textAutosizer->m_updatePageInfoDeferred); |
1297 textAutosizer->m_updatePageInfoDeferred = true; | 1304 textAutosizer->m_updatePageInfoDeferred = true; |
1298 } | 1305 } |
1299 } | 1306 } |
1300 | 1307 |
1301 TextAutosizer::DeferUpdatePageInfo::~DeferUpdatePageInfo() { | 1308 TextAutosizer::DeferUpdatePageInfo::~DeferUpdatePageInfo() { |
1302 if (TextAutosizer* textAutosizer = m_mainFrame->document()->textAutosizer()) { | 1309 if (TextAutosizer* textAutosizer = m_mainFrame->document()->textAutosizer()) { |
1303 ASSERT(textAutosizer->m_updatePageInfoDeferred); | 1310 DCHECK(textAutosizer->m_updatePageInfoDeferred); |
1304 textAutosizer->m_updatePageInfoDeferred = false; | 1311 textAutosizer->m_updatePageInfoDeferred = false; |
1305 textAutosizer->updatePageInfoInAllFrames(); | 1312 textAutosizer->updatePageInfoInAllFrames(); |
1306 } | 1313 } |
1307 } | 1314 } |
1308 | 1315 |
1309 float TextAutosizer::computeAutosizedFontSize(float specifiedSize, | 1316 float TextAutosizer::computeAutosizedFontSize(float specifiedSize, |
1310 float multiplier) { | 1317 float multiplier) { |
1311 DCHECK_GE(multiplier, 0); | 1318 DCHECK_GE(multiplier, 0); |
1312 | 1319 |
1313 // Somewhat arbitrary "pleasant" font size. | 1320 // Somewhat arbitrary "pleasant" font size. |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1371 } | 1378 } |
1372 } | 1379 } |
1373 potentiallyInconsistentSuperclusters.clear(); | 1380 potentiallyInconsistentSuperclusters.clear(); |
1374 } | 1381 } |
1375 | 1382 |
1376 DEFINE_TRACE(TextAutosizer) { | 1383 DEFINE_TRACE(TextAutosizer) { |
1377 visitor->trace(m_document); | 1384 visitor->trace(m_document); |
1378 } | 1385 } |
1379 | 1386 |
1380 } // namespace blink | 1387 } // namespace blink |
OLD | NEW |