initial import
[vuplus_webkit] / Source / WebCore / accessibility / gtk / AccessibilityObjectAtk.cpp
1 /*
2  * Copyright (C) 2008 Apple Ltd.
3  * Copyright (C) 2008 Alp Toker <alp@atoker.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public License
16  * along with this library; see the file COPYING.LIB.  If not, write to
17  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20
21 #include "config.h"
22 #include "AccessibilityObject.h"
23 #include "RenderObject.h"
24 #include "RenderText.h"
25
26 #include <glib-object.h>
27
28 #if HAVE(ACCESSIBILITY)
29
30 namespace WebCore {
31
32 bool AccessibilityObject::accessibilityIgnoreAttachment() const
33 {
34     return false;
35 }
36
37 AccessibilityObjectInclusion AccessibilityObject::accessibilityPlatformIncludesObject() const
38 {
39     AccessibilityObject* parent = parentObject();
40     if (!parent)
41         return DefaultBehavior;
42
43     AccessibilityRole role = roleValue();
44     if (role == SplitterRole)
45         return IncludeObject;
46
47     // We expose the slider as a whole but not its value indicator.
48     if (role == SliderThumbRole)
49         return IgnoreObject;
50
51     // When a list item is made up entirely of children (e.g. paragraphs)
52     // the list item gets ignored. We need it.
53     if (isGroup() && parent->isList())
54         return IncludeObject;
55
56     // Entries and password fields have extraneous children which we want to ignore.
57     if (parent->isPasswordField() || parent->isTextControl())
58         return IgnoreObject;
59
60     // Include all tables, even layout tables. The AT can decide what to do with each.
61     if (role == CellRole || role == TableRole)
62         return IncludeObject;
63
64     // The object containing the text should implement AtkText itself.
65     if (role == StaticTextRole)
66         return IgnoreObject;
67
68     // Include all list items, regardless they have or not inline children
69     if (role == ListItemRole)
70         return IncludeObject;
71
72     // Bullets/numbers for list items shouldn't be exposed as AtkObjects.
73     if (role == ListMarkerRole)
74         return IgnoreObject;
75
76     return DefaultBehavior;
77 }
78
79 AccessibilityObjectWrapper* AccessibilityObject::wrapper() const
80 {
81     return m_wrapper;
82 }
83
84 void AccessibilityObject::setWrapper(AccessibilityObjectWrapper* wrapper)
85 {
86     if (wrapper == m_wrapper)
87         return;
88
89     if (m_wrapper)
90         g_object_unref(m_wrapper);
91
92     m_wrapper = wrapper;
93
94     if (m_wrapper)
95         g_object_ref(m_wrapper);
96 }
97
98 bool AccessibilityObject::allowsTextRanges() const
99 {
100     // Check type for the AccessibilityObject.
101     if (isTextControl() || isWebArea() || isGroup() || isLink() || isHeading() || isListItem())
102         return true;
103
104     // Check roles as the last fallback mechanism.
105     AccessibilityRole role = roleValue();
106     return role == ParagraphRole || role == LabelRole || role == DivRole || role == FormRole;
107 }
108
109 unsigned AccessibilityObject::getLengthForTextRange() const
110 {
111     unsigned textLength = text().length();
112
113     if (textLength)
114         return textLength;
115
116     // Gtk ATs need this for all text objects; not just text controls.
117     Node* node = this->node();
118     RenderObject* renderer = node ? node->renderer() : 0;
119     if (renderer && renderer->isText()) {
120         RenderText* renderText = toRenderText(renderer);
121         textLength = renderText ? renderText->textLength() : 0;
122     }
123
124     // Get the text length from the elements under the
125     // accessibility object if the value is still zero.
126     if (!textLength && allowsTextRanges())
127         textLength = textUnderElement().length();
128
129     return textLength;
130 }
131
132 } // namespace WebCore
133
134 #endif // HAVE(ACCESSIBILITY)