2019-09-19 01:23:58 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* 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 mozilla_a11y_Pivot_h_
|
|
|
|
#define mozilla_a11y_Pivot_h_
|
|
|
|
|
|
|
|
#include <stdint.h>
|
2020-05-29 20:37:46 +03:00
|
|
|
#include "Role.h"
|
2019-09-19 01:23:58 +03:00
|
|
|
#include "mozilla/dom/ChildIterator.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace a11y {
|
|
|
|
|
|
|
|
class DocAccessible;
|
2021-07-22 20:58:49 +03:00
|
|
|
class Accessible;
|
2019-09-19 01:23:58 +03:00
|
|
|
|
|
|
|
class PivotRule {
|
|
|
|
public:
|
|
|
|
// A filtering function that returns a bitmask from
|
|
|
|
// nsIAccessibleTraversalRule: FILTER_IGNORE (0x0): Don't match this
|
|
|
|
// accessible. FILTER_MATCH (0x1): Match this accessible FILTER_IGNORE_SUBTREE
|
|
|
|
// (0x2): Ignore accessible's subtree.
|
2021-07-22 20:58:49 +03:00
|
|
|
virtual uint16_t Match(Accessible* aAcc) = 0;
|
2019-09-19 01:23:58 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
// The Pivot class is used for searching for accessible nodes in a given subtree
|
|
|
|
// with a given criteria. Since it only holds a weak reference to the root,
|
|
|
|
// this class is meant to be used primarily on the stack.
|
|
|
|
class Pivot final {
|
|
|
|
public:
|
2021-07-22 20:58:49 +03:00
|
|
|
explicit Pivot(Accessible* aRoot);
|
2019-09-19 01:23:58 +03:00
|
|
|
Pivot() = delete;
|
|
|
|
Pivot(const Pivot&) = delete;
|
|
|
|
Pivot& operator=(const Pivot&) = delete;
|
|
|
|
|
|
|
|
~Pivot();
|
|
|
|
|
|
|
|
// Return the next accessible after aAnchor in pre-order that matches the
|
|
|
|
// given rule. If aIncludeStart, return aAnchor if it matches the rule.
|
2021-07-22 20:58:49 +03:00
|
|
|
Accessible* Next(Accessible* aAnchor, PivotRule& aRule,
|
|
|
|
bool aIncludeStart = false);
|
2019-09-19 01:23:58 +03:00
|
|
|
|
|
|
|
// Return the previous accessible before aAnchor in pre-order that matches the
|
|
|
|
// given rule. If aIncludeStart, return aAnchor if it matches the rule.
|
2021-07-22 20:58:49 +03:00
|
|
|
Accessible* Prev(Accessible* aAnchor, PivotRule& aRule,
|
|
|
|
bool aIncludeStart = false);
|
2019-09-19 01:23:58 +03:00
|
|
|
|
|
|
|
// Return the first accessible within the root that matches the pivot rule.
|
2021-07-22 20:58:49 +03:00
|
|
|
Accessible* First(PivotRule& aRule);
|
2019-09-19 01:23:58 +03:00
|
|
|
|
|
|
|
// Return the last accessible within the root that matches the pivot rule.
|
2021-07-22 20:58:49 +03:00
|
|
|
Accessible* Last(PivotRule& aRule);
|
2019-09-19 01:23:58 +03:00
|
|
|
|
|
|
|
// Return the next range of text according to the boundary type.
|
2022-02-15 08:35:14 +03:00
|
|
|
Accessible* NextText(Accessible* aAnchor, int32_t* aStartOffset,
|
|
|
|
int32_t* aEndOffset, int32_t aBoundaryType);
|
2019-09-19 01:23:58 +03:00
|
|
|
|
|
|
|
// Return the previous range of text according to the boundary type.
|
2022-02-15 08:35:14 +03:00
|
|
|
Accessible* PrevText(Accessible* aAnchor, int32_t* aStartOffset,
|
|
|
|
int32_t* aEndOffset, int32_t aBoundaryType);
|
2019-09-19 01:23:58 +03:00
|
|
|
|
|
|
|
// Return the accessible at the given screen coordinate if it matches the
|
|
|
|
// pivot rule.
|
2021-07-22 20:58:49 +03:00
|
|
|
Accessible* AtPoint(int32_t aX, int32_t aY, PivotRule& aRule);
|
2019-09-19 01:23:58 +03:00
|
|
|
|
|
|
|
private:
|
2021-07-22 20:58:49 +03:00
|
|
|
Accessible* AdjustStartPosition(Accessible* aAnchor, PivotRule& aRule,
|
|
|
|
uint16_t* aFilterResult);
|
2019-09-19 01:23:58 +03:00
|
|
|
|
|
|
|
// Search in preorder for the first accessible to match the rule.
|
2021-07-22 20:58:49 +03:00
|
|
|
Accessible* SearchForward(Accessible* aAnchor, PivotRule& aRule,
|
|
|
|
bool aSearchCurrent);
|
2019-09-19 01:23:58 +03:00
|
|
|
|
|
|
|
// Reverse search in preorder for the first accessible to match the rule.
|
2021-07-22 20:58:49 +03:00
|
|
|
Accessible* SearchBackward(Accessible* aAnchor, PivotRule& aRule,
|
|
|
|
bool aSearchCurrent);
|
2019-09-19 01:23:58 +03:00
|
|
|
|
|
|
|
// Search in preorder for the first text accessible.
|
2022-02-15 08:35:14 +03:00
|
|
|
Accessible* SearchForText(Accessible* aAnchor, bool aBackward);
|
2019-09-19 01:23:58 +03:00
|
|
|
|
2021-07-22 20:58:49 +03:00
|
|
|
Accessible* mRoot;
|
2019-09-19 01:23:58 +03:00
|
|
|
};
|
|
|
|
|
2020-05-29 20:37:46 +03:00
|
|
|
/**
|
2020-08-05 00:00:25 +03:00
|
|
|
* This rule matches accessibles on a given role, filtering out non-direct
|
|
|
|
* descendants if necessary.
|
2020-05-29 20:37:46 +03:00
|
|
|
*/
|
2020-09-02 01:12:55 +03:00
|
|
|
class PivotRoleRule : public PivotRule {
|
2020-05-29 20:37:46 +03:00
|
|
|
public:
|
|
|
|
explicit PivotRoleRule(role aRole);
|
2021-07-22 20:58:49 +03:00
|
|
|
explicit PivotRoleRule(role aRole, Accessible* aDirectDescendantsFrom);
|
2020-05-29 20:37:46 +03:00
|
|
|
|
2021-07-22 20:58:49 +03:00
|
|
|
virtual uint16_t Match(Accessible* aAcc) override;
|
2020-05-29 20:37:46 +03:00
|
|
|
|
2020-09-02 01:12:55 +03:00
|
|
|
protected:
|
2020-05-29 20:37:46 +03:00
|
|
|
role mRole;
|
2021-07-22 20:58:49 +03:00
|
|
|
Accessible* mDirectDescendantsFrom;
|
2020-05-29 20:37:46 +03:00
|
|
|
};
|
|
|
|
|
2022-02-16 21:42:53 +03:00
|
|
|
/**
|
|
|
|
* This rule matches accessibles with a given state.
|
|
|
|
*/
|
|
|
|
class PivotStateRule : public PivotRule {
|
|
|
|
public:
|
|
|
|
explicit PivotStateRule(uint64_t aState);
|
|
|
|
|
|
|
|
virtual uint16_t Match(Accessible* aAcc) override;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
uint64_t mState;
|
|
|
|
};
|
|
|
|
|
2021-01-25 04:12:17 +03:00
|
|
|
/**
|
2021-02-20 02:14:33 +03:00
|
|
|
* This rule matches any local LocalAccessible (i.e. not RemoteAccessible) in
|
|
|
|
* the same document as the anchor. That is, it includes any descendant
|
2021-01-25 04:12:17 +03:00
|
|
|
* OuterDocAccessible, but not its descendants.
|
|
|
|
*/
|
|
|
|
class LocalAccInSameDocRule : public PivotRule {
|
|
|
|
public:
|
2021-07-22 20:58:49 +03:00
|
|
|
virtual uint16_t Match(Accessible* aAcc) override;
|
2021-01-25 04:12:17 +03:00
|
|
|
};
|
|
|
|
|
2019-09-19 01:23:58 +03:00
|
|
|
} // namespace a11y
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_a11y_Pivot_h_
|