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

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: 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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
1033 IA2CoordinateType coordinate_type, 1033 IA2CoordinateType coordinate_type,
1034 LONG* x, 1034 LONG* x,
1035 LONG* y) { 1035 LONG* y) {
1036 if (!instance_active()) 1036 if (!instance_active())
1037 return E_FAIL; 1037 return E_FAIL;
1038 1038
1039 if (!x || !y) 1039 if (!x || !y)
1040 return E_INVALIDARG; 1040 return E_INVALIDARG;
1041 1041
1042 if (coordinate_type == IA2_COORDTYPE_SCREEN_RELATIVE) { 1042 if (coordinate_type == IA2_COORDTYPE_SCREEN_RELATIVE) {
1043 HWND parent_hwnd = 1043 gfx::Rect bounds = GetScreenBoundsRect();
aboxhall 2016/08/12 16:05:10 Ahhh this is so great.
1044 manager()->ToBrowserAccessibilityManagerWin()->GetParentHWND(); 1044 *x = bounds.x();
1045 if (!parent_hwnd) 1045 *y = bounds.y();
1046 return E_FAIL;
1047 POINT top_left = {0, 0};
1048 ::ClientToScreen(parent_hwnd, &top_left);
1049 *x = GetLocation().x() + top_left.x;
1050 *y = GetLocation().y() + top_left.y;
1051 } else if (coordinate_type == IA2_COORDTYPE_PARENT_RELATIVE) { 1046 } else if (coordinate_type == IA2_COORDTYPE_PARENT_RELATIVE) {
1052 *x = GetLocation().x(); 1047 gfx::Rect bounds = GetPageBoundsRect();
1053 *y = GetLocation().y(); 1048 gfx::Rect parent_bounds =
1054 if (GetParent()) { 1049 GetParent() ? GetParent()->GetPageBoundsRect() : gfx::Rect();
1055 *x -= GetParent()->GetLocation().x(); 1050 *x = bounds.x() - parent_bounds.x();
1056 *y -= GetParent()->GetLocation().y(); 1051 *y = bounds.y() - parent_bounds.y();
1057 }
1058 } else { 1052 } else {
1059 return E_INVALIDARG; 1053 return E_INVALIDARG;
1060 } 1054 }
1061 1055
1062 return S_OK; 1056 return S_OK;
1063 } 1057 }
1064 1058
1065 STDMETHODIMP BrowserAccessibilityWin::get_imageSize(LONG* height, LONG* width) { 1059 STDMETHODIMP BrowserAccessibilityWin::get_imageSize(LONG* height, LONG* width) {
1066 if (!instance_active()) 1060 if (!instance_active())
1067 return E_FAIL; 1061 return E_FAIL;
1068 1062
1069 if (!height || !width) 1063 if (!height || !width)
1070 return E_INVALIDARG; 1064 return E_INVALIDARG;
1071 1065
1072 *height = GetLocation().height(); 1066 *height = GetPageBoundsRect().height();
1073 *width = GetLocation().width(); 1067 *width = GetPageBoundsRect().width();
1074 return S_OK; 1068 return S_OK;
1075 } 1069 }
1076 1070
1077 // 1071 //
1078 // IAccessibleTable methods. 1072 // IAccessibleTable methods.
1079 // 1073 //
1080 1074
1081 STDMETHODIMP BrowserAccessibilityWin::get_accessibleAt( 1075 STDMETHODIMP BrowserAccessibilityWin::get_accessibleAt(
1082 long row, 1076 long row,
1083 long column, 1077 long column,
(...skipping 920 matching lines...) Expand 10 before | Expand all | Expand 10 after
2004 return E_INVALIDARG; 1998 return E_INVALIDARG;
2005 1999
2006 const base::string16& text_str = GetText(); 2000 const base::string16& text_str = GetText();
2007 HandleSpecialTextOffset(text_str, &offset); 2001 HandleSpecialTextOffset(text_str, &offset);
2008 2002
2009 if (offset < 0 || offset > static_cast<LONG>(text_str.size())) 2003 if (offset < 0 || offset > static_cast<LONG>(text_str.size()))
2010 return E_INVALIDARG; 2004 return E_INVALIDARG;
2011 2005
2012 gfx::Rect character_bounds; 2006 gfx::Rect character_bounds;
2013 if (coordinate_type == IA2_COORDTYPE_SCREEN_RELATIVE) { 2007 if (coordinate_type == IA2_COORDTYPE_SCREEN_RELATIVE) {
2014 character_bounds = GetGlobalBoundsForRange(offset, 1); 2008 character_bounds = GetScreenBoundsForRange(offset, 1);
2015 } else if (coordinate_type == IA2_COORDTYPE_PARENT_RELATIVE) { 2009 } else if (coordinate_type == IA2_COORDTYPE_PARENT_RELATIVE) {
2016 character_bounds = GetLocalBoundsForRange(offset, 1); 2010 character_bounds = GetPageBoundsForRange(offset, 1);
2017 character_bounds -= GetLocation().OffsetFromOrigin(); 2011 if (GetParent())
2012 character_bounds -= GetParent()->GetPageBoundsRect().OffsetFromOrigin();
2018 } else { 2013 } else {
2019 return E_INVALIDARG; 2014 return E_INVALIDARG;
2020 } 2015 }
2021 2016
2022 *out_x = character_bounds.x(); 2017 *out_x = character_bounds.x();
2023 *out_y = character_bounds.y(); 2018 *out_y = character_bounds.y();
2024 *out_width = character_bounds.width(); 2019 *out_width = character_bounds.width();
2025 *out_height = character_bounds.height(); 2020 *out_height = character_bounds.height();
2026 2021
2027 return S_OK; 2022 return S_OK;
(...skipping 1060 matching lines...) Expand 10 before | Expand all | Expand 10 after
3088 3083
3089 if (!out_x || !out_y || !out_width || !out_height) 3084 if (!out_x || !out_y || !out_width || !out_height)
3090 return E_INVALIDARG; 3085 return E_INVALIDARG;
3091 3086
3092 unsigned int text_length = static_cast<unsigned int>(GetText().size()); 3087 unsigned int text_length = static_cast<unsigned int>(GetText().size());
3093 if (start_index > text_length || end_index > text_length || 3088 if (start_index > text_length || end_index > text_length ||
3094 start_index > end_index) { 3089 start_index > end_index) {
3095 return E_INVALIDARG; 3090 return E_INVALIDARG;
3096 } 3091 }
3097 3092
3098 gfx::Rect bounds = GetGlobalBoundsForRange( 3093 gfx::Rect bounds = GetScreenBoundsForRange(
3099 start_index, end_index - start_index); 3094 start_index, end_index - start_index);
3100 *out_x = bounds.x(); 3095 *out_x = bounds.x();
3101 *out_y = bounds.y(); 3096 *out_y = bounds.y();
3102 *out_width = bounds.width(); 3097 *out_width = bounds.width();
3103 *out_height = bounds.height(); 3098 *out_height = bounds.height();
3104 return S_OK; 3099 return S_OK;
3105 } 3100 }
3106 3101
3107 STDMETHODIMP BrowserAccessibilityWin::scrollToSubstring( 3102 STDMETHODIMP BrowserAccessibilityWin::scrollToSubstring(
3108 unsigned int start_index, 3103 unsigned int start_index,
3109 unsigned int end_index) { 3104 unsigned int end_index) {
3110 if (!instance_active()) 3105 if (!instance_active())
3111 return E_FAIL; 3106 return E_FAIL;
3112 3107
3113 unsigned int text_length = static_cast<unsigned int>(GetText().size()); 3108 unsigned int text_length = static_cast<unsigned int>(GetText().size());
3114 if (start_index > text_length || end_index > text_length || 3109 if (start_index > text_length || end_index > text_length ||
3115 start_index > end_index) { 3110 start_index > end_index) {
3116 return E_INVALIDARG; 3111 return E_INVALIDARG;
3117 } 3112 }
3118 3113
3119 manager()->ScrollToMakeVisible(*this, GetLocalBoundsForRange( 3114 manager()->ScrollToMakeVisible(*this, GetPageBoundsForRange(
3120 start_index, end_index - start_index)); 3115 start_index, end_index - start_index));
3121 manager()->ToBrowserAccessibilityManagerWin()->TrackScrollingObject(this); 3116 manager()->ToBrowserAccessibilityManagerWin()->TrackScrollingObject(this);
3122 3117
3123 return S_OK; 3118 return S_OK;
3124 } 3119 }
3125 3120
3126 STDMETHODIMP BrowserAccessibilityWin::get_fontFamily(BSTR* font_family) { 3121 STDMETHODIMP BrowserAccessibilityWin::get_fontFamily(BSTR* font_family) {
3127 if (!font_family) 3122 if (!font_family)
3128 return E_INVALIDARG; 3123 return E_INVALIDARG;
3129 *font_family = nullptr; 3124 *font_family = nullptr;
(...skipping 2072 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