2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2013-01-01 16:49:19 -08:00
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
2012-05-21 04:12:37 -07: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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-08-24 19:08:28 -07:00
|
|
|
#include "AccEvent.h"
|
2010-03-17 00:10:52 -07:00
|
|
|
|
2010-04-26 23:52:03 -07:00
|
|
|
#include "nsAccUtils.h"
|
2012-05-27 02:01:40 -07:00
|
|
|
#include "DocAccessible.h"
|
2013-01-19 07:38:01 -08:00
|
|
|
#include "xpcAccEvents.h"
|
2012-03-22 05:28:25 -07:00
|
|
|
#include "States.h"
|
2010-03-17 00:10:52 -07:00
|
|
|
|
2014-03-31 21:09:23 -07:00
|
|
|
#include "mozilla/EventStateManager.h"
|
2014-04-10 09:09:40 -07:00
|
|
|
#include "mozilla/dom/Selection.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-01-19 07:38:01 -08:00
|
|
|
using namespace mozilla;
|
2012-03-22 05:28:25 -07:00
|
|
|
using namespace mozilla::a11y;
|
|
|
|
|
2013-10-26 07:58:53 -07:00
|
|
|
static_assert(static_cast<bool>(eNoUserInput) == false &&
|
|
|
|
static_cast<bool>(eFromUserInput) == true,
|
|
|
|
"EIsFromUserInput cannot be casted to bool");
|
|
|
|
|
2010-01-20 03:16:32 -08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2010-08-24 19:08:28 -07:00
|
|
|
// AccEvent
|
2010-01-20 03:16:32 -08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2007-08-10 18:44:44 -07:00
|
|
|
|
2008-08-06 05:19:56 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2010-08-24 19:08:28 -07:00
|
|
|
// AccEvent constructors
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
AccEvent::AccEvent(uint32_t aEventType, Accessible* aAccessible,
|
2010-10-20 21:16:10 -07:00
|
|
|
EIsFromUserInput aIsFromUserInput, EEventRule aEventRule) :
|
|
|
|
mEventType(aEventType), mEventRule(aEventRule), mAccessible(aAccessible)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-11-20 21:25:20 -08:00
|
|
|
if (aIsFromUserInput == eAutoDetect)
|
2014-03-31 21:09:23 -07:00
|
|
|
mIsFromUserInput = EventStateManager::IsHandlingUserInput();
|
2012-11-20 21:25:20 -08:00
|
|
|
else
|
|
|
|
mIsFromUserInput = aIsFromUserInput == eFromUserInput ? true : false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-08-24 19:08:28 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// AccEvent cycle collection
|
|
|
|
|
2014-04-25 09:49:00 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION(AccEvent, mAccessible)
|
2010-08-24 19:08:28 -07:00
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(AccEvent, AddRef)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(AccEvent, Release)
|
|
|
|
|
2009-02-04 22:23:18 -08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2010-01-20 03:16:32 -08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2010-08-24 19:08:28 -07:00
|
|
|
// AccTextChangeEvent
|
2010-01-20 03:16:32 -08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2010-06-02 05:30:13 -07:00
|
|
|
// Note: we pass in eAllowDupes to the base class because we don't support text
|
2012-05-27 02:01:40 -07:00
|
|
|
// events coalescence. We fire delayed text change events in DocAccessible but
|
2010-06-02 05:30:13 -07: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-24 19:08:28 -07:00
|
|
|
AccTextChangeEvent::
|
2012-08-22 08:56:38 -07:00
|
|
|
AccTextChangeEvent(Accessible* aAccessible, int32_t aStart,
|
2011-09-28 23:19:26 -07:00
|
|
|
const nsAString& aModifiedText, bool aIsInserted,
|
2010-10-20 21:16:10 -07:00
|
|
|
EIsFromUserInput aIsFromUserInput)
|
2010-08-24 19:08:28 -07:00
|
|
|
: AccEvent(aIsInserted ?
|
2012-08-22 08:56:38 -07:00
|
|
|
static_cast<uint32_t>(nsIAccessibleEvent::EVENT_TEXT_INSERTED) :
|
|
|
|
static_cast<uint32_t>(nsIAccessibleEvent::EVENT_TEXT_REMOVED),
|
2010-10-20 21:16:10 -07:00
|
|
|
aAccessible, aIsFromUserInput, eAllowDupes)
|
2010-08-18 19:14:50 -07:00
|
|
|
, mStart(aStart)
|
|
|
|
, mIsInserted(aIsInserted)
|
|
|
|
, mModifiedText(aModifiedText)
|
2007-04-16 23:52:52 -07:00
|
|
|
{
|
2012-03-22 05:28:25 -07: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-16 23:52:52 -07:00
|
|
|
}
|
|
|
|
|
2010-07-01 18:49:42 -07:00
|
|
|
|
2010-10-20 21:16:10 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-11-12 22:29:22 -08:00
|
|
|
// AccReorderEvent
|
2010-10-20 21:16:10 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-11-12 22:29:22 -08:00
|
|
|
uint32_t
|
|
|
|
AccReorderEvent::IsShowHideEventTarget(const Accessible* aTarget) const
|
2010-10-20 21:16:10 -07:00
|
|
|
{
|
2012-11-12 22:29:22 -08:00
|
|
|
uint32_t count = mDependentEvents.Length();
|
|
|
|
for (uint32_t index = count - 1; index < count; index--) {
|
2013-01-01 16:49:19 -08: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-12 22:29:22 -08:00
|
|
|
}
|
|
|
|
}
|
2010-10-20 21:16:10 -07:00
|
|
|
|
2012-11-12 22:29:22 -08:00
|
|
|
return 0;
|
|
|
|
}
|
2010-10-20 21:16:10 -07:00
|
|
|
|
2010-07-01 18:49:42 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// AccHideEvent
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
AccHideEvent::
|
2012-05-28 18:18:45 -07:00
|
|
|
AccHideEvent(Accessible* aTarget, nsINode* aTargetNode) :
|
2011-01-18 00:03:38 -08:00
|
|
|
AccMutationEvent(::nsIAccessibleEvent::EVENT_HIDE, aTarget, aTargetNode)
|
2010-07-01 18:49:42 -07:00
|
|
|
{
|
2011-06-06 19:23:13 -07:00
|
|
|
mNextSibling = mAccessible->NextSibling();
|
|
|
|
mPrevSibling = mAccessible->PrevSibling();
|
2010-07-01 18:49:42 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-20 21:16:10 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// AccShowEvent
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
AccShowEvent::
|
2012-05-28 18:18:45 -07:00
|
|
|
AccShowEvent(Accessible* aTarget, nsINode* aTargetNode) :
|
2011-01-18 00:03:38 -08:00
|
|
|
AccMutationEvent(::nsIAccessibleEvent::EVENT_SHOW, aTarget, aTargetNode)
|
2010-10-20 21:16:10 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-26 07:58:53 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// AccTextSelChangeEvent
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
AccTextSelChangeEvent::AccTextSelChangeEvent(HyperTextAccessible* aTarget,
|
2014-04-10 09:09:40 -07:00
|
|
|
dom::Selection* aSelection,
|
2014-02-11 17:18:31 -08:00
|
|
|
int32_t aReason) :
|
2013-10-26 07:58:53 -07:00
|
|
|
AccEvent(nsIAccessibleEvent::EVENT_TEXT_SELECTION_CHANGED, aTarget,
|
|
|
|
eAutoDetect, eCoalesceTextSelChange),
|
2014-02-11 17:18:31 -08:00
|
|
|
mSel(aSelection), mReason(aReason) {}
|
2013-10-26 07:58:53 -07:00
|
|
|
|
|
|
|
AccTextSelChangeEvent::~AccTextSelChangeEvent() { }
|
|
|
|
|
2014-02-11 17:18:31 -08:00
|
|
|
bool
|
|
|
|
AccTextSelChangeEvent::IsCaretMoveOnly() const
|
|
|
|
{
|
|
|
|
return mSel->GetRangeCount() == 1 && mSel->IsCollapsed() &&
|
|
|
|
((mReason & (nsISelectionListener::COLLAPSETOSTART_REASON |
|
|
|
|
nsISelectionListener::COLLAPSETOEND_REASON)) == 0);
|
|
|
|
}
|
|
|
|
|
2011-10-31 17:52:27 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// AccSelChangeEvent
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
AccSelChangeEvent::
|
2012-05-28 18:18:45 -07:00
|
|
|
AccSelChangeEvent(Accessible* aWidget, Accessible* aItem,
|
2011-10-31 17:52:27 -07:00
|
|
|
SelChangeType aSelChangeType) :
|
|
|
|
AccEvent(0, aItem, eAutoDetect, eCoalesceSelectionChange),
|
|
|
|
mWidget(aWidget), mItem(aItem), mSelChangeType(aSelChangeType),
|
2012-07-30 07:20:58 -07:00
|
|
|
mPreceedingCount(0), mPackedEvent(nullptr)
|
2011-10-31 17:52:27 -07: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 03:16:32 -08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2010-08-24 19:08:28 -07:00
|
|
|
// AccTableChangeEvent
|
2010-01-20 03:16:32 -08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2010-08-24 19:08:28 -07:00
|
|
|
AccTableChangeEvent::
|
2012-08-22 08:56:38 -07:00
|
|
|
AccTableChangeEvent(Accessible* aAccessible, uint32_t aEventType,
|
|
|
|
int32_t aRowOrColIndex, int32_t aNumRowsOrCols) :
|
2010-10-20 21:16:10 -07:00
|
|
|
AccEvent(aEventType, aAccessible),
|
2008-01-17 18:56:38 -08:00
|
|
|
mRowOrColIndex(aRowOrColIndex), mNumRowsOrCols(aNumRowsOrCols)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-03-09 17:52:13 -08:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// AccVCChangeEvent
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
AccVCChangeEvent::
|
2012-05-28 18:18:45 -07:00
|
|
|
AccVCChangeEvent(Accessible* aAccessible,
|
2012-03-09 17:52:13 -08:00
|
|
|
nsIAccessible* aOldAccessible,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aOldStart, int32_t aOldEnd,
|
2014-08-14 18:44:59 -07:00
|
|
|
int16_t aReason, EIsFromUserInput aIsFromUserInput) :
|
|
|
|
AccEvent(::nsIAccessibleEvent::EVENT_VIRTUALCURSOR_CHANGED, aAccessible,
|
|
|
|
aIsFromUserInput),
|
2012-06-20 14:07:51 -07:00
|
|
|
mOldAccessible(aOldAccessible), mOldStart(aOldStart), mOldEnd(aOldEnd),
|
|
|
|
mReason(aReason)
|
2012-03-09 17:52:13 -08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-01-19 07:38:01 -08:00
|
|
|
already_AddRefed<nsIAccessibleEvent>
|
|
|
|
a11y::MakeXPCEvent(AccEvent* aEvent)
|
2012-03-09 17:52:13 -08:00
|
|
|
{
|
2013-01-19 07:38:01 -08: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);
|
|
|
|
xpEvent = new xpcAccStateChangeEvent(type, acc, doc, domNode, fromUser,
|
|
|
|
state, extra, sc->IsStateEnabled());
|
|
|
|
return xpEvent.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (eventGroup & (1 << AccEvent::eTextChangeEvent)) {
|
|
|
|
AccTextChangeEvent* tc = downcast_accEvent(aEvent);
|
|
|
|
nsString text;
|
|
|
|
tc->GetModifiedText(text);
|
|
|
|
xpEvent = new xpcAccTextChangeEvent(type, acc, doc, domNode, fromUser,
|
|
|
|
tc->GetStartOffset(), tc->GetLength(),
|
|
|
|
tc->IsTextInserted(), text);
|
|
|
|
return xpEvent.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (eventGroup & (1 << AccEvent::eHideEvent)) {
|
|
|
|
AccHideEvent* hideEvent = downcast_accEvent(aEvent);
|
|
|
|
xpEvent = new xpcAccHideEvent(type, acc, doc, domNode, fromUser,
|
|
|
|
hideEvent->TargetParent(),
|
|
|
|
hideEvent->TargetNextSibling(),
|
|
|
|
hideEvent->TargetPrevSibling());
|
|
|
|
return xpEvent.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (eventGroup & (1 << AccEvent::eCaretMoveEvent)) {
|
|
|
|
AccCaretMoveEvent* cm = downcast_accEvent(aEvent);
|
|
|
|
xpEvent = new xpcAccCaretMoveEvent(type, acc, doc, domNode, fromUser,
|
|
|
|
cm->GetCaretOffset());
|
|
|
|
return xpEvent.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (eventGroup & (1 << AccEvent::eVirtualCursorChangeEvent)) {
|
|
|
|
AccVCChangeEvent* vcc = downcast_accEvent(aEvent);
|
|
|
|
xpEvent = new xpcAccVirtualCursorChangeEvent(type, acc, doc, domNode, fromUser,
|
|
|
|
vcc->OldAccessible(),
|
|
|
|
vcc->OldStartOffset(),
|
|
|
|
vcc->OldEndOffset(),
|
|
|
|
vcc->Reason());
|
|
|
|
return xpEvent.forget();
|
|
|
|
}
|
|
|
|
|
2014-08-28 05:42:06 -07:00
|
|
|
if (eventGroup & (1 << AccEvent::eObjectAttrChangedEvent)) {
|
|
|
|
AccObjectAttrChangedEvent* oac = downcast_accEvent(aEvent);
|
|
|
|
xpEvent = new xpcAccObjectAttributeChangedEvent(type, acc, doc, domNode,
|
|
|
|
fromUser,
|
|
|
|
oac->GetAttribute());
|
|
|
|
return xpEvent.forget();
|
|
|
|
}
|
|
|
|
|
2013-01-19 07:38:01 -08:00
|
|
|
xpEvent = new xpcAccEvent(type, acc, doc, domNode, fromUser);
|
|
|
|
return xpEvent.forget();
|
|
|
|
}
|