Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(731)

Side by Side Diff: content/browser/accessibility/accessibility_ui.cc

Issue 2690653004: Expose a11y modes of web renderers to chrome://accessibility. (Closed)
Patch Set: Address dmazzoni comments Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | content/browser/resources/accessibility/accessibility.css » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/accessibility_ui.h" 5 #include "content/browser/accessibility/accessibility_ui.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 AccessibilityMode accessibility_mode, 74 AccessibilityMode accessibility_mode,
75 base::ProcessHandle handle = base::kNullProcessHandle) { 75 base::ProcessHandle handle = base::kNullProcessHandle) {
76 std::unique_ptr<base::DictionaryValue> target_data( 76 std::unique_ptr<base::DictionaryValue> target_data(
77 new base::DictionaryValue()); 77 new base::DictionaryValue());
78 target_data->SetInteger(kProcessIdField, process_id); 78 target_data->SetInteger(kProcessIdField, process_id);
79 target_data->SetInteger(kRouteIdField, route_id); 79 target_data->SetInteger(kRouteIdField, route_id);
80 target_data->SetString(kUrlField, url.spec()); 80 target_data->SetString(kUrlField, url.spec());
81 target_data->SetString(kNameField, net::EscapeForHTML(name)); 81 target_data->SetString(kNameField, net::EscapeForHTML(name));
82 target_data->SetInteger(kPidField, base::GetProcId(handle)); 82 target_data->SetInteger(kPidField, base::GetProcId(handle));
83 target_data->SetString(kFaviconUrlField, favicon_url.spec()); 83 target_data->SetString(kFaviconUrlField, favicon_url.spec());
84 target_data->SetBoolean( 84 target_data->SetInteger(kAccessibilityModeField, accessibility_mode);
85 kAccessibilityModeField,
86 0 != (accessibility_mode & ACCESSIBILITY_MODE_FLAG_WEB_CONTENTS));
87 return target_data; 85 return target_data;
88 } 86 }
89 87
90 std::unique_ptr<base::DictionaryValue> BuildTargetDescriptor( 88 std::unique_ptr<base::DictionaryValue> BuildTargetDescriptor(
91 RenderViewHost* rvh) { 89 RenderViewHost* rvh) {
92 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( 90 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>(
93 WebContents::FromRenderViewHost(rvh)); 91 WebContents::FromRenderViewHost(rvh));
94 AccessibilityMode accessibility_mode = AccessibilityModeOff; 92 AccessibilityMode accessibility_mode = AccessibilityModeOff;
95 93
96 std::string title; 94 std::string title;
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 WebUIDataSource::Add(browser_context, html_source); 212 WebUIDataSource::Add(browser_context, html_source);
215 } 213 }
216 214
217 AccessibilityUI::~AccessibilityUI() {} 215 AccessibilityUI::~AccessibilityUI() {}
218 216
219 void AccessibilityUI::ToggleAccessibility(const base::ListValue* args) { 217 void AccessibilityUI::ToggleAccessibility(const base::ListValue* args) {
220 std::string process_id_str; 218 std::string process_id_str;
221 std::string route_id_str; 219 std::string route_id_str;
222 int process_id; 220 int process_id;
223 int route_id; 221 int route_id;
224 CHECK_EQ(2U, args->GetSize()); 222 int mode;
223 CHECK_EQ(3U, args->GetSize());
225 CHECK(args->GetString(0, &process_id_str)); 224 CHECK(args->GetString(0, &process_id_str));
226 CHECK(args->GetString(1, &route_id_str)); 225 CHECK(args->GetString(1, &route_id_str));
226 CHECK(args->GetInteger(2, &mode));
227 CHECK(base::StringToInt(process_id_str, &process_id)); 227 CHECK(base::StringToInt(process_id_str, &process_id));
228 CHECK(base::StringToInt(route_id_str, &route_id)); 228 CHECK(base::StringToInt(route_id_str, &route_id));
229 229
230 RenderViewHost* rvh = RenderViewHost::FromID(process_id, route_id); 230 RenderViewHost* rvh = RenderViewHost::FromID(process_id, route_id);
231 if (!rvh) 231 if (!rvh)
232 return; 232 return;
233 auto* web_contents = 233 auto* web_contents =
234 static_cast<WebContentsImpl*>(WebContents::FromRenderViewHost(rvh)); 234 static_cast<WebContentsImpl*>(WebContents::FromRenderViewHost(rvh));
235 AccessibilityMode mode = web_contents->GetAccessibilityMode(); 235 AccessibilityMode current_mode = web_contents->GetAccessibilityMode();
236 // Note: this is slightly confusing, because: 236 // Flip the bits represented by |mode|. See accessibility_mode_enums.h for
237 // - Turning a11y ON for given web content will always turn it on, however 237 // values.
238 // - Turning a11y OFF for given web content will revert it to the 238 current_mode ^= mode;
239 // global state (not necessarily off) 239 web_contents->SetAccessibilityMode(current_mode);
240 // TODO(aleventhal): clear this up through chrome:/accessibility UI update
241 if ((mode & ACCESSIBILITY_MODE_COMPLETE) != ACCESSIBILITY_MODE_COMPLETE) {
242 web_contents->AddAccessibilityMode(ACCESSIBILITY_MODE_COMPLETE);
243 } else {
244 web_contents->SetAccessibilityMode(
245 BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode());
246 }
247 } 240 }
248 241
249 void AccessibilityUI::SetGlobalFlag(const base::ListValue* args) { 242 void AccessibilityUI::SetGlobalFlag(const base::ListValue* args) {
250 std::string flag_name_str; 243 std::string flag_name_str;
251 bool enabled; 244 bool enabled;
252 CHECK_EQ(2U, args->GetSize()); 245 CHECK_EQ(2U, args->GetSize());
253 CHECK(args->GetString(0, &flag_name_str)); 246 CHECK(args->GetString(0, &flag_name_str));
254 CHECK(args->GetBoolean(1, &enabled)); 247 CHECK(args->GetBoolean(1, &enabled));
255 248
256 if (flag_name_str == kInternal) { 249 if (flag_name_str == kInternal) {
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 formatter->FormatAccessibilityTree(ax_mgr->GetRoot(), 338 formatter->FormatAccessibilityTree(ax_mgr->GetRoot(),
346 &accessibility_contents_utf16); 339 &accessibility_contents_utf16);
347 result->Set("tree", 340 result->Set("tree",
348 new base::StringValue( 341 new base::StringValue(
349 base::UTF16ToUTF8(accessibility_contents_utf16))); 342 base::UTF16ToUTF8(accessibility_contents_utf16)));
350 web_ui()->CallJavascriptFunctionUnsafe("accessibility.showTree", 343 web_ui()->CallJavascriptFunctionUnsafe("accessibility.showTree",
351 *(result.get())); 344 *(result.get()));
352 } 345 }
353 346
354 } // namespace content 347 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/resources/accessibility/accessibility.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698