/** * Returns self if aView is the receiver or aView is a subview of the receiver, * the ancestor view shared by aView and the receiver if any, or * aView if it is an ancestor of the receiver, otherwise returns nil. */ public virtual NSView AncestorSharedWithView(NSView aView) { NSView self = this; if (self == aView) return self; if (this.IsDescendantOf(aView)) return aView; if (aView.IsDescendantOf(self)) return self; /* * If neither are descendants of each other and either does not have a * superview then they cannot have a common ancestor */ if (_super_view == null) return null; if (aView.Superview == null) return null; /* Find the common ancestor of superviews */ return _super_view.AncestorSharedWithView((NSView)aView.Superview); }