Merge "SplitPanel Changes (Divider touch extension + focus ui removal) - tizen2.2...
[framework/osp/uifw.git] / src / ui / FUi_AccessibilityManager.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0/
10 //
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.
16 //
17 #include <sys/utsname.h>
18 #include <FBaseInteger.h>
19 #include <pthread.h>
20 #include <FAppUiApp.h>
21 #include <FAppIAppFrame.h>
22 #include <FBaseRtTimer.h>
23 #include <FLclLocale.h>
24 #include <FUiAnimVisualElement.h>
25 #include <FUiCtrlFrame.h>
26 #include <FUiCtrlForm.h>
27 #include <FGrpCanvas.h>
28 #include <FGrpColor.h>
29 #include <FGrpFloatDimension.h>
30 #include <FGrpEnrichedText.h>
31 #include <FGrpBitmap.h>
32 #include <FBase_StringConverter.h>
33 #include <FGrp_BitmapImpl.h>
34 #include <FSys_SystemTimeImpl.h>
35 #include "FUi_AccessibilityGesture.h"
36 #include "FUi_AccessibilitySystemSettingLoader.h"
37 #include "FUi_AccessibilityTtsPlayer.h"
38 #include "FUi_AccessibilityManager.h"
39 #include "FUi_AccessibilityElement.h"
40 #include "FUi_AccessibilityContainer.h"
41 #include "FUi_IAccessibilityListener.h"
42 #include "FUi_ControlManager.h"
43 #include "FUi_TouchManager.h"
44 #include "FUi_UiEventManager.h"
45 #include "FUiAnim_VisualElementImpl.h"
46 #include "FUiCtrl_FrameImpl.h"
47 #include "FUiCtrl_ScrollPanel.h"
48 #include "FUiCtrl_IconListView.h"
49 #include "FUi_ResourceManager.h"
50
51 using namespace Tizen::App;
52 using namespace Tizen::Base;
53 using namespace Tizen::Base::Collection;
54 using namespace Tizen::Base::Runtime;
55 using namespace Tizen::Graphics;
56 using namespace Tizen::Ui::Animations;
57 using namespace Tizen::Ui::Controls;
58 using namespace Tizen::System;
59 namespace
60 {
61 class GuidePopupTimer
62         : public ITimerEventListener
63 {
64 public:
65         GuidePopupTimer(void)
66                 : __pElement(null)
67         {
68                 timer.Construct(*this);
69         }
70         virtual ~GuidePopupTimer(void) {}
71         void SetElement(VisualElement* pElement)
72         {
73                 if (__pElement != null)
74                 {
75                         timer.Cancel();
76                 }
77                 __pElement = pElement;
78                 timer.Start(3000);
79
80         }
81         void Stop(void)
82         {
83                 timer.Cancel();
84         }
85         virtual void OnTimerExpired(Timer& timer)
86         {
87                 if (__pElement)
88                 {
89                         __pElement->SetShowState(false);
90                 }
91                 __pElement = null;
92         }
93         VisualElement* __pElement;
94         Timer timer;
95 };
96
97 class AutoReadingTimer
98         : public ITimerEventListener
99 {
100 public:
101         AutoReadingTimer(Tizen::Ui::_AccessibilityManager* pManager)
102                 : __pAccessibilityManager(pManager)
103                 , __mode(Tizen::Ui::_ACCESSIBILITY_AUTO_READING_MODE_FIRST_ITEM)
104                 , __start(false)
105         {
106
107                 timer.Construct(*this);
108         }
109         virtual ~AutoReadingTimer(void) {}
110         void Start(Tizen::Ui::_AccessibilityAutoReadingMode mode)
111         {
112                 if((Tizen::App::_AppInfo::GetAppType() & _APP_TYPE_SERVICE_APP) || (Tizen::App::_AppInfo::GetAppType() & _APP_TYPE_IME_APP))
113                 {
114                         return;
115                 }
116                 if (__start)
117                 {
118                         return;
119                 }
120                 __start = true;
121                 __mode = mode;
122                 timer.Start(700);
123         }
124         void Stop(void)
125         {
126                 timer.Cancel();
127                 __start = false;
128         }
129         virtual void OnTimerExpired(Timer& timer)
130         {
131                 if (!(__pAccessibilityManager->IsScreenReaderActivated()) || UiApp::GetInstance()->GetAppUiState() == APP_UI_STATE_BACKGROUND)
132                 {
133                         return Stop();
134                 }
135                 SysLog(NID_UI, "mode %d", __mode);
136                 if (__pAccessibilityManager->GetTtsStatus() != Tizen::Ui::ACCESSIBILITY_SCREEN_READER_STATUS_READY
137                         && __pAccessibilityManager->GetTtsStatus() != Tizen::Ui::ACCESSIBILITY_SCREEN_READER_STATUS_PLAYING)
138                 {
139                         __start = false;
140                         Start(__mode);
141                         SysLog(NID_UI, "AccessibilityManager::AutoReadingTimer is started again because tts is not initialized.");
142                         return;
143                 }
144                 __start = false;
145                 __pAccessibilityManager->ReadElement(__mode);
146         }
147         Tizen::Ui::_AccessibilityManager* __pAccessibilityManager;
148         Timer timer;
149         Tizen::Ui::_AccessibilityAutoReadingMode __mode;
150         bool __start;
151 };
152
153 GuidePopupTimer* pGuidePopupTimer;
154 AutoReadingTimer* pAutoReadingTimer;
155 }
156 namespace Tizen { namespace Ui {
157
158 template <class T>
159 class _AccessibilityItemComparer
160         : public Tizen::Base::Collection::IComparerT <T>
161 {
162 public:
163         _AccessibilityItemComparer(void)
164         {
165         }
166         virtual ~_AccessibilityItemComparer(void)
167         {
168         }
169         virtual result Compare(const T& obj1, const T& obj2, int& cmp) const
170         {
171                 Tizen::Graphics::Rectangle rect1= obj1->GetAbsoluteBounds();
172                 Tizen::Graphics::Rectangle rect2= obj2->GetAbsoluteBounds();
173
174                 if (rect1.y > rect2.y)
175                 {
176                         cmp = 1;
177                         return E_SUCCESS;
178                 }
179                 else if (rect1.y < rect2.y)
180                 {
181                         cmp = -1;
182                         return E_SUCCESS;
183                 }
184                 else
185                 {
186                         if (rect1.x > rect2.x)
187                         {
188                                 cmp = 1;
189                                 return E_SUCCESS;
190                         }
191                         else if (rect1.x < rect2.x)
192                         {
193                                 cmp = -1;
194                                 return E_SUCCESS;
195                         }
196                         else
197                         {
198                                 cmp = 0;
199                                 return E_SUCCESS;
200                         }
201                 }
202         }
203 }; //class _AccessibilityComparer
204
205 template <class T>
206 class _ElementComparer
207         : public Tizen::Base::Collection::IComparerT <T>
208 {
209 public:
210         _ElementComparer(void)
211         {
212         }
213         virtual ~_ElementComparer(void)
214         {
215         }
216         virtual result Compare(const T& obj1, const T& obj2, int& cmp) const
217         {
218                 if (obj1->GetParent()->GetPriority() > obj2->GetParent()->GetPriority())
219                 {
220                         cmp = -1;
221                         return E_SUCCESS;
222                 }
223                 else if (obj1->GetParent()->GetPriority() < obj2->GetParent()->GetPriority())
224                 {
225                         cmp = 1;
226                         return E_SUCCESS;
227                 }
228                 else
229                 {
230                         Tizen::Graphics::FloatRectangle rect1= obj1->GetAbsoluteBounds();
231                         Tizen::Graphics::FloatRectangle rect2= obj2->GetAbsoluteBounds();
232
233                         if (rect1.y > rect2.y)
234                         {
235                                 cmp = 1;
236                                 return E_SUCCESS;
237                         }
238                         else if (rect1.y < rect2.y)
239                         {
240                                 cmp = -1;
241                                 return E_SUCCESS;
242                         }
243                         else
244                         {
245                                 if (rect1.x > rect2.x)
246                                 {
247                                         cmp = 1;
248                                         return E_SUCCESS;
249                                 }
250                                 else if (rect1.x < rect2.x)
251                                 {
252                                         cmp = -1;
253                                         return E_SUCCESS;
254                                 }
255                                 else
256                                 {
257                                         cmp = 0;
258                                         return E_SUCCESS;
259                                 }
260                         }
261                 }
262         }
263 };
264
265 static _AccessibilityManager* pAccManager = null;
266 bool _AccessibilityManager::__screenReaderIsEnabled = false;
267 _AccessibilityManager::_AccessibilityManager(void)
268         : __pAccGesture(null)
269         , __pTtsPlayer(null)
270         , __pSettingLoader(null)
271         , __pTargetContainer(null)
272         , __pTargetElement(null)
273         , __pTitleElement(null)
274         , __containerList()
275         , __candidateList()
276         , __mode(MODE_NONE)
277         , __pReadingVe(null)
278         , __pFocusVe(null)
279         , __pPanningControl(null)
280         , __needRefreshItem(false)
281 {
282         Initialize();
283 }
284 _AccessibilityManager::~_AccessibilityManager(void)
285 {
286         delete __pAccGesture;
287         __pAccGesture = null;
288         delete __pTtsPlayer;
289         __pTtsPlayer = null;
290         delete __pSettingLoader;
291         __pSettingLoader = null;
292         delete pGuidePopupTimer;
293         pGuidePopupTimer = null;
294         delete pAutoReadingTimer;
295         pAutoReadingTimer = null;
296 }
297
298 _AccessibilityManager*
299 _AccessibilityManager::GetInstance(void)
300 {
301         return pAccManager;
302 }
303
304 void
305 _AccessibilityManager::CreateInstance(void)
306 {
307         static pthread_once_t onceBlock = PTHREAD_ONCE_INIT;
308
309         if (pAccManager == null)
310         {
311                 pthread_once(&onceBlock, InitializeInstance);
312         }
313 }
314
315 void
316 _AccessibilityManager::InitializeInstance(void)
317 {
318         pAccManager = new (std::nothrow) _AccessibilityManager;
319 }
320 void
321 _AccessibilityManager::ReleaseInstance(void)
322 {
323         delete pAccManager;
324         pAccManager = null;
325 }
326 void
327 _AccessibilityManager::Initialize(void)
328 {
329         __pAccGesture = new (std::nothrow) _AccessibilityGesture(*this);
330         SysTryReturn(NID_UI, __pAccGesture, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed");
331         __pTtsPlayer = new (std::nothrow) _AccessibilityTtsPlayer(*this);
332         SysTryCatch(NID_UI, __pTtsPlayer, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed");
333         __pTtsPlayer->Construct();
334         __pSettingLoader = new (std::nothrow) _AccessibilitySystemSettingLoader(*this);
335         SysTryCatch(NID_UI, __pSettingLoader, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed");
336
337         if (IsScreenReaderActivated())
338         {
339                 __pTtsPlayer->SetLocale(__pSettingLoader->GetLocale());
340                 __pTtsPlayer->Activate();
341         }
342         pGuidePopupTimer = new (std::nothrow) GuidePopupTimer;
343         SysTryCatch(NID_UI, pGuidePopupTimer, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed");
344         pAutoReadingTimer = new (std::nothrow) AutoReadingTimer(this);
345         SysTryCatch(NID_UI, pAutoReadingTimer, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed");
346         return;
347
348 CATCH:
349         delete __pAccGesture;
350         __pAccGesture = null;
351         delete __pTtsPlayer;
352         __pTtsPlayer = null;
353         delete __pSettingLoader;
354         __pSettingLoader = null;
355         delete pGuidePopupTimer;
356         pGuidePopupTimer = null;
357         delete pAutoReadingTimer;
358         pAutoReadingTimer = null;
359 }
360 AccessibilityScreenReaderStatus
361 _AccessibilityManager::GetTtsStatus(void)
362 {
363         if (__pTtsPlayer)
364         {
365                 return __pTtsPlayer->GetStatus();
366         }
367         return ACCESSIBILITY_SCREEN_READER_STATUS_ERROR;
368 }
369 result
370 _AccessibilityManager::ReadContent(const Tizen::Base::String& content)
371 {
372         if (__pTtsPlayer)
373         {
374                 //ShowPopup(content);
375                 __pTtsPlayer->ReadGrammar(content);
376         }
377         return E_SUCCESS;
378 }
379 void
380 _AccessibilityManager::ReadElement(_AccessibilityAutoReadingMode mode)
381 {
382         MakeList();
383         int count = __candidateList.GetCount();
384         if (count < 1)
385         {
386                 return;
387         }
388         _AccessibilityElement* pElement = null;
389         result r = E_SYSTEM;
390
391         if (mode == _ACCESSIBILITY_AUTO_READING_MODE_FIRST_ITEM)
392         {
393                 r = __candidateList.GetAt(0, pElement);
394         }
395         else if (mode == _ACCESSIBILITY_AUTO_READING_MODE_FIRST_ITEM_OF_CONTENTS)
396         {
397                 for (int i = 0 ; i < count ; i++)
398                 {
399                         r = __candidateList.GetAt(i, pElement);
400                         if (r == E_SUCCESS && pElement)
401                         {
402                                 if (pElement->GetParent()->GetPriority() < ACCESSIBILITY_PRIORITY_TOP)
403                                 {
404                                         break;
405                                 }
406                         }
407                 }
408         }
409         else //_ACCESSIBILITY_AUTO_READING_MODE_CURRENT_FOCUS
410         {
411                 if (IsContainerValid(__pTargetContainer))
412                 {
413                         pElement = __pTargetElement;
414                         r = E_SUCCESS;
415                 }
416         }
417         if (r != E_SUCCESS || pElement == null)
418         {
419                 SysLog(NID_UI, "cause 1");
420                 return;
421         }
422         if (mode == _ACCESSIBILITY_AUTO_READING_MODE_FIRST_ITEM && __pTitleElement == pElement && !(__pTitleElement->IsUpdated()))
423         {
424                 SysLog(NID_UI, "cause 2");
425                 return;
426         }
427         __pTitleElement = pElement;
428         DrawFocusUi(*pElement);
429         __pTargetContainer = pElement->GetParent();
430         __pTargetElement = pElement;
431         __targetControlHandle = __pTargetContainer->GetOwner().GetHandle();
432         ReadElement(*pElement);
433 }
434
435 result
436 _AccessibilityManager::ReadElement(const _AccessibilityElement& element)
437 {
438         if (__pTtsPlayer)
439         {
440                 LinkedListT<_IAccessibilityListener*>* pList = static_cast<LinkedListT<_IAccessibilityListener*>*>(__pTargetContainer->GetListenerListN());
441                 if (pList != null)
442                 {
443                         for (int i = 0;i<pList->GetCount();i++)
444                         {
445                                 _IAccessibilityListener* pListener = null;
446                                 if (pList->GetAt(i, pListener) == E_SUCCESS)
447                                 {
448                                         pListener->OnAccessibilityReadingElement(*__pTargetContainer, element);
449                                 }
450                         }
451                         delete pList;
452                         pList = null;
453                 }
454                 //ShowPopup();
455                 __pTtsPlayer->ReadGrammar(element.GetReadingContents());
456         }
457         return E_SUCCESS;
458 }
459 result
460 _AccessibilityManager::ReadingStop(void)
461 {
462         return E_SUCCESS;
463 }
464 result
465 _AccessibilityManager::ReadingPause(void)
466 {
467         return E_SUCCESS;
468 }
469 result
470 _AccessibilityManager::ReadingResume(void)
471 {
472         return E_SUCCESS;
473 }
474
475 void
476 _AccessibilityManager::OnStartReading(const Tizen::Base::String& grammar)
477 {
478 }
479 void
480 _AccessibilityManager::HidePopup(void)
481 {
482         if (__readingPopupParentHandle.IsValid())
483         {
484                 if (__pReadingVe)
485                 {
486                         __pReadingVe->Destroy();
487                         __pReadingVe = null;
488                 }
489         }
490         else
491         {
492                 __pReadingVe = null;
493         }
494         pGuidePopupTimer->Stop();
495 }
496 void
497 _AccessibilityManager::ShowPopup(const String& content)
498 {
499         if (content.IsEmpty())
500         {
501                 return;
502         }
503         utsname sysInfo;
504         uname(&sysInfo);
505         if (String("i686_emulated") != sysInfo.machine)
506         {
507                 return;
508         }
509         Canvas* pCanvas = null;
510         Bitmap* pBgBitmap = null;
511         EnrichedText* pEnrichedTitleText = null;
512         EnrichedText* pText = null;
513         Frame* pFrame = null;
514
515         if (__readingPopupParentHandle.IsValid())
516         {
517                 if (__pReadingVe)
518                 {
519                         __pReadingVe->Destroy();
520                         __pReadingVe = null;
521                 }
522         }
523         else
524         {
525                 __pReadingVe = null;
526         }
527
528         pFrame = UiApp::GetInstance()->GetAppFrame()->GetFrame();
529
530         if (pFrame != null)
531         {
532                 int accesibilityVisualElementLevel = 3000;
533                 result r = E_SUCCESS;
534                 _Window* pWindow = _ControlManager::GetInstance()->GetTopVisibleWindow();
535                 VisualElement* pRootVe = pWindow->GetVisualElement();
536
537                 __pReadingVe = new (std::nothrow) VisualElement();
538                 SysTryCatch(NID_UI, __pReadingVe, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed");
539
540                 r = __pReadingVe->Construct();
541                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] System error");
542                 __pReadingVe->SetName("Accessibility reading popup");
543                 __pReadingVe->SetImplicitAnimationEnabled(false);
544                 _VisualElementImpl::GetInstance(*__pReadingVe)->SetZOrderGroup(accesibilityVisualElementLevel);
545                 pRootVe->AttachChild(*__pReadingVe);
546                 __readingPopupParentHandle = pWindow->GetHandle();
547         }
548
549         if (__pReadingVe)
550         {
551                 result r = E_SUCCESS;
552
553                 float titleFontSize = 0;
554                 float textFontSize = 0;
555                 float popupWidth = 0;
556                 float topMargin = 0;
557                 float bottomMargin = 0;
558                 float sideMargin = 0;
559                 float titleHeight = 0;
560                 float textTopMargin = 0;
561                 float textHeight = 0;
562
563                 Color titleTextColor;
564                 Color pointTextColor;
565                 Color textColor;
566                 TextElement* pElement = null;
567
568                 r = GET_SHAPE_CONFIG(ACCESSIBILITY::TITLE_FONT_SIZE, _CONTROL_ORIENTATION_PORTRAIT, titleFontSize);
569                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
570                 r = GET_SHAPE_CONFIG(ACCESSIBILITY::TEXT_FONT_SIZE, _CONTROL_ORIENTATION_PORTRAIT, textFontSize);
571                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
572                 r = GET_SHAPE_CONFIG(ACCESSIBILITY::POPUP_WIDTH, _CONTROL_ORIENTATION_PORTRAIT, popupWidth);
573                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
574                 r = GET_SHAPE_CONFIG(ACCESSIBILITY::TOP_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, topMargin);
575                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
576                 r = GET_SHAPE_CONFIG(ACCESSIBILITY::BOTTON_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, bottomMargin);
577                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
578                 r = GET_SHAPE_CONFIG(ACCESSIBILITY::SIDE_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, sideMargin);
579                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
580                 r = GET_SHAPE_CONFIG(ACCESSIBILITY::TITLE_HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, titleHeight);
581                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
582                 r = GET_SHAPE_CONFIG(ACCESSIBILITY::TEXT_TOP_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, textTopMargin);
583                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
584                 r = GET_SHAPE_CONFIG(ACCESSIBILITY::TEXT_HEGIHT, _CONTROL_ORIENTATION_PORTRAIT, textHeight);
585                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
586                 r = GET_COLOR_CONFIG(ACCESSIBILITY::TITLE_TEXT, titleTextColor);
587                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
588                 r = GET_COLOR_CONFIG(ACCESSIBILITY::POINT_TEXT, pointTextColor);
589                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
590                 r = GET_COLOR_CONFIG(ACCESSIBILITY::TEXT, textColor);
591                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
592                 r = GET_BITMAP_CONFIG_N(ACCESSIBILITY::POPUP_BG, BITMAP_PIXEL_FORMAT_ARGB8888, pBgBitmap);
593                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
594
595                 Font titleFont;
596                 r = titleFont.Construct(FONT_STYLE_PLAIN, titleFontSize);
597                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
598                 Font textFont;
599                 r = textFont.Construct(FONT_STYLE_PLAIN, textFontSize);
600                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
601
602                 pEnrichedTitleText = new (std::nothrow) EnrichedText;
603                 SysTryCatch(NID_UI, pEnrichedTitleText != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed");
604                 pEnrichedTitleText->Construct(FloatDimension(popupWidth-sideMargin*2, titleHeight));
605
606                 pText = new (std::nothrow) EnrichedText;
607                 SysTryCatch(NID_UI, pText != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed");
608                 pText->Construct(FloatDimension(popupWidth-sideMargin*2, textHeight));
609
610                 pElement = new (std::nothrow) TextElement;
611                 SysTryCatch(NID_UI, pElement != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed");
612                 r = pElement->Construct(L"Screen reading...");
613                 if (r != E_SUCCESS)
614                 {
615                         delete pElement;
616                         goto CATCH;
617                 }
618                 pElement->SetTextColor(titleTextColor);
619                 pElement->SetFont(titleFont);
620                 r = pEnrichedTitleText->Add(*pElement);
621                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
622                 pEnrichedTitleText->SetHorizontalAlignment(TEXT_ALIGNMENT_LEFT);
623                 pEnrichedTitleText->SetVerticalAlignment(TEXT_ALIGNMENT_TOP);
624                 pEnrichedTitleText->SetTextWrapStyle(TEXT_WRAP_CHARACTER_WRAP);
625                 pEnrichedTitleText->SetTextAbbreviationEnabled(true);
626
627                 pElement = new (std::nothrow) TextElement;
628                 SysTryCatch(NID_UI, pElement != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed");
629                 r = pElement->Construct(content);
630                 if (r != E_SUCCESS)
631                 {
632                         delete pElement;
633                         goto CATCH;
634                 }
635                 pElement->SetTextColor(textColor);
636                 pElement->SetFont(textFont);
637                 r = pText->Add(*pElement);
638                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
639                 pText->SetHorizontalAlignment(TEXT_ALIGNMENT_LEFT);
640                 pText->SetVerticalAlignment(TEXT_ALIGNMENT_TOP);
641                 pText->SetTextWrapStyle(TEXT_WRAP_CHARACTER_WRAP);
642                 pText->SetTextAbbreviationEnabled(true);
643
644                 float x = 40;
645                 float y = 200;
646                 float popupHeight = topMargin + bottomMargin + titleHeight + textTopMargin + textHeight;
647
648                 FloatDimension screen = Tizen::Ui::_ControlManager::GetInstance()->GetScreenSizeF();
649                 __pReadingVe->SetBounds(FloatRectangle(x, y, popupWidth, popupHeight));
650                 pCanvas = __pReadingVe->GetCanvasN();
651                 SysTryCatch(NID_UI, pCanvas != null, , E_SYSTEM, "System error for accessibility popup");
652                 pCanvas->DrawNinePatchedBitmap(FloatRectangle(0, 0, popupWidth, popupHeight), *pBgBitmap);
653                 float drawingTextY = topMargin;
654                 pCanvas->DrawText(FloatPoint(sideMargin, drawingTextY), *pEnrichedTitleText);
655                 drawingTextY += textTopMargin + titleHeight;
656                 pCanvas->DrawText(FloatPoint(sideMargin, drawingTextY), *pText);
657                 __pReadingVe->SetShowState(true);
658                 __pReadingVe->SetFlushNeeded();
659                 pGuidePopupTimer->SetElement(__pReadingVe);
660
661         }
662 CATCH:
663         delete pCanvas;
664         pCanvas = null;
665         delete pBgBitmap;
666         pBgBitmap = null;
667         if (pEnrichedTitleText)
668         {
669                 pEnrichedTitleText->RemoveAll(true);
670                 delete pEnrichedTitleText;
671         }
672         if (pText)
673         {
674                 pText->RemoveAll(true);
675                 delete pText;
676         }
677
678         return;
679
680 }
681 void
682 _AccessibilityManager::ShowPopup()
683 {
684         if (__pTargetElement == null)
685         {
686                 return;
687         }
688         utsname sysInfo;
689         uname(&sysInfo);
690         Frame* pFrame = null;
691         Canvas* pCanvas = null;
692         Bitmap* pBgBitmap = null;
693         EnrichedText* pEnrichedTitleText = null;
694         EnrichedText* pEnrichedNameText = null;
695         EnrichedText* pEnrichedLableText = null;
696         EnrichedText* pEnrichedTraitText = null;
697         EnrichedText* pEnrichedStatusText = null;
698         EnrichedText* pEnrichedHintText = null;
699         EnrichedText* pEnrichedValueText = null;
700         EnrichedText* pEnrichedBoundsText = null;
701         EnrichedText* pEnrichedAbsBoundsText = null;
702         TextElement* pElement = null;
703         FloatDimension screen;
704
705         if (String("i686_emulated") != sysInfo.machine)
706         {
707                 return;
708         }
709
710         if (__readingPopupParentHandle.IsValid())
711         {
712                 if (__pReadingVe)
713                 {
714                         __pReadingVe->Destroy();
715                         __pReadingVe = null;
716                 }
717         }
718         else
719         {
720                 __pReadingVe = null;
721         }
722
723         pFrame = UiApp::GetInstance()->GetAppFrame()->GetFrame();
724
725         if (pFrame != null)
726         {
727                 int accesibilityVisualElementLevel = 3000;
728                 result r = E_SUCCESS;
729                 _Window* pWindow = _ControlManager::GetInstance()->GetTopVisibleWindow();
730                 VisualElement* pRootVe = pWindow->GetVisualElement();
731                 __readingPopupParentHandle = pWindow->GetHandle();
732                 __pReadingVe = new (std::nothrow) VisualElement();
733                 SysTryCatch(NID_UI, __pReadingVe, , E_SYSTEM, "[E_SYSTEM] System error");
734
735                 r = __pReadingVe->Construct();
736                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] System error");
737                 __pReadingVe->SetName("Accessibility reading popup");
738                 __pReadingVe->SetImplicitAnimationEnabled(false);
739                 _VisualElementImpl::GetInstance(*__pReadingVe)->SetZOrderGroup(accesibilityVisualElementLevel);
740                 pRootVe->AttachChild(*__pReadingVe);
741         }
742
743         screen = _ControlManager::GetInstance()->GetScreenSizeF();
744         if (__pReadingVe)
745         {
746                 result r = E_SUCCESS;
747
748                 float titleFontSize = 0;
749                 float textFontSize = 0;
750                 float popupWidth = 0;
751                 float topMargin = 0;
752                 float bottomMargin = 0;
753                 float sideMargin = 0;
754                 float titleHeight = 0;
755                 float textTopMargin = 0;
756                 float textHeight = 0;
757
758                 Color titleTextColor;
759                 Color pointTextColor;
760                 Color textColor;
761
762                 r = GET_SHAPE_CONFIG(ACCESSIBILITY::TITLE_FONT_SIZE, _CONTROL_ORIENTATION_PORTRAIT, titleFontSize);
763                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
764                 r = GET_SHAPE_CONFIG(ACCESSIBILITY::TEXT_FONT_SIZE, _CONTROL_ORIENTATION_PORTRAIT, textFontSize);
765                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
766                 r = GET_SHAPE_CONFIG(ACCESSIBILITY::POPUP_WIDTH, _CONTROL_ORIENTATION_PORTRAIT, popupWidth);
767                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
768                 r = GET_SHAPE_CONFIG(ACCESSIBILITY::TOP_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, topMargin);
769                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
770                 r = GET_SHAPE_CONFIG(ACCESSIBILITY::BOTTON_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, bottomMargin);
771                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
772                 r = GET_SHAPE_CONFIG(ACCESSIBILITY::SIDE_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, sideMargin);
773                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
774                 r = GET_SHAPE_CONFIG(ACCESSIBILITY::TITLE_HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, titleHeight);
775                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
776                 r = GET_SHAPE_CONFIG(ACCESSIBILITY::TEXT_TOP_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, textTopMargin);
777                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
778                 r = GET_SHAPE_CONFIG(ACCESSIBILITY::TEXT_HEGIHT, _CONTROL_ORIENTATION_PORTRAIT, textHeight);
779                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
780                 r = GET_COLOR_CONFIG(ACCESSIBILITY::TITLE_TEXT, titleTextColor);
781                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
782                 r = GET_COLOR_CONFIG(ACCESSIBILITY::POINT_TEXT, pointTextColor);
783                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
784                 r = GET_COLOR_CONFIG(ACCESSIBILITY::TEXT, textColor);
785                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
786                 r = GET_BITMAP_CONFIG_N(ACCESSIBILITY::POPUP_BG, BITMAP_PIXEL_FORMAT_ARGB8888, pBgBitmap);
787                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
788
789                 Font titleFont;
790                 r = titleFont.Construct(FONT_STYLE_PLAIN, titleFontSize);
791                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
792
793                 Font textFont;
794                 r = textFont.Construct(FONT_STYLE_PLAIN, textFontSize);
795                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
796
797                 pEnrichedTitleText = new (std::nothrow) EnrichedText;
798                 SysTryCatch(NID_UI, pEnrichedTitleText != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed");
799                 pEnrichedTitleText->Construct(FloatDimension(popupWidth-sideMargin*2, titleHeight));
800
801                 pEnrichedNameText = new (std::nothrow) EnrichedText;
802                 SysTryCatch(NID_UI, pEnrichedNameText != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed");
803                 pEnrichedNameText->Construct(FloatDimension(popupWidth-sideMargin*2, textHeight));
804
805                 pEnrichedLableText = new (std::nothrow) EnrichedText;
806                 SysTryCatch(NID_UI, pEnrichedLableText != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed");
807                 pEnrichedLableText->Construct(FloatDimension(popupWidth-sideMargin*2, textHeight));
808
809                 pEnrichedTraitText = new (std::nothrow) EnrichedText;
810                 SysTryCatch(NID_UI, pEnrichedTraitText != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed.");
811                 pEnrichedTraitText->Construct(FloatDimension(popupWidth-sideMargin*2, textHeight));
812
813                 pEnrichedStatusText = new (std::nothrow) EnrichedText;
814                 SysTryCatch(NID_UI, pEnrichedStatusText != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed.");
815                 pEnrichedStatusText->Construct(FloatDimension(popupWidth-sideMargin*2, textHeight));
816
817                 pEnrichedHintText = new (std::nothrow) EnrichedText;
818                 SysTryCatch(NID_UI, pEnrichedHintText != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed.");
819                 pEnrichedHintText->Construct(FloatDimension(popupWidth-sideMargin*2, textHeight));
820
821                 pEnrichedValueText = new (std::nothrow) EnrichedText;
822                 SysTryCatch(NID_UI, pEnrichedValueText != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed.");
823                 pEnrichedValueText->Construct(FloatDimension(popupWidth-sideMargin*2, textHeight));
824
825                 pEnrichedBoundsText = new (std::nothrow) EnrichedText;
826                 SysTryCatch(NID_UI, pEnrichedBoundsText != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed.");
827                 pEnrichedBoundsText->Construct(FloatDimension(popupWidth-sideMargin*2, textHeight));
828
829                 pEnrichedAbsBoundsText = new (std::nothrow) EnrichedText;
830                 SysTryCatch(NID_UI, pEnrichedAbsBoundsText != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed.");
831                 pEnrichedAbsBoundsText->Construct(FloatDimension(popupWidth-sideMargin*2, textHeight));
832
833                 pElement = new (std::nothrow) TextElement;
834                 r = pElement->Construct(L"Screen reading...");
835                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
836                 pElement->SetTextColor(titleTextColor);
837                 pElement->SetFont(titleFont);
838                 r = pEnrichedTitleText->Add(*pElement);
839
840                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
841                 pEnrichedTitleText->SetHorizontalAlignment(TEXT_ALIGNMENT_LEFT);
842                 pEnrichedTitleText->SetVerticalAlignment(TEXT_ALIGNMENT_TOP);
843                 pEnrichedTitleText->SetTextWrapStyle(TEXT_WRAP_CHARACTER_WRAP);
844                 pEnrichedTitleText->SetTextAbbreviationEnabled(true);
845
846                 pElement  = new (std::nothrow) TextElement;
847                 r = pElement->Construct(L"Name: ");
848                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
849
850                 pElement->SetTextColor(pointTextColor);
851                 pElement->SetFont(textFont);
852                 r = pEnrichedNameText->Add(*pElement);
853                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
854
855                 if (!(__pTargetElement->GetName().IsEmpty()))
856                 {
857                         pElement  = new (std::nothrow) TextElement;
858                         r = pElement->Construct(__pTargetElement->GetName());
859                         SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
860
861                         pElement->SetTextColor(textColor);
862                         pElement->SetFont(textFont);
863                         r = pEnrichedNameText->Add(*pElement);
864                         SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
865                         SysLog(NID_UI, " Name :::::: %s", _StringConverter::CopyToCharArrayN(__pTargetElement->GetName()));
866                 }
867                 pEnrichedNameText->SetHorizontalAlignment(TEXT_ALIGNMENT_LEFT);
868                 pEnrichedNameText->SetVerticalAlignment(TEXT_ALIGNMENT_TOP);
869                 pEnrichedNameText->SetTextWrapStyle(TEXT_WRAP_CHARACTER_WRAP);
870                 pEnrichedNameText->SetTextAbbreviationEnabled(true);
871
872                 pElement  = new (std::nothrow) TextElement;
873                 SysTryCatch(NID_UI, pElement != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed");
874                 r = pElement->Construct(L"Label: ");
875                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
876
877                 pElement->SetTextColor(pointTextColor);
878                 pElement->SetFont(textFont);
879                 r = pEnrichedLableText->Add(*pElement);
880                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
881
882                 if (!(__pTargetElement->GetLabel().IsEmpty()))
883                 {
884                         pElement  = new (std::nothrow) TextElement;
885                         SysTryCatch(NID_UI, pElement != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed");
886                         r = pElement->Construct(__pTargetElement->GetLabel());
887                         SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
888
889                         pElement->SetTextColor(textColor);
890                         pElement->SetFont(textFont);
891                         r = pEnrichedLableText->Add(*pElement);
892                         SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
893                         SysLog(NID_UI, " Label :::::: %s", _StringConverter::CopyToCharArrayN(__pTargetElement->GetLabel()));
894                 }
895                 pEnrichedLableText->SetHorizontalAlignment(TEXT_ALIGNMENT_LEFT);
896                 pEnrichedLableText->SetVerticalAlignment(TEXT_ALIGNMENT_TOP);
897                 pEnrichedLableText->SetTextWrapStyle(TEXT_WRAP_CHARACTER_WRAP);
898                 pEnrichedLableText->SetTextAbbreviationEnabled(true);
899
900                 pElement  = new (std::nothrow) TextElement;
901                 SysTryCatch(NID_UI, pElement != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed");
902                 r = pElement->Construct(L"Trait: ");
903                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
904
905                 pElement->SetTextColor(pointTextColor);
906                 pElement->SetFont(textFont);
907                 r = pEnrichedTraitText->Add(*pElement);
908                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
909                 if (!(__pTargetElement->GetTraitString().IsEmpty()))
910                 {
911                         pElement  = new (std::nothrow) TextElement;
912                         SysTryCatch(NID_UI, pElement != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed");
913                         r = pElement->Construct(__pTargetElement->GetTraitString());
914                         SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
915
916                         pElement->SetTextColor(textColor);
917                         pElement->SetFont(textFont);
918                         r = pEnrichedTraitText->Add(*pElement);
919                         SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
920                 }
921                 pEnrichedTraitText->SetHorizontalAlignment(TEXT_ALIGNMENT_LEFT);
922                 pEnrichedTraitText->SetVerticalAlignment(TEXT_ALIGNMENT_TOP);
923                 pEnrichedTraitText->SetTextWrapStyle(TEXT_WRAP_CHARACTER_WRAP);
924                 pEnrichedTraitText->SetTextAbbreviationEnabled(true);
925
926                 pElement  = new (std::nothrow) TextElement;
927                 SysTryCatch(NID_UI, pElement != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed");
928                 r = pElement->Construct(L"Status: ");
929                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
930
931                 pElement->SetTextColor(pointTextColor);
932                 pElement->SetFont(textFont);
933                 r = pEnrichedStatusText->Add(*pElement);
934                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
935                 if (!(__pTargetElement->GetStatus().IsEmpty()))
936                 {
937                         pElement  = new (std::nothrow) TextElement;
938                         SysTryCatch(NID_UI, pElement != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed");
939                         r = pElement->Construct(__pTargetElement->GetStatus());
940                         SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
941
942                         pElement->SetTextColor(textColor);
943                         pElement->SetFont(textFont);
944                         r = pEnrichedStatusText->Add(*pElement);
945                         SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
946                 }
947                 pEnrichedStatusText->SetHorizontalAlignment(TEXT_ALIGNMENT_LEFT);
948                 pEnrichedStatusText->SetVerticalAlignment(TEXT_ALIGNMENT_TOP);
949                 pEnrichedStatusText->SetTextWrapStyle(TEXT_WRAP_CHARACTER_WRAP);
950                 pEnrichedStatusText->SetTextAbbreviationEnabled(true);
951
952                 pElement  = new (std::nothrow) TextElement;
953                 SysTryCatch(NID_UI, pElement != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed");
954                 r = pElement->Construct(L"Hint: ");
955                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
956
957                 pElement->SetTextColor(pointTextColor);
958                 pElement->SetFont(textFont);
959                 r = pEnrichedHintText->Add(*pElement);
960                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
961                 if (!(__pTargetElement->GetHint().IsEmpty()))
962                 {
963                         pElement  = new (std::nothrow) TextElement;
964                         SysTryCatch(NID_UI, pElement != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed");
965                         r = pElement->Construct(__pTargetElement->GetHint());
966                         SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
967
968                         pElement->SetTextColor(textColor);
969                         pElement->SetFont(textFont);
970                         r = pEnrichedHintText->Add(*pElement);
971                         SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
972                 }
973                 pEnrichedHintText->SetHorizontalAlignment(TEXT_ALIGNMENT_LEFT);
974                 pEnrichedHintText->SetVerticalAlignment(TEXT_ALIGNMENT_TOP);
975                 pEnrichedHintText->SetTextWrapStyle(TEXT_WRAP_CHARACTER_WRAP);
976                 pEnrichedHintText->SetTextAbbreviationEnabled(true);
977
978                 pElement  = new (std::nothrow) TextElement;
979                 SysTryCatch(NID_UI, pElement != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed");
980                 r = pElement->Construct(L"Value: ");
981                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
982
983                 pElement->SetTextColor(pointTextColor);
984                 pElement->SetFont(textFont);
985                 r = pEnrichedValueText->Add(*pElement);
986                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
987                 if (!(__pTargetElement->GetValue().IsEmpty()))
988                 {
989                         pElement  = new (std::nothrow) TextElement;
990                         SysTryCatch(NID_UI, pElement != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed");
991                         r = pElement->Construct(__pTargetElement->GetValue());
992                         SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
993
994                         pElement->SetTextColor(textColor);
995                         pElement->SetFont(textFont);
996                         r = pEnrichedValueText->Add(*pElement);
997                         SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
998                 }
999                 pEnrichedValueText->SetHorizontalAlignment(TEXT_ALIGNMENT_LEFT);
1000                 pEnrichedValueText->SetVerticalAlignment(TEXT_ALIGNMENT_TOP);
1001                 pEnrichedValueText->SetTextWrapStyle(TEXT_WRAP_CHARACTER_WRAP);
1002                 pEnrichedValueText->SetTextAbbreviationEnabled(true);
1003
1004                 pElement  = new (std::nothrow) TextElement;
1005                 SysTryCatch(NID_UI, pElement != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed");
1006                 r = pElement->Construct(L"Bound: ");
1007                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
1008
1009                 pElement->SetTextColor(pointTextColor);
1010                 pElement->SetFont(textFont);
1011                 r = pEnrichedBoundsText->Add(*pElement);
1012                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
1013
1014                 pElement  = new (std::nothrow) TextElement;
1015                 SysTryCatch(NID_UI, pElement != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed");
1016                 FloatRectangle rect = __pTargetElement->GetBounds();
1017                 String rectString;
1018                 rectString.Format(40, L"x:%.1f, y:%.1f, w:%.1f, h:%.1f", rect.x, rect.y, rect.width, rect.height);
1019                 r = pElement->Construct(rectString);
1020                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
1021
1022                 pElement->SetTextColor(textColor);
1023                 pElement->SetFont(textFont);
1024                 r = pEnrichedBoundsText->Add(*pElement);
1025                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
1026                 pEnrichedBoundsText->SetHorizontalAlignment(TEXT_ALIGNMENT_LEFT);
1027                 pEnrichedBoundsText->SetVerticalAlignment(TEXT_ALIGNMENT_TOP);
1028                 pEnrichedBoundsText->SetTextWrapStyle(TEXT_WRAP_CHARACTER_WRAP);
1029                 pEnrichedBoundsText->SetTextAbbreviationEnabled(true);
1030
1031                 pElement  = new (std::nothrow) TextElement;
1032                 SysTryCatch(NID_UI, pElement != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed");
1033                 r = pElement->Construct(L"AbsBound: ");
1034                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
1035
1036                 pElement->SetTextColor(pointTextColor);
1037                 pElement->SetFont(textFont);
1038                 r = pEnrichedAbsBoundsText->Add(*pElement);
1039                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
1040
1041                 pElement  = new (std::nothrow) TextElement;
1042                 SysTryCatch(NID_UI, pElement != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed");
1043                 rect = __pTargetElement->GetAbsoluteBounds();
1044                 rectString.Clear();
1045                 rectString.Format(40, L"x:%.1f, y:%.1f, w:%.1f, h:%.1f", rect.x, rect.y, rect.width, rect.height);
1046                 r = pElement->Construct(rectString);
1047                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
1048
1049                 pElement->SetTextColor(textColor);
1050                 pElement->SetFont(textFont);
1051                 r = pEnrichedAbsBoundsText->Add(*pElement);
1052                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
1053                 pEnrichedAbsBoundsText->SetHorizontalAlignment(TEXT_ALIGNMENT_LEFT);
1054                 pEnrichedAbsBoundsText->SetVerticalAlignment(TEXT_ALIGNMENT_TOP);
1055                 pEnrichedAbsBoundsText->SetTextWrapStyle(TEXT_WRAP_CHARACTER_WRAP);
1056                 pEnrichedAbsBoundsText->SetTextAbbreviationEnabled(true);
1057
1058                 float x = 0;
1059                 float y = 0;
1060                 float popupHeight = topMargin + bottomMargin + titleHeight + textTopMargin + textHeight * 8;
1061                 Frame* pFrame = UiApp::GetInstance()->GetAppFrame()->GetFrame();
1062                 Form* pForm = pFrame->GetCurrentForm();
1063                 FloatDimension screen = Tizen::Ui::_ControlManager::GetInstance()->GetScreenSizeF();
1064
1065                 if (pForm->GetOrientationStatus() == ORIENTATION_STATUS_PORTRAIT
1066                         || pForm->GetOrientationStatus() == ORIENTATION_STATUS_PORTRAIT_REVERSE)
1067                 {
1068                         x = (screen.width-popupWidth) / 2;
1069                         if (rect.y < screen.height/2)
1070                         {
1071                                 y = (screen.height/2 - popupHeight) /2 + screen.height/2;
1072                         }
1073                         else
1074                         {
1075                                 y = (screen.height/2 - popupHeight) /2;
1076                         }
1077                 }
1078                 else
1079                 {
1080                         y = (screen.width-popupHeight) / 2;
1081                         if (rect.x < screen.height/2)
1082                         {
1083                                 x = (screen.height/2 - popupWidth) /2 + screen.height/2;
1084                         }
1085                         else
1086                         {
1087                                 x = (screen.height/2 - popupWidth) /2;
1088                         }
1089                 }
1090
1091                 __pReadingVe->SetBounds(FloatRectangle(x, y, popupWidth, popupHeight));
1092                 pCanvas = __pReadingVe->GetCanvasN();
1093                 SysTryCatch(NID_UI, pCanvas != null, , E_SYSTEM, "System error for accessibility popup");
1094                 pCanvas->DrawNinePatchedBitmap(FloatRectangle(0, 0, popupWidth, popupHeight), *pBgBitmap);
1095                 float drawingTextY = topMargin;
1096                 pCanvas->DrawText(FloatPoint(sideMargin, drawingTextY), *pEnrichedTitleText);
1097                 drawingTextY += textTopMargin + titleHeight;
1098                 pCanvas->DrawText(FloatPoint(sideMargin, drawingTextY), *pEnrichedNameText);
1099                 drawingTextY += textHeight;
1100                 pCanvas->DrawText(FloatPoint(sideMargin, drawingTextY), *pEnrichedLableText);
1101                 drawingTextY += textHeight;
1102                 pCanvas->DrawText(FloatPoint(sideMargin, drawingTextY), *pEnrichedTraitText);
1103                 drawingTextY += textHeight;
1104                 pCanvas->DrawText(FloatPoint(sideMargin, drawingTextY), *pEnrichedStatusText);
1105                 drawingTextY += textHeight;
1106                 pCanvas->DrawText(FloatPoint(sideMargin, drawingTextY), *pEnrichedHintText);
1107                 drawingTextY += textHeight;
1108                 pCanvas->DrawText(FloatPoint(sideMargin, drawingTextY), *pEnrichedValueText);
1109                 drawingTextY += textHeight;
1110                 pCanvas->DrawText(FloatPoint(sideMargin, drawingTextY), *pEnrichedBoundsText);
1111                 drawingTextY += textHeight;
1112                 pCanvas->DrawText(FloatPoint(sideMargin, drawingTextY), *pEnrichedAbsBoundsText);
1113                 __pReadingVe->SetShowState(true);
1114                 __pReadingVe->SetFlushNeeded();
1115                 pGuidePopupTimer->SetElement(__pReadingVe);
1116
1117         }
1118         //go through
1119 CATCH:
1120         delete pCanvas;
1121         pCanvas = null;
1122         delete pBgBitmap;
1123         pBgBitmap = null;
1124         if (pEnrichedTitleText)
1125         {
1126                 pEnrichedTitleText->RemoveAll(true);
1127                 delete pEnrichedTitleText;
1128         }
1129         if (pEnrichedNameText)
1130         {
1131                 pEnrichedNameText->RemoveAll(true);
1132                 delete pEnrichedNameText;
1133         }
1134         if (pEnrichedLableText)
1135         {
1136                 pEnrichedLableText->RemoveAll(true);
1137                 delete pEnrichedLableText;
1138         }
1139         if (pEnrichedTraitText)
1140         {
1141                 pEnrichedTraitText->RemoveAll(true);
1142                 delete pEnrichedTraitText;
1143         }
1144         if (pEnrichedStatusText)
1145         {
1146                 pEnrichedStatusText->RemoveAll(true);
1147                 delete pEnrichedStatusText;
1148         }
1149         if (pEnrichedHintText)
1150         {
1151                 pEnrichedHintText->RemoveAll(true);
1152                 delete pEnrichedHintText;
1153         }
1154         if (pEnrichedValueText)
1155         {
1156                 pEnrichedValueText->RemoveAll(true);
1157                 delete pEnrichedValueText;
1158         }
1159         if (pEnrichedBoundsText)
1160         {
1161                 pEnrichedBoundsText->RemoveAll(true);
1162                 delete pEnrichedBoundsText;
1163         }
1164         if (pEnrichedAbsBoundsText)
1165         {
1166                 pEnrichedAbsBoundsText->RemoveAll(true);
1167                 delete pEnrichedAbsBoundsText;
1168         }
1169
1170         return;
1171 }
1172
1173 void
1174 _AccessibilityManager::OnFinishReading(const Tizen::Base::String& grammar)
1175 {
1176 //      HidePopup();
1177         if (!IsContainerValid(__pTargetContainer))
1178         {
1179                 return;
1180         }
1181         LinkedListT<_IAccessibilityListener*>* pList = static_cast<LinkedListT<_IAccessibilityListener*>*>(__pTargetContainer->GetListenerListN());
1182         if (pList != null)
1183         {
1184                 for (int i = 0;i<pList->GetCount();i++)
1185                 {
1186                         _IAccessibilityListener* pListener = null;
1187                         if (pList->GetAt(i, pListener) == E_SUCCESS)
1188                         {
1189                                 if (__pTargetElement)
1190                                 {
1191                                         pListener->OnAccessibilityReadElement(*__pTargetContainer, *__pTargetElement);
1192                                 }
1193                         }
1194                 }
1195                 delete pList;
1196                 pList = null;
1197         }
1198         return;
1199 }
1200
1201 String
1202 _AccessibilityManager::GetCurrentGrammar(void)
1203 {
1204         return L"";
1205 }
1206 void
1207 _AccessibilityManager::AddContainer(const _AccessibilityContainer& container)
1208 {
1209         __containerList.Add(&const_cast<_AccessibilityContainer&>(container));
1210         if(__mode == MODE_FOCUS_MOVE)
1211         {
1212                 SetGestureMode(MODE_TAP);
1213         }
1214         return;
1215 }
1216 void
1217 _AccessibilityManager::RemoveContainer(const _AccessibilityContainer& container)
1218 {
1219         __containerList.Remove(&const_cast<_AccessibilityContainer&>(container));
1220         if(__mode == MODE_FOCUS_MOVE)
1221         {
1222                 SetGestureMode(MODE_TAP);
1223         }
1224         if (__pTargetContainer == &container)
1225         {
1226                 __pTargetContainer = null;
1227                 __pTargetElement = null;
1228         }
1229         return;
1230 }
1231
1232 void
1233 _AccessibilityManager::MakeList(void)
1234 {
1235         struct DownVisitor
1236         {
1237                 DownVisitor(_Control& control, LinkedListT<_Control*>& list)
1238                 {
1239                         LinkedListT<_Control*> _list;
1240                         int count = control.GetChildCount();
1241                         _Control* pControl = null;
1242                         for (int i = 0; i < count ; i++)
1243                         {
1244                                 pControl = control.GetChild(i);
1245                                 if (pControl)
1246                                 {
1247                                         _list.Add(pControl);
1248                                 }
1249                         }
1250                         _AccessibilityItemComparer<_Control*> comparer;
1251                         _list.Sort(comparer);
1252                         int index = 0;
1253                         list.IndexOf(&control, index);
1254                         list.InsertItemsFrom(_list,index+1);
1255                         for (int i = 0; i < count ; i++)
1256                         {
1257                                 pControl = control.GetChild(i);
1258                                 DownVisitor(*pControl, list);
1259                         }
1260                 }
1261         };
1262         if ( !__needRefreshItem && GetGestureMode() == MODE_FOCUS_MOVE)
1263         {
1264                 __needRefreshItem = false;
1265                 return;
1266         }
1267         __needRefreshItem = false;
1268         result r = E_SUCCESS;
1269         int count = 0;
1270         _Control* pControl = null;
1271         _AccessibilityContainer* pContainer = null;
1272         _TouchManager* pTouchManager = _TouchManager::GetInstance();
1273         LinkedListT<_Control*> controlList;
1274         LinkedListT<_AccessibilityElement*> elementPositionList;
1275         LinkedListT<_AccessibilityElement*> elementPositionByControlList;
1276         __candidateList.RemoveAll();
1277
1278         if (pTouchManager)
1279         {
1280                 pControl = pTouchManager->GetCapturedControl();
1281                 if (pControl)
1282                 {
1283                         controlList.Add(pControl);
1284                 }
1285         }
1286
1287         if (pControl == null)
1288         {
1289                 pControl = static_cast<_Control*>(_ControlManager::GetInstance()->GetWindow(_ControlManager::GetInstance()->GetWindowCount() - 1));
1290                 controlList.Add(pControl);
1291         }
1292         DownVisitor(*pControl, controlList);
1293         count = controlList.GetCount();
1294         Dimension screen = _ResourceManager::GetInstance()->GetLogicalScreenSizen();
1295         int margin = _ControlManager::GetInstance()->GetOrientation() == _CONTROL_ORIENTATION_PORTRAIT ? screen.width : screen.height;
1296
1297         for(int i = 0 ; i < count ; i++)
1298         {
1299                 if (controlList.GetAt(i, pControl) == E_SUCCESS)
1300                 {
1301                         FloatRectangle rect = pControl->GetAbsoluteBoundsF();
1302                         if (rect.x + rect.width <= 0.0f || (rect.x) >= margin)
1303                         {
1304                                 bool inside = false;
1305                                 _Control* _pControl = pControl;
1306                                 while(_pControl)
1307                                 {
1308                                         if(dynamic_cast<_IScrollableContainer*>(_pControl))
1309                                         {
1310                                                 if (rect.x + rect.width > 0.0f && (rect.x) < margin)
1311                                                 {
1312                                                         inside = true;
1313                                                         break;
1314                                                 }
1315                                         }
1316                                         _pControl = _pControl->GetParent();
1317                                 }
1318                                 if(!inside)
1319                                 {
1320                                         _AccessibilityContainer* pContainer = pControl->GetAccessibilityContainer()->GetRootParent();
1321                                         if(pContainer != null)
1322                                         {
1323                                                 rect = pContainer->GetAbsoluteBounds();
1324                                                 if (rect.x + rect.width > 0.0f && (rect.x) < margin)
1325                                                 {
1326                                                         inside = true;
1327                                                 }
1328                                         }
1329                                 }
1330                                 if(!inside)
1331                                 {
1332                                         controlList.Remove(pControl);
1333                                         i--;
1334                                         count--;
1335                                 }
1336                         }
1337                 }
1338         }
1339         for (int i = 0; i < controlList.GetCount() ; i++)
1340         {
1341                 if (controlList.GetAt(i, pControl) == E_SUCCESS)
1342                 {
1343                         pContainer = pControl->GetAccessibilityContainer();
1344                         if (pContainer == null)
1345                         {
1346                                 continue;
1347                         }
1348                         if (IsContainerValid(pContainer))
1349                         {
1350                                 pContainer->SortElements();
1351                                 pContainer->GetElements(elementPositionList);
1352                                 pContainer->GetElements(elementPositionByControlList);
1353                         }
1354                 }
1355         }
1356         bool done = false;
1357         _ElementComparer<_AccessibilityElement*> comparer;
1358         elementPositionList.Sort(comparer);
1359         count = elementPositionList.GetCount();
1360         int index = 0;
1361         _AccessibilityElement* pPositionListElement = null;
1362         _AccessibilityElement* pPositionByControlListElement = null;
1363         while (!done && index < count && index < count)
1364         {
1365                 Rectangle rect;
1366                 r = elementPositionList.GetAt(index, pPositionListElement);
1367                 if (r != E_SUCCESS)
1368                 {
1369                         index++;
1370                         continue;
1371                 }
1372
1373                 r = elementPositionByControlList.GetAt(index, pPositionByControlListElement);
1374                 if (r != E_SUCCESS)
1375                 {
1376                         index++;
1377                         continue;
1378                 }
1379
1380                 if (pPositionListElement == pPositionByControlListElement)
1381                 {
1382                         __candidateList.Add(pPositionByControlListElement);
1383                         index++;
1384                         continue;
1385                 }
1386
1387                 if (pPositionListElement->GetParent()->GetPriority() > pPositionByControlListElement->GetParent()->GetPriority())
1388                 {
1389                         elementPositionByControlList.Remove(pPositionListElement);
1390                         elementPositionByControlList.InsertAt(pPositionListElement, index);
1391                         __candidateList.Add(pPositionListElement);
1392                         index++;
1393                         continue;
1394                 }
1395                 else if (pPositionListElement->GetParent()->GetPriority() < pPositionByControlListElement->GetParent()->GetPriority())
1396                 {
1397                         elementPositionList.Remove(pPositionByControlListElement);
1398                         elementPositionList.InsertAt(pPositionByControlListElement, index);
1399                         __candidateList.Add(pPositionByControlListElement);
1400                         index++;
1401                         continue;
1402                 }
1403
1404                 if (pPositionListElement->GetAbsoluteBounds().y > pPositionByControlListElement->GetAbsoluteBounds().y)
1405                 {
1406                         elementPositionList.Remove(pPositionByControlListElement);
1407                         elementPositionList.InsertAt(pPositionByControlListElement, index);
1408                         __candidateList.Add(pPositionByControlListElement);
1409                         index++;
1410                         continue;
1411                 }
1412                 else if (pPositionListElement->GetAbsoluteBounds().y < pPositionByControlListElement->GetAbsoluteBounds().y)
1413                 {
1414                         pControl = &(pPositionByControlListElement->GetParent()->GetOwner());
1415                         while (pControl)
1416                         {
1417                                 rect = pControl->GetAbsoluteBounds();
1418                                 if (rect.y >0)
1419                                 {
1420                                         break;
1421                                 }
1422                                 else
1423                                 {
1424                                         if(pControl->GetParent())
1425                                         {
1426                                                 pControl = pControl->GetParent();
1427                                         }
1428                                         else
1429                                         {
1430                                                 break;
1431                                         }
1432                                 }
1433                         }
1434                         if (pControl)
1435                         {
1436                                 controlList.RemoveAll();
1437                                 controlList.Add(pControl);
1438                                 DownVisitor(*pControl, controlList);
1439                                 int _count = controlList.GetCount();
1440                                 LinkedListT<_AccessibilityElement*> _elementPositionList;
1441                                 for (int i = 0; i < _count ; i++)
1442                                 {
1443                                         if (controlList.GetAt(i, pControl) == E_SUCCESS)
1444                                         {
1445                                                 pContainer = pControl->GetAccessibilityContainer();
1446                                                 if (pContainer == null)
1447                                                 {
1448                                                         continue;
1449                                                 }
1450                                                 if (IsContainerValid(pContainer))
1451                                                 {
1452                                                         pContainer->GetElements(_elementPositionList);
1453                                                 }
1454                                         }
1455                                 }
1456                                 _elementPositionList.Sort(comparer);
1457                                 _count = _elementPositionList.GetCount();
1458                                 _AccessibilityElement* pElement = null;
1459                                 for (int i = 0 ; i < _count ; i++)
1460                                 {
1461                                         r = _elementPositionList.GetAt(i, pElement);
1462                                         if (r != E_SUCCESS)
1463                                         {
1464                                                 continue;
1465                                         }
1466                                         if (__candidateList.Contains(pElement))
1467                                         {
1468                                                 continue;
1469                                         }
1470                                         __candidateList.Add(pElement);
1471                                         elementPositionByControlList.Remove(pElement);
1472                                         elementPositionByControlList.InsertAt(pElement, index);
1473                                         elementPositionList.Remove(pElement);
1474                                         elementPositionList.InsertAt(pElement, index);
1475                                         index++;
1476                                 }
1477                         }
1478                 }
1479                 else
1480                 {
1481                         elementPositionList.Remove(pPositionByControlListElement);
1482                         elementPositionList.InsertAt(pPositionByControlListElement, index);
1483                         __candidateList.Add(pPositionByControlListElement);
1484                         index++;
1485                         continue;
1486                 }
1487         }
1488
1489         count = __candidateList.GetCount();
1490         SysLog(NID_UI, "Accessibility element candidate count : %d", count);
1491         if (count < 1)
1492         {
1493                 return;
1494         }
1495
1496         _AccessibilityElement* pElement = null;
1497         _AccessibilityElement* pElement2 = null;
1498         int selectedHeader = -1;
1499         int startHeader = -1;
1500         int endHeader = -1;
1501         int selectedFooter = -1;
1502         int startFooter = -1;
1503         int endFooter = -1;
1504         for (int i = 0 ; i < count ; i++)
1505         {
1506                 r = __candidateList.GetAt(i, pElement);
1507                 if(pElement->GetParent()->GetPriority() == ACCESSIBILITY_PRIORITY_TOP)
1508                 {
1509                         if (startHeader == -1)
1510                         {
1511                                 startHeader=i;
1512                         }
1513                         endHeader = i;
1514                 }
1515                 if(pElement->GetParent()->GetPriority() == ACCESSIBILITY_PRIORITY_BOTTOM)
1516                 {
1517                         if (startFooter == -1)
1518                         {
1519                                 startFooter=i;
1520                         }
1521                         endFooter = i;
1522                 }
1523         }
1524         if(startHeader != -1 && endHeader - startHeader > 1)
1525         {
1526                 for(int i = startHeader; i <= endHeader ; i++)
1527                 {
1528                         r = __candidateList.GetAt(i, pElement);
1529                         if (r != E_SUCCESS)
1530                         {
1531                                 continue;
1532                         }
1533                         selectedHeader = i;
1534                         for(int j = i +1 ; j <= endHeader; j++)
1535                         {
1536                                 r = __candidateList.GetAt(j, pElement2);
1537                                 if (r != E_SUCCESS)
1538                                 {
1539                                         continue;
1540                                 }
1541                                 if(pElement->GetAbsoluteBounds().x > pElement2->GetAbsoluteBounds().x)
1542                                 {
1543                                         pElement = pElement2;
1544                                         selectedHeader = j;
1545                                 }
1546                         }
1547                         if(selectedHeader != i)
1548                         {
1549                                 __candidateList.Remove(pElement);
1550                                 __candidateList.InsertAt(pElement, i);
1551                         }
1552                 }
1553         }
1554         if(startFooter != -1 && endFooter - startFooter > 1)
1555         {
1556                 for(int i = startFooter; i <= endFooter ; i++)
1557                 {
1558                         r = __candidateList.GetAt(i, pElement);
1559                         if (r != E_SUCCESS)
1560                         {
1561                                 continue;
1562                         }
1563                         selectedFooter = i;
1564                         for(int j = i +1 ; j <= endFooter; j++)
1565                         {
1566                                 r = __candidateList.GetAt(j, pElement2);
1567                                 if (r != E_SUCCESS)
1568                                 {
1569                                         continue;
1570                                 }
1571                                 if(pElement->GetAbsoluteBounds().x > pElement2->GetAbsoluteBounds().x)
1572                                 {
1573                                         pElement = pElement2;
1574                                         selectedFooter = j;
1575                                 }
1576                         }
1577                         if(selectedFooter != i)
1578                         {
1579                                 __candidateList.Remove(pElement);
1580                                 __candidateList.InsertAt(pElement, i);
1581                         }
1582                 }
1583         }
1584         
1585         return;
1586 }
1587 void
1588 _AccessibilityManager::MakeList(_AccessibilityContainer* pContainer)
1589 {
1590         if (pContainer->GetOwner().IsVisible() && pContainer->IsActivated())
1591         {
1592                 pContainer->GetElements(__candidateList);
1593         }
1594         _Control* pControl = &(pContainer->GetOwner());
1595         int count = pControl->GetChildCount();
1596         for (int i = 0 ; i<count;i++)
1597         {
1598                 _Control* pChildControl = pControl->GetChild(i);
1599                 if (pChildControl)
1600                 {
1601                         MakeList(pChildControl->GetAccessibilityContainer());
1602                 }
1603         }
1604         return;
1605 }
1606 bool
1607 _AccessibilityManager::MoveFocus(_AccessibilityFocusDirection direction)
1608 {
1609         if (direction == _ACCESSIBILITY_FOCUS_DIRECTION_PREVIOUS
1610                 || direction == _ACCESSIBILITY_FOCUS_DIRECTION_NEXT)
1611         {
1612                 MakeList();
1613         }
1614         else
1615         {
1616                 return false;
1617         }
1618
1619         int count = __candidateList.GetCount();
1620         if (count <= 0)
1621         {
1622                 return false;
1623         }
1624         SysLog(NID_UI, "count ", count);
1625         result r = E_SUCCESS;
1626         int index = 0;
1627         _AccessibilityElement* pElement = null;
1628         _AccessibilityContainer* pContainer = null;
1629         bool focusManaged = false;
1630         if (IsContainerValid(__pTargetContainer))
1631         {
1632                 r = __candidateList.IndexOf(__pTargetElement, 0, index);
1633                 if (r != E_SUCCESS)
1634                 {
1635                         pElement = null;
1636                         __pTargetElement = null;
1637                         __pTargetContainer = null;
1638                 }
1639                 else
1640                 {
1641                         if ((__pTargetContainer->MoveFocus(direction)))
1642                         {
1643                                 pElement = __pTargetContainer->GetCurrentFocusedElement();
1644                                 focusManaged = true;
1645                         }
1646                         else
1647                         {
1648                                 index += direction;
1649                                 if (index < 0)
1650                                 {
1651                                         index = count - 1;
1652                                 }
1653                                 if (index > count - 1)
1654                                 {
1655                                         index = 0;
1656                                 }
1657                                  __candidateList.GetAt(index, pElement);
1658                                 if (pElement->GetParent()->IsFocusManaged())
1659                                 {
1660                                         if ((pElement->GetParent()->MoveFocus(direction)))
1661                                         {
1662                                                 focusManaged = true;
1663                                         }
1664                                 }
1665                         }
1666                 }
1667         }
1668         else
1669         {
1670                 SysTryReturn(NID_UI, __candidateList.GetAt(0, pElement) == E_SUCCESS, false, E_SUCCESS, "[E_SUCCESS] Candidates are not exist.");
1671         }
1672         if (pElement)
1673         {
1674                 pContainer = pElement->GetParent();
1675                 IListT<_IAccessibilityListener*>* pListenerList = pContainer->GetListenerListN();
1676                 if (pListenerList)
1677                 {
1678                         int listenerCount = pListenerList->GetCount();
1679                         if (listenerCount > 0)
1680                         {
1681                                 for (int i = 0;i<listenerCount;i++)
1682                                 {
1683                                         _IAccessibilityListener* pListener = null;
1684                                         if (pListenerList->GetAt(i, pListener) == E_SUCCESS)
1685                                         {
1686                                                 if (pListener->OnAccessibilityItemRefreshed(*pContainer, *pElement, direction) == true)
1687                                                 {
1688                                                         return MoveFocus(direction);
1689                                                 }
1690                                         }
1691                                 }
1692                         }
1693                         delete pListenerList;
1694                         pListenerList = null;
1695                 }
1696
1697                 if (__pTargetContainer)
1698                 {
1699                         pListenerList = __pTargetContainer->GetListenerListN();
1700                         if (pListenerList)
1701                         {
1702                                 int listenerCount = pListenerList->GetCount();
1703                                 if (listenerCount > 0)
1704                                 {
1705                                         for (int i = 0;i<listenerCount;i++)
1706                                         {
1707                                                 _IAccessibilityListener* pListener = null;
1708                                                 if (pListenerList->GetAt(i, pListener) == E_SUCCESS)
1709                                                 {
1710                                                         pListener->OnAccessibilityFocusOut(*__pTargetContainer, *__pTargetElement);
1711                                                 }
1712                                         }
1713                                 }
1714                                 delete pListenerList;
1715                                 pListenerList = null;
1716                         }
1717                 }
1718                 if(__pTargetContainer)
1719                 {
1720                         __pTargetContainer->SetCurrentFocusedElement(null);
1721                 }
1722                 if (focusManaged)
1723                 {
1724                         __pTargetElement = pElement;
1725                         __pTargetContainer = pContainer;
1726                         __targetControlHandle = pContainer->GetOwner().GetHandle();
1727                         EraseFocusUi();
1728                 }
1729                 else
1730                 {
1731
1732                         __pTargetElement = pElement;
1733                         __pTargetContainer = pContainer;
1734                         __targetControlHandle = pContainer->GetOwner().GetHandle();
1735                         pListenerList = __pTargetContainer->GetListenerListN();
1736                         if (pListenerList)
1737                         {
1738                                 int listenerCount = pListenerList->GetCount();
1739                                 if (listenerCount > 0)
1740                                 {
1741                                         for (int i = 0;i<listenerCount;i++)
1742                                         {
1743                                                 _IAccessibilityListener* pListener = null;
1744                                                 if (pListenerList->GetAt(i, pListener) == E_SUCCESS)
1745                                                 {
1746                                                         pListener->OnAccessibilityFocusIn(*__pTargetContainer, *__pTargetElement);
1747                                                         DrawFocusUi(*__pTargetElement);
1748                                                         if (direction == _ACCESSIBILITY_FOCUS_DIRECTION_PREVIOUS)
1749                                                         {
1750                                                                 pListener->OnAccessibilityFocusMovedPrevious(*__pTargetContainer, *__pTargetElement);
1751                                                         }
1752                                                         else if (direction == _ACCESSIBILITY_FOCUS_DIRECTION_NEXT)
1753                                                         {
1754                                                                 pListener->OnAccessibilityFocusMovedNext(*__pTargetContainer, *__pTargetElement);
1755                                                         }
1756                                                 }
1757                                         }
1758                                 }
1759                         }
1760                         else
1761                         {
1762                                 DrawFocusUi(*__pTargetElement);
1763                         }
1764                         delete pListenerList;
1765                         pListenerList = null;
1766                         ReadElement(*pElement);
1767                 }
1768                 return true;
1769         }
1770         return false;
1771 }
1772 void
1773 _AccessibilityManager::RequestToDrawFocusUi()
1774 {
1775         if (__pTargetContainer)
1776         {
1777                 //HidePopup();
1778                 DrawFocusUi(*__pTargetElement);
1779         }
1780 }
1781
1782 void
1783 _AccessibilityManager::RequestAutoReading(_AccessibilityAutoReadingMode mode)
1784 {
1785         if(__screenReaderIsEnabled)
1786         {
1787                 if (mode == _ACCESSIBILITY_AUTO_READING_MODE_RESET)
1788                 {
1789                         __pTitleElement = null;
1790                         return;
1791                 }
1792                 pAutoReadingTimer->Start(mode);
1793         }
1794 }
1795
1796 void
1797 _AccessibilityManager::SetTtsMode(_AccessibilityTtsMode mode)
1798 {
1799         if (__pTtsPlayer)
1800         {
1801                 //__pTtsPlayer->SetMode(mode);
1802         }
1803 }
1804
1805 void
1806 _AccessibilityManager::SetGlobalFocusedElement(_AccessibilityElement& element)
1807 {
1808         _AccessibilityElement* pElement = &element;
1809         if (!IsContainerValid(pElement->GetParent()))
1810         {
1811                 return;
1812         }
1813         __pTargetContainer = pElement->GetParent();
1814         __pTargetElement = pElement;
1815         RequestAutoReading(_ACCESSIBILITY_AUTO_READING_MODE_CURRENT_FOCUS);
1816 }
1817
1818 void
1819 _AccessibilityManager::EraseFocusUi(void)
1820 {
1821         if (__focusedControlHandle.IsValid())
1822         {
1823                 if (__pFocusVe)
1824                 {
1825                         __pFocusVe->Destroy();
1826                         __pFocusVe = null;
1827                 }
1828         }
1829         else
1830         {
1831                 __pFocusVe = null;
1832         }
1833 }
1834 void
1835 _AccessibilityManager::DrawFocusUi(const _AccessibilityElement& element)
1836 {
1837         FloatRectangle rectangle = element.GetBounds();
1838         Canvas* pCanvas = null;
1839
1840         _AccessibilityContainer* pContainer = element.GetParent();
1841
1842         if (__focusedControlHandle.IsValid())
1843         {
1844                 if (__pFocusVe)
1845                 {
1846                         __pFocusVe->Destroy();
1847                         __pFocusVe = null;
1848                 }
1849         }
1850         else
1851         {
1852                 __pFocusVe = null;
1853         }
1854
1855         result r = E_SUCCESS;
1856         _Control* pControl = &const_cast<_Control&>(pContainer->GetOwner());
1857         _VisualElement* pControlVe = pControl->GetVisualElement();
1858
1859         __pFocusVe = new (std::nothrow) VisualElement();
1860         SysTryCatch(NID_UI, __pFocusVe != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed");
1861         r = __pFocusVe->Construct();
1862         SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] System error");
1863
1864         __pFocusVe->SetName("Accessibility focus ui");
1865         __pFocusVe->SetImplicitAnimationEnabled(false);
1866         __focusedControlHandle = pControl->GetHandle();
1867         pControlVe->AttachChild(*__pFocusVe);
1868
1869         if (__pFocusVe)
1870         {
1871                 __pFocusVe->SetBounds(FloatRectangle(rectangle.x, rectangle.y, rectangle.width, rectangle.height));
1872                 pCanvas = __pFocusVe->GetCanvasN();
1873                 SysTryCatch(NID_UI, pCanvas, , E_SYSTEM, "[E_SYSTEM] System error");
1874                 pCanvas->SetBackgroundColor(0x00000000);
1875                 pCanvas->Clear();
1876                 Bitmap* pBitmap = null;
1877                 result r = GET_BITMAP_CONFIG_N(ACCESSIBILITY::FOCUS, BITMAP_PIXEL_FORMAT_ARGB8888, pBitmap);
1878                 if (r == E_SUCCESS)
1879                 {
1880                         if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pBitmap))
1881                         {
1882                                 r = pCanvas->DrawNinePatchedBitmap(Rectangle(0, 0, rectangle.width, rectangle.height), *pBitmap);
1883                                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] System error");
1884                         }
1885                         else
1886                         {
1887                                 r = pCanvas->DrawBitmap(Rectangle(0, 0, rectangle.width, rectangle.height), *pBitmap);
1888                                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] System error");
1889                         }
1890                 }
1891                 
1892                 __pFocusVe->SetShowState(true);
1893                 delete pCanvas;
1894         }
1895         pContainer ->SetCurrentFocusedElement(const_cast<_AccessibilityElement*>(&element));
1896         return;
1897 CATCH:
1898         delete pCanvas;
1899         if (__focusedControlHandle.IsValid())
1900         {
1901                 if (__pFocusVe)
1902                 {
1903                         __pFocusVe->Destroy();
1904                         __pFocusVe = null;
1905                 }
1906         }
1907         else
1908         {
1909                 __pFocusVe = null;
1910         }
1911         return;
1912 }
1913 bool
1914 _AccessibilityManager::ProcessGesture(_AccessibilityGestureType type, const FloatPoint& point)
1915 {
1916         switch(type)
1917         {
1918                 case _ACCESSIBILITY_GESTURE_TYPE_FLICK_UP:
1919                 case _ACCESSIBILITY_GESTURE_TYPE_FLICK_LEFT:
1920                         if (MoveFocus(_ACCESSIBILITY_FOCUS_DIRECTION_PREVIOUS))
1921                         {
1922                                 SetGestureMode(MODE_FOCUS_MOVE);
1923                         }
1924                         break;
1925                 case _ACCESSIBILITY_GESTURE_TYPE_FLICK_DOWN:
1926                 case _ACCESSIBILITY_GESTURE_TYPE_FLICK_RIGHT:
1927                         if (MoveFocus(_ACCESSIBILITY_FOCUS_DIRECTION_NEXT))
1928                         {
1929                                 SetGestureMode(MODE_FOCUS_MOVE);
1930                         }
1931                         break;
1932                 case _ACCESSIBILITY_GESTURE_TYPE_ONE_FINGER_ONE_TAP:
1933                 {
1934                         if (GetGestureMode() == MODE_FOCUS_MOVE)
1935                         {
1936                                 SetGestureMode(MODE_TAP);
1937                                 __candidateList.RemoveAll();
1938                         }
1939                         _Control* pControl = null;
1940                         Point pt((int)point.x, (int)point.y);
1941                         _Window* pWindow = _ControlManager::GetInstance()->GetTopVisibleWindow();
1942                         if (!(pWindow->IsLayoutChangable()))
1943                         {
1944                                 Rectangle topWindowAbsBounds = pWindow->GetAbsoluteBounds();
1945                                 pt.x = pt.x + topWindowAbsBounds.x;
1946                                 pt.y = pt.y + topWindowAbsBounds.y;
1947                         }
1948                         pControl = _ControlManager::GetInstance()->GetTopmostTouchedControl(pt);
1949                         if (pControl == null || !(pControl->GetAbsoluteBounds().Contains(pt)))
1950                         {
1951                                 return false;
1952                         }
1953                         _AccessibilityContainer* pAccContainer = pControl->GetAccessibilityContainer();
1954                         while(!(pAccContainer->IsActivated()))
1955                         {
1956                                 _Control* _pControl = pAccContainer->GetOwner().GetParent();
1957                                 if (_pControl == null)
1958                                 {
1959                                         return false;
1960                                 }
1961                                 pAccContainer = _pControl->GetAccessibilityContainer();
1962                                 if (pAccContainer == null)
1963                                 {
1964                                         return false;
1965                                 }
1966                         }
1967                         _AccessibilityElement* pElement = pAccContainer->Hit(pt);
1968                         if (pElement == null)
1969                         {
1970                                 return false;
1971                         }
1972
1973                         if (__pTargetElement == pElement)
1974                         {
1975                                 if (__pTtsPlayer)
1976                                 {
1977                                         AccessibilityScreenReaderStatus status = __pTtsPlayer->GetStatus();
1978                                         if (status == ACCESSIBILITY_SCREEN_READER_STATUS_PLAYING)
1979                                         {
1980                                                 return true;
1981                                         }
1982                                 }
1983                         }
1984
1985                         if (!(pAccContainer->MoveFocus(pt)))
1986                         {
1987                                 return false;
1988                         }
1989                         LinkedListT<_IAccessibilityListener*>* pList = null;
1990                         if (IsContainerValid(__pTargetContainer))
1991                         {
1992                                 __pTargetContainer->ResetFocus();
1993                                 __pTargetContainer->GetOwner().Invalidate();
1994                                 pList = static_cast<LinkedListT<_IAccessibilityListener*>*>(__pTargetContainer->GetListenerListN());
1995                                 if (pList != null)
1996                                 {
1997                                         int count = pList->GetCount();
1998                                         for (int i = 0;i<count;i++)
1999                                         {
2000                                                 _IAccessibilityListener* pListener = null;
2001                                                 if (pList->GetAt(i, pListener) == E_SUCCESS)
2002                                                 {
2003                                                         pListener->OnAccessibilityFocusOut(*__pTargetContainer, *__pTargetElement);
2004                                                 }
2005                                         }
2006                                         delete pList;
2007                                 }
2008                         }
2009                         if(__pTargetContainer)
2010                         {
2011                                 __pTargetContainer->SetCurrentFocusedElement(null);
2012                         }
2013                         if (pAccContainer->IsFocusManaged())
2014                         {
2015                                 __pTargetContainer = pAccContainer;
2016                                 __targetControlHandle = pAccContainer->GetOwner().GetHandle();
2017                                 __pTargetElement = pElement;
2018                                 EraseFocusUi();
2019                         }
2020                         else
2021                         {
2022                                 __pTargetContainer = pAccContainer;
2023                                 __targetControlHandle = pAccContainer->GetOwner().GetHandle();
2024                                 __pTargetElement = pElement;
2025                                 pList = static_cast<LinkedListT<_IAccessibilityListener*>*>(__pTargetContainer->GetListenerListN());
2026                                 if (pList != null)
2027                                 {
2028                                         int count = pList->GetCount();
2029                                         for (int i = 0;i<count;i++)
2030                                         {
2031                                                 _IAccessibilityListener* pListener = null;
2032                                                 if (pList->GetAt(i, pListener) == E_SUCCESS)
2033                                                 {
2034                                                         pListener->OnAccessibilityFocusIn(*__pTargetContainer, *__pTargetElement);
2035                                                 }
2036                                         }
2037                                         delete pList;
2038                                 }
2039                                 DrawFocusUi(*pElement);
2040                                 ReadElement(*pElement);
2041                         }
2042                 }
2043                         break;
2044                 case _ACCESSIBILITY_GESTURE_TYPE_ONE_FINGER_DOUBLE_TAP:
2045                 {
2046                         if (GetGestureMode() == MODE_FOCUS_MOVE)
2047                         {
2048                                 SetGestureMode(MODE_TAP);
2049                                 __candidateList.RemoveAll();
2050                         }
2051                         if (__pTargetElement == null)
2052                         {
2053                                 return true;
2054                         }
2055                         _TouchManager* pTouchMgr = _TouchManager::GetInstance();
2056                         _Control* _pControl = null;
2057                         if (pTouchMgr == null)
2058                         {
2059                                 return false;
2060                         }
2061                         if (IsContainerValid(__pTargetContainer))
2062                         {
2063                                 _pControl = &(__pTargetContainer->GetOwner());
2064                         }
2065                         else
2066                         {
2067                                 return false;
2068                         }
2069                         if (_pControl == null)
2070                         {
2071                                 return false;
2072                         }
2073                         if (_pControl->GetEnableState() == false)
2074                         {
2075                                 ReadContent(L"Unavailable");
2076                                 return true;
2077                         }
2078                         if (__pTargetElement->GetSupportOperatingGesture())
2079                         {
2080                                 long long tick = 0;
2081                                 if (_SystemTimeImpl::GetTicks(tick) != E_SUCCESS)
2082                                 {
2083                                         tick = 0;
2084                                 }
2085                                 FloatRectangle rect = __pTargetElement->GetAbsoluteBounds();
2086                                 Point _point((int)(rect.x + rect.width/2), (int)(rect.y + rect.height/2));
2087                                 _UiTouchEvent pressedEvent(_pControl->GetHandle(), _TouchInfo(0, _TOUCH_PRESSED, _point, false, tick));
2088                                 _UiTouchEvent releasedEvent(_pControl->GetHandle(), _TouchInfo(0, _TOUCH_RELEASED, _point, false, tick+1));
2089                                 pressedEvent.SetAccessibilityEvent(true);
2090                                 releasedEvent.SetAccessibilityEvent(true);
2091
2092                                 unsigned int pointId = 0;
2093                                 pointId = pTouchMgr->GeneratePointId(0);
2094                                 SysLog(NID_UI, "Accessibility manager generated touch pressed event. id: %d", pointId);
2095                                 _UiEventManager::GetInstance()->SendEvent(pressedEvent);
2096                                 pointId = pTouchMgr->GetPointId(0);
2097                                 SysLog(NID_UI, "Accessibility manager generated touch released event. id: %d", pointId);
2098                                 _UiEventManager::GetInstance()->SendEvent(releasedEvent);
2099                                 if (!IsContainerValid(__pTargetContainer))
2100                                 {
2101                                         return false;
2102                                 }
2103                         }
2104                         LinkedListT<_IAccessibilityListener*>* pList = static_cast<LinkedListT<_IAccessibilityListener*>*>(__pTargetContainer->GetListenerListN());
2105                         if (pList != null)
2106                         {
2107                                 int count = pList->GetCount();
2108                                 SysLog(NID_UI, "Accessibility manager called listeners. count : %d", count);
2109                                 for (int i = 0;i<count;i++)
2110                                 {
2111                                         _IAccessibilityListener* pListener = null;
2112                                         if (pList->GetAt(i, pListener) == E_SUCCESS)
2113                                         {
2114                                                 pListener->OnAccessibilityActionPerformed(*__pTargetContainer, *__pTargetElement);
2115                                         }
2116                                 }
2117                                 delete pList;
2118                         }
2119                 }
2120                 break;
2121
2122                 case _ACCESSIBILITY_GESTURE_TYPE_ONE_FINGER_LONGPRESS:
2123                         break;
2124                 case _ACCESSIBILITY_GESTURE_TYPE_ONE_FINGER_PANNING_STARTED:
2125                 case _ACCESSIBILITY_GESTURE_TYPE_ONE_FINGER_PANNING_CHANGED:
2126                 case _ACCESSIBILITY_GESTURE_TYPE_ONE_FINGER_PANNING_FINISHED:
2127                         break;
2128                 case _ACCESSIBILITY_GESTURE_TYPE_VALUE_INCREASED:
2129                         {
2130                                 if (!IsContainerValid(__pTargetContainer))
2131                                 {
2132                                         return false;
2133                                 }
2134
2135                                 _Control* pControl = &(__pTargetContainer->GetOwner());
2136                                 if (pControl->GetEnableState() == false)
2137                                 {
2138                                         ReadContent(L"Unavailable");
2139                                         return true;
2140                                 }
2141
2142                                 LinkedListT<_IAccessibilityListener*>* pList = static_cast<LinkedListT<_IAccessibilityListener*>*>(__pTargetContainer->GetListenerListN());
2143                                 if (pList != null)
2144                                 {
2145                                         int count = pList->GetCount();
2146                                         for (int i = 0;i<count;i++)
2147                                         {
2148                                                 _IAccessibilityListener* pListener = null;
2149                                                 if (pList->GetAt(i, pListener) == E_SUCCESS)
2150                                                 {
2151                                                         pListener->OnAccessibilityValueIncreased(*__pTargetContainer, *__pTargetElement);
2152                                                 }
2153                                         }
2154                                         delete pList;
2155                                 }
2156                         }
2157                         break;
2158                 case _ACCESSIBILITY_GESTURE_TYPE_VALUE_DECREASED:
2159                         {
2160                                 if (!IsContainerValid(__pTargetContainer))
2161                                 {
2162                                         return false;
2163                                 }
2164
2165                                 _Control* pControl = &(__pTargetContainer->GetOwner());
2166                                 if (pControl->GetEnableState() == false)
2167                                 {
2168                                         ReadContent(L"Unavailable");
2169                                         return true;
2170                                 }
2171
2172                                 LinkedListT<_IAccessibilityListener*>* pList = static_cast<LinkedListT<_IAccessibilityListener*>*>(__pTargetContainer->GetListenerListN());
2173                                 if (pList != null)
2174                                 {
2175                                         int count = pList->GetCount();
2176                                         for (int i = 0;i<count;i++)
2177                                         {
2178                                                 _IAccessibilityListener* pListener = null;
2179                                                 if (pList->GetAt(i, pListener) == E_SUCCESS)
2180                                                 {
2181                                                         pListener->OnAccessibilityValueDecreased(*__pTargetContainer, *__pTargetElement);
2182                                                 }
2183                                         }
2184                                         delete pList;
2185                                 }
2186                         }
2187                         break;
2188                 case _ACCESSIBILITY_GESTURE_TYPE_TWO_FINGER_PANNING_STARTED:
2189                 {
2190                         Point pt((int)point.x, (int)point.y);
2191                         _Control* pControl = _ControlManager::GetInstance()->GetTopmostTouchedControl(pt);
2192                         if (pControl == null)
2193                         {
2194                                 SysLog(NID_UI, "Two finger panning is started. but control is null");
2195                                 return false;
2196                         }
2197                         long long tick = 0;
2198                         if (_SystemTimeImpl::GetTicks(tick) != E_SUCCESS)
2199                         {
2200                                 tick = 0;
2201                         }
2202                         _UiTouchEvent pressedEvent(pControl->GetHandle(), _TouchInfo(0, _TOUCH_PRESSED, pt, false, tick));
2203                         unsigned int pointId = 0;
2204                         pointId = _TouchManager::GetInstance()->GeneratePointId(0);
2205                         _UiEventManager::GetInstance()->SendEvent(pressedEvent);
2206                         __pPanningControl = pControl;
2207                         SetGestureMode(MODE_PANNING);
2208                         SysLog(NID_UI, "Two finger panning is started. x:%d, y:%d", pt.x, pt.y);
2209                         }
2210                         break;
2211                 case _ACCESSIBILITY_GESTURE_TYPE_TWO_FINGER_PANNING_CHANGED:
2212                 {
2213                         if (__pPanningControl == null || GetGestureMode() != MODE_PANNING)
2214                         {
2215                                 SetGestureMode(MODE_TAP);
2216                                 SysLog(NID_UI, "Two finger panning is started. but control is null");
2217                                 return false;
2218                         }
2219                         long long tick = 0;
2220                         if (_SystemTimeImpl::GetTicks(tick) != E_SUCCESS)
2221                         {
2222                                 tick = 0;
2223                         }
2224                         Point pt((int)point.x, (int)point.y);
2225                         _UiTouchEvent movedEvent(__pPanningControl->GetHandle(), _TouchInfo(0, _TOUCH_MOVED, pt, false, tick));
2226                         unsigned int pointId = 0;
2227                         pointId = _TouchManager::GetInstance()->GetPointId(0);
2228                         _UiEventManager::GetInstance()->SendEvent(movedEvent);
2229                         SysLog(NID_UI, "Two finger panning is moved. x:%d, y:%d", pt.x, pt.y);
2230                 }
2231                         break;
2232                 case _ACCESSIBILITY_GESTURE_TYPE_TWO_FINGER_PANNING_FINISHED:
2233                 {
2234                         if (__pPanningControl == null || GetGestureMode() != MODE_PANNING)
2235                         {
2236                                 SetGestureMode(MODE_TAP);
2237                                 SysLog(NID_UI, "Two finger panning is started. but control is null");
2238                                 return false;
2239                         }
2240                         long long tick = 0;
2241                         if (_SystemTimeImpl::GetTicks(tick) != E_SUCCESS)
2242                         {
2243                                 tick = 0;
2244                         }
2245                         Point pt((int)point.x, (int)point.y);
2246                         _UiTouchEvent releasedEvent(__pPanningControl->GetHandle(), _TouchInfo(0, _TOUCH_RELEASED, pt, false, tick));
2247                         unsigned int pointId = 0;
2248                         pointId = _TouchManager::GetInstance()->GetPointId(0);
2249                         _UiEventManager::GetInstance()->SendEvent(releasedEvent);
2250                         __pPanningControl = null;
2251                         SetGestureMode(MODE_TAP);
2252                         SysLog(NID_UI, "Two finger panning is finished. x:%d, y:%d", pt.x, pt.y);
2253                 }
2254                         break;
2255                 default:
2256                         break;
2257         }
2258         return true;
2259 }
2260
2261 Tizen::Base::_HandleT<_AccessibilityContainer>
2262 _AccessibilityManager::Register(_AccessibilityContainer* pObject)
2263 {
2264         if (pObject == null)
2265         {
2266                 return Tizen::Base::_HandleT<_AccessibilityContainer>();
2267         }
2268
2269         return __objectManager.Register(*pObject);
2270 }
2271 void
2272 _AccessibilityManager::Unregister(Tizen::Base::_HandleT <_AccessibilityContainer> handle)
2273 {
2274         __objectManager.Unregister(handle);
2275         return;
2276 }
2277
2278 void
2279 _AccessibilityManager::OnChangedLocale(void)
2280 {
2281         if (__pTtsPlayer && __pSettingLoader)
2282         {
2283                 __pTtsPlayer->SetLocale(__pSettingLoader->GetLocale());
2284         }
2285 }
2286
2287 void
2288 _AccessibilityManager::OnAccessibilityScreenReaderIsActivated(bool set)
2289 {
2290         SysLog(NID_UI, "Screen reader status is changed. %d", set);
2291         if (__screenReaderIsEnabled == set)
2292         {
2293                 return;
2294         }
2295         else
2296         {
2297                 __screenReaderIsEnabled = set;
2298                 if (__screenReaderIsEnabled)
2299                 {
2300                         if (__pTtsPlayer)
2301                         {
2302                                 __pTtsPlayer->SetLocale(__pSettingLoader->GetLocale());
2303                                 __pTtsPlayer->Activate();
2304                                 RequestAutoReading(_ACCESSIBILITY_AUTO_READING_MODE_FIRST_ITEM);
2305                         }
2306                 }
2307                 else
2308                 {
2309                         __pTtsPlayer->Deactivate();
2310                         EraseFocusUi();
2311                         __pTargetContainer = null;
2312                         __pTargetElement = null;
2313                         __pTitleElement = null;
2314                         __candidateList.RemoveAll();
2315                         __mode = MODE_NONE;
2316                         __targetControlHandle = _ControlHandle();
2317                         __focusedControlHandle = _ControlHandle();
2318                         __readingPopupParentHandle = _ControlHandle();
2319                 }
2320         }
2321 }
2322 bool
2323 _AccessibilityManager::IsScreenReaderActivated(void)
2324 {
2325         __screenReaderIsEnabled = __pSettingLoader->IsScreenReaderActivated();
2326         return __screenReaderIsEnabled;
2327 }
2328 float
2329 _AccessibilityManager::GetLargeFontSize(void)
2330 {
2331         return __pSettingLoader->GetLargeFontSize();
2332 }
2333
2334 bool
2335 _AccessibilityManager::IsActivated()
2336 {
2337         return __screenReaderIsEnabled;
2338 }
2339
2340 bool
2341 _AccessibilityManager::IsContainerValid(_AccessibilityContainer* pContainer)
2342 {
2343         if (pContainer == null)
2344         {
2345                 return false;
2346         }
2347         if (!(pContainer->IsActivated()))
2348         {
2349                 return false;
2350         }
2351         if (!(pContainer->GetHandle().IsValid()))
2352         {
2353                 return false;
2354         }
2355         if (!(pContainer->GetOwner().GetHandle().IsValid()))
2356         {
2357                 return false;
2358         }
2359         if (!(pContainer->GetOwner().IsVisible()))
2360         {
2361                 return false;
2362         }
2363         if (!IsVisible(pContainer))
2364         {
2365                 return false;
2366         }
2367         return true;
2368 }
2369 bool
2370 _AccessibilityManager::IsTargetContainerValid(void)
2371 {
2372
2373         if (__pTargetContainer && __targetControlHandle.IsValid() && __pTargetContainer->GetOwner().IsVisible() && __pTargetContainer->GetOwner().GetRootWindow() && IsVisible(__pTargetContainer))
2374         {
2375                 return true;
2376         }
2377         return false;
2378 }
2379 bool
2380 _AccessibilityManager::IsFirstElementGainedFocus(void)
2381 {
2382         int count = __candidateList.GetCount();
2383         if(count == 0)
2384         {
2385                 return false;
2386         }
2387         if(__pTargetElement == null)
2388         {
2389                 return false;
2390         }
2391         _AccessibilityElement* pElement = null;
2392         if(__candidateList.GetAt(0, pElement) == E_SUCCESS)
2393         {
2394                 if(pElement == __pTargetElement)
2395                 {
2396                         return true;
2397                 }
2398         }
2399         return false;
2400 }
2401 bool
2402 _AccessibilityManager::IsLastElementGainedFocus(void)
2403 {
2404         int count = __candidateList.GetCount();
2405         if(count == 0)
2406         {
2407                 return false;
2408         }
2409         if(__pTargetElement == null)
2410         {
2411                 return false;
2412         }
2413         _AccessibilityElement* pElement = null;
2414         if(__candidateList.GetAt(count-1, pElement) == E_SUCCESS)
2415         {
2416                 if(pElement == __pTargetElement)
2417                 {
2418                         return true;
2419                 }
2420         }
2421         return false;
2422 }
2423 bool
2424 _AccessibilityManager::IsVisible(_AccessibilityElement* pElement)
2425 {
2426         return IsVisible(pElement->GetParent());
2427 }
2428 bool
2429 _AccessibilityManager::IsVisible(_AccessibilityContainer* pContainer)
2430 {
2431         _ControlManager* pControlManager = _ControlManager::GetInstance();
2432         int count = pControlManager->GetWindowCount();
2433         if (count < 1)
2434         {
2435                 return false;
2436         }
2437         _Window* pTopWindow = pControlManager->GetWindow(count - 1);
2438         if (pTopWindow != pContainer->GetOwner().GetRootWindow())
2439         {
2440                 return false;
2441         }
2442         return true;
2443 }
2444 void
2445 _AccessibilityManager::SetGestureMode(GestureMode mode)
2446 {
2447         __mode = mode;
2448 }
2449 _AccessibilityManager::GestureMode
2450 _AccessibilityManager::GetGestureMode(void)
2451 {
2452         return __mode;
2453 }
2454
2455 void
2456 _AccessibilityManager::NeedRefreshItem(void)
2457 {
2458         __needRefreshItem = true;
2459 }
2460
2461 }} //Tizen::Ui
2462