bool TryToPickInCanvas(Vector2 mousePosition) { if (viewport == null) { return(false); } var localMouse = m_Canvas.WorldToLocal(mousePosition); if (!m_Canvas.ContainsPoint(localMouse)) { m_ParentTracker?.Deactivate(); m_PlacementIndicator?.Deactivate(); return(false); } var pickedElement = Panel.PickAllWithoutValidatingLayout(m_Canvas, mousePosition); // Don't allow selection of elements inside template instances or outside current active document. pickedElement = pickedElement.GetClosestElementPartOfCurrentDocument(); if (pickedElement != null && !pickedElement.IsPartOfActiveVisualTreeAsset(m_PaneWindow.document)) { pickedElement = null; } // Get Closest valid element. pickedElement = pickedElement.GetClosestElementThatIsValid(IsPickedElementValid); if (pickedElement == null) { m_ParentTracker?.Deactivate(); m_PlacementIndicator?.Deactivate(); m_LastHoverElement = null; return(false); } // The placement indicator might decide to change the parent. if (SupportsPlacementIndicator() && m_PlacementIndicator != null) { m_PlacementIndicator.Activate(pickedElement, mousePosition); pickedElement = m_PlacementIndicator.parentElement; } m_ParentTracker.Activate(pickedElement); m_LastHoverElement = pickedElement; if (SupportsPlacementIndicator() && m_PlacementIndicator != null) { m_LastHoverElementChildIndex = m_PlacementIndicator.indexWithinParent; } return(true); }
void PerformDragInner(VisualElement target, Vector2 mousePosition) { // Move dragged element. m_DraggedElement.style.left = mousePosition.x; m_DraggedElement.style.top = mousePosition.y; m_LastRowHoverElement?.RemoveFromClassList(s_TreeItemHoverHoverClassName); m_LastRowHoverElement?.Query(className: BuilderConstants.ExplorerItemReorderZoneClassName).ForEach(e => e.RemoveFromClassList(s_TreeItemHoverWithDragBetweenElementsSupportClassName)); // Note: It's important for the Hierarchy/Stylesheet panes to be checked first because // this check does not account for which element is on top of which other element // so if the Viewport is panned such that the Canvas is behind the Hierarchy, // the TryToPickIn..() call will return true for the Canvas. var isCanvasBlocked = CanPickInExplorerRoot(mousePosition, builderHierarchyRoot) || CanPickInExplorerRoot(mousePosition, builderStylesheetRoot); if (isCanvasBlocked) { var validHover = TryToPickInExplorer(mousePosition, builderHierarchyRoot) || TryToPickInExplorer(mousePosition, builderStylesheetRoot); if (validHover) { VisualElement pickedElement; int index; GetPickedElementFromHoverElement(out pickedElement, out index); if (pickedElement == null) { return; } // Mirror final drag destination in the viewport using the placement indicator. m_PlacementIndicator?.Activate(pickedElement, index); m_Active = true; PerformDrag(target, pickedElement, index); return; } } else { var validHover = TryToPickInCanvas(mousePosition); if (validHover) { m_Active = true; PerformDrag(target, m_LastHoverElement, m_LastHoverElementChildIndex); return; } } m_PlacementIndicator?.Deactivate(); PerformDrag(target, null); }