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