sw/inc/crsrsh.hxx                |    2 ++
 sw/source/core/access/accdoc.cxx |    5 +++++
 sw/source/core/crsr/crsrsh.cxx   |   14 ++++++++++++++
 3 files changed, 21 insertions(+)

New commits:
commit 4a93739e619fd4f4ec369932e923554d71297900
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Fri Mar 17 12:37:15 2023 +0100
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Mon Mar 20 21:21:30 2023 +0000

    tdf#136760 sw a11y: Provide page-relative cursor pos via doc attr
    
    This introduce 2 new extended accessible attributes
    "cursor-position-in-page-horizontal" and
    "cursor-position-in-page-vertical" to expose
    the page-relative position of the cursor in Writer
    to assistive technology.
    
    This is similar to how the current page
    number is already exposed (attribute "page-number").
    
    Together with a corresponding pull request for the NVDA
    screen reader [1], this allows NVDA to announce the position
    similar to how it is done for Microsoft Word (where the information
    is not retrieved via the accessibility APIs but the
    MS Office COM API, s. discussion
    in the corresponding NVDA issue [2] for more details).
    
    (Side note: Currently there is no a11y object for a Writer
    page in the a11y tree, but "normal" paragraphs are direct
    children of the document object.)
    
    For performance reasons, introduce a new method
    `SwCursorShell::GetCursorPagePos` to get the position
    instead of passing the result from
    `SwCursorShell::GetCursorDocPos` to
    `SwFEShell::GetRelativePagePosition` to avoid
    iterating over the doc pages.
    
    [1] https://github.com/nvaccess/nvda/pull/14727
    [2] https://github.com/nvaccess/nvda/issues/11696
    
    Change-Id: I6fd56c5c7d051840bab836ce5fe525fdc061b376
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149051
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/sw/inc/crsrsh.hxx b/sw/inc/crsrsh.hxx
index 8eac979b5617..ddb7b301beef 100644
--- a/sw/inc/crsrsh.hxx
+++ b/sw/inc/crsrsh.hxx
@@ -598,6 +598,8 @@ public:
     bool IsCursorInFootnote() const;
 
     inline Point& GetCursorDocPos() const;
+    // get cursor position relative to the page it is in
+    Point GetCursorPagePos() const;
     inline bool IsCursorPtAtEnd() const;
 
     inline const  SwPaM* GetTableCrs() const;
diff --git a/sw/source/core/access/accdoc.cxx b/sw/source/core/access/accdoc.cxx
index 618425a68f9d..298b4270e5d8 100644
--- a/sw/source/core/access/accdoc.cxx
+++ b/sw/source/core/access/accdoc.cxx
@@ -533,6 +533,11 @@ uno::Any SAL_CALL 
SwAccessibleDocument::getExtendedAttributes()
             ";total-pages:" +
             OUString::number( pCursorShell->GetPageCnt() ) + ";";
 
+        // cursor position relative to the page
+        Point aCursorPagePos = pFEShell->GetCursorPagePos();
+        sValue += "cursor-position-in-page-horizontal:" + 
OUString::number(aCursorPagePos.getX())
+                + ";cursor-position-in-page-vertical:" + 
OUString::number(aCursorPagePos.getY()) + ";";
+
         SwContentFrame* pCurrFrame = pCursorShell->GetCurrFrame();
         SwPageFrame* 
pCurrPage=static_cast<SwFrame*>(pCurrFrame)->FindPageFrame();
         sal_uLong nLineNum = 0;
diff --git a/sw/source/core/crsr/crsrsh.cxx b/sw/source/core/crsr/crsrsh.cxx
index 298801ace223..9d94c133f028 100644
--- a/sw/source/core/crsr/crsrsh.cxx
+++ b/sw/source/core/crsr/crsrsh.cxx
@@ -1168,6 +1168,20 @@ bool SwCursorShell::IsCursorInFootnote() const
     return aStartNodeType == SwStartNodeType::SwFootnoteStartNode;
 }
 
+Point SwCursorShell::GetCursorPagePos() const
+{
+    Point aRet(-1, -1);
+    if (SwFrame *pFrame = GetCurrFrame())
+    {
+        if (SwPageFrame* pCurrentPage = pFrame->FindPageFrame())
+        {
+            const Point& rDocPos = GetCursorDocPos();
+            aRet = rDocPos - pCurrentPage->getFrameArea().TopLeft();
+        }
+    }
+    return aRet;
+}
+
 bool SwCursorShell::IsInFrontOfLabel() const
 {
     return m_pCurrentCursor->IsInFrontOfLabel();

Reply via email to