From 934692615d81248c0ab54e992050fa9bea7f1306 Mon Sep 17 00:00:00 2001 From: Carnivore233 <337006676@qq.com> Date: Sun, 1 Sep 2024 17:14:56 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90RichEditor=E3=80=91=E4=BF=AE=E6=94=B9s?= =?UTF-8?q?ymbol=E3=80=81shadow=E6=97=A0=E6=B3=95=E8=B7=9F=E9=9A=8F?= =?UTF-8?q?=E6=B7=B1=E6=B5=85=E8=89=B2=E5=88=87=E6=8D=A2=E9=A2=9C=E8=89=B2?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Carnivore233 <337006676@qq.com> --- adapter/ohos/capability/html/span_to_html.cpp | 7 --- adapter/ohos/capability/html/span_to_html.h | 1 - build/libace.map | 1 - .../jsview/js_richeditor.cpp | 42 ++++---------- .../jsview/js_richeditor.h | 1 - .../jsview/js_view_abstract.cpp | 1 + .../jsview/models/richeditor_model_impl.h | 4 +- .../components/common/properties/color.cpp | 57 +------------------ .../core/components/common/properties/color.h | 35 ++++++------ .../components/common/properties/shadow.h | 5 ++ .../common/properties/text_style.cpp | 2 + .../components/common/properties/text_style.h | 21 +------ .../pattern/rich_editor/rich_editor_model.h | 18 ++++-- .../rich_editor/rich_editor_model_ng.cpp | 8 +-- .../rich_editor/rich_editor_model_ng.h | 8 +-- .../rich_editor/rich_editor_pattern.cpp | 16 +++--- .../pattern/rich_editor/rich_editor_pattern.h | 12 ++-- .../components_ng/pattern/text/span_node.h | 4 +- .../pattern/text/text_layout_property.h | 4 +- .../pattern/text/text_styles.cpp | 18 ++++++ .../components_ng/pattern/text/text_styles.h | 16 ++---- .../native/node/rich_editor_modifier.cpp | 2 +- 22 files changed, 105 insertions(+), 178 deletions(-) diff --git a/adapter/ohos/capability/html/span_to_html.cpp b/adapter/ohos/capability/html/span_to_html.cpp index 93cc2bc319f..b487eff4f3e 100644 --- a/adapter/ohos/capability/html/span_to_html.cpp +++ b/adapter/ohos/capability/html/span_to_html.cpp @@ -90,13 +90,6 @@ std::string SpanToHtml::ColorToHtml(const std::optional& value) return ToHtmlStyleFormat("color", color); } -std::string SpanToHtml::ColorToHtml(const std::optional& value) -{ - auto color = value.value_or(DynamicColor(Color::BLACK)).ToColor().ColorToString(); - ToHtmlColor(color); - return ToHtmlStyleFormat("color", color); -} - std::string SpanToHtml::FontFamilyToHtml(const std::optional>& value) { return ToHtmlStyleFormat("font-family", GetFontFamilyInJson(value)); diff --git a/adapter/ohos/capability/html/span_to_html.h b/adapter/ohos/capability/html/span_to_html.h index 68373d491cb..1b9945df1ce 100644 --- a/adapter/ohos/capability/html/span_to_html.h +++ b/adapter/ohos/capability/html/span_to_html.h @@ -31,7 +31,6 @@ private: static std::string FontSizeToHtml(const std::optional& value); static std::string FontWeightToHtml(const std::optional& value); static std::string ColorToHtml(const std::optional& value); - static std::string ColorToHtml(const std::optional& value); static std::string FontFamilyToHtml(const std::optional>& value); static std::string TextDecorationToHtml(TextDecoration decoration); static std::string TextDecorationStyleToHtml(TextDecorationStyle decorationStyle); diff --git a/build/libace.map b/build/libace.map index 8a1c2b16858..906e3116f82 100644 --- a/build/libace.map +++ b/build/libace.map @@ -80,7 +80,6 @@ OHOS::Ace::ResourceWrapper::*; OHOS::Ace::NG::AppBarView::*; OHOS::Ace::Color::*; - OHOS::Ace::DynamicColor::*; OHOS::Ace::NG::UIObserverHandler::*; OHOS::Ace::UIDisplaySync::*; OHOS::Ace::Dimension::*; diff --git a/frameworks/bridge/declarative_frontend/jsview/js_richeditor.cpp b/frameworks/bridge/declarative_frontend/jsview/js_richeditor.cpp index 267dd6a745c..123ddfd65e3 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_richeditor.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_richeditor.cpp @@ -1084,7 +1084,7 @@ void JSRichEditor::SetPlaceholder(const JSCallbackInfo& info) JSRef colorVal = object->GetProperty("fontColor"); Color fontColor; if (!colorVal->IsNull() && JSContainerBase::ParseJsColor(colorVal, fontColor)) { - options.fontColor = DynamicColor(fontColor, ParseColorResourceId(colorVal)); + options.fontColor = fontColor; } } auto textTheme = pipelineContext->GetTheme(); @@ -1166,18 +1166,15 @@ void JSRichEditor::SetCaretColor(const JSCallbackInfo& info) return; } Color color; - DynamicColor dynamicColor; JSRef colorVal = info[0]; if (!ParseJsColor(colorVal, color)) { auto pipeline = PipelineBase::GetCurrentContext(); CHECK_NULL_VOID(pipeline); auto theme = pipeline->GetThemeManager()->GetTheme(); CHECK_NULL_VOID(theme); - dynamicColor = theme->GetCaretColor(); - } else { - dynamicColor = DynamicColor(color, ParseColorResourceId(colorVal)); + color = theme->GetCaretColor(); } - RichEditorModel::GetInstance()->SetCaretColor(dynamicColor); + RichEditorModel::GetInstance()->SetCaretColor(color); } void JSRichEditor::SetSelectedBackgroundColor(const JSCallbackInfo& info) @@ -1187,18 +1184,15 @@ void JSRichEditor::SetSelectedBackgroundColor(const JSCallbackInfo& info) return; } Color selectedColor; - DynamicColor dynamicSelectedColor; JSRef colorVal = info[0]; if (!ParseJsColor(colorVal, selectedColor)) { auto pipeline = PipelineBase::GetCurrentContext(); CHECK_NULL_VOID(pipeline); auto theme = pipeline->GetThemeManager()->GetTheme(); CHECK_NULL_VOID(theme); - dynamicSelectedColor = theme->GetSelectedBackgroundColor(); - } else { - dynamicSelectedColor = DynamicColor(selectedColor, ParseColorResourceId(colorVal)); + selectedColor = theme->GetSelectedBackgroundColor(); } - RichEditorModel::GetInstance()->SetSelectedBackgroundColor(dynamicSelectedColor); + RichEditorModel::GetInstance()->SetSelectedBackgroundColor(selectedColor); } void JSRichEditor::SetEnterKeyType(const JSCallbackInfo& info) @@ -1263,18 +1257,6 @@ void JSRichEditor::SetOnSubmit(const JSCallbackInfo& info) CreateJsRichEditorCommonEvent(info); } -std::optional JSRichEditor::ParseColorResourceId(JSRef colorVal) -{ - CHECK_NULL_RETURN(colorVal->IsObject(), std::nullopt); - JSRef jsObj = JSRef::Cast(colorVal); - JSViewAbstract::CompleteResourceObject(jsObj); - JSRef resId = jsObj->GetProperty("id"); - CHECK_NULL_RETURN(resId->IsNumber(), std::nullopt); - auto type = jsObj->GetPropertyValue("type", -1); - CHECK_NULL_RETURN(type == static_cast(ResourceType::COLOR), std::nullopt); - return resId->ToNumber(); -} - void JSRichEditor::SetEnableKeyboardOnFocus(const JSCallbackInfo& info) { CHECK_NULL_VOID(info.Length() > 0); @@ -2236,9 +2218,8 @@ void JSRichEditorBaseController::ParseJsTextStyle( JSRef fontColor = styleObject->GetProperty("fontColor"); Color textColor; if (!fontColor->IsNull() && JSContainerBase::ParseJsColor(fontColor, textColor)) { - DynamicColor dynamicColor = DynamicColor(textColor, JSRichEditor::ParseColorResourceId(fontColor)); - style.SetTextColor(dynamicColor); - updateSpanStyle.updateTextColor = dynamicColor; + style.SetTextColor(textColor); + updateSpanStyle.updateTextColor = textColor; updateSpanStyle.useThemeFontColor = false; } JSRef fontSize = styleObject->GetProperty("fontSize"); @@ -2356,9 +2337,8 @@ void JSRichEditorBaseController::ParseTextDecoration( JSRef color = decorationObject->GetProperty("color"); Color decorationColor; if (!color->IsNull() && JSContainerBase::ParseJsColor(color, decorationColor)) { - DynamicColor dynamicColor = DynamicColor(decorationColor, JSRichEditor::ParseColorResourceId(color)); - updateSpanStyle.updateTextDecorationColor = dynamicColor; - style.SetTextDecorationColor(dynamicColor); + updateSpanStyle.updateTextDecorationColor = decorationColor; + style.SetTextDecorationColor(decorationColor); updateSpanStyle.useThemeDecorationColor = false; } JSRef textDecorationStyle = decorationObject->GetProperty("style"); @@ -2368,8 +2348,8 @@ void JSRichEditorBaseController::ParseTextDecoration( style.SetTextDecorationStyle(static_cast(textDecorationStyle->ToNumber())); } if (!updateSpanStyle.updateTextDecorationColor.has_value() && updateSpanStyle.updateTextColor.has_value()) { - updateSpanStyle.updateTextDecorationColor = style.GetDynamicTextColor(); - style.SetTextDecorationColor(style.GetDynamicTextColor()); + updateSpanStyle.updateTextDecorationColor = style.GetTextColor(); + style.SetTextDecorationColor(style.GetTextColor()); } } } diff --git a/frameworks/bridge/declarative_frontend/jsview/js_richeditor.h b/frameworks/bridge/declarative_frontend/jsview/js_richeditor.h index 02208c15c56..3dee4aadfc7 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_richeditor.h +++ b/frameworks/bridge/declarative_frontend/jsview/js_richeditor.h @@ -78,7 +78,6 @@ public: static std::optional ParseMarginAttr(JsiRef marginAttr); static CalcDimension ParseLengthMetrics(const JSRef& obj); static void EditMenuOptions(const JSCallbackInfo& info); - static std::optional ParseColorResourceId(JSRef colorVal); static void SetEnableKeyboardOnFocus(const JSCallbackInfo& info); static void SetEnableHapticFeedback(const JSCallbackInfo& info); static JSRef CreateJsTextShadowObjectArray(const TextStyleResult& textStyleResult); diff --git a/frameworks/bridge/declarative_frontend/jsview/js_view_abstract.cpp b/frameworks/bridge/declarative_frontend/jsview/js_view_abstract.cpp index 67c27bff177..f166145b5c4 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_view_abstract.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_view_abstract.cpp @@ -5463,6 +5463,7 @@ bool JSViewAbstract::ParseJsObjColorFromResource(const JSRef &jsObj, C } if (type == static_cast(ResourceType::COLOR)) { result = resourceWrapper->GetColor(resId->ToNumber()); + result.SetResourceId(resId->ToNumber()); return true; } return false; diff --git a/frameworks/bridge/declarative_frontend/jsview/models/richeditor_model_impl.h b/frameworks/bridge/declarative_frontend/jsview/models/richeditor_model_impl.h index da3e63049f3..6122bbb8b5d 100644 --- a/frameworks/bridge/declarative_frontend/jsview/models/richeditor_model_impl.h +++ b/frameworks/bridge/declarative_frontend/jsview/models/richeditor_model_impl.h @@ -38,8 +38,8 @@ class ACE_EXPORT RichEditorModelImpl : public RichEditorModel { void SetTextDetectEnable(bool value) override {} void SetSupportPreviewText(bool value) override {} void SetTextDetectConfig(const TextDetectConfig& textDetectConfig) override {} - void SetSelectedBackgroundColor(const DynamicColor& selectedColor) override {} - void SetCaretColor(const DynamicColor& color) override {} + void SetSelectedBackgroundColor(const Color& selectedColor) override {} + void SetCaretColor(const Color& color) override {} void SetOnEditingChange(std::function&& func) override {} void SetOnSubmit(std::function&& func) override {} void SetEnterKeyType(TextInputAction value) override {} diff --git a/frameworks/core/components/common/properties/color.cpp b/frameworks/core/components/common/properties/color.cpp index d158112b611..3098e9d2580 100644 --- a/frameworks/core/components/common/properties/color.cpp +++ b/frameworks/core/components/common/properties/color.cpp @@ -590,66 +590,15 @@ bool Color::IsOpacityValid(double value) return value >= MIN_RGBA_OPACITY && value <= MAX_RGBA_OPACITY; } -DynamicColor::DynamicColor(const Color& color) -{ - SetValue(color.GetValue()); -} - -DynamicColor::DynamicColor(const Color& color, std::optional resId) : resourceId(resId) -{ - SetValue(color.GetValue()); -} - -DynamicColor::DynamicColor(const Color& color, uint32_t resId) : resourceId(resId) -{ - SetValue(color.GetValue()); -} - -void DynamicColor::UpdateColorByResourceId() +void Color::UpdateColorByResourceId() { #ifndef ACE_UNITTEST - CHECK_NULL_VOID(resourceId); + CHECK_NULL_VOID(resourceId_ != 0); auto resourceAdapter = ResourceManager::GetInstance().GetResourceAdapter(); CHECK_NULL_VOID(resourceAdapter); - auto newColor = resourceAdapter->GetColor(resourceId.value()); + auto newColor = resourceAdapter->GetColor(resourceId_); SetValue(newColor.GetValue()); #endif } -Color DynamicColor::ToColor() const -{ - return Color(GetValue()); -} - -std::string DynamicColor::ToString() const -{ - std::string ret = "color="; - ret += Color::ToString(); - ret += ", resourceId="; - ret += resourceId ? std::to_string(resourceId.value()) : "nullopt"; - return ret; -} - -DynamicColor& DynamicColor::operator=(const Color& rhs) -{ - SetValue(rhs.GetValue()); - return *this; -} - -bool DynamicColor::operator==(const DynamicColor& rhs) const -{ - if (this->GetValue() != rhs.GetValue()) { - return false; - } - if (!this->resourceId && !rhs.resourceId) { - return true; - } - return this->resourceId && rhs.resourceId && *(this->resourceId) == *(rhs.resourceId); -} - -bool DynamicColor::operator!=(const DynamicColor& rhs) const -{ - return !operator==(rhs); -} - } // namespace OHOS::Ace diff --git a/frameworks/core/components/common/properties/color.h b/frameworks/core/components/common/properties/color.h index 031972b3b5b..0f40f5dc867 100644 --- a/frameworks/core/components/common/properties/color.h +++ b/frameworks/core/components/common/properties/color.h @@ -55,6 +55,8 @@ class ACE_FORCE_EXPORT Color { public: Color() = default; constexpr explicit Color(uint32_t value) : colorValue_(ColorParam { .value = value }) {} + constexpr explicit Color(uint32_t value, uint32_t resId) + : colorValue_(ColorParam { .value = value }), resourceId_(resId) {} ~Color() = default; static Color FromARGB(uint8_t alpha, uint8_t red, uint8_t green, uint8_t blue); @@ -95,6 +97,16 @@ public: return colorValue_.value; } + void SetResourceId(uint32_t id) + { + resourceId_ = id; + } + + uint32_t GetResourceId() const + { + return resourceId_; + } + uint8_t GetAlpha() const { return colorValue_.argb.alpha; @@ -115,6 +127,8 @@ public: return colorValue_.argb.blue; } + void UpdateColorByResourceId(); + bool operator==(const Color& color) const { return colorValue_.value == color.GetValue(); @@ -139,7 +153,7 @@ public: std::string ToString() const; -protected: +private: constexpr explicit Color(ColorParam colorValue) : colorValue_(colorValue) {} static double ConvertGammaToLinear(uint8_t value); @@ -162,24 +176,7 @@ protected: float CalculateBlend(float alphaLeft, float alphaRight, float valueLeft, float valueRight) const; ColorParam colorValue_ { .value = 0xff000000 }; -}; - -class ACE_FORCE_EXPORT DynamicColor : public Color { -public: - DynamicColor() {} - DynamicColor(const Color& color); - DynamicColor(const Color& color, std::optional resId); - DynamicColor(const Color& color, uint32_t resId); - - void UpdateColorByResourceId(); - std::string ToString() const; - Color ToColor() const; - - DynamicColor& operator=(const Color& rhs); - bool operator==(const DynamicColor& rhs) const; - bool operator!=(const DynamicColor& rhs) const; - - std::optional resourceId = std::nullopt; + uint32_t resourceId_ = 0; }; namespace StringUtils { diff --git a/frameworks/core/components/common/properties/shadow.h b/frameworks/core/components/common/properties/shadow.h index 0bd1d6ff170..01b6d94474e 100644 --- a/frameworks/core/components/common/properties/shadow.h +++ b/frameworks/core/components/common/properties/shadow.h @@ -237,6 +237,11 @@ public: return blurRadius_ > 0.0 || spreadRadius_ > 0.0 || offset_ != Offset::Zero(); } + void UpdateColorByResourceId() + { + color_.UpdateColorByResourceId(); + } + private: float lightHeight_ = LIGHT_HEIGHT; float lightRadius_ = LIGHT_RADIUS; diff --git a/frameworks/core/components/common/properties/text_style.cpp b/frameworks/core/components/common/properties/text_style.cpp index 2e0a27f04a9..e65b3ca0907 100644 --- a/frameworks/core/components/common/properties/text_style.cpp +++ b/frameworks/core/components/common/properties/text_style.cpp @@ -80,6 +80,8 @@ void TextStyle::UpdateColorByResourceId() { textColor_.UpdateColorByResourceId(); textDecorationColor_.UpdateColorByResourceId(); + std::for_each(renderColors_.begin(), renderColors_.end(), [](Color& cl) { cl.UpdateColorByResourceId(); }); + std::for_each(textShadows_.begin(), textShadows_.end(), [](Shadow& sd) { sd.UpdateColorByResourceId(); }); } std::string TextStyle::ToString() const diff --git a/frameworks/core/components/common/properties/text_style.h b/frameworks/core/components/common/properties/text_style.h index e651fe6e3f7..4bc74fc9ab9 100644 --- a/frameworks/core/components/common/properties/text_style.h +++ b/frameworks/core/components/common/properties/text_style.h @@ -368,11 +368,6 @@ public: enableVariableFontWeight_ = enableVariableFontWeight; } const Color GetTextColor() const - { - return textColor_.ToColor(); - } - - const DynamicColor GetDynamicTextColor() const { return textColor_; } @@ -382,11 +377,6 @@ public: textColor_ = textColor; } - void SetTextColor(const DynamicColor& textColor) - { - textColor_ = textColor; - } - TextDecoration GetTextDecoration() const { return textDecoration_; @@ -408,16 +398,11 @@ public: } const Color GetTextDecorationColor() const - { - return textDecorationColor_.ToColor(); - } - - const DynamicColor GetDynamicTextDecorationColor() const { return textDecorationColor_; } - void SetTextDecorationColor(const DynamicColor& textDecorationColor) + void SetTextDecorationColor(const Color& textDecorationColor) { textDecorationColor_ = textDecorationColor; } @@ -811,8 +796,8 @@ private: TextCase textCase_ { TextCase::NORMAL }; EllipsisMode ellipsisMode_ = EllipsisMode::TAIL; LineBreakStrategy lineBreakStrategy_ { LineBreakStrategy::GREEDY }; - DynamicColor textColor_ { Color::BLACK }; - DynamicColor textDecorationColor_ { Color::BLACK }; + Color textColor_ { Color::BLACK }; + Color textDecorationColor_ { Color::BLACK }; uint32_t maxLines_ = UINT32_MAX; int32_t variableFontWeight_ = 0; bool hasHeightOverride_ = false; diff --git a/frameworks/core/components_ng/pattern/rich_editor/rich_editor_model.h b/frameworks/core/components_ng/pattern/rich_editor/rich_editor_model.h index c816a2e56c9..ef90bb91200 100644 --- a/frameworks/core/components_ng/pattern/rich_editor/rich_editor_model.h +++ b/frameworks/core/components_ng/pattern/rich_editor/rich_editor_model.h @@ -97,13 +97,13 @@ struct UpdateSpanStyle { updateSymbolEffectStrategy.reset(); } - std::optional updateTextColor = std::nullopt; + std::optional updateTextColor = std::nullopt; std::optional updateFontSize = std::nullopt; std::optional updateItalicFontStyle = std::nullopt; std::optional updateFontWeight = std::nullopt; std::optional> updateFontFamily = std::nullopt; std::optional updateTextDecoration = std::nullopt; - std::optional updateTextDecorationColor = std::nullopt; + std::optional updateTextDecorationColor = std::nullopt; std::optional updateTextDecorationStyle = std::nullopt; std::optional> updateTextShadows = std::nullopt; std::optional updateFontFeature = std::nullopt; @@ -134,6 +134,14 @@ struct UpdateSpanStyle { if (updateTextDecorationColor) { updateTextDecorationColor->UpdateColorByResourceId(); } + if (updateTextShadows) { + auto& shadows = updateTextShadows.value(); + std::for_each(shadows.begin(), shadows.end(), [](Shadow& sd) { sd.UpdateColorByResourceId(); }); + } + if (updateSymbolColor) { + auto& colors = updateSymbolColor.value(); + std::for_each(colors.begin(), colors.end(), [](Color& cl) { cl.UpdateColorByResourceId(); }); + } } std::string ToString() const @@ -240,7 +248,7 @@ struct PlaceholderOptions { std::optional value; std::optional fontWeight; std::optional fontSize; - std::optional fontColor; + std::optional fontColor; std::optional fontStyle; std::vector fontFamilies; @@ -341,8 +349,8 @@ public: virtual void SetTextDetectEnable(bool value) = 0; virtual void SetSupportPreviewText(bool value) = 0; virtual void SetTextDetectConfig(const TextDetectConfig& textDetectConfig) = 0; - virtual void SetSelectedBackgroundColor(const DynamicColor& selectedColor) = 0; - virtual void SetCaretColor(const DynamicColor& color) = 0; + virtual void SetSelectedBackgroundColor(const Color& selectedColor) = 0; + virtual void SetCaretColor(const Color& color) = 0; virtual void SetOnEditingChange(std::function&& func) = 0; virtual void SetEnterKeyType(TextInputAction value) = 0; virtual void SetOnSubmit(std::function&& func) = 0; diff --git a/frameworks/core/components_ng/pattern/rich_editor/rich_editor_model_ng.cpp b/frameworks/core/components_ng/pattern/rich_editor/rich_editor_model_ng.cpp index 3f750ceecab..0d76a9623f1 100644 --- a/frameworks/core/components_ng/pattern/rich_editor/rich_editor_model_ng.cpp +++ b/frameworks/core/components_ng/pattern/rich_editor/rich_editor_model_ng.cpp @@ -337,7 +337,7 @@ void RichEditorModelNG::SetTextDetectEnable(FrameNode* frameNode, bool value) richEditorPattern->SetTextDetectEnable(value); } -void RichEditorModelNG::SetSelectedBackgroundColor(const DynamicColor& selectedColor) +void RichEditorModelNG::SetSelectedBackgroundColor(const Color& selectedColor) { auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); CHECK_NULL_VOID(frameNode); @@ -346,14 +346,14 @@ void RichEditorModelNG::SetSelectedBackgroundColor(const DynamicColor& selectedC pattern->SetSelectedBackgroundColor(selectedColor); } -void RichEditorModelNG::SetSelectedBackgroundColor(FrameNode* frameNode, const DynamicColor& selectedColor) +void RichEditorModelNG::SetSelectedBackgroundColor(FrameNode* frameNode, const Color& selectedColor) { auto pattern = frameNode->GetPattern(); CHECK_NULL_VOID(pattern); pattern->SetSelectedBackgroundColor(selectedColor); } -void RichEditorModelNG::SetCaretColor(const DynamicColor& color) +void RichEditorModelNG::SetCaretColor(const Color& color) { auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); CHECK_NULL_VOID(frameNode); @@ -362,7 +362,7 @@ void RichEditorModelNG::SetCaretColor(const DynamicColor& color) pattern->SetCaretColor(color); } -void RichEditorModelNG::SetCaretColor(FrameNode* frameNode, const DynamicColor& color) +void RichEditorModelNG::SetCaretColor(FrameNode* frameNode, const Color& color) { auto pattern = frameNode->GetPattern(); CHECK_NULL_VOID(pattern); diff --git a/frameworks/core/components_ng/pattern/rich_editor/rich_editor_model_ng.h b/frameworks/core/components_ng/pattern/rich_editor/rich_editor_model_ng.h index 56255b91c3d..17cda0c7c36 100644 --- a/frameworks/core/components_ng/pattern/rich_editor/rich_editor_model_ng.h +++ b/frameworks/core/components_ng/pattern/rich_editor/rich_editor_model_ng.h @@ -41,8 +41,8 @@ public: void SetTextDetectEnable(bool value) override; void SetSupportPreviewText(bool value) override; void SetTextDetectConfig(const TextDetectConfig& textDetectConfig) override; - void SetSelectedBackgroundColor(const DynamicColor& selectedColor) override; - void SetCaretColor(const DynamicColor& color) override; + void SetSelectedBackgroundColor(const Color& selectedColor) override; + void SetCaretColor(const Color& color) override; void SetOnEditingChange(std::function&& func) override; void SetOnWillChange(std::function&& func) override; void SetOnDidChange(std::function&& func) override; @@ -64,12 +64,12 @@ public: static void SetOnDidIMEInput(FrameNode* frameNode, std::function&& callback); static void SetCopyOption(FrameNode* frameNode, CopyOptions& copyOptions); static void SetOnSelectionChange(FrameNode* frameNode, std::function&& callback); - static void SetCaretColor(FrameNode* frameNode, const DynamicColor& color); + static void SetCaretColor(FrameNode* frameNode, const Color& color); static void SetOnSelect(FrameNode* frameNode, std::function&& callback); static void SetOnReady(FrameNode* frameNode, std::function&& callback); static void SetOnDeleteComplete(FrameNode* frameNode, std::function&& callback); static void SetOnEditingChange(FrameNode* frameNode, std::function&& callback); - static void SetSelectedBackgroundColor(FrameNode* frameNode, const DynamicColor& selectedColor); + static void SetSelectedBackgroundColor(FrameNode* frameNode, const Color& selectedColor); static void SetOnPaste(FrameNode* frameNode, std::function&& func); static void SetOnCut(FrameNode* frameNode, std::function&& func); static void SetOnCopy(FrameNode* frameNode, std::function&& func); diff --git a/frameworks/core/components_ng/pattern/rich_editor/rich_editor_pattern.cpp b/frameworks/core/components_ng/pattern/rich_editor/rich_editor_pattern.cpp index 62ca7fd45d0..ce8e46a723a 100644 --- a/frameworks/core/components_ng/pattern/rich_editor/rich_editor_pattern.cpp +++ b/frameworks/core/components_ng/pattern/rich_editor/rich_editor_pattern.cpp @@ -910,7 +910,7 @@ int32_t RichEditorPattern::AddTextSpanOperation( spanNode->UpdateContent(options.value); spanNode->AddPropertyInfo(PropertyInfo::NONE); if (options.style.has_value()) { - spanNode->UpdateTextColor(options.style.value().GetDynamicTextColor()); + spanNode->UpdateTextColor(options.style.value().GetTextColor()); spanNode->AddPropertyInfo(PropertyInfo::FONTCOLOR); spanNode->UpdateFontSize(options.style.value().GetFontSize()); spanNode->AddPropertyInfo(PropertyInfo::FONTSIZE); @@ -922,7 +922,7 @@ int32_t RichEditorPattern::AddTextSpanOperation( spanNode->AddPropertyInfo(PropertyInfo::FONTFAMILY); spanNode->UpdateTextDecoration(options.style.value().GetTextDecoration()); spanNode->AddPropertyInfo(PropertyInfo::TEXTDECORATION); - spanNode->UpdateTextDecorationColor(options.style.value().GetDynamicTextDecorationColor()); + spanNode->UpdateTextDecorationColor(options.style.value().GetTextDecorationColor()); spanNode->AddPropertyInfo(PropertyInfo::NONE); spanNode->UpdateTextDecorationStyle(options.style.value().GetTextDecorationStyle()); spanNode->AddPropertyInfo(PropertyInfo::NONE); @@ -1662,7 +1662,7 @@ void RichEditorPattern::UpdateTextStyle( CHECK_NULL_VOID(host); UpdateFontFeatureTextStyle(spanNode, updateSpanStyle, textStyle); if (updateSpanStyle.updateTextColor.has_value()) { - spanNode->UpdateTextColor(textStyle.GetDynamicTextColor()); + spanNode->UpdateTextColor(textStyle.GetTextColor()); spanNode->GetSpanItem()->useThemeFontColor = false; spanNode->AddPropertyInfo(PropertyInfo::FONTCOLOR); } @@ -1708,7 +1708,7 @@ void RichEditorPattern::UpdateDecoration( spanNode->AddPropertyInfo(PropertyInfo::TEXTDECORATION); } if (updateSpanStyle.updateTextDecorationColor.has_value()) { - spanNode->UpdateTextDecorationColor(textStyle.GetDynamicTextDecorationColor()); + spanNode->UpdateTextDecorationColor(textStyle.GetTextDecorationColor()); spanNode->AddPropertyInfo(PropertyInfo::NONE); } if (updateSpanStyle.updateTextDecorationStyle.has_value()) { @@ -1974,7 +1974,7 @@ void RichEditorPattern::SetSelectSpanStyle(int32_t start, int32_t end, KeyCode c spanStyle = spanTextStyle.value(); } HandleSelectFontStyleWrapper(code, spanStyle); - updateSpanStyle.updateTextColor = spanStyle.GetDynamicTextColor(); + updateSpanStyle.updateTextColor = spanStyle.GetTextColor(); updateSpanStyle.updateFontSize = spanStyle.GetFontSize(); updateSpanStyle.updateItalicFontStyle = spanStyle.GetFontStyle(); updateSpanStyle.updateFontWeight = spanStyle.GetFontWeight(); @@ -8401,7 +8401,7 @@ bool RichEditorPattern::SetPlaceholder(std::vector>>& return true; } -DynamicColor RichEditorPattern::GetCaretColor() +Color RichEditorPattern::GetCaretColor() { if (caretColor_.has_value()) { return caretColor_.value(); @@ -8413,9 +8413,9 @@ DynamicColor RichEditorPattern::GetCaretColor() return richEditorTheme->GetCaretColor(); } -DynamicColor RichEditorPattern::GetSelectedBackgroundColor() +Color RichEditorPattern::GetSelectedBackgroundColor() { - DynamicColor selectedBackgroundColor; + Color selectedBackgroundColor; if (selectedBackgroundColor_.has_value()) { selectedBackgroundColor = selectedBackgroundColor_.value(); } else { diff --git a/frameworks/core/components_ng/pattern/rich_editor/rich_editor_pattern.h b/frameworks/core/components_ng/pattern/rich_editor/rich_editor_pattern.h index d0f5464fdae..8a2454f8dd9 100644 --- a/frameworks/core/components_ng/pattern/rich_editor/rich_editor_pattern.h +++ b/frameworks/core/components_ng/pattern/rich_editor/rich_editor_pattern.h @@ -784,19 +784,19 @@ public: void OnVirtualKeyboardAreaChanged() override; - void SetCaretColor(const DynamicColor& caretColor) + void SetCaretColor(const Color& caretColor) { caretColor_ = caretColor; } - DynamicColor GetCaretColor(); + Color GetCaretColor(); - void SetSelectedBackgroundColor(const DynamicColor& selectedBackgroundColor) + void SetSelectedBackgroundColor(const Color& selectedBackgroundColor) { selectedBackgroundColor_ = selectedBackgroundColor; } - DynamicColor GetSelectedBackgroundColor(); + Color GetSelectedBackgroundColor(); void SetCustomKeyboardOption(bool supportAvoidance); void StopEditing(); @@ -1269,8 +1269,8 @@ private: std::optional typingStyle_; std::optional typingTextStyle_; std::list dragResultObjects_; - std::optional caretColor_; - std::optional selectedBackgroundColor_; + std::optional caretColor_; + std::optional selectedBackgroundColor_; std::function customKeyboardBuilder_; std::function caretChangeListener_; RefPtr keyboardOverlay_; diff --git a/frameworks/core/components_ng/pattern/text/span_node.h b/frameworks/core/components_ng/pattern/text/span_node.h index d92684ef30c..1ff666f25fe 100644 --- a/frameworks/core/components_ng/pattern/text/span_node.h +++ b/frameworks/core/components_ng/pattern/text/span_node.h @@ -494,13 +494,13 @@ public: } DEFINE_SPAN_FONT_STYLE_ITEM(FontSize, Dimension); - DEFINE_SPAN_FONT_STYLE_ITEM(TextColor, DynamicColor); + DEFINE_SPAN_FONT_STYLE_ITEM(TextColor, Color); DEFINE_SPAN_FONT_STYLE_ITEM(ItalicFontStyle, Ace::FontStyle); DEFINE_SPAN_FONT_STYLE_ITEM(FontWeight, FontWeight); DEFINE_SPAN_FONT_STYLE_ITEM(FontFamily, std::vector); DEFINE_SPAN_FONT_STYLE_ITEM(TextDecoration, TextDecoration); DEFINE_SPAN_FONT_STYLE_ITEM(TextDecorationStyle, TextDecorationStyle); - DEFINE_SPAN_FONT_STYLE_ITEM(TextDecorationColor, DynamicColor); + DEFINE_SPAN_FONT_STYLE_ITEM(TextDecorationColor, Color); DEFINE_SPAN_FONT_STYLE_ITEM(FontFeature, FONT_FEATURES_LIST); DEFINE_SPAN_FONT_STYLE_ITEM(TextCase, TextCase); DEFINE_SPAN_FONT_STYLE_ITEM(TextShadow, std::vector); diff --git a/frameworks/core/components_ng/pattern/text/text_layout_property.h b/frameworks/core/components_ng/pattern/text/text_layout_property.h index e7bd8c6cb25..1b94714cb75 100644 --- a/frameworks/core/components_ng/pattern/text/text_layout_property.h +++ b/frameworks/core/components_ng/pattern/text/text_layout_property.h @@ -67,7 +67,7 @@ public: ACE_DEFINE_PROPERTY_GROUP(FontStyle, FontStyle); ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP(FontStyle, FontSize, Dimension, PROPERTY_UPDATE_MEASURE); - ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP(FontStyle, TextColor, DynamicColor, PROPERTY_UPDATE_MEASURE_SELF); + ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP(FontStyle, TextColor, Color, PROPERTY_UPDATE_MEASURE_SELF); ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP(FontStyle, TextShadow, std::vector, PROPERTY_UPDATE_MEASURE); ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP(FontStyle, ItalicFontStyle, Ace::FontStyle, PROPERTY_UPDATE_MEASURE); ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP(FontStyle, FontWeight, FontWeight, PROPERTY_UPDATE_MEASURE); @@ -112,7 +112,7 @@ public: ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM( PlaceholderFontStyle, FontSize, PlaceholderFontSize, Dimension, PROPERTY_UPDATE_MEASURE); ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM( - PlaceholderFontStyle, TextColor, PlaceholderTextColor, DynamicColor, PROPERTY_UPDATE_MEASURE_SELF); + PlaceholderFontStyle, TextColor, PlaceholderTextColor, Color, PROPERTY_UPDATE_MEASURE_SELF); ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM( PlaceholderFontStyle, ItalicFontStyle, PlaceholderItalicFontStyle, Ace::FontStyle, PROPERTY_UPDATE_MEASURE); ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM( diff --git a/frameworks/core/components_ng/pattern/text/text_styles.cpp b/frameworks/core/components_ng/pattern/text/text_styles.cpp index ac889e75487..225dc6869e8 100644 --- a/frameworks/core/components_ng/pattern/text/text_styles.cpp +++ b/frameworks/core/components_ng/pattern/text/text_styles.cpp @@ -196,4 +196,22 @@ std::string GetSymbolEffectOptionsInJson(const std::optionalUpdateColorByResourceId(); + } + if (propTextDecorationColor) { + propTextDecorationColor->UpdateColorByResourceId(); + } + if (propTextShadow) { + auto& shadows = propTextShadow.value(); + std::for_each(shadows.begin(), shadows.end(), [](Shadow& sd) { sd.UpdateColorByResourceId(); }); + } + if (propSymbolColorList) { + auto& colors = propSymbolColorList.value(); + std::for_each(colors.begin(), colors.end(), [](Color& cl) { cl.UpdateColorByResourceId(); }); + } +} } // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/pattern/text/text_styles.h b/frameworks/core/components_ng/pattern/text/text_styles.h index d316e980845..29a6822f50a 100644 --- a/frameworks/core/components_ng/pattern/text/text_styles.h +++ b/frameworks/core/components_ng/pattern/text/text_styles.h @@ -151,7 +151,7 @@ constexpr Dimension TEXT_DEFAULT_FONT_SIZE = 16.0_fp; using FONT_FEATURES_LIST = std::list>; struct FontStyle { ACE_DEFINE_PROPERTY_GROUP_ITEM(FontSize, Dimension); - ACE_DEFINE_PROPERTY_GROUP_ITEM(TextColor, DynamicColor); + ACE_DEFINE_PROPERTY_GROUP_ITEM(TextColor, Color); ACE_DEFINE_PROPERTY_GROUP_ITEM(TextShadow, std::vector); ACE_DEFINE_PROPERTY_GROUP_ITEM(ItalicFontStyle, Ace::FontStyle); ACE_DEFINE_PROPERTY_GROUP_ITEM(FontWeight, FontWeight); @@ -160,13 +160,13 @@ struct FontStyle { ACE_DEFINE_PROPERTY_GROUP_ITEM(FontFamily, std::vector); ACE_DEFINE_PROPERTY_GROUP_ITEM(FontFeature, FONT_FEATURES_LIST); ACE_DEFINE_PROPERTY_GROUP_ITEM(TextDecoration, TextDecoration); - ACE_DEFINE_PROPERTY_GROUP_ITEM(TextDecorationColor, DynamicColor); + ACE_DEFINE_PROPERTY_GROUP_ITEM(TextDecorationColor, Color); ACE_DEFINE_PROPERTY_GROUP_ITEM(TextDecorationStyle, TextDecorationStyle); ACE_DEFINE_PROPERTY_GROUP_ITEM(TextCase, TextCase); ACE_DEFINE_PROPERTY_GROUP_ITEM(AdaptMinFontSize, Dimension); ACE_DEFINE_PROPERTY_GROUP_ITEM(AdaptMaxFontSize, Dimension); ACE_DEFINE_PROPERTY_GROUP_ITEM(LetterSpacing, Dimension); - ACE_DEFINE_PROPERTY_GROUP_ITEM(ForegroundColor, DynamicColor); + ACE_DEFINE_PROPERTY_GROUP_ITEM(ForegroundColor, Color); ACE_DEFINE_PROPERTY_GROUP_ITEM(SymbolColorList, std::vector); ACE_DEFINE_PROPERTY_GROUP_ITEM(SymbolRenderingStrategy, uint32_t); ACE_DEFINE_PROPERTY_GROUP_ITEM(SymbolEffectStrategy, uint32_t); @@ -174,15 +174,7 @@ struct FontStyle { ACE_DEFINE_PROPERTY_GROUP_ITEM(MinFontScale, float); ACE_DEFINE_PROPERTY_GROUP_ITEM(MaxFontScale, float); - void UpdateColorByResourceId() - { - if (propTextColor) { - propTextColor->UpdateColorByResourceId(); - } - if (propTextDecorationColor) { - propTextDecorationColor->UpdateColorByResourceId(); - } - } + void UpdateColorByResourceId(); }; struct TextLineStyle { diff --git a/frameworks/core/interfaces/native/node/rich_editor_modifier.cpp b/frameworks/core/interfaces/native/node/rich_editor_modifier.cpp index 3900bd2ada5..4b73e2b3f1b 100644 --- a/frameworks/core/interfaces/native/node/rich_editor_modifier.cpp +++ b/frameworks/core/interfaces/native/node/rich_editor_modifier.cpp @@ -490,7 +490,7 @@ void SetRichEditorPlaceholder(ArkUINodeHandle node, ArkUI_CharPtr* stringParamet if (SetRichEditorPlaceholderValue(valuesArray, 3, valuesCount, colorResourceId) && // 3: colorResourceId GreatOrEqual(colorResourceId, 0.0)) { fontColor.SetValue(static_cast(result)); - options.fontColor = DynamicColor(fontColor, static_cast(colorResourceId)); + options.fontColor = fontColor; } else { fontColor.SetValue(static_cast(result)); options.fontColor = fontColor;