1 // Copyright 2017 The Chromium Embedded Framework Authors. Portions copyright 2 // 2013 The Chromium Authors. All rights reserved. Use of this source code is 3 // governed by a BSD-style license that can be found in the LICENSE file. 4 5 #ifndef CEF_TESTS_CEFCLIENT_BROWSER_OSR_ACCESSIBILITY_HELPER_H_ 6 #define CEF_TESTS_CEFCLIENT_BROWSER_OSR_ACCESSIBILITY_HELPER_H_ 7 8 #include <map> 9 10 #include "include/cef_browser.h" 11 12 namespace client { 13 14 class OsrAXNode; 15 class OsrAccessibilityHelper; 16 17 class OsrAXTree { 18 public: 19 OsrAXTree(); 20 OsrAXNode* GetNode(int nodeId) const; 21 void EraseNode(int nodeId); 22 void UpdateTreeData(CefRefPtr<CefDictionaryValue> value); 23 void AddNode(OsrAXNode* node); GetParentTreeId()24 const CefString& GetParentTreeId() const { return parent_tree_id_; } GetRootNodeId()25 int GetRootNodeId() const { return root_node_id_; } SetRootNodeId(int nodeId)26 void SetRootNodeId(int nodeId) { root_node_id_ = nodeId; } 27 28 private: 29 CefString parent_tree_id_; 30 int root_node_id_; 31 std::map<int, OsrAXNode*> node_map_; 32 }; 33 34 // Helper class that abstracts Renderer Accessibility tree and provides a 35 // uniform interface to be consumed by IAccessible interface on Windows and 36 // NSAccessibility implementation on Mac in CefClient. 37 class OsrAccessibilityHelper { 38 public: 39 OsrAccessibilityHelper(CefRefPtr<CefValue> value, 40 CefRefPtr<CefBrowser> browser); 41 42 void UpdateAccessibilityTree(CefRefPtr<CefValue> value); 43 44 void UpdateAccessibilityLocation(CefRefPtr<CefValue> value); 45 46 OsrAXNode* GetRootNode() const; 47 48 OsrAXNode* GetFocusedNode() const; 49 GetWindowHandle()50 CefWindowHandle GetWindowHandle() const { 51 return browser_->GetHost()->GetWindowHandle(); 52 } 53 GetBrowser()54 CefRefPtr<CefBrowser> GetBrowser() const { return browser_; } 55 56 OsrAXNode* GetNode(const CefString& treeId, int nodeId) const; 57 58 OsrAXNode* GetTreeRootNode(const CefString& treeId) const; 59 60 static int CastToInt(CefRefPtr<CefValue> value); 61 62 private: 63 void Reset(); 64 65 void UpdateLayout(const CefString& treeId, 66 CefRefPtr<CefDictionaryValue> update); 67 68 void UpdateFocusedNode(const CefString& treeId, int nodeId); 69 70 // Destroy the node and remove from Map 71 void DestroyNode(OsrAXNode* node); 72 CefString root_tree_id_; 73 CefString focused_tree_id_; 74 int focused_node_id_; 75 CefRefPtr<CefBrowser> browser_; 76 std::map<CefString, OsrAXTree> accessibility_node_map_; 77 }; 78 79 } // namespace client 80 81 #endif // CEF_TESTS_CEFCLIENT_BROWSER_OSR_ACCESSIBILITY_HELPER_H_ 82