Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(104)

Side by Side Diff: content/browser/accessibility/browser_accessibility_win.cc

Issue 2217363002: Use relative bounding boxes throughout Chrome accessibility (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address feedback from aboxhall Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include "content/browser/accessibility/browser_accessibility_win.h" 5 #include "content/browser/accessibility/browser_accessibility_win.h"
6 6
7 #include <UIAutomationClient.h> 7 #include <UIAutomationClient.h>
8 #include <UIAutomationCoreApi.h> 8 #include <UIAutomationCoreApi.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 STDMETHODIMP BrowserAccessibilityWin::accHitTest(LONG x_left, 254 STDMETHODIMP BrowserAccessibilityWin::accHitTest(LONG x_left,
255 LONG y_top, 255 LONG y_top,
256 VARIANT* child) { 256 VARIANT* child) {
257 if (!instance_active()) 257 if (!instance_active())
258 return E_FAIL; 258 return E_FAIL;
259 259
260 if (!child) 260 if (!child)
261 return E_INVALIDARG; 261 return E_INVALIDARG;
262 262
263 gfx::Point point(x_left, y_top); 263 gfx::Point point(x_left, y_top);
264 if (!GetGlobalBoundsRect().Contains(point)) { 264 if (!GetScreenBoundsRect().Contains(point)) {
265 // Return S_FALSE and VT_EMPTY when outside the object's boundaries. 265 // Return S_FALSE and VT_EMPTY when outside the object's boundaries.
266 child->vt = VT_EMPTY; 266 child->vt = VT_EMPTY;
267 return S_FALSE; 267 return S_FALSE;
268 } 268 }
269 269
270 BrowserAccessibility* result = BrowserAccessibilityForPoint(point); 270 BrowserAccessibility* result = BrowserAccessibilityForPoint(point);
271 if (result == this) { 271 if (result == this) {
272 // Point is within this object. 272 // Point is within this object.
273 child->vt = VT_I4; 273 child->vt = VT_I4;
274 child->lVal = CHILDID_SELF; 274 child->lVal = CHILDID_SELF;
(...skipping 12 matching lines...) Expand all
287 if (!instance_active()) 287 if (!instance_active())
288 return E_FAIL; 288 return E_FAIL;
289 289
290 if (!x_left || !y_top || !width || !height) 290 if (!x_left || !y_top || !width || !height)
291 return E_INVALIDARG; 291 return E_INVALIDARG;
292 292
293 BrowserAccessibilityWin* target = GetTargetFromChildID(var_id); 293 BrowserAccessibilityWin* target = GetTargetFromChildID(var_id);
294 if (!target) 294 if (!target)
295 return E_INVALIDARG; 295 return E_INVALIDARG;
296 296
297 gfx::Rect bounds = target->GetGlobalBoundsRect(); 297 gfx::Rect bounds = target->GetScreenBoundsRect();
298 *x_left = bounds.x(); 298 *x_left = bounds.x();
299 *y_top = bounds.y(); 299 *y_top = bounds.y();
300 *width = bounds.width(); 300 *width = bounds.width();
301 *height = bounds.height(); 301 *height = bounds.height();
302 302
303 return S_OK; 303 return S_OK;
304 } 304 }
305 305
306 STDMETHODIMP BrowserAccessibilityWin::accNavigate(LONG nav_dir, 306 STDMETHODIMP BrowserAccessibilityWin::accNavigate(LONG nav_dir,
307 VARIANT start, 307 VARIANT start,
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after
820 relations[i] = relations_[i]; 820 relations[i] = relations_[i];
821 } 821 }
822 822
823 return S_OK; 823 return S_OK;
824 } 824 }
825 825
826 STDMETHODIMP BrowserAccessibilityWin::scrollTo(IA2ScrollType scroll_type) { 826 STDMETHODIMP BrowserAccessibilityWin::scrollTo(IA2ScrollType scroll_type) {
827 if (!instance_active()) 827 if (!instance_active())
828 return E_FAIL; 828 return E_FAIL;
829 829
830 gfx::Rect r = GetLocation(); 830 gfx::Rect r = GetFrameBoundsRect();
831 switch(scroll_type) { 831 switch(scroll_type) {
832 case IA2_SCROLL_TYPE_TOP_LEFT: 832 case IA2_SCROLL_TYPE_TOP_LEFT:
833 manager()->ScrollToMakeVisible(*this, gfx::Rect(r.x(), r.y(), 0, 0)); 833 manager()->ScrollToMakeVisible(*this, gfx::Rect(r.x(), r.y(), 0, 0));
834 break; 834 break;
835 case IA2_SCROLL_TYPE_BOTTOM_RIGHT: 835 case IA2_SCROLL_TYPE_BOTTOM_RIGHT:
836 manager()->ScrollToMakeVisible( 836 manager()->ScrollToMakeVisible(
837 *this, gfx::Rect(r.right(), r.bottom(), 0, 0)); 837 *this, gfx::Rect(r.right(), r.bottom(), 0, 0));
838 break; 838 break;
839 case IA2_SCROLL_TYPE_TOP_EDGE: 839 case IA2_SCROLL_TYPE_TOP_EDGE:
840 manager()->ScrollToMakeVisible( 840 manager()->ScrollToMakeVisible(
(...skipping 27 matching lines...) Expand all
868 LONG y) { 868 LONG y) {
869 if (!instance_active()) 869 if (!instance_active())
870 return E_FAIL; 870 return E_FAIL;
871 871
872 gfx::Point scroll_to(x, y); 872 gfx::Point scroll_to(x, y);
873 873
874 if (coordinate_type == IA2_COORDTYPE_SCREEN_RELATIVE) { 874 if (coordinate_type == IA2_COORDTYPE_SCREEN_RELATIVE) {
875 scroll_to -= manager()->GetViewBounds().OffsetFromOrigin(); 875 scroll_to -= manager()->GetViewBounds().OffsetFromOrigin();
876 } else if (coordinate_type == IA2_COORDTYPE_PARENT_RELATIVE) { 876 } else if (coordinate_type == IA2_COORDTYPE_PARENT_RELATIVE) {
877 if (GetParent()) 877 if (GetParent())
878 scroll_to += GetParent()->GetLocation().OffsetFromOrigin(); 878 scroll_to += GetParent()->GetFrameBoundsRect().OffsetFromOrigin();
879 } else { 879 } else {
880 return E_INVALIDARG; 880 return E_INVALIDARG;
881 } 881 }
882 882
883 manager()->ScrollToPoint(*this, scroll_to); 883 manager()->ScrollToPoint(*this, scroll_to);
884 manager()->ToBrowserAccessibilityManagerWin()->TrackScrollingObject(this); 884 manager()->ToBrowserAccessibilityManagerWin()->TrackScrollingObject(this);
885 885
886 return S_OK; 886 return S_OK;
887 } 887 }
888 888
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
1036 IA2CoordinateType coordinate_type, 1036 IA2CoordinateType coordinate_type,
1037 LONG* x, 1037 LONG* x,
1038 LONG* y) { 1038 LONG* y) {
1039 if (!instance_active()) 1039 if (!instance_active())
1040 return E_FAIL; 1040 return E_FAIL;
1041 1041
1042 if (!x || !y) 1042 if (!x || !y)
1043 return E_INVALIDARG; 1043 return E_INVALIDARG;
1044 1044
1045 if (coordinate_type == IA2_COORDTYPE_SCREEN_RELATIVE) { 1045 if (coordinate_type == IA2_COORDTYPE_SCREEN_RELATIVE) {
1046 HWND parent_hwnd = 1046 gfx::Rect bounds = GetScreenBoundsRect();
1047 manager()->ToBrowserAccessibilityManagerWin()->GetParentHWND(); 1047 *x = bounds.x();
1048 if (!parent_hwnd) 1048 *y = bounds.y();
1049 return E_FAIL;
1050 POINT top_left = {0, 0};
1051 ::ClientToScreen(parent_hwnd, &top_left);
1052 *x = GetLocation().x() + top_left.x;
1053 *y = GetLocation().y() + top_left.y;
1054 } else if (coordinate_type == IA2_COORDTYPE_PARENT_RELATIVE) { 1049 } else if (coordinate_type == IA2_COORDTYPE_PARENT_RELATIVE) {
1055 *x = GetLocation().x(); 1050 gfx::Rect bounds = GetPageBoundsRect();
1056 *y = GetLocation().y(); 1051 gfx::Rect parent_bounds =
1057 if (GetParent()) { 1052 GetParent() ? GetParent()->GetPageBoundsRect() : gfx::Rect();
1058 *x -= GetParent()->GetLocation().x(); 1053 *x = bounds.x() - parent_bounds.x();
1059 *y -= GetParent()->GetLocation().y(); 1054 *y = bounds.y() - parent_bounds.y();
1060 }
1061 } else { 1055 } else {
1062 return E_INVALIDARG; 1056 return E_INVALIDARG;
1063 } 1057 }
1064 1058
1065 return S_OK; 1059 return S_OK;
1066 } 1060 }
1067 1061
1068 STDMETHODIMP BrowserAccessibilityWin::get_imageSize(LONG* height, LONG* width) { 1062 STDMETHODIMP BrowserAccessibilityWin::get_imageSize(LONG* height, LONG* width) {
1069 if (!instance_active()) 1063 if (!instance_active())
1070 return E_FAIL; 1064 return E_FAIL;
1071 1065
1072 if (!height || !width) 1066 if (!height || !width)
1073 return E_INVALIDARG; 1067 return E_INVALIDARG;
1074 1068
1075 *height = GetLocation().height(); 1069 *height = GetPageBoundsRect().height();
1076 *width = GetLocation().width(); 1070 *width = GetPageBoundsRect().width();
1077 return S_OK; 1071 return S_OK;
1078 } 1072 }
1079 1073
1080 // 1074 //
1081 // IAccessibleTable methods. 1075 // IAccessibleTable methods.
1082 // 1076 //
1083 1077
1084 STDMETHODIMP BrowserAccessibilityWin::get_accessibleAt( 1078 STDMETHODIMP BrowserAccessibilityWin::get_accessibleAt(
1085 long row, 1079 long row,
1086 long column, 1080 long column,
(...skipping 920 matching lines...) Expand 10 before | Expand all | Expand 10 after
2007 return E_INVALIDARG; 2001 return E_INVALIDARG;
2008 2002
2009 const base::string16& text_str = GetText(); 2003 const base::string16& text_str = GetText();
2010 HandleSpecialTextOffset(text_str, &offset); 2004 HandleSpecialTextOffset(text_str, &offset);
2011 2005
2012 if (offset < 0 || offset > static_cast<LONG>(text_str.size())) 2006 if (offset < 0 || offset > static_cast<LONG>(text_str.size()))
2013 return E_INVALIDARG; 2007 return E_INVALIDARG;
2014 2008
2015 gfx::Rect character_bounds; 2009 gfx::Rect character_bounds;
2016 if (coordinate_type == IA2_COORDTYPE_SCREEN_RELATIVE) { 2010 if (coordinate_type == IA2_COORDTYPE_SCREEN_RELATIVE) {
2017 character_bounds = GetGlobalBoundsForRange(offset, 1); 2011 character_bounds = GetScreenBoundsForRange(offset, 1);
2018 } else if (coordinate_type == IA2_COORDTYPE_PARENT_RELATIVE) { 2012 } else if (coordinate_type == IA2_COORDTYPE_PARENT_RELATIVE) {
2019 character_bounds = GetLocalBoundsForRange(offset, 1); 2013 character_bounds = GetPageBoundsForRange(offset, 1);
2020 character_bounds -= GetLocation().OffsetFromOrigin(); 2014 if (GetParent())
2015 character_bounds -= GetParent()->GetPageBoundsRect().OffsetFromOrigin();
2021 } else { 2016 } else {
2022 return E_INVALIDARG; 2017 return E_INVALIDARG;
2023 } 2018 }
2024 2019
2025 *out_x = character_bounds.x(); 2020 *out_x = character_bounds.x();
2026 *out_y = character_bounds.y(); 2021 *out_y = character_bounds.y();
2027 *out_width = character_bounds.width(); 2022 *out_width = character_bounds.width();
2028 *out_height = character_bounds.height(); 2023 *out_height = character_bounds.height();
2029 2024
2030 return S_OK; 2025 return S_OK;
(...skipping 1060 matching lines...) Expand 10 before | Expand all | Expand 10 after
3091 3086
3092 if (!out_x || !out_y || !out_width || !out_height) 3087 if (!out_x || !out_y || !out_width || !out_height)
3093 return E_INVALIDARG; 3088 return E_INVALIDARG;
3094 3089
3095 unsigned int text_length = static_cast<unsigned int>(GetText().size()); 3090 unsigned int text_length = static_cast<unsigned int>(GetText().size());
3096 if (start_index > text_length || end_index > text_length || 3091 if (start_index > text_length || end_index > text_length ||
3097 start_index > end_index) { 3092 start_index > end_index) {
3098 return E_INVALIDARG; 3093 return E_INVALIDARG;
3099 } 3094 }
3100 3095
3101 gfx::Rect bounds = GetGlobalBoundsForRange( 3096 gfx::Rect bounds = GetScreenBoundsForRange(
3102 start_index, end_index - start_index); 3097 start_index, end_index - start_index);
3103 *out_x = bounds.x(); 3098 *out_x = bounds.x();
3104 *out_y = bounds.y(); 3099 *out_y = bounds.y();
3105 *out_width = bounds.width(); 3100 *out_width = bounds.width();
3106 *out_height = bounds.height(); 3101 *out_height = bounds.height();
3107 return S_OK; 3102 return S_OK;
3108 } 3103 }
3109 3104
3110 STDMETHODIMP BrowserAccessibilityWin::scrollToSubstring( 3105 STDMETHODIMP BrowserAccessibilityWin::scrollToSubstring(
3111 unsigned int start_index, 3106 unsigned int start_index,
3112 unsigned int end_index) { 3107 unsigned int end_index) {
3113 if (!instance_active()) 3108 if (!instance_active())
3114 return E_FAIL; 3109 return E_FAIL;
3115 3110
3116 unsigned int text_length = static_cast<unsigned int>(GetText().size()); 3111 unsigned int text_length = static_cast<unsigned int>(GetText().size());
3117 if (start_index > text_length || end_index > text_length || 3112 if (start_index > text_length || end_index > text_length ||
3118 start_index > end_index) { 3113 start_index > end_index) {
3119 return E_INVALIDARG; 3114 return E_INVALIDARG;
3120 } 3115 }
3121 3116
3122 manager()->ScrollToMakeVisible(*this, GetLocalBoundsForRange( 3117 manager()->ScrollToMakeVisible(*this, GetPageBoundsForRange(
3123 start_index, end_index - start_index)); 3118 start_index, end_index - start_index));
3124 manager()->ToBrowserAccessibilityManagerWin()->TrackScrollingObject(this); 3119 manager()->ToBrowserAccessibilityManagerWin()->TrackScrollingObject(this);
3125 3120
3126 return S_OK; 3121 return S_OK;
3127 } 3122 }
3128 3123
3129 STDMETHODIMP BrowserAccessibilityWin::get_fontFamily(BSTR* font_family) { 3124 STDMETHODIMP BrowserAccessibilityWin::get_fontFamily(BSTR* font_family) {
3130 if (!font_family) 3125 if (!font_family)
3131 return E_INVALIDARG; 3126 return E_INVALIDARG;
3132 *font_family = nullptr; 3127 *font_family = nullptr;
(...skipping 2069 matching lines...) Expand 10 before | Expand all | Expand 10 after
5202 return static_cast<BrowserAccessibilityWin*>(obj); 5197 return static_cast<BrowserAccessibilityWin*>(obj);
5203 } 5198 }
5204 5199
5205 const BrowserAccessibilityWin* 5200 const BrowserAccessibilityWin*
5206 ToBrowserAccessibilityWin(const BrowserAccessibility* obj) { 5201 ToBrowserAccessibilityWin(const BrowserAccessibility* obj) {
5207 DCHECK(!obj || obj->IsNative()); 5202 DCHECK(!obj || obj->IsNative());
5208 return static_cast<const BrowserAccessibilityWin*>(obj); 5203 return static_cast<const BrowserAccessibilityWin*>(obj);
5209 } 5204 }
5210 5205
5211 } // namespace content 5206 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698