[NUI][ATSPI] Calculate states based on DALi
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI.Components / Controls / Dialog.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
18 using System;
19 using System.ComponentModel;
20 using Tizen.NUI.BaseComponents;
21
22 namespace Tizen.NUI.Components
23 {
24     /// <summary>
25     /// Dialog class shows a dialog with content.
26     /// </summary>
27     /// <since_tizen> 9 </since_tizen>
28     public class Dialog : Control
29     {
30         private View content = null;
31
32         /// <summary>
33         /// Creates a new instance of Dialog.
34         /// </summary>
35         /// <since_tizen> 9 </since_tizen>
36         public Dialog() : base()
37         {
38             Layout = new AbsoluteLayout();
39
40             this.Relayout += OnRelayout;
41         }
42
43         /// <inheritdoc/>
44         [EditorBrowsable(EditorBrowsableState.Never)]
45         protected override void Dispose(DisposeTypes type)
46         {
47             if (disposed)
48             {
49                 return;
50             }
51
52             if (type == DisposeTypes.Explicit)
53             {
54                 this.Relayout -= OnRelayout;
55
56                 if (content != null)
57                 {
58                     Utility.Dispose(content);
59                 }
60             }
61
62             base.Dispose(type);
63         }
64
65         /// <summary>
66         /// Popup content of Dialog.
67         /// Content is added as a child of Dialog automatically.
68         /// </summary>
69         /// <since_tizen> 9 </since_tizen>
70         public View Content
71         {
72             get
73             {
74                 return content;
75             }
76             set
77             {
78                 if (content == value)
79                 {
80                     return;
81                 }
82
83                 if (content != null)
84                 {
85                     Remove(content);
86                 }
87
88                 content = value;
89                 if (content == null)
90                 {
91                     return;
92                 }
93
94                 Add(content);
95             }
96         }
97
98         /// <summary>
99         /// Initialize AT-SPI object.
100         /// </summary>
101         [EditorBrowsable(EditorBrowsableState.Never)]
102         public override void OnInitialize()
103         {
104             base.OnInitialize();
105             SetAccessibilityConstructor(Role.Dialog);
106             AppendAccessibilityAttribute("sub-role", "Alert");
107             Show(); // calls AddPopup()
108         }
109
110         /// <summary>
111         /// Informs AT-SPI bridge about the set of AT-SPI states associated with this object.
112         /// </summary>
113         [EditorBrowsable(EditorBrowsableState.Never)]
114         protected override AccessibilityStates AccessibilityCalculateStates(ulong states)
115         {
116             var accessibilityStates = base.AccessibilityCalculateStates(states);
117             FlagSetter(ref accessibilityStates, AccessibilityStates.Modal, true);
118             return accessibilityStates;
119         }
120
121         private void OnRelayout(object sender, EventArgs e)
122         {
123             //FIXME: Needs to separate GUI implementation codes to style cs file.
124             CalculateContentPosition();
125         }
126
127         private void CalculateContentPosition()
128         {
129             var size = Size2D;
130             var parent = GetParent();
131             Size2D parentSize;
132
133             if ((parent != null) && (parent is View))
134             {
135                 parentSize = ((View)parent).Size;
136             }
137             else
138             {
139                 parentSize = NUIApplication.GetDefaultWindow().Size;
140             }
141
142             Position2D = new Position2D((parentSize.Width - size.Width) / 2, (parentSize.Height - size.Height) / 2);
143         }
144     }
145 }