Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* vim: set ts=2 et sw=2 tw=80: */ |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | #include "sdnAccessible-inl.h" |
michael@0 | 8 | #include "ISimpleDOMNode_i.c" |
michael@0 | 9 | |
michael@0 | 10 | #include "DocAccessibleWrap.h" |
michael@0 | 11 | |
michael@0 | 12 | #include "nsAttrName.h" |
michael@0 | 13 | #include "nsCoreUtils.h" |
michael@0 | 14 | #include "nsIAccessibleTypes.h" |
michael@0 | 15 | #include "nsIDOMHTMLElement.h" |
michael@0 | 16 | #include "nsIDOMCSSStyleDeclaration.h" |
michael@0 | 17 | #include "nsNameSpaceManager.h" |
michael@0 | 18 | #include "nsServiceManagerUtils.h" |
michael@0 | 19 | #include "nsWinUtils.h" |
michael@0 | 20 | |
michael@0 | 21 | #include "nsAutoPtr.h" |
michael@0 | 22 | |
michael@0 | 23 | #include "mozilla/dom/Element.h" |
michael@0 | 24 | |
michael@0 | 25 | using namespace mozilla; |
michael@0 | 26 | using namespace mozilla::a11y; |
michael@0 | 27 | |
michael@0 | 28 | STDMETHODIMP |
michael@0 | 29 | sdnAccessible::QueryInterface(REFIID aREFIID, void** aInstancePtr) |
michael@0 | 30 | { |
michael@0 | 31 | A11Y_TRYBLOCK_BEGIN |
michael@0 | 32 | |
michael@0 | 33 | if (!aInstancePtr) |
michael@0 | 34 | return E_FAIL; |
michael@0 | 35 | *aInstancePtr = nullptr; |
michael@0 | 36 | |
michael@0 | 37 | if (aREFIID == IID_ISimpleDOMNode) { |
michael@0 | 38 | *aInstancePtr = static_cast<ISimpleDOMNode*>(this); |
michael@0 | 39 | AddRef(); |
michael@0 | 40 | return S_OK; |
michael@0 | 41 | } |
michael@0 | 42 | |
michael@0 | 43 | AccessibleWrap* accessible = static_cast<AccessibleWrap*>(GetAccessible()); |
michael@0 | 44 | if (accessible) |
michael@0 | 45 | return accessible->QueryInterface(aREFIID, aInstancePtr); |
michael@0 | 46 | |
michael@0 | 47 | // IUnknown* is the canonical one if and only if this accessible doesn't have |
michael@0 | 48 | // an accessible. |
michael@0 | 49 | if (aREFIID == IID_IUnknown) { |
michael@0 | 50 | *aInstancePtr = static_cast<ISimpleDOMNode*>(this); |
michael@0 | 51 | AddRef(); |
michael@0 | 52 | return S_OK; |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | return E_NOINTERFACE; |
michael@0 | 56 | |
michael@0 | 57 | A11Y_TRYBLOCK_END |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | STDMETHODIMP |
michael@0 | 61 | sdnAccessible::get_nodeInfo(BSTR __RPC_FAR* aNodeName, |
michael@0 | 62 | short __RPC_FAR* aNameSpaceID, |
michael@0 | 63 | BSTR __RPC_FAR* aNodeValue, |
michael@0 | 64 | unsigned int __RPC_FAR* aNumChildren, |
michael@0 | 65 | unsigned int __RPC_FAR* aUniqueID, |
michael@0 | 66 | unsigned short __RPC_FAR* aNodeType) |
michael@0 | 67 | { |
michael@0 | 68 | A11Y_TRYBLOCK_BEGIN |
michael@0 | 69 | |
michael@0 | 70 | if (!aNodeName || !aNameSpaceID || !aNodeValue || !aNumChildren || |
michael@0 | 71 | !aUniqueID || !aNodeType) |
michael@0 | 72 | return E_INVALIDARG; |
michael@0 | 73 | |
michael@0 | 74 | *aNodeName = nullptr; |
michael@0 | 75 | *aNameSpaceID = 0; |
michael@0 | 76 | *aNodeValue = nullptr; |
michael@0 | 77 | *aNumChildren = 0; |
michael@0 | 78 | *aUniqueID = 0; |
michael@0 | 79 | *aNodeType = 0; |
michael@0 | 80 | |
michael@0 | 81 | if (IsDefunct()) |
michael@0 | 82 | return CO_E_OBJNOTCONNECTED; |
michael@0 | 83 | |
michael@0 | 84 | nsCOMPtr<nsIDOMNode> DOMNode(do_QueryInterface(mNode)); |
michael@0 | 85 | |
michael@0 | 86 | uint16_t nodeType = 0; |
michael@0 | 87 | DOMNode->GetNodeType(&nodeType); |
michael@0 | 88 | *aNodeType = static_cast<unsigned short>(nodeType); |
michael@0 | 89 | |
michael@0 | 90 | if (*aNodeType != NODETYPE_TEXT) { |
michael@0 | 91 | nsAutoString nodeName; |
michael@0 | 92 | DOMNode->GetNodeName(nodeName); |
michael@0 | 93 | *aNodeName = ::SysAllocString(nodeName.get()); |
michael@0 | 94 | } |
michael@0 | 95 | |
michael@0 | 96 | nsAutoString nodeValue; |
michael@0 | 97 | DOMNode->GetNodeValue(nodeValue); |
michael@0 | 98 | *aNodeValue = ::SysAllocString(nodeValue.get()); |
michael@0 | 99 | |
michael@0 | 100 | *aNameSpaceID = mNode->IsNodeOfType(nsINode::eCONTENT) ? |
michael@0 | 101 | static_cast<short>(mNode->AsContent()->GetNameSpaceID()) : 0; |
michael@0 | 102 | |
michael@0 | 103 | // This is a unique ID for every content node. The 3rd party accessibility |
michael@0 | 104 | // application can compare this to the childID we return for events such as |
michael@0 | 105 | // focus events, to correlate back to data nodes in their internal object |
michael@0 | 106 | // model. |
michael@0 | 107 | Accessible* accessible = GetAccessible(); |
michael@0 | 108 | *aUniqueID = - NS_PTR_TO_INT32(accessible ? accessible->UniqueID() : |
michael@0 | 109 | static_cast<void*>(this)); |
michael@0 | 110 | |
michael@0 | 111 | *aNumChildren = mNode->GetChildCount(); |
michael@0 | 112 | |
michael@0 | 113 | return S_OK; |
michael@0 | 114 | |
michael@0 | 115 | A11Y_TRYBLOCK_END |
michael@0 | 116 | } |
michael@0 | 117 | |
michael@0 | 118 | STDMETHODIMP |
michael@0 | 119 | sdnAccessible::get_attributes(unsigned short aMaxAttribs, |
michael@0 | 120 | BSTR __RPC_FAR* aAttribNames, |
michael@0 | 121 | short __RPC_FAR* aNameSpaceIDs, |
michael@0 | 122 | BSTR __RPC_FAR* aAttribValues, |
michael@0 | 123 | unsigned short __RPC_FAR* aNumAttribs) |
michael@0 | 124 | { |
michael@0 | 125 | A11Y_TRYBLOCK_BEGIN |
michael@0 | 126 | |
michael@0 | 127 | if (!aAttribNames || !aNameSpaceIDs || !aAttribValues || !aNumAttribs) |
michael@0 | 128 | return E_INVALIDARG; |
michael@0 | 129 | |
michael@0 | 130 | *aNumAttribs = 0; |
michael@0 | 131 | |
michael@0 | 132 | if (IsDefunct()) |
michael@0 | 133 | return CO_E_OBJNOTCONNECTED; |
michael@0 | 134 | |
michael@0 | 135 | if (!mNode->IsElement()) |
michael@0 | 136 | return S_FALSE; |
michael@0 | 137 | |
michael@0 | 138 | dom::Element* elm = mNode->AsElement(); |
michael@0 | 139 | uint32_t numAttribs = elm->GetAttrCount(); |
michael@0 | 140 | if (numAttribs > aMaxAttribs) |
michael@0 | 141 | numAttribs = aMaxAttribs; |
michael@0 | 142 | |
michael@0 | 143 | *aNumAttribs = static_cast<unsigned short>(numAttribs); |
michael@0 | 144 | |
michael@0 | 145 | for (uint32_t index = 0; index < numAttribs; index++) { |
michael@0 | 146 | aNameSpaceIDs[index] = 0; |
michael@0 | 147 | aAttribValues[index] = aAttribNames[index] = nullptr; |
michael@0 | 148 | nsAutoString attributeValue; |
michael@0 | 149 | |
michael@0 | 150 | const nsAttrName* name = elm->GetAttrNameAt(index); |
michael@0 | 151 | aNameSpaceIDs[index] = static_cast<short>(name->NamespaceID()); |
michael@0 | 152 | aAttribNames[index] = ::SysAllocString(name->LocalName()->GetUTF16String()); |
michael@0 | 153 | elm->GetAttr(name->NamespaceID(), name->LocalName(), attributeValue); |
michael@0 | 154 | aAttribValues[index] = ::SysAllocString(attributeValue.get()); |
michael@0 | 155 | } |
michael@0 | 156 | |
michael@0 | 157 | return S_OK; |
michael@0 | 158 | |
michael@0 | 159 | A11Y_TRYBLOCK_END |
michael@0 | 160 | } |
michael@0 | 161 | |
michael@0 | 162 | STDMETHODIMP |
michael@0 | 163 | sdnAccessible::get_attributesForNames(unsigned short aMaxAttribs, |
michael@0 | 164 | BSTR __RPC_FAR* aAttribNames, |
michael@0 | 165 | short __RPC_FAR* aNameSpaceID, |
michael@0 | 166 | BSTR __RPC_FAR* aAttribValues) |
michael@0 | 167 | { |
michael@0 | 168 | A11Y_TRYBLOCK_BEGIN |
michael@0 | 169 | |
michael@0 | 170 | if (!aAttribNames || !aNameSpaceID || !aAttribValues) |
michael@0 | 171 | return E_INVALIDARG; |
michael@0 | 172 | |
michael@0 | 173 | if (IsDefunct()) |
michael@0 | 174 | return CO_E_OBJNOTCONNECTED; |
michael@0 | 175 | |
michael@0 | 176 | if (!mNode->IsElement()) |
michael@0 | 177 | return S_FALSE; |
michael@0 | 178 | |
michael@0 | 179 | nsCOMPtr<nsIDOMElement> domElement(do_QueryInterface(mNode)); |
michael@0 | 180 | nsNameSpaceManager* nameSpaceManager = nsNameSpaceManager::GetInstance(); |
michael@0 | 181 | |
michael@0 | 182 | int32_t index = 0; |
michael@0 | 183 | for (index = 0; index < aMaxAttribs; index++) { |
michael@0 | 184 | aAttribValues[index] = nullptr; |
michael@0 | 185 | if (aAttribNames[index]) { |
michael@0 | 186 | nsAutoString attributeValue, nameSpaceURI; |
michael@0 | 187 | nsAutoString attributeName(nsDependentString( |
michael@0 | 188 | static_cast<const wchar_t*>(aAttribNames[index]))); |
michael@0 | 189 | |
michael@0 | 190 | nsresult rv = NS_OK; |
michael@0 | 191 | if (aNameSpaceID[index]>0 && |
michael@0 | 192 | NS_SUCCEEDED(nameSpaceManager->GetNameSpaceURI(aNameSpaceID[index], |
michael@0 | 193 | nameSpaceURI))) { |
michael@0 | 194 | rv = domElement->GetAttributeNS(nameSpaceURI, attributeName, |
michael@0 | 195 | attributeValue); |
michael@0 | 196 | } else { |
michael@0 | 197 | rv = domElement->GetAttribute(attributeName, attributeValue); |
michael@0 | 198 | } |
michael@0 | 199 | |
michael@0 | 200 | if (NS_SUCCEEDED(rv)) |
michael@0 | 201 | aAttribValues[index] = ::SysAllocString(attributeValue.get()); |
michael@0 | 202 | } |
michael@0 | 203 | } |
michael@0 | 204 | |
michael@0 | 205 | return S_OK; |
michael@0 | 206 | |
michael@0 | 207 | A11Y_TRYBLOCK_END |
michael@0 | 208 | } |
michael@0 | 209 | |
michael@0 | 210 | STDMETHODIMP |
michael@0 | 211 | sdnAccessible::get_computedStyle(unsigned short aMaxStyleProperties, |
michael@0 | 212 | boolean aUseAlternateView, |
michael@0 | 213 | BSTR __RPC_FAR* aStyleProperties, |
michael@0 | 214 | BSTR __RPC_FAR* aStyleValues, |
michael@0 | 215 | unsigned short __RPC_FAR* aNumStyleProperties) |
michael@0 | 216 | { |
michael@0 | 217 | A11Y_TRYBLOCK_BEGIN |
michael@0 | 218 | |
michael@0 | 219 | if (!aStyleProperties || aStyleValues || !aNumStyleProperties) |
michael@0 | 220 | return E_INVALIDARG; |
michael@0 | 221 | |
michael@0 | 222 | if (IsDefunct()) |
michael@0 | 223 | return CO_E_OBJNOTCONNECTED; |
michael@0 | 224 | |
michael@0 | 225 | *aNumStyleProperties = 0; |
michael@0 | 226 | |
michael@0 | 227 | if (mNode->IsNodeOfType(nsINode::eDOCUMENT)) |
michael@0 | 228 | return S_FALSE; |
michael@0 | 229 | |
michael@0 | 230 | nsCOMPtr<nsIDOMCSSStyleDeclaration> cssDecl = |
michael@0 | 231 | nsWinUtils::GetComputedStyleDeclaration(mNode->AsContent()); |
michael@0 | 232 | NS_ENSURE_TRUE(cssDecl, E_FAIL); |
michael@0 | 233 | |
michael@0 | 234 | uint32_t length = 0; |
michael@0 | 235 | cssDecl->GetLength(&length); |
michael@0 | 236 | |
michael@0 | 237 | uint32_t index = 0, realIndex = 0; |
michael@0 | 238 | for (index = realIndex = 0; index < length && realIndex < aMaxStyleProperties; |
michael@0 | 239 | index ++) { |
michael@0 | 240 | nsAutoString property, value; |
michael@0 | 241 | |
michael@0 | 242 | // Ignore -moz-* properties. |
michael@0 | 243 | if (NS_SUCCEEDED(cssDecl->Item(index, property)) && property.CharAt(0) != '-') |
michael@0 | 244 | cssDecl->GetPropertyValue(property, value); // Get property value |
michael@0 | 245 | |
michael@0 | 246 | if (!value.IsEmpty()) { |
michael@0 | 247 | aStyleProperties[realIndex] = ::SysAllocString(property.get()); |
michael@0 | 248 | aStyleValues[realIndex] = ::SysAllocString(value.get()); |
michael@0 | 249 | ++realIndex; |
michael@0 | 250 | } |
michael@0 | 251 | } |
michael@0 | 252 | |
michael@0 | 253 | *aNumStyleProperties = static_cast<unsigned short>(realIndex); |
michael@0 | 254 | |
michael@0 | 255 | return S_OK; |
michael@0 | 256 | |
michael@0 | 257 | A11Y_TRYBLOCK_END |
michael@0 | 258 | } |
michael@0 | 259 | |
michael@0 | 260 | STDMETHODIMP |
michael@0 | 261 | sdnAccessible::get_computedStyleForProperties(unsigned short aNumStyleProperties, |
michael@0 | 262 | boolean aUseAlternateView, |
michael@0 | 263 | BSTR __RPC_FAR* aStyleProperties, |
michael@0 | 264 | BSTR __RPC_FAR* aStyleValues) |
michael@0 | 265 | { |
michael@0 | 266 | A11Y_TRYBLOCK_BEGIN |
michael@0 | 267 | |
michael@0 | 268 | if (!aStyleProperties || !aStyleValues) |
michael@0 | 269 | return E_INVALIDARG; |
michael@0 | 270 | |
michael@0 | 271 | if (IsDefunct()) |
michael@0 | 272 | return CO_E_OBJNOTCONNECTED; |
michael@0 | 273 | |
michael@0 | 274 | if (mNode->IsNodeOfType(nsINode::eDOCUMENT)) |
michael@0 | 275 | return S_FALSE; |
michael@0 | 276 | |
michael@0 | 277 | nsCOMPtr<nsIDOMCSSStyleDeclaration> cssDecl = |
michael@0 | 278 | nsWinUtils::GetComputedStyleDeclaration(mNode->AsContent()); |
michael@0 | 279 | NS_ENSURE_TRUE(cssDecl, E_FAIL); |
michael@0 | 280 | |
michael@0 | 281 | uint32_t index = 0; |
michael@0 | 282 | for (index = 0; index < aNumStyleProperties; index++) { |
michael@0 | 283 | nsAutoString value; |
michael@0 | 284 | if (aStyleProperties[index]) |
michael@0 | 285 | cssDecl->GetPropertyValue(nsDependentString(aStyleProperties[index]), value); // Get property value |
michael@0 | 286 | aStyleValues[index] = ::SysAllocString(value.get()); |
michael@0 | 287 | } |
michael@0 | 288 | |
michael@0 | 289 | return S_OK; |
michael@0 | 290 | |
michael@0 | 291 | A11Y_TRYBLOCK_END |
michael@0 | 292 | } |
michael@0 | 293 | |
michael@0 | 294 | STDMETHODIMP |
michael@0 | 295 | sdnAccessible::scrollTo(boolean aScrollTopLeft) |
michael@0 | 296 | { |
michael@0 | 297 | A11Y_TRYBLOCK_BEGIN |
michael@0 | 298 | |
michael@0 | 299 | DocAccessible* document = GetDocument(); |
michael@0 | 300 | if (!document) // that's IsDefunct check |
michael@0 | 301 | return CO_E_OBJNOTCONNECTED; |
michael@0 | 302 | |
michael@0 | 303 | if (!mNode->IsContent()) |
michael@0 | 304 | return S_FALSE; |
michael@0 | 305 | |
michael@0 | 306 | uint32_t scrollType = |
michael@0 | 307 | aScrollTopLeft ? nsIAccessibleScrollType::SCROLL_TYPE_TOP_LEFT : |
michael@0 | 308 | nsIAccessibleScrollType::SCROLL_TYPE_BOTTOM_RIGHT; |
michael@0 | 309 | |
michael@0 | 310 | nsCoreUtils::ScrollTo(document->PresShell(), mNode->AsContent(), scrollType); |
michael@0 | 311 | return S_OK; |
michael@0 | 312 | |
michael@0 | 313 | A11Y_TRYBLOCK_END |
michael@0 | 314 | } |
michael@0 | 315 | |
michael@0 | 316 | STDMETHODIMP |
michael@0 | 317 | sdnAccessible::get_parentNode(ISimpleDOMNode __RPC_FAR *__RPC_FAR* aNode) |
michael@0 | 318 | { |
michael@0 | 319 | A11Y_TRYBLOCK_BEGIN |
michael@0 | 320 | |
michael@0 | 321 | if (!aNode) |
michael@0 | 322 | return E_INVALIDARG; |
michael@0 | 323 | *aNode = nullptr; |
michael@0 | 324 | |
michael@0 | 325 | if (IsDefunct()) |
michael@0 | 326 | return CO_E_OBJNOTCONNECTED; |
michael@0 | 327 | |
michael@0 | 328 | nsINode* resultNode = mNode->GetParentNode(); |
michael@0 | 329 | if (resultNode) { |
michael@0 | 330 | *aNode = static_cast<ISimpleDOMNode*>(new sdnAccessible(resultNode)); |
michael@0 | 331 | (*aNode)->AddRef(); |
michael@0 | 332 | } |
michael@0 | 333 | |
michael@0 | 334 | return S_OK; |
michael@0 | 335 | |
michael@0 | 336 | A11Y_TRYBLOCK_END |
michael@0 | 337 | } |
michael@0 | 338 | |
michael@0 | 339 | STDMETHODIMP |
michael@0 | 340 | sdnAccessible::get_firstChild(ISimpleDOMNode __RPC_FAR *__RPC_FAR* aNode) |
michael@0 | 341 | { |
michael@0 | 342 | A11Y_TRYBLOCK_BEGIN |
michael@0 | 343 | |
michael@0 | 344 | if (!aNode) |
michael@0 | 345 | return E_INVALIDARG; |
michael@0 | 346 | *aNode = nullptr; |
michael@0 | 347 | |
michael@0 | 348 | if (IsDefunct()) |
michael@0 | 349 | return CO_E_OBJNOTCONNECTED; |
michael@0 | 350 | |
michael@0 | 351 | nsINode* resultNode = mNode->GetFirstChild(); |
michael@0 | 352 | if (resultNode) { |
michael@0 | 353 | *aNode = static_cast<ISimpleDOMNode*>(new sdnAccessible(resultNode)); |
michael@0 | 354 | (*aNode)->AddRef(); |
michael@0 | 355 | } |
michael@0 | 356 | |
michael@0 | 357 | return S_OK; |
michael@0 | 358 | |
michael@0 | 359 | A11Y_TRYBLOCK_END |
michael@0 | 360 | } |
michael@0 | 361 | |
michael@0 | 362 | STDMETHODIMP |
michael@0 | 363 | sdnAccessible::get_lastChild(ISimpleDOMNode __RPC_FAR *__RPC_FAR* aNode) |
michael@0 | 364 | { |
michael@0 | 365 | A11Y_TRYBLOCK_BEGIN |
michael@0 | 366 | |
michael@0 | 367 | if (!aNode) |
michael@0 | 368 | return E_INVALIDARG; |
michael@0 | 369 | *aNode = nullptr; |
michael@0 | 370 | |
michael@0 | 371 | if (IsDefunct()) |
michael@0 | 372 | return CO_E_OBJNOTCONNECTED; |
michael@0 | 373 | |
michael@0 | 374 | nsINode* resultNode = mNode->GetLastChild(); |
michael@0 | 375 | if (resultNode) { |
michael@0 | 376 | *aNode = static_cast<ISimpleDOMNode*>(new sdnAccessible(resultNode)); |
michael@0 | 377 | (*aNode)->AddRef(); |
michael@0 | 378 | } |
michael@0 | 379 | |
michael@0 | 380 | return S_OK; |
michael@0 | 381 | |
michael@0 | 382 | A11Y_TRYBLOCK_END |
michael@0 | 383 | } |
michael@0 | 384 | |
michael@0 | 385 | STDMETHODIMP |
michael@0 | 386 | sdnAccessible::get_previousSibling(ISimpleDOMNode __RPC_FAR *__RPC_FAR* aNode) |
michael@0 | 387 | { |
michael@0 | 388 | A11Y_TRYBLOCK_BEGIN |
michael@0 | 389 | |
michael@0 | 390 | if (!aNode) |
michael@0 | 391 | return E_INVALIDARG; |
michael@0 | 392 | *aNode = nullptr; |
michael@0 | 393 | |
michael@0 | 394 | if (IsDefunct()) |
michael@0 | 395 | return CO_E_OBJNOTCONNECTED; |
michael@0 | 396 | |
michael@0 | 397 | nsINode* resultNode = mNode->GetPreviousSibling(); |
michael@0 | 398 | if (resultNode) { |
michael@0 | 399 | *aNode = static_cast<ISimpleDOMNode*>(new sdnAccessible(resultNode)); |
michael@0 | 400 | (*aNode)->AddRef(); |
michael@0 | 401 | } |
michael@0 | 402 | |
michael@0 | 403 | return S_OK; |
michael@0 | 404 | |
michael@0 | 405 | A11Y_TRYBLOCK_END |
michael@0 | 406 | } |
michael@0 | 407 | |
michael@0 | 408 | STDMETHODIMP |
michael@0 | 409 | sdnAccessible::get_nextSibling(ISimpleDOMNode __RPC_FAR *__RPC_FAR* aNode) |
michael@0 | 410 | { |
michael@0 | 411 | A11Y_TRYBLOCK_BEGIN |
michael@0 | 412 | |
michael@0 | 413 | if (!aNode) |
michael@0 | 414 | return E_INVALIDARG; |
michael@0 | 415 | *aNode = nullptr; |
michael@0 | 416 | |
michael@0 | 417 | if (IsDefunct()) |
michael@0 | 418 | return CO_E_OBJNOTCONNECTED; |
michael@0 | 419 | |
michael@0 | 420 | nsINode* resultNode = mNode->GetNextSibling(); |
michael@0 | 421 | if (resultNode) { |
michael@0 | 422 | *aNode = static_cast<ISimpleDOMNode*>(new sdnAccessible(resultNode)); |
michael@0 | 423 | (*aNode)->AddRef(); |
michael@0 | 424 | } |
michael@0 | 425 | |
michael@0 | 426 | return S_OK; |
michael@0 | 427 | |
michael@0 | 428 | A11Y_TRYBLOCK_END |
michael@0 | 429 | } |
michael@0 | 430 | |
michael@0 | 431 | STDMETHODIMP |
michael@0 | 432 | sdnAccessible::get_childAt(unsigned aChildIndex, |
michael@0 | 433 | ISimpleDOMNode __RPC_FAR *__RPC_FAR* aNode) |
michael@0 | 434 | { |
michael@0 | 435 | A11Y_TRYBLOCK_BEGIN |
michael@0 | 436 | |
michael@0 | 437 | if (!aNode) |
michael@0 | 438 | return E_INVALIDARG; |
michael@0 | 439 | *aNode = nullptr; |
michael@0 | 440 | |
michael@0 | 441 | if (IsDefunct()) |
michael@0 | 442 | return CO_E_OBJNOTCONNECTED; |
michael@0 | 443 | |
michael@0 | 444 | nsINode* resultNode = mNode->GetChildAt(aChildIndex); |
michael@0 | 445 | if (resultNode) { |
michael@0 | 446 | *aNode = static_cast<ISimpleDOMNode*>(new sdnAccessible(resultNode)); |
michael@0 | 447 | (*aNode)->AddRef(); |
michael@0 | 448 | } |
michael@0 | 449 | |
michael@0 | 450 | |
michael@0 | 451 | return S_OK; |
michael@0 | 452 | |
michael@0 | 453 | A11Y_TRYBLOCK_END |
michael@0 | 454 | } |
michael@0 | 455 | |
michael@0 | 456 | STDMETHODIMP |
michael@0 | 457 | sdnAccessible::get_innerHTML(BSTR __RPC_FAR* aInnerHTML) |
michael@0 | 458 | { |
michael@0 | 459 | A11Y_TRYBLOCK_BEGIN |
michael@0 | 460 | |
michael@0 | 461 | if (!aInnerHTML) |
michael@0 | 462 | return E_INVALIDARG; |
michael@0 | 463 | *aInnerHTML = nullptr; |
michael@0 | 464 | |
michael@0 | 465 | if (IsDefunct()) |
michael@0 | 466 | return CO_E_OBJNOTCONNECTED; |
michael@0 | 467 | |
michael@0 | 468 | if (!mNode->IsElement()) |
michael@0 | 469 | return S_FALSE; |
michael@0 | 470 | |
michael@0 | 471 | nsAutoString innerHTML; |
michael@0 | 472 | mNode->AsElement()->GetInnerHTML(innerHTML); |
michael@0 | 473 | if (innerHTML.IsEmpty()) |
michael@0 | 474 | return S_FALSE; |
michael@0 | 475 | |
michael@0 | 476 | *aInnerHTML = ::SysAllocStringLen(innerHTML.get(), innerHTML.Length()); |
michael@0 | 477 | if (!*aInnerHTML) |
michael@0 | 478 | return E_OUTOFMEMORY; |
michael@0 | 479 | |
michael@0 | 480 | return S_OK; |
michael@0 | 481 | |
michael@0 | 482 | A11Y_TRYBLOCK_END |
michael@0 | 483 | } |
michael@0 | 484 | |
michael@0 | 485 | STDMETHODIMP |
michael@0 | 486 | sdnAccessible::get_localInterface(void __RPC_FAR *__RPC_FAR* aLocalInterface) |
michael@0 | 487 | { |
michael@0 | 488 | A11Y_TRYBLOCK_BEGIN |
michael@0 | 489 | |
michael@0 | 490 | if (!aLocalInterface) |
michael@0 | 491 | return E_INVALIDARG; |
michael@0 | 492 | *aLocalInterface = nullptr; |
michael@0 | 493 | |
michael@0 | 494 | if (IsDefunct()) |
michael@0 | 495 | return CO_E_OBJNOTCONNECTED; |
michael@0 | 496 | |
michael@0 | 497 | *aLocalInterface = this; |
michael@0 | 498 | AddRef(); |
michael@0 | 499 | |
michael@0 | 500 | return S_OK; |
michael@0 | 501 | |
michael@0 | 502 | A11Y_TRYBLOCK_END |
michael@0 | 503 | } |
michael@0 | 504 | |
michael@0 | 505 | STDMETHODIMP |
michael@0 | 506 | sdnAccessible::get_language(BSTR __RPC_FAR* aLanguage) |
michael@0 | 507 | { |
michael@0 | 508 | A11Y_TRYBLOCK_BEGIN |
michael@0 | 509 | |
michael@0 | 510 | if (!aLanguage) |
michael@0 | 511 | return E_INVALIDARG; |
michael@0 | 512 | *aLanguage = nullptr; |
michael@0 | 513 | |
michael@0 | 514 | if (IsDefunct()) |
michael@0 | 515 | return CO_E_OBJNOTCONNECTED; |
michael@0 | 516 | |
michael@0 | 517 | nsAutoString language; |
michael@0 | 518 | if (mNode->IsContent()) |
michael@0 | 519 | nsCoreUtils::GetLanguageFor(mNode->AsContent(), nullptr, language); |
michael@0 | 520 | if (language.IsEmpty()) { // Nothing found, so use document's language |
michael@0 | 521 | mNode->OwnerDoc()->GetHeaderData(nsGkAtoms::headerContentLanguage, |
michael@0 | 522 | language); |
michael@0 | 523 | } |
michael@0 | 524 | |
michael@0 | 525 | if (language.IsEmpty()) |
michael@0 | 526 | return S_FALSE; |
michael@0 | 527 | |
michael@0 | 528 | *aLanguage = ::SysAllocStringLen(language.get(), language.Length()); |
michael@0 | 529 | if (!*aLanguage) |
michael@0 | 530 | return E_OUTOFMEMORY; |
michael@0 | 531 | |
michael@0 | 532 | return S_OK; |
michael@0 | 533 | |
michael@0 | 534 | A11Y_TRYBLOCK_END |
michael@0 | 535 | } |