accessible/ipc/win/COMPtrTypes.h
author Sylvestre Ledru <sledru@mozilla.com>
Fri, 30 Nov 2018 11:46:48 +0100
changeset 448947 6f3709b3878117466168c40affa7bca0b60cf75b
parent 384123 f76f2dcae8f17bb43ff125b82b36c70a6cc2334d
permissions -rw-r--r--
Bug 1511181 - Reformat everything to the Google coding style r=ehsan a=clang-format # ignore-this-changeset

/* -*- 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_COMPtrTypes_h
#define mozilla_a11y_COMPtrTypes_h

#include "mozilla/a11y/AccessibleHandler.h"
#include "mozilla/a11y/Compatibility.h"
#include "mozilla/Attributes.h"
#include "mozilla/mscom/ActivationContext.h"
#include "mozilla/mscom/COMPtrHolder.h"
#include "mozilla/NotNull.h"

#include <oleacc.h>

namespace mozilla {
namespace a11y {

class MOZ_RAII IAccessibleEnvironment : public mscom::ProxyStream::Environment {
 public:
  IAccessibleEnvironment() = default;

  bool Push() override {
    mActCtxRgn = GetActCtx();
    return !!mActCtxRgn;
  }

  bool Pop() override { return mActCtxRgn.Deactivate(); }

 private:
  static const mscom::ActivationContext& GetActCtx() {
    static const mscom::ActivationContext sActCtx(
        Compatibility::GetActCtxResourceId());
    MOZ_DIAGNOSTIC_ASSERT(sActCtx);
    return sActCtx;
  }

 private:
  mscom::ActivationContextRegion mActCtxRgn;
};

}  // namespace a11y

namespace mscom {
namespace detail {

template <>
struct EnvironmentSelector<IAccessible> {
  typedef a11y::IAccessibleEnvironment Type;
};

}  // namespace detail
}  // namespace mscom

namespace a11y {

typedef mozilla::mscom::COMPtrHolder<IAccessible, IID_IAccessible>
    IAccessibleHolder;
typedef mozilla::mscom::COMPtrHolder<IDispatch, IID_IDispatch> IDispatchHolder;

class Accessible;

IAccessibleHolder CreateHolderFromAccessible(NotNull<Accessible*> aAccToWrap);

typedef mozilla::mscom::COMPtrHolder<IHandlerControl, IID_IHandlerControl>
    IHandlerControlHolder;

IHandlerControlHolder CreateHolderFromHandlerControl(
    mscom::ProxyUniquePtr<IHandlerControl> aHandlerControl);

}  // namespace a11y
}  // namespace mozilla

#endif  // mozilla_a11y_COMPtrTypes_h