| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 , m_renderViewInfoPrepared(false) | 51 , m_renderViewInfoPrepared(false) |
| 52 #endif | 52 #endif |
| 53 { | 53 { |
| 54 } | 54 } |
| 55 | 55 |
| 56 void FastTextAutosizer::record(RenderBlock* block) | 56 void FastTextAutosizer::record(RenderBlock* block) |
| 57 { | 57 { |
| 58 if (!enabled()) | 58 if (!enabled()) |
| 59 return; | 59 return; |
| 60 | 60 |
| 61 if (!shouldBeClusterRoot(block)) | 61 if (!isFingerprintingCandidate(block)) |
| 62 return; | 62 return; |
| 63 | 63 |
| 64 AtomicString fingerprint = computeFingerprint(block); | 64 AtomicString fingerprint = computeFingerprint(block); |
| 65 if (fingerprint.isNull()) | 65 if (fingerprint.isNull()) |
| 66 return; | 66 return; |
| 67 | 67 |
| 68 m_fingerprintMapper.add(block, fingerprint); | 68 m_fingerprintMapper.add(block, fingerprint); |
| 69 } | 69 } |
| 70 | 70 |
| 71 void FastTextAutosizer::destroy(RenderBlock* block) | 71 void FastTextAutosizer::destroy(RenderBlock* block) |
| 72 { | 72 { |
| 73 m_fingerprintMapper.remove(block); | 73 m_fingerprintMapper.remove(block); |
| 74 } | 74 } |
| 75 | 75 |
| 76 void FastTextAutosizer::beginLayout(RenderBlock* block) | 76 void FastTextAutosizer::beginLayout(RenderBlock* block) |
| 77 { | 77 { |
| 78 if (!enabled()) | 78 if (!enabled()) |
| 79 return; | 79 return; |
| 80 | 80 |
| 81 if (block->isRenderView()) | 81 if (block->isRenderView()) |
| 82 prepareRenderViewInfo(toRenderView(block)); | 82 prepareRenderViewInfo(toRenderView(block)); |
| 83 | 83 |
| 84 if (shouldBeClusterRoot(block)) | 84 if (Cluster* cluster = maybeGetOrCreateCluster(block)) |
| 85 m_clusterStack.append(getOrCreateCluster(block)); | 85 m_clusterStack.append(cluster); |
| 86 | 86 |
| 87 if (block->childrenInline()) | 87 if (block->childrenInline()) |
| 88 inflate(block); | 88 inflate(block); |
| 89 } | 89 } |
| 90 | 90 |
| 91 void FastTextAutosizer::endLayout(RenderBlock* block) | 91 void FastTextAutosizer::endLayout(RenderBlock* block) |
| 92 { | 92 { |
| 93 if (!enabled()) | 93 if (!enabled()) |
| 94 return; | 94 return; |
| 95 | 95 |
| 96 if (!m_clusterStack.isEmpty() && m_clusterStack.last()->m_root == block) | 96 if (!m_clusterStack.isEmpty() && m_clusterStack.last()->m_root == block) |
| 97 m_clusterStack.removeLast(); | 97 m_clusterStack.removeLast(); |
| 98 } | 98 } |
| 99 | 99 |
| 100 void FastTextAutosizer::inflate(RenderBlock* block) | 100 void FastTextAutosizer::inflate(RenderBlock* block) |
| 101 { | 101 { |
| 102 if (m_clusterStack.isEmpty()) | 102 if (m_clusterStack.isEmpty()) |
| 103 return; | 103 return; |
| 104 Cluster* cluster = m_clusterStack.last(); | 104 Cluster* cluster = m_clusterStack.last(); |
| 105 | 105 |
| 106 // localMultiplier is used to prevent inflation of some containers such as a
row of links. | 106 float multiplier = cluster->m_autosize ? cluster->m_multiplier : 1.0f; |
| 107 float localMultiplier = TextAutosizer::containerShouldBeAutosized(block) ? c
luster->m_multiplier : 1; | |
| 108 | 107 |
| 109 for (InlineWalker walker(block); !walker.atEnd(); walker.advance()) { | 108 for (InlineWalker walker(block); !walker.atEnd(); walker.advance()) { |
| 110 RenderObject* inlineObj = walker.current(); | 109 RenderObject* inlineObj = walker.current(); |
| 111 if (inlineObj->isText()) { | 110 if (inlineObj->isText()) { |
| 112 applyMultiplier(inlineObj, localMultiplier); | 111 applyMultiplier(inlineObj, multiplier); |
| 113 applyMultiplier(inlineObj->parent(), localMultiplier); // Parent han
dles line spacing. | 112 applyMultiplier(inlineObj->parent(), multiplier); // Parent handles
line spacing. |
| 114 } | 113 } |
| 115 } | 114 } |
| 116 } | 115 } |
| 117 | 116 |
| 118 bool FastTextAutosizer::enabled() | 117 bool FastTextAutosizer::enabled() |
| 119 { | 118 { |
| 120 return m_document->settings() | 119 return m_document->settings() |
| 121 && m_document->settings()->textAutosizingEnabled() | 120 && m_document->settings()->textAutosizingEnabled() |
| 122 && !m_document->printing() | 121 && !m_document->printing() |
| 123 && m_document->page(); | 122 && m_document->page(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 140 m_baseMultiplier = m_document->settings()->accessibilityFontScaleFactor(); | 139 m_baseMultiplier = m_document->settings()->accessibilityFontScaleFactor(); |
| 141 // If the page has a meta viewport or @viewport, don't apply the device scal
e adjustment. | 140 // If the page has a meta viewport or @viewport, don't apply the device scal
e adjustment. |
| 142 const ViewportDescription& viewportDescription = m_document->page()->mainFra
me()->document()->viewportDescription(); | 141 const ViewportDescription& viewportDescription = m_document->page()->mainFra
me()->document()->viewportDescription(); |
| 143 if (!viewportDescription.isSpecifiedByAuthor()) | 142 if (!viewportDescription.isSpecifiedByAuthor()) |
| 144 m_baseMultiplier *= m_document->settings()->deviceScaleAdjustment(); | 143 m_baseMultiplier *= m_document->settings()->deviceScaleAdjustment(); |
| 145 #ifndef NDEBUG | 144 #ifndef NDEBUG |
| 146 m_renderViewInfoPrepared = true; | 145 m_renderViewInfoPrepared = true; |
| 147 #endif | 146 #endif |
| 148 } | 147 } |
| 149 | 148 |
| 150 bool FastTextAutosizer::shouldBeClusterRoot(RenderBlock* block) | 149 bool FastTextAutosizer::isFingerprintingCandidate(RenderBlock* block) |
| 151 { | 150 { |
| 152 // FIXME: move the logic out of TextAutosizer.cpp into this class. | 151 // FIXME: move the logic out of TextAutosizer.cpp into this class. |
| 153 return block->isRenderView() | 152 return block->isRenderView() |
| 154 || (TextAutosizer::isAutosizingContainer(block) | 153 || (TextAutosizer::isAutosizingContainer(block) |
| 155 && TextAutosizer::isIndependentDescendant(block)); | 154 && TextAutosizer::isIndependentDescendant(block)); |
| 156 } | 155 } |
| 157 | 156 |
| 158 bool FastTextAutosizer::clusterWantsAutosizing(RenderBlock* root) | 157 bool FastTextAutosizer::clusterWantsAutosizing(RenderBlock* root) |
| 159 { | 158 { |
| 160 // FIXME: this should be slightly different. | 159 // FIXME: this should call (or re-implement) TextAutosizer::clusterShouldBeA
utosized. |
| 161 return TextAutosizer::containerShouldBeAutosized(root); | 160 return true; |
| 162 } | 161 } |
| 163 | 162 |
| 164 AtomicString FastTextAutosizer::computeFingerprint(RenderBlock* block) | 163 AtomicString FastTextAutosizer::computeFingerprint(RenderBlock* block) |
| 165 { | 164 { |
| 166 // FIXME(crbug.com/322340): Implement a fingerprinting algorithm. | 165 // FIXME(crbug.com/322340): Implement a fingerprinting algorithm. |
| 167 return nullAtom; | 166 return nullAtom; |
| 168 } | 167 } |
| 169 | 168 |
| 170 FastTextAutosizer::Cluster* FastTextAutosizer::getOrCreateCluster(RenderBlock* b
lock) | 169 FastTextAutosizer::Cluster* FastTextAutosizer::maybeGetOrCreateCluster(RenderBlo
ck* block) |
| 171 { | 170 { |
| 171 if (!TextAutosizer::isAutosizingContainer(block)) |
| 172 return 0; |
| 173 |
| 174 bool isIndependentDescendant = TextAutosizer::isIndependentDescendant(block)
; |
| 175 |
| 176 // Create clusters to suppress / unsuppress autosizing based on containerSho
uldBeAutosized. |
| 177 bool containerCanAutosize = TextAutosizer::containerShouldBeAutosized(block)
; |
| 178 bool parentClusterCanAutosize = !m_clusterStack.isEmpty() && m_clusterStack.
last()->m_autosize; |
| 179 |
| 180 // If the container would not alter the m_autosize bit, it doesn't need to b
e a cluster. |
| 181 if (!isIndependentDescendant && containerCanAutosize == parentClusterCanAuto
size) |
| 182 return 0; |
| 183 |
| 172 ClusterMap::AddResult addResult = m_clusters.add(block, PassOwnPtr<Cluster>(
)); | 184 ClusterMap::AddResult addResult = m_clusters.add(block, PassOwnPtr<Cluster>(
)); |
| 173 if (!addResult.isNewEntry) | 185 if (!addResult.isNewEntry) |
| 174 return addResult.iterator->value.get(); | 186 return addResult.iterator->value.get(); |
| 175 | 187 |
| 176 AtomicString fingerprint = m_fingerprintMapper.get(block); | 188 AtomicString fingerprint = m_fingerprintMapper.get(block); |
| 177 if (fingerprint.isNull()) { | 189 if (fingerprint.isNull()) { |
| 178 addResult.iterator->value = adoptPtr(createCluster(block)); | 190 float multiplier; |
| 191 if (isIndependentDescendant) |
| 192 multiplier = clusterWantsAutosizing(block) ? computeMultiplier(block
) : 1.0f; |
| 193 else |
| 194 multiplier = m_clusterStack.last()->m_multiplier; |
| 195 addResult.iterator->value = adoptPtr(new Cluster(block, containerCanAuto
size, multiplier)); |
| 179 return addResult.iterator->value.get(); | 196 return addResult.iterator->value.get(); |
| 180 } | 197 } |
| 181 return addSupercluster(fingerprint, block); | 198 return addSupercluster(fingerprint, block); |
| 182 } | 199 } |
| 183 | 200 |
| 184 FastTextAutosizer::Cluster* FastTextAutosizer::createCluster(RenderBlock* block) | |
| 185 { | |
| 186 float multiplier = clusterWantsAutosizing(block) ? computeMultiplier(block)
: 1.0f; | |
| 187 return new Cluster(block, multiplier); | |
| 188 } | |
| 189 | |
| 190 FastTextAutosizer::Cluster* FastTextAutosizer::addSupercluster(AtomicString fing
erprint, RenderBlock* returnFor) | 201 FastTextAutosizer::Cluster* FastTextAutosizer::addSupercluster(AtomicString fing
erprint, RenderBlock* returnFor) |
| 191 { | 202 { |
| 192 BlockSet& roots = m_fingerprintMapper.getBlocks(fingerprint); | 203 BlockSet& roots = m_fingerprintMapper.getBlocks(fingerprint); |
| 193 RenderBlock* superRoot = deepestCommonAncestor(roots); | 204 RenderBlock* superRoot = deepestCommonAncestor(roots); |
| 194 | 205 |
| 195 bool shouldAutosize = false; | 206 bool shouldAutosize = false; |
| 196 for (BlockSet::iterator it = roots.begin(); it != roots.end(); ++it) | 207 for (BlockSet::iterator it = roots.begin(); it != roots.end(); ++it) |
| 197 shouldAutosize |= clusterWantsAutosizing(*it); | 208 shouldAutosize |= clusterWantsAutosizing(*it); |
| 198 | 209 |
| 199 float multiplier = shouldAutosize ? computeMultiplier(superRoot) : 1.0f; | 210 float multiplier = shouldAutosize ? computeMultiplier(superRoot) : 1.0f; |
| 200 | 211 |
| 201 Cluster* result = 0; | 212 Cluster* result = 0; |
| 202 for (BlockSet::iterator it = roots.begin(); it != roots.end(); ++it) { | 213 for (BlockSet::iterator it = roots.begin(); it != roots.end(); ++it) { |
| 203 Cluster* cluster = new Cluster(*it, multiplier); | 214 Cluster* cluster = new Cluster(*it, TextAutosizer::containerShouldBeAuto
sized(*it), multiplier); |
| 204 m_clusters.set(*it, adoptPtr(cluster)); | 215 m_clusters.set(*it, adoptPtr(cluster)); |
| 205 | 216 |
| 206 if (*it == returnFor) | 217 if (*it == returnFor) |
| 207 result = cluster; | 218 result = cluster; |
| 208 } | 219 } |
| 209 return result; | 220 return result; |
| 210 } | 221 } |
| 211 | 222 |
| 212 RenderBlock* FastTextAutosizer::deepestCommonAncestor(BlockSet& blocks) | 223 RenderBlock* FastTextAutosizer::deepestCommonAncestor(BlockSet& blocks) |
| 213 { | 224 { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 { | 289 { |
| 279 return m_fingerprints.get(block); | 290 return m_fingerprints.get(block); |
| 280 } | 291 } |
| 281 | 292 |
| 282 FastTextAutosizer::BlockSet& FastTextAutosizer::FingerprintMapper::getBlocks(Ato
micString fingerprint) | 293 FastTextAutosizer::BlockSet& FastTextAutosizer::FingerprintMapper::getBlocks(Ato
micString fingerprint) |
| 283 { | 294 { |
| 284 return *m_blocksForFingerprint.get(fingerprint); | 295 return *m_blocksForFingerprint.get(fingerprint); |
| 285 } | 296 } |
| 286 | 297 |
| 287 } // namespace WebCore | 298 } // namespace WebCore |
| OLD | NEW |