LCOV - code coverage report
Current view: top level - accessible/atk - nsMaiInterfaceDocument.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 0 68 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 5 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2             : /* vim: set ts=2 et sw=2 tw=80: */
       3             : /* This Source Code Form is subject to the terms of the Mozilla Public
       4             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       5             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       6             : 
       7             : #include "InterfaceInitFuncs.h"
       8             : 
       9             : #include "Accessible-inl.h"
      10             : #include "AccessibleWrap.h"
      11             : #include "DocAccessible.h"
      12             : #include "nsMai.h"
      13             : #include "ProxyAccessible.h"
      14             : #include "mozilla/Likely.h"
      15             : 
      16             : using namespace mozilla::a11y;
      17             : 
      18             : static const char* const kDocTypeName = "W3C-doctype";
      19             : static const char* const kDocUrlName = "DocURL";
      20             : static const char* const kMimeTypeName = "MimeType";
      21             : 
      22             : // below functions are vfuncs on an ATK  interface so they need to be C call
      23             : extern "C" {
      24             : 
      25             : static const gchar* getDocumentLocaleCB(AtkDocument* aDocument);
      26             : static AtkAttributeSet* getDocumentAttributesCB(AtkDocument* aDocument);
      27             : static const gchar* getDocumentAttributeValueCB(AtkDocument* aDocument,
      28             :                                                 const gchar* aAttrName);
      29             : 
      30             : void
      31           0 : documentInterfaceInitCB(AtkDocumentIface *aIface)
      32             : {
      33           0 :     NS_ASSERTION(aIface, "Invalid Interface");
      34           0 :     if(MOZ_UNLIKELY(!aIface))
      35           0 :         return;
      36             : 
      37             :     /*
      38             :      * We don't support get_document or set_attribute right now.
      39             :      * get_document_type is deprecated, we return DocType in
      40             :      * get_document_attribute_value and get_document_attributes instead.
      41             :      */
      42           0 :     aIface->get_document_attributes = getDocumentAttributesCB;
      43           0 :     aIface->get_document_attribute_value = getDocumentAttributeValueCB;
      44           0 :     aIface->get_document_locale = getDocumentLocaleCB;
      45             : }
      46             : 
      47             : const gchar *
      48           0 : getDocumentLocaleCB(AtkDocument *aDocument)
      49             : {
      50           0 :   nsAutoString locale;
      51           0 :   AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aDocument));
      52           0 :   if (accWrap) {
      53           0 :     accWrap->Language(locale);
      54           0 :   } else if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aDocument))) {
      55           0 :     proxy->Language(locale);
      56             :   }
      57             : 
      58           0 :   return locale.IsEmpty() ? nullptr : AccessibleWrap::ReturnString(locale);
      59             : }
      60             : 
      61             : static inline GSList *
      62           0 : prependToList(GSList *aList, const char *const aName, const nsAutoString &aValue)
      63             : {
      64           0 :   if (aValue.IsEmpty()) {
      65           0 :     return aList;
      66             :   }
      67             : 
      68             :   // libspi will free these
      69           0 :   AtkAttribute *atkAttr = (AtkAttribute *)g_malloc(sizeof(AtkAttribute));
      70           0 :   atkAttr->name = g_strdup(aName);
      71           0 :   atkAttr->value = g_strdup(NS_ConvertUTF16toUTF8(aValue).get());
      72           0 :   return g_slist_prepend(aList, atkAttr);
      73             : }
      74             : 
      75             : AtkAttributeSet *
      76           0 : getDocumentAttributesCB(AtkDocument *aDocument)
      77             : {
      78           0 :   nsAutoString url;
      79           0 :   nsAutoString w3cDocType;
      80           0 :   nsAutoString mimeType;
      81           0 :   AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aDocument));
      82           0 :   if (accWrap) {
      83           0 :     if (!accWrap->IsDoc()) {
      84           0 :       return nullptr;
      85             :     }
      86             : 
      87           0 :     DocAccessible* document = accWrap->AsDoc();
      88           0 :     document->URL(url);
      89           0 :     document->DocType(w3cDocType);
      90           0 :     document->MimeType(mimeType);
      91           0 :   } else if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aDocument))) {
      92           0 :     proxy->URLDocTypeMimeType(url, w3cDocType, mimeType);
      93             :   } else {
      94           0 :     return nullptr;
      95             :   }
      96             : 
      97             :   // according to atkobject.h, AtkAttributeSet is a GSList
      98           0 :   GSList* attributes = nullptr;
      99           0 :   attributes = prependToList(attributes, kDocUrlName, url);
     100           0 :   attributes = prependToList(attributes, kDocTypeName, w3cDocType);
     101           0 :   attributes = prependToList(attributes, kMimeTypeName, mimeType);
     102             : 
     103           0 :   return attributes;
     104             : }
     105             : 
     106             : const gchar *
     107           0 : getDocumentAttributeValueCB(AtkDocument *aDocument,
     108             :                             const gchar *aAttrName)
     109             : {
     110           0 :   ProxyAccessible* proxy = nullptr;
     111           0 :   DocAccessible* document = nullptr;
     112           0 :   AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aDocument));
     113           0 :   if (accWrap) {
     114           0 :     if (!accWrap->IsDoc()) {
     115           0 :       return nullptr;
     116             :     }
     117             : 
     118           0 :     document = accWrap->AsDoc();
     119             :   } else {
     120           0 :     proxy = GetProxy(ATK_OBJECT(aDocument));
     121           0 :     if (!proxy) {
     122           0 :       return nullptr;
     123             :     }
     124             :   }
     125             : 
     126           0 :   nsAutoString attrValue;
     127           0 :   if (!strcasecmp(aAttrName, kDocTypeName)) {
     128           0 :     if (document) {
     129           0 :       document->DocType(attrValue);
     130             :     } else {
     131           0 :       proxy->DocType(attrValue);
     132             :     }
     133           0 :   } else if (!strcasecmp(aAttrName, kDocUrlName)) {
     134           0 :     if (document) {
     135           0 :       document->URL(attrValue);
     136             :     } else {
     137           0 :       proxy->URL(attrValue);
     138             :     }
     139           0 :   } else if (!strcasecmp(aAttrName, kMimeTypeName)) {
     140           0 :     if (document) {
     141           0 :       document->MimeType(attrValue);
     142             :     } else {
     143           0 :       proxy->MimeType(attrValue);
     144             :     }
     145             :   } else {
     146           0 :     return nullptr;
     147             :   }
     148             : 
     149           0 :   return attrValue.IsEmpty() ? nullptr : AccessibleWrap::ReturnString(attrValue);
     150             : }
     151             : }

Generated by: LCOV version 1.13