/// <summary>
        /// Determines the bounds of the provided view, including the <see cref="UIElement.Clip"/>, using the window coordinate system.
        /// </summary>
        private static CGRect GetBounds(_Window window, _View view)
        {
            CGRect?finalRect = null;

            while (view != null)
            {
                if (view is _ScrollView)
                {
                    // We don't support ScrollViewer clipping, because detecting
                    // the scrolling position and adjusting it makes it for unreliable
                    // calculations, for now.
                    view = view.Superview;
                }
                else
                {
#if __MACOS__
                    var viewOnScreen = view.ConvertRectToView(view.Bounds, window.ContentView);
#else
                    var viewOnScreen = view.ConvertRectToView(view.Bounds, window);
#endif
                    var element = view as FrameworkElement;

                    if (element?.Clip != null)
                    {
                        var clip = element.Clip.Rect.ToCGRect();

                        // Offset the local clip bounds to get the clip bounds on screen
                        clip.Offset(viewOnScreen.X, viewOnScreen.Y);

                        viewOnScreen.Intersect(clip);
                    }

                    if (finalRect == null)
                    {
                        finalRect = viewOnScreen;
                    }

                    var r2 = finalRect.Value;
                    r2.Intersect(viewOnScreen);
                    finalRect = r2;

                    view = view.Superview;
                }
            }

            return(finalRect.Value);
        }