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 <FUiAnimVisualElementPropertyAnimation.h>
31 #include <FUiCtrlButton.h>
32 #include "FWebCtrl_WebImpl.h"
33 #include "FWebCtrl_WebNotificationHandler.h"
34 #include "FWebCtrl_WebNotification.h"
37 using namespace Tizen::Base;
38 using namespace Tizen::Base::Runtime;
39 using namespace Tizen::Graphics;
40 using namespace Tizen::Ui;
41 using namespace Tizen::Ui::Animations;
42 using namespace Tizen::Ui::Controls;
45 namespace Tizen { namespace Web { namespace Controls
49 _WebNotification::_WebNotification(void)
50 : __pNotificationHandler(null)
59 _WebNotification::~_WebNotification(void)
65 _WebNotification::Construct(Ewk_Context *pContext, uint64_t notificationId, Tizen::Web::Controls::_WebImpl* pImpl)
67 Rectangle rect(NOTIFCATION_RECT_AREA);
70 __pContext = pContext;
71 __notificationId = notificationId;
73 r = Window::Construct(rect, true, true);
74 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Error Propogating.", GetErrorMessage(r));
77 Window::SetOwner(&pImpl->GetPublic());
78 __pNotificationHandler = std::unique_ptr<_WebNotificationHandler>(new (std::nothrow) _WebNotificationHandler());
79 SysTryReturnResult(NID_WEB_CTRL, __pNotificationHandler.get(), E_OUT_OF_MEMORY, "Memory allocation failed.");
81 r = __pNotificationHandler->Construct(this);
82 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Error Propogating.", GetErrorMessage(r));
84 SetPropagatedTouchEventListener(__pNotificationHandler.get());
85 __pTimer = std::unique_ptr<Timer>( new (std::nothrow) Timer());
86 SysTryReturnResult(NID_WEB_CTRL, __pTimer.get(), E_OUT_OF_MEMORY, "Memory allocation failed.");
88 r = __pTimer->Construct(*this);
89 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Error Propogating.", GetErrorMessage(r));
98 _WebNotification::SetText(const String& text)
100 __pNotificationHandler->SetText(text);
105 _WebNotification::GetText(void) const
107 return __pNotificationHandler->GetText();
112 _WebNotification::OnDraw(void)
114 result r = E_SUCCESS;
115 SysTryReturnResult(NID_WEB_CTRL, __pNotificationHandler.get(), E_SYSTEM, "Failed to find Impl Instance.");
117 std::unique_ptr<Canvas> pCanvas(GetCanvasN());
118 SysTryReturnResult(NID_WEB_CTRL, pCanvas.get(), GetLastResult(), "[%s] Error Propagated.", GetErrorMessage(GetLastResult()));
120 r = __pNotificationHandler->DrawNotification(*pCanvas);
127 _WebNotification::OnClicked()
129 SysTryReturnVoidResult(NID_WEB_CTRL, __pContext != null, E_SYSTEM, "[E_SYSTEM] Context instance not found.");
130 ewk_notification_clicked(__pContext,__notificationId);
135 _WebNotification::OnChangeLayout(void)
144 _WebNotification::LaunchNotification()
146 result r = E_SUCCESS;
147 std::unique_ptr<Button> pButton( new (std::nothrow) Button());
148 SysTryReturnResult(NID_WEB_CTRL, pButton.get(), E_OUT_OF_MEMORY, "Memory Allocation Failed.");
150 r = pButton->Construct(Rectangle(NOTIFCATION_BUTTON_AREA));
151 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Error Propogating.", GetErrorMessage(r));
153 pButton->SetText(L"x"); //Need to add bitmap
154 pButton->AddActionEventListener(*this);
156 r = AddControl(pButton.get());
157 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Error Propogating.", GetErrorMessage(r));
162 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Error Propogating.", GetErrorMessage(r));
164 FloatRectangle rect(static_cast< float >(NOTIFCATION_RECT_AREA.x),static_cast< float >(NOTIFCATION_RECT_AREA.y),static_cast< float >(NOTIFCATION_RECT_AREA.width),static_cast< float >(NOTIFCATION_RECT_AREA.height));
166 FloatRectangle __endRect = rect;
167 FloatRectangle __startRect = FloatRectangle(rect.x, rect.height - 200, rect.width, rect.height);
169 std::unique_ptr<VisualElementPropertyAnimation> pAnimation(new (std::nothrow) VisualElementPropertyAnimation());
170 SysTryReturnResult(NID_WEB_CTRL, pAnimation.get(), E_OUT_OF_MEMORY, "Memory allocation failed.");
172 pAnimation->SetPropertyName(L"bounds");
173 pAnimation->SetStartValue(Variant(__startRect));
174 pAnimation->SetEndValue(Variant(__endRect));
175 pAnimation->SetDuration(2000);
176 this->GetVisualElement()->AddAnimation(L"bounds", *pAnimation);
178 __pTimer->Start(15000);
184 _WebNotification::OnTimerExpired(Timer& timer)
189 std::unique_ptr<VisualElementPropertyAnimation> pAnimation(new (std::nothrow) VisualElementPropertyAnimation());
190 SysTryReturnVoidResult(NID_WEB_CTRL, pAnimation.get(), E_OUT_OF_MEMORY, "Memory allocation failed.");
192 pAnimation->SetPropertyName(L"opacity");
193 pAnimation->SetStartValue(Variant(start));
194 pAnimation->SetEndValue(Variant(end));
195 pAnimation->SetDuration(2000);
196 this->GetVisualElement()->AddAnimation(L"opacity", *pAnimation);
201 _WebNotification::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
205 __pWebImpl->ClearWebNotification(this);