no bug - Correct some typos in the comments. a=typo-fix
[gecko.git] / accessible / mac / GeckoTextMarker.h
blob0e8f6606940d4c7a74903cf87197b65ce3b8601f
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 #include <ApplicationServices/ApplicationServices.h>
13 #include <Foundation/Foundation.h>
15 #include "TextLeafRange.h"
17 namespace mozilla {
18 namespace a11y {
20 class Accessible;
21 class GeckoTextMarkerRange;
23 class GeckoTextMarker final {
24 public:
25 GeckoTextMarker(Accessible* aAcc, int32_t aOffset);
27 explicit GeckoTextMarker(const TextLeafPoint& aTextLeafPoint)
28 : mPoint(aTextLeafPoint) {}
30 GeckoTextMarker() : mPoint() {}
32 static GeckoTextMarker MarkerFromAXTextMarker(Accessible* aDoc,
33 AXTextMarkerRef aTextMarker);
35 static GeckoTextMarker MarkerFromIndex(Accessible* aRoot, int32_t aIndex);
37 AXTextMarkerRef CreateAXTextMarker();
39 bool Next();
41 bool Previous();
43 GeckoTextMarkerRange LeftWordRange() const;
45 GeckoTextMarkerRange RightWordRange() const;
47 GeckoTextMarkerRange LineRange() const;
49 GeckoTextMarkerRange LeftLineRange() const;
51 GeckoTextMarkerRange RightLineRange() const;
53 GeckoTextMarkerRange ParagraphRange() const;
55 GeckoTextMarkerRange StyleRange() const;
57 int32_t& Offset() { return mPoint.mOffset; }
59 Accessible* Leaf();
61 Accessible* Acc() const { return mPoint.mAcc; }
63 bool IsValid() const { return !!mPoint; };
65 bool operator<(const GeckoTextMarker& aOther) const {
66 return mPoint < aOther.mPoint;
69 bool operator==(const GeckoTextMarker& aOther) const {
70 return mPoint == aOther.mPoint;
73 TextLeafPoint mPoint;
76 class GeckoTextMarkerRange final {
77 public:
78 GeckoTextMarkerRange(const GeckoTextMarker& aStart,
79 const GeckoTextMarker& aEnd)
80 : mRange(aStart.mPoint, aEnd.mPoint) {}
82 GeckoTextMarkerRange(const TextLeafPoint& aStart, const TextLeafPoint& aEnd)
83 : mRange(aStart, aEnd) {}
85 GeckoTextMarkerRange() {}
87 explicit GeckoTextMarkerRange(Accessible* aAccessible);
89 static GeckoTextMarkerRange MarkerRangeFromAXTextMarkerRange(
90 Accessible* aDoc, AXTextMarkerRangeRef aTextMarkerRange);
92 AXTextMarkerRangeRef CreateAXTextMarkerRange();
94 bool IsValid() const { return !!mRange.Start() && !!mRange.End(); };
96 GeckoTextMarker Start() { return GeckoTextMarker(mRange.Start()); }
98 GeckoTextMarker End() { return GeckoTextMarker(mRange.End()); }
101 * Return text enclosed by the range.
103 NSString* Text() const;
106 * Return the attributed text enclosed by the range.
108 NSAttributedString* AttributedText() const;
111 * Return length of characters enclosed by the range.
113 int32_t Length() const;
116 * Return screen bounds of range.
118 NSValue* Bounds() const;
121 * Set the current range as the DOM selection.
123 MOZ_CAN_RUN_SCRIPT_BOUNDARY void Select() const;
126 * Crops the range if it overlaps the given accessible element boundaries.
127 * Return true if successfully cropped. false if the range does not intersect
128 * with the container.
130 bool Crop(Accessible* aContainer) { return mRange.Crop(aContainer); }
132 TextLeafRange mRange;
135 } // namespace a11y
136 } // namespace mozilla
138 #endif