Revert "[Tizen](ATSPI) Fix Native TC fails"
[platform/core/uifw/dali-adaptor.git] / dali / internal / accessibility / bridge / bridge-text.cpp
1 /*
2  * Copyright (c) 2019 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 // CLASS HEADER
19 #include <dali/internal/accessibility/bridge/bridge-text.h>
20
21 // INTERNAL INCLUDES
22 #include <dali/internal/input/common/input-method-context-factory.h>
23
24 using namespace Dali::Accessibility;
25
26 void BridgeText::RegisterInterfaces()
27 {
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 );
38 }
39
40 Text* BridgeText::FindSelf() const
41 {
42   auto s = BridgeBase::FindSelf();
43   assert( s );
44   auto s2 = dynamic_cast< Text* >( s );
45   if( !s2 )
46     throw std::domain_error{"object " + s->GetAddress().ToString() + " doesn't have Text interface"};
47   return s2;
48 }
49
50 DBus::ValueOrError< std::string > BridgeText::GetText( int startOffset, int endOffset )
51 {
52   return FindSelf()->GetText( startOffset, endOffset );
53 }
54
55 DBus::ValueOrError< int32_t > BridgeText::GetCharacterCount()
56 {
57   return FindSelf()->GetCharacterCount();
58 }
59
60 DBus::ValueOrError< int32_t > BridgeText::GetCaretOffset()
61 {
62   return FindSelf()->GetCaretOffset();
63 }
64
65 DBus::ValueOrError< bool > BridgeText::SetCaretOffset( int32_t offset )
66 {
67   return FindSelf()->SetCaretOffset(offset);
68 }
69
70 DBus::ValueOrError< std::string, int, int > BridgeText::GetTextAtOffset( int32_t offset, uint32_t boundary )
71 {
72   auto r = FindSelf()->GetTextAtOffset( offset, static_cast< TextBoundary >( boundary ) );
73   return {r.content, static_cast< int >( r.startOffset ), static_cast< int >( r.endOffset )};
74 }
75
76 DBus::ValueOrError< int, int > BridgeText::GetSelection( int32_t selectionNum )
77 {
78   auto r = FindSelf()->GetSelection( selectionNum );
79   return {static_cast< int >( r.startOffset ), static_cast< int >( r.endOffset )};
80 }
81
82 DBus::ValueOrError< bool > BridgeText::RemoveSelection( int32_t selectionNum )
83 {
84   return FindSelf()->RemoveSelection( selectionNum );
85 }
86
87 DBus::ValueOrError< bool > BridgeText::SetSelection( int32_t selectionNum, int32_t startOffset, int32_t endOffset )
88 {
89   return FindSelf()->SetSelection( selectionNum, startOffset, endOffset );
90 }