summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Weghorn <m.weghorn@posteo.de>2024-02-27 13:12:43 +0100
committerMichael Weghorn <m.weghorn@posteo.de>2024-02-27 19:34:55 +0100
commitad1167b92b8b8fdabf6b21e945682c0bafc80946 (patch)
tree650e4b032aad39a148bbc29996ef608820e342e0
parent8e456d51a48b4d2461634a41a40a5a3b58bfdef3 (diff)
tdf#159910 a11y VclBuilder: Apply tool item's a11y name to itself
For the VCL `ToolBox` implementation of a toolbar, the items are not represented by own widgets (`vcl::Window`s), but handled by the `ToolBox`. As a consequence, the `vcl::Window` passed to `VclBuilder::applyAtkProperties` cannot be the tool item itself (e.g. a `GtkToolButton` in the .ui file), but is the `ToolBox`, i.e. the (VCL builder implementation of the `GtkToolbar` parent widget in the .ui file). So far, the ATK properties set for the tool item were just applied to the parent instead. For example, with the upcoming Change-Id: I852503e849651bb7be4daa419ec2379568623f0f Author: Michael Weghorn <m.weghorn@posteo.de> Date: Tue Feb 27 11:51:55 2024 +0100 tdf#159910 sw a11y: Set a11y names for Navigator items , this would result in the toolbars getting the name of their last item (one of the toolbars in the Navigator would get the a11y name "Show Up to Outline Level") and the toolbar items would only have an a11y name set because they still fall back to the tooltip text for the a11y name. Adjust that to set the accessible name for the actual toolbar item when a toolbar item is processed. (Add a bool param to indicate that). See also `VclBuilder::applyPackingProperty` which already had a similar way to determine and handle that case. With this in place, the accessible name set in the .ui file is now applied to the toolbar item as expected. (The accessible description could be handled similarly, but I'm a bit more hesitant to add that right away because the accessible description is currently also used for the extended tooltip text and the NVDA screen reader on Windows announces the description in addition to the name by default.) Change-Id: I45b87839dda90083ceba1c43fdb4d4ec460fce3d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164034 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
-rw-r--r--include/vcl/builder.hxx12
-rw-r--r--vcl/source/window/builder.cxx25
2 files changed, 26 insertions, 11 deletions
diff --git a/include/vcl/builder.hxx b/include/vcl/builder.hxx
index 37fbfbe97e16..59202ba34062 100644
--- a/include/vcl/builder.hxx
+++ b/include/vcl/builder.hxx
@@ -353,9 +353,12 @@ private:
void extractMnemonicWidget(const OUString &id, stringmap &rMap);
// either pParent or pAtkProps must be set, pParent for a child of a widget, pAtkProps for
- // collecting the atk info for a GtkMenuItem
- void handleChild(vcl::Window *pParent, stringmap *pAtkProps, xmlreader::XmlReader &reader);
- VclPtr<vcl::Window> handleObject(vcl::Window *pParent, stringmap *pAtkProps, xmlreader::XmlReader &reader);
+ // collecting the atk info for a GtkMenuItem,
+ // if bToolbarItem=true, pParent is the ToolBox that the item belongs to, since there's no widget for the item itself
+ void handleChild(vcl::Window *pParent, stringmap *pAtkProps, xmlreader::XmlReader &reader, bool bToolbarItem = false);
+ // if bToolbarItem=true, pParent is the ToolBox that the item belongs to, since there's no widget for the item itself
+ VclPtr<vcl::Window> handleObject(vcl::Window *pParent, stringmap *pAtkProps, xmlreader::XmlReader &reader, bool bToolbarItem);
+
void handlePacking(vcl::Window *pCurrent, vcl::Window *pParent, xmlreader::XmlReader &reader);
static std::vector<vcl::EnumContext::Context> handleStyle(xmlreader::XmlReader &reader, int &nPriority);
static OUString getStyleClass(xmlreader::XmlReader &reader);
@@ -385,7 +388,8 @@ private:
stringmap handleAtkObject(xmlreader::XmlReader &reader) const;
- static void applyAtkProperties(vcl::Window *pWindow, const stringmap& rProperties);
+ // if bToolbarItem=true, pParent is the ToolBox that the item belongs to, since there's no widget for the item itself
+ void applyAtkProperties(vcl::Window *pWindow, const stringmap& rProperties, bool bToolbarItem);
void handleActionWidget(xmlreader::XmlReader &reader);
diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx
index 0fcf7d6b65fd..7c77fad75a53 100644
--- a/vcl/source/window/builder.cxx
+++ b/vcl/source/window/builder.cxx
@@ -2796,7 +2796,7 @@ void VclBuilder::tweakInsertedChild(vcl::Window *pParent, vcl::Window* pCurrentC
}
}
-void VclBuilder::handleChild(vcl::Window *pParent, stringmap* pAtkProps, xmlreader::XmlReader &reader)
+void VclBuilder::handleChild(vcl::Window *pParent, stringmap* pAtkProps, xmlreader::XmlReader &reader, bool bToolbarItem)
{
xmlreader::Span name;
int nsId;
@@ -2833,7 +2833,7 @@ void VclBuilder::handleChild(vcl::Window *pParent, stringmap* pAtkProps, xmlread
{
if (name == "object" || name == "placeholder")
{
- pCurrentChild = handleObject(pParent, pAtkProps, reader);
+ pCurrentChild = handleObject(pParent, pAtkProps, reader, bToolbarItem);
bool bObjectInserted = pCurrentChild && pParent != pCurrentChild;
if (bObjectInserted)
@@ -3095,12 +3095,22 @@ VclBuilder::stringmap VclBuilder::handleAtkObject(xmlreader::XmlReader &reader)
return aProperties;
}
-void VclBuilder::applyAtkProperties(vcl::Window *pWindow, const stringmap& rProperties)
+void VclBuilder::applyAtkProperties(vcl::Window *pWindow, const stringmap& rProperties, bool bToolbarItem)
{
assert(pWindow);
for (auto const& [ rKey, rValue ] : rProperties)
{
- if (pWindow && rKey.match("AtkObject::"))
+ if (bToolbarItem)
+ {
+ // apply accessible name to the toolbar item
+ if (rKey == u"AtkObject::accessible-name")
+ {
+ ToolBox* pToolBox = dynamic_cast<ToolBox*>(pWindow);
+ assert(pToolBox);
+ pToolBox->SetAccessibleName(m_pParserState->m_nLastToolbarId, rValue);
+ }
+ }
+ else if (pWindow && rKey.match("AtkObject::"))
pWindow->set_property(rKey.copy(RTL_CONSTASCII_LENGTH("AtkObject::")), rValue);
else
SAL_WARN("vcl.builder", "unhandled atk prop: " << rKey);
@@ -3558,7 +3568,7 @@ template<typename T> static bool insertItems(vcl::Window *pWindow, VclBuilder::s
return true;
}
-VclPtr<vcl::Window> VclBuilder::handleObject(vcl::Window *pParent, stringmap *pAtkProps, xmlreader::XmlReader &reader)
+VclPtr<vcl::Window> VclBuilder::handleObject(vcl::Window *pParent, stringmap *pAtkProps, xmlreader::XmlReader &reader, bool bToolbarItem)
{
OUString sClass;
OUString sID;
@@ -3616,7 +3626,7 @@ VclPtr<vcl::Window> VclBuilder::handleObject(vcl::Window *pParent, stringmap *pA
assert(!(pParent && pAtkProps) && "must not have both");
auto aAtkProperties = handleAtkObject(reader);
if (pParent)
- applyAtkProperties(pParent, aAtkProperties);
+ applyAtkProperties(pParent, aAtkProperties, bToolbarItem);
if (pAtkProps)
*pAtkProps = aAtkProperties;
return nullptr;
@@ -3649,7 +3659,8 @@ VclPtr<vcl::Window> VclBuilder::handleObject(vcl::Window *pParent, stringmap *pA
pCurrentChild = insertObject(pParent, sClass, sID,
aProperties, aPangoAttributes, aAtkAttributes);
}
- handleChild(pCurrentChild, nullptr, reader);
+ const bool bToolItem = pCurrentChild == pParent && pCurrentChild->GetType() == WindowType::TOOLBOX && isToolbarItemClass(sClass);
+ handleChild(pCurrentChild, nullptr, reader, bToolItem);
}
else if (name == "items")
aItems = handleItems(reader);