2 * Copyright (C) 2008 Apple Ltd.
3 * Copyright (C) 2008 Alp Toker <alp@atoker.com>
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.
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.
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.
22 #include "AccessibilityObject.h"
23 #include "RenderObject.h"
24 #include "RenderText.h"
26 #include <glib-object.h>
28 #if HAVE(ACCESSIBILITY)
32 bool AccessibilityObject::accessibilityIgnoreAttachment() const
37 AccessibilityObjectInclusion AccessibilityObject::accessibilityPlatformIncludesObject() const
39 AccessibilityObject* parent = parentObject();
41 return DefaultBehavior;
43 AccessibilityRole role = roleValue();
44 if (role == SplitterRole)
47 // We expose the slider as a whole but not its value indicator.
48 if (role == SliderThumbRole)
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())
56 // Entries and password fields have extraneous children which we want to ignore.
57 if (parent->isPasswordField() || parent->isTextControl())
60 // Include all tables, even layout tables. The AT can decide what to do with each.
61 if (role == CellRole || role == TableRole)
64 // The object containing the text should implement AtkText itself.
65 if (role == StaticTextRole)
68 // Include all list items, regardless they have or not inline children
69 if (role == ListItemRole)
72 // Bullets/numbers for list items shouldn't be exposed as AtkObjects.
73 if (role == ListMarkerRole)
76 return DefaultBehavior;
79 AccessibilityObjectWrapper* AccessibilityObject::wrapper() const
84 void AccessibilityObject::setWrapper(AccessibilityObjectWrapper* wrapper)
86 if (wrapper == m_wrapper)
90 g_object_unref(m_wrapper);
95 g_object_ref(m_wrapper);
98 bool AccessibilityObject::allowsTextRanges() const
100 // Check type for the AccessibilityObject.
101 if (isTextControl() || isWebArea() || isGroup() || isLink() || isHeading() || isListItem())
104 // Check roles as the last fallback mechanism.
105 AccessibilityRole role = roleValue();
106 return role == ParagraphRole || role == LabelRole || role == DivRole || role == FormRole;
109 unsigned AccessibilityObject::getLengthForTextRange() const
111 unsigned textLength = text().length();
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;
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();
132 } // namespace WebCore
134 #endif // HAVE(ACCESSIBILITY)