Chromium Code Reviews| 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 "base/string_number_conversions.h" | 7 #include "base/string_number_conversions.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "base/win/scoped_comptr.h" | 10 #include "base/win/scoped_comptr.h" |
| (...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 676 return S_FALSE; | 676 return S_FALSE; |
| 677 | 677 |
| 678 for (long i = 0; i < count; ++i) { | 678 for (long i = 0; i < count; ++i) { |
| 679 relations_[i]->AddRef(); | 679 relations_[i]->AddRef(); |
| 680 relations[i] = relations_[i]; | 680 relations[i] = relations_[i]; |
| 681 } | 681 } |
| 682 | 682 |
| 683 return S_OK; | 683 return S_OK; |
| 684 } | 684 } |
| 685 | 685 |
| 686 STDMETHODIMP BrowserAccessibilityWin::scrollTo(enum IA2ScrollType scroll_type) { | |
| 687 if (!instance_active_) | |
| 688 return E_FAIL; | |
| 689 | |
| 690 // TODO(dmazzoni): Extend this to scroll every scrollable element as | |
| 691 // needed, not just the root. | |
| 692 BrowserAccessibility* root = this; | |
| 693 while (root->parent()) | |
| 694 root = root->parent(); | |
| 695 | |
| 696 gfx::Rect r = location_; | |
| 697 gfx::Rect view(-1000000, -1000000, 1000000, 1000000); | |
|
David Tseng
2011/12/02 00:51:51
#include <limits>
...
std::numeric_limits<int>::m
dmazzoni
2011/12/03 00:37:10
Done.
| |
| 698 switch(scroll_type) { | |
| 699 case IA2_SCROLL_TYPE_TOP_LEFT: | |
|
David Tseng
2011/12/02 00:51:51
indent
dmazzoni
2011/12/03 00:37:10
Done.
| |
| 700 root->ScrollToMakeVisible(gfx::Rect(r.x(), r.y(), 0, 0), r, view); | |
| 701 break; | |
| 702 case IA2_SCROLL_TYPE_BOTTOM_RIGHT: | |
| 703 root->ScrollToMakeVisible(gfx::Rect(r.right(), r.bottom(), 0, 0), r, view); | |
| 704 break; | |
| 705 case IA2_SCROLL_TYPE_TOP_EDGE: | |
| 706 root->ScrollToMakeVisible(gfx::Rect(r.x(), r.y(), r.width(), 0), r, view); | |
| 707 break; | |
| 708 case IA2_SCROLL_TYPE_BOTTOM_EDGE: | |
| 709 root->ScrollToMakeVisible( | |
| 710 gfx::Rect(r.x(), r.bottom(), r.width(), 0), r, view); | |
| 711 break; | |
| 712 case IA2_SCROLL_TYPE_LEFT_EDGE: | |
| 713 root->ScrollToMakeVisible(gfx::Rect(r.x(), r.y(), 0, r.height()), r, view); | |
| 714 break; | |
| 715 case IA2_SCROLL_TYPE_RIGHT_EDGE: | |
| 716 root->ScrollToMakeVisible( | |
| 717 gfx::Rect(r.right(), r.y(), 0, r.height()), r, view); | |
| 718 break; | |
| 719 case IA2_SCROLL_TYPE_ANYWHERE: | |
| 720 default: | |
| 721 root->ScrollToMakeVisible(r, r, view); | |
| 722 break; | |
| 723 } | |
| 724 | |
| 725 return S_OK; | |
| 726 } | |
| 727 | |
| 728 STDMETHODIMP BrowserAccessibilityWin::scrollToPoint( | |
| 729 enum IA2CoordinateType coordinate_type, | |
| 730 LONG x, | |
| 731 LONG y) { | |
| 732 if (!instance_active_) | |
| 733 return E_FAIL; | |
| 734 | |
| 735 // TODO(dmazzoni): Extend this to scroll every scrollable element as | |
| 736 // needed, not just the root. | |
| 737 BrowserAccessibility* root = this; | |
| 738 while (root->parent()) | |
| 739 root = root->parent(); | |
| 740 | |
| 741 if (coordinate_type == IA2_COORDTYPE_SCREEN_RELATIVE) { | |
|
David Tseng
2011/12/02 00:51:51
switch? Are we not handling all the cord types?
dmazzoni
2011/12/03 00:37:10
Actually there are only two.
| |
| 742 gfx::Point top_left = manager_->GetViewBounds().origin(); | |
| 743 x -= top_left.x(); | |
| 744 y -= top_left.y(); | |
| 745 } else if (coordinate_type == IA2_COORDTYPE_PARENT_RELATIVE) { | |
| 746 if (parent_) { | |
| 747 gfx::Rect parent_bounds = parent_->location(); | |
| 748 x += parent_bounds.x(); | |
| 749 y += parent_bounds.y(); | |
| 750 } | |
| 751 } else { | |
| 752 return E_INVALIDARG; | |
| 753 } | |
| 754 | |
| 755 gfx::Rect r = location_; | |
| 756 root->ScrollToMakeVisible(gfx::Rect(r.x(), r.y(), 0, 0), | |
| 757 r, | |
| 758 gfx::Rect(x, y, 0, 0)); | |
| 759 | |
| 760 return S_OK; | |
| 761 } | |
| 762 | |
| 686 // | 763 // |
| 687 // IAccessibleImage methods. | 764 // IAccessibleImage methods. |
| 688 // | 765 // |
| 689 | 766 |
| 690 STDMETHODIMP BrowserAccessibilityWin::get_description(BSTR* desc) { | 767 STDMETHODIMP BrowserAccessibilityWin::get_description(BSTR* desc) { |
| 691 if (!instance_active_) | 768 if (!instance_active_) |
| 692 return E_FAIL; | 769 return E_FAIL; |
| 693 | 770 |
| 694 if (!desc) | 771 if (!desc) |
| 695 return E_INVALIDARG; | 772 return E_INVALIDARG; |
| (...skipping 1150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1846 if (!offset) | 1923 if (!offset) |
| 1847 return E_INVALIDARG; | 1924 return E_INVALIDARG; |
| 1848 | 1925 |
| 1849 // TODO(dmazzoni): implement this. We're returning S_OK for now so that | 1926 // TODO(dmazzoni): implement this. We're returning S_OK for now so that |
| 1850 // screen readers still return partially accurate results rather than | 1927 // screen readers still return partially accurate results rather than |
| 1851 // completely failing. | 1928 // completely failing. |
| 1852 *offset = 0; | 1929 *offset = 0; |
| 1853 return S_OK; | 1930 return S_OK; |
| 1854 } | 1931 } |
| 1855 | 1932 |
| 1933 STDMETHODIMP BrowserAccessibilityWin::scrollSubstringTo( | |
| 1934 LONG start_index, | |
| 1935 LONG end_index, | |
| 1936 enum IA2ScrollType scroll_type) { | |
| 1937 // TODO(dmazzoni): adjust this for the start and end index, too. | |
| 1938 return scrollTo(scroll_type); | |
| 1939 } | |
| 1940 | |
| 1941 STDMETHODIMP BrowserAccessibilityWin::scrollSubstringToPoint( | |
| 1942 LONG start_index, | |
| 1943 LONG end_index, | |
| 1944 enum IA2CoordinateType coordinate_type, | |
| 1945 LONG x, LONG y) { | |
| 1946 // TODO(dmazzoni): adjust this for the start and end index, too. | |
| 1947 return scrollToPoint(coordinate_type, x, y); | |
| 1948 } | |
| 1949 | |
| 1950 STDMETHODIMP BrowserAccessibilityWin::addSelection( | |
|
David Tseng
2011/12/02 00:51:51
Part of another patch?
dmazzoni
2011/12/03 00:37:10
Yep, sorry. Gone now.
| |
| 1951 LONG start_offset, LONG end_offset) { | |
| 1952 if (!instance_active_) | |
| 1953 return E_FAIL; | |
| 1954 | |
| 1955 const string16& text_str = TextForIAccessibleText(); | |
| 1956 HandleSpecialTextOffset(text_str, &start_offset); | |
| 1957 HandleSpecialTextOffset(text_str, &end_offset); | |
| 1958 | |
| 1959 manager_->SetTextSelection(*this, start_offset, end_offset); | |
| 1960 return S_OK; | |
| 1961 } | |
| 1962 | |
| 1963 STDMETHODIMP BrowserAccessibilityWin::removeSelection(LONG selection_index) { | |
| 1964 if (!instance_active_) | |
| 1965 return E_FAIL; | |
| 1966 | |
| 1967 if (selection_index != 0) | |
| 1968 return E_INVALIDARG; | |
| 1969 | |
| 1970 manager_->SetTextSelection(*this, 0, 0); | |
| 1971 return S_OK; | |
| 1972 } | |
| 1973 | |
| 1974 STDMETHODIMP BrowserAccessibilityWin::setCaretOffset(LONG offset) { | |
| 1975 if (!instance_active_) | |
| 1976 return E_FAIL; | |
| 1977 | |
| 1978 const string16& text_str = TextForIAccessibleText(); | |
| 1979 HandleSpecialTextOffset(text_str, &offset); | |
| 1980 manager_->SetTextSelection(*this, offset, offset); | |
| 1981 return S_OK; | |
| 1982 } | |
| 1983 | |
| 1984 STDMETHODIMP BrowserAccessibilityWin::setSelection(LONG selection_index, | |
| 1985 LONG start_offset, | |
| 1986 LONG end_offset) { | |
| 1987 if (!instance_active_) | |
| 1988 return E_FAIL; | |
| 1989 | |
| 1990 if (selection_index != 0) | |
| 1991 return E_INVALIDARG; | |
| 1992 | |
| 1993 const string16& text_str = TextForIAccessibleText(); | |
| 1994 HandleSpecialTextOffset(text_str, &start_offset); | |
| 1995 HandleSpecialTextOffset(text_str, &end_offset); | |
| 1996 | |
| 1997 manager_->SetTextSelection(*this, start_offset, end_offset); | |
| 1998 return S_OK; | |
| 1999 } | |
| 2000 | |
| 1856 // | 2001 // |
| 1857 // IAccessibleValue methods. | 2002 // IAccessibleValue methods. |
| 1858 // | 2003 // |
| 1859 | 2004 |
| 1860 STDMETHODIMP BrowserAccessibilityWin::get_currentValue(VARIANT* value) { | 2005 STDMETHODIMP BrowserAccessibilityWin::get_currentValue(VARIANT* value) { |
| 1861 if (!instance_active_) | 2006 if (!instance_active_) |
| 1862 return E_FAIL; | 2007 return E_FAIL; |
| 1863 | 2008 |
| 1864 if (!value) | 2009 if (!value) |
| 1865 return E_INVALIDARG; | 2010 return E_INVALIDARG; |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2108 style_values[i] = SysAllocString(display.c_str()); | 2253 style_values[i] = SysAllocString(display.c_str()); |
| 2109 } else { | 2254 } else { |
| 2110 style_values[i] = NULL; | 2255 style_values[i] = NULL; |
| 2111 } | 2256 } |
| 2112 } | 2257 } |
| 2113 | 2258 |
| 2114 return S_OK; | 2259 return S_OK; |
| 2115 } | 2260 } |
| 2116 | 2261 |
| 2117 STDMETHODIMP BrowserAccessibilityWin::scrollTo(boolean placeTopLeft) { | 2262 STDMETHODIMP BrowserAccessibilityWin::scrollTo(boolean placeTopLeft) { |
| 2118 return E_NOTIMPL; | 2263 return scrollTo(placeTopLeft ? |
| 2264 IA2_SCROLL_TYPE_TOP_LEFT : | |
| 2265 IA2_SCROLL_TYPE_ANYWHERE); | |
| 2119 } | 2266 } |
| 2120 | 2267 |
| 2121 STDMETHODIMP BrowserAccessibilityWin::get_parentNode(ISimpleDOMNode** node) { | 2268 STDMETHODIMP BrowserAccessibilityWin::get_parentNode(ISimpleDOMNode** node) { |
| 2122 if (!instance_active_) | 2269 if (!instance_active_) |
| 2123 return E_FAIL; | 2270 return E_FAIL; |
| 2124 | 2271 |
| 2125 if (!node) | 2272 if (!node) |
| 2126 return E_INVALIDARG; | 2273 return E_INVALIDARG; |
| 2127 | 2274 |
| 2128 *node = parent_->toBrowserAccessibilityWin()->NewReference(); | 2275 *node = parent_->toBrowserAccessibilityWin()->NewReference(); |
| (...skipping 837 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2966 } | 3113 } |
| 2967 | 3114 |
| 2968 // The role should always be set. | 3115 // The role should always be set. |
| 2969 DCHECK(!role_name_.empty() || ia_role_); | 3116 DCHECK(!role_name_.empty() || ia_role_); |
| 2970 | 3117 |
| 2971 // If we didn't explicitly set the IAccessible2 role, make it the same | 3118 // If we didn't explicitly set the IAccessible2 role, make it the same |
| 2972 // as the MSAA role. | 3119 // as the MSAA role. |
| 2973 if (!ia2_role_) | 3120 if (!ia2_role_) |
| 2974 ia2_role_ = ia_role_; | 3121 ia2_role_ = ia_role_; |
| 2975 } | 3122 } |
| OLD | NEW |