1 // Copyright 2019 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 #ifndef UI_ACCESSIBILITY_PLATFORM_AX_FRAGMENT_ROOT_WIN_H_ 6 #define UI_ACCESSIBILITY_PLATFORM_AX_FRAGMENT_ROOT_WIN_H_ 7 8 #include "ui/accessibility/platform/ax_platform_node_delegate_base.h" 9 10 #include <wrl/client.h> 11 12 namespace ui { 13 14 class AXFragmentRootDelegateWin; 15 class AXFragmentRootPlatformNodeWin; 16 17 // UI Automation on Windows requires the root of a multi-element provider to 18 // implement IRawElementProviderFragmentRoot. Our internal accessibility trees 19 // may not know their roots for right away; for example, web content may 20 // deserialize the document for an iframe before the host document. Because of 21 // this, and because COM rules require that the list of interfaces returned by 22 // QueryInterface remain static over the lifetime of an object instance, we 23 // implement IRawElementProviderFragmentRoot on its own node for each HWND, with 24 // the root of our internal accessibility tree for that HWND as its sole child. 25 // 26 // Since UIA derives some information from the underlying HWND hierarchy, we 27 // expose one fragment root per HWND. The class that owns the HWND is expected 28 // to own the corresponding AXFragmentRootWin. 29 class AX_EXPORT AXFragmentRootWin : public ui::AXPlatformNodeDelegateBase { 30 public: 31 AXFragmentRootWin(gfx::AcceleratedWidget widget, 32 AXFragmentRootDelegateWin* delegate); 33 ~AXFragmentRootWin() override; 34 35 // Fragment roots register themselves in a map upon creation and unregister 36 // upon destruction. This method provides a lookup, which allows the internal 37 // accessibility root to navigate back to the corresponding fragment root. 38 static AXFragmentRootWin* GetForAcceleratedWidget( 39 gfx::AcceleratedWidget widget); 40 41 // If the given NativeViewAccessible is the direct descendant of a fragment 42 // root, return the corresponding fragment root. 43 static AXFragmentRootWin* GetFragmentRootParentOf( 44 gfx::NativeViewAccessible accessible); 45 46 // Returns the NativeViewAccessible for this fragment root. 47 gfx::NativeViewAccessible GetNativeViewAccessible() override; 48 49 // Assistive technologies will typically use UI Automation's control or 50 // content view rather than the raw view. 51 // Returns true if the fragment root should be included in the control and 52 // content views or false if it should be excluded. 53 bool IsControlElement(); 54 55 // If a child node is available, return its delegate. 56 AXPlatformNodeDelegate* GetChildNodeDelegate() const; 57 58 private: 59 // AXPlatformNodeDelegate overrides. 60 gfx::NativeViewAccessible GetParent() override; 61 int GetChildCount() const override; 62 gfx::NativeViewAccessible ChildAtIndex(int index) override; 63 gfx::NativeViewAccessible GetNextSibling() override; 64 gfx::NativeViewAccessible GetPreviousSibling() override; 65 gfx::NativeViewAccessible HitTestSync(int x, int y) const override; 66 gfx::NativeViewAccessible GetFocus() override; 67 const ui::AXUniqueId& GetUniqueId() const override; 68 gfx::AcceleratedWidget GetTargetForNativeAccessibilityEvent() override; 69 AXPlatformNode* GetFromTreeIDAndNodeID(const ui::AXTreeID& ax_tree_id, 70 int32_t id) override; 71 72 // A fragment root does not correspond to any node in the platform neutral 73 // accessibility tree. Rather, the fragment root's child is a child of the 74 // fragment root's parent. This helper computes the child's index in the 75 // parent's array of children. 76 int GetIndexInParentOfChild() const; 77 78 // If a parent node is available, return its delegate. 79 AXPlatformNodeDelegate* GetParentNodeDelegate() const; 80 81 gfx::AcceleratedWidget widget_; 82 AXFragmentRootDelegateWin* const delegate_; 83 Microsoft::WRL::ComPtr<ui::AXFragmentRootPlatformNodeWin> platform_node_; 84 ui::AXUniqueId unique_id_; 85 }; 86 87 } // namespace ui 88 89 #endif // UI_ACCESSIBILITY_PLATFORM_AX_FRAGMENT_ROOT_WIN_H_ 90