Chromium Code Reviews| Index: Source/core/rendering/FastTextAutosizer.cpp |
| diff --git a/Source/core/rendering/FastTextAutosizer.cpp b/Source/core/rendering/FastTextAutosizer.cpp |
| index 5cbbf1bd02c399e5b79e4b740fb5611d8b3f28eb..5fda6e47f68ff5c9ad794e1404d1569b00bcae93 100644 |
| --- a/Source/core/rendering/FastTextAutosizer.cpp |
| +++ b/Source/core/rendering/FastTextAutosizer.cpp |
| @@ -234,10 +234,11 @@ FastTextAutosizer::FastTextAutosizer(const Document* document) |
| , m_frameWidth(0) |
| , m_layoutWidth(0) |
| , m_baseMultiplier(0) |
| - , m_pageAutosizingStatus(PageAutosizingStatusUnknown) |
| + , m_pageNeedsAutosizing(false) |
| + , m_previouslyAutosized(false) |
| + , m_updatePageInfoDeferred(false) |
| , m_firstBlock(0) |
| #ifndef NDEBUG |
| - , m_renderViewInfoPrepared(false) |
| , m_blocksThatHaveBegunLayout() |
| #endif |
| , m_superclusters() |
| @@ -290,7 +291,7 @@ void FastTextAutosizer::prepareClusterStack(const RenderObject* renderer) |
| void FastTextAutosizer::beginLayout(RenderBlock* block) |
| { |
| - ASSERT(enabled() && m_pageAutosizingStatus == PageNeedsAutosizing); |
| + ASSERT(enabled() && m_pageNeedsAutosizing); |
| #ifndef NDEBUG |
| m_blocksThatHaveBegunLayout.add(block); |
| #endif |
| @@ -316,7 +317,7 @@ void FastTextAutosizer::beginLayout(RenderBlock* block) |
| void FastTextAutosizer::inflateListItem(RenderListItem* listItem, RenderListMarker* listItemMarker) |
| { |
| - if (!enabled() || m_pageAutosizingStatus != PageNeedsAutosizing) |
| + if (!enabled() || !m_pageNeedsAutosizing) |
| return; |
| ASSERT(listItem && listItemMarker); |
| #ifndef NDEBUG |
| @@ -379,11 +380,10 @@ void FastTextAutosizer::inflateTable(RenderTable* table) |
| void FastTextAutosizer::endLayout(RenderBlock* block) |
| { |
| - ASSERT(enabled() && m_pageAutosizingStatus == PageNeedsAutosizing); |
| + ASSERT(enabled() && m_pageNeedsAutosizing); |
| if (block == m_firstBlock) { |
| m_firstBlock = 0; |
| - m_pageAutosizingStatus = PageAutosizingStatusUnknown; |
| m_clusterStack.clear(); |
| m_superclusters.clear(); |
| #ifndef NDEBUG |
| @@ -425,8 +425,28 @@ bool FastTextAutosizer::enabled() |
| return m_document->settings()->textAutosizingEnabled(); |
| } |
| -void FastTextAutosizer::updateRenderViewInfo() |
| +void FastTextAutosizer::updatePageInfoInAllFrames() |
| { |
| + if (!enabled()) |
| + return; |
| + |
| + ASSERT(m_document->frame()->isMainFrame()); |
| + |
| + for (LocalFrame* frame = m_document->frame(); frame; frame = frame->tree().traverseNext()) { |
| + if (FastTextAutosizer* textAutosizer = frame->document()->fastTextAutosizer()) |
| + textAutosizer->updatePageInfo(); |
| + } |
| +} |
| + |
| +void FastTextAutosizer::updatePageInfo() |
| +{ |
| + if (!enabled() || m_updatePageInfoDeferred) |
| + return; |
| + |
| + int previousFrameWidth = m_frameWidth; |
| + int previousLayoutWidth = m_layoutWidth; |
| + float previousBaseMultiplier = m_baseMultiplier; |
| + |
| RenderView* renderView = toRenderView(m_document->renderer()); |
| bool horizontalWritingMode = isHorizontalWritingMode(renderView->style()->writingMode()); |
| @@ -448,12 +468,42 @@ void FastTextAutosizer::updateRenderViewInfo() |
| m_baseMultiplier *= deviceScaleAdjustment; |
| } |
| - m_pageAutosizingStatus = m_frameWidth && (m_baseMultiplier * (static_cast<float>(m_layoutWidth) / m_frameWidth) > 1.0f) |
| - ? PageNeedsAutosizing : PageDoesNotNeedAutosizing; |
| + m_pageNeedsAutosizing = !!m_frameWidth |
| + && (m_baseMultiplier * (static_cast<float>(m_layoutWidth) / m_frameWidth) > 1.0f); |
| -#ifndef NDEBUG |
| - m_renderViewInfoPrepared = true; |
| -#endif |
| + if (!m_pageNeedsAutosizing && m_previouslyAutosized) |
| + resetMultipliers(); |
| + |
| + if (m_pageNeedsAutosizing |
| + && (m_frameWidth != previousFrameWidth |
| + || m_layoutWidth != previousLayoutWidth |
| + || m_baseMultiplier != previousBaseMultiplier)) |
| + invalidateMultipliers(); |
| +} |
| + |
| +void FastTextAutosizer::resetMultipliers() |
| +{ |
| + RenderObject* renderer = m_document->renderer(); |
| + while (renderer) { |
| + if (RenderStyle* style = renderer->style()) { |
| + if (style->textAutosizingMultiplier() != 1) |
| + applyMultiplier(renderer, 1); |
|
pdr.
2014/03/24 01:03:18
Do we need to setNeedsLayout here? Normally, apply
skobes
2014/03/25 01:23:24
You're right, applyMultiplier assumes it is inside
|
| + } |
| + renderer = renderer->nextInPreOrder(); |
| + } |
| + m_previouslyAutosized = false; |
| +} |
| + |
| +void FastTextAutosizer::invalidateMultipliers() |
|
timvolodine
2014/03/24 15:24:27
nit: the name seems a bit confusing, it is not dir
skobes
2014/03/25 01:23:24
Done.
|
| +{ |
| + RenderObject* renderer = m_document->renderer(); |
| + while (renderer) { |
| + if (renderer->isText()) { |
| + renderer->setNeedsLayout(); |
| + renderer->parent()->setNeedsLayout(); |
|
pdr.
2014/03/24 01:03:18
setNeedsLayout already walks up the parent chain s
skobes
2014/03/25 01:23:24
Done. (This was an unsuccessful initial attempt to
|
| + } |
| + renderer = renderer->nextInPreOrder(); |
| + } |
| } |
| bool FastTextAutosizer::clusterWouldHaveEnoughTextToAutosize(const RenderBlock* root, const RenderBlock* widthProvider) |
| @@ -626,7 +676,6 @@ const RenderBlock* FastTextAutosizer::deepestCommonAncestor(BlockSet& blocks) |
| float FastTextAutosizer::clusterMultiplier(Cluster* cluster) |
| { |
| - ASSERT(m_renderViewInfoPrepared); |
| if (!cluster->m_multiplier) { |
| if (cluster->m_root->isTable() |
| || isIndependentDescendant(cluster->m_root) |
| @@ -807,6 +856,9 @@ void FastTextAutosizer::applyMultiplier(RenderObject* renderer, float multiplier |
| style->setTextAutosizingMultiplier(multiplier); |
| style->setUnique(); |
| renderer->setStyleInternal(style.release()); |
| + |
| + if (multiplier != 1) |
| + m_previouslyAutosized = true; |
| } |
| bool FastTextAutosizer::isWiderOrNarrowerDescendant(Cluster* cluster) |
| @@ -917,15 +969,7 @@ FastTextAutosizer::LayoutScope::LayoutScope(RenderBlock* block) |
| if (!m_textAutosizer) |
| return; |
| - if (!m_textAutosizer->enabled()) { |
| - m_textAutosizer = 0; |
| - return; |
| - } |
| - |
| - if (m_textAutosizer->m_pageAutosizingStatus == PageAutosizingStatusUnknown) |
| - m_textAutosizer->updateRenderViewInfo(); |
| - |
| - if (m_textAutosizer->m_pageAutosizingStatus == PageNeedsAutosizing) |
| + if (m_textAutosizer->enabled() && m_textAutosizer->m_pageNeedsAutosizing) |
| m_textAutosizer->beginLayout(m_block); |
| else |
| m_textAutosizer = 0; |