OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <limits> |
| 8 |
7 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
8 #include "base/string_util.h" | 10 #include "base/string_util.h" |
9 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
10 #include "base/win/scoped_comptr.h" | 12 #include "base/win/scoped_comptr.h" |
11 #include "content/browser/accessibility/browser_accessibility_manager_win.h" | 13 #include "content/browser/accessibility/browser_accessibility_manager_win.h" |
12 #include "content/common/view_messages.h" | 14 #include "content/common/view_messages.h" |
13 #include "net/base/escape.h" | 15 #include "net/base/escape.h" |
14 #include "ui/base/accessibility/accessible_text_utils.h" | 16 #include "ui/base/accessibility/accessible_text_utils.h" |
15 | 17 |
16 using webkit_glue::WebAccessibility; | 18 using webkit_glue::WebAccessibility; |
(...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
676 return S_FALSE; | 678 return S_FALSE; |
677 | 679 |
678 for (long i = 0; i < count; ++i) { | 680 for (long i = 0; i < count; ++i) { |
679 relations_[i]->AddRef(); | 681 relations_[i]->AddRef(); |
680 relations[i] = relations_[i]; | 682 relations[i] = relations_[i]; |
681 } | 683 } |
682 | 684 |
683 return S_OK; | 685 return S_OK; |
684 } | 686 } |
685 | 687 |
| 688 STDMETHODIMP BrowserAccessibilityWin::scrollTo(enum IA2ScrollType scroll_type) { |
| 689 if (!instance_active_) |
| 690 return E_FAIL; |
| 691 |
| 692 // TODO(dmazzoni): Extend this to scroll every scrollable element as |
| 693 // needed, not just the root. |
| 694 BrowserAccessibility* root = this; |
| 695 while (root->parent()) |
| 696 root = root->parent(); |
| 697 |
| 698 gfx::Rect r = location_; |
| 699 gfx::Rect view(std::numeric_limits<int>::min(), |
| 700 std::numeric_limits<int>::min(), |
| 701 std::numeric_limits<int>::max(), |
| 702 std::numeric_limits<int>::max()); |
| 703 switch(scroll_type) { |
| 704 case IA2_SCROLL_TYPE_TOP_LEFT: |
| 705 root->ScrollToMakeVisible( |
| 706 gfx::Rect(r.x(), r.y(), 0, 0), r, view); |
| 707 break; |
| 708 case IA2_SCROLL_TYPE_BOTTOM_RIGHT: |
| 709 root->ScrollToMakeVisible( |
| 710 gfx::Rect(r.right(), r.bottom(), 0, 0), r, view); |
| 711 break; |
| 712 case IA2_SCROLL_TYPE_TOP_EDGE: |
| 713 root->ScrollToMakeVisible( |
| 714 gfx::Rect(r.x(), r.y(), r.width(), 0), r, view); |
| 715 break; |
| 716 case IA2_SCROLL_TYPE_BOTTOM_EDGE: |
| 717 root->ScrollToMakeVisible( |
| 718 gfx::Rect(r.x(), r.bottom(), r.width(), 0), r, view); |
| 719 break; |
| 720 case IA2_SCROLL_TYPE_LEFT_EDGE: |
| 721 root->ScrollToMakeVisible( |
| 722 gfx::Rect(r.x(), r.y(), 0, r.height()), r, view); |
| 723 break; |
| 724 case IA2_SCROLL_TYPE_RIGHT_EDGE: |
| 725 root->ScrollToMakeVisible( |
| 726 gfx::Rect(r.right(), r.y(), 0, r.height()), r, view); |
| 727 break; |
| 728 case IA2_SCROLL_TYPE_ANYWHERE: |
| 729 default: |
| 730 root->ScrollToMakeVisible(r, r, view); |
| 731 break; |
| 732 } |
| 733 |
| 734 return S_OK; |
| 735 } |
| 736 |
| 737 STDMETHODIMP BrowserAccessibilityWin::scrollToPoint( |
| 738 enum IA2CoordinateType coordinate_type, |
| 739 LONG x, |
| 740 LONG y) { |
| 741 if (!instance_active_) |
| 742 return E_FAIL; |
| 743 |
| 744 // TODO(dmazzoni): Extend this to scroll every scrollable element as |
| 745 // needed, not just the root. |
| 746 BrowserAccessibility* root = this; |
| 747 while (root->parent()) |
| 748 root = root->parent(); |
| 749 |
| 750 if (coordinate_type == IA2_COORDTYPE_SCREEN_RELATIVE) { |
| 751 gfx::Point top_left = manager_->GetViewBounds().origin(); |
| 752 x -= top_left.x(); |
| 753 y -= top_left.y(); |
| 754 } else if (coordinate_type == IA2_COORDTYPE_PARENT_RELATIVE) { |
| 755 if (parent_) { |
| 756 gfx::Rect parent_bounds = parent_->location(); |
| 757 x += parent_bounds.x(); |
| 758 y += parent_bounds.y(); |
| 759 } |
| 760 } else { |
| 761 return E_INVALIDARG; |
| 762 } |
| 763 |
| 764 gfx::Rect r = location_; |
| 765 root->ScrollToMakeVisible(gfx::Rect(r.x(), r.y(), 0, 0), |
| 766 r, |
| 767 gfx::Rect(x, y, 0, 0)); |
| 768 |
| 769 return S_OK; |
| 770 } |
| 771 |
686 // | 772 // |
687 // IAccessibleImage methods. | 773 // IAccessibleImage methods. |
688 // | 774 // |
689 | 775 |
690 STDMETHODIMP BrowserAccessibilityWin::get_description(BSTR* desc) { | 776 STDMETHODIMP BrowserAccessibilityWin::get_description(BSTR* desc) { |
691 if (!instance_active_) | 777 if (!instance_active_) |
692 return E_FAIL; | 778 return E_FAIL; |
693 | 779 |
694 if (!desc) | 780 if (!desc) |
695 return E_INVALIDARG; | 781 return E_INVALIDARG; |
(...skipping 1150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1846 if (!offset) | 1932 if (!offset) |
1847 return E_INVALIDARG; | 1933 return E_INVALIDARG; |
1848 | 1934 |
1849 // TODO(dmazzoni): implement this. We're returning S_OK for now so that | 1935 // TODO(dmazzoni): implement this. We're returning S_OK for now so that |
1850 // screen readers still return partially accurate results rather than | 1936 // screen readers still return partially accurate results rather than |
1851 // completely failing. | 1937 // completely failing. |
1852 *offset = 0; | 1938 *offset = 0; |
1853 return S_OK; | 1939 return S_OK; |
1854 } | 1940 } |
1855 | 1941 |
| 1942 STDMETHODIMP BrowserAccessibilityWin::scrollSubstringTo( |
| 1943 LONG start_index, |
| 1944 LONG end_index, |
| 1945 enum IA2ScrollType scroll_type) { |
| 1946 // TODO(dmazzoni): adjust this for the start and end index, too. |
| 1947 return scrollTo(scroll_type); |
| 1948 } |
| 1949 |
| 1950 STDMETHODIMP BrowserAccessibilityWin::scrollSubstringToPoint( |
| 1951 LONG start_index, |
| 1952 LONG end_index, |
| 1953 enum IA2CoordinateType coordinate_type, |
| 1954 LONG x, LONG y) { |
| 1955 // TODO(dmazzoni): adjust this for the start and end index, too. |
| 1956 return scrollToPoint(coordinate_type, x, y); |
| 1957 } |
| 1958 |
| 1959 STDMETHODIMP BrowserAccessibilityWin::addSelection( |
| 1960 LONG start_offset, LONG end_offset) { |
| 1961 if (!instance_active_) |
| 1962 return E_FAIL; |
| 1963 |
| 1964 const string16& text_str = TextForIAccessibleText(); |
| 1965 HandleSpecialTextOffset(text_str, &start_offset); |
| 1966 HandleSpecialTextOffset(text_str, &end_offset); |
| 1967 |
| 1968 manager_->SetTextSelection(*this, start_offset, end_offset); |
| 1969 return S_OK; |
| 1970 } |
| 1971 |
| 1972 STDMETHODIMP BrowserAccessibilityWin::removeSelection(LONG selection_index) { |
| 1973 if (!instance_active_) |
| 1974 return E_FAIL; |
| 1975 |
| 1976 if (selection_index != 0) |
| 1977 return E_INVALIDARG; |
| 1978 |
| 1979 manager_->SetTextSelection(*this, 0, 0); |
| 1980 return S_OK; |
| 1981 } |
| 1982 |
| 1983 STDMETHODIMP BrowserAccessibilityWin::setCaretOffset(LONG offset) { |
| 1984 if (!instance_active_) |
| 1985 return E_FAIL; |
| 1986 |
| 1987 const string16& text_str = TextForIAccessibleText(); |
| 1988 HandleSpecialTextOffset(text_str, &offset); |
| 1989 manager_->SetTextSelection(*this, offset, offset); |
| 1990 return S_OK; |
| 1991 } |
| 1992 |
| 1993 STDMETHODIMP BrowserAccessibilityWin::setSelection(LONG selection_index, |
| 1994 LONG start_offset, |
| 1995 LONG end_offset) { |
| 1996 if (!instance_active_) |
| 1997 return E_FAIL; |
| 1998 |
| 1999 if (selection_index != 0) |
| 2000 return E_INVALIDARG; |
| 2001 |
| 2002 const string16& text_str = TextForIAccessibleText(); |
| 2003 HandleSpecialTextOffset(text_str, &start_offset); |
| 2004 HandleSpecialTextOffset(text_str, &end_offset); |
| 2005 |
| 2006 manager_->SetTextSelection(*this, start_offset, end_offset); |
| 2007 return S_OK; |
| 2008 } |
| 2009 |
1856 // | 2010 // |
1857 // IAccessibleValue methods. | 2011 // IAccessibleValue methods. |
1858 // | 2012 // |
1859 | 2013 |
1860 STDMETHODIMP BrowserAccessibilityWin::get_currentValue(VARIANT* value) { | 2014 STDMETHODIMP BrowserAccessibilityWin::get_currentValue(VARIANT* value) { |
1861 if (!instance_active_) | 2015 if (!instance_active_) |
1862 return E_FAIL; | 2016 return E_FAIL; |
1863 | 2017 |
1864 if (!value) | 2018 if (!value) |
1865 return E_INVALIDARG; | 2019 return E_INVALIDARG; |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2108 style_values[i] = SysAllocString(display.c_str()); | 2262 style_values[i] = SysAllocString(display.c_str()); |
2109 } else { | 2263 } else { |
2110 style_values[i] = NULL; | 2264 style_values[i] = NULL; |
2111 } | 2265 } |
2112 } | 2266 } |
2113 | 2267 |
2114 return S_OK; | 2268 return S_OK; |
2115 } | 2269 } |
2116 | 2270 |
2117 STDMETHODIMP BrowserAccessibilityWin::scrollTo(boolean placeTopLeft) { | 2271 STDMETHODIMP BrowserAccessibilityWin::scrollTo(boolean placeTopLeft) { |
2118 return E_NOTIMPL; | 2272 return scrollTo(placeTopLeft ? |
| 2273 IA2_SCROLL_TYPE_TOP_LEFT : |
| 2274 IA2_SCROLL_TYPE_ANYWHERE); |
2119 } | 2275 } |
2120 | 2276 |
2121 STDMETHODIMP BrowserAccessibilityWin::get_parentNode(ISimpleDOMNode** node) { | 2277 STDMETHODIMP BrowserAccessibilityWin::get_parentNode(ISimpleDOMNode** node) { |
2122 if (!instance_active_) | 2278 if (!instance_active_) |
2123 return E_FAIL; | 2279 return E_FAIL; |
2124 | 2280 |
2125 if (!node) | 2281 if (!node) |
2126 return E_INVALIDARG; | 2282 return E_INVALIDARG; |
2127 | 2283 |
2128 *node = parent_->toBrowserAccessibilityWin()->NewReference(); | 2284 *node = parent_->toBrowserAccessibilityWin()->NewReference(); |
(...skipping 837 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2966 } | 3122 } |
2967 | 3123 |
2968 // The role should always be set. | 3124 // The role should always be set. |
2969 DCHECK(!role_name_.empty() || ia_role_); | 3125 DCHECK(!role_name_.empty() || ia_role_); |
2970 | 3126 |
2971 // If we didn't explicitly set the IAccessible2 role, make it the same | 3127 // If we didn't explicitly set the IAccessible2 role, make it the same |
2972 // as the MSAA role. | 3128 // as the MSAA role. |
2973 if (!ia2_role_) | 3129 if (!ia2_role_) |
2974 ia2_role_ = ia_role_; | 3130 ia2_role_ = ia_role_; |
2975 } | 3131 } |
OLD | NEW |