Bug 1088781 - Rename nsLayoutUtils::GetStringWidth to nsLayoutUtils::AppUnitWidthOfStringBidi. r=dholbert

This commit is contained in:
Jonathan Watt 2014-10-26 17:57:49 +00:00
parent f605de8de4
commit 2ad71e273d
9 changed files with 65 additions and 67 deletions

View File

@ -4680,15 +4680,6 @@ static int32_t GetMaxChunkLength(nsFontMetrics& aFontMetrics)
return std::min(aFontMetrics.GetMaxStringLength(), MAX_GFX_TEXT_BUF_SIZE);
}
nscoord
nsLayoutUtils::AppUnitWidthOfString(const nsString& aString,
nsFontMetrics& aFontMetrics,
nsRenderingContext& aContext)
{
return AppUnitWidthOfString(aString.get(), aString.Length(),
aFontMetrics, aContext);
}
nscoord
nsLayoutUtils::AppUnitWidthOfString(const char16_t *aString,
uint32_t aLength,
@ -4706,6 +4697,26 @@ nsLayoutUtils::AppUnitWidthOfString(const char16_t *aString,
return width;
}
nscoord
nsLayoutUtils::AppUnitWidthOfStringBidi(const char16_t* aString,
uint32_t aLength,
const nsIFrame* aFrame,
nsFontMetrics& aFontMetrics,
nsRenderingContext& aContext)
{
nsPresContext* presContext = aFrame->PresContext();
if (presContext->BidiEnabled()) {
nsBidiLevel level =
nsBidiPresUtils::BidiLevelFromStyle(aFrame->StyleContext());
return nsBidiPresUtils::MeasureTextWidth(aString, aLength, level,
presContext, aContext,
aFontMetrics);
}
aFontMetrics.SetTextRunRTL(false);
return nsLayoutUtils::AppUnitWidthOfString(aString, aLength, aFontMetrics,
aContext);
}
nsBoundingMetrics
nsLayoutUtils::AppUnitBoundsOfString(const char16_t* aString,
uint32_t aLength,
@ -4799,26 +4810,6 @@ nsLayoutUtils::DrawUniDirString(const char16_t* aString,
}
}
nscoord
nsLayoutUtils::GetStringWidth(const nsIFrame* aFrame,
nsRenderingContext* aContext,
nsFontMetrics& aFontMetrics,
const char16_t* aString,
int32_t aLength)
{
nsPresContext* presContext = aFrame->PresContext();
if (presContext->BidiEnabled()) {
nsBidiLevel level =
nsBidiPresUtils::BidiLevelFromStyle(aFrame->StyleContext());
return nsBidiPresUtils::MeasureTextWidth(aString, aLength,
level, presContext, *aContext,
aFontMetrics);
}
aFontMetrics.SetTextRunRTL(false);
return nsLayoutUtils::AppUnitWidthOfString(aString, aLength, aFontMetrics,
*aContext);
}
/* static */ void
nsLayoutUtils::PaintTextShadow(const nsIFrame* aFrame,
nsRenderingContext* aContext,

View File

@ -1326,11 +1326,28 @@ public:
}
static nscoord AppUnitWidthOfString(const nsString& aString,
nsFontMetrics& aFontMetrics,
nsRenderingContext& aContext);
nsRenderingContext& aContext) {
return nsLayoutUtils::AppUnitWidthOfString(aString.get(), aString.Length(),
aFontMetrics, aContext);
}
static nscoord AppUnitWidthOfString(const char16_t *aString,
uint32_t aLength,
nsFontMetrics& aFontMetrics,
nsRenderingContext& aContext);
static nscoord AppUnitWidthOfStringBidi(const nsString& aString,
const nsIFrame* aFrame,
nsFontMetrics& aFontMetrics,
nsRenderingContext& aContext) {
return nsLayoutUtils::AppUnitWidthOfStringBidi(aString.get(),
aString.Length(), aFrame,
aFontMetrics, aContext);
}
static nscoord AppUnitWidthOfStringBidi(const char16_t* aString,
uint32_t aLength,
const nsIFrame* aFrame,
nsFontMetrics& aFontMetrics,
nsRenderingContext& aContext);
static nsBoundingMetrics AppUnitBoundsOfString(const char16_t* aString,
uint32_t aLength,
nsFontMetrics& aFontMetrics,
@ -1353,12 +1370,6 @@ public:
nsFontMetrics& aFontMetrics,
nsRenderingContext& aContext);
static nscoord GetStringWidth(const nsIFrame* aFrame,
nsRenderingContext* aContext,
nsFontMetrics& aFontMetrics,
const char16_t* aString,
int32_t aLength);
/**
* Helper function for drawing text-shadow. The callback's job
* is to draw whatever needs to be blurred onto the given context.

View File

@ -763,9 +763,8 @@ TextOverflow::Marker::SetupString(nsIFrame* aFrame)
nsRefPtr<nsFontMetrics> fm;
nsLayoutUtils::GetFontMetricsForFrame(aFrame, getter_AddRefs(fm),
nsLayoutUtils::FontSizeInflationFor(aFrame));
mWidth = nsLayoutUtils::GetStringWidth(aFrame, rc, *fm,
mStyle->mString.get(),
mStyle->mString.Length());
mWidth = nsLayoutUtils::AppUnitWidthOfStringBidi(mStyle->mString, aFrame,
*fm, *rc);
}
mIntrinsicISize = mWidth;
mInitialized = true;

View File

@ -602,8 +602,8 @@ nsBulletFrame::GetDesiredSize(nsPresContext* aCX,
GetListItemText(text);
finalSize.BSize(wm) = fm->MaxHeight();
finalSize.ISize(wm) =
nsLayoutUtils::GetStringWidth(this, aRenderingContext, *fm,
text.get(), text.Length());
nsLayoutUtils::AppUnitWidthOfStringBidi(text, this, *fm,
*aRenderingContext);
aMetrics.SetBlockStartAscent(fm->MaxAscent());
break;
}

View File

@ -1035,7 +1035,8 @@ nsImageFrame::MeasureString(const char16_t* aString,
// Measure this chunk of text, and see if it fits
nscoord width =
nsLayoutUtils::GetStringWidth(this, &aContext, aFontMetrics, aString, len);
nsLayoutUtils::AppUnitWidthOfStringBidi(aString, len, this, aFontMetrics,
aContext);
bool fits = (totalWidth + width) <= aMaxWidth;
// If it fits on the line, or it's the first word we've processed then

View File

@ -243,10 +243,9 @@ nscoord nsPageFrame::GetXPosition(nsRenderingContext& aRenderingContext,
int32_t aJust,
const nsString& aStr)
{
nscoord width = nsLayoutUtils::GetStringWidth(this, &aRenderingContext,
aFontMetrics,
aStr.get(), aStr.Length());
nscoord width = nsLayoutUtils::AppUnitWidthOfStringBidi(aStr, this,
aFontMetrics,
aRenderingContext);
nscoord x = aRect.x;
switch (aJust) {
case nsIPrintSettings::kJustLeft:

View File

@ -727,8 +727,8 @@ nsListBoxBodyFrame::ComputeIntrinsicISize(nsBoxLayoutState& aBoxLayoutState)
getter_AddRefs(fm));
nscoord textWidth =
nsLayoutUtils::GetStringWidth(this, rendContext, *fm,
value.get(), value.Length());
nsLayoutUtils::AppUnitWidthOfStringBidi(value, this, *fm,
*rendContext);
textWidth += width;
if (textWidth > largestWidth)

View File

@ -613,10 +613,9 @@ nsTextBoxFrame::CalculateTitleForWidth(nsPresContext* aPresContext,
nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fm));
// see if the text will completely fit in the width given
nscoord titleWidth = nsLayoutUtils::GetStringWidth(this, &aRenderingContext,
*fm,
mTitle.get(), mTitle.Length());
nscoord titleWidth =
nsLayoutUtils::AppUnitWidthOfStringBidi(mTitle, this, *fm,
aRenderingContext);
if (titleWidth <= aWidth) {
mCroppedTitle = mTitle;
if (HasRTLChars(mTitle)) {
@ -713,8 +712,8 @@ nsTextBoxFrame::CalculateTitleForWidth(nsPresContext* aPresContext,
case CropCenter:
{
nscoord stringWidth =
nsLayoutUtils::GetStringWidth(this, &aRenderingContext, *fm,
mTitle.get(), mTitle.Length());
nsLayoutUtils::AppUnitWidthOfStringBidi(mTitle, this, *fm,
aRenderingContext);
if (stringWidth <= aWidth) {
// the entire string will fit in the maximum width
mCroppedTitle.Insert(mTitle, 0);
@ -771,8 +770,8 @@ nsTextBoxFrame::CalculateTitleForWidth(nsPresContext* aPresContext,
break;
}
return nsLayoutUtils::GetStringWidth(this, &aRenderingContext, *fm,
mCroppedTitle.get(), mCroppedTitle.Length());
return nsLayoutUtils::AppUnitWidthOfStringBidi(mCroppedTitle, this, *fm,
aRenderingContext);
}
#define OLD_ELLIPSIS NS_LITERAL_STRING("...")
@ -1000,8 +999,8 @@ nsTextBoxFrame::GetTextSize(nsPresContext* aPresContext,
nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fontMet));
aSize.height = fontMet->MaxHeight();
aSize.width =
nsLayoutUtils::GetStringWidth(this, &aRenderingContext, *fontMet,
aString.get(), aString.Length());
nsLayoutUtils::AppUnitWidthOfStringBidi(aString, this, *fontMet,
aRenderingContext);
aAscent = fontMet->MaxAscent();
}

View File

@ -1319,9 +1319,9 @@ nsTreeBodyFrame::AdjustForCellText(nsAutoString& aText,
{
NS_PRECONDITION(aColumn && aColumn->GetFrame(), "invalid column passed");
nscoord width =
nsLayoutUtils::GetStringWidth(this, &aRenderingContext, aFontMetrics,
aText.get(), aText.Length());
nscoord width = nsLayoutUtils::AppUnitWidthOfStringBidi(aText, this,
aFontMetrics,
aRenderingContext);
nscoord maxWidth = aTextRect.width;
if (aColumn->Overflow()) {
@ -1459,9 +1459,8 @@ nsTreeBodyFrame::AdjustForCellText(nsAutoString& aText,
}
}
width = nsLayoutUtils::GetStringWidth(this, &aRenderingContext,
aFontMetrics, aText.get(),
aText.Length());
width = nsLayoutUtils::AppUnitWidthOfStringBidi(aText, this, aFontMetrics,
aRenderingContext);
}
switch (aColumn->GetTextAlignment()) {
@ -1748,9 +1747,8 @@ nsTreeBodyFrame::GetCellWidth(int32_t aRow, nsTreeColumn* aCol,
nsLayoutUtils::GetFontMetricsForStyleContext(textContext,
getter_AddRefs(fm));
// Get the width of the text itself
nscoord width =
nsLayoutUtils::GetStringWidth(this, aRenderingContext, *fm,
cellText.get(), cellText.Length());
nscoord width = nsLayoutUtils::AppUnitWidthOfStringBidi(cellText, this, *fm,
*aRenderingContext);
nscoord totalTextWidth = width + bp.left + bp.right;
aDesiredSize += totalTextWidth;
return NS_OK;