2012-02-02 10:14:51 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* 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/. */
|
2012-02-02 10:14:51 +04:00
|
|
|
|
|
|
|
#include "nsAccessiblePivot.h"
|
|
|
|
|
2012-05-31 12:04:41 +04:00
|
|
|
#include "HyperTextAccessible.h"
|
|
|
|
#include "nsAccUtils.h"
|
2012-02-02 10:14:51 +04:00
|
|
|
#include "States.h"
|
2019-09-19 01:23:58 +03:00
|
|
|
#include "Pivot.h"
|
2014-10-22 04:49:28 +04:00
|
|
|
#include "xpcAccessibleDocument.h"
|
2019-05-15 14:54:07 +03:00
|
|
|
#include "nsTArray.h"
|
|
|
|
#include "mozilla/Maybe.h"
|
2012-02-02 10:14:51 +04:00
|
|
|
|
|
|
|
using namespace mozilla::a11y;
|
2020-05-01 07:28:35 +03:00
|
|
|
using mozilla::DebugOnly;
|
2019-05-15 14:54:07 +03:00
|
|
|
using mozilla::Maybe;
|
2012-02-02 10:14:51 +04:00
|
|
|
|
|
|
|
/**
|
2014-04-26 06:42:19 +04:00
|
|
|
* An object that stores a given traversal rule during the pivot movement.
|
2012-02-02 10:14:51 +04:00
|
|
|
*/
|
2019-09-19 01:23:58 +03:00
|
|
|
class RuleCache : public PivotRule {
|
2012-02-02 10:14:51 +04:00
|
|
|
public:
|
2017-10-31 14:09:01 +03:00
|
|
|
explicit RuleCache(nsIAccessibleTraversalRule* aRule)
|
2019-05-15 14:54:07 +03:00
|
|
|
: mRule(aRule), mPreFilter{0} {}
|
|
|
|
~RuleCache() {}
|
2012-02-02 10:14:51 +04:00
|
|
|
|
2020-07-29 01:35:24 +03:00
|
|
|
virtual uint16_t Match(const AccessibleOrProxy& aAccOrProxy) override;
|
2012-02-02 10:14:51 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
nsCOMPtr<nsIAccessibleTraversalRule> mRule;
|
2019-05-15 14:54:07 +03:00
|
|
|
Maybe<nsTArray<uint32_t>> mAcceptRoles;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mPreFilter;
|
2012-02-02 10:14:51 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsAccessiblePivot
|
|
|
|
|
2021-02-20 02:14:32 +03:00
|
|
|
nsAccessiblePivot::nsAccessiblePivot(LocalAccessible* aRoot)
|
2013-05-24 22:13:50 +04:00
|
|
|
: mRoot(aRoot),
|
|
|
|
mModalRoot(nullptr),
|
|
|
|
mPosition(nullptr),
|
2012-02-02 10:14:51 +04:00
|
|
|
mStartOffset(-1),
|
|
|
|
mEndOffset(-1) {
|
|
|
|
NS_ASSERTION(aRoot, "A root accessible is required");
|
|
|
|
}
|
|
|
|
|
2014-06-23 23:56:09 +04:00
|
|
|
nsAccessiblePivot::~nsAccessiblePivot() {}
|
|
|
|
|
2012-02-02 10:14:51 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsISupports
|
|
|
|
|
2014-04-25 20:49:00 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION(nsAccessiblePivot, mRoot, mPosition, mObservers)
|
2012-02-02 10:14:51 +04:00
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsAccessiblePivot)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIAccessiblePivot)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIAccessiblePivot)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsAccessiblePivot)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsAccessiblePivot)
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsIAccessiblePivot
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAccessiblePivot::GetRoot(nsIAccessible** aRoot) {
|
|
|
|
NS_ENSURE_ARG_POINTER(aRoot);
|
|
|
|
|
2014-10-22 04:49:28 +04:00
|
|
|
NS_IF_ADDREF(*aRoot = ToXPC(mRoot));
|
2012-02-02 10:14:51 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAccessiblePivot::GetPosition(nsIAccessible** aPosition) {
|
|
|
|
NS_ENSURE_ARG_POINTER(aPosition);
|
|
|
|
|
2014-10-22 04:49:28 +04:00
|
|
|
NS_IF_ADDREF(*aPosition = ToXPC(mPosition));
|
2012-02-02 10:14:51 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAccessiblePivot::SetPosition(nsIAccessible* aPosition) {
|
2021-02-20 02:14:32 +03:00
|
|
|
RefPtr<LocalAccessible> position = nullptr;
|
2012-02-02 10:14:51 +04:00
|
|
|
|
|
|
|
if (aPosition) {
|
2014-10-22 04:49:28 +04:00
|
|
|
position = aPosition->ToInternalAccessible();
|
2021-02-20 02:14:32 +03:00
|
|
|
if (!position || !IsDescendantOf(position, GetActiveRoot())) {
|
2012-02-02 10:14:51 +04:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
2021-02-20 02:14:32 +03:00
|
|
|
}
|
2012-02-02 10:14:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Swap old position with new position, saves us an AddRef/Release.
|
2014-10-22 04:49:28 +04:00
|
|
|
mPosition.swap(position);
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t oldStart = mStartOffset, oldEnd = mEndOffset;
|
2012-02-02 10:14:51 +04:00
|
|
|
mStartOffset = mEndOffset = -1;
|
2014-10-22 04:49:28 +04:00
|
|
|
NotifyOfPivotChange(position, oldStart, oldEnd,
|
2018-07-16 13:56:00 +03:00
|
|
|
nsIAccessiblePivot::REASON_NONE,
|
|
|
|
nsIAccessiblePivot::NO_BOUNDARY, false);
|
2012-02-02 10:14:51 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-05-24 22:13:50 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAccessiblePivot::GetModalRoot(nsIAccessible** aModalRoot) {
|
|
|
|
NS_ENSURE_ARG_POINTER(aModalRoot);
|
|
|
|
|
2014-10-22 04:49:28 +04:00
|
|
|
NS_IF_ADDREF(*aModalRoot = ToXPC(mModalRoot));
|
2013-05-24 22:13:50 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAccessiblePivot::SetModalRoot(nsIAccessible* aModalRoot) {
|
2021-02-20 02:14:32 +03:00
|
|
|
LocalAccessible* modalRoot = nullptr;
|
2013-05-24 22:13:50 +04:00
|
|
|
|
|
|
|
if (aModalRoot) {
|
2014-10-22 04:49:28 +04:00
|
|
|
modalRoot = aModalRoot->ToInternalAccessible();
|
2021-02-20 02:14:32 +03:00
|
|
|
if (!modalRoot || !IsDescendantOf(modalRoot, mRoot)) {
|
2013-05-24 22:13:50 +04:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
2021-02-20 02:14:32 +03:00
|
|
|
}
|
2013-05-24 22:13:50 +04:00
|
|
|
}
|
|
|
|
|
2014-10-22 04:49:28 +04:00
|
|
|
mModalRoot = modalRoot;
|
2013-05-24 22:13:50 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-02-02 10:14:51 +04:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsAccessiblePivot::GetStartOffset(int32_t* aStartOffset) {
|
2012-02-02 10:14:51 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aStartOffset);
|
|
|
|
|
|
|
|
*aStartOffset = mStartOffset;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsAccessiblePivot::GetEndOffset(int32_t* aEndOffset) {
|
2012-02-02 10:14:51 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aEndOffset);
|
|
|
|
|
|
|
|
*aEndOffset = mEndOffset;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAccessiblePivot::SetTextRange(nsIAccessibleText* aTextAccessible,
|
2014-08-15 05:44:59 +04:00
|
|
|
int32_t aStartOffset, int32_t aEndOffset,
|
|
|
|
bool aIsFromUserInput, uint8_t aArgc) {
|
2012-02-02 10:14:51 +04:00
|
|
|
NS_ENSURE_ARG(aTextAccessible);
|
|
|
|
|
|
|
|
// Check that start offset is smaller than end offset, and that if a value is
|
|
|
|
// smaller than 0, both should be -1.
|
|
|
|
NS_ENSURE_TRUE(
|
|
|
|
aStartOffset <= aEndOffset &&
|
|
|
|
(aStartOffset >= 0 || (aStartOffset != -1 && aEndOffset != -1)),
|
|
|
|
NS_ERROR_INVALID_ARG);
|
|
|
|
|
2014-10-22 04:49:28 +04:00
|
|
|
nsCOMPtr<nsIAccessible> xpcAcc = do_QueryInterface(aTextAccessible);
|
|
|
|
NS_ENSURE_ARG(xpcAcc);
|
|
|
|
|
2021-02-20 02:14:32 +03:00
|
|
|
RefPtr<LocalAccessible> acc = xpcAcc->ToInternalAccessible();
|
2014-10-22 04:49:28 +04:00
|
|
|
NS_ENSURE_ARG(acc);
|
2012-06-20 03:01:10 +04:00
|
|
|
|
2014-10-22 04:49:28 +04:00
|
|
|
HyperTextAccessible* position = acc->AsHyperText();
|
2021-02-20 02:14:32 +03:00
|
|
|
if (!position || !IsDescendantOf(position, GetActiveRoot())) {
|
2012-02-02 10:14:51 +04:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
2021-02-20 02:14:32 +03:00
|
|
|
}
|
2012-02-02 10:14:51 +04:00
|
|
|
|
|
|
|
// Make sure the given offsets don't exceed the character count.
|
2021-02-20 02:14:32 +03:00
|
|
|
if (aEndOffset > static_cast<int32_t>(position->CharacterCount())) {
|
2012-02-02 10:14:51 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2021-02-20 02:14:32 +03:00
|
|
|
}
|
2012-02-02 10:14:51 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t oldStart = mStartOffset, oldEnd = mEndOffset;
|
2012-02-02 10:14:51 +04:00
|
|
|
mStartOffset = aStartOffset;
|
|
|
|
mEndOffset = aEndOffset;
|
|
|
|
|
2014-10-22 04:49:28 +04:00
|
|
|
mPosition.swap(acc);
|
|
|
|
NotifyOfPivotChange(acc, oldStart, oldEnd, nsIAccessiblePivot::REASON_NONE,
|
2018-07-16 13:56:00 +03:00
|
|
|
nsIAccessiblePivot::NO_BOUNDARY,
|
2014-08-15 05:44:59 +04:00
|
|
|
(aArgc > 0) ? aIsFromUserInput : true);
|
2012-02-02 10:14:51 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Traversal functions
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-05-31 06:00:04 +04:00
|
|
|
nsAccessiblePivot::MoveNext(nsIAccessibleTraversalRule* aRule,
|
|
|
|
nsIAccessible* aAnchor, bool aIncludeStart,
|
2014-08-15 05:44:59 +04:00
|
|
|
bool aIsFromUserInput, uint8_t aArgc,
|
|
|
|
bool* aResult) {
|
2012-02-02 10:14:51 +04:00
|
|
|
NS_ENSURE_ARG(aResult);
|
|
|
|
NS_ENSURE_ARG(aRule);
|
2012-05-31 06:00:04 +04:00
|
|
|
*aResult = false;
|
|
|
|
|
2021-02-20 02:14:32 +03:00
|
|
|
LocalAccessible* anchor = mPosition;
|
2014-10-22 04:49:28 +04:00
|
|
|
if (aArgc > 0 && aAnchor) anchor = aAnchor->ToInternalAccessible();
|
|
|
|
|
|
|
|
if (anchor &&
|
2021-02-20 02:14:32 +03:00
|
|
|
(anchor->IsDefunct() || !IsDescendantOf(anchor, GetActiveRoot()))) {
|
2012-05-15 01:21:59 +04:00
|
|
|
return NS_ERROR_NOT_IN_TREE;
|
2021-02-20 02:14:32 +03:00
|
|
|
}
|
2012-05-15 01:21:59 +04:00
|
|
|
|
2019-09-19 01:23:58 +03:00
|
|
|
Pivot pivot(GetActiveRoot());
|
|
|
|
RuleCache rule(aRule);
|
2020-07-29 01:35:24 +03:00
|
|
|
AccessibleOrProxy wrappedAnchor = AccessibleOrProxy(anchor);
|
|
|
|
AccessibleOrProxy newPos =
|
|
|
|
pivot.Next(wrappedAnchor, rule, (aArgc > 1) ? aIncludeStart : false);
|
|
|
|
if (!newPos.IsNull() && newPos.IsAccessible()) {
|
|
|
|
*aResult = MovePivotInternal(newPos.AsAccessible(),
|
|
|
|
nsIAccessiblePivot::REASON_NEXT,
|
2014-08-15 05:44:59 +04:00
|
|
|
(aArgc > 2) ? aIsFromUserInput : true);
|
2020-07-29 01:35:24 +03:00
|
|
|
} else if (newPos.IsProxy()) {
|
|
|
|
// we shouldn't ever end up with a proxy here, but if we do for some
|
|
|
|
// reason something is wrong. we should still return OK if we're null
|
|
|
|
return NS_ERROR_FAILURE;
|
2019-09-19 01:23:58 +03:00
|
|
|
}
|
2012-02-02 10:14:51 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-05-31 06:00:04 +04:00
|
|
|
nsAccessiblePivot::MovePrevious(nsIAccessibleTraversalRule* aRule,
|
|
|
|
nsIAccessible* aAnchor, bool aIncludeStart,
|
2014-08-15 05:44:59 +04:00
|
|
|
bool aIsFromUserInput, uint8_t aArgc,
|
2012-08-22 19:56:38 +04:00
|
|
|
bool* aResult) {
|
2012-02-02 10:14:51 +04:00
|
|
|
NS_ENSURE_ARG(aResult);
|
|
|
|
NS_ENSURE_ARG(aRule);
|
2012-05-31 06:00:04 +04:00
|
|
|
*aResult = false;
|
|
|
|
|
2021-02-20 02:14:32 +03:00
|
|
|
LocalAccessible* anchor = mPosition;
|
2014-10-22 04:49:28 +04:00
|
|
|
if (aArgc > 0 && aAnchor) anchor = aAnchor->ToInternalAccessible();
|
|
|
|
|
|
|
|
if (anchor &&
|
2021-02-20 02:14:32 +03:00
|
|
|
(anchor->IsDefunct() || !IsDescendantOf(anchor, GetActiveRoot()))) {
|
2012-05-15 01:21:59 +04:00
|
|
|
return NS_ERROR_NOT_IN_TREE;
|
2021-02-20 02:14:32 +03:00
|
|
|
}
|
2012-05-15 01:21:59 +04:00
|
|
|
|
2019-09-19 01:23:58 +03:00
|
|
|
Pivot pivot(GetActiveRoot());
|
|
|
|
RuleCache rule(aRule);
|
2020-07-29 01:35:24 +03:00
|
|
|
AccessibleOrProxy wrappedAnchor = AccessibleOrProxy(anchor);
|
|
|
|
AccessibleOrProxy newPos =
|
|
|
|
pivot.Prev(wrappedAnchor, rule, (aArgc > 1) ? aIncludeStart : false);
|
|
|
|
if (!newPos.IsNull() && newPos.IsAccessible()) {
|
|
|
|
*aResult = MovePivotInternal(newPos.AsAccessible(),
|
|
|
|
nsIAccessiblePivot::REASON_PREV,
|
2014-08-15 05:44:59 +04:00
|
|
|
(aArgc > 2) ? aIsFromUserInput : true);
|
2020-07-29 01:35:24 +03:00
|
|
|
} else if (newPos.IsProxy()) {
|
|
|
|
// we shouldn't ever end up with a proxy here, but if we do for some
|
|
|
|
// reason something is wrong. we should still return OK if we're null
|
|
|
|
return NS_ERROR_FAILURE;
|
2019-09-19 01:23:58 +03:00
|
|
|
}
|
2012-02-02 10:14:51 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-08-15 05:44:59 +04:00
|
|
|
nsAccessiblePivot::MoveFirst(nsIAccessibleTraversalRule* aRule,
|
|
|
|
bool aIsFromUserInput, uint8_t aArgc,
|
|
|
|
bool* aResult) {
|
2012-02-02 10:14:51 +04:00
|
|
|
NS_ENSURE_ARG(aResult);
|
|
|
|
NS_ENSURE_ARG(aRule);
|
2012-05-15 01:21:59 +04:00
|
|
|
|
2021-02-20 02:14:32 +03:00
|
|
|
LocalAccessible* root = GetActiveRoot();
|
2013-05-24 22:13:50 +04:00
|
|
|
NS_ENSURE_TRUE(root && !root->IsDefunct(), NS_ERROR_NOT_IN_TREE);
|
2012-05-15 01:21:59 +04:00
|
|
|
|
2019-09-19 01:23:58 +03:00
|
|
|
Pivot pivot(GetActiveRoot());
|
|
|
|
RuleCache rule(aRule);
|
2020-07-29 01:35:24 +03:00
|
|
|
AccessibleOrProxy newPos = pivot.First(rule);
|
|
|
|
if (!newPos.IsNull() && newPos.IsAccessible()) {
|
|
|
|
*aResult = MovePivotInternal(newPos.AsAccessible(),
|
|
|
|
nsIAccessiblePivot::REASON_FIRST,
|
2014-08-15 05:44:59 +04:00
|
|
|
(aArgc > 0) ? aIsFromUserInput : true);
|
2020-07-29 01:35:24 +03:00
|
|
|
} else if (newPos.IsProxy()) {
|
|
|
|
// we shouldn't ever end up with a proxy here, but if we do for some
|
|
|
|
// reason something is wrong. we should still return OK if we're null
|
|
|
|
return NS_ERROR_FAILURE;
|
2019-09-19 01:23:58 +03:00
|
|
|
}
|
2012-02-02 10:14:51 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-05-24 22:13:50 +04:00
|
|
|
nsAccessiblePivot::MoveLast(nsIAccessibleTraversalRule* aRule,
|
2014-08-15 05:44:59 +04:00
|
|
|
bool aIsFromUserInput, uint8_t aArgc,
|
|
|
|
bool* aResult) {
|
2012-02-02 10:14:51 +04:00
|
|
|
NS_ENSURE_ARG(aResult);
|
|
|
|
NS_ENSURE_ARG(aRule);
|
|
|
|
|
2021-02-20 02:14:32 +03:00
|
|
|
LocalAccessible* root = GetActiveRoot();
|
2013-05-24 22:13:50 +04:00
|
|
|
NS_ENSURE_TRUE(root && !root->IsDefunct(), NS_ERROR_NOT_IN_TREE);
|
2012-05-15 01:21:59 +04:00
|
|
|
|
2019-09-19 01:23:58 +03:00
|
|
|
Pivot pivot(root);
|
|
|
|
RuleCache rule(aRule);
|
2020-07-29 01:35:24 +03:00
|
|
|
AccessibleOrProxy newPos = pivot.Last(rule);
|
|
|
|
if (!newPos.IsNull() && newPos.IsAccessible()) {
|
|
|
|
*aResult = MovePivotInternal(newPos.AsAccessible(),
|
|
|
|
nsIAccessiblePivot::REASON_LAST,
|
2014-08-15 05:44:59 +04:00
|
|
|
(aArgc > 0) ? aIsFromUserInput : true);
|
2020-07-29 01:35:24 +03:00
|
|
|
} else if (newPos.IsProxy()) {
|
|
|
|
// we shouldn't ever end up with a proxy here, but if we do for some
|
|
|
|
// reason something is wrong. we should still return OK if we're null
|
|
|
|
return NS_ERROR_FAILURE;
|
2019-09-19 01:23:58 +03:00
|
|
|
}
|
2012-02-02 10:14:51 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-08-15 05:44:59 +04:00
|
|
|
nsAccessiblePivot::MoveNextByText(TextBoundaryType aBoundary,
|
|
|
|
bool aIsFromUserInput, uint8_t aArgc,
|
|
|
|
bool* aResult) {
|
2012-02-02 10:14:51 +04:00
|
|
|
NS_ENSURE_ARG(aResult);
|
|
|
|
|
|
|
|
*aResult = false;
|
|
|
|
|
2019-09-19 01:23:58 +03:00
|
|
|
Pivot pivot(GetActiveRoot());
|
2013-07-25 21:56:12 +04:00
|
|
|
|
2019-09-19 01:23:58 +03:00
|
|
|
int32_t newStart = mStartOffset, newEnd = mEndOffset;
|
2021-02-20 02:14:32 +03:00
|
|
|
LocalAccessible* newPos =
|
|
|
|
pivot.NextText(mPosition, &newStart, &newEnd, aBoundary);
|
2020-07-29 01:35:24 +03:00
|
|
|
if (newPos) {
|
2013-09-18 04:07:45 +04:00
|
|
|
*aResult = true;
|
|
|
|
int32_t oldStart = mStartOffset, oldEnd = mEndOffset;
|
2021-02-20 02:14:32 +03:00
|
|
|
LocalAccessible* oldPos = mPosition;
|
2019-09-19 01:23:58 +03:00
|
|
|
mStartOffset = newStart;
|
|
|
|
mEndOffset = newEnd;
|
|
|
|
mPosition = newPos;
|
|
|
|
NotifyOfPivotChange(oldPos, oldStart, oldEnd,
|
2018-07-16 13:56:00 +03:00
|
|
|
nsIAccessiblePivot::REASON_NEXT, aBoundary,
|
2014-08-15 05:44:59 +04:00
|
|
|
(aArgc > 0) ? aIsFromUserInput : true);
|
2013-09-18 04:07:45 +04:00
|
|
|
}
|
2019-09-19 01:23:58 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
2012-02-02 10:14:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-08-15 05:44:59 +04:00
|
|
|
nsAccessiblePivot::MovePreviousByText(TextBoundaryType aBoundary,
|
|
|
|
bool aIsFromUserInput, uint8_t aArgc,
|
|
|
|
bool* aResult) {
|
2012-02-02 10:14:51 +04:00
|
|
|
NS_ENSURE_ARG(aResult);
|
|
|
|
|
|
|
|
*aResult = false;
|
|
|
|
|
2019-09-19 01:23:58 +03:00
|
|
|
Pivot pivot(GetActiveRoot());
|
2013-09-18 04:07:45 +04:00
|
|
|
|
2019-09-19 01:23:58 +03:00
|
|
|
int32_t newStart = mStartOffset, newEnd = mEndOffset;
|
2021-02-20 02:14:32 +03:00
|
|
|
LocalAccessible* newPos =
|
|
|
|
pivot.PrevText(mPosition, &newStart, &newEnd, aBoundary);
|
2020-07-29 01:35:24 +03:00
|
|
|
if (newPos) {
|
2013-09-18 04:07:45 +04:00
|
|
|
*aResult = true;
|
|
|
|
int32_t oldStart = mStartOffset, oldEnd = mEndOffset;
|
2021-02-20 02:14:32 +03:00
|
|
|
LocalAccessible* oldPos = mPosition;
|
2019-09-19 01:23:58 +03:00
|
|
|
mStartOffset = newStart;
|
|
|
|
mEndOffset = newEnd;
|
|
|
|
mPosition = newPos;
|
|
|
|
NotifyOfPivotChange(oldPos, oldStart, oldEnd,
|
2018-07-16 13:56:00 +03:00
|
|
|
nsIAccessiblePivot::REASON_PREV, aBoundary,
|
2014-08-15 05:44:59 +04:00
|
|
|
(aArgc > 0) ? aIsFromUserInput : true);
|
2013-09-18 04:07:45 +04:00
|
|
|
}
|
2019-09-19 01:23:58 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
2012-02-02 10:14:51 +04:00
|
|
|
}
|
|
|
|
|
2012-06-21 01:07:51 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAccessiblePivot::MoveToPoint(nsIAccessibleTraversalRule* aRule, int32_t aX,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aY, bool aIgnoreNoMatch,
|
2014-08-15 05:44:59 +04:00
|
|
|
bool aIsFromUserInput, uint8_t aArgc,
|
2012-06-21 01:07:51 +04:00
|
|
|
bool* aResult) {
|
|
|
|
NS_ENSURE_ARG_POINTER(aResult);
|
|
|
|
NS_ENSURE_ARG_POINTER(aRule);
|
|
|
|
|
|
|
|
*aResult = false;
|
|
|
|
|
2021-02-20 02:14:32 +03:00
|
|
|
LocalAccessible* root = GetActiveRoot();
|
2013-05-24 22:13:50 +04:00
|
|
|
NS_ENSURE_TRUE(root && !root->IsDefunct(), NS_ERROR_NOT_IN_TREE);
|
2012-06-21 01:07:51 +04:00
|
|
|
|
2019-09-19 01:23:58 +03:00
|
|
|
RuleCache rule(aRule);
|
|
|
|
Pivot pivot(root);
|
2012-06-21 01:07:51 +04:00
|
|
|
|
2020-07-29 01:35:24 +03:00
|
|
|
AccessibleOrProxy newPos = pivot.AtPoint(aX, aY, rule);
|
|
|
|
if ((!newPos.IsNull() && newPos.IsAccessible()) ||
|
|
|
|
!aIgnoreNoMatch) { // TODO does this need a proxy check?
|
|
|
|
*aResult = MovePivotInternal(newPos.AsAccessible(),
|
|
|
|
nsIAccessiblePivot::REASON_POINT,
|
2014-08-15 05:44:59 +04:00
|
|
|
(aArgc > 0) ? aIsFromUserInput : true);
|
2020-07-29 01:35:24 +03:00
|
|
|
} else if (newPos.IsProxy()) {
|
|
|
|
// we shouldn't ever end up with a proxy here, but if we do for some
|
|
|
|
// reason something is wrong. we should still return OK if we're null
|
|
|
|
return NS_ERROR_FAILURE;
|
2019-09-19 01:23:58 +03:00
|
|
|
}
|
2012-06-21 01:07:51 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-02-02 10:14:51 +04:00
|
|
|
// Observer functions
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAccessiblePivot::AddObserver(nsIAccessiblePivotObserver* aObserver) {
|
|
|
|
NS_ENSURE_ARG(aObserver);
|
|
|
|
|
|
|
|
mObservers.AppendElement(aObserver);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAccessiblePivot::RemoveObserver(nsIAccessiblePivotObserver* aObserver) {
|
|
|
|
NS_ENSURE_ARG(aObserver);
|
|
|
|
|
|
|
|
return mObservers.RemoveElement(aObserver) ? NS_OK : NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Private utility methods
|
|
|
|
|
2021-02-20 02:14:32 +03:00
|
|
|
bool nsAccessiblePivot::IsDescendantOf(LocalAccessible* aAccessible,
|
|
|
|
LocalAccessible* aAncestor) {
|
2013-05-24 22:13:50 +04:00
|
|
|
if (!aAncestor || aAncestor->IsDefunct()) return false;
|
2012-05-15 01:21:59 +04:00
|
|
|
|
2012-05-31 02:14:23 +04:00
|
|
|
// XXX Optimize with IsInDocument() when appropriate. Blocked by bug 759875.
|
2021-02-20 02:14:32 +03:00
|
|
|
LocalAccessible* accessible = aAccessible;
|
2012-02-02 10:14:51 +04:00
|
|
|
do {
|
2013-05-24 22:13:50 +04:00
|
|
|
if (accessible == aAncestor) return true;
|
2021-02-16 23:05:10 +03:00
|
|
|
} while ((accessible = accessible->LocalParent()));
|
2012-02-02 10:14:51 +04:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-02-20 02:14:32 +03:00
|
|
|
bool nsAccessiblePivot::MovePivotInternal(LocalAccessible* aPosition,
|
2014-08-15 05:44:59 +04:00
|
|
|
PivotMoveReason aReason,
|
|
|
|
bool aIsFromUserInput) {
|
2021-02-20 02:14:32 +03:00
|
|
|
RefPtr<LocalAccessible> oldPosition = std::move(mPosition);
|
2012-02-02 10:14:51 +04:00
|
|
|
mPosition = aPosition;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t oldStart = mStartOffset, oldEnd = mEndOffset;
|
2012-02-02 10:14:51 +04:00
|
|
|
mStartOffset = mEndOffset = -1;
|
|
|
|
|
2014-08-15 05:44:59 +04:00
|
|
|
return NotifyOfPivotChange(oldPosition, oldStart, oldEnd, aReason,
|
2018-07-16 13:56:00 +03:00
|
|
|
nsIAccessiblePivot::NO_BOUNDARY, aIsFromUserInput);
|
2012-02-02 10:14:51 +04:00
|
|
|
}
|
|
|
|
|
2021-02-20 02:14:32 +03:00
|
|
|
bool nsAccessiblePivot::NotifyOfPivotChange(LocalAccessible* aOldPosition,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aOldStart, int32_t aOldEnd,
|
2018-07-16 13:56:00 +03:00
|
|
|
int16_t aReason,
|
|
|
|
int16_t aBoundaryType,
|
|
|
|
bool aIsFromUserInput) {
|
2012-06-19 03:07:56 +04:00
|
|
|
if (aOldPosition == mPosition && aOldStart == mStartOffset &&
|
2021-02-20 02:14:32 +03:00
|
|
|
aOldEnd == mEndOffset) {
|
2012-06-19 03:07:56 +04:00
|
|
|
return false;
|
2021-02-20 02:14:32 +03:00
|
|
|
}
|
2012-06-19 03:07:56 +04:00
|
|
|
|
2014-10-22 04:49:28 +04:00
|
|
|
nsCOMPtr<nsIAccessible> xpcOldPos = ToXPC(aOldPosition); // death grip
|
2020-06-16 13:14:32 +03:00
|
|
|
for (nsIAccessiblePivotObserver* obs : mObservers.ForwardRange()) {
|
2018-06-21 14:47:00 +03:00
|
|
|
obs->OnPivotChanged(this, xpcOldPos, aOldStart, aOldEnd, ToXPC(mPosition),
|
|
|
|
mStartOffset, mEndOffset, aReason, aBoundaryType,
|
2018-07-16 13:56:00 +03:00
|
|
|
aIsFromUserInput);
|
2012-02-02 10:14:51 +04:00
|
|
|
}
|
2012-06-19 03:07:56 +04:00
|
|
|
|
|
|
|
return true;
|
2012-02-02 10:14:51 +04:00
|
|
|
}
|
|
|
|
|
2020-07-29 01:35:24 +03:00
|
|
|
uint16_t RuleCache::Match(const AccessibleOrProxy& aAccOrProxy) {
|
2019-09-19 01:23:58 +03:00
|
|
|
uint16_t result = nsIAccessibleTraversalRule::FILTER_IGNORE;
|
2012-02-02 10:14:51 +04:00
|
|
|
|
|
|
|
if (!mAcceptRoles) {
|
2019-05-15 14:54:07 +03:00
|
|
|
mAcceptRoles.emplace();
|
2019-09-19 01:23:58 +03:00
|
|
|
DebugOnly<nsresult> rv = mRule->GetMatchRoles(*mAcceptRoles);
|
|
|
|
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
2012-02-02 10:14:51 +04:00
|
|
|
rv = mRule->GetPreFilter(&mPreFilter);
|
2019-09-19 01:23:58 +03:00
|
|
|
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
2012-02-02 10:14:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mPreFilter) {
|
2020-07-29 01:35:24 +03:00
|
|
|
uint64_t state;
|
|
|
|
if (aAccOrProxy.IsAccessible()) {
|
|
|
|
state = aAccOrProxy.AsAccessible()->State();
|
|
|
|
} else {
|
|
|
|
state = aAccOrProxy.AsProxy()->State();
|
|
|
|
}
|
2012-02-02 10:14:51 +04:00
|
|
|
|
2019-01-24 03:23:40 +03:00
|
|
|
if ((nsIAccessibleTraversalRule::PREFILTER_PLATFORM_PRUNED & mPreFilter) &&
|
2020-07-29 01:35:24 +03:00
|
|
|
nsAccUtils::MustPrune(aAccOrProxy)) {
|
2019-09-19 01:23:58 +03:00
|
|
|
result |= nsIAccessibleTraversalRule::FILTER_IGNORE_SUBTREE;
|
2019-01-24 03:23:40 +03:00
|
|
|
}
|
|
|
|
|
2012-02-02 10:14:51 +04:00
|
|
|
if ((nsIAccessibleTraversalRule::PREFILTER_INVISIBLE & mPreFilter) &&
|
2021-02-20 02:14:32 +03:00
|
|
|
(state & states::INVISIBLE)) {
|
2019-09-19 01:23:58 +03:00
|
|
|
return result;
|
2021-02-20 02:14:32 +03:00
|
|
|
}
|
2012-02-02 10:14:51 +04:00
|
|
|
|
|
|
|
if ((nsIAccessibleTraversalRule::PREFILTER_OFFSCREEN & mPreFilter) &&
|
2021-02-20 02:14:32 +03:00
|
|
|
(state & states::OFFSCREEN)) {
|
2019-09-19 01:23:58 +03:00
|
|
|
return result;
|
2021-02-20 02:14:32 +03:00
|
|
|
}
|
2012-02-02 10:14:51 +04:00
|
|
|
|
|
|
|
if ((nsIAccessibleTraversalRule::PREFILTER_NOT_FOCUSABLE & mPreFilter) &&
|
2021-02-20 02:14:32 +03:00
|
|
|
!(state & states::FOCUSABLE)) {
|
2019-09-19 01:23:58 +03:00
|
|
|
return result;
|
2021-02-20 02:14:32 +03:00
|
|
|
}
|
2013-05-24 22:13:51 +04:00
|
|
|
|
2020-07-29 01:35:24 +03:00
|
|
|
if (aAccOrProxy.IsAccessible() &&
|
|
|
|
(nsIAccessibleTraversalRule::PREFILTER_TRANSPARENT & mPreFilter) &&
|
2013-11-02 01:43:43 +04:00
|
|
|
!(state & states::OPAQUE1)) {
|
2020-07-29 01:35:24 +03:00
|
|
|
nsIFrame* frame = aAccOrProxy.AsAccessible()->GetFrame();
|
2016-04-12 08:52:43 +03:00
|
|
|
if (frame->StyleEffects()->mOpacity == 0.0f) {
|
2019-09-19 01:23:58 +03:00
|
|
|
return result | nsIAccessibleTraversalRule::FILTER_IGNORE_SUBTREE;
|
2013-11-02 01:43:43 +04:00
|
|
|
}
|
|
|
|
}
|
2012-02-02 10:14:51 +04:00
|
|
|
}
|
|
|
|
|
2019-05-15 14:54:07 +03:00
|
|
|
if (mAcceptRoles->Length() > 0) {
|
2020-07-29 01:35:24 +03:00
|
|
|
uint32_t accessibleRole = aAccOrProxy.Role();
|
2012-02-02 10:14:51 +04:00
|
|
|
bool matchesRole = false;
|
2019-05-15 14:54:07 +03:00
|
|
|
for (uint32_t idx = 0; idx < mAcceptRoles->Length(); idx++) {
|
|
|
|
matchesRole = mAcceptRoles->ElementAt(idx) == accessibleRole;
|
2012-02-02 10:14:51 +04:00
|
|
|
if (matchesRole) break;
|
|
|
|
}
|
2019-09-19 01:23:58 +03:00
|
|
|
|
|
|
|
if (!matchesRole) {
|
|
|
|
return result;
|
|
|
|
}
|
2012-02-02 10:14:51 +04:00
|
|
|
}
|
|
|
|
|
2019-01-24 03:23:40 +03:00
|
|
|
uint16_t matchResult = nsIAccessibleTraversalRule::FILTER_IGNORE;
|
2021-03-09 07:09:03 +03:00
|
|
|
|
|
|
|
// XXX: ToXPC takes an Accessible. This can go away when pivot
|
|
|
|
// removes AoP too.
|
|
|
|
if (aAccOrProxy.IsProxy()) {
|
|
|
|
DebugOnly<nsresult> rv =
|
|
|
|
mRule->Match(ToXPC(aAccOrProxy.AsProxy()), &matchResult);
|
|
|
|
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
|
|
|
} else {
|
|
|
|
DebugOnly<nsresult> rv =
|
|
|
|
mRule->Match(ToXPC(aAccOrProxy.AsAccessible()), &matchResult);
|
|
|
|
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
|
|
|
}
|
2019-09-19 01:23:58 +03:00
|
|
|
|
|
|
|
return result | matchResult;
|
2012-02-02 10:14:51 +04:00
|
|
|
}
|