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 692 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
720 int32_t ia_state() const { return win_attributes_->ia_state; } | 721 int32_t ia_state() const { return win_attributes_->ia_state; } |
721 const base::string16& role_name() const { return win_attributes_->role_name; } | 722 const base::string16& role_name() const { return win_attributes_->role_name; } |
722 int32_t ia2_role() const { return win_attributes_->ia2_role; } | 723 int32_t ia2_role() const { return win_attributes_->ia2_role; } |
723 int32_t ia2_state() const { return win_attributes_->ia2_state; } | 724 int32_t ia2_state() const { return win_attributes_->ia2_state; } |
724 const std::vector<base::string16>& ia2_attributes() const { | 725 const std::vector<base::string16>& ia2_attributes() const { |
725 return win_attributes_->ia2_attributes; | 726 return win_attributes_->ia2_attributes; |
726 } | 727 } |
727 base::string16 name() const { return win_attributes_->name; } | 728 base::string16 name() const { return win_attributes_->name; } |
728 base::string16 description() const { return win_attributes_->description; } | 729 base::string16 description() const { return win_attributes_->description; } |
729 base::string16 value() const { return win_attributes_->value; } | 730 base::string16 value() const { return win_attributes_->value; } |
| 731 base::hash_map<int, std::vector<base::string16>>& offset_to_text_attributes() |
| 732 const { |
| 733 return win_attributes_->offset_to_text_attributes; |
| 734 } |
730 std::map<int32_t, int32_t>& hyperlink_offset_to_index() const { | 735 std::map<int32_t, int32_t>& hyperlink_offset_to_index() const { |
731 return win_attributes_->hyperlink_offset_to_index; | 736 return win_attributes_->hyperlink_offset_to_index; |
732 } | 737 } |
733 std::vector<int32_t>& hyperlinks() const { | 738 std::vector<int32_t>& hyperlinks() const { |
734 return win_attributes_->hyperlinks; | 739 return win_attributes_->hyperlinks; |
735 } | 740 } |
736 | 741 |
737 private: | 742 private: |
738 // Add one to the reference count and return the same object. Always | 743 // Add one to the reference count and return the same object. Always |
739 // use this method when returning a BrowserAccessibilityWin object as | 744 // use this method when returning a BrowserAccessibilityWin object as |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
783 | 788 |
784 // | 789 // |
785 // Helper methods for IA2 hyperlinks. | 790 // Helper methods for IA2 hyperlinks. |
786 // | 791 // |
787 // Hyperlink is an IA2 misnomer. It refers to objects embedded within other | 792 // Hyperlink is an IA2 misnomer. It refers to objects embedded within other |
788 // objects, such as a numbered list within a contenteditable div. | 793 // objects, such as a numbered list within a contenteditable div. |
789 // Also, in IA2, text that includes embedded objects is called hypertext. | 794 // Also, in IA2, text that includes embedded objects is called hypertext. |
790 | 795 |
791 // Returns true if the current object is an IA2 hyperlink. | 796 // Returns true if the current object is an IA2 hyperlink. |
792 bool IsHyperlink() const; | 797 bool IsHyperlink() const; |
| 798 // Returns the hyperlink at the given text position, or nullptr if no |
| 799 // hyperlink can be found. |
| 800 BrowserAccessibilityWin* GetHyperlinkFromHypertextOffset(int offset) const; |
793 | 801 |
794 // Functions for retrieving offsets for hyperlinks and hypertext. | 802 // Functions for retrieving offsets for hyperlinks and hypertext. |
795 // Return -1 in case of failure. | 803 // Return -1 in case of failure. |
796 int32_t GetHyperlinkIndexFromChild( | 804 int32_t GetHyperlinkIndexFromChild( |
797 const BrowserAccessibilityWin& child) const; | 805 const BrowserAccessibilityWin& child) const; |
798 int32_t GetHypertextOffsetFromHyperlinkIndex(int32_t hyperlink_index) const; | 806 int32_t GetHypertextOffsetFromHyperlinkIndex(int32_t hyperlink_index) const; |
799 int32_t GetHypertextOffsetFromChild( | 807 int32_t GetHypertextOffsetFromChild( |
800 const BrowserAccessibilityWin& child) const; | 808 const BrowserAccessibilityWin& child) const; |
801 int32_t GetHypertextOffsetFromDescendant( | 809 int32_t GetHypertextOffsetFromDescendant( |
802 const BrowserAccessibilityWin& descendant) const; | 810 const BrowserAccessibilityWin& descendant) const; |
(...skipping 26 matching lines...) Expand all Loading... |
829 void GetSelectionOffsets(int* selection_start, int* selection_end) const; | 837 void GetSelectionOffsets(int* selection_start, int* selection_end) const; |
830 | 838 |
831 // Get the value text, which might come from the floating-point | 839 // Get the value text, which might come from the floating-point |
832 // value for some roles. | 840 // value for some roles. |
833 base::string16 GetValueText(); | 841 base::string16 GetValueText(); |
834 | 842 |
835 bool IsSameHypertextCharacter(size_t old_char_index, size_t new_char_index); | 843 bool IsSameHypertextCharacter(size_t old_char_index, size_t new_char_index); |
836 void ComputeHypertextRemovedAndInserted( | 844 void ComputeHypertextRemovedAndInserted( |
837 int* start, int* old_len, int* new_len); | 845 int* start, int* old_len, int* new_len); |
838 | 846 |
| 847 // Computes the IA2 text style attributes upon being requested. |
| 848 void ComputeTextAttributes(); |
| 849 |
839 // If offset is a member of IA2TextSpecialOffsets this function updates the | 850 // If offset is a member of IA2TextSpecialOffsets this function updates the |
840 // value of offset and returns, otherwise offset remains unchanged. | 851 // value of offset and returns, otherwise offset remains unchanged. |
841 void HandleSpecialTextOffset(const base::string16& text, LONG* offset); | 852 void HandleSpecialTextOffset(const base::string16& text, LONG* offset); |
842 | 853 |
843 // Convert from a IA2TextBoundaryType to a ui::TextBoundaryType. | 854 // Convert from a IA2TextBoundaryType to a ui::TextBoundaryType. |
844 ui::TextBoundaryType IA2TextBoundaryToTextBoundary(IA2TextBoundaryType type); | 855 ui::TextBoundaryType IA2TextBoundaryToTextBoundary(IA2TextBoundaryType type); |
845 | 856 |
846 // Search forwards (direction == 1) or backwards (direction == -1) | 857 // Search forwards (direction == 1) or backwards (direction == -1) |
847 // from the given offset until the given boundary is found, and | 858 // from the given offset until the given boundary is found, and |
848 // return the offset of that boundary. | 859 // return the offset of that boundary. |
849 LONG FindBoundary(const base::string16& text, | 860 LONG FindBoundary(const base::string16& text, |
850 IA2TextBoundaryType ia2_boundary, | 861 IA2TextBoundaryType ia2_boundary, |
851 LONG start_offset, | 862 LONG start_offset, |
852 ui::TextBoundaryDirection direction); | 863 ui::TextBoundaryDirection direction); |
853 | 864 |
| 865 // Searches forward from the given offset until the start of the next style |
| 866 // is found, or searches backward from the given offset until the start of the |
| 867 // current style is found. |
| 868 LONG FindStartOfStyle(LONG start_offset, |
| 869 ui::TextBoundaryDirection direction) const; |
| 870 |
854 // Return a pointer to the object corresponding to the given id, | 871 // Return a pointer to the object corresponding to the given id, |
855 // does not make a new reference. | 872 // does not make a new reference. |
856 BrowserAccessibilityWin* GetFromID(int32_t id); | 873 BrowserAccessibilityWin* GetFromID(int32_t id) const; |
857 | 874 |
858 // Returns true if this is a list box option with a parent of type list box, | 875 // Returns true if this is a list box option with a parent of type list box, |
859 // or a menu list option with a parent of type menu list popup. | 876 // or a menu list option with a parent of type menu list popup. |
860 bool IsListBoxOptionOrMenuListOption(); | 877 bool IsListBoxOptionOrMenuListOption(); |
861 | 878 |
862 // Updates object attributes of IA2 with html attributes. | |
863 void UpdateRequiredAttributes(); | |
864 | |
865 // Given an int list attribute containing the ids of related elements, | 879 // Given an int list attribute containing the ids of related elements, |
866 // add a new IAccessibleRelation for this object with the given type name. | 880 // add a new IAccessibleRelation for this object with the given type name. |
867 void AddRelations(ui::AXIntListAttribute src_attr, | 881 void AddRelations(ui::AXIntListAttribute src_attr, |
868 const base::string16& iaccessiblerelation_type); | 882 const base::string16& iaccessiblerelation_type); |
869 | 883 |
| 884 // Updates object attributes of IA2 with html attributes. |
| 885 void UpdateRequiredAttributes(); |
| 886 |
870 // Windows-specific unique ID (unique within the browser process), | 887 // Windows-specific unique ID (unique within the browser process), |
871 // used for get_accChild, NotifyWinEvent, and as the unique ID for | 888 // used for get_accChild, NotifyWinEvent, and as the unique ID for |
872 // IAccessible2 and ISimpleDOM. | 889 // IAccessible2 and ISimpleDOM. |
873 LONG unique_id_win_; | 890 LONG unique_id_win_; |
874 | 891 |
875 struct WinAttributes { | 892 struct WinAttributes { |
876 WinAttributes(); | 893 WinAttributes(); |
877 ~WinAttributes(); | 894 ~WinAttributes(); |
878 | 895 |
879 // IAccessible role and state. | 896 // IAccessible role and state. |
880 int32_t ia_role; | 897 int32_t ia_role; |
881 int32_t ia_state; | 898 int32_t ia_state; |
882 base::string16 role_name; | 899 base::string16 role_name; |
883 | 900 |
884 // IAccessible name, description, help, value. | 901 // IAccessible name, description, help, value. |
885 base::string16 name; | 902 base::string16 name; |
886 base::string16 description; | 903 base::string16 description; |
887 base::string16 value; | 904 base::string16 value; |
888 | 905 |
889 // IAccessible2 role and state. | 906 // IAccessible2 role and state. |
890 int32_t ia2_role; | 907 int32_t ia2_role; |
891 int32_t ia2_state; | 908 int32_t ia2_state; |
892 | 909 |
893 // IAccessible2 attributes. | 910 // IAccessible2 attributes. |
894 std::vector<base::string16> ia2_attributes; | 911 std::vector<base::string16> ia2_attributes; |
895 | 912 |
896 // Hypertext. | 913 // Hypertext. |
897 base::string16 hypertext; | 914 base::string16 hypertext; |
898 | 915 |
| 916 // Maps each style span to its start offset in hypertext. |
| 917 base::hash_map<int, std::vector<base::string16>> offset_to_text_attributes; |
| 918 |
899 // Maps the |hypertext_| embedded character offset to an index in | 919 // Maps the |hypertext_| embedded character offset to an index in |
900 // |hyperlinks_|. | 920 // |hyperlinks_|. |
901 std::map<int32_t, int32_t> hyperlink_offset_to_index; | 921 std::map<int32_t, int32_t> hyperlink_offset_to_index; |
902 | 922 |
903 // The id of a BrowserAccessibilityWin for each hyperlink. | 923 // The id of a BrowserAccessibilityWin for each hyperlink. |
904 // TODO(nektar): Replace object IDs with child indices. | 924 // TODO(nektar): Replace object IDs with child indices. |
905 std::vector<int32_t> hyperlinks; | 925 std::vector<int32_t> hyperlinks; |
906 }; | 926 }; |
907 | 927 |
908 scoped_ptr<WinAttributes> win_attributes_; | 928 scoped_ptr<WinAttributes> win_attributes_; |
(...skipping 15 matching lines...) Expand all Loading... |
924 // Give BrowserAccessibility::Create access to our constructor. | 944 // Give BrowserAccessibility::Create access to our constructor. |
925 friend class BrowserAccessibility; | 945 friend class BrowserAccessibility; |
926 friend class BrowserAccessibilityRelation; | 946 friend class BrowserAccessibilityRelation; |
927 | 947 |
928 DISALLOW_COPY_AND_ASSIGN(BrowserAccessibilityWin); | 948 DISALLOW_COPY_AND_ASSIGN(BrowserAccessibilityWin); |
929 }; | 949 }; |
930 | 950 |
931 } // namespace content | 951 } // namespace content |
932 | 952 |
933 #endif // CONTENT_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_WIN_H_ | 953 #endif // CONTENT_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_WIN_H_ |
OLD | NEW |