Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1088)

Side by Side Diff: Source/core/rendering/FastTextAutosizer.cpp

Issue 137123004: Fix treatment of non-autosizing containers. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Create a cluster whenever a container toggles autosizing status. Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 87
88 void FastTextAutosizer::inflate(RenderBlock* block) 88 void FastTextAutosizer::inflate(RenderBlock* block)
89 { 89 {
90 if (m_clusterStack.isEmpty()) 90 if (m_clusterStack.isEmpty())
91 return; 91 return;
92 Cluster* cluster = m_clusterStack.last(); 92 Cluster* cluster = m_clusterStack.last();
93 93
94 // localMultiplier is used to prevent inflation of some containers such as a row of links. 94 float multiplier = cluster->m_autosize ? cluster->m_multiplier : 1.0f;
pdr. 2014/01/14 02:50:03 Double-checking my own understanding: We no longer
skobes 2014/01/14 20:46:30 Correct. It was always broken to call containerSh
95 float localMultiplier = TextAutosizer::containerShouldBeAutosized(block) ? c luster->m_multiplier : 1;
96 95
97 // FIXME: Add an optimization to not do this walk if it's not needed. 96 // FIXME: Add an optimization to not do this walk if it's not needed.
pdr. 2014/01/14 02:50:03 (not for this patch) I originally added this FIXME
skobes 2014/01/14 20:46:30 I think we have to reset them. It is still kind o
98 for (InlineWalker walker(block); !walker.atEnd(); walker.advance()) { 97 for (InlineWalker walker(block); !walker.atEnd(); walker.advance()) {
99 RenderObject* inlineObj = walker.current(); 98 RenderObject* inlineObj = walker.current();
100 if (inlineObj->isText()) { 99 if (inlineObj->isText()) {
101 applyMultiplier(inlineObj, localMultiplier); 100 applyMultiplier(inlineObj, multiplier);
102 applyMultiplier(inlineObj->parent(), localMultiplier); // Parent han dles line spacing. 101 applyMultiplier(inlineObj->parent(), multiplier); // Parent handles line spacing.
103 } 102 }
104 } 103 }
105 } 104 }
106 105
107 void FastTextAutosizer::endLayout(RenderBlock* block) 106 void FastTextAutosizer::endLayout(RenderBlock* block)
108 { 107 {
109 if (!enabled()) 108 if (!enabled())
110 return; 109 return;
111 110
112 if (!m_clusterStack.isEmpty() && m_clusterStack.last()->m_root == block) 111 if (!m_clusterStack.isEmpty() && m_clusterStack.last()->m_root == block)
(...skipping 25 matching lines...) Expand all
138 m_baseMultiplier = m_document->settings()->accessibilityFontScaleFactor(); 137 m_baseMultiplier = m_document->settings()->accessibilityFontScaleFactor();
139 // If the page has a meta viewport or @viewport, don't apply the device scal e adjustment. 138 // If the page has a meta viewport or @viewport, don't apply the device scal e adjustment.
140 const ViewportDescription& viewportDescription = m_document->page()->mainFra me()->document()->viewportDescription(); 139 const ViewportDescription& viewportDescription = m_document->page()->mainFra me()->document()->viewportDescription();
141 if (!viewportDescription.isSpecifiedByAuthor()) 140 if (!viewportDescription.isSpecifiedByAuthor())
142 m_baseMultiplier *= m_document->settings()->deviceScaleAdjustment(); 141 m_baseMultiplier *= m_document->settings()->deviceScaleAdjustment();
143 #ifndef NDEBUG 142 #ifndef NDEBUG
144 m_renderViewInfoPrepared = true; 143 m_renderViewInfoPrepared = true;
145 #endif 144 #endif
146 } 145 }
147 146
148 bool FastTextAutosizer::shouldBeClusterRoot(RenderBlock* block) 147 bool FastTextAutosizer::isFingerprintingCandidate(RenderBlock* block)
149 { 148 {
150 // FIXME: move the logic out of TextAutosizer.cpp into this class. 149 // FIXME: move the logic out of TextAutosizer.cpp into this class.
151 return block->isRenderView() 150 return block->isRenderView()
152 || (TextAutosizer::isAutosizingContainer(block) 151 || (TextAutosizer::isAutosizingContainer(block)
153 && TextAutosizer::isIndependentDescendant(block)); 152 && TextAutosizer::isIndependentDescendant(block));
154 } 153 }
155 154
156 bool FastTextAutosizer::clusterWantsAutosizing(RenderBlock* root) 155 bool FastTextAutosizer::clusterWantsAutosizing(RenderBlock* root)
157 { 156 {
158 // FIXME: this should be slightly different. 157 // FIXME: this should call (or re-implement) TextAutosizer::clusterShouldBeA utosized.
159 return TextAutosizer::containerShouldBeAutosized(root); 158 return true;
160 } 159 }
161 160
162 AtomicString FastTextAutosizer::computeFingerprint(RenderBlock* block) 161 AtomicString FastTextAutosizer::computeFingerprint(RenderBlock* block)
163 { 162 {
164 // FIXME(crbug.com/322340): Implement a fingerprinting algorithm. 163 // FIXME(crbug.com/322340): Implement a fingerprinting algorithm.
165 return nullAtom; 164 return nullAtom;
166 } 165 }
167 166
168 FastTextAutosizer::Cluster* FastTextAutosizer::getOrCreateCluster(RenderBlock* b lock) 167 FastTextAutosizer::Cluster* FastTextAutosizer::maybeGetOrCreateCluster(RenderBlo ck* block)
169 { 168 {
169 if (!TextAutosizer::isAutosizingContainer(block))
170 return 0;
171
172 bool isIndependentDescendant = TextAutosizer::isIndependentDescendant(block) ;
173
174 // Create clusters to suppress / unsuppress autosizing based on containerSho uldBeAutosized.
175 bool containerCanAutosize = TextAutosizer::containerShouldBeAutosized(block) ;
176 bool parentClusterCanAutosize = !m_clusterStack.isEmpty() && m_clusterStack. last()->m_autosize;
177
178 if (!isIndependentDescendant && containerCanAutosize == parentClusterCanAuto size)
pdr. 2014/01/14 02:50:03 Double-checking my own understanding: Is this an o
skobes 2014/01/14 20:46:30 Correct. We don't need a cluster for EVERY contai
179 return 0;
180
170 ClusterMap::AddResult addResult = m_clusters.add(block, PassOwnPtr<Cluster>( )); 181 ClusterMap::AddResult addResult = m_clusters.add(block, PassOwnPtr<Cluster>( ));
171 if (!addResult.isNewEntry) 182 if (!addResult.isNewEntry)
172 return addResult.iterator->value.get(); 183 return addResult.iterator->value.get();
173 184
174 AtomicString fingerprint = m_fingerprintMapper.get(block); 185 AtomicString fingerprint = m_fingerprintMapper.get(block);
175 if (fingerprint.isNull()) { 186 if (fingerprint.isNull()) {
176 addResult.iterator->value = adoptPtr(createCluster(block)); 187 float multiplier;
188 if (isIndependentDescendant)
189 multiplier = clusterWantsAutosizing(block) ? computeMultiplier(block ) : 1.0f;
190 else
191 multiplier = m_clusterStack.last()->m_multiplier;
192 addResult.iterator->value = adoptPtr(new Cluster(block, containerCanAuto size, multiplier));
177 return addResult.iterator->value.get(); 193 return addResult.iterator->value.get();
178 } 194 }
179 return addSupercluster(fingerprint, block); 195 return addSupercluster(fingerprint, block);
180 } 196 }
181 197
182 FastTextAutosizer::Cluster* FastTextAutosizer::createCluster(RenderBlock* block)
183 {
184 float multiplier = clusterWantsAutosizing(block) ? computeMultiplier(block) : 1.0f;
185 return new Cluster(block, multiplier);
186 }
187
188 FastTextAutosizer::Cluster* FastTextAutosizer::addSupercluster(AtomicString fing erprint, RenderBlock* returnFor) 198 FastTextAutosizer::Cluster* FastTextAutosizer::addSupercluster(AtomicString fing erprint, RenderBlock* returnFor)
189 { 199 {
190 BlockSet& roots = m_fingerprintMapper.getBlocks(fingerprint); 200 BlockSet& roots = m_fingerprintMapper.getBlocks(fingerprint);
191 RenderBlock* superRoot = deepestCommonAncestor(roots); 201 RenderBlock* superRoot = deepestCommonAncestor(roots);
192 202
193 bool shouldAutosize = false; 203 bool shouldAutosize = false;
194 for (BlockSet::iterator it = roots.begin(); it != roots.end(); ++it) 204 for (BlockSet::iterator it = roots.begin(); it != roots.end(); ++it)
195 shouldAutosize |= clusterWantsAutosizing(*it); 205 shouldAutosize |= clusterWantsAutosizing(*it);
196 206
197 float multiplier = shouldAutosize ? computeMultiplier(superRoot) : 1.0f; 207 float multiplier = shouldAutosize ? computeMultiplier(superRoot) : 1.0f;
198 208
199 Cluster* result = 0; 209 Cluster* result = 0;
200 for (BlockSet::iterator it = roots.begin(); it != roots.end(); ++it) { 210 for (BlockSet::iterator it = roots.begin(); it != roots.end(); ++it) {
201 Cluster* cluster = new Cluster(*it, multiplier); 211 Cluster* cluster = new Cluster(*it, TextAutosizer::containerShouldBeAuto sized(*it), multiplier);
202 m_clusters.set(*it, adoptPtr(cluster)); 212 m_clusters.set(*it, adoptPtr(cluster));
203 213
204 if (*it == returnFor) 214 if (*it == returnFor)
205 result = cluster; 215 result = cluster;
206 } 216 }
207 return result; 217 return result;
208 } 218 }
209 219
210 RenderBlock* FastTextAutosizer::deepestCommonAncestor(BlockSet& blocks) 220 RenderBlock* FastTextAutosizer::deepestCommonAncestor(BlockSet& blocks)
211 { 221 {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 { 286 {
277 return m_fingerprints.get(block); 287 return m_fingerprints.get(block);
278 } 288 }
279 289
280 FastTextAutosizer::BlockSet& FastTextAutosizer::FingerprintMapper::getBlocks(Ato micString fingerprint) 290 FastTextAutosizer::BlockSet& FastTextAutosizer::FingerprintMapper::getBlocks(Ato micString fingerprint)
281 { 291 {
282 return *m_blocksForFingerprint.get(fingerprint); 292 return *m_blocksForFingerprint.get(fingerprint);
283 } 293 }
284 294
285 } // namespace WebCore 295 } // namespace WebCore
OLDNEW
« Source/core/rendering/FastTextAutosizer.h ('K') | « Source/core/rendering/FastTextAutosizer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698