Bug 729384 - Create an interface for virtual cursor changed events. r=surkov.alexander

This commit is contained in:
Eitan Isaacson 2012-03-09 20:52:13 -05:00
parent d449e79078
commit 91b58363c1
6 changed files with 136 additions and 2 deletions

View File

@ -571,3 +571,26 @@ interface nsIAccessibleTableChangeEvent: nsISupports
readonly attribute long numRowsOrCols;
};
/*
* An interface for virtual cursor changed events.
* Passes previous cursor position and text offsets.
*/
[scriptable, uuid(370e8b9b-2bbc-4bff-a9c7-16ddc54aea21)]
interface nsIAccessibleVirtualCursorChangeEvent : nsISupports
{
/**
* Previous object pointed at by virtual cursor. null if none.
*/
readonly attribute nsIAccessible oldAccessible;
/**
* Previous start offset of pivot. -1 if none.
*/
readonly attribute long oldStartOffset;
/**
* Previous end offset of pivot. -1 if none.
*/
readonly attribute long oldEndOffset;
};

View File

@ -380,3 +380,24 @@ AccTableChangeEvent::CreateXPCOMObject()
return event;
}
////////////////////////////////////////////////////////////////////////////////
// AccVCChangeEvent
////////////////////////////////////////////////////////////////////////////////
AccVCChangeEvent::
AccVCChangeEvent(nsAccessible* aAccessible,
nsIAccessible* aOldAccessible,
PRInt32 aOldStart, PRInt32 aOldEnd) :
AccEvent(::nsIAccessibleEvent::EVENT_VIRTUALCURSOR_CHANGED, aAccessible),
mOldAccessible(aOldAccessible), mOldStart(aOldStart), mOldEnd(aOldEnd)
{
}
already_AddRefed<nsAccEvent>
AccVCChangeEvent::CreateXPCOMObject()
{
nsAccEvent* event = new nsAccVirtualCursorChangeEvent(this);
NS_ADDREF(event);
return event;
}

View File

@ -129,7 +129,8 @@ public:
eShowEvent,
eCaretMoveEvent,
eSelectionChangeEvent,
eTableChangeEvent
eTableChangeEvent,
eVirtualCursorChangeEvent
};
static const EventGroup kEventGroup = eGenericEvent;
@ -399,6 +400,37 @@ private:
PRUint32 mNumRowsOrCols; // the number of inserted/deleted rows/columns
};
/**
* Accessible virtual cursor change event.
*/
class AccVCChangeEvent : public AccEvent
{
public:
AccVCChangeEvent(nsAccessible* aAccessible,
nsIAccessible* aOldAccessible,
PRInt32 aOldStart, PRInt32 aOldEnd);
virtual ~AccVCChangeEvent() { }
// AccEvent
virtual already_AddRefed<nsAccEvent> CreateXPCOMObject();
static const EventGroup kEventGroup = eVirtualCursorChangeEvent;
virtual unsigned int GetEventGroups() const
{
return AccEvent::GetEventGroups() | (1U << eVirtualCursorChangeEvent);
}
// AccTableChangeEvent
nsIAccessible* OldAccessible() const { return mOldAccessible; }
PRInt32 OldStartOffset() const { return mOldStart; }
PRInt32 OldEndOffset() const { return mOldEnd; }
private:
nsRefPtr<nsIAccessible> mOldAccessible;
PRInt32 mOldStart;
PRInt32 mOldEnd;
};
/**
* Downcast the generic accessible event object to derived type.

View File

@ -923,7 +923,8 @@ nsDocAccessible::OnPivotChanged(nsIAccessiblePivot* aPivot,
nsIAccessible* aOldAccessible,
PRInt32 aOldStart, PRInt32 aOldEnd)
{
nsRefPtr<AccEvent> event = new AccEvent(nsIAccessibleEvent::EVENT_VIRTUALCURSOR_CHANGED, this);
nsRefPtr<AccEvent> event = new AccVCChangeEvent(this, aOldAccessible,
aOldStart, aOldEnd);
nsEventShell::FireEvent(event);
return NS_OK;

View File

@ -253,3 +253,40 @@ nsAccTableChangeEvent::GetNumRowsOrCols(PRInt32* aNumRowsOrCols)
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////
// nsAccVirtualCursorChangeEvent
////////////////////////////////////////////////////////////////////////////////
NS_IMPL_ISUPPORTS_INHERITED1(nsAccVirtualCursorChangeEvent, nsAccEvent,
nsIAccessibleVirtualCursorChangeEvent)
NS_IMETHODIMP
nsAccVirtualCursorChangeEvent::GetOldAccessible(nsIAccessible** aOldAccessible)
{
NS_ENSURE_ARG_POINTER(aOldAccessible);
*aOldAccessible =
static_cast<AccVCChangeEvent*>(mEvent.get())->OldAccessible();
NS_IF_ADDREF(*aOldAccessible);
return NS_OK;
}
NS_IMETHODIMP
nsAccVirtualCursorChangeEvent::GetOldStartOffset(PRInt32* aOldStartOffset)
{
NS_ENSURE_ARG_POINTER(aOldStartOffset);
*aOldStartOffset =
static_cast<AccVCChangeEvent*>(mEvent.get())->OldStartOffset();
return NS_OK;
}
NS_IMETHODIMP
nsAccVirtualCursorChangeEvent::GetOldEndOffset(PRInt32* aOldEndOffset)
{
NS_ENSURE_ARG_POINTER(aOldEndOffset);
*aOldEndOffset =
static_cast<AccVCChangeEvent*>(mEvent.get())->OldEndOffset();
return NS_OK;
}

View File

@ -164,5 +164,25 @@ private:
nsAccTableChangeEvent& operator =(const nsAccTableChangeEvent&);
};
/**
* Accessible virtual cursor change event.
*/
class nsAccVirtualCursorChangeEvent : public nsAccEvent,
public nsIAccessibleVirtualCursorChangeEvent
{
public:
nsAccVirtualCursorChangeEvent(AccVCChangeEvent* aEvent) :
nsAccEvent(aEvent) { }
virtual ~nsAccVirtualCursorChangeEvent() { }
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSIACCESSIBLEVIRTUALCURSORCHANGEEVENT
private:
nsAccVirtualCursorChangeEvent() MOZ_DELETE;
nsAccVirtualCursorChangeEvent(const nsAccVirtualCursorChangeEvent&) MOZ_DELETE;
nsAccVirtualCursorChangeEvent& operator =(const nsAccVirtualCursorChangeEvent&) MOZ_DELETE;
};
#endif