1 /* 2 * Copyright (C) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef FOUNDATION_ACE_INTERFACE_INNERKITS_DATA_DETECTOR_INTERFACE_H 17 #define FOUNDATION_ACE_INTERFACE_INNERKITS_DATA_DETECTOR_INTERFACE_H 18 19 #include <functional> 20 #include <string> 21 #include <vector> 22 23 #include "base/utils/type_definition.h" 24 25 namespace OHOS::Ace { 26 constexpr int32_t UNSUPPORTED_CODE = 801; 27 28 struct TextDataDetectInfo { 29 std::string text; 30 std::string module; 31 bool isWordPosEnabled = false; 32 }; 33 34 struct TextDataDetectResult { 35 int32_t code = UNSUPPORTED_CODE; 36 std::string entity; 37 std::string wordPos; 38 std::string menuOption; 39 std::string entityMenuServiceInfo; 40 }; 41 42 using TextDetectResultFunc = std::function<void(const TextDataDetectResult)>; 43 44 class DataDetectorInterface { 45 public: 46 virtual bool IsDataDetectorSupported() = 0; 47 virtual void DataDetect(const TextDataDetectInfo& info, const TextDetectResultFunc& resultFunc) = 0; 48 GetCursorPosition(const std::string & text,int8_t offset)49 virtual int8_t GetCursorPosition(const std::string& text, int8_t offset) 50 { 51 return -1; 52 } 53 GetWordSelection(const std::string & text,int8_t offset)54 virtual std::vector<int8_t> GetWordSelection(const std::string& text, int8_t offset) 55 { 56 return std::vector<int8_t> { -1, -1 }; 57 } 58 59 protected: ~DataDetectorInterface()60 virtual ~DataDetectorInterface() {} 61 }; 62 } // namespace OHOS::Ace 63 #endif // FOUNDATION_ACE_INTERFACE_INNERKITS_DATA_DETECTOR_INTERFACE_H 64