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 pCurrentForm->AddIndicatorObject();
191 _Control* pFocusControl = pCurrentForm->GetFocusControl();
194 pFocusControl->SetFocused();
198 pCurrentForm->SetFocused();
200 _AccessibilityManager::GetInstance()->RequestAutoReading(_ACCESSIBILITY_AUTO_READING_MODE_FIRST_ITEM);
204 _Frame::OnNotifiedN(const _Control& source, IList* pArgs)
206 SysTryReturn(NID_UI_CTRL, pArgs, false, E_SYSTEM, "[E_SYSTEM] pArgs is null.")
208 String* pType = dynamic_cast <String*>(pArgs->GetAt(0));
209 SysTryReturn(NID_UI_CTRL, pType, false, E_SYSTEM, "[E_SYSTEM] pType is null.")
211 if (*pType == L"VisibilityEvent")
215 Integer* pObscured = dynamic_cast<Integer*>(pArgs->GetAt(1));
216 if (pObscured == null)
218 pArgs->RemoveAll(true);
224 obscured = pObscured->ToInt();
233 OnFrameDeactivated();
236 pArgs->RemoveAll(true);
241 else if (*pType == _ACTIVATE_FRAME)
243 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
246 pEcoreEvas->ActivateWindow(*this);
249 pArgs->RemoveAll(true);
259 _Frame::OnFrameActivated(void)
261 int childcount = GetChildCount();
263 for (int i = 0 ; i < childcount ; i++)
265 _Control* pChild = GetChild(i);
266 _Form* pForm = dynamic_cast<_Form*>(pChild);
269 pForm->MoveOverlayRegion(true);
274 IEventArg* pArg = _FrameEvent::CreateFrameEventArgN(*this, _FRAME_STATUS_ACTIVATED);
275 __pFrameEvent->Fire(*pArg);
277 if (GetChildCount() < 1)
279 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
280 SysTryReturnVoidResult(NID_UI_CTRL, pEcoreEvas, E_SYSTEM, "[E_SYSTEM] Unable to get evas");
282 if (GetShowMode() == FRAME_SHOW_MODE_FULL_SCREEN)
284 pEcoreEvas->SetIndicatorShowState(*GetRootWindow(), false);
290 _Frame::OnFrameDeactivated(void)
292 int childcount = GetChildCount();
294 for (int i = 0 ; i < childcount ; i++)
296 _Control* pChild = GetChild(i);
297 _Form* pForm = dynamic_cast<_Form*>(pChild);
300 pForm->MoveOverlayRegion(false);
305 IEventArg* pArg = _FrameEvent::CreateFrameEventArgN(*this, _FRAME_STATUS_DEACTIVATED);
306 __pFrameEvent->Fire(*pArg);
308 _TouchManager* pTouchManager = _TouchManager::GetInstance();
311 pTouchManager->SetTouchCanceled(null);
316 _Frame::OnFrameMinimized(void)
318 IEventArg* pArg = _FrameEvent::CreateFrameEventArgN(*this, _FRAME_STATUS_MINIMIZED);
319 __pFrameEvent->Fire(*pArg);
323 _Frame::OnFrameRestored(void)
327 IEventArg* pArg = _FrameEvent::CreateFrameEventArgN(*this, _FRAME_STATUS_RESTORED);
328 __pFrameEvent->Fire(*pArg);
332 _Frame::IsFocusableDescendant(const _Control* pFocus) const
334 const _Control* pTopChild = GetChild(GetChildCount() - 1); // Find the current Form.
335 const _Control* pTop = pFocus;
342 // 1. Find the Form of the pFocus.
343 // 2. If the Form is the current Form, then return true.
346 if (pTop == pTopChild)
350 pTop = pTop->GetParent();
357 _Frame::SetCurrentForm(const _Form* pForm)
359 result r = E_SUCCESS;
361 SysTryReturnVoidResult(NID_UI_CTRL, pForm != null, E_INVALID_ARG, "[E_INVALID_ARG] Form to become a new current form is null");
362 _Form* pNewForm = const_cast<_Form*>(pForm);
364 _Form* pCurrentForm = GetCurrentForm();
365 pNewForm->AddIndicatorObject();
367 if (pCurrentForm != null)
369 if (pCurrentForm != pForm)
371 _Control* pFocusTraversalControl = pCurrentForm->GetFocusTraversalControl();
372 if (pFocusTraversalControl)
374 pFocusTraversalControl->SetFocusModeStateEnabled(false) ;
377 r = MoveChildToTop(*pForm);
378 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
379 pNewForm->MoveOverlayRegion(true);
381 pCurrentForm->SetVisibleState(false);
382 pCurrentForm->MoveOverlayRegion(false);
384 if (__pFormActivationChangeEventListener)
385 __pFormActivationChangeEventListener->OnFormDeactivated(*pCurrentForm);
389 _Control* pFocus = pNewForm->GetFocusControl();
392 pFocus->SetFocused();
396 pNewForm->SetFocused();
399 pNewForm->SetVisibleState(true);
400 pNewForm->SetUpdateLayoutState(true);
402 if (__pFormActivationChangeEventListener)
403 __pFormActivationChangeEventListener->OnFormActivated(*pNewForm);
405 SetLastResult(E_SUCCESS);
411 _Frame::GetCurrentForm(void) const
413 _Form* pCurrentForm = null;
414 int controlCount = GetChildCount();
416 if (controlCount > 0)
418 for (int i = controlCount; i > 0; i--)
420 pCurrentForm = dynamic_cast<_Form*>(GetChild(i - 1));
421 SysTryReturn(NID_UI_CTRL, pCurrentForm != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
422 if (pCurrentForm->IsVisible())
433 _Frame::IsOrientationRoot(void) const
439 _Frame::SetRotation(bool rotation)
441 __rotation = rotation;
445 _Frame::AddFrameEventListener(const _IFrameEventListener& listener)
447 __constructed = true;
449 result r = __pFrameEvent->AddListener(listener);
450 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
454 _Frame::RemoveFrameEventListener(const _IFrameEventListener& listener)
456 result r = __pFrameEvent->RemoveListener(listener);
457 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
461 _Frame::SetFormActivationChangeEventListener(const _IFormActivationChangeEventListener* plistener)
463 __pFormActivationChangeEventListener = const_cast<_IFormActivationChangeEventListener*>(plistener);
468 _Frame::SetFloatingBounds(const FloatRectangle& rect)
470 __floatingBounds = rect;
474 _Frame::SetFloatingBounds(const Rectangle& rect)
476 __floatingBounds = _CoordinateSystemUtils::ConvertToFloat(rect);
480 _Frame::SetShowMode(FrameShowMode showMode)
482 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
483 SysTryReturnResult(NID_UI_CTRL, pEcoreEvas, E_SYSTEM, "The method cannot proceed due to a severe system error.");
485 if (showMode == FRAME_SHOW_MODE_MINIMIZED)
487 if (__minimized == true)
492 pEcoreEvas->MinimizeWindow(*GetRootWindow());
499 if (__minimized == true)
505 bool changeMode = true;
507 if ((showMode == FRAME_SHOW_MODE_PARTIAL_SCREEN) || (showMode == FRAME_SHOW_MODE_PARTIAL_SCREEN_FLOATING))
509 _Form* pCurrentForm = GetCurrentForm();
513 if (pCurrentForm->GetFormStyle() & _FORM_STYLE_INDICATOR)
520 SysTryReturnResult(NID_UI_CTRL, changeMode == true, E_SYSTEM, "The method cannot proceed due to a severe system error.");
522 int oldShowMode = __showMode;
523 __showMode = showMode;
525 result r = E_SUCCESS;
529 case FRAME_SHOW_MODE_FULL_SCREEN:
530 if (oldShowMode == FRAME_SHOW_MODE_PARTIAL_SCREEN_FLOATING)
532 r = pEcoreEvas->SetFloatingMode(*GetRootWindow(), false);
533 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
536 if (oldShowMode != FRAME_SHOW_MODE_FULL_SCREEN)
538 FloatDimension screen = _ControlManager::GetInstance()->GetScreenSizeF();
542 if (GetOrientation() == _CONTROL_ORIENTATION_PORTRAIT)
544 SetBounds(FloatRectangle(0.0f, 0.0f, screen.width, screen.height));
548 SetBounds(FloatRectangle(0.0f, 0.0f, screen.height, screen.width));
555 case FRAME_SHOW_MODE_PARTIAL_SCREEN:
556 if (oldShowMode == FRAME_SHOW_MODE_PARTIAL_SCREEN_FLOATING)
558 r = pEcoreEvas->SetFloatingMode(*GetRootWindow(), false);
559 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
562 if (oldShowMode == FRAME_SHOW_MODE_FULL_SCREEN)
564 SetBounds(__floatingBounds);
566 else if (oldShowMode == FRAME_SHOW_MODE_PARTIAL_SCREEN_FLOATING)
568 pEcoreEvas->SetWindowBounds(*GetRootWindow(), _CoordinateSystemUtils::ConvertToInteger(__floatingBounds));
572 case FRAME_SHOW_MODE_PARTIAL_SCREEN_FLOATING:
573 if (oldShowMode != FRAME_SHOW_MODE_PARTIAL_SCREEN_FLOATING)
575 r = pEcoreEvas->SetFloatingMode(*GetRootWindow(), true);
576 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
579 if (oldShowMode == FRAME_SHOW_MODE_FULL_SCREEN)
581 SetBounds(__floatingBounds);
593 _Frame::GetShowMode(bool minimize) const
597 if (__minimized == true)
599 return FRAME_SHOW_MODE_MINIMIZED;
613 _Frame::IsActivated(void) const
619 _Frame::OnChildAttached(const _Control& child)
621 _Form* pCurrentForm = GetCurrentForm();
623 if (pCurrentForm == &child)
625 int controlCount = GetChildCount();
627 if (controlCount > 1)
629 _Control* pOldCurrentForm = GetChild(controlCount - 2);
630 SysTryReturnVoidResult(NID_UI_CTRL, pOldCurrentForm != null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
631 pOldCurrentForm->SetVisibleState(false);
632 _Form* pOldForm = static_cast<_Form*>(pOldCurrentForm);
635 _Control* pFocusTraversalControl = pOldForm->GetFocusTraversalControl();
636 if (pFocusTraversalControl)
638 pFocusTraversalControl->SetFocusModeStateEnabled(false) ;
646 _Frame::OnChildDetached(const _Control& child)
648 int controlCount = GetChildCount();
650 if (controlCount > 0)
652 _Control* pCurrentForm = GetChild(controlCount - 1);
653 SysTryReturnVoidResult(NID_UI_CTRL, pCurrentForm, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
654 pCurrentForm->SetVisibleState(true);
658 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
659 SysTryReturnVoidResult(NID_UI_CTRL, pEcoreEvas, E_SYSTEM, "[E_SYSTEM] Unable to get evas");
660 pEcoreEvas->SetIndicatorShowState(*GetRootWindow(), false);
665 _Frame::OnBoundsChanging(const FloatRectangle& bounds)
667 int appType = _AppInfo::GetAppType();
668 if (appType & _APP_TYPE_IME_APP)
670 SysLog(NID_UI_CTRL, "[Ime Rotation]");
674 if (__restore == false)
676 __floatingBounds = bounds;
679 if ((__showMode == FRAME_SHOW_MODE_FULL_SCREEN) && (__restore == false))
681 if (__constructed == false)
687 if (__rotation == true)
693 return E_UNSUPPORTED_OPERATION;
698 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
699 SysTryReturn(NID_UI, pEcoreEvas, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
701 pEcoreEvas->SetWindowBounds(*GetRootWindow(), _CoordinateSystemUtils::ConvertToInteger(bounds));
702 result r = GetLastResult();
703 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
710 _Frame::OnAttached(void)
712 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
713 SysAssert(pEcoreEvas);
715 pEcoreEvas->SetWindowVisibleState(*GetRootWindow(), true);
721 _Frame::OnBackgroundColorChanged(Color& backgroundColor)
723 _RootVisualElement* pRootVE = GetRootVisualElement();
726 _EflLayer* pLayer = static_cast<_EflLayer*>(pRootVE->GetNativeLayer());
729 byte alpha = backgroundColor.GetAlpha();
730 float opacity = static_cast<float>(alpha) / 255.0f;
732 pLayer->SetOpacity(opacity);
735 FrameShowMode showMode = GetShowMode(false);
736 SetShowMode(FRAME_SHOW_MODE_FULL_SCREEN);
738 SetShowMode(showMode);
740 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
746 Orientation mode = ORIENTATION_PORTRAIT;
748 _Form* pCurrentForm = GetCurrentForm();
751 _FormImpl* pFormImpl = static_cast<_FormImpl*>(pCurrentForm->GetUserData());
754 mode = pFormImpl->GetOrientation();
759 _FrameImpl* pFrameImpl = static_cast<_FrameImpl*>(GetUserData());
762 mode = pFrameImpl->GetOrientation();
768 case ORIENTATION_PORTRAIT:
769 pEcoreEvas->SetWindowPreferredRotation(*this, 0, true);
771 case ORIENTATION_LANDSCAPE:
772 pEcoreEvas->SetWindowPreferredRotation(*this, 270, true);
774 case ORIENTATION_PORTRAIT_REVERSE:
775 pEcoreEvas->SetWindowPreferredRotation(*this, 180, true);
777 case ORIENTATION_LANDSCAPE_REVERSE:
778 pEcoreEvas->SetWindowPreferredRotation(*this, 90, true);
780 case ORIENTATION_AUTOMATIC:
782 pEcoreEvas->SetWindowPreferredRotation(*this, -1);
783 int autoRotation[3] = {0, 90, 270};
784 pEcoreEvas->SetWindowAvailabledRotation(*this, autoRotation, 3, true);
787 case ORIENTATION_AUTOMATIC_FOUR_DIRECTION:
789 pEcoreEvas->SetWindowPreferredRotation(*this, -1);
790 int autoFourRotation[4] = {0, 90, 180, 270};
791 pEcoreEvas->SetWindowAvailabledRotation(*this, autoFourRotation, 4, true);
800 _Frame::ResetFocusList(void)
802 Tizen::Ui::Controls::_Form* pCurrentForm = GetCurrentForm();
805 pCurrentForm->ResetFocusList();
810 _Frame::GetFocusControl(void) const
812 _Form* pForm = GetCurrentForm();
815 return pForm->GetFocusControl();
821 _Frame::SetFocusControl(const _Control* pControl)
823 _Form* pForm = GetCurrentForm();
826 pForm->SetFocusControl(pControl);
831 Tizen::Base::Collection::IListT<_Control*>*
832 _Frame::GetFocusList(void) const
834 _Form* pForm = GetCurrentForm();
837 return pForm->GetFocusList();
843 _Frame::GetFocusTraversalControl(void) const
845 _Form* pForm = GetCurrentForm();
848 return pForm->GetFocusTraversalControl();
854 _Frame::SetFocusTraversalControl(_Control* pControl)
856 _Form* pForm = GetCurrentForm();
859 pForm->SetFocusTraversalControl(pControl);
862 }}} // Tizen::Ui::Controls