From af996d529b105b0a01ad8ec7a114b440d5e53273 Mon Sep 17 00:00:00 2001 From: guanzengkun Date: Wed, 13 Mar 2024 14:37:46 +0800 Subject: [PATCH] =?UTF-8?q?https://gitee.com/openharmony/arkui=5Face=5Feng?= =?UTF-8?q?ine/issues/I985P3=20Description:[=E6=96=B0=E9=9C=80=E6=B1=82]:?= =?UTF-8?q?=20=E8=A1=A5=E5=85=85=E9=9C=80=E6=B1=82=E7=9A=84js=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0=E9=83=A8=E5=88=86=20Sig:=20SIG=5FApplicationFramework?= =?UTF-8?q?=20Feature=20or=20Bugfix:Feature=20Binary=20Source:No=20TDD:(?= =?UTF-8?q?=E8=AF=84=E4=BC=B0=E4=B8=8D=E6=B6=89=E5=8F=8A)=20XTS:Pass=20?= =?UTF-8?q?=E9=A2=84=E6=B5=8B=E8=AF=95:(=E8=AF=84=E4=BC=B0=E4=B8=8D?= =?UTF-8?q?=E6=B6=89=E5=8F=8A)=20Signed-off-by:guanzengkun=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../style_string/js_span_object.cpp | 68 ++- .../style_string/js_span_object.h | 7 +- .../style_string/js_span_string.cpp | 480 +++++++++++++++++- .../style_string/js_span_string.h | 6 +- .../pattern/text/span/span_string.h | 2 +- 5 files changed, 553 insertions(+), 10 deletions(-) diff --git a/frameworks/bridge/declarative_frontend/style_string/js_span_object.cpp b/frameworks/bridge/declarative_frontend/style_string/js_span_object.cpp index c944e0a5e58..31d7a8609a6 100644 --- a/frameworks/bridge/declarative_frontend/style_string/js_span_object.cpp +++ b/frameworks/bridge/declarative_frontend/style_string/js_span_object.cpp @@ -15,4 +15,70 @@ #include "frameworks/bridge/declarative_frontend/jsview/js_span_object.h" -namespace OHOS::Ace::Framework {} // namespace OHOS::Ace::Framework \ No newline at end of file +#include "frameworks/bridge/common/utils/utils.h" +#include "frameworks/bridge/declarative_frontend/engine/functions/js_function.h" +#include "frameworks/bridge/declarative_frontend/jsview/js_view_abstract.h" +namespace OHOS::Ace::Framework { + +void JSFontSpan::JSBind(BindingTarget globalObj) +{ + JSClass::Declare("TextStyle"); + JSClass::CustomProperty("fontColor", &JSFontSpan::GetFontColor, &JSFontSpan::SetFontColor); + JSClass::Bind(globalObj, JSFontSpan::Constructor, JSFontSpan::Destructor); +} + +void JSFontSpan::Constructor(const JSCallbackInfo& args) +{ + auto fontSpan = Referenced::MakeRefPtr(); + fontSpan->IncRefCount(); + + RefPtr span; + if (args.Length() <= 0) { + Font font; + span = AceType::MakeRefPtr(font); + } else { + span = JSFontSpan::ParseJsFontSpan(JSRef::Cast(args[0])); + } + fontSpan->fontSpan_ = span; + args.SetReturnValue(Referenced::RawPtr(fontSpan)); +} + +void JSFontSpan::Destructor(JSFontSpan* fontSpan) +{ + if (fontSpan != nullptr) { + fontSpan->DecRefCount(); + } +} + +RefPtr JSFontSpan::ParseJsFontSpan(JSRef obj) +{ + Font font; + Color color; + JSRef colorObj = JSRef::Cast(obj->GetProperty("fontColor")); + if (!colorObj->IsNull() && JSViewAbstract::ParseJsColor(colorObj, color)) { + font.fontColor = color; + } + return AceType::MakeRefPtr(font); +} +void JSFontSpan::GetFontColor(const JSCallbackInfo& info) +{ + CHECK_NULL_VOID(fontSpan_); + if (!fontSpan_->GetFont().fontColor.has_value()) { + return; + } + auto ret = JSRef::Make(JSVal(ToJSValue(fontSpan_->GetFont().GetFontColor()))); + info.SetReturnValue(ret); +} + +void JSFontSpan::SetFontColor(const JSCallbackInfo& info) {} + +RefPtr& JSFontSpan::GetFontSpan() +{ + return fontSpan_; +} +void JSFontSpan::SetFontSpan(const RefPtr& fontSpan) +{ + fontSpan_ = fontSpan; +} + +} // namespace OHOS::Ace::Framework \ No newline at end of file diff --git a/frameworks/bridge/declarative_frontend/style_string/js_span_object.h b/frameworks/bridge/declarative_frontend/style_string/js_span_object.h index c2033e377d7..4d7d358d4ef 100644 --- a/frameworks/bridge/declarative_frontend/style_string/js_span_object.h +++ b/frameworks/bridge/declarative_frontend/style_string/js_span_object.h @@ -38,11 +38,8 @@ public: static void Destructor(JSFontSpan* fontSpan); static void JSBind(BindingTarget globalObj); static RefPtr ParseJsFontSpan(JSRef obj); - void GetColor(const JSCallbackInfo& info); - void GetSize(const JSCallbackInfo& info); - void GetWeight(const JSCallbackInfo& info); - void GetFamily(const JSCallbackInfo& info); - void GetStyle(const JSCallbackInfo& info); + void GetFontColor(const JSCallbackInfo& info); + void SetFontColor(const JSCallbackInfo& info); RefPtr& GetFontSpan(); void SetFontSpan(const RefPtr& fontSpan); diff --git a/frameworks/bridge/declarative_frontend/style_string/js_span_string.cpp b/frameworks/bridge/declarative_frontend/style_string/js_span_string.cpp index 0c7a7c7d5d0..4c6001ca782 100644 --- a/frameworks/bridge/declarative_frontend/style_string/js_span_string.cpp +++ b/frameworks/bridge/declarative_frontend/style_string/js_span_string.cpp @@ -15,4 +15,482 @@ #include "frameworks/bridge/declarative_frontend/jsview/js_span_string.h" -namespace OHOS::Ace::Framework {} // namespace OHOS::Ace::Framework \ No newline at end of file +#include "frameworks/bridge/common/utils/utils.h" +#include "frameworks/bridge/declarative_frontend/engine/functions/js_function.h" +#include "frameworks/bridge/declarative_frontend/jsview/js_span_object.h" +#include "frameworks/bridge/declarative_frontend/jsview/js_view_abstract.h" +namespace OHOS::Ace::Framework { + +const std::vector types = { SpanType::Font }; + +void JSSpanString::Constructor(const JSCallbackInfo& args) +{ + auto jsSpanString = Referenced::MakeRefPtr(); + jsSpanString->IncRefCount(); + std::string data; + RefPtr spanString; + if (args.Length() == 0) { + spanString = AceType::MakeRefPtr(data); + } else if (args.Length() == 1) { + JSViewAbstract::ParseJsString(args[0], data); + spanString = AceType::MakeRefPtr(data); + } else { + JSViewAbstract::ParseJsString(args[0], data); + auto spanBases = JSSpanString::ParseJsSpanBaseVector(args[1], StringUtils::ToWstring(data).length()); + spanString = AceType::MakeRefPtr(data, spanBases); + } + jsSpanString->SetController(spanString); + args.SetReturnValue(Referenced::RawPtr(jsSpanString)); +} + +void JSSpanString::Destructor(JSSpanString* spanString) +{ + if (spanString != nullptr) { + spanString->DecRefCount(); + } +} + +void JSSpanString::JSBind(BindingTarget globalObj) +{ + JSClass::Declare("StyledString"); + JSClass::CustomMethod("getString", &JSSpanString::GetString); + JSClass::CustomProperty("length", &JSSpanString::GetLength, &JSSpanString::SetLength); + JSClass::CustomMethod("equals", &JSSpanString::IsEqualToSpanString); + JSClass::CustomMethod("subStyledString", &JSSpanString::GetSubSpanString); + JSClass::CustomMethod("getStyles", &JSSpanString::GetSpans); + JSClass::Bind(globalObj, JSSpanString::Constructor, JSSpanString::Destructor); +} + +void JSSpanString::GetString(const JSCallbackInfo& info) +{ + auto ret = JSRef::Make(JSVal(ToJSValue(spanString_->GetString()))); + info.SetReturnValue(ret); +} + +void JSSpanString::GetLength(const JSCallbackInfo& info) +{ + auto ret = JSRef::Make(JSVal(ToJSValue(spanString_->GetLength()))); + info.SetReturnValue(ret); +} + +void JSSpanString::SetLength(const JSCallbackInfo& info) {} + +void JSSpanString::IsEqualToSpanString(const JSCallbackInfo& info) +{ + if (info.Length() != 1 || !info[0]->IsObject()) { + info.SetReturnValue(JSRef::Make(JSVal(ToJSValue(false)))); + return; + } + auto jsSpanString = JSRef::Cast(info[0])->Unwrap(); + if (!jsSpanString || !jsSpanString->GetController()) { + info.SetReturnValue(JSRef::Make(JSVal(ToJSValue(false)))); + return; + } + auto spanString = jsSpanString->GetController(); + auto ret = JSRef::Make(JSVal(ToJSValue(spanString_->IsEqualToSpanString(spanString)))); + info.SetReturnValue(ret); +} + +void JSSpanString::GetSubSpanString(const JSCallbackInfo& info) +{ + if (info.Length() < 1 || !info[0]->IsNumber()) { + return; + } + auto start = info[0]->ToNumber(); + auto length = spanString_->GetLength() - start; + if (info.Length() == 2 && info[1]->IsNumber()) { + length = info[1]->ToNumber(); + } + CheckParameters(start, length); + auto spanString = spanString_->GetSubSpanString(start, length); + CHECK_NULL_VOID(spanString); + JSRef obj = JSClass::NewInstance(); + auto jsSpanString = Referenced::Claim(obj->Unwrap()); + jsSpanString->SetController(spanString); + info.SetReturnValue(obj); +} + +void JSSpanString::GetSpans(const JSCallbackInfo& info) +{ + if (info.Length() < 2 || !info[0]->IsNumber() || !info[1]->IsNumber()) { + return; + } + auto start = info[0]->ToNumber(); + auto length = info[1]->ToNumber(); + CheckParameters(start, length); + std::vector> spans; + if (info.Length() >= 3 && info[2]->IsNumber()) { + CheckSpanType(info[2]->ToNumber()); + SpanType type = static_cast(info[2]->ToNumber()); + spans = spanString_->GetSpans(start, length, type); + } else { + spans = spanString_->GetSpans(start, length); + } + + JSRef spanObjectArray = JSRef::New(); + uint32_t idx = 0; + for (const RefPtr& spanObject : spans) { + spanObjectArray->SetValueAt(idx++, CreateJSSpanBaseObject(spanObject)); + } + info.SetReturnValue(JSRef::Cast(spanObjectArray)); +} + +JSRef JSSpanString::CreateJSSpanBaseObject(const RefPtr& spanObject) +{ + JSRef resultObj = JSRef::New(); + resultObj->SetProperty("start", spanObject->GetStartIndex()); + resultObj->SetProperty("length", spanObject->GetLength()); + resultObj->SetProperty("styleKey", static_cast(spanObject->GetSpanType())); + switch (spanObject->GetSpanType()) { + case SpanType::Font: { + JSRef obj = CreateJsFontSpan(spanObject); + resultObj->SetPropertyObject("styleValue", obj); + return resultObj; + } + default: + break; + } + + return resultObj; +} + +JSRef JSSpanString::CreateJsFontSpan(const RefPtr& spanObject) +{ + auto span = AceType::DynamicCast(spanObject); + CHECK_NULL_RETURN(span, JSRef::New()); + JSRef obj = JSClass::NewInstance(); + auto fontSpan = Referenced::Claim(obj->Unwrap()); + fontSpan->SetFontSpan(span); + return obj; +} + +RefPtr JSSpanString::ParseJsSpanBase(int32_t start, int32_t length, SpanType type, JSRef obj) +{ + switch (type) { + case SpanType::Font: + return ParseJsFontSpan(start, length, obj); + default: + break; + } + return nullptr; +} + +RefPtr JSSpanString::ParseJsFontSpan(int32_t start, int32_t length, JSRef obj) +{ + auto* fontSpan = obj->Unwrap(); + if (fontSpan && fontSpan->GetFontSpan()) { + return AceType::MakeRefPtr(fontSpan->GetFontSpan()->GetFont(), start, start + length); + } + return nullptr; +} + +void JSSpanString::CheckSpanType(const int32_t& type) +{ + if (type < 0 || type >= static_cast(types.size())) { + JSException::Throw(ERROR_CODE_PARAM_INVALID, "%s", "Input span type check failed."); + } +} + +void JSSpanString::CheckParameters(const int32_t& start, const int32_t& length) +{ + // The input parameter must not cross the boundary. + if (!spanString_->CheckRange(start, length)) { + JSException::Throw(ERROR_CODE_PARAM_INVALID, "%s", "Input parameter check failed."); + } +} + +std::vector> JSSpanString::ParseJsSpanBaseVector(JSRef obj, int32_t maxLength) +{ + std::vector> spanBaseVector; + auto arrays = JSRef::Cast(obj); + for (size_t i = 0; i < arrays->Length(); i++) { + JSRef value = arrays->GetValueAt(i); + if (value->IsNull() || value->IsUndefined()) { + continue; + } + auto valueObj = JSRef::Cast(value); + auto startProperty = valueObj->GetProperty("start"); + auto lengthProperty = valueObj->GetProperty("length"); + int32_t start = 0; + if (!startProperty->IsNull() && startProperty->IsNumber()) { + start = startProperty->ToNumber(); + start = start < 0 ? 0 : start; + } + int32_t length = maxLength - start; + if (!lengthProperty->IsNull() && lengthProperty->IsNumber()) { + length = lengthProperty->ToNumber(); + length = length > maxLength - start ? maxLength - start : length; + } + auto styleKey = valueObj->GetProperty("styleKey"); + if (styleKey->IsNull() || !styleKey->IsNumber()) { + continue; + } + auto styleStringValue = valueObj->GetProperty("styleValue"); + if (!styleStringValue->IsObject()) { + continue; + } + SpanType type = static_cast(styleKey->ToNumber()); + auto spanBase = ParseJsSpanBase(start, length, type, JSRef::Cast(styleStringValue)); + if (spanBase) { + spanBaseVector.push_back(spanBase); + } + } + return spanBaseVector; +} + +RefPtr& JSSpanString::GetController() +{ + return spanString_; +} + +void JSSpanString::SetController(const RefPtr& spanString) +{ + spanString_ = spanString; +} + +void JSMutableSpanString::Constructor(const JSCallbackInfo& args) +{ + auto jsSpanString = Referenced::MakeRefPtr(); + jsSpanString->IncRefCount(); + std::string data; + + RefPtr spanString; + if (args.Length() == 0) { + spanString = AceType::MakeRefPtr(data); + } else if (args.Length() == 1) { + JSViewAbstract::ParseJsString(args[0], data); + spanString = AceType::MakeRefPtr(data); + } else { + JSViewAbstract::ParseJsString(args[0], data); + auto spanBases = JSSpanString::ParseJsSpanBaseVector(args[1], StringUtils::ToWstring(data).length()); + spanString = AceType::MakeRefPtr(data, spanBases); + } + jsSpanString->SetController(spanString); + jsSpanString->SetMutableController(spanString); + args.SetReturnValue(Referenced::RawPtr(jsSpanString)); +} + +void JSMutableSpanString::Destructor(JSMutableSpanString* spanString) +{ + if (spanString != nullptr) { + spanString->DecRefCount(); + } +} + +void JSMutableSpanString::JSBind(BindingTarget globalObj) +{ + JSClass::Declare("MutableStyledString"); + JSClass::CustomMethod("getString", &JSSpanString::GetString); + JSClass::CustomProperty("length", &JSSpanString::GetLength, &JSSpanString::SetLength); + JSClass::CustomMethod("equals", &JSSpanString::IsEqualToSpanString); + JSClass::CustomMethod("subStyledString", &JSSpanString::GetSubSpanString); + JSClass::CustomMethod("getStyles", &JSSpanString::GetSpans); + + JSClass::CustomMethod("replaceString", &JSMutableSpanString::ReplaceString); + JSClass::CustomMethod("insertString", &JSMutableSpanString::InsertString); + JSClass::CustomMethod("removeString", &JSMutableSpanString::RemoveString); + JSClass::CustomMethod("replaceStyle", &JSMutableSpanString::ReplaceSpan); + JSClass::CustomMethod("setStyle", &JSMutableSpanString::AddSpan); + JSClass::CustomMethod("removeStyle", &JSMutableSpanString::RemoveSpan); + JSClass::CustomMethod("removeStyles", &JSMutableSpanString::RemoveSpans); + JSClass::Method("clearStyles", &JSMutableSpanString::ClearAllSpans); + JSClass::CustomMethod("replaceStyledString", &JSMutableSpanString::ReplaceSpanString); + JSClass::CustomMethod("insertStyledString", &JSMutableSpanString::InsertSpanString); + JSClass::CustomMethod("appendStyledString", &JSMutableSpanString::AppendSpanString); + + JSClass::Bind(globalObj, JSMutableSpanString::Constructor, JSMutableSpanString::Destructor); +} + +void JSMutableSpanString::ReplaceString(const JSCallbackInfo& info) +{ + if (info.Length() != 3 || !info[0]->IsNumber() || !info[1]->IsNumber() || !info[2]->IsString()) { + return; + } + int32_t start = info[0]->ToNumber(); + int32_t length = info[1]->ToNumber(); + auto controller = GetMutableController().Upgrade(); + CHECK_NULL_VOID(controller); + CheckParameters(start, length); + std::string data = info[2]->ToString(); + controller->ReplaceString(start, length, data); +} + +void JSMutableSpanString::InsertString(const JSCallbackInfo& info) +{ + if (info.Length() != 2 || !info[0]->IsNumber() || !info[1]->IsString()) { + return; + } + auto start = info[0]->ToNumber(); + std::string data = info[1]->ToString(); + auto controller = GetMutableController().Upgrade(); + CHECK_NULL_VOID(controller); + // The input parameter must not cross the boundary. + auto characterLength = controller->GetLength(); + if (start < 0 || start > characterLength) { + JSException::Throw(ERROR_CODE_PARAM_INVALID, "%s", "Input parameter check failed."); + return; + } + controller->InsertString(start, data); +} + +void JSMutableSpanString::RemoveString(const JSCallbackInfo& info) +{ + if (info.Length() != 2 || !info[0]->IsNumber() || !info[1]->IsNumber()) { + return; + } + auto start = info[0]->ToNumber(); + auto length = info[1]->ToNumber(); + auto controller = GetMutableController().Upgrade(); + CHECK_NULL_VOID(controller); + CheckParameters(start, length); + controller->RemoveString(start, length); +} + +void JSMutableSpanString::ReplaceSpan(const JSCallbackInfo& info) +{ + if (info.Length() != 1 || !info[0]->IsObject()) { + return; + } + auto paramObject = JSRef::Cast(info[0]); + auto startObj = paramObject->GetProperty("start"); + auto lengthObj = paramObject->GetProperty("length"); + auto styleKeyObj = paramObject->GetProperty("styleKey"); + auto styleValueObj = paramObject->GetProperty("styleValue"); + if (!startObj->IsNumber() || !lengthObj->IsNumber() || !styleKeyObj->IsNumber() || !styleValueObj->IsObject()) { + return; + } + CheckSpanType(styleKeyObj->ToNumber()); + auto start = startObj->ToNumber(); + auto length = lengthObj->ToNumber(); + SpanType type = static_cast(styleKeyObj->ToNumber()); + auto spanBase = ParseJsSpanBase(start, length, type, JSRef::Cast(styleValueObj)); + CHECK_NULL_VOID(spanBase); + auto controller = GetMutableController().Upgrade(); + CHECK_NULL_VOID(controller); + CheckParameters(start, length); + controller->ReplaceSpan(start, length, spanBase); +} + +void JSMutableSpanString::AddSpan(const JSCallbackInfo& info) +{ + if (info.Length() != 1 || !info[0]->IsObject()) { + return; + } + auto paramObject = JSRef::Cast(info[0]); + auto startObj = paramObject->GetProperty("start"); + auto lengthObj = paramObject->GetProperty("length"); + auto styleKeyObj = paramObject->GetProperty("styleKey"); + auto styleValueObj = paramObject->GetProperty("styleValue"); + if (!startObj->IsNumber() || !lengthObj->IsNumber() || !styleKeyObj->IsNumber() || !styleValueObj->IsObject()) { + return; + } + CheckSpanType(styleKeyObj->ToNumber()); + auto start = startObj->ToNumber(); + auto length = lengthObj->ToNumber(); + SpanType type = static_cast(styleKeyObj->ToNumber()); + auto spanBase = ParseJsSpanBase(start, length, type, JSRef::Cast(styleValueObj)); + CHECK_NULL_VOID(spanBase); + auto controller = GetMutableController().Upgrade(); + CHECK_NULL_VOID(controller); + CheckParameters(start, length); + controller->AddSpan(spanBase); +} + +void JSMutableSpanString::RemoveSpan(const JSCallbackInfo& info) +{ + if (info.Length() != 3 || !info[0]->IsNumber() || !info[1]->IsNumber() || !info[2]->IsNumber()) { + return; + } + auto start = info[0]->ToNumber(); + auto length = info[1]->ToNumber(); + CheckSpanType(info[2]->ToNumber()); + SpanType type = static_cast(info[2]->ToNumber()); + auto controller = GetMutableController().Upgrade(); + CHECK_NULL_VOID(controller); + CheckParameters(start, length); + controller->RemoveSpan(start, length, type); +} + +void JSMutableSpanString::RemoveSpans(const JSCallbackInfo& info) +{ + if (info.Length() != 2 || !info[0]->IsNumber() || !info[1]->IsNumber()) { + return; + } + auto controller = GetMutableController().Upgrade(); + CHECK_NULL_VOID(controller); + auto start = info[0]->ToNumber(); + auto length = info[1]->ToNumber(); + CheckParameters(start, length); + controller->RemoveSpans(start, length); +} + +void JSMutableSpanString::ClearAllSpans() +{ + auto controller = GetMutableController().Upgrade(); + CHECK_NULL_VOID(controller); + controller->ClearAllSpans(); +} + +void JSMutableSpanString::ReplaceSpanString(const JSCallbackInfo& info) +{ + if (info.Length() != 3 || !info[0]->IsNumber() || !info[1]->IsNumber() || !info[2]->IsObject()) { + return; + } + auto start = info[0]->ToNumber(); + auto length = info[1]->ToNumber(); + auto* spanString = JSRef::Cast(info[2])->Unwrap(); + CHECK_NULL_VOID(spanString); + auto spanStringController = spanString->GetController(); + CHECK_NULL_VOID(spanStringController); + auto controller = GetMutableController().Upgrade(); + CHECK_NULL_VOID(controller); + CheckParameters(start, length); + controller->ReplaceSpanString(start, length, spanStringController); +} + +void JSMutableSpanString::InsertSpanString(const JSCallbackInfo& info) +{ + if (info.Length() != 2 || !info[0]->IsNumber() || !info[1]->IsObject()) { + return; + } + auto start = info[0]->ToNumber(); + auto* spanString = JSRef::Cast(info[1])->Unwrap(); + CHECK_NULL_VOID(spanString); + auto spanStringController = spanString->GetController(); + CHECK_NULL_VOID(spanStringController); + auto controller = GetMutableController().Upgrade(); + CHECK_NULL_VOID(controller); + // The input parameter must not cross the boundary. + auto characterLength = controller->GetLength(); + if (start < 0 || start >= characterLength) { + JSException::Throw(ERROR_CODE_PARAM_INVALID, "%s", "Input parameter check failed."); + return; + } + controller->InsertSpanString(start, spanStringController); +} + +void JSMutableSpanString::AppendSpanString(const JSCallbackInfo& info) +{ + if (info.Length() != 1 || !info[0]->IsObject()) { + return; + } + auto* spanString = JSRef::Cast(info[0])->Unwrap(); + CHECK_NULL_VOID(spanString); + auto spanStringController = spanString->GetController(); + CHECK_NULL_VOID(spanStringController); + auto controller = GetMutableController().Upgrade(); + CHECK_NULL_VOID(controller); + controller->AppendSpanString(spanStringController); +} + +WeakPtr& JSMutableSpanString::GetMutableController() +{ + return mutableSpanString_; +} + +void JSMutableSpanString::SetMutableController(const RefPtr& mutableSpanString) +{ + mutableSpanString_ = mutableSpanString; +} + +} // namespace OHOS::Ace::Framework \ No newline at end of file diff --git a/frameworks/bridge/declarative_frontend/style_string/js_span_string.h b/frameworks/bridge/declarative_frontend/style_string/js_span_string.h index fd92a13ee21..ad2eb8bbde1 100644 --- a/frameworks/bridge/declarative_frontend/style_string/js_span_string.h +++ b/frameworks/bridge/declarative_frontend/style_string/js_span_string.h @@ -39,15 +39,17 @@ public: static void JSBind(BindingTarget globalObj); void GetString(const JSCallbackInfo& info); void GetLength(const JSCallbackInfo& info); + void SetLength(const JSCallbackInfo& info); void IsEqualToSpanString(const JSCallbackInfo& info); void GetSubSpanString(const JSCallbackInfo& info); - static std::vector> ParseJsSpanBaseVector(JSRef obj); + static std::vector> ParseJsSpanBaseVector(JSRef obj, int32_t maxLength); static JSRef CreateJSSpanBaseObject(const RefPtr& spanObject); static JSRef CreateJsFontSpan(const RefPtr& spanObject); static RefPtr ParseJsSpanBase(int32_t start, int32_t length, SpanType type, JSRef obj); static RefPtr ParseJsFontSpan(int32_t start, int32_t length, JSRef obj); + static void CheckSpanType(const int32_t& type); + void CheckParameters(const int32_t& start, const int32_t& length); void GetSpans(const JSCallbackInfo& info); - void GetIndex(const JSCallbackInfo& info); RefPtr& GetController(); void SetController(const RefPtr& spanString); diff --git a/frameworks/core/components_ng/pattern/text/span/span_string.h b/frameworks/core/components_ng/pattern/text/span/span_string.h index 66ff63787e6..de3010ced5d 100644 --- a/frameworks/core/components_ng/pattern/text/span/span_string.h +++ b/frameworks/core/components_ng/pattern/text/span/span_string.h @@ -51,11 +51,11 @@ public: const std::list>& GetSpanItems() const; static RefPtr GetDefaultSpanItem(const std::string& text); void AddSpan(const RefPtr& span); + bool CheckRange(int32_t start, int32_t length, bool allowLengthZero = false) const; protected: RefPtr GetSpan(int32_t start, int32_t length, SpanType spanType) const; void BindWithSpans(std::vector> spans); - bool CheckRange(int32_t start, int32_t length, bool allowLengthZero = false) const; void MergeIntervals(std::list>& spans); void SplitInterval(std::list>& spans, std::pair interval); void ApplyToSpans(const RefPtr& spans, std::pair interval); -- Gitee