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/. */
6 
7 #ifndef mozilla_a11y_xpcAccessibleTextRange_h_
8 #define mozilla_a11y_xpcAccessibleTextRange_h_
9 
10 #include <utility>
11 
12 #include "TextRange.h"
13 #include "nsIAccessibleTextRange.h"
14 #include "xpcAccessibleHyperText.h"
15 
16 namespace mozilla {
17 namespace a11y {
18 
19 class TextRange;
20 
21 #define NS_ACCESSIBLETEXTRANGE_IMPL_IID              \
22   { /* 133c8bf4-4913-4355-bd50-426bd1d6e1ad */       \
23     0xb17652d9, 0x4f54, 0x4c56, {                    \
24       0xbb, 0x62, 0x6d, 0x5b, 0xf1, 0xef, 0x91, 0x0c \
25     }                                                \
26   }
27 
28 class xpcAccessibleTextRange final : public nsIAccessibleTextRange {
29  public:
xpcAccessibleTextRange(TextRange & aRange)30   explicit xpcAccessibleTextRange(TextRange& aRange) { SetRange(aRange); }
31 
32   NS_DECL_ISUPPORTS
33 
34   NS_IMETHOD GetStartContainer(nsIAccessibleText** aAnchor) final;
35   NS_IMETHOD GetStartOffset(int32_t* aOffset) final;
36   NS_IMETHOD GetEndContainer(nsIAccessibleText** aAnchor) final;
37   NS_IMETHOD GetEndOffset(int32_t* aOffset) final;
38   NS_IMETHOD GetContainer(nsIAccessible** aContainer) final;
39   NS_IMETHOD GetEmbeddedChildren(nsIArray** aList) final;
40   NS_IMETHOD Compare(nsIAccessibleTextRange* aOtherRange, bool* aResult) final;
41   NS_IMETHOD CompareEndPoints(uint32_t aEndPoint,
42                               nsIAccessibleTextRange* aOtherRange,
43                               uint32_t aOtherRangeEndPoint,
44                               int32_t* aResult) final;
45   NS_IMETHOD GetText(nsAString& aText) final;
46   NS_IMETHOD Crop(nsIAccessible* aContainer, bool* aSuccess) final;
47   NS_IMETHOD ScrollIntoView(uint32_t aHow) final;
48 
NS_DECLARE_STATIC_IID_ACCESSOR(NS_ACCESSIBLETEXTRANGE_IMPL_IID)49   NS_DECLARE_STATIC_IID_ACCESSOR(NS_ACCESSIBLETEXTRANGE_IMPL_IID)
50 
51  private:
52   xpcAccessibleTextRange() {}
53 
~xpcAccessibleTextRange()54   ~xpcAccessibleTextRange() {}
55 
56   friend class xpcAccessibleHyperText;
57 
58   xpcAccessibleTextRange& operator=(const xpcAccessibleTextRange&) = delete;
59 
60   void SetRange(TextRange& aRange);
61 
62   TextRange Range();
63 
64   // We can't hold a strong reference to an Accessible, but XPCOM needs strong
65   // references. Thus, instead of holding a TextRange here, we hold
66   // xpcAccessibleHyperText references and create the TextRange for each call
67   // using Range().
68   RefPtr<xpcAccessibleHyperText> mRoot;
69   RefPtr<xpcAccessibleHyperText> mStartContainer;
70   int32_t mStartOffset;
71   RefPtr<xpcAccessibleHyperText> mEndContainer;
72   int32_t mEndOffset;
73 };
74 
75 NS_DEFINE_STATIC_IID_ACCESSOR(xpcAccessibleTextRange,
76                               NS_ACCESSIBLETEXTRANGE_IMPL_IID)
77 
78 }  // namespace a11y
79 }  // namespace mozilla
80 
81 #endif
82