alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 Nuanti Ltd. |
jmalonzo@webkit.org | aaaea3b | 2009-08-08 07:39:48 +0000 | [diff] [blame] | 3 | * Copyright (C) 2009 Jan Alonzo |
mario@webkit.org | 9adab66 | 2012-01-23 10:21:03 +0000 | [diff] [blame] | 4 | * Copyright (C) 2009, 2010, 2011, 2012 Igalia S.L. |
mario@webkit.org | fecbacd | 2013-03-04 17:06:15 +0000 | [diff] [blame] | 5 | * Copyright (C) 2013 Samsung Electronics |
xan@webkit.org | e438710 | 2009-04-09 11:08:48 +0000 | [diff] [blame] | 6 | * |
| 7 | * Portions from Mozilla a11y, copyright as follows: |
| 8 | * |
| 9 | * The Original Code is mozilla.org code. |
| 10 | * |
| 11 | * The Initial Developer of the Original Code is |
| 12 | * Sun Microsystems, Inc. |
| 13 | * Portions created by the Initial Developer are Copyright (C) 2002 |
| 14 | * the Initial Developer. All Rights Reserved. |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 15 | * |
| 16 | * This library is free software; you can redistribute it and/or |
| 17 | * modify it under the terms of the GNU Library General Public |
| 18 | * License as published by the Free Software Foundation; either |
| 19 | * version 2 of the License, or (at your option) any later version. |
| 20 | * |
| 21 | * This library is distributed in the hope that it will be useful, |
| 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 24 | * Library General Public License for more details. |
| 25 | * |
| 26 | * You should have received a copy of the GNU Library General Public License |
| 27 | * along with this library; see the file COPYING.LIB. If not, write to |
| 28 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 29 | * Boston, MA 02110-1301, USA. |
| 30 | */ |
| 31 | |
| 32 | #include "config.h" |
mario@webkit.org | 9adab66 | 2012-01-23 10:21:03 +0000 | [diff] [blame] | 33 | #include "WebKitAccessibleWrapperAtk.h" |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 34 | |
ddkilzer@apple.com | 8d87863 | 2008-11-09 19:50:37 +0000 | [diff] [blame] | 35 | #if HAVE(ACCESSIBILITY) |
| 36 | |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 37 | #include "AXObjectCache.h" |
alp@webkit.org | c773899 | 2008-05-27 02:48:14 +0000 | [diff] [blame] | 38 | #include "Document.h" |
alp@webkit.org | c773899 | 2008-05-27 02:48:14 +0000 | [diff] [blame] | 39 | #include "Frame.h" |
| 40 | #include "FrameView.h" |
xan@webkit.org | 9561b2c | 2009-05-20 14:33:19 +0000 | [diff] [blame] | 41 | #include "HTMLNames.h" |
xan@webkit.org | 45b26ac | 2009-10-27 12:20:35 +0000 | [diff] [blame] | 42 | #include "HTMLTableElement.h" |
mario@webkit.org | 9adab66 | 2012-01-23 10:21:03 +0000 | [diff] [blame] | 43 | #include "HostWindow.h" |
mario@webkit.org | 970eaf3 | 2012-01-24 18:37:45 +0000 | [diff] [blame] | 44 | #include "RenderObject.h" |
mario@webkit.org | 6a24ba1 | 2010-12-14 15:35:22 +0000 | [diff] [blame] | 45 | #include "Settings.h" |
commit-queue@webkit.org | 74bd2e8 | 2010-09-12 11:16:14 +0000 | [diff] [blame] | 46 | #include "TextIterator.h" |
tkent@chromium.org | 8c35c12 | 2013-03-06 13:00:14 +0000 | [diff] [blame] | 47 | #include "VisibleUnits.h" |
mario@webkit.org | 7f95c62 | 2010-11-01 15:05:36 +0000 | [diff] [blame] | 48 | #include "WebKitAccessibleHyperlink.h" |
mario@webkit.org | deec839 | 2012-01-23 14:45:23 +0000 | [diff] [blame] | 49 | #include "WebKitAccessibleInterfaceAction.h" |
mario@webkit.org | be1ce55 | 2012-01-24 11:03:51 +0000 | [diff] [blame] | 50 | #include "WebKitAccessibleInterfaceComponent.h" |
mario@webkit.org | f8344ff | 2012-01-24 11:40:44 +0000 | [diff] [blame] | 51 | #include "WebKitAccessibleInterfaceDocument.h" |
mario@webkit.org | fc51ca6 | 2012-01-24 11:47:51 +0000 | [diff] [blame] | 52 | #include "WebKitAccessibleInterfaceEditableText.h" |
mario@webkit.org | 4dbd982 | 2012-01-24 11:55:18 +0000 | [diff] [blame] | 53 | #include "WebKitAccessibleInterfaceHyperlinkImpl.h" |
mario@webkit.org | 7024353 | 2012-01-24 11:58:52 +0000 | [diff] [blame] | 54 | #include "WebKitAccessibleInterfaceHypertext.h" |
mario@webkit.org | da3e608 | 2012-01-24 12:04:16 +0000 | [diff] [blame] | 55 | #include "WebKitAccessibleInterfaceImage.h" |
mario@webkit.org | 7e5931d | 2012-01-24 12:25:13 +0000 | [diff] [blame] | 56 | #include "WebKitAccessibleInterfaceSelection.h" |
mario@webkit.org | cd9f1b3 | 2012-01-24 18:28:22 +0000 | [diff] [blame] | 57 | #include "WebKitAccessibleInterfaceTable.h" |
mario@webkit.org | 987d737 | 2012-01-24 18:02:08 +0000 | [diff] [blame] | 58 | #include "WebKitAccessibleInterfaceText.h" |
mario@webkit.org | 980269e | 2012-01-24 16:22:57 +0000 | [diff] [blame] | 59 | #include "WebKitAccessibleInterfaceValue.h" |
mario@webkit.org | 7ceffa4 | 2012-01-23 11:55:01 +0000 | [diff] [blame] | 60 | #include "WebKitAccessibleUtil.h" |
mario@webkit.org | ba16aea | 2011-04-13 16:33:02 +0000 | [diff] [blame] | 61 | #include "htmlediting.h" |
xan@webkit.org | e438710 | 2009-04-09 11:08:48 +0000 | [diff] [blame] | 62 | #include <glib/gprintf.h> |
benjamin@webkit.org | 9d72cb0 | 2013-04-22 22:52:23 +0000 | [diff] [blame] | 63 | #include <wtf/text/CString.h> |
mario@webkit.org | 8c5dd90 | 2012-11-09 19:47:40 +0000 | [diff] [blame] | 64 | |
| 65 | #if PLATFORM(GTK) |
mario@webkit.org | 970eaf3 | 2012-01-24 18:37:45 +0000 | [diff] [blame] | 66 | #include <gtk/gtk.h> |
mario@webkit.org | 8c5dd90 | 2012-11-09 19:47:40 +0000 | [diff] [blame] | 67 | #endif |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 68 | |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 69 | using namespace WebCore; |
| 70 | |
mario@webkit.org | fecbacd | 2013-03-04 17:06:15 +0000 | [diff] [blame] | 71 | struct _WebKitAccessiblePrivate { |
| 72 | // Cached data for AtkObject. |
| 73 | CString accessibleName; |
| 74 | CString accessibleDescription; |
| 75 | |
| 76 | // Cached data for AtkAction. |
| 77 | CString actionName; |
| 78 | CString actionKeyBinding; |
| 79 | |
| 80 | // Cached data for AtkDocument. |
| 81 | CString documentLocale; |
| 82 | CString documentType; |
| 83 | CString documentEncoding; |
| 84 | CString documentURI; |
| 85 | |
| 86 | // Cached data for AtkImage. |
| 87 | CString imageDescription; |
| 88 | }; |
| 89 | |
| 90 | #define WEBKIT_ACCESSIBLE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), WEBKIT_TYPE_ACCESSIBLE, WebKitAccessiblePrivate)) |
| 91 | |
xan@webkit.org | c886cc6 | 2009-04-09 11:17:48 +0000 | [diff] [blame] | 92 | static AccessibilityObject* fallbackObject() |
| 93 | { |
cfleizach@apple.com | 6bd30ef | 2011-01-05 01:36:57 +0000 | [diff] [blame] | 94 | // FIXME: An AXObjectCache with a Document is meaningless. |
| 95 | static AXObjectCache* fallbackCache = new AXObjectCache(0); |
xan@webkit.org | c886cc6 | 2009-04-09 11:17:48 +0000 | [diff] [blame] | 96 | static AccessibilityObject* object = 0; |
| 97 | if (!object) { |
| 98 | // FIXME: using fallbackCache->getOrCreate(ListBoxOptionRole) is a hack |
| 99 | object = fallbackCache->getOrCreate(ListBoxOptionRole); |
| 100 | object->ref(); |
| 101 | } |
| 102 | |
| 103 | return object; |
| 104 | } |
| 105 | |
alp@webkit.org | c773899 | 2008-05-27 02:48:14 +0000 | [diff] [blame] | 106 | static AccessibilityObject* core(WebKitAccessible* accessible) |
| 107 | { |
| 108 | if (!accessible) |
| 109 | return 0; |
| 110 | |
| 111 | return accessible->m_object; |
| 112 | } |
| 113 | |
| 114 | static AccessibilityObject* core(AtkObject* object) |
| 115 | { |
| 116 | if (!WEBKIT_IS_ACCESSIBLE(object)) |
| 117 | return 0; |
| 118 | |
| 119 | return core(WEBKIT_ACCESSIBLE(object)); |
| 120 | } |
| 121 | |
mario@webkit.org | 5c96677 | 2012-01-24 18:48:50 +0000 | [diff] [blame] | 122 | static const gchar* webkitAccessibleGetName(AtkObject* object) |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 123 | { |
eric@webkit.org | 0f6cb45 | 2009-10-22 23:07:56 +0000 | [diff] [blame] | 124 | AccessibilityObject* coreObject = core(object); |
eric@webkit.org | 5a5bba5 | 2009-12-07 14:27:44 +0000 | [diff] [blame] | 125 | if (!coreObject->isAccessibilityRenderObject()) |
mario@webkit.org | fecbacd | 2013-03-04 17:06:15 +0000 | [diff] [blame] | 126 | return cacheAndReturnAtkProperty(object, AtkCachedAccessibleName, coreObject->stringValue()); |
eric@webkit.org | 5a5bba5 | 2009-12-07 14:27:44 +0000 | [diff] [blame] | 127 | |
commit-queue@webkit.org | 802c012 | 2012-09-11 01:41:27 +0000 | [diff] [blame] | 128 | if (coreObject->isFieldset()) { |
| 129 | AccessibilityObject* label = coreObject->titleUIElement(); |
| 130 | if (label) { |
| 131 | AtkObject* atkObject = label->wrapper(); |
| 132 | if (ATK_IS_TEXT(atkObject)) |
| 133 | return atk_text_get_text(ATK_TEXT(atkObject), 0, -1); |
| 134 | } |
| 135 | } |
| 136 | |
eric@webkit.org | 0f6cb45 | 2009-10-22 23:07:56 +0000 | [diff] [blame] | 137 | if (coreObject->isControl()) { |
mario@webkit.org | 7e9f241 | 2011-04-06 16:50:25 +0000 | [diff] [blame] | 138 | AccessibilityObject* label = coreObject->correspondingLabelForControlElement(); |
commit-queue@webkit.org | c5b9531 | 2010-06-24 03:18:17 +0000 | [diff] [blame] | 139 | if (label) { |
| 140 | AtkObject* atkObject = label->wrapper(); |
| 141 | if (ATK_IS_TEXT(atkObject)) |
mario@webkit.org | adc13a8 | 2012-01-24 21:18:36 +0000 | [diff] [blame] | 142 | return atk_text_get_text(ATK_TEXT(atkObject), 0, -1); |
commit-queue@webkit.org | c5b9531 | 2010-06-24 03:18:17 +0000 | [diff] [blame] | 143 | } |
commit-queue@webkit.org | ee60124 | 2010-08-04 18:29:10 +0000 | [diff] [blame] | 144 | |
mario@webkit.org | 92daa81 | 2011-02-16 17:12:38 +0000 | [diff] [blame] | 145 | // Try text under the node. |
mario@webkit.org | 7e9f241 | 2011-04-06 16:50:25 +0000 | [diff] [blame] | 146 | String textUnder = coreObject->textUnderElement(); |
commit-queue@webkit.org | ee60124 | 2010-08-04 18:29:10 +0000 | [diff] [blame] | 147 | if (textUnder.length()) |
mario@webkit.org | fecbacd | 2013-03-04 17:06:15 +0000 | [diff] [blame] | 148 | return cacheAndReturnAtkProperty(object, AtkCachedAccessibleName, textUnder); |
eric@webkit.org | 0f6cb45 | 2009-10-22 23:07:56 +0000 | [diff] [blame] | 149 | } |
eric@webkit.org | 5a5bba5 | 2009-12-07 14:27:44 +0000 | [diff] [blame] | 150 | |
mario@webkit.org | 7e9f241 | 2011-04-06 16:50:25 +0000 | [diff] [blame] | 151 | if (coreObject->isImage() || coreObject->isInputImage()) { |
| 152 | Node* node = coreObject->node(); |
eric@webkit.org | 5a5bba5 | 2009-12-07 14:27:44 +0000 | [diff] [blame] | 153 | if (node && node->isHTMLElement()) { |
| 154 | // Get the attribute rather than altText String so as not to fall back on title. |
commit-queue@webkit.org | 03477c8 | 2011-09-02 17:07:51 +0000 | [diff] [blame] | 155 | String alt = toHTMLElement(node)->getAttribute(HTMLNames::altAttr); |
eric@webkit.org | 5a5bba5 | 2009-12-07 14:27:44 +0000 | [diff] [blame] | 156 | if (!alt.isEmpty()) |
mario@webkit.org | fecbacd | 2013-03-04 17:06:15 +0000 | [diff] [blame] | 157 | return cacheAndReturnAtkProperty(object, AtkCachedAccessibleName, alt); |
eric@webkit.org | 5a5bba5 | 2009-12-07 14:27:44 +0000 | [diff] [blame] | 158 | } |
| 159 | } |
| 160 | |
mario@webkit.org | 92daa81 | 2011-02-16 17:12:38 +0000 | [diff] [blame] | 161 | // Fallback for the webArea object: just return the document's title. |
mario@webkit.org | 7e9f241 | 2011-04-06 16:50:25 +0000 | [diff] [blame] | 162 | if (coreObject->isWebArea()) { |
mario@webkit.org | 92daa81 | 2011-02-16 17:12:38 +0000 | [diff] [blame] | 163 | Document* document = coreObject->document(); |
| 164 | if (document) |
mario@webkit.org | fecbacd | 2013-03-04 17:06:15 +0000 | [diff] [blame] | 165 | return cacheAndReturnAtkProperty(object, AtkCachedAccessibleName, document->title()); |
mario@webkit.org | 92daa81 | 2011-02-16 17:12:38 +0000 | [diff] [blame] | 166 | } |
| 167 | |
mario@webkit.org | d684f51 | 2011-11-29 11:00:58 +0000 | [diff] [blame] | 168 | // Nothing worked so far, try with the AccessibilityObject's |
| 169 | // title() before going ahead with stringValue(). |
mario@webkit.org | 99e78ca | 2012-10-22 17:32:52 +0000 | [diff] [blame] | 170 | String axTitle = accessibilityTitle(coreObject); |
mario@webkit.org | d684f51 | 2011-11-29 11:00:58 +0000 | [diff] [blame] | 171 | if (!axTitle.isEmpty()) |
mario@webkit.org | fecbacd | 2013-03-04 17:06:15 +0000 | [diff] [blame] | 172 | return cacheAndReturnAtkProperty(object, AtkCachedAccessibleName, axTitle); |
mario@webkit.org | d684f51 | 2011-11-29 11:00:58 +0000 | [diff] [blame] | 173 | |
mario@webkit.org | fecbacd | 2013-03-04 17:06:15 +0000 | [diff] [blame] | 174 | return cacheAndReturnAtkProperty(object, AtkCachedAccessibleName, coreObject->stringValue()); |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 175 | } |
| 176 | |
mario@webkit.org | 5c96677 | 2012-01-24 18:48:50 +0000 | [diff] [blame] | 177 | static const gchar* webkitAccessibleGetDescription(AtkObject* object) |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 178 | { |
eric@webkit.org | d7b6294 | 2009-10-28 16:53:41 +0000 | [diff] [blame] | 179 | AccessibilityObject* coreObject = core(object); |
eric@webkit.org | 5a5bba5 | 2009-12-07 14:27:44 +0000 | [diff] [blame] | 180 | Node* node = 0; |
| 181 | if (coreObject->isAccessibilityRenderObject()) |
mario@webkit.org | 7e9f241 | 2011-04-06 16:50:25 +0000 | [diff] [blame] | 182 | node = coreObject->node(); |
eric@webkit.org | 5a5bba5 | 2009-12-07 14:27:44 +0000 | [diff] [blame] | 183 | if (!node || !node->isHTMLElement() || coreObject->ariaRoleAttribute() != UnknownRole) |
mario@webkit.org | fecbacd | 2013-03-04 17:06:15 +0000 | [diff] [blame] | 184 | return cacheAndReturnAtkProperty(object, AtkCachedAccessibleDescription, accessibilityDescription(coreObject)); |
eric@webkit.org | d7b6294 | 2009-10-28 16:53:41 +0000 | [diff] [blame] | 185 | |
| 186 | // atk_table_get_summary returns an AtkObject. We have no summary object, so expose summary here. |
eric@webkit.org | 5a5bba5 | 2009-12-07 14:27:44 +0000 | [diff] [blame] | 187 | if (coreObject->roleValue() == TableRole) { |
kangil.han@samsung.com | b44a681 | 2013-07-08 06:52:41 +0000 | [diff] [blame] | 188 | String summary = toHTMLTableElement(node)->summary(); |
eric@webkit.org | 5a5bba5 | 2009-12-07 14:27:44 +0000 | [diff] [blame] | 189 | if (!summary.isEmpty()) |
mario@webkit.org | fecbacd | 2013-03-04 17:06:15 +0000 | [diff] [blame] | 190 | return cacheAndReturnAtkProperty(object, AtkCachedAccessibleDescription, summary); |
eric@webkit.org | d7b6294 | 2009-10-28 16:53:41 +0000 | [diff] [blame] | 191 | } |
| 192 | |
eric@webkit.org | 5a5bba5 | 2009-12-07 14:27:44 +0000 | [diff] [blame] | 193 | // The title attribute should be reliably available as the object's descripton. |
| 194 | // We do not want to fall back on other attributes in its absence. See bug 25524. |
yael.aharon@nokia.com | 3be82c1 | 2011-02-09 23:13:27 +0000 | [diff] [blame] | 195 | String title = toHTMLElement(node)->title(); |
eric@webkit.org | 5a5bba5 | 2009-12-07 14:27:44 +0000 | [diff] [blame] | 196 | if (!title.isEmpty()) |
mario@webkit.org | fecbacd | 2013-03-04 17:06:15 +0000 | [diff] [blame] | 197 | return cacheAndReturnAtkProperty(object, AtkCachedAccessibleDescription, title); |
eric@webkit.org | 5a5bba5 | 2009-12-07 14:27:44 +0000 | [diff] [blame] | 198 | |
mario@webkit.org | fecbacd | 2013-03-04 17:06:15 +0000 | [diff] [blame] | 199 | return cacheAndReturnAtkProperty(object, AtkCachedAccessibleDescription, accessibilityDescription(coreObject)); |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 200 | } |
| 201 | |
eric@webkit.org | 0f6cb45 | 2009-10-22 23:07:56 +0000 | [diff] [blame] | 202 | static void setAtkRelationSetFromCoreObject(AccessibilityObject* coreObject, AtkRelationSet* relationSet) |
| 203 | { |
commit-queue@webkit.org | 802c012 | 2012-09-11 01:41:27 +0000 | [diff] [blame] | 204 | if (coreObject->isFieldset()) { |
| 205 | AccessibilityObject* label = coreObject->titleUIElement(); |
| 206 | if (label) |
| 207 | atk_relation_set_add_relation_by_type(relationSet, ATK_RELATION_LABELLED_BY, label->wrapper()); |
| 208 | return; |
| 209 | } |
| 210 | |
| 211 | if (coreObject->roleValue() == LegendRole) { |
| 212 | for (AccessibilityObject* parent = coreObject->parentObjectUnignored(); parent; parent = parent->parentObjectUnignored()) { |
| 213 | if (parent->isFieldset()) { |
| 214 | atk_relation_set_add_relation_by_type(relationSet, ATK_RELATION_LABEL_FOR, parent->wrapper()); |
| 215 | break; |
| 216 | } |
| 217 | } |
| 218 | return; |
| 219 | } |
| 220 | |
mario@webkit.org | 7e9f241 | 2011-04-06 16:50:25 +0000 | [diff] [blame] | 221 | if (coreObject->isControl()) { |
| 222 | AccessibilityObject* label = coreObject->correspondingLabelForControlElement(); |
eric@webkit.org | 0f6cb45 | 2009-10-22 23:07:56 +0000 | [diff] [blame] | 223 | if (label) |
| 224 | atk_relation_set_add_relation_by_type(relationSet, ATK_RELATION_LABELLED_BY, label->wrapper()); |
| 225 | } else { |
mario@webkit.org | 7e9f241 | 2011-04-06 16:50:25 +0000 | [diff] [blame] | 226 | AccessibilityObject* control = coreObject->correspondingControlForLabelElement(); |
eric@webkit.org | 0f6cb45 | 2009-10-22 23:07:56 +0000 | [diff] [blame] | 227 | if (control) |
| 228 | atk_relation_set_add_relation_by_type(relationSet, ATK_RELATION_LABEL_FOR, control->wrapper()); |
| 229 | } |
| 230 | } |
| 231 | |
mario@webkit.org | f88ffcb | 2012-11-16 13:47:03 +0000 | [diff] [blame] | 232 | static gpointer webkitAccessibleParentClass = 0; |
eric@webkit.org | b84b474 | 2009-10-20 21:20:50 +0000 | [diff] [blame] | 233 | |
mario@webkit.org | 86390a1 | 2011-01-07 17:34:02 +0000 | [diff] [blame] | 234 | static bool isRootObject(AccessibilityObject* coreObject) |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 235 | { |
mario@webkit.org | 86390a1 | 2011-01-07 17:34:02 +0000 | [diff] [blame] | 236 | // The root accessible object in WebCore is always an object with |
| 237 | // the ScrolledArea role with one child with the WebArea role. |
| 238 | if (!coreObject || !coreObject->isScrollView()) |
| 239 | return false; |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 240 | |
mario@webkit.org | 86390a1 | 2011-01-07 17:34:02 +0000 | [diff] [blame] | 241 | AccessibilityObject* firstChild = coreObject->firstChild(); |
| 242 | if (!firstChild || !firstChild->isWebArea()) |
| 243 | return false; |
| 244 | |
| 245 | return true; |
| 246 | } |
| 247 | |
| 248 | static AtkObject* atkParentOfRootObject(AtkObject* object) |
| 249 | { |
| 250 | AccessibilityObject* coreObject = core(object); |
| 251 | AccessibilityObject* coreParent = coreObject->parentObjectUnignored(); |
| 252 | |
| 253 | // The top level object claims to not have a parent. This makes it |
eric@webkit.org | 03b220b | 2009-10-19 11:58:38 +0000 | [diff] [blame] | 254 | // impossible for assistive technologies to ascend the accessible |
| 255 | // hierarchy all the way to the application. (Bug 30489) |
mario@webkit.org | 86390a1 | 2011-01-07 17:34:02 +0000 | [diff] [blame] | 256 | if (!coreParent && isRootObject(coreObject)) { |
mario@webkit.org | 8d00fa7 | 2011-04-13 16:27:23 +0000 | [diff] [blame] | 257 | Document* document = coreObject->document(); |
| 258 | if (!document) |
| 259 | return 0; |
| 260 | |
mario@webkit.org | 8c5dd90 | 2012-11-09 19:47:40 +0000 | [diff] [blame] | 261 | #if PLATFORM(GTK) |
mario@webkit.org | 8d00fa7 | 2011-04-13 16:27:23 +0000 | [diff] [blame] | 262 | HostWindow* hostWindow = document->view()->hostWindow(); |
eric@webkit.org | 03b220b | 2009-10-19 11:58:38 +0000 | [diff] [blame] | 263 | if (hostWindow) { |
mario@webkit.org | 86390a1 | 2011-01-07 17:34:02 +0000 | [diff] [blame] | 264 | PlatformPageClient scrollView = hostWindow->platformPageClient(); |
| 265 | if (scrollView) { |
| 266 | GtkWidget* scrollViewParent = gtk_widget_get_parent(scrollView); |
| 267 | if (scrollViewParent) |
| 268 | return gtk_widget_get_accessible(scrollViewParent); |
eric@webkit.org | 03b220b | 2009-10-19 11:58:38 +0000 | [diff] [blame] | 269 | } |
| 270 | } |
mario@webkit.org | 8c5dd90 | 2012-11-09 19:47:40 +0000 | [diff] [blame] | 271 | #endif // PLATFORM(GTK) |
eric@webkit.org | 03b220b | 2009-10-19 11:58:38 +0000 | [diff] [blame] | 272 | } |
| 273 | |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 274 | if (!coreParent) |
eric@webkit.org | 1f5f7fe | 2009-11-04 10:35:56 +0000 | [diff] [blame] | 275 | return 0; |
| 276 | |
| 277 | return coreParent->wrapper(); |
| 278 | } |
| 279 | |
mario@webkit.org | 5c96677 | 2012-01-24 18:48:50 +0000 | [diff] [blame] | 280 | static AtkObject* webkitAccessibleGetParent(AtkObject* object) |
eric@webkit.org | 1f5f7fe | 2009-11-04 10:35:56 +0000 | [diff] [blame] | 281 | { |
mario@webkit.org | 46e9b26 | 2011-11-17 11:50:07 +0000 | [diff] [blame] | 282 | // Check first if the parent has been already set. |
mario@webkit.org | f88ffcb | 2012-11-16 13:47:03 +0000 | [diff] [blame] | 283 | AtkObject* accessibleParent = ATK_OBJECT_CLASS(webkitAccessibleParentClass)->get_parent(object); |
mario@webkit.org | 46e9b26 | 2011-11-17 11:50:07 +0000 | [diff] [blame] | 284 | if (accessibleParent) |
| 285 | return accessibleParent; |
| 286 | |
| 287 | // Parent not set yet, so try to find it in the hierarchy. |
mario@webkit.org | 86390a1 | 2011-01-07 17:34:02 +0000 | [diff] [blame] | 288 | AccessibilityObject* coreObject = core(object); |
mario@webkit.org | 868b5ea | 2011-06-24 09:06:32 +0000 | [diff] [blame] | 289 | if (!coreObject) |
| 290 | return 0; |
| 291 | |
mario@webkit.org | 86390a1 | 2011-01-07 17:34:02 +0000 | [diff] [blame] | 292 | AccessibilityObject* coreParent = coreObject->parentObjectUnignored(); |
mario@webkit.org | 868b5ea | 2011-06-24 09:06:32 +0000 | [diff] [blame] | 293 | |
mario@webkit.org | 86390a1 | 2011-01-07 17:34:02 +0000 | [diff] [blame] | 294 | if (!coreParent && isRootObject(coreObject)) |
| 295 | return atkParentOfRootObject(object); |
eric@webkit.org | 1f5f7fe | 2009-11-04 10:35:56 +0000 | [diff] [blame] | 296 | |
| 297 | if (!coreParent) |
| 298 | return 0; |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 299 | |
mario@webkit.org | 8c5dd90 | 2012-11-09 19:47:40 +0000 | [diff] [blame] | 300 | // We don't expose table rows to Assistive technologies, but we |
mario@webkit.org | 868b5ea | 2011-06-24 09:06:32 +0000 | [diff] [blame] | 301 | // need to have them anyway in the hierarchy from WebCore to |
| 302 | // properly perform coordinates calculations when requested. |
| 303 | if (coreParent->isTableRow() && coreObject->isTableCell()) |
| 304 | coreParent = coreParent->parentObjectUnignored(); |
| 305 | |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 306 | return coreParent->wrapper(); |
| 307 | } |
| 308 | |
mario@webkit.org | 868b5ea | 2011-06-24 09:06:32 +0000 | [diff] [blame] | 309 | static gint getNChildrenForTable(AccessibilityObject* coreObject) |
| 310 | { |
| 311 | AccessibilityObject::AccessibilityChildrenVector tableChildren = coreObject->children(); |
| 312 | size_t tableChildrenCount = tableChildren.size(); |
| 313 | size_t cellsCount = 0; |
| 314 | |
| 315 | // Look for the actual index of the cell inside the table. |
| 316 | for (unsigned i = 0; i < tableChildrenCount; ++i) { |
| 317 | if (tableChildren[i]->isTableRow()) { |
| 318 | AccessibilityObject::AccessibilityChildrenVector rowChildren = tableChildren[i]->children(); |
| 319 | cellsCount += rowChildren.size(); |
| 320 | } else |
| 321 | cellsCount++; |
| 322 | } |
| 323 | |
| 324 | return cellsCount; |
| 325 | } |
| 326 | |
mario@webkit.org | 5c96677 | 2012-01-24 18:48:50 +0000 | [diff] [blame] | 327 | static gint webkitAccessibleGetNChildren(AtkObject* object) |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 328 | { |
mario@webkit.org | 868b5ea | 2011-06-24 09:06:32 +0000 | [diff] [blame] | 329 | AccessibilityObject* coreObject = core(object); |
| 330 | |
| 331 | // Tables should be treated in a different way because rows should |
mario@webkit.org | 8c5dd90 | 2012-11-09 19:47:40 +0000 | [diff] [blame] | 332 | // be bypassed when exposing the accessible hierarchy. |
mario@webkit.org | 868b5ea | 2011-06-24 09:06:32 +0000 | [diff] [blame] | 333 | if (coreObject->isAccessibilityTable()) |
| 334 | return getNChildrenForTable(coreObject); |
| 335 | |
| 336 | return coreObject->children().size(); |
| 337 | } |
| 338 | |
| 339 | static AccessibilityObject* getChildForTable(AccessibilityObject* coreObject, gint index) |
| 340 | { |
| 341 | AccessibilityObject::AccessibilityChildrenVector tableChildren = coreObject->children(); |
| 342 | size_t tableChildrenCount = tableChildren.size(); |
| 343 | size_t cellsCount = 0; |
mario@webkit.org | 868b5ea | 2011-06-24 09:06:32 +0000 | [diff] [blame] | 344 | |
| 345 | // Look for the actual index of the cell inside the table. |
| 346 | size_t current = static_cast<size_t>(index); |
| 347 | for (unsigned i = 0; i < tableChildrenCount; ++i) { |
| 348 | if (tableChildren[i]->isTableRow()) { |
| 349 | AccessibilityObject::AccessibilityChildrenVector rowChildren = tableChildren[i]->children(); |
| 350 | size_t rowChildrenCount = rowChildren.size(); |
| 351 | if (current < cellsCount + rowChildrenCount) |
| 352 | return rowChildren.at(current - cellsCount).get(); |
| 353 | cellsCount += rowChildrenCount; |
| 354 | } else if (cellsCount == current) |
| 355 | return tableChildren[i].get(); |
| 356 | else |
| 357 | cellsCount++; |
| 358 | } |
| 359 | |
| 360 | // Shouldn't reach if the child was found. |
| 361 | return 0; |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 362 | } |
| 363 | |
mario@webkit.org | 5c96677 | 2012-01-24 18:48:50 +0000 | [diff] [blame] | 364 | static AtkObject* webkitAccessibleRefChild(AtkObject* object, gint index) |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 365 | { |
mario@webkit.org | 868b5ea | 2011-06-24 09:06:32 +0000 | [diff] [blame] | 366 | if (index < 0) |
eric@webkit.org | dbd4d40 | 2009-11-04 09:31:06 +0000 | [diff] [blame] | 367 | return 0; |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 368 | |
mario@webkit.org | 868b5ea | 2011-06-24 09:06:32 +0000 | [diff] [blame] | 369 | AccessibilityObject* coreObject = core(object); |
| 370 | AccessibilityObject* coreChild = 0; |
| 371 | |
mario@webkit.org | 8c5dd90 | 2012-11-09 19:47:40 +0000 | [diff] [blame] | 372 | // Tables are special cases because rows should be bypassed, but |
| 373 | // still taking their cells into account. |
mario@webkit.org | 868b5ea | 2011-06-24 09:06:32 +0000 | [diff] [blame] | 374 | if (coreObject->isAccessibilityTable()) |
| 375 | coreChild = getChildForTable(coreObject, index); |
| 376 | else { |
| 377 | AccessibilityObject::AccessibilityChildrenVector children = coreObject->children(); |
| 378 | if (static_cast<unsigned>(index) >= children.size()) |
| 379 | return 0; |
| 380 | coreChild = children.at(index).get(); |
| 381 | } |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 382 | |
| 383 | if (!coreChild) |
eric@webkit.org | 4ff6fd7 | 2009-11-10 09:53:33 +0000 | [diff] [blame] | 384 | return 0; |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 385 | |
| 386 | AtkObject* child = coreChild->wrapper(); |
eric@webkit.org | b84b474 | 2009-10-20 21:20:50 +0000 | [diff] [blame] | 387 | atk_object_set_parent(child, object); |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 388 | g_object_ref(child); |
| 389 | |
| 390 | return child; |
| 391 | } |
| 392 | |
mario@webkit.org | 868b5ea | 2011-06-24 09:06:32 +0000 | [diff] [blame] | 393 | static gint getIndexInParentForCellInRow(AccessibilityObject* coreObject) |
| 394 | { |
| 395 | AccessibilityObject* parent = coreObject->parentObjectUnignored(); |
| 396 | if (!parent) |
| 397 | return -1; |
| 398 | |
| 399 | AccessibilityObject* grandParent = parent->parentObjectUnignored(); |
| 400 | if (!grandParent) |
| 401 | return -1; |
| 402 | |
| 403 | AccessibilityObject::AccessibilityChildrenVector rows = grandParent->children(); |
| 404 | size_t rowsCount = rows.size(); |
| 405 | size_t previousCellsCount = 0; |
| 406 | |
| 407 | // Look for the actual index of the cell inside the table. |
| 408 | for (unsigned i = 0; i < rowsCount; ++i) { |
| 409 | if (!rows[i]->isTableRow()) |
| 410 | continue; |
| 411 | |
| 412 | AccessibilityObject::AccessibilityChildrenVector cells = rows[i]->children(); |
| 413 | size_t cellsCount = cells.size(); |
| 414 | |
| 415 | if (rows[i] == parent) { |
| 416 | for (unsigned j = 0; j < cellsCount; ++j) { |
| 417 | if (cells[j] == coreObject) |
| 418 | return previousCellsCount + j; |
| 419 | } |
| 420 | } |
| 421 | |
| 422 | previousCellsCount += cellsCount; |
| 423 | } |
| 424 | |
| 425 | return -1; |
| 426 | } |
| 427 | |
mario@webkit.org | 5c96677 | 2012-01-24 18:48:50 +0000 | [diff] [blame] | 428 | static gint webkitAccessibleGetIndexInParent(AtkObject* object) |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 429 | { |
xan@webkit.org | 1f5349a | 2009-10-27 09:20:21 +0000 | [diff] [blame] | 430 | AccessibilityObject* coreObject = core(object); |
| 431 | AccessibilityObject* parent = coreObject->parentObjectUnignored(); |
| 432 | |
mario@webkit.org | 86390a1 | 2011-01-07 17:34:02 +0000 | [diff] [blame] | 433 | if (!parent && isRootObject(coreObject)) { |
| 434 | AtkObject* atkParent = atkParentOfRootObject(object); |
eric@webkit.org | 1f5f7fe | 2009-11-04 10:35:56 +0000 | [diff] [blame] | 435 | if (!atkParent) |
| 436 | return -1; |
| 437 | |
| 438 | unsigned count = atk_object_get_n_accessible_children(atkParent); |
| 439 | for (unsigned i = 0; i < count; ++i) { |
| 440 | AtkObject* child = atk_object_ref_accessible_child(atkParent, i); |
| 441 | bool childIsObject = child == object; |
| 442 | g_object_unref(child); |
| 443 | if (childIsObject) |
| 444 | return i; |
| 445 | } |
| 446 | } |
xan@webkit.org | 1f5349a | 2009-10-27 09:20:21 +0000 | [diff] [blame] | 447 | |
mario@webkit.org | 868b5ea | 2011-06-24 09:06:32 +0000 | [diff] [blame] | 448 | // Need to calculate the index of the cell in the table, as |
mario@webkit.org | 8c5dd90 | 2012-11-09 19:47:40 +0000 | [diff] [blame] | 449 | // rows won't be exposed to assistive technologies. |
mario@webkit.org | 868b5ea | 2011-06-24 09:06:32 +0000 | [diff] [blame] | 450 | if (parent && parent->isTableRow() && coreObject->isTableCell()) |
| 451 | return getIndexInParentForCellInRow(coreObject); |
| 452 | |
commit-queue@webkit.org | 54a624e | 2013-01-16 18:00:17 +0000 | [diff] [blame] | 453 | if (!parent) |
| 454 | return -1; |
| 455 | |
commit-queue@webkit.org | bf18355 | 2012-02-22 09:28:57 +0000 | [diff] [blame] | 456 | size_t index = parent->children().find(coreObject); |
| 457 | return (index == WTF::notFound) ? -1 : index; |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 458 | } |
| 459 | |
mario@webkit.org | 5c96677 | 2012-01-24 18:48:50 +0000 | [diff] [blame] | 460 | static AtkAttributeSet* webkitAccessibleGetAttributes(AtkObject* object) |
eric@webkit.org | 8449619 | 2009-10-17 20:00:33 +0000 | [diff] [blame] | 461 | { |
eric@webkit.org | 4ff6fd7 | 2009-11-10 09:53:33 +0000 | [diff] [blame] | 462 | AtkAttributeSet* attributeSet = 0; |
mario@webkit.org | 8c5dd90 | 2012-11-09 19:47:40 +0000 | [diff] [blame] | 463 | #if PLATFORM(GTK) |
mario@webkit.org | f8344ff | 2012-01-24 11:40:44 +0000 | [diff] [blame] | 464 | attributeSet = addToAtkAttributeSet(attributeSet, "toolkit", "WebKitGtk"); |
commit-queue@webkit.org | d994735 | 2012-12-05 17:56:12 +0000 | [diff] [blame] | 465 | #elif PLATFORM(EFL) |
| 466 | attributeSet = addToAtkAttributeSet(attributeSet, "toolkit", "WebKitEfl"); |
mario@webkit.org | 8c5dd90 | 2012-11-09 19:47:40 +0000 | [diff] [blame] | 467 | #endif |
eric@webkit.org | f4efc40 | 2010-05-15 09:55:52 +0000 | [diff] [blame] | 468 | |
commit-queue@webkit.org | a9398dd | 2010-10-26 19:19:29 +0000 | [diff] [blame] | 469 | AccessibilityObject* coreObject = core(object); |
| 470 | if (!coreObject) |
| 471 | return attributeSet; |
| 472 | |
commit-queue@webkit.org | 357dc22 | 2013-01-10 00:09:41 +0000 | [diff] [blame] | 473 | // Hack needed for WebKit2 tests because obtaining an element by its ID |
| 474 | // cannot be done from the UIProcess. Assistive technologies have no need |
| 475 | // for this information. |
| 476 | Node* node = coreObject->node(); |
| 477 | if (node && node->isElementNode()) { |
| 478 | String id = toElement(node)->getIdAttribute().string(); |
| 479 | if (!id.isEmpty()) |
| 480 | attributeSet = addToAtkAttributeSet(attributeSet, "html-id", id.utf8().data()); |
| 481 | } |
| 482 | |
commit-queue@webkit.org | a9398dd | 2010-10-26 19:19:29 +0000 | [diff] [blame] | 483 | int headingLevel = coreObject->headingLevel(); |
eric@webkit.org | 8449619 | 2009-10-17 20:00:33 +0000 | [diff] [blame] | 484 | if (headingLevel) { |
| 485 | String value = String::number(headingLevel); |
mario@webkit.org | f8344ff | 2012-01-24 11:40:44 +0000 | [diff] [blame] | 486 | attributeSet = addToAtkAttributeSet(attributeSet, "level", value.utf8().data()); |
eric@webkit.org | 8449619 | 2009-10-17 20:00:33 +0000 | [diff] [blame] | 487 | } |
commit-queue@webkit.org | a9398dd | 2010-10-26 19:19:29 +0000 | [diff] [blame] | 488 | |
| 489 | // Set the 'layout-guess' attribute to help Assistive |
| 490 | // Technologies know when an exposed table is not data table. |
| 491 | if (coreObject->isAccessibilityTable() && !coreObject->isDataTable()) |
mario@webkit.org | f8344ff | 2012-01-24 11:40:44 +0000 | [diff] [blame] | 492 | attributeSet = addToAtkAttributeSet(attributeSet, "layout-guess", "true"); |
commit-queue@webkit.org | a9398dd | 2010-10-26 19:19:29 +0000 | [diff] [blame] | 493 | |
commit-queue@webkit.org | 2db4aaa | 2012-12-10 01:09:32 +0000 | [diff] [blame] | 494 | String placeholder = coreObject->placeholderValue(); |
| 495 | if (!placeholder.isEmpty()) |
| 496 | attributeSet = addToAtkAttributeSet(attributeSet, "placeholder-text", placeholder.utf8().data()); |
| 497 | |
commit-queue@webkit.org | 5945f76 | 2013-07-16 12:55:56 +0000 | [diff] [blame] | 498 | if (coreObject->ariaHasPopup()) |
| 499 | attributeSet = addToAtkAttributeSet(attributeSet, "aria-haspopup", "true"); |
| 500 | |
commit-queue@webkit.org | e084cca | 2013-09-02 15:44:30 +0000 | [diff] [blame] | 501 | String invalidStatus = coreObject->invalidStatus().string(); |
| 502 | if (!invalidStatus.isEmpty() && invalidStatus != "false") |
| 503 | attributeSet = addToAtkAttributeSet(attributeSet, "aria-invalid", coreObject->invalidStatus().string().utf8().data()); |
| 504 | |
commit-queue@webkit.org | 88d00b6 | 2013-09-03 11:29:33 +0000 | [diff] [blame] | 505 | String helpText = coreObject->helpText(); |
| 506 | if (!helpText.isEmpty()) |
| 507 | attributeSet = addToAtkAttributeSet(attributeSet, "aria-help", helpText.utf8().data()); |
| 508 | |
| 509 | const char* sortDescription = "AXUnknownSortDirection"; |
| 510 | AccessibilitySortDirection sortDirection = coreObject->sortDirection(); |
| 511 | if (sortDirection == SortDirectionAscending) |
| 512 | sortDescription = "AXAscendingSortDirection"; |
| 513 | else if (sortDirection == SortDirectionDescending) |
| 514 | sortDescription = "AXDescendingSortDirection"; |
| 515 | |
| 516 | attributeSet = addToAtkAttributeSet(attributeSet, "aria-sort", sortDescription); |
| 517 | |
eric@webkit.org | 8449619 | 2009-10-17 20:00:33 +0000 | [diff] [blame] | 518 | return attributeSet; |
| 519 | } |
| 520 | |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 521 | static AtkRole atkRole(AccessibilityRole role) |
| 522 | { |
| 523 | switch (role) { |
xan@webkit.org | 0ea2f73 | 2009-04-27 21:56:05 +0000 | [diff] [blame] | 524 | case UnknownRole: |
| 525 | return ATK_ROLE_UNKNOWN; |
| 526 | case ButtonRole: |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 527 | return ATK_ROLE_PUSH_BUTTON; |
commit-queue@webkit.org | 6152cb9 | 2012-08-23 00:36:06 +0000 | [diff] [blame] | 528 | case ToggleButtonRole: |
| 529 | return ATK_ROLE_TOGGLE_BUTTON; |
xan@webkit.org | 0ea2f73 | 2009-04-27 21:56:05 +0000 | [diff] [blame] | 530 | case RadioButtonRole: |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 531 | return ATK_ROLE_RADIO_BUTTON; |
xan@webkit.org | 0ea2f73 | 2009-04-27 21:56:05 +0000 | [diff] [blame] | 532 | case CheckBoxRole: |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 533 | return ATK_ROLE_CHECK_BOX; |
xan@webkit.org | 0ea2f73 | 2009-04-27 21:56:05 +0000 | [diff] [blame] | 534 | case SliderRole: |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 535 | return ATK_ROLE_SLIDER; |
xan@webkit.org | 0ea2f73 | 2009-04-27 21:56:05 +0000 | [diff] [blame] | 536 | case TabGroupRole: |
commit-queue@webkit.org | 5255389 | 2012-12-13 15:43:38 +0000 | [diff] [blame] | 537 | case TabListRole: |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 538 | return ATK_ROLE_PAGE_TAB_LIST; |
xan@webkit.org | 0ea2f73 | 2009-04-27 21:56:05 +0000 | [diff] [blame] | 539 | case TextFieldRole: |
| 540 | case TextAreaRole: |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 541 | return ATK_ROLE_ENTRY; |
xan@webkit.org | 0ea2f73 | 2009-04-27 21:56:05 +0000 | [diff] [blame] | 542 | case StaticTextRole: |
| 543 | return ATK_ROLE_TEXT; |
| 544 | case OutlineRole: |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 545 | return ATK_ROLE_TREE; |
xan@webkit.org | 0ea2f73 | 2009-04-27 21:56:05 +0000 | [diff] [blame] | 546 | case MenuBarRole: |
| 547 | return ATK_ROLE_MENU_BAR; |
eric@webkit.org | a066929 | 2010-04-22 14:36:19 +0000 | [diff] [blame] | 548 | case MenuListPopupRole: |
xan@webkit.org | 0ea2f73 | 2009-04-27 21:56:05 +0000 | [diff] [blame] | 549 | case MenuRole: |
| 550 | return ATK_ROLE_MENU; |
eric@webkit.org | a066929 | 2010-04-22 14:36:19 +0000 | [diff] [blame] | 551 | case MenuListOptionRole: |
xan@webkit.org | 0ea2f73 | 2009-04-27 21:56:05 +0000 | [diff] [blame] | 552 | case MenuItemRole: |
| 553 | return ATK_ROLE_MENU_ITEM; |
| 554 | case ColumnRole: |
mario@webkit.org | 9adab66 | 2012-01-23 10:21:03 +0000 | [diff] [blame] | 555 | // return ATK_ROLE_TABLE_COLUMN_HEADER; // Is this right? |
xan@webkit.org | 0ea2f73 | 2009-04-27 21:56:05 +0000 | [diff] [blame] | 556 | return ATK_ROLE_UNKNOWN; // Matches Mozilla |
| 557 | case RowRole: |
mario@webkit.org | 9adab66 | 2012-01-23 10:21:03 +0000 | [diff] [blame] | 558 | // return ATK_ROLE_TABLE_ROW_HEADER; // Is this right? |
xan@webkit.org | 0ea2f73 | 2009-04-27 21:56:05 +0000 | [diff] [blame] | 559 | return ATK_ROLE_LIST_ITEM; // Matches Mozilla |
| 560 | case ToolbarRole: |
| 561 | return ATK_ROLE_TOOL_BAR; |
| 562 | case BusyIndicatorRole: |
| 563 | return ATK_ROLE_PROGRESS_BAR; // Is this right? |
| 564 | case ProgressIndicatorRole: |
mario@webkit.org | 9adab66 | 2012-01-23 10:21:03 +0000 | [diff] [blame] | 565 | // return ATK_ROLE_SPIN_BUTTON; // Some confusion about this role in AccessibilityRenderObject.cpp |
xan@webkit.org | 0ea2f73 | 2009-04-27 21:56:05 +0000 | [diff] [blame] | 566 | return ATK_ROLE_PROGRESS_BAR; |
| 567 | case WindowRole: |
| 568 | return ATK_ROLE_WINDOW; |
eric@webkit.org | a066929 | 2010-04-22 14:36:19 +0000 | [diff] [blame] | 569 | case PopUpButtonRole: |
xan@webkit.org | 0ea2f73 | 2009-04-27 21:56:05 +0000 | [diff] [blame] | 570 | case ComboBoxRole: |
| 571 | return ATK_ROLE_COMBO_BOX; |
| 572 | case SplitGroupRole: |
| 573 | return ATK_ROLE_SPLIT_PANE; |
| 574 | case SplitterRole: |
dmazzoni@google.com | f3cf2c4 | 2012-09-07 23:46:45 +0000 | [diff] [blame] | 575 | return ATK_ROLE_UNKNOWN; |
xan@webkit.org | 0ea2f73 | 2009-04-27 21:56:05 +0000 | [diff] [blame] | 576 | case ColorWellRole: |
| 577 | return ATK_ROLE_COLOR_CHOOSER; |
| 578 | case ListRole: |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 579 | return ATK_ROLE_LIST; |
xan@webkit.org | 0ea2f73 | 2009-04-27 21:56:05 +0000 | [diff] [blame] | 580 | case ScrollBarRole: |
| 581 | return ATK_ROLE_SCROLL_BAR; |
mario@webkit.org | 86390a1 | 2011-01-07 17:34:02 +0000 | [diff] [blame] | 582 | case ScrollAreaRole: |
| 583 | return ATK_ROLE_SCROLL_PANE; |
commit-queue@webkit.org | 777f3cc | 2011-04-01 18:05:04 +0000 | [diff] [blame] | 584 | case GridRole: // Is this right? |
xan@webkit.org | 0ea2f73 | 2009-04-27 21:56:05 +0000 | [diff] [blame] | 585 | case TableRole: |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 586 | return ATK_ROLE_TABLE; |
xan@webkit.org | 0ea2f73 | 2009-04-27 21:56:05 +0000 | [diff] [blame] | 587 | case ApplicationRole: |
| 588 | return ATK_ROLE_APPLICATION; |
xan@webkit.org | 0ea2f73 | 2009-04-27 21:56:05 +0000 | [diff] [blame] | 589 | case GroupRole: |
| 590 | case RadioGroupRole: |
commit-queue@webkit.org | 5255389 | 2012-12-13 15:43:38 +0000 | [diff] [blame] | 591 | case TabPanelRole: |
xan@webkit.org | 0ea2f73 | 2009-04-27 21:56:05 +0000 | [diff] [blame] | 592 | return ATK_ROLE_PANEL; |
mario@webkit.org | 47a021b | 2011-04-11 17:39:11 +0000 | [diff] [blame] | 593 | case RowHeaderRole: // Row headers are cells after all. |
| 594 | case ColumnHeaderRole: // Column headers are cells after all. |
xan@webkit.org | 0ea2f73 | 2009-04-27 21:56:05 +0000 | [diff] [blame] | 595 | case CellRole: |
| 596 | return ATK_ROLE_TABLE_CELL; |
| 597 | case LinkRole: |
| 598 | case WebCoreLinkRole: |
| 599 | case ImageMapLinkRole: |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 600 | return ATK_ROLE_LINK; |
xan@webkit.org | 0ea2f73 | 2009-04-27 21:56:05 +0000 | [diff] [blame] | 601 | case ImageMapRole: |
| 602 | case ImageRole: |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 603 | return ATK_ROLE_IMAGE; |
xan@webkit.org | 0ea2f73 | 2009-04-27 21:56:05 +0000 | [diff] [blame] | 604 | case ListMarkerRole: |
jmalonzo@webkit.org | ad9783b | 2009-05-23 22:22:52 +0000 | [diff] [blame] | 605 | return ATK_ROLE_TEXT; |
xan@webkit.org | 0ea2f73 | 2009-04-27 21:56:05 +0000 | [diff] [blame] | 606 | case WebAreaRole: |
mario@webkit.org | 9adab66 | 2012-01-23 10:21:03 +0000 | [diff] [blame] | 607 | // return ATK_ROLE_HTML_CONTAINER; // Is this right? |
xan@webkit.org | 0ea2f73 | 2009-04-27 21:56:05 +0000 | [diff] [blame] | 608 | return ATK_ROLE_DOCUMENT_FRAME; |
| 609 | case HeadingRole: |
| 610 | return ATK_ROLE_HEADING; |
| 611 | case ListBoxRole: |
| 612 | return ATK_ROLE_LIST; |
cfleizach@apple.com | 432ee57 | 2010-06-15 06:17:18 +0000 | [diff] [blame] | 613 | case ListItemRole: |
xan@webkit.org | 0ea2f73 | 2009-04-27 21:56:05 +0000 | [diff] [blame] | 614 | case ListBoxOptionRole: |
| 615 | return ATK_ROLE_LIST_ITEM; |
mario@webkit.org | 56f6bf2 | 2011-03-30 16:51:08 +0000 | [diff] [blame] | 616 | case ParagraphRole: |
| 617 | return ATK_ROLE_PARAGRAPH; |
| 618 | case LabelRole: |
commit-queue@webkit.org | 802c012 | 2012-09-11 01:41:27 +0000 | [diff] [blame] | 619 | case LegendRole: |
mario@webkit.org | 56f6bf2 | 2011-03-30 16:51:08 +0000 | [diff] [blame] | 620 | return ATK_ROLE_LABEL; |
| 621 | case DivRole: |
| 622 | return ATK_ROLE_SECTION; |
| 623 | case FormRole: |
| 624 | return ATK_ROLE_FORM; |
commit-queue@webkit.org | 52f6761 | 2012-09-07 05:09:04 +0000 | [diff] [blame] | 625 | case CanvasRole: |
| 626 | return ATK_ROLE_CANVAS; |
dmazzoni@google.com | f3cf2c4 | 2012-09-07 23:46:45 +0000 | [diff] [blame] | 627 | case HorizontalRuleRole: |
| 628 | return ATK_ROLE_SEPARATOR; |
commit-queue@webkit.org | c985400e | 2012-09-21 20:03:57 +0000 | [diff] [blame] | 629 | case SpinButtonRole: |
| 630 | return ATK_ROLE_SPIN_BUTTON; |
commit-queue@webkit.org | 5255389 | 2012-12-13 15:43:38 +0000 | [diff] [blame] | 631 | case TabRole: |
| 632 | return ATK_ROLE_PAGE_TAB; |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 633 | default: |
| 634 | return ATK_ROLE_UNKNOWN; |
| 635 | } |
| 636 | } |
| 637 | |
mario@webkit.org | 5c96677 | 2012-01-24 18:48:50 +0000 | [diff] [blame] | 638 | static AtkRole webkitAccessibleGetRole(AtkObject* object) |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 639 | { |
mario@webkit.org | 56f6bf2 | 2011-03-30 16:51:08 +0000 | [diff] [blame] | 640 | AccessibilityObject* coreObject = core(object); |
jmalonzo@webkit.org | 7ce3714 | 2009-05-20 11:16:01 +0000 | [diff] [blame] | 641 | |
mario@webkit.org | 56f6bf2 | 2011-03-30 16:51:08 +0000 | [diff] [blame] | 642 | if (!coreObject) |
jmalonzo@webkit.org | 7ce3714 | 2009-05-20 11:16:01 +0000 | [diff] [blame] | 643 | return ATK_ROLE_UNKNOWN; |
| 644 | |
| 645 | // Note: Why doesn't WebCore have a password field for this |
mario@webkit.org | 56f6bf2 | 2011-03-30 16:51:08 +0000 | [diff] [blame] | 646 | if (coreObject->isPasswordField()) |
jmalonzo@webkit.org | 7ce3714 | 2009-05-20 11:16:01 +0000 | [diff] [blame] | 647 | return ATK_ROLE_PASSWORD_TEXT; |
| 648 | |
mario@webkit.org | 56f6bf2 | 2011-03-30 16:51:08 +0000 | [diff] [blame] | 649 | return atkRole(coreObject->roleValue()); |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 650 | } |
| 651 | |
mario@webkit.org | 6a24ba1 | 2010-12-14 15:35:22 +0000 | [diff] [blame] | 652 | static bool isTextWithCaret(AccessibilityObject* coreObject) |
| 653 | { |
| 654 | if (!coreObject || !coreObject->isAccessibilityRenderObject()) |
| 655 | return false; |
| 656 | |
| 657 | Document* document = coreObject->document(); |
| 658 | if (!document) |
| 659 | return false; |
| 660 | |
| 661 | Frame* frame = document->frame(); |
| 662 | if (!frame) |
| 663 | return false; |
| 664 | |
akling@apple.com | 1752350 | 2013-08-17 10:58:40 +0000 | [diff] [blame] | 665 | if (!frame->settings().caretBrowsingEnabled()) |
mario@webkit.org | 6a24ba1 | 2010-12-14 15:35:22 +0000 | [diff] [blame] | 666 | return false; |
| 667 | |
| 668 | // Check text objects and paragraphs only. |
| 669 | AtkObject* axObject = coreObject->wrapper(); |
| 670 | AtkRole role = axObject ? atk_object_get_role(axObject) : ATK_ROLE_INVALID; |
| 671 | if (role != ATK_ROLE_TEXT && role != ATK_ROLE_PARAGRAPH) |
| 672 | return false; |
| 673 | |
| 674 | // Finally, check whether the caret is set in the current object. |
| 675 | VisibleSelection selection = coreObject->selection(); |
| 676 | if (!selection.isCaret()) |
| 677 | return false; |
| 678 | |
| 679 | return selectionBelongsToObject(coreObject, selection); |
| 680 | } |
| 681 | |
xan@webkit.org | 8be15d6 | 2009-04-09 11:20:57 +0000 | [diff] [blame] | 682 | static void setAtkStateSetFromCoreObject(AccessibilityObject* coreObject, AtkStateSet* stateSet) |
| 683 | { |
eric@webkit.org | 2dd4734 | 2009-10-26 11:42:42 +0000 | [diff] [blame] | 684 | AccessibilityObject* parent = coreObject->parentObject(); |
| 685 | bool isListBoxOption = parent && parent->isListBox(); |
xan@webkit.org | 8be15d6 | 2009-04-09 11:20:57 +0000 | [diff] [blame] | 686 | |
eric@webkit.org | 2dd4734 | 2009-10-26 11:42:42 +0000 | [diff] [blame] | 687 | // Please keep the state list in alphabetical order |
xan@webkit.org | 8be15d6 | 2009-04-09 11:20:57 +0000 | [diff] [blame] | 688 | if (coreObject->isChecked()) |
| 689 | atk_state_set_add_state(stateSet, ATK_STATE_CHECKED); |
| 690 | |
xan@webkit.org | df7d13a | 2009-06-26 09:12:44 +0000 | [diff] [blame] | 691 | // FIXME: isReadOnly does not seem to do the right thing for |
eric@webkit.org | 2dd4734 | 2009-10-26 11:42:42 +0000 | [diff] [blame] | 692 | // controls, so check explicitly for them. In addition, because |
| 693 | // isReadOnly is false for listBoxOptions, we need to add one |
| 694 | // more check so that we do not present them as being "editable". |
mario@webkit.org | 9adab66 | 2012-01-23 10:21:03 +0000 | [diff] [blame] | 695 | if ((!coreObject->isReadOnly() |
mario@webkit.org | f88ffcb | 2012-11-16 13:47:03 +0000 | [diff] [blame] | 696 | || (coreObject->isControl() && coreObject->canSetValueAttribute())) |
mario@webkit.org | 9adab66 | 2012-01-23 10:21:03 +0000 | [diff] [blame] | 697 | && !isListBoxOption) |
xan@webkit.org | 8be15d6 | 2009-04-09 11:20:57 +0000 | [diff] [blame] | 698 | atk_state_set_add_state(stateSet, ATK_STATE_EDITABLE); |
| 699 | |
xan@webkit.org | df7d13a | 2009-06-26 09:12:44 +0000 | [diff] [blame] | 700 | // FIXME: Put both ENABLED and SENSITIVE together here for now |
| 701 | if (coreObject->isEnabled()) { |
xan@webkit.org | 8be15d6 | 2009-04-09 11:20:57 +0000 | [diff] [blame] | 702 | atk_state_set_add_state(stateSet, ATK_STATE_ENABLED); |
xan@webkit.org | df7d13a | 2009-06-26 09:12:44 +0000 | [diff] [blame] | 703 | atk_state_set_add_state(stateSet, ATK_STATE_SENSITIVE); |
| 704 | } |
xan@webkit.org | 8be15d6 | 2009-04-09 11:20:57 +0000 | [diff] [blame] | 705 | |
mario@webkit.org | 8ce6a15 | 2010-11-30 21:16:14 +0000 | [diff] [blame] | 706 | if (coreObject->canSetExpandedAttribute()) |
| 707 | atk_state_set_add_state(stateSet, ATK_STATE_EXPANDABLE); |
| 708 | |
| 709 | if (coreObject->isExpanded()) |
| 710 | atk_state_set_add_state(stateSet, ATK_STATE_EXPANDED); |
| 711 | |
xan@webkit.org | 8be15d6 | 2009-04-09 11:20:57 +0000 | [diff] [blame] | 712 | if (coreObject->canSetFocusAttribute()) |
| 713 | atk_state_set_add_state(stateSet, ATK_STATE_FOCUSABLE); |
| 714 | |
mario@webkit.org | 6a24ba1 | 2010-12-14 15:35:22 +0000 | [diff] [blame] | 715 | if (coreObject->isFocused() || isTextWithCaret(coreObject)) |
xan@webkit.org | 8be15d6 | 2009-04-09 11:20:57 +0000 | [diff] [blame] | 716 | atk_state_set_add_state(stateSet, ATK_STATE_FOCUSED); |
| 717 | |
commit-queue@webkit.org | 471dff5 | 2013-03-20 08:12:15 +0000 | [diff] [blame] | 718 | if (coreObject->orientation() == AccessibilityOrientationHorizontal) |
| 719 | atk_state_set_add_state(stateSet, ATK_STATE_HORIZONTAL); |
| 720 | else if (coreObject->orientation() == AccessibilityOrientationVertical) |
| 721 | atk_state_set_add_state(stateSet, ATK_STATE_VERTICAL); |
xan@webkit.org | 8be15d6 | 2009-04-09 11:20:57 +0000 | [diff] [blame] | 722 | |
| 723 | if (coreObject->isIndeterminate()) |
| 724 | atk_state_set_add_state(stateSet, ATK_STATE_INDETERMINATE); |
| 725 | |
jhoneycutt@apple.com | 8acea08 | 2010-01-14 01:16:15 +0000 | [diff] [blame] | 726 | if (coreObject->isMultiSelectable()) |
xan@webkit.org | 8be15d6 | 2009-04-09 11:20:57 +0000 | [diff] [blame] | 727 | atk_state_set_add_state(stateSet, ATK_STATE_MULTISELECTABLE); |
| 728 | |
| 729 | // TODO: ATK_STATE_OPAQUE |
| 730 | |
| 731 | if (coreObject->isPressed()) |
| 732 | atk_state_set_add_state(stateSet, ATK_STATE_PRESSED); |
| 733 | |
commit-queue@webkit.org | 60f8d31 | 2013-06-21 10:33:34 +0000 | [diff] [blame] | 734 | if (coreObject->isRequired()) |
| 735 | atk_state_set_add_state(stateSet, ATK_STATE_REQUIRED); |
| 736 | |
xan@webkit.org | 8be15d6 | 2009-04-09 11:20:57 +0000 | [diff] [blame] | 737 | // TODO: ATK_STATE_SELECTABLE_TEXT |
| 738 | |
eric@webkit.org | 2dd4734 | 2009-10-26 11:42:42 +0000 | [diff] [blame] | 739 | if (coreObject->canSetSelectedAttribute()) { |
| 740 | atk_state_set_add_state(stateSet, ATK_STATE_SELECTABLE); |
mario@webkit.org | 8c5dd90 | 2012-11-09 19:47:40 +0000 | [diff] [blame] | 741 | // Items in focusable lists have both STATE_SELECT{ABLE,ED} |
| 742 | // and STATE_FOCUS{ABLE,ED}. We'll fake the latter based on |
| 743 | // the former. |
eric@webkit.org | 2dd4734 | 2009-10-26 11:42:42 +0000 | [diff] [blame] | 744 | if (isListBoxOption) |
| 745 | atk_state_set_add_state(stateSet, ATK_STATE_FOCUSABLE); |
| 746 | } |
| 747 | |
| 748 | if (coreObject->isSelected()) { |
xan@webkit.org | 8be15d6 | 2009-04-09 11:20:57 +0000 | [diff] [blame] | 749 | atk_state_set_add_state(stateSet, ATK_STATE_SELECTED); |
mario@webkit.org | 8c5dd90 | 2012-11-09 19:47:40 +0000 | [diff] [blame] | 750 | // Items in focusable lists have both STATE_SELECT{ABLE,ED} |
eric@webkit.org | 2dd4734 | 2009-10-26 11:42:42 +0000 | [diff] [blame] | 751 | // and STATE_FOCUS{ABLE,ED}. We'll fake the latter based on the |
| 752 | // former. |
| 753 | if (isListBoxOption) |
| 754 | atk_state_set_add_state(stateSet, ATK_STATE_FOCUSED); |
| 755 | } |
xan@webkit.org | 8be15d6 | 2009-04-09 11:20:57 +0000 | [diff] [blame] | 756 | |
xan@webkit.org | df7d13a | 2009-06-26 09:12:44 +0000 | [diff] [blame] | 757 | // FIXME: Group both SHOWING and VISIBLE here for now |
| 758 | // Not sure how to handle this in WebKit, see bug |
| 759 | // http://bugzilla.gnome.org/show_bug.cgi?id=509650 for other |
mario@webkit.org | 8c5dd90 | 2012-11-09 19:47:40 +0000 | [diff] [blame] | 760 | // issues with SHOWING vs VISIBLE. |
xan@webkit.org | df7d13a | 2009-06-26 09:12:44 +0000 | [diff] [blame] | 761 | if (!coreObject->isOffScreen()) { |
xan@webkit.org | 8be15d6 | 2009-04-09 11:20:57 +0000 | [diff] [blame] | 762 | atk_state_set_add_state(stateSet, ATK_STATE_SHOWING); |
xan@webkit.org | df7d13a | 2009-06-26 09:12:44 +0000 | [diff] [blame] | 763 | atk_state_set_add_state(stateSet, ATK_STATE_VISIBLE); |
| 764 | } |
xan@webkit.org | 8be15d6 | 2009-04-09 11:20:57 +0000 | [diff] [blame] | 765 | |
| 766 | // Mutually exclusive, so we group these two |
| 767 | if (coreObject->roleValue() == TextFieldRole) |
| 768 | atk_state_set_add_state(stateSet, ATK_STATE_SINGLE_LINE); |
| 769 | else if (coreObject->roleValue() == TextAreaRole) |
| 770 | atk_state_set_add_state(stateSet, ATK_STATE_MULTI_LINE); |
| 771 | |
| 772 | // TODO: ATK_STATE_SENSITIVE |
| 773 | |
xan@webkit.org | 8be15d6 | 2009-04-09 11:20:57 +0000 | [diff] [blame] | 774 | if (coreObject->isVisited()) |
| 775 | atk_state_set_add_state(stateSet, ATK_STATE_VISITED); |
| 776 | } |
| 777 | |
mario@webkit.org | 5c96677 | 2012-01-24 18:48:50 +0000 | [diff] [blame] | 778 | static AtkStateSet* webkitAccessibleRefStateSet(AtkObject* object) |
xan@webkit.org | 8be15d6 | 2009-04-09 11:20:57 +0000 | [diff] [blame] | 779 | { |
mario@webkit.org | f88ffcb | 2012-11-16 13:47:03 +0000 | [diff] [blame] | 780 | AtkStateSet* stateSet = ATK_OBJECT_CLASS(webkitAccessibleParentClass)->ref_state_set(object); |
xan@webkit.org | 8be15d6 | 2009-04-09 11:20:57 +0000 | [diff] [blame] | 781 | AccessibilityObject* coreObject = core(object); |
| 782 | |
| 783 | if (coreObject == fallbackObject()) { |
| 784 | atk_state_set_add_state(stateSet, ATK_STATE_DEFUNCT); |
| 785 | return stateSet; |
| 786 | } |
| 787 | |
mario@webkit.org | 6a24ba1 | 2010-12-14 15:35:22 +0000 | [diff] [blame] | 788 | // Text objects must be focusable. |
| 789 | AtkRole role = atk_object_get_role(object); |
| 790 | if (role == ATK_ROLE_TEXT || role == ATK_ROLE_PARAGRAPH) |
| 791 | atk_state_set_add_state(stateSet, ATK_STATE_FOCUSABLE); |
xan@webkit.org | 8be15d6 | 2009-04-09 11:20:57 +0000 | [diff] [blame] | 792 | |
mario@webkit.org | 6a24ba1 | 2010-12-14 15:35:22 +0000 | [diff] [blame] | 793 | setAtkStateSetFromCoreObject(coreObject, stateSet); |
xan@webkit.org | 8be15d6 | 2009-04-09 11:20:57 +0000 | [diff] [blame] | 794 | return stateSet; |
| 795 | } |
| 796 | |
mario@webkit.org | 5c96677 | 2012-01-24 18:48:50 +0000 | [diff] [blame] | 797 | static AtkRelationSet* webkitAccessibleRefRelationSet(AtkObject* object) |
eric@webkit.org | 0f6cb45 | 2009-10-22 23:07:56 +0000 | [diff] [blame] | 798 | { |
mario@webkit.org | f88ffcb | 2012-11-16 13:47:03 +0000 | [diff] [blame] | 799 | AtkRelationSet* relationSet = ATK_OBJECT_CLASS(webkitAccessibleParentClass)->ref_relation_set(object); |
eric@webkit.org | 0f6cb45 | 2009-10-22 23:07:56 +0000 | [diff] [blame] | 800 | AccessibilityObject* coreObject = core(object); |
| 801 | |
| 802 | setAtkRelationSetFromCoreObject(coreObject, relationSet); |
| 803 | |
| 804 | return relationSet; |
| 805 | } |
| 806 | |
mario@webkit.org | 5c96677 | 2012-01-24 18:48:50 +0000 | [diff] [blame] | 807 | static void webkitAccessibleInit(AtkObject* object, gpointer data) |
xan@webkit.org | e438710 | 2009-04-09 11:08:48 +0000 | [diff] [blame] | 808 | { |
mario@webkit.org | f88ffcb | 2012-11-16 13:47:03 +0000 | [diff] [blame] | 809 | if (ATK_OBJECT_CLASS(webkitAccessibleParentClass)->initialize) |
| 810 | ATK_OBJECT_CLASS(webkitAccessibleParentClass)->initialize(object, data); |
xan@webkit.org | e438710 | 2009-04-09 11:08:48 +0000 | [diff] [blame] | 811 | |
mario@webkit.org | fecbacd | 2013-03-04 17:06:15 +0000 | [diff] [blame] | 812 | WebKitAccessible* accessible = WEBKIT_ACCESSIBLE(object); |
| 813 | accessible->m_object = reinterpret_cast<AccessibilityObject*>(data); |
| 814 | accessible->priv = WEBKIT_ACCESSIBLE_GET_PRIVATE(accessible); |
xan@webkit.org | e438710 | 2009-04-09 11:08:48 +0000 | [diff] [blame] | 815 | } |
| 816 | |
commit-queue@webkit.org | 120f565 | 2013-06-12 21:39:42 +0000 | [diff] [blame] | 817 | static const gchar* webkitAccessibleGetObjectLocale(AtkObject* object) |
| 818 | { |
| 819 | if (ATK_IS_DOCUMENT(object)) { |
| 820 | AccessibilityObject* coreObject = core(object); |
| 821 | if (!coreObject) |
| 822 | return 0; |
| 823 | |
| 824 | // TODO: Should we fall back on lang xml:lang when the following comes up empty? |
| 825 | String language = coreObject->language(); |
| 826 | if (!language.isEmpty()) |
| 827 | return cacheAndReturnAtkProperty(object, AtkCachedDocumentLocale, language); |
| 828 | |
| 829 | } else if (ATK_IS_TEXT(object)) { |
| 830 | const gchar* locale = 0; |
| 831 | |
| 832 | AtkAttributeSet* textAttributes = atk_text_get_default_attributes(ATK_TEXT(object)); |
commit-queue@webkit.org | 44a695d | 2013-07-04 12:10:45 +0000 | [diff] [blame] | 833 | for (AtkAttributeSet* attributes = textAttributes; attributes; attributes = attributes->next) { |
commit-queue@webkit.org | 120f565 | 2013-06-12 21:39:42 +0000 | [diff] [blame] | 834 | AtkAttribute* atkAttribute = static_cast<AtkAttribute*>(attributes->data); |
| 835 | if (!strcmp(atkAttribute->name, atk_text_attribute_get_name(ATK_TEXT_ATTR_LANGUAGE))) { |
| 836 | locale = cacheAndReturnAtkProperty(object, AtkCachedDocumentLocale, String::fromUTF8(atkAttribute->value)); |
| 837 | break; |
| 838 | } |
| 839 | } |
commit-queue@webkit.org | 120f565 | 2013-06-12 21:39:42 +0000 | [diff] [blame] | 840 | atk_attribute_set_free(textAttributes); |
| 841 | |
| 842 | return locale; |
| 843 | } |
| 844 | |
| 845 | return 0; |
| 846 | } |
| 847 | |
mario@webkit.org | 5c96677 | 2012-01-24 18:48:50 +0000 | [diff] [blame] | 848 | static void webkitAccessibleFinalize(GObject* object) |
xan@webkit.org | e438710 | 2009-04-09 11:08:48 +0000 | [diff] [blame] | 849 | { |
mario@webkit.org | f88ffcb | 2012-11-16 13:47:03 +0000 | [diff] [blame] | 850 | G_OBJECT_CLASS(webkitAccessibleParentClass)->finalize(object); |
xan@webkit.org | e438710 | 2009-04-09 11:08:48 +0000 | [diff] [blame] | 851 | } |
| 852 | |
mario@webkit.org | f88ffcb | 2012-11-16 13:47:03 +0000 | [diff] [blame] | 853 | static void webkitAccessibleClassInit(AtkObjectClass* klass) |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 854 | { |
xan@webkit.org | e438710 | 2009-04-09 11:08:48 +0000 | [diff] [blame] | 855 | GObjectClass* gobjectClass = G_OBJECT_CLASS(klass); |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 856 | |
mario@webkit.org | f88ffcb | 2012-11-16 13:47:03 +0000 | [diff] [blame] | 857 | webkitAccessibleParentClass = g_type_class_peek_parent(klass); |
xan@webkit.org | e438710 | 2009-04-09 11:08:48 +0000 | [diff] [blame] | 858 | |
mario@webkit.org | 5c96677 | 2012-01-24 18:48:50 +0000 | [diff] [blame] | 859 | gobjectClass->finalize = webkitAccessibleFinalize; |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 860 | |
mario@webkit.org | 5c96677 | 2012-01-24 18:48:50 +0000 | [diff] [blame] | 861 | klass->initialize = webkitAccessibleInit; |
| 862 | klass->get_name = webkitAccessibleGetName; |
| 863 | klass->get_description = webkitAccessibleGetDescription; |
| 864 | klass->get_parent = webkitAccessibleGetParent; |
| 865 | klass->get_n_children = webkitAccessibleGetNChildren; |
| 866 | klass->ref_child = webkitAccessibleRefChild; |
| 867 | klass->get_role = webkitAccessibleGetRole; |
| 868 | klass->ref_state_set = webkitAccessibleRefStateSet; |
| 869 | klass->get_index_in_parent = webkitAccessibleGetIndexInParent; |
| 870 | klass->get_attributes = webkitAccessibleGetAttributes; |
| 871 | klass->ref_relation_set = webkitAccessibleRefRelationSet; |
commit-queue@webkit.org | 120f565 | 2013-06-12 21:39:42 +0000 | [diff] [blame] | 872 | klass->get_object_locale = webkitAccessibleGetObjectLocale; |
mario@webkit.org | fecbacd | 2013-03-04 17:06:15 +0000 | [diff] [blame] | 873 | |
| 874 | g_type_class_add_private(klass, sizeof(WebKitAccessiblePrivate)); |
xan@webkit.org | e438710 | 2009-04-09 11:08:48 +0000 | [diff] [blame] | 875 | } |
| 876 | |
| 877 | GType |
mario@webkit.org | f88ffcb | 2012-11-16 13:47:03 +0000 | [diff] [blame] | 878 | webkitAccessibleGetType(void) |
xan@webkit.org | e438710 | 2009-04-09 11:08:48 +0000 | [diff] [blame] | 879 | { |
mario@webkit.org | f88ffcb | 2012-11-16 13:47:03 +0000 | [diff] [blame] | 880 | static volatile gsize typeVolatile = 0; |
xan@webkit.org | e438710 | 2009-04-09 11:08:48 +0000 | [diff] [blame] | 881 | |
mario@webkit.org | f88ffcb | 2012-11-16 13:47:03 +0000 | [diff] [blame] | 882 | if (g_once_init_enter(&typeVolatile)) { |
xan@webkit.org | e438710 | 2009-04-09 11:08:48 +0000 | [diff] [blame] | 883 | static const GTypeInfo tinfo = { |
| 884 | sizeof(WebKitAccessibleClass), |
eric@webkit.org | 4ff6fd7 | 2009-11-10 09:53:33 +0000 | [diff] [blame] | 885 | (GBaseInitFunc) 0, |
| 886 | (GBaseFinalizeFunc) 0, |
mario@webkit.org | f88ffcb | 2012-11-16 13:47:03 +0000 | [diff] [blame] | 887 | (GClassInitFunc) webkitAccessibleClassInit, |
eric@webkit.org | 4ff6fd7 | 2009-11-10 09:53:33 +0000 | [diff] [blame] | 888 | (GClassFinalizeFunc) 0, |
| 889 | 0, /* class data */ |
xan@webkit.org | e438710 | 2009-04-09 11:08:48 +0000 | [diff] [blame] | 890 | sizeof(WebKitAccessible), /* instance size */ |
| 891 | 0, /* nb preallocs */ |
eric@webkit.org | 4ff6fd7 | 2009-11-10 09:53:33 +0000 | [diff] [blame] | 892 | (GInstanceInitFunc) 0, |
| 893 | 0 /* value table */ |
xan@webkit.org | e438710 | 2009-04-09 11:08:48 +0000 | [diff] [blame] | 894 | }; |
| 895 | |
mario@webkit.org | f88ffcb | 2012-11-16 13:47:03 +0000 | [diff] [blame] | 896 | GType type = g_type_register_static(ATK_TYPE_OBJECT, "WebKitAccessible", &tinfo, GTypeFlags(0)); |
| 897 | g_once_init_leave(&typeVolatile, type); |
xan@webkit.org | e438710 | 2009-04-09 11:08:48 +0000 | [diff] [blame] | 898 | } |
| 899 | |
mario@webkit.org | f88ffcb | 2012-11-16 13:47:03 +0000 | [diff] [blame] | 900 | return typeVolatile; |
alp@webkit.org | c773899 | 2008-05-27 02:48:14 +0000 | [diff] [blame] | 901 | } |
| 902 | |
xan@webkit.org | e438710 | 2009-04-09 11:08:48 +0000 | [diff] [blame] | 903 | static const GInterfaceInfo AtkInterfacesInitFunctions[] = { |
mario@webkit.org | deec839 | 2012-01-23 14:45:23 +0000 | [diff] [blame] | 904 | {reinterpret_cast<GInterfaceInitFunc>(webkitAccessibleActionInterfaceInit), 0, 0}, |
mario@webkit.org | 7e5931d | 2012-01-24 12:25:13 +0000 | [diff] [blame] | 905 | {reinterpret_cast<GInterfaceInitFunc>(webkitAccessibleSelectionInterfaceInit), 0, 0}, |
mario@webkit.org | fc51ca6 | 2012-01-24 11:47:51 +0000 | [diff] [blame] | 906 | {reinterpret_cast<GInterfaceInitFunc>(webkitAccessibleEditableTextInterfaceInit), 0, 0}, |
mario@webkit.org | 987d737 | 2012-01-24 18:02:08 +0000 | [diff] [blame] | 907 | {reinterpret_cast<GInterfaceInitFunc>(webkitAccessibleTextInterfaceInit), 0, 0}, |
mario@webkit.org | be1ce55 | 2012-01-24 11:03:51 +0000 | [diff] [blame] | 908 | {reinterpret_cast<GInterfaceInitFunc>(webkitAccessibleComponentInterfaceInit), 0, 0}, |
mario@webkit.org | da3e608 | 2012-01-24 12:04:16 +0000 | [diff] [blame] | 909 | {reinterpret_cast<GInterfaceInitFunc>(webkitAccessibleImageInterfaceInit), 0, 0}, |
mario@webkit.org | cd9f1b3 | 2012-01-24 18:28:22 +0000 | [diff] [blame] | 910 | {reinterpret_cast<GInterfaceInitFunc>(webkitAccessibleTableInterfaceInit), 0, 0}, |
mario@webkit.org | 7024353 | 2012-01-24 11:58:52 +0000 | [diff] [blame] | 911 | {reinterpret_cast<GInterfaceInitFunc>(webkitAccessibleHypertextInterfaceInit), 0, 0}, |
mario@webkit.org | 4dbd982 | 2012-01-24 11:55:18 +0000 | [diff] [blame] | 912 | {reinterpret_cast<GInterfaceInitFunc>(webkitAccessibleHyperlinkImplInterfaceInit), 0, 0}, |
mario@webkit.org | f8344ff | 2012-01-24 11:40:44 +0000 | [diff] [blame] | 913 | {reinterpret_cast<GInterfaceInitFunc>(webkitAccessibleDocumentInterfaceInit), 0, 0}, |
mario@webkit.org | 980269e | 2012-01-24 16:22:57 +0000 | [diff] [blame] | 914 | {reinterpret_cast<GInterfaceInitFunc>(webkitAccessibleValueInterfaceInit), 0, 0} |
xan@webkit.org | e438710 | 2009-04-09 11:08:48 +0000 | [diff] [blame] | 915 | }; |
| 916 | |
| 917 | enum WAIType { |
| 918 | WAI_ACTION, |
eric@webkit.org | f84ff63 | 2009-10-29 17:34:39 +0000 | [diff] [blame] | 919 | WAI_SELECTION, |
xan@webkit.org | e438710 | 2009-04-09 11:08:48 +0000 | [diff] [blame] | 920 | WAI_EDITABLE_TEXT, |
xan@webkit.org | 92b9169 | 2009-04-21 07:02:17 +0000 | [diff] [blame] | 921 | WAI_TEXT, |
xan@webkit.org | e43e70b | 2009-04-27 21:33:55 +0000 | [diff] [blame] | 922 | WAI_COMPONENT, |
xan@webkit.org | 45b26ac | 2009-10-27 12:20:35 +0000 | [diff] [blame] | 923 | WAI_IMAGE, |
eric@webkit.org | 65e12ba | 2009-11-01 21:22:30 +0000 | [diff] [blame] | 924 | WAI_TABLE, |
mario@webkit.org | 7f95c62 | 2010-11-01 15:05:36 +0000 | [diff] [blame] | 925 | WAI_HYPERTEXT, |
| 926 | WAI_HYPERLINK, |
mario@webkit.org | 04e38e9 | 2011-03-28 10:16:38 +0000 | [diff] [blame] | 927 | WAI_DOCUMENT, |
| 928 | WAI_VALUE, |
xan@webkit.org | e438710 | 2009-04-09 11:08:48 +0000 | [diff] [blame] | 929 | }; |
| 930 | |
| 931 | static GType GetAtkInterfaceTypeFromWAIType(WAIType type) |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 932 | { |
mario@webkit.org | 7f95c62 | 2010-11-01 15:05:36 +0000 | [diff] [blame] | 933 | switch (type) { |
| 934 | case WAI_ACTION: |
| 935 | return ATK_TYPE_ACTION; |
| 936 | case WAI_SELECTION: |
| 937 | return ATK_TYPE_SELECTION; |
| 938 | case WAI_EDITABLE_TEXT: |
| 939 | return ATK_TYPE_EDITABLE_TEXT; |
| 940 | case WAI_TEXT: |
| 941 | return ATK_TYPE_TEXT; |
| 942 | case WAI_COMPONENT: |
| 943 | return ATK_TYPE_COMPONENT; |
| 944 | case WAI_IMAGE: |
| 945 | return ATK_TYPE_IMAGE; |
| 946 | case WAI_TABLE: |
| 947 | return ATK_TYPE_TABLE; |
| 948 | case WAI_HYPERTEXT: |
| 949 | return ATK_TYPE_HYPERTEXT; |
| 950 | case WAI_HYPERLINK: |
| 951 | return ATK_TYPE_HYPERLINK_IMPL; |
| 952 | case WAI_DOCUMENT: |
| 953 | return ATK_TYPE_DOCUMENT; |
mario@webkit.org | 04e38e9 | 2011-03-28 10:16:38 +0000 | [diff] [blame] | 954 | case WAI_VALUE: |
| 955 | return ATK_TYPE_VALUE; |
mario@webkit.org | 7f95c62 | 2010-11-01 15:05:36 +0000 | [diff] [blame] | 956 | } |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 957 | |
mario@webkit.org | 7f95c62 | 2010-11-01 15:05:36 +0000 | [diff] [blame] | 958 | return G_TYPE_INVALID; |
xan@webkit.org | e438710 | 2009-04-09 11:08:48 +0000 | [diff] [blame] | 959 | } |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 960 | |
commit-queue@webkit.org | ca1b1d2 | 2012-08-22 01:37:04 +0000 | [diff] [blame] | 961 | static bool roleIsTextType(AccessibilityRole role) |
| 962 | { |
zandobersek@gmail.com | 2b2075f | 2012-09-01 08:53:50 +0000 | [diff] [blame] | 963 | return role == ParagraphRole || role == HeadingRole || role == DivRole || role == CellRole || role == ListItemRole; |
commit-queue@webkit.org | ca1b1d2 | 2012-08-22 01:37:04 +0000 | [diff] [blame] | 964 | } |
| 965 | |
xan@webkit.org | e438710 | 2009-04-09 11:08:48 +0000 | [diff] [blame] | 966 | static guint16 getInterfaceMaskFromObject(AccessibilityObject* coreObject) |
| 967 | { |
| 968 | guint16 interfaceMask = 0; |
alp@webkit.org | c773899 | 2008-05-27 02:48:14 +0000 | [diff] [blame] | 969 | |
xan@webkit.org | 92b9169 | 2009-04-21 07:02:17 +0000 | [diff] [blame] | 970 | // Component interface is always supported |
| 971 | interfaceMask |= 1 << WAI_COMPONENT; |
| 972 | |
mario@webkit.org | 7f95c62 | 2010-11-01 15:05:36 +0000 | [diff] [blame] | 973 | AccessibilityRole role = coreObject->roleValue(); |
| 974 | |
xan@webkit.org | b3c59bf | 2009-04-21 07:01:27 +0000 | [diff] [blame] | 975 | // Action |
mario@webkit.org | 8ce6a15 | 2010-11-30 21:16:14 +0000 | [diff] [blame] | 976 | // As the implementation of the AtkAction interface is a very |
| 977 | // basic one (just relays in executing the default action for each |
| 978 | // object, and only supports having one action per object), it is |
| 979 | // better just to implement this interface for every instance of |
| 980 | // the WebKitAccessible class and let WebCore decide what to do. |
| 981 | interfaceMask |= 1 << WAI_ACTION; |
xan@webkit.org | b3c59bf | 2009-04-21 07:01:27 +0000 | [diff] [blame] | 982 | |
eric@webkit.org | f84ff63 | 2009-10-29 17:34:39 +0000 | [diff] [blame] | 983 | // Selection |
mario@webkit.org | 8ce6a15 | 2010-11-30 21:16:14 +0000 | [diff] [blame] | 984 | if (coreObject->isListBox() || coreObject->isMenuList()) |
eric@webkit.org | f84ff63 | 2009-10-29 17:34:39 +0000 | [diff] [blame] | 985 | interfaceMask |= 1 << WAI_SELECTION; |
| 986 | |
mario@webkit.org | 9f0aee1 | 2011-04-11 21:02:23 +0000 | [diff] [blame] | 987 | // Get renderer if available. |
| 988 | RenderObject* renderer = 0; |
| 989 | if (coreObject->isAccessibilityRenderObject()) |
| 990 | renderer = coreObject->renderer(); |
| 991 | |
| 992 | // Hyperlink (links and embedded objects). |
| 993 | if (coreObject->isLink() || (renderer && renderer->isReplaced())) |
| 994 | interfaceMask |= 1 << WAI_HYPERLINK; |
| 995 | |
xan@webkit.org | e438710 | 2009-04-09 11:08:48 +0000 | [diff] [blame] | 996 | // Text & Editable Text |
mario@webkit.org | 8ce6a15 | 2010-11-30 21:16:14 +0000 | [diff] [blame] | 997 | if (role == StaticTextRole || coreObject->isMenuListOption()) |
xan@webkit.org | 7a07be5 | 2009-04-14 15:56:10 +0000 | [diff] [blame] | 998 | interfaceMask |= 1 << WAI_TEXT; |
mario@webkit.org | 9f0aee1 | 2011-04-11 21:02:23 +0000 | [diff] [blame] | 999 | else { |
eric@webkit.org | 10e02f8 | 2010-01-07 02:05:01 +0000 | [diff] [blame] | 1000 | if (coreObject->isTextControl()) { |
| 1001 | interfaceMask |= 1 << WAI_TEXT; |
| 1002 | if (!coreObject->isReadOnly()) |
| 1003 | interfaceMask |= 1 << WAI_EDITABLE_TEXT; |
commit-queue@webkit.org | 1f3aafe | 2010-09-22 07:49:34 +0000 | [diff] [blame] | 1004 | } else { |
mario@webkit.org | 7f95c62 | 2010-11-01 15:05:36 +0000 | [diff] [blame] | 1005 | if (role != TableRole) { |
| 1006 | interfaceMask |= 1 << WAI_HYPERTEXT; |
commit-queue@webkit.org | ca1b1d2 | 2012-08-22 01:37:04 +0000 | [diff] [blame] | 1007 | if ((renderer && renderer->childrenInline()) || roleIsTextType(role)) |
mario@webkit.org | 7f95c62 | 2010-11-01 15:05:36 +0000 | [diff] [blame] | 1008 | interfaceMask |= 1 << WAI_TEXT; |
| 1009 | } |
| 1010 | |
| 1011 | // Add the TEXT interface for list items whose |
| 1012 | // first accessible child has a text renderer |
| 1013 | if (role == ListItemRole) { |
mario@webkit.org | 7e9f241 | 2011-04-06 16:50:25 +0000 | [diff] [blame] | 1014 | AccessibilityObject::AccessibilityChildrenVector children = coreObject->children(); |
commit-queue@webkit.org | 1f3aafe | 2010-09-22 07:49:34 +0000 | [diff] [blame] | 1015 | if (children.size()) { |
| 1016 | AccessibilityObject* axRenderChild = children.at(0).get(); |
| 1017 | interfaceMask |= getInterfaceMaskFromObject(axRenderChild); |
| 1018 | } |
| 1019 | } |
| 1020 | } |
mario@webkit.org | 7f95c62 | 2010-11-01 15:05:36 +0000 | [diff] [blame] | 1021 | } |
xan@webkit.org | e438710 | 2009-04-09 11:08:48 +0000 | [diff] [blame] | 1022 | |
xan@webkit.org | e43e70b | 2009-04-27 21:33:55 +0000 | [diff] [blame] | 1023 | // Image |
| 1024 | if (coreObject->isImage()) |
| 1025 | interfaceMask |= 1 << WAI_IMAGE; |
| 1026 | |
xan@webkit.org | 45b26ac | 2009-10-27 12:20:35 +0000 | [diff] [blame] | 1027 | // Table |
| 1028 | if (role == TableRole) |
| 1029 | interfaceMask |= 1 << WAI_TABLE; |
| 1030 | |
eric@webkit.org | 65e12ba | 2009-11-01 21:22:30 +0000 | [diff] [blame] | 1031 | // Document |
| 1032 | if (role == WebAreaRole) |
| 1033 | interfaceMask |= 1 << WAI_DOCUMENT; |
| 1034 | |
mario@webkit.org | 04e38e9 | 2011-03-28 10:16:38 +0000 | [diff] [blame] | 1035 | // Value |
commit-queue@webkit.org | 3e37d78 | 2013-09-09 09:39:34 +0000 | [diff] [blame] | 1036 | if (role == SliderRole || role == SpinButtonRole || role == ScrollBarRole || role == ProgressIndicatorRole) |
mario@webkit.org | 04e38e9 | 2011-03-28 10:16:38 +0000 | [diff] [blame] | 1037 | interfaceMask |= 1 << WAI_VALUE; |
| 1038 | |
commit-queue@webkit.org | fd70fd3 | 2013-09-04 14:19:02 +0000 | [diff] [blame] | 1039 | #if ENABLE(INPUT_TYPE_COLOR) |
| 1040 | // Color type. |
| 1041 | if (role == ColorWellRole) |
| 1042 | interfaceMask |= 1 << WAI_TEXT; |
| 1043 | #endif |
| 1044 | |
xan@webkit.org | e438710 | 2009-04-09 11:08:48 +0000 | [diff] [blame] | 1045 | return interfaceMask; |
| 1046 | } |
| 1047 | |
| 1048 | static const char* getUniqueAccessibilityTypeName(guint16 interfaceMask) |
| 1049 | { |
| 1050 | #define WAI_TYPE_NAME_LEN (30) /* Enough for prefix + 5 hex characters (max) */ |
| 1051 | static char name[WAI_TYPE_NAME_LEN + 1]; |
eric@webkit.org | 4ff6fd7 | 2009-11-10 09:53:33 +0000 | [diff] [blame] | 1052 | |
xan@webkit.org | e438710 | 2009-04-09 11:08:48 +0000 | [diff] [blame] | 1053 | g_sprintf(name, "WAIType%x", interfaceMask); |
| 1054 | name[WAI_TYPE_NAME_LEN] = '\0'; |
eric@webkit.org | 4ff6fd7 | 2009-11-10 09:53:33 +0000 | [diff] [blame] | 1055 | |
xan@webkit.org | e438710 | 2009-04-09 11:08:48 +0000 | [diff] [blame] | 1056 | return name; |
| 1057 | } |
| 1058 | |
| 1059 | static GType getAccessibilityTypeFromObject(AccessibilityObject* coreObject) |
| 1060 | { |
| 1061 | static const GTypeInfo typeInfo = { |
| 1062 | sizeof(WebKitAccessibleClass), |
eric@webkit.org | 4ff6fd7 | 2009-11-10 09:53:33 +0000 | [diff] [blame] | 1063 | (GBaseInitFunc) 0, |
| 1064 | (GBaseFinalizeFunc) 0, |
| 1065 | (GClassInitFunc) 0, |
| 1066 | (GClassFinalizeFunc) 0, |
| 1067 | 0, /* class data */ |
xan@webkit.org | e438710 | 2009-04-09 11:08:48 +0000 | [diff] [blame] | 1068 | sizeof(WebKitAccessible), /* instance size */ |
| 1069 | 0, /* nb preallocs */ |
eric@webkit.org | 4ff6fd7 | 2009-11-10 09:53:33 +0000 | [diff] [blame] | 1070 | (GInstanceInitFunc) 0, |
| 1071 | 0 /* value table */ |
xan@webkit.org | e438710 | 2009-04-09 11:08:48 +0000 | [diff] [blame] | 1072 | }; |
| 1073 | |
| 1074 | guint16 interfaceMask = getInterfaceMaskFromObject(coreObject); |
| 1075 | const char* atkTypeName = getUniqueAccessibilityTypeName(interfaceMask); |
| 1076 | GType type = g_type_from_name(atkTypeName); |
| 1077 | if (type) |
| 1078 | return type; |
| 1079 | |
mario@webkit.org | f88ffcb | 2012-11-16 13:47:03 +0000 | [diff] [blame] | 1080 | type = g_type_register_static(WEBKIT_TYPE_ACCESSIBLE, atkTypeName, &typeInfo, GTypeFlags(0)); |
xan@webkit.org | e438710 | 2009-04-09 11:08:48 +0000 | [diff] [blame] | 1081 | for (guint i = 0; i < G_N_ELEMENTS(AtkInterfacesInitFunctions); i++) { |
| 1082 | if (interfaceMask & (1 << i)) |
| 1083 | g_type_add_interface_static(type, |
mario@webkit.org | f88ffcb | 2012-11-16 13:47:03 +0000 | [diff] [blame] | 1084 | GetAtkInterfaceTypeFromWAIType(static_cast<WAIType>(i)), |
| 1085 | &AtkInterfacesInitFunctions[i]); |
xan@webkit.org | e438710 | 2009-04-09 11:08:48 +0000 | [diff] [blame] | 1086 | } |
| 1087 | |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 1088 | return type; |
| 1089 | } |
| 1090 | |
mario@webkit.org | aacb217 | 2012-01-23 11:43:28 +0000 | [diff] [blame] | 1091 | WebKitAccessible* webkitAccessibleNew(AccessibilityObject* coreObject) |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 1092 | { |
xan@webkit.org | e438710 | 2009-04-09 11:08:48 +0000 | [diff] [blame] | 1093 | GType type = getAccessibilityTypeFromObject(coreObject); |
eric@webkit.org | 4ff6fd7 | 2009-11-10 09:53:33 +0000 | [diff] [blame] | 1094 | AtkObject* object = static_cast<AtkObject*>(g_object_new(type, 0)); |
xan@webkit.org | e438710 | 2009-04-09 11:08:48 +0000 | [diff] [blame] | 1095 | |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 1096 | atk_object_initialize(object, coreObject); |
xan@webkit.org | e438710 | 2009-04-09 11:08:48 +0000 | [diff] [blame] | 1097 | |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 1098 | return WEBKIT_ACCESSIBLE(object); |
| 1099 | } |
| 1100 | |
mario@webkit.org | aacb217 | 2012-01-23 11:43:28 +0000 | [diff] [blame] | 1101 | AccessibilityObject* webkitAccessibleGetAccessibilityObject(WebKitAccessible* accessible) |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 1102 | { |
| 1103 | return accessible->m_object; |
| 1104 | } |
| 1105 | |
mario@webkit.org | aacb217 | 2012-01-23 11:43:28 +0000 | [diff] [blame] | 1106 | void webkitAccessibleDetach(WebKitAccessible* accessible) |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 1107 | { |
alp@webkit.org | c773899 | 2008-05-27 02:48:14 +0000 | [diff] [blame] | 1108 | ASSERT(accessible->m_object); |
| 1109 | |
mario@webkit.org | 92daa81 | 2011-02-16 17:12:38 +0000 | [diff] [blame] | 1110 | if (core(accessible)->roleValue() == WebAreaRole) |
| 1111 | g_signal_emit_by_name(accessible, "state-change", "defunct", true); |
| 1112 | |
alp@webkit.org | c773899 | 2008-05-27 02:48:14 +0000 | [diff] [blame] | 1113 | // We replace the WebCore AccessibilityObject with a fallback object that |
| 1114 | // provides default implementations to avoid repetitive null-checking after |
| 1115 | // detachment. |
xan@webkit.org | c886cc6 | 2009-04-09 11:17:48 +0000 | [diff] [blame] | 1116 | accessible->m_object = fallbackObject(); |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 1117 | } |
| 1118 | |
mario@webkit.org | aacb217 | 2012-01-23 11:43:28 +0000 | [diff] [blame] | 1119 | AtkObject* webkitAccessibleGetFocusedElement(WebKitAccessible* accessible) |
jmalonzo@webkit.org | aaaea3b | 2009-08-08 07:39:48 +0000 | [diff] [blame] | 1120 | { |
| 1121 | if (!accessible->m_object) |
| 1122 | return 0; |
| 1123 | |
| 1124 | RefPtr<AccessibilityObject> focusedObj = accessible->m_object->focusedUIElement(); |
| 1125 | if (!focusedObj) |
| 1126 | return 0; |
| 1127 | |
| 1128 | return focusedObj->wrapper(); |
| 1129 | } |
| 1130 | |
mario@webkit.org | 4c778d7 | 2012-01-09 10:16:20 +0000 | [diff] [blame] | 1131 | AccessibilityObject* objectFocusedAndCaretOffsetUnignored(AccessibilityObject* referenceObject, int& offset) |
eric@webkit.org | 2fade49 | 2010-01-11 12:03:36 +0000 | [diff] [blame] | 1132 | { |
eric@webkit.org | 9cf227c | 2010-01-19 21:31:01 +0000 | [diff] [blame] | 1133 | // Indication that something bogus has transpired. |
| 1134 | offset = -1; |
eric@webkit.org | 2fade49 | 2010-01-11 12:03:36 +0000 | [diff] [blame] | 1135 | |
mario@webkit.org | 4c778d7 | 2012-01-09 10:16:20 +0000 | [diff] [blame] | 1136 | Document* document = referenceObject->document(); |
| 1137 | if (!document) |
mrobinson@webkit.org | bc2c5f2 | 2010-09-29 17:58:13 +0000 | [diff] [blame] | 1138 | return 0; |
eric@webkit.org | 2fade49 | 2010-01-11 12:03:36 +0000 | [diff] [blame] | 1139 | |
mario@webkit.org | 4c778d7 | 2012-01-09 10:16:20 +0000 | [diff] [blame] | 1140 | Node* focusedNode = referenceObject->selection().end().containerNode(); |
| 1141 | if (!focusedNode) |
mrobinson@webkit.org | bc2c5f2 | 2010-09-29 17:58:13 +0000 | [diff] [blame] | 1142 | return 0; |
eric@webkit.org | 2fade49 | 2010-01-11 12:03:36 +0000 | [diff] [blame] | 1143 | |
mario@webkit.org | 4c778d7 | 2012-01-09 10:16:20 +0000 | [diff] [blame] | 1144 | RenderObject* focusedRenderer = focusedNode->renderer(); |
| 1145 | if (!focusedRenderer) |
| 1146 | return 0; |
mario@webkit.org | 6698d35 | 2011-02-01 09:49:25 +0000 | [diff] [blame] | 1147 | |
mario@webkit.org | 4c778d7 | 2012-01-09 10:16:20 +0000 | [diff] [blame] | 1148 | AccessibilityObject* focusedObject = document->axObjectCache()->getOrCreate(focusedRenderer); |
| 1149 | if (!focusedObject) |
| 1150 | return 0; |
mario@webkit.org | 6698d35 | 2011-02-01 09:49:25 +0000 | [diff] [blame] | 1151 | |
mario@webkit.org | 4c778d7 | 2012-01-09 10:16:20 +0000 | [diff] [blame] | 1152 | // Look for the actual (not ignoring accessibility) selected object. |
mario@webkit.org | d048f76 | 2012-01-22 19:29:04 +0000 | [diff] [blame] | 1153 | AccessibilityObject* firstUnignoredParent = focusedObject; |
| 1154 | if (firstUnignoredParent->accessibilityIsIgnored()) |
| 1155 | firstUnignoredParent = firstUnignoredParent->parentObjectUnignored(); |
| 1156 | if (!firstUnignoredParent) |
mario@webkit.org | 4c778d7 | 2012-01-09 10:16:20 +0000 | [diff] [blame] | 1157 | return 0; |
| 1158 | |
| 1159 | // Don't ignore links if the offset is being requested for a link. |
mario@webkit.org | d048f76 | 2012-01-22 19:29:04 +0000 | [diff] [blame] | 1160 | if (!referenceObject->isLink() && firstUnignoredParent->isLink()) |
| 1161 | firstUnignoredParent = firstUnignoredParent->parentObjectUnignored(); |
| 1162 | if (!firstUnignoredParent) |
mario@webkit.org | 4c778d7 | 2012-01-09 10:16:20 +0000 | [diff] [blame] | 1163 | return 0; |
| 1164 | |
mario@webkit.org | d048f76 | 2012-01-22 19:29:04 +0000 | [diff] [blame] | 1165 | // The reference object must either coincide with the focused |
| 1166 | // object being considered, or be a descendant of it. |
| 1167 | if (referenceObject->isDescendantOfObject(firstUnignoredParent)) |
| 1168 | referenceObject = firstUnignoredParent; |
| 1169 | |
mario@webkit.org | 4c778d7 | 2012-01-09 10:16:20 +0000 | [diff] [blame] | 1170 | Node* startNode = 0; |
mario@webkit.org | d048f76 | 2012-01-22 19:29:04 +0000 | [diff] [blame] | 1171 | if (firstUnignoredParent != referenceObject || firstUnignoredParent->isTextControl()) { |
mario@webkit.org | 4c778d7 | 2012-01-09 10:16:20 +0000 | [diff] [blame] | 1172 | // We need to use the first child's node of the reference |
| 1173 | // object as the start point to calculate the caret offset |
| 1174 | // because we want it to be relative to the object of |
| 1175 | // reference, not just to the focused object (which could have |
| 1176 | // previous siblings which should be taken into account too). |
| 1177 | AccessibilityObject* axFirstChild = referenceObject->firstChild(); |
| 1178 | if (axFirstChild) |
| 1179 | startNode = axFirstChild->node(); |
| 1180 | } |
commit-queue@webkit.org | fb3e915 | 2013-02-01 00:37:22 +0000 | [diff] [blame] | 1181 | // Getting the Position of a PseudoElement now triggers an assertion. |
| 1182 | // This can occur when clicking on empty space in a render block. |
| 1183 | if (!startNode || startNode->isPseudoElement()) |
mario@webkit.org | d048f76 | 2012-01-22 19:29:04 +0000 | [diff] [blame] | 1184 | startNode = firstUnignoredParent->node(); |
mario@webkit.org | 4c778d7 | 2012-01-09 10:16:20 +0000 | [diff] [blame] | 1185 | |
mario@webkit.org | b311bdb | 2012-02-01 17:58:57 +0000 | [diff] [blame] | 1186 | // Check if the node for the first parent object not ignoring |
| 1187 | // accessibility is null again before using it. This might happen |
| 1188 | // with certain kind of accessibility objects, such as the root |
| 1189 | // one (the scroller containing the webArea object). |
| 1190 | if (!startNode) |
| 1191 | return 0; |
| 1192 | |
mario@webkit.org | d048f76 | 2012-01-22 19:29:04 +0000 | [diff] [blame] | 1193 | VisiblePosition startPosition = VisiblePosition(positionBeforeNode(startNode), DOWNSTREAM); |
| 1194 | VisiblePosition endPosition = firstUnignoredParent->selection().visibleEnd(); |
mario@webkit.org | 4c778d7 | 2012-01-09 10:16:20 +0000 | [diff] [blame] | 1195 | |
| 1196 | if (startPosition == endPosition) |
| 1197 | offset = 0; |
| 1198 | else if (!isStartOfLine(endPosition)) { |
| 1199 | RefPtr<Range> range = makeRange(startPosition, endPosition.previous()); |
| 1200 | offset = TextIterator::rangeLength(range.get(), true) + 1; |
| 1201 | } else { |
| 1202 | RefPtr<Range> range = makeRange(startPosition, endPosition); |
| 1203 | offset = TextIterator::rangeLength(range.get(), true); |
eric@webkit.org | 9cf227c | 2010-01-19 21:31:01 +0000 | [diff] [blame] | 1204 | } |
mario@webkit.org | ff7fd42 | 2011-01-27 19:38:03 +0000 | [diff] [blame] | 1205 | |
mario@webkit.org | d048f76 | 2012-01-22 19:29:04 +0000 | [diff] [blame] | 1206 | return firstUnignoredParent; |
eric@webkit.org | 2fade49 | 2010-01-11 12:03:36 +0000 | [diff] [blame] | 1207 | } |
| 1208 | |
mario@webkit.org | fecbacd | 2013-03-04 17:06:15 +0000 | [diff] [blame] | 1209 | const char* cacheAndReturnAtkProperty(AtkObject* object, AtkCachedProperty property, String value) |
| 1210 | { |
| 1211 | WebKitAccessiblePrivate* priv = WEBKIT_ACCESSIBLE(object)->priv; |
| 1212 | CString* propertyPtr = 0; |
| 1213 | |
| 1214 | switch (property) { |
| 1215 | case AtkCachedAccessibleName: |
| 1216 | propertyPtr = &priv->accessibleName; |
| 1217 | break; |
| 1218 | |
| 1219 | case AtkCachedAccessibleDescription: |
| 1220 | propertyPtr = &priv->accessibleDescription; |
| 1221 | break; |
| 1222 | |
| 1223 | case AtkCachedActionName: |
| 1224 | propertyPtr = &priv->actionName; |
| 1225 | break; |
| 1226 | |
| 1227 | case AtkCachedActionKeyBinding: |
| 1228 | propertyPtr = &priv->actionKeyBinding; |
| 1229 | break; |
| 1230 | |
| 1231 | case AtkCachedDocumentLocale: |
| 1232 | propertyPtr = &priv->documentLocale; |
| 1233 | break; |
| 1234 | |
| 1235 | case AtkCachedDocumentType: |
| 1236 | propertyPtr = &priv->documentType; |
| 1237 | break; |
| 1238 | |
| 1239 | case AtkCachedDocumentEncoding: |
| 1240 | propertyPtr = &priv->documentEncoding; |
| 1241 | break; |
| 1242 | |
| 1243 | case AtkCachedDocumentURI: |
| 1244 | propertyPtr = &priv->documentURI; |
| 1245 | break; |
| 1246 | |
| 1247 | case AtkCachedImageDescription: |
| 1248 | propertyPtr = &priv->imageDescription; |
| 1249 | break; |
| 1250 | |
| 1251 | default: |
| 1252 | ASSERT_NOT_REACHED(); |
| 1253 | } |
| 1254 | |
| 1255 | // Don't invalidate old memory if not stricly needed, since other |
| 1256 | // callers might be still holding on to it. |
| 1257 | if (*propertyPtr != value.utf8()) |
| 1258 | *propertyPtr = value.utf8(); |
| 1259 | |
| 1260 | return (*propertyPtr).data(); |
| 1261 | } |
| 1262 | |
ddkilzer@apple.com | 8d87863 | 2008-11-09 19:50:37 +0000 | [diff] [blame] | 1263 | #endif // HAVE(ACCESSIBILITY) |