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

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

Issue 263563006: [FastTextAutosizer] Remove printing checks from enabled() (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Update per reviewer comments Created 6 years, 7 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 | « LayoutTests/fast/text-autosizing/print-autosizing-expected.html ('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 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 #ifndef NDEBUG 313 #ifndef NDEBUG
314 m_blocksThatHaveBegunLayout.add(block); 314 m_blocksThatHaveBegunLayout.add(block);
315 #endif 315 #endif
316 if (Cluster* cluster = maybeCreateCluster(block)) 316 if (Cluster* cluster = maybeCreateCluster(block))
317 m_clusterStack.append(adoptPtr(cluster)); 317 m_clusterStack.append(adoptPtr(cluster));
318 } 318 }
319 } 319 }
320 320
321 void FastTextAutosizer::beginLayout(RenderBlock* block) 321 void FastTextAutosizer::beginLayout(RenderBlock* block)
322 { 322 {
323 ASSERT(enabled() && shouldHandleLayout()); 323 ASSERT(shouldHandleLayout());
324 324
325 if (prepareForLayout(block) == StopLayout) 325 if (prepareForLayout(block) == StopLayout)
326 return; 326 return;
327 327
328 if (Cluster* cluster = maybeCreateCluster(block)) { 328 if (Cluster* cluster = maybeCreateCluster(block)) {
329 m_clusterStack.append(adoptPtr(cluster)); 329 m_clusterStack.append(adoptPtr(cluster));
330 if (block->isTable()) 330 if (block->isTable())
331 inflateTable(toRenderTable(block)); 331 inflateTable(toRenderTable(block));
332 } 332 }
333 333
334 if (block->childrenInline() && block->firstChild()) 334 if (block->childrenInline() && block->firstChild())
335 inflate(block); 335 inflate(block);
336 } 336 }
337 337
338 void FastTextAutosizer::inflateListItem(RenderListItem* listItem, RenderListMark er* listItemMarker) 338 void FastTextAutosizer::inflateListItem(RenderListItem* listItem, RenderListMark er* listItemMarker)
339 { 339 {
340 if (!enabled() || !shouldHandleLayout()) 340 if (!shouldHandleLayout())
341 return; 341 return;
342 ASSERT(listItem && listItemMarker); 342 ASSERT(listItem && listItemMarker);
343 343
344 if (prepareForLayout(listItem) == StopLayout) 344 if (prepareForLayout(listItem) == StopLayout)
345 return; 345 return;
346 346
347 // Force the LI to be inside the DBCAT when computing the multiplier. 347 // Force the LI to be inside the DBCAT when computing the multiplier.
348 // This guarantees that the DBCAT has entered layout, so we can ask for its width. 348 // This guarantees that the DBCAT has entered layout, so we can ask for its width.
349 // It also makes sense because the list marker is autosized like a text node . 349 // It also makes sense because the list marker is autosized like a text node .
350 float multiplier = clusterMultiplier(currentCluster()); 350 float multiplier = clusterMultiplier(currentCluster());
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 } 412 }
413 } 413 }
414 } 414 }
415 } 415 }
416 } 416 }
417 } 417 }
418 } 418 }
419 419
420 void FastTextAutosizer::endLayout(RenderBlock* block) 420 void FastTextAutosizer::endLayout(RenderBlock* block)
421 { 421 {
422 ASSERT(enabled() && 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 #ifndef NDEBUG
430 m_blocksThatHaveBegunLayout.clear(); 430 m_blocksThatHaveBegunLayout.clear();
431 #endif 431 #endif
432 } else if (currentCluster()->m_root == block) { 432 } else if (currentCluster()->m_root == block) {
(...skipping 23 matching lines...) Expand all
456 if (descendant->parent()->isRenderInline()) 456 if (descendant->parent()->isRenderInline())
457 descendant->setPreferredLogicalWidthsDirty(MarkOnlyThis); 457 descendant->setPreferredLogicalWidthsDirty(MarkOnlyThis);
458 } 458 }
459 descendant = descendant->nextInPreOrder(block); 459 descendant = descendant->nextInPreOrder(block);
460 } 460 }
461 } 461 }
462 462
463 // FIXME(crbug.com/367864): Unify this with m_pageInfo.m_settingEnabled. 463 // FIXME(crbug.com/367864): Unify this with m_pageInfo.m_settingEnabled.
464 bool FastTextAutosizer::enabled() const 464 bool FastTextAutosizer::enabled() const
465 { 465 {
466 if (!m_document->settings() || !m_document->page() || m_document->printing() ) 466 return m_document->settings() && m_document->settings()->textAutosizingEnabl ed();
467 return false;
468
469 return m_document->settings()->textAutosizingEnabled();
470 } 467 }
471 468
472 bool FastTextAutosizer::shouldHandleLayout() const 469 bool FastTextAutosizer::shouldHandleLayout() const
473 { 470 {
474 return m_pageInfo.m_pageNeedsAutosizing && !m_updatePageInfoDeferred; 471 return enabled() && m_pageInfo.m_pageNeedsAutosizing && !m_updatePageInfoDef erred;
475 } 472 }
476 473
477 void FastTextAutosizer::updatePageInfoInAllFrames() 474 void FastTextAutosizer::updatePageInfoInAllFrames()
478 { 475 {
479 ASSERT(!enabled() || m_document->frame()->isMainFrame()); 476 ASSERT(!enabled() || m_document->frame()->isMainFrame());
480 477
481 for (LocalFrame* frame = m_document->frame(); frame; frame = frame->tree().t raverseNext()) { 478 for (LocalFrame* frame = m_document->frame(); frame; frame = frame->tree().t raverseNext()) {
482 if (FastTextAutosizer* textAutosizer = frame->document()->fastTextAutosi zer()) 479 if (FastTextAutosizer* textAutosizer = frame->document()->fastTextAutosi zer())
483 textAutosizer->updatePageInfo(); 480 textAutosizer->updatePageInfo();
484 } 481 }
485 } 482 }
486 483
487 void FastTextAutosizer::updatePageInfo() 484 void FastTextAutosizer::updatePageInfo()
488 { 485 {
486 if (m_updatePageInfoDeferred || !m_document->page())
487 return;
488
489 PageInfo previousPageInfo(m_pageInfo); 489 PageInfo previousPageInfo(m_pageInfo);
490 m_pageInfo.m_settingEnabled = enabled();
490 491
491 m_pageInfo.m_settingEnabled = m_document->settings() && m_document->settings ()->textAutosizingEnabled(); 492 if (!enabled() || m_document->printing()) {
492 if (!enabled()) { 493 m_pageInfo.m_pageNeedsAutosizing = false;
493 if (previousPageInfo.m_hasAutosized) 494 } else {
494 resetMultipliers(); 495 RenderView* renderView = toRenderView(m_document->renderer());
495 return; 496 bool horizontalWritingMode = isHorizontalWritingMode(renderView->style() ->writingMode());
497
498 LocalFrame* mainFrame = m_document->page()->mainFrame();
499 IntSize frameSize = m_document->settings()->textAutosizingWindowSizeOver ride();
500 if (frameSize.isEmpty())
501 frameSize = mainFrame->view()->unscaledVisibleContentSize(IncludeScr ollbars);
502 m_pageInfo.m_frameWidth = horizontalWritingMode ? frameSize.width() : fr ameSize.height();
503
504 IntSize layoutSize = mainFrame->view()->layoutSize();
505 m_pageInfo.m_layoutWidth = horizontalWritingMode ? layoutSize.width() : layoutSize.height();
506
507 // Compute the base font scale multiplier based on device and accessibil ity settings.
508 m_pageInfo.m_baseMultiplier = m_document->settings()->accessibilityFontS caleFactor();
509 // If the page has a meta viewport or @viewport, don't apply the device scale adjustment.
510 const ViewportDescription& viewportDescription = mainFrame->document()-> viewportDescription();
511 if (!viewportDescription.isSpecifiedByAuthor()) {
512 float deviceScaleAdjustment = m_document->settings()->deviceScaleAdj ustment();
513 m_pageInfo.m_baseMultiplier *= deviceScaleAdjustment;
514 }
515
516 m_pageInfo.m_pageNeedsAutosizing = !!m_pageInfo.m_frameWidth
517 && (m_pageInfo.m_baseMultiplier * (static_cast<float>(m_pageInfo.m_l ayoutWidth) / m_pageInfo.m_frameWidth) > 1.0f);
496 } 518 }
497 519
498 if (m_updatePageInfoDeferred) 520 if (m_pageInfo.m_pageNeedsAutosizing) {
499 return; 521 // If page info has changed, multipliers may have changed. Force a layou t to recompute them.
500 522 if (m_pageInfo.m_frameWidth != previousPageInfo.m_frameWidth
501 RenderView* renderView = toRenderView(m_document->renderer());
502 bool horizontalWritingMode = isHorizontalWritingMode(renderView->style()->wr itingMode());
503
504 LocalFrame* mainFrame = m_document->page()->mainFrame();
505 IntSize frameSize = m_document->settings()->textAutosizingWindowSizeOverride ();
506 if (frameSize.isEmpty())
507 frameSize = mainFrame->view()->unscaledVisibleContentSize(IncludeScrollb ars);
508 m_pageInfo.m_frameWidth = horizontalWritingMode ? frameSize.width() : frameS ize.height();
509
510 IntSize layoutSize = m_document->page()->mainFrame()->view()->layoutSize();
511 m_pageInfo.m_layoutWidth = horizontalWritingMode ? layoutSize.width() : layo utSize.height();
512
513 // Compute the base font scale multiplier based on device and accessibility settings.
514 m_pageInfo.m_baseMultiplier = m_document->settings()->accessibilityFontScale Factor();
515 // If the page has a meta viewport or @viewport, don't apply the device scal e adjustment.
516 const ViewportDescription& viewportDescription = m_document->page()->mainFra me()->document()->viewportDescription();
517 if (!viewportDescription.isSpecifiedByAuthor()) {
518 float deviceScaleAdjustment = m_document->settings()->deviceScaleAdjustm ent();
519 m_pageInfo.m_baseMultiplier *= deviceScaleAdjustment;
520 }
521
522 m_pageInfo.m_pageNeedsAutosizing = !!m_pageInfo.m_frameWidth
523 && (m_pageInfo.m_baseMultiplier * (static_cast<float>(m_pageInfo.m_layou tWidth) / m_pageInfo.m_frameWidth) > 1.0f);
524
525 // If we are no longer autosizing the page, we won't do anything during the next layout.
526 // Set all the multipliers back to 1 now.
527 if (!m_pageInfo.m_pageNeedsAutosizing && previousPageInfo.m_hasAutosized)
528 resetMultipliers();
529
530 // If page info has changed, multipliers may have changed. Force a layout to recompute them.
531 if (m_pageInfo.m_pageNeedsAutosizing
532 && (m_pageInfo.m_frameWidth != previousPageInfo.m_frameWidth
533 || m_pageInfo.m_layoutWidth != previousPageInfo.m_layoutWidth 523 || m_pageInfo.m_layoutWidth != previousPageInfo.m_layoutWidth
534 || m_pageInfo.m_baseMultiplier != previousPageInfo.m_baseMultiplier 524 || m_pageInfo.m_baseMultiplier != previousPageInfo.m_baseMultiplier
535 || m_pageInfo.m_settingEnabled != previousPageInfo.m_settingEnabled) ) 525 || m_pageInfo.m_settingEnabled != previousPageInfo.m_settingEnabled)
536 setAllTextNeedsLayout(); 526 setAllTextNeedsLayout();
527 } else if (previousPageInfo.m_hasAutosized) {
528 // If we are no longer autosizing the page, we won't do anything during the next layout.
529 // Set all the multipliers back to 1 now.
530 resetMultipliers();
531 m_pageInfo.m_hasAutosized = false;
532 }
537 } 533 }
538 534
539 void FastTextAutosizer::resetMultipliers() 535 void FastTextAutosizer::resetMultipliers()
540 { 536 {
541 RenderObject* renderer = m_document->renderer(); 537 RenderObject* renderer = m_document->renderer();
542 while (renderer) { 538 while (renderer) {
543 if (RenderStyle* style = renderer->style()) { 539 if (RenderStyle* style = renderer->style()) {
544 if (style->textAutosizingMultiplier() != 1) 540 if (style->textAutosizingMultiplier() != 1)
545 applyMultiplier(renderer, 1, LayoutNeeded); 541 applyMultiplier(renderer, 1, LayoutNeeded);
546 } 542 }
547 renderer = renderer->nextInPreOrder(); 543 renderer = renderer->nextInPreOrder();
548 } 544 }
549 m_pageInfo.m_hasAutosized = false;
550 } 545 }
551 546
552 void FastTextAutosizer::setAllTextNeedsLayout() 547 void FastTextAutosizer::setAllTextNeedsLayout()
553 { 548 {
554 RenderObject* renderer = m_document->renderer(); 549 RenderObject* renderer = m_document->renderer();
555 while (renderer) { 550 while (renderer) {
556 if (renderer->isText()) 551 if (renderer->isText())
557 renderer->setNeedsLayout(); 552 renderer->setNeedsLayout();
558 renderer = renderer->nextInPreOrder(); 553 renderer = renderer->nextInPreOrder();
559 } 554 }
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after
1064 return *m_blocksForFingerprint.get(fingerprint); 1059 return *m_blocksForFingerprint.get(fingerprint);
1065 } 1060 }
1066 1061
1067 FastTextAutosizer::LayoutScope::LayoutScope(RenderBlock* block) 1062 FastTextAutosizer::LayoutScope::LayoutScope(RenderBlock* block)
1068 : m_textAutosizer(block->document().fastTextAutosizer()) 1063 : m_textAutosizer(block->document().fastTextAutosizer())
1069 , m_block(block) 1064 , m_block(block)
1070 { 1065 {
1071 if (!m_textAutosizer) 1066 if (!m_textAutosizer)
1072 return; 1067 return;
1073 1068
1074 if (m_textAutosizer->enabled() && m_textAutosizer->shouldHandleLayout()) 1069 if (m_textAutosizer->shouldHandleLayout())
1075 m_textAutosizer->beginLayout(m_block); 1070 m_textAutosizer->beginLayout(m_block);
1076 else 1071 else
1077 m_textAutosizer = 0; 1072 m_textAutosizer = 0;
1078 } 1073 }
1079 1074
1080 FastTextAutosizer::LayoutScope::~LayoutScope() 1075 FastTextAutosizer::LayoutScope::~LayoutScope()
1081 { 1076 {
1082 if (m_textAutosizer) 1077 if (m_textAutosizer)
1083 m_textAutosizer->endLayout(m_block); 1078 m_textAutosizer->endLayout(m_block);
1084 } 1079 }
(...skipping 10 matching lines...) Expand all
1095 FastTextAutosizer::DeferUpdatePageInfo::~DeferUpdatePageInfo() 1090 FastTextAutosizer::DeferUpdatePageInfo::~DeferUpdatePageInfo()
1096 { 1091 {
1097 if (FastTextAutosizer* textAutosizer = m_mainFrame->document()->fastTextAuto sizer()) { 1092 if (FastTextAutosizer* textAutosizer = m_mainFrame->document()->fastTextAuto sizer()) {
1098 ASSERT(textAutosizer->m_updatePageInfoDeferred); 1093 ASSERT(textAutosizer->m_updatePageInfoDeferred);
1099 textAutosizer->m_updatePageInfoDeferred = false; 1094 textAutosizer->m_updatePageInfoDeferred = false;
1100 textAutosizer->updatePageInfoInAllFrames(); 1095 textAutosizer->updatePageInfoInAllFrames();
1101 } 1096 }
1102 } 1097 }
1103 1098
1104 } // namespace WebCore 1099 } // namespace WebCore
OLDNEW
« no previous file with comments | « LayoutTests/fast/text-autosizing/print-autosizing-expected.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698