fixes for static analysis tool results
[framework/osp/web.git] / src / controls / FWebCtrl_WebNotification.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file                FWebCtrl_WebNotification.cpp
20  * @brief               The file contains the definition of _WebNotification class.
21  */
22
23 #include <FBaseRtTimer.h>
24 #include <FBaseSysLog.h>
25 #include <FSysVibrator.h>
26 #include <FSys_VibratorImpl.h>
27 #include <FUiAnimControlAnimator.h>
28 #include <FUiAnimPointAnimation.h>
29 #include <FUiAnimFloatAnimation.h>
30 #include <FUiAnimAnimationTransaction.h>
31 #include <FUiCtrlButton.h>
32
33 #include "FWebCtrl_WebImpl.h"
34 #include "FWebCtrl_WebNotificationHandler.h"
35 #include "FWebCtrl_WebNotification.h"
36
37
38 using namespace Tizen::Base;
39 using namespace Tizen::Base::Runtime;
40 using namespace Tizen::Graphics;
41 using namespace Tizen::Ui;
42 using namespace Tizen::Ui::Animations;
43 using namespace Tizen::Ui::Controls;
44
45 namespace Tizen { namespace Web { namespace Controls
46 {
47
48 _WebNotification::_WebNotification(void)
49                                 : __pNotificationHandler(null)
50                                 , __pContext(null)
51                                 , __notificationId(0)
52                                 , __pTimer(null)
53 {
54 }
55
56
57 _WebNotification::~_WebNotification(void)
58 {
59 }
60
61 result
62 _WebNotification::Construct(Ewk_Context *pContext, uint64_t notificationId, Tizen::Web::Controls::_WebImpl* pImpl)
63 {
64
65 //      _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
66 //      Dimension screenRect = _ControlManager::GetInstance()->GetScreenSize();
67
68         Rectangle rect(NOTIFCATION_RECT_AREA);
69         result r = E_SUCCESS;
70
71         __pContext = pContext;
72         __notificationId = notificationId;
73
74         r = Window::Construct(rect, true, true);
75         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Error Propogating.", GetErrorMessage(r));
76         SetBounds(rect);
77
78         Window::SetOwner(&pImpl->GetPublic());
79         __pNotificationHandler = std::unique_ptr<_WebNotificationHandler>(new (std::nothrow) _WebNotificationHandler());
80         SysTryReturnResult(NID_WEB_CTRL, __pNotificationHandler.get(), E_OUT_OF_MEMORY, "Memory allocation failed.");
81
82         r = __pNotificationHandler->Construct(this);
83         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Error Propogating.", GetErrorMessage(r));
84
85         SetPropagatedTouchEventListener(__pNotificationHandler.get());
86         __pTimer = std::unique_ptr<Timer>( new (std::nothrow) Timer());
87         SysTryReturnResult(NID_WEB_CTRL, __pTimer.get(), E_OUT_OF_MEMORY, "Memory allocation failed.");
88
89         r = __pTimer->Construct(*this);
90         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Error Propogating.", GetErrorMessage(r));
91
92         return r;
93 }
94
95
96 void
97 _WebNotification::SetText(const String& text)
98 {
99         __pNotificationHandler->SetText(text);
100 }
101
102 String
103 _WebNotification::GetText(void) const
104 {
105         return __pNotificationHandler->GetText();
106 }
107
108
109 result
110 _WebNotification::OnDraw(void)
111 {
112         result r = E_SUCCESS;
113         SysTryReturnResult(NID_WEB_CTRL, __pNotificationHandler.get(), E_SYSTEM, "Failed to find Impl Instance.");
114
115         std::unique_ptr<Canvas> pCanvas(GetCanvasN());
116         SysTryReturnResult(NID_WEB_CTRL, pCanvas.get(), GetLastResult(), "[%s] Error Propagated.", GetErrorMessage(GetLastResult()));
117
118         r = __pNotificationHandler->DrawNotification(*pCanvas);
119
120         return r;
121 }
122
123
124 void
125 _WebNotification::OnClicked()
126 {
127         SysTryReturnVoidResult(NID_WEB_CTRL, __pContext != null, E_SYSTEM, "[E_SYSTEM] Context instance not found.");
128         ewk_notification_clicked(__pContext,__notificationId);
129 }
130
131 result
132 _WebNotification::LaunchNotification()
133 {
134         result r = E_SUCCESS;
135         std::unique_ptr<Button> pButton( new (std::nothrow) Button());
136         SysTryReturnResult(NID_WEB_CTRL, pButton.get(), E_OUT_OF_MEMORY, "Memory Allocation Failed.");
137
138         r = pButton->Construct(Rectangle(NOTIFCATION_BUTTON_AREA));
139         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Error Propogating.", GetErrorMessage(r));
140
141         pButton->SetText(L"x"); //Need to add bit map
142         pButton->AddActionEventListener(*this);
143
144         r = AddControl(pButton.get());
145         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Error Propogating.", GetErrorMessage(r));
146         pButton.release();
147
148         SetShowState(true);
149         r = Window::Show();
150         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Error Propogating.", GetErrorMessage(r));
151
152         Point start(0,-200),end;
153         PointAnimation pointAnimation(Point(0, 0), Point(0, 0), 0, ANIMATION_INTERPOLATOR_LINEAR);
154
155         end = Point(0,0);
156
157         pointAnimation.SetStartValue(start);
158         pointAnimation.SetEndValue(end);
159         pointAnimation.SetDuration(2000);
160         pointAnimation.SetAutoReverseEnabled(false);
161
162         ControlAnimator *pAnimator = this->GetControlAnimator();
163         r = pAnimator->StartUserAnimation(ANIMATION_TARGET_POSITION, pointAnimation);
164         SysTryReturnResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Error Propagated.", GetErrorMessage(r));
165
166         __pTimer->Start(15000);
167         return E_SUCCESS;
168 }
169
170
171 void
172 _WebNotification::OnTimerExpired(Timer& timer)
173 {
174
175         int transactionId = 0;
176         int duration = 1000;
177         float start = 1.0f;
178         float end = 0.0f;
179
180         ParallelAnimationGroup showAnim;
181         FloatAnimation floatAnim(start, end, duration, ANIMATION_INTERPOLATOR_LINEAR);
182         showAnim.AddAnimation(ANIMATION_TARGET_ALPHA, floatAnim);
183
184         AnimationTransaction::Begin(transactionId);
185
186         ControlAnimator *pAnimator = this->GetControlAnimator();
187         pAnimator->SetAnimation(ANIMATION_TRIGGER_SHOW_STATE_CHANGE, &showAnim);
188         pAnimator->SetShowState(static_cast< int >(start));
189
190         AnimationTransaction::Commit();
191         delete this;
192 }
193
194 void
195 _WebNotification::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
196 {
197         SetShowState(false);
198
199         delete this;
200 }
201
202 }}}