1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "xpcAccessiblePivot.h"
8 #include "xpcAccessibleDocument.h"
12 using namespace mozilla::a11y
;
14 using mozilla::DebugOnly
;
17 * An object that stores a given traversal rule during the pivot movement.
19 class xpcPivotRule
: public PivotRule
{
21 explicit xpcPivotRule(nsIAccessibleTraversalRule
* aRule
) : mRule(aRule
) {}
24 virtual uint16_t Match(Accessible
* aAcc
) override
;
27 nsCOMPtr
<nsIAccessibleTraversalRule
> mRule
;
30 ////////////////////////////////////////////////////////////////////////////////
33 xpcAccessiblePivot::xpcAccessiblePivot(nsIAccessible
* aRoot
) : mRoot(aRoot
) {
34 NS_ASSERTION(aRoot
, "A root accessible is required");
37 xpcAccessiblePivot::~xpcAccessiblePivot() {}
39 ////////////////////////////////////////////////////////////////////////////////
42 NS_IMPL_CYCLE_COLLECTION(xpcAccessiblePivot
, mRoot
)
44 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(xpcAccessiblePivot
)
45 NS_INTERFACE_MAP_ENTRY(nsIAccessiblePivot
)
46 NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports
, nsIAccessiblePivot
)
49 NS_IMPL_CYCLE_COLLECTING_ADDREF(xpcAccessiblePivot
)
50 NS_IMPL_CYCLE_COLLECTING_RELEASE(xpcAccessiblePivot
)
52 ////////////////////////////////////////////////////////////////////////////////
56 xpcAccessiblePivot::Next(nsIAccessible
* aAnchor
,
57 nsIAccessibleTraversalRule
* aRule
, bool aIncludeStart
,
58 uint8_t aArgc
, nsIAccessible
** aResult
) {
59 NS_ENSURE_ARG(aResult
);
62 Accessible
* root
= Root();
63 Accessible
* anchor
= aAnchor
->ToInternalGeneric();
64 NS_ENSURE_TRUE(root
&& anchor
, NS_ERROR_NOT_IN_TREE
);
67 xpcPivotRule
rule(aRule
);
69 pivot
.Next(anchor
, rule
, (aArgc
> 0) ? aIncludeStart
: false);
70 NS_IF_ADDREF(*aResult
= ToXPC(result
));
76 xpcAccessiblePivot::Prev(nsIAccessible
* aAnchor
,
77 nsIAccessibleTraversalRule
* aRule
, bool aIncludeStart
,
78 uint8_t aArgc
, nsIAccessible
** aResult
) {
79 NS_ENSURE_ARG(aResult
);
82 Accessible
* root
= Root();
83 Accessible
* anchor
= aAnchor
->ToInternalGeneric();
84 NS_ENSURE_TRUE(root
&& anchor
, NS_ERROR_NOT_IN_TREE
);
87 xpcPivotRule
rule(aRule
);
89 pivot
.Prev(anchor
, rule
, (aArgc
> 0) ? aIncludeStart
: false);
90 NS_IF_ADDREF(*aResult
= ToXPC(result
));
96 xpcAccessiblePivot::First(nsIAccessibleTraversalRule
* aRule
,
97 nsIAccessible
** aResult
) {
98 NS_ENSURE_ARG(aResult
);
101 Accessible
* root
= Root();
102 NS_ENSURE_TRUE(root
, NS_ERROR_NOT_IN_TREE
);
105 xpcPivotRule
rule(aRule
);
106 Accessible
* result
= pivot
.First(rule
);
107 NS_IF_ADDREF(*aResult
= ToXPC(result
));
113 xpcAccessiblePivot::Last(nsIAccessibleTraversalRule
* aRule
,
114 nsIAccessible
** aResult
) {
115 NS_ENSURE_ARG(aResult
);
116 NS_ENSURE_ARG(aRule
);
118 Accessible
* root
= Root();
119 NS_ENSURE_TRUE(root
, NS_ERROR_NOT_IN_TREE
);
122 xpcPivotRule
rule(aRule
);
123 Accessible
* result
= pivot
.Last(rule
);
124 NS_IF_ADDREF(*aResult
= ToXPC(result
));
130 xpcAccessiblePivot::AtPoint(int32_t aX
, int32_t aY
,
131 nsIAccessibleTraversalRule
* aRule
,
132 nsIAccessible
** aResult
) {
133 NS_ENSURE_ARG_POINTER(aResult
);
134 NS_ENSURE_ARG_POINTER(aRule
);
136 Accessible
* root
= Root();
137 NS_ENSURE_TRUE(root
, NS_ERROR_NOT_IN_TREE
);
139 xpcPivotRule
rule(aRule
);
142 Accessible
* result
= pivot
.AtPoint(aX
, aY
, rule
);
143 NS_IF_ADDREF(*aResult
= ToXPC(result
));
148 uint16_t xpcPivotRule::Match(Accessible
* aAcc
) {
149 uint16_t matchResult
= nsIAccessibleTraversalRule::FILTER_IGNORE
;
151 DebugOnly
<nsresult
> rv
= mRule
->Match(ToXPC(aAcc
), &matchResult
);
152 MOZ_ASSERT(NS_SUCCEEDED(rv
));