From 159859c23dae2ea6e0229a2cb59a257c11976f1f Mon Sep 17 00:00:00 2001 From: Trevor Saunders Date: Mon, 4 Jul 2011 09:49:44 -0400 Subject: [PATCH] bug 619002 - use text-remove / text-insert signals r=davidb, fer --- accessible/src/atk/nsAccessNodeWrap.cpp | 3 -- accessible/src/atk/nsAccessNodeWrap.h | 6 ---- accessible/src/atk/nsAccessibleWrap.cpp | 43 ++++++++++++++----------- accessible/src/atk/nsAccessibleWrap.h | 14 ++++++++ 4 files changed, 39 insertions(+), 27 deletions(-) diff --git a/accessible/src/atk/nsAccessNodeWrap.cpp b/accessible/src/atk/nsAccessNodeWrap.cpp index 298db4b64226..bdc8f3a0b3ba 100644 --- a/accessible/src/atk/nsAccessNodeWrap.cpp +++ b/accessible/src/atk/nsAccessNodeWrap.cpp @@ -41,8 +41,6 @@ #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 */ @@ -72,7 +70,6 @@ nsAccessNodeWrap::~nsAccessNodeWrap() void nsAccessNodeWrap::InitAccessibility() { nsAccessNode::InitXPAccessibility(); - gHaveNewTextSignals = g_signal_lookup("text-insert", ATK_TYPE_TEXT); } void nsAccessNodeWrap::ShutdownAccessibility() diff --git a/accessible/src/atk/nsAccessNodeWrap.h b/accessible/src/atk/nsAccessNodeWrap.h index 0f333dae9575..7258ae530384 100644 --- a/accessible/src/atk/nsAccessNodeWrap.h +++ b/accessible/src/atk/nsAccessNodeWrap.h @@ -55,12 +55,6 @@ public: // construction, destruction 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 diff --git a/accessible/src/atk/nsAccessibleWrap.cpp b/accessible/src/atk/nsAccessibleWrap.cpp index 4d125d4956d3..5329dd8af63f 100644 --- a/accessible/src/atk/nsAccessibleWrap.cpp +++ b/accessible/src/atk/nsAccessibleWrap.cpp @@ -67,6 +67,9 @@ #include "nsMaiInterfaceDocument.h" #include "nsMaiInterfaceImage.h" +nsAccessibleWrap::EAvailableAtkSignals nsAccessibleWrap::gAvailableAtkSignals = + eUnknown; + //defined in nsApplicationAccessibleWrap.cpp extern "C" GType g_atk_hyperlink_impl_type; @@ -1368,25 +1371,29 @@ nsAccessibleWrap::FireAtkTextChangedEvent(AccEvent* aEvent, 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 diff --git a/accessible/src/atk/nsAccessibleWrap.h b/accessible/src/atk/nsAccessibleWrap.h index 4af59e88be11..84d805014d3b 100644 --- a/accessible/src/atk/nsAccessibleWrap.h +++ b/accessible/src/atk/nsAccessibleWrap.h @@ -127,6 +127,20 @@ protected: 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); };