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

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

Issue 397733004: Allow assertions to be enabled in Blink Release builds. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebased. Created 6 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/rendering/FastTextAutosizer.h ('k') | Source/core/rendering/FloatingObjects.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 static bool hasExplicitWidth(const RenderBlock* block) 272 static bool hasExplicitWidth(const RenderBlock* 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 FastTextAutosizer::FastTextAutosizer(const Document* document) 279 FastTextAutosizer::FastTextAutosizer(const Document* document)
280 : m_document(document) 280 : m_document(document)
281 , m_firstBlockToBeginLayout(0) 281 , m_firstBlockToBeginLayout(0)
282 #ifndef NDEBUG 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 }
292 292
(...skipping 23 matching lines...) Expand all
316 // Clear the cluster stack and the supercluster map to avoid stale point ers. 316 // Clear the cluster stack and the supercluster map to avoid stale point ers.
317 // Speculative fix for http://crbug.com/369485. 317 // Speculative fix for http://crbug.com/369485.
318 m_firstBlockToBeginLayout = 0; 318 m_firstBlockToBeginLayout = 0;
319 m_clusterStack.clear(); 319 m_clusterStack.clear();
320 m_superclusters.clear(); 320 m_superclusters.clear();
321 } 321 }
322 } 322 }
323 323
324 FastTextAutosizer::BeginLayoutBehavior FastTextAutosizer::prepareForLayout(const RenderBlock* block) 324 FastTextAutosizer::BeginLayoutBehavior FastTextAutosizer::prepareForLayout(const RenderBlock* block)
325 { 325 {
326 #ifndef NDEBUG 326 #if ENABLE(ASSERT)
327 m_blocksThatHaveBegunLayout.add(block); 327 m_blocksThatHaveBegunLayout.add(block);
328 #endif 328 #endif
329 329
330 if (!m_firstBlockToBeginLayout) { 330 if (!m_firstBlockToBeginLayout) {
331 m_firstBlockToBeginLayout = block; 331 m_firstBlockToBeginLayout = block;
332 prepareClusterStack(block->parent()); 332 prepareClusterStack(block->parent());
333 } else if (block == currentCluster()->m_root) { 333 } else if (block == currentCluster()->m_root) {
334 // Ignore beginLayout on the same block twice. 334 // Ignore beginLayout on the same block twice.
335 // This can happen with paginated overflow. 335 // This can happen with paginated overflow.
336 return StopLayout; 336 return StopLayout;
337 } 337 }
338 338
339 return ContinueLayout; 339 return ContinueLayout;
340 } 340 }
341 341
342 void FastTextAutosizer::prepareClusterStack(const RenderObject* renderer) 342 void FastTextAutosizer::prepareClusterStack(const RenderObject* renderer)
343 { 343 {
344 if (!renderer) 344 if (!renderer)
345 return; 345 return;
346 prepareClusterStack(renderer->parent()); 346 prepareClusterStack(renderer->parent());
347 347
348 if (renderer->isRenderBlock()) { 348 if (renderer->isRenderBlock()) {
349 const RenderBlock* block = toRenderBlock(renderer); 349 const RenderBlock* block = toRenderBlock(renderer);
350 #ifndef NDEBUG 350 #if ENABLE(ASSERT)
351 m_blocksThatHaveBegunLayout.add(block); 351 m_blocksThatHaveBegunLayout.add(block);
352 #endif 352 #endif
353 if (Cluster* cluster = maybeCreateCluster(block)) 353 if (Cluster* cluster = maybeCreateCluster(block))
354 m_clusterStack.append(adoptPtr(cluster)); 354 m_clusterStack.append(adoptPtr(cluster));
355 } 355 }
356 } 356 }
357 357
358 void FastTextAutosizer::beginLayout(RenderBlock* block) 358 void FastTextAutosizer::beginLayout(RenderBlock* block)
359 { 359 {
360 ASSERT(shouldHandleLayout()); 360 ASSERT(shouldHandleLayout());
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 419
420 void FastTextAutosizer::endLayout(RenderBlock* block) 420 void FastTextAutosizer::endLayout(RenderBlock* block)
421 { 421 {
422 ASSERT(shouldHandleLayout()); 422 ASSERT(shouldHandleLayout());
423 423
424 if (block == m_firstBlockToBeginLayout) { 424 if (block == m_firstBlockToBeginLayout) {
425 m_firstBlockToBeginLayout = 0; 425 m_firstBlockToBeginLayout = 0;
426 m_clusterStack.clear(); 426 m_clusterStack.clear();
427 m_superclusters.clear(); 427 m_superclusters.clear();
428 m_stylesRetainedDuringLayout.clear(); 428 m_stylesRetainedDuringLayout.clear();
429 #ifndef NDEBUG 429 #if ENABLE(ASSERT)
430 m_blocksThatHaveBegunLayout.clear(); 430 m_blocksThatHaveBegunLayout.clear();
431 #endif 431 #endif
432 // Tables can create two layout scopes for the same block so the isEmpty 432 // Tables can create two layout scopes for the same block so the isEmpty
433 // check below is needed to guard against endLayout being called twice. 433 // check below is needed to guard against endLayout being called twice.
434 } else if (!m_clusterStack.isEmpty() && currentCluster()->m_root == block) { 434 } else if (!m_clusterStack.isEmpty() && currentCluster()->m_root == block) {
435 m_clusterStack.removeLast(); 435 m_clusterStack.removeLast();
436 } 436 }
437 } 437 }
438 438
439 float FastTextAutosizer::inflate(RenderObject* parent, InflateBehavior behavior, float multiplier) 439 float FastTextAutosizer::inflate(RenderObject* parent, InflateBehavior behavior, float multiplier)
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after
1002 1002
1003 return false; 1003 return false;
1004 } 1004 }
1005 1005
1006 FastTextAutosizer::Cluster* FastTextAutosizer::currentCluster() const 1006 FastTextAutosizer::Cluster* FastTextAutosizer::currentCluster() const
1007 { 1007 {
1008 ASSERT_WITH_SECURITY_IMPLICATION(!m_clusterStack.isEmpty()); 1008 ASSERT_WITH_SECURITY_IMPLICATION(!m_clusterStack.isEmpty());
1009 return m_clusterStack.last().get(); 1009 return m_clusterStack.last().get();
1010 } 1010 }
1011 1011
1012 #ifndef NDEBUG 1012 #if ENABLE(ASSERT)
1013 void FastTextAutosizer::FingerprintMapper::assertMapsAreConsistent() 1013 void FastTextAutosizer::FingerprintMapper::assertMapsAreConsistent()
1014 { 1014 {
1015 // For each fingerprint -> block mapping in m_blocksForFingerprint we should have an associated 1015 // For each fingerprint -> block mapping in m_blocksForFingerprint we should have an associated
1016 // map from block -> fingerprint in m_fingerprints. 1016 // map from block -> fingerprint in m_fingerprints.
1017 ReverseFingerprintMap::iterator end = m_blocksForFingerprint.end(); 1017 ReverseFingerprintMap::iterator end = m_blocksForFingerprint.end();
1018 for (ReverseFingerprintMap::iterator fingerprintIt = m_blocksForFingerprint. begin(); fingerprintIt != end; ++fingerprintIt) { 1018 for (ReverseFingerprintMap::iterator fingerprintIt = m_blocksForFingerprint. begin(); fingerprintIt != end; ++fingerprintIt) {
1019 Fingerprint fingerprint = fingerprintIt->key; 1019 Fingerprint fingerprint = fingerprintIt->key;
1020 BlockSet* blocks = fingerprintIt->value.get(); 1020 BlockSet* blocks = fingerprintIt->value.get();
1021 for (BlockSet::iterator blockIt = blocks->begin(); blockIt != blocks->en d(); ++blockIt) { 1021 for (BlockSet::iterator blockIt = blocks->begin(); blockIt != blocks->en d(); ++blockIt) {
1022 const RenderBlock* block = (*blockIt); 1022 const RenderBlock* block = (*blockIt);
1023 ASSERT(m_fingerprints.get(block) == fingerprint); 1023 ASSERT(m_fingerprints.get(block) == fingerprint);
1024 } 1024 }
1025 } 1025 }
1026 } 1026 }
1027 #endif 1027 #endif
1028 1028
1029 void FastTextAutosizer::FingerprintMapper::add(const RenderObject* renderer, Fin gerprint fingerprint) 1029 void FastTextAutosizer::FingerprintMapper::add(const RenderObject* renderer, Fin gerprint fingerprint)
1030 { 1030 {
1031 remove(renderer); 1031 remove(renderer);
1032 1032
1033 m_fingerprints.set(renderer, fingerprint); 1033 m_fingerprints.set(renderer, fingerprint);
1034 #ifndef NDEBUG 1034 #if ENABLE(ASSERT)
1035 assertMapsAreConsistent(); 1035 assertMapsAreConsistent();
1036 #endif 1036 #endif
1037 } 1037 }
1038 1038
1039 void FastTextAutosizer::FingerprintMapper::addTentativeClusterRoot(const RenderB lock* block, Fingerprint fingerprint) 1039 void FastTextAutosizer::FingerprintMapper::addTentativeClusterRoot(const RenderB lock* block, Fingerprint fingerprint)
1040 { 1040 {
1041 add(block, fingerprint); 1041 add(block, fingerprint);
1042 1042
1043 ReverseFingerprintMap::AddResult addResult = m_blocksForFingerprint.add(fing erprint, PassOwnPtr<BlockSet>()); 1043 ReverseFingerprintMap::AddResult addResult = m_blocksForFingerprint.add(fing erprint, PassOwnPtr<BlockSet>());
1044 if (addResult.isNewEntry) 1044 if (addResult.isNewEntry)
1045 addResult.storedValue->value = adoptPtr(new BlockSet); 1045 addResult.storedValue->value = adoptPtr(new BlockSet);
1046 addResult.storedValue->value->add(block); 1046 addResult.storedValue->value->add(block);
1047 #ifndef NDEBUG 1047 #if ENABLE(ASSERT)
1048 assertMapsAreConsistent(); 1048 assertMapsAreConsistent();
1049 #endif 1049 #endif
1050 } 1050 }
1051 1051
1052 bool FastTextAutosizer::FingerprintMapper::remove(const RenderObject* renderer) 1052 bool FastTextAutosizer::FingerprintMapper::remove(const RenderObject* renderer)
1053 { 1053 {
1054 Fingerprint fingerprint = m_fingerprints.take(renderer); 1054 Fingerprint fingerprint = m_fingerprints.take(renderer);
1055 if (!fingerprint || !renderer->isRenderBlock()) 1055 if (!fingerprint || !renderer->isRenderBlock())
1056 return false; 1056 return false;
1057 1057
1058 ReverseFingerprintMap::iterator blocksIter = m_blocksForFingerprint.find(fin gerprint); 1058 ReverseFingerprintMap::iterator blocksIter = m_blocksForFingerprint.find(fin gerprint);
1059 if (blocksIter == m_blocksForFingerprint.end()) 1059 if (blocksIter == m_blocksForFingerprint.end())
1060 return false; 1060 return false;
1061 1061
1062 BlockSet& blocks = *blocksIter->value; 1062 BlockSet& blocks = *blocksIter->value;
1063 blocks.remove(toRenderBlock(renderer)); 1063 blocks.remove(toRenderBlock(renderer));
1064 if (blocks.isEmpty()) 1064 if (blocks.isEmpty())
1065 m_blocksForFingerprint.remove(blocksIter); 1065 m_blocksForFingerprint.remove(blocksIter);
1066 #ifndef NDEBUG 1066 #if ENABLE(ASSERT)
1067 assertMapsAreConsistent(); 1067 assertMapsAreConsistent();
1068 #endif 1068 #endif
1069 return true; 1069 return true;
1070 } 1070 }
1071 1071
1072 FastTextAutosizer::Fingerprint FastTextAutosizer::FingerprintMapper::get(const R enderObject* renderer) 1072 FastTextAutosizer::Fingerprint FastTextAutosizer::FingerprintMapper::get(const R enderObject* renderer)
1073 { 1073 {
1074 return m_fingerprints.get(renderer); 1074 return m_fingerprints.get(renderer);
1075 } 1075 }
1076 1076
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1148 computedSize = multiplier * specifiedSize; 1148 computedSize = multiplier * specifiedSize;
1149 } else { 1149 } else {
1150 computedSize = multiplier * pleasantSize + gradientAfterPleasantSize * ( specifiedSize - pleasantSize); 1150 computedSize = multiplier * pleasantSize + gradientAfterPleasantSize * ( specifiedSize - pleasantSize);
1151 if (computedSize < specifiedSize) 1151 if (computedSize < specifiedSize)
1152 computedSize = specifiedSize; 1152 computedSize = specifiedSize;
1153 } 1153 }
1154 return computedSize; 1154 return computedSize;
1155 } 1155 }
1156 1156
1157 } // namespace WebCore 1157 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/rendering/FastTextAutosizer.h ('k') | Source/core/rendering/FloatingObjects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698