widget/windows/winrt/UIAAccessibilityBridge.h

branch
TOR_BUG_9701
changeset 10
ac0c01689b40
equal deleted inserted replaced
-1:000000000000 0:46767cc555c9
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 #pragma once
7
8 #if defined(ACCESSIBILITY)
9
10 #include "nsCOMPtr.h"
11 #include "nsIObserver.h"
12 #include "nsIObserverService.h"
13 #include "nsServiceManagerUtils.h"
14 #include "mozilla/a11y/Accessible.h"
15
16 #include "mozwrlbase.h"
17
18 namespace mozilla {
19 namespace widget {
20 namespace winrt {
21
22 // Connects to our accessibility framework to receive
23 // events and query the dom.
24 class AccessibilityBridge : public nsIObserver
25 {
26 public:
27 NS_DECL_ISUPPORTS
28 NS_DECL_NSIOBSERVER
29
30 AccessibilityBridge() {}
31
32 ~AccessibilityBridge() {
33 Disconnect();
34 }
35
36 bool Init(IUnknown* aBridge, mozilla::a11y::Accessible* aPtr) {
37 mAccess = aPtr;
38 mBridge = aBridge;
39 return Connect();
40 }
41
42 bool Connect() {
43 nsresult rv;
44
45 nsCOMPtr<nsIObserverService> observerService =
46 do_GetService("@mozilla.org/observer-service;1", &rv);
47 if (NS_FAILED(rv)) {
48 return false;
49 }
50 rv = observerService->AddObserver(this, "accessible-event", false);
51 if (NS_FAILED(rv)) {
52 return false;
53 }
54 return true;
55 }
56
57 bool Connected() {
58 return mAccess ? true : false;
59 }
60
61 void Disconnect() {
62 nsresult rv;
63 nsCOMPtr<nsIObserverService> observerService =
64 do_GetService("@mozilla.org/observer-service;1", &rv);
65 if (NS_FAILED(rv)) {
66 NS_WARNING("failed to get observersvc on shutdown.");
67 return;
68 }
69 observerService->RemoveObserver(this, "accessible-event");
70 mAccess = nullptr;
71 }
72
73 private:
74 nsRefPtr<mozilla::a11y::Accessible> mAccess;
75 Microsoft::WRL::ComPtr<IUnknown> mBridge;
76 };
77
78 } } }
79
80 #endif // ACCESSIBILITY

mercurial