sw/source/core/access/textmarkuphelper.cxx | 55 ++++++++++------------------- sw/source/core/access/textmarkuphelper.hxx | 6 +++ 2 files changed, 25 insertions(+), 36 deletions(-)
New commits: commit dccd32607d2d10a24e0214c01c74ed6dcf8746fb Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Thu Jul 6 10:27:37 2023 +0200 Commit: Michael Stahl <michael.st...@allotropia.de> CommitDate: Mon Jul 10 11:46:57 2023 +0200 tdf#155705 sw a11y: Unify iterator use in SwTextMarkupHelper Introduce a new helper method `SwTextMarkupHelper::getIterator` to get a `sw::WrongListIteratorCounter` and use that to deduplicate and unify handling in three methods. Change-Id: I81790c547f70f0649ce800bc481db70982dfa742 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154108 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> (cherry picked from commit 472950414a0fb07d5260b7b6b2d3a5d2dc18a68d) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154180 Reviewed-by: Michael Stahl <michael.st...@allotropia.de> diff --git a/sw/source/core/access/textmarkuphelper.cxx b/sw/source/core/access/textmarkuphelper.cxx index 5329241c6f1b..34be72fff584 100644 --- a/sw/source/core/access/textmarkuphelper.cxx +++ b/sw/source/core/access/textmarkuphelper.cxx @@ -86,13 +86,13 @@ SwTextMarkupHelper::SwTextMarkupHelper( const SwAccessiblePortionData& rPortionD { } -sal_Int32 SwTextMarkupHelper::getTextMarkupCount( const sal_Int32 nTextMarkupType ) -{ - sal_Int32 nTextMarkupCount( 0 ); +std::unique_ptr<sw::WrongListIteratorCounter> SwTextMarkupHelper::getIterator(sal_Int32 nTextMarkupType) +{ + std::unique_ptr<sw::WrongListIteratorCounter> pIter; if (mpTextMarkupList) { - nTextMarkupCount = mpTextMarkupList->Count(); + pIter.reset(new sw::WrongListIteratorCounter(*mpTextMarkupList)); } else { @@ -100,11 +100,22 @@ sal_Int32 SwTextMarkupHelper::getTextMarkupCount( const sal_Int32 nTextMarkupTyp SwWrongList const* (SwTextNode::*const pGetWrongList)() const = getTextMarkupFunc(nTextMarkupType); if (pGetWrongList) { - sw::WrongListIteratorCounter iter(*m_pTextFrame, pGetWrongList); - nTextMarkupCount = iter.GetElementCount(); + pIter.reset(new sw::WrongListIteratorCounter(*m_pTextFrame, pGetWrongList)); } } + return pIter; +} + + +sal_Int32 SwTextMarkupHelper::getTextMarkupCount( const sal_Int32 nTextMarkupType ) +{ + sal_Int32 nTextMarkupCount( 0 ); + + std::unique_ptr<sw::WrongListIteratorCounter> pIter = getIterator(nTextMarkupType); + if (pIter) + nTextMarkupCount = pIter->GetElementCount(); + return nTextMarkupCount; } @@ -122,21 +133,7 @@ css::accessibility::TextSegment aTextMarkupSegment.SegmentStart = -1; aTextMarkupSegment.SegmentEnd = -1; - std::unique_ptr<sw::WrongListIteratorCounter> pIter; - if (mpTextMarkupList) - { - pIter.reset(new sw::WrongListIteratorCounter(*mpTextMarkupList)); - } - else - { - assert(m_pTextFrame); - SwWrongList const* (SwTextNode::*const pGetWrongList)() const = getTextMarkupFunc(nTextMarkupType); - if (pGetWrongList) - { - pIter.reset(new sw::WrongListIteratorCounter(*m_pTextFrame, pGetWrongList)); - } - } - + std::unique_ptr<sw::WrongListIteratorCounter> pIter = getIterator(nTextMarkupType); if (pIter) { auto const oElement(pIter->GetElementAt(nTextMarkupIndex)); @@ -175,21 +172,7 @@ css::uno::Sequence< css::accessibility::TextSegment > return uno::Sequence< css::accessibility::TextSegment >(); } - std::unique_ptr<sw::WrongListIteratorCounter> pIter; - if (mpTextMarkupList) - { - pIter.reset(new sw::WrongListIteratorCounter(*mpTextMarkupList)); - } - else - { - assert(m_pTextFrame); - SwWrongList const* (SwTextNode::*const pGetWrongList)() const = getTextMarkupFunc(nTextMarkupType); - if (pGetWrongList) - { - pIter.reset(new sw::WrongListIteratorCounter(*m_pTextFrame, pGetWrongList)); - } - } - + std::unique_ptr<sw::WrongListIteratorCounter> pIter = getIterator(nTextMarkupType); std::vector< css::accessibility::TextSegment > aTmpTextMarkups; if (pIter) { diff --git a/sw/source/core/access/textmarkuphelper.hxx b/sw/source/core/access/textmarkuphelper.hxx index 6db3f9bc0e34..daccc0eef4ad 100644 --- a/sw/source/core/access/textmarkuphelper.hxx +++ b/sw/source/core/access/textmarkuphelper.hxx @@ -30,6 +30,10 @@ class SwAccessiblePortionData; class SwTextFrame; class SwWrongList; // #i108125# +namespace sw { + class WrongListIteratorCounter; +} + class SwTextMarkupHelper { public: @@ -60,6 +64,8 @@ class SwTextMarkupHelper SwTextMarkupHelper( const SwTextMarkupHelper& ) = delete; SwTextMarkupHelper& operator=( const SwTextMarkupHelper& ) = delete; + std::unique_ptr<sw::WrongListIteratorCounter> getIterator(sal_Int32 nTextMarkupType); + const SwAccessiblePortionData& mrPortionData; SwTextFrame const* m_pTextFrame;