Revert "Remove dali-core dependency of GLES version."
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / toolkit-accessibility-adaptor.cpp
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #include <dali/public-api/object/base-object.h>
19 #include <dali/integration-api/events/pan-gesture-event.h>
20 #include <dali/devel-api/adaptor-framework/accessibility-adaptor.h>
21 #include <dali/devel-api/adaptor-framework/accessibility-action-handler.h>
22 #include <dali/devel-api/adaptor-framework/accessibility-gesture-handler.h>
23
24 namespace Dali
25 {
26
27 namespace Internal
28 {
29
30 namespace Adaptor
31 {
32
33 /**
34  * Stub for the AccessibilityAdaptor
35  */
36 class AccessibilityAdaptor : public BaseObject
37 {
38 public: // Creation & Destruction
39
40   static Dali::AccessibilityAdaptor Get();
41
42   AccessibilityAdaptor();
43   ~AccessibilityAdaptor();
44
45 public:
46
47   // Functions to modify mock returns:
48
49   void MockSetReadPosition( Vector2& position );
50
51   void SetEnabled(bool enabled)
52   {
53     mIsEnabled = enabled;
54   }
55
56   void SendPanGesture( const Dali::Integration::PanGestureEvent& panEvent );
57
58 public:
59
60   bool IsEnabled() const;
61   void SetActionHandler(Dali::AccessibilityActionHandler& handler);
62   void SetGestureHandler(Dali::AccessibilityGestureHandler& handler);
63
64   Vector2 GetReadPosition() const;
65
66   bool HandleActionNextEvent(bool);
67   bool HandleActionPreviousEvent(bool);
68   bool HandleActionActivateEvent();
69   bool HandleActionReadEvent(unsigned int x, unsigned int y, bool allowReadAgain);
70   bool HandleActionReadNextEvent(bool);
71   bool HandleActionReadPreviousEvent(bool);
72   bool HandleActionUpEvent();
73   bool HandleActionDownEvent();
74   bool HandleActionClearFocusEvent();
75   bool HandleActionScrollEvent(const TouchPoint& point, unsigned long timeStamp);
76   bool HandleActionTouchEvent(const TouchPoint& point, unsigned long timeStamp);
77   bool HandleActionBackEvent();
78   bool HandleActionEnableEvent();
79   bool HandleActionDisableEvent();
80   bool HandleActionScrollUpEvent();
81   bool HandleActionScrollDownEvent();
82   bool HandleActionPageLeftEvent();
83   bool HandleActionPageRightEvent();
84   bool HandleActionPageUpEvent();
85   bool HandleActionPageDownEvent();
86   bool HandleActionMoveToFirstEvent();
87   bool HandleActionMoveToLastEvent();
88   bool HandleActionReadFromTopEvent();
89   bool HandleActionReadFromNextEvent();
90   bool HandleActionZoomEvent();
91   bool HandleActionReadPauseResumeEvent();
92   bool HandleActionStartStopEvent();
93
94 private:
95
96   bool mIsEnabled;
97   Dali::AccessibilityActionHandler* mActionHandler;
98   Dali::AccessibilityGestureHandler* mGestureHandler;
99   Vector2 mReadPosition;
100
101   static Dali::AccessibilityAdaptor mToolkitAccessibilityAdaptor;
102 };
103
104 Dali::AccessibilityAdaptor AccessibilityAdaptor::mToolkitAccessibilityAdaptor;
105
106
107 Dali::AccessibilityAdaptor AccessibilityAdaptor::Get()
108 {
109   if( !mToolkitAccessibilityAdaptor )
110   {
111     mToolkitAccessibilityAdaptor = Dali::AccessibilityAdaptor( new Dali::Internal::Adaptor::AccessibilityAdaptor() );
112   }
113   return mToolkitAccessibilityAdaptor;
114 }
115
116 AccessibilityAdaptor::AccessibilityAdaptor()
117 : mIsEnabled(false),
118   mActionHandler(NULL),
119   mGestureHandler(NULL),
120   mReadPosition( 0.0f, 0.0f )
121 {
122 }
123
124 AccessibilityAdaptor::~AccessibilityAdaptor()
125 {
126 }
127
128 Vector2 AccessibilityAdaptor::GetReadPosition() const
129 {
130   return mReadPosition;
131 }
132
133 void AccessibilityAdaptor::MockSetReadPosition( Vector2& position )
134 {
135   mReadPosition = position;
136 }
137
138 bool AccessibilityAdaptor::IsEnabled() const
139 {
140   return mIsEnabled;
141 }
142
143 void AccessibilityAdaptor::SendPanGesture( const Integration::PanGestureEvent& panEvent )
144 {
145   mGestureHandler->HandlePanGesture( panEvent );
146 }
147
148 void AccessibilityAdaptor::SetActionHandler(Dali::AccessibilityActionHandler& handler)
149 {
150   mActionHandler = &handler;
151 }
152
153 void AccessibilityAdaptor::SetGestureHandler(Dali::AccessibilityGestureHandler& handler)
154 {
155   mGestureHandler = &handler;
156 }
157
158 bool AccessibilityAdaptor::HandleActionNextEvent(bool allowEndFeedback)
159 {
160   if( mActionHandler )
161   {
162     return mActionHandler->AccessibilityActionNext( true );
163   }
164   return false;
165 }
166
167 bool AccessibilityAdaptor::HandleActionPreviousEvent(bool allowEndFeedback)
168 {
169   if( mActionHandler )
170   {
171     return mActionHandler->AccessibilityActionPrevious( true );
172   }
173   return false;
174 }
175
176 bool AccessibilityAdaptor::HandleActionActivateEvent()
177 {
178   if( mActionHandler )
179   {
180     return mActionHandler->AccessibilityActionActivate();
181   }
182   return false;
183 }
184
185 bool AccessibilityAdaptor::HandleActionReadEvent(unsigned int x, unsigned int y,  bool allowReadAgain)
186 {
187   if( mActionHandler )
188   {
189     return mActionHandler->AccessibilityActionRead( allowReadAgain );
190   }
191   return false;
192 }
193
194 bool AccessibilityAdaptor::HandleActionReadNextEvent(bool allowEndFeedback)
195 {
196   if( mActionHandler )
197   {
198     return mActionHandler->AccessibilityActionReadNext( true );
199   }
200   return false;
201 }
202
203 bool AccessibilityAdaptor::HandleActionReadPreviousEvent(bool allowEndFeedback)
204 {
205   if( mActionHandler )
206   {
207     return mActionHandler->AccessibilityActionReadPrevious( true );
208   }
209   return false;
210 }
211
212 bool AccessibilityAdaptor::HandleActionUpEvent()
213 {
214   if( mActionHandler )
215   {
216     return mActionHandler->AccessibilityActionUp();
217   }
218   return false;
219 }
220
221 bool AccessibilityAdaptor::HandleActionDownEvent()
222 {
223   if( mActionHandler )
224   {
225     return mActionHandler->AccessibilityActionDown();
226   }
227   return false;
228 }
229
230 bool AccessibilityAdaptor::HandleActionClearFocusEvent()
231 {
232   if( mActionHandler )
233   {
234     return mActionHandler->ClearAccessibilityFocus();
235   }
236   return false;
237 }
238
239 bool AccessibilityAdaptor::HandleActionScrollEvent(const TouchPoint& point, unsigned long timeStamp)
240 {
241   if( mActionHandler )
242   {
243     Dali::TouchEvent touchEvent;
244     touchEvent.points.push_back( point );
245     return mActionHandler->AccessibilityActionScroll( touchEvent );
246   }
247   return false;
248 }
249
250 bool AccessibilityAdaptor::HandleActionTouchEvent(const TouchPoint& point, unsigned long timeStamp)
251 {
252   if( mActionHandler )
253   {
254     Dali::TouchEvent touchEvent;
255     touchEvent.points.push_back( point );
256     return mActionHandler->AccessibilityActionTouch( touchEvent );
257   }
258   return false;
259 }
260
261 bool AccessibilityAdaptor::HandleActionBackEvent()
262 {
263   if( mActionHandler )
264   {
265     return mActionHandler->AccessibilityActionBack();
266   }
267   return false;
268 }
269
270 bool AccessibilityAdaptor::HandleActionEnableEvent()
271 {
272   if( mActionHandler )
273   {
274     return mActionHandler->ChangeAccessibilityStatus();
275   }
276   return false;
277 }
278
279 bool AccessibilityAdaptor::HandleActionDisableEvent()
280 {
281   if( mActionHandler )
282   {
283     return mActionHandler->ChangeAccessibilityStatus();
284   }
285   return false;
286 }
287
288 bool AccessibilityAdaptor::HandleActionScrollUpEvent()
289 {
290   if( mActionHandler )
291   {
292     return mActionHandler->AccessibilityActionScrollUp();
293   }
294   return false;
295 }
296
297 bool AccessibilityAdaptor::HandleActionScrollDownEvent()
298 {
299   if( mActionHandler )
300   {
301     return mActionHandler->AccessibilityActionScrollDown();
302   }
303   return false;
304 }
305
306 bool AccessibilityAdaptor::HandleActionPageLeftEvent()
307 {
308   if( mActionHandler )
309   {
310     return mActionHandler->AccessibilityActionPageLeft();
311   }
312   return false;
313 }
314
315 bool AccessibilityAdaptor::HandleActionPageRightEvent()
316 {
317   if( mActionHandler )
318   {
319     return mActionHandler->AccessibilityActionPageRight();
320   }
321   return false;
322 }
323
324 bool AccessibilityAdaptor::HandleActionPageUpEvent()
325 {
326   if( mActionHandler )
327   {
328     return mActionHandler->AccessibilityActionPageUp();
329   }
330   return false;
331 }
332
333 bool AccessibilityAdaptor::HandleActionPageDownEvent()
334 {
335   if( mActionHandler )
336   {
337     return mActionHandler->AccessibilityActionPageDown();
338   }
339   return false;
340 }
341
342 bool AccessibilityAdaptor::HandleActionMoveToFirstEvent()
343 {
344   if( mActionHandler )
345   {
346     return mActionHandler->AccessibilityActionMoveToFirst();
347   }
348   return false;
349 }
350
351 bool AccessibilityAdaptor::HandleActionMoveToLastEvent()
352 {
353   if( mActionHandler )
354   {
355     return mActionHandler->AccessibilityActionMoveToLast();
356   }
357   return false;
358 }
359
360 bool AccessibilityAdaptor::HandleActionReadFromTopEvent()
361 {
362   if( mActionHandler )
363   {
364     return mActionHandler->AccessibilityActionReadFromTop();
365   }
366   return false;
367 }
368
369 bool AccessibilityAdaptor::HandleActionReadFromNextEvent()
370 {
371   if( mActionHandler )
372   {
373     return mActionHandler->AccessibilityActionReadFromNext();
374   }
375   return false;
376 }
377
378 bool AccessibilityAdaptor::HandleActionZoomEvent()
379 {
380   if( mActionHandler )
381   {
382     return mActionHandler->AccessibilityActionZoom();
383   }
384   return false;
385 }
386
387 bool AccessibilityAdaptor::HandleActionReadPauseResumeEvent()
388 {
389   if( mActionHandler )
390   {
391     return mActionHandler->AccessibilityActionReadPauseResume();
392   }
393   return false;
394 }
395
396 bool AccessibilityAdaptor::HandleActionStartStopEvent()
397 {
398   if( mActionHandler )
399   {
400     return mActionHandler->AccessibilityActionStartStop();
401   }
402   return false;
403 }
404
405 static Internal::Adaptor::AccessibilityAdaptor& GetImplementation(Dali::AccessibilityAdaptor& adaptor)
406 {
407   BaseObject& handle = adaptor.GetBaseObject();
408   return static_cast<Internal::Adaptor::AccessibilityAdaptor&>(handle);
409 }
410
411 static const Internal::Adaptor::AccessibilityAdaptor& GetImplementation(const Dali::AccessibilityAdaptor& adaptor)
412 {
413   const BaseObject& handle = adaptor.GetBaseObject();
414   return static_cast<const Internal::Adaptor::AccessibilityAdaptor&>(handle);
415 }
416
417
418 } // namespace Adaptor
419 } // namespace Internal
420
421 ////////////////////////////////////////////////////////////////////////////////////////////////////
422
423 AccessibilityAdaptor::AccessibilityAdaptor()
424 {
425 }
426
427 AccessibilityAdaptor AccessibilityAdaptor::Get()
428 {
429   return Internal::Adaptor::AccessibilityAdaptor::Get();
430 }
431
432 AccessibilityAdaptor::~AccessibilityAdaptor()
433 {
434 }
435
436 // Methods:
437
438 Vector2 AccessibilityAdaptor::GetReadPosition() const
439 {
440   return Internal::Adaptor::GetImplementation(*this).GetReadPosition();
441 }
442
443 bool AccessibilityAdaptor::IsEnabled() const
444 {
445   return Internal::Adaptor::GetImplementation(*this).IsEnabled();
446 }
447
448 void AccessibilityAdaptor::SetActionHandler(AccessibilityActionHandler& handler)
449 {
450   Internal::Adaptor::GetImplementation(*this).SetActionHandler(handler);
451 }
452
453 void AccessibilityAdaptor::SetGestureHandler(AccessibilityGestureHandler& handler)
454 {
455   Internal::Adaptor::GetImplementation(*this).SetGestureHandler(handler);
456 }
457
458 bool AccessibilityAdaptor::HandleActionNextEvent(bool allowEndFeedback)
459 {
460   return Internal::Adaptor::GetImplementation(*this).HandleActionNextEvent(allowEndFeedback);
461 }
462
463 bool AccessibilityAdaptor::HandleActionPreviousEvent(bool allowEndFeedback)
464 {
465   return Internal::Adaptor::GetImplementation(*this).HandleActionPreviousEvent(allowEndFeedback);
466 }
467
468 bool AccessibilityAdaptor::HandleActionActivateEvent()
469 {
470   return Internal::Adaptor::GetImplementation(*this).HandleActionActivateEvent();
471 }
472
473 bool AccessibilityAdaptor::HandleActionReadEvent(unsigned int x, unsigned int y,  bool allowReadAgain)
474 {
475   return Internal::Adaptor::GetImplementation(*this).HandleActionReadEvent( x, y, allowReadAgain );
476 }
477
478 bool AccessibilityAdaptor::HandleActionReadNextEvent(bool allowEndFeedback)
479 {
480   return Internal::Adaptor::GetImplementation(*this).HandleActionReadNextEvent(allowEndFeedback);
481 }
482
483 bool AccessibilityAdaptor::HandleActionReadPreviousEvent(bool allowEndFeedback)
484 {
485   return Internal::Adaptor::GetImplementation(*this).HandleActionReadPreviousEvent(allowEndFeedback);
486 }
487
488 bool AccessibilityAdaptor::HandleActionUpEvent()
489 {
490   return Internal::Adaptor::GetImplementation(*this).HandleActionUpEvent();
491 }
492
493 bool AccessibilityAdaptor::HandleActionDownEvent()
494 {
495   return Internal::Adaptor::GetImplementation(*this).HandleActionDownEvent();
496 }
497
498 bool AccessibilityAdaptor::HandleActionClearFocusEvent()
499 {
500   return Internal::Adaptor::GetImplementation(*this).HandleActionClearFocusEvent();
501 }
502
503 bool AccessibilityAdaptor::HandleActionScrollEvent(const TouchPoint& point, unsigned long timeStamp)
504 {
505   return Internal::Adaptor::GetImplementation(*this).HandleActionScrollEvent(point, timeStamp);
506 }
507
508 bool AccessibilityAdaptor::HandleActionTouchEvent(const TouchPoint& point, unsigned long timeStamp)
509 {
510   return Internal::Adaptor::GetImplementation(*this).HandleActionTouchEvent(point, timeStamp);
511 }
512
513 bool AccessibilityAdaptor::HandleActionBackEvent()
514 {
515   return Internal::Adaptor::GetImplementation(*this).HandleActionBackEvent();
516 }
517
518 void AccessibilityAdaptor::HandleActionEnableEvent()
519 {
520   Internal::Adaptor::GetImplementation(*this).HandleActionEnableEvent();
521 }
522
523 void AccessibilityAdaptor::HandleActionDisableEvent()
524 {
525   Internal::Adaptor::GetImplementation(*this).HandleActionDisableEvent();
526 }
527
528 bool AccessibilityAdaptor::HandleActionScrollUpEvent()
529 {
530   return Internal::Adaptor::GetImplementation(*this).HandleActionScrollUpEvent();
531 }
532
533 bool AccessibilityAdaptor::HandleActionScrollDownEvent()
534 {
535   return Internal::Adaptor::GetImplementation(*this).HandleActionScrollDownEvent();
536 }
537
538 bool AccessibilityAdaptor::HandleActionPageLeftEvent()
539 {
540   return Internal::Adaptor::GetImplementation(*this).HandleActionPageLeftEvent();
541 }
542
543 bool AccessibilityAdaptor::HandleActionPageRightEvent()
544 {
545   return Internal::Adaptor::GetImplementation(*this).HandleActionPageRightEvent();
546 }
547
548 bool AccessibilityAdaptor::HandleActionPageUpEvent()
549 {
550   return Internal::Adaptor::GetImplementation(*this).HandleActionPageUpEvent();
551 }
552
553 bool AccessibilityAdaptor::HandleActionPageDownEvent()
554 {
555   return Internal::Adaptor::GetImplementation(*this).HandleActionPageDownEvent();
556 }
557
558 bool AccessibilityAdaptor::HandleActionMoveToFirstEvent()
559 {
560   return Internal::Adaptor::GetImplementation(*this).HandleActionMoveToFirstEvent();
561 }
562
563 bool AccessibilityAdaptor::HandleActionMoveToLastEvent()
564 {
565   return Internal::Adaptor::GetImplementation(*this).HandleActionMoveToLastEvent();
566 }
567
568 bool AccessibilityAdaptor::HandleActionReadFromTopEvent()
569 {
570   return Internal::Adaptor::GetImplementation(*this).HandleActionReadFromTopEvent();
571 }
572
573 bool AccessibilityAdaptor::HandleActionReadFromNextEvent()
574 {
575   return Internal::Adaptor::GetImplementation(*this).HandleActionReadFromNextEvent();
576 }
577
578 bool AccessibilityAdaptor::HandleActionZoomEvent()
579 {
580   return Internal::Adaptor::GetImplementation(*this).HandleActionZoomEvent();
581 }
582
583 bool AccessibilityAdaptor::HandleActionReadPauseResumeEvent()
584 {
585   return Internal::Adaptor::GetImplementation(*this).HandleActionReadPauseResumeEvent();
586 }
587
588 bool AccessibilityAdaptor::HandleActionStartStopEvent()
589 {
590   return Internal::Adaptor::GetImplementation(*this).HandleActionStartStopEvent();
591 }
592
593 AccessibilityAdaptor::AccessibilityAdaptor( Internal::Adaptor::AccessibilityAdaptor* adaptor )
594 : BaseHandle( adaptor )
595 {
596 }
597
598 } // namespace Dali
599
600
601 namespace Test
602 {
603 namespace AccessibilityAdaptor
604 {
605
606 // Mock setup:
607
608 void MockSetReadPosition( Dali::AccessibilityAdaptor adaptor, Dali::Vector2& position )
609 {
610   Dali::Internal::Adaptor::GetImplementation(adaptor).MockSetReadPosition( position );
611 }
612
613 void SetEnabled( Dali::AccessibilityAdaptor adaptor, bool enabled )
614 {
615   Dali::Internal::Adaptor::GetImplementation(adaptor).SetEnabled(enabled);
616 }
617
618 void SendPanGesture( Dali::AccessibilityAdaptor adaptor, const Dali::Integration::PanGestureEvent& panEvent )
619 {
620   Dali::Internal::Adaptor::GetImplementation(adaptor).SendPanGesture( panEvent );
621 }
622
623 } // namespace AccessibilityAdaptor
624 } // namespace Test