bug 783372 - use HyperTextAccessible directly in nsMaiInterface{,Editable}Text r=surkov
authorTrevor Saunders <trev.saunders@gmail.com>
Thu, 16 Aug 2012 16:57:31 -0400
changeset 108163 15cc8994c2be885c4adf3307bbdaef6e3f3b4b8f
parent 108162 3dfca392c32b0357f6a65329decd3abc5528395c
child 108164 b9721197c2211052051b7d38f0a0c9840330b629
push id23539
push userryanvm@gmail.com
push dateWed, 26 Sep 2012 22:55:55 +0000
treeherderautoland@ec079fd92224 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssurkov
bugs783372
milestone18.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 783372 - use HyperTextAccessible directly in nsMaiInterface{,Editable}Text r=surkov
accessible/src/atk/nsMaiInterfaceEditableText.cpp
accessible/src/atk/nsMaiInterfaceText.cpp
--- a/accessible/src/atk/nsMaiInterfaceEditableText.cpp
+++ b/accessible/src/atk/nsMaiInterfaceEditableText.cpp
@@ -7,163 +7,122 @@
 #include "InterfaceInitFuncs.h"
 
 #include "HyperTextAccessible.h"
 #include "nsMai.h"
 
 #include "nsString.h"
 
 extern "C" {
-
-static gboolean
-setRunAttributesCB(AtkEditableText *aText, AtkAttributeSet *aAttribSet,
-                   gint aStartOffset, gint aEndOffset)
-{
-  AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
-  if (!accWrap)
-    return FALSE;
-
-    nsCOMPtr<nsIAccessibleEditableText> accText;
-    accWrap->QueryInterface(NS_GET_IID(nsIAccessibleEditableText),
-                            getter_AddRefs(accText));
-    NS_ENSURE_TRUE(accText, FALSE);
-
-    nsCOMPtr<nsISupports> attrSet;
-    /* how to insert attributes into nsISupports ??? */
-
-    nsresult rv = accText->SetAttributes(aStartOffset, aEndOffset,
-                                         attrSet);
-    return NS_FAILED(rv) ? FALSE : TRUE;
-}
-
 static void
 setTextContentsCB(AtkEditableText *aText, const gchar *aString)
 {
   AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
   if (!accWrap)
     return;
 
-    nsCOMPtr<nsIAccessibleEditableText> accText;
-    accWrap->QueryInterface(NS_GET_IID(nsIAccessibleEditableText),
-                            getter_AddRefs(accText));
-    if (!accText)
-        return;
+  HyperTextAccessible* text = accWrap->AsHyperText();
+  if (!text || !text->IsTextRole())
+    return;
 
-    MAI_LOG_DEBUG(("EditableText: setTextContentsCB, aString=%s", aString));
+  MAI_LOG_DEBUG(("EditableText: setTextContentsCB, aString=%s", aString));
 
-    NS_ConvertUTF8toUTF16 strContent(aString);
-    accText->SetTextContents(strContent);
+  NS_ConvertUTF8toUTF16 strContent(aString);
+  text->SetTextContents(strContent);
 }
 
 static void
 insertTextCB(AtkEditableText *aText,
              const gchar *aString, gint aLength, gint *aPosition)
 {
   AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
   if (!accWrap)
     return;
 
-    nsCOMPtr<nsIAccessibleEditableText> accText;
-    accWrap->QueryInterface(NS_GET_IID(nsIAccessibleEditableText),
-                            getter_AddRefs(accText));
-    if (!accText)
-        return;
-
-    NS_ConvertUTF8toUTF16 strContent(aString, aLength);
+  HyperTextAccessible* text = accWrap->AsHyperText();
+  if (!text || !text->IsTextRole())
+    return;
 
-    // interface changed in nsIAccessibleEditableText.idl ???
-    //
-    // int32_t pos = *aPosition;
-    // nsresult rv = accText->InsertText(strContent, aLength, &pos);
-    // *aPosition = pos;
+  NS_ConvertUTF8toUTF16 strContent(aString, aLength);
+  text->InsertText(strContent, *aPosition);
 
-    accText->InsertText(strContent, *aPosition);
-
-    MAI_LOG_DEBUG(("EditableText: insert aString=%s, aLength=%d, aPosition=%d",
-                   aString, aLength, *aPosition));
+  MAI_LOG_DEBUG(("EditableText: insert aString=%s, aLength=%d, aPosition=%d",
+                 aString, aLength, *aPosition));
 }
 
 static void
 copyTextCB(AtkEditableText *aText, gint aStartPos, gint aEndPos)
 {
   AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
   if (!accWrap)
     return;
 
-    nsCOMPtr<nsIAccessibleEditableText> accText;
-    accWrap->QueryInterface(NS_GET_IID(nsIAccessibleEditableText),
-                            getter_AddRefs(accText));
-    if (!accText)
-        return;
+  HyperTextAccessible* text = accWrap->AsHyperText();
+  if (!text || !text->IsTextRole())
+    return;
 
-    MAI_LOG_DEBUG(("EditableText: copyTextCB, aStartPos=%d, aEndPos=%d",
-                   aStartPos, aEndPos));
-    accText->CopyText(aStartPos, aEndPos);
+  MAI_LOG_DEBUG(("EditableText: copyTextCB, aStartPos=%d, aEndPos=%d",
+                 aStartPos, aEndPos));
+  text->CopyText(aStartPos, aEndPos);
 }
 
 static void
 cutTextCB(AtkEditableText *aText, gint aStartPos, gint aEndPos)
 {
   AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
   if (!accWrap)
     return;
 
-    nsCOMPtr<nsIAccessibleEditableText> accText;
-    accWrap->QueryInterface(NS_GET_IID(nsIAccessibleEditableText),
-                            getter_AddRefs(accText));
-    if (!accText)
-        return;
-    MAI_LOG_DEBUG(("EditableText: cutTextCB, aStartPos=%d, aEndPos=%d",
-                   aStartPos, aEndPos));
-    accText->CutText(aStartPos, aEndPos);
+  HyperTextAccessible* text = accWrap->AsHyperText();
+  if (!text || !text->IsTextRole())
+    return;
+
+  MAI_LOG_DEBUG(("EditableText: cutTextCB, aStartPos=%d, aEndPos=%d",
+                 aStartPos, aEndPos));
+  text->CutText(aStartPos, aEndPos);
 }
 
 static void
 deleteTextCB(AtkEditableText *aText, gint aStartPos, gint aEndPos)
 {
   AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
   if (!accWrap)
     return;
 
-    nsCOMPtr<nsIAccessibleEditableText> accText;
-    accWrap->QueryInterface(NS_GET_IID(nsIAccessibleEditableText),
-                            getter_AddRefs(accText));
-    if (!accText)
-        return;
+  HyperTextAccessible* text = accWrap->AsHyperText();
+  if (!text || !text->IsTextRole())
+    return;
 
-    MAI_LOG_DEBUG(("EditableText: deleteTextCB, aStartPos=%d, aEndPos=%d",
-                   aStartPos, aEndPos));
-    accText->DeleteText(aStartPos, aEndPos);
+  MAI_LOG_DEBUG(("EditableText: deleteTextCB, aStartPos=%d, aEndPos=%d",
+                 aStartPos, aEndPos));
+  text->DeleteText(aStartPos, aEndPos);
 }
 
 static void
 pasteTextCB(AtkEditableText *aText, gint aPosition)
 {
   AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
   if (!accWrap)
     return;
 
-    nsCOMPtr<nsIAccessibleEditableText> accText;
-    accWrap->QueryInterface(NS_GET_IID(nsIAccessibleEditableText),
-                            getter_AddRefs(accText));
-    if (!accText)
-        return;
+  HyperTextAccessible* text = accWrap->AsHyperText();
+  if (!text || !text->IsTextRole())
+    return;
 
-    MAI_LOG_DEBUG(("EditableText: pasteTextCB, aPosition=%d", aPosition));
-    accText->PasteText(aPosition);
+  MAI_LOG_DEBUG(("EditableText: pasteTextCB, aPosition=%d", aPosition));
+  text->PasteText(aPosition);
 }
 }
 
 void
 editableTextInterfaceInitCB(AtkEditableTextIface* aIface)
 {
   NS_ASSERTION(aIface, "Invalid aIface");
   if (NS_UNLIKELY(!aIface))
     return;
 
-  aIface->set_run_attributes = setRunAttributesCB;
   aIface->set_text_contents = setTextContentsCB;
   aIface->insert_text = insertTextCB;
   aIface->copy_text = copyTextCB;
   aIface->cut_text = cutTextCB;
   aIface->delete_text = deleteTextCB;
   aIface->paste_text = pasteTextCB;
 }
--- a/accessible/src/atk/nsMaiInterfaceText.cpp
+++ b/accessible/src/atk/nsMaiInterfaceText.cpp
@@ -29,23 +29,22 @@ extern "C" {
 
 static gchar*
 getTextCB(AtkText *aText, gint aStartOffset, gint aEndOffset)
 {
   AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
   if (!accWrap)
     return nullptr;
 
-    nsCOMPtr<nsIAccessibleText> accText;
-    accWrap->QueryInterface(NS_GET_IID(nsIAccessibleText),
-                            getter_AddRefs(accText));
-    NS_ENSURE_TRUE(accText, nullptr);
+  HyperTextAccessible* text = accWrap->AsHyperText();
+  if (!text || !text->IsTextRole())
+    return nullptr;
 
     nsAutoString autoStr;
-    nsresult rv = accText->GetText(aStartOffset, aEndOffset, autoStr);
+    nsresult rv = text->GetText(aStartOffset, aEndOffset, autoStr);
     NS_ENSURE_SUCCESS(rv, nullptr);
 
     ConvertTexttoAsterisks(accWrap, autoStr);
     NS_ConvertUTF16toUTF8 cautoStr(autoStr);
 
     //copy and return, libspi will free it.
     return (cautoStr.get()) ? g_strdup(cautoStr.get()) : nullptr;
 }
@@ -54,55 +53,54 @@ static gchar*
 getTextAfterOffsetCB(AtkText *aText, gint aOffset,
                      AtkTextBoundary aBoundaryType,
                      gint *aStartOffset, gint *aEndOffset)
 {
   AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
   if (!accWrap)
     return nullptr;
 
-    nsCOMPtr<nsIAccessibleText> accText;
-    accWrap->QueryInterface(NS_GET_IID(nsIAccessibleText),
-                            getter_AddRefs(accText));
-    NS_ENSURE_TRUE(accText, nullptr);
+  HyperTextAccessible* text = accWrap->AsHyperText();
+  if (!text || !text->IsTextRole())
+    return nullptr;
 
-    nsAutoString autoStr;
-    int32_t startOffset = 0, endOffset = 0;
-    nsresult rv =
-        accText->GetTextAfterOffset(aOffset, aBoundaryType,
-                                    &startOffset, &endOffset, autoStr);
-    *aStartOffset = startOffset;
-    *aEndOffset = endOffset;
+  nsAutoString autoStr;
+  int32_t startOffset = 0, endOffset = 0;
+  nsresult rv =
+    text->GetTextAfterOffset(aOffset, aBoundaryType,
+                             &startOffset, &endOffset, autoStr);
 
-    NS_ENSURE_SUCCESS(rv, nullptr);
+  *aStartOffset = startOffset;
+  *aEndOffset = endOffset;
+
+  NS_ENSURE_SUCCESS(rv, nullptr);
 
     ConvertTexttoAsterisks(accWrap, autoStr);
     NS_ConvertUTF16toUTF8 cautoStr(autoStr);
     return (cautoStr.get()) ? g_strdup(cautoStr.get()) : nullptr;
 }
 
 static gchar*
 getTextAtOffsetCB(AtkText *aText, gint aOffset,
                   AtkTextBoundary aBoundaryType,
                   gint *aStartOffset, gint *aEndOffset)
 {
   AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
   if (!accWrap)
     return nullptr;
 
-    nsCOMPtr<nsIAccessibleText> accText;
-    accWrap->QueryInterface(NS_GET_IID(nsIAccessibleText),
-                            getter_AddRefs(accText));
-    NS_ENSURE_TRUE(accText, nullptr);
+  HyperTextAccessible* text = accWrap->AsHyperText();
+  if (!text || !text->IsTextRole())
+    return nullptr;
 
     nsAutoString autoStr;
     int32_t startOffset = 0, endOffset = 0;
     nsresult rv =
-        accText->GetTextAtOffset(aOffset, aBoundaryType,
-                                 &startOffset, &endOffset, autoStr);
+        text->GetTextAtOffset(aOffset, aBoundaryType,
+                              &startOffset, &endOffset, autoStr);
     *aStartOffset = startOffset;
     *aEndOffset = endOffset;
 
     NS_ENSURE_SUCCESS(rv, nullptr);
 
     ConvertTexttoAsterisks(accWrap, autoStr);
     NS_ConvertUTF16toUTF8 cautoStr(autoStr);
     return (cautoStr.get()) ? g_strdup(cautoStr.get()) : nullptr;
@@ -110,25 +108,24 @@ getTextAtOffsetCB(AtkText *aText, gint a
 
 static gunichar
 getCharacterAtOffsetCB(AtkText* aText, gint aOffset)
 {
   AccessibleWrap* 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);
+  HyperTextAccessible* text = accWrap->AsHyperText();
+  if (!text || !text->IsTextRole())
+    return 0;
 
   // PRUnichar is unsigned short in Mozilla
   // gnuichar is guint32 in glib
   PRUnichar uniChar = 0;
-  nsresult rv = accText->GetCharacterAtOffset(aOffset, &uniChar);
+  nsresult rv = text->GetCharacterAtOffset(aOffset, &uniChar);
   if (NS_FAILED(rv))
     return 0;
 
   // Convert char to "*" when it's "password text".
   if (accWrap->NativeRole() == roles::PASSWORD_TEXT)
     uniChar = '*';
 
   return static_cast<gunichar>(uniChar);
@@ -138,26 +135,25 @@ static gchar*
 getTextBeforeOffsetCB(AtkText *aText, gint aOffset,
                       AtkTextBoundary aBoundaryType,
                       gint *aStartOffset, gint *aEndOffset)
 {
   AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
   if (!accWrap)
     return nullptr;
 
-    nsCOMPtr<nsIAccessibleText> accText;
-    accWrap->QueryInterface(NS_GET_IID(nsIAccessibleText),
-                            getter_AddRefs(accText));
-    NS_ENSURE_TRUE(accText, nullptr);
+  HyperTextAccessible* text = accWrap->AsHyperText();
+  if (!text || !text->IsTextRole())
+    return nullptr;
 
     nsAutoString autoStr;
     int32_t startOffset = 0, endOffset = 0;
     nsresult rv =
-        accText->GetTextBeforeOffset(aOffset, aBoundaryType,
-                                     &startOffset, &endOffset, autoStr);
+        text->GetTextBeforeOffset(aOffset, aBoundaryType,
+                                  &startOffset, &endOffset, autoStr);
     *aStartOffset = startOffset;
     *aEndOffset = endOffset;
 
     NS_ENSURE_SUCCESS(rv, nullptr);
 
     ConvertTexttoAsterisks(accWrap, autoStr);
     NS_ConvertUTF16toUTF8 cautoStr(autoStr);
     return (cautoStr.get()) ? g_strdup(cautoStr.get()) : nullptr;
@@ -165,145 +161,138 @@ getTextBeforeOffsetCB(AtkText *aText, gi
 
 static gint
 getCaretOffsetCB(AtkText *aText)
 {
   AccessibleWrap* 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);
+  HyperTextAccessible* text = accWrap->AsHyperText();
+  if (!text || !text->IsTextRole())
+    return 0;
 
     int32_t offset;
-    nsresult rv = accText->GetCaretOffset(&offset);
+    nsresult rv = text->GetCaretOffset(&offset);
     return (NS_FAILED(rv)) ? 0 : static_cast<gint>(offset);
 }
 
 static AtkAttributeSet*
 getRunAttributesCB(AtkText *aText, gint aOffset,
                    gint *aStartOffset,
                    gint *aEndOffset)
 {
   *aStartOffset = -1;
   *aEndOffset = -1;
 
   AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
   if (!accWrap)
     return nullptr;
 
-    nsCOMPtr<nsIAccessibleText> accText;
-    accWrap->QueryInterface(NS_GET_IID(nsIAccessibleText),
-                            getter_AddRefs(accText));
-    NS_ENSURE_TRUE(accText, nullptr);
+  HyperTextAccessible* text = accWrap->AsHyperText();
+  if (!text || !text->IsTextRole())
+    return nullptr;
 
     nsCOMPtr<nsIPersistentProperties> attributes;
     int32_t startOffset = 0, endOffset = 0;
-    nsresult rv = accText->GetTextAttributes(false, aOffset,
-                                             &startOffset, &endOffset,
-                                             getter_AddRefs(attributes));
+    nsresult rv = text->GetTextAttributes(false, aOffset,
+                                          &startOffset, &endOffset,
+                                          getter_AddRefs(attributes));
     NS_ENSURE_SUCCESS(rv, nullptr);
 
     *aStartOffset = startOffset;
     *aEndOffset = endOffset;
 
     return ConvertToAtkAttributeSet(attributes);
 }
 
 static AtkAttributeSet*
 getDefaultAttributesCB(AtkText *aText)
 {
   AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
   if (!accWrap)
     return nullptr;
 
-    nsCOMPtr<nsIAccessibleText> accText;
-    accWrap->QueryInterface(NS_GET_IID(nsIAccessibleText),
-                            getter_AddRefs(accText));
-    NS_ENSURE_TRUE(accText, nullptr);
+  HyperTextAccessible* text = accWrap->AsHyperText();
+  if (!text || !text->IsTextRole())
+    return nullptr;
 
     nsCOMPtr<nsIPersistentProperties> attributes;
-    nsresult rv = accText->GetDefaultTextAttributes(getter_AddRefs(attributes));
+    nsresult rv = text->GetDefaultTextAttributes(getter_AddRefs(attributes));
     if (NS_FAILED(rv))
         return nullptr;
 
     return ConvertToAtkAttributeSet(attributes);
 }
 
 static void
 getCharacterExtentsCB(AtkText *aText, gint aOffset,
                       gint *aX, gint *aY,
                       gint *aWidth, gint *aHeight,
                       AtkCoordType aCoords)
 {
   AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
   if(!accWrap || !aX || !aY || !aWidth || !aHeight)
     return;
 
-    nsCOMPtr<nsIAccessibleText> accText;
-    accWrap->QueryInterface(NS_GET_IID(nsIAccessibleText),
-                            getter_AddRefs(accText));
-    if (!accText)
-        return;
+  HyperTextAccessible* text = accWrap->AsHyperText();
+  if (!text || !text->IsTextRole())
+    return;
 
     int32_t extY = 0, extX = 0;
     int32_t extWidth = 0, extHeight = 0;
 
     uint32_t geckoCoordType;
     if (aCoords == ATK_XY_SCREEN)
         geckoCoordType = nsIAccessibleCoordinateType::COORDTYPE_SCREEN_RELATIVE;
     else
         geckoCoordType = nsIAccessibleCoordinateType::COORDTYPE_WINDOW_RELATIVE;
 
 #ifdef DEBUG
     nsresult rv =
 #endif
-    accText->GetCharacterExtents(aOffset, &extX, &extY,
-                                 &extWidth, &extHeight,
-                                 geckoCoordType);
+    text->GetCharacterExtents(aOffset, &extX, &extY,
+                              &extWidth, &extHeight,
+                              geckoCoordType);
     *aX = extX;
     *aY = extY;
     *aWidth = extWidth;
     *aHeight = extHeight;
     NS_ASSERTION(NS_SUCCEEDED(rv),
                  "MaiInterfaceText::GetCharacterExtents, failed\n");
 }
 
 static void
 getRangeExtentsCB(AtkText *aText, gint aStartOffset, gint aEndOffset,
                   AtkCoordType aCoords, AtkTextRectangle *aRect)
 {
   AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
   if(!accWrap || !aRect)
     return;
 
-    nsCOMPtr<nsIAccessibleText> accText;
-    accWrap->QueryInterface(NS_GET_IID(nsIAccessibleText),
-                            getter_AddRefs(accText));
-    if (!accText)
-        return;
+  HyperTextAccessible* text = accWrap->AsHyperText();
+  if (!text || !text->IsTextRole())
+    return;
 
     int32_t extY = 0, extX = 0;
     int32_t extWidth = 0, extHeight = 0;
 
     uint32_t geckoCoordType;
     if (aCoords == ATK_XY_SCREEN)
         geckoCoordType = nsIAccessibleCoordinateType::COORDTYPE_SCREEN_RELATIVE;
     else
         geckoCoordType = nsIAccessibleCoordinateType::COORDTYPE_WINDOW_RELATIVE;
 
 #ifdef DEBUG
     nsresult rv =
 #endif
-    accText->GetRangeExtents(aStartOffset, aEndOffset,
-                             &extX, &extY,
-                             &extWidth, &extHeight,
-                             geckoCoordType);
+    text->GetRangeExtents(aStartOffset, aEndOffset,
+                          &extX, &extY,
+                          &extWidth, &extHeight,
+                          geckoCoordType);
     aRect->x = extX;
     aRect->y = extY;
     aRect->width = extWidth;
     aRect->height = extHeight;
     NS_ASSERTION(NS_SUCCEEDED(rv),
                  "MaiInterfaceText::GetRangeExtents, failed\n");
 }
 
@@ -323,66 +312,63 @@ static gint
 getOffsetAtPointCB(AtkText *aText,
                    gint aX, gint aY,
                    AtkCoordType aCoords)
 {
   AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
   if (!accWrap)
     return -1;
 
-    nsCOMPtr<nsIAccessibleText> accText;
-    accWrap->QueryInterface(NS_GET_IID(nsIAccessibleText),
-                            getter_AddRefs(accText));
-    NS_ENSURE_TRUE(accText, -1);
+  HyperTextAccessible* text = accWrap->AsHyperText();
+  if (!text || !text->IsTextRole())
+    return -1;
 
     int32_t offset = 0;
     uint32_t geckoCoordType;
     if (aCoords == ATK_XY_SCREEN)
         geckoCoordType = nsIAccessibleCoordinateType::COORDTYPE_SCREEN_RELATIVE;
     else
         geckoCoordType = nsIAccessibleCoordinateType::COORDTYPE_WINDOW_RELATIVE;
 
-    accText->GetOffsetAtPoint(aX, aY, geckoCoordType, &offset);
+    text->GetOffsetAtPoint(aX, aY, geckoCoordType, &offset);
     return static_cast<gint>(offset);
 }
 
 static gint
 getTextSelectionCountCB(AtkText *aText)
 {
   AccessibleWrap* 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);
+  HyperTextAccessible* text = accWrap->AsHyperText();
+  if (!text || !text->IsTextRole())
+    return 0;
 
     int32_t selectionCount;
-    nsresult rv = accText->GetSelectionCount(&selectionCount);
+    nsresult rv = text->GetSelectionCount(&selectionCount);
  
     return NS_FAILED(rv) ? 0 : selectionCount;
 }
 
 static gchar*
 getTextSelectionCB(AtkText *aText, gint aSelectionNum,
                    gint *aStartOffset, gint *aEndOffset)
 {
   AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
   if (!accWrap)
     return nullptr;
 
-    nsCOMPtr<nsIAccessibleText> accText;
-    accWrap->QueryInterface(NS_GET_IID(nsIAccessibleText),
-                            getter_AddRefs(accText));
-    NS_ENSURE_TRUE(accText, nullptr);
+  HyperTextAccessible* text = accWrap->AsHyperText();
+  if (!text || !text->IsTextRole())
+    return nullptr;
 
     int32_t startOffset = 0, endOffset = 0;
-    nsresult rv = accText->GetSelectionBounds(aSelectionNum,
-                                              &startOffset, &endOffset);
+    nsresult rv = text->GetSelectionBounds(aSelectionNum,
+                                           &startOffset, &endOffset);
 
     *aStartOffset = startOffset;
     *aEndOffset = endOffset;
 
     NS_ENSURE_SUCCESS(rv, nullptr);
 
     return getTextCB(aText, *aStartOffset, *aEndOffset);
 }
@@ -392,75 +378,71 @@ static gboolean
 addTextSelectionCB(AtkText *aText,
                    gint aStartOffset,
                    gint aEndOffset)
 {
   AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
   if (!accWrap)
     return FALSE;
 
-    nsCOMPtr<nsIAccessibleText> accText;
-    accWrap->QueryInterface(NS_GET_IID(nsIAccessibleText),
-                            getter_AddRefs(accText));
-    NS_ENSURE_TRUE(accText, FALSE);
+  HyperTextAccessible* text = accWrap->AsHyperText();
+  if (!text || !text->IsTextRole())
+    return false;
 
-    nsresult rv = accText->AddSelection(aStartOffset, aEndOffset);
+    nsresult rv = text->AddSelection(aStartOffset, aEndOffset);
 
     return NS_SUCCEEDED(rv) ? TRUE : FALSE;
 }
 
 static gboolean
 removeTextSelectionCB(AtkText *aText,
                       gint aSelectionNum)
 {
   AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
   if (!accWrap)
     return FALSE;
 
-    nsCOMPtr<nsIAccessibleText> accText;
-    accWrap->QueryInterface(NS_GET_IID(nsIAccessibleText),
-                            getter_AddRefs(accText));
-    NS_ENSURE_TRUE(accText, FALSE);
+  HyperTextAccessible* text = accWrap->AsHyperText();
+  if (!text || !text->IsTextRole())
+    return false;
 
-    nsresult rv = accText->RemoveSelection(aSelectionNum);
+    nsresult rv = text->RemoveSelection(aSelectionNum);
 
     return NS_SUCCEEDED(rv) ? TRUE : FALSE;
 }
 
 static gboolean
 setTextSelectionCB(AtkText *aText, gint aSelectionNum,
                    gint aStartOffset, gint aEndOffset)
 {
   AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
   if (!accWrap)
     return FALSE;
 
-    nsCOMPtr<nsIAccessibleText> accText;
-    accWrap->QueryInterface(NS_GET_IID(nsIAccessibleText),
-                            getter_AddRefs(accText));
-    NS_ENSURE_TRUE(accText, FALSE);
+  HyperTextAccessible* text = accWrap->AsHyperText();
+  if (!text || !text->IsTextRole())
+    return false;
 
-    nsresult rv = accText->SetSelectionBounds(aSelectionNum,
-                                              aStartOffset, aEndOffset);
+    nsresult rv = text->SetSelectionBounds(aSelectionNum,
+                                           aStartOffset, aEndOffset);
     return NS_SUCCEEDED(rv) ? TRUE : FALSE;
 }
 
 static gboolean
 setCaretOffsetCB(AtkText *aText, gint aOffset)
 {
   AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
   if (!accWrap)
     return FALSE;
 
-    nsCOMPtr<nsIAccessibleText> accText;
-    accWrap->QueryInterface(NS_GET_IID(nsIAccessibleText),
-                            getter_AddRefs(accText));
-    NS_ENSURE_TRUE(accText, FALSE);
+  HyperTextAccessible* text = accWrap->AsHyperText();
+  if (!text || !text->IsTextRole())
+    return false;
 
-    nsresult rv = accText->SetCaretOffset(aOffset);
+    nsresult rv = text->SetCaretOffset(aOffset);
     return NS_SUCCEEDED(rv) ? TRUE : FALSE;
 }
 }
 
 void
 textInterfaceInitCB(AtkTextIface* aIface)
 {
   NS_ASSERTION(aIface, "Invalid aIface");