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_
|
|
|
|
|
2021-10-27 23:38:07 +03:00
|
|
|
#include <ApplicationServices/ApplicationServices.h>
|
|
|
|
#include <Foundation/Foundation.h>
|
|
|
|
|
|
|
|
#include "HyperTextAccessibleWrap.h"
|
|
|
|
#include "PlatformExtTypes.h"
|
|
|
|
#include "SDKDeclarations.h"
|
2020-07-03 00:35:05 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace a11y {
|
|
|
|
|
2021-07-22 20:58:49 +03:00
|
|
|
class Accessible;
|
2020-07-21 01:53:04 +03:00
|
|
|
class GeckoTextMarkerRange;
|
2020-07-03 00:35:05 +03:00
|
|
|
|
|
|
|
class GeckoTextMarker final {
|
|
|
|
public:
|
2021-07-22 20:58:49 +03:00
|
|
|
GeckoTextMarker(Accessible* aContainer, int32_t aOffset)
|
2020-07-03 00:35:05 +03:00
|
|
|
: mContainer(aContainer), mOffset(aOffset) {}
|
|
|
|
|
|
|
|
GeckoTextMarker(const GeckoTextMarker& aPoint)
|
|
|
|
: mContainer(aPoint.mContainer), mOffset(aPoint.mOffset) {}
|
|
|
|
|
2021-07-22 20:58:49 +03:00
|
|
|
GeckoTextMarker(Accessible* aDoc, AXTextMarkerRef aTextMarker);
|
2020-07-03 00:35:05 +03:00
|
|
|
|
|
|
|
GeckoTextMarker() : mContainer(nullptr), mOffset(0) {}
|
|
|
|
|
2021-07-22 20:58:49 +03:00
|
|
|
static GeckoTextMarker MarkerFromIndex(Accessible* aRoot, int32_t aIndex);
|
2020-08-27 23:06:51 +03:00
|
|
|
|
2021-10-27 23:38:07 +03:00
|
|
|
AXTextMarkerRef CreateAXTextMarker();
|
2020-07-03 00:35:05 +03:00
|
|
|
|
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
|
|
|
|
2021-07-22 20:58:49 +03:00
|
|
|
Accessible* Leaf();
|
2020-09-11 08:08:00 +03:00
|
|
|
|
2021-07-22 20:58:49 +03:00
|
|
|
bool IsValid() const { return !!mContainer; };
|
2020-07-22 21:08:10 +03:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2021-07-22 20:58:49 +03:00
|
|
|
Accessible* mContainer;
|
2020-07-03 00:35:05 +03:00
|
|
|
int32_t mOffset;
|
2020-07-21 01:53:04 +03:00
|
|
|
|
2020-08-14 22:33:02 +03:00
|
|
|
HyperTextAccessibleWrap* ContainerAsHyperTextWrap() const {
|
2021-07-22 20:58:49 +03:00
|
|
|
return (mContainer && mContainer->IsLocal())
|
2020-08-26 00:40:32 +03:00
|
|
|
? static_cast<HyperTextAccessibleWrap*>(
|
2021-07-22 20:58:49 +03:00
|
|
|
mContainer->AsLocal()->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() {}
|
|
|
|
|
2021-07-22 20:58:49 +03:00
|
|
|
GeckoTextMarkerRange(Accessible* aDoc, AXTextMarkerRangeRef aTextMarkerRange);
|
2020-07-03 00:35:05 +03:00
|
|
|
|
2021-07-22 20:58:49 +03:00
|
|
|
explicit GeckoTextMarkerRange(Accessible* aAccessible);
|
2020-09-11 08:07:52 +03:00
|
|
|
|
2021-10-27 23:38:07 +03:00
|
|
|
AXTextMarkerRangeRef CreateAXTextMarkerRange();
|
2020-07-03 00:35:05 +03:00
|
|
|
|
2021-07-22 20:58:49 +03:00
|
|
|
bool IsValid() const { return !!mStart.mContainer && !!mEnd.mContainer; };
|
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
|
|
|
|
2021-02-09 02:26:31 +03:00
|
|
|
/**
|
|
|
|
* Return the attributed text enclosed by the range.
|
|
|
|
*/
|
|
|
|
NSAttributedString* AttributedText() const;
|
|
|
|
|
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.
|
|
|
|
*/
|
2021-07-22 20:58:49 +03:00
|
|
|
bool Crop(Accessible* aContainer);
|
2020-11-21 07:13:45 +03:00
|
|
|
|
2020-07-03 00:35:05 +03:00
|
|
|
GeckoTextMarker mStart;
|
|
|
|
GeckoTextMarker mEnd;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace a11y
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif
|