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