!40207 文本实体识别支持自定义AI实体颜色

Merge pull request !40207 from 范盼/AI_entityColor
This commit is contained in:
openharmony_ci 2024-08-15 02:05:57 +00:00 committed by Gitee
commit b3efd3aa77
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
36 changed files with 342 additions and 214 deletions

View File

@ -7596,12 +7596,17 @@ class RichEditorDataDetectorConfigModifier extends ModifierWithKey {
if (reset) {
getUINativeModule().richEditor.resetDataDetectorConfig(node);
} else {
getUINativeModule().richEditor.setDataDetectorConfig(node, this.value.types, this.value.onDetectResultUpdate);
getUINativeModule().richEditor.setDataDetectorConfig(node, this.value.types, this.value.onDetectResultUpdate,
this.value.color, this.value.decorationType, this.value.decorationColor, this.value.decorationStyle);
}
}
checkObjectDiff() {
return !isBaseOrResourceEqual(this.stageValue.types, this.value.types) ||
!isBaseOrResourceEqual(this.stageValue.onDetectResultUpdate, this.value.onDetectResultUpdate);
!isBaseOrResourceEqual(this.stageValue.onDetectResultUpdate, this.value.onDetectResultUpdate) ||
!isBaseOrResourceEqual(this.stageValue.color, this.value.color) ||
!isBaseOrResourceEqual(this.stageValue.decorationType, this.value.decorationType) ||
!isBaseOrResourceEqual(this.stageValue.decorationColor, this.value.decorationColor) ||
!isBaseOrResourceEqual(this.stageValue.decorationStyle, this.value.decorationStyle);
}
}
RichEditorDataDetectorConfigModifier.identity = Symbol('richEditorDataDetectorConfig');
@ -7844,6 +7849,12 @@ class ArkRichEditorComponent extends ArkComponent {
let detectorConfig = new TextDataDetectorConfig();
detectorConfig.types = config.types;
detectorConfig.onDetectResultUpdate = config.onDetectResultUpdate;
detectorConfig.color = config.color;
if (config.decoration) {
detectorConfig.decorationType = config.decoration.type;
detectorConfig.decorationColor = config.decoration.color;
detectorConfig.decorationStyle = config.decoration.style;
}
modifierWithKey(this._modifiersWithKeys, RichEditorDataDetectorConfigModifier.identity, RichEditorDataDetectorConfigModifier, detectorConfig);
return this;
}
@ -11031,12 +11042,17 @@ class TextDataDetectorConfigModifier extends ModifierWithKey {
if (reset) {
getUINativeModule().text.resetDataDetectorConfig(node);
} else {
getUINativeModule().text.setDataDetectorConfig(node, this.value.types, this.value.onDetectResultUpdate);
getUINativeModule().text.setDataDetectorConfig(node, this.value.types, this.value.onDetectResultUpdate,
this.value.color, this.value.decorationType, this.value.decorationColor, this.value.decorationStyle);
}
}
checkObjectDiff() {
return !isBaseOrResourceEqual(this.stageValue.types, this.value.types) ||
!isBaseOrResourceEqual(this.stageValue.onDetectResultUpdate, this.value.onDetectResultUpdate);
!isBaseOrResourceEqual(this.stageValue.onDetectResultUpdate, this.value.onDetectResultUpdate) ||
!isBaseOrResourceEqual(this.stageValue.color, this.value.color) ||
!isBaseOrResourceEqual(this.stageValue.decorationType, this.value.decorationType) ||
!isBaseOrResourceEqual(this.stageValue.decorationColor, this.value.decorationColor) ||
!isBaseOrResourceEqual(this.stageValue.decorationStyle, this.value.decorationStyle);
}
}
TextDataDetectorConfigModifier.identity = Symbol('textDataDetectorConfig');
@ -11137,6 +11153,12 @@ class ArkTextComponent extends ArkComponent {
let detectorConfig = new TextDataDetectorConfig();
detectorConfig.types = config.types;
detectorConfig.onDetectResultUpdate = config.onDetectResultUpdate;
detectorConfig.color = config.color;
if (config.decoration) {
detectorConfig.decorationType = config.decoration.type;
detectorConfig.decorationColor = config.decoration.color;
detectorConfig.decorationStyle = config.decoration.style;
}
modifierWithKey(this._modifiersWithKeys, TextDataDetectorConfigModifier.identity, TextDataDetectorConfigModifier, detectorConfig);
return this;
}
@ -14748,10 +14770,15 @@ class TextDataDetectorConfig {
constructor() {
this.types = undefined;
this.onDetectResultUpdate = undefined;
this.color = undefined;
this.decorationType = undefined;
this.decorationColor = undefined;
this.decorationStyle = undefined;
}
isEqual(another) {
return (this.types === another.types) &&
(this.onDetectResultUpdate === another.onDetectResultUpdate);
return (this.types === another.types) && (this.onDetectResultUpdate === another.onDetectResultUpdate) &&
(this.color === another.color) && (this.decorationType === another.decorationType) &&
(this.decorationColor=== another.decorationColor) && (this.decorationStyle === another.decorationStyle);
}
}

View File

@ -27,7 +27,11 @@ namespace {
constexpr int NUM_0 = 0;
constexpr int NUM_1 = 1;
constexpr int NUM_2 = 2;
const std::vector<std::string> TEXT_DETECT_TYPES = { "phoneNum", "url", "email", "location" };
constexpr int NUM_3 = 3;
constexpr int NUM_4 = 4;
constexpr int NUM_5 = 5;
constexpr int NUM_6 = 6;
const std::vector<std::string> TEXT_DETECT_TYPES = { "phoneNum", "url", "email", "location", "datetime" };
}
ArkUINativeModuleValue RichEditorBridge::SetEnableDataDetector(ArkUIRuntimeCallInfo* runtimeCallInfo)
@ -86,11 +90,13 @@ ArkUINativeModuleValue RichEditorBridge::SetDataDetectorConfig(ArkUIRuntimeCallI
auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
auto frameNode = reinterpret_cast<FrameNode*>(nativeNode);
CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
if (!typesArg->IsArray(vm) || !callbackArg->IsFunction(vm)) {
if (!typesArg->IsArray(vm)) {
GetArkUINodeModifiers()->getRichEditorModifier()->
resetRichEditorDataDetectorConfigWithEvent(nativeNode);
return panda::JSValueRef::Undefined(vm);
}
struct ArkUITextDetectConfigStruct arkUITextDetectConfig;
std::string types;
auto array = panda::Local<panda::ArrayRef>(typesArg);
for (size_t i = 0; i < array->Length(vm); i++) {
@ -104,22 +110,54 @@ ArkUINativeModuleValue RichEditorBridge::SetDataDetectorConfig(ArkUIRuntimeCallI
}
types.append(TEXT_DETECT_TYPES[index]);
}
panda::Local<panda::FunctionRef> func = callbackArg->ToObject(vm);
std::function<void(const std::string&)> callback = [vm, frameNode,
func = panda::CopyableGlobal(vm, func)](const std::string& info) {
panda::LocalScope pandaScope(vm);
panda::TryCatch trycatch(vm);
PipelineContext::SetCallBackNode(AceType::WeakClaim(frameNode));
panda::Local<panda::JSValueRef> params[NUM_1] = {
panda::StringRef::NewFromUtf8(vm, info.c_str()) };
func->Call(vm, func.ToLocal(), params, NUM_1);
};
arkUITextDetectConfig.types = types.c_str();
if (callbackArg->IsFunction(vm)) {
panda::Local<panda::FunctionRef> func = callbackArg->ToObject(vm);
std::function<void(const std::string&)> callback = [vm, frameNode,
func = panda::CopyableGlobal(vm, func)](const std::string& info) {
panda::LocalScope pandaScope(vm);
panda::TryCatch trycatch(vm);
PipelineContext::SetCallBackNode(AceType::WeakClaim(frameNode));
panda::Local<panda::JSValueRef> params[NUM_1] = {
panda::StringRef::NewFromUtf8(vm, info.c_str()) };
func->Call(vm, func.ToLocal(), params, NUM_1);
};
arkUITextDetectConfig.onResult = reinterpret_cast<void*>(&callback);
}
ParseAIEntityColor(runtimeCallInfo, arkUITextDetectConfig);
GetArkUINodeModifiers()->getRichEditorModifier()->
setRichEditorDataDetectorConfigWithEvent(nativeNode,
types.c_str(), reinterpret_cast<void*>(&callback));
setRichEditorDataDetectorConfigWithEvent(nativeNode, &arkUITextDetectConfig);
return panda::JSValueRef::Undefined(vm);
}
void RichEditorBridge::ParseAIEntityColor(
ArkUIRuntimeCallInfo* runtimeCallInfo, struct ArkUITextDetectConfigStruct& arkUITextDetectConfig)
{
EcmaVM* vm = runtimeCallInfo->GetVM();
CHECK_NULL_VOID(vm);
TextDetectConfig textDetectConfig;
Local<JSValueRef> entityColorArg = runtimeCallInfo->GetCallArgRef(NUM_3);
ArkTSUtils::ParseJsColorAlpha(vm, entityColorArg, textDetectConfig.entityColor);
arkUITextDetectConfig.entityColor = textDetectConfig.entityColor.GetValue();
Local<JSValueRef> entityDecorationTypeArg = runtimeCallInfo->GetCallArgRef(NUM_4);
Local<JSValueRef> entityDecorationColorArg = runtimeCallInfo->GetCallArgRef(NUM_5);
Local<JSValueRef> entityDecorationStyleArg = runtimeCallInfo->GetCallArgRef(NUM_6);
arkUITextDetectConfig.entityDecorationType = static_cast<int32_t>(textDetectConfig.entityDecorationType);
arkUITextDetectConfig.entityDecorationColor = arkUITextDetectConfig.entityColor;
arkUITextDetectConfig.entityDecorationStyle = static_cast<int32_t>(textDetectConfig.entityDecorationStyle);
if (entityDecorationTypeArg->IsInt()) {
arkUITextDetectConfig.entityDecorationType = entityDecorationTypeArg->Int32Value(vm);
}
if (ArkTSUtils::ParseJsColorAlpha(vm, entityDecorationColorArg, textDetectConfig.entityDecorationColor)) {
arkUITextDetectConfig.entityDecorationColor = textDetectConfig.entityDecorationColor.GetValue();
}
if (entityDecorationStyleArg->IsInt()) {
arkUITextDetectConfig.entityDecorationStyle = entityDecorationStyleArg->Int32Value(vm);
}
}
ArkUINativeModuleValue RichEditorBridge::ResetDataDetectorConfig(ArkUIRuntimeCallInfo* runtimeCallInfo)
{
EcmaVM* vm = runtimeCallInfo->GetVM();

View File

@ -67,7 +67,11 @@ public:
static ArkUINativeModuleValue SetEnterKeyType(ArkUIRuntimeCallInfo* runtimeCallInfo);
static ArkUINativeModuleValue ResetEnterKeyType(ArkUIRuntimeCallInfo* runtimeCallInfo);
};
private:
static void ParseAIEntityColor(
ArkUIRuntimeCallInfo* runtimeCallInfo, struct ArkUITextDetectConfigStruct& arkUITextDetectConfig);
};
}
#endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_JSI_NATIVEMODULE_ARKTS_NATIVE_RICH_EDITOR_H

View File

@ -51,7 +51,7 @@ constexpr int NUM_6 = 6;
constexpr int NUM_7 = 7;
const std::vector<TextOverflow> TEXT_OVERFLOWS = { TextOverflow::NONE, TextOverflow::CLIP, TextOverflow::ELLIPSIS,
TextOverflow::MARQUEE };
const std::vector<std::string> TEXT_DETECT_TYPES = { "phoneNum", "url", "email", "location" };
const std::vector<std::string> TEXT_DETECT_TYPES = { "phoneNum", "url", "email", "location", "datetime" };
} // namespace
ArkUINativeModuleValue TextBridge::SetFontWeight(ArkUIRuntimeCallInfo* runtimeCallInfo)
@ -1112,11 +1112,13 @@ ArkUINativeModuleValue TextBridge::SetDataDetectorConfig(ArkUIRuntimeCallInfo* r
auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
auto frameNode = reinterpret_cast<FrameNode*>(nativeNode);
CHECK_NULL_RETURN(frameNode, panda::NativePointerRef::New(vm, nullptr));
if (!typesArg->IsArray(vm) || !callbackArg->IsFunction(vm)) {
if (!typesArg->IsArray(vm)) {
GetArkUINodeModifiers()->getTextModifier()->
resetTextDataDetectorConfigWithEvent(nativeNode);
return panda::JSValueRef::Undefined(vm);
}
struct ArkUITextDetectConfigStruct arkUITextDetectConfig;
std::string types;
auto array = panda::Local<panda::ArrayRef>(typesArg);
for (size_t i = 0; i < array->Length(vm); i++) {
@ -1130,22 +1132,54 @@ ArkUINativeModuleValue TextBridge::SetDataDetectorConfig(ArkUIRuntimeCallInfo* r
}
types.append(TEXT_DETECT_TYPES[index]);
}
panda::Local<panda::FunctionRef> func = callbackArg->ToObject(vm);
std::function<void(const std::string&)> callback = [vm, frameNode,
func = panda::CopyableGlobal(vm, func)](const std::string& info) {
panda::LocalScope pandaScope(vm);
panda::TryCatch trycatch(vm);
PipelineContext::SetCallBackNode(AceType::WeakClaim(frameNode));
panda::Local<panda::JSValueRef> params[PARAM_ARR_LENGTH_1] = {
panda::StringRef::NewFromUtf8(vm, info.c_str()) };
func->Call(vm, func.ToLocal(), params, PARAM_ARR_LENGTH_1);
};
arkUITextDetectConfig.types = types.c_str();
if (callbackArg->IsFunction(vm)) {
panda::Local<panda::FunctionRef> func = callbackArg->ToObject(vm);
std::function<void(const std::string&)> callback = [vm, frameNode,
func = panda::CopyableGlobal(vm, func)](const std::string& info) {
panda::LocalScope pandaScope(vm);
panda::TryCatch trycatch(vm);
PipelineContext::SetCallBackNode(AceType::WeakClaim(frameNode));
panda::Local<panda::JSValueRef> params[PARAM_ARR_LENGTH_1] = {
panda::StringRef::NewFromUtf8(vm, info.c_str()) };
func->Call(vm, func.ToLocal(), params, PARAM_ARR_LENGTH_1);
};
arkUITextDetectConfig.onResult = reinterpret_cast<void*>(&callback);
}
ParseAIEntityColor(runtimeCallInfo, arkUITextDetectConfig);
GetArkUINodeModifiers()->getTextModifier()->
setTextDataDetectorConfigWithEvent(nativeNode,
types.c_str(), reinterpret_cast<void*>(&callback));
setTextDataDetectorConfigWithEvent(nativeNode, &arkUITextDetectConfig);
return panda::JSValueRef::Undefined(vm);
}
void TextBridge::ParseAIEntityColor(
ArkUIRuntimeCallInfo* runtimeCallInfo, struct ArkUITextDetectConfigStruct& arkUITextDetectConfig)
{
EcmaVM* vm = runtimeCallInfo->GetVM();
CHECK_NULL_VOID(vm);
TextDetectConfig textDetectConfig;
Local<JSValueRef> entityColorArg = runtimeCallInfo->GetCallArgRef(NUM_3);
ArkTSUtils::ParseJsColorAlpha(vm, entityColorArg, textDetectConfig.entityColor);
arkUITextDetectConfig.entityColor = textDetectConfig.entityColor.GetValue();
Local<JSValueRef> entityDecorationTypeArg = runtimeCallInfo->GetCallArgRef(NUM_4);
Local<JSValueRef> entityDecorationColorArg = runtimeCallInfo->GetCallArgRef(NUM_5);
Local<JSValueRef> entityDecorationStyleArg = runtimeCallInfo->GetCallArgRef(NUM_6);
arkUITextDetectConfig.entityDecorationType = static_cast<int32_t>(textDetectConfig.entityDecorationType);
arkUITextDetectConfig.entityDecorationColor = arkUITextDetectConfig.entityColor;
arkUITextDetectConfig.entityDecorationStyle = static_cast<int32_t>(textDetectConfig.entityDecorationStyle);
if (entityDecorationTypeArg->IsInt()) {
arkUITextDetectConfig.entityDecorationType = entityDecorationTypeArg->Int32Value(vm);
}
if (ArkTSUtils::ParseJsColorAlpha(vm, entityDecorationColorArg, textDetectConfig.entityDecorationColor)) {
arkUITextDetectConfig.entityDecorationColor = textDetectConfig.entityDecorationColor.GetValue();
}
if (entityDecorationStyleArg->IsInt()) {
arkUITextDetectConfig.entityDecorationStyle = entityDecorationStyleArg->Int32Value(vm);
}
}
ArkUINativeModuleValue TextBridge::ResetDataDetectorConfig(ArkUIRuntimeCallInfo* runtimeCallInfo)
{
EcmaVM* vm = runtimeCallInfo->GetVM();

View File

@ -101,6 +101,10 @@ public:
static ArkUINativeModuleValue ResetHalfLeading(ArkUIRuntimeCallInfo* runtimeCallInfo);
static ArkUINativeModuleValue SetOnClick(ArkUIRuntimeCallInfo* runtimeCallInfo);
static ArkUINativeModuleValue ResetOnClick(ArkUIRuntimeCallInfo* runtimeCallInfo);
private:
static void ParseAIEntityColor(
ArkUIRuntimeCallInfo* runtimeCallInfo, struct ArkUITextDetectConfigStruct& arkUITextDetectConfig);
};
} // namespace OHOS::Ace::NG

View File

@ -1155,12 +1155,11 @@ void JSRichEditor::JsDataDetectorConfig(const JSCallbackInfo& info)
return;
}
std::string textTypes;
std::function<void(const std::string&)> onResult;
if (!ParseDataDetectorConfig(info, textTypes, onResult)) {
TextDetectConfig textDetectConfig;
if (!ParseDataDetectorConfig(info, textDetectConfig)) {
return;
}
RichEditorModel::GetInstance()->SetTextDetectConfig(textTypes, std::move(onResult));
RichEditorModel::GetInstance()->SetTextDetectConfig(textDetectConfig);
}
void JSRichEditor::SetCaretColor(const JSCallbackInfo& info)

View File

@ -876,12 +876,11 @@ void JSText::JsDataDetectorConfig(const JSCallbackInfo& info)
return;
}
std::string textTypes;
std::function<void(const std::string&)> onResult;
if (!ParseDataDetectorConfig(info, textTypes, onResult)) {
TextDetectConfig textDetectConfig;
if (!ParseDataDetectorConfig(info, textDetectConfig)) {
return;
}
TextModel::GetInstance()->SetTextDetectConfig(textTypes, std::move(onResult));
TextModel::GetInstance()->SetTextDetectConfig(textDetectConfig);
}
void JSText::BindSelectionMenu(const JSCallbackInfo& info)

View File

@ -171,7 +171,7 @@ constexpr float DEFAULT_SCALE_MIDDLE_OR_HEAVY = 0.95f;
constexpr float MAX_ANGLE = 360.0f;
constexpr float DEFAULT_BIAS = 0.5f;
const std::vector<FontStyle> FONT_STYLES = { FontStyle::NORMAL, FontStyle::ITALIC };
const std::vector<std::string> TEXT_DETECT_TYPES = { "phoneNum", "url", "email", "location" };
const std::vector<std::string> TEXT_DETECT_TYPES = { "phoneNum", "url", "email", "location", "datetime" };
const std::vector<std::string> RESOURCE_HEADS = { "app", "sys" };
const std::string SHEET_HEIGHT_MEDIUM = "medium";
const std::string SHEET_HEIGHT_LARGE = "large";
@ -9250,8 +9250,7 @@ bool JSViewAbstract::ParseJsResource(const JSRef<JSVal>& jsValue, CalcDimension&
return false;
}
bool JSViewAbstract::ParseDataDetectorConfig(
const JSCallbackInfo& info, std::string& types, std::function<void(const std::string&)>& onResult)
bool JSViewAbstract::ParseDataDetectorConfig(const JSCallbackInfo& info, TextDetectConfig& textDetectConfig)
{
JSRef<JSVal> arg = info[0];
if (!arg->IsObject()) {
@ -9270,21 +9269,54 @@ bool JSViewAbstract::ParseDataDetectorConfig(
return false;
}
if (i != 0) {
types.append(",");
textDetectConfig.types.append(",");
}
types.append(TEXT_DETECT_TYPES[index]);
textDetectConfig.types.append(TEXT_DETECT_TYPES[index]);
}
WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
JSRef<JSVal> resultCallback = obj->GetProperty("onDetectResultUpdate");
if (resultCallback->IsFunction()) {
auto jsFunc = AceType::MakeRefPtr<JsClipboardFunction>(JSRef<JSFunc>::Cast(resultCallback));
onResult = [execCtx = info.GetExecutionContext(), func = std::move(jsFunc), node = frameNode](
textDetectConfig.onResult = [execCtx = info.GetExecutionContext(), func = std::move(jsFunc), node = frameNode](
const std::string& result) {
JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
PipelineContext::SetCallBackNode(node);
func->Execute(result);
};
}
return ParseAIEntityColor(obj, textDetectConfig);
}
bool JSViewAbstract::ParseAIEntityColor(const JSRef<JSObject>& obj, TextDetectConfig& textDetectConfig)
{
JSRef<JSVal> entityColorValue = obj->GetProperty("color");
ParseJsColor(entityColorValue, textDetectConfig.entityColor);
JSRef<JSVal> decorationValue = obj->GetProperty("decoration");
if (decorationValue->IsUndefined() || !decorationValue->IsObject()) {
textDetectConfig.entityDecorationColor = textDetectConfig.entityColor;
return true;
}
JSRef<JSObject> decorationObj = JSRef<JSObject>::Cast(decorationValue);
JSRef<JSVal> typeValue = decorationObj->GetProperty("type");
JSRef<JSVal> colorValue = decorationObj->GetProperty("color");
JSRef<JSVal> styleValue = decorationObj->GetProperty("style");
if (typeValue->IsNumber()) {
textDetectConfig.entityDecorationType = static_cast<TextDecoration>(typeValue->ToNumber<int32_t>());
} else {
textDetectConfig.entityDecorationType = TextDecoration::UNDERLINE;
}
if (!ParseJsColor(colorValue, textDetectConfig.entityDecorationColor)) {
textDetectConfig.entityDecorationColor = textDetectConfig.entityColor;
}
if (styleValue->IsNumber()) {
textDetectConfig.entityDecorationStyle = static_cast<TextDecorationStyle>(styleValue->ToNumber<int32_t>());
} else {
textDetectConfig.entityDecorationStyle = TextDecorationStyle::SOLID;
}
return true;
}

View File

@ -37,6 +37,7 @@
#include "core/components_ng/event/gesture_event_hub.h"
#include "core/components_ng/pattern/overlay/sheet_presentation_pattern.h"
#include "core/components_ng/pattern/tabs/tab_content_model.h"
#include "core/components_ng/pattern/text/text_model.h"
#include "core/components_ng/pattern/text/text_menu_extension.h"
#include "core/components_ng/property/gradient_property.h"
#include "core/components_ng/property/transition_property.h"
@ -333,8 +334,8 @@ public:
static void ParseShadowOffsetX(const JSRef<JSObject>& jsObj, CalcDimension& offsetX, Shadow& shadow);
static bool GetShadowFromTheme(ShadowStyle shadowStyle, Shadow& shadow);
static bool ParseJsResource(const JSRef<JSVal>& jsValue, CalcDimension& result);
static bool ParseDataDetectorConfig(const JSCallbackInfo& info, std::string& types,
std::function<void(const std::string&)>& onResult);
static bool ParseDataDetectorConfig(const JSCallbackInfo& info, TextDetectConfig& textDetectConfig);
static bool ParseAIEntityColor(const JSRef<JSObject>& obj, TextDetectConfig& textDetectConfig);
static bool ParseInvertProps(const JSRef<JSVal>& jsValue, InvertVariant& invert);
static std::pair<CalcDimension, CalcDimension> ParseSize(const JSCallbackInfo& info);
static void JsUseAlign(const JSCallbackInfo& info);

View File

@ -37,7 +37,7 @@ class ACE_EXPORT RichEditorModelImpl : public RichEditorModel {
void SetPlaceholder(PlaceholderOptions& options) override {}
void SetTextDetectEnable(bool value) override {}
void SetSupportPreviewText(bool value) override {}
void SetTextDetectConfig(const std::string& value, std::function<void(const std::string&)>&& onResult) override {}
void SetTextDetectConfig(const TextDetectConfig& textDetectConfig) override {}
void SetSelectedBackgroundColor(const DynamicColor& selectedColor) override {}
void SetCaretColor(const DynamicColor& color) override {}
void SetOnEditingChange(std::function<void(const bool&)>&& func) override {}

View File

@ -236,8 +236,7 @@ void TextModelImpl::SetHeightAdaptivePolicy(TextHeightAdaptivePolicy value) {}
void TextModelImpl::SetTextDetectEnable(bool value) {}
void TextModelImpl::SetTextDetectConfig(const std::string& value,
std::function<void(const std::string&)>&& onResult) {}
void TextModelImpl::SetTextDetectConfig(const TextDetectConfig& textDetectConfig) {}
void TextModelImpl::OnSetWidth()
{

View File

@ -57,7 +57,7 @@ public:
void SetAdaptMaxFontSize(const Dimension& value) override;
void SetHeightAdaptivePolicy(TextHeightAdaptivePolicy value) override;
void SetTextDetectEnable(bool value) override;
void SetTextDetectConfig(const std::string& value, std::function<void(const std::string&)>&& onResult) override;
void SetTextDetectConfig(const TextDetectConfig& textDetectConfig) override;
void OnSetHeight() override;
void OnSetWidth() override;
void OnSetAlign() override;

View File

@ -112,6 +112,11 @@ private:
TimeStamp startDetectorTimeStamp_;
std::vector<std::string> detectTexts_;
int32_t mainContainerId_ = -1;
std::optional<Color> entityColor_;
std::optional<TextDecoration> entityDecorationType_;
std::optional<Color> entityDecorationColor_;
std::optional<TextDecorationStyle> entityDecorationStyle_;
std::string textDetectConfigStr_;
};
} // namespace OHOS::Ace

View File

@ -57,7 +57,7 @@ void CanvasRenderingContext2DModelNG::SetFontWeight(const FontWeight& weight)
pattern_->UpdateFontWeight(weight);
}
void CanvasRenderingContext2DModelNG::SetFontStyle(const FontStyle& fontStyle)
void CanvasRenderingContext2DModelNG::SetFontStyle(const Ace::FontStyle& fontStyle)
{
CHECK_NULL_VOID(pattern_);
pattern_->UpdateFontStyle(fontStyle);

View File

@ -34,7 +34,7 @@ public:
void SetStrokeText(const PaintState& state, const FillTextInfo& fillTextInfo) override;
void SetAntiAlias(bool anti) override;
void SetFontWeight(const FontWeight& weight) override;
void SetFontStyle(const FontStyle& fontStyle) override;
void SetFontStyle(const Ace::FontStyle& fontStyle) override;
void SetFontFamilies(const std::vector<std::string>& families) override;
void SetFontSize(const Dimension& size) override;
std::vector<double> GetLineDash() override;

View File

@ -61,7 +61,7 @@ void OffscreenCanvasRenderingContext2DModelNG::SetFontWeight(const FontWeight& w
pattern_->SetFontWeight(weight);
}
void OffscreenCanvasRenderingContext2DModelNG::SetFontStyle(const FontStyle& fontStyle)
void OffscreenCanvasRenderingContext2DModelNG::SetFontStyle(const Ace::FontStyle& fontStyle)
{
CHECK_NULL_VOID(pattern_);
pattern_->SetFontStyle(fontStyle);

View File

@ -34,7 +34,7 @@ public:
void SetStrokeText(const PaintState& state, const FillTextInfo& fillTextInfo) override;
void SetAntiAlias(bool anti) override;
void SetFontWeight(const FontWeight& weight) override;
void SetFontStyle(const FontStyle& fontStyle) override;
void SetFontStyle(const Ace::FontStyle& fontStyle) override;
void SetFontFamilies(const std::vector<std::string>& families) override;
void SetFontSize(const Dimension& size) override;
std::vector<double> GetLineDash() override;

View File

@ -337,7 +337,7 @@ public:
virtual void SetPlaceholder(PlaceholderOptions& options) = 0;
virtual void SetTextDetectEnable(bool value) = 0;
virtual void SetSupportPreviewText(bool value) = 0;
virtual void SetTextDetectConfig(const std::string& value, std::function<void(const std::string&)>&& onResult) = 0;
virtual void SetTextDetectConfig(const TextDetectConfig& textDetectConfig) = 0;
virtual void SetSelectedBackgroundColor(const DynamicColor& selectedColor) = 0;
virtual void SetCaretColor(const DynamicColor& color) = 0;
virtual void SetOnEditingChange(std::function<void(const bool&)>&& func) = 0;

View File

@ -275,25 +275,21 @@ void RichEditorModelNG::SetSupportPreviewText(bool value)
pattern->SetSupportPreviewText(value);
}
void RichEditorModelNG::SetTextDetectConfig(const std::string& value,
std::function<void(const std::string&)>&& onResult)
void RichEditorModelNG::SetTextDetectConfig(const TextDetectConfig& textDetectConfig)
{
auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
CHECK_NULL_VOID(frameNode);
auto pattern = frameNode->GetPattern<RichEditorPattern>();
CHECK_NULL_VOID(pattern);
pattern->SetTextDetectTypes(value);
pattern->SetOnResult(std::move(onResult));
pattern->SetTextDetectConfig(textDetectConfig);
}
void RichEditorModelNG::SetTextDetectConfig(FrameNode* frameNode, const std::string& value,
std::function<void(const std::string&)>&& onResult)
void RichEditorModelNG::SetTextDetectConfig(FrameNode* frameNode, const TextDetectConfig& textDetectConfig)
{
CHECK_NULL_VOID(frameNode);
auto pattern = frameNode->GetPattern<RichEditorPattern>();
CHECK_NULL_VOID(pattern);
pattern->SetTextDetectTypes(value);
pattern->SetOnResult(std::move(onResult));
pattern->SetTextDetectConfig(textDetectConfig);
}
void RichEditorModelNG::SetOnSelectionChange(FrameNode* frameNode, std::function<void(const BaseEventInfo*)>&& callback)

View File

@ -40,7 +40,7 @@ public:
void SetPlaceholder(PlaceholderOptions& options) override;
void SetTextDetectEnable(bool value) override;
void SetSupportPreviewText(bool value) override;
void SetTextDetectConfig(const std::string& value, std::function<void(const std::string&)>&& onResult) override;
void SetTextDetectConfig(const TextDetectConfig& textDetectConfig) override;
void SetSelectedBackgroundColor(const DynamicColor& selectedColor) override;
void SetCaretColor(const DynamicColor& color) override;
void SetOnEditingChange(std::function<void(const bool&)>&& func) override;
@ -53,8 +53,7 @@ public:
void SetRequestKeyboardOnFocus(bool needToRequest) override;
static void SetTextDetectEnable(FrameNode* frameNode, bool value);
static void SetTextDetectConfig(FrameNode* frameNode, const std::string& value,
std::function<void(const std::string&)>&& onResult);
static void SetTextDetectConfig(FrameNode* frameNode, const TextDetectConfig& textDetectConfig);
static void SetOnIMEInputComplete(FrameNode* frameNode,
std::function<void(const RichEditorAbstractSpanResult&)>&& callback);
static void SetOnDidIMEInput(FrameNode* frameNode, std::function<void(const TextRange&)>&& callback);

View File

@ -275,7 +275,9 @@ int32_t SpanItem::UpdateParagraph(const RefPtr<FrameNode>& frameNode, const RefP
CHECK_NULL_RETURN(pattern, -1);
textStyle.SetTextBackgroundStyle(backgroundStyle);
if (pattern->NeedShowAIDetect() && !aiSpanMap.empty()) {
UpdateTextStyleForAISpan(spanContent, builder, textStyle);
TextStyle aiSpanStyle = textStyle;
pattern->ModifyAISpanStyle(aiSpanStyle);
UpdateTextStyleForAISpan(spanContent, builder, textStyle, aiSpanStyle);
} else {
UpdateTextStyle(spanContent, builder, textStyle, selectedStart, selectedEnd);
}
@ -341,8 +343,8 @@ void SpanItem::UpdateSymbolSpanColor(const RefPtr<FrameNode>& frameNode, TextSty
}
}
void SpanItem::UpdateTextStyleForAISpan(
const std::string& spanContent, const RefPtr<Paragraph>& builder, const TextStyle& textStyle)
void SpanItem::UpdateTextStyleForAISpan(const std::string& spanContent, const RefPtr<Paragraph>& builder,
const TextStyle& textStyle, const TextStyle& aiSpanStyle)
{
auto wSpanContent = StringUtils::ToWstring(spanContent);
int32_t wSpanContentLength = static_cast<int32_t>(wSpanContent.length());
@ -351,8 +353,6 @@ void SpanItem::UpdateTextStyleForAISpan(
spanStart -= 1;
}
int32_t preEnd = spanStart;
std::optional<TextStyle> aiSpanTextStyle = textStyle;
SetAiSpanTextStyle(aiSpanTextStyle);
while (!aiSpanMap.empty()) {
auto aiSpan = aiSpanMap.begin()->second;
if (aiSpan.start >= position || preEnd >= position) {
@ -375,7 +375,7 @@ void SpanItem::UpdateTextStyleForAISpan(
}
auto displayContent = StringUtils::ToWstring(aiSpan.content)
.substr(aiSpanStartInSpan - aiSpan.start, aiSpanEndInSpan - aiSpanStartInSpan);
UpdateTextStyle(StringUtils::ToString(displayContent), builder, aiSpanTextStyle.value(),
UpdateTextStyle(StringUtils::ToString(displayContent), builder, aiSpanStyle,
selectedStart - contentStart, selectedEnd - contentStart);
preEnd = aiSpanEndInSpan;
if (aiSpan.end > position) {
@ -391,28 +391,6 @@ void SpanItem::UpdateTextStyleForAISpan(
}
}
void SpanItem::SetAiSpanTextStyle(std::optional<TextStyle>& aiSpanTextStyle)
{
auto pipelineContext = PipelineContext::GetCurrentContext();
CHECK_NULL_VOID(pipelineContext);
if (!aiSpanTextStyle.has_value()) {
TextStyle themeTextStyle =
CreateTextStyleUsingTheme(fontStyle, textLineStyle, pipelineContext->GetTheme<TextTheme>());
if (NearZero(themeTextStyle.GetFontSize().Value())) {
return;
}
aiSpanTextStyle = themeTextStyle;
} else {
auto hyerlinkTheme = pipelineContext->GetTheme<HyperlinkTheme>();
CHECK_NULL_VOID(hyerlinkTheme);
auto hyerlinkColor = hyerlinkTheme->GetTextColor();
aiSpanTextStyle.value().SetTextColor(hyerlinkColor);
aiSpanTextStyle.value().SetTextDecoration(TextDecoration::UNDERLINE);
aiSpanTextStyle.value().SetTextDecorationColor(hyerlinkColor);
aiSpanTextStyle.value().SetTextDecorationStyle(TextDecorationStyle::SOLID);
}
}
void SpanItem::FontRegisterCallback(const RefPtr<FrameNode>& frameNode, const TextStyle& textStyle)
{
auto callback = [weakNode = WeakPtr<FrameNode>(frameNode)] {

View File

@ -218,13 +218,12 @@ public:
virtual int32_t UpdateParagraph(const RefPtr<FrameNode>& frameNode, const RefPtr<Paragraph>& builder,
bool isSpanStringMode = false, PlaceholderStyle placeholderStyle = PlaceholderStyle(), bool isMarquee = false);
virtual void UpdateSymbolSpanColor(const RefPtr<FrameNode>& frameNode, TextStyle& symbolSpanStyle);
virtual void UpdateTextStyleForAISpan(
const std::string& content, const RefPtr<Paragraph>& builder, const TextStyle& textStyle);
virtual void UpdateTextStyleForAISpan(const std::string& content, const RefPtr<Paragraph>& builder,
const TextStyle& textStyle, const TextStyle& aiSpanStyle);
virtual void UpdateTextStyle(const std::string& content, const RefPtr<Paragraph>& builder,
const TextStyle& textStyle, const int32_t selStart, const int32_t selEnd);
virtual void UpdateContentTextStyle(
const std::string& content, const RefPtr<Paragraph>& builder, const TextStyle& textStyle);
virtual void SetAiSpanTextStyle(std::optional<TextStyle>& textStyle);
virtual void GetIndex(int32_t& start, int32_t& end) const;
virtual void FontRegisterCallback(const RefPtr<FrameNode>& frameNode, const TextStyle& textStyle);
virtual void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const;

View File

@ -204,8 +204,8 @@ void TextLayoutAlgorithm::UpdateParagraphForAISpan(
dragSpanPosition.dragStart = pattern->GetRecoverStart();
dragSpanPosition.dragEnd = pattern->GetRecoverEnd();
bool isDragging = pattern->IsDragging();
TextStyle aiSpanTextStyle = textStyle;
ResetAiSpanTextStyle(frameNode, aiSpanTextStyle);
TextStyle aiSpanStyle = textStyle;
pattern->ModifyAISpanStyle(aiSpanStyle);
for (auto kv : pattern->GetAISpanMap()) {
if (preEnd >= wTextForAILength) {
break;
@ -223,7 +223,7 @@ void TextLayoutAlgorithm::UpdateParagraphForAISpan(
preEnd = aiSpan.end;
dragSpanPosition.spanStart = aiSpan.start;
dragSpanPosition.spanEnd = aiSpan.end;
GrayDisplayAISpan(dragSpanPosition, wTextForAI, aiSpanTextStyle, isDragging, paragraph);
GrayDisplayAISpan(dragSpanPosition, wTextForAI, aiSpanStyle, isDragging, paragraph);
}
if (preEnd < wTextForAILength) {
dragSpanPosition.spanStart = preEnd;
@ -232,19 +232,6 @@ void TextLayoutAlgorithm::UpdateParagraphForAISpan(
}
}
void TextLayoutAlgorithm::ResetAiSpanTextStyle(const RefPtr<FrameNode>& frameNode, TextStyle& aiSpanTextStyle)
{
auto pipeline = frameNode->GetContext();
CHECK_NULL_VOID(pipeline);
auto hyerlinkTheme = pipeline->GetTheme<HyperlinkTheme>();
CHECK_NULL_VOID(hyerlinkTheme);
auto hyerlinkColor = hyerlinkTheme->GetTextColor();
aiSpanTextStyle.SetTextColor(hyerlinkColor);
aiSpanTextStyle.SetTextDecoration(TextDecoration::UNDERLINE);
aiSpanTextStyle.SetTextDecorationColor(hyerlinkColor);
aiSpanTextStyle.SetTextDecorationStyle(TextDecorationStyle::SOLID);
}
void TextLayoutAlgorithm::GrayDisplayAISpan(const DragSpanPosition& dragSpanPosition, const std::wstring wTextForAI,
const TextStyle& textStyle, bool isDragging, const RefPtr<Paragraph>& paragraph)
{

View File

@ -114,7 +114,6 @@ private:
bool AdaptMaxTextSize(TextStyle& textStyle, const std::string& content, const LayoutConstraintF& contentConstraint,
LayoutWrapper* layoutWrapper);
void UpdateSensitiveContent(std::string& content);
void ResetAiSpanTextStyle(const RefPtr<FrameNode>& frameNode, TextStyle& aiSpanTextStyle);
std::optional<TextStyle> textStyle_;
RefPtr<PropertyBool> showSelect_;

View File

@ -19,6 +19,7 @@
#include <functional>
#include <memory>
#include <mutex>
#include <optional>
#include <string>
#include "base/geometry/dimension.h"
@ -27,6 +28,7 @@
#include "base/utils/noncopyable.h"
#include "core/components/box/drag_drop_event.h"
#include "core/components/common/properties/color.h"
#include "core/components/hyperlink/hyperlink_theme.h"
#include "core/components_ng/event/gesture_event_hub.h"
#include "core/components_ng/pattern/text/layout_info_interface.h"
#include "core/components_ng/pattern/text/text_menu_extension.h"
@ -35,6 +37,36 @@
#include "core/components_ng/pattern/text_field/text_selector.h"
namespace OHOS::Ace {
struct TextDetectConfig {
std::string types;
std::function<void(const std::string&)> onResult;
Color entityColor;
TextDecoration entityDecorationType;
Color entityDecorationColor;
TextDecorationStyle entityDecorationStyle;
TextDetectConfig()
{
auto pipeline = PipelineContext::GetCurrentContextSafely();
CHECK_NULL_VOID(pipeline);
auto hyperlinkTheme = pipeline->GetTheme<HyperlinkTheme>();
CHECK_NULL_VOID(hyperlinkTheme);
entityColor = hyperlinkTheme->GetTextColor();
entityDecorationType = TextDecoration::UNDERLINE;
entityDecorationColor = entityColor;
entityDecorationStyle = TextDecorationStyle::SOLID;
}
std::string ToString() const
{
auto jsonValue = JsonUtil::Create(true);
JSON_STRING_PUT_STRING(jsonValue, types);
JSON_STRING_PUT_STRINGABLE(jsonValue, entityColor);
JSON_STRING_PUT_INT(jsonValue, entityDecorationType);
JSON_STRING_PUT_STRINGABLE(jsonValue, entityDecorationColor);
return jsonValue->ToString();
}
};
class ACE_EXPORT SpanStringBase : public AceType {
DECLARE_ACE_TYPE(SpanStringBase, AceType);
};
@ -81,7 +113,7 @@ public:
virtual void SetAdaptMaxFontSize(const Dimension& value) = 0;
virtual void SetHeightAdaptivePolicy(TextHeightAdaptivePolicy value) = 0;
virtual void SetTextDetectEnable(bool value) = 0;
virtual void SetTextDetectConfig(const std::string& value, std::function<void(const std::string&)>&& onResult) = 0;
virtual void SetTextDetectConfig(const TextDetectConfig& textDetectConfig) = 0;
virtual void OnSetWidth() {};
virtual void OnSetHeight() {};
virtual void OnSetAlign() {};

View File

@ -357,14 +357,13 @@ void TextModelNG::SetTextDetectEnable(bool value)
textPattern->SetTextDetectEnable(value);
}
void TextModelNG::SetTextDetectConfig(const std::string& value, std::function<void(const std::string&)>&& onResult)
void TextModelNG::SetTextDetectConfig(const TextDetectConfig& textDetectConfig)
{
auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
CHECK_NULL_VOID(frameNode);
auto textPattern = frameNode->GetPattern<TextPattern>();
CHECK_NULL_VOID(textPattern);
textPattern->SetTextDetectTypes(value);
textPattern->SetOnResult(std::move(onResult));
textPattern->SetTextDetectConfig(textDetectConfig);
}
void TextModelNG::SetOnClick(std::function<void(BaseEventInfo* info)>&& click)
@ -997,14 +996,12 @@ void TextModelNG::SetTextSelection(FrameNode* frameNode, int32_t startIndex, int
textPattern->SetTextSelection(startIndex, endIndex);
}
void TextModelNG::SetTextDetectConfig(FrameNode* frameNode, const std::string& value,
std::function<void(const std::string&)>&& onResult)
void TextModelNG::SetTextDetectConfig(FrameNode* frameNode, const TextDetectConfig& textDetectConfig)
{
CHECK_NULL_VOID(frameNode);
auto textPattern = frameNode->GetPattern<TextPattern>();
CHECK_NULL_VOID(textPattern);
textPattern->SetTextDetectTypes(value);
textPattern->SetOnResult(std::move(onResult));
textPattern->SetTextDetectConfig(textDetectConfig);
}
void TextModelNG::SetOnCopy(FrameNode* frameNode, std::function<void(const std::string&)>&& func)

View File

@ -60,7 +60,7 @@ public:
void SetAdaptMaxFontSize(const Dimension& value) override;
void SetHeightAdaptivePolicy(TextHeightAdaptivePolicy value) override;
void SetTextDetectEnable(bool value) override;
void SetTextDetectConfig(const std::string& value, std::function<void(const std::string&)>&& onResult) override;
void SetTextDetectConfig(const TextDetectConfig& textDetectConfig) override;
void SetOnClick(std::function<void(BaseEventInfo* info)>&& click) override;
void ClearOnClick() override;
void SetRemoteMessage(std::function<void()>&& event) override;
@ -161,8 +161,7 @@ public:
static LineBreakStrategy GetLineBreakStrategy(FrameNode* frameNode);
static void SetTextSelection(FrameNode* frameNode, int32_t startIndex, int32_t endIndex);
static void SetTextSelectableMode(FrameNode* frameNode, TextSelectableMode value);
static void SetTextDetectConfig(FrameNode* frameNode, const std::string& value,
std::function<void(const std::string&)>&& onResult);
static void SetTextDetectConfig(FrameNode* frameNode, const TextDetectConfig& textDetectConfig);
static void SetOnCopy(FrameNode* frameNode, std::function<void(const std::string&)>&& func);
static void SetOnTextSelectionChange(FrameNode* frameNode, std::function<void(int32_t, int32_t)>&& func);
static void SetSelectionMenuOptions(FrameNode* frameNode, const NG::OnCreateMenuCallback&& onCreateMenuCallback,

View File

@ -239,6 +239,33 @@ public:
{
return dataDetectorAdapter_->textDetectResult_;
}
void SetTextDetectConfig(const TextDetectConfig& textDetectConfig)
{
dataDetectorAdapter_->SetTextDetectTypes(textDetectConfig.types);
dataDetectorAdapter_->onResult_ = std::move(textDetectConfig.onResult);
dataDetectorAdapter_->entityColor_ = textDetectConfig.entityColor;
dataDetectorAdapter_->entityDecorationType_ = textDetectConfig.entityDecorationType;
dataDetectorAdapter_->entityDecorationColor_ = textDetectConfig.entityDecorationColor;
dataDetectorAdapter_->entityDecorationStyle_ = textDetectConfig.entityDecorationStyle;
auto textDetectConfigCache = dataDetectorAdapter_->textDetectConfigStr_;
dataDetectorAdapter_->textDetectConfigStr_ = textDetectConfig.ToString();
if (textDetectConfigCache != dataDetectorAdapter_->textDetectConfigStr_) {
auto host = GetHost();
CHECK_NULL_VOID(host);
host->MarkDirtyNode(PROPERTY_UPDATE_MEASURE);
}
}
void ModifyAISpanStyle(TextStyle& aiSpanStyle)
{
TextDetectConfig textDetectConfig;
aiSpanStyle.SetTextColor(dataDetectorAdapter_->entityColor_.value_or(textDetectConfig.entityColor));
aiSpanStyle.SetTextDecoration(
dataDetectorAdapter_->entityDecorationType_.value_or(textDetectConfig.entityDecorationType));
aiSpanStyle.SetTextDecorationColor(
dataDetectorAdapter_->entityDecorationColor_.value_or(textDetectConfig.entityColor));
aiSpanStyle.SetTextDecorationStyle(
dataDetectorAdapter_->entityDecorationStyle_.value_or(textDetectConfig.entityDecorationStyle));
}
void OnVisibleChange(bool isVisible) override;

View File

@ -304,6 +304,15 @@ struct ArkUITextShadowStruct {
ArkUI_Uint32 fill;
};
struct ArkUITextDetectConfigStruct {
ArkUI_CharPtr types;
void* onResult;
ArkUI_Uint32 entityColor;
ArkUI_Int32 entityDecorationType;
ArkUI_Uint32 entityDecorationColor;
ArkUI_Int32 entityDecorationStyle;
};
struct ArkUIImagePropertiesStruct {
ArkUI_CharPtr src;
ArkUI_Float32 number[4];
@ -1994,7 +2003,8 @@ struct ArkUITextModifier {
void (*resetTextSelection)(ArkUINodeHandle node);
void (*setTextSelectableMode)(ArkUINodeHandle node, ArkUI_Uint32 textSelectableMode);
void (*resetTextSelectableMode)(ArkUINodeHandle node);
void (*setTextDataDetectorConfigWithEvent)(ArkUINodeHandle node, ArkUI_CharPtr types, void* callback);
void (*setTextDataDetectorConfigWithEvent)(
ArkUINodeHandle node, const struct ArkUITextDetectConfigStruct* arkUITextDetectConfig);
void (*resetTextDataDetectorConfigWithEvent)(ArkUINodeHandle node);
void (*setTextOnCopy)(ArkUINodeHandle node, void* callback);
void (*resetTextOnCopy)(ArkUINodeHandle node);
@ -4243,7 +4253,8 @@ struct ArkUIColumnSplitModifier {
struct ArkUIRichEditorModifier {
void (*setRichEditorEnableDataDetector)(ArkUINodeHandle node, ArkUI_Uint32 enableDataDetector);
void (*resetRichEditorEnableDataDetector)(ArkUINodeHandle node);
void (*setRichEditorDataDetectorConfigWithEvent)(ArkUINodeHandle node, ArkUI_CharPtr types, void* callback);
void (*setRichEditorDataDetectorConfigWithEvent)(
ArkUINodeHandle node, const struct ArkUITextDetectConfigStruct* arkUITextDetectConfig);
void (*resetRichEditorDataDetectorConfigWithEvent)(ArkUINodeHandle node);
void (*setRichEditorOnIMEInputComplete)(ArkUINodeHandle node, void* callback);
void (*resetRichEditorOnIMEInputComplete)(ArkUINodeHandle node);

View File

@ -640,7 +640,8 @@ struct CJUITextModifier {
void (*resetTextSelection)(ArkUINodeHandle node);
void (*setTextSelectableMode)(ArkUINodeHandle node, ArkUI_Uint32 textSelectableMode);
void (*resetTextSelectableMode)(ArkUINodeHandle node);
void (*setTextDataDetectorConfigWithEvent)(ArkUINodeHandle node, ArkUI_CharPtr types, void* callback);
void (*setTextDataDetectorConfigWithEvent)(
ArkUINodeHandle node, const struct ArkUITextDetectConfigStruct* arkUITextDetectConfig);
void (*resetTextDataDetectorConfigWithEvent)(ArkUINodeHandle node);
void (*setTextOnCopy)(ArkUINodeHandle node, void* callback);
void (*resetTextOnCopy)(ArkUINodeHandle node);

View File

@ -58,7 +58,7 @@ const std::vector<EllipsisMode> ELLIPSIS_MODALS = { EllipsisMode::HEAD, Ellipsis
const std::vector<TextSelectableMode> TEXT_SELECTABLE_MODE = { TextSelectableMode::SELECTABLE_UNFOCUSABLE,
TextSelectableMode::SELECTABLE_FOCUSABLE, TextSelectableMode::UNSELECTABLE };
constexpr bool DEFAULT_ENABLE_TEXT_DETECTOR = false;
const std::vector<std::string> TEXT_DETECT_TYPES = { "phoneNum", "url", "email", "location" };
const std::vector<std::string> TEXT_DETECT_TYPES = { "phoneNum", "url", "email", "location", "datetime" };
std::map<TextHeightAdaptivePolicy, int> TEXT_HEIGHT_ADAPTIVE_POLICY_MAP = {
{ TextHeightAdaptivePolicy::MAX_LINES_FIRST, 0 },
@ -1000,23 +1000,30 @@ void ResetTextSelectableMode(ArkUINodeHandle node)
TextModelNG::SetTextSelectableMode(frameNode, TEXT_SELECTABLE_MODE[0]);
}
void SetTextDataDetectorConfigWithEvent(ArkUINodeHandle node, ArkUI_CharPtr types, void* callback)
void SetTextDataDetectorConfigWithEvent(
ArkUINodeHandle node, const struct ArkUITextDetectConfigStruct* arkUITextDetectConfig)
{
auto* frameNode = reinterpret_cast<FrameNode*>(node);
CHECK_NULL_VOID(frameNode);
std::string strValue = types;
std::function<void(const std::string&)>* onResult = nullptr;
if (callback) {
onResult = reinterpret_cast<std::function<void(const std::string&)>*>(callback);
TextDetectConfig textDetectConfig;
textDetectConfig.types = arkUITextDetectConfig->types;
if (arkUITextDetectConfig->onResult) {
textDetectConfig.onResult =
std::move(*(reinterpret_cast<std::function<void(const std::string&)>*>(arkUITextDetectConfig->onResult)));
}
TextModelNG::SetTextDetectConfig(frameNode, strValue, std::move(*onResult));
textDetectConfig.entityColor = Color(arkUITextDetectConfig->entityColor);
textDetectConfig.entityDecorationType = TextDecoration(arkUITextDetectConfig->entityDecorationType);
textDetectConfig.entityDecorationColor = Color(arkUITextDetectConfig->entityDecorationColor);
textDetectConfig.entityDecorationStyle = TextDecorationStyle(arkUITextDetectConfig->entityDecorationStyle);
TextModelNG::SetTextDetectConfig(frameNode, textDetectConfig);
}
void ResetTextDataDetectorConfigWithEvent(ArkUINodeHandle node)
{
auto* frameNode = reinterpret_cast<FrameNode*>(node);
CHECK_NULL_VOID(frameNode);
TextModelNG::SetTextDetectConfig(frameNode, "", nullptr);
TextDetectConfig textDetectConfig;
TextModelNG::SetTextDetectConfig(frameNode, textDetectConfig);
}
void SetTextOnCopy(ArkUINodeHandle node, void* callback)

View File

@ -38,23 +38,30 @@ void ResetRichEditorDetectEnable(ArkUINodeHandle node)
RichEditorModelNG::SetTextDetectEnable(frameNode, DEFAULT_ENABLE_TEXT_DETECTOR);
}
void SetRichEditorDataDetectorConfigWithEvent(ArkUINodeHandle node, ArkUI_CharPtr types, void* callback)
void SetRichEditorDataDetectorConfigWithEvent(
ArkUINodeHandle node, const struct ArkUITextDetectConfigStruct* arkUITextDetectConfig)
{
auto* frameNode = reinterpret_cast<FrameNode*>(node);
CHECK_NULL_VOID(frameNode);
std::string strValue = types;
std::function<void(const std::string&)>* onResult = nullptr;
if (callback) {
onResult = reinterpret_cast<std::function<void(const std::string&)>*>(callback);
TextDetectConfig textDetectConfig;
textDetectConfig.types = arkUITextDetectConfig->types;
if (arkUITextDetectConfig->onResult) {
textDetectConfig.onResult =
std::move(*(reinterpret_cast<std::function<void(const std::string&)>*>(arkUITextDetectConfig->onResult)));
}
RichEditorModelNG::SetTextDetectConfig(frameNode, strValue, std::move(*onResult));
textDetectConfig.entityColor = Color(arkUITextDetectConfig->entityColor);
textDetectConfig.entityDecorationType = TextDecoration(arkUITextDetectConfig->entityDecorationType);
textDetectConfig.entityDecorationColor = Color(arkUITextDetectConfig->entityDecorationColor);
textDetectConfig.entityDecorationStyle = TextDecorationStyle(arkUITextDetectConfig->entityDecorationStyle);
RichEditorModelNG::SetTextDetectConfig(frameNode, textDetectConfig);
}
void ResetRichEditorDataDetectorConfigWithEvent(ArkUINodeHandle node)
{
auto* frameNode = reinterpret_cast<FrameNode*>(node);
CHECK_NULL_VOID(frameNode);
RichEditorModelNG::SetTextDetectConfig(frameNode, "", nullptr);
TextDetectConfig textDetectConfig;
RichEditorModelNG::SetTextDetectConfig(frameNode, textDetectConfig);
}
void SetRichEditorOnIMEInputComplete(ArkUINodeHandle node, void* callback)

View File

@ -883,7 +883,9 @@ HWTEST_F(SpanTestNg, UpdateTextStyleForAISpan001, TestSize.Level1)
.textOverflow = textStyle.GetTextOverflow() };
auto paragraph= MockParagraph::GetOrCreateMockParagraph();
spanNode->spanItem_->UpdateTextStyleForAISpan(spanContent, paragraph, textStyle);
auto aiSpanStyle = textStyle;
pattern->ModifyAISpanStyle(aiSpanStyle);
spanNode->spanItem_->UpdateTextStyleForAISpan(spanContent, paragraph, textStyle, aiSpanStyle);
EXPECT_EQ(spanNode->spanItem_->fontStyle, nullptr);
}
@ -1324,13 +1326,15 @@ HWTEST_F(SpanTestNg, UpdateTextStyleForAISpan002, TestSize.Level1)
std::string spanContent = TEXT_FOR_AI;
spanNode->spanItem_->position = StringUtils::ToWstring(spanContent).length();
TextStyle textStyle;
auto aiSpanStyle = textStyle;
pattern->ModifyAISpanStyle(aiSpanStyle);
auto paragraph = MockParagraph::GetOrCreateMockParagraph();
EXPECT_CALL(*paragraph, PushStyle).Times(AnyNumber());
EXPECT_CALL(*paragraph, AddText).Times(AnyNumber());
EXPECT_CALL(*paragraph, PopStyle).Times(AnyNumber());
spanNode->spanItem_->SetNeedRemoveNewLine(true);
spanNode->spanItem_->UpdateTextStyleForAISpan(spanContent, paragraph, textStyle);
spanNode->spanItem_->UpdateTextStyleForAISpan(spanContent, paragraph, textStyle, aiSpanStyle);
EXPECT_EQ(spanNode->spanItem_->fontStyle, nullptr);
MockParagraph::TearDown();
}

View File

@ -221,13 +221,15 @@ HWTEST_F(TextTestNg, SetTextDetectEnable003, TestSize.Level1)
textModelNG.SetTextDetectConfig(frameNode, "apple, orange, banana");
ASSERT_NE(textModelNG.GetTextDetectConfig(frameNode), "apple, orange, banana");
auto onResult = [](const std::string&) {};
textModelNG.SetTextDetectConfig(frameNode, "apple, orange, banana", std::move(onResult));
TextDetectConfig textDetectConfig;
textDetectConfig.types = "apple, orange, banana";
textDetectConfig.onResult = [](const std::string&) {};
textModelNG.SetTextDetectConfig(frameNode, textDetectConfig);
ASSERT_NE(textModelNG.GetTextDetectConfig(frameNode), "apple, orange, banana");
auto textPattern = frameNode->GetPattern<TextPattern>();
ASSERT_NE(textPattern, nullptr);
textModelNG.SetOnDetectResultUpdate(frameNode, std::move(onResult));
textModelNG.SetOnDetectResultUpdate(frameNode, std::move(textDetectConfig.onResult));
EXPECT_NE(textPattern->dataDetectorAdapter_->onResult_, nullptr);
FONT_FEATURES_LIST value;
@ -658,37 +660,6 @@ HWTEST_F(TextTestNg, MeasureContent001, TestSize.Level1)
EXPECT_EQ(ret.has_value(), true);
}
/**
* @tc.name: ResetAiSpanTextStyle001
* @tc.desc: Test ResetAiSpanTextStyle.
* @tc.type: FUNC
*/
HWTEST_F(TextTestNg, ResetAiSpanTextStyle001, TestSize.Level1)
{
/**
* @tc.steps: step1. init
*/
auto pattern = AceType::MakeRefPtr<TextPattern>();
auto frameNode = FrameNode::CreateFrameNode("Test", 1, pattern);
ASSERT_NE(frameNode, nullptr);
pattern->AttachToFrameNode(frameNode);
pattern->selectOverlayProxy_ = nullptr;
DirtySwapConfig config;
config.skipMeasure = false;
auto layoutWrapper = AceType::MakeRefPtr<LayoutWrapperNode>(
frameNode, AceType::MakeRefPtr<GeometryNode>(), frameNode->GetLayoutProperty());
ASSERT_NE(layoutWrapper, nullptr);
auto rowLayoutAlgorithm = AceType::DynamicCast<TextLayoutAlgorithm>(pattern->CreateLayoutAlgorithm());
ASSERT_NE(rowLayoutAlgorithm, nullptr);
/**
* @tc.steps: step2. call function.
*/
TextStyle textStyle;
rowLayoutAlgorithm->ResetAiSpanTextStyle(frameNode, textStyle);
EXPECT_EQ(textStyle.textDecoration_, TextDecoration::NONE);
}
/**
* @tc.name: UpdateParagraphForAISpan001
* @tc.desc: Test UpdateParagraphForAISpan

View File

@ -1787,33 +1787,6 @@ HWTEST_F(TextTestFiveNg, UpdateSymbolSpanColor001, TestSize.Level1)
EXPECT_EQ(symbolSpanStyle.GetSymbolColorList().size(), 1);
}
/**
* @tc.name: SetAiSpanTextStyle001
* @tc.desc: test span_node.cpp SetAiSpanTextStyle function
* @tc.type: FUNC
*/
HWTEST_F(TextTestFiveNg, SetAiSpanTextStyle001, TestSize.Level1)
{
auto pattern = AceType::MakeRefPtr<TextPattern>();
ASSERT_NE(pattern, nullptr);
auto frameNode = FrameNode::CreateFrameNode("Test", 1, pattern);
ASSERT_NE(frameNode, nullptr);
pattern->AttachToFrameNode(frameNode);
auto spanItem = AceType::MakeRefPtr<SpanItem>();
ASSERT_NE(spanItem, nullptr);
std::optional<TextStyle> aiSpanTextStyle = std::nullopt;
spanItem->fontStyle->UpdateFontSize(Dimension(0));
spanItem->SetAiSpanTextStyle(aiSpanTextStyle);
EXPECT_EQ(aiSpanTextStyle, std::nullopt);
spanItem->fontStyle->UpdateFontSize(Dimension(10));
spanItem->SetAiSpanTextStyle(aiSpanTextStyle);
EXPECT_NE(aiSpanTextStyle, std::nullopt);
}
/**
* @tc.name: FontRegisterCallback002
* @tc.desc: test span_node.cpp FontRegisterCallback function

View File

@ -1658,9 +1658,8 @@ HWTEST_F(TextTestThreeNg, SetTextDetectTypes001, TestSize.Level1)
*/
TextModelNG textModelNG;
textModelNG.Create("");
textModelNG.SetCopyOption(CopyOptions::InApp);
auto onResult = [](const std::string&) {};
textModelNG.SetTextDetectConfig("apple, orange, banana", std::move(onResult));
TextDetectConfig textDetectConfig;
textModelNG.SetTextDetectConfig(textDetectConfig);
auto frameNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
auto pattern = frameNode->GetPattern<TextPattern>();
EXPECT_EQ(pattern->dataDetectorAdapter_->aiDetectInitialized_, false);