[NUI] Change Button, TimePicker and etc 's Focusable property as true
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI.Components / Controls / Navigation / Page.cs
1 /*
2  * Copyright(c) 2021 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 using System;
18 using System.ComponentModel;
19 using Tizen.NUI.Binding;
20
21 namespace Tizen.NUI.Components
22 {
23     /// <summary>
24     /// PageAppearingEventArgs is a class to record <see cref="Page.Appearing"/> event arguments which will be sent to user.
25     /// </summary>
26     /// <since_tizen> 9 </since_tizen>
27     public class PageAppearingEventArgs : EventArgs
28     {
29     }
30
31     /// <summary>
32     /// PageDisappearingEventArgs is a class to record <see cref="Page.Disappearing"/> event arguments which will be sent to user.
33     /// </summary>
34     /// <since_tizen> 9 </since_tizen>
35     public class PageDisappearingEventArgs : EventArgs
36     {
37     }
38
39     /// <summary>
40     /// PageAppearedEventArgs is a class to record <see cref="Page.Appeared"/> event arguments which will be sent to user.
41     /// </summary>
42     /// <since_tizen> 9 </since_tizen>
43     public class PageAppearedEventArgs : EventArgs
44     {
45     }
46
47     /// <summary>
48     /// PageDisappearedEventArgs is a class to record <see cref="Page.Disappeared"/> event arguments which will be sent to user.
49     /// </summary>
50     /// <since_tizen> 9 </since_tizen>
51     public class PageDisappearedEventArgs : EventArgs
52     {
53     }
54
55     /// <summary>
56     /// The Page class is a class which is an element of navigation.
57     /// </summary>
58     /// <since_tizen> 9 </since_tizen>
59     public abstract class Page : Control
60     {
61         /// <summary>
62         /// AppearingTransitionProperty
63         /// </summary>
64         [EditorBrowsable(EditorBrowsableState.Never)]
65         public static readonly BindableProperty AppearingTransitionProperty = BindableProperty.Create(nameof(AppearingTransition), typeof(TransitionBase), typeof(Page), null, propertyChanged: (bindable, oldValue, newValue) =>
66         {
67             var instance = (Page)bindable;
68             if (newValue != null)
69             {
70                 instance.InternalAppearingTransition = newValue as TransitionBase;
71             }
72         },
73         defaultValueCreator: (bindable) =>
74         {
75             var instance = (Page)bindable;
76             return instance.InternalAppearingTransition;
77         });
78
79         /// <summary>
80         /// DisappearingTransitionProperty
81         /// </summary>
82         [EditorBrowsable(EditorBrowsableState.Never)]
83         public static readonly BindableProperty DisappearingTransitionProperty = BindableProperty.Create(nameof(DisappearingTransition), typeof(TransitionBase), typeof(Page), null, propertyChanged: (bindable, oldValue, newValue) =>
84         {
85             var instance = (Page)bindable;
86             if (newValue != null)
87             {
88                 instance.InternalDisappearingTransition = newValue as TransitionBase;
89             }
90         },
91         defaultValueCreator: (bindable) =>
92         {
93             var instance = (Page)bindable;
94             return instance.InternalDisappearingTransition;
95         });
96
97         [EditorBrowsable(EditorBrowsableState.Never)]
98         protected internal BaseComponents.View LastFocusedView = null;
99
100         private Navigator navigator = null;
101
102         // Default transition is Fade.
103         private TransitionBase appearingTransition = null;
104
105         private TransitionBase disappearingTransition = null;
106
107         /// <summary>
108         /// Creates a new instance of a Page.
109         /// </summary>
110         /// <since_tizen> 9 </since_tizen>
111         public Page() : base()
112         {
113         }
114
115         /// <summary>
116         /// Navigator which has pushed the Page into its stack.
117         /// If this Page has not been pushed into any Navigator, then Navigator is null.
118         /// </summary>
119         /// <since_tizen> 9 </since_tizen>
120         public Navigator Navigator
121         {
122             get
123             {
124                 return navigator;
125             }
126             internal set
127             {
128                 if (navigator == value)
129                 {
130                     return;
131                 }
132
133                 navigator = value;
134             }
135         }
136
137         /// <summary>
138         /// Transition properties for the transition of Views in this page during this page is pushed to Navigator.
139         /// </summary>
140         [EditorBrowsable(EditorBrowsableState.Never)]
141         public TransitionBase AppearingTransition
142         {
143             get
144             {
145                 return GetValue(AppearingTransitionProperty) as TransitionBase;
146             }
147             set
148             {
149                 SetValue(AppearingTransitionProperty, value);
150                 NotifyPropertyChanged();
151             }
152         }
153         private TransitionBase InternalAppearingTransition
154         {
155             set
156             {
157                 appearingTransition = value;
158             }
159             get
160             {
161                 return appearingTransition;
162             }
163         }
164
165         /// <summary>
166         /// Transition properties for the transition of Views in this page during this page is popped from Navigator.
167         /// </summary>
168         [EditorBrowsable(EditorBrowsableState.Never)]
169         public TransitionBase DisappearingTransition
170         {
171             get
172             {
173                 return GetValue(DisappearingTransitionProperty) as TransitionBase;
174             }
175             set
176             {
177                 SetValue(DisappearingTransitionProperty, value);
178                 NotifyPropertyChanged();
179             }
180         }
181         private TransitionBase InternalDisappearingTransition
182         {
183             set
184             {
185                 disappearingTransition = value;
186             }
187             get
188             {
189                 return disappearingTransition;
190             }
191         }
192
193         /// <summary>
194         /// Appearing event is invoked right before the page appears.
195         /// </summary>
196         /// <since_tizen> 9 </since_tizen>
197         public event EventHandler<PageAppearingEventArgs> Appearing;
198
199         /// <summary>
200         /// Disappearing event is invoked right before the page disappears.
201         /// </summary>
202         /// <since_tizen> 9 </since_tizen>
203         public event EventHandler<PageDisappearingEventArgs> Disappearing;
204
205         /// <summary>
206         /// Appeared event is invoked right after the page appears.
207         /// </summary>
208         /// <since_tizen> 9 </since_tizen>
209         public event EventHandler<PageAppearedEventArgs> Appeared;
210
211         /// <summary>
212         /// Disappeared event is invoked right after the page disappears.
213         /// </summary>
214         /// <since_tizen> 9 </since_tizen>
215         public event EventHandler<PageDisappearedEventArgs> Disappeared;
216
217         internal void InvokeAppearing()
218         {
219             Appearing?.Invoke(this, new PageAppearingEventArgs());
220         }
221
222         internal void InvokeDisappearing()
223         {
224             Disappearing?.Invoke(this, new PageDisappearingEventArgs());
225         }
226
227         internal void InvokeAppeared()
228         {
229             Appeared?.Invoke(this, new PageAppearedEventArgs());
230         }
231
232         internal void InvokeDisappeared()
233         {
234             Disappeared?.Invoke(this, new PageDisappearedEventArgs());
235         }
236
237         /// <summary>
238         /// works only when DefaultAlgorithm is enabled.
239         /// to save the currently focused View when disappeared.
240         /// </summary>
241         [EditorBrowsable(EditorBrowsableState.Never)]
242         protected internal virtual void SaveKeyFocus()
243         {
244             if (FocusManager.Instance.IsDefaultAlgorithmEnabled())
245             {
246                 var currentFocusedView = FocusManager.Instance.GetCurrentFocusView();
247                 if (currentFocusedView)
248                 {
249                     var findChild = FindDescendantByID(currentFocusedView.ID);
250                     if (findChild)
251                     {
252                         LastFocusedView = findChild;
253                         return;
254                     }
255                 }
256                 LastFocusedView = null;
257             }
258         }
259
260         /// <summary>
261         /// works only when DefaultAlgorithm is enabled.
262         /// to set key focused View when showing.
263         /// </summary>
264         [EditorBrowsable(EditorBrowsableState.Never)]
265         protected internal virtual void RestoreKeyFocus()
266         {
267             if (FocusManager.Instance.IsDefaultAlgorithmEnabled())
268             {
269                 if (LastFocusedView)
270                 {
271                     FocusManager.Instance.SetCurrentFocusView(LastFocusedView);
272                 }
273                 else
274                 {
275                     var temp = new Tizen.NUI.BaseComponents.View()
276                     {
277                         Size = new Size(0.1f, 0.1f, 0.0f),
278                         Position = new Position(0, 0, 0),
279                         Focusable = true,
280                     };
281                     this.Add(temp);
282                     temp.LowerToBottom();
283                     FocusManager.Instance.SetCurrentFocusView(temp);
284                     var focused = FocusManager.Instance.GetNearestFocusableActor(this, temp, Tizen.NUI.BaseComponents.View.FocusDirection.Down);
285                     if (focused)
286                     {
287                         FocusManager.Instance.SetCurrentFocusView(focused);
288                     }
289                     else
290                     {
291                         FocusManager.Instance.ClearFocus();
292                     }
293                     temp.Unparent();
294                     temp.Dispose();
295                 }
296             }
297
298         }
299
300     }
301 }