|
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/. */ |
|
6 |
|
7 #ifndef mozilla_a11y_TextRange_h__ |
|
8 #define mozilla_a11y_TextRange_h__ |
|
9 |
|
10 #include "mozilla/Move.h" |
|
11 #include "nsAutoPtr.h" |
|
12 |
|
13 namespace mozilla { |
|
14 namespace a11y { |
|
15 |
|
16 class Accessible; |
|
17 class HyperTextAccessible; |
|
18 |
|
19 /** |
|
20 * Represents a text range within the text control or document. |
|
21 */ |
|
22 class TextRange MOZ_FINAL |
|
23 { |
|
24 public: |
|
25 TextRange(HyperTextAccessible* aRoot, |
|
26 Accessible* aStartContainer, int32_t aStartOffset, |
|
27 Accessible* aEndContainer, int32_t aEndOffset); |
|
28 TextRange() {} |
|
29 TextRange(TextRange&& aRange) : |
|
30 mRoot(Move(aRange.mRoot)), mStartContainer(Move(aRange.mStartContainer)), |
|
31 mEndContainer(Move(aRange.mEndContainer)), |
|
32 mStartOffset(aRange.mStartOffset), mEndOffset(aRange.mEndOffset) {} |
|
33 |
|
34 TextRange& operator= (TextRange&& aRange) |
|
35 { |
|
36 mRoot = Move(aRange.mRoot); |
|
37 mStartContainer = Move(aRange.mStartContainer); |
|
38 mEndContainer = Move(aRange.mEndContainer); |
|
39 mStartOffset = aRange.mStartOffset; |
|
40 mEndOffset = aRange.mEndOffset; |
|
41 return *this; |
|
42 } |
|
43 |
|
44 Accessible* StartContainer() const { return mStartContainer; } |
|
45 int32_t StartOffset() const { return mStartOffset; } |
|
46 Accessible* EndContainer() const { return mEndContainer; } |
|
47 int32_t EndOffset() const { return mEndOffset; } |
|
48 |
|
49 /** |
|
50 * Return text enclosed by the range. |
|
51 */ |
|
52 void Text(nsAString& aText) const; |
|
53 |
|
54 /** |
|
55 * Return true if this TextRange object represents an actual range of text. |
|
56 */ |
|
57 bool IsValid() const { return mRoot; } |
|
58 |
|
59 private: |
|
60 TextRange(const TextRange& aRange) MOZ_DELETE; |
|
61 TextRange& operator=(const TextRange& aRange) MOZ_DELETE; |
|
62 |
|
63 friend class HyperTextAccessible; |
|
64 friend class xpcAccessibleTextRange; |
|
65 |
|
66 void Set(HyperTextAccessible* aRoot, |
|
67 Accessible* aStartContainer, int32_t aStartOffset, |
|
68 Accessible* aEndContainer, int32_t aEndOffset); |
|
69 |
|
70 nsRefPtr<HyperTextAccessible> mRoot; |
|
71 nsRefPtr<Accessible> mStartContainer; |
|
72 nsRefPtr<Accessible> mEndContainer; |
|
73 int32_t mStartOffset; |
|
74 int32_t mEndOffset; |
|
75 }; |
|
76 |
|
77 |
|
78 } // namespace a11y |
|
79 } // namespace mozilla |
|
80 |
|
81 #endif |