accessible/windows/ProxyWrappers.h
author Gregory Szorc <gps@mozilla.com>
Wed, 20 Jul 2016 09:21:38 -0700
changeset 390086 5fa517a2ac0dd948a2826c7031ee3784f528b40a
parent 302640 d2d09d65a73f382842c463f0a8d2688d120fbbb1
child 392057 191e2e45ab06451dac34fed04a4328f867813d8e
permissions -rw-r--r--
Bug 1247168 - Change decision image to Ubuntu 16.04; r?dustin We're currently running Ubuntu 14.04 in the decision image. While still in LTS support, 16.04 ships with a modern, properly configured Python 2.7. So we upgrade to 16.04 and drop the install of Python from source because it is no longer needed. This is part 1 of a larger refactor to this image.

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. *
 */

#ifndef MOZILLA_A11Y_ProxyWrappers_h
#define MOZILLA_A11Y_ProxyWrappers_h

#include "HyperTextAccessible.h"

namespace mozilla {
namespace a11y {

class ProxyAccessibleWrap : public AccessibleWrap
{
  public:
  ProxyAccessibleWrap(ProxyAccessible* aProxy) :
    AccessibleWrap(nullptr, nullptr)
  {
    mType = eProxyType;
    mBits.proxy = aProxy;
  }

  virtual void Shutdown() override
  {
    mBits.proxy = nullptr;
    mStateFlags |= eIsDefunct;
  }
};

class HyperTextProxyAccessibleWrap : public HyperTextAccessibleWrap
{
public:
  HyperTextProxyAccessibleWrap(ProxyAccessible* aProxy) :
    HyperTextAccessibleWrap(nullptr, nullptr)
  {
    mType = eProxyType;
    mBits.proxy = aProxy;
  }

  virtual void Shutdown() override
  {
    mBits.proxy = nullptr;
 mStateFlags |= eIsDefunct;
  }
};

class DocProxyAccessibleWrap : public HyperTextProxyAccessibleWrap
{
public:
  DocProxyAccessibleWrap(ProxyAccessible* aProxy) :
    HyperTextProxyAccessibleWrap(aProxy)
  { mGenericTypes |= eDocument; }

  void AddID(uint32_t aID, AccessibleWrap* aAcc)
    { mIDToAccessibleMap.Put(aID, aAcc); }
  void RemoveID(uint32_t aID) { mIDToAccessibleMap.Remove(aID); }
  AccessibleWrap* GetAccessibleByID(uint32_t aID) const
    { return mIDToAccessibleMap.Get(aID); }

private:
  /*
   * This provides a mapping from 32 bit id to accessible objects.
   */
  nsDataHashtable<nsUint32HashKey, AccessibleWrap*> mIDToAccessibleMap;
};

template<typename T>
inline ProxyAccessible*
HyperTextProxyFor(T* aWrapper)
{
  static_assert(mozilla::IsBaseOf<IUnknown, T>::value, "only IAccessible* should be passed in");
  auto wrapper = static_cast<HyperTextProxyAccessibleWrap*>(aWrapper);
  return wrapper->IsProxy() ? wrapper->Proxy() : nullptr;
}

}
}

#endif