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