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 683 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
694 | 694 |
695 SuperclusterMap::AddResult addResult = m_superclusters.add(fingerprint, Pass
OwnPtr<Supercluster>()); | 695 SuperclusterMap::AddResult addResult = m_superclusters.add(fingerprint, Pass
OwnPtr<Supercluster>()); |
696 if (!addResult.isNewEntry) | 696 if (!addResult.isNewEntry) |
697 return addResult.storedValue->value.get(); | 697 return addResult.storedValue->value.get(); |
698 | 698 |
699 Supercluster* supercluster = new Supercluster(roots); | 699 Supercluster* supercluster = new Supercluster(roots); |
700 addResult.storedValue->value = adoptPtr(supercluster); | 700 addResult.storedValue->value = adoptPtr(supercluster); |
701 return supercluster; | 701 return supercluster; |
702 } | 702 } |
703 | 703 |
| 704 const RenderBlock* FastTextAutosizer::deepestCommonAncestor(BlockSet& blocks) |
| 705 { |
| 706 // Find the lowest common ancestor of blocks. |
| 707 // Note: this could be improved to not be O(b*h) for b blocks and tree heigh
t h. |
| 708 HashCountedSet<const RenderBlock*> ancestors; |
| 709 for (BlockSet::iterator it = blocks.begin(); it != blocks.end(); ++it) { |
| 710 for (const RenderBlock* block = (*it); block; block = block->containingB
lock()) { |
| 711 ancestors.add(block); |
| 712 // The first ancestor that has all of the blocks as children wins. |
| 713 if (ancestors.count(block) == blocks.size()) |
| 714 return block; |
| 715 } |
| 716 } |
| 717 ASSERT_NOT_REACHED(); |
| 718 return 0; |
| 719 } |
| 720 |
704 float FastTextAutosizer::clusterMultiplier(Cluster* cluster) | 721 float FastTextAutosizer::clusterMultiplier(Cluster* cluster) |
705 { | 722 { |
706 if (cluster->m_multiplier) | 723 if (cluster->m_multiplier) |
707 return cluster->m_multiplier; | 724 return cluster->m_multiplier; |
708 | 725 |
709 if (cluster->m_root->isTable() | 726 if (cluster->m_root->isTable() |
710 || isIndependentDescendant(cluster->m_root) | 727 || isIndependentDescendant(cluster->m_root) |
711 || isWiderOrNarrowerDescendant(cluster)) { | 728 || isWiderOrNarrowerDescendant(cluster)) { |
712 | 729 |
713 if (cluster->m_supercluster) { | 730 if (cluster->m_supercluster) { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
761 return false; | 778 return false; |
762 } | 779 } |
763 | 780 |
764 float FastTextAutosizer::superclusterMultiplier(Cluster* cluster) | 781 float FastTextAutosizer::superclusterMultiplier(Cluster* cluster) |
765 { | 782 { |
766 Supercluster* supercluster = cluster->m_supercluster; | 783 Supercluster* supercluster = cluster->m_supercluster; |
767 if (!supercluster->m_multiplier) { | 784 if (!supercluster->m_multiplier) { |
768 const BlockSet* roots = supercluster->m_roots; | 785 const BlockSet* roots = supercluster->m_roots; |
769 const RenderBlock* widthProvider; | 786 const RenderBlock* widthProvider; |
770 | 787 |
771 widthProvider = maxClusterWidthProvider(cluster->m_supercluster, cluster
->m_root); | 788 if (cluster->m_root->isTableCell()) { |
| 789 widthProvider = clusterWidthProvider(cluster->m_root); |
| 790 } else { |
| 791 BlockSet widthProviders; |
| 792 for (BlockSet::iterator it = roots->begin(); it != roots->end(); ++i
t) |
| 793 widthProviders.add(clusterWidthProvider(*it)); |
| 794 widthProvider = deepestCommonAncestor(widthProviders); |
| 795 } |
772 | 796 |
773 supercluster->m_multiplier = anyClusterHasEnoughTextToAutosize(roots, wi
dthProvider) | 797 supercluster->m_multiplier = anyClusterHasEnoughTextToAutosize(roots, wi
dthProvider) |
774 ? multiplierFromBlock(widthProvider) : 1.0f; | 798 ? multiplierFromBlock(widthProvider) : 1.0f; |
775 } | 799 } |
776 ASSERT(supercluster->m_multiplier); | 800 ASSERT(supercluster->m_multiplier); |
777 return supercluster->m_multiplier; | 801 return supercluster->m_multiplier; |
778 } | 802 } |
779 | 803 |
780 const RenderBlock* FastTextAutosizer::clusterWidthProvider(const RenderBlock* ro
ot) | 804 const RenderBlock* FastTextAutosizer::clusterWidthProvider(const RenderBlock* ro
ot) |
781 { | 805 { |
782 if (root->isTable() || root->isTableCell()) | 806 if (root->isTable() || root->isTableCell()) |
783 return root; | 807 return root; |
784 | 808 |
785 return deepestBlockContainingAllText(root); | 809 return deepestBlockContainingAllText(root); |
786 } | 810 } |
787 | 811 |
788 | |
789 const RenderBlock* FastTextAutosizer::maxClusterWidthProvider(const Supercluster
* supercluster, const RenderBlock* currentRoot) | |
790 { | |
791 float maxWidth = 0; | |
792 const RenderBlock* result = 0; | |
793 const BlockSet* roots = supercluster->m_roots; | |
794 for (BlockSet::iterator it = roots->begin(); it != roots->end(); ++it) { | |
795 const RenderBlock* widthProvider = clusterWidthProvider(*it); | |
796 if (widthProvider != currentRoot && widthProvider->needsLayout()) | |
797 continue; | |
798 float width = widthFromBlock(widthProvider); | |
799 if (width > maxWidth) { | |
800 maxWidth = width; | |
801 result = widthProvider; | |
802 } | |
803 } | |
804 return result; | |
805 } | |
806 | |
807 float FastTextAutosizer::widthFromBlock(const RenderBlock* block) | 812 float FastTextAutosizer::widthFromBlock(const RenderBlock* block) |
808 { | 813 { |
809 if (block->isTable()) { | 814 if (block->isTable()) { |
810 RenderBlock* containingBlock = block->containingBlock(); | 815 RenderBlock* containingBlock = block->containingBlock(); |
811 ASSERT(block->containingBlock()); | 816 ASSERT(block->containingBlock()); |
812 if (block->style()->logicalWidth().isSpecified()) | 817 if (block->style()->logicalWidth().isSpecified()) |
813 return floatValueForLength(block->style()->logicalWidth(), containin
gBlock->contentLogicalWidth().toFloat()); | 818 return floatValueForLength(block->style()->logicalWidth(), containin
gBlock->contentLogicalWidth().toFloat()); |
814 return containingBlock->contentLogicalWidth().toFloat(); | 819 return containingBlock->contentLogicalWidth().toFloat(); |
815 } | 820 } |
816 return block->contentLogicalWidth().toFloat(); | 821 return block->contentLogicalWidth().toFloat(); |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1073 FastTextAutosizer::DeferUpdatePageInfo::~DeferUpdatePageInfo() | 1078 FastTextAutosizer::DeferUpdatePageInfo::~DeferUpdatePageInfo() |
1074 { | 1079 { |
1075 if (FastTextAutosizer* textAutosizer = m_mainFrame->document()->fastTextAuto
sizer()) { | 1080 if (FastTextAutosizer* textAutosizer = m_mainFrame->document()->fastTextAuto
sizer()) { |
1076 ASSERT(textAutosizer->m_updatePageInfoDeferred); | 1081 ASSERT(textAutosizer->m_updatePageInfoDeferred); |
1077 textAutosizer->m_updatePageInfoDeferred = false; | 1082 textAutosizer->m_updatePageInfoDeferred = false; |
1078 textAutosizer->updatePageInfoInAllFrames(); | 1083 textAutosizer->updatePageInfoInAllFrames(); |
1079 } | 1084 } |
1080 } | 1085 } |
1081 | 1086 |
1082 } // namespace WebCore | 1087 } // namespace WebCore |
OLD | NEW |