[email protected] | fa4f9168 | 2012-02-21 19:53:26 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | ff42d4c9 | 2010-10-05 00:56:19 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
[email protected] | fa4f9168 | 2012-02-21 19:53:26 | [diff] [blame] | 5 | #ifndef CONTENT_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_STATE_IMPL_H_ |
6 | #define CONTENT_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_STATE_IMPL_H_ | ||||
[email protected] | ff42d4c9 | 2010-10-05 00:56:19 | [diff] [blame] | 7 | |
[email protected] | 8943015 | 2012-12-03 19:18:56 | [diff] [blame] | 8 | #include <vector> |
9 | |||||
[email protected] | ec6bf33 | 2012-03-16 21:43:41 | [diff] [blame] | 10 | #include "base/compiler_specific.h" |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 11 | #include "base/macros.h" |
[email protected] | 18df736 | 2012-10-24 01:29:40 | [diff] [blame] | 12 | #include "base/memory/singleton.h" |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 13 | #include "content/common/accessibility_mode_enums.h" |
[email protected] | fa4f9168 | 2012-02-21 19:53:26 | [diff] [blame] | 14 | #include "content/public/browser/browser_accessibility_state.h" |
[email protected] | fee46a8 | 2010-12-09 16:42:15 | [diff] [blame] | 15 | |
[email protected] | e6b3487 | 2012-10-24 20:51:32 | [diff] [blame] | 16 | namespace content { |
17 | |||||
[email protected] | ff42d4c9 | 2010-10-05 00:56:19 | [diff] [blame] | 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. | ||||
23 | // | ||||
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 | ||||
[email protected] | 2fc6672 | 2011-05-19 14:43:12 | [diff] [blame] | 28 | // NotifiyWinEvent in NativeWidgetWin with a custom ID and wait to see if the ID |
[email protected] | ff42d4c9 | 2010-10-05 00:56:19 | [diff] [blame] | 29 | // is requested by a subsequent call to WM_GETOBJECT. |
[email protected] | f6855a0a | 2011-05-03 19:36:38 | [diff] [blame] | 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). | ||||
[email protected] | fa4f9168 | 2012-02-21 19:53:26 | [diff] [blame] | 35 | class CONTENT_EXPORT BrowserAccessibilityStateImpl |
[email protected] | 18df736 | 2012-10-24 01:29:40 | [diff] [blame] | 36 | : public base::RefCountedThreadSafe<BrowserAccessibilityStateImpl>, |
37 | public BrowserAccessibilityState { | ||||
[email protected] | ff42d4c9 | 2010-10-05 00:56:19 | [diff] [blame] | 38 | public: |
[email protected] | b90cad7 | 2012-04-10 23:27:53 | [diff] [blame] | 39 | BrowserAccessibilityStateImpl(); |
40 | |||||
[email protected] | fa4f9168 | 2012-02-21 19:53:26 | [diff] [blame] | 41 | static BrowserAccessibilityStateImpl* GetInstance(); |
[email protected] | ff42d4c9 | 2010-10-05 00:56:19 | [diff] [blame] | 42 | |
dcheng | c2282aa | 2014-10-21 12:07:58 | [diff] [blame] | 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; | ||||
[email protected] | ff42d4c9 | 2010-10-05 00:56:19 | [diff] [blame] | 49 | |
dcheng | c2282aa | 2014-10-21 12:07:58 | [diff] [blame] | 50 | void UpdateHistogramsForTesting() override; |
[email protected] | 88c2505 | 2011-11-05 20:16:05 | [diff] [blame] | 51 | |
[email protected] | df37697 | 2013-05-03 21:45:03 | [diff] [blame] | 52 | AccessibilityMode accessibility_mode() const { return accessibility_mode_; }; |
[email protected] | 1e558fa | 2014-02-12 23:28:52 | [diff] [blame] | 53 | |
54 | // Adds the given accessibility mode to the current accessibility mode bitmap. | ||||
55 | void AddAccessibilityMode(AccessibilityMode mode); | ||||
56 | |||||
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); | ||||
[email protected] | e2fa1cca4 | 2012-08-22 14:07:27 | [diff] [blame] | 62 | |
dmazzoni | dea5ba6 | 2015-02-03 19:27:24 | [diff] [blame] | 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; | ||||
70 | } | ||||
71 | bool disable_hot_tracking_for_testing() const { | ||||
72 | return disable_hot_tracking_; | ||||
73 | } | ||||
74 | |||||
[email protected] | 18df736 | 2012-10-24 01:29:40 | [diff] [blame] | 75 | private: |
76 | friend class base::RefCountedThreadSafe<BrowserAccessibilityStateImpl>; | ||||
olli.raula | 36aa8be | 2015-09-10 11:14:22 | [diff] [blame] | 77 | friend struct base::DefaultSingletonTraits<BrowserAccessibilityStateImpl>; |
[email protected] | 88c2505 | 2011-11-05 20:16:05 | [diff] [blame] | 78 | |
[email protected] | 1e558fa | 2014-02-12 23:28:52 | [diff] [blame] | 79 | // Resets accessibility_mode_ to the default value. |
80 | void ResetAccessibilityModeValue(); | ||||
81 | |||||
[email protected] | 30fdb36 | 2013-01-09 02:33:27 | [diff] [blame] | 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(); | ||||
85 | |||||
[email protected] | 18df736 | 2012-10-24 01:29:40 | [diff] [blame] | 86 | // Leaky singleton, destructor generally won't be called. |
dcheng | c2282aa | 2014-10-21 12:07:58 | [diff] [blame] | 87 | ~BrowserAccessibilityStateImpl() override; |
[email protected] | 18df736 | 2012-10-24 01:29:40 | [diff] [blame] | 88 | |
89 | void UpdatePlatformSpecificHistograms(); | ||||
90 | |||||
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 91 | // Updates the accessibility mode of all web contents, including swapped out |
[email protected] | 1e558fa | 2014-02-12 23:28:52 | [diff] [blame] | 92 | // ones. |add| specifies whether the mode should be added or removed. |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 93 | void AddOrRemoveFromAllWebContents(AccessibilityMode mode, bool add); |
[email protected] | 1e558fa | 2014-02-12 23:28:52 | [diff] [blame] | 94 | |
[email protected] | 18df736 | 2012-10-24 01:29:40 | [diff] [blame] | 95 | AccessibilityMode accessibility_mode_; |
[email protected] | ff42d4c9 | 2010-10-05 00:56:19 | [diff] [blame] | 96 | |
[email protected] | 8943015 | 2012-12-03 19:18:56 | [diff] [blame] | 97 | std::vector<base::Closure> histogram_callbacks_; |
98 | |||||
dmazzoni | dea5ba6 | 2015-02-03 19:27:24 | [diff] [blame] | 99 | bool disable_hot_tracking_; |
100 | |||||
[email protected] | fa4f9168 | 2012-02-21 19:53:26 | [diff] [blame] | 101 | DISALLOW_COPY_AND_ASSIGN(BrowserAccessibilityStateImpl); |
[email protected] | ff42d4c9 | 2010-10-05 00:56:19 | [diff] [blame] | 102 | }; |
103 | |||||
[email protected] | e6b3487 | 2012-10-24 20:51:32 | [diff] [blame] | 104 | } // namespace content |
105 | |||||
[email protected] | fa4f9168 | 2012-02-21 19:53:26 | [diff] [blame] | 106 | #endif // CONTENT_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_STATE_IMPL_H_ |