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

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

Issue 1130733006: Adds color, font size, text direction and text styles to the accessibility tree. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: First attempt at exposing style info to the native APIs. Created 5 years, 7 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
OLDNEW
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_win.h" 5 #include "content/browser/accessibility/browser_accessibility_win.h"
6 6
7 #include <UIAutomationClient.h> 7 #include <UIAutomationClient.h>
8 #include <UIAutomationCoreApi.h> 8 #include <UIAutomationCoreApi.h>
9 9
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 target->ia_role() == ROLE_SYSTEM_SCROLLBAR || 598 target->ia_role() == ROLE_SYSTEM_SCROLLBAR ||
599 target->ia_role() == ROLE_SYSTEM_SLIDER) { 599 target->ia_role() == ROLE_SYSTEM_SLIDER) {
600 base::string16 value_text = target->GetValueText(); 600 base::string16 value_text = target->GetValueText();
601 *value = SysAllocString(value_text.c_str()); 601 *value = SysAllocString(value_text.c_str());
602 DCHECK(*value); 602 DCHECK(*value);
603 return S_OK; 603 return S_OK;
604 } 604 }
605 605
606 // Expose color well value. 606 // Expose color well value.
607 if (target->ia2_role() == IA2_ROLE_COLOR_CHOOSER) { 607 if (target->ia2_role() == IA2_ROLE_COLOR_CHOOSER) {
608 int r = target->GetIntAttribute( 608 int color = target->GetIntAttribute(ui::AX_ATTR_COLOR_VALUE);
609 ui::AX_ATTR_COLOR_VALUE_RED); 609 int red = (color >> 16) & 0xFF;
610 int g = target->GetIntAttribute( 610 int green = (color >> 8) & 0xFF;
611 ui::AX_ATTR_COLOR_VALUE_GREEN); 611 int blue = color & 0xFF;
612 int b = target->GetIntAttribute(
613 ui::AX_ATTR_COLOR_VALUE_BLUE);
614 base::string16 value_text; 612 base::string16 value_text;
615 value_text = base::IntToString16((r * 100) / 255) + L"% red " + 613 value_text = base::IntToString16((red * 100) / 255) + L"% red " +
616 base::IntToString16((g * 100) / 255) + L"% green " + 614 base::IntToString16((green * 100) / 255) + L"% green " +
617 base::IntToString16((b * 100) / 255) + L"% blue"; 615 base::IntToString16((blue * 100) / 255) + L"% blue";
618 *value = SysAllocString(value_text.c_str()); 616 *value = SysAllocString(value_text.c_str());
619 DCHECK(*value); 617 DCHECK(*value);
620 return S_OK; 618 return S_OK;
621 } 619 }
622 620
623 *value = SysAllocString(target->value().c_str()); 621 *value = SysAllocString(target->value().c_str());
624 DCHECK(*value); 622 DCHECK(*value);
625 return S_OK; 623 return S_OK;
626 } 624 }
627 625
(...skipping 1747 matching lines...) Expand 10 before | Expand all | Expand 10 after
2375 return E_INVALIDARG; 2373 return E_INVALIDARG;
2376 2374
2377 const base::string16& text_str = TextForIAccessibleText(); 2375 const base::string16& text_str = TextForIAccessibleText();
2378 HandleSpecialTextOffset(text_str, &start_offset); 2376 HandleSpecialTextOffset(text_str, &start_offset);
2379 HandleSpecialTextOffset(text_str, &end_offset); 2377 HandleSpecialTextOffset(text_str, &end_offset);
2380 2378
2381 manager()->SetTextSelection(*this, start_offset, end_offset); 2379 manager()->SetTextSelection(*this, start_offset, end_offset);
2382 return S_OK; 2380 return S_OK;
2383 } 2381 }
2384 2382
2385 //
2386 // IAccessibleText methods not implemented.
2387 //
2388
2389 STDMETHODIMP BrowserAccessibilityWin::get_attributes(LONG offset, 2383 STDMETHODIMP BrowserAccessibilityWin::get_attributes(LONG offset,
2390 LONG* start_offset, 2384 LONG* start_offset,
2391 LONG* end_offset, 2385 LONG* end_offset,
2392 BSTR* text_attributes) { 2386 BSTR* text_attributes) {
2393 return E_NOTIMPL; 2387 if (!instance_active())
2388 return E_FAIL;
2389
2390 if (!start_offset || !end_offset || !text_attributes)
2391 return E_INVALIDARG;
2392
2393 const base::string16& text_str = TextForIAccessibleText();
2394 HandleSpecialTextOffset(text_str, &offset);
2395 if (offset < 0)
2396 return E_INVALIDARG;
2397
2398 LONG text_len = text_str.length();
2399 if (offset > text_len)
2400 return E_INVALIDARG;
2401
2402 base::string16 attributes_str = GetTextAttributes();
2403 if (attributes_str.empty()) {
2404 *start_offset = 0;
2405 *end_offset = 0;
2406 return S_FALSE;
2407 }
2408
2409 *text_attributes = SysAllocString(attributes_str.c_str());
2410 DCHECK(*text_attributes);
2411 *start_offset = GetStyleChangeBoundary(offset, ui::BACKWARDS_DIRECTION);
2412 *end_offset = GetStyleChangeBoundary(offset, ui::FORWARDS_DIRECTION);
2413 return S_OK;
2394 } 2414 }
2395 2415
2396 // 2416 //
2397 // IAccessibleHypertext methods. 2417 // IAccessibleHypertext methods.
2398 // 2418 //
2399 2419
2400 STDMETHODIMP BrowserAccessibilityWin::get_nHyperlinks(long* hyperlink_count) { 2420 STDMETHODIMP BrowserAccessibilityWin::get_nHyperlinks(long* hyperlink_count) {
2401 if (!instance_active()) 2421 if (!instance_active())
2402 return E_FAIL; 2422 return E_FAIL;
2403 2423
(...skipping 1154 matching lines...) Expand 10 before | Expand all | Expand 10 after
3558 3578
3559 bool BrowserAccessibilityWin::IsNative() const { 3579 bool BrowserAccessibilityWin::IsNative() const {
3560 return true; 3580 return true;
3561 } 3581 }
3562 3582
3563 void BrowserAccessibilityWin::OnLocationChanged() { 3583 void BrowserAccessibilityWin::OnLocationChanged() {
3564 manager()->ToBrowserAccessibilityManagerWin()->MaybeCallNotifyWinEvent( 3584 manager()->ToBrowserAccessibilityManagerWin()->MaybeCallNotifyWinEvent(
3565 EVENT_OBJECT_LOCATIONCHANGE, this); 3585 EVENT_OBJECT_LOCATIONCHANGE, this);
3566 } 3586 }
3567 3587
3588 //
3589 // Private methods.
3590 //
3591
3592 base::string16 BrowserAccessibilityWin::GetTextAttributes() const {
3593 base::string16 text_attributes;
3594 int background_color = GetIntAttribute(ui::AX_ATTR_BACKGROUND_COLOR);
3595 int color = GetIntAttribute(ui::AX_ATTR_COLOR);
3596 float font_size = GetFloatAttribute(ui::AX_ATTR_FONT_SIZE);
3597 int red = (color >> 16) & 0xFF;
3598 int green = (color >> 8) & 0xFF;
3599 int blue = color & 0xFF;
3600 base::string16 value_text;
3601 value_text = base::IntToString16((red * 100) / 255) + L"% red " +
3602 base::IntToString16((green * 100) / 255) + L"% green " +
3603 base::IntToString16((blue * 100) / 255) + L"% blue";
3604 *value = SysAllocString(value_text.c_str());
3605 DCHECK(*value);
3606 return text_attributes;
3607 }
3608
3568 BrowserAccessibilityWin* BrowserAccessibilityWin::NewReference() { 3609 BrowserAccessibilityWin* BrowserAccessibilityWin::NewReference() {
3569 AddRef(); 3610 AddRef();
3570 return this; 3611 return this;
3571 } 3612 }
3572 3613
3573 BrowserAccessibilityWin* BrowserAccessibilityWin::GetTargetFromChildID( 3614 BrowserAccessibilityWin* BrowserAccessibilityWin::GetTargetFromChildID(
3574 const VARIANT& var_id) { 3615 const VARIANT& var_id) {
3575 if (var_id.vt != VT_I4) 3616 if (var_id.vt != VT_I4)
3576 return NULL; 3617 return NULL;
3577 3618
(...skipping 772 matching lines...) Expand 10 before | Expand all | Expand 10 after
4350 ia2_role = ia_role; 4391 ia2_role = ia_role;
4351 4392
4352 win_attributes_->ia_role = ia_role; 4393 win_attributes_->ia_role = ia_role;
4353 win_attributes_->ia_state = ia_state; 4394 win_attributes_->ia_state = ia_state;
4354 win_attributes_->role_name = role_name; 4395 win_attributes_->role_name = role_name;
4355 win_attributes_->ia2_role = ia2_role; 4396 win_attributes_->ia2_role = ia2_role;
4356 win_attributes_->ia2_state = ia2_state; 4397 win_attributes_->ia2_state = ia2_state;
4357 } 4398 }
4358 4399
4359 } // namespace content 4400 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/accessibility/browser_accessibility_win.h ('k') | content/renderer/accessibility/blink_ax_enum_conversion.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698