Apply font size inflation to text. (Bug 627842, patch 9) r=roc

This applies the font size inflation to reflow and painting of text
frames.  However, it does not (by design) apply to intrinsic width
computation, since the inflation is itself a function of the containers
width, which can depend on the intrinsic width.
This commit is contained in:
L. David Baron 2011-11-23 18:48:23 -08:00
Родитель f1feb010c8
Коммит 93a3cc8415
4 изменённых файлов: 382 добавлений и 147 удалений

Просмотреть файл

@ -2167,9 +2167,9 @@ static nsresult GetPartialTextRect(nsLayoutUtils::RectCallback* aCallback,
continue;
// overlapping with the offset we want
f->EnsureTextRun();
NS_ENSURE_TRUE(f->GetTextRun(), NS_ERROR_OUT_OF_MEMORY);
bool rtl = f->GetTextRun()->IsRightToLeft();
f->EnsureTextRun(nsTextFrame::eInflated);
NS_ENSURE_TRUE(f->GetTextRun(nsTextFrame::eInflated), NS_ERROR_OUT_OF_MEMORY);
bool rtl = f->GetTextRun(nsTextFrame::eInflated)->IsRightToLeft();
nsRect r(f->GetOffsetTo(relativeTo), f->GetSize());
if (fstart < aStartOffset) {
// aStartOffset is within this frame

Просмотреть файл

@ -4278,8 +4278,8 @@ nsLayoutUtils::GetFontFacesForText(nsIFrame* aFrame,
}
// overlapping with the offset we want
gfxSkipCharsIterator iter = curr->EnsureTextRun();
gfxTextRun* textRun = curr->GetTextRun();
gfxSkipCharsIterator iter = curr->EnsureTextRun(nsTextFrame::eInflated);
gfxTextRun* textRun = curr->GetTextRun(nsTextFrame::eInflated);
NS_ENSURE_TRUE(textRun, NS_ERROR_OUT_OF_MEMORY);
PRUint32 skipStart = iter.ConvertOriginalToSkipped(fstart);
@ -4302,12 +4302,15 @@ nsLayoutUtils::GetTextRunMemoryForFrames(nsIFrame* aFrame, PRUint64* aTotal)
if (aFrame->GetType() == nsGkAtoms::textFrame) {
nsTextFrame* textFrame = static_cast<nsTextFrame*>(aFrame);
gfxTextRun *run = textFrame->GetTextRun();
if (run) {
if (aTotal) {
run->AccountForSize(aTotal);
} else {
run->ClearSizeAccounted();
for (PRUint32 i = 0; i < 2; ++i) {
gfxTextRun *run = textFrame->GetTextRun(
(i != 0) ? nsTextFrame::eInflated : nsTextFrame::eNotInflated);
if (run) {
if (aTotal) {
run->AccountForSize(aTotal);
} else {
run->ClearSizeAccounted();
}
}
}
return NS_OK;

Просмотреть файл

@ -65,13 +65,16 @@ class PropertyProvider;
// reflow
#define TEXT_HAS_NONCOLLAPSED_CHARACTERS NS_FRAME_STATE_BIT(31)
#define TEXT_HAS_FONT_INFLATION NS_FRAME_STATE_BIT(61)
class nsTextFrame : public nsFrame {
public:
NS_DECL_FRAMEARENA_HELPERS
friend class nsContinuingTextFrame;
nsTextFrame(nsStyleContext* aContext) : nsFrame(aContext)
nsTextFrame(nsStyleContext* aContext)
: nsFrame(aContext)
{
NS_ASSERTION(mContentOffset == 0, "Bogus content offset");
}
@ -225,7 +228,13 @@ public:
#ifdef ACCESSIBILITY
virtual already_AddRefed<nsAccessible> CreateAccessible();
#endif
float GetFontSizeInflation() const;
bool HasFontSizeInflation() const {
return (GetStateBits() & TEXT_HAS_FONT_INFLATION) != 0;
}
void SetFontSizeInflation(float aInflation);
virtual void MarkIntrinsicWidthsDirty();
virtual nscoord GetMinWidth(nsRenderingContext *aRenderingContext);
virtual nscoord GetPrefWidth(nsRenderingContext *aRenderingContext);
@ -366,6 +375,16 @@ public:
// boundary.
PRInt32 GetInFlowContentLength();
enum TextRunType {
// Anything in reflow (but not intrinsic width calculation) or
// painting should use the inflated text run (i.e., with font size
// inflation applied).
eInflated,
// Intrinsic width calculation should use the non-inflated text run.
// When there is font size inflation, it will be different.
eNotInflated
};
/**
* Acquires the text run for this content, if necessary.
* @param aRC the rendering context to use as a reference for creating
@ -378,19 +397,49 @@ public:
* to offsets into the textrun; its initial offset is set to this frame's
* content offset
*/
gfxSkipCharsIterator EnsureTextRun(gfxContext* aReferenceContext = nsnull,
gfxSkipCharsIterator EnsureTextRun(TextRunType aWhichTextRun,
float aInflation,
gfxContext* aReferenceContext = nsnull,
nsIFrame* aLineContainer = nsnull,
const nsLineList::iterator* aLine = nsnull,
PRUint32* aFlowEndInTextRun = nsnull);
// Since we can't reference |this| in default arguments:
gfxSkipCharsIterator EnsureTextRun(TextRunType aWhichTextRun) {
return EnsureTextRun(aWhichTextRun,
(aWhichTextRun == eInflated)
? GetFontSizeInflation() : 1.0f);
}
gfxTextRun* GetTextRun() { return mTextRun; }
void SetTextRun(gfxTextRun* aTextRun) { mTextRun = aTextRun; }
gfxTextRun* GetTextRun(TextRunType aWhichTextRun) {
if (aWhichTextRun == eInflated || !HasFontSizeInflation())
return mTextRun;
return GetUninflatedTextRun();
}
gfxTextRun* GetUninflatedTextRun();
void SetTextRun(gfxTextRun* aTextRun, TextRunType aWhichTextRun,
float aInflation);
/**
* Clears out |mTextRun| from all frames that hold a reference to it,
* starting at |aStartContinuation|, or if it's nsnull, starting at |this|.
* Deletes |mTextRun| if all references were cleared and it's not cached.
* Notify the frame that it should drop its pointer to a text run.
* Returns whether the text run was removed (i.e., whether it was
* associated with this frame, either as its inflated or non-inflated
* text run.
*/
void ClearTextRun(nsTextFrame* aStartContinuation);
bool RemoveTextRun(gfxTextRun* aTextRun);
/**
* Clears out |mTextRun| (or the uninflated text run, when aInflated
* is nsTextFrame::eNotInflated and there is inflation) from all frames that hold a
* reference to it, starting at |aStartContinuation|, or if it's
* nsnull, starting at |this|. Deletes the text run if all references
* were cleared and it's not cached.
*/
void ClearTextRun(nsTextFrame* aStartContinuation,
TextRunType aWhichTextRun);
void ClearTextRuns() {
ClearTextRun(nsnull, nsTextFrame::eInflated);
ClearTextRun(nsnull, nsTextFrame::eNotInflated);
}
// Get the DOM content range mapped by this frame after excluding
// whitespace subject to start-of-line and end-of-line trimming.

Разница между файлами не показана из-за своего большого размера Загрузить разницу