Bug 1890277: part 2) Add `require-trusted-types-for` directive to CSP parser, guarded...
[gecko.git] / accessible / xpcom / xpcAccessibleTextLeafRange.cpp
blob8f493deea59932f52f8aaf845201b4b08a2c5547
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 file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "xpcAccessibleTextLeafRange.h"
9 #include "nsIAccessible.h"
10 #include "TextLeafRange.h"
11 #include "xpcAccessibleDocument.h"
13 using namespace mozilla;
14 using namespace mozilla::a11y;
16 // xpcAccessibleTextLeafPoint
18 NS_IMPL_ADDREF(xpcAccessibleTextLeafPoint)
19 NS_IMPL_RELEASE(xpcAccessibleTextLeafPoint)
21 NS_IMPL_QUERY_INTERFACE(xpcAccessibleTextLeafPoint, nsIAccessibleTextLeafPoint)
23 xpcAccessibleTextLeafPoint::xpcAccessibleTextLeafPoint(
24 nsIAccessible* aAccessible, int32_t aOffset)
25 : mAccessible(nullptr), mOffset(0) {
26 // When constructing a text point it will actualize the offset
27 // and adjust the accessible to the appropriate leaf. These
28 // might differ from the given constructor arguments.
29 if (aAccessible) {
30 TextLeafPoint point(aAccessible->ToInternalGeneric(), aOffset);
31 mAccessible = ToXPC(point.mAcc);
32 mOffset = point.mOffset;
36 NS_IMETHODIMP xpcAccessibleTextLeafPoint::GetAccessible(
37 nsIAccessible** aAccessible) {
38 NS_ENSURE_ARG_POINTER(aAccessible);
39 RefPtr<nsIAccessible> acc = mAccessible;
40 acc.forget(aAccessible);
41 return NS_OK;
44 NS_IMETHODIMP xpcAccessibleTextLeafPoint::SetAccessible(
45 nsIAccessible* aAccessible) {
46 mAccessible = aAccessible;
47 return NS_OK;
50 NS_IMETHODIMP xpcAccessibleTextLeafPoint::GetOffset(int32_t* aOffset) {
51 NS_ENSURE_ARG_POINTER(aOffset);
52 *aOffset = mOffset;
53 return NS_OK;
55 NS_IMETHODIMP xpcAccessibleTextLeafPoint::SetOffset(int32_t aOffset) {
56 mOffset = aOffset;
57 return NS_OK;
60 NS_IMETHODIMP xpcAccessibleTextLeafPoint::FindBoundary(
61 AccessibleTextBoundary aBoundaryType, uint32_t aDirection, uint32_t aFlags,
62 nsIAccessibleTextLeafPoint** aPoint) {
63 TextLeafPoint thisPoint = ToPoint();
64 if (!thisPoint) {
65 return NS_ERROR_FAILURE;
68 TextLeafPoint result = thisPoint.FindBoundary(
69 aBoundaryType, static_cast<nsDirection>(aDirection),
70 static_cast<TextLeafPoint::BoundaryFlags>(aFlags));
71 RefPtr<xpcAccessibleTextLeafPoint> point = new xpcAccessibleTextLeafPoint(
72 result ? ToXPC(result.mAcc) : nullptr, result ? result.mOffset : 0);
73 point.forget(aPoint);
74 return NS_OK;
77 TextLeafPoint xpcAccessibleTextLeafPoint::ToPoint() {
78 if (mAccessible) {
79 return TextLeafPoint(mAccessible->ToInternalGeneric(), mOffset);
82 return TextLeafPoint();