2 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include <dali/internal/accessibility/tizen-wayland/atspi/accessibility-common.h>
22 #include <third-party/libunibreak/wordbreak.h>
23 #include <third-party/libunibreak/linebreak.h>
25 using namespace Dali::Accessibility;
27 std::vector< std::string > Accessible::GetInterfaces()
29 std::vector< std::string > tmp;
30 tmp.push_back(AtspiDbusInterfaceAccessible);
31 if (dynamic_cast<Collection*>(this))
33 tmp.push_back(AtspiDbusInterfaceCollection);
35 if (dynamic_cast<Text*>(this))
37 tmp.push_back(AtspiDbusInterfaceText);
39 if (dynamic_cast<Value*>(this))
41 tmp.push_back(AtspiDbusInterfaceValue);
43 if (dynamic_cast<Component*>(this))
45 tmp.push_back(AtspiDbusInterfaceComponent);
47 if (auto d = dynamic_cast<Action*>(this))
49 if (d->GetActionCount() > 0)
51 tmp.push_back(AtspiDbusInterfaceAction);
57 Accessible::Accessible()
61 Accessible::~Accessible()
63 auto b = bridgeData.lock();
65 b->knownObjects.erase(this);
68 void Accessible::EmitActiveDescendantChanged(Accessible* obj, Accessible* child)
70 if (auto b = GetBridgeData())
72 b->bridge->EmitActiveDescendantChanged(obj, child);
76 void Accessible::EmitStateChanged(State state, int newValue1, int newValue2)
78 if (auto b = GetBridgeData())
80 b->bridge->EmitStateChanged(this, state, newValue1, newValue2);
84 void Accessible::EmitShowing(bool showing)
86 if (auto b = GetBridgeData())
88 b->bridge->EmitStateChanged(this, State::SHOWING, showing ? 1 : 0, 0);
92 void Accessible::EmitVisible(bool visible)
94 if (auto b = GetBridgeData())
96 b->bridge->EmitStateChanged(this, State::VISIBLE, visible ? 1 : 0, 0);
100 void Accessible::EmitHighlighted(bool set)
102 if (auto b = GetBridgeData())
104 b->bridge->EmitStateChanged(this, State::HIGHLIGHTED, set ? 1 : 0, 0);
108 void Accessible::EmitFocused(bool set)
110 if (auto b = GetBridgeData()) {
111 b->bridge->EmitStateChanged(this, State::FOCUSED, set ? 1 : 0, 0);
114 void Accessible::EmitTextInserted(unsigned int position, unsigned int length, const std::string& content)
116 if (auto b = GetBridgeData()) {
117 b->bridge->EmitTextChanged(this, TextChangedState::INSERT, position, length, content);
120 void Accessible::EmitTextDeleted(unsigned int position, unsigned int length, const std::string& content)
122 if (auto b = GetBridgeData()) {
123 b->bridge->EmitTextChanged(this, TextChangedState::DELETE, position, length, content);
126 void Accessible::EmitTextCaretMoved(unsigned int cursorPosition)
128 if (auto b = GetBridgeData()) {
129 b->bridge->EmitCaretMoved(this, cursorPosition);
132 void Accessible::Emit(WindowEvent we, unsigned int detail1)
134 if (auto b = GetBridgeData())
136 b->bridge->Emit(this, we, detail1);
139 void Accessible::Emit(ObjectPropertyChangeEvent ev)
141 if (auto b = GetBridgeData())
143 b->bridge->Emit(this, ev);
147 void Accessible::EmitBoundsChanged(Rect<> rect)
149 if (auto b = GetBridgeData())
151 b->bridge->EmitBoundsChanged(this, rect);
155 std::vector< Accessible* > Accessible::GetChildren()
157 std::vector< Accessible* > tmp(GetChildCount());
158 for (auto i = 0u; i < tmp.size(); ++i)
160 tmp[i] = GetChildAtIndex(i);
165 std::shared_ptr< Bridge::Data > Accessible::GetBridgeData()
167 auto b = bridgeData.lock();
170 auto p = Bridge::GetCurrentBridge();
176 Address Accessible::GetAddress()
178 auto b = bridgeData.lock();
183 b->bridge->RegisterOnBridge(this);
185 std::ostringstream tmp;
187 return { b ? b->busName : "", tmp.str() };
190 void Bridge::RegisterOnBridge(Accessible* obj)
192 assert(!obj->bridgeData.lock() || obj->bridgeData.lock() == data);
193 if (!obj->bridgeData.lock())
196 data->knownObjects.insert(obj);
197 obj->bridgeData = data;
201 bool Accessible::IsProxy()
206 Accessible* Accessible::GetDefaultLabel()
211 void Accessible::NotifyAccessibilityStateChange(Dali::Accessibility::States states, bool doRecursive)
213 if (auto b = GetBridgeData())
215 auto s = GetStates() & states;
216 for (auto i = 0u; i < s.size(); i++)
218 auto index = static_cast<Dali::Accessibility::State>(i);
220 b->bridge->EmitStateChanged(this, index, 1, 0);
224 auto children = GetChildren();
225 for (auto c : children)
226 c->NotifyAccessibilityStateChange(states, doRecursive);
231 void Accessible::FindWordSeparationsUtf8(const utf8_t* s, size_t length, const char* language, char* breaks)
233 set_wordbreaks_utf8(s, length, language, breaks);
236 void Accessible::FindLineSeparationsUtf8(const utf8_t* s, size_t length, const char* language, char* breaks)
238 set_linebreaks_utf8(s, length, language, breaks);