2003-06-16 10:35:11 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2013-01-02 00:49:19 +00:00
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2003-06-16 10:35:11 +00:00
|
|
|
|
2010-08-25 02:08:28 +00:00
|
|
|
#include "AccEvent.h"
|
2010-03-17 07:10:52 +00:00
|
|
|
|
2010-04-27 06:52:03 +00:00
|
|
|
#include "nsAccUtils.h"
|
2012-05-27 09:01:40 +00:00
|
|
|
#include "DocAccessible.h"
|
2013-01-19 15:38:01 +00:00
|
|
|
#include "xpcAccEvents.h"
|
2012-03-22 12:28:25 +00:00
|
|
|
#include "States.h"
|
2014-10-22 00:49:28 +00:00
|
|
|
#include "xpcAccessibleDocument.h"
|
2010-03-17 07:10:52 +00:00
|
|
|
|
2014-04-01 04:09:23 +00:00
|
|
|
#include "mozilla/EventStateManager.h"
|
2014-04-10 16:09:40 +00:00
|
|
|
#include "mozilla/dom/Selection.h"
|
2003-06-16 10:35:11 +00:00
|
|
|
|
2013-01-19 15:38:01 +00:00
|
|
|
using namespace mozilla;
|
2012-03-22 12:28:25 +00:00
|
|
|
using namespace mozilla::a11y;
|
|
|
|
|
2013-10-26 14:58:53 +00:00
|
|
|
static_assert(static_cast<bool>(eNoUserInput) == false &&
|
|
|
|
static_cast<bool>(eFromUserInput) == true,
|
|
|
|
"EIsFromUserInput cannot be casted to bool");
|
|
|
|
|
2010-01-20 11:16:32 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2010-08-25 02:08:28 +00:00
|
|
|
// AccEvent
|
2010-01-20 11:16:32 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2007-08-11 01:44:44 +00:00
|
|
|
|
2008-08-06 12:19:56 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2010-08-25 02:08:28 +00:00
|
|
|
// AccEvent constructors
|
2003-06-16 10:35:11 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
AccEvent::AccEvent(uint32_t aEventType, Accessible* aAccessible,
|
2010-10-21 04:16:10 +00:00
|
|
|
EIsFromUserInput aIsFromUserInput, EEventRule aEventRule) :
|
|
|
|
mEventType(aEventType), mEventRule(aEventRule), mAccessible(aAccessible)
|
2003-06-16 10:35:11 +00:00
|
|
|
{
|
2012-11-21 05:25:20 +00:00
|
|
|
if (aIsFromUserInput == eAutoDetect)
|
2014-04-01 04:09:23 +00:00
|
|
|
mIsFromUserInput = EventStateManager::IsHandlingUserInput();
|
2012-11-21 05:25:20 +00:00
|
|
|
else
|
|
|
|
mIsFromUserInput = aIsFromUserInput == eFromUserInput ? true : false;
|
2003-06-16 10:35:11 +00:00
|
|
|
}
|
2005-06-10 13:57:27 +00:00
|
|
|
|
2010-08-25 02:08:28 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// AccEvent cycle collection
|
|
|
|
|
2014-04-25 16:49:00 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION(AccEvent, mAccessible)
|
2010-08-25 02:08:28 +00:00
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(AccEvent, AddRef)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(AccEvent, Release)
|
|
|
|
|
2009-02-05 06:23:18 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2010-01-20 11:16:32 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2010-08-25 02:08:28 +00:00
|
|
|
// AccTextChangeEvent
|
2010-01-20 11:16:32 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2010-06-02 12:30:13 +00:00
|
|
|
// Note: we pass in eAllowDupes to the base class because we don't support text
|
2012-05-27 09:01:40 +00:00
|
|
|
// events coalescence. We fire delayed text change events in DocAccessible but
|
2010-06-02 12:30:13 +00:00
|
|
|
// we continue to base the event off the accessible object rather than just the
|
|
|
|
// node. This means we won't try to create an accessible based on the node when
|
|
|
|
// we are ready to fire the event and so we will no longer assert at that point
|
|
|
|
// if the node was removed from the document. Either way, the AT won't work with
|
|
|
|
// a defunct accessible so the behaviour should be equivalent.
|
2010-08-25 02:08:28 +00:00
|
|
|
AccTextChangeEvent::
|
2012-08-22 15:56:38 +00:00
|
|
|
AccTextChangeEvent(Accessible* aAccessible, int32_t aStart,
|
2011-09-29 06:19:26 +00:00
|
|
|
const nsAString& aModifiedText, bool aIsInserted,
|
2010-10-21 04:16:10 +00:00
|
|
|
EIsFromUserInput aIsFromUserInput)
|
2010-08-25 02:08:28 +00:00
|
|
|
: AccEvent(aIsInserted ?
|
2012-08-22 15:56:38 +00:00
|
|
|
static_cast<uint32_t>(nsIAccessibleEvent::EVENT_TEXT_INSERTED) :
|
|
|
|
static_cast<uint32_t>(nsIAccessibleEvent::EVENT_TEXT_REMOVED),
|
2010-10-21 04:16:10 +00:00
|
|
|
aAccessible, aIsFromUserInput, eAllowDupes)
|
2010-08-19 02:14:50 +00:00
|
|
|
, mStart(aStart)
|
|
|
|
, mIsInserted(aIsInserted)
|
|
|
|
, mModifiedText(aModifiedText)
|
2007-04-17 06:52:52 +00:00
|
|
|
{
|
2012-03-22 12:28:25 +00:00
|
|
|
// XXX We should use IsFromUserInput here, but that isn't always correct
|
|
|
|
// when the text change isn't related to content insertion or removal.
|
|
|
|
mIsFromUserInput = mAccessible->State() &
|
|
|
|
(states::FOCUSED | states::EDITABLE);
|
2007-04-17 06:52:52 +00:00
|
|
|
}
|
|
|
|
|
2010-07-02 01:49:42 +00:00
|
|
|
|
2010-10-21 04:16:10 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-11-13 06:29:22 +00:00
|
|
|
// AccReorderEvent
|
2010-10-21 04:16:10 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-11-13 06:29:22 +00:00
|
|
|
uint32_t
|
|
|
|
AccReorderEvent::IsShowHideEventTarget(const Accessible* aTarget) const
|
2010-10-21 04:16:10 +00:00
|
|
|
{
|
2012-11-13 06:29:22 +00:00
|
|
|
uint32_t count = mDependentEvents.Length();
|
|
|
|
for (uint32_t index = count - 1; index < count; index--) {
|
2013-01-02 00:49:19 +00:00
|
|
|
if (mDependentEvents[index]->mAccessible == aTarget) {
|
|
|
|
uint32_t eventType = mDependentEvents[index]->mEventType;
|
|
|
|
if (eventType == nsIAccessibleEvent::EVENT_SHOW ||
|
|
|
|
eventType == nsIAccessibleEvent::EVENT_HIDE) {
|
|
|
|
return mDependentEvents[index]->mEventType;
|
|
|
|
}
|
2012-11-13 06:29:22 +00:00
|
|
|
}
|
|
|
|
}
|
2010-10-21 04:16:10 +00:00
|
|
|
|
2012-11-13 06:29:22 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2010-10-21 04:16:10 +00:00
|
|
|
|
2010-07-02 01:49:42 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// AccHideEvent
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
AccHideEvent::
|
2012-05-29 01:18:45 +00:00
|
|
|
AccHideEvent(Accessible* aTarget, nsINode* aTargetNode) :
|
2011-01-18 08:03:38 +00:00
|
|
|
AccMutationEvent(::nsIAccessibleEvent::EVENT_HIDE, aTarget, aTargetNode)
|
2010-07-02 01:49:42 +00:00
|
|
|
{
|
2011-06-07 02:23:13 +00:00
|
|
|
mNextSibling = mAccessible->NextSibling();
|
|
|
|
mPrevSibling = mAccessible->PrevSibling();
|
2010-07-02 01:49:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-21 04:16:10 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// AccShowEvent
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
AccShowEvent::
|
2012-05-29 01:18:45 +00:00
|
|
|
AccShowEvent(Accessible* aTarget, nsINode* aTargetNode) :
|
2011-01-18 08:03:38 +00:00
|
|
|
AccMutationEvent(::nsIAccessibleEvent::EVENT_SHOW, aTarget, aTargetNode)
|
2010-10-21 04:16:10 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-26 14:58:53 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// AccTextSelChangeEvent
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
AccTextSelChangeEvent::AccTextSelChangeEvent(HyperTextAccessible* aTarget,
|
2014-04-10 16:09:40 +00:00
|
|
|
dom::Selection* aSelection,
|
2014-02-12 01:18:31 +00:00
|
|
|
int32_t aReason) :
|
2013-10-26 14:58:53 +00:00
|
|
|
AccEvent(nsIAccessibleEvent::EVENT_TEXT_SELECTION_CHANGED, aTarget,
|
|
|
|
eAutoDetect, eCoalesceTextSelChange),
|
2014-02-12 01:18:31 +00:00
|
|
|
mSel(aSelection), mReason(aReason) {}
|
2013-10-26 14:58:53 +00:00
|
|
|
|
|
|
|
AccTextSelChangeEvent::~AccTextSelChangeEvent() { }
|
|
|
|
|
2014-02-12 01:18:31 +00:00
|
|
|
bool
|
|
|
|
AccTextSelChangeEvent::IsCaretMoveOnly() const
|
|
|
|
{
|
|
|
|
return mSel->GetRangeCount() == 1 && mSel->IsCollapsed() &&
|
|
|
|
((mReason & (nsISelectionListener::COLLAPSETOSTART_REASON |
|
|
|
|
nsISelectionListener::COLLAPSETOEND_REASON)) == 0);
|
|
|
|
}
|
|
|
|
|
2011-11-01 00:52:27 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// AccSelChangeEvent
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
AccSelChangeEvent::
|
2012-05-29 01:18:45 +00:00
|
|
|
AccSelChangeEvent(Accessible* aWidget, Accessible* aItem,
|
2011-11-01 00:52:27 +00:00
|
|
|
SelChangeType aSelChangeType) :
|
|
|
|
AccEvent(0, aItem, eAutoDetect, eCoalesceSelectionChange),
|
|
|
|
mWidget(aWidget), mItem(aItem), mSelChangeType(aSelChangeType),
|
2012-07-30 14:20:58 +00:00
|
|
|
mPreceedingCount(0), mPackedEvent(nullptr)
|
2011-11-01 00:52:27 +00:00
|
|
|
{
|
|
|
|
if (aSelChangeType == eSelectionAdd) {
|
|
|
|
if (mWidget->GetSelectedItem(1))
|
|
|
|
mEventType = nsIAccessibleEvent::EVENT_SELECTION_ADD;
|
|
|
|
else
|
|
|
|
mEventType = nsIAccessibleEvent::EVENT_SELECTION;
|
|
|
|
} else {
|
|
|
|
mEventType = nsIAccessibleEvent::EVENT_SELECTION_REMOVE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-20 11:16:32 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2010-08-25 02:08:28 +00:00
|
|
|
// AccTableChangeEvent
|
2010-01-20 11:16:32 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2010-08-25 02:08:28 +00:00
|
|
|
AccTableChangeEvent::
|
2012-08-22 15:56:38 +00:00
|
|
|
AccTableChangeEvent(Accessible* aAccessible, uint32_t aEventType,
|
|
|
|
int32_t aRowOrColIndex, int32_t aNumRowsOrCols) :
|
2010-10-21 04:16:10 +00:00
|
|
|
AccEvent(aEventType, aAccessible),
|
2008-01-18 02:56:38 +00:00
|
|
|
mRowOrColIndex(aRowOrColIndex), mNumRowsOrCols(aNumRowsOrCols)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-03-10 01:52:13 +00:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// AccVCChangeEvent
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
AccVCChangeEvent::
|
2012-05-29 01:18:45 +00:00
|
|
|
AccVCChangeEvent(Accessible* aAccessible,
|
2014-10-22 00:49:28 +00:00
|
|
|
Accessible* aOldAccessible,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t aOldStart, int32_t aOldEnd,
|
2014-08-15 01:44:59 +00:00
|
|
|
int16_t aReason, EIsFromUserInput aIsFromUserInput) :
|
|
|
|
AccEvent(::nsIAccessibleEvent::EVENT_VIRTUALCURSOR_CHANGED, aAccessible,
|
|
|
|
aIsFromUserInput),
|
2012-06-20 21:07:51 +00:00
|
|
|
mOldAccessible(aOldAccessible), mOldStart(aOldStart), mOldEnd(aOldEnd),
|
|
|
|
mReason(aReason)
|
2012-03-10 01:52:13 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-01-19 15:38:01 +00:00
|
|
|
already_AddRefed<nsIAccessibleEvent>
|
|
|
|
a11y::MakeXPCEvent(AccEvent* aEvent)
|
2012-03-10 01:52:13 +00:00
|
|
|
{
|
2013-01-19 15:38:01 +00:00
|
|
|
DocAccessible* doc = aEvent->GetDocAccessible();
|
|
|
|
Accessible* acc = aEvent->GetAccessible();
|
|
|
|
nsINode* node = acc->GetNode();
|
|
|
|
nsIDOMNode* domNode = node ? node->AsDOMNode() : nullptr;
|
|
|
|
bool fromUser = aEvent->IsFromUserInput();
|
|
|
|
uint32_t type = aEvent->GetEventType();
|
|
|
|
uint32_t eventGroup = aEvent->GetEventGroups();
|
|
|
|
nsCOMPtr<nsIAccessibleEvent> xpEvent;
|
|
|
|
|
|
|
|
if (eventGroup & (1 << AccEvent::eStateChangeEvent)) {
|
|
|
|
AccStateChangeEvent* sc = downcast_accEvent(aEvent);
|
|
|
|
bool extra = false;
|
|
|
|
uint32_t state = nsAccUtils::To32States(sc->GetState(), &extra);
|
2014-10-22 00:49:28 +00:00
|
|
|
xpEvent = new xpcAccStateChangeEvent(type, ToXPC(acc), ToXPCDocument(doc),
|
|
|
|
domNode, fromUser,
|
2013-01-19 15:38:01 +00:00
|
|
|
state, extra, sc->IsStateEnabled());
|
|
|
|
return xpEvent.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (eventGroup & (1 << AccEvent::eTextChangeEvent)) {
|
|
|
|
AccTextChangeEvent* tc = downcast_accEvent(aEvent);
|
|
|
|
nsString text;
|
|
|
|
tc->GetModifiedText(text);
|
2014-10-22 00:49:28 +00:00
|
|
|
xpEvent = new xpcAccTextChangeEvent(type, ToXPC(acc), ToXPCDocument(doc),
|
|
|
|
domNode, fromUser,
|
2013-01-19 15:38:01 +00:00
|
|
|
tc->GetStartOffset(), tc->GetLength(),
|
|
|
|
tc->IsTextInserted(), text);
|
|
|
|
return xpEvent.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (eventGroup & (1 << AccEvent::eHideEvent)) {
|
|
|
|
AccHideEvent* hideEvent = downcast_accEvent(aEvent);
|
2014-10-22 00:49:28 +00:00
|
|
|
xpEvent = new xpcAccHideEvent(type, ToXPC(acc), ToXPCDocument(doc),
|
|
|
|
domNode, fromUser,
|
|
|
|
ToXPC(hideEvent->TargetParent()),
|
|
|
|
ToXPC(hideEvent->TargetNextSibling()),
|
|
|
|
ToXPC(hideEvent->TargetPrevSibling()));
|
2013-01-19 15:38:01 +00:00
|
|
|
return xpEvent.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (eventGroup & (1 << AccEvent::eCaretMoveEvent)) {
|
|
|
|
AccCaretMoveEvent* cm = downcast_accEvent(aEvent);
|
2014-10-22 00:49:28 +00:00
|
|
|
xpEvent = new xpcAccCaretMoveEvent(type, ToXPC(acc), ToXPCDocument(doc),
|
|
|
|
domNode, fromUser,
|
2013-01-19 15:38:01 +00:00
|
|
|
cm->GetCaretOffset());
|
|
|
|
return xpEvent.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (eventGroup & (1 << AccEvent::eVirtualCursorChangeEvent)) {
|
|
|
|
AccVCChangeEvent* vcc = downcast_accEvent(aEvent);
|
2014-10-22 00:49:28 +00:00
|
|
|
xpEvent = new xpcAccVirtualCursorChangeEvent(type,
|
|
|
|
ToXPC(acc), ToXPCDocument(doc),
|
|
|
|
domNode, fromUser,
|
|
|
|
ToXPC(vcc->OldAccessible()),
|
2013-01-19 15:38:01 +00:00
|
|
|
vcc->OldStartOffset(),
|
|
|
|
vcc->OldEndOffset(),
|
|
|
|
vcc->Reason());
|
|
|
|
return xpEvent.forget();
|
|
|
|
}
|
|
|
|
|
2014-08-28 12:42:06 +00:00
|
|
|
if (eventGroup & (1 << AccEvent::eObjectAttrChangedEvent)) {
|
|
|
|
AccObjectAttrChangedEvent* oac = downcast_accEvent(aEvent);
|
2014-10-22 00:49:28 +00:00
|
|
|
xpEvent = new xpcAccObjectAttributeChangedEvent(type,
|
|
|
|
ToXPC(acc),
|
|
|
|
ToXPCDocument(doc), domNode,
|
2014-08-28 12:42:06 +00:00
|
|
|
fromUser,
|
|
|
|
oac->GetAttribute());
|
|
|
|
return xpEvent.forget();
|
|
|
|
}
|
|
|
|
|
2014-10-22 00:49:28 +00:00
|
|
|
xpEvent = new xpcAccEvent(type, ToXPC(acc), ToXPCDocument(doc), domNode, fromUser);
|
2013-01-19 15:38:01 +00:00
|
|
|
return xpEvent.forget();
|
|
|
|
}
|