ia2AccessibleImage.cpp (2118B)
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim:expandtab:shiftwidth=2:tabstop=2: 3 */ 4 /* This Source Code Form is subject to the terms of the Mozilla Public 5 * License, v. 2.0. If a copy of the MPL was not distributed with this 6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 7 8 #include "ia2AccessibleImage.h" 9 10 #include "AccessibleImage_i.c" 11 12 #include "ImageAccessible.h" 13 #include "IUnknownImpl.h" 14 #include "nsIAccessibleTypes.h" 15 16 #include "nsString.h" 17 18 using namespace mozilla; 19 using namespace mozilla::a11y; 20 21 // IUnknown 22 IMPL_IUNKNOWN_QUERY_HEAD(ia2AccessibleImage) 23 IMPL_IUNKNOWN_QUERY_IFACE(IAccessibleImage) 24 IMPL_IUNKNOWN_QUERY_TAIL_INHERITED(MsaaAccessible) 25 26 // IAccessibleImage 27 28 STDMETHODIMP 29 ia2AccessibleImage::get_description(BSTR* aDescription) { 30 if (!aDescription) return E_INVALIDARG; 31 32 *aDescription = nullptr; 33 34 Accessible* acc = Acc(); 35 if (!acc) return CO_E_OBJNOTCONNECTED; 36 37 nsAutoString description; 38 acc->Name(description); 39 if (description.IsEmpty()) return S_FALSE; 40 41 *aDescription = ::SysAllocStringLen(description.get(), description.Length()); 42 return *aDescription ? S_OK : E_OUTOFMEMORY; 43 } 44 45 STDMETHODIMP 46 ia2AccessibleImage::get_imagePosition(enum IA2CoordinateType aCoordType, 47 long* aX, long* aY) { 48 if (!aX || !aY) return E_INVALIDARG; 49 50 *aX = 0; 51 *aY = 0; 52 53 Accessible* acc = Acc(); 54 if (!acc) return CO_E_OBJNOTCONNECTED; 55 56 uint32_t geckoCoordType = 57 (aCoordType == IA2_COORDTYPE_SCREEN_RELATIVE) 58 ? nsIAccessibleCoordinateType::COORDTYPE_SCREEN_RELATIVE 59 : nsIAccessibleCoordinateType::COORDTYPE_PARENT_RELATIVE; 60 61 LayoutDeviceIntPoint pos = acc->Position(geckoCoordType); 62 *aX = pos.x; 63 *aY = pos.y; 64 return S_OK; 65 } 66 67 STDMETHODIMP 68 ia2AccessibleImage::get_imageSize(long* aHeight, long* aWidth) { 69 if (!aHeight || !aWidth) return E_INVALIDARG; 70 71 *aHeight = 0; 72 *aWidth = 0; 73 74 Accessible* acc = Acc(); 75 if (!acc) return CO_E_OBJNOTCONNECTED; 76 77 LayoutDeviceIntSize size = acc->Size(); 78 *aHeight = size.width; 79 *aWidth = size.height; 80 return S_OK; 81 }