2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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.
18 * @file FShell_AppWidgetPopupView.cpp
19 * @brief This is the implementation file for the _AppWidgetPopupView class.
26 #include <FBaseSysLog.h>
27 #include <FBaseString.h>
28 #include <FGrpDimension.h>
29 #include <FGrpPoint.h>
30 #include <FGrpRectangle.h>
31 #include <FMediaImageTypes.h>
32 #include <FSysSystemTime.h>
33 #include <FUiAnimVisualElementAnimation.h>
34 #include <FUiAnimVisualElementAnimationGroup.h>
35 #include <FUiAnimVisualElementPropertyAnimation.h>
36 #include <FBase_StringConverter.h>
37 #include <FGrp_BitmapImpl.h>
38 #include <FMedia_ImageDecoder.h>
39 #include <FUi_ControlManager.h>
40 #include <FUi_CoordinateSystemUtils.h>
41 #include <FUi_Types.h>
42 #include <FUiAnim_EflNode.h>
43 #include <FUiAnim_VisualElement.h>
44 #include <FUiAnim_VisualElementImpl.h>
45 #include <FUiAnim_VisualElementSurfaceImpl.h>
46 #include <FUiCtrl_Frame.h>
47 #include "FShell_AppWidgetPopupView.h"
48 #include "FShell_AppWidgetPopupViewPresenter.h"
49 #include "FShell_AppWidgetPopupViewEvent.h"
50 #include "FShell_AppWidgetView.h"
51 #include "FShell_IAppWidgetPopupViewEventListener.h"
54 using namespace Tizen::Base;
55 using namespace Tizen::Base::Runtime;
56 using namespace Tizen::Graphics;
57 using namespace Tizen::System;
58 using namespace Tizen::Ui;
59 using namespace Tizen::Ui::Controls;
60 using namespace Tizen::Ui::Animations;
62 namespace Tizen { namespace Shell
65 const wchar_t* OPEN_ANIMATION = L"Open";
66 const wchar_t* CLOSE_ANIMATION = L"Close";
68 _AppWidgetPopupView::_AppWidgetPopupView(_AppWidgetView& appwidgetView)
69 : __pAppWidgetPopupViewPresenter(new (std::nothrow) _AppWidgetPopupViewPresenter(*this))
70 , __pAppWidgetView(&appwidgetView)
71 , __pAppWidgetPopupViewEvent(_AppWidgetPopupViewEvent::CreateInstanceN(*this))
72 , __firstUpdated(false)
77 _AppWidgetPopupView::~_AppWidgetPopupView(void)
79 if (livebox_has_pd(__pAppWidgetView->__pAppWidget))
81 livebox_destroy_pd(__pAppWidgetView->__pAppWidget, OnAppWidgetPopupDestroyed, this);
84 __pAppWidgetView = null;
88 _AppWidgetPopupView::CreateAppWidgetPopupN(_AppWidgetView& appwidgetView)
90 SysTryReturn(NID_UI_CTRL, livebox_has_pd(appwidgetView.__pAppWidget), null, E_SYSTEM, "[E_SYSTEM] A system error occured.");
92 unique_ptr<_AppWidgetPopupView> pAppWidgetPopup(new (std::nothrow) _AppWidgetPopupView(appwidgetView));
93 SysTryReturn(NID_UI_CTRL, pAppWidgetPopup, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
95 result r = GetLastResult();
96 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
98 r = pAppWidgetPopup->CreateRootVisualElement();
99 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
101 pAppWidgetPopup->AcquireHandle();
103 SetLastResult(E_SUCCESS);
105 return pAppWidgetPopup.release();
109 _AppWidgetPopupView::Initialize(const FloatRectangle& bounds)
111 FloatDimension screenSize = _ControlManager::GetInstance()->GetScreenSizeF();
113 FloatRectangle viewAbsoluteBounds = __pAppWidgetView->GetAbsoluteBoundsF();
114 double x = (static_cast<double>(viewAbsoluteBounds.x) + static_cast<double>((viewAbsoluteBounds.width) / 2)) / static_cast<double>(screenSize.width);
119 __pAppWidgetView->GetRemainingSpace(lower, upper);
126 SysLog(NID_UI_CTRL, "[%f %f %f %f]", bounds.x, bounds.y, bounds.width, bounds.height);
127 SysLog(NID_UI_CTRL, "[%f %f %f %f]", viewAbsoluteBounds.x, viewAbsoluteBounds.y, viewAbsoluteBounds.width, viewAbsoluteBounds.height);
128 SysLog(NID_UI_CTRL, "[%f %f]", x, y);
130 int ret = livebox_create_pd_with_position(__pAppWidgetView->__pAppWidget, x, y, OnAppWidgetPopupCreated, this);
131 SysTryReturn(NID_UI_CTRL, ret == 0, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
133 result r = SetBounds(bounds);
134 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
136 SetBackgroundColor(Color(0, 0, 0, 0));
142 _AppWidgetPopupView::AddAppWidgetPopupEventListener(const _IAppWidgetPopupViewEventListener& listener)
144 result r = __pAppWidgetPopupViewEvent->AddListener(listener);
145 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
151 _AppWidgetPopupView::RemoveAppWidgetPopupEventListener(const _IAppWidgetPopupViewEventListener& listener)
153 result r = __pAppWidgetPopupViewEvent->RemoveListener(listener);
154 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
160 _AppWidgetPopupView::GetBitmap(void) const
162 return __pBitmap.get();
166 _AppWidgetPopupView::SetPopupBounds(const FloatDimension& size)
168 FloatRectangle absoluteViewBounds = __pAppWidgetView->GetAbsoluteBoundsF();
169 FloatRectangle popupBounds(0, 0, size.width, size.height);
174 FloatDimension anchorSize = __pAppWidgetView->GetAnchorSize();
175 __pAppWidgetView->GetRemainingSpace(lower, upper);
179 popupBounds.y = absoluteViewBounds.y - size.height + anchorSize.height;
183 popupBounds.y = absoluteViewBounds.y + absoluteViewBounds.height - anchorSize.height;
186 SetBounds(popupBounds);
188 SysLog(NID_UI_CTRL, "[%f %f %f %f]", popupBounds.x, popupBounds.y, popupBounds.width, popupBounds.height);
192 _AppWidgetPopupView::FireAppWidgetPopupEvent(bool open)
194 if (__pAppWidgetPopupViewEvent)
196 IEventArg* pEventArg = _AppWidgetPopupViewEvent::CreateAppWidgetPopupViewEventArgN(open);
197 result r = GetLastResult();
198 SysTryReturnVoidResult(NID_UI_CTRL, pEventArg != null, r, "[%s] Propagating.", GetErrorMessage(r));
200 __pAppWidgetPopupViewEvent->Fire(*pEventArg);
205 _AppWidgetPopupView::GetTouchPostion(const Tizen::Graphics::FloatPoint& point, double& x, double& y) const
207 FloatRectangle bounds = GetBoundsF();
209 x = static_cast<double>(point.x) / static_cast<double>(bounds.width);
210 y = static_cast<double>(point.y) / static_cast<double>(bounds.height);
214 _AppWidgetPopupView::PlayAnimation(bool open)
216 const int ANIMATION1_DURATION = 100;
217 // const int ANIMATION2_DURATION = 300;
219 _VisualElement* pVisualElement = GetVisualElement();
220 result r = GetLastResult();
221 SysTryReturnVoidResult(NID_UI_CTRL, pVisualElement, r, "[%s] Propagating.", GetErrorMessage(r));
223 VisualElementAnimationGroup animationGroup;
224 animationGroup.SetVisualElementAnimationStatusEventListener(this);
226 FloatRectangle bounds = GetBoundsF();
230 FloatRectangle startBounds(bounds.x, bounds.y, bounds.width, 0.0f);
231 FloatRectangle endBounds(bounds);
234 startBounds = bounds;
235 endBounds = FloatRectangle(bounds.x, bounds.y, bounds.width, 0.0f);
238 VisualElementPropertyAnimation animation1;
239 animation1.SetPropertyName(L"bounds");
240 animation1.SetStartValue(Variant(startBounds));
241 animation1.SetEndValue(Variant(endBounds));
242 animation1.SetDuration(ANIMATION1_DURATION);
244 animationGroup.AddAnimation(animation1);
246 float startOpacity = 0.0f;
247 float endOpacity = 1.0f;
254 VisualElementPropertyAnimation animation2;
255 animation2.SetPropertyName(L"opacity");
256 animation2.SetStartValue(Variant(startOpacity));
257 animation2.SetEndValue(Variant(endOpacity));
258 animation2.SetDuration(ANIMATION2_DURATION);
260 animationGroup.AddAnimation(animation2);
262 String keyName = (open) ? OPEN_ANIMATION : CLOSE_ANIMATION;
263 pVisualElement->AddAnimation(keyName, animationGroup);
267 _AppWidgetPopupView::OnAttached(void)
273 _VisualElement* pVisualElement = GetVisualElement();
274 SysTryReturn(NID_UI_CTRL, pVisualElement, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
276 _EflNode* pEflNode = dynamic_cast<_EflNode*>(pVisualElement->GetNativeNode());
277 SysTryReturn(NID_UI_CTRL, pEflNode, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
279 Evas_Object* pSmartObject = (Evas_Object*)pEflNode->GetGroupContainer();
280 SysTryReturn(NID_UI_CTRL, pSmartObject, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
282 Evas* pEvas = evas_object_evas_get(pSmartObject);
283 SysTryReturn(NID_UI_CTRL, pEvas, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
285 pEflNode->AddNativeSmartObject(*pVisualElement, __pPixmapObject.get());
296 _AppWidgetPopupView::OnActivated(void)
298 SetTouchCapture(false, false);
302 _AppWidgetPopupView::OnDeactivated(void)
304 ReleaseTouchCapture();
308 _AppWidgetPopupView::OnTouchPressed(const _Control& source, const _TouchInfo& touchInfo)
313 Point position = _CoordinateSystemUtils::ConvertToInteger(touchInfo.GetCurrentPosition());
314 GetTouchPostion(FloatPoint(static_cast<float>(position.x), static_cast<float>(position.y)), x, y);
316 livebox_content_event(__pAppWidgetView->__pAppWidget, PD_MOUSE_DOWN, x, y);
322 _AppWidgetPopupView::OnTouchReleased(const _Control& source, const _TouchInfo& touchInfo)
324 FloatRectangle clientBounds(GetClientBoundsF());
326 Point position = _CoordinateSystemUtils::ConvertToInteger(touchInfo.GetCurrentPosition());
327 FloatPoint floatPosition(static_cast<float>(position.x), static_cast<float>(position.y));
329 if (!clientBounds.Contains(floatPosition))
331 PlayAnimation(false);
337 GetTouchPostion(floatPosition, x, y);
339 livebox_content_event(__pAppWidgetView->__pAppWidget, PD_MOUSE_UP, x, y);
345 _AppWidgetPopupView::OnTouchMoved(const _Control& source, const _TouchInfo& touchInfo)
350 Point position = _CoordinateSystemUtils::ConvertToInteger(touchInfo.GetCurrentPosition());
351 GetTouchPostion(FloatPoint(static_cast<float>(position.x), static_cast<float>(position.y)), x, y);
353 livebox_content_event(__pAppWidgetView->__pAppWidget, PD_MOUSE_MOVE, x, y);
359 _AppWidgetPopupView::OnBoundsChanged(void)
364 _AppWidgetPopupView::OnVisualElementAnimationStarted(const Tizen::Ui::Animations::VisualElementAnimation& animation, const Tizen::Base::String& keyName, Tizen::Ui::Animations::VisualElement& target)
369 _AppWidgetPopupView::OnVisualElementAnimationFinished(const Tizen::Ui::Animations::VisualElementAnimation& animation, const Tizen::Base::String& keyName, Tizen::Ui::Animations::VisualElement& target, bool completedNormally)
371 if (keyName == CLOSE_ANIMATION)
373 SysLog(NID_UI_CTRL, "Close AppWidgetPopup");
375 FireAppWidgetPopupEvent(false);
380 _AppWidgetPopupView::OnVisualElementAnimationRepeated(const Tizen::Ui::Animations::VisualElementAnimation& animation, const Tizen::Base::String& keyName, Tizen::Ui::Animations::VisualElement& target, long currentRepeatCount)
385 _AppWidgetPopupView::OnDraw(void)
387 __pAppWidgetPopupViewPresenter->Draw();
391 _AppWidgetPopupView::OnAttachedToMainTree(void)
393 result r = _Window::OnAttachedToMainTree();
395 _Window* pWindow = _ControlManager::GetInstance()->GetCurrentFrame();
398 _Frame* pFrame = dynamic_cast<_Frame*>(pWindow);
401 pFrame->AddFrameEventListener(*this);
409 _AppWidgetPopupView::OnDetachingFromMainTree(void)
411 result r = _Window::OnDetachingFromMainTree();
413 _Window* pWindow = _ControlManager::GetInstance()->GetCurrentFrame();
416 _Frame* pFrame = dynamic_cast<_Frame*>(pWindow);
419 pFrame->RemoveFrameEventListener(*this);
427 _AppWidgetPopupView::OnFrameActivated(const Tizen::Ui::Controls::_Frame& source)
432 _AppWidgetPopupView::OnFrameDeactivated(const Tizen::Ui::Controls::_Frame& source)
434 PlayAnimation(false);
438 _AppWidgetPopupView::OnFrameMinimized(const Tizen::Ui::Controls::_Frame& source)
443 _AppWidgetPopupView::OnFrameRestored(const Tizen::Ui::Controls::_Frame& source)
448 _AppWidgetPopupView::OnAppWidgetUpdated(const Tizen::Graphics::Bitmap& bitmap, const Tizen::Graphics::FloatDimension& size)
451 SystemTime::GetTicks(ticks);
453 SysLog(NID_UI_CTRL, "(%f %f) %lld", size.width, size.height, ticks);
455 if (size != GetSizeF())
457 SetPopupBounds(size);
460 __pBitmap.reset(const_cast<Bitmap*>(&bitmap));
465 __firstUpdated = true;
474 _AppWidgetPopupView::OnAppWidgetUpdated(int pixmap)
481 ecore_x_pixmap_geometry_get(pixmap, &x, &y, &width, &height);
482 SysTryReturnVoidResult(NID_UI_CTRL, (width > 0) && (height > 0), E_INVALID_ARG, "[E_INVALID_ARG] The argument is invalid [0x%x %d %d].", pixmap, width , height);
484 if (__pixmap != pixmap )
486 _VisualElement* pVisualElement = GetVisualElement();
487 // _VisualElement* pVisualElement = __pAppWidgetView->GetVisualElement();
488 SysTryReturnVoidResult(NID_UI_CTRL, pVisualElement, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
490 _EflNode* pEflNode = dynamic_cast<_EflNode*>(pVisualElement->GetNativeNode());
491 SysTryReturnVoidResult(NID_UI_CTRL, pEflNode, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
493 Evas_Object* pSmartObject = (Evas_Object*)pEflNode->GetGroupContainer();
494 SysTryReturnVoidResult(NID_UI_CTRL, pSmartObject, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
496 Evas* pEvas = evas_object_evas_get(pSmartObject);
497 SysTryReturnVoidResult(NID_UI_CTRL, pEvas, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
499 __pPixmapObject.reset(evas_object_image_filled_add(pEvas));
500 SysTryReturnVoidResult(NID_UI_CTRL, __pPixmapObject.get(), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
502 pEflNode->AddNativeSmartObject(*pVisualElement, __pPixmapObject.get());
504 evas_object_image_size_set(__pPixmapObject.get(), width, height);
505 evas_object_image_colorspace_set(__pPixmapObject.get(), EVAS_COLORSPACE_ARGB8888);
506 evas_object_image_alpha_set(__pPixmapObject.get(), EINA_TRUE);
508 evas_object_move(__pPixmapObject.get(), 0, 0);
509 evas_object_show(__pPixmapObject.get());
511 Evas_Native_Surface surface;
513 surface.version = EVAS_NATIVE_SURFACE_VERSION;
514 surface.type = EVAS_NATIVE_SURFACE_X11;
515 surface.data.x11.visual = ecore_x_default_visual_get(ecore_x_display_get(), ecore_x_default_screen_get());
516 surface.data.x11.pixmap = pixmap;
518 evas_object_image_native_surface_set(__pPixmapObject.get(), &surface);
520 /*__pixmapDamage.reset(ecore_x_damage_new(pixmap, ECORE_X_DAMAGE_REPORT_RAW_RECTANGLES));
521 SysTryReturnVoidResult(NID_UI_CTRL, __pixmapDamage.get() != 0, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
523 __pPixmapEventHandler.reset(ecore_event_handler_add(ECORE_X_EVENT_DAMAGE_NOTIFY, OnPixmapDamaged, (void*)this));
524 SysTryReturnVoidResult(NID_UI_CTRL, __pPixmapEventHandler, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");*/
526 SysLog(NID_UI_CTRL, "[0x%x]", surface.data.x11.pixmap);
529 SysLog(NID_UI_CTRL, "[%d %d %d %d]", x, y, width, height);
531 evas_object_image_size_set(__pPixmapObject.get(), width, height);
532 evas_object_image_pixels_dirty_set(__pPixmapObject.get(), EINA_TRUE);
533 evas_object_image_fill_set(__pPixmapObject.get(), 0, 0, width, height);
534 evas_object_image_data_update_add(__pPixmapObject.get(), 0, 0, width, height);
535 evas_object_resize(__pPixmapObject.get(), width, height);
537 FloatDimension size(width, height);
538 if (size != GetSizeF())
540 SetPopupBounds(size);
546 __firstUpdated = true;
553 _AppWidgetPopupView::OnAppWidgetPopupCreated(struct livebox *pAppWidget, int ret, void* pData)
555 SysTryReturnVoidResult(NID_UI_CTRL, pAppWidget, E_INVALID_ARG, "[E_INVALID_ARG] The argument is invalid.");
556 SysTryReturnVoidResult(NID_UI_CTRL, ret == 0, E_INVALID_ARG, "[E_INVALID_ARG] The argument is invalid.");
558 _AppWidgetPopupView* pAppWidgetViewManager = static_cast<_AppWidgetPopupView*>(pData);
559 SysTryReturnVoidResult(NID_UI_CTRL, pAppWidgetViewManager, E_INVALID_ARG, "[E_INVALID_ARG] The argument is invalid.");
563 _AppWidgetPopupView::OnAppWidgetPopupDestroyed(struct livebox *pAppWidget, int ret, void* pData)
565 SysTryReturnVoidResult(NID_UI_CTRL, pAppWidget, E_INVALID_ARG, "[E_INVALID_ARG] The argument is invalid.");
566 SysTryReturnVoidResult(NID_UI_CTRL, ret == 0, E_INVALID_ARG, "[E_INVALID_ARG] The argument is invalid.");
568 _AppWidgetPopupView* pAppWidgetViewManager = static_cast<_AppWidgetPopupView*>(pData);
569 SysTryReturnVoidResult(NID_UI_CTRL, pAppWidgetViewManager, E_INVALID_ARG, "[E_INVALID_ARG] The argument is invalid.");
573 _AppWidgetPopupView::OnPixmapDamaged(void* pData, int type, void* pEvent)
575 _AppWidgetPopupView* pPopupView = static_cast<_AppWidgetPopupView*>(pData);
576 SysTryReturn(NID_UI_CTRL, pPopupView != null, ECORE_CALLBACK_PASS_ON, E_INVALID_ARG, "[[E_INVALID_ARG] The argument is invalid.");
578 Ecore_X_Event_Damage* pDamageEvent = static_cast<Ecore_X_Event_Damage*>(pEvent);
579 SysTryReturn(NID_UI_CTRL, pDamageEvent != null, ECORE_CALLBACK_PASS_ON, E_INVALID_ARG, "[E_INVALID_ARG] The argument is invalid.");
581 int pixmap = pPopupView->__pixmap;
582 SysTryReturn(NID_UI_CTRL, pDamageEvent->drawable == pixmap, ECORE_CALLBACK_PASS_ON, E_INVALID_ARG, "[E_INVALID_ARG] The argument is invalid [%d %d].", pDamageEvent->drawable, pixmap);
589 ecore_x_pixmap_geometry_get(pixmap, &x, &y, &width, &height);
590 SysTryReturn(NID_UI_CTRL, (width > 0) && (height > 0), ECORE_CALLBACK_PASS_ON, E_INVALID_ARG, "[E_INVALID_ARG] The argument is invalid [0x%x %d %d].", pixmap, width , height);
592 Evas_Object* pPixmapObject = pPopupView->__pPixmapObject.get();
593 SysTryReturn(NID_UI_CTRL, pPixmapObject, ECORE_CALLBACK_PASS_ON, E_INVALID_ARG, "[E_INVALID_ARG] The argument is invalid.");
595 evas_object_image_pixels_dirty_set(pPixmapObject, EINA_TRUE);
596 evas_object_image_fill_set(pPixmapObject, 0, 0, width, height);
597 evas_object_image_data_update_add(pPixmapObject, 0, 0, width, height);
599 SysLog(NID_UI_CTRL, "[%d %d %d]", pixmap, width, height);
601 return ECORE_CALLBACK_DONE;