OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "base/string_number_conversions.h" |
7 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "base/utf_string_conversions.h" |
8 #include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityCache.h" | 10 #include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityCache.h" |
9 #include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityObject.h" | 11 #include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityObject.h" |
10 #include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityRole.h" | 12 #include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityRole.h" |
11 #include "third_party/WebKit/WebKit/chromium/public/WebAttribute.h" | 13 #include "third_party/WebKit/WebKit/chromium/public/WebAttribute.h" |
12 #include "third_party/WebKit/WebKit/chromium/public/WebDocument.h" | 14 #include "third_party/WebKit/WebKit/chromium/public/WebDocument.h" |
13 #include "third_party/WebKit/WebKit/chromium/public/WebDocumentType.h" | 15 #include "third_party/WebKit/WebKit/chromium/public/WebDocumentType.h" |
14 #include "third_party/WebKit/WebKit/chromium/public/WebElement.h" | 16 #include "third_party/WebKit/WebKit/chromium/public/WebElement.h" |
| 17 #include "third_party/WebKit/WebKit/chromium/public/WebFormControlElement.h" |
15 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" | 18 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" |
| 19 #include "third_party/WebKit/WebKit/chromium/public/WebInputElement.h" |
16 #include "third_party/WebKit/WebKit/chromium/public/WebNamedNodeMap.h" | 20 #include "third_party/WebKit/WebKit/chromium/public/WebNamedNodeMap.h" |
17 #include "third_party/WebKit/WebKit/chromium/public/WebNode.h" | 21 #include "third_party/WebKit/WebKit/chromium/public/WebNode.h" |
18 #include "third_party/WebKit/WebKit/chromium/public/WebString.h" | 22 #include "third_party/WebKit/WebKit/chromium/public/WebString.h" |
19 | 23 |
20 using WebKit::WebAccessibilityCache; | 24 using WebKit::WebAccessibilityCache; |
21 using WebKit::WebAccessibilityRole; | 25 using WebKit::WebAccessibilityRole; |
22 using WebKit::WebAccessibilityObject; | 26 using WebKit::WebAccessibilityObject; |
23 | 27 |
24 namespace webkit_glue { | 28 namespace webkit_glue { |
25 | 29 |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 // TODO(ctguil): The tagName in WebKit is lower cased but | 329 // TODO(ctguil): The tagName in WebKit is lower cased but |
326 // HTMLElement::nodeName calls localNameUpper. Consider adding | 330 // HTMLElement::nodeName calls localNameUpper. Consider adding |
327 // a WebElement method that returns the original lower cased tagName. | 331 // a WebElement method that returns the original lower cased tagName. |
328 attributes[ATTR_HTML_TAG] = StringToLowerASCII(string16(element.tagName())); | 332 attributes[ATTR_HTML_TAG] = StringToLowerASCII(string16(element.tagName())); |
329 for (unsigned i = 0; i < element.attributes().length(); i++) { | 333 for (unsigned i = 0; i < element.attributes().length(); i++) { |
330 html_attributes.push_back( | 334 html_attributes.push_back( |
331 std::pair<string16, string16>( | 335 std::pair<string16, string16>( |
332 element.attributes().attributeItem(i).localName(), | 336 element.attributes().attributeItem(i).localName(), |
333 element.attributes().attributeItem(i).value())); | 337 element.attributes().attributeItem(i).value())); |
334 } | 338 } |
| 339 |
| 340 if (element.isFormControlElement()) { |
| 341 WebKit::WebFormControlElement form_element = |
| 342 element.to<WebKit::WebFormControlElement>(); |
| 343 if (form_element.formControlType() == ASCIIToUTF16("text")) { |
| 344 WebKit::WebInputElement input_element = |
| 345 form_element.to<WebKit::WebInputElement>(); |
| 346 attributes[ATTR_TEXT_SEL_START] = base::IntToString16( |
| 347 input_element.selectionStart()); |
| 348 attributes[ATTR_TEXT_SEL_END] = base::IntToString16( |
| 349 input_element.selectionEnd()); |
| 350 } |
| 351 } |
335 } | 352 } |
336 | 353 |
337 if (role == WebAccessibility::ROLE_DOCUMENT || | 354 if (role == WebAccessibility::ROLE_DOCUMENT || |
338 role == WebAccessibility::ROLE_WEB_AREA) { | 355 role == WebAccessibility::ROLE_WEB_AREA) { |
339 WebKit::WebDocument document = src.document(); | 356 const WebKit::WebDocument& document = src.document(); |
340 if (name.empty()) | 357 if (name.empty()) |
341 name = document.title(); | 358 name = document.title(); |
342 attributes[ATTR_DOC_TITLE] = document.title(); | 359 attributes[ATTR_DOC_TITLE] = document.title(); |
343 attributes[ATTR_DOC_URL] = document.frame()->url().spec().utf16(); | 360 attributes[ATTR_DOC_URL] = document.frame()->url().spec().utf16(); |
344 if (document.isXHTMLDocument()) | 361 if (document.isXHTMLDocument()) |
345 attributes[ATTR_DOC_MIMETYPE] = WebKit::WebString("text/xhtml"); | 362 attributes[ATTR_DOC_MIMETYPE] = WebKit::WebString("text/xhtml"); |
346 else | 363 else |
347 attributes[ATTR_DOC_MIMETYPE] = WebKit::WebString("text/html"); | 364 attributes[ATTR_DOC_MIMETYPE] = WebKit::WebString("text/html"); |
348 | 365 |
349 WebKit::WebDocumentType doctype = document.doctype(); | 366 const WebKit::WebDocumentType& doctype = document.doctype(); |
350 if (!doctype.isNull()) | 367 if (!doctype.isNull()) |
351 attributes[ATTR_DOC_DOCTYPE] = doctype.name(); | 368 attributes[ATTR_DOC_DOCTYPE] = doctype.name(); |
352 } | 369 } |
353 | 370 |
354 // Add the source object to the cache and store its id. | 371 // Add the source object to the cache and store its id. |
355 id = cache->addOrGetId(src); | 372 id = cache->addOrGetId(src); |
356 | 373 |
357 // Recursively create children. | 374 // Recursively create children. |
358 int child_count = src.childCount(); | 375 int child_count = src.childCount(); |
359 for (int i = 0; i < child_count; i++) { | 376 for (int i = 0; i < child_count; i++) { |
360 WebAccessibilityObject child = src.childAt(i); | 377 WebAccessibilityObject child = src.childAt(i); |
361 | 378 |
362 // The child may be invalid due to issues in webkit accessibility code. | 379 // The child may be invalid due to issues in webkit accessibility code. |
363 // Don't add children are invalid thus preventing a crash. | 380 // Don't add children are invalid thus preventing a crash. |
364 // https://bugs.webkit.org/show_bug.cgi?id=44149 | 381 // https://bugs.webkit.org/show_bug.cgi?id=44149 |
365 // TODO(ctguil): We may want to remove this check as webkit stabilizes. | 382 // TODO(ctguil): We may want to remove this check as webkit stabilizes. |
366 if (child.isValid()) | 383 if (child.isValid()) |
367 children.push_back(WebAccessibility(child, cache)); | 384 children.push_back(WebAccessibility(child, cache)); |
368 } | 385 } |
369 } | 386 } |
370 | 387 |
371 } // namespace webkit_glue | 388 } // namespace webkit_glue |
OLD | NEW |