| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_manager_android.h" | 5 #include "content/browser/accessibility/browser_accessibility_manager_android.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <cmath> | 9 #include <cmath> |
| 10 | 10 |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 | 201 |
| 202 if (event_type == ui::AX_EVENT_HOVER) { | 202 if (event_type == ui::AX_EVENT_HOVER) { |
| 203 HandleHoverEvent(node); | 203 HandleHoverEvent(node); |
| 204 return; | 204 return; |
| 205 } | 205 } |
| 206 | 206 |
| 207 // Always send AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED to notify | 207 // Always send AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED to notify |
| 208 // the Android system that the accessibility hierarchy rooted at this | 208 // the Android system that the accessibility hierarchy rooted at this |
| 209 // node has changed. | 209 // node has changed. |
| 210 Java_BrowserAccessibilityManager_handleContentChanged( | 210 Java_BrowserAccessibilityManager_handleContentChanged( |
| 211 env, obj.obj(), node->GetId()); | 211 env, obj.obj(), node->unique_id()); |
| 212 | 212 |
| 213 switch (event_type) { | 213 switch (event_type) { |
| 214 case ui::AX_EVENT_LOAD_COMPLETE: | 214 case ui::AX_EVENT_LOAD_COMPLETE: |
| 215 Java_BrowserAccessibilityManager_handlePageLoaded( | 215 Java_BrowserAccessibilityManager_handlePageLoaded( |
| 216 env, obj.obj(), GetFocus()->GetId()); | 216 env, obj.obj(), GetFocus()->unique_id()); |
| 217 break; | 217 break; |
| 218 case ui::AX_EVENT_FOCUS: | 218 case ui::AX_EVENT_FOCUS: |
| 219 Java_BrowserAccessibilityManager_handleFocusChanged( | 219 Java_BrowserAccessibilityManager_handleFocusChanged( |
| 220 env, obj.obj(), node->GetId()); | 220 env, obj.obj(), node->unique_id()); |
| 221 break; | 221 break; |
| 222 case ui::AX_EVENT_CHECKED_STATE_CHANGED: | 222 case ui::AX_EVENT_CHECKED_STATE_CHANGED: |
| 223 Java_BrowserAccessibilityManager_handleCheckStateChanged( | 223 Java_BrowserAccessibilityManager_handleCheckStateChanged( |
| 224 env, obj.obj(), node->GetId()); | 224 env, obj.obj(), node->unique_id()); |
| 225 break; | 225 break; |
| 226 case ui::AX_EVENT_CLICKED: | 226 case ui::AX_EVENT_CLICKED: |
| 227 Java_BrowserAccessibilityManager_handleClicked(env, obj.obj(), | 227 Java_BrowserAccessibilityManager_handleClicked(env, obj.obj(), |
| 228 node->GetId()); | 228 node->unique_id()); |
| 229 break; | 229 break; |
| 230 case ui::AX_EVENT_SCROLL_POSITION_CHANGED: | 230 case ui::AX_EVENT_SCROLL_POSITION_CHANGED: |
| 231 Java_BrowserAccessibilityManager_handleScrollPositionChanged( | 231 Java_BrowserAccessibilityManager_handleScrollPositionChanged( |
| 232 env, obj.obj(), node->GetId()); | 232 env, obj.obj(), node->unique_id()); |
| 233 break; | 233 break; |
| 234 case ui::AX_EVENT_SCROLLED_TO_ANCHOR: | 234 case ui::AX_EVENT_SCROLLED_TO_ANCHOR: |
| 235 Java_BrowserAccessibilityManager_handleScrolledToAnchor( | 235 Java_BrowserAccessibilityManager_handleScrolledToAnchor( |
| 236 env, obj.obj(), node->GetId()); | 236 env, obj.obj(), node->unique_id()); |
| 237 break; | 237 break; |
| 238 case ui::AX_EVENT_ALERT: | 238 case ui::AX_EVENT_ALERT: |
| 239 // An alert is a special case of live region. Fall through to the | 239 // An alert is a special case of live region. Fall through to the |
| 240 // next case to handle it. | 240 // next case to handle it. |
| 241 case ui::AX_EVENT_SHOW: { | 241 case ui::AX_EVENT_SHOW: { |
| 242 // This event is fired when an object appears in a live region. | 242 // This event is fired when an object appears in a live region. |
| 243 // Speak its text. | 243 // Speak its text. |
| 244 Java_BrowserAccessibilityManager_announceLiveRegionText( | 244 Java_BrowserAccessibilityManager_announceLiveRegionText( |
| 245 env, obj.obj(), | 245 env, obj.obj(), |
| 246 base::android::ConvertUTF16ToJavaString( | 246 base::android::ConvertUTF16ToJavaString( |
| 247 env, android_node->GetText()).obj()); | 247 env, android_node->GetText()).obj()); |
| 248 break; | 248 break; |
| 249 } | 249 } |
| 250 case ui::AX_EVENT_TEXT_SELECTION_CHANGED: | 250 case ui::AX_EVENT_TEXT_SELECTION_CHANGED: |
| 251 Java_BrowserAccessibilityManager_handleTextSelectionChanged( | 251 Java_BrowserAccessibilityManager_handleTextSelectionChanged( |
| 252 env, obj.obj(), node->GetId()); | 252 env, obj.obj(), node->unique_id()); |
| 253 break; | 253 break; |
| 254 case ui::AX_EVENT_TEXT_CHANGED: | 254 case ui::AX_EVENT_TEXT_CHANGED: |
| 255 case ui::AX_EVENT_VALUE_CHANGED: | 255 case ui::AX_EVENT_VALUE_CHANGED: |
| 256 if (android_node->IsEditableText() && GetFocus() == node) { | 256 if (android_node->IsEditableText() && GetFocus() == node) { |
| 257 Java_BrowserAccessibilityManager_handleEditableTextChanged( | 257 Java_BrowserAccessibilityManager_handleEditableTextChanged( |
| 258 env, obj.obj(), node->GetId()); | 258 env, obj.obj(), node->unique_id()); |
| 259 } else if (android_node->IsSlider()) { | 259 } else if (android_node->IsSlider()) { |
| 260 Java_BrowserAccessibilityManager_handleSliderChanged( | 260 Java_BrowserAccessibilityManager_handleSliderChanged( |
| 261 env, obj.obj(), node->GetId()); | 261 env, obj.obj(), node->unique_id()); |
| 262 } | 262 } |
| 263 break; | 263 break; |
| 264 default: | 264 default: |
| 265 // There are some notifications that aren't meaningful on Android. | 265 // There are some notifications that aren't meaningful on Android. |
| 266 // It's okay to skip them. | 266 // It's okay to skip them. |
| 267 break; | 267 break; |
| 268 } | 268 } |
| 269 } | 269 } |
| 270 | 270 |
| 271 void BrowserAccessibilityManagerAndroid::OnLocationChanges( | 271 void BrowserAccessibilityManagerAndroid::OnLocationChanges( |
| (...skipping 12 matching lines...) Expand all Loading... |
| 284 return; | 284 return; |
| 285 } | 285 } |
| 286 | 286 |
| 287 BrowserAccessibilityManager::OnLocationChanges(params); | 287 BrowserAccessibilityManager::OnLocationChanges(params); |
| 288 } | 288 } |
| 289 | 289 |
| 290 jint BrowserAccessibilityManagerAndroid::GetRootId( | 290 jint BrowserAccessibilityManagerAndroid::GetRootId( |
| 291 JNIEnv* env, | 291 JNIEnv* env, |
| 292 const JavaParamRef<jobject>& obj) { | 292 const JavaParamRef<jobject>& obj) { |
| 293 if (GetRoot()) | 293 if (GetRoot()) |
| 294 return static_cast<jint>(GetRoot()->GetId()); | 294 return static_cast<jint>(GetRoot()->unique_id()); |
| 295 else | 295 else |
| 296 return -1; | 296 return -1; |
| 297 } | 297 } |
| 298 | 298 |
| 299 jboolean BrowserAccessibilityManagerAndroid::IsNodeValid( | 299 jboolean BrowserAccessibilityManagerAndroid::IsNodeValid( |
| 300 JNIEnv* env, | 300 JNIEnv* env, |
| 301 const JavaParamRef<jobject>& obj, | 301 const JavaParamRef<jobject>& obj, |
| 302 jint id) { | 302 jint id) { |
| 303 return GetFromID(id) != NULL; | 303 return GetFromUniqueID(id) != NULL; |
| 304 } | 304 } |
| 305 | 305 |
| 306 void BrowserAccessibilityManagerAndroid::HitTest( | 306 void BrowserAccessibilityManagerAndroid::HitTest( |
| 307 JNIEnv* env, | 307 JNIEnv* env, |
| 308 const JavaParamRef<jobject>& obj, | 308 const JavaParamRef<jobject>& obj, |
| 309 jint x, | 309 jint x, |
| 310 jint y) { | 310 jint y) { |
| 311 if (delegate()) | 311 if (delegate()) |
| 312 delegate()->AccessibilityHitTest(gfx::Point(x, y)); | 312 delegate()->AccessibilityHitTest(gfx::Point(x, y)); |
| 313 } | 313 } |
| 314 | 314 |
| 315 jboolean BrowserAccessibilityManagerAndroid::IsEditableText( | 315 jboolean BrowserAccessibilityManagerAndroid::IsEditableText( |
| 316 JNIEnv* env, | 316 JNIEnv* env, |
| 317 const JavaParamRef<jobject>& obj, | 317 const JavaParamRef<jobject>& obj, |
| 318 jint id) { | 318 jint id) { |
| 319 BrowserAccessibilityAndroid* node = static_cast<BrowserAccessibilityAndroid*>( | 319 BrowserAccessibilityAndroid* node = GetFromUniqueID(id); |
| 320 GetFromID(id)); | |
| 321 if (!node) | 320 if (!node) |
| 322 return false; | 321 return false; |
| 323 | 322 |
| 324 return node->IsEditableText(); | 323 return node->IsEditableText(); |
| 325 } | 324 } |
| 326 | 325 |
| 327 jint BrowserAccessibilityManagerAndroid::GetEditableTextSelectionStart( | 326 jint BrowserAccessibilityManagerAndroid::GetEditableTextSelectionStart( |
| 328 JNIEnv* env, | 327 JNIEnv* env, |
| 329 const JavaParamRef<jobject>& obj, | 328 const JavaParamRef<jobject>& obj, |
| 330 jint id) { | 329 jint id) { |
| 331 BrowserAccessibilityAndroid* node = static_cast<BrowserAccessibilityAndroid*>( | 330 BrowserAccessibilityAndroid* node = GetFromUniqueID(id); |
| 332 GetFromID(id)); | |
| 333 if (!node) | 331 if (!node) |
| 334 return false; | 332 return false; |
| 335 | 333 |
| 336 return node->GetIntAttribute(ui::AX_ATTR_TEXT_SEL_START); | 334 return node->GetIntAttribute(ui::AX_ATTR_TEXT_SEL_START); |
| 337 } | 335 } |
| 338 | 336 |
| 339 jint BrowserAccessibilityManagerAndroid::GetEditableTextSelectionEnd( | 337 jint BrowserAccessibilityManagerAndroid::GetEditableTextSelectionEnd( |
| 340 JNIEnv* env, | 338 JNIEnv* env, |
| 341 const JavaParamRef<jobject>& obj, | 339 const JavaParamRef<jobject>& obj, |
| 342 jint id) { | 340 jint id) { |
| 343 BrowserAccessibilityAndroid* node = static_cast<BrowserAccessibilityAndroid*>( | 341 BrowserAccessibilityAndroid* node = GetFromUniqueID(id); |
| 344 GetFromID(id)); | |
| 345 if (!node) | 342 if (!node) |
| 346 return false; | 343 return false; |
| 347 | 344 |
| 348 return node->GetIntAttribute(ui::AX_ATTR_TEXT_SEL_END); | 345 return node->GetIntAttribute(ui::AX_ATTR_TEXT_SEL_END); |
| 349 } | 346 } |
| 350 | 347 |
| 351 jboolean BrowserAccessibilityManagerAndroid::PopulateAccessibilityNodeInfo( | 348 jboolean BrowserAccessibilityManagerAndroid::PopulateAccessibilityNodeInfo( |
| 352 JNIEnv* env, | 349 JNIEnv* env, |
| 353 const JavaParamRef<jobject>& obj, | 350 const JavaParamRef<jobject>& obj, |
| 354 const JavaParamRef<jobject>& info, | 351 const JavaParamRef<jobject>& info, |
| 355 jint id) { | 352 jint id) { |
| 356 BrowserAccessibilityAndroid* node = static_cast<BrowserAccessibilityAndroid*>( | 353 BrowserAccessibilityAndroid* node = GetFromUniqueID(id); |
| 357 GetFromID(id)); | |
| 358 if (!node) | 354 if (!node) |
| 359 return false; | 355 return false; |
| 360 | 356 |
| 361 if (node->GetParent()) { | 357 if (node->GetParent()) { |
| 362 Java_BrowserAccessibilityManager_setAccessibilityNodeInfoParent( | 358 Java_BrowserAccessibilityManager_setAccessibilityNodeInfoParent( |
| 363 env, obj, info, node->GetParent()->GetId()); | 359 env, obj, info, node->GetParent()->unique_id()); |
| 364 } | 360 } |
| 365 for (unsigned i = 0; i < node->PlatformChildCount(); ++i) { | 361 for (unsigned i = 0; i < node->PlatformChildCount(); ++i) { |
| 366 Java_BrowserAccessibilityManager_addAccessibilityNodeInfoChild( | 362 Java_BrowserAccessibilityManager_addAccessibilityNodeInfoChild( |
| 367 env, obj, info, node->InternalGetChild(i)->GetId()); | 363 env, obj, info, node->InternalGetChild(i)->unique_id()); |
| 368 } | 364 } |
| 369 Java_BrowserAccessibilityManager_setAccessibilityNodeInfoBooleanAttributes( | 365 Java_BrowserAccessibilityManager_setAccessibilityNodeInfoBooleanAttributes( |
| 370 env, obj, info, | 366 env, obj, info, |
| 371 id, | 367 id, |
| 372 node->IsCheckable(), | 368 node->IsCheckable(), |
| 373 node->IsChecked(), | 369 node->IsChecked(), |
| 374 node->IsClickable(), | 370 node->IsClickable(), |
| 375 node->IsEnabled(), | 371 node->IsEnabled(), |
| 376 node->IsFocusable(), | 372 node->IsFocusable(), |
| 377 node->IsFocused(), | 373 node->IsFocused(), |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 | 461 |
| 466 return true; | 462 return true; |
| 467 } | 463 } |
| 468 | 464 |
| 469 jboolean BrowserAccessibilityManagerAndroid::PopulateAccessibilityEvent( | 465 jboolean BrowserAccessibilityManagerAndroid::PopulateAccessibilityEvent( |
| 470 JNIEnv* env, | 466 JNIEnv* env, |
| 471 const JavaParamRef<jobject>& obj, | 467 const JavaParamRef<jobject>& obj, |
| 472 const JavaParamRef<jobject>& event, | 468 const JavaParamRef<jobject>& event, |
| 473 jint id, | 469 jint id, |
| 474 jint event_type) { | 470 jint event_type) { |
| 475 BrowserAccessibilityAndroid* node = static_cast<BrowserAccessibilityAndroid*>( | 471 BrowserAccessibilityAndroid* node = GetFromUniqueID(id); |
| 476 GetFromID(id)); | |
| 477 if (!node) | 472 if (!node) |
| 478 return false; | 473 return false; |
| 479 | 474 |
| 480 Java_BrowserAccessibilityManager_setAccessibilityEventBooleanAttributes( | 475 Java_BrowserAccessibilityManager_setAccessibilityEventBooleanAttributes( |
| 481 env, obj, event, | 476 env, obj, event, |
| 482 node->IsChecked(), | 477 node->IsChecked(), |
| 483 node->IsEnabled(), | 478 node->IsEnabled(), |
| 484 node->IsPassword(), | 479 node->IsPassword(), |
| 485 node->IsScrollable()); | 480 node->IsScrollable()); |
| 486 Java_BrowserAccessibilityManager_setAccessibilityEventClassName( | 481 Java_BrowserAccessibilityManager_setAccessibilityEventClassName( |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 node->RangeMax(), | 563 node->RangeMax(), |
| 569 node->RangeCurrentValue()); | 564 node->RangeCurrentValue()); |
| 570 } | 565 } |
| 571 | 566 |
| 572 return true; | 567 return true; |
| 573 } | 568 } |
| 574 | 569 |
| 575 void BrowserAccessibilityManagerAndroid::Click(JNIEnv* env, | 570 void BrowserAccessibilityManagerAndroid::Click(JNIEnv* env, |
| 576 const JavaParamRef<jobject>& obj, | 571 const JavaParamRef<jobject>& obj, |
| 577 jint id) { | 572 jint id) { |
| 578 BrowserAccessibility* node = GetFromID(id); | 573 BrowserAccessibilityAndroid* node = GetFromUniqueID(id); |
| 579 if (node) | 574 if (node) |
| 580 DoDefaultAction(*node); | 575 DoDefaultAction(*node); |
| 581 } | 576 } |
| 582 | 577 |
| 583 void BrowserAccessibilityManagerAndroid::Focus(JNIEnv* env, | 578 void BrowserAccessibilityManagerAndroid::Focus(JNIEnv* env, |
| 584 const JavaParamRef<jobject>& obj, | 579 const JavaParamRef<jobject>& obj, |
| 585 jint id) { | 580 jint id) { |
| 586 BrowserAccessibility* node = GetFromID(id); | 581 BrowserAccessibilityAndroid* node = GetFromUniqueID(id); |
| 587 if (node) | 582 if (node) |
| 588 SetFocus(*node); | 583 SetFocus(*node); |
| 589 } | 584 } |
| 590 | 585 |
| 591 void BrowserAccessibilityManagerAndroid::Blur( | 586 void BrowserAccessibilityManagerAndroid::Blur( |
| 592 JNIEnv* env, | 587 JNIEnv* env, |
| 593 const JavaParamRef<jobject>& obj) { | 588 const JavaParamRef<jobject>& obj) { |
| 594 SetFocus(*GetRoot()); | 589 SetFocus(*GetRoot()); |
| 595 } | 590 } |
| 596 | 591 |
| 597 void BrowserAccessibilityManagerAndroid::ScrollToMakeNodeVisible( | 592 void BrowserAccessibilityManagerAndroid::ScrollToMakeNodeVisible( |
| 598 JNIEnv* env, | 593 JNIEnv* env, |
| 599 const JavaParamRef<jobject>& obj, | 594 const JavaParamRef<jobject>& obj, |
| 600 jint id) { | 595 jint id) { |
| 601 BrowserAccessibility* node = GetFromID(id); | 596 BrowserAccessibilityAndroid* node = GetFromUniqueID(id); |
| 602 if (node) | 597 if (node) |
| 603 ScrollToMakeVisible(*node, gfx::Rect(node->GetLocation().size())); | 598 ScrollToMakeVisible(*node, gfx::Rect(node->GetLocation().size())); |
| 604 } | 599 } |
| 605 | 600 |
| 606 void BrowserAccessibilityManagerAndroid::SetTextFieldValue( | 601 void BrowserAccessibilityManagerAndroid::SetTextFieldValue( |
| 607 JNIEnv* env, | 602 JNIEnv* env, |
| 608 const JavaParamRef<jobject>& obj, | 603 const JavaParamRef<jobject>& obj, |
| 609 jint id, | 604 jint id, |
| 610 const JavaParamRef<jstring>& value) { | 605 const JavaParamRef<jstring>& value) { |
| 611 BrowserAccessibility* node = GetFromID(id); | 606 BrowserAccessibilityAndroid* node = GetFromUniqueID(id); |
| 612 if (node) { | 607 if (node) { |
| 613 BrowserAccessibilityManager::SetValue( | 608 BrowserAccessibilityManager::SetValue( |
| 614 *node, base::android::ConvertJavaStringToUTF16(env, value)); | 609 *node, base::android::ConvertJavaStringToUTF16(env, value)); |
| 615 } | 610 } |
| 616 } | 611 } |
| 617 | 612 |
| 618 void BrowserAccessibilityManagerAndroid::SetSelection( | 613 void BrowserAccessibilityManagerAndroid::SetSelection( |
| 619 JNIEnv* env, | 614 JNIEnv* env, |
| 620 const JavaParamRef<jobject>& obj, | 615 const JavaParamRef<jobject>& obj, |
| 621 jint id, | 616 jint id, |
| 622 jint start, | 617 jint start, |
| 623 jint end) { | 618 jint end) { |
| 624 BrowserAccessibility* node = GetFromID(id); | 619 BrowserAccessibilityAndroid* node = GetFromUniqueID(id); |
| 625 if (node) | 620 if (node) |
| 626 SetTextSelection(*node, start, end); | 621 SetTextSelection(*node, start, end); |
| 627 } | 622 } |
| 628 | 623 |
| 629 jboolean BrowserAccessibilityManagerAndroid::AdjustSlider( | 624 jboolean BrowserAccessibilityManagerAndroid::AdjustSlider( |
| 630 JNIEnv* env, | 625 JNIEnv* env, |
| 631 const JavaParamRef<jobject>& obj, | 626 const JavaParamRef<jobject>& obj, |
| 632 jint id, | 627 jint id, |
| 633 jboolean increment) { | 628 jboolean increment) { |
| 634 BrowserAccessibility* node = GetFromID(id); | 629 BrowserAccessibilityAndroid* node = GetFromUniqueID(id); |
| 635 if (!node) | 630 if (!node) |
| 636 return false; | 631 return false; |
| 637 | 632 |
| 638 BrowserAccessibilityAndroid* android_node = | 633 BrowserAccessibilityAndroid* android_node = |
| 639 static_cast<BrowserAccessibilityAndroid*>(node); | 634 static_cast<BrowserAccessibilityAndroid*>(node); |
| 640 | 635 |
| 641 if (!android_node->IsSlider() || !android_node->IsEnabled()) | 636 if (!android_node->IsSlider() || !android_node->IsEnabled()) |
| 642 return false; | 637 return false; |
| 643 | 638 |
| 644 float value = node->GetFloatAttribute(ui::AX_ATTR_VALUE_FOR_RANGE); | 639 float value = node->GetFloatAttribute(ui::AX_ATTR_VALUE_FOR_RANGE); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 674 if (ancestor->PlatformIsLeaf() || | 669 if (ancestor->PlatformIsLeaf() || |
| 675 (ancestor->IsFocusable() && !ancestor->HasFocusableChild())) { | 670 (ancestor->IsFocusable() && !ancestor->HasFocusableChild())) { |
| 676 node = ancestor; | 671 node = ancestor; |
| 677 // Don't break - we want the highest ancestor that's focusable or a | 672 // Don't break - we want the highest ancestor that's focusable or a |
| 678 // leaf node. | 673 // leaf node. |
| 679 } | 674 } |
| 680 ancestor = static_cast<BrowserAccessibilityAndroid*>(ancestor->GetParent()); | 675 ancestor = static_cast<BrowserAccessibilityAndroid*>(ancestor->GetParent()); |
| 681 } | 676 } |
| 682 | 677 |
| 683 Java_BrowserAccessibilityManager_handleHover( | 678 Java_BrowserAccessibilityManager_handleHover( |
| 684 env, obj.obj(), node->GetId()); | 679 env, obj.obj(), node->unique_id()); |
| 685 } | 680 } |
| 686 | 681 |
| 687 jint BrowserAccessibilityManagerAndroid::FindElementType( | 682 jint BrowserAccessibilityManagerAndroid::FindElementType( |
| 688 JNIEnv* env, | 683 JNIEnv* env, |
| 689 const JavaParamRef<jobject>& obj, | 684 const JavaParamRef<jobject>& obj, |
| 690 jint start_id, | 685 jint start_id, |
| 691 const JavaParamRef<jstring>& element_type_str, | 686 const JavaParamRef<jstring>& element_type_str, |
| 692 jboolean forwards) { | 687 jboolean forwards) { |
| 693 BrowserAccessibility* start_node = GetFromID(start_id); | 688 BrowserAccessibilityAndroid* start_node = GetFromUniqueID(start_id); |
| 694 if (!start_node) | 689 if (!start_node) |
| 695 return 0; | 690 return 0; |
| 696 | 691 |
| 697 BrowserAccessibilityManager* root_manager = GetRootManager(); | 692 BrowserAccessibilityManager* root_manager = GetRootManager(); |
| 698 if (!root_manager) | 693 if (!root_manager) |
| 699 return 0; | 694 return 0; |
| 700 | 695 |
| 701 BrowserAccessibility* root = root_manager->GetRoot(); | 696 BrowserAccessibility* root = root_manager->GetRoot(); |
| 702 if (!root) | 697 if (!root) |
| 703 return 0; | 698 return 0; |
| 704 | 699 |
| 705 AccessibilityMatchPredicate predicate = PredicateForSearchKey( | 700 AccessibilityMatchPredicate predicate = PredicateForSearchKey( |
| 706 base::android::ConvertJavaStringToUTF16(env, element_type_str)); | 701 base::android::ConvertJavaStringToUTF16(env, element_type_str)); |
| 707 | 702 |
| 708 OneShotAccessibilityTreeSearch tree_search(root); | 703 OneShotAccessibilityTreeSearch tree_search(root); |
| 709 tree_search.SetStartNode(start_node); | 704 tree_search.SetStartNode(start_node); |
| 710 tree_search.SetDirection( | 705 tree_search.SetDirection( |
| 711 forwards ? | 706 forwards ? |
| 712 OneShotAccessibilityTreeSearch::FORWARDS : | 707 OneShotAccessibilityTreeSearch::FORWARDS : |
| 713 OneShotAccessibilityTreeSearch::BACKWARDS); | 708 OneShotAccessibilityTreeSearch::BACKWARDS); |
| 714 tree_search.SetResultLimit(1); | 709 tree_search.SetResultLimit(1); |
| 715 tree_search.SetImmediateDescendantsOnly(false); | 710 tree_search.SetImmediateDescendantsOnly(false); |
| 716 tree_search.SetVisibleOnly(false); | 711 tree_search.SetVisibleOnly(false); |
| 717 tree_search.AddPredicate(predicate); | 712 tree_search.AddPredicate(predicate); |
| 718 | 713 |
| 719 if (tree_search.CountMatches() == 0) | 714 if (tree_search.CountMatches() == 0) |
| 720 return 0; | 715 return 0; |
| 721 | 716 |
| 722 return tree_search.GetMatchAtIndex(0)->GetId(); | 717 return tree_search.GetMatchAtIndex(0)->unique_id(); |
| 723 } | 718 } |
| 724 | 719 |
| 725 jboolean BrowserAccessibilityManagerAndroid::NextAtGranularity( | 720 jboolean BrowserAccessibilityManagerAndroid::NextAtGranularity( |
| 726 JNIEnv* env, | 721 JNIEnv* env, |
| 727 const JavaParamRef<jobject>& obj, | 722 const JavaParamRef<jobject>& obj, |
| 728 jint granularity, | 723 jint granularity, |
| 729 jboolean extend_selection, | 724 jboolean extend_selection, |
| 730 jint id, | 725 jint id, |
| 731 jint cursor_index) { | 726 jint cursor_index) { |
| 732 BrowserAccessibilityAndroid* node = static_cast<BrowserAccessibilityAndroid*>( | 727 BrowserAccessibilityAndroid* node = GetFromUniqueID(id); |
| 733 GetFromID(id)); | |
| 734 if (!node) | 728 if (!node) |
| 735 return false; | 729 return false; |
| 736 | 730 |
| 737 jint start_index = -1; | 731 jint start_index = -1; |
| 738 int end_index = -1; | 732 int end_index = -1; |
| 739 if (NextAtGranularity(granularity, cursor_index, node, | 733 if (NextAtGranularity(granularity, cursor_index, node, |
| 740 &start_index, &end_index)) { | 734 &start_index, &end_index)) { |
| 741 base::string16 text; | 735 base::string16 text; |
| 742 if (!node->IsPassword() || | 736 if (!node->IsPassword() || |
| 743 Java_BrowserAccessibilityManager_shouldExposePasswordText(env, obj)) { | 737 Java_BrowserAccessibilityManager_shouldExposePasswordText(env, obj)) { |
| 744 text = node->GetText(); | 738 text = node->GetText(); |
| 745 } | 739 } |
| 746 Java_BrowserAccessibilityManager_finishGranularityMove( | 740 Java_BrowserAccessibilityManager_finishGranularityMove( |
| 747 env, obj, base::android::ConvertUTF16ToJavaString( | 741 env, obj, base::android::ConvertUTF16ToJavaString( |
| 748 env, text).obj(), | 742 env, text).obj(), |
| 749 extend_selection, start_index, end_index, true); | 743 extend_selection, start_index, end_index, true); |
| 750 return true; | 744 return true; |
| 751 } | 745 } |
| 752 return false; | 746 return false; |
| 753 } | 747 } |
| 754 | 748 |
| 755 jboolean BrowserAccessibilityManagerAndroid::PreviousAtGranularity( | 749 jboolean BrowserAccessibilityManagerAndroid::PreviousAtGranularity( |
| 756 JNIEnv* env, | 750 JNIEnv* env, |
| 757 const JavaParamRef<jobject>& obj, | 751 const JavaParamRef<jobject>& obj, |
| 758 jint granularity, | 752 jint granularity, |
| 759 jboolean extend_selection, | 753 jboolean extend_selection, |
| 760 jint id, | 754 jint id, |
| 761 jint cursor_index) { | 755 jint cursor_index) { |
| 762 BrowserAccessibilityAndroid* node = static_cast<BrowserAccessibilityAndroid*>( | 756 BrowserAccessibilityAndroid* node = GetFromUniqueID(id); |
| 763 GetFromID(id)); | |
| 764 if (!node) | 757 if (!node) |
| 765 return false; | 758 return false; |
| 766 | 759 |
| 767 jint start_index = -1; | 760 jint start_index = -1; |
| 768 int end_index = -1; | 761 int end_index = -1; |
| 769 if (PreviousAtGranularity(granularity, cursor_index, node, | 762 if (PreviousAtGranularity(granularity, cursor_index, node, |
| 770 &start_index, &end_index)) { | 763 &start_index, &end_index)) { |
| 771 Java_BrowserAccessibilityManager_finishGranularityMove( | 764 Java_BrowserAccessibilityManager_finishGranularityMove( |
| 772 env, obj, base::android::ConvertUTF16ToJavaString( | 765 env, obj, base::android::ConvertUTF16ToJavaString( |
| 773 env, node->GetText()).obj(), | 766 env, node->GetText()).obj(), |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 873 const JavaParamRef<jobject>& obj, | 866 const JavaParamRef<jobject>& obj, |
| 874 jint id) { | 867 jint id) { |
| 875 if (delegate_) | 868 if (delegate_) |
| 876 delegate_->AccessibilitySetAccessibilityFocus(id); | 869 delegate_->AccessibilitySetAccessibilityFocus(id); |
| 877 } | 870 } |
| 878 | 871 |
| 879 bool BrowserAccessibilityManagerAndroid::IsSlider( | 872 bool BrowserAccessibilityManagerAndroid::IsSlider( |
| 880 JNIEnv* env, | 873 JNIEnv* env, |
| 881 const JavaParamRef<jobject>& obj, | 874 const JavaParamRef<jobject>& obj, |
| 882 jint id) { | 875 jint id) { |
| 883 BrowserAccessibilityAndroid* node = static_cast<BrowserAccessibilityAndroid*>( | 876 BrowserAccessibilityAndroid* node = GetFromUniqueID(id); |
| 884 GetFromID(id)); | |
| 885 if (!node) | 877 if (!node) |
| 886 return false; | 878 return false; |
| 887 | 879 |
| 888 return node->GetRole() == ui::AX_ROLE_SLIDER; | 880 return node->GetRole() == ui::AX_ROLE_SLIDER; |
| 889 } | 881 } |
| 890 | 882 |
| 891 bool BrowserAccessibilityManagerAndroid::Scroll( | 883 bool BrowserAccessibilityManagerAndroid::Scroll( |
| 892 JNIEnv* env, | 884 JNIEnv* env, |
| 893 const JavaParamRef<jobject>& obj, | 885 const JavaParamRef<jobject>& obj, |
| 894 jint id, | 886 jint id, |
| 895 int direction) { | 887 int direction) { |
| 896 BrowserAccessibilityAndroid* node = static_cast<BrowserAccessibilityAndroid*>( | 888 BrowserAccessibilityAndroid* node = GetFromUniqueID(id); |
| 897 GetFromID(id)); | |
| 898 if (!node) | 889 if (!node) |
| 899 return false; | 890 return false; |
| 900 | 891 |
| 901 return node->Scroll(direction); | 892 return node->Scroll(direction); |
| 902 } | 893 } |
| 903 | 894 |
| 904 void BrowserAccessibilityManagerAndroid::OnAtomicUpdateFinished( | 895 void BrowserAccessibilityManagerAndroid::OnAtomicUpdateFinished( |
| 905 ui::AXTree* tree, | 896 ui::AXTree* tree, |
| 906 bool root_changed, | 897 bool root_changed, |
| 907 const std::vector<ui::AXTreeDelegate::Change>& changes) { | 898 const std::vector<ui::AXTreeDelegate::Change>& changes) { |
| 908 if (root_changed) { | 899 if (root_changed) { |
| 909 JNIEnv* env = AttachCurrentThread(); | 900 JNIEnv* env = AttachCurrentThread(); |
| 910 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 901 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
| 911 if (obj.is_null()) | 902 if (obj.is_null()) |
| 912 return; | 903 return; |
| 913 | 904 |
| 914 Java_BrowserAccessibilityManager_handleNavigate(env, obj.obj()); | 905 Java_BrowserAccessibilityManager_handleNavigate(env, obj.obj()); |
| 915 } | 906 } |
| 916 } | 907 } |
| 917 | 908 |
| 918 bool | 909 bool |
| 919 BrowserAccessibilityManagerAndroid::UseRootScrollOffsetsWhenComputingBounds() { | 910 BrowserAccessibilityManagerAndroid::UseRootScrollOffsetsWhenComputingBounds() { |
| 920 // The Java layer handles the root scroll offset. | 911 // The Java layer handles the root scroll offset. |
| 921 return false; | 912 return false; |
| 922 } | 913 } |
| 923 | 914 |
| 915 BrowserAccessibilityAndroid* |
| 916 BrowserAccessibilityManagerAndroid::GetFromUniqueID(int32_t unique_id) { |
| 917 return static_cast<BrowserAccessibilityAndroid*>( |
| 918 BrowserAccessibility::GetFromUniqueID(unique_id)); |
| 919 } |
| 920 |
| 924 bool RegisterBrowserAccessibilityManager(JNIEnv* env) { | 921 bool RegisterBrowserAccessibilityManager(JNIEnv* env) { |
| 925 return RegisterNativesImpl(env); | 922 return RegisterNativesImpl(env); |
| 926 } | 923 } |
| 927 | 924 |
| 928 } // namespace content | 925 } // namespace content |
| OLD | NEW |