AccessibilityTextMarker.cpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * Copyright (C) 2010 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. #include "config.h"
  26. #include "AccessibilityTextMarker.h"
  27. #include "AccessibilityUIElement.h"
  28. #include <JavaScriptCore/JSRetainPtr.h>
  29. // MARK: AccessibilityTextMarker
  30. // Callback methods
  31. AccessibilityTextMarker* toTextMarker(JSObjectRef object)
  32. {
  33. return static_cast<AccessibilityTextMarker*>(JSObjectGetPrivate(object));
  34. }
  35. static JSValueRef isMarkerEqualCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  36. {
  37. if (argumentCount != 1)
  38. return JSValueMakeBoolean(context, false);
  39. JSObjectRef otherMarker = JSValueToObject(context, arguments[0], exception);
  40. return JSValueMakeBoolean(context, toTextMarker(thisObject)->isEqual(toTextMarker(otherMarker)));
  41. }
  42. // Destruction
  43. static void markerFinalize(JSObjectRef thisObject)
  44. {
  45. delete toTextMarker(thisObject);
  46. }
  47. // Object Creation
  48. JSObjectRef AccessibilityTextMarker::makeJSAccessibilityTextMarker(JSContextRef context, const AccessibilityTextMarker& element)
  49. {
  50. return JSObjectMake(context, AccessibilityTextMarker::getJSClass(), new AccessibilityTextMarker(element));
  51. }
  52. JSClassRef AccessibilityTextMarker::getJSClass()
  53. {
  54. static JSStaticValue staticValues[] = {
  55. { 0, 0, 0, 0 }
  56. };
  57. static JSStaticFunction staticFunctions[] = {
  58. { "isEqual", isMarkerEqualCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  59. { 0, 0, 0 }
  60. };
  61. static JSClassDefinition classDefinition = {
  62. 0, kJSClassAttributeNone, "AccessibilityTextMarker", 0, staticValues, staticFunctions,
  63. 0, markerFinalize, 0, 0, 0, 0, 0, 0, 0, 0, 0
  64. };
  65. static JSClassRef accessibilityTextMarkerClass = JSClassCreate(&classDefinition);
  66. return accessibilityTextMarkerClass;
  67. }
  68. // MARK: AccessibilityTextMarkerRange
  69. // Callback methods
  70. AccessibilityTextMarkerRange* toTextMarkerRange(JSObjectRef object)
  71. {
  72. return static_cast<AccessibilityTextMarkerRange*>(JSObjectGetPrivate(object));
  73. }
  74. static JSValueRef isMarkerRangeEqualCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
  75. {
  76. if (argumentCount != 1)
  77. return JSValueMakeBoolean(context, false);
  78. JSObjectRef otherMarker = JSValueToObject(context, arguments[0], exception);
  79. return JSValueMakeBoolean(context, toTextMarkerRange(thisObject)->isEqual(toTextMarkerRange(otherMarker)));
  80. }
  81. // Destruction
  82. static void markerRangeFinalize(JSObjectRef thisObject)
  83. {
  84. delete toTextMarkerRange(thisObject);
  85. }
  86. // Object Creation
  87. JSObjectRef AccessibilityTextMarkerRange::makeJSAccessibilityTextMarkerRange(JSContextRef context, const AccessibilityTextMarkerRange& element)
  88. {
  89. return JSObjectMake(context, AccessibilityTextMarkerRange::getJSClass(), new AccessibilityTextMarkerRange(element));
  90. }
  91. JSClassRef AccessibilityTextMarkerRange::getJSClass()
  92. {
  93. static JSStaticValue staticValues[] = {
  94. { 0, 0, 0, 0 }
  95. };
  96. static JSStaticFunction staticFunctions[] = {
  97. { "isEqual", isMarkerRangeEqualCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
  98. { 0, 0, 0 }
  99. };
  100. static JSClassDefinition classDefinition = {
  101. 0, kJSClassAttributeNone, "AccessibilityTextMarkerRange", 0, staticValues, staticFunctions,
  102. 0, markerRangeFinalize, 0, 0, 0, 0, 0, 0, 0, 0, 0
  103. };
  104. static JSClassRef accessibilityTextMarkerRangeClass = JSClassCreate(&classDefinition);
  105. return accessibilityTextMarkerRangeClass;
  106. }