bug 1155829 - move AccessibleWrap::GetMaiHyperlink to MaiAtkObject::GetAtkHyperlink r=surkov
authorTrevor Saunders <tbsaunde@tbsaunde.org>
Fri, 17 Apr 2015 15:21:36 -0400
changeset 259169 2cea659eaa02c8e39c9187c7835875860f3450a5
parent 259168 a7a57e6ee03623c37b4f926c12c3fbdda34a93a6
child 259170 b0b7eb86d1158d53cab2f20a73963f72bae51053
push id8007
push userraliiev@mozilla.com
push dateMon, 11 May 2015 19:23:16 +0000
treeherdermozilla-aurora@e2ce1aac996e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssurkov
bugs1155829
milestone40.0a1
bug 1155829 - move AccessibleWrap::GetMaiHyperlink to MaiAtkObject::GetAtkHyperlink r=surkov
accessible/atk/AccessibleWrap.cpp
accessible/atk/AccessibleWrap.h
accessible/atk/nsMai.h
accessible/atk/nsMaiInterfaceHyperlinkImpl.cpp
accessible/atk/nsMaiInterfaceHypertext.cpp
--- a/accessible/atk/AccessibleWrap.cpp
+++ b/accessible/atk/AccessibleWrap.cpp
@@ -124,16 +124,30 @@ static const GInterfaceInfo atk_if_infos
 };
 
 // This is or'd with the pointer in MaiAtkObject::accWrap if the wrap-ee is a
 // proxy.
 static const uintptr_t IS_PROXY = 1;
 
 static GQuark quark_mai_hyperlink = 0;
 
+AtkHyperlink*
+MaiAtkObject::GetAtkHyperlink()
+{
+  NS_ASSERTION(quark_mai_hyperlink, "quark_mai_hyperlink not initialized");
+  MaiHyperlink* maiHyperlink =
+    (MaiHyperlink*)g_object_get_qdata(G_OBJECT(this), quark_mai_hyperlink);
+  if (!maiHyperlink) {
+    maiHyperlink = new MaiHyperlink(reinterpret_cast<Accessible*>(accWrap));
+    g_object_set_qdata(G_OBJECT(this), quark_mai_hyperlink, maiHyperlink);
+  }
+
+  return maiHyperlink->GetAtkHyperlink();
+}
+
 void
 MaiAtkObject::Shutdown()
 {
   accWrap = 0;
   MaiHyperlink* maiHyperlink =
     (MaiHyperlink*)g_object_get_qdata(G_OBJECT(this), quark_mai_hyperlink);
   if (maiHyperlink) {
     delete maiHyperlink;
@@ -262,37 +276,16 @@ AccessibleWrap::ShutdownAtkObject()
 
 void
 AccessibleWrap::Shutdown()
 {
   ShutdownAtkObject();
   Accessible::Shutdown();
 }
 
-MaiHyperlink*
-AccessibleWrap::GetMaiHyperlink(bool aCreate /* = true */)
-{
-    // make sure mAtkObject is created
-    GetAtkObject();
-
-    NS_ASSERTION(quark_mai_hyperlink, "quark_mai_hyperlink not initialized");
-    NS_ASSERTION(IS_MAI_OBJECT(mAtkObject), "Invalid AtkObject");
-    MaiHyperlink* maiHyperlink = nullptr;
-    if (quark_mai_hyperlink && IS_MAI_OBJECT(mAtkObject)) {
-        maiHyperlink = (MaiHyperlink*)g_object_get_qdata(G_OBJECT(mAtkObject),
-                                                         quark_mai_hyperlink);
-        if (!maiHyperlink && aCreate) {
-            maiHyperlink = new MaiHyperlink(this);
-            g_object_set_qdata(G_OBJECT(mAtkObject), quark_mai_hyperlink,
-                               maiHyperlink);
-        }
-    }
-    return maiHyperlink;
-}
-
 void
 AccessibleWrap::GetNativeInterface(void** aOutAccessible)
 {
   *aOutAccessible = nullptr;
 
   if (!mAtkObject) {
     if (IsDefunct() || !nsAccUtils::IsEmbeddedObject(this)) {
       // We don't create ATK objects for node which has been shutdown or
--- a/accessible/atk/AccessibleWrap.h
+++ b/accessible/atk/AccessibleWrap.h
@@ -58,19 +58,16 @@ public:
   virtual void GetNativeInterface(void** aOutAccessible) override;
   virtual nsresult HandleAccEvent(AccEvent* aEvent) override;
 
   AtkObject * GetAtkObject(void);
   static AtkObject* GetAtkObject(Accessible* aAccessible);
 
   bool IsValidObject();
 
-  // get the MaiHyperlink object for this AccessibleWrap
-  MaiHyperlink* GetMaiHyperlink(bool aCreate = true);
-
   static const char * ReturnString(nsAString &aString) {
     static nsCString returnedString;
     returnedString = NS_ConvertUTF16toUTF8(aString);
     return returnedString.get();
   }
 
 protected:
 
--- a/accessible/atk/nsMai.h
+++ b/accessible/atk/nsMai.h
@@ -59,14 +59,19 @@ struct MaiAtkObject
   AtkObject parent;
   /*
    * The AccessibleWrap whose properties and features are exported
    * via this object instance.
    */
   uintptr_t accWrap;
 
   /*
+   * Get the AtkHyperlink for this atk object.
+   */
+  AtkHyperlink* GetAtkHyperlink();
+
+  /*
    * Shutdown this AtkObject.
    */
   void Shutdown();
 };
 
 #endif /* __NS_MAI_H__ */
--- a/accessible/atk/nsMaiInterfaceHyperlinkImpl.cpp
+++ b/accessible/atk/nsMaiInterfaceHyperlinkImpl.cpp
@@ -16,19 +16,17 @@ static AtkHyperlink*
 getHyperlinkCB(AtkHyperlinkImpl* aImpl)
 {
   AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aImpl));
   if (!accWrap)
     return nullptr;
 
   NS_ENSURE_TRUE(accWrap->IsLink(), nullptr);
 
-  MaiHyperlink* maiHyperlink = accWrap->GetMaiHyperlink();
-  NS_ENSURE_TRUE(maiHyperlink, nullptr);
-  return maiHyperlink->GetAtkHyperlink();
+  return MAI_ATK_OBJECT(aImpl)->GetAtkHyperlink();
 }
 }
 
 void
 hyperlinkImplInterfaceInitCB(AtkHyperlinkImplIface *aIface)
 {
   NS_ASSERTION(aIface, "no interface!");
   if (MOZ_UNLIKELY(!aIface))
--- a/accessible/atk/nsMaiInterfaceHypertext.cpp
+++ b/accessible/atk/nsMaiInterfaceHypertext.cpp
@@ -27,22 +27,19 @@ getLinkCB(AtkHypertext *aText, gint aLin
     NS_ENSURE_TRUE(hyperText, nullptr);
 
     Accessible* hyperLink = hyperText->LinkAt(aLinkIndex);
     if (!hyperLink) {
       return nullptr;
     }
 
     AtkObject* hyperLinkAtkObj = AccessibleWrap::GetAtkObject(hyperLink);
-    AccessibleWrap* accChild = GetAccessibleWrap(hyperLinkAtkObj);
-    NS_ENSURE_TRUE(accChild, nullptr);
+    NS_ENSURE_TRUE(IS_MAI_OBJECT(hyperLinkAtkObj), nullptr);
 
-    MaiHyperlink* maiHyperlink = accChild->GetMaiHyperlink();
-    NS_ENSURE_TRUE(maiHyperlink, nullptr);
-    return maiHyperlink->GetAtkHyperlink();
+    return MAI_ATK_OBJECT(hyperLinkAtkObj)->GetAtkHyperlink();
   }
 
   if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aText))) {
     ProxyAccessible* proxyLink = proxy->LinkAt(aLinkIndex);
     if (proxyLink) {
       NS_WARNING("IMPLEMENT ME! See bug 1146518.");
       // We should somehow get from ProxyAccessible* to AtkHyperlink*.
     }