widget/windows/winrt/UIAAccessibilityBridge.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/widget/windows/winrt/UIAAccessibilityBridge.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,80 @@
     1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#pragma once
    1.10 +
    1.11 +#if defined(ACCESSIBILITY)
    1.12 +
    1.13 +#include "nsCOMPtr.h"
    1.14 +#include "nsIObserver.h"
    1.15 +#include "nsIObserverService.h"
    1.16 +#include "nsServiceManagerUtils.h"
    1.17 +#include "mozilla/a11y/Accessible.h"
    1.18 +
    1.19 +#include "mozwrlbase.h"
    1.20 +
    1.21 +namespace mozilla {
    1.22 +namespace widget {
    1.23 +namespace winrt {
    1.24 +
    1.25 +// Connects to our accessibility framework to receive
    1.26 +// events and query the dom.
    1.27 +class AccessibilityBridge : public nsIObserver
    1.28 +{
    1.29 +public:
    1.30 +  NS_DECL_ISUPPORTS
    1.31 +  NS_DECL_NSIOBSERVER
    1.32 +
    1.33 +  AccessibilityBridge() {}
    1.34 +
    1.35 +  ~AccessibilityBridge() {
    1.36 +    Disconnect();
    1.37 +  }
    1.38 +
    1.39 +  bool Init(IUnknown* aBridge, mozilla::a11y::Accessible* aPtr) {
    1.40 +    mAccess = aPtr;
    1.41 +    mBridge = aBridge;
    1.42 +    return Connect();
    1.43 +  }
    1.44 +
    1.45 +  bool Connect() {
    1.46 +    nsresult rv;
    1.47 +
    1.48 +    nsCOMPtr<nsIObserverService> observerService = 
    1.49 +      do_GetService("@mozilla.org/observer-service;1", &rv);
    1.50 +    if (NS_FAILED(rv)) {
    1.51 +      return false;
    1.52 +    }
    1.53 +    rv = observerService->AddObserver(this, "accessible-event", false);
    1.54 +    if (NS_FAILED(rv)) {
    1.55 +      return false;
    1.56 +    }
    1.57 +    return true;
    1.58 +  }
    1.59 +
    1.60 +  bool Connected() {
    1.61 +    return mAccess ? true : false;
    1.62 +  }
    1.63 +
    1.64 +  void Disconnect() {
    1.65 +    nsresult rv;
    1.66 +    nsCOMPtr<nsIObserverService> observerService = 
    1.67 +      do_GetService("@mozilla.org/observer-service;1", &rv);
    1.68 +    if (NS_FAILED(rv)) {
    1.69 +      NS_WARNING("failed to get observersvc on shutdown.");
    1.70 +      return;
    1.71 +    }
    1.72 +    observerService->RemoveObserver(this, "accessible-event");
    1.73 +    mAccess = nullptr;
    1.74 +  }
    1.75 +
    1.76 +private:
    1.77 +  nsRefPtr<mozilla::a11y::Accessible> mAccess;
    1.78 +  Microsoft::WRL::ComPtr<IUnknown> mBridge;
    1.79 +};
    1.80 +
    1.81 +} } }
    1.82 +
    1.83 +#endif // ACCESSIBILITY

mercurial