[dali_2.3.25] Merge branch 'devel/master'
[platform/core/uifw/dali-adaptor.git] / dali / internal / accessibility / bridge / bridge-text.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 // 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   // The second arguments below are the names (or signatures) of DBus methods.
29   // Screen Reader will call the methods with the exact names as specified in the AT-SPI Text interface:
30   // https://gitlab.gnome.org/GNOME/at-spi2-core/-/blob/master/xml/Text.xml
31
32   DBus::DBusInterfaceDescription desc{Accessible::GetInterfaceName(AtspiInterface::TEXT)};
33   AddFunctionToInterface(desc, "GetText", &BridgeText::GetText);
34   AddGetPropertyToInterface(desc, "CharacterCount", &BridgeText::GetCharacterCount);
35   AddGetPropertyToInterface(desc, "CaretOffset", &BridgeText::GetCursorOffset);
36   AddFunctionToInterface(desc, "SetCaretOffset", &BridgeText::SetCursorOffset);
37   AddFunctionToInterface(desc, "GetTextAtOffset", &BridgeText::GetTextAtOffset);
38   AddFunctionToInterface(desc, "GetSelection", &BridgeText::GetRangeOfSelection);
39   AddFunctionToInterface(desc, "SetSelection", &BridgeText::SetRangeOfSelection);
40   AddFunctionToInterface(desc, "RemoveSelection", &BridgeText::RemoveSelection);
41   AddFunctionToInterface(desc, "GetRangeExtents", &BridgeText::GetRangeExtents);
42   mDbusServer.addInterface("/", desc, true);
43 }
44
45 Text* BridgeText::FindSelf() const
46 {
47   return FindCurrentObjectWithInterface<Dali::Accessibility::AtspiInterface::TEXT>();
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::GetCursorOffset()
61 {
62   return FindSelf()->GetCursorOffset();
63 }
64
65 DBus::ValueOrError<bool> BridgeText::SetCursorOffset(int32_t offset)
66 {
67   return FindSelf()->SetCursorOffset(offset);
68 }
69
70 DBus::ValueOrError<std::string, int, int> BridgeText::GetTextAtOffset(int32_t offset, uint32_t boundary)
71 {
72   auto range = FindSelf()->GetTextAtOffset(offset, static_cast<TextBoundary>(boundary));
73   return {range.content, static_cast<int>(range.startOffset), static_cast<int>(range.endOffset)};
74 }
75
76 DBus::ValueOrError<int, int> BridgeText::GetRangeOfSelection(int32_t selectionIndex)
77 {
78   auto range = FindSelf()->GetRangeOfSelection(selectionIndex);
79   return {static_cast<int>(range.startOffset), static_cast<int>(range.endOffset)};
80 }
81
82 DBus::ValueOrError<bool> BridgeText::RemoveSelection(int32_t selectionIndex)
83 {
84   return FindSelf()->RemoveSelection(selectionIndex);
85 }
86
87 DBus::ValueOrError<bool> BridgeText::SetRangeOfSelection(int32_t selectionIndex, int32_t startOffset, int32_t endOffset)
88 {
89   return FindSelf()->SetRangeOfSelection(selectionIndex, startOffset, endOffset);
90 }
91
92 DBus::ValueOrError<int32_t, int32_t, int32_t, int32_t> BridgeText::GetRangeExtents(int32_t startOffset, int32_t endOffset, uint32_t coordType)
93 {
94   auto rect = FindSelf()->GetRangeExtents(startOffset, endOffset, static_cast<CoordinateType>(coordType));
95   return {static_cast<int32_t>(rect.x), static_cast<int32_t>(rect.y), static_cast<int32_t>(rect.width), static_cast<int32_t>(rect.height)};
96 }