sw/source/core/access/AccessibilityCheck.cxx | 35 ++++++++++++++++-- sw/source/core/access/AccessibilityIssue.cxx | 37 +++++++++++++++----- sw/source/core/inc/AccessibilityCheck.hxx | 2 - sw/source/core/inc/AccessibilityIssue.hxx | 1 sw/source/core/txtnode/OnlineAccessibilityCheck.cxx | 4 -- 5 files changed, 62 insertions(+), 17 deletions(-)
New commits: commit 5445e9de41b1330fa27e07d46eaa4babe956645f Author: Michael Stahl <michael.st...@allotropia.de> AuthorDate: Thu Mar 6 10:43:23 2025 +0100 Commit: Michael Stahl <michael.st...@allotropia.de> CommitDate: Thu Mar 6 16:24:41 2025 +0100 tdf#161583 sw: a11y check: warn about flys with RES_URL with no "name" Fly frames can have hyperlinks too. Change-Id: I80da4b53e44e6f82a4f37f4b2aa859b8475b452a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/182577 Tested-by: Jenkins Reviewed-by: Michael Stahl <michael.st...@allotropia.de> diff --git a/sw/source/core/access/AccessibilityCheck.cxx b/sw/source/core/access/AccessibilityCheck.cxx index 9434f5318fff..3985683f65ff 100644 --- a/sw/source/core/access/AccessibilityCheck.cxx +++ b/sw/source/core/access/AccessibilityCheck.cxx @@ -44,6 +44,7 @@ #include <o3tl/vector_utils.hxx> #include <svx/swframetypes.hxx> #include <fmtanchr.hxx> +#include <fmturl.hxx> #include <dcontact.hxx> #include <unotext.hxx> #include <svx/svdoashp.hxx> @@ -2613,13 +2614,39 @@ public: } // end anonymous namespace // Check Shapes, TextBox -void AccessibilityCheck::checkObject(SwNode* pCurrent, SdrObject* pObject) +void AccessibilityCheck::checkObject(SwNode* pCurrent, SwFrameFormat const& rFrameFormat) { + SdrObject const* const pObject{ rFrameFormat.FindSdrObject() }; if (!pObject) return; + // check hyperlink + if (SwFormatURL const* const pItem{ rFrameFormat.GetItemIfSet(RES_URL, false) }) + { + OUString const sHyperlink{ pItem->GetURL() }; + if (!sHyperlink.isEmpty() && pItem->GetName().isEmpty()) + { + INetURLObject const aHyperlink(sHyperlink); + if (aHyperlink.GetProtocol() != INetProtocol::NotValid) + { + std::shared_ptr<sw::AccessibilityIssue> pNameIssue + = lclAddIssue(m_aIssueCollection, SwResId(STR_HYPERLINK_NO_NAME), + sfx::AccessibilityIssueID::HYPERLINK_NO_NAME, + sfx::AccessibilityIssueLevel::WARNLEV); + + if (pNameIssue) + { + pNameIssue->setIssueObject(IssueObject::HYPERLINKFLY); + pNameIssue->setObjectID(rFrameFormat.GetName()); + pNameIssue->setNode(pCurrent); + pNameIssue->setDoc(*m_pDoc); + } + } + } + } + // Check for fontworks. - if (SdrObjCustomShape* pCustomShape = dynamic_cast<SdrObjCustomShape*>(pObject)) + if (SdrObjCustomShape const* pCustomShape = dynamic_cast<SdrObjCustomShape const*>(pObject)) { const SdrCustomShapeGeometryItem& rGeometryItem = pCustomShape->GetMergedItem(SDRATTR_CUSTOMSHAPE_GEOMETRY); @@ -2764,9 +2791,7 @@ void AccessibilityCheck::check() for (SwFrameFormat* const& pFrameFormat : pNode->GetAnchoredFlys()) { - SdrObject* pObject = pFrameFormat->FindSdrObject(); - if (pObject) - checkObject(pNode, pObject); + checkObject(pNode, *pFrameFormat); } } } diff --git a/sw/source/core/access/AccessibilityIssue.cxx b/sw/source/core/access/AccessibilityIssue.cxx index c561995b37b1..37cca560da1f 100644 --- a/sw/source/core/access/AccessibilityIssue.cxx +++ b/sw/source/core/access/AccessibilityIssue.cxx @@ -29,6 +29,7 @@ #include <svx/svdview.hxx> #include <flyfrm.hxx> +#include <fmturl.hxx> #include <unotextrange.hxx> #include <txatbase.hxx> #include <txtfrm.hxx> @@ -83,6 +84,7 @@ void AccessibilityIssue::gotoIssue() const case IssueObject::GRAPHIC: case IssueObject::OLE: case IssueObject::TEXTFRAME: + case IssueObject::HYPERLINKFLY: { bool bSelected = pWrtShell->GotoFly(TempIssueObject.m_sObjectID, FLYCNTTYPE_ALL, true); @@ -245,6 +247,7 @@ bool AccessibilityIssue::canQuickFixIssue() const || m_eIssueObject == IssueObject::DOCUMENT_TITLE || m_eIssueObject == IssueObject::DOCUMENT_BACKGROUND || m_eIssueObject == IssueObject::LANGUAGE_NOT_SET + || m_eIssueObject == IssueObject::HYPERLINKFLY || m_eIssueObject == IssueObject::HYPERLINKTEXT; } @@ -332,6 +335,7 @@ void AccessibilityIssue::quickFixIssue() const } break; case IssueObject::HYPERLINKTEXT: + case IssueObject::HYPERLINKFLY: { SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); SwWrtShell* pWrtShell = pShell->GetWrtShell(); @@ -340,15 +344,32 @@ void AccessibilityIssue::quickFixIssue() const SwResId(STR_HYPERLINK_NO_NAME_DLG))); if (aNameDialog->Execute() == RET_OK) { - SwContentNode* pContentNode = m_pNode->GetContentNode(); - SwPosition aStart(*pContentNode, m_nStart); - SwPosition aEnd(*pContentNode, m_nEnd); - rtl::Reference<SwXTextRange> xRun - = SwXTextRange::CreateXTextRange(*m_pDoc, aStart, &aEnd); - if (xRun.is() - && xRun->getPropertySetInfo()->hasPropertyByName(u"HyperLinkName"_ustr)) + if (m_eIssueObject == IssueObject::HYPERLINKTEXT) { - xRun->setPropertyValue(u"HyperLinkName"_ustr, uno::Any(aNameDialog->GetName())); + SwContentNode* pContentNode = m_pNode->GetContentNode(); + SwPosition aStart(*pContentNode, m_nStart); + SwPosition aEnd(*pContentNode, m_nEnd); + rtl::Reference<SwXTextRange> xRun + = SwXTextRange::CreateXTextRange(*m_pDoc, aStart, &aEnd); + if (xRun.is() + && xRun->getPropertySetInfo()->hasPropertyByName(u"HyperLinkName"_ustr)) + { + xRun->setPropertyValue(u"HyperLinkName"_ustr, + uno::Any(aNameDialog->GetName())); + } + } + else + { + SwFlyFrameFormat* const pFlyFormat{ const_cast<SwFlyFrameFormat*>( + m_pDoc->FindFlyByName(m_sObjectID)) }; + if (pFlyFormat) + { + SwFormatURL item{ pFlyFormat->GetURL() }; + item.SetName(aNameDialog->GetName()); + SwAttrSet set{ m_pDoc->GetAttrPool(), svl::Items<RES_URL, RES_URL> }; + set.Put(item); + m_pDoc->SetFlyFrameAttr(*pFlyFormat, set); + } } pWrtShell->SetModified(); } diff --git a/sw/source/core/inc/AccessibilityCheck.hxx b/sw/source/core/inc/AccessibilityCheck.hxx index caaff1944842..30fb75246481 100644 --- a/sw/source/core/inc/AccessibilityCheck.hxx +++ b/sw/source/core/inc/AccessibilityCheck.hxx @@ -49,7 +49,7 @@ public: } void check() override; - void checkObject(SwNode* pNode, SdrObject* pObject); + void checkObject(SwNode* pNode, SwFrameFormat const&); void checkNode(SwNode* pNode); void checkDocumentProperties(); }; diff --git a/sw/source/core/inc/AccessibilityIssue.hxx b/sw/source/core/inc/AccessibilityIssue.hxx index 647d51b66da7..1d8afcfc5e36 100644 --- a/sw/source/core/inc/AccessibilityIssue.hxx +++ b/sw/source/core/inc/AccessibilityIssue.hxx @@ -27,6 +27,7 @@ enum class IssueObject TABLE, TEXT, HYPERLINKTEXT, + HYPERLINKFLY, DOCUMENT_TITLE, DOCUMENT_BACKGROUND, LANGUAGE_NOT_SET, diff --git a/sw/source/core/txtnode/OnlineAccessibilityCheck.cxx b/sw/source/core/txtnode/OnlineAccessibilityCheck.cxx index d861084d7018..235a7b5b4545 100644 --- a/sw/source/core/txtnode/OnlineAccessibilityCheck.cxx +++ b/sw/source/core/txtnode/OnlineAccessibilityCheck.cxx @@ -140,9 +140,7 @@ void OnlineAccessibilityCheck::runAccessibilityCheck(SwNode* pNode) for (SwFrameFormat* const& pFrameFormat : pNode->GetAnchoredFlys()) { - SdrObject* pObject = pFrameFormat->FindSdrObject(); - if (pObject) - m_aAccessibilityCheck.checkObject(pNode, pObject); + m_aAccessibilityCheck.checkObject(pNode, *pFrameFormat); } auto aCollection = m_aAccessibilityCheck.getIssueCollection();