Bug 1216427 - part 2 - Ensure mouse selection does not split up a Regional Indicator flag symbol. r=emk

This commit is contained in:
Jonathan Kew 2015-10-26 10:47:18 +00:00
Родитель a48628058f
Коммит c3830d77b0
1 изменённых файлов: 24 добавлений и 1 удалений

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

@ -6658,10 +6658,33 @@ nsTextFrame::GetCharacterOffsetAtFramePointInternal(nsPoint aPoint,
// cluster.
gfxSkipCharsIterator extraCluster(provider.GetStart());
extraCluster.AdvanceSkipped(charsFit);
bool allowSplitLigature = true; // Allow selection of partial ligature...
// ...but don't let selection/insertion-point split two Regional Indicator
// chars that are ligated in the textrun to form a single flag symbol.
uint32_t offs = extraCluster.GetOriginalOffset();
const nsTextFragment* frag = GetContent()->GetText();
if (offs + 1 < frag->GetLength() &&
NS_IS_HIGH_SURROGATE(frag->CharAt(offs)) &&
NS_IS_LOW_SURROGATE(frag->CharAt(offs + 1)) &&
gfxFontUtils::IsRegionalIndicator
(SURROGATE_TO_UCS4(frag->CharAt(offs), frag->CharAt(offs + 1)))) {
allowSplitLigature = false;
if (extraCluster.GetSkippedOffset() > 1 &&
!mTextRun->IsLigatureGroupStart(extraCluster.GetSkippedOffset())) {
// CountCharsFit() left us in the middle of the flag; back up over the
// first character of the ligature, and adjust fitWidth accordingly.
extraCluster.AdvanceSkipped(-2); // it's a surrogate pair: 2 code units
fitWidth -= mTextRun->GetAdvanceWidth(extraCluster.GetSkippedOffset(),
2, &provider);
}
}
gfxSkipCharsIterator extraClusterLastChar(extraCluster);
FindClusterEnd(mTextRun,
provider.GetStart().GetOriginalOffset() + provider.GetOriginalLength(),
&extraClusterLastChar);
&extraClusterLastChar, allowSplitLigature);
PropertyProvider::Spacing spacing;
gfxFloat charWidth =
mTextRun->GetAdvanceWidth(extraCluster.GetSkippedOffset(),