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" |
mario.prada@samsung.com | 4fb934b | 2013-12-17 18:08:34 +0000 | [diff] [blame] | 38 | #include "AccessibilityList.h" |
akling@apple.com | 88e05f6 | 2013-09-16 15:17:24 +0000 | [diff] [blame] | 39 | #include "AccessibilityListBoxOption.h" |
cdumez@apple.com | b04d574 | 2014-10-22 21:45:20 +0000 | [diff] [blame] | 40 | #include "AccessibilityTable.h" |
alp@webkit.org | c773899 | 2008-05-27 02:48:14 +0000 | [diff] [blame] | 41 | #include "Document.h" |
alp@webkit.org | c773899 | 2008-05-27 02:48:14 +0000 | [diff] [blame] | 42 | #include "Frame.h" |
| 43 | #include "FrameView.h" |
xan@webkit.org | 9561b2c | 2009-05-20 14:33:19 +0000 | [diff] [blame] | 44 | #include "HTMLNames.h" |
xan@webkit.org | 45b26ac | 2009-10-27 12:20:35 +0000 | [diff] [blame] | 45 | #include "HTMLTableElement.h" |
mario@webkit.org | 9adab66 | 2012-01-23 10:21:03 +0000 | [diff] [blame] | 46 | #include "HostWindow.h" |
jdiggs@igalia.com | 3504d46 | 2016-03-16 01:45:57 +0000 | [diff] [blame] | 47 | #include "RenderAncestorIterator.h" |
| 48 | #include "RenderFieldset.h" |
mario@webkit.org | 970eaf3 | 2012-01-24 18:37:45 +0000 | [diff] [blame] | 49 | #include "RenderObject.h" |
jdiggs@igalia.com | 2f555dc | 2016-03-05 21:35:57 +0000 | [diff] [blame] | 50 | #include "SVGElement.h" |
mario@webkit.org | 6a24ba1 | 2010-12-14 15:35:22 +0000 | [diff] [blame] | 51 | #include "Settings.h" |
commit-queue@webkit.org | 74bd2e8 | 2010-09-12 11:16:14 +0000 | [diff] [blame] | 52 | #include "TextIterator.h" |
tkent@chromium.org | 8c35c12 | 2013-03-06 13:00:14 +0000 | [diff] [blame] | 53 | #include "VisibleUnits.h" |
mario@webkit.org | 7f95c62 | 2010-11-01 15:05:36 +0000 | [diff] [blame] | 54 | #include "WebKitAccessibleHyperlink.h" |
mario@webkit.org | deec839 | 2012-01-23 14:45:23 +0000 | [diff] [blame] | 55 | #include "WebKitAccessibleInterfaceAction.h" |
mario@webkit.org | be1ce55 | 2012-01-24 11:03:51 +0000 | [diff] [blame] | 56 | #include "WebKitAccessibleInterfaceComponent.h" |
mario@webkit.org | f8344ff | 2012-01-24 11:40:44 +0000 | [diff] [blame] | 57 | #include "WebKitAccessibleInterfaceDocument.h" |
mario@webkit.org | fc51ca6 | 2012-01-24 11:47:51 +0000 | [diff] [blame] | 58 | #include "WebKitAccessibleInterfaceEditableText.h" |
mario@webkit.org | 4dbd982 | 2012-01-24 11:55:18 +0000 | [diff] [blame] | 59 | #include "WebKitAccessibleInterfaceHyperlinkImpl.h" |
mario@webkit.org | 7024353 | 2012-01-24 11:58:52 +0000 | [diff] [blame] | 60 | #include "WebKitAccessibleInterfaceHypertext.h" |
mario@webkit.org | da3e608 | 2012-01-24 12:04:16 +0000 | [diff] [blame] | 61 | #include "WebKitAccessibleInterfaceImage.h" |
mario@webkit.org | 7e5931d | 2012-01-24 12:25:13 +0000 | [diff] [blame] | 62 | #include "WebKitAccessibleInterfaceSelection.h" |
mario@webkit.org | cd9f1b3 | 2012-01-24 18:28:22 +0000 | [diff] [blame] | 63 | #include "WebKitAccessibleInterfaceTable.h" |
k.czech@samsung.com | 2608de9 | 2014-02-27 11:28:31 +0000 | [diff] [blame] | 64 | #include "WebKitAccessibleInterfaceTableCell.h" |
mario@webkit.org | 987d737 | 2012-01-24 18:02:08 +0000 | [diff] [blame] | 65 | #include "WebKitAccessibleInterfaceText.h" |
mario@webkit.org | 980269e | 2012-01-24 16:22:57 +0000 | [diff] [blame] | 66 | #include "WebKitAccessibleInterfaceValue.h" |
mario@webkit.org | 7ceffa4 | 2012-01-23 11:55:01 +0000 | [diff] [blame] | 67 | #include "WebKitAccessibleUtil.h" |
mario@webkit.org | ba16aea | 2011-04-13 16:33:02 +0000 | [diff] [blame] | 68 | #include "htmlediting.h" |
xan@webkit.org | e438710 | 2009-04-09 11:08:48 +0000 | [diff] [blame] | 69 | #include <glib/gprintf.h> |
benjamin@webkit.org | 9d72cb0 | 2013-04-22 22:52:23 +0000 | [diff] [blame] | 70 | #include <wtf/text/CString.h> |
mario@webkit.org | 8c5dd90 | 2012-11-09 19:47:40 +0000 | [diff] [blame] | 71 | |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 72 | using namespace WebCore; |
| 73 | |
mario@webkit.org | fecbacd | 2013-03-04 17:06:15 +0000 | [diff] [blame] | 74 | struct _WebKitAccessiblePrivate { |
| 75 | // Cached data for AtkObject. |
| 76 | CString accessibleName; |
| 77 | CString accessibleDescription; |
| 78 | |
| 79 | // Cached data for AtkAction. |
| 80 | CString actionName; |
| 81 | CString actionKeyBinding; |
| 82 | |
| 83 | // Cached data for AtkDocument. |
| 84 | CString documentLocale; |
| 85 | CString documentType; |
| 86 | CString documentEncoding; |
| 87 | CString documentURI; |
| 88 | |
| 89 | // Cached data for AtkImage. |
| 90 | CString imageDescription; |
| 91 | }; |
| 92 | |
| 93 | #define WEBKIT_ACCESSIBLE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), WEBKIT_TYPE_ACCESSIBLE, WebKitAccessiblePrivate)) |
| 94 | |
xan@webkit.org | c886cc6 | 2009-04-09 11:17:48 +0000 | [diff] [blame] | 95 | static AccessibilityObject* fallbackObject() |
| 96 | { |
akling@apple.com | ad2beb5 | 2014-12-25 07:50:20 +0000 | [diff] [blame] | 97 | static AccessibilityObject* object = &AccessibilityListBoxOption::create().leakRef(); |
xan@webkit.org | c886cc6 | 2009-04-09 11:17:48 +0000 | [diff] [blame] | 98 | return object; |
| 99 | } |
| 100 | |
alp@webkit.org | c773899 | 2008-05-27 02:48:14 +0000 | [diff] [blame] | 101 | static AccessibilityObject* core(AtkObject* object) |
| 102 | { |
| 103 | if (!WEBKIT_IS_ACCESSIBLE(object)) |
| 104 | return 0; |
| 105 | |
mario@webkit.org | ff8cf0f | 2013-09-27 09:44:20 +0000 | [diff] [blame] | 106 | return webkitAccessibleGetAccessibilityObject(WEBKIT_ACCESSIBLE(object)); |
alp@webkit.org | c773899 | 2008-05-27 02:48:14 +0000 | [diff] [blame] | 107 | } |
| 108 | |
mario@webkit.org | 5c96677 | 2012-01-24 18:48:50 +0000 | [diff] [blame] | 109 | static const gchar* webkitAccessibleGetName(AtkObject* object) |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 110 | { |
mario@webkit.org | ff8cf0f | 2013-09-27 09:44:20 +0000 | [diff] [blame] | 111 | g_return_val_if_fail(WEBKIT_IS_ACCESSIBLE(object), 0); |
| 112 | returnValIfWebKitAccessibleIsInvalid(WEBKIT_ACCESSIBLE(object), 0); |
| 113 | |
jdiggs@igalia.com | e184cee | 2016-05-18 07:12:09 +0000 | [diff] [blame] | 114 | Vector<AccessibilityText> textOrder; |
| 115 | core(object)->accessibilityText(textOrder); |
| 116 | |
| 117 | for (const auto& text : textOrder) { |
| 118 | // FIXME: This check is here because AccessibilityNodeObject::titleElementText() |
| 119 | // appends an empty String for the LabelByElementText source when there is a |
| 120 | // titleUIElement(). Removing this check makes some fieldsets lose their name. |
| 121 | if (text.text.isEmpty()) |
| 122 | continue; |
| 123 | |
| 124 | // WebCore Accessibility should provide us with the text alternative computation |
| 125 | // in the order defined by that spec. So take the first thing that our platform |
| 126 | // does not expose via the AtkObject description. |
| 127 | if (text.textSource != HelpText && text.textSource != SummaryText) |
| 128 | return cacheAndReturnAtkProperty(object, AtkCachedAccessibleName, text.text); |
commit-queue@webkit.org | 802c012 | 2012-09-11 01:41:27 +0000 | [diff] [blame] | 129 | } |
| 130 | |
jdiggs@igalia.com | e184cee | 2016-05-18 07:12:09 +0000 | [diff] [blame] | 131 | return cacheAndReturnAtkProperty(object, AtkCachedAccessibleName, ""); |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 132 | } |
| 133 | |
mario@webkit.org | 5c96677 | 2012-01-24 18:48:50 +0000 | [diff] [blame] | 134 | static const gchar* webkitAccessibleGetDescription(AtkObject* object) |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 135 | { |
mario@webkit.org | ff8cf0f | 2013-09-27 09:44:20 +0000 | [diff] [blame] | 136 | g_return_val_if_fail(WEBKIT_IS_ACCESSIBLE(object), 0); |
| 137 | returnValIfWebKitAccessibleIsInvalid(WEBKIT_ACCESSIBLE(object), 0); |
| 138 | |
jdiggs@igalia.com | e184cee | 2016-05-18 07:12:09 +0000 | [diff] [blame] | 139 | Vector<AccessibilityText> textOrder; |
| 140 | core(object)->accessibilityText(textOrder); |
jdiggs@igalia.com | 2f555dc | 2016-03-05 21:35:57 +0000 | [diff] [blame] | 141 | |
jdiggs@igalia.com | e184cee | 2016-05-18 07:12:09 +0000 | [diff] [blame] | 142 | bool nameTextAvailable = false; |
| 143 | for (const auto& text : textOrder) { |
| 144 | // WebCore Accessibility should provide us with the text alternative computation |
| 145 | // in the order defined by that spec. So take the first thing that our platform |
| 146 | // does not expose via the AtkObject name. |
| 147 | if (text.textSource == HelpText || text.textSource == SummaryText) |
| 148 | return cacheAndReturnAtkProperty(object, AtkCachedAccessibleDescription, text.text); |
jdiggs@igalia.com | 2f555dc | 2016-03-05 21:35:57 +0000 | [diff] [blame] | 149 | |
jdiggs@igalia.com | e184cee | 2016-05-18 07:12:09 +0000 | [diff] [blame] | 150 | // If there is no other text alternative, the title tag contents will have been |
| 151 | // used for the AtkObject name. We don't want to duplicate it here. |
| 152 | if (text.textSource == TitleTagText && nameTextAvailable) |
| 153 | return cacheAndReturnAtkProperty(object, AtkCachedAccessibleDescription, text.text); |
| 154 | |
| 155 | nameTextAvailable = true; |
jdiggs@igalia.com | 2f555dc | 2016-03-05 21:35:57 +0000 | [diff] [blame] | 156 | } |
| 157 | |
jdiggs@igalia.com | e184cee | 2016-05-18 07:12:09 +0000 | [diff] [blame] | 158 | return cacheAndReturnAtkProperty(object, AtkCachedAccessibleDescription, ""); |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 159 | } |
| 160 | |
m.pakula@samsung.com | e026b6a | 2013-11-06 18:17:03 +0000 | [diff] [blame] | 161 | static void removeAtkRelationByType(AtkRelationSet* relationSet, AtkRelationType relationType) |
| 162 | { |
| 163 | int count = atk_relation_set_get_n_relations(relationSet); |
| 164 | for (int i = 0; i < count; i++) { |
| 165 | AtkRelation* relation = atk_relation_set_get_relation(relationSet, i); |
| 166 | if (atk_relation_get_relation_type(relation) == relationType) { |
| 167 | atk_relation_set_remove(relationSet, relation); |
| 168 | break; |
| 169 | } |
| 170 | } |
| 171 | } |
| 172 | |
eric@webkit.org | 0f6cb45 | 2009-10-22 23:07:56 +0000 | [diff] [blame] | 173 | static void setAtkRelationSetFromCoreObject(AccessibilityObject* coreObject, AtkRelationSet* relationSet) |
| 174 | { |
jdiggs@igalia.com | 3504d46 | 2016-03-16 01:45:57 +0000 | [diff] [blame] | 175 | // FIXME: We're not implementing all the relation types, most notably the inverse/reciprocal |
| 176 | // types. Filed as bug 155494. |
commit-queue@webkit.org | 802c012 | 2012-09-11 01:41:27 +0000 | [diff] [blame] | 177 | |
jdiggs@igalia.com | 3504d46 | 2016-03-16 01:45:57 +0000 | [diff] [blame] | 178 | // Elements with aria-labelledby should have the labelled-by relation as per the ARIA AAM spec. |
| 179 | // Controls with a label element and fieldsets with a legend element should also use this relation |
| 180 | // as per the HTML AAM spec. The reciprocal label-for relation should also be used. |
| 181 | removeAtkRelationByType(relationSet, ATK_RELATION_LABELLED_BY); |
mario@webkit.org | 7e9f241 | 2011-04-06 16:50:25 +0000 | [diff] [blame] | 182 | if (coreObject->isControl()) { |
jdiggs@igalia.com | 3504d46 | 2016-03-16 01:45:57 +0000 | [diff] [blame] | 183 | if (AccessibilityObject* label = coreObject->correspondingLabelForControlElement()) |
eric@webkit.org | 0f6cb45 | 2009-10-22 23:07:56 +0000 | [diff] [blame] | 184 | atk_relation_set_add_relation_by_type(relationSet, ATK_RELATION_LABELLED_BY, label->wrapper()); |
jdiggs@igalia.com | 3504d46 | 2016-03-16 01:45:57 +0000 | [diff] [blame] | 185 | } else if (coreObject->isFieldset()) { |
| 186 | if (AccessibilityObject* label = coreObject->titleUIElement()) |
| 187 | atk_relation_set_add_relation_by_type(relationSet, ATK_RELATION_LABELLED_BY, label->wrapper()); |
| 188 | } else if (coreObject->roleValue() == LegendRole) { |
| 189 | if (RenderFieldset* renderFieldset = ancestorsOfType<RenderFieldset>(*coreObject->renderer()).first()) { |
| 190 | AccessibilityObject* fieldset = coreObject->axObjectCache()->getOrCreate(renderFieldset); |
| 191 | atk_relation_set_add_relation_by_type(relationSet, ATK_RELATION_LABEL_FOR, fieldset->wrapper()); |
m.pakula@samsung.com | e026b6a | 2013-11-06 18:17:03 +0000 | [diff] [blame] | 192 | } |
jdiggs@igalia.com | 3504d46 | 2016-03-16 01:45:57 +0000 | [diff] [blame] | 193 | } else if (AccessibilityObject* control = coreObject->correspondingControlForLabelElement()) { |
| 194 | atk_relation_set_add_relation_by_type(relationSet, ATK_RELATION_LABEL_FOR, control->wrapper()); |
eric@webkit.org | 0f6cb45 | 2009-10-22 23:07:56 +0000 | [diff] [blame] | 195 | } else { |
jdiggs@igalia.com | 3504d46 | 2016-03-16 01:45:57 +0000 | [diff] [blame] | 196 | AccessibilityObject::AccessibilityChildrenVector ariaLabelledByElements; |
| 197 | coreObject->ariaLabelledByElements(ariaLabelledByElements); |
| 198 | for (const auto& accessibilityObject : ariaLabelledByElements) |
| 199 | atk_relation_set_add_relation_by_type(relationSet, ATK_RELATION_LABELLED_BY, accessibilityObject->wrapper()); |
eric@webkit.org | 0f6cb45 | 2009-10-22 23:07:56 +0000 | [diff] [blame] | 200 | } |
k.czech@samsung.com | 2254581 | 2014-01-21 09:10:25 +0000 | [diff] [blame] | 201 | |
jdiggs@igalia.com | 3504d46 | 2016-03-16 01:45:57 +0000 | [diff] [blame] | 202 | // Elements with aria-flowto should have the flows-to relation as per the ARIA AAM spec. |
| 203 | removeAtkRelationByType(relationSet, ATK_RELATION_FLOWS_TO); |
| 204 | AccessibilityObject::AccessibilityChildrenVector ariaFlowToElements; |
| 205 | coreObject->ariaFlowToElements(ariaFlowToElements); |
| 206 | for (const auto& accessibilityObject : ariaFlowToElements) |
| 207 | atk_relation_set_add_relation_by_type(relationSet, ATK_RELATION_FLOWS_TO, accessibilityObject->wrapper()); |
k.czech@samsung.com | 7e9868e | 2014-01-29 13:16:27 +0000 | [diff] [blame] | 208 | |
jdiggs@igalia.com | 3504d46 | 2016-03-16 01:45:57 +0000 | [diff] [blame] | 209 | // Elements with aria-describedby should have the described-by relation as per the ARIA AAM spec. |
| 210 | removeAtkRelationByType(relationSet, ATK_RELATION_DESCRIBED_BY); |
| 211 | AccessibilityObject::AccessibilityChildrenVector ariaDescribedByElements; |
| 212 | coreObject->ariaDescribedByElements(ariaDescribedByElements); |
| 213 | for (const auto& accessibilityObject : ariaDescribedByElements) |
| 214 | atk_relation_set_add_relation_by_type(relationSet, ATK_RELATION_DESCRIBED_BY, accessibilityObject->wrapper()); |
k.czech@samsung.com | b8ad4bf | 2014-02-03 09:16:54 +0000 | [diff] [blame] | 215 | |
jdiggs@igalia.com | 3504d46 | 2016-03-16 01:45:57 +0000 | [diff] [blame] | 216 | // Elements with aria-controls should have the controller-for relation as per the ARIA AAM spec. |
| 217 | removeAtkRelationByType(relationSet, ATK_RELATION_CONTROLLER_FOR); |
| 218 | AccessibilityObject::AccessibilityChildrenVector ariaControls; |
| 219 | coreObject->ariaControlsElements(ariaControls); |
| 220 | for (const auto& accessibilityObject : ariaControls) |
| 221 | atk_relation_set_add_relation_by_type(relationSet, ATK_RELATION_CONTROLLER_FOR, accessibilityObject->wrapper()); |
eric@webkit.org | 0f6cb45 | 2009-10-22 23:07:56 +0000 | [diff] [blame] | 222 | } |
| 223 | |
commit-queue@webkit.org | 9a24e2d | 2015-05-29 04:53:35 +0000 | [diff] [blame] | 224 | static gpointer webkitAccessibleParentClass = nullptr; |
eric@webkit.org | b84b474 | 2009-10-20 21:20:50 +0000 | [diff] [blame] | 225 | |
mario@webkit.org | 86390a1 | 2011-01-07 17:34:02 +0000 | [diff] [blame] | 226 | static bool isRootObject(AccessibilityObject* coreObject) |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 227 | { |
mario@webkit.org | 86390a1 | 2011-01-07 17:34:02 +0000 | [diff] [blame] | 228 | // The root accessible object in WebCore is always an object with |
| 229 | // the ScrolledArea role with one child with the WebArea role. |
| 230 | if (!coreObject || !coreObject->isScrollView()) |
| 231 | return false; |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 232 | |
mario@webkit.org | 86390a1 | 2011-01-07 17:34:02 +0000 | [diff] [blame] | 233 | AccessibilityObject* firstChild = coreObject->firstChild(); |
| 234 | if (!firstChild || !firstChild->isWebArea()) |
| 235 | return false; |
| 236 | |
| 237 | return true; |
| 238 | } |
| 239 | |
| 240 | static AtkObject* atkParentOfRootObject(AtkObject* object) |
| 241 | { |
| 242 | AccessibilityObject* coreObject = core(object); |
| 243 | AccessibilityObject* coreParent = coreObject->parentObjectUnignored(); |
| 244 | |
| 245 | // 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] | 246 | // impossible for assistive technologies to ascend the accessible |
| 247 | // hierarchy all the way to the application. (Bug 30489) |
mario@webkit.org | 86390a1 | 2011-01-07 17:34:02 +0000 | [diff] [blame] | 248 | if (!coreParent && isRootObject(coreObject)) { |
mario@webkit.org | 8d00fa7 | 2011-04-13 16:27:23 +0000 | [diff] [blame] | 249 | Document* document = coreObject->document(); |
| 250 | if (!document) |
| 251 | return 0; |
eric@webkit.org | 03b220b | 2009-10-19 11:58:38 +0000 | [diff] [blame] | 252 | } |
| 253 | |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 254 | if (!coreParent) |
eric@webkit.org | 1f5f7fe | 2009-11-04 10:35:56 +0000 | [diff] [blame] | 255 | return 0; |
| 256 | |
| 257 | return coreParent->wrapper(); |
| 258 | } |
| 259 | |
mario@webkit.org | 5c96677 | 2012-01-24 18:48:50 +0000 | [diff] [blame] | 260 | static AtkObject* webkitAccessibleGetParent(AtkObject* object) |
eric@webkit.org | 1f5f7fe | 2009-11-04 10:35:56 +0000 | [diff] [blame] | 261 | { |
mario@webkit.org | ff8cf0f | 2013-09-27 09:44:20 +0000 | [diff] [blame] | 262 | g_return_val_if_fail(WEBKIT_IS_ACCESSIBLE(object), 0); |
| 263 | returnValIfWebKitAccessibleIsInvalid(WEBKIT_ACCESSIBLE(object), 0); |
| 264 | |
mario@webkit.org | 46e9b26 | 2011-11-17 11:50:07 +0000 | [diff] [blame] | 265 | // Check first if the parent has been already set. |
mario@webkit.org | f88ffcb | 2012-11-16 13:47:03 +0000 | [diff] [blame] | 266 | AtkObject* accessibleParent = ATK_OBJECT_CLASS(webkitAccessibleParentClass)->get_parent(object); |
mario@webkit.org | 46e9b26 | 2011-11-17 11:50:07 +0000 | [diff] [blame] | 267 | if (accessibleParent) |
| 268 | return accessibleParent; |
| 269 | |
| 270 | // 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] | 271 | AccessibilityObject* coreObject = core(object); |
mario@webkit.org | 868b5ea | 2011-06-24 09:06:32 +0000 | [diff] [blame] | 272 | if (!coreObject) |
| 273 | return 0; |
| 274 | |
mario@webkit.org | 86390a1 | 2011-01-07 17:34:02 +0000 | [diff] [blame] | 275 | AccessibilityObject* coreParent = coreObject->parentObjectUnignored(); |
mario@webkit.org | 868b5ea | 2011-06-24 09:06:32 +0000 | [diff] [blame] | 276 | |
mario@webkit.org | 86390a1 | 2011-01-07 17:34:02 +0000 | [diff] [blame] | 277 | if (!coreParent && isRootObject(coreObject)) |
| 278 | return atkParentOfRootObject(object); |
eric@webkit.org | 1f5f7fe | 2009-11-04 10:35:56 +0000 | [diff] [blame] | 279 | |
| 280 | if (!coreParent) |
| 281 | return 0; |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 282 | |
| 283 | return coreParent->wrapper(); |
| 284 | } |
| 285 | |
mario@webkit.org | 5c96677 | 2012-01-24 18:48:50 +0000 | [diff] [blame] | 286 | static gint webkitAccessibleGetNChildren(AtkObject* object) |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 287 | { |
mario@webkit.org | ff8cf0f | 2013-09-27 09:44:20 +0000 | [diff] [blame] | 288 | g_return_val_if_fail(WEBKIT_IS_ACCESSIBLE(object), 0); |
| 289 | returnValIfWebKitAccessibleIsInvalid(WEBKIT_ACCESSIBLE(object), 0); |
| 290 | |
mario@webkit.org | 868b5ea | 2011-06-24 09:06:32 +0000 | [diff] [blame] | 291 | AccessibilityObject* coreObject = core(object); |
| 292 | |
mario@webkit.org | 868b5ea | 2011-06-24 09:06:32 +0000 | [diff] [blame] | 293 | return coreObject->children().size(); |
| 294 | } |
| 295 | |
mario@webkit.org | 5c96677 | 2012-01-24 18:48:50 +0000 | [diff] [blame] | 296 | static AtkObject* webkitAccessibleRefChild(AtkObject* object, gint index) |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 297 | { |
mario@webkit.org | ff8cf0f | 2013-09-27 09:44:20 +0000 | [diff] [blame] | 298 | g_return_val_if_fail(WEBKIT_IS_ACCESSIBLE(object), 0); |
| 299 | returnValIfWebKitAccessibleIsInvalid(WEBKIT_ACCESSIBLE(object), 0); |
| 300 | |
mario@webkit.org | 868b5ea | 2011-06-24 09:06:32 +0000 | [diff] [blame] | 301 | if (index < 0) |
eric@webkit.org | dbd4d40 | 2009-11-04 09:31:06 +0000 | [diff] [blame] | 302 | return 0; |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 303 | |
mario@webkit.org | 868b5ea | 2011-06-24 09:06:32 +0000 | [diff] [blame] | 304 | AccessibilityObject* coreObject = core(object); |
commit-queue@webkit.org | 9a24e2d | 2015-05-29 04:53:35 +0000 | [diff] [blame] | 305 | AccessibilityObject* coreChild = nullptr; |
mario@webkit.org | 868b5ea | 2011-06-24 09:06:32 +0000 | [diff] [blame] | 306 | |
jdiggs@igalia.com | e8a090d | 2014-12-03 02:02:36 +0000 | [diff] [blame] | 307 | const AccessibilityObject::AccessibilityChildrenVector& children = coreObject->children(); |
| 308 | if (static_cast<size_t>(index) >= children.size()) |
| 309 | return 0; |
| 310 | coreChild = children.at(index).get(); |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 311 | |
| 312 | if (!coreChild) |
eric@webkit.org | 4ff6fd7 | 2009-11-10 09:53:33 +0000 | [diff] [blame] | 313 | return 0; |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 314 | |
| 315 | AtkObject* child = coreChild->wrapper(); |
eric@webkit.org | b84b474 | 2009-10-20 21:20:50 +0000 | [diff] [blame] | 316 | atk_object_set_parent(child, object); |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 317 | g_object_ref(child); |
| 318 | |
| 319 | return child; |
| 320 | } |
| 321 | |
mario@webkit.org | 5c96677 | 2012-01-24 18:48:50 +0000 | [diff] [blame] | 322 | static gint webkitAccessibleGetIndexInParent(AtkObject* object) |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 323 | { |
mario@webkit.org | ff8cf0f | 2013-09-27 09:44:20 +0000 | [diff] [blame] | 324 | g_return_val_if_fail(WEBKIT_IS_ACCESSIBLE(object), -1); |
| 325 | returnValIfWebKitAccessibleIsInvalid(WEBKIT_ACCESSIBLE(object), -1); |
| 326 | |
xan@webkit.org | 1f5349a | 2009-10-27 09:20:21 +0000 | [diff] [blame] | 327 | AccessibilityObject* coreObject = core(object); |
| 328 | AccessibilityObject* parent = coreObject->parentObjectUnignored(); |
| 329 | |
mario@webkit.org | 86390a1 | 2011-01-07 17:34:02 +0000 | [diff] [blame] | 330 | if (!parent && isRootObject(coreObject)) { |
| 331 | AtkObject* atkParent = atkParentOfRootObject(object); |
eric@webkit.org | 1f5f7fe | 2009-11-04 10:35:56 +0000 | [diff] [blame] | 332 | if (!atkParent) |
| 333 | return -1; |
| 334 | |
| 335 | unsigned count = atk_object_get_n_accessible_children(atkParent); |
| 336 | for (unsigned i = 0; i < count; ++i) { |
| 337 | AtkObject* child = atk_object_ref_accessible_child(atkParent, i); |
| 338 | bool childIsObject = child == object; |
| 339 | g_object_unref(child); |
| 340 | if (childIsObject) |
| 341 | return i; |
| 342 | } |
| 343 | } |
xan@webkit.org | 1f5349a | 2009-10-27 09:20:21 +0000 | [diff] [blame] | 344 | |
commit-queue@webkit.org | 54a624e | 2013-01-16 18:00:17 +0000 | [diff] [blame] | 345 | if (!parent) |
| 346 | return -1; |
| 347 | |
commit-queue@webkit.org | bf18355 | 2012-02-22 09:28:57 +0000 | [diff] [blame] | 348 | size_t index = parent->children().find(coreObject); |
| 349 | return (index == WTF::notFound) ? -1 : index; |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 350 | } |
| 351 | |
mario@webkit.org | 5c96677 | 2012-01-24 18:48:50 +0000 | [diff] [blame] | 352 | static AtkAttributeSet* webkitAccessibleGetAttributes(AtkObject* object) |
eric@webkit.org | 8449619 | 2009-10-17 20:00:33 +0000 | [diff] [blame] | 353 | { |
mario@webkit.org | ff8cf0f | 2013-09-27 09:44:20 +0000 | [diff] [blame] | 354 | g_return_val_if_fail(WEBKIT_IS_ACCESSIBLE(object), 0); |
| 355 | returnValIfWebKitAccessibleIsInvalid(WEBKIT_ACCESSIBLE(object), 0); |
| 356 | |
commit-queue@webkit.org | 9a24e2d | 2015-05-29 04:53:35 +0000 | [diff] [blame] | 357 | AtkAttributeSet* attributeSet = nullptr; |
mario@webkit.org | 8c5dd90 | 2012-11-09 19:47:40 +0000 | [diff] [blame] | 358 | #if PLATFORM(GTK) |
mario@webkit.org | f8344ff | 2012-01-24 11:40:44 +0000 | [diff] [blame] | 359 | attributeSet = addToAtkAttributeSet(attributeSet, "toolkit", "WebKitGtk"); |
commit-queue@webkit.org | d994735 | 2012-12-05 17:56:12 +0000 | [diff] [blame] | 360 | #elif PLATFORM(EFL) |
| 361 | attributeSet = addToAtkAttributeSet(attributeSet, "toolkit", "WebKitEfl"); |
mario@webkit.org | 8c5dd90 | 2012-11-09 19:47:40 +0000 | [diff] [blame] | 362 | #endif |
eric@webkit.org | f4efc40 | 2010-05-15 09:55:52 +0000 | [diff] [blame] | 363 | |
commit-queue@webkit.org | a9398dd | 2010-10-26 19:19:29 +0000 | [diff] [blame] | 364 | AccessibilityObject* coreObject = core(object); |
| 365 | if (!coreObject) |
| 366 | return attributeSet; |
| 367 | |
commit-queue@webkit.org | 357dc22 | 2013-01-10 00:09:41 +0000 | [diff] [blame] | 368 | // Hack needed for WebKit2 tests because obtaining an element by its ID |
| 369 | // cannot be done from the UIProcess. Assistive technologies have no need |
| 370 | // for this information. |
jdiggs@igalia.com | bcff952 | 2014-11-28 00:24:43 +0000 | [diff] [blame] | 371 | Element* element = coreObject->element() ? coreObject->element() : coreObject->actionElement(); |
| 372 | if (element) { |
jdiggs@igalia.com | 5a8352d | 2015-06-17 20:03:13 +0000 | [diff] [blame] | 373 | String tagName = element->tagName(); |
| 374 | if (!tagName.isEmpty()) |
darin@apple.com | 4d716f2 | 2016-02-01 05:46:20 +0000 | [diff] [blame] | 375 | attributeSet = addToAtkAttributeSet(attributeSet, "tag", tagName.convertToASCIILowercase().utf8().data()); |
jdiggs@igalia.com | bcff952 | 2014-11-28 00:24:43 +0000 | [diff] [blame] | 376 | String id = element->getIdAttribute().string(); |
commit-queue@webkit.org | 357dc22 | 2013-01-10 00:09:41 +0000 | [diff] [blame] | 377 | if (!id.isEmpty()) |
| 378 | attributeSet = addToAtkAttributeSet(attributeSet, "html-id", id.utf8().data()); |
| 379 | } |
| 380 | |
commit-queue@webkit.org | a9398dd | 2010-10-26 19:19:29 +0000 | [diff] [blame] | 381 | int headingLevel = coreObject->headingLevel(); |
eric@webkit.org | 8449619 | 2009-10-17 20:00:33 +0000 | [diff] [blame] | 382 | if (headingLevel) { |
| 383 | String value = String::number(headingLevel); |
mario@webkit.org | f8344ff | 2012-01-24 11:40:44 +0000 | [diff] [blame] | 384 | attributeSet = addToAtkAttributeSet(attributeSet, "level", value.utf8().data()); |
eric@webkit.org | 8449619 | 2009-10-17 20:00:33 +0000 | [diff] [blame] | 385 | } |
commit-queue@webkit.org | a9398dd | 2010-10-26 19:19:29 +0000 | [diff] [blame] | 386 | |
jdiggs@igalia.com | 6b8c173 | 2015-01-28 17:02:32 +0000 | [diff] [blame] | 387 | if (coreObject->roleValue() == MathElementRole) { |
| 388 | if (coreObject->isMathMultiscriptObject(PreSuperscript) || coreObject->isMathMultiscriptObject(PreSubscript)) |
| 389 | attributeSet = addToAtkAttributeSet(attributeSet, "multiscript-type", "pre"); |
| 390 | else if (coreObject->isMathMultiscriptObject(PostSuperscript) || coreObject->isMathMultiscriptObject(PostSubscript)) |
| 391 | attributeSet = addToAtkAttributeSet(attributeSet, "multiscript-type", "post"); |
| 392 | } |
| 393 | |
commit-queue@webkit.org | a9398dd | 2010-10-26 19:19:29 +0000 | [diff] [blame] | 394 | // Set the 'layout-guess' attribute to help Assistive |
| 395 | // Technologies know when an exposed table is not data table. |
cdumez@apple.com | b04d574 | 2014-10-22 21:45:20 +0000 | [diff] [blame] | 396 | if (is<AccessibilityTable>(*coreObject) && downcast<AccessibilityTable>(*coreObject).isExposableThroughAccessibility() && !coreObject->isDataTable()) |
mario@webkit.org | f8344ff | 2012-01-24 11:40:44 +0000 | [diff] [blame] | 397 | attributeSet = addToAtkAttributeSet(attributeSet, "layout-guess", "true"); |
commit-queue@webkit.org | a9398dd | 2010-10-26 19:19:29 +0000 | [diff] [blame] | 398 | |
commit-queue@webkit.org | 2db4aaa | 2012-12-10 01:09:32 +0000 | [diff] [blame] | 399 | String placeholder = coreObject->placeholderValue(); |
| 400 | if (!placeholder.isEmpty()) |
| 401 | attributeSet = addToAtkAttributeSet(attributeSet, "placeholder-text", placeholder.utf8().data()); |
| 402 | |
commit-queue@webkit.org | 5945f76 | 2013-07-16 12:55:56 +0000 | [diff] [blame] | 403 | if (coreObject->ariaHasPopup()) |
mario@webkit.org | e2f7e78 | 2013-09-18 08:28:59 +0000 | [diff] [blame] | 404 | attributeSet = addToAtkAttributeSet(attributeSet, "haspopup", "true"); |
commit-queue@webkit.org | 5945f76 | 2013-07-16 12:55:56 +0000 | [diff] [blame] | 405 | |
commit-queue@webkit.org | 88d00b6 | 2013-09-03 11:29:33 +0000 | [diff] [blame] | 406 | AccessibilitySortDirection sortDirection = coreObject->sortDirection(); |
mario@webkit.org | e2f7e78 | 2013-09-18 08:28:59 +0000 | [diff] [blame] | 407 | if (sortDirection != SortDirectionNone) { |
mario@webkit.org | 9bf8261 | 2013-09-27 08:58:08 +0000 | [diff] [blame] | 408 | // WAI-ARIA spec says to translate the value as is from the attribute. |
| 409 | const AtomicString& sortAttribute = coreObject->getAttribute(HTMLNames::aria_sortAttr); |
| 410 | attributeSet = addToAtkAttributeSet(attributeSet, "sort", sortAttribute.string().utf8().data()); |
mario@webkit.org | e2f7e78 | 2013-09-18 08:28:59 +0000 | [diff] [blame] | 411 | } |
commit-queue@webkit.org | 88d00b6 | 2013-09-03 11:29:33 +0000 | [diff] [blame] | 412 | |
k.czech@samsung.com | dcc76c7 | 2014-03-11 09:04:08 +0000 | [diff] [blame] | 413 | if (coreObject->supportsARIAPosInSet()) |
| 414 | attributeSet = addToAtkAttributeSet(attributeSet, "posinset", String::number(coreObject->ariaPosInSet()).utf8().data()); |
| 415 | |
| 416 | if (coreObject->supportsARIASetSize()) |
| 417 | attributeSet = addToAtkAttributeSet(attributeSet, "setsize", String::number(coreObject->ariaSetSize()).utf8().data()); |
| 418 | |
jdiggs@igalia.com | 23022cc | 2016-05-11 07:14:31 +0000 | [diff] [blame] | 419 | String isReadOnly = coreObject->ariaReadOnlyValue(); |
| 420 | if (!isReadOnly.isEmpty()) |
| 421 | attributeSet = addToAtkAttributeSet(attributeSet, "readonly", isReadOnly.utf8().data()); |
| 422 | |
jdiggs@igalia.com | 6ccb778 | 2016-05-18 18:57:33 +0000 | [diff] [blame] | 423 | String valueDescription = coreObject->valueDescription(); |
| 424 | if (!valueDescription.isEmpty()) |
| 425 | attributeSet = addToAtkAttributeSet(attributeSet, "valuetext", valueDescription.utf8().data()); |
| 426 | |
jdiggs@igalia.com | 55b9262 | 2015-05-22 06:12:05 +0000 | [diff] [blame] | 427 | // According to the W3C Core Accessibility API Mappings 1.1, section 5.4.1 General Rules: |
| 428 | // "User agents must expose the WAI-ARIA role string if the API supports a mechanism to do so." |
| 429 | // In the case of ATK, the mechanism to do so is an object attribute pair (xml-roles:"string"). |
| 430 | // The computedRoleString is primarily for testing, and not limited to elements with ARIA roles. |
| 431 | // Because the computedRoleString currently contains the ARIA role string, we'll use it for |
| 432 | // both purposes, as the "computed-role" object attribute for all elements which have a value |
| 433 | // and also via the "xml-roles" attribute for elements with ARIA, as well as for landmarks. |
| 434 | String roleString = coreObject->computedRoleString(); |
| 435 | if (!roleString.isEmpty()) { |
| 436 | if (coreObject->ariaRoleAttribute() != UnknownRole || coreObject->isLandmark()) |
| 437 | attributeSet = addToAtkAttributeSet(attributeSet, "xml-roles", roleString.utf8().data()); |
| 438 | attributeSet = addToAtkAttributeSet(attributeSet, "computed-role", roleString.utf8().data()); |
mario.prada@samsung.com | e10ceaa | 2013-12-11 19:49:39 +0000 | [diff] [blame] | 439 | } |
| 440 | |
jdiggs@igalia.com | 9cef8aa | 2016-04-29 16:44:30 +0000 | [diff] [blame] | 441 | String roleDescription = coreObject->roleDescription(); |
| 442 | if (!roleDescription.isEmpty()) |
| 443 | attributeSet = addToAtkAttributeSet(attributeSet, "roledescription", roleDescription.utf8().data()); |
| 444 | |
eric@webkit.org | 8449619 | 2009-10-17 20:00:33 +0000 | [diff] [blame] | 445 | return attributeSet; |
| 446 | } |
| 447 | |
mario.prada@samsung.com | 4fb934b | 2013-12-17 18:08:34 +0000 | [diff] [blame] | 448 | static AtkRole atkRole(AccessibilityObject* coreObject) |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 449 | { |
mario.prada@samsung.com | 4fb934b | 2013-12-17 18:08:34 +0000 | [diff] [blame] | 450 | AccessibilityRole role = coreObject->roleValue(); |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 451 | switch (role) { |
mario.prada@samsung.com | 810148f | 2013-12-10 20:11:18 +0000 | [diff] [blame] | 452 | case ApplicationAlertDialogRole: |
commit-queue@webkit.org | b68dfdf | 2013-12-06 13:58:38 +0000 | [diff] [blame] | 453 | case ApplicationAlertRole: |
| 454 | return ATK_ROLE_ALERT; |
| 455 | case ApplicationDialogRole: |
commit-queue@webkit.org | b68dfdf | 2013-12-06 13:58:38 +0000 | [diff] [blame] | 456 | return ATK_ROLE_DIALOG; |
| 457 | case ApplicationStatusRole: |
| 458 | return ATK_ROLE_STATUSBAR; |
xan@webkit.org | 0ea2f73 | 2009-04-27 21:56:05 +0000 | [diff] [blame] | 459 | case UnknownRole: |
| 460 | return ATK_ROLE_UNKNOWN; |
mario@webkit.org | 5323952 | 2013-11-07 11:12:23 +0000 | [diff] [blame] | 461 | case AudioRole: |
jdiggs@igalia.com | c7a2f56 | 2014-11-16 07:32:08 +0000 | [diff] [blame] | 462 | #if ATK_CHECK_VERSION(2, 11, 3) |
| 463 | return ATK_ROLE_AUDIO; |
| 464 | #endif |
mario@webkit.org | 5323952 | 2013-11-07 11:12:23 +0000 | [diff] [blame] | 465 | case VideoRole: |
jdiggs@igalia.com | c7a2f56 | 2014-11-16 07:32:08 +0000 | [diff] [blame] | 466 | #if ATK_CHECK_VERSION(2, 11, 3) |
| 467 | return ATK_ROLE_VIDEO; |
| 468 | #endif |
mario@webkit.org | 5323952 | 2013-11-07 11:12:23 +0000 | [diff] [blame] | 469 | return ATK_ROLE_EMBEDDED; |
xan@webkit.org | 0ea2f73 | 2009-04-27 21:56:05 +0000 | [diff] [blame] | 470 | case ButtonRole: |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 471 | return ATK_ROLE_PUSH_BUTTON; |
jdiggs@igalia.com | 26fff3c | 2015-02-25 01:43:42 +0000 | [diff] [blame] | 472 | case SwitchRole: |
commit-queue@webkit.org | 6152cb9 | 2012-08-23 00:36:06 +0000 | [diff] [blame] | 473 | case ToggleButtonRole: |
| 474 | return ATK_ROLE_TOGGLE_BUTTON; |
xan@webkit.org | 0ea2f73 | 2009-04-27 21:56:05 +0000 | [diff] [blame] | 475 | case RadioButtonRole: |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 476 | return ATK_ROLE_RADIO_BUTTON; |
xan@webkit.org | 0ea2f73 | 2009-04-27 21:56:05 +0000 | [diff] [blame] | 477 | case CheckBoxRole: |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 478 | return ATK_ROLE_CHECK_BOX; |
xan@webkit.org | 0ea2f73 | 2009-04-27 21:56:05 +0000 | [diff] [blame] | 479 | case SliderRole: |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 480 | return ATK_ROLE_SLIDER; |
xan@webkit.org | 0ea2f73 | 2009-04-27 21:56:05 +0000 | [diff] [blame] | 481 | case TabGroupRole: |
commit-queue@webkit.org | 5255389 | 2012-12-13 15:43:38 +0000 | [diff] [blame] | 482 | case TabListRole: |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 483 | return ATK_ROLE_PAGE_TAB_LIST; |
xan@webkit.org | 0ea2f73 | 2009-04-27 21:56:05 +0000 | [diff] [blame] | 484 | case TextFieldRole: |
| 485 | case TextAreaRole: |
jdiggs@igalia.com | 2588aa1 | 2015-02-25 10:04:16 +0000 | [diff] [blame] | 486 | case SearchFieldRole: |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 487 | return ATK_ROLE_ENTRY; |
xan@webkit.org | 0ea2f73 | 2009-04-27 21:56:05 +0000 | [diff] [blame] | 488 | case StaticTextRole: |
jdiggs@igalia.com | 12f11cb | 2016-04-29 13:08:03 +0000 | [diff] [blame] | 489 | #if ATK_CHECK_VERSION(2, 15, 2) |
| 490 | return ATK_ROLE_STATIC; |
| 491 | #else |
xan@webkit.org | 0ea2f73 | 2009-04-27 21:56:05 +0000 | [diff] [blame] | 492 | return ATK_ROLE_TEXT; |
jdiggs@igalia.com | 12f11cb | 2016-04-29 13:08:03 +0000 | [diff] [blame] | 493 | #endif |
xan@webkit.org | 0ea2f73 | 2009-04-27 21:56:05 +0000 | [diff] [blame] | 494 | case OutlineRole: |
commit-queue@webkit.org | b68dfdf | 2013-12-06 13:58:38 +0000 | [diff] [blame] | 495 | case TreeRole: |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 496 | return ATK_ROLE_TREE; |
commit-queue@webkit.org | b68dfdf | 2013-12-06 13:58:38 +0000 | [diff] [blame] | 497 | case TreeItemRole: |
| 498 | return ATK_ROLE_TREE_ITEM; |
xan@webkit.org | 0ea2f73 | 2009-04-27 21:56:05 +0000 | [diff] [blame] | 499 | case MenuBarRole: |
| 500 | return ATK_ROLE_MENU_BAR; |
eric@webkit.org | a066929 | 2010-04-22 14:36:19 +0000 | [diff] [blame] | 501 | case MenuListPopupRole: |
xan@webkit.org | 0ea2f73 | 2009-04-27 21:56:05 +0000 | [diff] [blame] | 502 | case MenuRole: |
| 503 | return ATK_ROLE_MENU; |
eric@webkit.org | a066929 | 2010-04-22 14:36:19 +0000 | [diff] [blame] | 504 | case MenuListOptionRole: |
xan@webkit.org | 0ea2f73 | 2009-04-27 21:56:05 +0000 | [diff] [blame] | 505 | case MenuItemRole: |
| 506 | return ATK_ROLE_MENU_ITEM; |
mario.prada@samsung.com | 092b72a | 2013-12-16 15:58:34 +0000 | [diff] [blame] | 507 | case MenuItemCheckboxRole: |
| 508 | return ATK_ROLE_CHECK_MENU_ITEM; |
commit-queue@webkit.org | 413f75b | 2013-09-11 11:31:14 +0000 | [diff] [blame] | 509 | case MenuItemRadioRole: |
| 510 | return ATK_ROLE_RADIO_MENU_ITEM; |
xan@webkit.org | 0ea2f73 | 2009-04-27 21:56:05 +0000 | [diff] [blame] | 511 | case ColumnRole: |
mario@webkit.org | 9adab66 | 2012-01-23 10:21:03 +0000 | [diff] [blame] | 512 | // return ATK_ROLE_TABLE_COLUMN_HEADER; // Is this right? |
xan@webkit.org | 0ea2f73 | 2009-04-27 21:56:05 +0000 | [diff] [blame] | 513 | return ATK_ROLE_UNKNOWN; // Matches Mozilla |
| 514 | case RowRole: |
jdiggs@igalia.com | e8a090d | 2014-12-03 02:02:36 +0000 | [diff] [blame] | 515 | return ATK_ROLE_TABLE_ROW; |
xan@webkit.org | 0ea2f73 | 2009-04-27 21:56:05 +0000 | [diff] [blame] | 516 | case ToolbarRole: |
| 517 | return ATK_ROLE_TOOL_BAR; |
| 518 | case BusyIndicatorRole: |
| 519 | return ATK_ROLE_PROGRESS_BAR; // Is this right? |
| 520 | case ProgressIndicatorRole: |
jdiggs@igalia.com | 6ccb778 | 2016-05-18 18:57:33 +0000 | [diff] [blame] | 521 | return coreObject->isMeter() ? ATK_ROLE_LEVEL_BAR : ATK_ROLE_PROGRESS_BAR; |
xan@webkit.org | 0ea2f73 | 2009-04-27 21:56:05 +0000 | [diff] [blame] | 522 | case WindowRole: |
| 523 | return ATK_ROLE_WINDOW; |
eric@webkit.org | a066929 | 2010-04-22 14:36:19 +0000 | [diff] [blame] | 524 | case PopUpButtonRole: |
xan@webkit.org | 0ea2f73 | 2009-04-27 21:56:05 +0000 | [diff] [blame] | 525 | case ComboBoxRole: |
| 526 | return ATK_ROLE_COMBO_BOX; |
| 527 | case SplitGroupRole: |
| 528 | return ATK_ROLE_SPLIT_PANE; |
| 529 | case SplitterRole: |
mario.prada@samsung.com | ae97a65 | 2013-12-10 20:12:56 +0000 | [diff] [blame] | 530 | return ATK_ROLE_SEPARATOR; |
xan@webkit.org | 0ea2f73 | 2009-04-27 21:56:05 +0000 | [diff] [blame] | 531 | case ColorWellRole: |
jdiggs@igalia.com | feb6f00 | 2015-02-24 17:20:01 +0000 | [diff] [blame] | 532 | #if PLATFORM(GTK) |
| 533 | // ATK_ROLE_COLOR_CHOOSER is defined as a dialog (i.e. it's what appears when you push the button). |
| 534 | return ATK_ROLE_PUSH_BUTTON; |
| 535 | #elif PLATFORM(EFL) |
xan@webkit.org | 0ea2f73 | 2009-04-27 21:56:05 +0000 | [diff] [blame] | 536 | return ATK_ROLE_COLOR_CHOOSER; |
jdiggs@igalia.com | feb6f00 | 2015-02-24 17:20:01 +0000 | [diff] [blame] | 537 | #endif |
xan@webkit.org | 0ea2f73 | 2009-04-27 21:56:05 +0000 | [diff] [blame] | 538 | case ListRole: |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 539 | return ATK_ROLE_LIST; |
xan@webkit.org | 0ea2f73 | 2009-04-27 21:56:05 +0000 | [diff] [blame] | 540 | case ScrollBarRole: |
| 541 | return ATK_ROLE_SCROLL_BAR; |
mario@webkit.org | 86390a1 | 2011-01-07 17:34:02 +0000 | [diff] [blame] | 542 | case ScrollAreaRole: |
| 543 | return ATK_ROLE_SCROLL_PANE; |
jdiggs@igalia.com | 99deeb3 | 2015-12-08 11:07:11 +0000 | [diff] [blame] | 544 | case GridRole: |
xan@webkit.org | 0ea2f73 | 2009-04-27 21:56:05 +0000 | [diff] [blame] | 545 | case TableRole: |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 546 | return ATK_ROLE_TABLE; |
xan@webkit.org | 0ea2f73 | 2009-04-27 21:56:05 +0000 | [diff] [blame] | 547 | case ApplicationRole: |
| 548 | return ATK_ROLE_APPLICATION; |
xan@webkit.org | 0ea2f73 | 2009-04-27 21:56:05 +0000 | [diff] [blame] | 549 | case RadioGroupRole: |
jdiggs@igalia.com | 2f555dc | 2016-03-05 21:35:57 +0000 | [diff] [blame] | 550 | case SVGRootRole: |
commit-queue@webkit.org | 5255389 | 2012-12-13 15:43:38 +0000 | [diff] [blame] | 551 | case TabPanelRole: |
xan@webkit.org | 0ea2f73 | 2009-04-27 21:56:05 +0000 | [diff] [blame] | 552 | return ATK_ROLE_PANEL; |
jdiggs@igalia.com | 6bb2ed4 | 2016-04-06 19:13:50 +0000 | [diff] [blame] | 553 | case GroupRole: |
| 554 | return coreObject->isStyleFormatGroup() ? ATK_ROLE_SECTION : ATK_ROLE_PANEL; |
commit-queue@webkit.org | c150a07 | 2014-10-10 08:32:58 +0000 | [diff] [blame] | 555 | case RowHeaderRole: |
| 556 | return ATK_ROLE_ROW_HEADER; |
| 557 | case ColumnHeaderRole: |
| 558 | return ATK_ROLE_COLUMN_HEADER; |
jdiggs@igalia.com | e8a090d | 2014-12-03 02:02:36 +0000 | [diff] [blame] | 559 | case CaptionRole: |
| 560 | return ATK_ROLE_CAPTION; |
xan@webkit.org | 0ea2f73 | 2009-04-27 21:56:05 +0000 | [diff] [blame] | 561 | case CellRole: |
jdiggs@igalia.com | 99deeb3 | 2015-12-08 11:07:11 +0000 | [diff] [blame] | 562 | case GridCellRole: |
jdiggs@igalia.com | 63bfc54 | 2014-06-05 23:53:17 +0000 | [diff] [blame] | 563 | return coreObject->inheritsPresentationalRole() ? ATK_ROLE_SECTION : ATK_ROLE_TABLE_CELL; |
xan@webkit.org | 0ea2f73 | 2009-04-27 21:56:05 +0000 | [diff] [blame] | 564 | case LinkRole: |
| 565 | case WebCoreLinkRole: |
| 566 | case ImageMapLinkRole: |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 567 | return ATK_ROLE_LINK; |
xan@webkit.org | 0ea2f73 | 2009-04-27 21:56:05 +0000 | [diff] [blame] | 568 | case ImageMapRole: |
jdiggs@igalia.com | 51d2ebf | 2014-11-22 18:18:11 +0000 | [diff] [blame] | 569 | return ATK_ROLE_IMAGE_MAP; |
xan@webkit.org | 0ea2f73 | 2009-04-27 21:56:05 +0000 | [diff] [blame] | 570 | case ImageRole: |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 571 | return ATK_ROLE_IMAGE; |
xan@webkit.org | 0ea2f73 | 2009-04-27 21:56:05 +0000 | [diff] [blame] | 572 | case ListMarkerRole: |
jmalonzo@webkit.org | ad9783b | 2009-05-23 22:22:52 +0000 | [diff] [blame] | 573 | return ATK_ROLE_TEXT; |
commit-queue@webkit.org | b68dfdf | 2013-12-06 13:58:38 +0000 | [diff] [blame] | 574 | case DocumentArticleRole: |
mario.prada@samsung.com | 2a1d562 | 2013-12-16 15:17:58 +0000 | [diff] [blame] | 575 | #if ATK_CHECK_VERSION(2, 11, 3) |
| 576 | return ATK_ROLE_ARTICLE; |
| 577 | #endif |
| 578 | case DocumentRole: |
xan@webkit.org | 0ea2f73 | 2009-04-27 21:56:05 +0000 | [diff] [blame] | 579 | return ATK_ROLE_DOCUMENT_FRAME; |
mario.prada@samsung.com | c4a5eca | 2013-12-16 16:18:30 +0000 | [diff] [blame] | 580 | case DocumentNoteRole: |
| 581 | return ATK_ROLE_COMMENT; |
xan@webkit.org | 0ea2f73 | 2009-04-27 21:56:05 +0000 | [diff] [blame] | 582 | case HeadingRole: |
| 583 | return ATK_ROLE_HEADING; |
| 584 | case ListBoxRole: |
jdiggs@igalia.com | b0b6255 | 2016-11-19 21:12:24 +0000 | [diff] [blame^] | 585 | // https://rawgit.com/w3c/aria/master/core-aam/core-aam.html#role-map-listbox |
| 586 | return coreObject->isDescendantOfRole(ComboBoxRole) ? ATK_ROLE_MENU : ATK_ROLE_LIST_BOX; |
cfleizach@apple.com | 432ee57 | 2010-06-15 06:17:18 +0000 | [diff] [blame] | 587 | case ListItemRole: |
jdiggs@igalia.com | 63bfc54 | 2014-06-05 23:53:17 +0000 | [diff] [blame] | 588 | return coreObject->inheritsPresentationalRole() ? ATK_ROLE_SECTION : ATK_ROLE_LIST_ITEM; |
xan@webkit.org | 0ea2f73 | 2009-04-27 21:56:05 +0000 | [diff] [blame] | 589 | case ListBoxOptionRole: |
jdiggs@igalia.com | b0b6255 | 2016-11-19 21:12:24 +0000 | [diff] [blame^] | 590 | return coreObject->isDescendantOfRole(ComboBoxRole) ? ATK_ROLE_MENU_ITEM : ATK_ROLE_LIST_ITEM; |
mario@webkit.org | 56f6bf2 | 2011-03-30 16:51:08 +0000 | [diff] [blame] | 591 | case ParagraphRole: |
| 592 | return ATK_ROLE_PARAGRAPH; |
| 593 | case LabelRole: |
commit-queue@webkit.org | 802c012 | 2012-09-11 01:41:27 +0000 | [diff] [blame] | 594 | case LegendRole: |
mario@webkit.org | 56f6bf2 | 2011-03-30 16:51:08 +0000 | [diff] [blame] | 595 | return ATK_ROLE_LABEL; |
jdiggs@igalia.com | abd4d5f | 2014-11-16 16:51:08 +0000 | [diff] [blame] | 596 | case BlockquoteRole: |
| 597 | #if ATK_CHECK_VERSION(2, 11, 3) |
| 598 | return ATK_ROLE_BLOCK_QUOTE; |
| 599 | #endif |
mario@webkit.org | 56f6bf2 | 2011-03-30 16:51:08 +0000 | [diff] [blame] | 600 | case DivRole: |
jdiggs@igalia.com | 7d43a73 | 2015-05-07 17:30:00 +0000 | [diff] [blame] | 601 | case PreRole: |
jdiggs@igalia.com | 2f555dc | 2016-03-05 21:35:57 +0000 | [diff] [blame] | 602 | case SVGTextRole: |
mario@webkit.org | 56f6bf2 | 2011-03-30 16:51:08 +0000 | [diff] [blame] | 603 | return ATK_ROLE_SECTION; |
jdiggs@igalia.com | 45e9714 | 2014-11-16 07:26:41 +0000 | [diff] [blame] | 604 | case FooterRole: |
| 605 | return ATK_ROLE_FOOTER; |
mario@webkit.org | 56f6bf2 | 2011-03-30 16:51:08 +0000 | [diff] [blame] | 606 | case FormRole: |
| 607 | return ATK_ROLE_FORM; |
commit-queue@webkit.org | 52f6761 | 2012-09-07 05:09:04 +0000 | [diff] [blame] | 608 | case CanvasRole: |
| 609 | return ATK_ROLE_CANVAS; |
dmazzoni@google.com | f3cf2c4 | 2012-09-07 23:46:45 +0000 | [diff] [blame] | 610 | case HorizontalRuleRole: |
| 611 | return ATK_ROLE_SEPARATOR; |
commit-queue@webkit.org | c985400e | 2012-09-21 20:03:57 +0000 | [diff] [blame] | 612 | case SpinButtonRole: |
| 613 | return ATK_ROLE_SPIN_BUTTON; |
commit-queue@webkit.org | 5255389 | 2012-12-13 15:43:38 +0000 | [diff] [blame] | 614 | case TabRole: |
| 615 | return ATK_ROLE_PAGE_TAB; |
commit-queue@webkit.org | b68dfdf | 2013-12-06 13:58:38 +0000 | [diff] [blame] | 616 | case UserInterfaceTooltipRole: |
| 617 | return ATK_ROLE_TOOL_TIP; |
| 618 | case WebAreaRole: |
| 619 | return ATK_ROLE_DOCUMENT_WEB; |
jdiggs@igalia.com | 4ccb70f | 2016-04-09 01:19:07 +0000 | [diff] [blame] | 620 | case WebApplicationRole: |
mario.prada@samsung.com | e10ceaa | 2013-12-11 19:49:39 +0000 | [diff] [blame] | 621 | return ATK_ROLE_EMBEDDED; |
| 622 | #if ATK_CHECK_VERSION(2, 11, 3) |
mario.prada@samsung.com | c4a5eca | 2013-12-16 16:18:30 +0000 | [diff] [blame] | 623 | case ApplicationLogRole: |
| 624 | return ATK_ROLE_LOG; |
| 625 | case ApplicationMarqueeRole: |
| 626 | return ATK_ROLE_MARQUEE; |
| 627 | case ApplicationTimerRole: |
| 628 | return ATK_ROLE_TIMER; |
| 629 | case DefinitionRole: |
| 630 | return ATK_ROLE_DEFINITION; |
| 631 | case DocumentMathRole: |
| 632 | return ATK_ROLE_MATH; |
jdiggs@igalia.com | 0f83ca3 | 2014-12-09 18:31:53 +0000 | [diff] [blame] | 633 | case MathElementRole: |
| 634 | if (coreObject->isMathRow()) |
| 635 | return ATK_ROLE_PANEL; |
| 636 | if (coreObject->isMathTable()) |
| 637 | return ATK_ROLE_TABLE; |
| 638 | if (coreObject->isMathTableRow()) |
| 639 | return ATK_ROLE_TABLE_ROW; |
| 640 | if (coreObject->isMathTableCell()) |
| 641 | return ATK_ROLE_TABLE_CELL; |
jdiggs@igalia.com | 6b8c173 | 2015-01-28 17:02:32 +0000 | [diff] [blame] | 642 | if (coreObject->isMathSubscriptSuperscript() || coreObject->isMathMultiscript()) |
| 643 | return ATK_ROLE_SECTION; |
| 644 | #if ATK_CHECK_VERSION(2, 15, 4) |
| 645 | if (coreObject->isMathFraction()) |
| 646 | return ATK_ROLE_MATH_FRACTION; |
| 647 | if (coreObject->isMathSquareRoot() || coreObject->isMathRoot()) |
| 648 | return ATK_ROLE_MATH_ROOT; |
| 649 | if (coreObject->isMathScriptObject(Subscript) |
| 650 | || coreObject->isMathMultiscriptObject(PreSubscript) || coreObject->isMathMultiscriptObject(PostSubscript)) |
| 651 | return ATK_ROLE_SUBSCRIPT; |
| 652 | if (coreObject->isMathScriptObject(Superscript) |
| 653 | || coreObject->isMathMultiscriptObject(PreSuperscript) || coreObject->isMathMultiscriptObject(PostSuperscript)) |
| 654 | return ATK_ROLE_SUPERSCRIPT; |
| 655 | #endif |
jdiggs@igalia.com | 0f83ca3 | 2014-12-09 18:31:53 +0000 | [diff] [blame] | 656 | #if ATK_CHECK_VERSION(2, 15, 2) |
| 657 | if (coreObject->isMathToken()) |
| 658 | return ATK_ROLE_STATIC; |
| 659 | #endif |
| 660 | return ATK_ROLE_UNKNOWN; |
mario.prada@samsung.com | e10ceaa | 2013-12-11 19:49:39 +0000 | [diff] [blame] | 661 | case LandmarkBannerRole: |
| 662 | case LandmarkComplementaryRole: |
| 663 | case LandmarkContentInfoRole: |
| 664 | case LandmarkMainRole: |
| 665 | case LandmarkNavigationRole: |
jdiggs@igalia.com | 571fd1a6 | 2016-05-04 12:54:59 +0000 | [diff] [blame] | 666 | case LandmarkRegionRole: |
mario.prada@samsung.com | e10ceaa | 2013-12-11 19:49:39 +0000 | [diff] [blame] | 667 | case LandmarkSearchRole: |
| 668 | return ATK_ROLE_LANDMARK; |
| 669 | #endif |
mario.prada@samsung.com | 4fb934b | 2013-12-17 18:08:34 +0000 | [diff] [blame] | 670 | #if ATK_CHECK_VERSION(2, 11, 4) |
| 671 | case DescriptionListRole: |
| 672 | return ATK_ROLE_DESCRIPTION_LIST; |
| 673 | case DescriptionListTermRole: |
| 674 | return ATK_ROLE_DESCRIPTION_TERM; |
| 675 | case DescriptionListDetailRole: |
| 676 | return ATK_ROLE_DESCRIPTION_VALUE; |
| 677 | #endif |
jdiggs@igalia.com | 85721d1 | 2014-12-03 19:51:28 +0000 | [diff] [blame] | 678 | case InlineRole: |
jdiggs@igalia.com | 0ec0d33 | 2016-04-29 01:30:34 +0000 | [diff] [blame] | 679 | #if ATK_CHECK_VERSION(2, 15, 4) |
| 680 | if (coreObject->isSubscriptStyleGroup()) |
| 681 | return ATK_ROLE_SUBSCRIPT; |
| 682 | if (coreObject->isSuperscriptStyleGroup()) |
| 683 | return ATK_ROLE_SUPERSCRIPT; |
| 684 | #endif |
| 685 | #if ATK_CHECK_VERSION(2, 15, 2) |
| 686 | return ATK_ROLE_STATIC; |
jdiggs@igalia.com | 2f555dc | 2016-03-05 21:35:57 +0000 | [diff] [blame] | 687 | case SVGTextPathRole: |
| 688 | case SVGTSpanRole: |
jdiggs@igalia.com | 85721d1 | 2014-12-03 19:51:28 +0000 | [diff] [blame] | 689 | return ATK_ROLE_STATIC; |
| 690 | #endif |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 691 | default: |
| 692 | return ATK_ROLE_UNKNOWN; |
| 693 | } |
| 694 | } |
| 695 | |
mario@webkit.org | 5c96677 | 2012-01-24 18:48:50 +0000 | [diff] [blame] | 696 | static AtkRole webkitAccessibleGetRole(AtkObject* object) |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 697 | { |
jdiggs@igalia.com | 00e44c4 | 2014-11-13 22:11:41 +0000 | [diff] [blame] | 698 | // ATK_ROLE_UNKNOWN should only be applied in cases where there is a valid |
| 699 | // WebCore accessible object for which the platform role mapping is unknown. |
| 700 | g_return_val_if_fail(WEBKIT_IS_ACCESSIBLE(object), ATK_ROLE_INVALID); |
| 701 | returnValIfWebKitAccessibleIsInvalid(WEBKIT_ACCESSIBLE(object), ATK_ROLE_INVALID); |
mario@webkit.org | ff8cf0f | 2013-09-27 09:44:20 +0000 | [diff] [blame] | 702 | |
mario@webkit.org | 56f6bf2 | 2011-03-30 16:51:08 +0000 | [diff] [blame] | 703 | AccessibilityObject* coreObject = core(object); |
jmalonzo@webkit.org | 7ce3714 | 2009-05-20 11:16:01 +0000 | [diff] [blame] | 704 | |
mario@webkit.org | 56f6bf2 | 2011-03-30 16:51:08 +0000 | [diff] [blame] | 705 | if (!coreObject) |
jdiggs@igalia.com | 00e44c4 | 2014-11-13 22:11:41 +0000 | [diff] [blame] | 706 | return ATK_ROLE_INVALID; |
jmalonzo@webkit.org | 7ce3714 | 2009-05-20 11:16:01 +0000 | [diff] [blame] | 707 | |
| 708 | // Note: Why doesn't WebCore have a password field for this |
mario@webkit.org | 56f6bf2 | 2011-03-30 16:51:08 +0000 | [diff] [blame] | 709 | if (coreObject->isPasswordField()) |
jmalonzo@webkit.org | 7ce3714 | 2009-05-20 11:16:01 +0000 | [diff] [blame] | 710 | return ATK_ROLE_PASSWORD_TEXT; |
| 711 | |
mario.prada@samsung.com | 4fb934b | 2013-12-17 18:08:34 +0000 | [diff] [blame] | 712 | return atkRole(coreObject); |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 713 | } |
| 714 | |
mario@webkit.org | 6a24ba1 | 2010-12-14 15:35:22 +0000 | [diff] [blame] | 715 | static bool isTextWithCaret(AccessibilityObject* coreObject) |
| 716 | { |
| 717 | if (!coreObject || !coreObject->isAccessibilityRenderObject()) |
| 718 | return false; |
| 719 | |
| 720 | Document* document = coreObject->document(); |
| 721 | if (!document) |
| 722 | return false; |
| 723 | |
| 724 | Frame* frame = document->frame(); |
| 725 | if (!frame) |
| 726 | return false; |
| 727 | |
akling@apple.com | 1752350 | 2013-08-17 10:58:40 +0000 | [diff] [blame] | 728 | if (!frame->settings().caretBrowsingEnabled()) |
mario@webkit.org | 6a24ba1 | 2010-12-14 15:35:22 +0000 | [diff] [blame] | 729 | return false; |
| 730 | |
| 731 | // Check text objects and paragraphs only. |
| 732 | AtkObject* axObject = coreObject->wrapper(); |
| 733 | AtkRole role = axObject ? atk_object_get_role(axObject) : ATK_ROLE_INVALID; |
| 734 | if (role != ATK_ROLE_TEXT && role != ATK_ROLE_PARAGRAPH) |
| 735 | return false; |
| 736 | |
| 737 | // Finally, check whether the caret is set in the current object. |
| 738 | VisibleSelection selection = coreObject->selection(); |
| 739 | if (!selection.isCaret()) |
| 740 | return false; |
| 741 | |
| 742 | return selectionBelongsToObject(coreObject, selection); |
| 743 | } |
| 744 | |
xan@webkit.org | 8be15d6 | 2009-04-09 11:20:57 +0000 | [diff] [blame] | 745 | static void setAtkStateSetFromCoreObject(AccessibilityObject* coreObject, AtkStateSet* stateSet) |
| 746 | { |
eric@webkit.org | 2dd4734 | 2009-10-26 11:42:42 +0000 | [diff] [blame] | 747 | AccessibilityObject* parent = coreObject->parentObject(); |
| 748 | bool isListBoxOption = parent && parent->isListBox(); |
xan@webkit.org | 8be15d6 | 2009-04-09 11:20:57 +0000 | [diff] [blame] | 749 | |
eric@webkit.org | 2dd4734 | 2009-10-26 11:42:42 +0000 | [diff] [blame] | 750 | // Please keep the state list in alphabetical order |
commit-queue@webkit.org | c429926 | 2013-12-02 10:40:07 +0000 | [diff] [blame] | 751 | if (isListBoxOption && coreObject->isSelectedOptionActive()) |
| 752 | atk_state_set_add_state(stateSet, ATK_STATE_ACTIVE); |
| 753 | |
jdiggs@igalia.com | 77cdc2a | 2016-11-19 08:08:03 +0000 | [diff] [blame] | 754 | if (coreObject->isBusy()) |
| 755 | atk_state_set_add_state(stateSet, ATK_STATE_BUSY); |
| 756 | |
jdiggs@igalia.com | 23022cc | 2016-05-11 07:14:31 +0000 | [diff] [blame] | 757 | #if ATK_CHECK_VERSION(2,11,2) |
| 758 | if (coreObject->supportsChecked() && coreObject->canSetValueAttribute()) |
| 759 | atk_state_set_add_state(stateSet, ATK_STATE_CHECKABLE); |
| 760 | #endif |
| 761 | |
xan@webkit.org | 8be15d6 | 2009-04-09 11:20:57 +0000 | [diff] [blame] | 762 | if (coreObject->isChecked()) |
| 763 | atk_state_set_add_state(stateSet, ATK_STATE_CHECKED); |
| 764 | |
jdiggs@igalia.com | 23022cc | 2016-05-11 07:14:31 +0000 | [diff] [blame] | 765 | if ((coreObject->isTextControl() || coreObject->isNonNativeTextControl()) && coreObject->canSetValueAttribute()) |
xan@webkit.org | 8be15d6 | 2009-04-09 11:20:57 +0000 | [diff] [blame] | 766 | atk_state_set_add_state(stateSet, ATK_STATE_EDITABLE); |
| 767 | |
xan@webkit.org | df7d13a | 2009-06-26 09:12:44 +0000 | [diff] [blame] | 768 | // FIXME: Put both ENABLED and SENSITIVE together here for now |
| 769 | if (coreObject->isEnabled()) { |
xan@webkit.org | 8be15d6 | 2009-04-09 11:20:57 +0000 | [diff] [blame] | 770 | atk_state_set_add_state(stateSet, ATK_STATE_ENABLED); |
xan@webkit.org | df7d13a | 2009-06-26 09:12:44 +0000 | [diff] [blame] | 771 | atk_state_set_add_state(stateSet, ATK_STATE_SENSITIVE); |
| 772 | } |
xan@webkit.org | 8be15d6 | 2009-04-09 11:20:57 +0000 | [diff] [blame] | 773 | |
mario@webkit.org | 8ce6a15 | 2010-11-30 21:16:14 +0000 | [diff] [blame] | 774 | if (coreObject->canSetExpandedAttribute()) |
| 775 | atk_state_set_add_state(stateSet, ATK_STATE_EXPANDABLE); |
| 776 | |
| 777 | if (coreObject->isExpanded()) |
| 778 | atk_state_set_add_state(stateSet, ATK_STATE_EXPANDED); |
| 779 | |
xan@webkit.org | 8be15d6 | 2009-04-09 11:20:57 +0000 | [diff] [blame] | 780 | if (coreObject->canSetFocusAttribute()) |
| 781 | atk_state_set_add_state(stateSet, ATK_STATE_FOCUSABLE); |
| 782 | |
mario@webkit.org | 6a24ba1 | 2010-12-14 15:35:22 +0000 | [diff] [blame] | 783 | if (coreObject->isFocused() || isTextWithCaret(coreObject)) |
xan@webkit.org | 8be15d6 | 2009-04-09 11:20:57 +0000 | [diff] [blame] | 784 | atk_state_set_add_state(stateSet, ATK_STATE_FOCUSED); |
| 785 | |
commit-queue@webkit.org | 471dff5 | 2013-03-20 08:12:15 +0000 | [diff] [blame] | 786 | if (coreObject->orientation() == AccessibilityOrientationHorizontal) |
| 787 | atk_state_set_add_state(stateSet, ATK_STATE_HORIZONTAL); |
| 788 | else if (coreObject->orientation() == AccessibilityOrientationVertical) |
| 789 | atk_state_set_add_state(stateSet, ATK_STATE_VERTICAL); |
xan@webkit.org | 8be15d6 | 2009-04-09 11:20:57 +0000 | [diff] [blame] | 790 | |
| 791 | if (coreObject->isIndeterminate()) |
| 792 | atk_state_set_add_state(stateSet, ATK_STATE_INDETERMINATE); |
| 793 | |
k.czech@samsung.com | 43a8931 | 2014-01-07 11:28:04 +0000 | [diff] [blame] | 794 | if (coreObject->isCheckboxOrRadio() || coreObject->isMenuItem()) { |
| 795 | if (coreObject->checkboxOrRadioValue() == ButtonStateMixed) |
| 796 | atk_state_set_add_state(stateSet, ATK_STATE_INDETERMINATE); |
| 797 | } |
| 798 | |
mario@webkit.org | e0f00f1 | 2013-10-08 10:55:25 +0000 | [diff] [blame] | 799 | if (coreObject->invalidStatus() != "false") |
| 800 | atk_state_set_add_state(stateSet, ATK_STATE_INVALID_ENTRY); |
| 801 | |
jhoneycutt@apple.com | 8acea08 | 2010-01-14 01:16:15 +0000 | [diff] [blame] | 802 | if (coreObject->isMultiSelectable()) |
xan@webkit.org | 8be15d6 | 2009-04-09 11:20:57 +0000 | [diff] [blame] | 803 | atk_state_set_add_state(stateSet, ATK_STATE_MULTISELECTABLE); |
| 804 | |
| 805 | // TODO: ATK_STATE_OPAQUE |
| 806 | |
| 807 | if (coreObject->isPressed()) |
| 808 | atk_state_set_add_state(stateSet, ATK_STATE_PRESSED); |
| 809 | |
jdiggs@igalia.com | 23022cc | 2016-05-11 07:14:31 +0000 | [diff] [blame] | 810 | #if ATK_CHECK_VERSION(2,15,3) |
| 811 | if (!coreObject->canSetValueAttribute() && (coreObject->supportsARIAReadOnly())) |
| 812 | atk_state_set_add_state(stateSet, ATK_STATE_READ_ONLY); |
| 813 | #endif |
| 814 | |
commit-queue@webkit.org | 60f8d31 | 2013-06-21 10:33:34 +0000 | [diff] [blame] | 815 | if (coreObject->isRequired()) |
| 816 | atk_state_set_add_state(stateSet, ATK_STATE_REQUIRED); |
| 817 | |
xan@webkit.org | 8be15d6 | 2009-04-09 11:20:57 +0000 | [diff] [blame] | 818 | // TODO: ATK_STATE_SELECTABLE_TEXT |
| 819 | |
eric@webkit.org | 2dd4734 | 2009-10-26 11:42:42 +0000 | [diff] [blame] | 820 | if (coreObject->canSetSelectedAttribute()) { |
| 821 | atk_state_set_add_state(stateSet, ATK_STATE_SELECTABLE); |
mario@webkit.org | 8c5dd90 | 2012-11-09 19:47:40 +0000 | [diff] [blame] | 822 | // Items in focusable lists have both STATE_SELECT{ABLE,ED} |
| 823 | // and STATE_FOCUS{ABLE,ED}. We'll fake the latter based on |
| 824 | // the former. |
eric@webkit.org | 2dd4734 | 2009-10-26 11:42:42 +0000 | [diff] [blame] | 825 | if (isListBoxOption) |
| 826 | atk_state_set_add_state(stateSet, ATK_STATE_FOCUSABLE); |
| 827 | } |
| 828 | |
| 829 | if (coreObject->isSelected()) { |
xan@webkit.org | 8be15d6 | 2009-04-09 11:20:57 +0000 | [diff] [blame] | 830 | atk_state_set_add_state(stateSet, ATK_STATE_SELECTED); |
mario@webkit.org | 8c5dd90 | 2012-11-09 19:47:40 +0000 | [diff] [blame] | 831 | // Items in focusable lists have both STATE_SELECT{ABLE,ED} |
eric@webkit.org | 2dd4734 | 2009-10-26 11:42:42 +0000 | [diff] [blame] | 832 | // and STATE_FOCUS{ABLE,ED}. We'll fake the latter based on the |
| 833 | // former. |
| 834 | if (isListBoxOption) |
| 835 | atk_state_set_add_state(stateSet, ATK_STATE_FOCUSED); |
| 836 | } |
xan@webkit.org | 8be15d6 | 2009-04-09 11:20:57 +0000 | [diff] [blame] | 837 | |
xan@webkit.org | df7d13a | 2009-06-26 09:12:44 +0000 | [diff] [blame] | 838 | // FIXME: Group both SHOWING and VISIBLE here for now |
| 839 | // Not sure how to handle this in WebKit, see bug |
| 840 | // http://bugzilla.gnome.org/show_bug.cgi?id=509650 for other |
mario@webkit.org | 8c5dd90 | 2012-11-09 19:47:40 +0000 | [diff] [blame] | 841 | // issues with SHOWING vs VISIBLE. |
xan@webkit.org | df7d13a | 2009-06-26 09:12:44 +0000 | [diff] [blame] | 842 | if (!coreObject->isOffScreen()) { |
xan@webkit.org | 8be15d6 | 2009-04-09 11:20:57 +0000 | [diff] [blame] | 843 | atk_state_set_add_state(stateSet, ATK_STATE_SHOWING); |
xan@webkit.org | df7d13a | 2009-06-26 09:12:44 +0000 | [diff] [blame] | 844 | atk_state_set_add_state(stateSet, ATK_STATE_VISIBLE); |
| 845 | } |
xan@webkit.org | 8be15d6 | 2009-04-09 11:20:57 +0000 | [diff] [blame] | 846 | |
| 847 | // Mutually exclusive, so we group these two |
jdiggs@igalia.com | 18b89b8 | 2016-11-14 17:39:10 +0000 | [diff] [blame] | 848 | if (coreObject->roleValue() == TextAreaRole || coreObject->ariaIsMultiline()) |
xan@webkit.org | 8be15d6 | 2009-04-09 11:20:57 +0000 | [diff] [blame] | 849 | atk_state_set_add_state(stateSet, ATK_STATE_MULTI_LINE); |
jdiggs@igalia.com | 18b89b8 | 2016-11-14 17:39:10 +0000 | [diff] [blame] | 850 | else if (coreObject->roleValue() == TextFieldRole || coreObject->roleValue() == SearchFieldRole) |
| 851 | atk_state_set_add_state(stateSet, ATK_STATE_SINGLE_LINE); |
xan@webkit.org | 8be15d6 | 2009-04-09 11:20:57 +0000 | [diff] [blame] | 852 | |
| 853 | // TODO: ATK_STATE_SENSITIVE |
| 854 | |
xan@webkit.org | 8be15d6 | 2009-04-09 11:20:57 +0000 | [diff] [blame] | 855 | if (coreObject->isVisited()) |
| 856 | atk_state_set_add_state(stateSet, ATK_STATE_VISITED); |
| 857 | } |
| 858 | |
mario@webkit.org | 5c96677 | 2012-01-24 18:48:50 +0000 | [diff] [blame] | 859 | static AtkStateSet* webkitAccessibleRefStateSet(AtkObject* object) |
xan@webkit.org | 8be15d6 | 2009-04-09 11:20:57 +0000 | [diff] [blame] | 860 | { |
mario@webkit.org | ff8cf0f | 2013-09-27 09:44:20 +0000 | [diff] [blame] | 861 | g_return_val_if_fail(WEBKIT_IS_ACCESSIBLE(object), 0); |
| 862 | |
mario@webkit.org | f88ffcb | 2012-11-16 13:47:03 +0000 | [diff] [blame] | 863 | AtkStateSet* stateSet = ATK_OBJECT_CLASS(webkitAccessibleParentClass)->ref_state_set(object); |
xan@webkit.org | 8be15d6 | 2009-04-09 11:20:57 +0000 | [diff] [blame] | 864 | AccessibilityObject* coreObject = core(object); |
| 865 | |
mario@webkit.org | ff8cf0f | 2013-09-27 09:44:20 +0000 | [diff] [blame] | 866 | // Make sure the layout is updated to really know whether the object |
| 867 | // is defunct or not, so we can return the proper state. |
| 868 | coreObject->updateBackingStore(); |
| 869 | |
xan@webkit.org | 8be15d6 | 2009-04-09 11:20:57 +0000 | [diff] [blame] | 870 | if (coreObject == fallbackObject()) { |
| 871 | atk_state_set_add_state(stateSet, ATK_STATE_DEFUNCT); |
| 872 | return stateSet; |
| 873 | } |
| 874 | |
mario@webkit.org | 6a24ba1 | 2010-12-14 15:35:22 +0000 | [diff] [blame] | 875 | // Text objects must be focusable. |
| 876 | AtkRole role = atk_object_get_role(object); |
| 877 | if (role == ATK_ROLE_TEXT || role == ATK_ROLE_PARAGRAPH) |
| 878 | atk_state_set_add_state(stateSet, ATK_STATE_FOCUSABLE); |
xan@webkit.org | 8be15d6 | 2009-04-09 11:20:57 +0000 | [diff] [blame] | 879 | |
mario@webkit.org | 6a24ba1 | 2010-12-14 15:35:22 +0000 | [diff] [blame] | 880 | setAtkStateSetFromCoreObject(coreObject, stateSet); |
xan@webkit.org | 8be15d6 | 2009-04-09 11:20:57 +0000 | [diff] [blame] | 881 | return stateSet; |
| 882 | } |
| 883 | |
mario@webkit.org | 5c96677 | 2012-01-24 18:48:50 +0000 | [diff] [blame] | 884 | static AtkRelationSet* webkitAccessibleRefRelationSet(AtkObject* object) |
eric@webkit.org | 0f6cb45 | 2009-10-22 23:07:56 +0000 | [diff] [blame] | 885 | { |
mario@webkit.org | ff8cf0f | 2013-09-27 09:44:20 +0000 | [diff] [blame] | 886 | g_return_val_if_fail(WEBKIT_IS_ACCESSIBLE(object), 0); |
| 887 | returnValIfWebKitAccessibleIsInvalid(WEBKIT_ACCESSIBLE(object), 0); |
| 888 | |
mario@webkit.org | f88ffcb | 2012-11-16 13:47:03 +0000 | [diff] [blame] | 889 | AtkRelationSet* relationSet = ATK_OBJECT_CLASS(webkitAccessibleParentClass)->ref_relation_set(object); |
eric@webkit.org | 0f6cb45 | 2009-10-22 23:07:56 +0000 | [diff] [blame] | 890 | AccessibilityObject* coreObject = core(object); |
| 891 | |
| 892 | setAtkRelationSetFromCoreObject(coreObject, relationSet); |
| 893 | |
| 894 | return relationSet; |
| 895 | } |
| 896 | |
mario@webkit.org | 5c96677 | 2012-01-24 18:48:50 +0000 | [diff] [blame] | 897 | static void webkitAccessibleInit(AtkObject* object, gpointer data) |
xan@webkit.org | e438710 | 2009-04-09 11:08:48 +0000 | [diff] [blame] | 898 | { |
mario@webkit.org | f88ffcb | 2012-11-16 13:47:03 +0000 | [diff] [blame] | 899 | if (ATK_OBJECT_CLASS(webkitAccessibleParentClass)->initialize) |
| 900 | ATK_OBJECT_CLASS(webkitAccessibleParentClass)->initialize(object, data); |
xan@webkit.org | e438710 | 2009-04-09 11:08:48 +0000 | [diff] [blame] | 901 | |
mario@webkit.org | fecbacd | 2013-03-04 17:06:15 +0000 | [diff] [blame] | 902 | WebKitAccessible* accessible = WEBKIT_ACCESSIBLE(object); |
| 903 | accessible->m_object = reinterpret_cast<AccessibilityObject*>(data); |
| 904 | accessible->priv = WEBKIT_ACCESSIBLE_GET_PRIVATE(accessible); |
xan@webkit.org | e438710 | 2009-04-09 11:08:48 +0000 | [diff] [blame] | 905 | } |
| 906 | |
commit-queue@webkit.org | 120f565 | 2013-06-12 21:39:42 +0000 | [diff] [blame] | 907 | static const gchar* webkitAccessibleGetObjectLocale(AtkObject* object) |
| 908 | { |
mario@webkit.org | ff8cf0f | 2013-09-27 09:44:20 +0000 | [diff] [blame] | 909 | g_return_val_if_fail(WEBKIT_IS_ACCESSIBLE(object), 0); |
| 910 | returnValIfWebKitAccessibleIsInvalid(WEBKIT_ACCESSIBLE(object), 0); |
commit-queue@webkit.org | 120f565 | 2013-06-12 21:39:42 +0000 | [diff] [blame] | 911 | |
mario@webkit.org | ff8cf0f | 2013-09-27 09:44:20 +0000 | [diff] [blame] | 912 | AccessibilityObject* coreObject = core(object); |
| 913 | if (!coreObject) |
| 914 | return 0; |
| 915 | |
| 916 | if (ATK_IS_DOCUMENT(object)) { |
commit-queue@webkit.org | 120f565 | 2013-06-12 21:39:42 +0000 | [diff] [blame] | 917 | // TODO: Should we fall back on lang xml:lang when the following comes up empty? |
| 918 | String language = coreObject->language(); |
| 919 | if (!language.isEmpty()) |
| 920 | return cacheAndReturnAtkProperty(object, AtkCachedDocumentLocale, language); |
| 921 | |
| 922 | } else if (ATK_IS_TEXT(object)) { |
commit-queue@webkit.org | 9a24e2d | 2015-05-29 04:53:35 +0000 | [diff] [blame] | 923 | const gchar* locale = nullptr; |
commit-queue@webkit.org | 120f565 | 2013-06-12 21:39:42 +0000 | [diff] [blame] | 924 | |
| 925 | AtkAttributeSet* textAttributes = atk_text_get_default_attributes(ATK_TEXT(object)); |
commit-queue@webkit.org | 44a695d | 2013-07-04 12:10:45 +0000 | [diff] [blame] | 926 | for (AtkAttributeSet* attributes = textAttributes; attributes; attributes = attributes->next) { |
commit-queue@webkit.org | 120f565 | 2013-06-12 21:39:42 +0000 | [diff] [blame] | 927 | AtkAttribute* atkAttribute = static_cast<AtkAttribute*>(attributes->data); |
| 928 | if (!strcmp(atkAttribute->name, atk_text_attribute_get_name(ATK_TEXT_ATTR_LANGUAGE))) { |
| 929 | locale = cacheAndReturnAtkProperty(object, AtkCachedDocumentLocale, String::fromUTF8(atkAttribute->value)); |
| 930 | break; |
| 931 | } |
| 932 | } |
commit-queue@webkit.org | 120f565 | 2013-06-12 21:39:42 +0000 | [diff] [blame] | 933 | atk_attribute_set_free(textAttributes); |
| 934 | |
| 935 | return locale; |
| 936 | } |
| 937 | |
| 938 | return 0; |
| 939 | } |
| 940 | |
mario@webkit.org | 5c96677 | 2012-01-24 18:48:50 +0000 | [diff] [blame] | 941 | static void webkitAccessibleFinalize(GObject* object) |
xan@webkit.org | e438710 | 2009-04-09 11:08:48 +0000 | [diff] [blame] | 942 | { |
mario@webkit.org | f88ffcb | 2012-11-16 13:47:03 +0000 | [diff] [blame] | 943 | G_OBJECT_CLASS(webkitAccessibleParentClass)->finalize(object); |
xan@webkit.org | e438710 | 2009-04-09 11:08:48 +0000 | [diff] [blame] | 944 | } |
| 945 | |
mario@webkit.org | f88ffcb | 2012-11-16 13:47:03 +0000 | [diff] [blame] | 946 | static void webkitAccessibleClassInit(AtkObjectClass* klass) |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 947 | { |
xan@webkit.org | e438710 | 2009-04-09 11:08:48 +0000 | [diff] [blame] | 948 | GObjectClass* gobjectClass = G_OBJECT_CLASS(klass); |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 949 | |
mario@webkit.org | f88ffcb | 2012-11-16 13:47:03 +0000 | [diff] [blame] | 950 | webkitAccessibleParentClass = g_type_class_peek_parent(klass); |
xan@webkit.org | e438710 | 2009-04-09 11:08:48 +0000 | [diff] [blame] | 951 | |
mario@webkit.org | 5c96677 | 2012-01-24 18:48:50 +0000 | [diff] [blame] | 952 | gobjectClass->finalize = webkitAccessibleFinalize; |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 953 | |
mario@webkit.org | 5c96677 | 2012-01-24 18:48:50 +0000 | [diff] [blame] | 954 | klass->initialize = webkitAccessibleInit; |
| 955 | klass->get_name = webkitAccessibleGetName; |
| 956 | klass->get_description = webkitAccessibleGetDescription; |
| 957 | klass->get_parent = webkitAccessibleGetParent; |
| 958 | klass->get_n_children = webkitAccessibleGetNChildren; |
| 959 | klass->ref_child = webkitAccessibleRefChild; |
| 960 | klass->get_role = webkitAccessibleGetRole; |
| 961 | klass->ref_state_set = webkitAccessibleRefStateSet; |
| 962 | klass->get_index_in_parent = webkitAccessibleGetIndexInParent; |
| 963 | klass->get_attributes = webkitAccessibleGetAttributes; |
| 964 | klass->ref_relation_set = webkitAccessibleRefRelationSet; |
commit-queue@webkit.org | 120f565 | 2013-06-12 21:39:42 +0000 | [diff] [blame] | 965 | klass->get_object_locale = webkitAccessibleGetObjectLocale; |
mario@webkit.org | fecbacd | 2013-03-04 17:06:15 +0000 | [diff] [blame] | 966 | |
| 967 | g_type_class_add_private(klass, sizeof(WebKitAccessiblePrivate)); |
xan@webkit.org | e438710 | 2009-04-09 11:08:48 +0000 | [diff] [blame] | 968 | } |
| 969 | |
| 970 | GType |
mario@webkit.org | f88ffcb | 2012-11-16 13:47:03 +0000 | [diff] [blame] | 971 | webkitAccessibleGetType(void) |
xan@webkit.org | e438710 | 2009-04-09 11:08:48 +0000 | [diff] [blame] | 972 | { |
mario@webkit.org | f88ffcb | 2012-11-16 13:47:03 +0000 | [diff] [blame] | 973 | static volatile gsize typeVolatile = 0; |
xan@webkit.org | e438710 | 2009-04-09 11:08:48 +0000 | [diff] [blame] | 974 | |
mario@webkit.org | f88ffcb | 2012-11-16 13:47:03 +0000 | [diff] [blame] | 975 | if (g_once_init_enter(&typeVolatile)) { |
xan@webkit.org | e438710 | 2009-04-09 11:08:48 +0000 | [diff] [blame] | 976 | static const GTypeInfo tinfo = { |
| 977 | sizeof(WebKitAccessibleClass), |
eric@webkit.org | 4ff6fd7 | 2009-11-10 09:53:33 +0000 | [diff] [blame] | 978 | (GBaseInitFunc) 0, |
| 979 | (GBaseFinalizeFunc) 0, |
mario@webkit.org | f88ffcb | 2012-11-16 13:47:03 +0000 | [diff] [blame] | 980 | (GClassInitFunc) webkitAccessibleClassInit, |
eric@webkit.org | 4ff6fd7 | 2009-11-10 09:53:33 +0000 | [diff] [blame] | 981 | (GClassFinalizeFunc) 0, |
| 982 | 0, /* class data */ |
xan@webkit.org | e438710 | 2009-04-09 11:08:48 +0000 | [diff] [blame] | 983 | sizeof(WebKitAccessible), /* instance size */ |
| 984 | 0, /* nb preallocs */ |
eric@webkit.org | 4ff6fd7 | 2009-11-10 09:53:33 +0000 | [diff] [blame] | 985 | (GInstanceInitFunc) 0, |
| 986 | 0 /* value table */ |
xan@webkit.org | e438710 | 2009-04-09 11:08:48 +0000 | [diff] [blame] | 987 | }; |
| 988 | |
mario@webkit.org | f88ffcb | 2012-11-16 13:47:03 +0000 | [diff] [blame] | 989 | GType type = g_type_register_static(ATK_TYPE_OBJECT, "WebKitAccessible", &tinfo, GTypeFlags(0)); |
| 990 | g_once_init_leave(&typeVolatile, type); |
xan@webkit.org | e438710 | 2009-04-09 11:08:48 +0000 | [diff] [blame] | 991 | } |
| 992 | |
mario@webkit.org | f88ffcb | 2012-11-16 13:47:03 +0000 | [diff] [blame] | 993 | return typeVolatile; |
alp@webkit.org | c773899 | 2008-05-27 02:48:14 +0000 | [diff] [blame] | 994 | } |
| 995 | |
xan@webkit.org | e438710 | 2009-04-09 11:08:48 +0000 | [diff] [blame] | 996 | static const GInterfaceInfo AtkInterfacesInitFunctions[] = { |
mario@webkit.org | deec839 | 2012-01-23 14:45:23 +0000 | [diff] [blame] | 997 | {reinterpret_cast<GInterfaceInitFunc>(webkitAccessibleActionInterfaceInit), 0, 0}, |
mario@webkit.org | 7e5931d | 2012-01-24 12:25:13 +0000 | [diff] [blame] | 998 | {reinterpret_cast<GInterfaceInitFunc>(webkitAccessibleSelectionInterfaceInit), 0, 0}, |
mario@webkit.org | fc51ca6 | 2012-01-24 11:47:51 +0000 | [diff] [blame] | 999 | {reinterpret_cast<GInterfaceInitFunc>(webkitAccessibleEditableTextInterfaceInit), 0, 0}, |
mario@webkit.org | 987d737 | 2012-01-24 18:02:08 +0000 | [diff] [blame] | 1000 | {reinterpret_cast<GInterfaceInitFunc>(webkitAccessibleTextInterfaceInit), 0, 0}, |
mario@webkit.org | be1ce55 | 2012-01-24 11:03:51 +0000 | [diff] [blame] | 1001 | {reinterpret_cast<GInterfaceInitFunc>(webkitAccessibleComponentInterfaceInit), 0, 0}, |
mario@webkit.org | da3e608 | 2012-01-24 12:04:16 +0000 | [diff] [blame] | 1002 | {reinterpret_cast<GInterfaceInitFunc>(webkitAccessibleImageInterfaceInit), 0, 0}, |
mario@webkit.org | cd9f1b3 | 2012-01-24 18:28:22 +0000 | [diff] [blame] | 1003 | {reinterpret_cast<GInterfaceInitFunc>(webkitAccessibleTableInterfaceInit), 0, 0}, |
k.czech@samsung.com | 2608de9 | 2014-02-27 11:28:31 +0000 | [diff] [blame] | 1004 | #if ATK_CHECK_VERSION(2,11,90) |
| 1005 | {reinterpret_cast<GInterfaceInitFunc>(webkitAccessibleTableCellInterfaceInit), 0, 0}, |
| 1006 | #endif |
mario@webkit.org | 7024353 | 2012-01-24 11:58:52 +0000 | [diff] [blame] | 1007 | {reinterpret_cast<GInterfaceInitFunc>(webkitAccessibleHypertextInterfaceInit), 0, 0}, |
mario@webkit.org | 4dbd982 | 2012-01-24 11:55:18 +0000 | [diff] [blame] | 1008 | {reinterpret_cast<GInterfaceInitFunc>(webkitAccessibleHyperlinkImplInterfaceInit), 0, 0}, |
mario@webkit.org | f8344ff | 2012-01-24 11:40:44 +0000 | [diff] [blame] | 1009 | {reinterpret_cast<GInterfaceInitFunc>(webkitAccessibleDocumentInterfaceInit), 0, 0}, |
mario@webkit.org | 980269e | 2012-01-24 16:22:57 +0000 | [diff] [blame] | 1010 | {reinterpret_cast<GInterfaceInitFunc>(webkitAccessibleValueInterfaceInit), 0, 0} |
xan@webkit.org | e438710 | 2009-04-09 11:08:48 +0000 | [diff] [blame] | 1011 | }; |
| 1012 | |
| 1013 | enum WAIType { |
k.czech@samsung.com | 3871a7a | 2014-02-27 14:22:14 +0000 | [diff] [blame] | 1014 | WAIAction, |
| 1015 | WAISelection, |
| 1016 | WAIEditableText, |
| 1017 | WAIText, |
| 1018 | WAIComponent, |
| 1019 | WAIImage, |
| 1020 | WAITable, |
k.czech@samsung.com | 2608de9 | 2014-02-27 11:28:31 +0000 | [diff] [blame] | 1021 | #if ATK_CHECK_VERSION(2,11,90) |
k.czech@samsung.com | 3871a7a | 2014-02-27 14:22:14 +0000 | [diff] [blame] | 1022 | WAITableCell, |
k.czech@samsung.com | 2608de9 | 2014-02-27 11:28:31 +0000 | [diff] [blame] | 1023 | #endif |
k.czech@samsung.com | 3871a7a | 2014-02-27 14:22:14 +0000 | [diff] [blame] | 1024 | WAIHypertext, |
| 1025 | WAIHyperlink, |
| 1026 | WAIDocument, |
| 1027 | WAIValue, |
xan@webkit.org | e438710 | 2009-04-09 11:08:48 +0000 | [diff] [blame] | 1028 | }; |
| 1029 | |
| 1030 | static GType GetAtkInterfaceTypeFromWAIType(WAIType type) |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 1031 | { |
mario@webkit.org | 7f95c62 | 2010-11-01 15:05:36 +0000 | [diff] [blame] | 1032 | switch (type) { |
k.czech@samsung.com | 3871a7a | 2014-02-27 14:22:14 +0000 | [diff] [blame] | 1033 | case WAIAction: |
mario@webkit.org | 7f95c62 | 2010-11-01 15:05:36 +0000 | [diff] [blame] | 1034 | return ATK_TYPE_ACTION; |
k.czech@samsung.com | 3871a7a | 2014-02-27 14:22:14 +0000 | [diff] [blame] | 1035 | case WAISelection: |
mario@webkit.org | 7f95c62 | 2010-11-01 15:05:36 +0000 | [diff] [blame] | 1036 | return ATK_TYPE_SELECTION; |
k.czech@samsung.com | 3871a7a | 2014-02-27 14:22:14 +0000 | [diff] [blame] | 1037 | case WAIEditableText: |
mario@webkit.org | 7f95c62 | 2010-11-01 15:05:36 +0000 | [diff] [blame] | 1038 | return ATK_TYPE_EDITABLE_TEXT; |
k.czech@samsung.com | 3871a7a | 2014-02-27 14:22:14 +0000 | [diff] [blame] | 1039 | case WAIText: |
mario@webkit.org | 7f95c62 | 2010-11-01 15:05:36 +0000 | [diff] [blame] | 1040 | return ATK_TYPE_TEXT; |
k.czech@samsung.com | 3871a7a | 2014-02-27 14:22:14 +0000 | [diff] [blame] | 1041 | case WAIComponent: |
mario@webkit.org | 7f95c62 | 2010-11-01 15:05:36 +0000 | [diff] [blame] | 1042 | return ATK_TYPE_COMPONENT; |
k.czech@samsung.com | 3871a7a | 2014-02-27 14:22:14 +0000 | [diff] [blame] | 1043 | case WAIImage: |
mario@webkit.org | 7f95c62 | 2010-11-01 15:05:36 +0000 | [diff] [blame] | 1044 | return ATK_TYPE_IMAGE; |
k.czech@samsung.com | 3871a7a | 2014-02-27 14:22:14 +0000 | [diff] [blame] | 1045 | case WAITable: |
mario@webkit.org | 7f95c62 | 2010-11-01 15:05:36 +0000 | [diff] [blame] | 1046 | return ATK_TYPE_TABLE; |
k.czech@samsung.com | 2608de9 | 2014-02-27 11:28:31 +0000 | [diff] [blame] | 1047 | #if ATK_CHECK_VERSION(2,11,90) |
k.czech@samsung.com | 3871a7a | 2014-02-27 14:22:14 +0000 | [diff] [blame] | 1048 | case WAITableCell: |
k.czech@samsung.com | 2608de9 | 2014-02-27 11:28:31 +0000 | [diff] [blame] | 1049 | return ATK_TYPE_TABLE_CELL; |
| 1050 | #endif |
k.czech@samsung.com | 3871a7a | 2014-02-27 14:22:14 +0000 | [diff] [blame] | 1051 | case WAIHypertext: |
mario@webkit.org | 7f95c62 | 2010-11-01 15:05:36 +0000 | [diff] [blame] | 1052 | return ATK_TYPE_HYPERTEXT; |
k.czech@samsung.com | 3871a7a | 2014-02-27 14:22:14 +0000 | [diff] [blame] | 1053 | case WAIHyperlink: |
mario@webkit.org | 7f95c62 | 2010-11-01 15:05:36 +0000 | [diff] [blame] | 1054 | return ATK_TYPE_HYPERLINK_IMPL; |
k.czech@samsung.com | 3871a7a | 2014-02-27 14:22:14 +0000 | [diff] [blame] | 1055 | case WAIDocument: |
mario@webkit.org | 7f95c62 | 2010-11-01 15:05:36 +0000 | [diff] [blame] | 1056 | return ATK_TYPE_DOCUMENT; |
k.czech@samsung.com | 3871a7a | 2014-02-27 14:22:14 +0000 | [diff] [blame] | 1057 | case WAIValue: |
mario@webkit.org | 04e38e9 | 2011-03-28 10:16:38 +0000 | [diff] [blame] | 1058 | return ATK_TYPE_VALUE; |
mario@webkit.org | 7f95c62 | 2010-11-01 15:05:36 +0000 | [diff] [blame] | 1059 | } |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 1060 | |
mario@webkit.org | 7f95c62 | 2010-11-01 15:05:36 +0000 | [diff] [blame] | 1061 | return G_TYPE_INVALID; |
xan@webkit.org | e438710 | 2009-04-09 11:08:48 +0000 | [diff] [blame] | 1062 | } |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 1063 | |
commit-queue@webkit.org | ca1b1d2 | 2012-08-22 01:37:04 +0000 | [diff] [blame] | 1064 | static bool roleIsTextType(AccessibilityRole role) |
| 1065 | { |
commit-queue@webkit.org | d8a8ec3 | 2014-06-13 16:12:27 +0000 | [diff] [blame] | 1066 | return role == ParagraphRole || role == HeadingRole || role == DivRole || role == CellRole |
jdiggs@igalia.com | 99deeb3 | 2015-12-08 11:07:11 +0000 | [diff] [blame] | 1067 | || role == LinkRole || role == WebCoreLinkRole || role == ListItemRole || role == PreRole |
| 1068 | || role == GridCellRole; |
commit-queue@webkit.org | ca1b1d2 | 2012-08-22 01:37:04 +0000 | [diff] [blame] | 1069 | } |
| 1070 | |
xan@webkit.org | e438710 | 2009-04-09 11:08:48 +0000 | [diff] [blame] | 1071 | static guint16 getInterfaceMaskFromObject(AccessibilityObject* coreObject) |
| 1072 | { |
| 1073 | guint16 interfaceMask = 0; |
alp@webkit.org | c773899 | 2008-05-27 02:48:14 +0000 | [diff] [blame] | 1074 | |
xan@webkit.org | 92b9169 | 2009-04-21 07:02:17 +0000 | [diff] [blame] | 1075 | // Component interface is always supported |
k.czech@samsung.com | 3871a7a | 2014-02-27 14:22:14 +0000 | [diff] [blame] | 1076 | interfaceMask |= 1 << WAIComponent; |
xan@webkit.org | 92b9169 | 2009-04-21 07:02:17 +0000 | [diff] [blame] | 1077 | |
mario@webkit.org | 7f95c62 | 2010-11-01 15:05:36 +0000 | [diff] [blame] | 1078 | AccessibilityRole role = coreObject->roleValue(); |
| 1079 | |
xan@webkit.org | b3c59bf | 2009-04-21 07:01:27 +0000 | [diff] [blame] | 1080 | // Action |
mario@webkit.org | 8ce6a15 | 2010-11-30 21:16:14 +0000 | [diff] [blame] | 1081 | // As the implementation of the AtkAction interface is a very |
| 1082 | // basic one (just relays in executing the default action for each |
| 1083 | // object, and only supports having one action per object), it is |
| 1084 | // better just to implement this interface for every instance of |
| 1085 | // the WebKitAccessible class and let WebCore decide what to do. |
k.czech@samsung.com | 3871a7a | 2014-02-27 14:22:14 +0000 | [diff] [blame] | 1086 | interfaceMask |= 1 << WAIAction; |
xan@webkit.org | b3c59bf | 2009-04-21 07:01:27 +0000 | [diff] [blame] | 1087 | |
eric@webkit.org | f84ff63 | 2009-10-29 17:34:39 +0000 | [diff] [blame] | 1088 | // Selection |
jdiggs@igalia.com | b0b6255 | 2016-11-19 21:12:24 +0000 | [diff] [blame^] | 1089 | if (coreObject->canHaveSelectedChildren() || coreObject->isMenuList()) |
k.czech@samsung.com | 3871a7a | 2014-02-27 14:22:14 +0000 | [diff] [blame] | 1090 | interfaceMask |= 1 << WAISelection; |
eric@webkit.org | f84ff63 | 2009-10-29 17:34:39 +0000 | [diff] [blame] | 1091 | |
mario@webkit.org | 9f0aee1 | 2011-04-11 21:02:23 +0000 | [diff] [blame] | 1092 | // Get renderer if available. |
commit-queue@webkit.org | 9a24e2d | 2015-05-29 04:53:35 +0000 | [diff] [blame] | 1093 | RenderObject* renderer = nullptr; |
mario@webkit.org | 9f0aee1 | 2011-04-11 21:02:23 +0000 | [diff] [blame] | 1094 | if (coreObject->isAccessibilityRenderObject()) |
| 1095 | renderer = coreObject->renderer(); |
| 1096 | |
| 1097 | // Hyperlink (links and embedded objects). |
| 1098 | if (coreObject->isLink() || (renderer && renderer->isReplaced())) |
k.czech@samsung.com | 3871a7a | 2014-02-27 14:22:14 +0000 | [diff] [blame] | 1099 | interfaceMask |= 1 << WAIHyperlink; |
mario@webkit.org | 9f0aee1 | 2011-04-11 21:02:23 +0000 | [diff] [blame] | 1100 | |
mario.prada@samsung.com | 56598be | 2014-04-09 15:05:58 +0000 | [diff] [blame] | 1101 | // Text, Editable Text & Hypertext |
mario@webkit.org | 8ce6a15 | 2010-11-30 21:16:14 +0000 | [diff] [blame] | 1102 | if (role == StaticTextRole || coreObject->isMenuListOption()) |
k.czech@samsung.com | 3871a7a | 2014-02-27 14:22:14 +0000 | [diff] [blame] | 1103 | interfaceMask |= 1 << WAIText; |
jdiggs@igalia.com | 23022cc | 2016-05-11 07:14:31 +0000 | [diff] [blame] | 1104 | else if (coreObject->isTextControl() || coreObject->isNonNativeTextControl()) { |
mario.prada@samsung.com | 56598be | 2014-04-09 15:05:58 +0000 | [diff] [blame] | 1105 | interfaceMask |= 1 << WAIText; |
jdiggs@igalia.com | 23022cc | 2016-05-11 07:14:31 +0000 | [diff] [blame] | 1106 | if (coreObject->canSetValueAttribute()) |
mario.prada@samsung.com | 56598be | 2014-04-09 15:05:58 +0000 | [diff] [blame] | 1107 | interfaceMask |= 1 << WAIEditableText; |
| 1108 | } else if (!coreObject->isWebArea()) { |
| 1109 | if (role != TableRole) { |
| 1110 | interfaceMask |= 1 << WAIHypertext; |
jdiggs@igalia.com | ad83c35 | 2014-12-10 19:57:33 +0000 | [diff] [blame] | 1111 | if ((renderer && renderer->childrenInline()) || roleIsTextType(role) || coreObject->isMathToken()) |
mario.prada@samsung.com | 56598be | 2014-04-09 15:05:58 +0000 | [diff] [blame] | 1112 | interfaceMask |= 1 << WAIText; |
| 1113 | } |
mario@webkit.org | 7f95c62 | 2010-11-01 15:05:36 +0000 | [diff] [blame] | 1114 | |
mario.prada@samsung.com | 56598be | 2014-04-09 15:05:58 +0000 | [diff] [blame] | 1115 | // Add the TEXT interface for list items whose |
| 1116 | // first accessible child has a text renderer |
| 1117 | if (role == ListItemRole) { |
| 1118 | const AccessibilityObject::AccessibilityChildrenVector& children = coreObject->children(); |
| 1119 | if (children.size()) { |
| 1120 | AccessibilityObject* axRenderChild = children.at(0).get(); |
| 1121 | interfaceMask |= getInterfaceMaskFromObject(axRenderChild); |
commit-queue@webkit.org | 1f3aafe | 2010-09-22 07:49:34 +0000 | [diff] [blame] | 1122 | } |
| 1123 | } |
mario@webkit.org | 7f95c62 | 2010-11-01 15:05:36 +0000 | [diff] [blame] | 1124 | } |
xan@webkit.org | e438710 | 2009-04-09 11:08:48 +0000 | [diff] [blame] | 1125 | |
xan@webkit.org | e43e70b | 2009-04-27 21:33:55 +0000 | [diff] [blame] | 1126 | // Image |
| 1127 | if (coreObject->isImage()) |
k.czech@samsung.com | 3871a7a | 2014-02-27 14:22:14 +0000 | [diff] [blame] | 1128 | interfaceMask |= 1 << WAIImage; |
xan@webkit.org | e43e70b | 2009-04-27 21:33:55 +0000 | [diff] [blame] | 1129 | |
xan@webkit.org | 45b26ac | 2009-10-27 12:20:35 +0000 | [diff] [blame] | 1130 | // Table |
jdiggs@igalia.com | 7382486 | 2015-12-08 16:02:50 +0000 | [diff] [blame] | 1131 | if (role == TableRole || role == GridRole) |
k.czech@samsung.com | 3871a7a | 2014-02-27 14:22:14 +0000 | [diff] [blame] | 1132 | interfaceMask |= 1 << WAITable; |
xan@webkit.org | 45b26ac | 2009-10-27 12:20:35 +0000 | [diff] [blame] | 1133 | |
k.czech@samsung.com | 2608de9 | 2014-02-27 11:28:31 +0000 | [diff] [blame] | 1134 | #if ATK_CHECK_VERSION(2,11,90) |
commit-queue@webkit.org | c150a07 | 2014-10-10 08:32:58 +0000 | [diff] [blame] | 1135 | if (role == CellRole || role == ColumnHeaderRole || role == RowHeaderRole) |
k.czech@samsung.com | 3871a7a | 2014-02-27 14:22:14 +0000 | [diff] [blame] | 1136 | interfaceMask |= 1 << WAITableCell; |
k.czech@samsung.com | 2608de9 | 2014-02-27 11:28:31 +0000 | [diff] [blame] | 1137 | #endif |
| 1138 | |
eric@webkit.org | 65e12ba | 2009-11-01 21:22:30 +0000 | [diff] [blame] | 1139 | // Document |
| 1140 | if (role == WebAreaRole) |
k.czech@samsung.com | 3871a7a | 2014-02-27 14:22:14 +0000 | [diff] [blame] | 1141 | interfaceMask |= 1 << WAIDocument; |
eric@webkit.org | 65e12ba | 2009-11-01 21:22:30 +0000 | [diff] [blame] | 1142 | |
mario@webkit.org | 04e38e9 | 2011-03-28 10:16:38 +0000 | [diff] [blame] | 1143 | // Value |
commit-queue@webkit.org | 35af6cf | 2013-09-16 14:00:35 +0000 | [diff] [blame] | 1144 | if (role == SliderRole || role == SpinButtonRole || role == ScrollBarRole || role == ProgressIndicatorRole) |
k.czech@samsung.com | 3871a7a | 2014-02-27 14:22:14 +0000 | [diff] [blame] | 1145 | interfaceMask |= 1 << WAIValue; |
mario@webkit.org | 04e38e9 | 2011-03-28 10:16:38 +0000 | [diff] [blame] | 1146 | |
commit-queue@webkit.org | fd70fd3 | 2013-09-04 14:19:02 +0000 | [diff] [blame] | 1147 | #if ENABLE(INPUT_TYPE_COLOR) |
| 1148 | // Color type. |
| 1149 | if (role == ColorWellRole) |
k.czech@samsung.com | 3871a7a | 2014-02-27 14:22:14 +0000 | [diff] [blame] | 1150 | interfaceMask |= 1 << WAIText; |
commit-queue@webkit.org | fd70fd3 | 2013-09-04 14:19:02 +0000 | [diff] [blame] | 1151 | #endif |
| 1152 | |
xan@webkit.org | e438710 | 2009-04-09 11:08:48 +0000 | [diff] [blame] | 1153 | return interfaceMask; |
| 1154 | } |
| 1155 | |
| 1156 | static const char* getUniqueAccessibilityTypeName(guint16 interfaceMask) |
| 1157 | { |
| 1158 | #define WAI_TYPE_NAME_LEN (30) /* Enough for prefix + 5 hex characters (max) */ |
| 1159 | static char name[WAI_TYPE_NAME_LEN + 1]; |
eric@webkit.org | 4ff6fd7 | 2009-11-10 09:53:33 +0000 | [diff] [blame] | 1160 | |
xan@webkit.org | e438710 | 2009-04-09 11:08:48 +0000 | [diff] [blame] | 1161 | g_sprintf(name, "WAIType%x", interfaceMask); |
| 1162 | name[WAI_TYPE_NAME_LEN] = '\0'; |
eric@webkit.org | 4ff6fd7 | 2009-11-10 09:53:33 +0000 | [diff] [blame] | 1163 | |
xan@webkit.org | e438710 | 2009-04-09 11:08:48 +0000 | [diff] [blame] | 1164 | return name; |
| 1165 | } |
| 1166 | |
| 1167 | static GType getAccessibilityTypeFromObject(AccessibilityObject* coreObject) |
| 1168 | { |
| 1169 | static const GTypeInfo typeInfo = { |
| 1170 | sizeof(WebKitAccessibleClass), |
eric@webkit.org | 4ff6fd7 | 2009-11-10 09:53:33 +0000 | [diff] [blame] | 1171 | (GBaseInitFunc) 0, |
| 1172 | (GBaseFinalizeFunc) 0, |
| 1173 | (GClassInitFunc) 0, |
| 1174 | (GClassFinalizeFunc) 0, |
| 1175 | 0, /* class data */ |
xan@webkit.org | e438710 | 2009-04-09 11:08:48 +0000 | [diff] [blame] | 1176 | sizeof(WebKitAccessible), /* instance size */ |
| 1177 | 0, /* nb preallocs */ |
eric@webkit.org | 4ff6fd7 | 2009-11-10 09:53:33 +0000 | [diff] [blame] | 1178 | (GInstanceInitFunc) 0, |
| 1179 | 0 /* value table */ |
xan@webkit.org | e438710 | 2009-04-09 11:08:48 +0000 | [diff] [blame] | 1180 | }; |
| 1181 | |
| 1182 | guint16 interfaceMask = getInterfaceMaskFromObject(coreObject); |
| 1183 | const char* atkTypeName = getUniqueAccessibilityTypeName(interfaceMask); |
| 1184 | GType type = g_type_from_name(atkTypeName); |
| 1185 | if (type) |
| 1186 | return type; |
| 1187 | |
mario@webkit.org | f88ffcb | 2012-11-16 13:47:03 +0000 | [diff] [blame] | 1188 | 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] | 1189 | for (guint i = 0; i < G_N_ELEMENTS(AtkInterfacesInitFunctions); i++) { |
| 1190 | if (interfaceMask & (1 << i)) |
| 1191 | g_type_add_interface_static(type, |
mario@webkit.org | f88ffcb | 2012-11-16 13:47:03 +0000 | [diff] [blame] | 1192 | GetAtkInterfaceTypeFromWAIType(static_cast<WAIType>(i)), |
| 1193 | &AtkInterfacesInitFunctions[i]); |
xan@webkit.org | e438710 | 2009-04-09 11:08:48 +0000 | [diff] [blame] | 1194 | } |
| 1195 | |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 1196 | return type; |
| 1197 | } |
| 1198 | |
mario@webkit.org | aacb217 | 2012-01-23 11:43:28 +0000 | [diff] [blame] | 1199 | WebKitAccessible* webkitAccessibleNew(AccessibilityObject* coreObject) |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 1200 | { |
xan@webkit.org | e438710 | 2009-04-09 11:08:48 +0000 | [diff] [blame] | 1201 | GType type = getAccessibilityTypeFromObject(coreObject); |
eric@webkit.org | 4ff6fd7 | 2009-11-10 09:53:33 +0000 | [diff] [blame] | 1202 | AtkObject* object = static_cast<AtkObject*>(g_object_new(type, 0)); |
xan@webkit.org | e438710 | 2009-04-09 11:08:48 +0000 | [diff] [blame] | 1203 | |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 1204 | atk_object_initialize(object, coreObject); |
xan@webkit.org | e438710 | 2009-04-09 11:08:48 +0000 | [diff] [blame] | 1205 | |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 1206 | return WEBKIT_ACCESSIBLE(object); |
| 1207 | } |
| 1208 | |
mario@webkit.org | aacb217 | 2012-01-23 11:43:28 +0000 | [diff] [blame] | 1209 | AccessibilityObject* webkitAccessibleGetAccessibilityObject(WebKitAccessible* accessible) |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 1210 | { |
| 1211 | return accessible->m_object; |
| 1212 | } |
| 1213 | |
mario@webkit.org | aacb217 | 2012-01-23 11:43:28 +0000 | [diff] [blame] | 1214 | void webkitAccessibleDetach(WebKitAccessible* accessible) |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 1215 | { |
alp@webkit.org | c773899 | 2008-05-27 02:48:14 +0000 | [diff] [blame] | 1216 | ASSERT(accessible->m_object); |
| 1217 | |
mario@webkit.org | ff8cf0f | 2013-09-27 09:44:20 +0000 | [diff] [blame] | 1218 | if (accessible->m_object->roleValue() == WebAreaRole) |
mario@webkit.org | ca84906 | 2013-10-21 14:02:03 +0000 | [diff] [blame] | 1219 | atk_object_notify_state_change(ATK_OBJECT(accessible), ATK_STATE_DEFUNCT, true); |
mario@webkit.org | 92daa81 | 2011-02-16 17:12:38 +0000 | [diff] [blame] | 1220 | |
alp@webkit.org | c773899 | 2008-05-27 02:48:14 +0000 | [diff] [blame] | 1221 | // We replace the WebCore AccessibilityObject with a fallback object that |
| 1222 | // provides default implementations to avoid repetitive null-checking after |
| 1223 | // detachment. |
xan@webkit.org | c886cc6 | 2009-04-09 11:17:48 +0000 | [diff] [blame] | 1224 | accessible->m_object = fallbackObject(); |
alp@webkit.org | 3a5e7ca | 2008-05-20 01:12:20 +0000 | [diff] [blame] | 1225 | } |
| 1226 | |
mario@webkit.org | ff8cf0f | 2013-09-27 09:44:20 +0000 | [diff] [blame] | 1227 | bool webkitAccessibleIsDetached(WebKitAccessible* accessible) |
| 1228 | { |
| 1229 | ASSERT(accessible->m_object); |
| 1230 | return accessible->m_object == fallbackObject(); |
| 1231 | } |
| 1232 | |
mario@webkit.org | 4c778d7 | 2012-01-09 10:16:20 +0000 | [diff] [blame] | 1233 | AccessibilityObject* objectFocusedAndCaretOffsetUnignored(AccessibilityObject* referenceObject, int& offset) |
eric@webkit.org | 2fade49 | 2010-01-11 12:03:36 +0000 | [diff] [blame] | 1234 | { |
eric@webkit.org | 9cf227c | 2010-01-19 21:31:01 +0000 | [diff] [blame] | 1235 | // Indication that something bogus has transpired. |
| 1236 | offset = -1; |
eric@webkit.org | 2fade49 | 2010-01-11 12:03:36 +0000 | [diff] [blame] | 1237 | |
mario@webkit.org | 4c778d7 | 2012-01-09 10:16:20 +0000 | [diff] [blame] | 1238 | Document* document = referenceObject->document(); |
| 1239 | if (!document) |
mrobinson@webkit.org | bc2c5f2 | 2010-09-29 17:58:13 +0000 | [diff] [blame] | 1240 | return 0; |
eric@webkit.org | 2fade49 | 2010-01-11 12:03:36 +0000 | [diff] [blame] | 1241 | |
mario@webkit.org | 4c778d7 | 2012-01-09 10:16:20 +0000 | [diff] [blame] | 1242 | Node* focusedNode = referenceObject->selection().end().containerNode(); |
| 1243 | if (!focusedNode) |
mrobinson@webkit.org | bc2c5f2 | 2010-09-29 17:58:13 +0000 | [diff] [blame] | 1244 | return 0; |
eric@webkit.org | 2fade49 | 2010-01-11 12:03:36 +0000 | [diff] [blame] | 1245 | |
mario@webkit.org | 4c778d7 | 2012-01-09 10:16:20 +0000 | [diff] [blame] | 1246 | RenderObject* focusedRenderer = focusedNode->renderer(); |
| 1247 | if (!focusedRenderer) |
| 1248 | return 0; |
mario@webkit.org | 6698d35 | 2011-02-01 09:49:25 +0000 | [diff] [blame] | 1249 | |
mario@webkit.org | 4c778d7 | 2012-01-09 10:16:20 +0000 | [diff] [blame] | 1250 | AccessibilityObject* focusedObject = document->axObjectCache()->getOrCreate(focusedRenderer); |
| 1251 | if (!focusedObject) |
| 1252 | return 0; |
mario@webkit.org | 6698d35 | 2011-02-01 09:49:25 +0000 | [diff] [blame] | 1253 | |
mario@webkit.org | 4c778d7 | 2012-01-09 10:16:20 +0000 | [diff] [blame] | 1254 | // Look for the actual (not ignoring accessibility) selected object. |
mario@webkit.org | d048f76 | 2012-01-22 19:29:04 +0000 | [diff] [blame] | 1255 | AccessibilityObject* firstUnignoredParent = focusedObject; |
| 1256 | if (firstUnignoredParent->accessibilityIsIgnored()) |
| 1257 | firstUnignoredParent = firstUnignoredParent->parentObjectUnignored(); |
| 1258 | if (!firstUnignoredParent) |
mario@webkit.org | 4c778d7 | 2012-01-09 10:16:20 +0000 | [diff] [blame] | 1259 | return 0; |
| 1260 | |
commit-queue@webkit.org | 3499c51 | 2014-06-24 11:09:22 +0000 | [diff] [blame] | 1261 | // Don't ignore links if the offset is being requested for a link |
| 1262 | // or if the link is a block. |
| 1263 | if (!referenceObject->isLink() && firstUnignoredParent->isLink() |
| 1264 | && !(firstUnignoredParent->renderer() && !firstUnignoredParent->renderer()->isInline())) |
mario@webkit.org | d048f76 | 2012-01-22 19:29:04 +0000 | [diff] [blame] | 1265 | firstUnignoredParent = firstUnignoredParent->parentObjectUnignored(); |
| 1266 | if (!firstUnignoredParent) |
mario@webkit.org | 4c778d7 | 2012-01-09 10:16:20 +0000 | [diff] [blame] | 1267 | return 0; |
| 1268 | |
mario@webkit.org | d048f76 | 2012-01-22 19:29:04 +0000 | [diff] [blame] | 1269 | // The reference object must either coincide with the focused |
| 1270 | // object being considered, or be a descendant of it. |
| 1271 | if (referenceObject->isDescendantOfObject(firstUnignoredParent)) |
| 1272 | referenceObject = firstUnignoredParent; |
| 1273 | |
commit-queue@webkit.org | 9a24e2d | 2015-05-29 04:53:35 +0000 | [diff] [blame] | 1274 | Node* startNode = nullptr; |
mario@webkit.org | d048f76 | 2012-01-22 19:29:04 +0000 | [diff] [blame] | 1275 | if (firstUnignoredParent != referenceObject || firstUnignoredParent->isTextControl()) { |
mario@webkit.org | 4c778d7 | 2012-01-09 10:16:20 +0000 | [diff] [blame] | 1276 | // We need to use the first child's node of the reference |
| 1277 | // object as the start point to calculate the caret offset |
| 1278 | // because we want it to be relative to the object of |
| 1279 | // reference, not just to the focused object (which could have |
| 1280 | // previous siblings which should be taken into account too). |
| 1281 | AccessibilityObject* axFirstChild = referenceObject->firstChild(); |
| 1282 | if (axFirstChild) |
| 1283 | startNode = axFirstChild->node(); |
| 1284 | } |
commit-queue@webkit.org | fb3e915 | 2013-02-01 00:37:22 +0000 | [diff] [blame] | 1285 | // Getting the Position of a PseudoElement now triggers an assertion. |
| 1286 | // This can occur when clicking on empty space in a render block. |
| 1287 | if (!startNode || startNode->isPseudoElement()) |
mario@webkit.org | d048f76 | 2012-01-22 19:29:04 +0000 | [diff] [blame] | 1288 | startNode = firstUnignoredParent->node(); |
mario@webkit.org | 4c778d7 | 2012-01-09 10:16:20 +0000 | [diff] [blame] | 1289 | |
mario@webkit.org | b311bdb | 2012-02-01 17:58:57 +0000 | [diff] [blame] | 1290 | // Check if the node for the first parent object not ignoring |
| 1291 | // accessibility is null again before using it. This might happen |
| 1292 | // with certain kind of accessibility objects, such as the root |
| 1293 | // one (the scroller containing the webArea object). |
| 1294 | if (!startNode) |
| 1295 | return 0; |
| 1296 | |
mario@webkit.org | d048f76 | 2012-01-22 19:29:04 +0000 | [diff] [blame] | 1297 | VisiblePosition startPosition = VisiblePosition(positionBeforeNode(startNode), DOWNSTREAM); |
| 1298 | VisiblePosition endPosition = firstUnignoredParent->selection().visibleEnd(); |
mario@webkit.org | 4c778d7 | 2012-01-09 10:16:20 +0000 | [diff] [blame] | 1299 | |
| 1300 | if (startPosition == endPosition) |
| 1301 | offset = 0; |
| 1302 | else if (!isStartOfLine(endPosition)) { |
| 1303 | RefPtr<Range> range = makeRange(startPosition, endPosition.previous()); |
| 1304 | offset = TextIterator::rangeLength(range.get(), true) + 1; |
| 1305 | } else { |
| 1306 | RefPtr<Range> range = makeRange(startPosition, endPosition); |
| 1307 | offset = TextIterator::rangeLength(range.get(), true); |
eric@webkit.org | 9cf227c | 2010-01-19 21:31:01 +0000 | [diff] [blame] | 1308 | } |
mario@webkit.org | ff7fd42 | 2011-01-27 19:38:03 +0000 | [diff] [blame] | 1309 | |
mario@webkit.org | d048f76 | 2012-01-22 19:29:04 +0000 | [diff] [blame] | 1310 | return firstUnignoredParent; |
eric@webkit.org | 2fade49 | 2010-01-11 12:03:36 +0000 | [diff] [blame] | 1311 | } |
| 1312 | |
mario@webkit.org | fecbacd | 2013-03-04 17:06:15 +0000 | [diff] [blame] | 1313 | const char* cacheAndReturnAtkProperty(AtkObject* object, AtkCachedProperty property, String value) |
| 1314 | { |
| 1315 | WebKitAccessiblePrivate* priv = WEBKIT_ACCESSIBLE(object)->priv; |
commit-queue@webkit.org | 9a24e2d | 2015-05-29 04:53:35 +0000 | [diff] [blame] | 1316 | CString* propertyPtr = nullptr; |
mario@webkit.org | fecbacd | 2013-03-04 17:06:15 +0000 | [diff] [blame] | 1317 | |
| 1318 | switch (property) { |
| 1319 | case AtkCachedAccessibleName: |
| 1320 | propertyPtr = &priv->accessibleName; |
| 1321 | break; |
| 1322 | |
| 1323 | case AtkCachedAccessibleDescription: |
| 1324 | propertyPtr = &priv->accessibleDescription; |
| 1325 | break; |
| 1326 | |
| 1327 | case AtkCachedActionName: |
| 1328 | propertyPtr = &priv->actionName; |
| 1329 | break; |
| 1330 | |
| 1331 | case AtkCachedActionKeyBinding: |
| 1332 | propertyPtr = &priv->actionKeyBinding; |
| 1333 | break; |
| 1334 | |
| 1335 | case AtkCachedDocumentLocale: |
| 1336 | propertyPtr = &priv->documentLocale; |
| 1337 | break; |
| 1338 | |
| 1339 | case AtkCachedDocumentType: |
| 1340 | propertyPtr = &priv->documentType; |
| 1341 | break; |
| 1342 | |
| 1343 | case AtkCachedDocumentEncoding: |
| 1344 | propertyPtr = &priv->documentEncoding; |
| 1345 | break; |
| 1346 | |
| 1347 | case AtkCachedDocumentURI: |
| 1348 | propertyPtr = &priv->documentURI; |
| 1349 | break; |
| 1350 | |
| 1351 | case AtkCachedImageDescription: |
| 1352 | propertyPtr = &priv->imageDescription; |
| 1353 | break; |
| 1354 | |
| 1355 | default: |
| 1356 | ASSERT_NOT_REACHED(); |
| 1357 | } |
| 1358 | |
| 1359 | // Don't invalidate old memory if not stricly needed, since other |
| 1360 | // callers might be still holding on to it. |
| 1361 | if (*propertyPtr != value.utf8()) |
| 1362 | *propertyPtr = value.utf8(); |
| 1363 | |
| 1364 | return (*propertyPtr).data(); |
| 1365 | } |
| 1366 | |
ddkilzer@apple.com | 8d87863 | 2008-11-09 19:50:37 +0000 | [diff] [blame] | 1367 | #endif // HAVE(ACCESSIBILITY) |