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.
19 #include <dali/internal/accessibility/bridge/bridge-text.h>
22 #include <dali/internal/input/common/input-method-context-factory.h>
24 using namespace Dali::Accessibility;
26 void BridgeText::RegisterInterfaces()
28 DBus::DBusInterfaceDescription desc{AtspiDbusInterfaceText};
29 AddFunctionToInterface( desc, "GetText", &BridgeText::GetText );
30 AddGetPropertyToInterface( desc, "CharacterCount", &BridgeText::GetCharacterCount );
31 AddGetPropertyToInterface( desc, "CaretOffset", &BridgeText::GetCaretOffset );
32 AddFunctionToInterface( desc, "SetCaretOffset", &BridgeText::SetCaretOffset );
33 AddFunctionToInterface( desc, "GetTextAtOffset", &BridgeText::GetTextAtOffset );
34 AddFunctionToInterface( desc, "GetSelection", &BridgeText::GetSelection );
35 AddFunctionToInterface( desc, "SetSelection", &BridgeText::SetSelection );
36 AddFunctionToInterface( desc, "RemoveSelection", &BridgeText::RemoveSelection );
37 dbusServer.addInterface( "/", desc, true );
40 Text* BridgeText::FindSelf() const
42 auto s = BridgeBase::FindSelf();
44 auto s2 = dynamic_cast< Text* >( s );
46 throw std::domain_error{"object " + s->GetAddress().ToString() + " doesn't have Text interface"};
50 DBus::ValueOrError< std::string > BridgeText::GetText( int startOffset, int endOffset )
52 return FindSelf()->GetText( startOffset, endOffset );
55 DBus::ValueOrError< int32_t > BridgeText::GetCharacterCount()
57 return FindSelf()->GetCharacterCount();
60 DBus::ValueOrError< int32_t > BridgeText::GetCaretOffset()
62 return FindSelf()->GetCaretOffset();
65 DBus::ValueOrError< bool > BridgeText::SetCaretOffset( int32_t offset )
67 return FindSelf()->SetCaretOffset(offset);
70 DBus::ValueOrError< std::string, int, int > BridgeText::GetTextAtOffset( int32_t offset, uint32_t boundary )
72 auto r = FindSelf()->GetTextAtOffset( offset, static_cast< TextBoundary >( boundary ) );
73 return {r.content, static_cast< int >( r.startOffset ), static_cast< int >( r.endOffset )};
76 DBus::ValueOrError< int, int > BridgeText::GetSelection( int32_t selectionNum )
78 auto r = FindSelf()->GetSelection( selectionNum );
79 return {static_cast< int >( r.startOffset ), static_cast< int >( r.endOffset )};
82 DBus::ValueOrError< bool > BridgeText::RemoveSelection( int32_t selectionNum )
84 return FindSelf()->RemoveSelection( selectionNum );
87 DBus::ValueOrError< bool > BridgeText::SetSelection( int32_t selectionNum, int32_t startOffset, int32_t endOffset )
89 return FindSelf()->SetSelection( selectionNum, startOffset, endOffset );