diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2022-10-20 22:33:22 +0200 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2022-11-15 00:03:41 +0100 |
commit | 0b96a1747fc3f96ca70fd159594fe1a478369da0 (patch) | |
tree | 754c9203429eb03fad90088634ade9c33f118a7b /sw | |
parent | 7d750720b667a178b273db4e1f280a756583d74f (diff) |
sw: add online accessibility check implementation
Change-Id: Ic68aa91b1cbf23ac305ad4e361c56b91556757ee
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141604
Tested-by: Tomaž Vajngerl <quikee@gmail.com>
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/Library_sw.mk | 1 | ||||
-rw-r--r-- | sw/inc/OnlineAccessibilityCheck.hxx | 43 | ||||
-rw-r--r-- | sw/inc/doc.hxx | 6 | ||||
-rw-r--r-- | sw/inc/ndtxt.hxx | 12 | ||||
-rw-r--r-- | sw/source/core/crsr/crsrsh.cxx | 4 | ||||
-rw-r--r-- | sw/source/core/doc/docnew.cxx | 4 | ||||
-rw-r--r-- | sw/source/core/txtnode/OnlineAccessibilityCheck.cxx | 124 |
7 files changed, 193 insertions, 1 deletions
diff --git a/sw/Library_sw.mk b/sw/Library_sw.mk index 483f00601b04..7785ba9b6254 100644 --- a/sw/Library_sw.mk +++ b/sw/Library_sw.mk @@ -430,6 +430,7 @@ $(eval $(call gb_Library_add_exception_objects,sw,\ sw/source/core/tox/ToxTextGenerator \ sw/source/core/tox/ToxWhitespaceStripper \ sw/source/core/txtnode/GrammarContact \ + sw/source/core/txtnode/OnlineAccessibilityCheck \ sw/source/core/txtnode/attrcontentcontrol \ sw/source/core/txtnode/atrfld \ sw/source/core/txtnode/atrflyin \ diff --git a/sw/inc/OnlineAccessibilityCheck.hxx b/sw/inc/OnlineAccessibilityCheck.hxx new file mode 100644 index 000000000000..f27f867ce96b --- /dev/null +++ b/sw/inc/OnlineAccessibilityCheck.hxx @@ -0,0 +1,43 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + */ + +#pragma once + +#include "ndindex.hxx" +#include "ndtxt.hxx" +#include <svl/listener.hxx> +#include <vcl/timer.hxx> +#include <AccessibilityCheck.hxx> + +struct SwPosition; +class SwTextNode; + +namespace sw +{ +class OnlineAccessibilityCheck : public SvtListener +{ +private: + SwDoc& m_rDocument; + sw::AccessibilityCheck m_aAccessibilityCheck; + SwTextNode* m_pCurrentTextNode; + SwNodeOffset m_aCurrentNodeIndex; + sal_Int32 m_nAccessibilityIssues; + + void runCheck(SwTextNode* pTextNode); + +public: + OnlineAccessibilityCheck(SwDoc& rDocument); + void update(const SwPosition& rNewPos); + sal_Int32 getNumberOfAccessibilityIssues() { return m_nAccessibilityIssues; } +}; + +} // end sw + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/inc/doc.hxx b/sw/inc/doc.hxx index de5ec6112a00..80aa234cc6e3 100644 --- a/sw/inc/doc.hxx +++ b/sw/inc/doc.hxx @@ -163,6 +163,7 @@ namespace sw { class DocumentStylePoolManager; class DocumentExternalDataManager; class GrammarContact; + class OnlineAccessibilityCheck; } namespace com::sun::star { @@ -285,6 +286,7 @@ class SW_DLLPUBLIC SwDoc final document for a faster formatting */ std::unique_ptr<sw::GrammarContact> mpGrammarContact; //< for grammar checking in paragraphs during editing + std::unique_ptr<sw::OnlineAccessibilityCheck> mpOnlineAccessibilityCheck; css::uno::Reference< css::script::vba::XVBAEventProcessor > mxVbaEvents; css::uno::Reference< ooo::vba::word::XFind > mxVbaFind; @@ -1562,6 +1564,10 @@ public: bool ContainsHiddenChars() const; std::unique_ptr<sw::GrammarContact> const& getGrammarContact() const { return mpGrammarContact; } + std::unique_ptr<sw::OnlineAccessibilityCheck> const& getOnlineAccessibilityCheck() const + { + return mpOnlineAccessibilityCheck; + } /** Marks/Unmarks a list level of a certain list diff --git a/sw/inc/ndtxt.hxx b/sw/inc/ndtxt.hxx index 42cc43380f1a..63b019cf8178 100644 --- a/sw/inc/ndtxt.hxx +++ b/sw/inc/ndtxt.hxx @@ -37,6 +37,7 @@ #include <memory> #include <vector> #include <functional> +#include <sfx2/AccessibilityIssue.hxx> class SfxHint; class SwNumRule; @@ -101,6 +102,12 @@ struct ParagraphIdleData bool bAutoComplDirty = true; ///< auto complete list dirty }; +struct AccessibilityCheckStatus +{ + std::unique_ptr<sfx::AccessibilityIssueCollection> pCollection; + bool bDirty = true; +}; + } // end namespace sw /// SwTextNode is a paragraph in the document model. @@ -128,6 +135,7 @@ class SW_DLLPUBLIC SwTextNode final OUString m_Text; mutable sw::ParagraphIdleData m_aParagraphIdleData; + mutable sw::AccessibilityCheckStatus m_aAccessibilityCheckStatus; /** Some of the chars this para are hidden. Paragraph has to be reformatted on changing the view to print preview. */ @@ -234,6 +242,10 @@ public: /// End: Data collected during idle time + sw::AccessibilityCheckStatus& getAccessibilityCheckStatus() + { + return m_aAccessibilityCheckStatus; + } public: using SwContentNode::GetAttr; diff --git a/sw/source/core/crsr/crsrsh.cxx b/sw/source/core/crsr/crsrsh.cxx index 0267990c8741..97df404d39ec 100644 --- a/sw/source/core/crsr/crsrsh.cxx +++ b/sw/source/core/crsr/crsrsh.cxx @@ -56,6 +56,7 @@ #include <vcl/svapp.hxx> #include <vcl/settings.hxx> #include <GrammarContact.hxx> +#include <OnlineAccessibilityCheck.hxx> #include <comphelper/flagguard.hxx> #include <strings.hrc> #include <IDocumentLayoutAccess.hxx> @@ -1504,7 +1505,10 @@ void SwCursorShell::UpdateCursorPos() } auto* pDoc = GetDoc(); if (pDoc) + { pDoc->getGrammarContact()->updateCursorPosition(*m_pCurrentCursor->GetPoint()); + pDoc->getOnlineAccessibilityCheck()->update(*m_pCurrentCursor->GetPoint()); + } --mnStartAction; if( aOldSz != GetDocSize() ) diff --git a/sw/source/core/doc/docnew.cxx b/sw/source/core/doc/docnew.cxx index 07456301f42e..8dc280e2853e 100644 --- a/sw/source/core/doc/docnew.cxx +++ b/sw/source/core/doc/docnew.cxx @@ -76,6 +76,7 @@ #include <istyleaccess.hxx> #include "swstylemanager.hxx" #include <GrammarContact.hxx> +#include <OnlineAccessibilityCheck.hxx> #include <tblafmt.hxx> #include <MarkManager.hxx> #include <UndoManager.hxx> @@ -250,6 +251,7 @@ SwDoc::SwDoc() mpNumRuleTable( new SwNumRuleTable ), mpExtInputRing( nullptr ), mpGrammarContact(new sw::GrammarContact), + mpOnlineAccessibilityCheck(new sw::OnlineAccessibilityCheck(*this)), mpCellStyles(new SwCellStyleTable), mReferenceCount(0), mbDtor(false), @@ -271,7 +273,6 @@ SwDoc::SwDoc() mbIsPrepareSelAll(false), meDictionaryMissing( MissingDictionary::Undefined ), mbContainsAtPageObjWithContentAnchor(false), //#i119292#, fdo#37024 - meDocType(DOCTYPE_NATIVE) { // The DrawingLayer ItemPool which is used as 2nd pool for Writer documents' pool @@ -408,6 +409,7 @@ SwDoc::~SwDoc() } mpGrammarContact.reset(); + mpOnlineAccessibilityCheck.reset(); getIDocumentTimerAccess().StopIdling(); // stop idle timer diff --git a/sw/source/core/txtnode/OnlineAccessibilityCheck.cxx b/sw/source/core/txtnode/OnlineAccessibilityCheck.cxx new file mode 100644 index 000000000000..109bac52545b --- /dev/null +++ b/sw/source/core/txtnode/OnlineAccessibilityCheck.cxx @@ -0,0 +1,124 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <OnlineAccessibilityCheck.hxx> +#include <doc.hxx> +#include <pam.hxx> +#include <txtfrm.hxx> +#include <officecfg/Office/Common.hxx> + +namespace sw +{ +OnlineAccessibilityCheck::OnlineAccessibilityCheck(SwDoc& rDocument) + : m_rDocument(rDocument) + , m_aAccessibilityCheck(&m_rDocument) + , m_pCurrentTextNode(nullptr) + , m_aCurrentNodeIndex(-1) + , m_nAccessibilityIssues(0) +{ +} + +void OnlineAccessibilityCheck::runCheck(SwTextNode* pTextNode) +{ + m_aAccessibilityCheck.checkNode(pTextNode); + + for (SwFrameFormat* const& pFrameFormat : pTextNode->GetAnchoredFlys()) + { + SdrObject* pObject = pFrameFormat->FindSdrObject(); + if (pObject) + m_aAccessibilityCheck.checkObject(pObject); + } + + auto aCollection = m_aAccessibilityCheck.getIssueCollection(); + + pTextNode->getAccessibilityCheckStatus().pCollection + = std::make_unique<sfx::AccessibilityIssueCollection>(aCollection); + + m_nAccessibilityIssues = 0; + auto const& pNodes = m_rDocument.GetNodes(); + for (SwNodeOffset n(0); n < pNodes.Count(); ++n) + { + SwNode* pNode = pNodes[n]; + if (pNode && pNode->IsTextNode()) + { + auto* pCurrentTextNode = pNode->GetTextNode(); + auto& rStatus = pCurrentTextNode->getAccessibilityCheckStatus(); + if (rStatus.pCollection) + m_nAccessibilityIssues += rStatus.pCollection->getIssues().size(); + } + } +} + +void OnlineAccessibilityCheck::update(const SwPosition& rNewPos) +{ + bool bOnlineCheckStatus + = officecfg::Office::Common::Accessibility::OnlineAccessibilityCheck::get(); + + if (!bOnlineCheckStatus) + return; + + if (!HasBroadcaster()) + { + m_pCurrentTextNode = nullptr; + m_aCurrentNodeIndex = SwNodeOffset(-1); + } + + auto aNodeIndex = rNewPos.GetNodeIndex(); + + m_aAccessibilityCheck.getIssueCollection().clear(); + + SwTextNode* pTextNode = rNewPos.GetNode().GetTextNode(); + if (!pTextNode) + { + m_pCurrentTextNode = nullptr; + m_aCurrentNodeIndex = SwNodeOffset(-1); + return; + } + + if (pTextNode == m_pCurrentTextNode) + { + if (m_aCurrentNodeIndex != aNodeIndex && m_aCurrentNodeIndex >= SwNodeOffset(0) + && m_aCurrentNodeIndex < pTextNode->GetNodes().Count()) + { + pTextNode = pTextNode->GetNodes()[m_aCurrentNodeIndex]->GetTextNode(); + + if (pTextNode) + { + runCheck(pTextNode); + } + } + } + else if (m_pCurrentTextNode) + { + runCheck(m_pCurrentTextNode); + } + + m_aCurrentNodeIndex = aNodeIndex; + + if (pTextNode && m_pCurrentTextNode != pTextNode) + { + EndListeningAll(); + StartListening(pTextNode->GetNotifier()); + m_pCurrentTextNode = pTextNode; + } +} + +} // end sw + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |