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 | |
721 float FastTextAutosizer::clusterMultiplier(Cluster* cluster) | 704 float FastTextAutosizer::clusterMultiplier(Cluster* cluster) |
722 { | 705 { |
723 if (cluster->m_multiplier) | 706 if (cluster->m_multiplier) |
724 return cluster->m_multiplier; | 707 return cluster->m_multiplier; |
725 | 708 |
726 if (cluster->m_root->isTable() | 709 if (cluster->m_root->isTable() |
727 || isIndependentDescendant(cluster->m_root) | 710 || isIndependentDescendant(cluster->m_root) |
728 || isWiderOrNarrowerDescendant(cluster)) { | 711 || isWiderOrNarrowerDescendant(cluster)) { |
729 | 712 |
730 if (cluster->m_supercluster) { | 713 if (cluster->m_supercluster) { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
778 return false; | 761 return false; |
779 } | 762 } |
780 | 763 |
781 float FastTextAutosizer::superclusterMultiplier(Cluster* cluster) | 764 float FastTextAutosizer::superclusterMultiplier(Cluster* cluster) |
782 { | 765 { |
783 Supercluster* supercluster = cluster->m_supercluster; | 766 Supercluster* supercluster = cluster->m_supercluster; |
784 if (!supercluster->m_multiplier) { | 767 if (!supercluster->m_multiplier) { |
785 const BlockSet* roots = supercluster->m_roots; | 768 const BlockSet* roots = supercluster->m_roots; |
786 const RenderBlock* widthProvider; | 769 const RenderBlock* widthProvider; |
787 | 770 |
788 if (cluster->m_root->isTableCell()) { | 771 widthProvider = maxClusterWidthProvider(cluster->m_supercluster, cluster
->m_root); |
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 } | |
796 | 772 |
797 supercluster->m_multiplier = anyClusterHasEnoughTextToAutosize(roots, wi
dthProvider) | 773 supercluster->m_multiplier = anyClusterHasEnoughTextToAutosize(roots, wi
dthProvider) |
798 ? multiplierFromBlock(widthProvider) : 1.0f; | 774 ? multiplierFromBlock(widthProvider) : 1.0f; |
799 } | 775 } |
800 ASSERT(supercluster->m_multiplier); | 776 ASSERT(supercluster->m_multiplier); |
801 return supercluster->m_multiplier; | 777 return supercluster->m_multiplier; |
802 } | 778 } |
803 | 779 |
804 const RenderBlock* FastTextAutosizer::clusterWidthProvider(const RenderBlock* ro
ot) | 780 const RenderBlock* FastTextAutosizer::clusterWidthProvider(const RenderBlock* ro
ot) |
805 { | 781 { |
806 if (root->isTable() || root->isTableCell()) | 782 if (root->isTable() || root->isTableCell()) |
807 return root; | 783 return root; |
808 | 784 |
809 return deepestBlockContainingAllText(root); | 785 return deepestBlockContainingAllText(root); |
810 } | 786 } |
811 | 787 |
| 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 |
812 float FastTextAutosizer::widthFromBlock(const RenderBlock* block) | 807 float FastTextAutosizer::widthFromBlock(const RenderBlock* block) |
813 { | 808 { |
814 if (block->isTable()) { | 809 if (block->isTable()) { |
815 RenderBlock* containingBlock = block->containingBlock(); | 810 RenderBlock* containingBlock = block->containingBlock(); |
816 ASSERT(block->containingBlock()); | 811 ASSERT(block->containingBlock()); |
817 if (block->style()->logicalWidth().isSpecified()) | 812 if (block->style()->logicalWidth().isSpecified()) |
818 return floatValueForLength(block->style()->logicalWidth(), containin
gBlock->contentLogicalWidth().toFloat()); | 813 return floatValueForLength(block->style()->logicalWidth(), containin
gBlock->contentLogicalWidth().toFloat()); |
819 return containingBlock->contentLogicalWidth().toFloat(); | 814 return containingBlock->contentLogicalWidth().toFloat(); |
820 } | 815 } |
821 return block->contentLogicalWidth().toFloat(); | 816 return block->contentLogicalWidth().toFloat(); |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1078 FastTextAutosizer::DeferUpdatePageInfo::~DeferUpdatePageInfo() | 1073 FastTextAutosizer::DeferUpdatePageInfo::~DeferUpdatePageInfo() |
1079 { | 1074 { |
1080 if (FastTextAutosizer* textAutosizer = m_mainFrame->document()->fastTextAuto
sizer()) { | 1075 if (FastTextAutosizer* textAutosizer = m_mainFrame->document()->fastTextAuto
sizer()) { |
1081 ASSERT(textAutosizer->m_updatePageInfoDeferred); | 1076 ASSERT(textAutosizer->m_updatePageInfoDeferred); |
1082 textAutosizer->m_updatePageInfoDeferred = false; | 1077 textAutosizer->m_updatePageInfoDeferred = false; |
1083 textAutosizer->updatePageInfoInAllFrames(); | 1078 textAutosizer->updatePageInfoInAllFrames(); |
1084 } | 1079 } |
1085 } | 1080 } |
1086 | 1081 |
1087 } // namespace WebCore | 1082 } // namespace WebCore |
OLD | NEW |