/src/mozilla-central/accessible/atk/nsMaiInterfaceDocument.cpp
Line | Count | Source (jump to first uncovered line) |
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 | | documentInterfaceInitCB(AtkDocumentIface *aIface) |
32 | 0 | { |
33 | 0 | NS_ASSERTION(aIface, "Invalid Interface"); |
34 | 0 | if(MOZ_UNLIKELY(!aIface)) |
35 | 0 | return; |
36 | 0 | |
37 | 0 | /* |
38 | 0 | * We don't support get_document or set_attribute right now. |
39 | 0 | * get_document_type is deprecated, we return DocType in |
40 | 0 | * get_document_attribute_value and get_document_attributes instead. |
41 | 0 | */ |
42 | 0 | aIface->get_document_attributes = getDocumentAttributesCB; |
43 | 0 | aIface->get_document_attribute_value = getDocumentAttributeValueCB; |
44 | 0 | aIface->get_document_locale = getDocumentLocaleCB; |
45 | 0 | } |
46 | | |
47 | | const gchar * |
48 | | getDocumentLocaleCB(AtkDocument *aDocument) |
49 | 0 | { |
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 | 0 | } |
57 | 0 |
|
58 | 0 | return locale.IsEmpty() ? nullptr : AccessibleWrap::ReturnString(locale); |
59 | 0 | } |
60 | | |
61 | | static inline GSList * |
62 | | prependToList(GSList *aList, const char *const aName, const nsAutoString &aValue) |
63 | 0 | { |
64 | 0 | if (aValue.IsEmpty()) { |
65 | 0 | return aList; |
66 | 0 | } |
67 | 0 | |
68 | 0 | // 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 | 0 | } |
74 | | |
75 | | AtkAttributeSet * |
76 | | getDocumentAttributesCB(AtkDocument *aDocument) |
77 | 0 | { |
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 | 0 | } |
86 | 0 | |
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 | 0 | } else { |
94 | 0 | return nullptr; |
95 | 0 | } |
96 | 0 | |
97 | 0 | // 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 | 0 |
|
103 | 0 | return attributes; |
104 | 0 | } |
105 | | |
106 | | const gchar * |
107 | | getDocumentAttributeValueCB(AtkDocument *aDocument, |
108 | | const gchar *aAttrName) |
109 | 0 | { |
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 | 0 | } |
117 | 0 | |
118 | 0 | document = accWrap->AsDoc(); |
119 | 0 | } else { |
120 | 0 | proxy = GetProxy(ATK_OBJECT(aDocument)); |
121 | 0 | if (!proxy) { |
122 | 0 | return nullptr; |
123 | 0 | } |
124 | 0 | } |
125 | 0 | |
126 | 0 | nsAutoString attrValue; |
127 | 0 | if (!strcasecmp(aAttrName, kDocTypeName)) { |
128 | 0 | if (document) { |
129 | 0 | document->DocType(attrValue); |
130 | 0 | } else { |
131 | 0 | proxy->DocType(attrValue); |
132 | 0 | } |
133 | 0 | } else if (!strcasecmp(aAttrName, kDocUrlName)) { |
134 | 0 | if (document) { |
135 | 0 | document->URL(attrValue); |
136 | 0 | } else { |
137 | 0 | proxy->URL(attrValue); |
138 | 0 | } |
139 | 0 | } else if (!strcasecmp(aAttrName, kMimeTypeName)) { |
140 | 0 | if (document) { |
141 | 0 | document->MimeType(attrValue); |
142 | 0 | } else { |
143 | 0 | proxy->MimeType(attrValue); |
144 | 0 | } |
145 | 0 | } else { |
146 | 0 | return nullptr; |
147 | 0 | } |
148 | 0 | |
149 | 0 | return attrValue.IsEmpty() ? nullptr : AccessibleWrap::ReturnString(attrValue); |
150 | 0 | } |
151 | | } |