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