// Copyright © 2020 The CefSharp Authors. All rights reserved. // // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. using System; using System.Windows; namespace CefSharp.Wpf.Experimental.Accessibility { /// /// Provides a limited read-only Accessibility Handler implementation. /// To enable accessibility support use the --force-renderer-accessibility to enable /// for all browsers or call /// on a per browser basis to enable. By default accessibility is disabled by default. /// Having accessibility enabled can impact performance until accessibility is disabled. /// public class AccessibilityHandler : IAccessibilityHandler { public BrowserAutomationPeer AutomationPeer { get; protected set; } protected readonly FrameworkElement owner; public AccessibilityHandler(FrameworkElement owner) { this.AutomationPeer = new BrowserAutomationPeer(owner); this.owner = owner; } void IAccessibilityHandler.OnAccessibilityLocationChange(IValue value) { OnAccessibilityLocationChange(value); } /// /// Called after renderer process sends accessibility location changes to the browser process. /// /// Updated location info. protected virtual void OnAccessibilityLocationChange(IValue value) { } void IAccessibilityHandler.OnAccessibilityTreeChange(IValue value) { OnAccessibilityTreeChange(value); } /// /// Called after renderer process sends accessibility tree changes to the browser process. /// /// Updated tree info. protected virtual void OnAccessibilityTreeChange(IValue value) { if (value.Type != Enums.ValueType.Dictionary) { return; } var accessibilityUpdateDictionary = value.GetDictionary(); if (accessibilityUpdateDictionary == null || !accessibilityUpdateDictionary.ContainsKey("ax_tree_id")) { return; } string treeId = accessibilityUpdateDictionary["ax_tree_id"].GetString(); owner.Dispatcher.Invoke(new Action(() => AutomationPeer.OnAccessibilityTreeChange(treeId, accessibilityUpdateDictionary) )); } } }