2 * Copyright (c) 2021 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 // 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
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);
45 Text* BridgeText::FindSelf() const
47 return FindCurrentObjectWithInterface<Dali::Accessibility::AtspiInterface::TEXT>();
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::GetCursorOffset()
62 return FindSelf()->GetCursorOffset();
65 DBus::ValueOrError<bool> BridgeText::SetCursorOffset(int32_t offset)
67 return FindSelf()->SetCursorOffset(offset);
70 DBus::ValueOrError<std::string, int, int> BridgeText::GetTextAtOffset(int32_t offset, uint32_t boundary)
72 auto range = FindSelf()->GetTextAtOffset(offset, static_cast<TextBoundary>(boundary));
73 return {range.content, static_cast<int>(range.startOffset), static_cast<int>(range.endOffset)};
76 DBus::ValueOrError<int, int> BridgeText::GetRangeOfSelection(int32_t selectionIndex)
78 auto range = FindSelf()->GetRangeOfSelection(selectionIndex);
79 return {static_cast<int>(range.startOffset), static_cast<int>(range.endOffset)};
82 DBus::ValueOrError<bool> BridgeText::RemoveSelection(int32_t selectionIndex)
84 return FindSelf()->RemoveSelection(selectionIndex);
87 DBus::ValueOrError<bool> BridgeText::SetRangeOfSelection(int32_t selectionIndex, int32_t startOffset, int32_t endOffset)
89 return FindSelf()->SetRangeOfSelection(selectionIndex, startOffset, endOffset);
92 DBus::ValueOrError<int32_t, int32_t, int32_t, int32_t> BridgeText::GetRangeExtents(int32_t startOffset, int32_t endOffset, uint32_t coordType)
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)};