Bug 1140917 - IPC Proxy for replace/insert/copy/cut/delete/paste, r=tbsaunde
authorOlli Pettay <Olli.Pettay@helsinki.fi>
Mon, 09 Mar 2015 23:04:02 +0200
changeset 232710 737f554af428dac7e744acf3089bc1a54fd6f54a
parent 232709 d929f723b8e300a83ab88a9b5eef197242763c01
child 232711 68233f28f9598b644b67dc06a97a60ef8ee7dc56
push id56637
push useropettay@mozilla.com
push dateTue, 10 Mar 2015 11:07:52 +0000
treeherdermozilla-inbound@737f554af428 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstbsaunde
bugs1140917
milestone39.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 1140917 - IPC Proxy for replace/insert/copy/cut/delete/paste, r=tbsaunde
accessible/atk/nsMaiInterfaceEditableText.cpp
accessible/ipc/DocAccessibleChild.cpp
accessible/ipc/DocAccessibleChild.h
accessible/ipc/PDocAccessible.ipdl
accessible/ipc/ProxyAccessible.cpp
accessible/ipc/ProxyAccessible.h
--- a/accessible/atk/nsMaiInterfaceEditableText.cpp
+++ b/accessible/atk/nsMaiInterfaceEditableText.cpp
@@ -4,108 +4,122 @@
  * 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/. */
 
 #include "InterfaceInitFuncs.h"
 
 #include "Accessible-inl.h"
 #include "HyperTextAccessible-inl.h"
 #include "nsMai.h"
-
+#include "ProxyAccessible.h"
 #include "nsString.h"
 #include "mozilla/Likely.h"
 
 using namespace mozilla::a11y;
 
 extern "C" {
 static void
 setTextContentsCB(AtkEditableText *aText, const gchar *aString)
 {
   AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
-  if (!accWrap)
-    return;
+  if (accWrap) {
+    HyperTextAccessible* text = accWrap->AsHyperText();
+    if (!text || !text->IsTextRole()) {
+      return;
+    }
 
-  HyperTextAccessible* text = accWrap->AsHyperText();
-  if (!text || !text->IsTextRole())
-    return;
-
-  NS_ConvertUTF8toUTF16 strContent(aString);
-  text->ReplaceText(strContent);
+    NS_ConvertUTF8toUTF16 strContent(aString);
+    text->ReplaceText(strContent);
+  } else if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aText))) {
+    NS_ConvertUTF8toUTF16 strContent(aString);
+    proxy->ReplaceText(strContent);
+  }
 }
 
 static void
 insertTextCB(AtkEditableText *aText,
              const gchar *aString, gint aLength, gint *aPosition)
 {
   AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
-  if (!accWrap)
-    return;
+  if (accWrap) {
+    HyperTextAccessible* text = accWrap->AsHyperText();
+    if (!text || !text->IsTextRole()) {
+      return;
+    }
 
-  HyperTextAccessible* text = accWrap->AsHyperText();
-  if (!text || !text->IsTextRole())
-    return;
-
-  NS_ConvertUTF8toUTF16 strContent(aString, aLength);
-  text->InsertText(strContent, *aPosition);
+    NS_ConvertUTF8toUTF16 strContent(aString);
+    text->InsertText(strContent, *aPosition);
+  } else if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aText))) {
+    NS_ConvertUTF8toUTF16 strContent(aString);
+    proxy->InsertText(strContent, *aPosition);
+  }
 }
 
 static void
 copyTextCB(AtkEditableText *aText, gint aStartPos, gint aEndPos)
 {
   AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
-  if (!accWrap)
-    return;
+  if (accWrap) {
+    HyperTextAccessible* text = accWrap->AsHyperText();
+    if (!text || !text->IsTextRole()) {
+      return;
+    }
 
-  HyperTextAccessible* text = accWrap->AsHyperText();
-  if (!text || !text->IsTextRole())
-    return;
-
-  text->CopyText(aStartPos, aEndPos);
+    text->CopyText(aStartPos, aEndPos);
+  } else if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aText))) {
+    proxy->CopyText(aStartPos, aEndPos);
+  }
 }
 
 static void
 cutTextCB(AtkEditableText *aText, gint aStartPos, gint aEndPos)
 {
   AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
-  if (!accWrap)
-    return;
+  if (accWrap) {
+    HyperTextAccessible* text = accWrap->AsHyperText();
+    if (!text || !text->IsTextRole()) {
+      return;
+    }
 
-  HyperTextAccessible* text = accWrap->AsHyperText();
-  if (!text || !text->IsTextRole())
-    return;
-
-  text->CutText(aStartPos, aEndPos);
+    text->CutText(aStartPos, aEndPos);
+  } else if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aText))) {
+    proxy->CutText(aStartPos, aEndPos);
+  }
 }
 
 static void
 deleteTextCB(AtkEditableText *aText, gint aStartPos, gint aEndPos)
 {
   AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
-  if (!accWrap)
-    return;
+  if (accWrap) {
+    HyperTextAccessible* text = accWrap->AsHyperText();
+    if (!text || !text->IsTextRole()) {
+      return;
+    }
 
-  HyperTextAccessible* text = accWrap->AsHyperText();
-  if (!text || !text->IsTextRole())
-    return;
-
-  text->DeleteText(aStartPos, aEndPos);
+    text->DeleteText(aStartPos, aEndPos);
+  } else if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aText))) {
+    proxy->DeleteText(aStartPos, aEndPos);
+  }
 }
 
 static void
 pasteTextCB(AtkEditableText *aText, gint aPosition)
 {
   AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
-  if (!accWrap)
-    return;
+  if (accWrap) {
+    HyperTextAccessible* text = accWrap->AsHyperText();
+    if (!text || !text->IsTextRole()) {
+      return;
+    }
 
-  HyperTextAccessible* text = accWrap->AsHyperText();
-  if (!text || !text->IsTextRole())
-    return;
-
-  text->PasteText(aPosition);
+    text->PasteText(aPosition);
+  } else if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aText))) {
+    proxy->PasteText(aPosition);
+  }
 }
 }
 
 void
 editableTextInterfaceInitCB(AtkEditableTextIface* aIface)
 {
   NS_ASSERTION(aIface, "Invalid aIface");
   if (MOZ_UNLIKELY(!aIface))
--- a/accessible/ipc/DocAccessibleChild.cpp
+++ b/accessible/ipc/DocAccessibleChild.cpp
@@ -503,10 +503,86 @@ DocAccessibleChild::RecvScrollSubstringT
     acc->ScrollSubstringToPoint(aStartOffset, aEndOffset, aCoordinateType,
                                 aX, aY);
   }
 
   return true;
 }
 
 
+bool
+DocAccessibleChild::RecvReplaceText(const uint64_t& aID,
+                                    const nsString& aText)
+{
+  HyperTextAccessible* acc = IdToHyperTextAccessible(aID);
+  if (acc && acc->IsTextRole()) {
+    acc->ReplaceText(aText);
+  }
+
+  return true;
+}
+
+bool
+DocAccessibleChild::RecvInsertText(const uint64_t& aID,
+                                   const nsString& aText,
+                                   const int32_t& aPosition)
+{
+  HyperTextAccessible* acc = IdToHyperTextAccessible(aID);
+  if (acc && acc->IsTextRole()) {
+    acc->InsertText(aText, aPosition);
+  }
+
+  return true;
+}
+
+bool
+DocAccessibleChild::RecvCopyText(const uint64_t& aID,
+                                 const int32_t& aStartPos,
+                                 const int32_t& aEndPos)
+{
+  HyperTextAccessible* acc = IdToHyperTextAccessible(aID);
+  if (acc && acc->IsTextRole()) {
+    acc->CopyText(aStartPos, aEndPos);
+  }
+
+  return true;
+}
+
+bool
+DocAccessibleChild::RecvCutText(const uint64_t& aID,
+                                const int32_t& aStartPos,
+                                const int32_t& aEndPos)
+{
+  HyperTextAccessible* acc = IdToHyperTextAccessible(aID);
+  if (acc && acc->IsTextRole()) {
+    acc->CutText(aStartPos, aEndPos);
+  }
+
+  return true;
+}
+
+bool
+DocAccessibleChild::RecvDeleteText(const uint64_t& aID,
+                                   const int32_t& aStartPos,
+                                   const int32_t& aEndPos)
+{
+  HyperTextAccessible* acc = IdToHyperTextAccessible(aID);
+  if (acc && acc->IsTextRole()) {
+    acc->DeleteText(aStartPos, aEndPos);
+  }
+
+  return true;
+}
+
+bool
+DocAccessibleChild::RecvPasteText(const uint64_t& aID,
+                                  const int32_t& aPosition)
+{
+  HyperTextAccessible* acc = IdToHyperTextAccessible(aID);
+  if (acc && acc->IsTextRole()) {
+    acc->PasteText(aPosition);
+  }
+
+  return true;
+}
+
 }
 }
--- a/accessible/ipc/DocAccessibleChild.h
+++ b/accessible/ipc/DocAccessibleChild.h
@@ -157,16 +157,38 @@ public:
 
   virtual bool RecvScrollSubstringToPoint(const uint64_t& aID,
                                           const int32_t& aStartOffset,
                                           const int32_t& aEndOffset,
                                           const uint32_t& aCoordinateType,
                                           const int32_t& aX,
                                           const int32_t& aY) MOZ_OVERRIDE;
 
+  virtual bool RecvReplaceText(const uint64_t& aID,
+                               const nsString& aText);
+
+  virtual bool RecvInsertText(const uint64_t& aID,
+                              const nsString& aText,
+                              const int32_t& aPosition);
+
+  virtual bool RecvCopyText(const uint64_t& aID,
+                            const int32_t& aStartPos,
+                            const int32_t& aEndPos);
+
+  virtual bool RecvCutText(const uint64_t& aID,
+                           const int32_t& aStartPos,
+                           const int32_t& aEndPos);
+
+  virtual bool RecvDeleteText(const uint64_t& aID,
+                              const int32_t& aStartPos,
+                              const int32_t& aEndPos);
+
+  virtual bool RecvPasteText(const uint64_t& aID,
+                             const int32_t& aPosition);
+
 private:
   bool PersistentPropertiesToArray(nsIPersistentProperties* aProps,
                                    nsTArray<Attribute>* aAttributes);
 
   DocAccessible* mDoc;
 };
 
 }
--- a/accessible/ipc/PDocAccessible.ipdl
+++ b/accessible/ipc/PDocAccessible.ipdl
@@ -109,12 +109,19 @@ child:
 
   ScrollSubstringTo(uint64_t aID, int32_t aStartOffset, int32_t aEndOffset,
                     uint32_t aScrollType);
   ScrollSubstringToPoint(uint64_t aID,
                          int32_t aStartOffset,
                          int32_t aEndOffset,
                          uint32_t aCoordinateType,
                          int32_t aX, int32_t aY);
+
+  prio(high) sync ReplaceText(uint64_t aID, nsString aText);
+  prio(high) sync InsertText(uint64_t aID, nsString aText, int32_t aPosition);
+  prio(high) sync CopyText(uint64_t aID, int32_t aStartPos, int32_t aEndPos);
+  prio(high) sync CutText(uint64_t aID, int32_t aStartPos, int32_t aEndPos);
+  prio(high) sync DeleteText(uint64_t aID, int32_t aStartPos, int32_t aEndPos);
+  prio(high) sync PasteText(uint64_t aID, int32_t aPosition);
 };
 
 }
 }
--- a/accessible/ipc/ProxyAccessible.cpp
+++ b/accessible/ipc/ProxyAccessible.cpp
@@ -322,10 +322,46 @@ ProxyAccessible::ScrollSubstringToPoint(
                                         int32_t aEndOffset,
                                         uint32_t aCoordinateType,
                                         int32_t aX, int32_t aY)
 {
   unused << mDoc->SendScrollSubstringToPoint(mID, aStartOffset, aEndOffset,
                                              aCoordinateType, aX, aY);
 }
 
+void
+ProxyAccessible::ReplaceText(const nsString& aText)
+{
+  unused << mDoc->SendReplaceText(mID, aText);
+}
+
+void
+ProxyAccessible::InsertText(const nsString& aText, int32_t aPosition)
+{
+  unused << mDoc->SendInsertText(mID, aText, aPosition);
+}
+
+void
+ProxyAccessible::CopyText(int32_t aStartPos, int32_t aEndPos)
+{
+  unused << mDoc->SendCopyText(mID, aStartPos, aEndPos);
+}
+
+void
+ProxyAccessible::CutText(int32_t aStartPos, int32_t aEndPos)
+{
+  unused << mDoc->SendCutText(mID, aStartPos, aEndPos);
+}
+
+void
+ProxyAccessible::DeleteText(int32_t aStartPos, int32_t aEndPos)
+{
+  unused << mDoc->SendDeleteText(mID, aStartPos, aEndPos);
+}
+
+void
+ProxyAccessible::PasteText(int32_t aPosition)
+{
+  unused << mDoc->SendPasteText(mID, aPosition);
+}
+
 }
 }
--- a/accessible/ipc/ProxyAccessible.h
+++ b/accessible/ipc/ProxyAccessible.h
@@ -157,16 +157,28 @@ public:
   void ScrollSubstringTo(int32_t aStartOffset, int32_t aEndOffset,
                          uint32_t aScrollType);
 
   void ScrollSubstringToPoint(int32_t aStartOffset,
                               int32_t aEndOffset,
                               uint32_t aCoordinateType,
                               int32_t aX, int32_t aY);
 
+  void ReplaceText(const nsString& aText);
+
+  void InsertText(const nsString& aText, int32_t aPosition);
+
+  void CopyText(int32_t aStartPos, int32_t aEndPos);
+
+  void CutText(int32_t aStartPos, int32_t aEndPos);
+
+  void DeleteText(int32_t aStartPos, int32_t aEndPos);
+
+  void PasteText(int32_t aPosition);
+
   /**
    * Allow the platform to store a pointers worth of data on us.
    */
   uintptr_t GetWrapper() const { return mWrapper; }
   void SetWrapper(uintptr_t aWrapper) { mWrapper = aWrapper; }
 
   /*
    * Return the ID of the accessible being proxied.