Use the same width basis for font inflation throughout a font inflation flow root. (Bug 747720, patch 3) r=roc

Font inflation flow roots are similar to block formatting contexts,
though I'm trying to make not all block formatting contexts be flow
roots in later patches on this bug, bug 707195, and related bugs.

This will lead to more consistent font size inflation in a flow of text
where the blocks vary in width (e.g., because some of the blocks have
horizontal margins) but we determine the text to comprise a single flow.
This commit is contained in:
L. David Baron 2012-05-20 22:18:27 -07:00
parent 11f5c76522
commit 4a752104bd
4 changed files with 37 additions and 56 deletions

View File

@ -4765,14 +4765,6 @@ nsLayoutUtils::FontSizeInflationInner(const nsIFrame *aFrame,
return (1.0f / ratio) + (1.0f / 3.0f);
}
static inline bool
InflationDataSaysEnabled(const nsIFrame *aFrame)
{
nsFontInflationData *data =
nsFontInflationData::FindFontInflationDataFor(aFrame);
return data && data->InflationEnabled();
}
static bool
ShouldInflateFontsForContainer(const nsIFrame *aFrame)
{
@ -4789,55 +4781,35 @@ ShouldInflateFontsForContainer(const nsIFrame *aFrame)
!(aFrame->GetStateBits() & NS_FRAME_IN_CONSTRAINED_HEIGHT) &&
// We also want to disable font inflation for containers that have
// preformatted text.
styleText->WhiteSpaceCanWrap() &&
InflationDataSaysEnabled(aFrame);
styleText->WhiteSpaceCanWrap();
}
nscoord
nsLayoutUtils::InflationMinFontSizeFor(const nsIFrame *aFrame,
WidthDetermination aWidthDetermination)
{
#ifdef DEBUG
if (aWidthDetermination == eNotInReflow) {
// Check that neither this frame nor any of its ancestors are
// currently being reflowed.
// It's ok for box frames (but not arbitrary ancestors of box frames)
// since they set their size before reflow.
if (!(aFrame->IsBoxFrame() && IsContainerForFontSizeInflation(aFrame))) {
for (const nsIFrame *f = aFrame; f; f = f->GetParent()) {
NS_ABORT_IF_FALSE(!(f->GetStateBits() & NS_FRAME_IN_REFLOW),
"must call nsHTMLReflowState& version during reflow");
}
}
// It's ok if frames are dirty, or even if they've never been
// reflowed, since they will be eventually and then we'll get the
// right size.
}
#endif
nsPresContext *presContext = aFrame->PresContext();
if (!FontSizeInflationEnabled(presContext) ||
presContext->mInflationDisabledForShrinkWrap) {
return 0;
}
if (aWidthDetermination == eInReflow) {
nsIFrame *container = presContext->mCurrentInflationContainer;
if (!container || !ShouldInflateFontsForContainer(container)) {
return 0;
}
return MinimumFontSizeFor(presContext,
presContext->mCurrentInflationContainerWidth);
}
for (const nsIFrame *f = aFrame; f; f = f->GetParent()) {
if (IsContainerForFontSizeInflation(f)) {
if (!ShouldInflateFontsForContainer(f)) {
return 0;
}
nsFontInflationData *data =
nsFontInflationData::FindFontInflationDataFor(aFrame);
// FIXME: The need to null-check here is sort of a bug, and might
// lead to incorrect results.
if (!data || !data->InflationEnabled()) {
return 0;
}
return MinimumFontSizeFor(aFrame->PresContext(),
f->GetContentRect().width);
data->EffectiveWidth());
}
}
@ -4850,24 +4822,6 @@ float
nsLayoutUtils::FontSizeInflationFor(const nsIFrame *aFrame,
WidthDetermination aWidthDetermination)
{
#ifdef DEBUG
if (aWidthDetermination == eNotInReflow) {
// Check that neither this frame nor any of its ancestors are
// currently being reflowed.
// It's ok for box frames (but not arbitrary ancestors of box frames)
// since they set their size before reflow.
if (!(aFrame->IsBoxFrame() && IsContainerForFontSizeInflation(aFrame))) {
for (const nsIFrame *f = aFrame; f; f = f->GetParent()) {
NS_ABORT_IF_FALSE(!(f->GetStateBits() & NS_FRAME_IN_REFLOW),
"must call nsHTMLReflowState& version during reflow");
}
}
// It's ok if frames are dirty, or even if they've never been
// reflowed, since they will be eventually and then we'll get the
// right size.
}
#endif
if (!FontSizeInflationEnabled(aFrame->PresContext())) {
return 1.0;
}

View File

@ -92,3 +92,5 @@ fuzzy-if(gtk2Widget,1,8) test-pref(font.size.inflation.emPerLine,15) test-pref(f
fuzzy-if(gtk2Widget,1,8) test-pref(font.size.inflation.emPerLine,15) test-pref(font.size.inflation.lineThreshold,100) == threshold-select-combobox-contents-under-2.html threshold-select-combobox-contents-under-2.html
fuzzy-if(gtk2Widget,1,8) test-pref(font.size.inflation.emPerLine,15) test-pref(font.size.inflation.lineThreshold,100) == threshold-select-combobox-contents-at-1.html threshold-select-combobox-contents-at-1-ref.html
fuzzy-if(gtk2Widget,1,8) test-pref(font.size.inflation.emPerLine,15) test-pref(font.size.inflation.lineThreshold,100) == threshold-select-combobox-contents-at-2.html threshold-select-combobox-contents-at-2-ref.html
test-pref(font.size.inflation.emPerLine,15) test-pref(font.size.inflation.lineThreshold,0) == relevant-width-1.html relevant-width-1-ref.html

View File

@ -0,0 +1,9 @@
<!DOCTYPE HTML>
<style>
div { font-size: 34px; width: 450px }
div.inner { width: 300px }
</style>
<div class="middle">
Text in middle.
<div class="inner">Text in inner.</div>
</div>

View File

@ -0,0 +1,16 @@
<!DOCTYPE HTML>
<style>
div.outer { font-size: 12px; width: 600px }
div.middle { width: 450px; }
div.inner { width: 300px; }
</style>
<!--
In a 450px container, the minimum font size at 15em per line is 30px.
This means we map 0px-45px into 30px-45px, so 12px gets mapped to 34px.
-->
<div class="outer">
<div class="middle">
Text in middle.
<div class="inner">Text in inner.</div>
</div>
</div>