Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/accessibility/browser_accessibility_state_impl.h" | 5 #include "content/browser/accessibility/browser_accessibility_state_impl.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/timer/timer.h" | 9 #include "base/timer/timer.h" |
| 10 #include "content/browser/renderer_host/render_widget_host_impl.h" | 10 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 29 } | 29 } |
| 30 | 30 |
| 31 // static | 31 // static |
| 32 BrowserAccessibilityStateImpl* BrowserAccessibilityStateImpl::GetInstance() { | 32 BrowserAccessibilityStateImpl* BrowserAccessibilityStateImpl::GetInstance() { |
| 33 return Singleton<BrowserAccessibilityStateImpl, | 33 return Singleton<BrowserAccessibilityStateImpl, |
| 34 LeakySingletonTraits<BrowserAccessibilityStateImpl> >::get(); | 34 LeakySingletonTraits<BrowserAccessibilityStateImpl> >::get(); |
| 35 } | 35 } |
| 36 | 36 |
| 37 BrowserAccessibilityStateImpl::BrowserAccessibilityStateImpl() | 37 BrowserAccessibilityStateImpl::BrowserAccessibilityStateImpl() |
| 38 : BrowserAccessibilityState(), | 38 : BrowserAccessibilityState(), |
| 39 accessibility_mode_(AccessibilityModeOff) { | 39 accessibility_mode_(0) { |
| 40 #if defined(OS_WIN) | 40 #if defined(OS_WIN) |
| 41 // On Windows 8, always enable accessibility for editable text controls | 41 // On Windows 8, always enable accessibility for editable text controls |
| 42 // so we can show the virtual keyboard when one is enabled. | 42 // so we can show the virtual keyboard when one is enabled. |
| 43 if (base::win::GetVersion() >= base::win::VERSION_WIN8 && | 43 if (base::win::GetVersion() >= base::win::VERSION_WIN8 && |
| 44 !CommandLine::ForCurrentProcess()->HasSwitch( | 44 !CommandLine::ForCurrentProcess()->HasSwitch( |
| 45 switches::kDisableRendererAccessibility)) { | 45 switches::kDisableRendererAccessibility)) { |
| 46 accessibility_mode_ = AccessibilityModeEditableTextOnly; | 46 accessibility_mode_ = |
| 47 AccessibilityModeFlagRenderer & AccessibilityModeFlagEditableTextOnly; | |
| 47 } | 48 } |
| 48 #endif // defined(OS_WIN) | 49 #endif // defined(OS_WIN) |
| 49 | 50 |
| 50 if (CommandLine::ForCurrentProcess()->HasSwitch( | 51 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 51 switches::kForceRendererAccessibility)) { | 52 switches::kForceRendererAccessibility)) { |
| 52 accessibility_mode_ = AccessibilityModeComplete; | 53 accessibility_mode_ = |
| 54 AccessibilityModeFlagRenderer & AccessibilityModeFlagPlatform; | |
| 53 } | 55 } |
| 54 | 56 |
| 55 #if defined(OS_WIN) | 57 #if defined(OS_WIN) |
| 56 // On Windows, UpdateHistograms calls some system functions with unknown | 58 // On Windows, UpdateHistograms calls some system functions with unknown |
| 57 // runtime, so call it on the file thread to ensure there's no jank. | 59 // runtime, so call it on the file thread to ensure there's no jank. |
| 58 // Everything in that method must be safe to call on another thread. | 60 // Everything in that method must be safe to call on another thread. |
| 59 BrowserThread::ID update_histogram_thread = BrowserThread::FILE; | 61 BrowserThread::ID update_histogram_thread = BrowserThread::FILE; |
| 60 #else | 62 #else |
| 61 // On all other platforms, UpdateHistograms should be called on the main | 63 // On all other platforms, UpdateHistograms should be called on the main |
| 62 // thread. | 64 // thread. |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 73 } | 75 } |
| 74 | 76 |
| 75 BrowserAccessibilityStateImpl::~BrowserAccessibilityStateImpl() { | 77 BrowserAccessibilityStateImpl::~BrowserAccessibilityStateImpl() { |
| 76 } | 78 } |
| 77 | 79 |
| 78 void BrowserAccessibilityStateImpl::OnScreenReaderDetected() { | 80 void BrowserAccessibilityStateImpl::OnScreenReaderDetected() { |
| 79 if (CommandLine::ForCurrentProcess()->HasSwitch( | 81 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 80 switches::kDisableRendererAccessibility)) { | 82 switches::kDisableRendererAccessibility)) { |
| 81 return; | 83 return; |
| 82 } | 84 } |
| 83 SetAccessibilityMode(AccessibilityModeComplete); | 85 SetAccessibilityMode(AccessibilityModeFlagRenderer | |
| 86 AccessibilityModeFlagPlatform); | |
| 84 } | 87 } |
| 85 | 88 |
| 86 void BrowserAccessibilityStateImpl::EnableAccessibility() { | 89 void BrowserAccessibilityStateImpl::EnableAccessibility() { |
| 87 // We may want to do something different with this later. | 90 // We may want to do something different with this later. |
| 88 SetAccessibilityMode(AccessibilityModeComplete); | 91 SetAccessibilityMode(AccessibilityModeFlagRenderer | |
| 92 AccessibilityModeFlagPlatform); | |
| 89 } | 93 } |
| 90 | 94 |
| 91 void BrowserAccessibilityStateImpl::DisableAccessibility() { | 95 void BrowserAccessibilityStateImpl::DisableAccessibility() { |
| 92 SetAccessibilityMode(AccessibilityModeOff); | 96 SetAccessibilityMode(0); |
|
David Tseng
2014/01/23 18:44:19
Add a name for 0 as well.
aboxhall
2014/01/27 18:03:15
Done.
| |
| 93 } | 97 } |
| 94 | 98 |
| 95 bool BrowserAccessibilityStateImpl::IsAccessibleBrowser() { | 99 bool BrowserAccessibilityStateImpl::IsAccessibleBrowser() { |
| 96 return (accessibility_mode_ == AccessibilityModeComplete); | 100 return ((accessibility_mode_ & AccessibilityModeFlagRenderer) && |
| 101 (accessibility_mode_ & AccessibilityModeFlagPlatform)); | |
| 97 } | 102 } |
| 98 | 103 |
| 99 void BrowserAccessibilityStateImpl::AddHistogramCallback( | 104 void BrowserAccessibilityStateImpl::AddHistogramCallback( |
| 100 base::Closure callback) { | 105 base::Closure callback) { |
| 101 histogram_callbacks_.push_back(callback); | 106 histogram_callbacks_.push_back(callback); |
| 102 } | 107 } |
| 103 | 108 |
| 104 void BrowserAccessibilityStateImpl::UpdateHistogramsForTesting() { | 109 void BrowserAccessibilityStateImpl::UpdateHistogramsForTesting() { |
| 105 UpdateHistograms(); | 110 UpdateHistograms(); |
| 106 } | 111 } |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 117 UMA_HISTOGRAM_BOOLEAN("Accessibility.ManuallyEnabled", | 122 UMA_HISTOGRAM_BOOLEAN("Accessibility.ManuallyEnabled", |
| 118 CommandLine::ForCurrentProcess()->HasSwitch( | 123 CommandLine::ForCurrentProcess()->HasSwitch( |
| 119 switches::kForceRendererAccessibility)); | 124 switches::kForceRendererAccessibility)); |
| 120 } | 125 } |
| 121 | 126 |
| 122 #if !defined(OS_WIN) | 127 #if !defined(OS_WIN) |
| 123 void BrowserAccessibilityStateImpl::UpdatePlatformSpecificHistograms() { | 128 void BrowserAccessibilityStateImpl::UpdatePlatformSpecificHistograms() { |
| 124 } | 129 } |
| 125 #endif | 130 #endif |
| 126 | 131 |
| 127 void BrowserAccessibilityStateImpl::SetAccessibilityMode( | 132 void BrowserAccessibilityStateImpl::SetAccessibilityMode(unsigned int mode) { |
| 128 AccessibilityMode mode) { | |
| 129 if (accessibility_mode_ == mode) | 133 if (accessibility_mode_ == mode) |
| 130 return; | 134 return; |
| 131 accessibility_mode_ = mode; | 135 accessibility_mode_ = mode; |
| 132 | 136 |
| 133 // Iterate over all RenderWidgetHosts, even swapped out ones in case | 137 // Iterate over all RenderWidgetHosts, even swapped out ones in case |
| 134 // they become active again. | 138 // they become active again. |
| 135 scoped_ptr<RenderWidgetHostIterator> widgets( | 139 scoped_ptr<RenderWidgetHostIterator> widgets( |
| 136 RenderWidgetHostImpl::GetAllRenderWidgetHosts()); | 140 RenderWidgetHostImpl::GetAllRenderWidgetHosts()); |
| 137 while (RenderWidgetHost* widget = widgets->GetNextHost()) { | 141 while (RenderWidgetHost* widget = widgets->GetNextHost()) { |
| 138 // Ignore processes that don't have a connection, such as crashed tabs. | 142 // Ignore processes that don't have a connection, such as crashed tabs. |
| 139 if (!widget->GetProcess()->HasConnection()) | 143 if (!widget->GetProcess()->HasConnection()) |
| 140 continue; | 144 continue; |
| 141 if (!widget->IsRenderView()) | 145 if (!widget->IsRenderView()) |
| 142 continue; | 146 continue; |
| 143 | 147 |
| 144 RenderWidgetHostImpl::From(widget)->SetAccessibilityMode(mode); | 148 RenderWidgetHostImpl::From(widget)->SetAccessibilityMode(mode); |
| 145 } | 149 } |
| 146 } | 150 } |
| 147 | 151 |
| 152 void BrowserAccessibilityStateImpl::SetRendererAccessibilityMode(bool on) { | |
| 153 if ((accessibility_mode_ & AccessibilityModeFlagRenderer) == on) | |
|
David Tseng
2014/01/23 18:44:19
This looks wrong; don't you want:
((accessibility_
aboxhall
2014/01/27 18:03:15
I don't think so. I want to check not whether it's
| |
| 154 return; | |
| 155 | |
| 156 if (on) | |
| 157 accessibility_mode_ |= AccessibilityModeFlagRenderer; | |
| 158 else | |
| 159 accessibility_mode_ &= (~AccessibilityModeFlagRenderer); | |
| 160 // Iterate over all RenderWidgetHosts, even swapped out ones in case | |
| 161 // they become active again. | |
| 162 scoped_ptr<RenderWidgetHostIterator> widgets( | |
| 163 RenderWidgetHostImpl::GetAllRenderWidgetHosts()); | |
| 164 while (RenderWidgetHost* widget = widgets->GetNextHost()) { | |
| 165 // Ignore processes that don't have a connection, such as crashed tabs. | |
| 166 if (!widget->GetProcess()->HasConnection()) | |
| 167 continue; | |
| 168 if (!widget->IsRenderView()) | |
| 169 continue; | |
| 170 | |
| 171 RenderWidgetHostImpl::From(widget) | |
| 172 ->SetAccessibilityMode(accessibility_mode_); | |
| 173 } | |
| 174 } | |
| 175 | |
| 148 } // namespace content | 176 } // namespace content |
| OLD | NEW |