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

Unified 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, 10 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 side-by-side diff with in-line comments
Download patch
Index: Source/core/rendering/FastTextAutosizer.cpp
diff --git a/Source/core/rendering/FastTextAutosizer.cpp b/Source/core/rendering/FastTextAutosizer.cpp
index 7d9c5172dc9c58b62cd208684b087fa016f9e9ae..79fc28ac96ce53a90fa6010dd9b68a25363bb1d3 100644
--- a/Source/core/rendering/FastTextAutosizer.cpp
+++ b/Source/core/rendering/FastTextAutosizer.cpp
@@ -63,6 +63,7 @@ FastTextAutosizer::FastTextAutosizer(const Document* document)
, m_frameWidth(0)
, m_layoutWidth(0)
, m_baseMultiplier(0)
+ , m_pageNeedsAutosizing(PageNeedsAutosizing_Unknown)
, m_firstBlock(0)
#ifndef NDEBUG
, m_renderViewInfoPrepared(false)
@@ -121,9 +122,8 @@ void FastTextAutosizer::beginLayout(RenderBlock* block)
#endif
if (!m_firstBlock) {
- prepareRenderViewInfo();
- prepareClusterStack(block->parent());
m_firstBlock = block;
+ prepareClusterStack(block->parent());
} else if (block == currentCluster()->m_root) {
// Ignore beginLayout on the same block twice.
// This can happen with paginated overflow.
@@ -140,6 +140,11 @@ void FastTextAutosizer::beginLayout(RenderBlock* block)
inflate(block);
}
+bool FastTextAutosizer::isInLayout() const
+{
+ return !!m_firstBlock;
+}
+
void FastTextAutosizer::inflateListItem(RenderListItem* listItem, RenderListMarker* listItemMarker)
{
if (!enabled())
@@ -229,14 +234,29 @@ void FastTextAutosizer::inflate(RenderBlock* block)
bool FastTextAutosizer::enabled()
{
- if (!m_document->settings() || !m_document->page() || m_document->printing())
+ if (!m_document->settings()
+ || !m_document->page()
+ || m_document->printing()
+ || !m_document->settings()->textAutosizingEnabled())
return false;
- return m_document->settings()->textAutosizingEnabled();
+ if (m_pageNeedsAutosizing == PageNeedsAutosizing_Unknown)
+ updateRenderViewInfo();
+
+ if (m_pageNeedsAutosizing == PageNeedsAutosizing_No)
+ return false;
+
+ return true;
}
-void FastTextAutosizer::prepareRenderViewInfo()
+void FastTextAutosizer::updateRenderViewInfo()
{
+ if (!m_document->settings()
pdr. 2014/03/01 05:16:43 Having these checks in two places doesn't seem rig
+ || !m_document->page()
+ || m_document->printing()
+ || !m_document->settings()->textAutosizingEnabled())
+ return;
+
RenderView* renderView = toRenderView(m_document->renderer());
bool horizontalWritingMode = isHorizontalWritingMode(renderView->style()->writingMode());
@@ -257,6 +277,14 @@ void FastTextAutosizer::prepareRenderViewInfo()
float deviceScaleAdjustment = m_document->settings()->deviceScaleAdjustment();
m_baseMultiplier *= deviceScaleAdjustment;
}
+
+ if (m_frameWidth) {
+ m_pageNeedsAutosizing = (m_baseMultiplier * (static_cast<float>(m_layoutWidth) / m_frameWidth) > 1.0f)
+ ? PageNeedsAutosizing_Yes : PageNeedsAutosizing_No;
+ } else {
+ m_pageNeedsAutosizing = PageNeedsAutosizing_Unknown;
+ }
+
#ifndef NDEBUG
m_renderViewInfoPrepared = true;
#endif
@@ -279,8 +307,8 @@ bool FastTextAutosizer::clusterWouldHaveEnoughTextToAutosize(const RenderBlock*
bool FastTextAutosizer::clusterHasEnoughTextToAutosize(Cluster* cluster, const RenderBlock* widthProvider)
{
- if (cluster->m_hasEnoughTextToAutosize != Unknown)
- return cluster->m_hasEnoughTextToAutosize == Yes;
+ if (cluster->m_hasEnoughTextToAutosize != HasEnoughTextToAutosize_Unknown)
+ return cluster->m_hasEnoughTextToAutosize == HasEnoughTextToAutosize_Yes;
const RenderBlock* root = cluster->m_root;
if (!widthProvider)
@@ -288,12 +316,12 @@ bool FastTextAutosizer::clusterHasEnoughTextToAutosize(Cluster* cluster, const R
// TextAreas and user-modifiable areas get a free pass to autosize regardless of text content.
if (root->isTextArea() || (root->style() && root->style()->userModify() != READ_ONLY)) {
- cluster->m_hasEnoughTextToAutosize = Yes;
+ cluster->m_hasEnoughTextToAutosize = HasEnoughTextToAutosize_Yes;
return true;
}
if (!TextAutosizer::containerShouldBeAutosized(root)) {
- cluster->m_hasEnoughTextToAutosize = No;
+ cluster->m_hasEnoughTextToAutosize = HasEnoughTextToAutosize_No;
return false;
}
@@ -321,14 +349,14 @@ bool FastTextAutosizer::clusterHasEnoughTextToAutosize(Cluster* cluster, const R
length += toRenderText(descendant)->text().stripWhiteSpace().length() * descendant->style()->specifiedFontSize();
if (length >= minimumTextLengthToAutosize) {
- cluster->m_hasEnoughTextToAutosize = Yes;
+ cluster->m_hasEnoughTextToAutosize = HasEnoughTextToAutosize_Yes;
return true;
}
}
descendant = descendant->nextInPreOrder(root);
}
- cluster->m_hasEnoughTextToAutosize = No;
+ cluster->m_hasEnoughTextToAutosize = HasEnoughTextToAutosize_No;
return false;
}
@@ -518,7 +546,7 @@ float FastTextAutosizer::multiplierFromBlock(const RenderBlock* block)
// Block width, in CSS pixels.
float blockWidth = widthFromBlock(block);
- float multiplier = min(blockWidth, static_cast<float>(m_layoutWidth)) / m_frameWidth;
+ float multiplier = m_frameWidth ? min(blockWidth, static_cast<float>(m_layoutWidth)) / m_frameWidth : 1.0f;
return max(m_baseMultiplier * multiplier, 1.0f);
}
@@ -703,4 +731,25 @@ RenderObject* FastTextAutosizer::nextChildSkippingChildrenOfBlocks(const RenderO
return current->nextInPreOrderAfterChildren(stayWithin);
}
+FastTextAutosizer::LayoutScope::LayoutScope(RenderBlock* block)
+ : m_textAutosizer(block->document().fastTextAutosizer())
+ , m_block(block)
+{
+ if (m_textAutosizer) {
+ if (!m_textAutosizer->isInLayout())
+ m_textAutosizer->updateRenderViewInfo();
pdr. 2014/03/01 05:16:43 Won't the enabled check below handle calling updat
+
+ if (m_textAutosizer->enabled())
+ m_textAutosizer->beginLayout(m_block);
+ else
+ m_textAutosizer = 0;
+ }
+}
+
+FastTextAutosizer::LayoutScope::~LayoutScope()
+{
+ if (m_textAutosizer)
+ m_textAutosizer->endLayout(m_block);
+}
+
} // namespace WebCore

Powered by Google App Engine
This is Rietveld 408576698