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

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

Issue 319013003: Set multiplier to 1 on blocks with no direct text children. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 6 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
« no previous file with comments | « Source/core/rendering/FastTextAutosizer.h ('k') | no next file » | 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 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 ASSERT(shouldHandleLayout()); 365 ASSERT(shouldHandleLayout());
366 366
367 if (prepareForLayout(block) == StopLayout) 367 if (prepareForLayout(block) == StopLayout)
368 return; 368 return;
369 369
370 if (Cluster* cluster = maybeCreateCluster(block)) 370 if (Cluster* cluster = maybeCreateCluster(block))
371 m_clusterStack.append(adoptPtr(cluster)); 371 m_clusterStack.append(adoptPtr(cluster));
372 372
373 // Cells in auto-layout tables are handled separately by inflateAutoTable. 373 // Cells in auto-layout tables are handled separately by inflateAutoTable.
374 bool isAutoTableCell = block->isTableCell() && !toRenderTableCell(block)->ta ble()->style()->isFixedTableLayout(); 374 bool isAutoTableCell = block->isTableCell() && !toRenderTableCell(block)->ta ble()->style()->isFixedTableLayout();
375 if (block->childrenInline() && block->firstChild() && !isAutoTableCell) 375 if (!isAutoTableCell && !m_clusterStack.isEmpty())
376 inflate(block); 376 inflate(block);
377 } 377 }
378 378
379 void FastTextAutosizer::inflateListItem(RenderListItem* listItem, RenderListMark er* listItemMarker) 379 void FastTextAutosizer::inflateListItem(RenderListItem* listItem, RenderListMark er* listItemMarker)
380 { 380 {
381 if (!shouldHandleLayout()) 381 if (!shouldHandleLayout())
382 return; 382 return;
383 ASSERT(listItem && listItemMarker); 383 ASSERT(listItem && listItemMarker);
384 384
385 if (prepareForLayout(listItem) == StopLayout) 385 if (prepareForLayout(listItem) == StopLayout)
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 #ifndef NDEBUG 434 #ifndef NDEBUG
435 m_blocksThatHaveBegunLayout.clear(); 435 m_blocksThatHaveBegunLayout.clear();
436 #endif 436 #endif
437 // Tables can create two layout scopes for the same block so the isEmpty 437 // Tables can create two layout scopes for the same block so the isEmpty
438 // check below is needed to guard against endLayout being called twice. 438 // check below is needed to guard against endLayout being called twice.
439 } else if (!m_clusterStack.isEmpty() && currentCluster()->m_root == block) { 439 } else if (!m_clusterStack.isEmpty() && currentCluster()->m_root == block) {
440 m_clusterStack.removeLast(); 440 m_clusterStack.removeLast();
441 } 441 }
442 } 442 }
443 443
444 void FastTextAutosizer::inflate(RenderBlock* block) 444 float FastTextAutosizer::inflate(RenderObject* parent, float multiplier)
445 { 445 {
446 Cluster* cluster = currentCluster(); 446 Cluster* cluster = currentCluster();
447 float multiplier = 0; 447 bool hasTextChild = false;
448 RenderObject* descendant = block->firstChild(); 448
449 while (descendant) { 449 RenderObject* child = 0;
450 // Skip block descendants because they will be inflate()'d on their own. 450 if (parent->isRenderBlock() && parent->childrenInline())
451 if (descendant->isRenderBlock()) { 451 child = toRenderBlock(parent)->firstChild();
452 descendant = descendant->nextInPreOrderAfterChildren(block); 452 else if (parent->isRenderInline())
453 continue; 453 child = toRenderInline(parent)->firstChild();
454 } 454
455 if (descendant->isText()) { 455 while (child) {
456 if (child->isText()) {
457 hasTextChild = true;
456 // We only calculate this multiplier on-demand to ensure the parent block of this text 458 // We only calculate this multiplier on-demand to ensure the parent block of this text
457 // has entered layout. 459 // has entered layout.
458 if (!multiplier) 460 if (!multiplier)
459 multiplier = cluster->m_flags & SUPPRESSING ? 1.0f : clusterMult iplier(cluster); 461 multiplier = cluster->m_flags & SUPPRESSING ? 1.0f : clusterMult iplier(cluster);
460 applyMultiplier(descendant, multiplier); 462 applyMultiplier(child, multiplier);
461 applyMultiplier(descendant->parent(), multiplier); // Parent handles line spacing.
462 // FIXME: Investigate why MarkOnlyThis is sufficient. 463 // FIXME: Investigate why MarkOnlyThis is sufficient.
463 if (descendant->parent()->isRenderInline()) 464 if (parent->isRenderInline())
464 descendant->setPreferredLogicalWidthsDirty(MarkOnlyThis); 465 child->setPreferredLogicalWidthsDirty(MarkOnlyThis);
466 } else if (child->isRenderInline()) {
467 multiplier = inflate(child, multiplier);
465 } 468 }
466 descendant = descendant->nextInPreOrder(block); 469 child = child->nextSibling();
467 } 470 }
471
472 if (hasTextChild) {
473 applyMultiplier(parent, multiplier); // Parent handles line spacing.
474 } else if (!parent->isListItem()) {
475 // For consistency, a block with no immediate text child should always h ave a
476 // multiplier of 1 (except for list items which are handled in inflateLi stItem).
477 applyMultiplier(parent, 1);
478 }
479 return multiplier;
468 } 480 }
469 481
470 bool FastTextAutosizer::shouldHandleLayout() const 482 bool FastTextAutosizer::shouldHandleLayout() const
471 { 483 {
472 return m_pageInfo.m_settingEnabled && m_pageInfo.m_pageNeedsAutosizing && !m _updatePageInfoDeferred; 484 return m_pageInfo.m_settingEnabled && m_pageInfo.m_pageNeedsAutosizing && !m _updatePageInfoDeferred;
473 } 485 }
474 486
475 void FastTextAutosizer::updatePageInfoInAllFrames() 487 void FastTextAutosizer::updatePageInfoInAllFrames()
476 { 488 {
477 ASSERT(!m_document->frame() || m_document->frame()->isMainFrame()); 489 ASSERT(!m_document->frame() || m_document->frame()->isMainFrame());
(...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after
1110 FastTextAutosizer::DeferUpdatePageInfo::~DeferUpdatePageInfo() 1122 FastTextAutosizer::DeferUpdatePageInfo::~DeferUpdatePageInfo()
1111 { 1123 {
1112 if (FastTextAutosizer* textAutosizer = m_mainFrame->document()->fastTextAuto sizer()) { 1124 if (FastTextAutosizer* textAutosizer = m_mainFrame->document()->fastTextAuto sizer()) {
1113 ASSERT(textAutosizer->m_updatePageInfoDeferred); 1125 ASSERT(textAutosizer->m_updatePageInfoDeferred);
1114 textAutosizer->m_updatePageInfoDeferred = false; 1126 textAutosizer->m_updatePageInfoDeferred = false;
1115 textAutosizer->updatePageInfoInAllFrames(); 1127 textAutosizer->updatePageInfoInAllFrames();
1116 } 1128 }
1117 } 1129 }
1118 1130
1119 } // namespace WebCore 1131 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/rendering/FastTextAutosizer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698