Bug 729384 - Create an interface for virtual cursor changed events. r=surkov.alexander
authorEitan Isaacson <eitan@monotonous.org>
Fri, 09 Mar 2012 20:52:13 -0500
changeset 91948 7ec7f2468d66357f2ab90f1f966657942c109eda
parent 91947 412f24be91ed1e5e024f5989f1cc6d0cf693cd5e
child 91949 c53de99a72cbff3617480c48ccc7a8111e0b9674
push id136
push userlsblakk@mozilla.com
push dateFri, 01 Jun 2012 02:39:32 +0000
treeherdermozilla-release@7ebf7352c959 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssurkov
bugs729384
milestone13.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 729384 - Create an interface for virtual cursor changed events. r=surkov.alexander
accessible/public/nsIAccessibleEvent.idl
accessible/src/base/AccEvent.cpp
accessible/src/base/AccEvent.h
accessible/src/base/nsDocAccessible.cpp
accessible/src/xpcom/nsAccEvent.cpp
accessible/src/xpcom/nsAccEvent.h
--- a/accessible/public/nsIAccessibleEvent.idl
+++ b/accessible/public/nsIAccessibleEvent.idl
@@ -566,8 +566,31 @@ interface nsIAccessibleTableChangeEvent:
   readonly attribute long rowOrColIndex;
 
   /**
    * Return the number of rows or cols
    */
   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;
+};
--- a/accessible/src/base/AccEvent.cpp
+++ b/accessible/src/base/AccEvent.cpp
@@ -375,8 +375,29 @@ AccTableChangeEvent::
 already_AddRefed<nsAccEvent>
 AccTableChangeEvent::CreateXPCOMObject()
 {
   nsAccEvent* event = new nsAccTableChangeEvent(this);
   NS_IF_ADDREF(event);
   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;
+}
--- a/accessible/src/base/AccEvent.h
+++ b/accessible/src/base/AccEvent.h
@@ -124,17 +124,18 @@ public:
     eGenericEvent,
     eStateChangeEvent,
     eTextChangeEvent,
     eMutationEvent,
     eHideEvent,
     eShowEvent,
     eCaretMoveEvent,
     eSelectionChangeEvent,
-    eTableChangeEvent
+    eTableChangeEvent,
+    eVirtualCursorChangeEvent
   };
 
   static const EventGroup kEventGroup = eGenericEvent;
   virtual unsigned int GetEventGroups() const
   {
     return 1U << eGenericEvent;
   }
 
@@ -394,16 +395,47 @@ public:
   PRUint32 GetIndex() const { return mRowOrColIndex; }
   PRUint32 GetCount() const { return mNumRowsOrCols; }
 
 private:
   PRUint32 mRowOrColIndex;   // the start row/column after which the rows are inserted/deleted.
   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.
  */
 class downcast_accEvent
 {
 public:
   downcast_accEvent(AccEvent* e) : mRawPtr(e) { }
--- a/accessible/src/base/nsDocAccessible.cpp
+++ b/accessible/src/base/nsDocAccessible.cpp
@@ -918,17 +918,18 @@ NS_IMETHODIMP nsDocAccessible::Observe(n
 ////////////////////////////////////////////////////////////////////////////////
 // nsIAccessiblePivotObserver
 
 NS_IMETHODIMP
 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;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 // nsIDocumentObserver
 
--- a/accessible/src/xpcom/nsAccEvent.cpp
+++ b/accessible/src/xpcom/nsAccEvent.cpp
@@ -248,8 +248,45 @@ NS_IMETHODIMP
 nsAccTableChangeEvent::GetNumRowsOrCols(PRInt32* aNumRowsOrCols)
 {
   NS_ENSURE_ARG_POINTER(aNumRowsOrCols);
 
   *aNumRowsOrCols = static_cast<AccTableChangeEvent*>(mEvent.get())->GetCount();
   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;
+}
--- a/accessible/src/xpcom/nsAccEvent.h
+++ b/accessible/src/xpcom/nsAccEvent.h
@@ -159,10 +159,30 @@ public:
   NS_DECL_NSIACCESSIBLETABLECHANGEEVENT
 
 private:
   nsAccTableChangeEvent();
   nsAccTableChangeEvent(const nsAccTableChangeEvent&);
   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