1 /* 2 * Copyright (c) 2024 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 #include "bridge/cj_frontend/interfaces/cj_ffi/cj_richtext_ffi.h" 17 18 #ifndef PREVIEW 19 20 #include "cj_lambda.h" 21 #include "core/components_ng/pattern/web/richtext_model_ng.h" 22 23 #include <string> 24 25 using namespace OHOS::Ace; 26 27 extern "C" { FfiOHOSAceFrameworkRichTextCreate(const char * content)28void FfiOHOSAceFrameworkRichTextCreate(const char* content) 29 { 30 auto string = static_cast<std::string>(content); 31 RichTextModel::GetInstance()->Create(string); 32 } 33 FfiOHOSAceFrameworkRichTextOnStart(void (* callback)())34void FfiOHOSAceFrameworkRichTextOnStart(void(*callback)()) 35 { 36 auto lambda = [onStart = CJLambda::Create(callback)](const BaseEventInfo* info) { 37 onStart(); 38 }; 39 RichTextModel::GetInstance()->SetOnPageStart(lambda); 40 } 41 FfiOHOSAceFrameworkRichTextOnComplete(void (* callback)())42void FfiOHOSAceFrameworkRichTextOnComplete(void(*callback)()) 43 { 44 auto lambda = [onComplete = CJLambda::Create(callback)](const BaseEventInfo* info) { 45 onComplete(); 46 }; 47 RichTextModel::GetInstance()->SetOnPageFinish(lambda); 48 } 49 } 50 #else 51 extern "C" { FfiOHOSAceFrameworkRichTextCreate(const char * content)52void FfiOHOSAceFrameworkRichTextCreate(const char* content) {} FfiOHOSAceFrameworkRichTextOnStart(void (* callback)())53void FfiOHOSAceFrameworkRichTextOnStart(void(*callback)()) {} FfiOHOSAceFrameworkRichTextOnComplete(void (* callback)())54void FfiOHOSAceFrameworkRichTextOnComplete(void(*callback)()) {} 55 } 56 #endif