| 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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 explanation.utf8().data(), pageInfo.utf8().data()))); | 114 explanation.utf8().data(), pageInfo.utf8().data()))); |
| 115 } | 115 } |
| 116 #endif | 116 #endif |
| 117 | 117 |
| 118 static const LayoutObject* parentElementLayoutObject(const LayoutObject* layoutO
bject) | 118 static const LayoutObject* parentElementLayoutObject(const LayoutObject* layoutO
bject) |
| 119 { | 119 { |
| 120 // At style recalc, the layoutObject's parent may not be attached, | 120 // At style recalc, the layoutObject's parent may not be attached, |
| 121 // so we need to obtain this from the DOM tree. | 121 // so we need to obtain this from the DOM tree. |
| 122 const Node* node = layoutObject->node(); | 122 const Node* node = layoutObject->node(); |
| 123 if (!node) | 123 if (!node) |
| 124 return 0; | 124 return nullptr; |
| 125 | 125 |
| 126 // FIXME: This should be using LayoutTreeBuilderTraversal::parent(). | 126 // FIXME: This should be using LayoutTreeBuilderTraversal::parent(). |
| 127 if (Element* parent = node->parentElement()) | 127 if (Element* parent = node->parentElement()) |
| 128 return parent->layoutObject(); | 128 return parent->layoutObject(); |
| 129 return 0; | 129 return nullptr; |
| 130 } | 130 } |
| 131 | 131 |
| 132 static bool isNonTextAreaFormControl(const LayoutObject* layoutObject) | 132 static bool isNonTextAreaFormControl(const LayoutObject* layoutObject) |
| 133 { | 133 { |
| 134 const Node* node = layoutObject ? layoutObject->node() : 0; | 134 const Node* node = layoutObject ? layoutObject->node() : nullptr; |
| 135 if (!node || !node->isElementNode()) | 135 if (!node || !node->isElementNode()) |
| 136 return false; | 136 return false; |
| 137 const Element* element = toElement(node); | 137 const Element* element = toElement(node); |
| 138 | 138 |
| 139 return (element->isFormControlElement() && !isHTMLTextAreaElement(element)); | 139 return (element->isFormControlElement() && !isHTMLTextAreaElement(element)); |
| 140 } | 140 } |
| 141 | 141 |
| 142 static bool isPotentialClusterRoot(const LayoutObject* layoutObject) | 142 static bool isPotentialClusterRoot(const LayoutObject* layoutObject) |
| 143 { | 143 { |
| 144 // "Potential cluster roots" are the smallest unit for which we can | 144 // "Potential cluster roots" are the smallest unit for which we can |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 | 271 |
| 272 static bool hasExplicitWidth(const LayoutBlock* block) | 272 static bool hasExplicitWidth(const LayoutBlock* block) |
| 273 { | 273 { |
| 274 // FIXME: This heuristic may need to be expanded to other ways a block can b
e wider or narrower | 274 // FIXME: This heuristic may need to be expanded to other ways a block can b
e wider or narrower |
| 275 // than its parent containing block. | 275 // than its parent containing block. |
| 276 return block->style() && block->style()->width().isSpecified(); | 276 return block->style() && block->style()->width().isSpecified(); |
| 277 } | 277 } |
| 278 | 278 |
| 279 TextAutosizer::TextAutosizer(const Document* document) | 279 TextAutosizer::TextAutosizer(const Document* document) |
| 280 : m_document(document) | 280 : m_document(document) |
| 281 , m_firstBlockToBeginLayout(0) | 281 , m_firstBlockToBeginLayout(nullptr) |
| 282 #if ENABLE(ASSERT) | 282 #if ENABLE(ASSERT) |
| 283 , m_blocksThatHaveBegunLayout() | 283 , m_blocksThatHaveBegunLayout() |
| 284 #endif | 284 #endif |
| 285 , m_superclusters() | 285 , m_superclusters() |
| 286 , m_clusterStack() | 286 , m_clusterStack() |
| 287 , m_fingerprintMapper() | 287 , m_fingerprintMapper() |
| 288 , m_pageInfo() | 288 , m_pageInfo() |
| 289 , m_updatePageInfoDeferred(false) | 289 , m_updatePageInfoDeferred(false) |
| 290 { | 290 { |
| 291 } | 291 } |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 } else if (!m_clusterStack.isEmpty() && currentCluster()->m_root == block) { | 416 } else if (!m_clusterStack.isEmpty() && currentCluster()->m_root == block) { |
| 417 m_clusterStack.removeLast(); | 417 m_clusterStack.removeLast(); |
| 418 } | 418 } |
| 419 } | 419 } |
| 420 | 420 |
| 421 float TextAutosizer::inflate(LayoutObject* parent, InflateBehavior behavior, flo
at multiplier) | 421 float TextAutosizer::inflate(LayoutObject* parent, InflateBehavior behavior, flo
at multiplier) |
| 422 { | 422 { |
| 423 Cluster* cluster = currentCluster(); | 423 Cluster* cluster = currentCluster(); |
| 424 bool hasTextChild = false; | 424 bool hasTextChild = false; |
| 425 | 425 |
| 426 LayoutObject* child = 0; | 426 LayoutObject* child = nullptr; |
| 427 if (parent->isLayoutBlock() && (parent->childrenInline() || behavior == Desc
endToInnerBlocks)) | 427 if (parent->isLayoutBlock() && (parent->childrenInline() || behavior == Desc
endToInnerBlocks)) |
| 428 child = toLayoutBlock(parent)->firstChild(); | 428 child = toLayoutBlock(parent)->firstChild(); |
| 429 else if (parent->isLayoutInline()) | 429 else if (parent->isLayoutInline()) |
| 430 child = toLayoutInline(parent)->firstChild(); | 430 child = toLayoutInline(parent)->firstChild(); |
| 431 | 431 |
| 432 while (child) { | 432 while (child) { |
| 433 if (child->isText()) { | 433 if (child->isText()) { |
| 434 hasTextChild = true; | 434 hasTextChild = true; |
| 435 // We only calculate this multiplier on-demand to ensure the parent
block of this text | 435 // We only calculate this multiplier on-demand to ensure the parent
block of this text |
| 436 // has entered layout. | 436 // has entered layout. |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 604 flags |= EXPLICIT_WIDTH; | 604 flags |= EXPLICIT_WIDTH; |
| 605 | 605 |
| 606 if ((mask & SUPPRESSING) && blockSuppressesAutosizing(block)) | 606 if ((mask & SUPPRESSING) && blockSuppressesAutosizing(block)) |
| 607 flags |= SUPPRESSING; | 607 flags |= SUPPRESSING; |
| 608 } | 608 } |
| 609 return flags; | 609 return flags; |
| 610 } | 610 } |
| 611 | 611 |
| 612 bool TextAutosizer::clusterWouldHaveEnoughTextToAutosize(const LayoutBlock* root
, const LayoutBlock* widthProvider) | 612 bool TextAutosizer::clusterWouldHaveEnoughTextToAutosize(const LayoutBlock* root
, const LayoutBlock* widthProvider) |
| 613 { | 613 { |
| 614 Cluster hypotheticalCluster(root, classifyBlock(root), 0); | 614 Cluster hypotheticalCluster(root, classifyBlock(root), nullptr); |
| 615 return clusterHasEnoughTextToAutosize(&hypotheticalCluster, widthProvider); | 615 return clusterHasEnoughTextToAutosize(&hypotheticalCluster, widthProvider); |
| 616 } | 616 } |
| 617 | 617 |
| 618 bool TextAutosizer::clusterHasEnoughTextToAutosize(Cluster* cluster, const Layou
tBlock* widthProvider) | 618 bool TextAutosizer::clusterHasEnoughTextToAutosize(Cluster* cluster, const Layou
tBlock* widthProvider) |
| 619 { | 619 { |
| 620 if (cluster->m_hasEnoughTextToAutosize != UnknownAmountOfText) | 620 if (cluster->m_hasEnoughTextToAutosize != UnknownAmountOfText) |
| 621 return cluster->m_hasEnoughTextToAutosize == HasEnoughText; | 621 return cluster->m_hasEnoughTextToAutosize == HasEnoughText; |
| 622 | 622 |
| 623 const LayoutBlock* root = cluster->m_root; | 623 const LayoutBlock* root = cluster->m_root; |
| 624 if (!widthProvider) | 624 if (!widthProvider) |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 707 | 707 |
| 708 return StringHasher::computeHash<UChar>( | 708 return StringHasher::computeHash<UChar>( |
| 709 static_cast<const UChar*>(static_cast<const void*>(&data)), | 709 static_cast<const UChar*>(static_cast<const void*>(&data)), |
| 710 sizeof data / sizeof(UChar)); | 710 sizeof data / sizeof(UChar)); |
| 711 } | 711 } |
| 712 | 712 |
| 713 TextAutosizer::Cluster* TextAutosizer::maybeCreateCluster(const LayoutBlock* blo
ck) | 713 TextAutosizer::Cluster* TextAutosizer::maybeCreateCluster(const LayoutBlock* blo
ck) |
| 714 { | 714 { |
| 715 BlockFlags flags = classifyBlock(block); | 715 BlockFlags flags = classifyBlock(block); |
| 716 if (!(flags & POTENTIAL_ROOT)) | 716 if (!(flags & POTENTIAL_ROOT)) |
| 717 return 0; | 717 return nullptr; |
| 718 | 718 |
| 719 Cluster* parentCluster = m_clusterStack.isEmpty() ? 0 : currentCluster(); | 719 Cluster* parentCluster = m_clusterStack.isEmpty() ? nullptr : currentCluster
(); |
| 720 ASSERT(parentCluster || block->isLayoutView()); | 720 ASSERT(parentCluster || block->isLayoutView()); |
| 721 | 721 |
| 722 // If a non-independent block would not alter the SUPPRESSING flag, it doesn
't need to be a cluster. | 722 // If a non-independent block would not alter the SUPPRESSING flag, it doesn
't need to be a cluster. |
| 723 bool parentSuppresses = parentCluster && (parentCluster->m_flags & SUPPRESSI
NG); | 723 bool parentSuppresses = parentCluster && (parentCluster->m_flags & SUPPRESSI
NG); |
| 724 if (!(flags & INDEPENDENT) && !(flags & EXPLICIT_WIDTH) && !!(flags & SUPPRE
SSING) == parentSuppresses) | 724 if (!(flags & INDEPENDENT) && !(flags & EXPLICIT_WIDTH) && !!(flags & SUPPRE
SSING) == parentSuppresses) |
| 725 return 0; | 725 return nullptr; |
| 726 | 726 |
| 727 Cluster* cluster = new Cluster(block, flags, parentCluster, getSupercluster(
block)); | 727 Cluster* cluster = new Cluster(block, flags, parentCluster, getSupercluster(
block)); |
| 728 #ifdef AUTOSIZING_DOM_DEBUG_INFO | 728 #ifdef AUTOSIZING_DOM_DEBUG_INFO |
| 729 // Non-SUPPRESSING clusters are annotated in clusterMultiplier. | 729 // Non-SUPPRESSING clusters are annotated in clusterMultiplier. |
| 730 if (flags & SUPPRESSING) | 730 if (flags & SUPPRESSING) |
| 731 writeClusterDebugInfo(cluster); | 731 writeClusterDebugInfo(cluster); |
| 732 #endif | 732 #endif |
| 733 return cluster; | 733 return cluster; |
| 734 } | 734 } |
| 735 | 735 |
| 736 TextAutosizer::Supercluster* TextAutosizer::getSupercluster(const LayoutBlock* b
lock) | 736 TextAutosizer::Supercluster* TextAutosizer::getSupercluster(const LayoutBlock* b
lock) |
| 737 { | 737 { |
| 738 Fingerprint fingerprint = m_fingerprintMapper.get(block); | 738 Fingerprint fingerprint = m_fingerprintMapper.get(block); |
| 739 if (!fingerprint) | 739 if (!fingerprint) |
| 740 return 0; | 740 return nullptr; |
| 741 | 741 |
| 742 BlockSet* roots = m_fingerprintMapper.getTentativeClusterRoots(fingerprint); | 742 BlockSet* roots = m_fingerprintMapper.getTentativeClusterRoots(fingerprint); |
| 743 if (!roots || roots->size() < 2 || !roots->contains(block)) | 743 if (!roots || roots->size() < 2 || !roots->contains(block)) |
| 744 return 0; | 744 return nullptr; |
| 745 | 745 |
| 746 SuperclusterMap::AddResult addResult = m_superclusters.add(fingerprint, Pass
OwnPtr<Supercluster>()); | 746 SuperclusterMap::AddResult addResult = m_superclusters.add(fingerprint, Pass
OwnPtr<Supercluster>()); |
| 747 if (!addResult.isNewEntry) | 747 if (!addResult.isNewEntry) |
| 748 return addResult.storedValue->value.get(); | 748 return addResult.storedValue->value.get(); |
| 749 | 749 |
| 750 Supercluster* supercluster = new Supercluster(roots); | 750 Supercluster* supercluster = new Supercluster(roots); |
| 751 addResult.storedValue->value = adoptPtr(supercluster); | 751 addResult.storedValue->value = adoptPtr(supercluster); |
| 752 return supercluster; | 752 return supercluster; |
| 753 } | 753 } |
| 754 | 754 |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 950 // Note: At this point clusters may not have been created for these bloc
ks so we cannot rely | 950 // Note: At this point clusters may not have been created for these bloc
ks so we cannot rely |
| 951 // on m_clusters. Instead, we use a best-guess about whether the b
lock will become a cluster. | 951 // on m_clusters. Instead, we use a best-guess about whether the b
lock will become a cluster. |
| 952 if (!classifyBlock(child, INDEPENDENT)) { | 952 if (!classifyBlock(child, INDEPENDENT)) { |
| 953 if (const LayoutObject* leaf = findTextLeaf(child, depth, firstOrLas
t)) | 953 if (const LayoutObject* leaf = findTextLeaf(child, depth, firstOrLas
t)) |
| 954 return leaf; | 954 return leaf; |
| 955 } | 955 } |
| 956 child = (firstOrLast == First) ? child->nextSibling() : child->previousS
ibling(); | 956 child = (firstOrLast == First) ? child->nextSibling() : child->previousS
ibling(); |
| 957 } | 957 } |
| 958 --depth; | 958 --depth; |
| 959 | 959 |
| 960 return 0; | 960 return nullptr; |
| 961 } | 961 } |
| 962 | 962 |
| 963 void TextAutosizer::applyMultiplier(LayoutObject* layoutObject, float multiplier
, RelayoutBehavior relayoutBehavior) | 963 void TextAutosizer::applyMultiplier(LayoutObject* layoutObject, float multiplier
, RelayoutBehavior relayoutBehavior) |
| 964 { | 964 { |
| 965 ASSERT(layoutObject); | 965 ASSERT(layoutObject); |
| 966 ComputedStyle& currentStyle = layoutObject->mutableStyleRef(); | 966 ComputedStyle& currentStyle = layoutObject->mutableStyleRef(); |
| 967 if (currentStyle.textAutosizingMultiplier() == multiplier) | 967 if (currentStyle.textAutosizingMultiplier() == multiplier) |
| 968 return; | 968 return; |
| 969 | 969 |
| 970 // We need to clone the layoutObject style to avoid breaking style sharing. | 970 // We need to clone the layoutObject style to avoid breaking style sharing. |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1168 } | 1168 } |
| 1169 return computedSize; | 1169 return computedSize; |
| 1170 } | 1170 } |
| 1171 | 1171 |
| 1172 DEFINE_TRACE(TextAutosizer) | 1172 DEFINE_TRACE(TextAutosizer) |
| 1173 { | 1173 { |
| 1174 visitor->trace(m_document); | 1174 visitor->trace(m_document); |
| 1175 } | 1175 } |
| 1176 | 1176 |
| 1177 } // namespace blink | 1177 } // namespace blink |
| OLD | NEW |