AccessibilityControllerIOS.mm 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * Copyright (C) 2009 Apple Inc. All Rights Reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. * 1. Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * 2. Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. *
  13. * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
  14. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  15. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  16. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
  17. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  18. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  19. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  20. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  21. * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  23. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #import "config.h"
  26. #import "DumpRenderTree.h"
  27. #import "AccessibilityController.h"
  28. #if PLATFORM(IOS)
  29. #import "AccessibilityCommonMac.h"
  30. #import "AccessibilityUIElement.h"
  31. #import <Foundation/Foundation.h>
  32. #import <WebKit/WebFramePrivate.h>
  33. #import <WebKit/WebHTMLViewPrivate.h>
  34. @interface WebHTMLView (Private)
  35. - (id)accessibilityFocusedUIElement;
  36. @end
  37. AccessibilityController::AccessibilityController()
  38. {
  39. }
  40. AccessibilityController::~AccessibilityController()
  41. {
  42. }
  43. AccessibilityUIElement AccessibilityController::elementAtPoint(int x, int y)
  44. {
  45. return rootElement().elementAtPoint(x, y);
  46. }
  47. AccessibilityUIElement AccessibilityController::focusedElement()
  48. {
  49. id webDocumentView = [[mainFrame frameView] documentView];
  50. if ([webDocumentView isKindOfClass:[WebHTMLView class]])
  51. return AccessibilityUIElement([(WebHTMLView *)webDocumentView accessibilityFocusedUIElement]);
  52. return 0;
  53. }
  54. AccessibilityUIElement AccessibilityController::rootElement()
  55. {
  56. // FIXME: we could do some caching here.
  57. id webDocumentView = [[mainFrame frameView] documentView];
  58. if ([webDocumentView isKindOfClass:[WebHTMLView class]])
  59. return AccessibilityUIElement([(WebHTMLView *)webDocumentView accessibilityRootElement]);
  60. return 0;
  61. }
  62. static id findAccessibleObjectById(id obj, NSString *idAttribute)
  63. {
  64. id objIdAttribute = [obj accessibilityIdentifier];
  65. if ([objIdAttribute isKindOfClass:[NSString class]] && [objIdAttribute isEqualToString:idAttribute])
  66. return obj;
  67. NSUInteger childrenCount = [obj accessibilityElementCount];
  68. for (NSUInteger i = 0; i < childrenCount; ++i) {
  69. id result = findAccessibleObjectById([obj accessibilityElementAtIndex:i], idAttribute);
  70. if (result)
  71. return result;
  72. }
  73. return 0;
  74. }
  75. AccessibilityUIElement AccessibilityController::accessibleElementById(JSStringRef idAttributeRef)
  76. {
  77. id webDocumentView = [[mainFrame frameView] documentView];
  78. if (![webDocumentView isKindOfClass:[WebHTMLView class]])
  79. return 0;
  80. id root = [(WebHTMLView *)webDocumentView accessibilityRootElement];
  81. NSString *idAttribute = [NSString stringWithJSStringRef:idAttributeRef];
  82. id result = findAccessibleObjectById(root, idAttribute);
  83. if (result)
  84. return AccessibilityUIElement(result);
  85. return 0;
  86. }
  87. void AccessibilityController::setLogFocusEvents(bool)
  88. {
  89. }
  90. void AccessibilityController::setLogScrollingStartEvents(bool)
  91. {
  92. }
  93. void AccessibilityController::setLogValueChangeEvents(bool)
  94. {
  95. }
  96. void AccessibilityController::setLogAccessibilityEvents(bool)
  97. {
  98. }
  99. bool AccessibilityController::addNotificationListener(JSObjectRef functionCallback)
  100. {
  101. return false;
  102. }
  103. void AccessibilityController::removeNotificationListener()
  104. {
  105. }
  106. #endif // PLATFORM(IOS)