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* pFocusedControl = pCurrentForm->GetFocused();
194 pFocusedControl->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)
372 r = MoveChildToTop(*pForm);
373 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
374 pNewForm->MoveOverlayRegion(true);
376 pCurrentForm->SetVisibleState(false);
377 pCurrentForm->MoveOverlayRegion(false);
379 if (__pFormActivationChangeEventListener)
380 __pFormActivationChangeEventListener->OnFormDeactivated(*pCurrentForm);
384 _Control* pFocus = pNewForm->GetFocused();
387 pFocus->SetFocused();
391 pNewForm->SetFocused();
394 pNewForm->SetVisibleState(true);
395 pNewForm->SetUpdateLayoutState(true);
397 if (__pFormActivationChangeEventListener)
398 __pFormActivationChangeEventListener->OnFormActivated(*pNewForm);
400 SetLastResult(E_SUCCESS);
406 _Frame::GetCurrentForm(void) const
408 _Form* pCurrentForm = null;
409 int controlCount = GetChildCount();
411 if (controlCount > 0)
413 for (int i = controlCount; i > 0; i--)
415 pCurrentForm = dynamic_cast<_Form*>(GetChild(i - 1));
416 SysTryReturn(NID_UI_CTRL, pCurrentForm != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
417 if (pCurrentForm->IsVisible())
428 _Frame::IsOrientationRoot(void) const
434 _Frame::SetRotation(bool rotation)
436 __rotation = rotation;
440 _Frame::AddFrameEventListener(const _IFrameEventListener& listener)
442 __constructed = true;
444 result r = __pFrameEvent->AddListener(listener);
445 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
449 _Frame::RemoveFrameEventListener(const _IFrameEventListener& listener)
451 result r = __pFrameEvent->RemoveListener(listener);
452 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
456 _Frame::SetFormActivationChangeEventListener(const _IFormActivationChangeEventListener* plistener)
458 __pFormActivationChangeEventListener = const_cast<_IFormActivationChangeEventListener*>(plistener);
463 _Frame::SetFloatingBounds(const FloatRectangle& rect)
465 __floatingBounds = rect;
469 _Frame::SetFloatingBounds(const Rectangle& rect)
471 __floatingBounds = _CoordinateSystemUtils::ConvertToFloat(rect);
475 _Frame::SetShowMode(FrameShowMode showMode)
477 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
478 SysTryReturnResult(NID_UI_CTRL, pEcoreEvas, E_SYSTEM, "The method cannot proceed due to a severe system error.");
480 if (showMode == FRAME_SHOW_MODE_MINIMIZED)
482 if (__minimized == true)
487 pEcoreEvas->MinimizeWindow(*GetRootWindow());
494 if (__minimized == true)
500 bool changeMode = true;
502 if ((showMode == FRAME_SHOW_MODE_PARTIAL_SCREEN) || (showMode == FRAME_SHOW_MODE_PARTIAL_SCREEN_FLOATING))
504 _Form* pCurrentForm = GetCurrentForm();
508 if (pCurrentForm->GetFormStyle() & _FORM_STYLE_INDICATOR)
515 SysTryReturnResult(NID_UI_CTRL, changeMode == true, E_SYSTEM, "The method cannot proceed due to a severe system error.");
517 int oldShowMode = __showMode;
518 __showMode = showMode;
520 result r = E_SUCCESS;
524 case FRAME_SHOW_MODE_FULL_SCREEN:
525 if (oldShowMode == FRAME_SHOW_MODE_PARTIAL_SCREEN_FLOATING)
527 r = pEcoreEvas->SetFloatingMode(*GetRootWindow(), false);
528 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
531 if (oldShowMode != FRAME_SHOW_MODE_FULL_SCREEN)
533 FloatDimension screen = _ControlManager::GetInstance()->GetScreenSizeF();
537 if (GetOrientation() == _CONTROL_ORIENTATION_PORTRAIT)
539 SetBounds(FloatRectangle(0.0f, 0.0f, screen.width, screen.height));
543 SetBounds(FloatRectangle(0.0f, 0.0f, screen.height, screen.width));
550 case FRAME_SHOW_MODE_PARTIAL_SCREEN:
551 if (oldShowMode == FRAME_SHOW_MODE_PARTIAL_SCREEN_FLOATING)
553 r = pEcoreEvas->SetFloatingMode(*GetRootWindow(), false);
554 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
557 if (oldShowMode == FRAME_SHOW_MODE_FULL_SCREEN)
559 SetBounds(__floatingBounds);
561 else if (oldShowMode == FRAME_SHOW_MODE_PARTIAL_SCREEN_FLOATING)
563 pEcoreEvas->SetWindowBounds(*GetRootWindow(), _CoordinateSystemUtils::ConvertToInteger(__floatingBounds));
567 case FRAME_SHOW_MODE_PARTIAL_SCREEN_FLOATING:
568 if (oldShowMode != FRAME_SHOW_MODE_PARTIAL_SCREEN_FLOATING)
570 r = pEcoreEvas->SetFloatingMode(*GetRootWindow(), true);
571 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
574 if (oldShowMode == FRAME_SHOW_MODE_FULL_SCREEN)
576 SetBounds(__floatingBounds);
588 _Frame::GetShowMode(bool minimize) const
592 if (__minimized == true)
594 return FRAME_SHOW_MODE_MINIMIZED;
608 _Frame::IsActivated(void) const
614 _Frame::OnChildAttached(const _Control& child)
616 _Form* pCurrentForm = GetCurrentForm();
618 if (pCurrentForm == &child)
620 int controlCount = GetChildCount();
622 if (controlCount > 1)
624 _Control* pOldCurrentForm = GetChild(controlCount - 2);
625 SysTryReturnVoidResult(NID_UI_CTRL, pOldCurrentForm != null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
626 pOldCurrentForm->SetVisibleState(false);
632 _Frame::OnChildDetached(const _Control& child)
634 int controlCount = GetChildCount();
636 if (controlCount > 0)
638 _Control* pCurrentForm = GetChild(controlCount - 1);
639 SysTryReturnVoidResult(NID_UI_CTRL, pCurrentForm, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
640 pCurrentForm->SetVisibleState(true);
644 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
645 SysTryReturnVoidResult(NID_UI_CTRL, pEcoreEvas, E_SYSTEM, "[E_SYSTEM] Unable to get evas");
646 pEcoreEvas->SetIndicatorShowState(*GetRootWindow(), false);
651 _Frame::OnBoundsChanging(const FloatRectangle& bounds)
653 int appType = _AppInfo::GetAppType();
654 if (appType & _APP_TYPE_IME_APP)
656 SysLog(NID_UI_CTRL, "[Ime Rotation]");
660 if (__restore == false)
662 __floatingBounds = bounds;
665 if ((__showMode == FRAME_SHOW_MODE_FULL_SCREEN) && (__restore == false))
667 if (__constructed == false)
673 if (__rotation == true)
679 return E_UNSUPPORTED_OPERATION;
684 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
685 SysTryReturn(NID_UI, pEcoreEvas, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
687 pEcoreEvas->SetWindowBounds(*GetRootWindow(), _CoordinateSystemUtils::ConvertToInteger(bounds));
688 result r = GetLastResult();
689 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
696 _Frame::OnAttached(void)
698 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
699 SysAssert(pEcoreEvas);
701 pEcoreEvas->SetWindowVisibleState(*GetRootWindow(), true);
707 _Frame::OnBackgroundColorChanged(Color& backgroundColor)
709 _RootVisualElement* pRootVE = GetRootVisualElement();
712 _EflLayer* pLayer = static_cast<_EflLayer*>(pRootVE->GetNativeLayer());
715 byte alpha = backgroundColor.GetAlpha();
716 float opacity = static_cast<float>(alpha) / 255.0f;
718 pLayer->SetOpacity(opacity);
721 FrameShowMode showMode = GetShowMode(false);
722 SetShowMode(FRAME_SHOW_MODE_FULL_SCREEN);
724 SetShowMode(showMode);
726 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
732 Orientation mode = ORIENTATION_PORTRAIT;
734 _Form* pCurrentForm = GetCurrentForm();
737 _FormImpl* pFormImpl = static_cast<_FormImpl*>(pCurrentForm->GetUserData());
740 mode = pFormImpl->GetOrientation();
745 _FrameImpl* pFrameImpl = static_cast<_FrameImpl*>(GetUserData());
748 mode = pFrameImpl->GetOrientation();
754 case ORIENTATION_PORTRAIT:
755 pEcoreEvas->SetWindowPreferredRotation(*this, 0, true);
757 case ORIENTATION_LANDSCAPE:
758 pEcoreEvas->SetWindowPreferredRotation(*this, 270, true);
760 case ORIENTATION_PORTRAIT_REVERSE:
761 pEcoreEvas->SetWindowPreferredRotation(*this, 180, true);
763 case ORIENTATION_LANDSCAPE_REVERSE:
764 pEcoreEvas->SetWindowPreferredRotation(*this, 90, true);
766 case ORIENTATION_AUTOMATIC:
768 pEcoreEvas->SetWindowPreferredRotation(*this, -1);
769 int autoRotation[3] = {0, 90, 270};
770 pEcoreEvas->SetWindowAvailabledRotation(*this, autoRotation, 3, true);
773 case ORIENTATION_AUTOMATIC_FOUR_DIRECTION:
775 pEcoreEvas->SetWindowPreferredRotation(*this, -1);
776 int autoFourRotation[4] = {0, 90, 180, 270};
777 pEcoreEvas->SetWindowAvailabledRotation(*this, autoFourRotation, 4, true);
786 _Frame::ResetFocusList(void)
788 Tizen::Ui::Controls::_Form* pCurrentForm = GetCurrentForm();
791 pCurrentForm->ResetFocusList();
794 }}} // Tizen::Ui::Controls