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/bridge/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 ) )
32 tmp.push_back( AtspiDbusInterfaceCollection );
33 if( dynamic_cast< Text* >( this ) )
34 tmp.push_back( AtspiDbusInterfaceText );
35 if( dynamic_cast< Value* >( this ) )
36 tmp.push_back( AtspiDbusInterfaceValue );
37 if( dynamic_cast< Component* >( this ) )
38 tmp.push_back( AtspiDbusInterfaceComponent );
39 if( auto d = dynamic_cast< Action* >( this ) )
41 if( d->GetActionCount() > 0 )
42 tmp.push_back( AtspiDbusInterfaceAction );
47 Accessible::Accessible()
51 Accessible::~Accessible()
53 auto b = bridgeData.lock();
55 b->knownObjects.erase( this );
58 void Accessible::EmitActiveDescendantChanged( Accessible* obj, Accessible *child )
60 if( auto b = GetBridgeData() )
62 b->bridge->EmitActiveDescendantChanged( obj, child );
66 void Accessible::EmitStateChanged( State state, int newValue1, int newValue2 )
68 if( auto b = GetBridgeData() )
70 b->bridge->EmitStateChanged( this, state, newValue1, newValue2 );
74 void Accessible::EmitShowing( bool showing )
76 if( auto b = GetBridgeData() )
78 b->bridge->EmitStateChanged( this, State::SHOWING, showing ? 1 : 0, 0 );
82 void Accessible::EmitVisible( bool visible )
84 if( auto b = GetBridgeData() )
86 b->bridge->EmitStateChanged( this, State::VISIBLE, visible ? 1 : 0, 0 );
90 void Accessible::EmitHighlighted( bool set )
92 if( auto b = GetBridgeData() )
94 b->bridge->EmitStateChanged( this, State::HIGHLIGHTED, set ? 1 : 0, 0 );
98 void Accessible::EmitFocused( bool set )
100 if ( auto b = GetBridgeData() ) {
101 b->bridge->EmitStateChanged( this, State::FOCUSED, set ? 1 : 0, 0 );
104 void Accessible::EmitTextInserted( unsigned int position, unsigned int length, const std::string &content )
106 if ( auto b = GetBridgeData() ) {
107 b->bridge->EmitTextChanged( this, TextChangedState::INSERT, position, length, content );
110 void Accessible::EmitTextDeleted( unsigned int position, unsigned int length, const std::string &content )
112 if ( auto b = GetBridgeData() ) {
113 b->bridge->EmitTextChanged( this, TextChangedState::DELETE, position, length, content );
116 void Accessible::EmitTextCaretMoved( unsigned int cursorPosition )
118 if ( auto b = GetBridgeData() ) {
119 b->bridge->EmitCaretMoved( this, cursorPosition );
122 void Accessible::Emit( WindowEvent we, unsigned int detail1 )
124 if( auto b = GetBridgeData() )
126 b->bridge->Emit( this, we, detail1 );
129 void Accessible::Emit( ObjectPropertyChangeEvent ev )
131 if( auto b = GetBridgeData() )
133 b->bridge->Emit( this, ev );
137 void Accessible::EmitBoundsChanged( Rect<> rect )
139 if( auto b = GetBridgeData() )
141 b->bridge->EmitBoundsChanged( this, rect );
145 std::vector< Accessible* > Accessible::GetChildren()
147 std::vector< Accessible* > tmp( GetChildCount() );
148 for( auto i = 0u; i < tmp.size(); ++i )
150 tmp[i] = GetChildAtIndex( i );
155 std::shared_ptr< Bridge::Data > Accessible::GetBridgeData()
157 auto b = bridgeData.lock();
160 auto p = Bridge::GetCurrentBridge();
166 Address Accessible::GetAddress()
168 auto b = bridgeData.lock();
173 b->bridge->RegisterOnBridge( this );
175 std::ostringstream tmp;
177 return {b ? b->busName : "", tmp.str() };
180 void Bridge::RegisterOnBridge( Accessible* obj )
182 assert( !obj->bridgeData.lock() || obj->bridgeData.lock() == data );
183 if( !obj->bridgeData.lock() )
186 data->knownObjects.insert( obj );
187 obj->bridgeData = data;
191 bool Accessible::IsProxy()
196 Accessible* Accessible::GetDefaultLabel()
201 void Accessible::NotifyAccessibilityStateChange( Dali::Accessibility::States states, bool doRecursive )
203 if( auto b = GetBridgeData() )
205 auto s = GetStates() & states;
206 for( auto i = 0u; i < s.size(); i++ )
208 auto index = static_cast< Dali::Accessibility::State >( i );
210 b->bridge->EmitStateChanged( this, index, 1, 0 );
214 auto children = GetChildren();
215 for( auto c : children )
216 c->NotifyAccessibilityStateChange( states, doRecursive );
221 void Accessible::FindWordSeparationsUtf8( const utf8_t *s, size_t length, const char *language, char *breaks )
223 set_wordbreaks_utf8( s, length, language, breaks );
226 void Accessible::FindLineSeparationsUtf8( const utf8_t *s, size_t length, const char *language, char *breaks )
228 set_linebreaks_utf8( s, length, language, breaks );