[AT-SPI] Require ControlAccessible for Control
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / navigation-view / navigation-view-impl.cpp
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 // CLASS HEADER
19 #include "navigation-view-impl.h"
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/object/type-registry-helper.h>
23
24 // INTERNAL INCLUDES
25 #include <dali-toolkit/devel-api/controls/control-devel.h>
26
27 namespace Dali
28 {
29 namespace Toolkit
30 {
31 namespace Internal
32 {
33 namespace // to register type
34 {
35 BaseHandle Create()
36 {
37   return Toolkit::NavigationView::New();
38 }
39
40 DALI_TYPE_REGISTRATION_BEGIN(Toolkit::NavigationView, Toolkit::Control, Create)
41 DALI_TYPE_REGISTRATION_END()
42
43 } // namespace
44
45 NavigationView::NavigationView()
46 : Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT))
47 {
48 }
49
50 NavigationView::~NavigationView()
51 {
52   // Clear all the items in the stack, forces their destruction before NavigationView is destroyed.
53   mContentStack.clear();
54 }
55
56 Toolkit::NavigationView NavigationView::New()
57 {
58   // Create the implementation, temporarily owned by this handle on stack
59   IntrusivePtr<NavigationView> internalNavigationView = new NavigationView();
60
61   // Pass ownership to CustomActor handle
62   Toolkit::NavigationView navigationView(*internalNavigationView);
63
64   // Second-phase init of the implementation
65   // This can only be done after the CustomActor connection has been made...
66   internalNavigationView->Initialize();
67
68   return navigationView;
69 }
70
71 void NavigationView::OnInitialize()
72 {
73   DevelControl::SetAccessibilityConstructor(Self(), [](Dali::Actor actor) {
74     return std::make_unique<DevelControl::ControlAccessible>(actor, Dali::Accessibility::Role::FILLER);
75   });
76 }
77
78 void NavigationView::OnSceneConnection(int depth)
79 {
80   Self().SetProperty(Actor::Property::SENSITIVE, true);
81
82   Control::OnSceneConnection(depth);
83 }
84
85 void NavigationView::Push(Actor& actor)
86 {
87   // check the uninitialized item
88   // check the duplicated push for the top item
89   if(!actor)
90   {
91     return;
92   }
93
94   if(mContentStack.size() > 0)
95   {
96     Self().Remove(mContentStack.back());
97   }
98
99   //push the new item into the stack and show it
100   mContentStack.push_back(actor);
101   Self().Add(actor);
102 }
103
104 Actor NavigationView::Pop()
105 {
106   // cannot pop out the bottom-most item
107   Actor poppedItem;
108   if(mContentStack.size() > 1)
109   {
110     // pop out the top item of the stack and show the new item right under the old one.
111     Self().Remove(mContentStack.back());
112     poppedItem = mContentStack.back();
113     mContentStack.pop_back();
114     Self().Add(mContentStack.back());
115   }
116
117   return poppedItem;
118 }
119
120 } // namespace Internal
121
122 } // namespace Toolkit
123
124 } // namespace Dali