2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 * @file FWebCtrl_WebNotification.cpp
20 * @brief The file contains the definition of _WebNotification class.
22 #include <FBaseRtTimer.h>
23 #include <FBaseSysLog.h>
24 #include <FSysVibrator.h>
25 #include <FSys_VibratorImpl.h>
26 #include <FUiAnimControlAnimator.h>
27 #include <FUiAnimPointAnimation.h>
28 #include <FUiAnimFloatAnimation.h>
29 #include <FUiAnimAnimationTransaction.h>
30 #include <FUiCtrlButton.h>
31 #include "FWebCtrl_WebImpl.h"
32 #include "FWebCtrl_WebNotificationHandler.h"
33 #include "FWebCtrl_WebNotification.h"
36 using namespace Tizen::Base;
37 using namespace Tizen::Base::Runtime;
38 using namespace Tizen::Graphics;
39 using namespace Tizen::Ui;
40 using namespace Tizen::Ui::Animations;
41 using namespace Tizen::Ui::Controls;
44 namespace Tizen { namespace Web { namespace Controls
48 _WebNotification::_WebNotification(void)
49 : __pNotificationHandler(null)
58 _WebNotification::~_WebNotification(void)
64 _WebNotification::Construct(Ewk_Context *pContext, uint64_t notificationId, Tizen::Web::Controls::_WebImpl* pImpl)
66 Rectangle rect(NOTIFCATION_RECT_AREA);
69 __pContext = pContext;
70 __notificationId = notificationId;
72 r = Window::Construct(rect, true, true);
73 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Error Propogating.", GetErrorMessage(r));
76 Window::SetOwner(&pImpl->GetPublic());
77 __pNotificationHandler = std::unique_ptr<_WebNotificationHandler>(new (std::nothrow) _WebNotificationHandler());
78 SysTryReturnResult(NID_WEB_CTRL, __pNotificationHandler.get(), E_OUT_OF_MEMORY, "Memory allocation failed.");
80 r = __pNotificationHandler->Construct(this);
81 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Error Propogating.", GetErrorMessage(r));
83 SetPropagatedTouchEventListener(__pNotificationHandler.get());
84 __pTimer = std::unique_ptr<Timer>( new (std::nothrow) Timer());
85 SysTryReturnResult(NID_WEB_CTRL, __pTimer.get(), E_OUT_OF_MEMORY, "Memory allocation failed.");
87 r = __pTimer->Construct(*this);
88 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Error Propogating.", GetErrorMessage(r));
97 _WebNotification::SetText(const String& text)
99 __pNotificationHandler->SetText(text);
104 _WebNotification::GetText(void) const
106 return __pNotificationHandler->GetText();
111 _WebNotification::OnDraw(void)
113 result r = E_SUCCESS;
114 SysTryReturnResult(NID_WEB_CTRL, __pNotificationHandler.get(), E_SYSTEM, "Failed to find Impl Instance.");
116 std::unique_ptr<Canvas> pCanvas(GetCanvasN());
117 SysTryReturnResult(NID_WEB_CTRL, pCanvas.get(), GetLastResult(), "[%s] Error Propagated.", GetErrorMessage(GetLastResult()));
119 r = __pNotificationHandler->DrawNotification(*pCanvas);
126 _WebNotification::OnClicked()
128 SysTryReturnVoidResult(NID_WEB_CTRL, __pContext != null, E_SYSTEM, "[E_SYSTEM] Context instance not found.");
129 ewk_notification_clicked(__pContext,__notificationId);
134 _WebNotification::OnChangeLayout(void)
143 _WebNotification::LaunchNotification()
145 result r = E_SUCCESS;
146 std::unique_ptr<Button> pButton( new (std::nothrow) Button());
147 SysTryReturnResult(NID_WEB_CTRL, pButton.get(), E_OUT_OF_MEMORY, "Memory Allocation Failed.");
149 r = pButton->Construct(Rectangle(NOTIFCATION_BUTTON_AREA));
150 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Error Propogating.", GetErrorMessage(r));
152 pButton->SetText(L"x"); //Need to add bitmap
153 pButton->AddActionEventListener(*this);
155 r = AddControl(pButton.get());
156 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Error Propogating.", GetErrorMessage(r));
161 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Error Propogating.", GetErrorMessage(r));
163 Point start(0,-200),end;
164 PointAnimation pointAnimation(Point(0, 0), Point(0, 0), 0, ANIMATION_INTERPOLATOR_LINEAR);
168 pointAnimation.SetStartValue(start);
169 pointAnimation.SetEndValue(end);
170 pointAnimation.SetDuration(2000);
171 pointAnimation.SetAutoReverseEnabled(false);
173 ControlAnimator *pAnimator = this->GetControlAnimator();
174 r = pAnimator->StartUserAnimation(ANIMATION_TARGET_POSITION, pointAnimation);
175 SysTryReturnResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Error Propagated.", GetErrorMessage(r));
177 __pTimer->Start(15000);
183 _WebNotification::OnTimerExpired(Timer& timer)
185 int transactionId = 0;
190 ParallelAnimationGroup showAnim;
191 FloatAnimation floatAnim(start, end, duration, ANIMATION_INTERPOLATOR_LINEAR);
192 showAnim.AddAnimation(ANIMATION_TARGET_ALPHA, floatAnim);
194 AnimationTransaction::Begin(transactionId);
196 ControlAnimator *pAnimator = this->GetControlAnimator();
197 pAnimator->SetAnimation(ANIMATION_TRIGGER_SHOW_STATE_CHANGE, &showAnim);
198 pAnimator->SetShowState(static_cast< int >(start));
200 AnimationTransaction::Commit();
201 __pWebImpl->ClearWebNotification(this);
208 _WebNotification::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
212 __pWebImpl->ClearWebNotification(this);