ce4f3a8652a4067193c1243892b9b8336a208d73
[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 <FLclLocale.h>
23 #include <FUiAnimVisualElement.h>
24 #include <FUiCtrlFrame.h>
25 #include <FUiCtrlForm.h>
26 #include <FGrpCanvas.h>
27 #include <FGrpColor.h>
28 #include <FGrpFloatDimension.h>
29 #include <FGrpEnrichedText.h>
30 #include <FGrpBitmap.h>
31 #include <FBase_StringConverter.h>
32 #include <FGrp_BitmapImpl.h>
33 #include "FUi_AccessibilityGesture.h"
34 #include "FUi_AccessibilitySystemSettingLoader.h"
35 #include "FUi_AccessibilityTtsPlayer.h"
36 #include "FUi_AccessibilityManager.h"
37 #include "FUi_AccessibilityElement.h"
38 #include "FUi_AccessibilityContainer.h"
39 #include "FUi_IAccessibilityListener.h"
40 #include "FUi_ControlManager.h"
41 #include "FUi_TouchManager.h"
42 #include "FUi_UiEventManager.h"
43 #include "FUiAnim_VisualElementImpl.h"
44 #include "FUiCtrl_FrameImpl.h"
45 #include "FUiCtrl_ScrollPanel.h"
46 #include "FUiCtrl_IconListView.h"
47 #include "FUi_ResourceManager.h"
48
49 using namespace Tizen::App;
50 using namespace Tizen::Base;
51 using namespace Tizen::Base::Collection;
52 using namespace Tizen::Base::Runtime;
53 using namespace Tizen::Graphics;
54 using namespace Tizen::Ui::Animations;
55 using namespace Tizen::Ui::Controls;
56
57 namespace
58 {
59 class GuidePopupTimer
60         : public ITimerEventListener
61 {
62 public:
63         GuidePopupTimer(void)
64                 : __pElement(null)
65         {
66                 timer.Construct(*this);
67         }
68         virtual ~GuidePopupTimer(void) {}
69         void SetElement(VisualElement* pElement)
70         {
71                 if (__pElement != null)
72                 {
73                         timer.Cancel();
74                 }
75                 __pElement = pElement;
76                 timer.Start(3000);
77
78         }
79         void Stop(void)
80         {
81                 timer.Cancel();
82         }
83         virtual void OnTimerExpired(Timer& timer)
84         {
85                 if (__pElement)
86                 {
87                         __pElement->SetShowState(false);
88                 }
89                 __pElement = null;
90         }
91         VisualElement* __pElement;
92         Timer timer;
93 };
94
95 class AutoReadingTimer
96         : public ITimerEventListener
97 {
98 public:
99         AutoReadingTimer(Tizen::Ui::_AccessibilityManager* pManager)
100                 : __pAccessibilityManager(pManager)
101                 , __mode(Tizen::Ui::_ACCESSIBILITY_AUTO_READING_MODE_FIRST_ITEM)
102                 , __start(false)
103         {
104
105                 timer.Construct(*this);
106         }
107         virtual ~AutoReadingTimer(void) {}
108         void Start(Tizen::Ui::_AccessibilityAutoReadingMode mode)
109         {
110                 SysLog(NID_UI, "AccessibilityManager::AutoReadingTimer is requested mode : %d", mode);
111                 if (__start)
112                 {
113                         return;
114                 }
115                 __start = true;
116                 SysLog(NID_UI, "AccessibilityManager::AutoReadingTimer is started mode : %d", mode);
117                 __mode = mode;
118                 timer.Start(700);
119         }
120         void Stop(void)
121         {
122                 timer.Cancel();
123                 __start = false;
124         }
125         virtual void OnTimerExpired(Timer& timer)
126         {
127                 SysLog(NID_UI, "mode %d", __mode);
128                 if (__pAccessibilityManager->GetTtsStatus() != Tizen::Ui::ACCESSIBILITY_SCREEN_READER_STATUS_READY
129                         && __pAccessibilityManager->GetTtsStatus() != Tizen::Ui::ACCESSIBILITY_SCREEN_READER_STATUS_PLAYING)
130                 {
131                         __start = false;
132                         Start(__mode);
133                         SysLog(NID_UI, "AccessibilityManager::AutoReadingTimer is started again because tts is not initialized.");
134                         return;
135                 }
136                 __start = false;
137                 __pAccessibilityManager->ReadElement(__mode);
138         }
139         Tizen::Ui::_AccessibilityManager* __pAccessibilityManager;
140         Timer timer;
141         Tizen::Ui::_AccessibilityAutoReadingMode __mode;
142         bool __start;
143 };
144
145 GuidePopupTimer* pGuidePopupTimer;
146 AutoReadingTimer* pAutoReadingTimer;
147 }
148 namespace Tizen { namespace Ui {
149
150 template <class T>
151 class _AccessibilityItemComparer
152         : public Tizen::Base::Collection::IComparerT <T>
153 {
154 public:
155         _AccessibilityItemComparer(void)
156         {
157         }
158         virtual ~_AccessibilityItemComparer(void)
159         {
160         }
161         virtual result Compare(const T& obj1, const T& obj2, int& cmp) const
162         {
163                 Tizen::Graphics::Rectangle rect1= obj1->GetAbsoluteBounds();
164                 Tizen::Graphics::Rectangle rect2= obj2->GetAbsoluteBounds();
165
166                 if (rect1.y > rect2.y)
167                 {
168                         cmp = 1;
169                         return E_SUCCESS;
170                 }
171                 else if (rect1.y < rect2.y)
172                 {
173                         cmp = -1;
174                         return E_SUCCESS;
175                 }
176                 else
177                 {
178                         if (rect1.x > rect2.x)
179                         {
180                                 cmp = 1;
181                                 return E_SUCCESS;
182                         }
183                         else if (rect1.x < rect2.x)
184                         {
185                                 cmp = -1;
186                                 return E_SUCCESS;
187                         }
188                         else
189                         {
190                                 cmp = 0;
191                                 return E_SUCCESS;
192                         }
193                 }
194         }
195 }; //class _AccessibilityComparer
196
197 template <class T>
198 class _ElementComparer
199         : public Tizen::Base::Collection::IComparerT <T>
200 {
201 public:
202         _ElementComparer(void)
203         {
204         }
205         virtual ~_ElementComparer(void)
206         {
207         }
208         virtual result Compare(const T& obj1, const T& obj2, int& cmp) const
209         {
210                 if (obj1->GetParent()->GetPriority() > obj2->GetParent()->GetPriority())
211                 {
212                         cmp = -1;
213                         return E_SUCCESS;
214                 }
215                 else if (obj1->GetParent()->GetPriority() < obj2->GetParent()->GetPriority())
216                 {
217                         cmp = 1;
218                         return E_SUCCESS;
219                 }
220                 else
221                 {
222                         Tizen::Graphics::FloatRectangle rect1= obj1->GetAbsoluteBounds();
223                         Tizen::Graphics::FloatRectangle rect2= obj2->GetAbsoluteBounds();
224
225                         if (rect1.y > rect2.y)
226                         {
227                                 cmp = 1;
228                                 return E_SUCCESS;
229                         }
230                         else if (rect1.y < rect2.y)
231                         {
232                                 cmp = -1;
233                                 return E_SUCCESS;
234                         }
235                         else
236                         {
237                                 if (rect1.x > rect2.x)
238                                 {
239                                         cmp = 1;
240                                         return E_SUCCESS;
241                                 }
242                                 else if (rect1.x < rect2.x)
243                                 {
244                                         cmp = -1;
245                                         return E_SUCCESS;
246                                 }
247                                 else
248                                 {
249                                         cmp = 0;
250                                         return E_SUCCESS;
251                                 }
252                         }
253                 }
254         }
255 };
256
257 static _AccessibilityManager* pAccManager = null;
258 bool _AccessibilityManager::__screenReaderIsEnabled = false;
259 _AccessibilityManager::_AccessibilityManager(void)
260         : __pAccGesture(null)
261         , __pTtsPlayer(null)
262         , __pSettingLoader(null)
263         , __pTargetContainer(null)
264         , __pTargetElement(null)
265         , __pTitleElement(null)
266         , __containerList()
267         , __candidateList()
268         , __mode(MODE_NONE)
269         , __pReadingVe(null)
270         , __pFocusVe(null)
271         , __pPanningControl(null)
272 {
273         Initialize();
274 }
275 _AccessibilityManager::~_AccessibilityManager(void)
276 {
277         delete __pAccGesture;
278         __pAccGesture = null;
279         delete __pTtsPlayer;
280         __pTtsPlayer = null;
281         delete __pSettingLoader;
282         __pSettingLoader = null;
283         delete pGuidePopupTimer;
284         pGuidePopupTimer = null;
285         delete pAutoReadingTimer;
286         pAutoReadingTimer = null;
287 }
288
289 _AccessibilityManager*
290 _AccessibilityManager::GetInstance(void)
291 {
292         return pAccManager;
293 }
294
295 void
296 _AccessibilityManager::CreateInstance(void)
297 {
298         static pthread_once_t onceBlock = PTHREAD_ONCE_INIT;
299
300         if (pAccManager == null)
301         {
302                 pthread_once(&onceBlock, InitializeInstance);
303         }
304 }
305
306 void
307 _AccessibilityManager::InitializeInstance(void)
308 {
309         pAccManager = new (std::nothrow) _AccessibilityManager;
310 }
311 void
312 _AccessibilityManager::ReleaseInstance(void)
313 {
314         delete pAccManager;
315         pAccManager = null;
316 }
317 void
318 _AccessibilityManager::Initialize(void)
319 {
320         __pAccGesture = new (std::nothrow) _AccessibilityGesture(*this);
321         SysTryReturn(NID_UI, __pAccGesture, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed");
322         __pTtsPlayer = new (std::nothrow) _AccessibilityTtsPlayer(*this);
323         SysTryCatch(NID_UI, __pTtsPlayer, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed");
324         __pTtsPlayer->Construct();
325         __pSettingLoader = new (std::nothrow) _AccessibilitySystemSettingLoader(*this);
326         SysTryCatch(NID_UI, __pSettingLoader, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed");
327
328         if (IsScreenReaderActivated())
329         {
330                 __pTtsPlayer->SetLocale(__pSettingLoader->GetLocale());
331                 __pTtsPlayer->Activate();
332         }
333         pGuidePopupTimer = new (std::nothrow) GuidePopupTimer;
334         SysTryCatch(NID_UI, pGuidePopupTimer, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed");
335         pAutoReadingTimer = new (std::nothrow) AutoReadingTimer(this);
336         SysTryCatch(NID_UI, pAutoReadingTimer, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed");
337         return;
338
339 CATCH:
340         delete __pAccGesture;
341         __pAccGesture = null;
342         delete __pTtsPlayer;
343         __pTtsPlayer = null;
344         delete __pSettingLoader;
345         __pSettingLoader = null;
346         delete pGuidePopupTimer;
347         pGuidePopupTimer = null;
348         delete pAutoReadingTimer;
349         pAutoReadingTimer = null;
350 }
351 AccessibilityScreenReaderStatus
352 _AccessibilityManager::GetTtsStatus(void)
353 {
354         if (__pTtsPlayer)
355         {
356                 return __pTtsPlayer->GetStatus();
357         }
358         return ACCESSIBILITY_SCREEN_READER_STATUS_ERROR;
359 }
360 result
361 _AccessibilityManager::ReadContent(const Tizen::Base::String& content)
362 {
363         if (__pTtsPlayer)
364         {
365                 ShowPopup(content);
366                 __pTtsPlayer->ReadGrammar(content);
367         }
368         return E_SUCCESS;
369 }
370 void
371 _AccessibilityManager::ReadElement(_AccessibilityAutoReadingMode mode)
372 {
373         MakeList();
374         int count = __candidateList.GetCount();
375         if (count < 1)
376         {
377                 return;
378         }
379         _AccessibilityElement* pElement = null;
380         result r = E_SYSTEM;
381
382         if (mode == _ACCESSIBILITY_AUTO_READING_MODE_FIRST_ITEM)
383         {
384                 r = __candidateList.GetAt(0, pElement);
385         }
386         else if (mode == _ACCESSIBILITY_AUTO_READING_MODE_FIRST_ITEM_OF_CONTENTS)
387         {
388                 for (int i = 0 ; i < count ; i++)
389                 {
390                         r = __candidateList.GetAt(i, pElement);
391                         if (r == E_SUCCESS && pElement)
392                         {
393                                 if (pElement->GetParent()->GetPriority() < ACCESSIBILITY_PRIORITY_TOP)
394                                 {
395                                         break;
396                                 }
397                         }
398                 }
399         }
400         else //_ACCESSIBILITY_AUTO_READING_MODE_CURRENT_FOCUS
401         {
402                 if (IsContainerValid(__pTargetContainer))
403                 {
404                         pElement = __pTargetElement;
405                         r = E_SUCCESS;
406                 }
407         }
408         if (r != E_SUCCESS || pElement == null)
409         {
410                 SysLog(NID_UI, "cause 1");
411                 return;
412         }
413         if (mode == _ACCESSIBILITY_AUTO_READING_MODE_FIRST_ITEM && __pTitleElement == pElement && !(__pTitleElement->IsUpdated()))
414         {
415                 SysLog(NID_UI, "cause 2");
416                 return;
417         }
418         __pTitleElement = pElement;
419         pElement->GetParent()->SetCurrentFocusedElement(pElement);
420         DrawFocusUi(*pElement);
421         __pTargetContainer = pElement->GetParent();
422         __pTargetElement = pElement;
423         __targetControlHandle = __pTargetContainer->GetOwner().GetHandle();
424         ReadElement(*pElement);
425 }
426
427 result
428 _AccessibilityManager::ReadElement(const _AccessibilityElement& element)
429 {
430         if (__pTtsPlayer)
431         {
432                 LinkedListT<_IAccessibilityListener*>* pList = static_cast<LinkedListT<_IAccessibilityListener*>*>(__pTargetContainer->GetListenerListN());
433                 if (pList != null)
434                 {
435                         for (int i = 0;i<pList->GetCount();i++)
436                         {
437                                 _IAccessibilityListener* pListener = null;
438                                 if (pList->GetAt(i, pListener) == E_SUCCESS)
439                                 {
440                                         pListener->OnAccessibilityReadingElement(*__pTargetContainer, element);
441                                 }
442                         }
443                         delete pList;
444                         pList = null;
445                 }
446                 ShowPopup();
447                 __pTtsPlayer->ReadGrammar(element.GetReadingContents());
448         }
449         return E_SUCCESS;
450 }
451 result
452 _AccessibilityManager::ReadingStop(void)
453 {
454         return E_SUCCESS;
455 }
456 result
457 _AccessibilityManager::ReadingPause(void)
458 {
459         return E_SUCCESS;
460 }
461 result
462 _AccessibilityManager::ReadingResume(void)
463 {
464         return E_SUCCESS;
465 }
466
467 void
468 _AccessibilityManager::OnStartReading(const Tizen::Base::String& grammar)
469 {
470 }
471 void
472 _AccessibilityManager::HidePopup(void)
473 {
474         if (__pReadingVe)
475         {
476                 __pReadingVe->Destroy();
477                 __pReadingVe = null;
478         }
479         pGuidePopupTimer->Stop();
480 }
481 void
482 _AccessibilityManager::ShowPopup(const String& content)
483 {
484         if (content.IsEmpty())
485         {
486                 return;
487         }
488         utsname sysInfo;
489         uname(&sysInfo);
490         if (String("i686_emulated") != sysInfo.machine)
491         {
492                 return;
493         }
494         Canvas* pCanvas = null;
495         Bitmap* pBgBitmap = null;
496         EnrichedText* pEnrichedTitleText = null;
497         EnrichedText* pText = null;
498         Frame* pFrame = null;
499
500         if (__pReadingVe == null)
501         {
502                 pFrame = UiApp::GetInstance()->GetAppFrame()->GetFrame();
503
504                 if (pFrame != null)
505                 {
506                         int accesibilityVisualElementLevel = 3000;
507                         result r = E_SUCCESS;
508                         VisualElement* pRootVe = _ControlManager::GetInstance()->GetTopVisibleWindow()->GetVisualElement();
509
510                         __pReadingVe = new (std::nothrow) VisualElement();
511                         SysTryCatch(NID_UI, __pReadingVe, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed");
512
513                         r = __pReadingVe->Construct();
514                         SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] System error");
515                         __pReadingVe->SetName("Accessibility reading popup");
516                         _VisualElementImpl::GetInstance(*__pReadingVe)->SetZOrderGroup(accesibilityVisualElementLevel);
517                         pRootVe->AttachChild(*__pReadingVe);
518                 }
519         }
520         if (__pReadingVe)
521         {
522                 result r = E_SUCCESS;
523
524                 float titleFontSize = 0;
525                 float textFontSize = 0;
526                 float popupWidth = 0;
527                 float topMargin = 0;
528                 float bottomMargin = 0;
529                 float sideMargin = 0;
530                 float titleHeight = 0;
531                 float textTopMargin = 0;
532                 float textHeight = 0;
533
534                 Color titleTextColor;
535                 Color pointTextColor;
536                 Color textColor;
537                 TextElement* pElement = null;
538
539                 r = GET_SHAPE_CONFIG(ACCESSIBILITY::TITLE_FONT_SIZE, _CONTROL_ORIENTATION_PORTRAIT, titleFontSize);
540                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
541                 r = GET_SHAPE_CONFIG(ACCESSIBILITY::TEXT_FONT_SIZE, _CONTROL_ORIENTATION_PORTRAIT, textFontSize);
542                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
543                 r = GET_SHAPE_CONFIG(ACCESSIBILITY::POPUP_WIDTH, _CONTROL_ORIENTATION_PORTRAIT, popupWidth);
544                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
545                 r = GET_SHAPE_CONFIG(ACCESSIBILITY::TOP_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, topMargin);
546                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
547                 r = GET_SHAPE_CONFIG(ACCESSIBILITY::BOTTON_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, bottomMargin);
548                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
549                 r = GET_SHAPE_CONFIG(ACCESSIBILITY::SIDE_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, sideMargin);
550                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
551                 r = GET_SHAPE_CONFIG(ACCESSIBILITY::TITLE_HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, titleHeight);
552                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
553                 r = GET_SHAPE_CONFIG(ACCESSIBILITY::TEXT_TOP_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, textTopMargin);
554                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
555                 r = GET_SHAPE_CONFIG(ACCESSIBILITY::TEXT_HEGIHT, _CONTROL_ORIENTATION_PORTRAIT, textHeight);
556                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
557                 r = GET_COLOR_CONFIG(ACCESSIBILITY::TITLE_TEXT, titleTextColor);
558                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
559                 r = GET_COLOR_CONFIG(ACCESSIBILITY::POINT_TEXT, pointTextColor);
560                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
561                 r = GET_COLOR_CONFIG(ACCESSIBILITY::TEXT, textColor);
562                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
563                 r = GET_BITMAP_CONFIG_N(ACCESSIBILITY::POPUP_BG, BITMAP_PIXEL_FORMAT_ARGB8888, pBgBitmap);
564                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
565
566                 Font titleFont;
567                 r = titleFont.Construct(FONT_STYLE_PLAIN, titleFontSize);
568                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
569                 Font textFont;
570                 r = textFont.Construct(FONT_STYLE_PLAIN, textFontSize);
571                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
572
573                 pEnrichedTitleText = new (std::nothrow) EnrichedText;
574                 SysTryCatch(NID_UI, pEnrichedTitleText != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed");
575                 pEnrichedTitleText->Construct(FloatDimension(popupWidth-sideMargin*2, titleHeight));
576
577                 pText = new (std::nothrow) EnrichedText;
578                 SysTryCatch(NID_UI, pText != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed");
579                 pText->Construct(FloatDimension(popupWidth-sideMargin*2, textHeight));
580
581                 pElement = new (std::nothrow) TextElement;
582                 SysTryCatch(NID_UI, pElement != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed");
583                 r = pElement->Construct(L"Screen reading...");
584                 if (r != E_SUCCESS)
585                 {
586                         delete pElement;
587                         goto CATCH;
588                 }
589                 pElement->SetTextColor(titleTextColor);
590                 pElement->SetFont(titleFont);
591                 r = pEnrichedTitleText->Add(*pElement);
592                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
593                 pEnrichedTitleText->SetHorizontalAlignment(TEXT_ALIGNMENT_LEFT);
594                 pEnrichedTitleText->SetVerticalAlignment(TEXT_ALIGNMENT_TOP);
595                 pEnrichedTitleText->SetTextWrapStyle(TEXT_WRAP_CHARACTER_WRAP);
596                 pEnrichedTitleText->SetTextAbbreviationEnabled(true);
597
598                 pElement = new (std::nothrow) TextElement;
599                 SysTryCatch(NID_UI, pElement != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed");
600                 r = pElement->Construct(content);
601                 if (r != E_SUCCESS)
602                 {
603                         delete pElement;
604                         goto CATCH;
605                 }
606                 pElement->SetTextColor(textColor);
607                 pElement->SetFont(textFont);
608                 r = pText->Add(*pElement);
609                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
610                 pText->SetHorizontalAlignment(TEXT_ALIGNMENT_LEFT);
611                 pText->SetVerticalAlignment(TEXT_ALIGNMENT_TOP);
612                 pText->SetTextWrapStyle(TEXT_WRAP_CHARACTER_WRAP);
613                 pText->SetTextAbbreviationEnabled(true);
614
615                 float x = 40;
616                 float y = 200;
617                 float popupHeight = topMargin + bottomMargin + titleHeight + textTopMargin + textHeight;
618
619                 FloatDimension screen = Tizen::Ui::_ControlManager::GetInstance()->GetScreenSizeF();
620                 __pReadingVe->SetBounds(FloatRectangle(x, y, popupWidth, popupHeight));
621                 pCanvas = __pReadingVe->GetCanvasN();
622                 SysTryCatch(NID_UI, pCanvas != null, , E_SYSTEM, "System error for accessibility popup");
623                 pCanvas->DrawNinePatchedBitmap(FloatRectangle(0, 0, popupWidth, popupHeight), *pBgBitmap);
624                 float drawingTextY = topMargin;
625                 pCanvas->DrawText(FloatPoint(sideMargin, drawingTextY), *pEnrichedTitleText);
626                 drawingTextY += textTopMargin + titleHeight;
627                 pCanvas->DrawText(FloatPoint(sideMargin, drawingTextY), *pText);
628                 __pReadingVe->SetShowState(true);
629                 __pReadingVe->SetFlushNeeded();
630                 pGuidePopupTimer->SetElement(__pReadingVe);
631
632         }
633 CATCH:
634         delete pCanvas;
635         pCanvas = null;
636         delete pBgBitmap;
637         pBgBitmap = null;
638         if (pEnrichedTitleText)
639         {
640                 pEnrichedTitleText->RemoveAll(true);
641                 delete pEnrichedTitleText;
642         }
643         if (pText)
644         {
645                 pText->RemoveAll(true);
646                 delete pText;
647         }
648
649         return;
650
651 }
652 void
653 _AccessibilityManager::ShowPopup()
654 {
655         if (__pTargetElement == null)
656         {
657                 return;
658         }
659         utsname sysInfo;
660         uname(&sysInfo);
661         Frame* pFrame = null;
662         Canvas* pCanvas = null;
663         Bitmap* pBgBitmap = null;
664         EnrichedText* pEnrichedTitleText = null;
665         EnrichedText* pEnrichedNameText = null;
666         EnrichedText* pEnrichedLableText = null;
667         EnrichedText* pEnrichedTraitText = null;
668         EnrichedText* pEnrichedStatusText = null;
669         EnrichedText* pEnrichedHintText = null;
670         EnrichedText* pEnrichedValueText = null;
671         EnrichedText* pEnrichedBoundsText = null;
672         EnrichedText* pEnrichedAbsBoundsText = null;
673         TextElement* pElement = null;
674         FloatDimension screen;
675
676         if (String("i686_emulated") != sysInfo.machine)
677         {
678                 return;
679         }
680
681         if (__pReadingVe == null)
682         {
683                 pFrame = UiApp::GetInstance()->GetAppFrame()->GetFrame();
684
685                 if (pFrame != null)
686                 {
687                         int accesibilityVisualElementLevel = 3000;
688                         result r = E_SUCCESS;
689                         VisualElement* pRootVe = _ControlManager::GetInstance()->GetTopVisibleWindow()->GetVisualElement();
690
691                         __pReadingVe = new (std::nothrow) VisualElement();
692                         SysTryCatch(NID_UI, __pReadingVe, , E_SYSTEM, "[E_SYSTEM] System error");
693
694                         r = __pReadingVe->Construct();
695                         SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] System error");
696                         __pReadingVe->SetName("Accessibility reading popup");
697                         _VisualElementImpl::GetInstance(*__pReadingVe)->SetZOrderGroup(accesibilityVisualElementLevel);
698                         pRootVe->AttachChild(*__pReadingVe);
699                 }
700         }
701
702         screen = _ControlManager::GetInstance()->GetScreenSizeF();
703         if (__pReadingVe)
704         {
705                 result r = E_SUCCESS;
706
707                 float titleFontSize = 0;
708                 float textFontSize = 0;
709                 float popupWidth = 0;
710                 float topMargin = 0;
711                 float bottomMargin = 0;
712                 float sideMargin = 0;
713                 float titleHeight = 0;
714                 float textTopMargin = 0;
715                 float textHeight = 0;
716
717                 Color titleTextColor;
718                 Color pointTextColor;
719                 Color textColor;
720
721                 r = GET_SHAPE_CONFIG(ACCESSIBILITY::TITLE_FONT_SIZE, _CONTROL_ORIENTATION_PORTRAIT, titleFontSize);
722                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
723                 r = GET_SHAPE_CONFIG(ACCESSIBILITY::TEXT_FONT_SIZE, _CONTROL_ORIENTATION_PORTRAIT, textFontSize);
724                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
725                 r = GET_SHAPE_CONFIG(ACCESSIBILITY::POPUP_WIDTH, _CONTROL_ORIENTATION_PORTRAIT, popupWidth);
726                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
727                 r = GET_SHAPE_CONFIG(ACCESSIBILITY::TOP_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, topMargin);
728                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
729                 r = GET_SHAPE_CONFIG(ACCESSIBILITY::BOTTON_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, bottomMargin);
730                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
731                 r = GET_SHAPE_CONFIG(ACCESSIBILITY::SIDE_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, sideMargin);
732                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
733                 r = GET_SHAPE_CONFIG(ACCESSIBILITY::TITLE_HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, titleHeight);
734                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
735                 r = GET_SHAPE_CONFIG(ACCESSIBILITY::TEXT_TOP_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, textTopMargin);
736                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
737                 r = GET_SHAPE_CONFIG(ACCESSIBILITY::TEXT_HEGIHT, _CONTROL_ORIENTATION_PORTRAIT, textHeight);
738                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
739                 r = GET_COLOR_CONFIG(ACCESSIBILITY::TITLE_TEXT, titleTextColor);
740                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
741                 r = GET_COLOR_CONFIG(ACCESSIBILITY::POINT_TEXT, pointTextColor);
742                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
743                 r = GET_COLOR_CONFIG(ACCESSIBILITY::TEXT, textColor);
744                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
745                 r = GET_BITMAP_CONFIG_N(ACCESSIBILITY::POPUP_BG, BITMAP_PIXEL_FORMAT_ARGB8888, pBgBitmap);
746                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
747
748                 Font titleFont;
749                 r = titleFont.Construct(FONT_STYLE_PLAIN, titleFontSize);
750                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
751
752                 Font textFont;
753                 r = textFont.Construct(FONT_STYLE_PLAIN, textFontSize);
754                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
755
756                 pEnrichedTitleText = new (std::nothrow) EnrichedText;
757                 SysTryCatch(NID_UI, pEnrichedTitleText != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed");
758                 pEnrichedTitleText->Construct(FloatDimension(popupWidth-sideMargin*2, titleHeight));
759
760                 pEnrichedNameText = new (std::nothrow) EnrichedText;
761                 SysTryCatch(NID_UI, pEnrichedNameText != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed");
762                 pEnrichedNameText->Construct(FloatDimension(popupWidth-sideMargin*2, textHeight));
763
764                 pEnrichedLableText = new (std::nothrow) EnrichedText;
765                 SysTryCatch(NID_UI, pEnrichedLableText != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed");
766                 pEnrichedLableText->Construct(FloatDimension(popupWidth-sideMargin*2, textHeight));
767
768                 pEnrichedTraitText = new (std::nothrow) EnrichedText;
769                 SysTryCatch(NID_UI, pEnrichedTraitText != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed.");
770                 pEnrichedTraitText->Construct(FloatDimension(popupWidth-sideMargin*2, textHeight));
771
772                 pEnrichedStatusText = new (std::nothrow) EnrichedText;
773                 SysTryCatch(NID_UI, pEnrichedStatusText != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed.");
774                 pEnrichedStatusText->Construct(FloatDimension(popupWidth-sideMargin*2, textHeight));
775
776                 pEnrichedHintText = new (std::nothrow) EnrichedText;
777                 SysTryCatch(NID_UI, pEnrichedHintText != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed.");
778                 pEnrichedHintText->Construct(FloatDimension(popupWidth-sideMargin*2, textHeight));
779
780                 pEnrichedValueText = new (std::nothrow) EnrichedText;
781                 SysTryCatch(NID_UI, pEnrichedValueText != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed.");
782                 pEnrichedValueText->Construct(FloatDimension(popupWidth-sideMargin*2, textHeight));
783
784                 pEnrichedBoundsText = new (std::nothrow) EnrichedText;
785                 SysTryCatch(NID_UI, pEnrichedBoundsText != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed.");
786                 pEnrichedBoundsText->Construct(FloatDimension(popupWidth-sideMargin*2, textHeight));
787
788                 pEnrichedAbsBoundsText = new (std::nothrow) EnrichedText;
789                 SysTryCatch(NID_UI, pEnrichedAbsBoundsText != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed.");
790                 pEnrichedAbsBoundsText->Construct(FloatDimension(popupWidth-sideMargin*2, textHeight));
791
792                 pElement = new (std::nothrow) TextElement;
793                 r = pElement->Construct(L"Screen reading...");
794                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
795                 pElement->SetTextColor(titleTextColor);
796                 pElement->SetFont(titleFont);
797                 r = pEnrichedTitleText->Add(*pElement);
798
799                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
800                 pEnrichedTitleText->SetHorizontalAlignment(TEXT_ALIGNMENT_LEFT);
801                 pEnrichedTitleText->SetVerticalAlignment(TEXT_ALIGNMENT_TOP);
802                 pEnrichedTitleText->SetTextWrapStyle(TEXT_WRAP_CHARACTER_WRAP);
803                 pEnrichedTitleText->SetTextAbbreviationEnabled(true);
804
805                 pElement  = new (std::nothrow) TextElement;
806                 r = pElement->Construct(L"Name: ");
807                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
808
809                 pElement->SetTextColor(pointTextColor);
810                 pElement->SetFont(textFont);
811                 r = pEnrichedNameText->Add(*pElement);
812                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
813
814                 if (!(__pTargetElement->GetName().IsEmpty()))
815                 {
816                         pElement  = new (std::nothrow) TextElement;
817                         r = pElement->Construct(__pTargetElement->GetName());
818                         SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
819
820                         pElement->SetTextColor(textColor);
821                         pElement->SetFont(textFont);
822                         r = pEnrichedNameText->Add(*pElement);
823                         SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
824                         SysLog(NID_UI, " Name :::::: %s", _StringConverter::CopyToCharArrayN(__pTargetElement->GetName()));
825                 }
826                 pEnrichedNameText->SetHorizontalAlignment(TEXT_ALIGNMENT_LEFT);
827                 pEnrichedNameText->SetVerticalAlignment(TEXT_ALIGNMENT_TOP);
828                 pEnrichedNameText->SetTextWrapStyle(TEXT_WRAP_CHARACTER_WRAP);
829                 pEnrichedNameText->SetTextAbbreviationEnabled(true);
830
831                 pElement  = new (std::nothrow) TextElement;
832                 SysTryCatch(NID_UI, pElement != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed");
833                 r = pElement->Construct(L"Label: ");
834                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
835
836                 pElement->SetTextColor(pointTextColor);
837                 pElement->SetFont(textFont);
838                 r = pEnrichedLableText->Add(*pElement);
839                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
840
841                 if (!(__pTargetElement->GetLabel().IsEmpty()))
842                 {
843                         pElement  = new (std::nothrow) TextElement;
844                         SysTryCatch(NID_UI, pElement != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed");
845                         r = pElement->Construct(__pTargetElement->GetLabel());
846                         SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
847
848                         pElement->SetTextColor(textColor);
849                         pElement->SetFont(textFont);
850                         r = pEnrichedLableText->Add(*pElement);
851                         SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
852                         SysLog(NID_UI, " Label :::::: %s", _StringConverter::CopyToCharArrayN(__pTargetElement->GetLabel()));
853                 }
854                 pEnrichedLableText->SetHorizontalAlignment(TEXT_ALIGNMENT_LEFT);
855                 pEnrichedLableText->SetVerticalAlignment(TEXT_ALIGNMENT_TOP);
856                 pEnrichedLableText->SetTextWrapStyle(TEXT_WRAP_CHARACTER_WRAP);
857                 pEnrichedLableText->SetTextAbbreviationEnabled(true);
858
859                 pElement  = new (std::nothrow) TextElement;
860                 SysTryCatch(NID_UI, pElement != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed");
861                 r = pElement->Construct(L"Trait: ");
862                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
863
864                 pElement->SetTextColor(pointTextColor);
865                 pElement->SetFont(textFont);
866                 r = pEnrichedTraitText->Add(*pElement);
867                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
868                 if (!(__pTargetElement->GetTraitString().IsEmpty()))
869                 {
870                         pElement  = new (std::nothrow) TextElement;
871                         SysTryCatch(NID_UI, pElement != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed");
872                         r = pElement->Construct(__pTargetElement->GetTraitString());
873                         SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
874
875                         pElement->SetTextColor(textColor);
876                         pElement->SetFont(textFont);
877                         r = pEnrichedTraitText->Add(*pElement);
878                         SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
879                 }
880                 pEnrichedTraitText->SetHorizontalAlignment(TEXT_ALIGNMENT_LEFT);
881                 pEnrichedTraitText->SetVerticalAlignment(TEXT_ALIGNMENT_TOP);
882                 pEnrichedTraitText->SetTextWrapStyle(TEXT_WRAP_CHARACTER_WRAP);
883                 pEnrichedTraitText->SetTextAbbreviationEnabled(true);
884
885                 pElement  = new (std::nothrow) TextElement;
886                 SysTryCatch(NID_UI, pElement != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed");
887                 r = pElement->Construct(L"Status: ");
888                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
889
890                 pElement->SetTextColor(pointTextColor);
891                 pElement->SetFont(textFont);
892                 r = pEnrichedStatusText->Add(*pElement);
893                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
894                 if (!(__pTargetElement->GetStatus().IsEmpty()))
895                 {
896                         pElement  = new (std::nothrow) TextElement;
897                         SysTryCatch(NID_UI, pElement != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed");
898                         r = pElement->Construct(__pTargetElement->GetStatus());
899                         SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
900
901                         pElement->SetTextColor(textColor);
902                         pElement->SetFont(textFont);
903                         r = pEnrichedStatusText->Add(*pElement);
904                         SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
905                 }
906                 pEnrichedStatusText->SetHorizontalAlignment(TEXT_ALIGNMENT_LEFT);
907                 pEnrichedStatusText->SetVerticalAlignment(TEXT_ALIGNMENT_TOP);
908                 pEnrichedStatusText->SetTextWrapStyle(TEXT_WRAP_CHARACTER_WRAP);
909                 pEnrichedStatusText->SetTextAbbreviationEnabled(true);
910
911                 pElement  = new (std::nothrow) TextElement;
912                 SysTryCatch(NID_UI, pElement != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed");
913                 r = pElement->Construct(L"Hint: ");
914                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
915
916                 pElement->SetTextColor(pointTextColor);
917                 pElement->SetFont(textFont);
918                 r = pEnrichedHintText->Add(*pElement);
919                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
920                 if (!(__pTargetElement->GetHint().IsEmpty()))
921                 {
922                         pElement  = new (std::nothrow) TextElement;
923                         SysTryCatch(NID_UI, pElement != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed");
924                         r = pElement->Construct(__pTargetElement->GetHint());
925                         SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
926
927                         pElement->SetTextColor(textColor);
928                         pElement->SetFont(textFont);
929                         r = pEnrichedHintText->Add(*pElement);
930                         SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
931                 }
932                 pEnrichedHintText->SetHorizontalAlignment(TEXT_ALIGNMENT_LEFT);
933                 pEnrichedHintText->SetVerticalAlignment(TEXT_ALIGNMENT_TOP);
934                 pEnrichedHintText->SetTextWrapStyle(TEXT_WRAP_CHARACTER_WRAP);
935                 pEnrichedHintText->SetTextAbbreviationEnabled(true);
936
937                 pElement  = new (std::nothrow) TextElement;
938                 SysTryCatch(NID_UI, pElement != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed");
939                 r = pElement->Construct(L"Value: ");
940                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
941
942                 pElement->SetTextColor(pointTextColor);
943                 pElement->SetFont(textFont);
944                 r = pEnrichedValueText->Add(*pElement);
945                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
946                 if (!(__pTargetElement->GetValue().IsEmpty()))
947                 {
948                         pElement  = new (std::nothrow) TextElement;
949                         SysTryCatch(NID_UI, pElement != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed");
950                         r = pElement->Construct(__pTargetElement->GetValue());
951                         SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
952
953                         pElement->SetTextColor(textColor);
954                         pElement->SetFont(textFont);
955                         r = pEnrichedValueText->Add(*pElement);
956                         SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
957                 }
958                 pEnrichedValueText->SetHorizontalAlignment(TEXT_ALIGNMENT_LEFT);
959                 pEnrichedValueText->SetVerticalAlignment(TEXT_ALIGNMENT_TOP);
960                 pEnrichedValueText->SetTextWrapStyle(TEXT_WRAP_CHARACTER_WRAP);
961                 pEnrichedValueText->SetTextAbbreviationEnabled(true);
962
963                 pElement  = new (std::nothrow) TextElement;
964                 SysTryCatch(NID_UI, pElement != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed");
965                 r = pElement->Construct(L"Bound: ");
966                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
967
968                 pElement->SetTextColor(pointTextColor);
969                 pElement->SetFont(textFont);
970                 r = pEnrichedBoundsText->Add(*pElement);
971                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
972
973                 pElement  = new (std::nothrow) TextElement;
974                 SysTryCatch(NID_UI, pElement != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed");
975                 FloatRectangle rect = __pTargetElement->GetBounds();
976                 String rectString;
977                 rectString.Format(40, L"x:%f, y:%f, w:%f, h:%f", rect.x, rect.y, rect.width, rect.height);
978                 r = pElement->Construct(rectString);
979                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
980
981                 pElement->SetTextColor(textColor);
982                 pElement->SetFont(textFont);
983                 r = pEnrichedBoundsText->Add(*pElement);
984                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
985                 pEnrichedBoundsText->SetHorizontalAlignment(TEXT_ALIGNMENT_LEFT);
986                 pEnrichedBoundsText->SetVerticalAlignment(TEXT_ALIGNMENT_TOP);
987                 pEnrichedBoundsText->SetTextWrapStyle(TEXT_WRAP_CHARACTER_WRAP);
988                 pEnrichedBoundsText->SetTextAbbreviationEnabled(true);
989
990                 pElement  = new (std::nothrow) TextElement;
991                 SysTryCatch(NID_UI, pElement != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed");
992                 r = pElement->Construct(L"AbsBound: ");
993                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
994
995                 pElement->SetTextColor(pointTextColor);
996                 pElement->SetFont(textFont);
997                 r = pEnrichedAbsBoundsText->Add(*pElement);
998                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
999
1000                 pElement  = new (std::nothrow) TextElement;
1001                 SysTryCatch(NID_UI, pElement != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed");
1002                 rect = __pTargetElement->GetAbsoluteBounds();
1003                 rectString.Clear();
1004                 rectString.Format(40, L"x:%f, y:%f, w:%f, h:%f", rect.x, rect.y, rect.width, rect.height);
1005                 r = pElement->Construct(rectString);
1006                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
1007
1008                 pElement->SetTextColor(textColor);
1009                 pElement->SetFont(textFont);
1010                 r = pEnrichedAbsBoundsText->Add(*pElement);
1011                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "System error for accessibility popup");
1012                 pEnrichedAbsBoundsText->SetHorizontalAlignment(TEXT_ALIGNMENT_LEFT);
1013                 pEnrichedAbsBoundsText->SetVerticalAlignment(TEXT_ALIGNMENT_TOP);
1014                 pEnrichedAbsBoundsText->SetTextWrapStyle(TEXT_WRAP_CHARACTER_WRAP);
1015                 pEnrichedAbsBoundsText->SetTextAbbreviationEnabled(true);
1016
1017                 float x = 0;
1018                 float y = 0;
1019                 float popupHeight = topMargin + bottomMargin + titleHeight + textTopMargin + textHeight * 8;
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         __focusedControlHandle = pControl->GetHandle();
1708         pControlVe->AttachChild(*__pFocusVe);
1709
1710         if (__pFocusVe)
1711         {
1712                 __pFocusVe->SetBounds(FloatRectangle(rectangle.x, rectangle.y, rectangle.width, rectangle.height));
1713                 pCanvas = __pFocusVe->GetCanvasN();
1714                 SysTryCatch(NID_UI, pCanvas, , E_SYSTEM, "[E_SYSTEM] System error");
1715                 pCanvas->SetBackgroundColor(0x00000000);
1716                 pCanvas->Clear();
1717                 Bitmap* pBitmap = null;
1718                 result r = GET_BITMAP_CONFIG_N(ACCESSIBILITY::FOCUS, BITMAP_PIXEL_FORMAT_ARGB8888, pBitmap);
1719                 if (r == E_SUCCESS)
1720                 {
1721                         if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pBitmap))
1722                         {
1723                                 r = pCanvas->DrawNinePatchedBitmap(Rectangle(0, 0, rectangle.width, rectangle.height), *pBitmap);
1724                                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] System error");
1725                         }
1726                         else
1727                         {
1728                                 r = pCanvas->DrawBitmap(Rectangle(0, 0, rectangle.width, rectangle.height), *pBitmap);
1729                                 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] System error");
1730                         }
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->GetLocale());
2081         }
2082 }
2083
2084 void
2085 _AccessibilityManager::OnAccessibilityScreenReaderIsActivated(bool set)
2086 {
2087         if (__screenReaderIsEnabled == set)
2088         {
2089                 return;
2090         }
2091         else
2092         {
2093                 __screenReaderIsEnabled = set;
2094                 if (__screenReaderIsEnabled)
2095                 {
2096                         if (__pTtsPlayer)
2097                         {
2098                                 __pTtsPlayer->SetLocale(__pSettingLoader->GetLocale());
2099                                 __pTtsPlayer->Activate();
2100                         }
2101                 }
2102                 else
2103                 {
2104                         __pTtsPlayer->Deactivate();
2105                 }
2106         }
2107 }
2108 bool
2109 _AccessibilityManager::IsAccessibilityActivated(void)
2110 {
2111         return __pSettingLoader->IsAccessibilityActivated();
2112 }
2113 bool
2114 _AccessibilityManager::IsScreenReaderActivated(void)
2115 {
2116         __screenReaderIsEnabled = __pSettingLoader->IsScreenReaderActivated();
2117         return __screenReaderIsEnabled;
2118 }
2119 float
2120 _AccessibilityManager::GetLargeFontSize(void)
2121 {
2122         return __pSettingLoader->GetLargeFontSize();
2123 }
2124
2125 bool
2126 _AccessibilityManager::IsActivated()
2127 {
2128         return __screenReaderIsEnabled;
2129 }
2130
2131 bool
2132 _AccessibilityManager::IsContainerValid(_AccessibilityContainer* pContainer)
2133 {
2134         if (pContainer == null)
2135         {
2136                 return false;
2137         }
2138         if (!(pContainer->IsActivated()))
2139         {
2140                 return false;
2141         }
2142         if (!(pContainer->GetHandle().IsValid()))
2143         {
2144                 return false;
2145         }
2146         if (!(pContainer->GetOwner().GetHandle().IsValid()))
2147         {
2148                 return false;
2149         }
2150         if (!(pContainer->GetOwner().IsVisible()))
2151         {
2152                 return false;
2153         }
2154         if (!IsVisible(pContainer))
2155         {
2156                 return false;
2157         }
2158         return true;
2159 }
2160 bool
2161 _AccessibilityManager::IsTargetContainerValid(void)
2162 {
2163
2164         if (__pTargetContainer && __targetControlHandle.IsValid() && __pTargetContainer->GetOwner().IsVisible() && __pTargetContainer->GetOwner().GetRootWindow() && IsVisible(__pTargetContainer))
2165         {
2166                 return true;
2167         }
2168         return false;
2169 }
2170 bool
2171 _AccessibilityManager::IsVisible(_AccessibilityElement* pElement)
2172 {
2173         return IsVisible(pElement->GetParent());
2174 }
2175 bool
2176 _AccessibilityManager::IsVisible(_AccessibilityContainer* pContainer)
2177 {
2178         _ControlManager* pControlManager = _ControlManager::GetInstance();
2179         int count = pControlManager->GetWindowCount();
2180         if (count < 1)
2181         {
2182                 return false;
2183         }
2184         _Window* pTopWindow = pControlManager->GetWindow(count - 1);
2185         if (pTopWindow != pContainer->GetOwner().GetRootWindow())
2186         {
2187                 return false;
2188         }
2189         return true;
2190 }
2191 void
2192 _AccessibilityManager::SetGestureMode(GestureMode mode)
2193 {
2194         __mode = mode;
2195 }
2196 _AccessibilityManager::GestureMode
2197 _AccessibilityManager::GetGestureMode(void)
2198 {
2199         return __mode;
2200 }
2201
2202 }} //Tizen::Ui
2203