예제 #1
0
        bool IViewHierarchyHandler.TryGetHighlightedView(double x, double y, bool clear, out IInspectView highlightedView)
        {
            highlightedView = null;

            MacInspectView view = null;

            foreach (var window in NSApplication.SharedApplication.Windows)
            {
                var position = window.ConvertRectFromScreen(new CGRect(x, y, 1, 1)).Location;
                position = window.ContentView.ConvertPointFromView(position, null);
                view     = HitTestHarder(window.ContentView, position);
                if (view != null)
                {
                    break;
                }
            }

            if (clear || view == null)
            {
                if (selectionLayer != null)
                {
                    selectionLayer.RemoveFromSuperview();
                    selectionLayer.Dispose();
                    selectionLayer = null;
                }

                if (view == null)
                {
                    return(false);
                }

                highlightedView = view;
                return(true);
            }

            selectionLayer  = view.UpdateSelection(selectionLayer ?? new SelectionLayer());
            highlightedView = view;
            return(true);
        }
예제 #2
0
        bool IViewHierarchyHandler.TryGetRepresentedView(object view, bool withSubviews, out IInspectView representedView)
        {
            // TODO: Add withSubviews support to MacInspectView.
            if (view is NSApplication)
            {
                representedView = new MacRootInspectView {
                    DisplayName = Identity.ApplicationName
                };
                return(true);
            }

            var nsview = view as NSView;

            if (nsview != null)
            {
                representedView = new MacInspectView(nsview);
                return(true);
            }

            representedView = null;
            return(false);
        }
예제 #3
0
        public MacInspectView(NSView view)
        {
            if (view == null)
            {
                throw new ArgumentNullException(nameof(view));
            }

            this.view = view;

            PopulateTypeInformationFromObject(view);

            // FIXME: special case certain view types and fill in the Description property
            var flipped = view.Superview.IsFlipped;

            if (view.FrameRotation != 0)
            {
                Transform = GetLocalTransform(view)
                            .ToViewTransform();
                X      = view.Bounds.X;
                Y      = view.Bounds.Y;
                Width  = view.Bounds.Width;
                Height = view.Bounds.Height;
            }
            else
            {
                X      = view.Frame.X;
                Y      = flipped ? view.Frame.Y : view.Superview.Frame.Height - (view.Frame.Y + view.Frame.Height);
                Width  = view.Frame.Width;
                Height = view.Frame.Height;
            }
            Kind = ViewKind.Primary;
            // macOS doesn't have a concept of hidden but laid out, so it's either collapsed or visible.
            Visibility = view.Hidden ? ViewVisibility.Collapsed : ViewVisibility.Visible;

            var visitedLayers = new HashSet <IntPtr> ();

            var subviews = view.Subviews;

            if (subviews != null && subviews.Length > 0)
            {
                for (int i = 0; i < subviews.Length; i++)
                {
                    var subview = new MacInspectView(subviews [i]);
                    base.AddSubview(subview);

                    if (subview.Layer == null)
                    {
                        continue;
                    }

                    // After calling AddSubview, add any visited layers to the list. We track
                    // visited layers here so that when we actually recurse into the layer that
                    // belongs to this view, we don't duplicate things. This is needed because of
                    // the pointer-into-a-tree nature of layers, as explained above in the constructor
                    // remarks.
                    var subviewLayer = (MacInspectView)subview.Layer;
                    if (subviewLayer.layer != null)
                    {
                        visitedLayers.Add(subviewLayer.layer.Handle);
                    }

                    subviewLayer.layer?.Sublayers?.ForEach(
                        layer => visitedLayers.Add(layer.Handle));
                }
            }

            if (view.WantsLayer && !visitedLayers.Contains(view.Layer.Handle))
            {
                Layer = new MacInspectView(view, view.Layer, visitedLayers)
                {
                    Parent = this
                }
            }
            ;
        }