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 #include <ApplicationServices/ApplicationServices.h>
13 #include <Foundation/Foundation.h>
15 #include "HyperTextAccessibleWrap.h"
16 #include "PlatformExtTypes.h"
17 #include "SDKDeclarations.h"
23 class GeckoTextMarkerRange
;
25 class GeckoTextMarker final
{
27 GeckoTextMarker(Accessible
* aContainer
, int32_t aOffset
)
28 : mContainer(aContainer
), mOffset(aOffset
) {}
30 GeckoTextMarker(const GeckoTextMarker
& aPoint
)
31 : mContainer(aPoint
.mContainer
), mOffset(aPoint
.mOffset
) {}
33 GeckoTextMarker(Accessible
* aDoc
, AXTextMarkerRef aTextMarker
);
35 GeckoTextMarker() : mContainer(nullptr), mOffset(0) {}
37 static GeckoTextMarker
MarkerFromIndex(Accessible
* aRoot
, int32_t aIndex
);
39 AXTextMarkerRef
CreateAXTextMarker();
45 // Return a range with the given type relative to this marker.
46 GeckoTextMarkerRange
Range(EWhichRange aRangeType
);
50 bool IsValid() const { return !!mContainer
; };
52 bool operator<(const GeckoTextMarker
& aPoint
) const;
54 bool operator==(const GeckoTextMarker
& aPoint
) const {
55 return mContainer
== aPoint
.mContainer
&& mOffset
== aPoint
.mOffset
;
58 Accessible
* mContainer
;
61 HyperTextAccessibleWrap
* ContainerAsHyperTextWrap() const {
62 return (mContainer
&& mContainer
->IsLocal())
63 ? static_cast<HyperTextAccessibleWrap
*>(
64 mContainer
->AsLocal()->AsHyperText())
69 bool IsEditableRoot();
72 class GeckoTextMarkerRange final
{
74 GeckoTextMarkerRange(const GeckoTextMarker
& aStart
,
75 const GeckoTextMarker
& aEnd
)
76 : mStart(aStart
), mEnd(aEnd
) {}
78 GeckoTextMarkerRange() {}
80 GeckoTextMarkerRange(Accessible
* aDoc
, AXTextMarkerRangeRef aTextMarkerRange
);
82 explicit GeckoTextMarkerRange(Accessible
* aAccessible
);
84 AXTextMarkerRangeRef
CreateAXTextMarkerRange();
86 bool IsValid() const { return !!mStart
.mContainer
&& !!mEnd
.mContainer
; };
89 * Return text enclosed by the range.
91 NSString
* Text() const;
94 * Return the attributed text enclosed by the range.
96 NSAttributedString
* AttributedText() const;
99 * Return length of characters enclosed by the range.
101 int32_t Length() const;
104 * Return screen bounds of range.
106 NSValue
* Bounds() const;
109 * Set the current range as the DOM selection.
111 MOZ_CAN_RUN_SCRIPT_BOUNDARY
void Select() const;
114 * Crops the range if it overlaps the given accessible element boundaries.
115 * Return true if successfully cropped. false if the range does not intersect
116 * with the container.
118 bool Crop(Accessible
* aContainer
);
120 GeckoTextMarker mStart
;
121 GeckoTextMarker mEnd
;
125 } // namespace mozilla