accessible/src/windows/ia2/ia2AccessibleAction.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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/. */
     8 #include "ia2AccessibleAction.h"
    10 #include "AccessibleAction_i.c"
    12 #include "AccessibleWrap.h"
    13 #include "IUnknownImpl.h"
    15 using namespace mozilla::a11y;
    17 // IUnknown
    19 STDMETHODIMP
    20 ia2AccessibleAction::QueryInterface(REFIID iid, void** ppv)
    21 {
    22   if (!ppv)
    23     return E_INVALIDARG;
    25   *ppv = nullptr;
    27   if (IID_IAccessibleAction == iid) {
    28     *ppv = static_cast<IAccessibleAction*>(this);
    29     (reinterpret_cast<IUnknown*>(*ppv))->AddRef();
    30     return S_OK;
    31   }
    33   return E_NOINTERFACE;
    34 }
    36 // IAccessibleAction
    38 STDMETHODIMP
    39 ia2AccessibleAction::nActions(long* aActionCount)
    40 {
    41   A11Y_TRYBLOCK_BEGIN
    43   if (!aActionCount)
    44     return E_INVALIDARG;
    46   *aActionCount = 0;
    48   AccessibleWrap* acc = static_cast<AccessibleWrap*>(this);
    49   if (acc->IsDefunct())
    50     return CO_E_OBJNOTCONNECTED;
    52   *aActionCount = acc->ActionCount();
    53   return S_OK;
    55   A11Y_TRYBLOCK_END
    56 }
    58 STDMETHODIMP
    59 ia2AccessibleAction::doAction(long aActionIndex)
    60 {
    61   A11Y_TRYBLOCK_BEGIN
    63   AccessibleWrap* acc = static_cast<AccessibleWrap*>(this);
    64   if (acc->IsDefunct())
    65     return CO_E_OBJNOTCONNECTED;
    67   uint8_t index = static_cast<uint8_t>(aActionIndex);
    68   nsresult rv = acc->DoAction(index);
    69   return GetHRESULT(rv);
    71   A11Y_TRYBLOCK_END
    72 }
    74 STDMETHODIMP
    75 ia2AccessibleAction::get_description(long aActionIndex, BSTR *aDescription)
    76 {
    77   A11Y_TRYBLOCK_BEGIN
    79   if (!aDescription)
    80     return E_INVALIDARG;
    82   *aDescription = nullptr;
    84   AccessibleWrap* acc = static_cast<AccessibleWrap*>(this);
    85   if (acc->IsDefunct())
    86     return CO_E_OBJNOTCONNECTED;
    88   nsAutoString description;
    89   uint8_t index = static_cast<uint8_t>(aActionIndex);
    90   nsresult rv = acc->GetActionDescription(index, description);
    91   if (NS_FAILED(rv))
    92     return GetHRESULT(rv);
    94   if (description.IsEmpty())
    95     return S_FALSE;
    97   *aDescription = ::SysAllocStringLen(description.get(),
    98                                       description.Length());
    99   return *aDescription ? S_OK : E_OUTOFMEMORY;
   101   A11Y_TRYBLOCK_END
   102 }
   104 STDMETHODIMP
   105 ia2AccessibleAction::get_keyBinding(long aActionIndex, long aNumMaxBinding,
   106                                   BSTR **aKeyBinding,
   107                                   long *aNumBinding)
   108 {
   109   A11Y_TRYBLOCK_BEGIN
   111   if (!aKeyBinding)
   112     return E_INVALIDARG;
   113   *aKeyBinding = nullptr;
   115   if (!aNumBinding)
   116     return E_INVALIDARG;
   117   *aNumBinding = 0;
   119   if (aActionIndex != 0 || aNumMaxBinding < 1)
   120     return E_INVALIDARG;
   122   AccessibleWrap* acc = static_cast<AccessibleWrap*>(this);
   123   if (acc->IsDefunct())
   124     return CO_E_OBJNOTCONNECTED;
   126   // Expose keyboard shortcut if it's not exposed via MSAA keyboard shortcut.
   127   KeyBinding keyBinding = acc->AccessKey();
   128   if (keyBinding.IsEmpty())
   129     return S_FALSE;
   131   keyBinding = acc->KeyboardShortcut();
   132   if (keyBinding.IsEmpty())
   133     return S_FALSE;
   135   nsAutoString keyStr;
   136   keyBinding.ToString(keyStr);
   138   *aKeyBinding = static_cast<BSTR*>(::CoTaskMemAlloc(sizeof(BSTR*)));
   139   if (!*aKeyBinding)
   140     return E_OUTOFMEMORY;
   142   *(aKeyBinding[0]) = ::SysAllocStringLen(keyStr.get(), keyStr.Length());
   143   if (!*(aKeyBinding[0])) {
   144     ::CoTaskMemFree(*aKeyBinding);
   145     return E_OUTOFMEMORY;
   146   }
   148   *aNumBinding = 1;
   149   return S_OK;
   151   A11Y_TRYBLOCK_END
   152 }
   154 STDMETHODIMP
   155 ia2AccessibleAction::get_name(long aActionIndex, BSTR *aName)
   156 {
   157   A11Y_TRYBLOCK_BEGIN
   159   if (!aName)
   160     return E_INVALIDARG;
   162   *aName = nullptr;
   164   AccessibleWrap* acc = static_cast<AccessibleWrap*>(this);
   165   if (acc->IsDefunct())
   166     return CO_E_OBJNOTCONNECTED;
   168   nsAutoString name;
   169   uint8_t index = static_cast<uint8_t>(aActionIndex);
   170   nsresult rv = acc->GetActionName(index, name);
   171   if (NS_FAILED(rv))
   172     return GetHRESULT(rv);
   174   if (name.IsEmpty())
   175     return S_FALSE;
   177   *aName = ::SysAllocStringLen(name.get(), name.Length());
   178   return *aName ? S_OK : E_OUTOFMEMORY;
   180   A11Y_TRYBLOCK_END
   181 }
   183 STDMETHODIMP
   184 ia2AccessibleAction::get_localizedName(long aActionIndex, BSTR *aLocalizedName)
   185 {
   186   A11Y_TRYBLOCK_BEGIN
   188   if (!aLocalizedName)
   189     return E_INVALIDARG;
   191   *aLocalizedName = nullptr;
   192   return E_NOTIMPL;
   194   A11Y_TRYBLOCK_END
   195 }

mercurial