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

Side by Side Diff: ui/accessibility/platform/ax_platform_node_win.cc

Issue 2933353002: Forward four more BrowserAccessibility APIs to AXPlatformNode. (Closed)
Patch Set: Use SkColor.h instead Created 3 years, 6 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 <atlbase.h> 5 #include <atlbase.h>
6 #include <atlcom.h> 6 #include <atlcom.h>
7 #include <limits.h> 7 #include <limits.h>
8 #include <oleacc.h> 8 #include <oleacc.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
11 #include "base/containers/hash_tables.h" 11 #include "base/containers/hash_tables.h"
12 #include "base/lazy_instance.h" 12 #include "base/lazy_instance.h"
13 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
15 #include "base/strings/utf_string_conversions.h"
14 #include "base/win/scoped_comptr.h" 16 #include "base/win/scoped_comptr.h"
15 #include "base/win/scoped_variant.h" 17 #include "base/win/scoped_variant.h"
16 #include "third_party/iaccessible2/ia2_api_all.h" 18 #include "third_party/iaccessible2/ia2_api_all.h"
19 #include "third_party/skia/include/core/SkColor.h"
17 #include "ui/accessibility/ax_action_data.h" 20 #include "ui/accessibility/ax_action_data.h"
18 #include "ui/accessibility/ax_node_data.h" 21 #include "ui/accessibility/ax_node_data.h"
19 #include "ui/accessibility/ax_text_utils.h" 22 #include "ui/accessibility/ax_text_utils.h"
23 #include "ui/accessibility/ax_tree_data.h"
20 #include "ui/accessibility/platform/ax_platform_node_delegate.h" 24 #include "ui/accessibility/platform/ax_platform_node_delegate.h"
21 #include "ui/accessibility/platform/ax_platform_node_win.h" 25 #include "ui/accessibility/platform/ax_platform_node_win.h"
22 #include "ui/base/win/atl_module.h" 26 #include "ui/base/win/atl_module.h"
23 #include "ui/gfx/geometry/rect_conversions.h" 27 #include "ui/gfx/geometry/rect_conversions.h"
24 28
25 // 29 //
26 // Macros to use at the top of any AXPlatformNodeWin function that implements 30 // Macros to use at the top of any AXPlatformNodeWin function that implements
27 // a COM interface. Because COM objects are reference counted and clients 31 // a COM interface. Because COM objects are reference counted and clients
28 // are completely untrusted, it's important to always first check that our 32 // are completely untrusted, it's important to always first check that our
29 // object is still valid, and then check that all pointer arguments are 33 // object is still valid, and then check that all pointer arguments are
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 533
530 STDMETHODIMP AXPlatformNodeWin::get_accHelp( 534 STDMETHODIMP AXPlatformNodeWin::get_accHelp(
531 VARIANT var_id, BSTR* help) { 535 VARIANT var_id, BSTR* help) {
532 COM_OBJECT_VALIDATE_1_ARG(help); 536 COM_OBJECT_VALIDATE_1_ARG(help);
533 return S_FALSE; 537 return S_FALSE;
534 } 538 }
535 539
536 STDMETHODIMP AXPlatformNodeWin::get_accValue(VARIANT var_id, BSTR* value) { 540 STDMETHODIMP AXPlatformNodeWin::get_accValue(VARIANT var_id, BSTR* value) {
537 AXPlatformNodeWin* target; 541 AXPlatformNodeWin* target;
538 COM_OBJECT_VALIDATE_VAR_ID_1_ARG_AND_GET_TARGET(var_id, value, target); 542 COM_OBJECT_VALIDATE_VAR_ID_1_ARG_AND_GET_TARGET(var_id, value, target);
539 return target->GetStringAttributeAsBstr(ui::AX_ATTR_VALUE, value); 543
544 // get_accValue() has two sets of special cases depending on the node's role.
545 // The first set apply without regard for the nodes |value| attribute. That is
546 // the nodes value attribute isn't consider for the first set of special
547 // cases. For example, if the node role is AX_ROLE_COLOR_WELL, we do not care
548 // at all about the node's AX_ATTR_VALUE attribute. The second set of special
549 // cases only apply if the value attribute for the node is empty. That is, if
550 // AX_ATTR_VALUE is empty, we do something special.
551
552 base::string16 result;
553
554 //
555 // Color Well special case (Use AX_ATTR_COLOR_VALUE)
556 //
557 if (target->GetData().role == ui::AX_ROLE_COLOR_WELL) {
558 unsigned int color = static_cast<unsigned int>(target->GetIntAttribute(
559 ui::AX_ATTR_COLOR_VALUE)); // todo, why the static cast?
560
561 unsigned int red = SkColorGetR(color);
562 unsigned int green = SkColorGetG(color);
563 unsigned int blue = SkColorGetB(color);
564 base::string16 value_text;
565 value_text = base::UintToString16(red * 100 / 255) + L"% red " +
566 base::UintToString16(green * 100 / 255) + L"% green " +
567 base::UintToString16(blue * 100 / 255) + L"% blue";
568 *value = SysAllocString(value_text.c_str());
569 DCHECK(*value);
570 return S_OK;
571 }
572
573 //
574 // Document special case (Use the document's url)
575 //
576 if (target->GetData().role == ui::AX_ROLE_ROOT_WEB_AREA ||
577 target->GetData().role == ui::AX_ROLE_WEB_AREA) {
578 result = base::UTF8ToUTF16(target->delegate_->GetTreeData().url);
579 *value = SysAllocString(result.c_str());
580 DCHECK(*value);
581 return S_OK;
582 }
583
584 //
585 // Links (Use AX_ATTR_URL)
586 //
587 if (target->GetData().role == ui::AX_ROLE_LINK ||
588 target->GetData().role == ui::AX_ROLE_IMAGE_MAP_LINK) {
589 result = target->GetString16Attribute(ui::AX_ATTR_URL);
590 *value = SysAllocString(result.c_str());
591 DCHECK(*value);
592 return S_OK;
593 }
594
595 // After this point, the role based special cases should test for an empty
596 // result.
597
598 result = target->GetString16Attribute(ui::AX_ATTR_VALUE);
599
600 //
601 // RangeValue (Use AX_ATTR_VALUE_FOR_RANGE)
602 //
603 if (result.empty() && target->IsRangeValueSupported()) {
604 float fval;
605 if (target->GetFloatAttribute(ui::AX_ATTR_VALUE_FOR_RANGE, &fval)) {
606 result = base::UTF8ToUTF16(base::DoubleToString(fval));
607 *value = SysAllocString(result.c_str());
608 DCHECK(*value);
609 return S_OK;
610 }
611 }
612
613 // Last resort (Use innerText)
614 if (result.empty() &&
615 (target->IsSimpleTextControl() || target->IsRichTextControl()) &&
616 !target->IsNativeTextControl()) {
617 result = target->GetInnerText();
618 }
619
620 *value = SysAllocString(result.c_str());
621 DCHECK(*value);
622 return S_OK;
540 } 623 }
541 624
542 STDMETHODIMP AXPlatformNodeWin::put_accValue(VARIANT var_id, 625 STDMETHODIMP AXPlatformNodeWin::put_accValue(VARIANT var_id,
543 BSTR new_value) { 626 BSTR new_value) {
544 AXPlatformNodeWin* target; 627 AXPlatformNodeWin* target;
545 COM_OBJECT_VALIDATE_VAR_ID_AND_GET_TARGET(var_id, target); 628 COM_OBJECT_VALIDATE_VAR_ID_AND_GET_TARGET(var_id, target);
546 629
547 AXActionData data; 630 AXActionData data;
548 data.action = ui::AX_ACTION_SET_VALUE; 631 data.action = ui::AX_ACTION_SET_VALUE;
549 data.value = new_value; 632 data.value = new_value;
(...skipping 1066 matching lines...) Expand 10 before | Expand all | Expand 10 after
1616 1699
1617 AXPlatformNodeBase* base = 1700 AXPlatformNodeBase* base =
1618 FromNativeViewAccessible(node->GetNativeViewAccessible()); 1701 FromNativeViewAccessible(node->GetNativeViewAccessible());
1619 if (base && !IsDescendant(base)) 1702 if (base && !IsDescendant(base))
1620 base = nullptr; 1703 base = nullptr;
1621 1704
1622 return static_cast<AXPlatformNodeWin*>(base); 1705 return static_cast<AXPlatformNodeWin*>(base);
1623 } 1706 }
1624 1707
1625 } // namespace ui 1708 } // namespace ui
OLDNEW
« no previous file with comments | « ui/accessibility/platform/ax_platform_node_delegate.h ('k') | ui/accessibility/platform/test_ax_node_wrapper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698