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