Bug 748601 - nsMaiInterfaceText.cpp should check internal role not atk role, r=tbsaunde, f=surkov
authorMax Li <maxli@maxli.ca>
Wed, 02 May 2012 07:13:34 -0400
changeset 96964 298c5504def8e3277ec488867350cb732def9acf
parent 96963 e18b59be7262dbededb7e1393b750603647df666
child 96965 1863228248eb66e54e4aa83ff967ce5c0505f40a
push id1116
push userlsblakk@mozilla.com
push dateMon, 16 Jul 2012 19:38:18 +0000
treeherdermozilla-beta@95f959a8b4dc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstbsaunde
bugs748601
milestone15.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 748601 - nsMaiInterfaceText.cpp should check internal role not atk role, r=tbsaunde, f=surkov
accessible/src/atk/nsAccessibleWrap.cpp
accessible/src/atk/nsAccessibleWrap.h
accessible/src/atk/nsMaiInterfaceText.cpp
--- a/accessible/src/atk/nsAccessibleWrap.cpp
+++ b/accessible/src/atk/nsAccessibleWrap.cpp
@@ -724,18 +724,31 @@ getRoleCB(AtkObject *aAtkObj)
 #ifdef DEBUG_A11Y
   NS_ASSERTION(nsAccUtils::IsTextInterfaceSupportCorrect(accWrap),
       "Does not support nsIAccessibleText when it should");
 #endif
 
   if (aAtkObj->role != ATK_ROLE_INVALID)
     return aAtkObj->role;
 
-  return aAtkObj->role =
-    static_cast<AtkRole>(nsAccessibleWrap::AtkRoleFor(accWrap->Role()));
+#define ROLE(geckoRole, stringRole, atkRole, macRole, msaaRole, ia2Role) \
+  case roles::geckoRole: \
+    aAtkObj->role = atkRole; \
+    break;
+
+  switch (accWrap->Role()) {
+#include "RoleMap.h"
+    default:
+      MOZ_NOT_REACHED("Unknown role.");
+      aAtkObj->role = ATK_ROLE_UNKNOWN;
+  };
+
+#undef ROLE
+
+  return aAtkObj->role;
 }
 
 AtkAttributeSet*
 ConvertToAtkAttributeSet(nsIPersistentProperties* aAttributes)
 {
     if (!aAttributes)
         return nsnull;
 
@@ -1385,25 +1398,8 @@ nsAccessibleWrap::FireAtkShowHideEvent(A
     bool isFromUserInput = aEvent->IsFromUserInput();
     char *signal_name = g_strconcat(aIsAdded ? "children_changed::add" :  "children_changed::remove",
                                     isFromUserInput ? "" : kNonUserInputEvent, NULL);
     g_signal_emit_by_name(parentObject, signal_name, indexInParent, aObject, NULL);
     g_free(signal_name);
 
     return NS_OK;
 }
-
-PRUint32
-nsAccessibleWrap::AtkRoleFor(role aRole)
-{
-#define ROLE(geckoRole, stringRole, atkRole, macRole, msaaRole, ia2Role) \
-  case roles::geckoRole: \
-    return atkRole;
-
-  switch (aRole) {
-#include "RoleMap.h"
-    default:
-      MOZ_NOT_REACHED("Unknown role.");
-      return ATK_ROLE_UNKNOWN;
-  }
-
-#undef ROLE
-}
--- a/accessible/src/atk/nsAccessibleWrap.h
+++ b/accessible/src/atk/nsAccessibleWrap.h
@@ -111,21 +111,16 @@ public:
     void SetMaiHyperlink(MaiHyperlink* aMaiHyperlink);
 
     static const char * ReturnString(nsAString &aString) {
       static nsCString returnedString;
       returnedString = NS_ConvertUTF16toUTF8(aString);
       return returnedString.get();
     }
 
-  /**
-   * Function mapping from cross platform roles to ATK roles.
-   */
-  static PRUint32 AtkRoleFor(mozilla::a11y::role aRole);
-
 protected:
     virtual nsresult FirePlatformEvent(AccEvent* aEvent);
 
     nsresult FireAtkStateChangeEvent(AccEvent* aEvent, AtkObject *aObject);
     nsresult FireAtkTextChangedEvent(AccEvent* aEvent, AtkObject *aObject);
     nsresult FireAtkShowHideEvent(AccEvent* aEvent, AtkObject *aObject,
                                   bool aIsAdded);
 
--- a/accessible/src/atk/nsMaiInterfaceText.cpp
+++ b/accessible/src/atk/nsMaiInterfaceText.cpp
@@ -40,27 +40,28 @@
 
 #include "InterfaceInitFuncs.h"
 
 #include "nsHyperTextAccessible.h"
 #include "nsMai.h"
 
 #include "nsIPersistentProperties2.h"
 
+using namespace mozilla::a11y;
+
 AtkAttributeSet* ConvertToAtkAttributeSet(nsIPersistentProperties* aAttributes);
 
 static void
 ConvertTexttoAsterisks(nsAccessibleWrap* accWrap, nsAString& aString)
 {
-    // convert each char to "*" when it's "password text" 
-    PRUint32 atkRole = nsAccessibleWrap::AtkRoleFor(accWrap->NativeRole());
-    if (atkRole == ATK_ROLE_PASSWORD_TEXT) {
-        for (PRUint32 i = 0; i < aString.Length(); i++)
-            aString.Replace(i, 1, NS_LITERAL_STRING("*"));
-    }
+  // convert each char to "*" when it's "password text" 
+  if (accWrap->NativeRole() == roles::PASSWORD_TEXT) {
+    for (PRUint32 i = 0; i < aString.Length(); i++)
+      aString.Replace(i, 1, NS_LITERAL_STRING("*"));
+  }
 }
 
 extern "C" {
 
 static gchar*
 getTextCB(AtkText *aText, gint aStartOffset, gint aEndOffset)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
@@ -137,39 +138,39 @@ getTextAtOffsetCB(AtkText *aText, gint a
     NS_ENSURE_SUCCESS(rv, nsnull);
 
     ConvertTexttoAsterisks(accWrap, autoStr);
     NS_ConvertUTF16toUTF8 cautoStr(autoStr);
     return (cautoStr.get()) ? g_strdup(cautoStr.get()) : nsnull;
 }
 
 static gunichar
-getCharacterAtOffsetCB(AtkText *aText, gint aOffset)
+getCharacterAtOffsetCB(AtkText* aText, gint aOffset)
 {
-    nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
-    if (!accWrap)
-        return 0;
+  nsAccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
+  if (!accWrap)
+    return 0;
 
-    nsCOMPtr<nsIAccessibleText> accText;
-    accWrap->QueryInterface(NS_GET_IID(nsIAccessibleText),
-                            getter_AddRefs(accText));
-    NS_ENSURE_TRUE(accText, 0);
+  nsCOMPtr<nsIAccessibleText> accText;
+  accWrap->QueryInterface(NS_GET_IID(nsIAccessibleText),
+                          getter_AddRefs(accText));
+  NS_ENSURE_TRUE(accText, 0);
 
-    /* PRUnichar is unsigned short in Mozilla */
-    /* gnuichar is guint32 in glib */
-    PRUnichar uniChar;
-    nsresult rv =
-        accText->GetCharacterAtOffset(aOffset, &uniChar);
+  // PRUnichar is unsigned short in Mozilla
+  // gnuichar is guint32 in glib
+  PRUnichar uniChar = 0;
+  nsresult rv = accText->GetCharacterAtOffset(aOffset, &uniChar);
+  if (NS_FAILED(rv))
+    return 0;
 
-    // convert char to "*" when it's "password text" 
-    PRUint32 atkRole = nsAccessibleWrap::AtkRoleFor(accWrap->NativeRole());
-    if (atkRole == ATK_ROLE_PASSWORD_TEXT)
-        uniChar = '*';
+  // Convert char to "*" when it's "password text".
+  if (accWrap->NativeRole() == roles::PASSWORD_TEXT)
+    uniChar = '*';
 
-    return (NS_FAILED(rv)) ? 0 : static_cast<gunichar>(uniChar);
+  return static_cast<gunichar>(uniChar);
 }
 
 static gchar*
 getTextBeforeOffsetCB(AtkText *aText, gint aOffset,
                       AtkTextBoundary aBoundaryType,
                       gint *aStartOffset, gint *aEndOffset)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aText));