OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/containers/hash_tables.h" |
| 6 #include "ui/accessibility/platform/test_ax_node_wrapper.h" |
| 7 |
| 8 namespace ui { |
| 9 |
| 10 namespace { |
| 11 |
| 12 // A global map from AXNodes to TestAXNodeWrappers. |
| 13 base::hash_map<AXNode*, TestAXNodeWrapper*> g_node_to_wrapper_map; |
| 14 |
| 15 // A global coordinate offset. |
| 16 gfx::Vector2d g_offset; |
| 17 |
| 18 // A simple implementation of AXTreeDelegate to catch when AXNodes are |
| 19 // deleted so we can delete their wrappers. |
| 20 class TestAXTreeDelegate : public AXTreeDelegate { |
| 21 void OnNodeWillBeDeleted(AXNode* node) override { |
| 22 auto iter = g_node_to_wrapper_map.find(node); |
| 23 if (iter != g_node_to_wrapper_map.end()) { |
| 24 TestAXNodeWrapper* wrapper = iter->second; |
| 25 delete wrapper; |
| 26 g_node_to_wrapper_map.erase(iter->first); |
| 27 } |
| 28 } |
| 29 void OnSubtreeWillBeDeleted(AXNode* node) override {} |
| 30 void OnNodeCreated(AXNode* node) override {} |
| 31 void OnNodeChanged(AXNode* node) override {} |
| 32 void OnAtomicUpdateFinished(bool root_changed, |
| 33 const std::vector<Change>& changes) override {} |
| 34 }; |
| 35 |
| 36 TestAXTreeDelegate g_ax_tree_delegate; |
| 37 |
| 38 } // namespace |
| 39 |
| 40 // static |
| 41 TestAXNodeWrapper* TestAXNodeWrapper::GetOrCreate(AXTree* tree, AXNode* node) { |
| 42 // Just return NULL if |node| is NULL; this makes test code simpler because |
| 43 // now we don't have to null-check AXNode* every time we call GetOrCreate. |
| 44 if (!node) |
| 45 return nullptr; |
| 46 |
| 47 auto iter = g_node_to_wrapper_map.find(node); |
| 48 if (iter != g_node_to_wrapper_map.end()) |
| 49 return iter->second; |
| 50 TestAXNodeWrapper* wrapper = new TestAXNodeWrapper(tree, node); |
| 51 g_node_to_wrapper_map[node] = wrapper; |
| 52 return wrapper; |
| 53 } |
| 54 |
| 55 // static |
| 56 void TestAXNodeWrapper::SetGlobalCoordinateOffset(const gfx::Vector2d& offset) { |
| 57 g_offset = offset; |
| 58 } |
| 59 |
| 60 TestAXNodeWrapper::~TestAXNodeWrapper() { |
| 61 platform_node_->Destroy(); |
| 62 } |
| 63 |
| 64 const AXNodeData* TestAXNodeWrapper::GetData() { |
| 65 return &node_->data(); |
| 66 } |
| 67 |
| 68 gfx::NativeViewAccessible TestAXNodeWrapper::GetParent() { |
| 69 TestAXNodeWrapper* parent_wrapper = GetOrCreate(tree_, node_->parent()); |
| 70 return parent_wrapper ? |
| 71 parent_wrapper->ax_platform_node()->GetNativeViewAccessible() : |
| 72 nullptr; |
| 73 } |
| 74 |
| 75 int TestAXNodeWrapper::GetChildCount() { |
| 76 return node_->child_count(); |
| 77 } |
| 78 |
| 79 gfx::NativeViewAccessible TestAXNodeWrapper::ChildAtIndex(int index) { |
| 80 CHECK_GE(index, 0); |
| 81 CHECK_LT(index, GetChildCount()); |
| 82 TestAXNodeWrapper* child_wrapper = |
| 83 GetOrCreate(tree_, node_->children()[index]); |
| 84 return child_wrapper ? |
| 85 child_wrapper->ax_platform_node()->GetNativeViewAccessible() : |
| 86 nullptr; |
| 87 } |
| 88 |
| 89 int TestAXNodeWrapper::GetIndexInParent() { |
| 90 return node_->index_in_parent(); |
| 91 } |
| 92 |
| 93 gfx::Vector2d TestAXNodeWrapper::GetGlobalCoordinateOffset() { |
| 94 return g_offset; |
| 95 } |
| 96 |
| 97 gfx::NativeViewAccessible TestAXNodeWrapper::HitTestSync(int x, int y) { |
| 98 return nullptr; |
| 99 } |
| 100 |
| 101 gfx::NativeViewAccessible TestAXNodeWrapper::GetFocus() { |
| 102 return nullptr; |
| 103 } |
| 104 |
| 105 gfx::AcceleratedWidget |
| 106 TestAXNodeWrapper::GetTargetForNativeAccessibilityEvent() { |
| 107 return gfx::kNullAcceleratedWidget; |
| 108 } |
| 109 |
| 110 void TestAXNodeWrapper::DoDefaultAction() { |
| 111 } |
| 112 |
| 113 bool TestAXNodeWrapper::SetStringValue(const base::string16& new_value) { |
| 114 return false; |
| 115 } |
| 116 |
| 117 TestAXNodeWrapper::TestAXNodeWrapper(AXTree* tree, AXNode* node) |
| 118 : tree_(tree), |
| 119 node_(node), |
| 120 platform_node_(AXPlatformNode::Create(this)) { |
| 121 } |
| 122 |
| 123 } // namespace ui |
OLD | NEW |