2 * Copyright(c) 2021 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 using System.ComponentModel;
18 using Tizen.NUI.BaseComponents;
20 namespace Tizen.NUI.Components
23 /// The ContentPage class is a class which is a formatted full screen page.
24 /// ContentPage contains title app bar and content.
26 /// <since_tizen> 9 </since_tizen>
27 public partial class ContentPage : Page
29 private AppBar appBar = null;
30 private View content = null;
32 private void Initialize()
34 Layout = new ContentPageLayout();
36 // ContentPage matches to parent by default.
37 WidthSpecification = LayoutParamPolicies.MatchParent;
38 HeightSpecification = LayoutParamPolicies.MatchParent;
42 /// Creates a new instance of a ContentPage.
44 /// <since_tizen> 9 </since_tizen>
45 public ContentPage() : base()
51 /// Creates a new instance of a ContentPage with style.
53 /// <param name="style">A style applied to the newly created ContentPage.</param>
54 [EditorBrowsable(EditorBrowsableState.Never)]
55 public ContentPage(ControlStyle style) : base(style)
61 /// Dispose ContentPage and all children on it.
63 /// <param name="type">Dispose type.</param>
64 [EditorBrowsable(EditorBrowsableState.Never)]
65 protected override void Dispose(DisposeTypes type)
72 if (type == DisposeTypes.Explicit)
76 Utility.Dispose(appBar);
81 Utility.Dispose(content);
89 [EditorBrowsable(EditorBrowsableState.Never)]
90 public override void OnInitialize()
94 AccessibilityRole = Role.PageTab;
98 /// AppBar of ContentPage.
99 /// AppBar is added as a child of ContentPage automatically.
100 /// AppBar is positioned at the top of the Page.
102 /// <since_tizen> 9 </since_tizen>
107 return GetValue(AppBarProperty) as AppBar;
111 SetValue(AppBarProperty, value);
112 NotifyPropertyChanged();
115 private AppBar InternalAppBar
144 /// Content of ContentPage.
145 /// Content is added as a child of ContentPage automatically.
146 /// Content is positioned below AppBar.
147 /// Content is resized to fill the full screen except AppBar.
149 /// <since_tizen> 9 </since_tizen>
154 return GetValue(ContentProperty) as View;
158 SetValue(ContentProperty, value);
159 NotifyPropertyChanged();
164 /// for the case of ContentPage, it sets key focus on AppBar's NavigationContent
166 protected internal override void RestoreKeyFocus()
168 if (FocusManager.Instance.IsDefaultAlgorithmEnabled())
172 FocusManager.Instance.SetCurrentFocusView(LastFocusedView);
178 FocusManager.Instance.SetCurrentFocusView(AppBar.PassFocusableViewInsideIfNeeded());
182 FocusManager.Instance.ClearFocus();
188 private View InternalContent
196 if (content == value)
216 private class ContentPageLayout : AbsoluteLayout
218 protected override void OnMeasure(MeasureSpecification widthMeasureSpec, MeasureSpecification heightMeasureSpec)
220 float maxWidth = SuggestedMinimumWidth.AsDecimal();
221 float maxHeight = SuggestedMinimumHeight.AsDecimal();
223 MeasuredSize.StateType childWidthState = MeasuredSize.StateType.MeasuredSizeOK;
224 MeasuredSize.StateType childHeightState = MeasuredSize.StateType.MeasuredSizeOK;
226 var appBar = (Owner as ContentPage)?.AppBar;
227 var content = (Owner as ContentPage)?.Content;
229 bool measureAppBarLayout = false;
231 if ((appBar != null) && (appBar.Layout != null) && (LayoutChildren.Contains(appBar.Layout)) && appBar.Layout.SetPositionByLayout)
233 MeasureChildWithoutPadding(appBar.Layout, widthMeasureSpec, heightMeasureSpec);
234 measureAppBarLayout = true;
237 foreach (var childLayout in LayoutChildren)
239 if (!childLayout.SetPositionByLayout)
244 if ((content != null) && (content == childLayout.Owner) && (content.HeightSpecification == LayoutParamPolicies.MatchParent) && measureAppBarLayout)
246 var contentSizeH = heightMeasureSpec.Size.AsDecimal() - Padding.Top - Padding.Bottom - content.Margin.Top - content.Margin.Bottom - (appBar?.Layout.MeasuredHeight.Size.AsDecimal() ?? 0);
247 MeasureSpecification contentHeightSpec = new MeasureSpecification(new LayoutLength(contentSizeH), MeasureSpecification.ModeType.Exactly);
248 MeasureChildWithoutPadding(childLayout, widthMeasureSpec, contentHeightSpec);
250 else if (!measureAppBarLayout || (appBar != childLayout.Owner)) // if childLayout is not appBar.Layout
252 MeasureChildWithoutPadding(childLayout, widthMeasureSpec, heightMeasureSpec);
255 float childRight = childLayout.MeasuredWidth.Size.AsDecimal() + childLayout.Owner.PositionX;
256 float childBottom = childLayout.MeasuredHeight.Size.AsDecimal() + childLayout.Owner.PositionY;
258 if (maxWidth < childRight)
259 maxWidth = childRight;
261 if (maxHeight < childBottom)
262 maxHeight = childBottom;
264 if (childLayout.MeasuredWidth.State == MeasuredSize.StateType.MeasuredSizeTooSmall)
266 childWidthState = MeasuredSize.StateType.MeasuredSizeTooSmall;
268 if (childLayout.MeasuredHeight.State == MeasuredSize.StateType.MeasuredSizeTooSmall)
270 childHeightState = MeasuredSize.StateType.MeasuredSizeTooSmall;
274 SetMeasuredDimensions(ResolveSizeAndState(new LayoutLength(maxWidth), widthMeasureSpec, childWidthState),
275 ResolveSizeAndState(new LayoutLength(maxHeight), heightMeasureSpec, childHeightState));
278 protected override void OnLayout(bool changed, LayoutLength left, LayoutLength top, LayoutLength right, LayoutLength bottom)
280 foreach (var childLayout in LayoutChildren)
282 if (!childLayout.SetPositionByLayout)
287 LayoutLength childWidth = childLayout.MeasuredWidth.Size;
288 LayoutLength childHeight = childLayout.MeasuredHeight.Size;
290 LayoutLength childLeft = new LayoutLength(childLayout.Owner.PositionX);
291 LayoutLength childTop = new LayoutLength(childLayout.Owner.PositionY);
293 var appBar = (Owner as ContentPage)?.AppBar;
294 var content = (Owner as ContentPage)?.Content;
296 if ((content != null) && (content == childLayout.Owner))
298 childTop = new LayoutLength(Padding.Top + content.Margin.Top + (appBar?.Layout.MeasuredHeight.Size.AsDecimal() ?? 0));
299 childLayout.Layout(childLeft, childTop, childLeft + childWidth, childTop + childHeight, false);
303 childLayout.Layout(childLeft, childTop, childLeft + childWidth, childTop + childHeight, true);