- add sources.
[platform/framework/web/crosswalk.git] / src / content / browser / accessibility / browser_accessibility_state_impl.h
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.
4
5 #ifndef CONTENT_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_STATE_IMPL_H_
6 #define CONTENT_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_STATE_IMPL_H_
7
8 #include <vector>
9
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "base/memory/singleton.h"
13 #include "content/common/view_message_enums.h"
14 #include "content/public/browser/browser_accessibility_state.h"
15
16 namespace content {
17
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
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();
40
41   static BrowserAccessibilityStateImpl* GetInstance();
42
43   virtual void EnableAccessibility() OVERRIDE;
44   virtual void DisableAccessibility() OVERRIDE;
45   virtual void OnScreenReaderDetected() OVERRIDE;
46   virtual bool IsAccessibleBrowser() OVERRIDE;
47   virtual void AddHistogramCallback(base::Closure callback) OVERRIDE;
48
49   virtual void UpdateHistogramsForTesting() OVERRIDE;
50
51   AccessibilityMode accessibility_mode() const { return accessibility_mode_; };
52   void SetAccessibilityMode(AccessibilityMode mode);
53
54  private:
55   friend class base::RefCountedThreadSafe<BrowserAccessibilityStateImpl>;
56   friend struct DefaultSingletonTraits<BrowserAccessibilityStateImpl>;
57
58   // Called a short while after startup to allow time for the accessibility
59   // state to be determined. Updates histograms with the current state.
60   void UpdateHistograms();
61
62   // Leaky singleton, destructor generally won't be called.
63   virtual ~BrowserAccessibilityStateImpl();
64
65   void UpdatePlatformSpecificHistograms();
66
67   AccessibilityMode accessibility_mode_;
68
69   std::vector<base::Closure> histogram_callbacks_;
70
71   DISALLOW_COPY_AND_ASSIGN(BrowserAccessibilityStateImpl);
72 };
73
74 }  // namespace content
75
76 #endif  // CONTENT_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_STATE_IMPL_H_