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#ifndef AccessibilityTextMarker_h
27#define AccessibilityTextMarker_h
28
29#include <JavaScriptCore/JSObjectRef.h>
30
31#if PLATFORM(MAC)
32#define SUPPORTS_AX_TEXTMARKERS 1
33#else
34#define SUPPORTS_AX_TEXTMARKERS 0
35#endif
36
37#if PLATFORM(MAC)
38#include <wtf/RetainPtr.h>
39typedef CFTypeRef PlatformTextMarker;
40typedef CFTypeRef PlatformTextMarkerRange;
41#else
42typedef void* PlatformTextMarker;
43typedef void* PlatformTextMarkerRange;
44#endif
45
46class AccessibilityUIElement;
47
48class AccessibilityTextMarker {
49public:
50    AccessibilityTextMarker(PlatformTextMarker);
51    AccessibilityTextMarker(const AccessibilityTextMarker&);
52    ~AccessibilityTextMarker();
53
54    PlatformTextMarker platformTextMarker() const;
55
56    static JSObjectRef makeJSAccessibilityTextMarker(JSContextRef, const AccessibilityTextMarker&);
57    bool isEqual(AccessibilityTextMarker*);
58
59private:
60    static JSClassRef getJSClass();
61#if PLATFORM(MAC)
62    RetainPtr<PlatformTextMarker> m_textMarker;
63#else
64    PlatformTextMarker m_textMarker;
65#endif
66};
67
68class AccessibilityTextMarkerRange {
69public:
70    AccessibilityTextMarkerRange(PlatformTextMarkerRange);
71    AccessibilityTextMarkerRange(const AccessibilityTextMarkerRange&);
72    ~AccessibilityTextMarkerRange();
73
74    PlatformTextMarkerRange platformTextMarkerRange() const;
75
76    static JSObjectRef makeJSAccessibilityTextMarkerRange(JSContextRef, const AccessibilityTextMarkerRange&);
77    bool isEqual(AccessibilityTextMarkerRange*);
78
79private:
80    static JSClassRef getJSClass();
81#if PLATFORM(MAC)
82    RetainPtr<PlatformTextMarkerRange> m_textMarkerRange;
83#else
84    PlatformTextMarkerRange m_textMarkerRange;
85#endif
86};
87
88AccessibilityTextMarker* toTextMarker(JSObjectRef object);
89AccessibilityTextMarkerRange* toTextMarkerRange(JSObjectRef object);
90
91#if !SUPPORTS_AX_TEXTMARKERS
92inline AccessibilityTextMarker::AccessibilityTextMarker(PlatformTextMarker) { }
93inline AccessibilityTextMarker::AccessibilityTextMarker(const AccessibilityTextMarker&) { }
94inline AccessibilityTextMarker::~AccessibilityTextMarker() { }
95inline bool AccessibilityTextMarker::isEqual(AccessibilityTextMarker*) { return false; }
96inline PlatformTextMarker AccessibilityTextMarker::platformTextMarker() const { return m_textMarker; }
97
98inline AccessibilityTextMarkerRange::AccessibilityTextMarkerRange(PlatformTextMarkerRange) { }
99inline AccessibilityTextMarkerRange::AccessibilityTextMarkerRange(const AccessibilityTextMarkerRange&) { }
100inline AccessibilityTextMarkerRange::~AccessibilityTextMarkerRange() { }
101inline bool AccessibilityTextMarkerRange::isEqual(AccessibilityTextMarkerRange*) { return false; }
102inline PlatformTextMarkerRange AccessibilityTextMarkerRange::platformTextMarkerRange() const { return m_textMarkerRange; }
103#endif
104
105#endif // AccessibilityUIElement_h
106