Change common test application
[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 HandleActionReadIndicatorInformationEvent();
92   bool HandleActionReadPauseResumeEvent();
93   bool HandleActionStartStopEvent();
94
95 private:
96
97   bool mIsEnabled;
98   Dali::AccessibilityActionHandler* mActionHandler;
99   Dali::AccessibilityGestureHandler* mGestureHandler;
100   Vector2 mReadPosition;
101
102   static Dali::AccessibilityAdaptor mToolkitAccessibilityAdaptor;
103 };
104
105 Dali::AccessibilityAdaptor AccessibilityAdaptor::mToolkitAccessibilityAdaptor;
106
107
108 Dali::AccessibilityAdaptor AccessibilityAdaptor::Get()
109 {
110   if( !mToolkitAccessibilityAdaptor )
111   {
112     mToolkitAccessibilityAdaptor = Dali::AccessibilityAdaptor( new Dali::Internal::Adaptor::AccessibilityAdaptor() );
113   }
114   return mToolkitAccessibilityAdaptor;
115 }
116
117 AccessibilityAdaptor::AccessibilityAdaptor()
118 : mIsEnabled(false),
119   mActionHandler(NULL),
120   mGestureHandler(NULL),
121   mReadPosition( 0.0f, 0.0f )
122 {
123 }
124
125 AccessibilityAdaptor::~AccessibilityAdaptor()
126 {
127 }
128
129 Vector2 AccessibilityAdaptor::GetReadPosition() const
130 {
131   return mReadPosition;
132 }
133
134 void AccessibilityAdaptor::MockSetReadPosition( Vector2& position )
135 {
136   mReadPosition = position;
137 }
138
139 bool AccessibilityAdaptor::IsEnabled() const
140 {
141   return mIsEnabled;
142 }
143
144 void AccessibilityAdaptor::SendPanGesture( const Integration::PanGestureEvent& panEvent )
145 {
146   mGestureHandler->HandlePanGesture( panEvent );
147 }
148
149 void AccessibilityAdaptor::SetActionHandler(Dali::AccessibilityActionHandler& handler)
150 {
151   mActionHandler = &handler;
152 }
153
154 void AccessibilityAdaptor::SetGestureHandler(Dali::AccessibilityGestureHandler& handler)
155 {
156   mGestureHandler = &handler;
157 }
158
159 bool AccessibilityAdaptor::HandleActionNextEvent(bool allowEndFeedback)
160 {
161   if( mActionHandler )
162   {
163     return mActionHandler->AccessibilityActionNext( true );
164   }
165   return false;
166 }
167
168 bool AccessibilityAdaptor::HandleActionPreviousEvent(bool allowEndFeedback)
169 {
170   if( mActionHandler )
171   {
172     return mActionHandler->AccessibilityActionPrevious( true );
173   }
174   return false;
175 }
176
177 bool AccessibilityAdaptor::HandleActionActivateEvent()
178 {
179   if( mActionHandler )
180   {
181     return mActionHandler->AccessibilityActionActivate();
182   }
183   return false;
184 }
185
186 bool AccessibilityAdaptor::HandleActionReadEvent(unsigned int x, unsigned int y,  bool allowReadAgain)
187 {
188   if( mActionHandler )
189   {
190     return mActionHandler->AccessibilityActionRead( allowReadAgain );
191   }
192   return false;
193 }
194
195 bool AccessibilityAdaptor::HandleActionReadNextEvent(bool allowEndFeedback)
196 {
197   if( mActionHandler )
198   {
199     return mActionHandler->AccessibilityActionReadNext( true );
200   }
201   return false;
202 }
203
204 bool AccessibilityAdaptor::HandleActionReadPreviousEvent(bool allowEndFeedback)
205 {
206   if( mActionHandler )
207   {
208     return mActionHandler->AccessibilityActionReadPrevious( true );
209   }
210   return false;
211 }
212
213 bool AccessibilityAdaptor::HandleActionUpEvent()
214 {
215   if( mActionHandler )
216   {
217     return mActionHandler->AccessibilityActionUp();
218   }
219   return false;
220 }
221
222 bool AccessibilityAdaptor::HandleActionDownEvent()
223 {
224   if( mActionHandler )
225   {
226     return mActionHandler->AccessibilityActionDown();
227   }
228   return false;
229 }
230
231 bool AccessibilityAdaptor::HandleActionClearFocusEvent()
232 {
233   if( mActionHandler )
234   {
235     return mActionHandler->ClearAccessibilityFocus();
236   }
237   return false;
238 }
239
240 bool AccessibilityAdaptor::HandleActionScrollEvent(const TouchPoint& point, unsigned long timeStamp)
241 {
242   if( mActionHandler )
243   {
244     Dali::TouchEvent touchEvent;
245     touchEvent.points.push_back( point );
246     return mActionHandler->AccessibilityActionScroll( touchEvent );
247   }
248   return false;
249 }
250
251 bool AccessibilityAdaptor::HandleActionTouchEvent(const TouchPoint& point, unsigned long timeStamp)
252 {
253   if( mActionHandler )
254   {
255     Dali::TouchEvent touchEvent;
256     touchEvent.points.push_back( point );
257     return mActionHandler->AccessibilityActionTouch( touchEvent );
258   }
259   return false;
260 }
261
262 bool AccessibilityAdaptor::HandleActionBackEvent()
263 {
264   if( mActionHandler )
265   {
266     return mActionHandler->AccessibilityActionBack();
267   }
268   return false;
269 }
270
271 bool AccessibilityAdaptor::HandleActionEnableEvent()
272 {
273   if( mActionHandler )
274   {
275     return mActionHandler->ChangeAccessibilityStatus();
276   }
277   return false;
278 }
279
280 bool AccessibilityAdaptor::HandleActionDisableEvent()
281 {
282   if( mActionHandler )
283   {
284     return mActionHandler->ChangeAccessibilityStatus();
285   }
286   return false;
287 }
288
289 bool AccessibilityAdaptor::HandleActionScrollUpEvent()
290 {
291   if( mActionHandler )
292   {
293     return mActionHandler->AccessibilityActionScrollUp();
294   }
295   return false;
296 }
297
298 bool AccessibilityAdaptor::HandleActionScrollDownEvent()
299 {
300   if( mActionHandler )
301   {
302     return mActionHandler->AccessibilityActionScrollDown();
303   }
304   return false;
305 }
306
307 bool AccessibilityAdaptor::HandleActionPageLeftEvent()
308 {
309   if( mActionHandler )
310   {
311     return mActionHandler->AccessibilityActionPageLeft();
312   }
313   return false;
314 }
315
316 bool AccessibilityAdaptor::HandleActionPageRightEvent()
317 {
318   if( mActionHandler )
319   {
320     return mActionHandler->AccessibilityActionPageRight();
321   }
322   return false;
323 }
324
325 bool AccessibilityAdaptor::HandleActionPageUpEvent()
326 {
327   if( mActionHandler )
328   {
329     return mActionHandler->AccessibilityActionPageUp();
330   }
331   return false;
332 }
333
334 bool AccessibilityAdaptor::HandleActionPageDownEvent()
335 {
336   if( mActionHandler )
337   {
338     return mActionHandler->AccessibilityActionPageDown();
339   }
340   return false;
341 }
342
343 bool AccessibilityAdaptor::HandleActionMoveToFirstEvent()
344 {
345   if( mActionHandler )
346   {
347     return mActionHandler->AccessibilityActionMoveToFirst();
348   }
349   return false;
350 }
351
352 bool AccessibilityAdaptor::HandleActionMoveToLastEvent()
353 {
354   if( mActionHandler )
355   {
356     return mActionHandler->AccessibilityActionMoveToLast();
357   }
358   return false;
359 }
360
361 bool AccessibilityAdaptor::HandleActionReadFromTopEvent()
362 {
363   if( mActionHandler )
364   {
365     return mActionHandler->AccessibilityActionReadFromTop();
366   }
367   return false;
368 }
369
370 bool AccessibilityAdaptor::HandleActionReadFromNextEvent()
371 {
372   if( mActionHandler )
373   {
374     return mActionHandler->AccessibilityActionReadFromNext();
375   }
376   return false;
377 }
378
379 bool AccessibilityAdaptor::HandleActionZoomEvent()
380 {
381   if( mActionHandler )
382   {
383     return mActionHandler->AccessibilityActionZoom();
384   }
385   return false;
386 }
387
388 bool AccessibilityAdaptor::HandleActionReadIndicatorInformationEvent()
389 {
390   if( mActionHandler )
391   {
392     return mActionHandler->AccessibilityActionReadIndicatorInformation();
393   }
394   return false;
395 }
396
397 bool AccessibilityAdaptor::HandleActionReadPauseResumeEvent()
398 {
399   if( mActionHandler )
400   {
401     return mActionHandler->AccessibilityActionReadPauseResume();
402   }
403   return false;
404 }
405
406 bool AccessibilityAdaptor::HandleActionStartStopEvent()
407 {
408   if( mActionHandler )
409   {
410     return mActionHandler->AccessibilityActionStartStop();
411   }
412   return false;
413 }
414
415 static Internal::Adaptor::AccessibilityAdaptor& GetImplementation(Dali::AccessibilityAdaptor& adaptor)
416 {
417   BaseObject& handle = adaptor.GetBaseObject();
418   return static_cast<Internal::Adaptor::AccessibilityAdaptor&>(handle);
419 }
420
421 static const Internal::Adaptor::AccessibilityAdaptor& GetImplementation(const Dali::AccessibilityAdaptor& adaptor)
422 {
423   const BaseObject& handle = adaptor.GetBaseObject();
424   return static_cast<const Internal::Adaptor::AccessibilityAdaptor&>(handle);
425 }
426
427
428 } // namespace Adaptor
429 } // namespace Internal
430
431 ////////////////////////////////////////////////////////////////////////////////////////////////////
432
433 AccessibilityAdaptor::AccessibilityAdaptor()
434 {
435 }
436
437 AccessibilityAdaptor AccessibilityAdaptor::Get()
438 {
439   return Internal::Adaptor::AccessibilityAdaptor::Get();
440 }
441
442 AccessibilityAdaptor::~AccessibilityAdaptor()
443 {
444 }
445
446 // Methods:
447
448 Vector2 AccessibilityAdaptor::GetReadPosition() const
449 {
450   return Internal::Adaptor::GetImplementation(*this).GetReadPosition();
451 }
452
453 bool AccessibilityAdaptor::IsEnabled() const
454 {
455   return Internal::Adaptor::GetImplementation(*this).IsEnabled();
456 }
457
458 void AccessibilityAdaptor::SetActionHandler(AccessibilityActionHandler& handler)
459 {
460   Internal::Adaptor::GetImplementation(*this).SetActionHandler(handler);
461 }
462
463 void AccessibilityAdaptor::SetGestureHandler(AccessibilityGestureHandler& handler)
464 {
465   Internal::Adaptor::GetImplementation(*this).SetGestureHandler(handler);
466 }
467
468 bool AccessibilityAdaptor::HandleActionNextEvent(bool allowEndFeedback)
469 {
470   return Internal::Adaptor::GetImplementation(*this).HandleActionNextEvent(allowEndFeedback);
471 }
472
473 bool AccessibilityAdaptor::HandleActionPreviousEvent(bool allowEndFeedback)
474 {
475   return Internal::Adaptor::GetImplementation(*this).HandleActionPreviousEvent(allowEndFeedback);
476 }
477
478 bool AccessibilityAdaptor::HandleActionActivateEvent()
479 {
480   return Internal::Adaptor::GetImplementation(*this).HandleActionActivateEvent();
481 }
482
483 bool AccessibilityAdaptor::HandleActionReadEvent(unsigned int x, unsigned int y,  bool allowReadAgain)
484 {
485   return Internal::Adaptor::GetImplementation(*this).HandleActionReadEvent( x, y, allowReadAgain );
486 }
487
488 bool AccessibilityAdaptor::HandleActionReadNextEvent(bool allowEndFeedback)
489 {
490   return Internal::Adaptor::GetImplementation(*this).HandleActionReadNextEvent(allowEndFeedback);
491 }
492
493 bool AccessibilityAdaptor::HandleActionReadPreviousEvent(bool allowEndFeedback)
494 {
495   return Internal::Adaptor::GetImplementation(*this).HandleActionReadPreviousEvent(allowEndFeedback);
496 }
497
498 bool AccessibilityAdaptor::HandleActionUpEvent()
499 {
500   return Internal::Adaptor::GetImplementation(*this).HandleActionUpEvent();
501 }
502
503 bool AccessibilityAdaptor::HandleActionDownEvent()
504 {
505   return Internal::Adaptor::GetImplementation(*this).HandleActionDownEvent();
506 }
507
508 bool AccessibilityAdaptor::HandleActionClearFocusEvent()
509 {
510   return Internal::Adaptor::GetImplementation(*this).HandleActionClearFocusEvent();
511 }
512
513 bool AccessibilityAdaptor::HandleActionScrollEvent(const TouchPoint& point, unsigned long timeStamp)
514 {
515   return Internal::Adaptor::GetImplementation(*this).HandleActionScrollEvent(point, timeStamp);
516 }
517
518 bool AccessibilityAdaptor::HandleActionTouchEvent(const TouchPoint& point, unsigned long timeStamp)
519 {
520   return Internal::Adaptor::GetImplementation(*this).HandleActionTouchEvent(point, timeStamp);
521 }
522
523 bool AccessibilityAdaptor::HandleActionBackEvent()
524 {
525   return Internal::Adaptor::GetImplementation(*this).HandleActionBackEvent();
526 }
527
528 void AccessibilityAdaptor::HandleActionEnableEvent()
529 {
530   Internal::Adaptor::GetImplementation(*this).HandleActionEnableEvent();
531 }
532
533 void AccessibilityAdaptor::HandleActionDisableEvent()
534 {
535   Internal::Adaptor::GetImplementation(*this).HandleActionDisableEvent();
536 }
537
538 bool AccessibilityAdaptor::HandleActionScrollUpEvent()
539 {
540   return Internal::Adaptor::GetImplementation(*this).HandleActionScrollUpEvent();
541 }
542
543 bool AccessibilityAdaptor::HandleActionScrollDownEvent()
544 {
545   return Internal::Adaptor::GetImplementation(*this).HandleActionScrollDownEvent();
546 }
547
548 bool AccessibilityAdaptor::HandleActionPageLeftEvent()
549 {
550   return Internal::Adaptor::GetImplementation(*this).HandleActionPageLeftEvent();
551 }
552
553 bool AccessibilityAdaptor::HandleActionPageRightEvent()
554 {
555   return Internal::Adaptor::GetImplementation(*this).HandleActionPageRightEvent();
556 }
557
558 bool AccessibilityAdaptor::HandleActionPageUpEvent()
559 {
560   return Internal::Adaptor::GetImplementation(*this).HandleActionPageUpEvent();
561 }
562
563 bool AccessibilityAdaptor::HandleActionPageDownEvent()
564 {
565   return Internal::Adaptor::GetImplementation(*this).HandleActionPageDownEvent();
566 }
567
568 bool AccessibilityAdaptor::HandleActionMoveToFirstEvent()
569 {
570   return Internal::Adaptor::GetImplementation(*this).HandleActionMoveToFirstEvent();
571 }
572
573 bool AccessibilityAdaptor::HandleActionMoveToLastEvent()
574 {
575   return Internal::Adaptor::GetImplementation(*this).HandleActionMoveToLastEvent();
576 }
577
578 bool AccessibilityAdaptor::HandleActionReadFromTopEvent()
579 {
580   return Internal::Adaptor::GetImplementation(*this).HandleActionReadFromTopEvent();
581 }
582
583 bool AccessibilityAdaptor::HandleActionReadFromNextEvent()
584 {
585   return Internal::Adaptor::GetImplementation(*this).HandleActionReadFromNextEvent();
586 }
587
588 bool AccessibilityAdaptor::HandleActionZoomEvent()
589 {
590   return Internal::Adaptor::GetImplementation(*this).HandleActionZoomEvent();
591 }
592
593 bool AccessibilityAdaptor::HandleActionReadIndicatorInformationEvent()
594 {
595   return Internal::Adaptor::GetImplementation(*this).HandleActionReadIndicatorInformationEvent();
596 }
597
598 bool AccessibilityAdaptor::HandleActionReadPauseResumeEvent()
599 {
600   return Internal::Adaptor::GetImplementation(*this).HandleActionReadPauseResumeEvent();
601 }
602
603 bool AccessibilityAdaptor::HandleActionStartStopEvent()
604 {
605   return Internal::Adaptor::GetImplementation(*this).HandleActionStartStopEvent();
606 }
607
608 AccessibilityAdaptor::AccessibilityAdaptor( Internal::Adaptor::AccessibilityAdaptor* adaptor )
609 : BaseHandle( adaptor )
610 {
611 }
612
613 } // namespace Dali
614
615
616 namespace Test
617 {
618 namespace AccessibilityAdaptor
619 {
620
621 // Mock setup:
622
623 void MockSetReadPosition( Dali::AccessibilityAdaptor adaptor, Dali::Vector2& position )
624 {
625   Dali::Internal::Adaptor::GetImplementation(adaptor).MockSetReadPosition( position );
626 }
627
628 void SetEnabled( Dali::AccessibilityAdaptor adaptor, bool enabled )
629 {
630   Dali::Internal::Adaptor::GetImplementation(adaptor).SetEnabled(enabled);
631 }
632
633 void SendPanGesture( Dali::AccessibilityAdaptor adaptor, const Dali::Integration::PanGestureEvent& panEvent )
634 {
635   Dali::Internal::Adaptor::GetImplementation(adaptor).SendPanGesture( panEvent );
636 }
637
638 } // namespace AccessibilityAdaptor
639 } // namespace Test