AccessibilityObjectAtk.cpp revision 2bde8e466a4451c7319e3a072d118917957d6554
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 30namespace WebCore { 31 32bool AccessibilityObject::accessibilityIgnoreAttachment() const 33{ 34 return false; 35} 36 37AccessibilityObjectInclusion AccessibilityObject::accessibilityPlatformIncludesObject() const 38{ 39 AccessibilityObject* parent = parentObject(); 40 if (!parent) 41 return DefaultBehavior; 42 43 if (roleValue() == SplitterRole) 44 return IncludeObject; 45 46 // When a list item is made up entirely of children (e.g. paragraphs) 47 // the list item gets ignored. We need it. 48 if (isGroup() && parent->isList()) 49 return IncludeObject; 50 51 // Entries and password fields have extraneous children which we want to ignore. 52 if (parent->isPasswordField() || parent->isTextControl()) 53 return IgnoreObject; 54 55 AccessibilityRole role = roleValue(); 56 57 // Include all tables, even layout tables. The AT can decide what to do with each. 58 if (role == CellRole || role == TableRole) 59 return IncludeObject; 60 61 // We at some point might have a need to expose a table row; but it's not standard Gtk+. 62 if (role == RowRole) 63 return IgnoreObject; 64 65 // The object containing the text should implement AtkText itself. 66 if (role == StaticTextRole) 67 return IgnoreObject; 68 69 // Include all list items, regardless they have or not inline children 70 if (role == ListItemRole) 71 return IncludeObject; 72 73 // Bullets/numbers for list items shouldn't be exposed as AtkObjects. 74 if (role == ListMarkerRole) 75 return IgnoreObject; 76 77 return DefaultBehavior; 78} 79 80AccessibilityObjectWrapper* AccessibilityObject::wrapper() const 81{ 82 return m_wrapper; 83} 84 85void AccessibilityObject::setWrapper(AccessibilityObjectWrapper* wrapper) 86{ 87 if (wrapper == m_wrapper) 88 return; 89 90 if (m_wrapper) 91 g_object_unref(m_wrapper); 92 93 m_wrapper = wrapper; 94 95 if (m_wrapper) 96 g_object_ref(m_wrapper); 97} 98 99bool AccessibilityObject::allowsTextRanges() const 100{ 101 // Check type for the AccessibilityObject. 102 if (isTextControl() || isWebArea() || isGroup() || isLink() || isHeading() || isListItem()) 103 return true; 104 105 // Check roles as the last fallback mechanism. 106 AccessibilityRole role = roleValue(); 107 return role == ParagraphRole || role == LabelRole || role == DivRole || role == FormRole; 108} 109 110unsigned AccessibilityObject::getLengthForTextRange() const 111{ 112 unsigned textLength = text().length(); 113 114 if (textLength) 115 return textLength; 116 117 // Gtk ATs need this for all text objects; not just text controls. 118 Node* node = this->node(); 119 RenderObject* renderer = node ? node->renderer() : 0; 120 if (renderer && renderer->isText()) { 121 RenderText* renderText = toRenderText(renderer); 122 textLength = renderText ? renderText->textLength() : 0; 123 } 124 125 // Get the text length from the elements under the 126 // accessibility object if the value is still zero. 127 if (!textLength && allowsTextRanges()) 128 textLength = textUnderElement().length(); 129 130 return textLength; 131} 132 133} // namespace WebCore 134 135#endif // HAVE(ACCESSIBILITY) 136