2 // Open Service Platform
3 // Copyright (c) 2012-2013 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.
18 * @file FUiCtrl_Frame.cpp
19 * @brief This is the implementation file for the _Frame class.
23 #include <FBaseErrorDefine.h>
24 #include <FBaseInteger.h>
25 #include <FBaseSysLog.h>
26 #include <FApp_AppInfo.h>
27 #include "FUi_UiNotificationEvent.h"
28 #include "FUi_UiEventManager.h"
29 #include "FUi_ControlManager.h"
30 #include "FUi_EcoreEvasMgr.h"
31 #include "FUi_EcoreEvas.h"
32 #include "FUi_TouchManager.h"
33 #include "FUi_CoordinateSystemUtils.h"
34 #include "FUiCtrl_Frame.h"
35 #include "FUiCtrl_FramePresenter.h"
36 #include "FUiCtrl_FrameEvent.h"
37 #include "FUiCtrl_IFrameEventListener.h"
38 #include "FUiCtrl_IFormActivationChangeEventListener.h"
39 #include "FUiCtrl_Form.h"
40 #include "FUiCtrl_FormImpl.h"
41 #include "FUiCtrl_FrameImpl.h"
42 #include "FUiAnim_VisualElement.h"
43 #include "FUiAnim_RootVisualElement.h"
44 #include "FUiAnim_EflLayer.h"
45 #include "FUi_AccessibilityManager.h"
47 using namespace Tizen::App;
48 using namespace Tizen::Ui::Animations;
49 using namespace Tizen::Ui;
50 using namespace Tizen::Base;
51 using namespace Tizen::Base::Collection;
52 using namespace Tizen::Base::Runtime;
53 using namespace Tizen::Graphics;
55 namespace Tizen { namespace Ui { namespace Controls {
57 const String _ACTIVATE_FRAME = L"ActivateFrame";
60 : __pFramePresenter(null)
62 , __floatingBounds(0.0f, 0.0f, 0.0f, 0.0f)
63 , __showMode(FRAME_SHOW_MODE_FULL_SCREEN)
67 , __constructed(false)
69 , __pFormActivationChangeEventListener(null)
71 _FramePresenter* pPresenter = new (std::nothrow) _FramePresenter(*this);
72 SysTryReturnVoidResult(NID_UI_CTRL, pPresenter, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
74 FloatDimension screen = _ControlManager::GetInstance()->GetScreenSizeF();
75 __floatingBounds.width = screen.width;
76 __floatingBounds.height = screen.height;
78 __pFrameEvent = _FrameEvent::CreateInstanceN(*this);
79 SysTryCatch(NID_UI_CTRL, __pFrameEvent, , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
81 SetPresenter(*pPresenter);
82 SetClipChildrenEnabled(false);
101 delete __pFramePresenter;
102 __pFramePresenter = null;
108 _Frame::CreateFrameN(void)
110 result r = E_SUCCESS;
111 _RootVisualElement* pRootVE = null;
112 _EflLayer* pLayer = null;
113 int appType = _AppInfo::GetAppType();
115 _Frame* pFrame = new (std::nothrow) _Frame;
116 SysTryCatch(NID_UI_CTRL, pFrame, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
117 SysTryCatch(NID_UI_CTRL, GetLastResult() == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error occurred.");
119 if (appType & _APP_TYPE_IME_APP)
121 SysLog(NID_UI_CTRL, "[Ime Rotation]");
122 r = pFrame->CreateRootVisualElement(_WINDOW_TYPE_SUB);
123 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
127 r = pFrame->CreateRootVisualElement();
128 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
131 pRootVE = pFrame->GetRootVisualElement();
134 pLayer = static_cast<_EflLayer*>(pRootVE->GetNativeLayer());
137 if (!(appType & _APP_TYPE_IME_APP))
139 pLayer->SetOpacity(1);
142 pFrame->AcquireHandle();
144 SetLastResult(E_SUCCESS);
155 _Frame::SetPresenter(const _FramePresenter& framePresenter)
157 __pFramePresenter = const_cast <_FramePresenter*>(&framePresenter);
165 if (__pFramePresenter)
167 __pFramePresenter->Draw();
172 _Frame::OnActivated(void)
174 SysLog(NID_UI, "activated(%d)", __activated);
181 _Window::OnActivated();
183 _Form* pCurrentForm = GetCurrentForm();
184 if (pCurrentForm == null)
189 _Control* pFocusedControl = pCurrentForm->GetFocused();
192 pFocusedControl->SetFocused();
196 pCurrentForm->SetFocused();
198 _AccessibilityManager::GetInstance()->RequestAutoReading(_ACCESSIBILITY_AUTO_READING_MODE_FIRST_ITEM);
202 _Frame::OnNotifiedN(const _Control& source, IList* pArgs)
204 SysTryReturn(NID_UI_CTRL, pArgs, false, E_SYSTEM, "[E_SYSTEM] pArgs is null.")
206 String* pType = dynamic_cast <String*>(pArgs->GetAt(0));
207 SysTryReturn(NID_UI_CTRL, pType, false, E_SYSTEM, "[E_SYSTEM] pType is null.")
209 if (*pType == L"VisibilityEvent")
213 Integer* pObscured = dynamic_cast<Integer*>(pArgs->GetAt(1));
214 if (pObscured == null)
216 pArgs->RemoveAll(true);
222 obscured = pObscured->ToInt();
231 OnFrameDeactivated();
234 pArgs->RemoveAll(true);
239 else if (*pType == _ACTIVATE_FRAME)
241 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
244 pEcoreEvas->ActivateWindow(*this);
247 pArgs->RemoveAll(true);
257 _Frame::OnFrameActivated(void)
259 int childcount = GetChildCount();
261 for (int i = 0 ; i < childcount ; i++)
263 _Control* pChild = GetChild(i);
264 _Form* pForm = dynamic_cast<_Form*>(pChild);
267 pForm->MoveOverlayRegion(true);
272 IEventArg* pArg = _FrameEvent::CreateFrameEventArgN(*this, _FRAME_STATUS_ACTIVATED);
273 __pFrameEvent->Fire(*pArg);
275 if (GetChildCount() < 1)
277 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
278 SysTryReturnVoidResult(NID_UI_CTRL, pEcoreEvas, E_SYSTEM, "[E_SYSTEM] Unable to get evas");
280 if (GetShowMode() == FRAME_SHOW_MODE_FULL_SCREEN)
282 pEcoreEvas->SetIndicatorShowState(*GetRootWindow(), false);
288 _Frame::OnFrameDeactivated(void)
290 int childcount = GetChildCount();
292 for (int i = 0 ; i < childcount ; i++)
294 _Control* pChild = GetChild(i);
295 _Form* pForm = dynamic_cast<_Form*>(pChild);
298 pForm->MoveOverlayRegion(false);
303 IEventArg* pArg = _FrameEvent::CreateFrameEventArgN(*this, _FRAME_STATUS_DEACTIVATED);
304 __pFrameEvent->Fire(*pArg);
306 _TouchManager* pTouchManager = _TouchManager::GetInstance();
309 pTouchManager->SetTouchCanceled(null);
314 _Frame::OnFrameMinimized(void)
316 IEventArg* pArg = _FrameEvent::CreateFrameEventArgN(*this, _FRAME_STATUS_MINIMIZED);
317 __pFrameEvent->Fire(*pArg);
321 _Frame::OnFrameRestored(void)
325 IEventArg* pArg = _FrameEvent::CreateFrameEventArgN(*this, _FRAME_STATUS_RESTORED);
326 __pFrameEvent->Fire(*pArg);
330 _Frame::IsFocusableDescendant(const _Control* pFocus) const
332 const _Control* pTopChild = GetChild(GetChildCount() - 1); // Find the current Form.
333 const _Control* pTop = pFocus;
340 // 1. Find the Form of the pFocus.
341 // 2. If the Form is the current Form, then return true.
344 if (pTop == pTopChild)
348 pTop = pTop->GetParent();
355 _Frame::SetCurrentForm(const _Form* pForm)
357 result r = E_SUCCESS;
359 SysTryReturnVoidResult(NID_UI_CTRL, pForm != null, E_INVALID_ARG, "[E_INVALID_ARG] Form to become a new current form is null");
360 _Form* pNewForm = const_cast<_Form*>(pForm);
362 _Form* pCurrentForm = GetCurrentForm();
363 pNewForm->AddIndicatorObject();
365 if (pCurrentForm != null)
367 if (pCurrentForm != pForm)
370 r = MoveChildToTop(*pForm);
371 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
372 pNewForm->MoveOverlayRegion(true);
374 pCurrentForm->SetVisibleState(false);
375 pCurrentForm->MoveOverlayRegion(false);
377 if (__pFormActivationChangeEventListener)
378 __pFormActivationChangeEventListener->OnFormDeactivated(*pCurrentForm);
382 _Control* pFocus = pNewForm->GetFocused();
385 pFocus->SetFocused();
389 pNewForm->SetFocused();
392 pNewForm->SetVisibleState(true);
393 pNewForm->SetUpdateLayoutState(true);
395 if (__pFormActivationChangeEventListener)
396 __pFormActivationChangeEventListener->OnFormActivated(*pNewForm);
398 SetLastResult(E_SUCCESS);
404 _Frame::GetCurrentForm(void) const
406 _Form* pCurrentForm = null;
407 int controlCount = GetChildCount();
409 if (controlCount > 0)
411 for (int i = controlCount; i > 0; i--)
413 pCurrentForm = dynamic_cast<_Form*>(GetChild(i - 1));
414 SysTryReturn(NID_UI_CTRL, pCurrentForm != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
415 if (pCurrentForm->IsVisible())
426 _Frame::IsOrientationRoot(void) const
432 _Frame::SetRotation(bool rotation)
434 __rotation = rotation;
438 _Frame::AddFrameEventListener(const _IFrameEventListener& listener)
440 __constructed = true;
442 result r = __pFrameEvent->AddListener(listener);
443 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
447 _Frame::RemoveFrameEventListener(const _IFrameEventListener& listener)
449 result r = __pFrameEvent->RemoveListener(listener);
450 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
454 _Frame::SetFormActivationChangeEventListener(const _IFormActivationChangeEventListener* plistener)
456 __pFormActivationChangeEventListener = const_cast<_IFormActivationChangeEventListener*>(plistener);
461 _Frame::SetFloatingBounds(const FloatRectangle& rect)
463 __floatingBounds = rect;
467 _Frame::SetFloatingBounds(const Rectangle& rect)
469 __floatingBounds = _CoordinateSystemUtils::ConvertToFloat(rect);
473 _Frame::SetShowMode(FrameShowMode showMode)
475 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
476 SysTryReturnResult(NID_UI_CTRL, pEcoreEvas, E_SYSTEM, "The method cannot proceed due to a severe system error.");
478 if (showMode == FRAME_SHOW_MODE_MINIMIZED)
480 if (__minimized == true)
485 pEcoreEvas->MinimizeWindow(*GetRootWindow());
492 if (__minimized == true)
498 bool changeMode = true;
500 if ((showMode == FRAME_SHOW_MODE_PARTIAL_SCREEN) || (showMode == FRAME_SHOW_MODE_PARTIAL_SCREEN_FLOATING))
502 _Form* pCurrentForm = GetCurrentForm();
506 if (pCurrentForm->GetFormStyle() & _FORM_STYLE_INDICATOR)
513 SysTryReturnResult(NID_UI_CTRL, changeMode == true, E_SYSTEM, "The method cannot proceed due to a severe system error.");
515 int oldShowMode = __showMode;
516 __showMode = showMode;
518 result r = E_SUCCESS;
522 case FRAME_SHOW_MODE_FULL_SCREEN:
523 if (oldShowMode == FRAME_SHOW_MODE_PARTIAL_SCREEN_FLOATING)
525 r = pEcoreEvas->SetFloatingMode(*GetRootWindow(), false);
526 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
529 if (oldShowMode != FRAME_SHOW_MODE_FULL_SCREEN)
531 FloatDimension screen = _ControlManager::GetInstance()->GetScreenSizeF();
535 if (GetOrientation() == _CONTROL_ORIENTATION_PORTRAIT)
537 SetBounds(FloatRectangle(0.0f, 0.0f, screen.width, screen.height));
541 SetBounds(FloatRectangle(0.0f, 0.0f, screen.height, screen.width));
548 case FRAME_SHOW_MODE_PARTIAL_SCREEN:
549 if (oldShowMode == FRAME_SHOW_MODE_PARTIAL_SCREEN_FLOATING)
551 r = pEcoreEvas->SetFloatingMode(*GetRootWindow(), false);
552 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
555 if (oldShowMode == FRAME_SHOW_MODE_FULL_SCREEN)
557 SetBounds(__floatingBounds);
559 else if (oldShowMode == FRAME_SHOW_MODE_PARTIAL_SCREEN_FLOATING)
561 pEcoreEvas->SetWindowBounds(*GetRootWindow(), _CoordinateSystemUtils::ConvertToInteger(__floatingBounds));
565 case FRAME_SHOW_MODE_PARTIAL_SCREEN_FLOATING:
566 if (oldShowMode != FRAME_SHOW_MODE_PARTIAL_SCREEN_FLOATING)
568 r = pEcoreEvas->SetFloatingMode(*GetRootWindow(), true);
569 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
572 if (oldShowMode == FRAME_SHOW_MODE_FULL_SCREEN)
574 SetBounds(__floatingBounds);
586 _Frame::GetShowMode(bool minimize) const
590 if (__minimized == true)
592 return FRAME_SHOW_MODE_MINIMIZED;
606 _Frame::IsActivated(void) const
612 _Frame::OnChildAttached(const _Control& child)
614 _Form* pCurrentForm = GetCurrentForm();
616 if (pCurrentForm == &child)
618 int controlCount = GetChildCount();
620 if (controlCount > 1)
622 _Control* pOldCurrentForm = GetChild(controlCount - 2);
623 SysTryReturnVoidResult(NID_UI_CTRL, pOldCurrentForm != null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
624 pOldCurrentForm->SetVisibleState(false);
630 _Frame::OnChildDetached(const _Control& child)
632 int controlCount = GetChildCount();
634 if (controlCount > 0)
636 _Control* pCurrentForm = GetChild(controlCount - 1);
637 SysTryReturnVoidResult(NID_UI_CTRL, pCurrentForm, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
638 pCurrentForm->SetVisibleState(true);
642 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
643 SysTryReturnVoidResult(NID_UI_CTRL, pEcoreEvas, E_SYSTEM, "[E_SYSTEM] Unable to get evas");
644 pEcoreEvas->SetIndicatorShowState(*GetRootWindow(), false);
649 _Frame::OnBoundsChanging(const FloatRectangle& bounds)
651 int appType = _AppInfo::GetAppType();
652 if (appType & _APP_TYPE_IME_APP)
654 SysLog(NID_UI_CTRL, "[Ime Rotation]");
658 if (__restore == false)
660 __floatingBounds = bounds;
663 if ((__showMode == FRAME_SHOW_MODE_FULL_SCREEN) && (__restore == false))
665 if (__constructed == false)
671 if (__rotation == true)
677 return E_UNSUPPORTED_OPERATION;
682 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
683 SysTryReturn(NID_UI, pEcoreEvas, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
685 pEcoreEvas->SetWindowBounds(*GetRootWindow(), _CoordinateSystemUtils::ConvertToInteger(bounds));
686 result r = GetLastResult();
687 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
694 _Frame::OnAttached(void)
696 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
697 SysAssert(pEcoreEvas);
699 pEcoreEvas->SetWindowVisibleState(*GetRootWindow(), true);
705 _Frame::OnBackgroundColorChanged(Color& backgroundColor)
707 _RootVisualElement* pRootVE = GetRootVisualElement();
710 _EflLayer* pLayer = static_cast<_EflLayer*>(pRootVE->GetNativeLayer());
713 byte alpha = backgroundColor.GetAlpha();
714 float opacity = static_cast<float>(alpha) / 255.0f;
716 pLayer->SetOpacity(opacity);
719 FrameShowMode showMode = GetShowMode(false);
720 SetShowMode(FRAME_SHOW_MODE_FULL_SCREEN);
722 SetShowMode(showMode);
724 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
730 Orientation mode = ORIENTATION_PORTRAIT;
732 _Form* pCurrentForm = GetCurrentForm();
735 _FormImpl* pFormImpl = static_cast<_FormImpl*>(pCurrentForm->GetUserData());
738 mode = pFormImpl->GetOrientation();
743 _FrameImpl* pFrameImpl = static_cast<_FrameImpl*>(GetUserData());
746 mode = pFrameImpl->GetOrientation();
752 case ORIENTATION_PORTRAIT:
753 pEcoreEvas->SetWindowPreferredRotation(*this, 0, true);
755 case ORIENTATION_LANDSCAPE:
756 pEcoreEvas->SetWindowPreferredRotation(*this, 270, true);
758 case ORIENTATION_PORTRAIT_REVERSE:
759 pEcoreEvas->SetWindowPreferredRotation(*this, 180, true);
761 case ORIENTATION_LANDSCAPE_REVERSE:
762 pEcoreEvas->SetWindowPreferredRotation(*this, 90, true);
764 case ORIENTATION_AUTOMATIC:
766 pEcoreEvas->SetWindowPreferredRotation(*this, -1);
767 int autoRotation[3] = {0, 90, 270};
768 pEcoreEvas->SetWindowAvailabledRotation(*this, autoRotation, 3, true);
771 case ORIENTATION_AUTOMATIC_FOUR_DIRECTION:
773 pEcoreEvas->SetWindowPreferredRotation(*this, -1);
774 int autoFourRotation[4] = {0, 90, 180, 270};
775 pEcoreEvas->SetWindowAvailabledRotation(*this, autoFourRotation, 4, true);
784 _Frame::ResetFocusList(void)
786 Tizen::Ui::Controls::_Form* pCurrentForm = GetCurrentForm();
789 pCurrentForm->ResetFocusList();
792 }}} // Tizen::Ui::Controls