| OLD | NEW | 
|---|
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #include "webkit/glue/webaccessibility.h" | 5 #include "webkit/glue/webaccessibility.h" | 
| 6 | 6 | 
| 7 #include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityCache.h" | 7 #include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityCache.h" | 
| 8 #include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityObject.h" | 8 #include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityObject.h" | 
| 9 #include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityRole.h" | 9 #include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityRole.h" | 
| 10 #include "third_party/WebKit/WebKit/chromium/public/WebPoint.h" | 10 #include "third_party/WebKit/WebKit/chromium/public/WebPoint.h" | 
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 138 | 138 | 
| 139   if (o.isVisited()) | 139   if (o.isVisited()) | 
| 140     state |= static_cast<long>(1 << WebAccessibility::STATE_TRAVERSED); | 140     state |= static_cast<long>(1 << WebAccessibility::STATE_TRAVERSED); | 
| 141 | 141 | 
| 142   if (!o.isEnabled()) | 142   if (!o.isEnabled()) | 
| 143     state |= static_cast<long>(1 << WebAccessibility::STATE_UNAVAILABLE); | 143     state |= static_cast<long>(1 << WebAccessibility::STATE_UNAVAILABLE); | 
| 144 | 144 | 
| 145   return state; | 145   return state; | 
| 146 } | 146 } | 
| 147 | 147 | 
| 148 | 148 int32 WebAccessibility::GetAccObjInfo(WebAccessibilityCache* cache, | 
| 149 bool WebAccessibility::GetAccObjInfo(WebAccessibilityCache* cache, |  | 
| 150   const WebAccessibility::InParams& in_params, | 149   const WebAccessibility::InParams& in_params, | 
| 151   WebAccessibility::OutParams* out_params) { | 150   WebAccessibility::OutParams* out_params) { | 
| 152 |  | 
| 153   // Find object requested by |object_id|. | 151   // Find object requested by |object_id|. | 
| 154   WebAccessibilityObject active_acc_obj; | 152   WebAccessibilityObject active_acc_obj; | 
| 155 | 153 | 
| 156   // Since ids assigned by Chrome starts at 1000, whereas platform-specific ids | 154   // Since ids assigned by Chrome starts at 1000, whereas platform-specific ids | 
| 157   // used to reference a child will be in a wholly different range, we know | 155   // used to reference a child will be in a wholly different range, we know | 
| 158   // that any id that high should be treated as a non-direct descendant. | 156   // that any id that high should be treated as a non-direct descendant. | 
| 159   bool local_child = false; | 157   bool local_child = false; | 
| 160   if (cache->isValidId(in_params.child_id)) { | 158   if (cache->isValidId(in_params.child_id)) { | 
| 161     // Object is not a direct child, re-map the input parameters accordingly. | 159     // Object is not a direct child, re-map the input parameters accordingly. | 
| 162     // The object to be retrieved is referred to by the |in_params.child_id|, as | 160     // The object to be retrieved is referred to by the |in_params.child_id|, as | 
| 163     // a result of e.g. a focus event. | 161     // a result of e.g. a focus event. | 
| 164     active_acc_obj = cache->getObjectById(in_params.child_id); | 162     active_acc_obj = cache->getObjectById(in_params.child_id); | 
| 165   } else { | 163   } else { | 
| 166     local_child = true; | 164     local_child = true; | 
| 167 | 165 | 
| 168     active_acc_obj = cache->getObjectById(in_params.object_id); | 166     active_acc_obj = cache->getObjectById(in_params.object_id); | 
| 169     if (active_acc_obj.isNull()) | 167     if (active_acc_obj.isNull()) | 
| 170       return false; | 168       return RETURNCODE_FAIL; | 
| 171 | 169 | 
| 172     // child_id == 0 means self. Otherwise, it's a local child - 1. | 170     // child_id == 0 means self. Otherwise, it's a local child - 1. | 
| 173     if (in_params.child_id > 0) { | 171     if (in_params.child_id > 0) { | 
| 174       unsigned index = in_params.child_id - 1; | 172       unsigned index = in_params.child_id - 1; | 
| 175       if (index >= active_acc_obj.childCount()) | 173       if (index >= active_acc_obj.childCount()) | 
| 176         return false; | 174         return RETURNCODE_FAIL; | 
| 177 | 175 | 
| 178       active_acc_obj = active_acc_obj.childAt(index); | 176       active_acc_obj = active_acc_obj.childAt(index); | 
| 179     } | 177     } | 
| 180   } | 178   } | 
| 181 | 179 | 
| 182   if (active_acc_obj.isNull()) | 180   if (active_acc_obj.isNull()) | 
| 183     return false; | 181     return RETURNCODE_FAIL; | 
| 184 | 182 | 
| 185   // Temp paramters for holding output information. | 183   // Temp paramters for holding output information. | 
| 186   WebAccessibilityObject out_acc_obj; | 184   WebAccessibilityObject out_acc_obj; | 
| 187   string16 out_string; | 185   string16 out_string; | 
| 188 | 186 | 
| 189   switch (in_params.function_id) { | 187   switch (in_params.function_id) { | 
| 190     case WebAccessibility::FUNCTION_DODEFAULTACTION: { | 188     case WebAccessibility::FUNCTION_DODEFAULTACTION: { | 
| 191       if (!active_acc_obj.performDefaultAction()) | 189       if (!active_acc_obj.performDefaultAction()) | 
| 192         return false; | 190         return RETURNCODE_FALSE; | 
| 193       break; | 191       break; | 
| 194     } | 192     } | 
| 195     case WebAccessibility::FUNCTION_HITTEST: { | 193     case WebAccessibility::FUNCTION_HITTEST: { | 
| 196       WebPoint point(in_params.input_long1, in_params.input_long2); | 194       WebPoint point(in_params.input_long1, in_params.input_long2); | 
| 197       out_acc_obj = active_acc_obj.hitTest(point); | 195       out_acc_obj = active_acc_obj.hitTest(point); | 
| 198       if (out_acc_obj.isNull()) | 196       if (out_acc_obj.isNull()) | 
| 199         return false; | 197         return RETURNCODE_FALSE; | 
| 200       break; | 198       break; | 
| 201     } | 199     } | 
| 202     case WebAccessibility::FUNCTION_LOCATION: { | 200     case WebAccessibility::FUNCTION_LOCATION: { | 
| 203       WebRect rect = active_acc_obj.boundingBoxRect(); | 201       WebRect rect = active_acc_obj.boundingBoxRect(); | 
| 204       out_params->output_long1 = rect.x; | 202       out_params->output_long1 = rect.x; | 
| 205       out_params->output_long2 = rect.y; | 203       out_params->output_long2 = rect.y; | 
| 206       out_params->output_long3 = rect.width; | 204       out_params->output_long3 = rect.width; | 
| 207       out_params->output_long4 = rect.height; | 205       out_params->output_long4 = rect.height; | 
| 208       break; | 206       break; | 
| 209     } | 207     } | 
| 210     case WebAccessibility::FUNCTION_NAVIGATE: { | 208     case WebAccessibility::FUNCTION_NAVIGATE: { | 
| 211       WebAccessibility::Direction dir = | 209       WebAccessibility::Direction dir = | 
| 212         static_cast<WebAccessibility::Direction>(in_params.input_long1); | 210         static_cast<WebAccessibility::Direction>(in_params.input_long1); | 
| 213       switch (dir) { | 211       switch (dir) { | 
| 214         case WebAccessibility::DIRECTION_DOWN: | 212         case WebAccessibility::DIRECTION_DOWN: | 
| 215         case WebAccessibility::DIRECTION_UP: | 213         case WebAccessibility::DIRECTION_UP: | 
| 216         case WebAccessibility::DIRECTION_LEFT: | 214         case WebAccessibility::DIRECTION_LEFT: | 
| 217         case WebAccessibility::DIRECTION_RIGHT: | 215         case WebAccessibility::DIRECTION_RIGHT: | 
| 218           // These directions are not implemented, matching Mozilla and IE. | 216           // These directions are not implemented, matching Mozilla and IE. | 
| 219           return false; | 217           return RETURNCODE_FALSE; | 
| 220         case WebAccessibility::DIRECTION_LASTCHILD: | 218         case WebAccessibility::DIRECTION_LASTCHILD: | 
| 221         case WebAccessibility::DIRECTION_FIRSTCHILD: | 219         case WebAccessibility::DIRECTION_FIRSTCHILD: | 
| 222           // MSDN states that navigating to first/last child can only be from | 220           // MSDN states that navigating to first/last child can only be from | 
| 223           // self. | 221           // self. | 
| 224           if (!local_child) | 222           if (!local_child) | 
| 225             return false; | 223             return RETURNCODE_FALSE; | 
| 226 | 224 | 
| 227           if (dir == WebAccessibility::DIRECTION_FIRSTCHILD) { | 225           if (dir == WebAccessibility::DIRECTION_FIRSTCHILD) { | 
| 228             out_acc_obj = active_acc_obj.firstChild(); | 226             out_acc_obj = active_acc_obj.firstChild(); | 
| 229           } else { | 227           } else { | 
| 230             out_acc_obj = active_acc_obj.lastChild(); | 228             out_acc_obj = active_acc_obj.lastChild(); | 
| 231           } | 229           } | 
| 232           break; | 230           break; | 
| 233         case WebAccessibility::DIRECTION_NEXT: | 231         case WebAccessibility::DIRECTION_NEXT: | 
| 234         case WebAccessibility::DIRECTION_PREVIOUS: { | 232         case WebAccessibility::DIRECTION_PREVIOUS: { | 
| 235           if (dir == WebAccessibility::DIRECTION_NEXT) { | 233           if (dir == WebAccessibility::DIRECTION_NEXT) { | 
| 236             out_acc_obj = active_acc_obj.nextSibling(); | 234             out_acc_obj = active_acc_obj.nextSibling(); | 
| 237           } else { | 235           } else { | 
| 238             out_acc_obj = active_acc_obj.previousSibling(); | 236             out_acc_obj = active_acc_obj.previousSibling(); | 
| 239           } | 237           } | 
| 240           break; | 238           break; | 
| 241         } | 239         } | 
| 242         default: | 240         default: | 
| 243           return false; | 241           return RETURNCODE_FALSE; | 
| 244       } | 242       } | 
|  | 243 | 
| 245       if (out_acc_obj.isNull()) | 244       if (out_acc_obj.isNull()) | 
| 246         return false; | 245         return RETURNCODE_FALSE; | 
|  | 246 | 
| 247       break; | 247       break; | 
| 248     } | 248     } | 
| 249     case WebAccessibility::FUNCTION_GETCHILD: { | 249     case WebAccessibility::FUNCTION_GETCHILD: { | 
| 250       out_params->object_id = in_params.object_id; | 250       out_params->object_id = in_params.object_id; | 
| 251       out_acc_obj = active_acc_obj; | 251       out_acc_obj = active_acc_obj; | 
| 252       break; | 252       break; | 
| 253     } | 253     } | 
| 254     case WebAccessibility::FUNCTION_CHILDCOUNT: { | 254     case WebAccessibility::FUNCTION_CHILDCOUNT: { | 
| 255       out_params->output_long1 = active_acc_obj.childCount(); | 255       out_params->output_long1 = active_acc_obj.childCount(); | 
| 256       break; | 256       break; | 
| 257     } | 257     } | 
| 258     case WebAccessibility::FUNCTION_DEFAULTACTION: { | 258     case WebAccessibility::FUNCTION_DEFAULTACTION: { | 
| 259       out_string = active_acc_obj.actionVerb(); | 259       out_string = active_acc_obj.actionVerb(); | 
| 260       if (out_string.empty()) | 260       if (out_string.empty()) | 
| 261         return false; | 261         return RETURNCODE_FALSE; | 
| 262       break; | 262       break; | 
| 263     } | 263     } | 
| 264     case WebAccessibility::FUNCTION_DESCRIPTION: { | 264     case WebAccessibility::FUNCTION_DESCRIPTION: { | 
| 265       out_string = active_acc_obj.accessibilityDescription(); | 265       out_string = active_acc_obj.accessibilityDescription(); | 
| 266       if (out_string.empty()) | 266       if (out_string.empty()) | 
| 267         return false; | 267         return RETURNCODE_FALSE; | 
| 268       // From the Mozilla MSAA implementation: | 268       // From the Mozilla MSAA implementation: | 
| 269       // "Signal to screen readers that this description is speakable and is not | 269       // "Signal to screen readers that this description is speakable and is not | 
| 270       // a formatted positional information description. Don't localize the | 270       // a formatted positional information description. Don't localize the | 
| 271       // 'Description: ' part of this string, it will be parsed out by assistive | 271       // 'Description: ' part of this string, it will be parsed out by assistive | 
| 272       // technologies." | 272       // technologies." | 
| 273       out_string = L"Description: " + out_string; | 273       out_string = L"Description: " + out_string; | 
| 274       break; | 274       break; | 
| 275     } | 275     } | 
| 276     case WebAccessibility::FUNCTION_GETFOCUSEDCHILD: { | 276     case WebAccessibility::FUNCTION_GETFOCUSEDCHILD: { | 
| 277       out_acc_obj = active_acc_obj.focusedChild(); | 277       out_acc_obj = active_acc_obj.focusedChild(); | 
| 278       if (out_acc_obj.isNull()) | 278       if (out_acc_obj.isNull()) | 
| 279         return false; | 279         return RETURNCODE_FALSE; | 
| 280       break; | 280       break; | 
| 281     } | 281     } | 
| 282     case WebAccessibility::FUNCTION_HELPTEXT: { | 282     case WebAccessibility::FUNCTION_HELPTEXT: { | 
| 283       out_string = active_acc_obj.helpText(); | 283       out_string = active_acc_obj.helpText(); | 
| 284       if (out_string.empty()) | 284       if (out_string.empty()) | 
| 285         return false; | 285         return RETURNCODE_FALSE; | 
| 286       break; | 286       break; | 
| 287     } | 287     } | 
| 288     case WebAccessibility::FUNCTION_KEYBOARDSHORTCUT: { | 288     case WebAccessibility::FUNCTION_KEYBOARDSHORTCUT: { | 
| 289       out_string = active_acc_obj.keyboardShortcut(); | 289       out_string = active_acc_obj.keyboardShortcut(); | 
| 290       if (out_string.empty()) | 290       if (out_string.empty()) | 
| 291         return false; | 291         return RETURNCODE_FALSE; | 
| 292       break; | 292       break; | 
| 293     } | 293     } | 
| 294     case WebAccessibility::FUNCTION_NAME: { | 294     case WebAccessibility::FUNCTION_NAME: { | 
| 295       out_string = active_acc_obj.title(); | 295       out_string = active_acc_obj.title(); | 
| 296       if (out_string.empty()) | 296       if (out_string.empty()) | 
| 297         return false; | 297         return RETURNCODE_FALSE; | 
| 298       break; | 298       break; | 
| 299     } | 299     } | 
| 300     case WebAccessibility::FUNCTION_GETPARENT: { | 300     case WebAccessibility::FUNCTION_GETPARENT: { | 
| 301       out_acc_obj = active_acc_obj.parentObject(); | 301       out_acc_obj = active_acc_obj.parentObject(); | 
| 302       if (out_acc_obj.isNull()) | 302       if (out_acc_obj.isNull()) | 
| 303         return false; | 303         return RETURNCODE_FALSE; | 
| 304       break; | 304       break; | 
| 305     } | 305     } | 
| 306     case WebAccessibility::FUNCTION_ROLE: { | 306     case WebAccessibility::FUNCTION_ROLE: { | 
| 307       out_params->output_long1 = ConvertRole(active_acc_obj.roleValue()); | 307       out_params->output_long1 = ConvertRole(active_acc_obj.roleValue()); | 
| 308       break; | 308       break; | 
| 309     } | 309     } | 
| 310     case WebAccessibility::FUNCTION_STATE: { | 310     case WebAccessibility::FUNCTION_STATE: { | 
| 311       out_params->output_long1 = ConvertState(active_acc_obj); | 311       out_params->output_long1 = ConvertState(active_acc_obj); | 
| 312       break; | 312       break; | 
| 313     } | 313     } | 
| 314     case WebAccessibility::FUNCTION_VALUE: { | 314     case WebAccessibility::FUNCTION_VALUE: { | 
| 315       out_string = active_acc_obj.stringValue(); | 315       out_string = active_acc_obj.stringValue(); | 
| 316       if (out_string.empty()) | 316       if (out_string.empty()) | 
| 317         return false; | 317         return RETURNCODE_FALSE; | 
| 318       break; | 318       break; | 
| 319     } | 319     } | 
| 320     default: | 320     default: | 
| 321       // Non-supported function id. | 321       // Non-supported function id. | 
| 322       return false; | 322       return RETURNCODE_FAIL; | 
| 323   } | 323   } | 
| 324 | 324 | 
| 325   // Output and hashmap assignments, as appropriate. | 325   // Output and hashmap assignments, as appropriate. | 
| 326   if (!out_string.empty()) | 326   if (!out_string.empty()) | 
| 327     out_params->output_string = out_string; | 327     out_params->output_string = out_string; | 
| 328 | 328 | 
| 329   if (out_acc_obj.isNull()) | 329   if (out_acc_obj.isNull()) | 
| 330     return true; | 330     return RETURNCODE_TRUE; | 
| 331 | 331 | 
| 332   int id = cache->addOrGetId(out_acc_obj); | 332   int id = cache->addOrGetId(out_acc_obj); | 
| 333   out_params->object_id = id; | 333   out_params->object_id = id; | 
| 334   out_params->output_long1 = -1; | 334   out_params->output_long1 = -1; | 
| 335 | 335 | 
| 336   // TODO(klink): Handle simple objects returned. | 336   // TODO(ctguil): Handle simple objects returned. | 
| 337   return true; | 337   return RETURNCODE_TRUE; | 
| 338 } | 338 } | 
| 339 | 339 | 
| 340 }  // namespace webkit_glue | 340 }  // namespace webkit_glue | 
| OLD | NEW | 
|---|