2003-06-16 14:35:11 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2013-01-02 04:49:19 +04:00
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04: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 14:35:11 +04:00
|
|
|
|
2010-08-25 06:08:28 +04:00
|
|
|
#include "AccEvent.h"
|
2010-03-17 10:10:52 +03:00
|
|
|
|
2010-04-27 10:52:03 +04:00
|
|
|
#include "nsAccUtils.h"
|
2012-05-27 13:01:40 +04:00
|
|
|
#include "DocAccessible.h"
|
2013-01-19 19:38:01 +04:00
|
|
|
#include "xpcAccEvents.h"
|
2012-03-22 16:28:25 +04:00
|
|
|
#include "States.h"
|
2014-10-22 04:49:28 +04:00
|
|
|
#include "xpcAccessibleDocument.h"
|
2010-03-17 10:10:52 +03:00
|
|
|
|
2014-04-01 08:09:23 +04:00
|
|
|
#include "mozilla/EventStateManager.h"
|
2014-04-10 20:09:40 +04:00
|
|
|
#include "mozilla/dom/Selection.h"
|
2003-06-16 14:35:11 +04:00
|
|
|
|
2013-01-19 19:38:01 +04:00
|
|
|
using namespace mozilla;
|
2012-03-22 16:28:25 +04:00
|
|
|
using namespace mozilla::a11y;
|
|
|
|
|
2013-10-26 18:58:53 +04:00
|
|
|
static_assert(static_cast<bool>(eNoUserInput) == false &&
|
|
|
|
static_cast<bool>(eFromUserInput) == true,
|
|
|
|
"EIsFromUserInput cannot be casted to bool");
|
|
|
|
|
2010-01-20 14:16:32 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2010-08-25 06:08:28 +04:00
|
|
|
// AccEvent
|
2010-01-20 14:16:32 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2007-08-11 05:44:44 +04:00
|
|
|
|
2008-08-06 16:19:56 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2010-08-25 06:08:28 +04:00
|
|
|
// AccEvent constructors
|
2003-06-16 14:35:11 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
AccEvent::AccEvent(uint32_t aEventType, Accessible* aAccessible,
|
2010-10-21 08:16:10 +04:00
|
|
|
EIsFromUserInput aIsFromUserInput, EEventRule aEventRule) :
|
|
|
|
mEventType(aEventType), mEventRule(aEventRule), mAccessible(aAccessible)
|
2003-06-16 14:35:11 +04:00
|
|
|
{
|
2012-11-21 09:25:20 +04:00
|
|
|
if (aIsFromUserInput == eAutoDetect)
|
2014-04-01 08:09:23 +04:00
|
|
|
mIsFromUserInput = EventStateManager::IsHandlingUserInput();
|
2012-11-21 09:25:20 +04:00
|
|
|
else
|
|
|
|
mIsFromUserInput = aIsFromUserInput == eFromUserInput ? true : false;
|
2003-06-16 14:35:11 +04:00
|
|
|
}
|
2005-06-10 17:57:27 +04:00
|
|
|
|
2010-08-25 06:08:28 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// AccEvent cycle collection
|
|
|
|
|
2016-09-03 03:50:56 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(AccEvent)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(AccEvent)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mAccessible)
|
|
|
|
if (AccTreeMutationEvent* tmEvent = downcast_accEvent(tmp)) {
|
|
|
|
tmEvent->SetNextEvent(nullptr);
|
|
|
|
tmEvent->SetPrevEvent(nullptr);
|
|
|
|
}
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(AccEvent)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mAccessible)
|
|
|
|
if (AccTreeMutationEvent* tmEvent = downcast_accEvent(tmp)) {
|
|
|
|
CycleCollectionNoteChild(cb, tmEvent->NextEvent(), "mNext");
|
|
|
|
CycleCollectionNoteChild(cb, tmEvent->PrevEvent(), "mPrevEvent");
|
|
|
|
}
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
2010-08-25 06:08:28 +04:00
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(AccEvent, AddRef)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(AccEvent, Release)
|
|
|
|
|
2009-02-05 09:23:18 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2010-01-20 14:16:32 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2010-08-25 06:08:28 +04:00
|
|
|
// AccTextChangeEvent
|
2010-01-20 14:16:32 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2010-06-02 16:30:13 +04:00
|
|
|
// Note: we pass in eAllowDupes to the base class because we don't support text
|
2012-05-27 13:01:40 +04:00
|
|
|
// events coalescence. We fire delayed text change events in DocAccessible but
|
2010-06-02 16:30:13 +04: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 06:08:28 +04:00
|
|
|
AccTextChangeEvent::
|
2012-08-22 19:56:38 +04:00
|
|
|
AccTextChangeEvent(Accessible* aAccessible, int32_t aStart,
|
2011-09-29 10:19:26 +04:00
|
|
|
const nsAString& aModifiedText, bool aIsInserted,
|
2010-10-21 08:16:10 +04:00
|
|
|
EIsFromUserInput aIsFromUserInput)
|
2010-08-25 06:08:28 +04:00
|
|
|
: AccEvent(aIsInserted ?
|
2012-08-22 19:56:38 +04:00
|
|
|
static_cast<uint32_t>(nsIAccessibleEvent::EVENT_TEXT_INSERTED) :
|
|
|
|
static_cast<uint32_t>(nsIAccessibleEvent::EVENT_TEXT_REMOVED),
|
2010-10-21 08:16:10 +04:00
|
|
|
aAccessible, aIsFromUserInput, eAllowDupes)
|
2010-08-19 06:14:50 +04:00
|
|
|
, mStart(aStart)
|
|
|
|
, mIsInserted(aIsInserted)
|
|
|
|
, mModifiedText(aModifiedText)
|
2007-04-17 10:52:52 +04:00
|
|
|
{
|
2012-03-22 16:28:25 +04: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 10:52:52 +04:00
|
|
|
}
|
|
|
|
|
2010-07-02 05:49:42 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// AccHideEvent
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
AccHideEvent::
|
2015-12-16 08:24:06 +03:00
|
|
|
AccHideEvent(Accessible* aTarget, bool aNeedsShutdown) :
|
|
|
|
AccMutationEvent(::nsIAccessibleEvent::EVENT_HIDE, aTarget),
|
2015-09-15 19:01:51 +03:00
|
|
|
mNeedsShutdown(aNeedsShutdown)
|
2010-07-02 05:49:42 +04:00
|
|
|
{
|
2011-06-07 06:23:13 +04:00
|
|
|
mNextSibling = mAccessible->NextSibling();
|
|
|
|
mPrevSibling = mAccessible->PrevSibling();
|
2010-07-02 05:49:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-21 08:16:10 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// AccShowEvent
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
AccShowEvent::
|
2015-12-16 08:24:06 +03:00
|
|
|
AccShowEvent(Accessible* aTarget) :
|
|
|
|
AccMutationEvent(::nsIAccessibleEvent::EVENT_SHOW, aTarget)
|
2010-10-21 08:16:10 +04:00
|
|
|
{
|
2016-03-23 23:44:50 +03:00
|
|
|
int32_t idx = aTarget->IndexInParent();
|
|
|
|
MOZ_ASSERT(idx >= 0);
|
|
|
|
mInsertionIndex = idx;
|
2010-10-21 08:16:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-26 18:58:53 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// AccTextSelChangeEvent
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
AccTextSelChangeEvent::AccTextSelChangeEvent(HyperTextAccessible* aTarget,
|
2014-04-10 20:09:40 +04:00
|
|
|
dom::Selection* aSelection,
|
2014-02-12 05:18:31 +04:00
|
|
|
int32_t aReason) :
|
2013-10-26 18:58:53 +04:00
|
|
|
AccEvent(nsIAccessibleEvent::EVENT_TEXT_SELECTION_CHANGED, aTarget,
|
|
|
|
eAutoDetect, eCoalesceTextSelChange),
|
2014-02-12 05:18:31 +04:00
|
|
|
mSel(aSelection), mReason(aReason) {}
|
2013-10-26 18:58:53 +04:00
|
|
|
|
|
|
|
AccTextSelChangeEvent::~AccTextSelChangeEvent() { }
|
|
|
|
|
2014-02-12 05:18:31 +04:00
|
|
|
bool
|
|
|
|
AccTextSelChangeEvent::IsCaretMoveOnly() const
|
|
|
|
{
|
2015-02-25 19:08:00 +03:00
|
|
|
return mSel->RangeCount() == 1 && mSel->IsCollapsed() &&
|
2014-02-12 05:18:31 +04:00
|
|
|
((mReason & (nsISelectionListener::COLLAPSETOSTART_REASON |
|
|
|
|
nsISelectionListener::COLLAPSETOEND_REASON)) == 0);
|
|
|
|
}
|
|
|
|
|
2011-11-01 04:52:27 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// AccSelChangeEvent
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
AccSelChangeEvent::
|
2012-05-29 05:18:45 +04:00
|
|
|
AccSelChangeEvent(Accessible* aWidget, Accessible* aItem,
|
2011-11-01 04:52:27 +04:00
|
|
|
SelChangeType aSelChangeType) :
|
|
|
|
AccEvent(0, aItem, eAutoDetect, eCoalesceSelectionChange),
|
|
|
|
mWidget(aWidget), mItem(aItem), mSelChangeType(aSelChangeType),
|
2012-07-30 18:20:58 +04:00
|
|
|
mPreceedingCount(0), mPackedEvent(nullptr)
|
2011-11-01 04:52:27 +04: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 14:16:32 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2010-08-25 06:08:28 +04:00
|
|
|
// AccTableChangeEvent
|
2010-01-20 14:16:32 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2010-08-25 06:08:28 +04:00
|
|
|
AccTableChangeEvent::
|
2012-08-22 19:56:38 +04:00
|
|
|
AccTableChangeEvent(Accessible* aAccessible, uint32_t aEventType,
|
|
|
|
int32_t aRowOrColIndex, int32_t aNumRowsOrCols) :
|
2010-10-21 08:16:10 +04:00
|
|
|
AccEvent(aEventType, aAccessible),
|
2008-01-18 05:56:38 +03:00
|
|
|
mRowOrColIndex(aRowOrColIndex), mNumRowsOrCols(aNumRowsOrCols)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-03-10 05:52:13 +04:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// AccVCChangeEvent
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
AccVCChangeEvent::
|
2012-05-29 05:18:45 +04:00
|
|
|
AccVCChangeEvent(Accessible* aAccessible,
|
2014-10-22 04:49:28 +04:00
|
|
|
Accessible* aOldAccessible,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aOldStart, int32_t aOldEnd,
|
2018-06-21 14:47:00 +03:00
|
|
|
Accessible* aNewAccessible,
|
|
|
|
int32_t aNewStart, int32_t aNewEnd,
|
2018-07-16 13:56:00 +03:00
|
|
|
int16_t aReason, int16_t aBoundaryType,
|
|
|
|
EIsFromUserInput aIsFromUserInput) :
|
2014-08-15 05:44:59 +04:00
|
|
|
AccEvent(::nsIAccessibleEvent::EVENT_VIRTUALCURSOR_CHANGED, aAccessible,
|
|
|
|
aIsFromUserInput),
|
2018-06-21 14:47:00 +03:00
|
|
|
mOldAccessible(aOldAccessible), mNewAccessible(aNewAccessible),
|
|
|
|
mOldStart(aOldStart), mNewStart(aNewStart),
|
|
|
|
mOldEnd(aOldEnd), mNewEnd(aNewEnd),
|
2018-07-16 13:56:00 +03:00
|
|
|
mReason(aReason), mBoundaryType(aBoundaryType)
|
2012-03-10 05:52:13 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-01-19 19:38:01 +04:00
|
|
|
already_AddRefed<nsIAccessibleEvent>
|
|
|
|
a11y::MakeXPCEvent(AccEvent* aEvent)
|
2012-03-10 05:52:13 +04:00
|
|
|
{
|
2016-05-19 20:56:58 +03:00
|
|
|
DocAccessible* doc = aEvent->Document();
|
2013-01-19 19:38:01 +04:00
|
|
|
Accessible* acc = aEvent->GetAccessible();
|
|
|
|
nsINode* node = acc->GetNode();
|
|
|
|
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 04:49:28 +04:00
|
|
|
xpEvent = new xpcAccStateChangeEvent(type, ToXPC(acc), ToXPCDocument(doc),
|
2018-05-30 05:58:47 +03:00
|
|
|
node, fromUser,
|
2013-01-19 19:38:01 +04: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 04:49:28 +04:00
|
|
|
xpEvent = new xpcAccTextChangeEvent(type, ToXPC(acc), ToXPCDocument(doc),
|
2018-05-30 05:58:47 +03:00
|
|
|
node, fromUser,
|
2013-01-19 19:38:01 +04:00
|
|
|
tc->GetStartOffset(), tc->GetLength(),
|
|
|
|
tc->IsTextInserted(), text);
|
|
|
|
return xpEvent.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (eventGroup & (1 << AccEvent::eHideEvent)) {
|
|
|
|
AccHideEvent* hideEvent = downcast_accEvent(aEvent);
|
2014-10-22 04:49:28 +04:00
|
|
|
xpEvent = new xpcAccHideEvent(type, ToXPC(acc), ToXPCDocument(doc),
|
2018-05-30 05:58:47 +03:00
|
|
|
node, fromUser,
|
2014-10-22 04:49:28 +04:00
|
|
|
ToXPC(hideEvent->TargetParent()),
|
|
|
|
ToXPC(hideEvent->TargetNextSibling()),
|
|
|
|
ToXPC(hideEvent->TargetPrevSibling()));
|
2013-01-19 19:38:01 +04:00
|
|
|
return xpEvent.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (eventGroup & (1 << AccEvent::eCaretMoveEvent)) {
|
|
|
|
AccCaretMoveEvent* cm = downcast_accEvent(aEvent);
|
2014-10-22 04:49:28 +04:00
|
|
|
xpEvent = new xpcAccCaretMoveEvent(type, ToXPC(acc), ToXPCDocument(doc),
|
2018-05-30 05:58:47 +03:00
|
|
|
node, fromUser,
|
2013-01-19 19:38:01 +04:00
|
|
|
cm->GetCaretOffset());
|
|
|
|
return xpEvent.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (eventGroup & (1 << AccEvent::eVirtualCursorChangeEvent)) {
|
|
|
|
AccVCChangeEvent* vcc = downcast_accEvent(aEvent);
|
2014-10-22 04:49:28 +04:00
|
|
|
xpEvent = new xpcAccVirtualCursorChangeEvent(type,
|
|
|
|
ToXPC(acc), ToXPCDocument(doc),
|
2018-05-30 05:58:47 +03:00
|
|
|
node, fromUser,
|
2014-10-22 04:49:28 +04:00
|
|
|
ToXPC(vcc->OldAccessible()),
|
2013-01-19 19:38:01 +04:00
|
|
|
vcc->OldStartOffset(),
|
|
|
|
vcc->OldEndOffset(),
|
2018-06-21 14:47:00 +03:00
|
|
|
ToXPC(vcc->NewAccessible()),
|
|
|
|
vcc->NewStartOffset(),
|
|
|
|
vcc->NewEndOffset(),
|
2018-07-16 13:56:00 +03:00
|
|
|
vcc->Reason(),
|
|
|
|
vcc->BoundaryType());
|
2013-01-19 19:38:01 +04:00
|
|
|
return xpEvent.forget();
|
|
|
|
}
|
|
|
|
|
2014-08-28 16:42:06 +04:00
|
|
|
if (eventGroup & (1 << AccEvent::eObjectAttrChangedEvent)) {
|
|
|
|
AccObjectAttrChangedEvent* oac = downcast_accEvent(aEvent);
|
2017-08-24 10:19:09 +03:00
|
|
|
nsString attribute;
|
|
|
|
oac->GetAttribute()->ToString(attribute);
|
2014-10-22 04:49:28 +04:00
|
|
|
xpEvent = new xpcAccObjectAttributeChangedEvent(type,
|
|
|
|
ToXPC(acc),
|
2018-05-30 05:58:47 +03:00
|
|
|
ToXPCDocument(doc), node,
|
2014-08-28 16:42:06 +04:00
|
|
|
fromUser,
|
2017-08-24 10:19:09 +03:00
|
|
|
attribute);
|
2014-08-28 16:42:06 +04:00
|
|
|
return xpEvent.forget();
|
|
|
|
}
|
|
|
|
|
2018-05-30 05:58:47 +03:00
|
|
|
xpEvent = new xpcAccEvent(type, ToXPC(acc), ToXPCDocument(doc), node, fromUser);
|
2013-01-19 19:38:01 +04:00
|
|
|
return xpEvent.forget();
|
|
|
|
}
|