[Release] wrt_0.8.274
[platform/framework/web/wrt.git] / src / api_new / runnable_widget_object_state.h
1 /*
2  * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
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  * @file    core_module.cpp
18  * @author  Tomasz Iwanek (t.iwanek@samsung.com)
19  * @version 1.0
20  * @brief   State classes for runnable object
21  */
22 #ifndef RUNNABLE_WIDGET_OBJECT_STATE_H
23 #define RUNNABLE_WIDGET_OBJECT_STATE_H
24
25 //forward declarations
26 namespace WRT {
27 class RunnableWidgetObject;
28
29 namespace State {
30 class RunnableWidgetObjectState;
31 }
32 }
33
34 #include <dpl/exception.h>
35
36 #include <i_runnable_widget_object.h>
37
38 namespace WRT {
39 namespace State {
40 typedef std::shared_ptr<RunnableWidgetObjectState> RunnableWidgetObjectStatePtr;
41
42 /**
43  * @brief The StateChange class
44  *
45  * RunnableWidgetObject state change abstraction
46  */
47 class StateChange
48 {
49   public:
50     static const StateChange NoChange;
51
52     StateChange();
53     explicit StateChange(RunnableWidgetObjectStatePtr sptr);
54
55     /**
56      * @brief commit actually performs change of state
57      */
58     void commit();
59
60   private:
61     RunnableWidgetObjectStatePtr m_sptr;
62 };
63
64 /**
65  * @brief The RunnableWidgetObjectState class
66  *
67  * Base class for all runnable object states
68  *
69  * Allow methods should be called if referenced method are actually
70  * going to be called effectively. They return next state object.
71  * Call commit on this object to make change of state of RunnableWidgetObject
72  */
73 class RunnableWidgetObjectState
74 {
75   public:
76     explicit RunnableWidgetObjectState(RunnableWidgetObject & object);
77     virtual ~RunnableWidgetObjectState();
78
79     virtual StateChange allowCheckBeforeLaunch();
80     virtual StateChange allowPrepareView();
81     virtual StateChange allowShow();
82     virtual StateChange allowHide();
83     virtual StateChange allowSuspend();
84     virtual StateChange allowResume();
85     virtual StateChange allowReset();
86     virtual StateChange allowGetCurrentWebview();
87     virtual StateChange allowSetUserDelegates();
88     virtual StateChange allowBackward();
89     virtual StateChange allowForward();
90     virtual StateChange allowReload();
91     virtual StateChange allowFireJavascriptEvent();
92
93     virtual std::string toString() const = 0;
94     virtual RunnableWidgetObject & getObject() const;
95
96   protected:
97     RunnableWidgetObject & m_object;
98 };
99
100 /**
101  * INITIAL STATE
102  */
103 class InitialState : public RunnableWidgetObjectState
104 {
105   public:
106     explicit InitialState(RunnableWidgetObject & object);
107     std::string toString() const;
108
109     StateChange allowPrepareView();
110     StateChange allowHide();
111     StateChange allowGetCurrentWebview();
112 };
113
114 /**
115  * PREPARED STATE
116  */
117 class PreparedState : public RunnableWidgetObjectState
118 {
119   public:
120     explicit PreparedState(RunnableWidgetObject & object);
121     std::string toString() const;
122
123     StateChange allowCheckBeforeLaunch();
124 };
125
126 /**
127  * SECURITY CHECKED STATE
128  */
129 class SecurityCheckedState : public RunnableWidgetObjectState
130 {
131   public:
132     explicit SecurityCheckedState(RunnableWidgetObject & object);
133     std::string toString() const;
134
135     StateChange allowShow();
136     StateChange allowSetUserDelegates();
137 };
138
139 /**
140  * SHOWED STATE
141  */
142 class ShowedState : public RunnableWidgetObjectState
143 {
144   public:
145     explicit ShowedState(RunnableWidgetObject & object);
146     std::string toString() const;
147
148     StateChange allowSuspend();
149     StateChange allowBackward();
150     StateChange allowForward();
151     StateChange allowReload();
152     StateChange allowReset();
153     StateChange allowFireJavascriptEvent();
154 };
155
156 /**
157  * SUSPENDED STATE
158  */
159 class SuspendedState : public RunnableWidgetObjectState
160 {
161   public:
162     explicit SuspendedState(RunnableWidgetObject & object);
163     std::string toString() const;
164
165     StateChange allowResume();
166     StateChange allowReset();
167 };
168
169 /**
170  * HIDDEN STATE
171  */
172 class HiddenState : public RunnableWidgetObjectState
173 {
174   public:
175     explicit HiddenState(RunnableWidgetObject & object);
176     std::string toString() const;
177
178     StateChange allowHide();
179 };
180 }
181 }
182
183 #endif // RUNNABLE_WIDGET_OBJECT_STATE_H