 Chromium Code Reviews
 Chromium Code Reviews Issue 6452011:
  Rework tree APIs to reflect Google style and more const-correctness....  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src/
    
  
    Issue 6452011:
  Rework tree APIs to reflect Google style and more const-correctness....  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src/| OLD | NEW | 
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "views/accessibility/view_accessibility.h" | 5 #include "views/accessibility/view_accessibility.h" | 
| 6 | 6 | 
| 7 #include "ui/base/view_prop.h" | 7 #include "ui/base/view_prop.h" | 
| 8 #include "views/controls/button/native_button.h" | 8 #include "views/controls/button/native_button.h" | 
| 9 #include "views/widget/widget.h" | 9 #include "views/widget/widget.h" | 
| 10 #include "views/widget/widget_win.h" | 10 #include "views/widget/widget_win.h" | 
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 101 } | 101 } | 
| 102 | 102 | 
| 103 STDMETHODIMP ViewAccessibility::accLocation( | 103 STDMETHODIMP ViewAccessibility::accLocation( | 
| 104 LONG* x_left, LONG* y_top, LONG* width, LONG* height, VARIANT var_id) { | 104 LONG* x_left, LONG* y_top, LONG* width, LONG* height, VARIANT var_id) { | 
| 105 if (!IsValidId(var_id) || !x_left || !y_top || !width || !height) | 105 if (!IsValidId(var_id) || !x_left || !y_top || !width || !height) | 
| 106 return E_INVALIDARG; | 106 return E_INVALIDARG; | 
| 107 | 107 | 
| 108 if (!view_) | 108 if (!view_) | 
| 109 return E_FAIL; | 109 return E_FAIL; | 
| 110 | 110 | 
| 111 gfx::Rect view_bounds; | 111 gfx::Rect view_bounds(view_->bounds()); | 
| 
sky
2011/02/08 19:11:54
I don't think you need this line anymore.
 | |
| 112 // Retrieving the parent View to be used for converting from view-to-screen | 112 if (!view_->bounds().IsEmpty()) { | 
| 113 // coordinates. | 113 *width = view_->width(); | 
| 114 views::View* parent = view_->GetParent(); | 114 *height = view_->height(); | 
| 115 | 115 gfx::Point topleft(view_->bounds().origin()); | 
| 116 if (parent == NULL) { | 116 views::View::ConvertPointToScreen(view_->parent() ? view_->parent() : view_, | 
| 117 // If no parent, remain within the same View. | 117 &topleft); | 
| 118 parent = view_; | |
| 119 } | |
| 120 | |
| 121 // Retrieve active View's bounds. | |
| 122 view_bounds = view_->bounds(); | |
| 123 | |
| 124 if (!view_bounds.IsEmpty()) { | |
| 125 *width = view_bounds.width(); | |
| 126 *height = view_bounds.height(); | |
| 127 | |
| 128 gfx::Point topleft(view_bounds.origin()); | |
| 129 views::View::ConvertPointToScreen(parent, &topleft); | |
| 130 *x_left = topleft.x(); | 118 *x_left = topleft.x(); | 
| 131 *y_top = topleft.y(); | 119 *y_top = topleft.y(); | 
| 132 } else { | 120 } else { | 
| 133 return E_FAIL; | 121 return E_FAIL; | 
| 134 } | 122 } | 
| 135 return S_OK; | 123 return S_OK; | 
| 136 } | 124 } | 
| 137 | 125 | 
| 138 STDMETHODIMP ViewAccessibility::accNavigate(LONG nav_dir, VARIANT start, | 126 STDMETHODIMP ViewAccessibility::accNavigate(LONG nav_dir, VARIANT start, | 
| 139 VARIANT* end) { | 127 VARIANT* end) { | 
| 140 if (start.vt != VT_I4 || !end) | 128 if (start.vt != VT_I4 || !end) | 
| 141 return E_INVALIDARG; | 129 return E_INVALIDARG; | 
| 142 | 130 | 
| 143 if (!view_) | 131 if (!view_) | 
| 144 return E_FAIL; | 132 return E_FAIL; | 
| 145 | 133 | 
| 146 switch (nav_dir) { | 134 switch (nav_dir) { | 
| 147 case NAVDIR_FIRSTCHILD: | 135 case NAVDIR_FIRSTCHILD: | 
| 148 case NAVDIR_LASTCHILD: { | 136 case NAVDIR_LASTCHILD: { | 
| 149 if (start.lVal != CHILDID_SELF) { | 137 if (start.lVal != CHILDID_SELF) { | 
| 150 // Start of navigation must be on the View itself. | 138 // Start of navigation must be on the View itself. | 
| 151 return E_INVALIDARG; | 139 return E_INVALIDARG; | 
| 152 } else if (view_->GetChildViewCount() == 0) { | 140 } else if (!view_->has_children()) { | 
| 153 // No children found. | 141 // No children found. | 
| 154 return S_FALSE; | 142 return S_FALSE; | 
| 155 } | 143 } | 
| 156 | 144 | 
| 157 // Set child_id based on first or last child. | 145 // Set child_id based on first or last child. | 
| 158 int child_id = 0; | 146 int child_id = 0; | 
| 159 if (nav_dir == NAVDIR_LASTCHILD) { | 147 if (nav_dir == NAVDIR_LASTCHILD) | 
| 160 child_id = view_->GetChildViewCount() - 1; | 148 child_id = view_->child_count() - 1; | 
| 161 } | |
| 162 | 149 | 
| 163 views::View* child = view_->GetChildViewAt(child_id); | 150 views::View* child = view_->GetChildViewAt(child_id); | 
| 164 end->vt = VT_DISPATCH; | 151 end->vt = VT_DISPATCH; | 
| 165 end->pdispVal = GetAccessibleForView(child); | 152 end->pdispVal = GetAccessibleForView(child); | 
| 166 end->pdispVal->AddRef(); | 153 end->pdispVal->AddRef(); | 
| 167 return S_OK; | 154 return S_OK; | 
| 168 } | 155 } | 
| 169 case NAVDIR_LEFT: | 156 case NAVDIR_LEFT: | 
| 170 case NAVDIR_UP: | 157 case NAVDIR_UP: | 
| 171 case NAVDIR_PREVIOUS: | 158 case NAVDIR_PREVIOUS: | 
| 172 case NAVDIR_RIGHT: | 159 case NAVDIR_RIGHT: | 
| 173 case NAVDIR_DOWN: | 160 case NAVDIR_DOWN: | 
| 174 case NAVDIR_NEXT: { | 161 case NAVDIR_NEXT: { | 
| 175 // Retrieve parent to access view index and perform bounds checking. | 162 // Retrieve parent to access view index and perform bounds checking. | 
| 176 views::View* parent = view_->GetParent(); | 163 views::View* parent = view_->parent(); | 
| 177 if (!parent) { | 164 if (!parent) { | 
| 178 return E_FAIL; | 165 return E_FAIL; | 
| 179 } | 166 } | 
| 180 | 167 | 
| 181 if (start.lVal == CHILDID_SELF) { | 168 if (start.lVal == CHILDID_SELF) { | 
| 182 int view_index = parent->GetChildIndex(view_); | 169 int view_index = parent->GetIndexOf(view_); | 
| 183 // Check navigation bounds, adjusting for View child indexing (MSAA | 170 // Check navigation bounds, adjusting for View child indexing (MSAA | 
| 184 // child indexing starts with 1, whereas View indexing starts with 0). | 171 // child indexing starts with 1, whereas View indexing starts with 0). | 
| 185 if (!IsValidNav(nav_dir, view_index, -1, | 172 if (!IsValidNav(nav_dir, view_index, -1, | 
| 186 parent->GetChildViewCount() - 1)) { | 173 parent->child_count() - 1)) { | 
| 187 // Navigation attempted to go out-of-bounds. | 174 // Navigation attempted to go out-of-bounds. | 
| 188 end->vt = VT_EMPTY; | 175 end->vt = VT_EMPTY; | 
| 189 return S_FALSE; | 176 return S_FALSE; | 
| 190 } else { | 177 } else { | 
| 191 if (IsNavDirNext(nav_dir)) { | 178 if (IsNavDirNext(nav_dir)) { | 
| 192 view_index += 1; | 179 view_index += 1; | 
| 193 } else { | 180 } else { | 
| 194 view_index -=1; | 181 view_index -=1; | 
| 195 } | 182 } | 
| 196 } | 183 } | 
| 197 | 184 | 
| 198 views::View* child = parent->GetChildViewAt(view_index); | 185 views::View* child = parent->GetChildViewAt(view_index); | 
| 199 end->pdispVal = GetAccessibleForView(child); | 186 end->pdispVal = GetAccessibleForView(child); | 
| 200 end->vt = VT_DISPATCH; | 187 end->vt = VT_DISPATCH; | 
| 201 end->pdispVal->AddRef(); | 188 end->pdispVal->AddRef(); | 
| 202 return S_OK; | 189 return S_OK; | 
| 203 } else { | 190 } else { | 
| 204 // Check navigation bounds, adjusting for MSAA child indexing (MSAA | 191 // Check navigation bounds, adjusting for MSAA child indexing (MSAA | 
| 205 // child indexing starts with 1, whereas View indexing starts with 0). | 192 // child indexing starts with 1, whereas View indexing starts with 0). | 
| 206 if (!IsValidNav(nav_dir, start.lVal, 0, | 193 if (!IsValidNav(nav_dir, start.lVal, 0, parent->child_count() + 1)) { | 
| 207 parent->GetChildViewCount() + 1)) { | |
| 208 // Navigation attempted to go out-of-bounds. | 194 // Navigation attempted to go out-of-bounds. | 
| 209 end->vt = VT_EMPTY; | 195 end->vt = VT_EMPTY; | 
| 210 return S_FALSE; | 196 return S_FALSE; | 
| 211 } else { | 197 } else { | 
| 212 if (IsNavDirNext(nav_dir)) { | 198 if (IsNavDirNext(nav_dir)) { | 
| 213 start.lVal += 1; | 199 start.lVal += 1; | 
| 214 } else { | 200 } else { | 
| 215 start.lVal -= 1; | 201 start.lVal -= 1; | 
| 216 } | 202 } | 
| 217 } | 203 } | 
| (...skipping 30 matching lines...) Expand all Loading... | |
| 248 | 234 | 
| 249 LONG child_id = V_I4(&var_child); | 235 LONG child_id = V_I4(&var_child); | 
| 250 | 236 | 
| 251 if (child_id == CHILDID_SELF) { | 237 if (child_id == CHILDID_SELF) { | 
| 252 // Remain with the same dispatch. | 238 // Remain with the same dispatch. | 
| 253 return S_OK; | 239 return S_OK; | 
| 254 } | 240 } | 
| 255 | 241 | 
| 256 views::View* child_view = NULL; | 242 views::View* child_view = NULL; | 
| 257 if (child_id > 0) { | 243 if (child_id > 0) { | 
| 258 if (child_id <= view_->GetChildViewCount()) { | 244 size_t child_id_as_index = static_cast<size_t>(child_id) - 1; | 
| 245 if (child_id_as_index < view_->child_count()) { | |
| 259 // Note: child_id is a one based index when indexing children. | 246 // Note: child_id is a one based index when indexing children. | 
| 260 child_view = view_->GetChildViewAt(child_id - 1); | 247 child_view = view_->GetChildViewAt(child_id_as_index); | 
| 261 } else { | 248 } else { | 
| 262 // Attempt to retrieve a child view with the specified id. | 249 // Attempt to retrieve a child view with the specified id. | 
| 263 child_view = view_->GetViewByID(child_id); | 250 child_view = view_->GetViewByID(child_id); | 
| 264 } | 251 } | 
| 265 } else { | 252 } else { | 
| 266 // Negative values are used for events fired using the view's WidgetWin | 253 // Negative values are used for events fired using the view's WidgetWin | 
| 267 views::WidgetWin* widget = | 254 views::WidgetWin* widget = | 
| 268 static_cast<views::WidgetWin*>(view_->GetWidget()); | 255 static_cast<views::WidgetWin*>(view_->GetWidget()); | 
| 269 child_view = widget->GetAccessibilityViewEventAt(child_id); | 256 child_view = widget->GetAccessibilityViewEventAt(child_id); | 
| 270 } | 257 } | 
| 271 | 258 | 
| 272 if (!child_view) { | 259 if (!child_view) { | 
| 273 // No child found. | 260 // No child found. | 
| 274 *disp_child = NULL; | 261 *disp_child = NULL; | 
| 275 return E_FAIL; | 262 return E_FAIL; | 
| 276 } | 263 } | 
| 277 | 264 | 
| 278 *disp_child = GetAccessibleForView(child_view); | 265 *disp_child = GetAccessibleForView(child_view); | 
| 279 (*disp_child)->AddRef(); | 266 (*disp_child)->AddRef(); | 
| 280 return S_OK; | 267 return S_OK; | 
| 281 } | 268 } | 
| 282 | 269 | 
| 283 STDMETHODIMP ViewAccessibility::get_accChildCount(LONG* child_count) { | 270 STDMETHODIMP ViewAccessibility::get_accChildCount(LONG* child_count) { | 
| 284 if (!child_count || !view_) | 271 if (!child_count || !view_) | 
| 285 return E_INVALIDARG; | 272 return E_INVALIDARG; | 
| 286 | 273 | 
| 287 if (!view_) | 274 if (!view_) | 
| 288 return E_FAIL; | 275 return E_FAIL; | 
| 289 | 276 | 
| 290 *child_count = view_->GetChildViewCount(); | 277 *child_count = view_->child_count(); | 
| 291 return S_OK; | 278 return S_OK; | 
| 292 } | 279 } | 
| 293 | 280 | 
| 294 STDMETHODIMP ViewAccessibility::get_accDefaultAction( | 281 STDMETHODIMP ViewAccessibility::get_accDefaultAction( | 
| 295 VARIANT var_id, BSTR* def_action) { | 282 VARIANT var_id, BSTR* def_action) { | 
| 296 if (!IsValidId(var_id) || !def_action) | 283 if (!IsValidId(var_id) || !def_action) | 
| 297 return E_INVALIDARG; | 284 return E_INVALIDARG; | 
| 298 | 285 | 
| 299 if (!view_) | 286 if (!view_) | 
| 300 return E_FAIL; | 287 return E_FAIL; | 
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 337 return E_FAIL; | 324 return E_FAIL; | 
| 338 | 325 | 
| 339 views::View* focus = NULL; | 326 views::View* focus = NULL; | 
| 340 views::FocusManager* focus_manager = view_->GetFocusManager(); | 327 views::FocusManager* focus_manager = view_->GetFocusManager(); | 
| 341 if (focus_manager) | 328 if (focus_manager) | 
| 342 focus = focus_manager->GetFocusedView(); | 329 focus = focus_manager->GetFocusedView(); | 
| 343 if (focus == view_) { | 330 if (focus == view_) { | 
| 344 // This view has focus. | 331 // This view has focus. | 
| 345 focus_child->vt = VT_I4; | 332 focus_child->vt = VT_I4; | 
| 346 focus_child->lVal = CHILDID_SELF; | 333 focus_child->lVal = CHILDID_SELF; | 
| 347 } else if (focus && view_->IsParentOf(focus)) { | 334 } else if (focus && view_->Contains(focus)) { | 
| 348 // Return the child object that has the keyboard focus. | 335 // Return the child object that has the keyboard focus. | 
| 349 focus_child->pdispVal = GetAccessibleForView(focus); | 336 focus_child->pdispVal = GetAccessibleForView(focus); | 
| 350 focus_child->pdispVal->AddRef(); | 337 focus_child->pdispVal->AddRef(); | 
| 351 return S_OK; | 338 return S_OK; | 
| 352 } else { | 339 } else { | 
| 353 // Neither this object nor any of its children has the keyboard focus. | 340 // Neither this object nor any of its children has the keyboard focus. | 
| 354 focus_child->vt = VT_EMPTY; | 341 focus_child->vt = VT_EMPTY; | 
| 355 } | 342 } | 
| 356 return S_OK; | 343 return S_OK; | 
| 357 } | 344 } | 
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 397 return S_OK; | 384 return S_OK; | 
| 398 } | 385 } | 
| 399 | 386 | 
| 400 STDMETHODIMP ViewAccessibility::get_accParent(IDispatch** disp_parent) { | 387 STDMETHODIMP ViewAccessibility::get_accParent(IDispatch** disp_parent) { | 
| 401 if (!disp_parent) | 388 if (!disp_parent) | 
| 402 return E_INVALIDARG; | 389 return E_INVALIDARG; | 
| 403 | 390 | 
| 404 if (!view_) | 391 if (!view_) | 
| 405 return E_FAIL; | 392 return E_FAIL; | 
| 406 | 393 | 
| 407 views::View* parent_view = view_->GetParent(); | 394 views::View* parent_view = view_->parent(); | 
| 408 | 395 | 
| 409 if (!parent_view) { | 396 if (!parent_view) { | 
| 410 // This function can get called during teardown of WidetWin so we | 397 // This function can get called during teardown of WidetWin so we | 
| 411 // should bail out if we fail to get the HWND. | 398 // should bail out if we fail to get the HWND. | 
| 412 if (!view_->GetWidget() || !view_->GetWidget()->GetNativeView()) { | 399 if (!view_->GetWidget() || !view_->GetWidget()->GetNativeView()) { | 
| 413 *disp_parent = NULL; | 400 *disp_parent = NULL; | 
| 414 return S_FALSE; | 401 return S_FALSE; | 
| 415 } | 402 } | 
| 416 | 403 | 
| 417 // For a View that has no parent (e.g. root), point the accessible parent to | 404 // For a View that has no parent (e.g. root), point the accessible parent to | 
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 521 void ViewAccessibility::SetState(VARIANT* msaa_state, views::View* view) { | 508 void ViewAccessibility::SetState(VARIANT* msaa_state, views::View* view) { | 
| 522 // Ensure the output param is initialized to zero. | 509 // Ensure the output param is initialized to zero. | 
| 523 msaa_state->lVal = 0; | 510 msaa_state->lVal = 0; | 
| 524 | 511 | 
| 525 // Default state; all views can have accessibility focus. | 512 // Default state; all views can have accessibility focus. | 
| 526 msaa_state->lVal |= STATE_SYSTEM_FOCUSABLE; | 513 msaa_state->lVal |= STATE_SYSTEM_FOCUSABLE; | 
| 527 | 514 | 
| 528 if (!view) | 515 if (!view) | 
| 529 return; | 516 return; | 
| 530 | 517 | 
| 531 if (!view->IsEnabled()) { | 518 if (!view->IsEnabled()) | 
| 532 msaa_state->lVal |= STATE_SYSTEM_UNAVAILABLE; | 519 msaa_state->lVal |= STATE_SYSTEM_UNAVAILABLE; | 
| 533 } | 520 if (!view->IsVisible()) | 
| 534 if (!view->IsVisible()) { | |
| 535 msaa_state->lVal |= STATE_SYSTEM_INVISIBLE; | 521 msaa_state->lVal |= STATE_SYSTEM_INVISIBLE; | 
| 536 } | 522 if (view->IsHotTracked()) | 
| 537 if (view->IsHotTracked()) { | |
| 538 msaa_state->lVal |= STATE_SYSTEM_HOTTRACKED; | 523 msaa_state->lVal |= STATE_SYSTEM_HOTTRACKED; | 
| 539 } | 524 if (view->IsPushed()) | 
| 540 if (view->IsPushed()) { | |
| 541 msaa_state->lVal |= STATE_SYSTEM_PRESSED; | 525 msaa_state->lVal |= STATE_SYSTEM_PRESSED; | 
| 542 } | |
| 543 // Check both for actual View focus, as well as accessibility focus. | |
| 544 views::View* parent = view->GetParent(); | |
| 545 | |
| 546 if (view->HasFocus()) | 526 if (view->HasFocus()) | 
| 547 msaa_state->lVal |= STATE_SYSTEM_FOCUSED; | 527 msaa_state->lVal |= STATE_SYSTEM_FOCUSED; | 
| 548 | 528 | 
| 549 // Add on any view-specific states. | 529 // Add on any view-specific states. | 
| 550 msaa_state->lVal |= MSAAState(view->GetAccessibleState()); | 530 msaa_state->lVal |= MSAAState(view->GetAccessibleState()); | 
| 551 } | 531 } | 
| 552 | 532 | 
| 553 // IAccessible functions not supported. | 533 // IAccessible functions not supported. | 
| 554 | 534 | 
| 555 STDMETHODIMP ViewAccessibility::get_accSelection(VARIANT* selected) { | 535 STDMETHODIMP ViewAccessibility::get_accSelection(VARIANT* selected) { | 
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 739 HWND native_view_window , IAccessible** accessible) { | 719 HWND native_view_window , IAccessible** accessible) { | 
| 740 if (IsWindow(native_view_window)) { | 720 if (IsWindow(native_view_window)) { | 
| 741 LRESULT ret = SendMessage(native_view_window, WM_GETOBJECT, 0, | 721 LRESULT ret = SendMessage(native_view_window, WM_GETOBJECT, 0, | 
| 742 OBJID_CLIENT); | 722 OBJID_CLIENT); | 
| 743 return ObjectFromLresult(ret, IID_IDispatch, 0, | 723 return ObjectFromLresult(ret, IID_IDispatch, 0, | 
| 744 reinterpret_cast<void**>(accessible)); | 724 reinterpret_cast<void**>(accessible)); | 
| 745 } | 725 } | 
| 746 | 726 | 
| 747 return E_FAIL; | 727 return E_FAIL; | 
| 748 } | 728 } | 
| OLD | NEW |