1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/accessible/src/windows/msaa/HyperTextAccessibleWrap.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,102 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim:expandtab:shiftwidth=2:tabstop=2: 1.6 + */ 1.7 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.8 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.9 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.10 + 1.11 +#include "HyperTextAccessibleWrap.h" 1.12 +#include "Accessible-inl.h" 1.13 + 1.14 +#include "nsEventShell.h" 1.15 + 1.16 +#include "mozilla/StaticPtr.h" 1.17 + 1.18 +using namespace mozilla; 1.19 +using namespace mozilla::a11y; 1.20 + 1.21 +StaticRefPtr<Accessible> HyperTextAccessibleWrap::sLastTextChangeAcc; 1.22 +StaticAutoPtr<nsString> HyperTextAccessibleWrap::sLastTextChangeString; 1.23 +uint32_t HyperTextAccessibleWrap::sLastTextChangeStart = 0; 1.24 +uint32_t HyperTextAccessibleWrap::sLastTextChangeEnd = 0; 1.25 +bool HyperTextAccessibleWrap::sLastTextChangeWasInsert = false; 1.26 + 1.27 +NS_IMPL_ISUPPORTS_INHERITED0(HyperTextAccessibleWrap, 1.28 + HyperTextAccessible) 1.29 + 1.30 +STDMETHODIMP 1.31 +HyperTextAccessibleWrap::QueryInterface(REFIID aIID, void** aInstancePtr) 1.32 +{ 1.33 + if (!aInstancePtr) 1.34 + return E_FAIL; 1.35 + 1.36 + *aInstancePtr = nullptr; 1.37 + 1.38 + if (IsTextRole()) { 1.39 + if (aIID == IID_IAccessibleText) 1.40 + *aInstancePtr = 1.41 + static_cast<IAccessibleText*>(static_cast<ia2AccessibleText*>(this)); 1.42 + else if (aIID == IID_IAccessibleHypertext) 1.43 + *aInstancePtr = static_cast<IAccessibleHypertext*>(this); 1.44 + else if (aIID == IID_IAccessibleEditableText) 1.45 + *aInstancePtr = static_cast<IAccessibleEditableText*>(this); 1.46 + 1.47 + if (*aInstancePtr) { 1.48 + AddRef(); 1.49 + return S_OK; 1.50 + } 1.51 + } 1.52 + 1.53 + return AccessibleWrap::QueryInterface(aIID, aInstancePtr); 1.54 +} 1.55 + 1.56 +nsresult 1.57 +HyperTextAccessibleWrap::HandleAccEvent(AccEvent* aEvent) 1.58 +{ 1.59 + uint32_t eventType = aEvent->GetEventType(); 1.60 + 1.61 + if (eventType == nsIAccessibleEvent::EVENT_TEXT_REMOVED || 1.62 + eventType == nsIAccessibleEvent::EVENT_TEXT_INSERTED) { 1.63 + Accessible* accessible = aEvent->GetAccessible(); 1.64 + if (accessible && accessible->IsHyperText()) { 1.65 + sLastTextChangeAcc = accessible; 1.66 + if (!sLastTextChangeString) 1.67 + sLastTextChangeString = new nsString(); 1.68 + 1.69 + AccTextChangeEvent* event = downcast_accEvent(aEvent); 1.70 + event->GetModifiedText(*sLastTextChangeString); 1.71 + sLastTextChangeStart = event->GetStartOffset(); 1.72 + sLastTextChangeEnd = sLastTextChangeStart + event->GetLength(); 1.73 + sLastTextChangeWasInsert = event->IsTextInserted(); 1.74 + } 1.75 + } 1.76 + 1.77 + return HyperTextAccessible::HandleAccEvent(aEvent); 1.78 +} 1.79 + 1.80 +nsresult 1.81 +HyperTextAccessibleWrap::GetModifiedText(bool aGetInsertedText, 1.82 + nsAString& aText, 1.83 + uint32_t* aStartOffset, 1.84 + uint32_t* aEndOffset) 1.85 +{ 1.86 + aText.Truncate(); 1.87 + *aStartOffset = 0; 1.88 + *aEndOffset = 0; 1.89 + 1.90 + if (!sLastTextChangeAcc) 1.91 + return NS_OK; 1.92 + 1.93 + if (aGetInsertedText != sLastTextChangeWasInsert) 1.94 + return NS_OK; 1.95 + 1.96 + if (sLastTextChangeAcc != this) 1.97 + return NS_OK; 1.98 + 1.99 + *aStartOffset = sLastTextChangeStart; 1.100 + *aEndOffset = sLastTextChangeEnd; 1.101 + aText.Append(*sLastTextChangeString); 1.102 + 1.103 + return NS_OK; 1.104 +} 1.105 +