michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim:expandtab:shiftwidth=2:tabstop=2: michael@0: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "ia2AccessibleImage.h" michael@0: michael@0: #include "AccessibleImage_i.c" michael@0: michael@0: #include "ImageAccessibleWrap.h" michael@0: #include "IUnknownImpl.h" michael@0: #include "nsIAccessibleTypes.h" michael@0: michael@0: #include "nsString.h" michael@0: #include "nsIURI.h" michael@0: michael@0: using namespace mozilla; michael@0: using namespace mozilla::a11y; michael@0: michael@0: // IUnknown michael@0: michael@0: STDMETHODIMP michael@0: ia2AccessibleImage::QueryInterface(REFIID iid, void** ppv) michael@0: { michael@0: if (!ppv) michael@0: return E_INVALIDARG; michael@0: michael@0: *ppv = nullptr; michael@0: michael@0: if (IID_IAccessibleImage == iid) { michael@0: *ppv = static_cast(this); michael@0: (static_cast(*ppv))->AddRef(); michael@0: return S_OK; michael@0: } michael@0: michael@0: return E_NOINTERFACE; michael@0: } michael@0: michael@0: // IAccessibleImage michael@0: michael@0: STDMETHODIMP michael@0: ia2AccessibleImage::get_description(BSTR* aDescription) michael@0: { michael@0: A11Y_TRYBLOCK_BEGIN michael@0: michael@0: if (!aDescription) michael@0: return E_INVALIDARG; michael@0: michael@0: *aDescription = nullptr; michael@0: michael@0: ImageAccessibleWrap* acc = static_cast(this); michael@0: if (acc->IsDefunct()) michael@0: return CO_E_OBJNOTCONNECTED; michael@0: michael@0: nsAutoString description; michael@0: nsresult rv = acc->GetName(description); michael@0: if (NS_FAILED(rv)) michael@0: return GetHRESULT(rv); michael@0: michael@0: if (description.IsEmpty()) michael@0: return S_FALSE; michael@0: michael@0: *aDescription = ::SysAllocStringLen(description.get(), description.Length()); michael@0: return *aDescription ? S_OK : E_OUTOFMEMORY; michael@0: michael@0: A11Y_TRYBLOCK_END michael@0: } michael@0: michael@0: STDMETHODIMP michael@0: ia2AccessibleImage::get_imagePosition(enum IA2CoordinateType aCoordType, michael@0: long* aX, michael@0: long* aY) michael@0: { michael@0: A11Y_TRYBLOCK_BEGIN michael@0: michael@0: if (!aX || !aY) michael@0: return E_INVALIDARG; michael@0: michael@0: *aX = 0; michael@0: *aY = 0; michael@0: michael@0: ImageAccessibleWrap* imageAcc = static_cast(this); michael@0: if (imageAcc->IsDefunct()) michael@0: return CO_E_OBJNOTCONNECTED; michael@0: michael@0: uint32_t geckoCoordType = (aCoordType == IA2_COORDTYPE_SCREEN_RELATIVE) ? michael@0: nsIAccessibleCoordinateType::COORDTYPE_SCREEN_RELATIVE : michael@0: nsIAccessibleCoordinateType::COORDTYPE_PARENT_RELATIVE; michael@0: int32_t x = 0, y = 0; michael@0: michael@0: nsresult rv = imageAcc->GetImagePosition(geckoCoordType, &x, &y); michael@0: if (NS_FAILED(rv)) michael@0: return GetHRESULT(rv); michael@0: michael@0: *aX = x; michael@0: *aY = y; michael@0: return S_OK; michael@0: michael@0: A11Y_TRYBLOCK_END michael@0: } michael@0: michael@0: STDMETHODIMP michael@0: ia2AccessibleImage::get_imageSize(long* aHeight, long* aWidth) michael@0: { michael@0: A11Y_TRYBLOCK_BEGIN michael@0: michael@0: if (!aHeight || !aWidth) michael@0: return E_INVALIDARG; michael@0: michael@0: *aHeight = 0; michael@0: *aWidth = 0; michael@0: michael@0: ImageAccessibleWrap* imageAcc = static_cast(this); michael@0: if (imageAcc->IsDefunct()) michael@0: return CO_E_OBJNOTCONNECTED; michael@0: michael@0: int32_t width = 0, height = 0; michael@0: nsresult rv = imageAcc->GetImageSize(&width, &height); michael@0: if (NS_FAILED(rv)) michael@0: return GetHRESULT(rv); michael@0: michael@0: *aHeight = width; michael@0: *aWidth = height; michael@0: return S_OK; michael@0: michael@0: A11Y_TRYBLOCK_END michael@0: } michael@0: