blob: 4818e9813850270ee4ff9c21b7d54d9d09860340 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
/* clang-format off */
/* -*- Mode: Objective-C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* clang-format on */
/* vim: set ts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef _GeckoTextMarker_H_
#define _GeckoTextMarker_H_
typedef CFTypeRef AXTextMarkerRef;
typedef CFTypeRef AXTextMarkerRangeRef;
namespace mozilla {
namespace a11y {
class AccessibleOrProxy;
class GeckoTextMarkerRange;
class GeckoTextMarker final {
public:
GeckoTextMarker(const AccessibleOrProxy& aContainer, int32_t aOffset)
: mContainer(aContainer), mOffset(aOffset) {}
GeckoTextMarker(const GeckoTextMarker& aPoint)
: mContainer(aPoint.mContainer), mOffset(aPoint.mOffset) {}
GeckoTextMarker(AccessibleOrProxy aDoc, AXTextMarkerRef aTextMarker);
GeckoTextMarker() : mContainer(nullptr), mOffset(0) {}
static GeckoTextMarker MarkerFromIndex(const AccessibleOrProxy& aRoot,
int32_t aIndex);
id CreateAXTextMarker();
bool Next();
bool Previous();
// Return a range with the given type relative to this marker.
GeckoTextMarkerRange Range(EWhichRange aRangeType);
AccessibleOrProxy Leaf();
bool IsValid() const { return !mContainer.IsNull(); };
bool operator<(const GeckoTextMarker& aPoint) const;
bool operator==(const GeckoTextMarker& aPoint) const {
return mContainer == aPoint.mContainer && mOffset == aPoint.mOffset;
}
AccessibleOrProxy mContainer;
int32_t mOffset;
HyperTextAccessibleWrap* ContainerAsHyperTextWrap() const {
return mContainer.IsAccessible()
? static_cast<HyperTextAccessibleWrap*>(
mContainer.AsAccessible()->AsHyperText())
: nullptr;
}
private:
bool IsEditableRoot();
};
class GeckoTextMarkerRange final {
public:
GeckoTextMarkerRange(const GeckoTextMarker& aStart,
const GeckoTextMarker& aEnd)
: mStart(aStart), mEnd(aEnd) {}
GeckoTextMarkerRange() {}
GeckoTextMarkerRange(AccessibleOrProxy aDoc,
AXTextMarkerRangeRef aTextMarkerRange);
explicit GeckoTextMarkerRange(const AccessibleOrProxy& aAccessible);
id CreateAXTextMarkerRange();
bool IsValid() const {
return !mStart.mContainer.IsNull() && !mEnd.mContainer.IsNull();
};
/**
* Return text enclosed by the range.
*/
NSString* Text() const;
/**
* Return length of characters enclosed by the range.
*/
int32_t Length() const;
/**
* Return screen bounds of range.
*/
NSValue* Bounds() const;
/**
* Set the current range as the DOM selection.
*/
MOZ_CAN_RUN_SCRIPT_BOUNDARY void Select() const;
/**
* Crops the range if it overlaps the given accessible element boundaries.
* Return true if successfully cropped. false if the range does not intersect
* with the container.
*/
bool Crop(const AccessibleOrProxy& aContainer);
GeckoTextMarker mStart;
GeckoTextMarker mEnd;
};
} // namespace a11y
} // namespace mozilla
#endif
|