blob: 5beb762551f39d96edb97b15f51b1def808963f8 [file] [log] [blame]
[email protected]fa4f91682012-02-21 19:53:261// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]ff42d4c92010-10-05 00:56:192// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]fa4f91682012-02-21 19:53:265#ifndef CONTENT_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_STATE_IMPL_H_
6#define CONTENT_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_STATE_IMPL_H_
[email protected]ff42d4c92010-10-05 00:56:197
[email protected]89430152012-12-03 19:18:568#include <vector>
9
[email protected]ec6bf332012-03-16 21:43:4110#include "base/compiler_specific.h"
avib7348942015-12-25 20:57:1011#include "base/macros.h"
[email protected]18df7362012-10-24 01:29:4012#include "base/memory/singleton.h"
[email protected]95640212014-07-26 18:14:3013#include "content/common/accessibility_mode_enums.h"
[email protected]fa4f91682012-02-21 19:53:2614#include "content/public/browser/browser_accessibility_state.h"
[email protected]fee46a82010-12-09 16:42:1515
[email protected]e6b34872012-10-24 20:51:3216namespace content {
17
[email protected]ff42d4c92010-10-05 00:56:1918// 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]2fc66722011-05-19 14:43:1228// NotifiyWinEvent in NativeWidgetWin with a custom ID and wait to see if the ID
[email protected]ff42d4c92010-10-05 00:56:1929// is requested by a subsequent call to WM_GETOBJECT.
[email protected]f6855a0a2011-05-03 19:36:3830// (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]fa4f91682012-02-21 19:53:2635class CONTENT_EXPORT BrowserAccessibilityStateImpl
[email protected]18df7362012-10-24 01:29:4036 : public base::RefCountedThreadSafe<BrowserAccessibilityStateImpl>,
37 public BrowserAccessibilityState {
[email protected]ff42d4c92010-10-05 00:56:1938 public:
[email protected]b90cad72012-04-10 23:27:5339 BrowserAccessibilityStateImpl();
40
[email protected]fa4f91682012-02-21 19:53:2641 static BrowserAccessibilityStateImpl* GetInstance();
[email protected]ff42d4c92010-10-05 00:56:1942
dchengc2282aa2014-10-21 12:07:5843 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]ff42d4c92010-10-05 00:56:1949
dchengc2282aa2014-10-21 12:07:5850 void UpdateHistogramsForTesting() override;
[email protected]88c25052011-11-05 20:16:0551
[email protected]df376972013-05-03 21:45:0352 AccessibilityMode accessibility_mode() const { return accessibility_mode_; };
[email protected]1e558fa2014-02-12 23:28:5253
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]e2fa1cca42012-08-22 14:07:2762
dmazzonidea5ba62015-02-03 19:27:2463 // 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]18df7362012-10-24 01:29:4075 private:
76 friend class base::RefCountedThreadSafe<BrowserAccessibilityStateImpl>;
olli.raula36aa8be2015-09-10 11:14:2277 friend struct base::DefaultSingletonTraits<BrowserAccessibilityStateImpl>;
[email protected]88c25052011-11-05 20:16:0578
[email protected]1e558fa2014-02-12 23:28:5279 // Resets accessibility_mode_ to the default value.
80 void ResetAccessibilityModeValue();
81
[email protected]30fdb362013-01-09 02:33:2782 // 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]18df7362012-10-24 01:29:4086 // Leaky singleton, destructor generally won't be called.
dchengc2282aa2014-10-21 12:07:5887 ~BrowserAccessibilityStateImpl() override;
[email protected]18df7362012-10-24 01:29:4088
89 void UpdatePlatformSpecificHistograms();
90
[email protected]95640212014-07-26 18:14:3091 // Updates the accessibility mode of all web contents, including swapped out
[email protected]1e558fa2014-02-12 23:28:5292 // ones. |add| specifies whether the mode should be added or removed.
[email protected]95640212014-07-26 18:14:3093 void AddOrRemoveFromAllWebContents(AccessibilityMode mode, bool add);
[email protected]1e558fa2014-02-12 23:28:5294
[email protected]18df7362012-10-24 01:29:4095 AccessibilityMode accessibility_mode_;
[email protected]ff42d4c92010-10-05 00:56:1996
[email protected]89430152012-12-03 19:18:5697 std::vector<base::Closure> histogram_callbacks_;
98
dmazzonidea5ba62015-02-03 19:27:2499 bool disable_hot_tracking_;
100
[email protected]fa4f91682012-02-21 19:53:26101 DISALLOW_COPY_AND_ASSIGN(BrowserAccessibilityStateImpl);
[email protected]ff42d4c92010-10-05 00:56:19102};
103
[email protected]e6b34872012-10-24 20:51:32104} // namespace content
105
[email protected]fa4f91682012-02-21 19:53:26106#endif // CONTENT_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_STATE_IMPL_H_