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

Side by Side Diff: chrome/renderer/extensions/automation_internal_custom_bindings.cc

Issue 1589623002: Keep track of accessibility focus across windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: git cl format Created 4 years, 10 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "chrome/renderer/extensions/automation_internal_custom_bindings.h" 5 #include "chrome/renderer/extensions/automation_internal_custom_bindings.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 base::Bind(&AutomationInternalCustomBindings::FN, \ 409 base::Bind(&AutomationInternalCustomBindings::FN, \
410 base::Unretained(this))) 410 base::Unretained(this)))
411 ROUTE_FUNCTION(IsInteractPermitted); 411 ROUTE_FUNCTION(IsInteractPermitted);
412 ROUTE_FUNCTION(GetSchemaAdditions); 412 ROUTE_FUNCTION(GetSchemaAdditions);
413 ROUTE_FUNCTION(GetRoutingID); 413 ROUTE_FUNCTION(GetRoutingID);
414 ROUTE_FUNCTION(StartCachingAccessibilityTrees); 414 ROUTE_FUNCTION(StartCachingAccessibilityTrees);
415 ROUTE_FUNCTION(DestroyAccessibilityTree); 415 ROUTE_FUNCTION(DestroyAccessibilityTree);
416 ROUTE_FUNCTION(AddTreeChangeObserver); 416 ROUTE_FUNCTION(AddTreeChangeObserver);
417 ROUTE_FUNCTION(RemoveTreeChangeObserver); 417 ROUTE_FUNCTION(RemoveTreeChangeObserver);
418 ROUTE_FUNCTION(GetChildIDAtIndex); 418 ROUTE_FUNCTION(GetChildIDAtIndex);
419 ROUTE_FUNCTION(GetFocus);
419 #undef ROUTE_FUNCTION 420 #undef ROUTE_FUNCTION
420 421
421 // Bindings that take a Tree ID and return a property of the tree. 422 // Bindings that take a Tree ID and return a property of the tree.
422 423
423 RouteTreeIDFunction( 424 RouteTreeIDFunction(
424 "GetRootID", [](v8::Isolate* isolate, v8::ReturnValue<v8::Value> result, 425 "GetRootID", [](v8::Isolate* isolate, v8::ReturnValue<v8::Value> result,
425 TreeCache* cache) { 426 TreeCache* cache) {
426 result.Set(v8::Integer::New(isolate, cache->tree.root()->id())); 427 result.Set(v8::Integer::New(isolate, cache->tree.root()->id()));
427 }); 428 });
428 RouteTreeIDFunction( 429 RouteTreeIDFunction(
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
770 iter != tree_change_observers_.end(); ++iter) { 771 iter != tree_change_observers_.end(); ++iter) {
771 if (iter->id == observer_id) { 772 if (iter->id == observer_id) {
772 tree_change_observers_.erase(iter); 773 tree_change_observers_.erase(iter);
773 break; 774 break;
774 } 775 }
775 } 776 }
776 777
777 UpdateOverallTreeChangeObserverFilter(); 778 UpdateOverallTreeChangeObserverFilter();
778 } 779 }
779 780
781 void AutomationInternalCustomBindings::GetFocus(
782 const v8::FunctionCallbackInfo<v8::Value>& args) {
783 if (args.Length() != 1 || !args[0]->IsNumber()) {
784 ThrowInvalidArgumentsException(this);
785 return;
786 }
787
788 int tree_id = args[0]->Int32Value();
789 ui::AXNode* focus = nullptr;
790 TreeCache* cache = GetTreeCacheFromTreeID(tree_id);
791 if (!cache)
792 return;
793
794 int focus_id = cache->tree.data().focus_id;
795 focus = cache->tree.GetFromId(focus_id);
796 if (!focus)
797 return;
798
799 while (focus->data().HasIntAttribute(ui::AX_ATTR_CHILD_TREE_ID)) {
800 // Try to keep following focus recursively, by letting |tree_id| be the
801 // new subtree to search in, while keeping |focus_tree_id| set to the tree
802 // where we know we found a focused node.
803 int child_tree_id =
804 focus->data().GetIntAttribute(ui::AX_ATTR_CHILD_TREE_ID);
805
806 TreeCache* child_cache = GetTreeCacheFromTreeID(child_tree_id);
807 if (!child_cache)
808 break;
809
810 int child_focus_id = child_cache->tree.data().focus_id;
811 ui::AXNode* child_focus = cache->tree.GetFromId(focus_id);
812 if (!child_focus)
813 break;
814
815 focus = child_focus;
816 tree_id = child_tree_id;
817 focus_id = child_focus_id;
818 }
819
820 v8::Isolate* isolate = GetIsolate();
821 v8::Local<v8::Object> result(v8::Object::New(isolate));
822 result->Set(CreateV8String(isolate, "treeId"),
823 v8::Integer::New(isolate, tree_id));
824 result->Set(CreateV8String(isolate, "nodeId"),
825 v8::Integer::New(isolate, focus_id));
826 args.GetReturnValue().Set(result);
827 }
828
780 void AutomationInternalCustomBindings::UpdateOverallTreeChangeObserverFilter() { 829 void AutomationInternalCustomBindings::UpdateOverallTreeChangeObserverFilter() {
781 tree_change_observer_overall_filter_ = 830 tree_change_observer_overall_filter_ =
782 api::automation::TREE_CHANGE_OBSERVER_FILTER_NOTREECHANGES; 831 api::automation::TREE_CHANGE_OBSERVER_FILTER_NOTREECHANGES;
783 for (const auto& observer : tree_change_observers_) { 832 for (const auto& observer : tree_change_observers_) {
784 tree_change_observer_overall_filter_ = 833 tree_change_observer_overall_filter_ =
785 std::max(observer.filter, tree_change_observer_overall_filter_); 834 std::max(observer.filter, tree_change_observer_overall_filter_);
786 } 835 }
787 } 836 }
788 837
789 void AutomationInternalCustomBindings::RouteTreeIDFunction( 838 void AutomationInternalCustomBindings::RouteTreeIDFunction(
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
1054 v8::Local<v8::Array> args(v8::Array::New(GetIsolate(), 2U)); 1103 v8::Local<v8::Array> args(v8::Array::New(GetIsolate(), 2U));
1055 args->Set(0U, v8::Integer::New(GetIsolate(), tree_id)); 1104 args->Set(0U, v8::Integer::New(GetIsolate(), tree_id));
1056 v8::Local<v8::Array> nodes(v8::Array::New(GetIsolate(), ids.size())); 1105 v8::Local<v8::Array> nodes(v8::Array::New(GetIsolate(), ids.size()));
1057 args->Set(1U, nodes); 1106 args->Set(1U, nodes);
1058 for (size_t i = 0; i < ids.size(); ++i) 1107 for (size_t i = 0; i < ids.size(); ++i)
1059 nodes->Set(i, v8::Integer::New(GetIsolate(), ids[i])); 1108 nodes->Set(i, v8::Integer::New(GetIsolate(), ids[i]));
1060 context()->DispatchEvent("automationInternal.onNodesRemoved", args); 1109 context()->DispatchEvent("automationInternal.onNodesRemoved", args);
1061 } 1110 }
1062 1111
1063 } // namespace extensions 1112 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698