// Copyright (c) The Avalonia Project. All rights reserved. // Licensed under the MIT license. See licence.md file in the project root for full license information. using System; using System.Collections.Generic; using System.Linq; using Avalonia.VisualTree; namespace Avalonia.Input { /// /// Defines extensions for the interface. /// public static class InputExtensions { /// /// Returns the active input elements at a point on an . /// /// The element to test. /// The point on . /// /// The active input elements found at the point, ordered topmost first. /// public static IEnumerable GetInputElementsAt(this IInputElement element, Point p) { Contract.Requires(element != null); return element.GetVisualsAt(p, IsHitTestVisible).Cast(); } /// /// Returns the topmost active input element at a point on an . /// /// The element to test. /// The point on . /// The topmost at the specified position. public static IInputElement InputHitTest(this IInputElement element, Point p) { return element.GetInputElementsAt(p).FirstOrDefault(); } private static bool IsHitTestVisible(IVisual visual) { var element = visual as IInputElement; return element != null && element.IsVisible && element.IsHitTestVisible && element.IsEnabledCore && element.IsAttachedToVisualTree; } } }