Bug 1063857 - Improve selecting on justified characters. r=roc

This commit is contained in:
Xidorn Quan 2014-11-10 12:25:09 +11:00
parent 70928558b6
commit f16b0e2980
3 changed files with 20 additions and 4 deletions

View File

@ -949,7 +949,8 @@ gfxTextRun::BreakAndMeasureText(uint32_t aStart, uint32_t aMaxLength,
gfxFloat
gfxTextRun::GetAdvanceWidth(uint32_t aStart, uint32_t aLength,
PropertyProvider *aProvider)
PropertyProvider *aProvider,
PropertyProvider::Spacing* aSpacing)
{
NS_ASSERTION(aStart + aLength <= GetLength(), "Substring out of range");
@ -960,6 +961,10 @@ gfxTextRun::GetAdvanceWidth(uint32_t aStart, uint32_t aLength,
gfxFloat result = ComputePartialLigatureWidth(aStart, ligatureRunStart, aProvider) +
ComputePartialLigatureWidth(ligatureRunEnd, aStart + aLength, aProvider);
if (aSpacing) {
aSpacing->mBefore = aSpacing->mAfter = 0;
}
// Account for all remaining spacing here. This is more efficient than
// processing it along with the glyphs.
if (aProvider && (mFlags & gfxTextRunFactory::TEXT_ENABLE_SPACING)) {
@ -972,6 +977,10 @@ gfxTextRun::GetAdvanceWidth(uint32_t aStart, uint32_t aLength,
PropertyProvider::Spacing *space = &spacingBuffer[i];
result += space->mBefore + space->mAfter;
}
if (aSpacing) {
aSpacing->mBefore = spacingBuffer[0].mBefore;
aSpacing->mAfter = spacingBuffer.LastElement().mAfter;
}
}
}

View File

@ -267,9 +267,13 @@ public:
/**
* Computes just the advance width for a substring.
* Uses GetSpacing from aBreakProvider.
* If aSpacing is not null, the spacing attached before and after
* the substring would be returned in it. NOTE: the spacing is
* included in the advance width.
*/
gfxFloat GetAdvanceWidth(uint32_t aStart, uint32_t aLength,
PropertyProvider *aProvider);
PropertyProvider *aProvider,
PropertyProvider::Spacing* aSpacing = nullptr);
/**
* Clear all stored line breaks for the given range (both before and after),

View File

@ -6376,11 +6376,14 @@ nsTextFrame::GetCharacterOffsetAtFramePointInternal(nsPoint aPoint,
FindClusterEnd(mTextRun,
provider.GetStart().GetOriginalOffset() + provider.GetOriginalLength(),
&extraClusterLastChar);
PropertyProvider::Spacing spacing;
gfxFloat charWidth =
mTextRun->GetAdvanceWidth(extraCluster.GetSkippedOffset(),
GetSkippedDistance(extraCluster, extraClusterLastChar) + 1,
&provider);
selectedOffset = !aForInsertionPoint || width <= fitWidth + charWidth/2
&provider, &spacing);
charWidth -= spacing.mBefore + spacing.mAfter;
selectedOffset = !aForInsertionPoint ||
width <= fitWidth + spacing.mBefore + charWidth/2
? extraCluster.GetOriginalOffset()
: extraClusterLastChar.GetOriginalOffset() + 1;
} else {