bug 828141 - windows shouldn't hold onto events r=surkov

This commit is contained in:
Trevor Saunders 2013-01-08 19:41:58 -05:00
parent 30ded1b75a
commit 15c408b167
5 changed files with 39 additions and 35 deletions

View File

@ -9,9 +9,17 @@
#include "nsEventShell.h"
#include "mozilla/StaticPtr.h"
using namespace mozilla;
using namespace mozilla::a11y;
StaticRefPtr<Accessible> HyperTextAccessibleWrap::sLastTextChangeAcc;
StaticAutoPtr<nsString> HyperTextAccessibleWrap::sLastTextChangeString;
uint32_t HyperTextAccessibleWrap::sLastTextChangeStart = 0;
uint32_t HyperTextAccessibleWrap::sLastTextChangeEnd = 0;
bool HyperTextAccessibleWrap::sLastTextChangeWasInsert = false;
NS_IMPL_ISUPPORTS_INHERITED0(HyperTextAccessibleWrap,
HyperTextAccessible)
@ -49,19 +57,16 @@ HyperTextAccessibleWrap::HandleAccEvent(AccEvent* aEvent)
if (eventType == nsIAccessibleEvent::EVENT_TEXT_REMOVED ||
eventType == nsIAccessibleEvent::EVENT_TEXT_INSERTED) {
Accessible* accessible = aEvent->GetAccessible();
if (accessible) {
nsCOMPtr<nsIWinAccessNode> winAccessNode(do_QueryObject(accessible));
if (winAccessNode) {
void *instancePtr = NULL;
nsresult rv = winAccessNode->QueryNativeInterface(IID_IAccessibleText,
&instancePtr);
if (NS_SUCCEEDED(rv)) {
NS_IF_RELEASE(gTextEvent);
NS_IF_ADDREF(gTextEvent = downcast_accEvent(aEvent));
if (accessible && accessible->IsHyperText()) {
sLastTextChangeAcc = accessible;
if (!sLastTextChangeString)
sLastTextChangeString = new nsString();
(static_cast<IUnknown*>(instancePtr))->Release();
}
}
AccTextChangeEvent* event = downcast_accEvent(aEvent);
event->GetModifiedText(*sLastTextChangeString);
sLastTextChangeStart = event->GetStartOffset();
sLastTextChangeEnd = sLastTextChangeStart + event->GetLength();
sLastTextChangeWasInsert = event->IsTextInserted();
}
}
@ -78,20 +83,18 @@ HyperTextAccessibleWrap::GetModifiedText(bool aGetInsertedText,
*aStartOffset = 0;
*aEndOffset = 0;
if (!gTextEvent)
if (!sLastTextChangeAcc)
return NS_OK;
bool isInserted = gTextEvent->IsTextInserted();
if (aGetInsertedText != isInserted)
if (aGetInsertedText != sLastTextChangeWasInsert)
return NS_OK;
Accessible* targetAcc = gTextEvent->GetAccessible();
if (targetAcc != this)
if (sLastTextChangeAcc != this)
return NS_OK;
*aStartOffset = gTextEvent->GetStartOffset();
*aEndOffset = *aStartOffset + gTextEvent->GetLength();
gTextEvent->GetModifiedText(aText);
*aStartOffset = sLastTextChangeStart;
*aEndOffset = sLastTextChangeEnd;
aText.Append(*sLastTextChangeString);
return NS_OK;
}

View File

@ -13,6 +13,9 @@
#include "ia2AccessibleHypertext.h"
namespace mozilla {
template<class T> class StaticAutoPtr;
template<class T> class StaticRefPtr;
namespace a11y {
class HyperTextAccessibleWrap : public HyperTextAccessible,
@ -36,6 +39,14 @@ protected:
virtual nsresult GetModifiedText(bool aGetInsertedText, nsAString& aText,
uint32_t *aStartOffset,
uint32_t *aEndOffset);
static StaticRefPtr<Accessible> sLastTextChangeAcc;
static StaticAutoPtr<nsString> sLastTextChangeString;
static bool sLastTextChangeWasInsert;
static uint32_t sLastTextChangeStart;
static uint32_t sLastTextChangeEnd;
friend void PlatformInit();
};
} // namespace a11y

View File

@ -8,9 +8,11 @@
#include "AccEvent.h"
#include "Compatibility.h"
#include "nsAccessNodeWrap.h"
#include "HyperTextAccessibleWrap.h"
#include "nsWinUtils.h"
#include "mozilla/ClearOnShutdown.h"
using namespace mozilla;
using namespace mozilla::a11y;
@ -20,12 +22,13 @@ a11y::PlatformInit()
Compatibility::Init();
nsWinUtils::MaybeStartWindowEmulation();
ClearOnShutdown(&HyperTextAccessibleWrap::sLastTextChangeAcc);
ClearOnShutdown(&HyperTextAccessibleWrap::sLastTextChangeString);
}
void
a11y::PlatformShutdown()
{
NS_IF_RELEASE(nsAccessNodeWrap::gTextEvent);
::DestroyCaret();
nsWinUtils::ShutdownWindowEmulation();

View File

@ -27,8 +27,6 @@
using namespace mozilla;
using namespace mozilla::a11y;
AccTextChangeEvent* nsAccessNodeWrap::gTextEvent = nullptr;
////////////////////////////////////////////////////////////////////////////////
// nsAccessNodeWrap
////////////////////////////////////////////////////////////////////////////////

View File

@ -47,8 +47,6 @@
namespace mozilla {
namespace a11y {
class AccTextChangeEvent;
#ifdef __GNUC__
// Inheriting from both XPCOM and MSCOM interfaces causes a lot of warnings
// about virtual functions being hidden by each other. This is done by
@ -83,15 +81,6 @@ public: // construction, destruction
WPARAM WParam, LPARAM lParam);
static nsRefPtrHashtable<nsPtrHashKey<void>, DocAccessible> sHWNDCache;
protected:
/**
* It is used in HyperTextAccessibleWrap for IA2::newText/oldText
* implementation.
*/
static AccTextChangeEvent* gTextEvent;
friend void PlatformShutdown();
};
} // namespace a11y