/// <summary>
        /// Gets a VisualElementFocusChangeTarget from the pool and initializes it with the given target. Use this function instead of creating new VisualElementFocusChangeTarget. Results obtained using this method need to be released back to the pool. You can use `Dispose()` to release them.
        /// </summary>
        public static VisualElementFocusChangeTarget GetPooled(Focusable target)
        {
            var r = Pool.Get();

            r.target = target;
            return(r);
        }
        public FocusChangeDirection GetFocusChangeDirection(Focusable currentFocusable, EventBase e)
        {
            bool flag = e == null;

            if (flag)
            {
                throw new ArgumentNullException("e");
            }
            bool flag2 = e.eventTypeId == EventBase <MouseDownEvent> .TypeId();

            FocusChangeDirection result;

            if (flag2)
            {
                Focusable focusable = e.target as Focusable;
                bool      flag3     = focusable != null;
                if (flag3)
                {
                    result = VisualElementFocusChangeTarget.GetPooled(focusable);
                    return(result);
                }
            }
            bool flag4 = currentFocusable is IMGUIContainer && e.imguiEvent != null;

            if (flag4)
            {
                result = FocusChangeDirection.none;
            }
            else
            {
                result = VisualElementFocusRing.GetKeyDownFocusChangeDirection(e);
            }
            return(result);
        }
 private void AboutToGrabFocus(Focusable focusable, Focusable willTakeFocusFrom, FocusChangeDirection direction)
 {
     using (FocusInEvent pooled = FocusEventBase <FocusInEvent> .GetPooled(focusable, willTakeFocusFrom, direction, this, false))
     {
         focusable.SendEvent(pooled);
     }
 }
        internal Focusable SwitchFocusOnEvent(EventBase e)
        {
            bool      processedByFocusController = e.processedByFocusController;
            Focusable result;

            if (processedByFocusController)
            {
                result = this.GetLeafFocusedElement();
            }
            else
            {
                using (FocusChangeDirection focusChangeDirection = this.focusRing.GetFocusChangeDirection(this.GetLeafFocusedElement(), e))
                {
                    bool flag = focusChangeDirection != FocusChangeDirection.none;
                    if (flag)
                    {
                        Focusable nextFocusable = this.focusRing.GetNextFocusable(this.GetLeafFocusedElement(), focusChangeDirection);
                        focusChangeDirection.ApplyTo(this, nextFocusable);
                        e.processedByFocusController = true;
                        result = nextFocusable;
                        return(result);
                    }
                }
                result = this.GetLeafFocusedElement();
            }
            return(result);
        }
 private void ReleaseFocus(Focusable focusable, Focusable willGiveFocusTo, FocusChangeDirection direction)
 {
     using (BlurEvent pooled = FocusEventBase <BlurEvent> .GetPooled(focusable, willGiveFocusTo, direction, this, false))
     {
         focusable.SendEvent(pooled);
     }
 }
        /// <summary>
        /// Get the direction of the focus change for the given event. For example, when the Tab key is pressed, focus should be given to the element to the right in the focus ring.
        /// </summary>
        public FocusChangeDirection GetFocusChangeDirection(Focusable currentFocusable, EventBase e)
        {
            if (e == null)
            {
                throw new ArgumentNullException(nameof(e));
            }

            // FUTURE:
            // We could implement an extendable adapter system to convert event to a focus change direction.
            // This would enable new event sources to change the focus.

            if (e.eventTypeId == PointerDownEvent.TypeId())
            {
                if (focusController.GetFocusableParentForPointerEvent(e.target as Focusable, out var target))
                {
                    return(VisualElementFocusChangeTarget.GetPooled(target));
                }
            }

            if (currentFocusable is IMGUIContainer && e.imguiEvent != null)
            {
                // Let IMGUIContainer manage the focus change.
                return(FocusChangeDirection.none);
            }

            return(GetKeyDownFocusChangeDirection(e));
        }
Example #7
0
 void ReleaseFocus(Focusable focusable, Focusable willGiveFocusTo, FocusChangeDirection direction)
 {
     using (BlurEvent e = BlurEvent.GetPooled(focusable, willGiveFocusTo, direction, this))
     {
         focusable.SendEvent(e);
     }
 }
        internal void DoFocusChange(Focusable f)
        {
            this.m_FocusedElements.Clear();
            VisualElement visualElement = f as VisualElement;
            bool          flag          = !(f is IMGUIContainer);

            if (flag)
            {
                this.m_LastFocusedElement = f;
            }
            while (visualElement != null)
            {
                bool flag2 = visualElement.hierarchy.parent == null || visualElement.isCompositeRoot;
                if (flag2)
                {
                    this.m_FocusedElements.Add(new FocusController.FocusedElement
                    {
                        m_SubTreeRoot    = visualElement,
                        m_FocusedElement = f
                    });
                    f = visualElement;
                }
                visualElement = visualElement.hierarchy.parent;
            }
        }
Example #9
0
        public FocusChangeDirection GetFocusChangeDirection(Focusable currentFocusable, EventBase e)
        {
            if (e == null)
            {
                throw new ArgumentNullException(nameof(e));
            }

            // FUTURE:
            // We could implement an extendable adapter system to convert event to a focus change direction.
            // This would enable new event sources to change the focus.

            if (currentFocusable is IMGUIContainer && e.imguiEvent != null)
            {
                // Let IMGUIContainer manage the focus change.
                return(FocusChangeDirection.none);
            }

            if (e.eventTypeId == KeyDownEvent.TypeId())
            {
                KeyDownEvent kde = e as KeyDownEvent;

                if (kde.character == (char)25 || kde.character == '\t')
                {
                    if ((kde.modifiers & EventModifiers.Shift) == 0)
                    {
                        return(VisualElementFocusChangeDirection.right);
                    }

                    return(VisualElementFocusChangeDirection.left);
                }
            }

            return(FocusChangeDirection.none);
        }
Example #10
0
 void AboutToGrabFocus(Focusable focusable, Focusable willTakeFocusFrom, FocusChangeDirection direction)
 {
     using (FocusInEvent e = FocusInEvent.GetPooled(focusable, willTakeFocusFrom, direction, this))
     {
         focusable.SendEvent(e);
     }
 }
Example #11
0
        public FocusChangeDirection GetFocusChangeDirection(Focusable currentFocusable, EventBase e)
        {
            if (e.eventTypeId == PointerDownEvent.TypeId())
            {
                if (focusController.GetFocusableParentForPointerEvent(e.target as Focusable, out var target))
                {
                    return(VisualElementFocusChangeTarget.GetPooled(target));
                }
            }

            if (e.eventTypeId == NavigationMoveEvent.TypeId())
            {
                switch (((NavigationMoveEvent)e).direction)
                {
                case NavigationMoveEvent.Direction.Left: return(Left);

                case NavigationMoveEvent.Direction.Up: return(Up);

                case NavigationMoveEvent.Direction.Right: return(Right);

                case NavigationMoveEvent.Direction.Down: return(Down);

                case NavigationMoveEvent.Direction.Next: return(Next);

                case NavigationMoveEvent.Direction.Previous: return(Previous);
                }
            }

            return(FocusChangeDirection.none);
        }
Example #12
0
 void GrabFocus(Focusable focusable, Focusable willTakeFocusFrom, FocusChangeDirection direction, bool bIsFocusDelegated = false)
 {
     using (FocusEvent e = FocusEvent.GetPooled(focusable, willTakeFocusFrom, direction, this, bIsFocusDelegated))
     {
         focusable.SendEvent(e);
     }
 }
Example #13
0
        private static Focusable GetFirstFocusableChild(VisualElement ve)
        {
            int       childCount = ve.hierarchy.childCount;
            int       i          = 0;
            Focusable result;

            while (i < childCount)
            {
                VisualElement visualElement = ve.hierarchy[i];
                bool          canGrabFocus  = visualElement.canGrabFocus;
                if (!canGrabFocus)
                {
                    bool flag  = visualElement.hierarchy.parent != null && visualElement == visualElement.hierarchy.parent.contentContainer;
                    bool flag2 = !visualElement.isCompositeRoot && !flag;
                    if (flag2)
                    {
                        Focusable firstFocusableChild = Focusable.GetFirstFocusableChild(visualElement);
                        bool      flag3 = firstFocusableChild != null;
                        if (flag3)
                        {
                            result = firstFocusableChild;
                            return(result);
                        }
                    }
                    i++;
                    continue;
                }
                result = visualElement;
                return(result);
            }
            result = null;
            return(result);
        }
 void AboutToReleaseFocus(Focusable focusable, Focusable willGiveFocusTo, FocusChangeDirection direction, DispatchMode dispatchMode)
 {
     using (FocusOutEvent e = FocusOutEvent.GetPooled(focusable, willGiveFocusTo, direction, this))
     {
         focusable.SendEvent(e, dispatchMode);
     }
 }
        internal Focusable FocusNextInDirection(FocusChangeDirection direction)
        {
            Focusable f = focusRing.GetNextFocusable(GetLeafFocusedElement(), direction);

            direction.ApplyTo(this, f);
            return(f);
        }
        public static VisualElementFocusChangeTarget GetPooled(Focusable target)
        {
            VisualElementFocusChangeTarget visualElementFocusChangeTarget = VisualElementFocusChangeTarget.Pool.Get();

            visualElementFocusChangeTarget.target = target;
            return(visualElementFocusChangeTarget);
        }
        internal override void ApplyTo(FocusController focusController, Focusable f)
        {
            // Unselect selected TextElement on pointer down.
            focusController.selectedTextElement = null;

            f.Focus(); // Call Focus() virtual method when an element is clicked or otherwise focused explicitly.
        }
Example #18
0
        internal void Blur()
        {
            m_SavedFocusedElement = focusController?.GetLeafFocusedElement();

            if (m_SavedFocusedElement != null && !(m_SavedFocusedElement is IMGUIContainer))
            {
                m_SavedFocusedElement.Blur();
            }
        }
Example #19
0
        internal void Focus()
        {
            if (m_SavedFocusedElement != null && !(m_SavedFocusedElement is IMGUIContainer))
            {
                m_SavedFocusedElement.Focus();
            }

            m_SavedFocusedElement = null;
        }
        internal void Blur(Focusable focusable, bool bIsFocusDelegated = false, DispatchMode dispatchMode = DispatchMode.Default)
        {
            var ownsFocus = m_PendingFocusCount > 0 ? IsPendingFocus(focusable) : IsFocused(focusable);

            if (ownsFocus)
            {
                SwitchFocus(null, bIsFocusDelegated, dispatchMode);
            }
        }
        internal void Blur(Focusable focusable, bool bIsFocusDelegated = false)
        {
            var ownsFocus = m_PendingFocusCount > 0 ? IsPendingFocus(focusable) : IsFocused(focusable);

            if (ownsFocus)
            {
                SwitchFocus(null, bIsFocusDelegated);
            }
        }
Example #22
0
        internal void SetFocusToLastFocusedElement()
        {
            if (m_LastFocusedElement != null && !(m_LastFocusedElement is IMGUIContainer))
            {
                m_LastFocusedElement.Focus();
            }

            m_LastFocusedElement = null;
        }
Example #23
0
        public virtual Focusable GetNextFocusable(Focusable currentFocusable, FocusChangeDirection direction)
        {
            if (direction == Up || direction == Down || direction == Right || direction == Left)
            {
                return(GetNextFocusable2D(currentFocusable, (ChangeDirection)direction));
            }

            return(m_Ring.GetNextFocusable(currentFocusable, direction));
        }
Example #24
0
 internal void BlurLastFocusedElement()
 {
     if (m_LastFocusedElement != null && !(m_LastFocusedElement is IMGUIContainer))
     {
         // Blur will change the lastFocusedElement to null
         var tmpLastFocusedElement = m_LastFocusedElement;
         m_LastFocusedElement.Blur();
         m_LastFocusedElement = tmpLastFocusedElement;
     }
 }
Example #25
0
        private Focusable GetFocusDelegate()
        {
            Focusable focusable = this;

            while (focusable != null && focusable.delegatesFocus)
            {
                focusable = Focusable.GetFirstFocusableChild(focusable as VisualElement);
            }
            return(focusable);
        }
        internal void SetFocusToLastFocusedElement()
        {
            bool flag = this.m_LastFocusedElement != null && !(this.m_LastFocusedElement is IMGUIContainer);

            if (flag)
            {
                this.m_LastFocusedElement.Focus();
            }
            this.m_LastFocusedElement = null;
        }
Example #27
0
        public static T GetPooled(IEventHandler target, Focusable relatedTarget, FocusChangeDirection direction, FocusController focusController, bool bIsFocusDelegated = false)
        {
            T pooled = EventBase <T> .GetPooled();

            pooled.target           = target;
            pooled.relatedTarget    = relatedTarget;
            pooled.direction        = direction;
            pooled.focusController  = focusController;
            pooled.IsFocusDelegated = bIsFocusDelegated;
            return(pooled);
        }
        internal void BlurLastFocusedElement()
        {
            bool flag = this.m_LastFocusedElement != null && !(this.m_LastFocusedElement is IMGUIContainer);

            if (flag)
            {
                Focusable lastFocusedElement = this.m_LastFocusedElement;
                this.m_LastFocusedElement.Blur();
                this.m_LastFocusedElement = lastFocusedElement;
            }
        }
Example #29
0
        internal bool IsFocused(Focusable f)
        {
            foreach (var fe in m_FocusedElements)
            {
                if (fe.m_FocusedElement == f)
                {
                    return(true);
                }
            }

            return(false);
        }
Example #30
0
        internal void SyncIMGUIFocus(int imguiKeyboardControlID, Focusable imguiContainerHavingKeyboardControl, bool forceSwitch)
        {
            imguiKeyboardControl = imguiKeyboardControlID;

            if (forceSwitch || imguiKeyboardControl != 0)
            {
                SwitchFocus(imguiContainerHavingKeyboardControl, FocusChangeDirection.unspecified);
            }
            else
            {
                SwitchFocus(null, FocusChangeDirection.unspecified);
            }
        }