accessibility: simplify OCommonAccessibleText

Change-Id: Ied5520179d15f0a854c16b14f5a5e6b84cef1300
Reviewed-on: https://gerrit.libreoffice.org/51514
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Arnaud Versini <arnaud.versini@libreoffice.org>
This commit is contained in:
Arnaud Versini 2018-03-18 20:25:25 +01:00 committed by Noel Grandin
parent db22599c8c
commit dd5df4ccb3
3 changed files with 36 additions and 41 deletions

View File

@ -96,21 +96,19 @@ namespace comphelper
}
void OCommonAccessibleText::implGetGlyphBoundary( i18n::Boundary& rBoundary, sal_Int32 nIndex )
void OCommonAccessibleText::implGetGlyphBoundary( const OUString& rText, i18n::Boundary& rBoundary, sal_Int32 nIndex )
{
OUString sText( implGetText() );
if ( implIsValidIndex( nIndex, sText.getLength() ) )
if ( implIsValidIndex( nIndex, rText.getLength() ) )
{
Reference < i18n::XBreakIterator > xBreakIter = implGetBreakIterator();
if ( xBreakIter.is() )
{
sal_Int32 nCount = 1;
sal_Int32 nDone;
sal_Int32 nStartIndex = xBreakIter->previousCharacters( sText, nIndex, implGetLocale(), i18n::CharacterIteratorMode::SKIPCELL, nCount, nDone );
sal_Int32 nStartIndex = xBreakIter->previousCharacters( rText, nIndex, implGetLocale(), i18n::CharacterIteratorMode::SKIPCELL, nCount, nDone );
if ( nDone != 0 )
nStartIndex = xBreakIter->nextCharacters( sText, nStartIndex, implGetLocale(), i18n::CharacterIteratorMode::SKIPCELL, nCount, nDone );
sal_Int32 nEndIndex = xBreakIter->nextCharacters( sText, nStartIndex, implGetLocale(), i18n::CharacterIteratorMode::SKIPCELL, nCount, nDone );
nStartIndex = xBreakIter->nextCharacters( rText, nStartIndex, implGetLocale(), i18n::CharacterIteratorMode::SKIPCELL, nCount, nDone );
sal_Int32 nEndIndex = xBreakIter->nextCharacters( rText, nStartIndex, implGetLocale(), i18n::CharacterIteratorMode::SKIPCELL, nCount, nDone );
if ( nDone != 0 )
{
rBoundary.startPos = nStartIndex;
@ -126,23 +124,22 @@ namespace comphelper
}
bool OCommonAccessibleText::implGetWordBoundary( i18n::Boundary& rBoundary, sal_Int32 nIndex )
bool OCommonAccessibleText::implGetWordBoundary( const OUString& rText, i18n::Boundary& rBoundary, sal_Int32 nIndex )
{
bool bWord = false;
OUString sText( implGetText() );
if ( implIsValidIndex( nIndex, sText.getLength() ) )
if ( implIsValidIndex( nIndex, rText.getLength() ) )
{
Reference < i18n::XBreakIterator > xBreakIter = implGetBreakIterator();
if ( xBreakIter.is() )
{
rBoundary = xBreakIter->getWordBoundary( sText, nIndex, implGetLocale(), i18n::WordType::ANY_WORD, true );
rBoundary = xBreakIter->getWordBoundary( rText, nIndex, implGetLocale(), i18n::WordType::ANY_WORD, true );
// it's a word, if the first character is an alpha-numeric character
Reference< i18n::XCharacterClassification > xCharClass = implGetCharacterClassification();
if ( xCharClass.is() )
{
sal_Int32 nType = xCharClass->getCharacterType( sText, rBoundary.startPos, implGetLocale() );
sal_Int32 nType = xCharClass->getCharacterType( rText, rBoundary.startPos, implGetLocale() );
if ( ( nType & ( i18n::KCharacterType::LETTER | i18n::KCharacterType::DIGIT ) ) != 0 )
bWord = true;
}
@ -158,18 +155,16 @@ namespace comphelper
}
void OCommonAccessibleText::implGetSentenceBoundary( i18n::Boundary& rBoundary, sal_Int32 nIndex )
void OCommonAccessibleText::implGetSentenceBoundary( const OUString& rText, i18n::Boundary& rBoundary, sal_Int32 nIndex )
{
OUString sText( implGetText() );
if ( implIsValidIndex( nIndex, sText.getLength() ) )
if ( implIsValidIndex( nIndex, rText.getLength() ) )
{
Locale aLocale = implGetLocale();
Reference < i18n::XBreakIterator > xBreakIter = implGetBreakIterator();
if ( xBreakIter.is() )
{
rBoundary.endPos = xBreakIter->endOfSentence( sText, nIndex, aLocale );
rBoundary.startPos = xBreakIter->beginOfSentence( sText, rBoundary.endPos, aLocale );
rBoundary.endPos = xBreakIter->endOfSentence( rText, nIndex, aLocale );
rBoundary.startPos = xBreakIter->beginOfSentence( rText, rBoundary.endPos, aLocale );
}
}
else
@ -313,7 +308,7 @@ namespace comphelper
case AccessibleTextType::GLYPH:
{
// get glyph at index
implGetGlyphBoundary( aBoundary, nIndex );
implGetGlyphBoundary( sText, aBoundary, nIndex );
if ( implIsValidBoundary( aBoundary, nLength ) )
{
aResult.SegmentText = sText.copy( aBoundary.startPos, aBoundary.endPos - aBoundary.startPos );
@ -325,7 +320,7 @@ namespace comphelper
case AccessibleTextType::WORD:
{
// get word at index
bool bWord = implGetWordBoundary( aBoundary, nIndex );
bool bWord = implGetWordBoundary( sText, aBoundary, nIndex );
if ( bWord && implIsValidBoundary( aBoundary, nLength ) )
{
aResult.SegmentText = sText.copy( aBoundary.startPos, aBoundary.endPos - aBoundary.startPos );
@ -337,7 +332,7 @@ namespace comphelper
case AccessibleTextType::SENTENCE:
{
// get sentence at index
implGetSentenceBoundary( aBoundary, nIndex );
implGetSentenceBoundary( sText, aBoundary, nIndex );
if ( implIsValidBoundary( aBoundary, nLength ) )
{
aResult.SegmentText = sText.copy( aBoundary.startPos, aBoundary.endPos - aBoundary.startPos );
@ -417,11 +412,11 @@ namespace comphelper
case AccessibleTextType::GLYPH:
{
// get glyph at index
implGetGlyphBoundary( aBoundary, nIndex );
implGetGlyphBoundary( sText, aBoundary, nIndex );
// get previous glyph
if ( aBoundary.startPos > 0 )
{
implGetGlyphBoundary( aBoundary, aBoundary.startPos - 1 );
implGetGlyphBoundary( sText, aBoundary, aBoundary.startPos - 1 );
if ( implIsValidBoundary( aBoundary, nLength ) )
{
aResult.SegmentText = sText.copy( aBoundary.startPos, aBoundary.endPos - aBoundary.startPos );
@ -434,11 +429,11 @@ namespace comphelper
case AccessibleTextType::WORD:
{
// get word at index
implGetWordBoundary( aBoundary, nIndex );
implGetWordBoundary( sText, aBoundary, nIndex );
// get previous word
bool bWord = false;
while ( !bWord && aBoundary.startPos > 0 )
bWord = implGetWordBoundary( aBoundary, aBoundary.startPos - 1 );
bWord = implGetWordBoundary( sText, aBoundary, aBoundary.startPos - 1 );
if ( bWord && implIsValidBoundary( aBoundary, nLength ) )
{
aResult.SegmentText = sText.copy( aBoundary.startPos, aBoundary.endPos - aBoundary.startPos );
@ -450,11 +445,11 @@ namespace comphelper
case AccessibleTextType::SENTENCE:
{
// get sentence at index
implGetSentenceBoundary( aBoundary, nIndex );
implGetSentenceBoundary( sText, aBoundary, nIndex );
// get previous sentence
if ( aBoundary.startPos > 0 )
{
implGetSentenceBoundary( aBoundary, aBoundary.startPos - 1 );
implGetSentenceBoundary( sText, aBoundary, aBoundary.startPos - 1 );
if ( implIsValidBoundary( aBoundary, nLength ) )
{
aResult.SegmentText = sText.copy( aBoundary.startPos, aBoundary.endPos - aBoundary.startPos );
@ -541,11 +536,11 @@ namespace comphelper
case AccessibleTextType::GLYPH:
{
// get glyph at index
implGetGlyphBoundary( aBoundary, nIndex );
implGetGlyphBoundary( sText, aBoundary, nIndex );
// get next glyph
if ( aBoundary.endPos < nLength )
{
implGetGlyphBoundary( aBoundary, aBoundary.endPos );
implGetGlyphBoundary( sText, aBoundary, aBoundary.endPos );
if ( implIsValidBoundary( aBoundary, nLength ) )
{
aResult.SegmentText = sText.copy( aBoundary.startPos, aBoundary.endPos - aBoundary.startPos );
@ -558,11 +553,11 @@ namespace comphelper
case AccessibleTextType::WORD:
{
// get word at index
implGetWordBoundary( aBoundary, nIndex );
implGetWordBoundary( sText, aBoundary, nIndex );
// get next word
bool bWord = false;
while ( !bWord && aBoundary.endPos < nLength )
bWord = implGetWordBoundary( aBoundary, aBoundary.endPos );
bWord = implGetWordBoundary( sText, aBoundary, aBoundary.endPos );
if ( bWord && implIsValidBoundary( aBoundary, nLength ) )
{
aResult.SegmentText = sText.copy( aBoundary.startPos, aBoundary.endPos - aBoundary.startPos );
@ -574,14 +569,14 @@ namespace comphelper
case AccessibleTextType::SENTENCE:
{
// get sentence at index
implGetSentenceBoundary( aBoundary, nIndex );
implGetSentenceBoundary( sText, aBoundary, nIndex );
// get next sentence
sal_Int32 nEnd = aBoundary.endPos;
sal_Int32 nI = aBoundary.endPos;
bool bFound = false;
while ( !bFound && ++nI < nLength )
{
implGetSentenceBoundary( aBoundary, nI );
implGetSentenceBoundary( sText, aBoundary, nI );
bFound = ( aBoundary.endPos > nEnd );
}
if ( bFound && implIsValidBoundary( aBoundary, nLength ) )

View File

@ -1907,7 +1907,7 @@ namespace accessibility
sal_Int32 nLength = sText.getLength();
// get word at index
implGetWordBoundary( aBoundary, nIndex );
implGetWordBoundary( sText, aBoundary, nIndex );
//sal_Int32 curWordStart = aBoundary.startPos;
@ -1926,7 +1926,7 @@ namespace accessibility
while ( (preWordStart >= 0 && !bWord ) || ( aBoundary.endPos > curWordStart ) )
{
preWordStart--;
bWord = implGetWordBoundary( aBoundary, preWordStart );
bWord = implGetWordBoundary( sText, aBoundary, preWordStart );
}
if ( bWord && implIsValidBoundary( aBoundary, nLength ) )
{
@ -2036,7 +2036,7 @@ namespace accessibility
sal_Int32 nLength = sText.getLength();
// get word at index
bool bWord = implGetWordBoundary( aBoundary, nIndex );
bool bWord = implGetWordBoundary( sText, aBoundary, nIndex );
// real current world
sal_Int32 nextWord = nIndex;
@ -2045,7 +2045,7 @@ namespace accessibility
{
nextWord = aBoundary.endPos;
if( sText[nextWord] == u' ' ) nextWord++;
bWord = implGetWordBoundary( aBoundary, nextWord );
bWord = implGetWordBoundary( sText, aBoundary, nextWord );
}
if ( bWord && implIsValidBoundary( aBoundary, nLength ) )

View File

@ -54,13 +54,13 @@ namespace comphelper
static bool implIsValidIndex( sal_Int32 nIndex, sal_Int32 nLength );
static bool implIsValidRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex, sal_Int32 nLength );
static sal_Unicode implGetCharacter( const OUString& rText, sal_Int32 nIndex );
static OUString implGetTextRange( const OUString& rTest, sal_Int32 nStartIndex, sal_Int32 nEndIndex );
static OUString implGetTextRange( const OUString& rText, sal_Int32 nStartIndex, sal_Int32 nEndIndex );
virtual OUString implGetText() = 0;
virtual css::lang::Locale implGetLocale() = 0;
virtual void implGetSelection( sal_Int32& nStartIndex, sal_Int32& nEndIndex ) = 0;
void implGetGlyphBoundary( css::i18n::Boundary& rBoundary, sal_Int32 nIndex );
bool implGetWordBoundary( css::i18n::Boundary& rBoundary, sal_Int32 nIndex );
void implGetSentenceBoundary( css::i18n::Boundary& rBoundary, sal_Int32 nIndex );
void implGetGlyphBoundary( const OUString& rText, css::i18n::Boundary& rBoundary, sal_Int32 nIndex );
bool implGetWordBoundary( const OUString& rText, css::i18n::Boundary& rBoundary, sal_Int32 nIndex );
void implGetSentenceBoundary( const OUString& rText, css::i18n::Boundary& rBoundary, sal_Int32 nIndex );
virtual void implGetParagraphBoundary( css::i18n::Boundary& rBoundary, sal_Int32 nIndex );
virtual void implGetLineBoundary( css::i18n::Boundary& rBoundary, sal_Int32 nIndex );