bug 619002 - use text-remove / text-insert signals r=davidb, fer
authorTrevor Saunders <trev.saunders@gmail.com>
Mon, 04 Jul 2011 09:49:44 -0400
changeset 72806 c3e051b9da9c841a8283bc1c73c7300a01f21ab5
parent 72805 320e5abc6f5aeb067b537f9b357c81dbd00d8751
child 72807 0c94f01f53af675e49a841a2f70c83f99b335cc5
push id159
push usereakhgari@mozilla.com
push dateTue, 16 Aug 2011 17:53:11 +0000
treeherdermozilla-beta@8786e3e49240 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdavidb, fer
bugs619002
milestone7.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 619002 - use text-remove / text-insert signals r=davidb, fer
accessible/src/atk/nsAccessNodeWrap.cpp
accessible/src/atk/nsAccessNodeWrap.h
accessible/src/atk/nsAccessibleWrap.cpp
accessible/src/atk/nsAccessibleWrap.h
--- a/accessible/src/atk/nsAccessNodeWrap.cpp
+++ b/accessible/src/atk/nsAccessNodeWrap.cpp
@@ -36,18 +36,16 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsAccessNodeWrap.h"
 #include "nsApplicationAccessibleWrap.h"
 #include "nsMaiInterfaceText.h"
 
-PRBool nsAccessNodeWrap::gHaveNewTextSignals = PR_FALSE;
-
 /* For documentation of the accessibility architecture, 
  * see http://lxr.mozilla.org/seamonkey/source/accessible/accessible-docs.html
  */
 
 
 ////////////////////////////////////////////////////////////////////////////////
 // nsAccessNodeWrap
 ////////////////////////////////////////////////////////////////////////////////
@@ -67,16 +65,15 @@ nsAccessNodeWrap::
 //-----------------------------------------------------
 nsAccessNodeWrap::~nsAccessNodeWrap()
 {
 }
 
 void nsAccessNodeWrap::InitAccessibility()
 {
   nsAccessNode::InitXPAccessibility();
-  gHaveNewTextSignals = g_signal_lookup("text-insert", ATK_TYPE_TEXT);
 }
 
 void nsAccessNodeWrap::ShutdownAccessibility()
 {
   nsAccessNode::ShutdownXPAccessibility();
 }
 
--- a/accessible/src/atk/nsAccessNodeWrap.h
+++ b/accessible/src/atk/nsAccessNodeWrap.h
@@ -50,17 +50,11 @@ class nsAccessNodeWrap :  public nsAcces
 {
 public: // construction, destruction
     nsAccessNodeWrap(nsIContent *aContent, nsIWeakReference *aShell);
     virtual ~nsAccessNodeWrap();
 
     static void InitAccessibility();
     static void ShutdownAccessibility();
 
-    /*
-     * do we have text-remove and text-insert signals if not we need to use
-     * text-changed see nsAccessibleWrap::FireAtkTextChangedEvent() and
-     * bug 619002
-     */
-    static PRBool gHaveNewTextSignals;
 };
 
 #endif
--- a/accessible/src/atk/nsAccessibleWrap.cpp
+++ b/accessible/src/atk/nsAccessibleWrap.cpp
@@ -62,16 +62,19 @@
 #include "nsMaiInterfaceHypertext.h"
 #include "nsMaiInterfaceHyperlinkImpl.h"
 #include "nsMaiInterfaceTable.h"
 #include "nsXPCOMStrings.h"
 #include "nsComponentManagerUtils.h"
 #include "nsMaiInterfaceDocument.h"
 #include "nsMaiInterfaceImage.h"
 
+nsAccessibleWrap::EAvailableAtkSignals nsAccessibleWrap::gAvailableAtkSignals =
+  eUnknown;
+
 //defined in nsApplicationAccessibleWrap.cpp
 extern "C" GType g_atk_hyperlink_impl_type;
 
 /* MaiAtkObject */
 
 enum {
   ACTIVATE,
   CREATE,
@@ -1363,35 +1366,39 @@ nsAccessibleWrap::FireAtkTextChangedEven
     NS_ENSURE_TRUE(event, NS_ERROR_FAILURE);
 
     PRInt32 start = event->GetStartOffset();
     PRUint32 length = event->GetLength();
     PRBool isInserted = event->IsTextInserted();
     PRBool isFromUserInput = aEvent->IsFromUserInput();
     char* signal_name = nsnull;
 
-    if (gHaveNewTextSignals) {
-        nsAutoString text;
-        event->GetModifiedText(text);
-        signal_name = g_strconcat(isInserted ? "text-insert" : "text-remove",
-                                  isFromUserInput ? "" : "::system", NULL);
-        g_signal_emit_by_name(aObject, signal_name, start, length,
-                              NS_ConvertUTF16toUTF8(text).get());
-    } else {
-        // XXX remove this code and the gHaveNewTextSignals check when we can
-        // stop supporting old atk since it doesn't really work anyway
-        // see bug 619002
-        signal_name = g_strconcat(isInserted ? "text_changed::insert" :
-                                  "text_changed::delete",
-                                  isFromUserInput ? "" : kNonUserInputEvent, NULL);
-        g_signal_emit_by_name(aObject, signal_name, start, length);
-    }
+  if (gAvailableAtkSignals == eUnknown)
+    gAvailableAtkSignals = g_signal_lookup("text-insert", ATK_TYPE_TEXT) ?
+      eHaveNewAtkTextSignals : eNoNewAtkSignals;
 
-    g_free(signal_name);
-    return NS_OK;
+  if (gAvailableAtkSignals == eNoNewAtkSignals) {
+    // XXX remove this code and the gHaveNewTextSignals check when we can
+    // stop supporting old atk since it doesn't really work anyway
+    // see bug 619002
+    signal_name = g_strconcat(isInserted ? "text_changed::insert" :
+                              "text_changed::delete",
+                              isFromUserInput ? "" : kNonUserInputEvent, NULL);
+    g_signal_emit_by_name(aObject, signal_name, start, length);
+  } else {
+    nsAutoString text;
+    event->GetModifiedText(text);
+    signal_name = g_strconcat(isInserted ? "text-insert" : "text-remove",
+                              isFromUserInput ? "" : "::system", NULL);
+    g_signal_emit_by_name(aObject, signal_name, start, length,
+                          NS_ConvertUTF16toUTF8(text).get());
+  }
+
+  g_free(signal_name);
+  return NS_OK;
 }
 
 nsresult
 nsAccessibleWrap::FireAtkShowHideEvent(AccEvent* aEvent,
                                        AtkObject *aObject, PRBool aIsAdded)
 {
     if (aIsAdded)
         MAI_LOG_DEBUG(("\n\nReceived: Show event\n"));
--- a/accessible/src/atk/nsAccessibleWrap.h
+++ b/accessible/src/atk/nsAccessibleWrap.h
@@ -122,12 +122,26 @@ protected:
     nsresult FireAtkStateChangeEvent(AccEvent* aEvent, AtkObject *aObject);
     nsresult FireAtkTextChangedEvent(AccEvent* aEvent, AtkObject *aObject);
     nsresult FireAtkShowHideEvent(AccEvent* aEvent, AtkObject *aObject,
                                   PRBool aIsAdded);
 
     AtkObject *mAtkObject;
 
 private:
+
+  /*
+   * do we have text-remove and text-insert signals if not we need to use
+   * text-changed see nsAccessibleWrap::FireAtkTextChangedEvent() and
+   * bug 619002
+   */
+  enum EAvailableAtkSignals {
+    eUnknown,
+    eHaveNewAtkTextSignals,
+    eNoNewAtkSignals
+  };
+
+  static EAvailableAtkSignals gAvailableAtkSignals;
+
     PRUint16 CreateMaiInterfaces(void);
 };
 
 #endif /* __NS_ACCESSIBLE_WRAP_H__ */