summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Weghorn <m.weghorn@posteo.de>2023-07-06 10:27:37 +0200
committerMichael Weghorn <m.weghorn@posteo.de>2023-07-08 00:12:01 +0200
commit472950414a0fb07d5260b7b6b2d3a5d2dc18a68d (patch)
tree912b439f1981fa02d6b33edb33e3d726eade8603
parent243e54564050f87535a5e7b96cd5bc143dffae0c (diff)
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.weghorn@posteo.de>
-rw-r--r--sw/source/core/access/textmarkuphelper.cxx55
-rw-r--r--sw/source/core/access/textmarkuphelper.hxx6
2 files changed, 25 insertions, 36 deletions
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;