2020-07-03 00:35:05 +03:00
|
|
|
/* 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;
|
2020-07-21 01:53:04 +03:00
|
|
|
class GeckoTextMarkerRange;
|
2020-07-03 00:35:05 +03:00
|
|
|
|
|
|
|
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) {}
|
|
|
|
|
2020-08-27 23:06:51 +03:00
|
|
|
static GeckoTextMarker MarkerFromIndex(const AccessibleOrProxy& aRoot,
|
|
|
|
int32_t aIndex);
|
|
|
|
|
2020-07-03 00:35:05 +03:00
|
|
|
id CreateAXTextMarker();
|
|
|
|
|
2020-08-14 22:33:02 +03:00
|
|
|
bool Next();
|
2020-07-21 01:53:04 +03:00
|
|
|
|
2020-08-14 22:33:02 +03:00
|
|
|
bool Previous();
|
2020-07-21 01:53:04 +03:00
|
|
|
|
2020-09-24 19:04:41 +03:00
|
|
|
// Return a range with the given type relative to this marker.
|
|
|
|
GeckoTextMarkerRange Range(EWhichRange aRangeType);
|
2020-07-21 01:53:04 +03:00
|
|
|
|
2020-09-11 08:08:00 +03:00
|
|
|
AccessibleOrProxy Leaf();
|
|
|
|
|
2020-07-22 21:08:10 +03:00
|
|
|
bool IsValid() const { return !mContainer.IsNull(); };
|
|
|
|
|
2020-07-03 00:35:05 +03:00
|
|
|
bool operator<(const GeckoTextMarker& aPoint) const;
|
|
|
|
|
2021-01-23 00:12:56 +03:00
|
|
|
bool operator==(const GeckoTextMarker& aPoint) const {
|
|
|
|
return mContainer == aPoint.mContainer && mOffset == aPoint.mOffset;
|
|
|
|
}
|
|
|
|
|
2020-07-03 00:35:05 +03:00
|
|
|
AccessibleOrProxy mContainer;
|
|
|
|
int32_t mOffset;
|
2020-07-21 01:53:04 +03:00
|
|
|
|
2020-08-14 22:33:02 +03:00
|
|
|
HyperTextAccessibleWrap* ContainerAsHyperTextWrap() const {
|
|
|
|
return mContainer.IsAccessible()
|
2020-08-26 00:40:32 +03:00
|
|
|
? static_cast<HyperTextAccessibleWrap*>(
|
|
|
|
mContainer.AsAccessible()->AsHyperText())
|
2020-08-14 22:33:02 +03:00
|
|
|
: nullptr;
|
|
|
|
}
|
|
|
|
|
2020-07-21 01:53:04 +03:00
|
|
|
private:
|
2020-07-22 02:02:57 +03:00
|
|
|
bool IsEditableRoot();
|
2020-07-03 00:35:05 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
class GeckoTextMarkerRange final {
|
|
|
|
public:
|
2020-08-26 00:40:32 +03:00
|
|
|
GeckoTextMarkerRange(const GeckoTextMarker& aStart,
|
|
|
|
const GeckoTextMarker& aEnd)
|
2020-07-03 00:35:05 +03:00
|
|
|
: mStart(aStart), mEnd(aEnd) {}
|
|
|
|
|
2020-11-21 07:13:45 +03:00
|
|
|
GeckoTextMarkerRange() {}
|
|
|
|
|
2020-08-26 00:40:32 +03:00
|
|
|
GeckoTextMarkerRange(AccessibleOrProxy aDoc,
|
|
|
|
AXTextMarkerRangeRef aTextMarkerRange);
|
2020-07-03 00:35:05 +03:00
|
|
|
|
2020-09-11 08:07:52 +03:00
|
|
|
explicit GeckoTextMarkerRange(const AccessibleOrProxy& aAccessible);
|
|
|
|
|
2020-07-03 00:35:05 +03:00
|
|
|
id CreateAXTextMarkerRange();
|
|
|
|
|
2020-08-26 00:40:32 +03:00
|
|
|
bool IsValid() const {
|
|
|
|
return !mStart.mContainer.IsNull() && !mEnd.mContainer.IsNull();
|
|
|
|
};
|
2020-07-03 00:57:55 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return text enclosed by the range.
|
|
|
|
*/
|
|
|
|
NSString* Text() const;
|
2020-07-03 00:35:05 +03:00
|
|
|
|
2020-08-27 23:06:51 +03:00
|
|
|
/**
|
|
|
|
* Return length of characters enclosed by the range.
|
|
|
|
*/
|
|
|
|
int32_t Length() const;
|
|
|
|
|
2020-08-21 01:12:23 +03:00
|
|
|
/**
|
|
|
|
* Return screen bounds of range.
|
|
|
|
*/
|
|
|
|
NSValue* Bounds() const;
|
|
|
|
|
2020-09-22 01:00:08 +03:00
|
|
|
/**
|
|
|
|
* Set the current range as the DOM selection.
|
|
|
|
*/
|
|
|
|
MOZ_CAN_RUN_SCRIPT_BOUNDARY void Select() const;
|
|
|
|
|
2020-11-21 07:13:45 +03:00
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
2020-07-03 00:35:05 +03:00
|
|
|
GeckoTextMarker mStart;
|
|
|
|
GeckoTextMarker mEnd;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace a11y
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif
|