[ATSPI] Add a function to check whether accessibility is enabled
[platform/core/uifw/dali-adaptor.git] / dali / devel-api / adaptor-framework / atspi-accessibility.cpp
1 /*
2  * Copyright (c) 2021 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/devel-api/adaptor-framework/accessibility-impl.h>
19 #include <dali/devel-api/adaptor-framework/atspi-accessibility.h>
20
21 void Dali::AtspiAccessibility::Pause()
22 {
23   if(auto bridge = Dali::Accessibility::Bridge::GetCurrentBridge())
24   {
25     bridge->Pause();
26   }
27 }
28
29 void Dali::AtspiAccessibility::Resume()
30 {
31   if(auto bridge = Dali::Accessibility::Bridge::GetCurrentBridge())
32   {
33     bridge->Resume();
34   }
35 }
36
37 void Dali::AtspiAccessibility::StopReading(bool alsoNonDiscardable)
38 {
39   if(auto bridge = Dali::Accessibility::Bridge::GetCurrentBridge())
40   {
41     bridge->StopReading(alsoNonDiscardable);
42   }
43 }
44
45 bool Dali::AtspiAccessibility::SuppressScreenReader(bool suppress)
46 {
47   if(auto bridge = Dali::Accessibility::Bridge::GetCurrentBridge())
48   {
49     bridge->SuppressScreenReader(suppress);
50     return true;
51   }
52
53   return false;
54 }
55
56 void Dali::AtspiAccessibility::Say(const std::string& text, bool discardable, std::function<void(std::string)> callback)
57 {
58   if(auto bridge = Dali::Accessibility::Bridge::GetCurrentBridge())
59   {
60     bridge->Say(text, discardable, callback);
61   }
62 }
63
64 int Dali::AtspiAccessibility::SetForcefully(bool turnOn)
65 {
66   if(turnOn)
67   {
68     if(auto bridge = Dali::Accessibility::Bridge::GetCurrentBridge())
69     {
70       bridge->Initialize();
71       auto ret = bridge->ForceUp();
72       return (int)ret;
73     }
74   }
75   else
76   {
77     if(auto bridge = Dali::Accessibility::Bridge::GetCurrentBridge())
78     {
79       bridge->ForceDown();
80       return 0;
81     }
82   }
83   return -1;
84 }
85
86 int Dali::AtspiAccessibility::GetStatus()
87 {
88   //0(ATSPI OFF, ScreenReader OFF), 1(ATSPI ON, ScreenReader OFF), 2 (ATSPI OFF, ScreenReader ON), 3(ATSPI ON, ScreenReader ON)
89   if(auto bridge = Dali::Accessibility::Bridge::GetCurrentBridge())
90   {
91     if(bridge->GetScreenReaderEnabled())
92     {
93       if(bridge->IsEnabled())
94       {
95         return 3;
96       }
97       else
98       {
99         return 2;
100       }
101     }
102     else
103     {
104       if(bridge->IsEnabled())
105       {
106         return 1;
107       }
108       else
109       {
110         return 0;
111       }
112     }
113   }
114   return -1;
115 }
116
117 bool Dali::AtspiAccessibility::IsEnabled()
118 {
119   return Dali::Accessibility::IsUp();
120 }