1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* 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/.
*/
#include <test/a11y/swaccessibletestbase.hxx>
#include <com/sun/star/accessibility/AccessibleRelationType.hpp>
#include <com/sun/star/accessibility/XAccessibleContext.hpp>
#include <com/sun/star/accessibility/XAccessibleText.hpp>
#include <com/sun/star/uno/Reference.hxx>
#include <rtl/ustrbuf.hxx>
#include <test/a11y/AccessibilityTools.hxx>
using namespace css;
uno::Reference<accessibility::XAccessibleContext>
test::SwAccessibleTestBase::getPreviousFlowingSibling(
const uno::Reference<accessibility::XAccessibleContext>& xContext)
{
return getFirstRelationTargetOfType(xContext,
accessibility::AccessibleRelationType::CONTENT_FLOWS_FROM);
}
uno::Reference<accessibility::XAccessibleContext> test::SwAccessibleTestBase::getNextFlowingSibling(
const uno::Reference<accessibility::XAccessibleContext>& xContext)
{
return getFirstRelationTargetOfType(xContext,
accessibility::AccessibleRelationType::CONTENT_FLOWS_TO);
}
/* Care has to be taken not to walk sideways as the relation is also used
* with children of nested containers (possibly as the "natural"/"perceived" flow?). */
std::deque<uno::Reference<accessibility::XAccessibleContext>>
test::SwAccessibleTestBase::getAllChildren(
const uno::Reference<accessibility::XAccessibleContext>& xContext)
{
/* first, get all "natural" children */
auto children = AccessibleTestBase::getAllChildren(xContext);
if (!children.size())
return children;
/* then, try and find flowing siblings at the same levels that are not included in the list */
/* first, backwards: */
auto child = getPreviousFlowingSibling(children.front());
while (child.is() && children.size() < AccessibilityTools::MAX_CHILDREN)
{
auto childParent = child->getAccessibleParent();
if (childParent.is()
&& AccessibilityTools::equals(xContext, childParent->getAccessibleContext()))
children.push_front(child);
child = getPreviousFlowingSibling(child);
}
/* then forward */
child = getNextFlowingSibling(children.back());
while (child.is() && children.size() < AccessibilityTools::MAX_CHILDREN)
{
auto childParent = child->getAccessibleParent();
if (childParent.is()
&& AccessibilityTools::equals(xContext, childParent->getAccessibleContext()))
children.push_back(child);
child = getNextFlowingSibling(child);
}
return children;
}
void test::SwAccessibleTestBase::collectText(
const uno::Reference<accessibility::XAccessibleContext>& xContext, rtl::OUStringBuffer& buffer,
bool onlyChildren)
{
const auto& roleName = AccessibilityTools::getRoleName(xContext->getAccessibleRole());
std::cout << "collecting text for child of role " << roleName << "..." << std::endl;
if (!onlyChildren)
{
const struct
{
std::u16string_view name;
rtl::OUString value;
} attrs[] = {
{ u"name", xContext->getAccessibleName() },
{ u"description", xContext->getAccessibleDescription() },
};
buffer.append('<');
buffer.append(roleName);
for (auto& attr : attrs)
{
if (attr.value.getLength() == 0)
continue;
buffer.append(' ');
buffer.append(attr.name);
buffer.append(u"=\"" + attr.value.replaceAll(u"\"", u""") + "\"");
}
buffer.append('>');
}
auto openTagLength = buffer.getLength();
uno::Reference<accessibility::XAccessibleText> xText(xContext, uno::UNO_QUERY);
if (xText.is())
buffer.append(xText->getText());
for (auto& childContext : getAllChildren(xContext))
collectText(childContext, buffer);
if (!onlyChildren)
{
if (buffer.getLength() != openTagLength)
buffer.append("</" + roleName + ">");
else
{
/* there was no content, so make is a short tag for more concise output */
buffer[openTagLength - 1] = '/';
buffer.append('>');
}
}
}
OUString test::SwAccessibleTestBase::collectText(
const uno::Reference<accessibility::XAccessibleContext>& xContext)
{
rtl::OUStringBuffer buf;
collectText(xContext, buf, isDocumentRole(xContext->getAccessibleRole()));
return buf.makeStringAndClear();
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
|