Bug 1735252 [wpt PR 31197] - Regenerate WPT certificates, a=testonly
[gecko.git] / accessible / mac / GeckoTextMarker.h
blobeea8a88f855a230bf8858b61f39a4001fc72e1df
1 /* clang-format off */
2 /* -*- Mode: Objective-C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
3 /* clang-format on */
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;
15 namespace mozilla {
16 namespace a11y {
18 class Accessible;
19 class GeckoTextMarkerRange;
21 class GeckoTextMarker final {
22 public:
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();
37 bool Next();
39 bool Previous();
41 // Return a range with the given type relative to this marker.
42 GeckoTextMarkerRange Range(EWhichRange aRangeType);
44 Accessible* Leaf();
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;
55 int32_t mOffset;
57 HyperTextAccessibleWrap* ContainerAsHyperTextWrap() const {
58 return (mContainer && mContainer->IsLocal())
59 ? static_cast<HyperTextAccessibleWrap*>(
60 mContainer->AsLocal()->AsHyperText())
61 : nullptr;
64 private:
65 bool IsEditableRoot();
68 class GeckoTextMarkerRange final {
69 public:
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; };
84 /**
85 * Return text enclosed by the range.
87 NSString* Text() const;
89 /**
90 * Return the attributed text enclosed by the range.
92 NSAttributedString* AttributedText() const;
94 /**
95 * Return length of characters enclosed by the range.
97 int32_t Length() const;
99 /**
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;
120 } // namespace a11y
121 } // namespace mozilla
123 #endif