michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #pragma once michael@0: michael@0: #if defined(ACCESSIBILITY) michael@0: michael@0: #include "nsCOMPtr.h" michael@0: #include "nsIObserver.h" michael@0: #include "nsIObserverService.h" michael@0: #include "nsServiceManagerUtils.h" michael@0: #include "mozilla/a11y/Accessible.h" michael@0: michael@0: #include "mozwrlbase.h" michael@0: michael@0: namespace mozilla { michael@0: namespace widget { michael@0: namespace winrt { michael@0: michael@0: // Connects to our accessibility framework to receive michael@0: // events and query the dom. michael@0: class AccessibilityBridge : public nsIObserver michael@0: { michael@0: public: michael@0: NS_DECL_ISUPPORTS michael@0: NS_DECL_NSIOBSERVER michael@0: michael@0: AccessibilityBridge() {} michael@0: michael@0: ~AccessibilityBridge() { michael@0: Disconnect(); michael@0: } michael@0: michael@0: bool Init(IUnknown* aBridge, mozilla::a11y::Accessible* aPtr) { michael@0: mAccess = aPtr; michael@0: mBridge = aBridge; michael@0: return Connect(); michael@0: } michael@0: michael@0: bool Connect() { michael@0: nsresult rv; michael@0: michael@0: nsCOMPtr observerService = michael@0: do_GetService("@mozilla.org/observer-service;1", &rv); michael@0: if (NS_FAILED(rv)) { michael@0: return false; michael@0: } michael@0: rv = observerService->AddObserver(this, "accessible-event", false); michael@0: if (NS_FAILED(rv)) { michael@0: return false; michael@0: } michael@0: return true; michael@0: } michael@0: michael@0: bool Connected() { michael@0: return mAccess ? true : false; michael@0: } michael@0: michael@0: void Disconnect() { michael@0: nsresult rv; michael@0: nsCOMPtr observerService = michael@0: do_GetService("@mozilla.org/observer-service;1", &rv); michael@0: if (NS_FAILED(rv)) { michael@0: NS_WARNING("failed to get observersvc on shutdown."); michael@0: return; michael@0: } michael@0: observerService->RemoveObserver(this, "accessible-event"); michael@0: mAccess = nullptr; michael@0: } michael@0: michael@0: private: michael@0: nsRefPtr mAccess; michael@0: Microsoft::WRL::ComPtr mBridge; michael@0: }; michael@0: michael@0: } } } michael@0: michael@0: #endif // ACCESSIBILITY