From 9d8c537cf4c2f833df4e17ddeab012afca6a94dd Mon Sep 17 00:00:00 2001 From: kseniazakharova Date: Tue, 22 Oct 2024 10:14:45 +0300 Subject: [PATCH 1/2] Added PlaceholderColorFlagByUser property --- .../declarative_frontend/jsview/js_textfield.cpp | 7 ++++++- .../jsview/models/text_field_model_impl.h | 2 ++ .../text_field/text_field_layout_algorithm.cpp | 12 ++++++++---- .../pattern/text_field/text_field_layout_algorithm.h | 4 ++-- .../pattern/text_field/text_field_model.h | 2 ++ .../pattern/text_field/text_field_model_ng.cpp | 10 ++++++++++ .../pattern/text_field/text_field_model_ng.h | 2 ++ .../pattern/text_field/text_field_paint_property.h | 3 +++ .../pattern/text_field/text_field_pattern.cpp | 7 +------ 9 files changed, 36 insertions(+), 13 deletions(-) diff --git a/frameworks/bridge/declarative_frontend/jsview/js_textfield.cpp b/frameworks/bridge/declarative_frontend/jsview/js_textfield.cpp index 54caafc4d0c1..f658fb3e03cf 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_textfield.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_textfield.cpp @@ -247,8 +247,13 @@ void JSTextField::SetPlaceholderColor(const JSCallbackInfo& info) auto theme = GetTheme(); CHECK_NULL_VOID(theme); Color color = theme->GetPlaceholderColor(); - CheckColor(info[0], color, V2::TEXTINPUT_ETS_TAG, "PlaceholderColor"); + if (!CheckColor(info[0], color, V2::TEXTINPUT_ETS_TAG, "PlaceholderColor")) { + APP_LOGW("RESET PLACEHOLDER"); + TextFieldModel::GetInstance()->ResetPlaceholderColorFlagByUser(); + return; + } TextFieldModel::GetInstance()->SetPlaceholderColor(color); + TextFieldModel::GetInstance()->SetPlaceholderColorFlagByUser(color); } void JSTextField::SetPlaceholderFont(const JSCallbackInfo& info) diff --git a/frameworks/bridge/declarative_frontend/jsview/models/text_field_model_impl.h b/frameworks/bridge/declarative_frontend/jsview/models/text_field_model_impl.h index 950f5d2d70d6..151de48ae6a7 100644 --- a/frameworks/bridge/declarative_frontend/jsview/models/text_field_model_impl.h +++ b/frameworks/bridge/declarative_frontend/jsview/models/text_field_model_impl.h @@ -38,6 +38,8 @@ public: void SetType(TextInputType value) override; void SetContentType(const NG::TextContentType& value) override {}; void SetPlaceholderColor(const Color& value) override; + void SetPlaceholderColorFlagByUser(const Color& value) override {}; + void ResetPlaceholderColorFlagByUser() override {}; void SetPlaceholderFont(const Font& value) override; void SetEnterKeyType(TextInputAction value) override; void SetTextAlign(TextAlign value) override; diff --git a/frameworks/core/components_ng/pattern/text_field/text_field_layout_algorithm.cpp b/frameworks/core/components_ng/pattern/text_field/text_field_layout_algorithm.cpp index eb291ed63adf..bcff59e2c1a9 100644 --- a/frameworks/core/components_ng/pattern/text_field/text_field_layout_algorithm.cpp +++ b/frameworks/core/components_ng/pattern/text_field/text_field_layout_algorithm.cpp @@ -67,8 +67,9 @@ void TextFieldLayoutAlgorithm::ConstructTextStyles( textContent = pattern->GetTextValue(); UpdateTextStyleTextOverflowAndWordBreak(textStyle, isTextArea, isInlineStyle, textFieldLayoutProperty); } else { + APP_LOGW("ConstructTextStyles HasPlaceholderTextColor %{public}s", textFieldPaintProperty->HasPlaceholderColorFlagByUser() ? "true" : "false"); UpdatePlaceholderTextStyle( - frameNode, textFieldLayoutProperty, textFieldTheme, textStyle, pattern->IsDisabled()); + frameNode, textFieldLayoutProperty, textFieldTheme, textStyle, pattern->IsDisabled(), textFieldPaintProperty->HasPlaceholderColorFlagByUser()); textContent = textFieldLayoutProperty->GetPlaceholderValue(""); showPlaceHolder = true; } @@ -634,7 +635,7 @@ void TextFieldLayoutAlgorithm::UpdateTextStyle(const RefPtr& frameNod void TextFieldLayoutAlgorithm::UpdatePlaceholderTextStyle(const RefPtr& frameNode, const RefPtr& layoutProperty, const RefPtr& theme, TextStyle& textStyle, - bool isDisabled) + bool isDisabled, bool isTextColorByUser) { const std::vector defaultFontFamily = { "sans-serif" }; textStyle.SetFontFamilies(layoutProperty->GetPlaceholderFontFamilyValue(defaultFontFamily)); @@ -666,8 +667,11 @@ void TextFieldLayoutAlgorithm::UpdatePlaceholderTextStyle(const RefPtrGetTextColorDisable() : textStyle.GetTextColor()); } } else { - textStyle.SetTextColor(layoutProperty->GetPlaceholderTextColorValue( - theme ? theme->GetPlaceholderColor() : textStyle.GetTextColor())); + if (!isTextColorByUser) { + layoutProperty->UpdatePlaceholderTextColor(theme ? theme->GetPlaceholderColor() : textStyle.GetTextColor()); + } + textStyle.SetTextColor( + layoutProperty->GetPlaceholderTextColorValue(theme ? theme->GetPlaceholderColor() : textStyle.GetTextColor())); } if (layoutProperty->HasPlaceholderMaxLines()) { textStyle.SetMaxLines(layoutProperty->GetPlaceholderMaxLines().value()); diff --git a/frameworks/core/components_ng/pattern/text_field/text_field_layout_algorithm.h b/frameworks/core/components_ng/pattern/text_field/text_field_layout_algorithm.h index c18aa5264e1b..6df83e9d56ab 100644 --- a/frameworks/core/components_ng/pattern/text_field/text_field_layout_algorithm.h +++ b/frameworks/core/components_ng/pattern/text_field/text_field_layout_algorithm.h @@ -78,10 +78,10 @@ public: static void UpdateTextStyle(const RefPtr& frameNode, const RefPtr& layoutProperty, const RefPtr& theme, - TextStyle& textStyle, bool isDisabled, bool isTextColorByUser = false); + TextStyle& textStyle, bool isDisabled, bool isTextColorByUser = true); static void UpdatePlaceholderTextStyle(const RefPtr& frameNode, const RefPtr& layoutProperty, const RefPtr& theme, - TextStyle& textStyle, bool isDisabled); + TextStyle& textStyle, bool isDisabled, bool isTextColorByUser = true); void CounterLayout(LayoutWrapper* layoutWrapper); float CounterNodeMeasure(float contentWidth, LayoutWrapper* layoutWrapper); void UpdateCounterTextMargin(LayoutWrapper* layoutWrapper); diff --git a/frameworks/core/components_ng/pattern/text_field/text_field_model.h b/frameworks/core/components_ng/pattern/text_field/text_field_model.h index bc129091ee16..d906ffbc85ab 100644 --- a/frameworks/core/components_ng/pattern/text_field/text_field_model.h +++ b/frameworks/core/components_ng/pattern/text_field/text_field_model.h @@ -270,6 +270,8 @@ public: virtual void SetType(TextInputType value) = 0; virtual void SetContentType(const NG::TextContentType& value) = 0; virtual void SetPlaceholderColor(const Color& value) = 0; + virtual void SetPlaceholderColorFlagByUser(const Color& value) = 0; + virtual void ResetPlaceholderColorFlagByUser() = 0; virtual void SetPlaceholderFont(const Font& value) = 0; virtual void SetEnterKeyType(TextInputAction value) = 0; virtual void SetTextAlign(TextAlign value) = 0; diff --git a/frameworks/core/components_ng/pattern/text_field/text_field_model_ng.cpp b/frameworks/core/components_ng/pattern/text_field/text_field_model_ng.cpp index 8921df6b4824..7593d88d9c21 100644 --- a/frameworks/core/components_ng/pattern/text_field/text_field_model_ng.cpp +++ b/frameworks/core/components_ng/pattern/text_field/text_field_model_ng.cpp @@ -268,6 +268,16 @@ void TextFieldModelNG::SetPlaceholderColor(const Color& value) ACE_UPDATE_LAYOUT_PROPERTY(TextFieldLayoutProperty, PlaceholderTextColor, value); } +void TextFieldModelNG::SetPlaceholderColorFlagByUser(const Color& value) +{ + ACE_UPDATE_PAINT_PROPERTY(TextFieldPaintProperty, PlaceholderColorFlagByUser, value); +} + +void TextFieldModelNG::ResetPlaceholderColorFlagByUser() +{ + ACE_RESET_PAINT_PROPERTY(TextFieldPaintProperty, PlaceholderColorFlagByUser); +} + void TextFieldModelNG::SetContentType(const TextContentType& value) { auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); diff --git a/frameworks/core/components_ng/pattern/text_field/text_field_model_ng.h b/frameworks/core/components_ng/pattern/text_field/text_field_model_ng.h index fc95a0555639..693318cec9e0 100644 --- a/frameworks/core/components_ng/pattern/text_field/text_field_model_ng.h +++ b/frameworks/core/components_ng/pattern/text_field/text_field_model_ng.h @@ -37,6 +37,8 @@ public: void SetType(TextInputType value) override; void SetContentType(const TextContentType& value) override; void SetPlaceholderColor(const Color& value) override; + void SetPlaceholderColorFlagByUser(const Color& value) override; + void ResetPlaceholderColorFlagByUser() override; void SetPlaceholderFont(const Font& value) override; void SetEnterKeyType(TextInputAction value) override; void SetTextAlign(TextAlign value) override; diff --git a/frameworks/core/components_ng/pattern/text_field/text_field_paint_property.h b/frameworks/core/components_ng/pattern/text_field/text_field_paint_property.h index 34b5e38a9659..1698bd12e483 100644 --- a/frameworks/core/components_ng/pattern/text_field/text_field_paint_property.h +++ b/frameworks/core/components_ng/pattern/text_field/text_field_paint_property.h @@ -58,6 +58,7 @@ public: ResetHoverBgColor(); ResetTextColorFlagByUser(); ResetCaretColorFlagByUser(); + ResetPlaceholderColorFlagByUser(); ResetBorderRadiusFlagByUser(); ResetBorderColorFlagByUser(); ResetBorderWidthFlagByUser(); @@ -71,6 +72,7 @@ public: ResetBackgroundColor(); ResetTextColorFlagByUser(); ResetCaretColorFlagByUser(); + ResetPlaceholderColorFlagByUser(); ResetBorderRadiusFlagByUser(); ResetBorderColorFlagByUser(); ResetBorderWidthFlagByUser(); @@ -96,6 +98,7 @@ public: // 用于记录开发者设置的值 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(TextColorFlagByUser, Color, PROPERTY_UPDATE_RENDER); ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(CaretColorFlagByUser, Color, PROPERTY_UPDATE_RENDER); + ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(PlaceholderColorFlagByUser, Color, PROPERTY_UPDATE_RENDER); ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(BorderRadiusFlagByUser, BorderRadiusProperty, PROPERTY_UPDATE_RENDER); ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(BorderColorFlagByUser, BorderColorProperty, PROPERTY_UPDATE_RENDER); ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(BorderWidthFlagByUser, BorderWidthProperty, PROPERTY_UPDATE_RENDER); diff --git a/frameworks/core/components_ng/pattern/text_field/text_field_pattern.cpp b/frameworks/core/components_ng/pattern/text_field/text_field_pattern.cpp index d0a4ff955e14..dadd64bd82c3 100644 --- a/frameworks/core/components_ng/pattern/text_field/text_field_pattern.cpp +++ b/frameworks/core/components_ng/pattern/text_field/text_field_pattern.cpp @@ -3973,11 +3973,6 @@ bool TextFieldPattern::OnThemeScopeUpdate(int32_t themeScopeId) result = true; } - if (!paintProperty->HasTextColorFlagByUser()) { - textFieldLayoutProperty->UpdateTextColor(textFieldTheme->GetTextColor()); - result = true; - } - if (!paintProperty->HasTextColorFlagByUser()) { textFieldLayoutProperty->UpdateTextColor(textFieldTheme->GetTextColor()); result = true; @@ -3988,7 +3983,7 @@ bool TextFieldPattern::OnThemeScopeUpdate(int32_t themeScopeId) result = true; } - if (result) { + if (result || !paintProperty->HasPlaceholderColorFlagByUser()) { host->MarkDirtyNode(PROPERTY_UPDATE_MEASURE); } -- Gitee From 52c7acd239d2a099fd2c7e4ca932d10f8885fa1b Mon Sep 17 00:00:00 2001 From: kseniazakharova Date: Tue, 22 Oct 2024 12:43:54 +0300 Subject: [PATCH 2/2] Delete logs --- frameworks/bridge/declarative_frontend/jsview/js_textfield.cpp | 1 - .../pattern/text_field/text_field_layout_algorithm.cpp | 1 - 2 files changed, 2 deletions(-) diff --git a/frameworks/bridge/declarative_frontend/jsview/js_textfield.cpp b/frameworks/bridge/declarative_frontend/jsview/js_textfield.cpp index f658fb3e03cf..aa13209f8d9a 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_textfield.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_textfield.cpp @@ -248,7 +248,6 @@ void JSTextField::SetPlaceholderColor(const JSCallbackInfo& info) CHECK_NULL_VOID(theme); Color color = theme->GetPlaceholderColor(); if (!CheckColor(info[0], color, V2::TEXTINPUT_ETS_TAG, "PlaceholderColor")) { - APP_LOGW("RESET PLACEHOLDER"); TextFieldModel::GetInstance()->ResetPlaceholderColorFlagByUser(); return; } diff --git a/frameworks/core/components_ng/pattern/text_field/text_field_layout_algorithm.cpp b/frameworks/core/components_ng/pattern/text_field/text_field_layout_algorithm.cpp index bcff59e2c1a9..b037e7fcd633 100644 --- a/frameworks/core/components_ng/pattern/text_field/text_field_layout_algorithm.cpp +++ b/frameworks/core/components_ng/pattern/text_field/text_field_layout_algorithm.cpp @@ -67,7 +67,6 @@ void TextFieldLayoutAlgorithm::ConstructTextStyles( textContent = pattern->GetTextValue(); UpdateTextStyleTextOverflowAndWordBreak(textStyle, isTextArea, isInlineStyle, textFieldLayoutProperty); } else { - APP_LOGW("ConstructTextStyles HasPlaceholderTextColor %{public}s", textFieldPaintProperty->HasPlaceholderColorFlagByUser() ? "true" : "false"); UpdatePlaceholderTextStyle( frameNode, textFieldLayoutProperty, textFieldTheme, textStyle, pattern->IsDisabled(), textFieldPaintProperty->HasPlaceholderColorFlagByUser()); textContent = textFieldLayoutProperty->GetPlaceholderValue(""); -- Gitee