2 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.1 (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
8 // http://floralicense.org/license/
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.
17 * @file FShell_AppWidgetPopup.cpp
18 * @brief This is the implementation file for the _AppWidgetPopup class.
23 #include <Ecore_Evas.h>
25 #include <provider_buffer.h>
26 #include <FBaseSysLog.h>
27 #include <FSysSystemTime.h>
28 #include <FBase_StringConverter.h>
29 #include "FUi_UiKeyEvent.h"
30 #include "FUi_IUiEventManager.h"
31 #include "FUi_UiEventManager.h"
32 #include "FUi_ResourceManager.h"
33 #include "FUiAnim_DisplayManager.h"
34 #include "FUiAnim_RootVisualElement.h"
35 #include "FShell_AppWidgetLayer.h"
36 #include "FShell_AppWidgetPopup.h"
37 #include "FShell_AppWidgetPopupPresenter.h"
38 #include "FShell_AppWidgetProviderManagerImpl.h"
41 using namespace Tizen::Base;
42 using namespace Tizen::Graphics;
43 using namespace Tizen::System;
44 using namespace Tizen::Ui;
45 using namespace Tizen::Ui::Animations;
46 using namespace Tizen::Ui::Controls;
48 namespace Tizen { namespace Shell
51 class _AppWidgetPopupLayer
52 : public _AppWidgetLayer
55 _AppWidgetPopupLayer(const Tizen::Base::String& providerId, const FloatDimension& size);
56 virtual ~_AppWidgetPopupLayer(void);
59 _AppWidgetPopupLayer(const _AppWidgetPopupLayer& rhs);
60 _AppWidgetPopupLayer& operator =(const _AppWidgetPopupLayer& rhs);
62 virtual result RegisterTouchEventListener(void);
63 virtual int AcquirePixmap(void);
64 virtual result Sync(const FloatDimension& size);
65 virtual void ReleasePixmap(void);
68 _AppWidgetPopupLayer::_AppWidgetPopupLayer(const Tizen::Base::String& providerId, const FloatDimension& size)
69 : _AppWidgetLayer(providerId, size)
73 _AppWidgetPopupLayer::~_AppWidgetPopupLayer(void)
83 _AppWidgetPopupLayer::RegisterTouchEventListener(void)
85 result r = _AppWidgetProviderManagerImpl::GetInstance()->SetAppWidgetPopupEventListener(*this);
86 SysTryReturn(NID_SHELL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
92 _AppWidgetPopupLayer::AcquirePixmap(void)
95 SystemTime::GetTicks(ticks);
96 SysLog(NID_SHELL, "%lld", ticks);
100 result r = _AppWidgetProviderManagerImpl::GetInstance()->RequestSharedMemoryIdForPD(GetProviderId(), __size.width, __size.height, pixmapId);
101 SysTryReturn(NID_SHELL, r == E_SUCCESS, -1, r, "[%s] Propagating.", GetErrorMessage(r));
103 SystemTime::GetTicks(ticks);
104 SysLog(NID_SHELL, "%lld", ticks);
106 SysLog(NID_SHELL, "pixmapId(%d) size(%f %f)", pixmapId, __size.width, __size.height);
112 _AppWidgetPopupLayer::Sync(const FloatDimension& size)
114 result r = _AppWidgetProviderManagerImpl::GetInstance()->RequestSyncSharedMemoryForPD(GetProviderId());
115 SysTryReturn(NID_SHELL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
121 _AppWidgetPopupLayer::ReleasePixmap(void)
123 _AppWidgetProviderManagerImpl::GetInstance()->RequestReleaseSharedMemoryForPD(GetProviderId());
126 _AppWidgetPopup::_AppWidgetPopup(void)
127 : __pAppWidgetPopupPresenter(new (std::nothrow) _AppWidgetPopupPresenter(*this))
128 , __pAppWidgetPopupLayer(null)
129 , __pAppWidgetPopupRootVisualElement(null)
130 , __pEventManager(null)
132 SysTryReturnVoidResult(NID_SHELL, __pAppWidgetPopupPresenter, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
134 _UiEventManager* pEventManager = _UiEventManager::GetInstance();
135 SysTryReturnVoidResult(NID_SHELL, pEventManager, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
137 __pEventManager = pEventManager->GetEventManager();
138 SysTryReturnVoidResult(NID_SHELL, __pEventManager, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
141 _AppWidgetPopup::~_AppWidgetPopup(void)
145 __pEventManager->UnregisterTouchEventHandler(*this);
148 __pAppWidgetPopupLayer = null;
149 __pAppWidgetPopupRootVisualElement = null;
153 _AppWidgetPopup::CreateAppWidgetPopupN(void)
155 unique_ptr<_AppWidgetPopup> pAppWidgetPopup(new (std::nothrow) _AppWidgetPopup());
156 SysTryReturn(NID_SHELL, pAppWidgetPopup, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
158 result r = GetLastResult();
159 SysTryReturn(NID_SHELL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
161 pAppWidgetPopup->AcquireHandle();
163 SetLastResult(E_SUCCESS);
165 return pAppWidgetPopup.release();
169 _AppWidgetPopup::Initialize(const FloatDimension& size)
172 SystemTime::GetTicks(ticks);
174 SysLog(NID_SHELL, "(%d %d) %lld", size.width, size.height, ticks);
176 result r = E_SUCCESS;
178 __appwidgetSize = size;
180 SetSystemWindow(true);
182 r = __pAppWidgetPopupPresenter->Initialize();
183 SysTryReturn(NID_SHELL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
185 r = CreateRootVisualElement();
186 SysTryReturn(NID_SHELL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
188 FloatRectangle bounds(0.0f, 0.0f, size.width, size.height);
189 r = SetBounds(bounds);
190 SysTryReturn(NID_SHELL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
192 __pAppWidgetPopupLayer->SetLayerBounds(FloatRectangle(0.0f, 0.0f, 1.0f, 1.0f));
193 __pAppWidgetPopupLayer->SetShowState(false);
195 __pAppWidgetPopupRootVisualElement->SetImplicitAnimationEnabled(false);
196 __pAppWidgetPopupRootVisualElement->SetName(L"_AppWidgetPopup");
197 __pAppWidgetPopupRootVisualElement->SetBounds(bounds);
198 __pAppWidgetPopupRootVisualElement->SetShowState(false);
200 SetBackgroundColor(Color(0, 0, 0, 0));
202 __pEventManager->RegisterTouchEventHandler(*this);
204 SysTryReturn(NID_SHELL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
210 _AppWidgetPopup::SetProviderId(const String& providerId)
212 __pAppWidgetPopupPresenter->SetProviderId(providerId);
214 result r = __pAppWidgetPopupLayer->SetProviderId(providerId);
215 SysTryReturn(NID_SHELL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
217 FloatRectangle bounds(0.0f, 0.0f, __appwidgetSize.width, __appwidgetSize.height);
219 __pAppWidgetPopupLayer->SetLayerBounds(bounds);
225 _AppWidgetPopup::GetProviderId(void) const
227 return __pAppWidgetPopupPresenter->GetProviderId();
231 _AppWidgetPopup::SetAnchorPosition(const FloatPoint& position)
233 return __pAppWidgetPopupPresenter->SetAnchorPosition(position);
237 _AppWidgetPopup::GetAnchorPosition(void) const
239 return __pAppWidgetPopupPresenter->GetAnchorPosition();
243 _AppWidgetPopup::GetClientAreaCanvasN(void) const
245 Canvas* pCanvas = GetCanvasN(GetClientBoundsF());
246 result r = GetLastResult();
247 SysTryReturn(NID_SHELL, pCanvas, null, r, "[%s] Propagating.", GetErrorMessage(r));
253 _AppWidgetPopup::TranslateToClientAreaPosition(const FloatPoint& controlPosition) const
255 FloatRectangle leftTop = GetClientBoundsF();
257 return FloatPoint(controlPosition.x - leftTop.x, controlPosition.y - leftTop.y);
261 _AppWidgetPopup::TranslateToControlPosition(const FloatPoint& clientPosition) const
263 FloatRectangle leftTop = GetClientBoundsF();
265 return FloatPoint(clientPosition.x + leftTop.x, clientPosition.y + leftTop.y);
269 _AppWidgetPopup::SetLayerShowState(bool showState)
271 result r = E_SUCCESS;
273 if (__pAppWidgetPopupRootVisualElement)
275 _AppWidgetPopupLayer* pLayer = dynamic_cast<_AppWidgetPopupLayer*>(__pAppWidgetPopupRootVisualElement->GetNativeLayer());
276 SysTryReturn(NID_SHELL, pLayer, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
278 r = pLayer->SetShowState(showState);
279 SysTryReturn(NID_SHELL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
281 __pAppWidgetPopupRootVisualElement->SetShowState(showState);
288 _AppWidgetPopup::SetLayerBounds(const FloatRectangle& bounds)
290 result r = E_SUCCESS;
292 if (__pAppWidgetPopupRootVisualElement && !GetProviderId().IsEmpty())
294 _AppWidgetPopupLayer* pLayer = dynamic_cast<_AppWidgetPopupLayer*>(__pAppWidgetPopupRootVisualElement->GetNativeLayer());
296 SysTryReturn(NID_SHELL, pLayer, r, r, "[%s] Propagating.", GetErrorMessage(r));
298 pLayer->SetLayerBounds(bounds);
299 __pAppWidgetPopupRootVisualElement->SetBounds(bounds);
306 _AppWidgetPopup::GetAppWidgetPopupClientBounds(void) const
311 int bottomMargin = 0;
312 _ControlOrientation orientation = GetOrientation();
314 GET_SHAPE_CONFIG(APPWIDGET::POPUP_LEFT_MARGIN, orientation, leftMargin);
315 GET_SHAPE_CONFIG(APPWIDGET::POPUP_RIGHT_MARGIN, orientation, rightMargin);
316 GET_SHAPE_CONFIG(APPWIDGET::POPUP_TOP_MARGIN, orientation, topMargin);
317 GET_SHAPE_CONFIG(APPWIDGET::POPUP_BOTTOM_MARGIN, orientation, bottomMargin);
319 FloatRectangle bounds = GetBoundsF();
321 FloatRectangle clientBounds(bounds.x + leftMargin, bounds.y + topMargin, bounds.width - leftMargin - rightMargin, bounds.height - topMargin - bottomMargin);
323 SysLog(NID_SHELL, "[%d %d %d %d]", clientBounds.x, clientBounds.y, clientBounds.width, clientBounds.height);
329 _AppWidgetPopup::UpdateClientBounds(const FloatDimension& size, FloatRectangle& clientBounds)
331 clientBounds = GetAppWidgetPopupClientBounds();
335 _AppWidgetPopup::CreateLayer(void)
337 unique_ptr<_AppWidgetPopupLayer> pLayer(new (std::nothrow) _AppWidgetPopupLayer(GetProviderId(), FloatDimension(1.0f, 1.0f)));
338 SysTryReturn(NID_SHELL, pLayer, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
340 result r = pLayer->Construct();
341 SysTryReturn(NID_SHELL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
343 __pAppWidgetPopupLayer = pLayer.release();
344 __pAppWidgetPopupRootVisualElement = __pAppWidgetPopupLayer->GetRootVisualElement();
346 SetLayer(*__pAppWidgetPopupLayer);
347 SetRootVisualElement(*__pAppWidgetPopupRootVisualElement);
353 _AppWidgetPopup::OnActivated(void)
355 result r = SetLayerShowState(true);
356 SysTryReturnVoidResult(NID_SHELL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
360 _AppWidgetPopup::OnBoundsChanged(void)
362 SetLayerBounds(GetBoundsF());
364 SetClientBounds(GetAppWidgetPopupClientBounds());
368 _AppWidgetPopup::OnDraw(void)
370 if (__pAppWidgetPopupPresenter)
372 __pAppWidgetPopupPresenter->Draw();