AccessibilityObjectAtk.cpp 3.96 KB
Newer Older
1
2
/*
 * Copyright (C) 2008 Apple Ltd.
3
 * Copyright (C) 2008 Alp Toker <alp@atoker.com>
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this library; see the file COPYING.LIB.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

#include "config.h"
#include "AccessibilityObject.h"
23
24
#include "RenderObject.h"
#include "RenderText.h"
25

26
27
#include <glib-object.h>

28
29
#if HAVE(ACCESSIBILITY)

30
31
32
33
34
35
36
namespace WebCore {

bool AccessibilityObject::accessibilityIgnoreAttachment() const
{
    return false;
}

37
AccessibilityObjectInclusion AccessibilityObject::accessibilityPlatformIncludesObject() const
38
{
39
40
41
42
    AccessibilityObject* parent = parentObject();
    if (!parent)
        return DefaultBehavior;

43
44
    AccessibilityRole role = roleValue();
    if (role == SplitterRole)
45
46
        return IncludeObject;

47
48
49
50
    // We expose the slider as a whole but not its value indicator.
    if (role == SliderThumbRole)
        return IgnoreObject;

51
52
53
54
    // When a list item is made up entirely of children (e.g. paragraphs)
    // the list item gets ignored. We need it.
    if (isGroup() && parent->isList())
        return IncludeObject;
55
56
57
58

    // Entries and password fields have extraneous children which we want to ignore.
    if (parent->isPasswordField() || parent->isTextControl())
        return IgnoreObject;
59

60
61
62
63
    // Include all tables, even layout tables. The AT can decide what to do with each.
    if (role == CellRole || role == TableRole)
        return IncludeObject;

64
    // The object containing the text should implement AtkText itself.
65
    if (role == StaticTextRole)
66
67
        return IgnoreObject;

68
69
70
71
    // Include all list items, regardless they have or not inline children
    if (role == ListItemRole)
        return IncludeObject;

72
    // Bullets/numbers for list items shouldn't be exposed as AtkObjects.
73
    if (role == ListMarkerRole)
74
75
        return IgnoreObject;

76
    return DefaultBehavior;
77
78
}

79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
AccessibilityObjectWrapper* AccessibilityObject::wrapper() const
{
    return m_wrapper;
}

void AccessibilityObject::setWrapper(AccessibilityObjectWrapper* wrapper)
{
    if (wrapper == m_wrapper)
        return;

    if (m_wrapper)
        g_object_unref(m_wrapper);

    m_wrapper = wrapper;

    if (m_wrapper)
        g_object_ref(m_wrapper);
}

98
99
bool AccessibilityObject::allowsTextRanges() const
{
100
101
102
103
104
105
106
    // Check type for the AccessibilityObject.
    if (isTextControl() || isWebArea() || isGroup() || isLink() || isHeading() || isListItem())
        return true;

    // Check roles as the last fallback mechanism.
    AccessibilityRole role = roleValue();
    return role == ParagraphRole || role == LabelRole || role == DivRole || role == FormRole;
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
unsigned AccessibilityObject::getLengthForTextRange() const
{
    unsigned textLength = text().length();

    if (textLength)
        return textLength;

    // Gtk ATs need this for all text objects; not just text controls.
    Node* node = this->node();
    RenderObject* renderer = node ? node->renderer() : 0;
    if (renderer && renderer->isText()) {
        RenderText* renderText = toRenderText(renderer);
        textLength = renderText ? renderText->textLength() : 0;
    }

    // Get the text length from the elements under the
    // accessibility object if the value is still zero.
    if (!textLength && allowsTextRanges())
        textLength = textUnderElement().length();

    return textLength;
}

132
} // namespace WebCore
133
134

#endif // HAVE(ACCESSIBILITY)