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 #ifndef CONTENT_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_WIN_H_ | 5 #ifndef CONTENT_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_WIN_H_ |
6 #define CONTENT_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_WIN_H_ | 6 #define CONTENT_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_WIN_H_ |
7 | 7 |
8 #include <atlbase.h> | 8 #include <atlbase.h> |
9 #include <atlcom.h> | 9 #include <atlcom.h> |
10 #include <oleacc.h> | 10 #include <oleacc.h> |
11 #include <stddef.h> | 11 #include <stddef.h> |
12 #include <stdint.h> | 12 #include <stdint.h> |
13 #include <UIAutomationCore.h> | 13 #include <UIAutomationCore.h> |
14 | 14 |
15 #include <vector> | 15 #include <vector> |
16 | 16 |
17 #include "base/compiler_specific.h" | 17 #include "base/compiler_specific.h" |
| 18 #include "base/containers/hash_tables.h" |
18 #include "base/gtest_prod_util.h" | 19 #include "base/gtest_prod_util.h" |
19 #include "base/macros.h" | 20 #include "base/macros.h" |
20 #include "content/browser/accessibility/browser_accessibility.h" | 21 #include "content/browser/accessibility/browser_accessibility.h" |
21 #include "content/common/content_export.h" | 22 #include "content/common/content_export.h" |
22 #include "third_party/iaccessible2/ia2_api_all.h" | 23 #include "third_party/iaccessible2/ia2_api_all.h" |
23 #include "third_party/isimpledom/ISimpleDOMDocument.h" | 24 #include "third_party/isimpledom/ISimpleDOMDocument.h" |
24 #include "third_party/isimpledom/ISimpleDOMNode.h" | 25 #include "third_party/isimpledom/ISimpleDOMNode.h" |
25 #include "third_party/isimpledom/ISimpleDOMText.h" | 26 #include "third_party/isimpledom/ISimpleDOMText.h" |
26 | 27 |
27 namespace ui { | 28 namespace ui { |
(...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
716 int32_t ia_state() const { return win_attributes_->ia_state; } | 717 int32_t ia_state() const { return win_attributes_->ia_state; } |
717 const base::string16& role_name() const { return win_attributes_->role_name; } | 718 const base::string16& role_name() const { return win_attributes_->role_name; } |
718 int32_t ia2_role() const { return win_attributes_->ia2_role; } | 719 int32_t ia2_role() const { return win_attributes_->ia2_role; } |
719 int32_t ia2_state() const { return win_attributes_->ia2_state; } | 720 int32_t ia2_state() const { return win_attributes_->ia2_state; } |
720 const std::vector<base::string16>& ia2_attributes() const { | 721 const std::vector<base::string16>& ia2_attributes() const { |
721 return win_attributes_->ia2_attributes; | 722 return win_attributes_->ia2_attributes; |
722 } | 723 } |
723 base::string16 name() const { return win_attributes_->name; } | 724 base::string16 name() const { return win_attributes_->name; } |
724 base::string16 description() const { return win_attributes_->description; } | 725 base::string16 description() const { return win_attributes_->description; } |
725 base::string16 value() const { return win_attributes_->value; } | 726 base::string16 value() const { return win_attributes_->value; } |
| 727 const base::hash_map<int, std::vector<base::string16>>& |
| 728 offset_to_text_attributes() const { |
| 729 return win_attributes_->offset_to_text_attributes; |
| 730 } |
726 std::map<int32_t, int32_t>& hyperlink_offset_to_index() const { | 731 std::map<int32_t, int32_t>& hyperlink_offset_to_index() const { |
727 return win_attributes_->hyperlink_offset_to_index; | 732 return win_attributes_->hyperlink_offset_to_index; |
728 } | 733 } |
729 std::vector<int32_t>& hyperlinks() const { | 734 std::vector<int32_t>& hyperlinks() const { |
730 return win_attributes_->hyperlinks; | 735 return win_attributes_->hyperlinks; |
731 } | 736 } |
732 | 737 |
733 private: | 738 private: |
| 739 // Returns the IA2 text attributes for this object. |
| 740 std::vector<base::string16> ComputeTextAttributes() const; |
| 741 |
734 // Add one to the reference count and return the same object. Always | 742 // Add one to the reference count and return the same object. Always |
735 // use this method when returning a BrowserAccessibilityWin object as | 743 // use this method when returning a BrowserAccessibilityWin object as |
736 // an output parameter to a COM interface, never use it otherwise. | 744 // an output parameter to a COM interface, never use it otherwise. |
737 BrowserAccessibilityWin* NewReference(); | 745 BrowserAccessibilityWin* NewReference(); |
738 | 746 |
739 // Many MSAA methods take a var_id parameter indicating that the operation | 747 // Many MSAA methods take a var_id parameter indicating that the operation |
740 // should be performed on a particular child ID, rather than this object. | 748 // should be performed on a particular child ID, rather than this object. |
741 // This method tries to figure out the target object from |var_id| and | 749 // This method tries to figure out the target object from |var_id| and |
742 // returns a pointer to the target object if it exists, otherwise NULL. | 750 // returns a pointer to the target object if it exists, otherwise NULL. |
743 // Does not return a new reference. | 751 // Does not return a new reference. |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
779 | 787 |
780 // | 788 // |
781 // Helper methods for IA2 hyperlinks. | 789 // Helper methods for IA2 hyperlinks. |
782 // | 790 // |
783 // Hyperlink is an IA2 misnomer. It refers to objects embedded within other | 791 // Hyperlink is an IA2 misnomer. It refers to objects embedded within other |
784 // objects, such as a numbered list within a contenteditable div. | 792 // objects, such as a numbered list within a contenteditable div. |
785 // Also, in IA2, text that includes embedded objects is called hypertext. | 793 // Also, in IA2, text that includes embedded objects is called hypertext. |
786 | 794 |
787 // Returns true if the current object is an IA2 hyperlink. | 795 // Returns true if the current object is an IA2 hyperlink. |
788 bool IsHyperlink() const; | 796 bool IsHyperlink() const; |
| 797 // Returns the hyperlink at the given text position, or nullptr if no |
| 798 // hyperlink can be found. |
| 799 BrowserAccessibilityWin* GetHyperlinkFromHypertextOffset(int offset) const; |
789 | 800 |
790 // Functions for retrieving offsets for hyperlinks and hypertext. | 801 // Functions for retrieving offsets for hyperlinks and hypertext. |
791 // Return -1 in case of failure. | 802 // Return -1 in case of failure. |
792 int32_t GetHyperlinkIndexFromChild( | 803 int32_t GetHyperlinkIndexFromChild( |
793 const BrowserAccessibilityWin& child) const; | 804 const BrowserAccessibilityWin& child) const; |
794 int32_t GetHypertextOffsetFromHyperlinkIndex(int32_t hyperlink_index) const; | 805 int32_t GetHypertextOffsetFromHyperlinkIndex(int32_t hyperlink_index) const; |
795 int32_t GetHypertextOffsetFromChild( | 806 int32_t GetHypertextOffsetFromChild( |
796 const BrowserAccessibilityWin& child) const; | 807 const BrowserAccessibilityWin& child) const; |
797 int32_t GetHypertextOffsetFromDescendant( | 808 int32_t GetHypertextOffsetFromDescendant( |
798 const BrowserAccessibilityWin& descendant) const; | 809 const BrowserAccessibilityWin& descendant) const; |
(...skipping 26 matching lines...) Expand all Loading... |
825 void GetSelectionOffsets(int* selection_start, int* selection_end) const; | 836 void GetSelectionOffsets(int* selection_start, int* selection_end) const; |
826 | 837 |
827 // Get the value text, which might come from the floating-point | 838 // Get the value text, which might come from the floating-point |
828 // value for some roles. | 839 // value for some roles. |
829 base::string16 GetValueText(); | 840 base::string16 GetValueText(); |
830 | 841 |
831 bool IsSameHypertextCharacter(size_t old_char_index, size_t new_char_index); | 842 bool IsSameHypertextCharacter(size_t old_char_index, size_t new_char_index); |
832 void ComputeHypertextRemovedAndInserted( | 843 void ComputeHypertextRemovedAndInserted( |
833 int* start, int* old_len, int* new_len); | 844 int* start, int* old_len, int* new_len); |
834 | 845 |
| 846 // Computes and caches the IA2 text style attributes for the text and other |
| 847 // embedded child objects. |
| 848 void MayBeComputeStyles(); |
| 849 |
835 // If offset is a member of IA2TextSpecialOffsets this function updates the | 850 // If offset is a member of IA2TextSpecialOffsets this function updates the |
836 // value of offset and returns, otherwise offset remains unchanged. | 851 // value of offset and returns, otherwise offset remains unchanged. |
837 void HandleSpecialTextOffset(const base::string16& text, LONG* offset); | 852 void HandleSpecialTextOffset(const base::string16& text, LONG* offset); |
838 | 853 |
839 // Convert from a IA2TextBoundaryType to a ui::TextBoundaryType. | 854 // Convert from a IA2TextBoundaryType to a ui::TextBoundaryType. |
840 ui::TextBoundaryType IA2TextBoundaryToTextBoundary(IA2TextBoundaryType type); | 855 ui::TextBoundaryType IA2TextBoundaryToTextBoundary(IA2TextBoundaryType type); |
841 | 856 |
842 // Search forwards (direction == 1) or backwards (direction == -1) | 857 // Search forwards (direction == 1) or backwards (direction == -1) |
843 // from the given offset until the given boundary is found, and | 858 // from the given offset until the given boundary is found, and |
844 // return the offset of that boundary. | 859 // return the offset of that boundary. |
845 LONG FindBoundary(const base::string16& text, | 860 LONG FindBoundary(const base::string16& text, |
846 IA2TextBoundaryType ia2_boundary, | 861 IA2TextBoundaryType ia2_boundary, |
847 LONG start_offset, | 862 LONG start_offset, |
848 ui::TextBoundaryDirection direction); | 863 ui::TextBoundaryDirection direction); |
849 | 864 |
850 // Return a pointer to the object corresponding to the given id, | 865 // Searches forward from the given offset until the start of the next style |
851 // does not make a new reference. | 866 // is found, or searches backward from the given offset until the start of the |
852 BrowserAccessibilityWin* GetFromID(int32_t id); | 867 // current style is found. |
| 868 LONG FindStartOfStyle(LONG start_offset, |
| 869 ui::TextBoundaryDirection direction) const; |
| 870 |
| 871 // ID refers to the node ID in the current tree, not the globally unique ID. |
| 872 // TODO(nektar): Could we use globally unique IDs everywhere? |
| 873 // TODO(nektar): Rename this function to GetFromNodeID. |
| 874 BrowserAccessibilityWin* GetFromID(int32_t id) const; |
853 | 875 |
854 // Returns true if this is a list box option with a parent of type list box, | 876 // Returns true if this is a list box option with a parent of type list box, |
855 // or a menu list option with a parent of type menu list popup. | 877 // or a menu list option with a parent of type menu list popup. |
856 bool IsListBoxOptionOrMenuListOption(); | 878 bool IsListBoxOptionOrMenuListOption(); |
857 | 879 |
858 // Updates object attributes of IA2 with html attributes. | |
859 void UpdateRequiredAttributes(); | |
860 | |
861 // Given an int list attribute containing the ids of related elements, | 880 // Given an int list attribute containing the ids of related elements, |
862 // add a new IAccessibleRelation for this object with the given type name. | 881 // add a new IAccessibleRelation for this object with the given type name. |
863 void AddRelations(ui::AXIntListAttribute src_attr, | 882 void AddRelations(ui::AXIntListAttribute src_attr, |
864 const base::string16& iaccessiblerelation_type); | 883 const base::string16& iaccessiblerelation_type); |
865 | 884 |
| 885 // Updates object attributes of IA2 with html attributes. |
| 886 void UpdateRequiredAttributes(); |
| 887 |
| 888 // Updates the IA2 text style attributes. |
| 889 void UpdateTextAttributes(); |
| 890 |
866 struct WinAttributes { | 891 struct WinAttributes { |
867 WinAttributes(); | 892 WinAttributes(); |
868 ~WinAttributes(); | 893 ~WinAttributes(); |
869 | 894 |
870 // IAccessible role and state. | 895 // IAccessible role and state. |
871 int32_t ia_role; | 896 int32_t ia_role; |
872 int32_t ia_state; | 897 int32_t ia_state; |
873 base::string16 role_name; | 898 base::string16 role_name; |
874 | 899 |
875 // IAccessible name, description, help, value. | 900 // IAccessible name, description, help, value. |
876 base::string16 name; | 901 base::string16 name; |
877 base::string16 description; | 902 base::string16 description; |
878 base::string16 value; | 903 base::string16 value; |
879 | 904 |
880 // IAccessible2 role and state. | 905 // IAccessible2 role and state. |
881 int32_t ia2_role; | 906 int32_t ia2_role; |
882 int32_t ia2_state; | 907 int32_t ia2_state; |
883 | 908 |
884 // IAccessible2 attributes. | 909 // IAccessible2 attributes. |
885 std::vector<base::string16> ia2_attributes; | 910 std::vector<base::string16> ia2_attributes; |
886 | 911 |
887 // Hypertext. | 912 // Hypertext. |
888 base::string16 hypertext; | 913 base::string16 hypertext; |
889 | 914 |
| 915 // Maps each style span to its start offset in hypertext. |
| 916 base::hash_map<int, std::vector<base::string16>> offset_to_text_attributes; |
| 917 |
890 // Maps the |hypertext_| embedded character offset to an index in | 918 // Maps the |hypertext_| embedded character offset to an index in |
891 // |hyperlinks_|. | 919 // |hyperlinks_|. |
892 std::map<int32_t, int32_t> hyperlink_offset_to_index; | 920 std::map<int32_t, int32_t> hyperlink_offset_to_index; |
893 | 921 |
894 // The id of a BrowserAccessibilityWin for each hyperlink. | 922 // The id of a BrowserAccessibilityWin for each hyperlink. |
895 // TODO(nektar): Replace object IDs with child indices. | 923 // TODO(nektar): Replace object IDs with child indices. |
896 std::vector<int32_t> hyperlinks; | 924 std::vector<int32_t> hyperlinks; |
897 }; | 925 }; |
898 | 926 |
899 scoped_ptr<WinAttributes> win_attributes_; | 927 scoped_ptr<WinAttributes> win_attributes_; |
(...skipping 18 matching lines...) Expand all Loading... |
918 | 946 |
919 CONTENT_EXPORT BrowserAccessibilityWin* | 947 CONTENT_EXPORT BrowserAccessibilityWin* |
920 ToBrowserAccessibilityWin(BrowserAccessibility* obj); | 948 ToBrowserAccessibilityWin(BrowserAccessibility* obj); |
921 | 949 |
922 CONTENT_EXPORT const BrowserAccessibilityWin* | 950 CONTENT_EXPORT const BrowserAccessibilityWin* |
923 ToBrowserAccessibilityWin(const BrowserAccessibility* obj); | 951 ToBrowserAccessibilityWin(const BrowserAccessibility* obj); |
924 | 952 |
925 } // namespace content | 953 } // namespace content |
926 | 954 |
927 #endif // CONTENT_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_WIN_H_ | 955 #endif // CONTENT_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_WIN_H_ |
OLD | NEW |