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

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

Issue 180743004: Disable FTA when max multiplier is 1. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 9 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') | Source/core/rendering/RenderBlock.cpp » ('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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 return parent; 56 return parent;
57 } 57 }
58 return 0; 58 return 0;
59 } 59 }
60 60
61 FastTextAutosizer::FastTextAutosizer(const Document* document) 61 FastTextAutosizer::FastTextAutosizer(const Document* document)
62 : m_document(document) 62 : m_document(document)
63 , m_frameWidth(0) 63 , m_frameWidth(0)
64 , m_layoutWidth(0) 64 , m_layoutWidth(0)
65 , m_baseMultiplier(0) 65 , m_baseMultiplier(0)
66 , m_maxMultiplier(0)
66 , m_firstBlock(0) 67 , m_firstBlock(0)
67 #ifndef NDEBUG 68 #ifndef NDEBUG
68 , m_renderViewInfoPrepared(false) 69 , m_renderViewInfoPrepared(false)
69 , m_blocksThatHaveBegunLayout() 70 , m_blocksThatHaveBegunLayout()
70 #endif 71 #endif
71 , m_superclusters() 72 , m_superclusters()
72 , m_clusterStack() 73 , m_clusterStack()
73 , m_fingerprintMapper() 74 , m_fingerprintMapper()
74 { 75 {
75 } 76 }
76 77
77 void FastTextAutosizer::record(const RenderBlock* block) 78 void FastTextAutosizer::record(const RenderBlock* block)
78 { 79 {
79 if (!enabled()) 80 if (!enabled())
pdr. 2014/02/28 22:13:33 enabled() can end up depending on layout (for the
skobes 2014/03/01 01:45:38 I think updateRenderViewInfo doesn't depend on lay
80 return; 81 return;
81 82
82 ASSERT(!m_blocksThatHaveBegunLayout.contains(block)); 83 ASSERT(!m_blocksThatHaveBegunLayout.contains(block));
83 84
84 if (!isFingerprintingCandidate(block)) 85 if (!isFingerprintingCandidate(block))
85 return; 86 return;
86 87
87 if (Fingerprint fingerprint = computeFingerprint(block)) 88 if (Fingerprint fingerprint = computeFingerprint(block))
88 m_fingerprintMapper.addTentativeClusterRoot(block, fingerprint); 89 m_fingerprintMapper.addTentativeClusterRoot(block, fingerprint);
89 } 90 }
(...skipping 24 matching lines...) Expand all
114 } 115 }
115 116
116 void FastTextAutosizer::beginLayout(RenderBlock* block) 117 void FastTextAutosizer::beginLayout(RenderBlock* block)
117 { 118 {
118 ASSERT(enabled()); 119 ASSERT(enabled());
119 #ifndef NDEBUG 120 #ifndef NDEBUG
120 m_blocksThatHaveBegunLayout.add(block); 121 m_blocksThatHaveBegunLayout.add(block);
121 #endif 122 #endif
122 123
123 if (!m_firstBlock) { 124 if (!m_firstBlock) {
124 prepareRenderViewInfo();
125 prepareClusterStack(block->parent()); 125 prepareClusterStack(block->parent());
126 m_firstBlock = block; 126 m_firstBlock = block;
pdr. 2014/02/28 22:13:33 Can we move m_firstBlock = block above prepareClus
skobes 2014/03/01 01:45:38 Done, but prepareClusterStack doesn't call isInLay
127 } else if (block == currentCluster()->m_root) { 127 } else if (block == currentCluster()->m_root) {
128 // Ignore beginLayout on the same block twice. 128 // Ignore beginLayout on the same block twice.
129 // This can happen with paginated overflow. 129 // This can happen with paginated overflow.
130 return; 130 return;
131 } 131 }
132 132
133 if (Cluster* cluster = maybeCreateCluster(block)) { 133 if (Cluster* cluster = maybeCreateCluster(block)) {
134 m_clusterStack.append(adoptPtr(cluster)); 134 m_clusterStack.append(adoptPtr(cluster));
135 if (block->isTable()) 135 if (block->isTable())
136 inflateTable(toRenderTable(block)); 136 inflateTable(toRenderTable(block));
137 } 137 }
138 138
139 if (block->childrenInline()) 139 if (block->childrenInline())
140 inflate(block); 140 inflate(block);
141 } 141 }
142 142
143 bool FastTextAutosizer::isInLayout() const
144 {
145 return !!m_firstBlock;
146 }
147
143 void FastTextAutosizer::inflateListItem(RenderListItem* listItem, RenderListMark er* listItemMarker) 148 void FastTextAutosizer::inflateListItem(RenderListItem* listItem, RenderListMark er* listItemMarker)
144 { 149 {
145 if (!enabled()) 150 if (!enabled())
146 return; 151 return;
147 ASSERT(listItem && listItemMarker); 152 ASSERT(listItem && listItemMarker);
148 #ifndef NDEBUG 153 #ifndef NDEBUG
149 m_blocksThatHaveBegunLayout.add(listItem); 154 m_blocksThatHaveBegunLayout.add(listItem);
150 #endif 155 #endif
151 // Force the LI to be inside the DBCAT when computing the multiplier. 156 // Force the LI to be inside the DBCAT when computing the multiplier.
152 // This guarantees that the DBCAT has entered layout, so we can ask for its width. 157 // This guarantees that the DBCAT has entered layout, so we can ask for its width.
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 if (!multiplier) 227 if (!multiplier)
223 multiplier = cluster->m_autosize ? clusterMultiplier(cluster) : 1.0f; 228 multiplier = cluster->m_autosize ? clusterMultiplier(cluster) : 1.0f;
224 applyMultiplier(descendant, multiplier); 229 applyMultiplier(descendant, multiplier);
225 applyMultiplier(descendant->parent(), multiplier); // Parent handles line spacing. 230 applyMultiplier(descendant->parent(), multiplier); // Parent handles line spacing.
226 } 231 }
227 } 232 }
228 } 233 }
229 234
230 bool FastTextAutosizer::enabled() 235 bool FastTextAutosizer::enabled()
231 { 236 {
232 if (!m_document->settings() || !m_document->page() || m_document->printing() ) 237 if (!m_document->settings()
238 || !m_document->page()
239 || m_document->printing()
240 || !m_document->settings()->textAutosizingEnabled())
233 return false; 241 return false;
234 242
235 return m_document->settings()->textAutosizingEnabled(); 243 if (!m_maxMultiplier)
244 updateRenderViewInfo();
245
246 if (m_maxMultiplier == 1.0f)
247 return false;
248
249 return true;
236 } 250 }
237 251
238 void FastTextAutosizer::prepareRenderViewInfo() 252 void FastTextAutosizer::updateRenderViewInfo()
239 { 253 {
254 if (!m_document->settings()
255 || !m_document->page()
256 || m_document->printing()
257 || !m_document->settings()->textAutosizingEnabled())
258 return;
259
240 RenderView* renderView = toRenderView(m_document->renderer()); 260 RenderView* renderView = toRenderView(m_document->renderer());
241 bool horizontalWritingMode = isHorizontalWritingMode(renderView->style()->wr itingMode()); 261 bool horizontalWritingMode = isHorizontalWritingMode(renderView->style()->wr itingMode());
242 262
243 LocalFrame* mainFrame = m_document->page()->mainFrame(); 263 LocalFrame* mainFrame = m_document->page()->mainFrame();
244 IntSize frameSize = m_document->settings()->textAutosizingWindowSizeOverride (); 264 IntSize frameSize = m_document->settings()->textAutosizingWindowSizeOverride ();
245 if (frameSize.isEmpty()) 265 if (frameSize.isEmpty())
246 frameSize = mainFrame->view()->unscaledVisibleContentSize(IncludeScrollb ars); 266 frameSize = mainFrame->view()->unscaledVisibleContentSize(IncludeScrollb ars);
247 m_frameWidth = horizontalWritingMode ? frameSize.width() : frameSize.height( ); 267 m_frameWidth = horizontalWritingMode ? frameSize.width() : frameSize.height( );
248 268
249 IntSize layoutSize = m_document->page()->mainFrame()->view()->layoutSize(); 269 IntSize layoutSize = m_document->page()->mainFrame()->view()->layoutSize();
250 m_layoutWidth = horizontalWritingMode ? layoutSize.width() : layoutSize.heig ht(); 270 m_layoutWidth = horizontalWritingMode ? layoutSize.width() : layoutSize.heig ht();
251 271
252 // Compute the base font scale multiplier based on device and accessibility settings. 272 // Compute the base font scale multiplier based on device and accessibility settings.
253 m_baseMultiplier = m_document->settings()->accessibilityFontScaleFactor(); 273 m_baseMultiplier = m_document->settings()->accessibilityFontScaleFactor();
254 // If the page has a meta viewport or @viewport, don't apply the device scal e adjustment. 274 // If the page has a meta viewport or @viewport, don't apply the device scal e adjustment.
255 const ViewportDescription& viewportDescription = m_document->page()->mainFra me()->document()->viewportDescription(); 275 const ViewportDescription& viewportDescription = m_document->page()->mainFra me()->document()->viewportDescription();
256 if (!viewportDescription.isSpecifiedByAuthor()) { 276 if (!viewportDescription.isSpecifiedByAuthor()) {
257 float deviceScaleAdjustment = m_document->settings()->deviceScaleAdjustm ent(); 277 float deviceScaleAdjustment = m_document->settings()->deviceScaleAdjustm ent();
258 m_baseMultiplier *= deviceScaleAdjustment; 278 m_baseMultiplier *= deviceScaleAdjustment;
259 } 279 }
280 m_maxMultiplier = m_frameWidth ? max(m_baseMultiplier *
pdr. 2014/02/28 22:13:33 m_maxMultiplier is never actually used as a float.
skobes 2014/03/01 01:45:38 Replaced with an enum.
281 (static_cast<float>(m_layoutWidth) / m_frameWidth), 1.0f) : 1.0f;
282
260 #ifndef NDEBUG 283 #ifndef NDEBUG
261 m_renderViewInfoPrepared = true; 284 m_renderViewInfoPrepared = true;
262 #endif 285 #endif
263 } 286 }
264 287
265 bool FastTextAutosizer::isFingerprintingCandidate(const RenderBlock* block) 288 bool FastTextAutosizer::isFingerprintingCandidate(const RenderBlock* block)
266 { 289 {
267 // FIXME: move the logic out of TextAutosizer.cpp into this class. 290 // FIXME: move the logic out of TextAutosizer.cpp into this class.
268 return block->isRenderView() 291 return block->isRenderView()
269 || (TextAutosizer::isAutosizingContainer(block) 292 || (TextAutosizer::isAutosizingContainer(block)
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 534
512 float FastTextAutosizer::multiplierFromBlock(const RenderBlock* block) 535 float FastTextAutosizer::multiplierFromBlock(const RenderBlock* block)
513 { 536 {
514 // If block->needsLayout() is false, it does not need to be in m_blocksThatH aveBegunLayout. 537 // If block->needsLayout() is false, it does not need to be in m_blocksThatH aveBegunLayout.
515 // This can happen during layout of a positioned object if the cluster's DBC AT is deeper 538 // This can happen during layout of a positioned object if the cluster's DBC AT is deeper
516 // than the positioned object's containing block, and wasn't marked as needi ng layout. 539 // than the positioned object's containing block, and wasn't marked as needi ng layout.
517 ASSERT(m_blocksThatHaveBegunLayout.contains(block) || !block->needsLayout()) ; 540 ASSERT(m_blocksThatHaveBegunLayout.contains(block) || !block->needsLayout()) ;
518 541
519 // Block width, in CSS pixels. 542 // Block width, in CSS pixels.
520 float blockWidth = widthFromBlock(block); 543 float blockWidth = widthFromBlock(block);
521 float multiplier = min(blockWidth, static_cast<float>(m_layoutWidth)) / m_fr ameWidth; 544 float multiplier = m_frameWidth ? min(blockWidth, static_cast<float>(m_layou tWidth)) / m_frameWidth : 1.0f;
522 545
523 return max(m_baseMultiplier * multiplier, 1.0f); 546 return max(m_baseMultiplier * multiplier, 1.0f);
524 } 547 }
525 548
526 const RenderBlock* FastTextAutosizer::deepestBlockContainingAllText(Cluster* clu ster) 549 const RenderBlock* FastTextAutosizer::deepestBlockContainingAllText(Cluster* clu ster)
527 { 550 {
528 if (!cluster->m_deepestBlockContainingAllText) 551 if (!cluster->m_deepestBlockContainingAllText)
529 cluster->m_deepestBlockContainingAllText = deepestBlockContainingAllText (cluster->m_root); 552 cluster->m_deepestBlockContainingAllText = deepestBlockContainingAllText (cluster->m_root);
530 553
531 return cluster->m_deepestBlockContainingAllText; 554 return cluster->m_deepestBlockContainingAllText;
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 return *m_blocksForFingerprint.get(fingerprint); 719 return *m_blocksForFingerprint.get(fingerprint);
697 } 720 }
698 721
699 RenderObject* FastTextAutosizer::nextChildSkippingChildrenOfBlocks(const RenderO bject* current, const RenderObject* stayWithin) 722 RenderObject* FastTextAutosizer::nextChildSkippingChildrenOfBlocks(const RenderO bject* current, const RenderObject* stayWithin)
700 { 723 {
701 if (current == stayWithin || !current->isRenderBlock()) 724 if (current == stayWithin || !current->isRenderBlock())
702 return current->nextInPreOrder(stayWithin); 725 return current->nextInPreOrder(stayWithin);
703 return current->nextInPreOrderAfterChildren(stayWithin); 726 return current->nextInPreOrderAfterChildren(stayWithin);
704 } 727 }
705 728
729 FastTextAutosizer::LayoutScope::LayoutScope(RenderBlock* block)
730 : m_textAutosizer(block->document().fastTextAutosizer())
731 , m_block(block)
732 {
733 if (m_textAutosizer) {
734 if (!m_textAutosizer->isInLayout())
735 m_textAutosizer->updateRenderViewInfo();
736
737 if (m_textAutosizer->enabled())
738 m_textAutosizer->beginLayout(m_block);
739 else
740 m_textAutosizer = 0;
741 }
742 }
743
744 FastTextAutosizer::LayoutScope::~LayoutScope()
745 {
746 if (m_textAutosizer)
747 m_textAutosizer->endLayout(m_block);
748 }
749
706 } // namespace WebCore 750 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/rendering/FastTextAutosizer.h ('k') | Source/core/rendering/RenderBlock.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698