Revert "[DO NOT REVIEW][TEST][NUI] key focus default algorithm test"
authordongsug.song <dongsug.song@samsung.com>
Tue, 15 Mar 2022 07:10:55 +0000 (16:10 +0900)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Tue, 15 Mar 2022 08:03:22 +0000 (17:03 +0900)
This reverts commit bf89dd9e1d0b37d2ecbb65cf47d0ed65c4e693b1.

src/Tizen.NUI.Components/Controls/Button.cs
src/Tizen.NUI.Components/Controls/Navigation/Navigator.cs
src/Tizen.NUI.Components/Controls/Navigation/Page.cs
src/Tizen.NUI/src/public/Input/FocusManager.cs
test/Tizen.NUI.StyleGuide/Examples/ButtonExample.cs
test/Tizen.NUI.StyleGuide/Examples/ScrollableBase/ScrollableBaseDirectionExample.cs
test/Tizen.NUI.StyleGuide/Examples/ScrollableBase/ScrollableBaseExample.cs
test/Tizen.NUI.StyleGuide/Tizen.NUI.StyleGuide.cs

index 752b52b..70595df 100755 (executable)
@@ -193,7 +193,6 @@ namespace Tizen.NUI.Components
         /// <since_tizen> 6 </since_tizen>
         public Button() : base()
         {
-            Focusable = true;
         }
 
         /// <summary>
@@ -203,7 +202,6 @@ namespace Tizen.NUI.Components
         /// <since_tizen> 8 </since_tizen>
         public Button(string style) : base(style)
         {
-            Focusable = true;
         }
 
         /// <summary>
@@ -213,7 +211,6 @@ namespace Tizen.NUI.Components
         /// <since_tizen> 8 </since_tizen>
         public Button(ButtonStyle buttonStyle) : base(buttonStyle)
         {
-            Focusable = true;
         }
 
         /// <summary>
index 6b6b12b..a60dc14 100755 (executable)
@@ -228,7 +228,7 @@ namespace Tizen.NUI.Components
             {
                 if (page is DialogPage == false)
                 {
-                    topPage.SetVisible(false);
+                   topPage.SetVisible(false);
                 }
 
                 // Need to update Content of the new page
@@ -338,20 +338,6 @@ namespace Tizen.NUI.Components
             page.InvokeAppearing();
             curTop.InvokeDisappearing();
 
-            //test.
-            // if (FocusManager.Instance.IsDefaultAlgorithmEnabled())
-            // {
-            //     curTop.LastFocusedView = FocusManager.Instance.GetCurrentFocusView();
-            //     if(page.LastFocusedView)
-            //     {
-            //         FocusManager.Instance.SetCurrentFocusView(page.LastFocusedView);
-            //     }
-            //     else
-            //     {
-            //         FocusManager.Instance.ClearFocus();
-            //     }
-            // }
-
             //TODO: The following transition codes will be replaced with view transition.
             InitializeAnimation();
 
@@ -382,15 +368,6 @@ namespace Tizen.NUI.Components
                     //Invoke Page events
                     page.InvokeAppeared();
                     NotifyAccessibilityStatesChangeOfPages(curTop, page);
-
-                    //test.
-                    // if (FocusManager.Instance.IsDefaultAlgorithmEnabled())
-                    // {
-                    //     FocusManager.Instance.ClearFocus();
-                    //     FocusManager.Instance.MoveFocus(View.FocusDirection.Down);
-                    //     //FocusManager.Instance.MoveFocus(View.FocusDirection.Down);
-                    // }
-
                 };
                 newAnimation.Play();
             }
@@ -398,14 +375,6 @@ namespace Tizen.NUI.Components
             {
                 ShowContentOfPage(page);
             }
-
-            //test.
-            // if (FocusManager.Instance.IsDefaultAlgorithmEnabled())
-            // {
-            //     FocusManager.Instance.ClearFocus();
-            //     FocusManager.Instance.MoveFocus(View.FocusDirection.Down);
-            //     FocusManager.Instance.MoveFocus(View.FocusDirection.Down);
-            // }
         }
 
         /// <summary>
@@ -445,20 +414,6 @@ namespace Tizen.NUI.Components
             newTop.InvokeAppearing();
             curTop.InvokeDisappearing();
 
-            //test.
-            // if (FocusManager.Instance.IsDefaultAlgorithmEnabled())
-            // {
-            //     curTop.LastFocusedView = FocusManager.Instance.GetCurrentFocusView();
-            //     if(newTop.LastFocusedView)
-            //     {
-            //         FocusManager.Instance.SetCurrentFocusView(newTop.LastFocusedView);
-            //     }
-            //     else
-            //     {
-            //         FocusManager.Instance.ClearFocus();
-            //     }
-            // }
-
             //TODO: The following transition codes will be replaced with view transition.
             InitializeAnimation();
 
@@ -493,17 +448,6 @@ namespace Tizen.NUI.Components
 
                     //Invoke Page events
                     newTop.InvokeAppeared();
-
-
-                    //test.
-                    // if (FocusManager.Instance.IsDefaultAlgorithmEnabled())
-                    // {
-                    //     FocusManager.Instance.ClearFocus();
-                    //     FocusManager.Instance.MoveFocus(View.FocusDirection.Down);
-                    //     //FocusManager.Instance.MoveFocus(View.FocusDirection.Down);
-                    // }
-
-
                 };
                 newAnimation.Play();
             }
@@ -512,23 +456,6 @@ namespace Tizen.NUI.Components
                 Remove(curTop);
             }
 
-            //test.
-            // if (FocusManager.Instance.IsDefaultAlgorithmEnabled())
-            // {
-            //     if(newTop.LastFocusedView)
-            //     {
-            //         FocusManager.Instance.SetCurrentFocusView(newTop.LastFocusedView);
-            //     }
-            // }
-
-            // //test.
-            // if (FocusManager.Instance.IsDefaultAlgorithmEnabled())
-            // {
-            //     FocusManager.Instance.ClearFocus();
-            //     FocusManager.Instance.MoveFocus(View.FocusDirection.Down);
-            //     FocusManager.Instance.MoveFocus(View.FocusDirection.Down);
-            // }
-
             return curTop;
         }
 
@@ -814,12 +741,12 @@ namespace Tizen.NUI.Components
             RetrieveTaggedViews(taggedViewsInCurrentTopPage, currentTopPage, true);
 
             List<KeyValuePair<View, View>> sameTaggedViewPair = new List<KeyValuePair<View, View>>();
-            foreach (View currentTopPageView in taggedViewsInCurrentTopPage)
+            foreach(View currentTopPageView in taggedViewsInCurrentTopPage)
             {
                 bool findPair = false;
-                foreach (View newTopPageView in taggedViewsInNewTopPage)
+                foreach(View newTopPageView in taggedViewsInNewTopPage)
                 {
-                    if ((currentTopPageView.TransitionOptions != null) && (newTopPageView.TransitionOptions != null) &&
+                    if((currentTopPageView.TransitionOptions != null) && (newTopPageView.TransitionOptions != null) &&
                         currentTopPageView.TransitionOptions?.TransitionTag == newTopPageView.TransitionOptions?.TransitionTag)
                     {
                         sameTaggedViewPair.Add(new KeyValuePair<View, View>(currentTopPageView, newTopPageView));
@@ -827,21 +754,21 @@ namespace Tizen.NUI.Components
                         break;
                     }
                 }
-                if (findPair)
+                if(findPair)
                 {
                     taggedViewsInNewTopPage.Remove(sameTaggedViewPair[sameTaggedViewPair.Count - 1].Value);
                 }
             }
-            foreach (KeyValuePair<View, View> pair in sameTaggedViewPair)
+            foreach(KeyValuePair<View, View> pair in sameTaggedViewPair)
             {
                 taggedViewsInCurrentTopPage.Remove(pair.Key);
             }
 
             TransitionSet newTransitionSet = new TransitionSet();
-            foreach (KeyValuePair<View, View> pair in sameTaggedViewPair)
+            foreach(KeyValuePair<View, View> pair in sameTaggedViewPair)
             {
                 TransitionItem pairTransition = transition.CreateTransition(pair.Key, pair.Value, pushTransition);
-                if (pair.Value.TransitionOptions?.TransitionWithChild ?? false)
+                if(pair.Value.TransitionOptions?.TransitionWithChild ?? false)
                 {
                     pairTransition.TransitionWithChild = true;
                 }
@@ -850,11 +777,11 @@ namespace Tizen.NUI.Components
 
             newTransitionSet.Finished += (object sender, EventArgs e) =>
             {
-                if (newTopPage.Layout != null)
+                if(newTopPage.Layout != null)
                 {
                     newTopPage.Layout.RequestLayout();
                 }
-                if (currentTopPage.Layout != null)
+                if(currentTopPage.Layout != null)
                 {
                     currentTopPage.Layout.RequestLayout();
                 }
index e2d7197..fba9475 100755 (executable)
@@ -94,8 +94,6 @@ namespace Tizen.NUI.Components
             return instance.InternalDisappearingTransition;
         });
 
-        internal BaseComponents.View LastFocusedView = null;
-
         private Navigator navigator = null;
 
         // Default transition is Fade.
index cc27082..204d898 100755 (executable)
@@ -72,8 +72,6 @@ namespace Tizen.NUI
         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
         private delegate void FocusedViewEnterKeyEventCallback2(IntPtr view);
 
-        private View internalFocusIndicator = null;
-
         /// <summary>
         /// PreFocusChange will be triggered before the focus is going to be changed.<br />
         /// The FocusManager makes the best guess for which view to focus towards the given direction, but applications might want to change that.<br />
@@ -476,15 +474,14 @@ namespace Tizen.NUI
         {
             Interop.FocusManager.SetFocusIndicatorActor(SwigCPtr, View.getCPtr(indicator));
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
-            internalFocusIndicator = indicator;
         }
 
         internal View GetFocusIndicatorView()
         {
             //to fix memory leak issue, match the handle count with native side.
             IntPtr cPtr = Interop.FocusManager.GetFocusIndicatorActor(SwigCPtr);
-            internalFocusIndicator = this.GetInstanceSafely<View>(cPtr);
-            return internalFocusIndicator;
+            View ret = this.GetInstanceSafely<View>(cPtr);
+            return ret;
         }
 
         internal PreFocusChangeSignal PreFocusChangeSignal()
index 38b4e5a..a73ffd8 100644 (file)
@@ -28,11 +28,11 @@ namespace Tizen.NUI.StyleGuide
         private Window window;
         public void Activate()
         {
-           Log.Info(this.GetType().Name, $"this.GetType().Name={this.GetType().Name}, Activate()\n");
+           Log.Info(this.GetType().Name, $"@@@ this.GetType().Name={this.GetType().Name}, Activate()\n");
         }
         public void Deactivate()
         {
-            Log.Info(this.GetType().Name, $"this.GetType().Name={this.GetType().Name}, Deactivate()\n");
+            Log.Info(this.GetType().Name, $"@@@ this.GetType().Name={this.GetType().Name}, Deactivate()\n");
             window = null;
         }
 
@@ -71,6 +71,7 @@ namespace Tizen.NUI.StyleGuide
             {
                 Text = "Enabled"
             };
+            enabledButton.EnableFocus();
             enabledButton.Clicked += (object obj, ClickedEventArgs ev) =>
             {
                 Log.Info(this.GetType().Name, "Enabled Button Clicked\n");
@@ -95,6 +96,7 @@ namespace Tizen.NUI.StyleGuide
                 Text = "Unselected",
                 IsSelectable = true,
             };
+            selectableButton.EnableFocus();
             selectableButton.Clicked += (object obj, ClickedEventArgs ev) =>
             {
                 Log.Info(this.GetType().Name, "Selected Button Clicked\n");
index 610d0ab..2ab5934 100644 (file)
@@ -81,6 +81,7 @@ namespace Tizen.NUI.StyleGuide
                 colorView.WidthSpecification = (isHorizontal? 200 : LayoutParamPolicies.MatchParent);
                 colorView.HeightSpecification = (isHorizontal? LayoutParamPolicies.MatchParent : 200);
                 colorView.BackgroundColor = new Color((float)rnd.Next(256)/256f, (float)rnd.Next(256)/256f, (float)rnd.Next(256)/256f, 1);
+                colorView.EnableFocus();
                 scrollView.Add(colorView);
             }
 
index 1208fd8..6db39d0 100644 (file)
@@ -31,11 +31,11 @@ namespace Tizen.NUI.StyleGuide
         private List<DirectionOption> directionMenu;
         public void Activate()
         {
-            Log.Info(this.GetType().Name, $"this.GetType().Name={this.GetType().Name}, Activate()\n");
+            Log.Info(this.GetType().Name, $"@@@ this.GetType().Name={this.GetType().Name}, Activate()\n");
         }
         public void Deactivate()
         {
-            Log.Info(this.GetType().Name, $"this.GetType().Name={this.GetType().Name}, Deactivate()\n");
+            Log.Info(this.GetType().Name, $"@@@ this.GetType().Name={this.GetType().Name}, Deactivate()\n");
             window = null;
             directionMenu = null;
         }
@@ -73,6 +73,7 @@ namespace Tizen.NUI.StyleGuide
                     };
                     item.Label.SetBinding(TextLabel.TextProperty, "Direction");
                     item.Label.HorizontalAlignment = HorizontalAlignment.Begin;
+                    item.EnableFocus();
                     return item;
                 }),
                 ScrollingDirection = ScrollableBase.Direction.Vertical,
@@ -87,6 +88,7 @@ namespace Tizen.NUI.StyleGuide
                     Page scrollDirPage = new ScrollableBaseDirectionExample(directionItem.Direction);
                     window = NUIApplication.GetDefaultWindow();
                     window.GetDefaultNavigator().Push(scrollDirPage);
+                    FocusableExtension.SetFocusOnPage(scrollDirPage);
                 }
                 directionListView.SelectedItem = null;
             };
index def75a4..ffa0663 100644 (file)
@@ -26,6 +26,67 @@ using System.Reflection;
 
 namespace Tizen.NUI.StyleGuide
 {
+
+    /// Helder static extension class for Focusable.
+    /// NUI default behavior is unfocusable in key or touch,
+    /// this class help to setting focusable features easily.
+    public static class FocusableExtension
+    {
+        public static FocusManager FocusManager;
+        public static void EnableFocus(this View view)
+        {
+            view.Focusable = true;
+            view.FocusableInTouch = true;
+        }
+
+        public static void EnableAutoFocusable()
+        {
+            FocusManager = FocusManager.Instance;
+            FocusManager.EnableDefaultAlgorithm(true);
+            FocusManager.FocusIndicator = new View()
+            {
+                PositionUsesPivotPoint = true,
+                PivotPoint = new Position(0, 0, 0),
+                WidthResizePolicy = ResizePolicyType.FillToParent,
+                HeightResizePolicy = ResizePolicyType.FillToParent,
+                BorderlineColor = Color.Orange,
+                BorderlineWidth = 4.0f,
+                BorderlineOffset = -1f,
+                BackgroundColor = new Color(0.2f, 0.2f, 0.2f, 0.2f),
+            };
+        }
+
+        public static void SetFocusOnPage(Page page)
+        {
+            View focusCandidate = null;
+            if (page == null) return;
+
+            if (page is ContentPage contentPage)
+            {
+                focusCandidate = contentPage.AppBar?.NavigationContent;
+                focusCandidate.Focusable = true;
+            }
+
+            if (focusCandidate == null)
+            {
+                foreach (View child in page.Children)
+                {
+                    if (child.Focusable)
+                    {
+                        focusCandidate = child;
+                    }
+                }
+            }
+
+            Log.Info("FocusableExtension", $"Focus candidate {focusCandidate}\n");
+
+            if (focusCandidate != null)
+            {
+                FocusManager.SetCurrentFocusView(focusCandidate);
+            }
+        }
+    }
+
     public class SearchField : View
     {
         public TextField SearchTextField;
@@ -47,12 +108,14 @@ namespace Tizen.NUI.StyleGuide
 
             var searchTextBox = CreateSearchText();
             SearchTextField = CreateTextField();
+            SearchTextField.EnableFocus();
             var underline = CreateUnderline();
 
             searchTextBox.Add(SearchTextField);
             searchTextBox.Add(underline);
 
             SearchButton = CreateSearchButton();
+            SearchButton.EnableFocus();
 
             Add(searchTextBox);
             Add(SearchButton);
@@ -80,7 +143,6 @@ namespace Tizen.NUI.StyleGuide
                 WidthSpecification = LayoutParamPolicies.MatchParent,
                 HeightSpecification = LayoutParamPolicies.WrapContent,
                 MinimumSize = new Size2D(0, 40),
-                Focusable = true, //BaseComponents' Focusable is false as a default value, true should be set to navigate key focus and edit text.
             };
         }
 
@@ -156,7 +218,7 @@ namespace Tizen.NUI.StyleGuide
 
             foreach (Type type in assembly.GetTypes())
             {
-                Console.WriteLine($"type.Name={type.Name}, type.FullName={type.FullName}");
+                Console.WriteLine($"@@@ type.Name={type.Name}, type.FullName={type.FullName}");
                 if (exampleType.IsAssignableFrom(type) && type.Name != "SampleMain" && this.GetType() != type && type.IsClass)
                 {
                     NamePool.Add(new Tuple<string, string>(type.Name, type.FullName));
@@ -190,7 +252,7 @@ namespace Tizen.NUI.StyleGuide
 
                     if (navigator.PageCount == 0)
                     {
-                        Exit();
+                         Exit();
                     }
                 }
             }
@@ -198,13 +260,13 @@ namespace Tizen.NUI.StyleGuide
 
         public void OnSelectionChanged(object sender, SelectionChangedEventArgs ev)
         {
-            Console.WriteLine($"OnSelectionChanged() {ev.CurrentSelection}");
+            Console.WriteLine($"@@@ OnSelectionChanged() {ev.CurrentSelection}");
 
             if (ev.CurrentSelection.Count == 0) return;
 
             if (ev.CurrentSelection[0] is ControlMenu selItem)
             {
-                Console.WriteLine($"selItem.Name={selItem.Name}, selItem.FullName={selItem.FullName}");
+                Console.WriteLine($"@@@ selItem.Name={selItem.Name}, selItem.FullName={selItem.FullName}");
                 RunSample(selItem?.FullName);
             }
             colView.SelectedItem = null;
@@ -215,27 +277,6 @@ namespace Tizen.NUI.StyleGuide
             base.OnCreate();
             Initialize();
             SetMainPage();
-
-            focusManager = FocusManager.Instance;
-
-            //set user customized focus indicator
-            if (!focusManager.FocusIndicator)
-            {
-                focusManager.FocusIndicator = new View()
-                {
-                    PositionUsesPivotPoint = true,
-                    PivotPoint = new Position(0, 0, 0),
-                    WidthResizePolicy = ResizePolicyType.FillToParent,
-                    HeightResizePolicy = ResizePolicyType.FillToParent,
-                    BorderlineColor = Color.Orange,
-                    BorderlineWidth = 4.0f,
-                    BorderlineOffset = -1f,
-                    BackgroundColor = new Color(0.2f, 0.2f, 0.2f, 0.2f),
-                };
-            }
-
-            //enable FocusManger default algorithm
-            focusManager.EnableDefaultAlgorithm(true);
         }
         private void Initialize()
         {
@@ -243,10 +284,13 @@ namespace Tizen.NUI.StyleGuide
             window.Title = "NUI Style Guide";
             window.KeyEvent += OnKeyEvent;
 
+            FocusableExtension.EnableAutoFocusable();
+
             navigator = window.GetDefaultNavigator();
             navigator.Popped += (object obj, PoppedEventArgs ev) =>
             {
                 Page top = navigator.Peek();
+                FocusableExtension.SetFocusOnPage(top);
             };
         }
 
@@ -275,6 +319,7 @@ namespace Tizen.NUI.StyleGuide
             var appBarStyle = ThemeManager.GetStyle("Tizen.NUI.Components.AppBar");
             var moreButton = new Button(((AppBarStyle)appBarStyle).BackButton);
             moreButton.Icon.ResourceUrl = Tizen.Applications.Application.Current.DirectoryInfo.Resource + "menu.png";
+            moreButton.EnableFocus();
             appBar.NavigationContent = moreButton;
 
 
@@ -314,7 +359,7 @@ namespace Tizen.NUI.StyleGuide
                     };
                     item.Label.SetBinding(TextLabel.TextProperty, "ViewLabel");
                     item.Label.HorizontalAlignment = HorizontalAlignment.Begin;
-                    item.Focusable = true; //BaseComponents' Focusable is false as a default value, true should be set to navigate key focus.
+                    item.EnableFocus();
                     return item;
                 }),
                 Header = myTitle,
@@ -333,8 +378,10 @@ namespace Tizen.NUI.StyleGuide
                 AppBar = appBar,
                 Content = pageContent,
             };
+            page.Focusable = true;
 
             navigator.Push(page);
+            FocusableExtension.SetFocusOnPage(page);
         }
 
         private void RunSample(string name)
@@ -342,19 +389,21 @@ namespace Tizen.NUI.StyleGuide
             IExample example = typeof(Program).Assembly?.CreateInstance(name) as IExample;
 
 
-            Console.WriteLine($"typeof(Program).Assembly={typeof(Program).Assembly}, name={name}");
+            Console.WriteLine($"@@@ typeof(Program).Assembly={typeof(Program).Assembly}, name={name}");
 
             if (example != null)
             {
                 example.Activate();
                 if (example is Page examplePage)
                 {
+                    examplePage.Focusable = true;
                     navigator.Push(examplePage);
+                    FocusableExtension.SetFocusOnPage(examplePage);
                 }
             }
             else
             {
-                Console.WriteLine($"examle is null!");
+                Console.WriteLine($"@@@ examle is null!");
             }
         }