OLD | NEW |
---|---|
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" |
17 #include "ui/accessibility/ax_action_data.h" | 19 #include "ui/accessibility/ax_action_data.h" |
18 #include "ui/accessibility/ax_node_data.h" | 20 #include "ui/accessibility/ax_node_data.h" |
19 #include "ui/accessibility/ax_text_utils.h" | 21 #include "ui/accessibility/ax_text_utils.h" |
22 #include "ui/accessibility/ax_tree_data.h" | |
20 #include "ui/accessibility/platform/ax_platform_node_delegate.h" | 23 #include "ui/accessibility/platform/ax_platform_node_delegate.h" |
21 #include "ui/accessibility/platform/ax_platform_node_win.h" | 24 #include "ui/accessibility/platform/ax_platform_node_win.h" |
22 #include "ui/base/win/atl_module.h" | 25 #include "ui/base/win/atl_module.h" |
23 #include "ui/gfx/geometry/rect_conversions.h" | 26 #include "ui/gfx/geometry/rect_conversions.h" |
24 | 27 |
25 // | 28 // |
26 // Macros to use at the top of any AXPlatformNodeWin function that implements | 29 // Macros to use at the top of any AXPlatformNodeWin function that implements |
27 // a COM interface. Because COM objects are reference counted and clients | 30 // a COM interface. Because COM objects are reference counted and clients |
28 // are completely untrusted, it's important to always first check that our | 31 // 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 | 32 // object is still valid, and then check that all pointer arguments are |
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
529 | 532 |
530 STDMETHODIMP AXPlatformNodeWin::get_accHelp( | 533 STDMETHODIMP AXPlatformNodeWin::get_accHelp( |
531 VARIANT var_id, BSTR* help) { | 534 VARIANT var_id, BSTR* help) { |
532 COM_OBJECT_VALIDATE_1_ARG(help); | 535 COM_OBJECT_VALIDATE_1_ARG(help); |
533 return S_FALSE; | 536 return S_FALSE; |
534 } | 537 } |
535 | 538 |
536 STDMETHODIMP AXPlatformNodeWin::get_accValue(VARIANT var_id, BSTR* value) { | 539 STDMETHODIMP AXPlatformNodeWin::get_accValue(VARIANT var_id, BSTR* value) { |
537 AXPlatformNodeWin* target; | 540 AXPlatformNodeWin* target; |
538 COM_OBJECT_VALIDATE_VAR_ID_1_ARG_AND_GET_TARGET(var_id, value, target); | 541 COM_OBJECT_VALIDATE_VAR_ID_1_ARG_AND_GET_TARGET(var_id, value, target); |
539 return target->GetStringAttributeAsBstr(ui::AX_ATTR_VALUE, value); | 542 |
543 // get_accValue() has two sets of special cases depending on the node's role. | |
544 // The first set apply without regard for the nodes |value| attribute. That is | |
545 // the nodes value attribute isn't consider for the first set of special | |
546 // cases. For example, if the node role is AX_ROLE_COLOR_WELL, we do not care | |
547 // at all about the node's AX_ATTR_VALUE attribute. The second set of special | |
548 // cases only apply if the value attribute for the node is empty. That is, if | |
549 // AX_ATTR_VALUE is empty, we do something special. | |
550 | |
551 base::string16 result; | |
552 | |
553 // | |
554 // Color Well special case (Use AX_ATTR_COLOR_VALUE) | |
555 // | |
556 if (target->GetData().role == ui::AX_ROLE_COLOR_WELL) { | |
557 unsigned int color = static_cast<unsigned int>(target->GetIntAttribute( | |
558 ui::AX_ATTR_COLOR_VALUE)); // todo, why the static cast? | |
559 | |
560 // To avoid a dependency on third_party/skia, we will just | |
dmazzoni
2017/06/15 06:24:48
We already depend on //skia, I'd just add the depe
| |
561 // duplicate these macros here: | |
562 /** return the red byte from a SkColor value */ | |
563 #define SkColorGetR(color) (((color) >> 16) & 0xFF) | |
564 /** return the green byte from a SkColor value */ | |
565 #define SkColorGetG(color) (((color) >> 8) & 0xFF) | |
566 /** return the blue byte from a SkColor value */ | |
567 #define SkColorGetB(color) (((color) >> 0) & 0xFF) | |
568 | |
569 unsigned int red = SkColorGetR(color); | |
570 unsigned int green = SkColorGetG(color); | |
571 unsigned int blue = SkColorGetB(color); | |
572 base::string16 value_text; | |
573 value_text = base::UintToString16(red * 100 / 255) + L"% red " + | |
574 base::UintToString16(green * 100 / 255) + L"% green " + | |
575 base::UintToString16(blue * 100 / 255) + L"% blue"; | |
576 *value = SysAllocString(value_text.c_str()); | |
577 DCHECK(*value); | |
578 return S_OK; | |
579 } | |
580 | |
581 // | |
582 // Document special case (Use the document's url) | |
583 // | |
584 if (target->GetData().role == ui::AX_ROLE_ROOT_WEB_AREA || | |
585 target->GetData().role == ui::AX_ROLE_WEB_AREA) { | |
586 result = base::UTF8ToUTF16(target->delegate_->GetTreeData().url); | |
587 *value = SysAllocString(result.c_str()); | |
588 DCHECK(*value); | |
589 return S_OK; | |
590 } | |
591 | |
592 // | |
593 // Links (Use AX_ATTR_URL) | |
594 // | |
595 if (target->GetData().role == ui::AX_ROLE_LINK || | |
596 target->GetData().role == ui::AX_ROLE_IMAGE_MAP_LINK) { | |
597 result = target->GetString16Attribute(ui::AX_ATTR_URL); | |
598 *value = SysAllocString(result.c_str()); | |
599 DCHECK(*value); | |
600 return S_OK; | |
601 } | |
602 | |
603 // After this point, the role based special cases should test for an empty | |
604 // result. | |
605 | |
606 result = target->GetString16Attribute(ui::AX_ATTR_VALUE); | |
607 | |
608 // | |
609 // RangeValue (Use AX_ATTR_VALUE_FOR_RANGE) | |
610 // | |
611 if (result.empty() && target->IsRangeValueSupported()) { | |
612 float fval; | |
613 if (target->GetFloatAttribute(ui::AX_ATTR_VALUE_FOR_RANGE, &fval)) { | |
614 result = base::UTF8ToUTF16(base::DoubleToString(fval)); | |
615 *value = SysAllocString(result.c_str()); | |
616 DCHECK(*value); | |
617 return S_OK; | |
618 } | |
619 } | |
620 | |
621 // Last resort (Use innerText) | |
622 if (result.empty() && | |
623 (target->IsSimpleTextControl() || target->IsRichTextControl()) && | |
624 !target->IsNativeTextControl()) { | |
625 result = target->GetInnerText(); | |
626 } | |
627 | |
628 *value = SysAllocString(result.c_str()); | |
629 DCHECK(*value); | |
630 return S_OK; | |
540 } | 631 } |
541 | 632 |
542 STDMETHODIMP AXPlatformNodeWin::put_accValue(VARIANT var_id, | 633 STDMETHODIMP AXPlatformNodeWin::put_accValue(VARIANT var_id, |
543 BSTR new_value) { | 634 BSTR new_value) { |
544 AXPlatformNodeWin* target; | 635 AXPlatformNodeWin* target; |
545 COM_OBJECT_VALIDATE_VAR_ID_AND_GET_TARGET(var_id, target); | 636 COM_OBJECT_VALIDATE_VAR_ID_AND_GET_TARGET(var_id, target); |
546 | 637 |
547 AXActionData data; | 638 AXActionData data; |
548 data.action = ui::AX_ACTION_SET_VALUE; | 639 data.action = ui::AX_ACTION_SET_VALUE; |
549 data.value = new_value; | 640 data.value = new_value; |
(...skipping 1165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1715 | 1806 |
1716 AXPlatformNodeBase* base = | 1807 AXPlatformNodeBase* base = |
1717 FromNativeViewAccessible(node->GetNativeViewAccessible()); | 1808 FromNativeViewAccessible(node->GetNativeViewAccessible()); |
1718 if (base && !IsDescendant(base)) | 1809 if (base && !IsDescendant(base)) |
1719 base = nullptr; | 1810 base = nullptr; |
1720 | 1811 |
1721 return static_cast<AXPlatformNodeWin*>(base); | 1812 return static_cast<AXPlatformNodeWin*>(base); |
1722 } | 1813 } |
1723 | 1814 |
1724 } // namespace ui | 1815 } // namespace ui |
OLD | NEW |