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