|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* vim:expandtab:shiftwidth=2:tabstop=2: |
|
3 */ |
|
4 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
5 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
7 |
|
8 #include "HyperTextAccessibleWrap.h" |
|
9 #include "Accessible-inl.h" |
|
10 |
|
11 #include "nsEventShell.h" |
|
12 |
|
13 #include "mozilla/StaticPtr.h" |
|
14 |
|
15 using namespace mozilla; |
|
16 using namespace mozilla::a11y; |
|
17 |
|
18 StaticRefPtr<Accessible> HyperTextAccessibleWrap::sLastTextChangeAcc; |
|
19 StaticAutoPtr<nsString> HyperTextAccessibleWrap::sLastTextChangeString; |
|
20 uint32_t HyperTextAccessibleWrap::sLastTextChangeStart = 0; |
|
21 uint32_t HyperTextAccessibleWrap::sLastTextChangeEnd = 0; |
|
22 bool HyperTextAccessibleWrap::sLastTextChangeWasInsert = false; |
|
23 |
|
24 NS_IMPL_ISUPPORTS_INHERITED0(HyperTextAccessibleWrap, |
|
25 HyperTextAccessible) |
|
26 |
|
27 STDMETHODIMP |
|
28 HyperTextAccessibleWrap::QueryInterface(REFIID aIID, void** aInstancePtr) |
|
29 { |
|
30 if (!aInstancePtr) |
|
31 return E_FAIL; |
|
32 |
|
33 *aInstancePtr = nullptr; |
|
34 |
|
35 if (IsTextRole()) { |
|
36 if (aIID == IID_IAccessibleText) |
|
37 *aInstancePtr = |
|
38 static_cast<IAccessibleText*>(static_cast<ia2AccessibleText*>(this)); |
|
39 else if (aIID == IID_IAccessibleHypertext) |
|
40 *aInstancePtr = static_cast<IAccessibleHypertext*>(this); |
|
41 else if (aIID == IID_IAccessibleEditableText) |
|
42 *aInstancePtr = static_cast<IAccessibleEditableText*>(this); |
|
43 |
|
44 if (*aInstancePtr) { |
|
45 AddRef(); |
|
46 return S_OK; |
|
47 } |
|
48 } |
|
49 |
|
50 return AccessibleWrap::QueryInterface(aIID, aInstancePtr); |
|
51 } |
|
52 |
|
53 nsresult |
|
54 HyperTextAccessibleWrap::HandleAccEvent(AccEvent* aEvent) |
|
55 { |
|
56 uint32_t eventType = aEvent->GetEventType(); |
|
57 |
|
58 if (eventType == nsIAccessibleEvent::EVENT_TEXT_REMOVED || |
|
59 eventType == nsIAccessibleEvent::EVENT_TEXT_INSERTED) { |
|
60 Accessible* accessible = aEvent->GetAccessible(); |
|
61 if (accessible && accessible->IsHyperText()) { |
|
62 sLastTextChangeAcc = accessible; |
|
63 if (!sLastTextChangeString) |
|
64 sLastTextChangeString = new nsString(); |
|
65 |
|
66 AccTextChangeEvent* event = downcast_accEvent(aEvent); |
|
67 event->GetModifiedText(*sLastTextChangeString); |
|
68 sLastTextChangeStart = event->GetStartOffset(); |
|
69 sLastTextChangeEnd = sLastTextChangeStart + event->GetLength(); |
|
70 sLastTextChangeWasInsert = event->IsTextInserted(); |
|
71 } |
|
72 } |
|
73 |
|
74 return HyperTextAccessible::HandleAccEvent(aEvent); |
|
75 } |
|
76 |
|
77 nsresult |
|
78 HyperTextAccessibleWrap::GetModifiedText(bool aGetInsertedText, |
|
79 nsAString& aText, |
|
80 uint32_t* aStartOffset, |
|
81 uint32_t* aEndOffset) |
|
82 { |
|
83 aText.Truncate(); |
|
84 *aStartOffset = 0; |
|
85 *aEndOffset = 0; |
|
86 |
|
87 if (!sLastTextChangeAcc) |
|
88 return NS_OK; |
|
89 |
|
90 if (aGetInsertedText != sLastTextChangeWasInsert) |
|
91 return NS_OK; |
|
92 |
|
93 if (sLastTextChangeAcc != this) |
|
94 return NS_OK; |
|
95 |
|
96 *aStartOffset = sLastTextChangeStart; |
|
97 *aEndOffset = sLastTextChangeEnd; |
|
98 aText.Append(*sLastTextChangeString); |
|
99 |
|
100 return NS_OK; |
|
101 } |
|
102 |