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