2 /* -*- Mode: Objective-C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
4 /* vim: set ts=2 et sw=2 tw=80: */
5 /* This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
9 #ifndef _GeckoTextMarker_H_
10 #define _GeckoTextMarker_H_
12 typedef CFTypeRef AXTextMarkerRef
;
13 typedef CFTypeRef AXTextMarkerRangeRef
;
19 class GeckoTextMarkerRange
;
21 class GeckoTextMarker final
{
23 GeckoTextMarker(Accessible
* aContainer
, int32_t aOffset
)
24 : mContainer(aContainer
), mOffset(aOffset
) {}
26 GeckoTextMarker(const GeckoTextMarker
& aPoint
)
27 : mContainer(aPoint
.mContainer
), mOffset(aPoint
.mOffset
) {}
29 GeckoTextMarker(Accessible
* aDoc
, AXTextMarkerRef aTextMarker
);
31 GeckoTextMarker() : mContainer(nullptr), mOffset(0) {}
33 static GeckoTextMarker
MarkerFromIndex(Accessible
* aRoot
, int32_t aIndex
);
35 id
CreateAXTextMarker();
41 // Return a range with the given type relative to this marker.
42 GeckoTextMarkerRange
Range(EWhichRange aRangeType
);
46 bool IsValid() const { return !!mContainer
; };
48 bool operator<(const GeckoTextMarker
& aPoint
) const;
50 bool operator==(const GeckoTextMarker
& aPoint
) const {
51 return mContainer
== aPoint
.mContainer
&& mOffset
== aPoint
.mOffset
;
54 Accessible
* mContainer
;
57 HyperTextAccessibleWrap
* ContainerAsHyperTextWrap() const {
58 return (mContainer
&& mContainer
->IsLocal())
59 ? static_cast<HyperTextAccessibleWrap
*>(
60 mContainer
->AsLocal()->AsHyperText())
65 bool IsEditableRoot();
68 class GeckoTextMarkerRange final
{
70 GeckoTextMarkerRange(const GeckoTextMarker
& aStart
,
71 const GeckoTextMarker
& aEnd
)
72 : mStart(aStart
), mEnd(aEnd
) {}
74 GeckoTextMarkerRange() {}
76 GeckoTextMarkerRange(Accessible
* aDoc
, AXTextMarkerRangeRef aTextMarkerRange
);
78 explicit GeckoTextMarkerRange(Accessible
* aAccessible
);
80 id
CreateAXTextMarkerRange();
82 bool IsValid() const { return !!mStart
.mContainer
&& !!mEnd
.mContainer
; };
85 * Return text enclosed by the range.
87 NSString
* Text() const;
90 * Return the attributed text enclosed by the range.
92 NSAttributedString
* AttributedText() const;
95 * Return length of characters enclosed by the range.
97 int32_t Length() const;
100 * Return screen bounds of range.
102 NSValue
* Bounds() const;
105 * Set the current range as the DOM selection.
107 MOZ_CAN_RUN_SCRIPT_BOUNDARY
void Select() const;
110 * Crops the range if it overlaps the given accessible element boundaries.
111 * Return true if successfully cropped. false if the range does not intersect
112 * with the container.
114 bool Crop(Accessible
* aContainer
);
116 GeckoTextMarker mStart
;
117 GeckoTextMarker mEnd
;
121 } // namespace mozilla