accessible/src/windows/ia2/ia2AccessibleImage.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/accessible/src/windows/ia2/ia2AccessibleImage.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,130 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* vim:expandtab:shiftwidth=2:tabstop=2:
     1.6 + */
     1.7 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.8 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.9 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
    1.10 +
    1.11 +#include "ia2AccessibleImage.h"
    1.12 +
    1.13 +#include "AccessibleImage_i.c"
    1.14 +
    1.15 +#include "ImageAccessibleWrap.h"
    1.16 +#include "IUnknownImpl.h"
    1.17 +#include "nsIAccessibleTypes.h"
    1.18 +
    1.19 +#include "nsString.h"
    1.20 +#include "nsIURI.h"
    1.21 +
    1.22 +using namespace mozilla;
    1.23 +using namespace mozilla::a11y;
    1.24 +
    1.25 +// IUnknown
    1.26 +
    1.27 +STDMETHODIMP
    1.28 +ia2AccessibleImage::QueryInterface(REFIID iid, void** ppv)
    1.29 +{
    1.30 +  if (!ppv)
    1.31 +    return E_INVALIDARG;
    1.32 +
    1.33 +  *ppv = nullptr;
    1.34 +
    1.35 +  if (IID_IAccessibleImage == iid) {
    1.36 +    *ppv = static_cast<IAccessibleImage*>(this);
    1.37 +    (static_cast<IUnknown*>(*ppv))->AddRef();
    1.38 +    return S_OK;
    1.39 +  }
    1.40 +
    1.41 +  return E_NOINTERFACE;
    1.42 +}
    1.43 +
    1.44 +// IAccessibleImage
    1.45 +
    1.46 +STDMETHODIMP
    1.47 +ia2AccessibleImage::get_description(BSTR* aDescription)
    1.48 +{
    1.49 +  A11Y_TRYBLOCK_BEGIN
    1.50 +
    1.51 +  if (!aDescription)
    1.52 +    return E_INVALIDARG;
    1.53 +
    1.54 +  *aDescription = nullptr;
    1.55 +
    1.56 +  ImageAccessibleWrap* acc = static_cast<ImageAccessibleWrap*>(this);
    1.57 +  if (acc->IsDefunct())
    1.58 +    return CO_E_OBJNOTCONNECTED;
    1.59 +
    1.60 +  nsAutoString description;
    1.61 +  nsresult rv = acc->GetName(description);
    1.62 +  if (NS_FAILED(rv))
    1.63 +    return GetHRESULT(rv);
    1.64 +
    1.65 +  if (description.IsEmpty())
    1.66 +    return S_FALSE;
    1.67 +
    1.68 +  *aDescription = ::SysAllocStringLen(description.get(), description.Length());
    1.69 +  return *aDescription ? S_OK : E_OUTOFMEMORY;
    1.70 +
    1.71 +  A11Y_TRYBLOCK_END
    1.72 +}
    1.73 +
    1.74 +STDMETHODIMP
    1.75 +ia2AccessibleImage::get_imagePosition(enum IA2CoordinateType aCoordType,
    1.76 +                                      long* aX,
    1.77 +                                      long* aY)
    1.78 +{
    1.79 +  A11Y_TRYBLOCK_BEGIN
    1.80 +
    1.81 +  if (!aX || !aY)
    1.82 +    return E_INVALIDARG;
    1.83 +
    1.84 +  *aX = 0;
    1.85 +  *aY = 0;
    1.86 +
    1.87 +  ImageAccessibleWrap* imageAcc = static_cast<ImageAccessibleWrap*>(this);
    1.88 +  if (imageAcc->IsDefunct())
    1.89 +    return CO_E_OBJNOTCONNECTED;
    1.90 +
    1.91 +  uint32_t geckoCoordType = (aCoordType == IA2_COORDTYPE_SCREEN_RELATIVE) ?
    1.92 +    nsIAccessibleCoordinateType::COORDTYPE_SCREEN_RELATIVE :
    1.93 +    nsIAccessibleCoordinateType::COORDTYPE_PARENT_RELATIVE;
    1.94 +  int32_t x = 0, y = 0;
    1.95 +
    1.96 +  nsresult rv = imageAcc->GetImagePosition(geckoCoordType, &x, &y);
    1.97 +  if (NS_FAILED(rv))
    1.98 +    return GetHRESULT(rv);
    1.99 +
   1.100 +  *aX = x;
   1.101 +  *aY = y;
   1.102 +  return S_OK;
   1.103 +
   1.104 +  A11Y_TRYBLOCK_END
   1.105 +}
   1.106 +
   1.107 +STDMETHODIMP
   1.108 +ia2AccessibleImage::get_imageSize(long* aHeight, long* aWidth)
   1.109 +{
   1.110 +  A11Y_TRYBLOCK_BEGIN
   1.111 +
   1.112 +  if (!aHeight || !aWidth)
   1.113 +    return E_INVALIDARG;
   1.114 +
   1.115 +  *aHeight = 0;
   1.116 +  *aWidth = 0;
   1.117 +
   1.118 +  ImageAccessibleWrap* imageAcc = static_cast<ImageAccessibleWrap*>(this);
   1.119 +  if (imageAcc->IsDefunct())
   1.120 +    return CO_E_OBJNOTCONNECTED;
   1.121 +
   1.122 +  int32_t width = 0, height = 0;
   1.123 +  nsresult rv = imageAcc->GetImageSize(&width, &height);
   1.124 +  if (NS_FAILED(rv))
   1.125 +    return GetHRESULT(rv);
   1.126 +
   1.127 +  *aHeight = width;
   1.128 +  *aWidth = height;
   1.129 +  return S_OK;
   1.130 +
   1.131 +  A11Y_TRYBLOCK_END
   1.132 +}
   1.133 +

mercurial