Roll src/third_party/WebKit f298044:aa8346d (svn 202628:202629)
[chromium-blink-merge.git] / content / browser / accessibility / browser_accessibility_state_impl.h
blobe3da7f7dad2ea23588a0c41b38d2f10e9ffddb94
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_STATE_IMPL_H_
6 #define CONTENT_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_STATE_IMPL_H_
8 #include <vector>
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "base/memory/singleton.h"
13 #include "content/common/accessibility_mode_enums.h"
14 #include "content/public/browser/browser_accessibility_state.h"
16 namespace content {
18 // The BrowserAccessibilityState class is used to determine if Chrome should be
19 // customized for users with assistive technology, such as screen readers. We
20 // modify the behavior of certain user interfaces to provide a better experience
21 // for screen reader users. The way we detect a screen reader program is
22 // different for each platform.
24 // Screen Reader Detection
25 // (1) On windows many screen reader detection mechinisms will give false
26 // positives like relying on the SPI_GETSCREENREADER system parameter. In Chrome
27 // we attempt to dynamically detect a MSAA client screen reader by calling
28 // NotifiyWinEvent in NativeWidgetWin with a custom ID and wait to see if the ID
29 // is requested by a subsequent call to WM_GETOBJECT.
30 // (2) On mac we detect dynamically if VoiceOver is running. We rely upon the
31 // undocumented accessibility attribute @"AXEnhancedUserInterface" which is set
32 // when VoiceOver is launched and unset when VoiceOver is closed. This is an
33 // improvement over reading defaults preference values (which has no callback
34 // mechanism).
35 class CONTENT_EXPORT BrowserAccessibilityStateImpl
36 : public base::RefCountedThreadSafe<BrowserAccessibilityStateImpl>,
37 public BrowserAccessibilityState {
38 public:
39 BrowserAccessibilityStateImpl();
41 static BrowserAccessibilityStateImpl* GetInstance();
43 void EnableAccessibility() override;
44 void DisableAccessibility() override;
45 void ResetAccessibilityMode() override;
46 void OnScreenReaderDetected() override;
47 bool IsAccessibleBrowser() override;
48 void AddHistogramCallback(base::Closure callback) override;
50 void UpdateHistogramsForTesting() override;
52 AccessibilityMode accessibility_mode() const { return accessibility_mode_; };
54 // Adds the given accessibility mode to the current accessibility mode bitmap.
55 void AddAccessibilityMode(AccessibilityMode mode);
57 // Removes the given accessibility mode from the current accessibility mode
58 // bitmap, managing the bits that are shared with other modes such that a
59 // bit will only be turned off when all modes that depend on it have been
60 // removed.
61 void RemoveAccessibilityMode(AccessibilityMode mode);
63 // Accessibility objects can have the "hot tracked" state set when
64 // the mouse is hovering over them, but this makes tests flaky because
65 // the test behaves differently when the mouse happens to be over an
66 // element. This is a global switch to not use the "hot tracked" state
67 // in a test.
68 void set_disable_hot_tracking_for_testing(bool disable_hot_tracking) {
69 disable_hot_tracking_ = disable_hot_tracking;
71 bool disable_hot_tracking_for_testing() const {
72 return disable_hot_tracking_;
75 private:
76 friend class base::RefCountedThreadSafe<BrowserAccessibilityStateImpl>;
77 friend struct base::DefaultSingletonTraits<BrowserAccessibilityStateImpl>;
79 // Resets accessibility_mode_ to the default value.
80 void ResetAccessibilityModeValue();
82 // Called a short while after startup to allow time for the accessibility
83 // state to be determined. Updates histograms with the current state.
84 void UpdateHistograms();
86 // Leaky singleton, destructor generally won't be called.
87 ~BrowserAccessibilityStateImpl() override;
89 void UpdatePlatformSpecificHistograms();
91 // Updates the accessibility mode of all web contents, including swapped out
92 // ones. |add| specifies whether the mode should be added or removed.
93 void AddOrRemoveFromAllWebContents(AccessibilityMode mode, bool add);
95 AccessibilityMode accessibility_mode_;
97 std::vector<base::Closure> histogram_callbacks_;
99 bool disable_hot_tracking_;
101 DISALLOW_COPY_AND_ASSIGN(BrowserAccessibilityStateImpl);
104 } // namespace content
106 #endif // CONTENT_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_STATE_IMPL_H_