diff --git a/frameworks/bridge/declarative_frontend/jsview/js_textfield.cpp b/frameworks/bridge/declarative_frontend/jsview/js_textfield.cpp index bd9bcc5c4a1b731742d1af2a412b58a126e37588..7ebf38c951e2b8708579ccb79b1909fe14b260de 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_textfield.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_textfield.cpp @@ -503,21 +503,6 @@ void JSTextField::JsHeight(const JSCallbackInfo& info) textInputComponent->SetHeight(value); } -void JSTextField::JsWidth(const JSCallbackInfo& info) -{ - if (info[0]->IsString() && info[0]->ToString() == "auto") { - ViewAbstractModel::GetInstance()->ClearWidthOrHeight(true); - TextFieldModel::GetInstance()->SetWidthAuto(true); - return; - } - JSViewAbstract::JsWidth(info); - if (info.Length() < 1) { - LOGE("The arg is wrong, it is supposed to have at least 1 arguments"); - return; - } - TextFieldModel::GetInstance()->SetWidthAuto(false); -} - void JSTextField::JsPadding(const JSCallbackInfo& info) { if (Container::IsCurrentUseNewPipeline()) { diff --git a/frameworks/bridge/declarative_frontend/jsview/js_textfield.h b/frameworks/bridge/declarative_frontend/jsview/js_textfield.h index fce7105e9331d4060f387a65f8f2f9c1e055316d..1302b83f62303e0ccf7a04bc961932727f517be1 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_textfield.h +++ b/frameworks/bridge/declarative_frontend/jsview/js_textfield.h @@ -46,7 +46,6 @@ public: static void SetShowPasswordIcon(const JSCallbackInfo& info); static void SetBackgroundColor(const JSCallbackInfo& info); static void JsHeight(const JSCallbackInfo& info); - static void JsWidth(const JSCallbackInfo& info); static void JsPadding(const JSCallbackInfo& info); static void JsBorder(const JSCallbackInfo& info); static void JsBorderWidth(const JSCallbackInfo& info); diff --git a/frameworks/bridge/declarative_frontend/jsview/js_textinput.cpp b/frameworks/bridge/declarative_frontend/jsview/js_textinput.cpp index 42e294778164f3d8a1bc83bb7e2be5b8a1acf0a9..e53fe43a9f5361d86f5ee1041a0e2e56ba80a4f3 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_textinput.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_textinput.cpp @@ -45,7 +45,6 @@ void JSTextInput::JSBind(BindingTarget globalObj) JSClass::StaticMethod("enterKeyType", &JSTextField::SetEnterKeyType); JSClass::StaticMethod("caretColor", &JSTextField::SetCaretColor); JSClass::StaticMethod("maxLength", &JSTextField::SetMaxLength); - JSClass::StaticMethod("width", &JSTextField::JsWidth); JSClass::StaticMethod("height", &JSTextField::JsHeight); JSClass::StaticMethod("padding", &JSTextField::JsPadding); JSClass::StaticMethod("border", &JSTextField::JsBorder); 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 781695c611dde5117fd9983767836bb4b3da0c8d..7aab7892a097795e11a337d866c5a01e0b14b611 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 @@ -33,7 +33,7 @@ public: { return nullptr; } - void SetWidthAuto(bool isAuto) override {}; + void SetType(TextInputType value) override; void SetPlaceholderColor(const Color& value) override; void SetPlaceholderFont(const Font& value) override; diff --git a/frameworks/bridge/declarative_frontend/jsview/models/view_abstract_model_impl.h b/frameworks/bridge/declarative_frontend/jsview/models/view_abstract_model_impl.h index 9c1336eee22df21360dd5ed82016bb77807e8a15..1d76f217c43e8268d1b4792f66d1d34649d8f8ac 100644 --- a/frameworks/bridge/declarative_frontend/jsview/models/view_abstract_model_impl.h +++ b/frameworks/bridge/declarative_frontend/jsview/models/view_abstract_model_impl.h @@ -31,7 +31,6 @@ public: void SetWidth(const Dimension& width) override; void SetHeight(const Dimension& height) override; - void ClearWidthOrHeight(bool isWidth) override {}; void SetMinWidth(const Dimension& minWidth) override; void SetMinHeight(const Dimension& minHeight) override; void SetMaxWidth(const Dimension& maxWidth) override; diff --git a/frameworks/core/components/text_field/render_text_field.cpp b/frameworks/core/components/text_field/render_text_field.cpp index 20102e814fd5c2bf55d460cf1ecbae798bccdbe9..3d35cbe6e3f22f8c7bafc86d681760f64ffaf8d3 100644 --- a/frameworks/core/components/text_field/render_text_field.cpp +++ b/frameworks/core/components/text_field/render_text_field.cpp @@ -1164,7 +1164,7 @@ void RenderTextField::ResetOnFocusForTextFieldManager() bool RenderTextField::RequestKeyboard(bool isFocusViewChanged, bool needStartTwinkling, bool needShowSoftKeyboard) { if (!enabled_) { - LOGW("TextField is not enabled."); + LOGD("TextField is not enabled."); return false; } @@ -1277,7 +1277,7 @@ void RenderTextField::AttachIme() config.action = action_; config.actionLabel = actionLabel_; config.obscureText = obscure_; - LOGI("Request keyboard configuration: type=%{private}d action=%{private}d actionLabel=%{private}s " + LOGD("Request keyboard configuration: type=%{private}d action=%{private}d actionLabel=%{private}s " "obscureText=%{private}d", keyboard_, action_, actionLabel_.c_str(), obscure_); connection_ = @@ -1704,7 +1704,7 @@ void RenderTextField::PerformDefaultAction() void RenderTextField::PerformAction(TextInputAction action, bool forceCloseKeyboard) { - LOGI("PerformAction %{public}d", static_cast(action)); + LOGD("PerformAction %{public}d", static_cast(action)); ContainerScope scope(instanceId_); if (keyboard_ == TextInputType::MULTILINE) { auto value = GetEditingValue(); @@ -2351,11 +2351,11 @@ void RenderTextField::HandleOnCut() return; } if (GetEditingValue().GetSelectedText().empty()) { - LOGW("copy value is empty"); + LOGD("copy value is empty"); return; } if (copyOption_ != CopyOptions::None) { - LOGI("copy value is %{private}s", GetEditingValue().GetSelectedText().c_str()); + LOGD("copy value is %{private}s", GetEditingValue().GetSelectedText().c_str()); clipboard_->SetData(GetEditingValue().GetSelectedText(), copyOption_); } if (onCut_) { @@ -2380,7 +2380,7 @@ void RenderTextField::HandleOnCopy() return; } if (copyOption_ != CopyOptions::None) { - LOGI("copy value is %{private}s", GetEditingValue().GetSelectedText().c_str()); + LOGD("copy value is %{private}s", GetEditingValue().GetSelectedText().c_str()); clipboard_->SetData(GetEditingValue().GetSelectedText(), copyOption_); } if (onCopy_) { @@ -2401,7 +2401,7 @@ void RenderTextField::HandleOnPaste() LOGW("paste value is empty"); return; } - LOGI("paste value is %{private}s", data.c_str()); + LOGD("paste value is %{private}s", data.c_str()); auto textfield = weak.Upgrade(); if (textfield) { auto value = textfield->GetEditingValue(); diff --git a/frameworks/core/components/text_field/render_text_field.h b/frameworks/core/components/text_field/render_text_field.h index 32454735e2266669a31185ed77f146bc9ab8b8b5..cebb9e0b5a60d68db784eedd13bb202ab4a773c4 100644 --- a/frameworks/core/components/text_field/render_text_field.h +++ b/frameworks/core/components/text_field/render_text_field.h @@ -426,14 +426,6 @@ protected: Offset offset; // When caret is close to different glyphs, the height will be different. double height = 0.0; - std::string ToString() const - { - std::string result = "Offset: "; - result += offset.ToString(); - result += ", height: "; - result += std::to_string(height); - return result; - } }; RenderTextField(); diff --git a/frameworks/core/components/text_field/textfield_theme.h b/frameworks/core/components/text_field/textfield_theme.h index 70b57612c42d5bb29871b317aa1c3681f0ccfdc2..7d4d38bbbf1a063e8dc86e1a1d98e52792e08359 100644 --- a/frameworks/core/components/text_field/textfield_theme.h +++ b/frameworks/core/components/text_field/textfield_theme.h @@ -154,7 +154,7 @@ public: theme->cursorColor_ = pattern->GetAttr("cursor_color", Color()); theme->hoverColor_ = pattern->GetAttr(PATTERN_BG_COLOR_HOVERED, Color()); theme->pressColor_ = pattern->GetAttr(PATTERN_BG_COLOR_PRESSED, Color()); - theme->disabledIconFillColor_ = theme->bgColor_.BlendOpacity(theme->disableOpacityRatio_); + } }; @@ -240,11 +240,6 @@ public: return disableOpacityRatio_; } - const Color& GetDisabledIconFillColor() const - { - return disabledIconFillColor_; - } - const Dimension& GetOverHideLength() const { return overHideLength_; @@ -345,7 +340,6 @@ private: Color selectedColor_; Color hoverColor_; Color pressColor_; - Color disabledIconFillColor_; Dimension errorSpacing_; bool errorIsInner_ = false; Dimension errorBorderWidth_; diff --git a/frameworks/core/components/text_overlay/text_overlay_manager.h b/frameworks/core/components/text_overlay/text_overlay_manager.h index 5f9f17ca8ad8bebf884d616fa60a39d0c7dac7e5..155d59b085d7d89b16a1683b4f5cd4649dd07347 100644 --- a/frameworks/core/components/text_overlay/text_overlay_manager.h +++ b/frameworks/core/components/text_overlay/text_overlay_manager.h @@ -18,9 +18,9 @@ #include "core/components/common/layout/constants.h" #include "core/components/common/properties/color.h" +#include "frameworks/base/memory/ace_type.h" #include "frameworks/base/geometry/offset.h" #include "frameworks/base/geometry/rect.h" -#include "frameworks/base/memory/ace_type.h" #include "frameworks/core/common/ime/text_editing_value.h" #include "frameworks/core/pipeline/base/overlay_show_option.h" @@ -64,14 +64,6 @@ struct CaretMetrics { Offset offset; // When caret is close to different glyphs, the height will be different. double height = 0.0; - std::string ToString() const - { - std::string result = "Offset: "; - result += offset.ToString(); - result += ", height: "; - result += std::to_string(height); - return result; - } }; class TextOverlayBase : public virtual AceType { @@ -104,7 +96,7 @@ public: static bool IsSelectiveDevice() { return (SystemProperties::GetDeviceType() != DeviceType::TV && - SystemProperties::GetDeviceType() != DeviceType::WATCH); + SystemProperties::GetDeviceType() != DeviceType::WATCH); } void MarkIsOverlayShowed(bool isOverlayShowed) @@ -163,8 +155,8 @@ protected: TextEditingValue textValue_; std::string textForDisplay_; int32_t cursorPositionForShow_ = 0; - double cursorWidth_ = 0.0; // The unit is px. - bool isOverlayShowed_ = false; // Whether overlay has showed. + double cursorWidth_ = 0.0; // The unit is px. + bool isOverlayShowed_ = false; // Whether overlay has showed. RefPtr animator_; std::function updateHandlePosition_; std::function updateHandleDiameter_; @@ -235,8 +227,8 @@ public: const RefPtr GetTargetNode() const; void PopTextOverlay(); - void PushTextOverlayToStack( - const RefPtr& textOverlay, const WeakPtr& context); + void PushTextOverlayToStack(const RefPtr& textOverlay, + const WeakPtr& context); void HandleCtrlC() const; diff --git a/frameworks/core/components_ng/base/view_abstract.cpp b/frameworks/core/components_ng/base/view_abstract.cpp index 07ee4d15da71e9913980a7421b07d857b6680c70..ca8b7fb7502912f3c280264637dd9a54887835a2 100644 --- a/frameworks/core/components_ng/base/view_abstract.cpp +++ b/frameworks/core/components_ng/base/view_abstract.cpp @@ -84,19 +84,6 @@ void ViewAbstract::SetHeight(const CalcLength& height) layoutProperty->UpdateUserDefinedIdealSize(CalcSize(std::nullopt, height)); } -void ViewAbstract::ClearWidthOrHeight(bool isWidth) -{ - if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) { - LOGD("current state is not processed, return"); - return; - } - auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); - CHECK_NULL_VOID(frameNode); - auto layoutProperty = frameNode->GetLayoutProperty(); - CHECK_NULL_VOID(layoutProperty); - layoutProperty->ClearUserDefinedIdealSize(isWidth); -} - void ViewAbstract::SetMinWidth(const CalcLength& width) { if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) { diff --git a/frameworks/core/components_ng/base/view_abstract.h b/frameworks/core/components_ng/base/view_abstract.h index eebc74aee85bc3b2e30e62c854064944a45ca5b0..b77e34d3125a96ce91970bee8da83c1571e3e448 100644 --- a/frameworks/core/components_ng/base/view_abstract.h +++ b/frameworks/core/components_ng/base/view_abstract.h @@ -52,7 +52,6 @@ class ACE_EXPORT ViewAbstract { public: static void SetWidth(const CalcLength& width); static void SetHeight(const CalcLength& height); - static void ClearWidthOrHeight(bool isWidth); static void SetMinWidth(const CalcLength& minWidth); static void SetMinHeight(const CalcLength& minHeight); static void SetMaxWidth(const CalcLength& maxWidth); diff --git a/frameworks/core/components_ng/base/view_abstract_model.h b/frameworks/core/components_ng/base/view_abstract_model.h index 49b5ec8ddd84532b85aed25258a5d190e0e59f66..19b73fcdebcfc1292a65a9922c3c0fbc514f010c 100644 --- a/frameworks/core/components_ng/base/view_abstract_model.h +++ b/frameworks/core/components_ng/base/view_abstract_model.h @@ -56,7 +56,6 @@ public: // basic size virtual void SetWidth(const Dimension& width) = 0; virtual void SetHeight(const Dimension& height) = 0; - virtual void ClearWidthOrHeight(bool isWidth) = 0; virtual void SetMinWidth(const Dimension& minWidth) = 0; virtual void SetMinHeight(const Dimension& minHeight) = 0; virtual void SetMaxWidth(const Dimension& maxWidth) = 0; diff --git a/frameworks/core/components_ng/base/view_abstract_model_ng.h b/frameworks/core/components_ng/base/view_abstract_model_ng.h index 0aa2e31fe19b7886173a5a0b654276050e09e4c4..590a47691dce9837dc5c16bf513c5822df85c8e3 100644 --- a/frameworks/core/components_ng/base/view_abstract_model_ng.h +++ b/frameworks/core/components_ng/base/view_abstract_model_ng.h @@ -52,11 +52,6 @@ public: ViewAbstract::SetHeight(NG::CalcLength(height)); } - void ClearWidthOrHeight(bool isWidth) override - { - ViewAbstract::ClearWidthOrHeight(isWidth); - } - void SetMinWidth(const Dimension& minWidth) override { ViewAbstract::SetMinWidth(NG::CalcLength(minWidth)); diff --git a/frameworks/core/components_ng/layout/layout_property.h b/frameworks/core/components_ng/layout/layout_property.h index 4da226edcc4c88efa68febbb24ae7a9e63750f21..515aa95c49f86c161b48a996c2decd4958574f56 100644 --- a/frameworks/core/components_ng/layout/layout_property.h +++ b/frameworks/core/components_ng/layout/layout_property.h @@ -205,16 +205,6 @@ public: } } - void ClearUserDefinedIdealSize(bool isWidth) - { - if (!calcLayoutConstraint_) { - calcLayoutConstraint_ = std::make_unique(); - } - if (calcLayoutConstraint_->ClearSelfIdealSize(isWidth)) { - propertyChangeFlag_ = propertyChangeFlag_ | PROPERTY_UPDATE_MEASURE; - } - } - void UpdateCalcMinSize(const CalcSize& value) { if (!calcLayoutConstraint_) { diff --git a/frameworks/core/components_ng/pattern/text_field/on_text_changed_listener_impl.cpp b/frameworks/core/components_ng/pattern/text_field/on_text_changed_listener_impl.cpp index ee69ed89394131eda6151837f9243c2c51729f47..4a9f5f5ec3fafbffadfe00ccad35717fe909db72 100644 --- a/frameworks/core/components_ng/pattern/text_field/on_text_changed_listener_impl.cpp +++ b/frameworks/core/components_ng/pattern/text_field/on_text_changed_listener_impl.cpp @@ -83,18 +83,10 @@ void OnTextChangedListenerImpl::SendKeyEventFromInputMethod(const MiscServices:: void OnTextChangedListenerImpl::SendKeyboardInfo(const MiscServices::KeyboardInfo& info) { - HandleKeyboardStatus(info.GetKeyboardStatus()); HandleFunctionKey(info.GetFunctionKey()); } -void OnTextChangedListenerImpl::HandleKeyboardStatus(MiscServices::KeyboardStatus status) -{ - LOGI("[OnTextChangedListenerImpl] HandleKeyboardStatus status: %{public}d", status); - if (status == MiscServices::KeyboardStatus::NONE) { - return; - } - SetKeyboardStatus(status == MiscServices::KeyboardStatus::SHOW); -} +void OnTextChangedListenerImpl::HandleKeyboardStatus(MiscServices::KeyboardStatus status) {} void OnTextChangedListenerImpl::HandleFunctionKey(MiscServices::FunctionKey functionKey) { diff --git a/frameworks/core/components_ng/pattern/text_field/text_editing_value_ng.h b/frameworks/core/components_ng/pattern/text_field/text_editing_value_ng.h index e060ab496a7f41661b43f4f95557c1a215a1f5fd..1e9c37a8b9dcfedcc6a42170aa38c1e9d4f2398d 100644 --- a/frameworks/core/components_ng/pattern/text_field/text_editing_value_ng.h +++ b/frameworks/core/components_ng/pattern/text_field/text_editing_value_ng.h @@ -101,22 +101,6 @@ struct TextEditingValueNG { return StringUtils::ToString(wideText.substr(min, max - min)); } - bool CaretAtLast() const - { - return static_cast(GetWideText().length()) == caretPosition; - } - - char16_t LastChar() const - { - if (text.empty()) { - return 0; - } - if (static_cast(caretPosition) > text.length()) { - return 0; - } - return text[std::max(0, caretPosition - 1)]; - } - std::string ToString() const { return GetValueBeforeCursor() + "|" + GetValueAfterCursor(); 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 72ad7ec1754e16a549fdc52c6244cd53345b296e..6d9bb42920ff8da4837d9be74e76532f5afd5d47 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 @@ -33,7 +33,6 @@ #include "core/components_ng/pattern/text/text_layout_property.h" #include "core/components_ng/pattern/text_field/text_field_layout_property.h" #include "core/components_ng/pattern/text_field/text_field_pattern.h" -#include "core/components_ng/pattern/text_field/text_selector.h" #include "core/components_ng/property/measure_utils.h" #include "core/components_ng/render/drawing_prop_convertor.h" #include "core/components_ng/render/font_collection.h" @@ -51,17 +50,12 @@ void TextFieldLayoutAlgorithm::Measure(LayoutWrapper* layoutWrapper) CHECK_NULL_VOID(frameNode); auto pattern = frameNode->GetPattern(); CHECK_NULL_VOID(pattern); - float contentWidth = 0.0f; float contentHeight = 0.0f; if (content) { auto contentSize = content->GetRect().GetSize(); - contentWidth = contentSize.Width(); contentHeight = contentSize.Height(); } if (pattern->IsTextArea()) { - if (!layoutConstraint->selfIdealSize.Width().has_value()) { - frameSize.SetWidth(contentWidth + pattern->GetHorizontalPaddingSum()); - } if (!frameSize.Height().has_value()) { frameSize.SetHeight(contentHeight + pattern->GetVerticalPaddingSum()); } @@ -74,19 +68,6 @@ void TextFieldLayoutAlgorithm::Measure(LayoutWrapper* layoutWrapper) frameSize.SetHeight( std::min(layoutConstraint->maxSize.Height(), contentHeight + pattern->GetVerticalPaddingSum())); } - auto textfieldLayoutProperty = AceType::DynamicCast(layoutWrapper->GetLayoutProperty()); - CHECK_NULL_VOID(textfieldLayoutProperty); - if (textfieldLayoutProperty->GetWidthAutoValue(false)) { - if (LessOrEqual(layoutConstraint->minSize.Width(), 0.0f)) { - frameSize.SetWidth(std::clamp(textRect_.GetSize().Width() + pattern->GetHorizontalPaddingSum(), - pattern->GetHorizontalPaddingSum(), layoutConstraint->maxSize.Width())); - } else if (LessOrEqual(textRect_.Width(), 0.0f)) { - frameSize.SetWidth(layoutConstraint->minSize.Width()); - } else { - frameSize.SetWidth(std::clamp(textRect_.Width() + pattern->GetHorizontalPaddingSum(), - layoutConstraint->minSize.Width(), layoutConstraint->maxSize.Width())); - } - } layoutWrapper->GetGeometryNode()->SetFrameSize(frameSize.ConvertToSizeT()); frameRect_ = RectF(layoutWrapper->GetGeometryNode()->GetFrameOffset(), layoutWrapper->GetGeometryNode()->GetFrameSize()); @@ -108,50 +89,45 @@ std::optional TextFieldLayoutAlgorithm::MeasureContent( TextStyle textStyle; std::string textContent; bool showPlaceHolder = false; - auto idealWidth = contentConstraint.selfIdealSize.Width().value_or(contentConstraint.maxSize.Width()) - - pattern->GetHorizontalPaddingSum(); - auto idealHeight = contentConstraint.selfIdealSize.Height().value_or(contentConstraint.maxSize.Height()) - - pattern->GetVerticalPaddingSum(); if (!textFieldLayoutProperty->GetValueValue("").empty()) { - UpdateTextStyle(textFieldLayoutProperty, textFieldTheme, textStyle, pattern->IsDisabled()); + UpdateTextStyle(textFieldLayoutProperty, textFieldTheme, textStyle); textContent = textFieldLayoutProperty->GetValueValue(""); } else { - UpdatePlaceholderTextStyle(textFieldLayoutProperty, textFieldTheme, textStyle, pattern->IsDisabled()); + UpdatePlaceholderTextStyle(textFieldLayoutProperty, textFieldTheme, textStyle); textContent = textFieldLayoutProperty->GetPlaceholderValue(""); showPlaceHolder = true; } auto isPasswordType = textFieldLayoutProperty->GetTextInputTypeValue(TextInputType::UNSPECIFIED) == TextInputType::VISIBLE_PASSWORD; CreateParagraph(textStyle, textContent, isPasswordType && pattern->GetTextObscured() && !showPlaceHolder); + + auto horizontalPaddingSum = pattern->GetHorizontalPaddingSum(); if (textStyle.GetMaxLines() == 1 && !showPlaceHolder) { // for text input case, need to measure in one line without constraint. paragraph_->Layout(std::numeric_limits::infinity()); } else { // for text area, max width is content width without password icon - paragraph_->Layout(idealWidth); + paragraph_->Layout(contentConstraint.maxSize.Width() - horizontalPaddingSum); } auto paragraphNewWidth = static_cast(paragraph_->GetMaxIntrinsicWidth()); if (!NearEqual(paragraphNewWidth, paragraph_->GetMaxWidth()) && !pattern->IsTextArea()) { paragraph_->Layout(std::ceil(paragraphNewWidth)); } - if (showPlaceHolder) { - placeholderParagraphHeight_ = paragraph_->GetHeight(); - } auto preferredHeight = static_cast(paragraph_->GetHeight()); if (textContent.empty()) { preferredHeight = pattern->PreferredLineHeight(); } if (pattern->IsTextArea()) { - auto useHeight = static_cast(paragraph_->GetHeight()); - textRect_.SetSize(SizeF(idealWidth, useHeight)); - return SizeF(idealWidth, std::min(idealHeight, useHeight)); + textRect_.SetSize(SizeF( + contentConstraint.maxSize.Width() - horizontalPaddingSum, static_cast(paragraph_->GetHeight()))); + return SizeF(contentConstraint.maxSize.Width() - horizontalPaddingSum, preferredHeight); } auto showPasswordIcon = textFieldLayoutProperty->GetShowPasswordIcon().value_or(true); // check password image size. if (!showPasswordIcon || !isPasswordType) { textRect_.SetSize(SizeF(static_cast(paragraph_->GetLongestLine()), preferredHeight)); imageRect_.Reset(); - return SizeF(idealWidth, preferredHeight); + return SizeF(contentConstraint.maxSize.Width() - horizontalPaddingSum, preferredHeight); } float imageSize = 0.0f; imageSize = showPasswordIcon ? preferredHeight : 0.0f; @@ -161,10 +137,10 @@ std::optional TextFieldLayoutAlgorithm::MeasureContent( if (textStyle.GetMaxLines() > 1 || pattern->IsTextArea()) { // for textArea, need to delete imageWidth and remeasure. - paragraph_->Layout(idealWidth - imageSize); + paragraph_->Layout(contentConstraint.maxSize.Width() - imageSize); textRect_.SetSize(SizeF(static_cast(paragraph_->GetLongestLine()), preferredHeight)); imageRect_.SetSize(SizeF(0.0f, 0.0f)); - return SizeF(idealWidth, imageSize); + return SizeF(contentConstraint.maxSize.Width(), imageSize); } imageRect_.SetSize(SizeF(imageSize, imageSize)); if (pattern->GetTextObscured() && pattern->GetHidePasswordIconCtx()) { @@ -172,9 +148,10 @@ std::optional TextFieldLayoutAlgorithm::MeasureContent( } else if (!pattern->GetTextObscured() && pattern->GetShowPasswordIconCtx()) { pattern->GetShowPasswordIconCtx()->MakeCanvasImage(imageRect_.GetSize(), true, ImageFit::NONE); } - preferredHeight = std::min(static_cast(paragraph_->GetHeight()), idealHeight); + preferredHeight = std::min(static_cast(paragraph_->GetHeight()), contentConstraint.maxSize.Height()); textRect_.SetSize(SizeF(static_cast(paragraph_->GetLongestLine()), static_cast(preferredHeight))); - return SizeF(idealWidth - imageSize, std::min(idealHeight, preferredHeight)); + return SizeF(contentConstraint.maxSize.Width() - horizontalPaddingSum - imageSize, + std::min(contentConstraint.maxSize.Height() - pattern->GetVerticalPaddingSum(), preferredHeight)); } void TextFieldLayoutAlgorithm::Layout(LayoutWrapper* layoutWrapper) @@ -205,7 +182,9 @@ void TextFieldLayoutAlgorithm::Layout(LayoutWrapper* layoutWrapper) textRect_.SetOffset(contentOffset); return; } + contentOffset = Alignment::GetAlignPosition(size, contentSize, align); + content->SetOffset(OffsetF(pattern->GetPaddingLeft(), contentOffset.GetY())); // if handler is moving, no need to adjust text rect in pattern if (pattern->GetCaretUpdateType() == CaretUpdateType::HANDLE_MOVE || @@ -237,8 +216,8 @@ void TextFieldLayoutAlgorithm::Layout(LayoutWrapper* layoutWrapper) } } -void TextFieldLayoutAlgorithm::UpdateTextStyle(const RefPtr& layoutProperty, - const RefPtr& theme, TextStyle& textStyle, bool isDisabled) +void TextFieldLayoutAlgorithm::UpdateTextStyle( + const RefPtr& layoutProperty, const RefPtr& theme, TextStyle& textStyle) { const std::vector defaultFontFamily = { "sans-serif" }; textStyle.SetFontFamilies(layoutProperty->GetFontFamilyValue(defaultFontFamily)); @@ -250,15 +229,10 @@ void TextFieldLayoutAlgorithm::UpdateTextStyle(const RefPtrGetFontSize() : textStyle.GetFontSize(); } textStyle.SetFontSize(fontSize); - textStyle.SetTextAlign(layoutProperty->GetTextAlignValue(TextAlign::START)); + textStyle.SetFontWeight( layoutProperty->GetFontWeightValue(theme ? theme->GetFontWeight() : textStyle.GetFontWeight())); - if (isDisabled) { - textStyle.SetTextColor(theme ? theme->GetDisableTextColor() : textStyle.GetTextColor()); - } else { - textStyle.SetTextColor( - layoutProperty->GetTextColorValue(theme ? theme->GetTextColor() : textStyle.GetTextColor())); - } + textStyle.SetTextColor(layoutProperty->GetTextColorValue(theme ? theme->GetTextColor() : textStyle.GetTextColor())); if (layoutProperty->GetMaxLines()) { textStyle.SetMaxLines(layoutProperty->GetMaxLines().value()); } @@ -270,8 +244,8 @@ void TextFieldLayoutAlgorithm::UpdateTextStyle(const RefPtr& layoutProperty, - const RefPtr& theme, TextStyle& textStyle, bool isDisabled) +void TextFieldLayoutAlgorithm::UpdatePlaceholderTextStyle( + const RefPtr& layoutProperty, const RefPtr& theme, TextStyle& textStyle) { const std::vector defaultFontFamily = { "sans-serif" }; textStyle.SetFontFamilies(layoutProperty->GetFontFamilyValue(defaultFontFamily)); @@ -285,12 +259,8 @@ void TextFieldLayoutAlgorithm::UpdatePlaceholderTextStyle(const RefPtrGetPlaceholderFontWeightValue(theme ? theme->GetFontWeight() : textStyle.GetFontWeight())); - if (isDisabled) { - textStyle.SetTextColor(theme ? theme->GetDisableTextColor() : textStyle.GetTextColor()); - } else { - textStyle.SetTextColor(layoutProperty->GetPlaceholderTextColorValue( - theme ? theme->GetPlaceholderColor() : textStyle.GetTextColor())); - } + textStyle.SetTextColor( + layoutProperty->GetPlaceholderTextColorValue(theme ? theme->GetPlaceholderColor() : textStyle.GetTextColor())); if (layoutProperty->HasPlaceholderMaxLines()) { textStyle.SetMaxLines(layoutProperty->GetPlaceholderMaxLines().value()); } @@ -310,7 +280,6 @@ void TextFieldLayoutAlgorithm::CreateParagraph(const TextStyle& textStyle, std:: paraStyle.maxLines_ = textStyle.GetMaxLines(); paraStyle.locale_ = Localization::GetInstance()->GetFontLocale(); paraStyle.wordBreakType_ = ToRSWordBreakType(textStyle.GetWordBreak()); - paraStyle.fontSize_ = textStyle.GetFontSize().ConvertToPx(); if (textStyle.GetTextOverflow() == TextOverflow::ELLIPSIS) { paraStyle.ellipsis_ = RSParagraphStyle::ELLIPSIS; } 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 ecd4f1cde1f5f2775b0f9c22727987b0bce44db9..f04623ebfe6d2fd7954adf4d9543bc7b792de723 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 @@ -85,14 +85,9 @@ public: static TextDirection GetTextDirection(const std::string& content); static void UpdateTextStyle(const RefPtr& layoutProperty, - const RefPtr& theme, TextStyle& textStyle, bool isDisabled); + const RefPtr& theme, TextStyle& textStyle); static void UpdatePlaceholderTextStyle(const RefPtr& layoutProperty, - const RefPtr& theme, TextStyle& textStyle, bool isDisabled); - - float GetPlaceholderParagraphHeight() - { - return placeholderParagraphHeight_; - } + const RefPtr& theme, TextStyle& textStyle); private: void CreateParagraph(const TextStyle& textStyle, std::string content, bool needObscureText); @@ -112,7 +107,6 @@ private: RectF textRect_; RectF imageRect_; OffsetF parentGlobalOffset_; - float placeholderParagraphHeight_ = 0.0f; float caretOffsetX_ = 0.0f; diff --git a/frameworks/core/components_ng/pattern/text_field/text_field_layout_property.h b/frameworks/core/components_ng/pattern/text_field/text_field_layout_property.h index db5cec5d058068433f213a74e35bcac00dce7669..111b97689adc65cb1fe321cafba8d09c2586c5a7 100644 --- a/frameworks/core/components_ng/pattern/text_field/text_field_layout_property.h +++ b/frameworks/core/components_ng/pattern/text_field/text_field_layout_property.h @@ -53,7 +53,6 @@ public: ResetShowPasswordIcon(); ResetCopyOptions(); ResetLastValue(); - ResetWidthAuto(); } ACE_DEFINE_PROPERTY_GROUP(FontStyle, FontStyle); @@ -96,10 +95,8 @@ public: ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(InputFilter, std::string, PROPERTY_UPDATE_MEASURE); ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(ShowPasswordIcon, bool, PROPERTY_UPDATE_MEASURE); - ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(WidthAuto, bool, PROPERTY_UPDATE_MEASURE); ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(TypeChanged, bool, PROPERTY_UPDATE_MEASURE); ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(CopyOptions, CopyOptions, PROPERTY_UPDATE_MEASURE); - ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(PreferredNewLineHeightNeedToUpdate, bool, PROPERTY_UPDATE_MEASURE); ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(PreferredLineHeightNeedToUpdate, bool, PROPERTY_UPDATE_MEASURE); ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(LastValue, std::string, PROPERTY_UPDATE_MEASURE); @@ -122,7 +119,6 @@ protected: value->propShowPasswordIcon_ = CloneShowPasswordIcon(); value->propCopyOptions_ = CloneCopyOptions(); value->propLastValue_ = CloneLastValue(); - value->propWidthAuto_ = CloneWidthAuto(); } private: 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 51261ca01f14f2675bee7c9a7cd699ec2c46dbe2..df9aaf15d33e7c82dc4daaf3e1d9198d9982589c 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 @@ -105,7 +105,6 @@ public: virtual RefPtr CreateTextArea( const std::optional& placeholder, const std::optional& value) = 0; - virtual void SetWidthAuto(bool isAuto) {} virtual void SetType(TextInputType value) = 0; virtual void SetPlaceholderColor(const Color& value) = 0; virtual void SetPlaceholderFont(const Font& 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 e747599eac3fa03a2cb08337a05a74d1f0ececbe..550ddf4159b57be6daa14b002181faf21b65c1fb 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 @@ -116,16 +116,6 @@ RefPtr TextFieldModelNG::CreateTextArea( return pattern->GetTextFieldController(); } -void TextFieldModelNG::SetWidthAuto(bool isAuto) -{ - auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); - CHECK_NULL_VOID(frameNode); - if (frameNode->GetTag() == V2::TEXTAREA_ETS_TAG) { - return; - } - ACE_UPDATE_LAYOUT_PROPERTY(TextFieldLayoutProperty, WidthAuto, isAuto); -} - void TextFieldModelNG::SetType(TextInputType 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 b015d36bec1d9d855fe7601ffdfea3186d1008f7..718812e66458d05164126a0e9a629006f41a0fab 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 @@ -32,7 +32,6 @@ public: RefPtr CreateTextArea( const std::optional& placeholder, const std::optional& value) override; - void SetWidthAuto(bool isAuto) override; void SetType(TextInputType value) override; void SetPlaceholderColor(const Color& value) override; void SetPlaceholderFont(const Font& value) override; diff --git a/frameworks/core/components_ng/pattern/text_field/text_field_paint_method.cpp b/frameworks/core/components_ng/pattern/text_field/text_field_paint_method.cpp index 0863b509ea2dc131863ce56bf30dfda736eec0cb..9e536413ac64e3c2e5b87c3443724f8264120200 100644 --- a/frameworks/core/components_ng/pattern/text_field/text_field_paint_method.cpp +++ b/frameworks/core/components_ng/pattern/text_field/text_field_paint_method.cpp @@ -54,7 +54,6 @@ CanvasDrawFunction TextFieldPaintMethod::GetContentDrawFunction(PaintWrapper* pa passwordIconCanvasImage](RSCanvas& canvas) { CHECK_NULL_VOID_NOLOG(textFieldPattern); auto frameRect = textFieldPattern->GetFrameRect(); - auto iconRect = textFieldPattern->GetImageRect(); RSRect clipInnerRect; if (textFieldPattern->IsTextArea()) { clipInnerRect = RSRect(offset.GetX(), contentOffset.GetY(), contentSize.Width() + contentOffset.GetX(), @@ -74,12 +73,12 @@ CanvasDrawFunction TextFieldPaintMethod::GetContentDrawFunction(PaintWrapper* pa paragraph->Paint(&canvas, textFieldPattern->GetTextRect().GetX(), contentOffset.GetY()); } } - canvas.Restore(); if (!textFieldPattern->NeedShowPasswordIcon()) { return; } CHECK_NULL_VOID_NOLOG(passwordIconCanvasImage); const ImagePainter passwordIconImagePainter(passwordIconCanvasImage); + auto iconRect = textFieldPattern->GetImageRect(); passwordIconImagePainter.DrawImage(canvas, iconRect.GetOffset(), iconRect.GetSize()); }; return drawFunction; @@ -126,8 +125,8 @@ void TextFieldPaintMethod::PaintSelection(RSCanvas& canvas, PaintWrapper* paintW switch (paintProperty->GetInputStyleValue(InputStyle::DEFAULT)) { case InputStyle::DEFAULT: // for default style, selection height is equal to the content height - canvas.DrawRect(RSRect(startOffset, textFieldPattern->GetCaretRect().GetY(), endOffset, - textFieldPattern->GetCaretRect().GetY() + textFieldPattern->GetCaretRect().Height())); + canvas.DrawRect(RSRect(startOffset, paintWrapper->GetContentOffset().GetY(), endOffset, + paintWrapper->GetContentOffset().GetY() + paintWrapper->GetContentSize().Height())); break; case InputStyle::INLINE: // for inline style, selection height is equal to the frame height @@ -160,7 +159,7 @@ void TextFieldPaintMethod::PaintCursor(RSCanvas& canvas, PaintWrapper* paintWrap brush.SetAntiAlias(true); brush.SetColor(cursorColor.GetValue()); canvas.AttachBrush(brush); - float caretHeight = textFieldPattern->GetCaretRect().Height(); + float caretHeight = textFieldPattern->GetTextOrPlaceHolderFontSize(); if (!textFieldPattern->IsTextArea()) { auto top = static_cast( paintWrapper->GetContentOffset().GetY() + (paintWrapper->GetContentSize().Height() - caretHeight) / 2); 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 c6cad548d1d3c75e8c65b9e97bca2494b5980302..9f4260a287a71adb03092d466c5f6f774d5db336 100755 --- a/frameworks/core/components_ng/pattern/text_field/text_field_pattern.cpp +++ b/frameworks/core/components_ng/pattern/text_field/text_field_pattern.cpp @@ -65,7 +65,6 @@ constexpr uint32_t TWINKLING_INTERVAL_MS = 500; constexpr uint32_t OBSCURE_SHOW_TICKS = 3; constexpr char16_t OBSCURING_CHARACTER = u'•'; constexpr char16_t OBSCURING_CHARACTER_FOR_AR = u'*'; -constexpr char16_t NEWLINE_CODE = u'\n'; const std::string DIGIT_WHITE_LIST = "^[0-9]*$"; const std::string PHONE_WHITE_LIST = "[\\d\\-\\+\\*\\#]+"; const std::string EMAIL_WHITE_LIST = "[\\w.]"; @@ -206,12 +205,9 @@ bool TextFieldPattern::OnDirtyLayoutWrapperSwap(const RefPtr& dir textRect_ = textFieldLayoutAlgorithm->GetTextRect(); imageRect_ = textFieldLayoutAlgorithm->GetImageRect(); parentGlobalOffset_ = textFieldLayoutAlgorithm->GetParentGlobalOffset(); - placeholderParagraphHeight_ = textFieldLayoutAlgorithm->GetPlaceholderParagraphHeight(); - auto textRectNotNeedToChange = UpdateCaretPosition(); + auto textRectNeedToChange = UpdateCaretPosition(); UpdateCaretInfoToController(); - if (textRectNotNeedToChange) { - return true; - } + CHECK_NULL_RETURN_NOLOG(!textRectNeedToChange, true); // after new text input or events such as left right key, // the procedure will be: // caret position change (such as move left) @@ -238,13 +234,17 @@ void TextFieldPattern::UpdateCaretInfoToController() const auto pipeline = GetHost()->GetContext(); CHECK_NULL_VOID(pipeline); auto windowRect = pipeline->GetCurrentWindowRect(); - MiscServices::CursorInfo cursorInfo { .left = caretRect_.Left() + windowRect.Left(), + MiscServices::CursorInfo cursorInfo { + .left = caretRect_.Left() + windowRect.Left(), .top = caretRect_.Top() + windowRect.Top(), .width = CURSOR_WIDTH.ConvertToPx(), .height = caretRect_.Height() }; LOGD("UpdateCaretInfoToController, left %{public}f, top %{public}f, width %{public}f, height %{public}f", cursorInfo.left, cursorInfo.top, cursorInfo.width, cursorInfo.height); MiscServices::InputMethodController::GetInstance()->OnCursorUpdate(cursorInfo); + if (selectionMode_ == SelectionMode::NONE) { + return; + } auto value = GetEditingValue(); MiscServices::InputMethodController::GetInstance()->OnSelectionChange( StringUtils::Str8ToStr16(value.text), textSelector_.GetStart(), textSelector_.GetEnd()); @@ -277,7 +277,6 @@ bool TextFieldPattern::UpdateCaretPosition() } } else if (caretUpdateType_ == CaretUpdateType::NONE) { if (GetEditingValue().text.empty()) { - UpdateSelection(0); SetCaretOffsetXForEmptyText(); } else { caretRect_.SetLeft(textRect_.GetX() + textRect_.Width()); @@ -432,7 +431,6 @@ bool TextFieldPattern::UpdateCaretPositionByMouseMovement() void TextFieldPattern::UpdateCaretOffsetByEvent() { if (textEditingValue_.text.empty()) { - UpdateSelection(0, 0); SetCaretOffsetXForEmptyText(); return; } @@ -453,8 +451,6 @@ void TextFieldPattern::UpdateSelectionOffset() { CHECK_NULL_VOID_NOLOG(InSelectMode()); if (textSelector_.baseOffset == textSelector_.destinationOffset) { - textSelector_.selectionBaseOffset.SetX(caretRect_.GetX()); - textSelector_.selectionDestinationOffset.SetX(caretRect_.GetX()); return; } if (selectionMode_ == SelectionMode::SELECT_ALL) { @@ -492,16 +488,14 @@ void TextFieldPattern::UpdateSelectionOffset() if (caretUpdateType_ == CaretUpdateType::HANDLE_MOVE || caretUpdateType_ == CaretUpdateType::HANDLE_MOVE_DONE) { return; } - auto caretMetrics = CalcCursorOffsetByPosition(textSelector_.baseOffset); - textSelector_.selectionBaseOffset.SetX(caretMetrics.offset.GetX()); - caretMetrics = CalcCursorOffsetByPosition(textSelector_.destinationOffset); - textSelector_.selectionDestinationOffset.SetX(caretMetrics.offset.GetX()); + textSelector_.selectionDestinationOffset.SetX(caretRect_.GetX()); + auto offsetToParagraphBeginning = CalcCursorOffsetByPosition(textSelector_.baseOffset); + textSelector_.selectionBaseOffset.SetX(offsetToParagraphBeginning.GetX() + textRect_.GetX()); } void TextFieldPattern::UpdateCaretPositionByTextEdit() { if (textEditingValue_.text.empty()) { - UpdateSelection(0); SetCaretOffsetXForEmptyText(); return; } @@ -511,16 +505,15 @@ void TextFieldPattern::UpdateCaretPositionByTextEdit() return; } UpdateCaretRectByPosition(textEditingValue_.caretPosition); - UpdateSelection(textEditingValue_.caretPosition); } void TextFieldPattern::UpdateCaretRectByPosition(int32_t position) { - auto caretMetrics = CalcCursorOffsetByPosition(position); - caretRect_.SetLeft(caretMetrics.offset.GetX()); + auto offsetToParagraphBeginning = CalcCursorOffsetByPosition(position); + caretRect_.SetLeft(offsetToParagraphBeginning.GetX() + textRect_.GetX()); // add 1.0f here for offsetToParagraphBeginning offsetY is negative when caret position is zero - caretRect_.SetTop(caretMetrics.offset.GetY()); - caretRect_.SetHeight(caretMetrics.height); + caretRect_.SetTop(GetLineNumber(std::max(offsetToParagraphBeginning.GetY(), 0.0f) + 1.0f) * PreferredLineHeight() + + textRect_.GetY()); } int32_t TextFieldPattern::GetLineNumber(float offsetY) @@ -539,9 +532,10 @@ int32_t TextFieldPattern::GetLineNumber(float offsetY) void TextFieldPattern::SetCaretOffsetXForEmptyText() { auto layoutProperty = GetHost()->GetLayoutProperty(); - caretRect_.SetLeft(textRect_.GetX()); caretRect_.SetTop(textRect_.GetY()); - caretRect_.SetHeight(placeholderParagraphHeight_); + if (IsTextArea()) { + caretRect_.SetLeft(textRect_.GetX()); + } switch (layoutProperty->GetTextAlignValue(TextAlign::START)) { case TextAlign::START: caretRect_.SetLeft(textRect_.GetX()); @@ -569,22 +563,19 @@ void TextFieldPattern::UpdateCaretPositionByPressOffset() UpdateSelection(textEditingValue_.caretPosition); } -CaretMetricsF TextFieldPattern::CalcCursorOffsetByPosition(int32_t position) +OffsetF TextFieldPattern::CalcCursorOffsetByPosition(int32_t position) { - // this function will calculate caret offset and height by caret position - CaretMetricsF result; + // this function will calculate proto caret offset x aligned with paragraph_ if (position == 0) { - result.offset = OffsetF(textRect_.GetOffset().GetX(), 0.0f); - result.height = PreferredLineHeight(); - return result; + return OffsetF(0.0f, 0.0f); } - if (!(ComputeOffsetForCaretDownstream(position, result) || ComputeOffsetForCaretUpstream(position, result))) { - LOGW("Get caret offset failed, set it to text start"); - result.offset = OffsetF(textRect_.GetOffset().GetX(), 0.0f); - result.height = PreferredLineHeight(); - return result; + CaretMetrics downStreamMetrics; + if (!ComputeOffsetForCaretDownstream(GetEditingValue(), position, downStreamMetrics)) { + LOGW("Get caret offset failed, set it to text tail"); + return OffsetF(textRect_.Width(), 0.0f); } - return result; + return OffsetF( + static_cast(downStreamMetrics.offset.GetX()), static_cast(downStreamMetrics.offset.GetY())); } float TextFieldPattern::AdjustTextRectOffsetX() @@ -703,16 +694,17 @@ void TextFieldPattern::GetTextRectsInRange( base, destination, RSTypographyProperties::RectHeightStyle::MAX, RSTypographyProperties::RectWidthStyle::TIGHT); } -bool TextFieldPattern::ComputeOffsetForCaretDownstream(int32_t extent, CaretMetricsF& result) +bool TextFieldPattern::ComputeOffsetForCaretDownstream( + const TextEditingValueNG& TextEditingValueNG, int32_t extent, CaretMetrics& result) { CHECK_NULL_RETURN_NOLOG(paragraph_, false); - if (!IsTextArea() && static_cast(extent) >= textEditingValue_.GetWideText().length()) { + if (!IsTextArea() && static_cast(extent) >= TextEditingValueNG.GetWideText().length()) { return false; } result.Reset(); const int32_t graphemeClusterLength = 1; - const int32_t next = extent + graphemeClusterLength; + const int32_t next = extent - graphemeClusterLength; GetTextRectsInRange(next, extent, textBoxes_); if (textBoxes_.empty()) { @@ -722,81 +714,14 @@ bool TextFieldPattern::ComputeOffsetForCaretDownstream(int32_t extent, CaretMetr const auto& textBox = *textBoxes_.begin(); // Caret is within width of the downstream glyphs. - float offsetX = textBox.rect_.GetLeft(); + float caretStart = textBox.rect_.GetRight(); + float offsetX = std::min(caretStart, static_cast(paragraph_->GetLongestLine())); result.offset.SetX(offsetX); result.offset.SetY(textBox.rect_.GetTop()); result.height = textBox.rect_.GetHeight(); return true; } -bool TextFieldPattern::ComputeOffsetForCaretUpstream(int32_t extent, CaretMetricsF& result) const -{ - auto text = textEditingValue_.text; - if (!paragraph_ || text.empty()) { - return false; - } - - char16_t prevChar = 0; - if (static_cast(extent) <= text.length()) { - prevChar = text[std::max(0, extent - 1)]; - } - - result.Reset(); - int32_t graphemeClusterLength = StringUtils::NotInUtf16Bmp(prevChar) ? 2 : 1; - int32_t prev = extent - graphemeClusterLength; - auto boxes = paragraph_->GetRectsForRange( - prev, extent, RSTypographyProperties::RectHeightStyle::MAX, RSTypographyProperties::RectWidthStyle::TIGHT); - while (boxes.empty() && !textEditingValue_.text.empty()) { - graphemeClusterLength *= 2; - prev = extent - graphemeClusterLength; - if (prev < 0) { - boxes = paragraph_->GetRectsForRange( - 0, extent, RSTypographyProperties::RectHeightStyle::MAX, RSTypographyProperties::RectWidthStyle::TIGHT); - break; - } - boxes = paragraph_->GetRectsForRange( - prev, extent, RSTypographyProperties::RectHeightStyle::MAX, RSTypographyProperties::RectWidthStyle::TIGHT); - } - if (boxes.empty()) { - LOGW("Empty box"); - return false; - } - - const auto& textBox = *boxes.begin(); - // Caret is within width of the downstream glyphs. - if (prevChar == NEWLINE_CODE) { - result.offset.SetX(MakeEmptyOffset().GetX()); - result.offset.SetY(textBox.rect_.GetBottom() + GetPaddingTop()); - result.height = textBox.rect_.GetHeight(); - return true; - } - - result.offset.SetX(textBox.rect_.GetRight() + textRect_.GetX()); - result.offset.SetY(textBox.rect_.GetTop() + GetPaddingTop()); - result.height = textBox.rect_.GetHeight(); - return true; -} - -bool TextFieldPattern::LastInputIsNewLine() const -{ - return textEditingValue_.LastChar() == NEWLINE_CODE; -} - -OffsetF TextFieldPattern::MakeEmptyOffset() const -{ - auto layoutProperty = GetHost()->GetLayoutProperty(); - CHECK_NULL_RETURN(layoutProperty, {}); - switch (layoutProperty->GetTextAlignValue(TextAlign::START)) { - case TextAlign::CENTER: - return OffsetF((contentRect_.GetX() + contentRect_.Width()) * 0.5f, 0.0f); - case TextAlign::END: - return OffsetF(contentRect_.GetX() + contentRect_.Width(), 0.0f); - case TextAlign::START: - default: - return OffsetF(contentRect_.GetX(), 0.0f); - } -} - int32_t TextFieldPattern::ConvertTouchOffsetToCaretPosition(const Offset& localOffset) { CHECK_NULL_RETURN(paragraph_, 0); @@ -893,6 +818,7 @@ void TextFieldPattern::HandleSelect(int32_t keyCode, int32_t cursorMoveSkip) } } + void TextFieldPattern::InitFocusEvent() { CHECK_NULL_VOID_NOLOG(!focusEventInitialized_); @@ -930,7 +856,7 @@ void TextFieldPattern::HandleBlurEvent() StopTwinkling(); CloseKeyboard(true); auto pos = static_cast(textEditingValue_.GetWideText().length()); - UpdateSelection(pos); + UpdateSelection(pos, pos); selectionMode_ = SelectionMode::NONE; auto eventHub = host->GetEventHub(); eventHub->FireOnEditChanged(false); @@ -1008,7 +934,6 @@ bool TextFieldPattern::HandleKeyEvent(const KeyEvent& keyEvent) void TextFieldPattern::HandleOnUndoAction() { - LOGI("TextFieldPattern::HandleOnUndoAction"); if (operationRecords_.empty()) { LOGW("Operation records empty, cannot undo"); return; @@ -1017,7 +942,7 @@ void TextFieldPattern::HandleOnUndoAction() operationRecords_.pop_back(); redoOperationRecords_.push_back(value); if (operationRecords_.empty()) { - LOGW("No record left, clear"); + LOGD("No record left, clear"); ClearEditingValue(); return; } @@ -1032,7 +957,6 @@ void TextFieldPattern::HandleOnUndoAction() void TextFieldPattern::HandleOnRedoAction() { - LOGI("TextFieldPattern::HandleOnRedoAction"); if (redoOperationRecords_.empty()) { LOGW("Redo operation records empty, cannot undo"); return; @@ -1050,7 +974,6 @@ void TextFieldPattern::HandleOnRedoAction() void TextFieldPattern::HandleOnSelectAll() { - LOGI("TextFieldPattern::HandleOnSelectAll"); auto textSize = GetEditingValue().GetWideText().length(); UpdateSelection(0, static_cast(textSize)); textEditingValue_.caretPosition = static_cast(textEditingValue_.text.length()); @@ -1061,7 +984,6 @@ void TextFieldPattern::HandleOnSelectAll() void TextFieldPattern::HandleOnCopy() { - LOGI("TextFieldPattern::HandleOnCopy"); CHECK_NULL_VOID(clipboard_); auto layoutProperty = GetHost()->GetLayoutProperty(); CHECK_NULL_VOID(layoutProperty); @@ -1104,7 +1026,6 @@ void TextFieldPattern::HandleOnCopy() void TextFieldPattern::HandleOnPaste() { - LOGI("TextFieldPattern::HandleOnPaste"); CHECK_NULL_VOID(clipboard_); auto pasteCallback = [weak = WeakClaim(this), textSelector = textSelector_](const std::string& data) { if (data.empty()) { @@ -1167,7 +1088,6 @@ void TextFieldPattern::HandleOnPaste() void TextFieldPattern::HandleOnCut() { - LOGI("TextFieldPattern::HandleOnCut"); CHECK_NULL_VOID(clipboard_); auto layoutProperty = GetHost()->GetLayoutProperty(); CHECK_NULL_VOID(layoutProperty); @@ -1201,7 +1121,7 @@ void TextFieldPattern::HandleOnCut() if (parentFrameNode && parentFrameNode->GetTag() == V2::SEARCH_ETS_TAG) { auto eventHub = parentFrameNode->GetEventHub(); CHECK_NULL_VOID(eventHub); - eventHub->FireOnCut(selectedText); + eventHub->FireOnCut(textEditingValue_.text); FireEventHubOnChange(textEditingValue_.text); host->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF); return; @@ -1209,7 +1129,7 @@ void TextFieldPattern::HandleOnCut() auto eventHub = host->GetEventHub(); CHECK_NULL_VOID(eventHub); - eventHub->FireOnCut(selectedText); + eventHub->FireOnCut(textEditingValue_.text); FireEventHubOnChange(textEditingValue_.text); host->MarkDirtyNode(layoutProperty->GetMaxLinesValue(Infinity()) <= 1 ? PROPERTY_UPDATE_MEASURE_SELF : PROPERTY_UPDATE_MEASURE); @@ -1270,7 +1190,7 @@ void TextFieldPattern::HandleTouchDown(const Offset& offset) void TextFieldPattern::HandleTouchUp() { if (isMousePressed_) { - LOGI("TextFieldPattern::HandleTouchUp of mouse"); + LOGD("TextFieldPattern::HandleTouchUp of mouse"); isMousePressed_ = false; } if (enableTouchAndHoverEffect_) { @@ -1315,7 +1235,6 @@ void TextFieldPattern::InitClickEvent() void TextFieldPattern::HandleClickEvent(GestureEvent& info) { - LOGI("TextFieldPattern::HandleClickEvent"); UpdateTextFieldManager(info.GetGlobalLocation(), frameRect_.Height()); auto focusHub = GetHost()->GetOrCreateFocusHub(); if (!focusHub->IsFocusable()) { @@ -1338,10 +1257,11 @@ void TextFieldPattern::HandleClickEvent(GestureEvent& info) GetHost()->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF); if (isMousePressed_) { - LOGI("TextFieldPattern::HandleTouchUp of mouse"); + LOGD("TextFieldPattern::HandleTouchUp of mouse"); isMousePressed_ = false; return; } + LOGD("TextFieldPattern::HandleTouchUp"); if (!focusHub->RequestFocusImmediately()) { LOGE("Request focus failed, cannot open input method"); StopTwinkling(); @@ -1439,7 +1359,6 @@ void TextFieldPattern::OnModifyDone() if (textEditingValue_.caretPosition == 0) { caretRect_.SetLeft(GetPaddingLeft()); caretRect_.SetTop(GetPaddingTop()); - caretRect_.SetHeight(PreferredLineHeight()); } auto paintProperty = GetPaintProperty(); auto renderContext = GetHost()->GetRenderContext(); @@ -1454,21 +1373,14 @@ void TextFieldPattern::OnModifyDone() redoOperationRecords_.clear(); } auto maxLength = GetMaxLength(); - if (static_cast(textEditingValue_.GetWideText().length()) > maxLength) { - textEditingValue_.text = StringUtils::ToString(textEditingValue_.GetWideText().substr(0, maxLength)); + if (GreatOrEqual(textEditingValue_.text.length(), maxLength)) { + textEditingValue_.text = textEditingValue_.text.substr(0, maxLength); SetEditingValueToProperty(textEditingValue_.text); } host->MarkDirtyNode(layoutProperty->GetMaxLinesValue(Infinity()) <= 1 ? PROPERTY_UPDATE_MEASURE_SELF : PROPERTY_UPDATE_MEASURE); } -bool TextFieldPattern::IsDisabled() -{ - auto eventHub = GetHost()->GetEventHub(); - CHECK_NULL_RETURN(eventHub, true); - return !eventHub->IsEnabled(); -} - void TextFieldPattern::ProcessPadding() { auto pipeline = GetHost()->GetContext(); @@ -1533,18 +1445,16 @@ void TextFieldPattern::ProcessOverlay() selectionMode_ = SelectionMode::SELECT; if (caretUpdateType_ == CaretUpdateType::LONG_PRESSED) { if (textEditingValue_.caretPosition == 0) { - UpdateSelection(0, 0); - } else if (textEditingValue_.CaretAtLast()) { - UpdateSelection(textEditingValue_.caretPosition, textEditingValue_.caretPosition); + UpdateSelection(0, 1); } else { UpdateSelection(textEditingValue_.caretPosition - 1, textEditingValue_.caretPosition); } } - OffsetF firstHandleOffset(CalcCursorOffsetByPosition(textSelector_.GetStart()).offset.GetX() + textRect_.GetX() - - contentRect_.GetX() + parentGlobalOffset_.GetX(), + OffsetF firstHandleOffset( + CalcCursorOffsetByPosition(textSelector_.GetStart()).GetX() + textRect_.GetX() + parentGlobalOffset_.GetX(), contentRect_.GetY() + parentGlobalOffset_.GetY()); - OffsetF secondHandleOffset(CalcCursorOffsetByPosition(textSelector_.GetEnd()).offset.GetX() + textRect_.GetX() - - contentRect_.GetX() + parentGlobalOffset_.GetX(), + OffsetF secondHandleOffset( + CalcCursorOffsetByPosition(textSelector_.GetEnd()).GetX() + textRect_.GetX() + parentGlobalOffset_.GetX(), contentRect_.GetY() + parentGlobalOffset_.GetY()); SizeF handlePaintSize = { SelectHandleInfo::GetDefaultLineWidth().ConvertToPx(), GetTextOrPlaceHolderFontSize() }; RectF firstHandle; @@ -1680,11 +1590,11 @@ void TextFieldPattern::OnHandleMove(const RectF& handleRect, bool isFirstHandle) position = ConvertTouchOffsetToCaretPosition(offset); } textEditingValue_.CursorMoveToPosition(position); - auto caretMetrics = CalcCursorOffsetByPosition(position); - caretRect_.SetOffset(OffsetF(caretMetrics.offset.GetX(), caretMetrics.offset.GetY())); + OffsetF offsetToParagraphBeginning = CalcCursorOffsetByPosition(position); + caretRect_.SetOffset(offsetToParagraphBeginning + OffsetF(textRect_.GetOffset().GetX(), 0.0f)); selectionMode_ = isSingleHandle_ ? SelectionMode::NONE : SelectionMode::SELECT; caretUpdateType_ = CaretUpdateType::HANDLE_MOVE; - UpdateTextSelectorByHandleMove(isFirstHandle, position, caretMetrics.offset); + UpdateTextSelectorByHandleMove(isFirstHandle, position, offsetToParagraphBeginning); GetHost()->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF); } @@ -1774,34 +1684,16 @@ void TextFieldPattern::InitMouseEvent() inputHub->AddOnHoverEvent(hoverEvent_); } -void TextFieldPattern::SetMouseStyle(MouseFormat format) -{ - auto pipeline = PipelineContext::GetCurrentContext(); - CHECK_NULL_VOID(pipeline); - auto windowId = pipeline->GetWindowId(); - auto mouseStyle = MouseStyle::CreateMouseStyle(); - mouseStyle->SetPointerStyle(windowId, format); - int32_t currentPointerStyle = 0; - mouseStyle->GetPointerStyle(windowId, currentPointerStyle); - if (currentPointerStyle != static_cast(format)) { - mouseStyle->SetPointerStyle(windowId, format); - } -} - void TextFieldPattern::OnHover(bool isHover) { - LOGD("Textfield %{public}d %{public}s", GetHost()->GetId(), isHover ? "on hover" : "exit hover"); if (enableTouchAndHoverEffect_) { auto textfieldPaintProperty = GetPaintProperty(); CHECK_NULL_VOID(textfieldPaintProperty); auto renderContext = GetHost()->GetRenderContext(); if (isHover) { - SetMouseStyle(HasFocus() ? MouseFormat::TEXT_CURSOR : MouseFormat::HAND_POINTING); renderContext->UpdateBackgroundColor(textfieldPaintProperty->GetHoverBgColorValue(Color())); GetHost()->MarkDirtyNode(PROPERTY_UPDATE_RENDER); return; - } else { - SetMouseStyle(MouseFormat::DEFAULT); } renderContext->UpdateBackgroundColor(textfieldPaintProperty->GetBackgroundColorValue(Color())); GetHost()->MarkDirtyNode(PROPERTY_UPDATE_RENDER); @@ -1813,7 +1705,6 @@ void TextFieldPattern::HandleMouseEvent(const MouseInfo& info) auto focusHub = GetHost()->GetOrCreateFocusHub(); CloseSelectOverlay(); if (info.GetAction() == MouseAction::PRESS) { - LOGI("Handle mouse press"); if (!focusHub->IsFocusable()) { return; } @@ -1825,18 +1716,14 @@ void TextFieldPattern::HandleMouseEvent(const MouseInfo& info) if (!focusHub->RequestFocusImmediately()) { LOGE("Request focus failed, cannot open input method"); StopTwinkling(); - SetMouseStyle(MouseFormat::HAND_GRABBING); return; } - SetMouseStyle(MouseFormat::TEXT_CURSOR); GetHost()->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF); return; } if (info.GetAction() == MouseAction::RELEASE) { - LOGI("Handle mouse release"); - caretUpdateType_ = CaretUpdateType::NONE; + caretUpdateType_ = CaretUpdateType::PRESSED; isMousePressed_ = false; - SetMouseStyle(HasFocus() ? MouseFormat::TEXT_CURSOR : MouseFormat::HAND_POINTING); if (!focusHub->IsCurrentFocus()) { return; } @@ -1876,11 +1763,6 @@ void TextFieldPattern::UpdateTextFieldManager(const Offset& offset, float height bool TextFieldPattern::RequestKeyboard(bool isFocusViewChanged, bool needStartTwinkling, bool needShowSoftKeyboard) { -#if defined(OHOS_STANDARD_SYSTEM) && !defined(PREVIEW) - if (imeAttached_) { - return false; - } -#endif auto host = GetHost(); auto context = host->GetContext(); CHECK_NULL_RETURN(context, false); @@ -1914,9 +1796,10 @@ bool TextFieldPattern::RequestKeyboard(bool isFocusViewChanged, bool needStartTw bool TextFieldPattern::CloseKeyboard(bool forceClose) { - LOGI("Request close soft keyboard"); + LOGI("Close keyboard"); if (forceClose) { StopTwinkling(); + LOGI("Request close soft keyboard"); #if defined(ENABLE_STANDARD_INPUT) #if defined(OHOS_STANDARD_SYSTEM) && !defined(PREVIEW) if (!imeAttached_) { @@ -1979,6 +1862,7 @@ ImageSourceInfo TextFieldPattern::GetImageSourceInfoFromTheme(bool checkHidePass ImageSourceInfo imageSourceInfo; auto theme = context->GetTheme(); CHECK_NULL_RETURN(theme, imageSourceInfo); + ImageSourceInfo srcInfo; if (checkHidePasswordIcon) { imageSourceInfo.SetResourceId(InternalResource::ResourceId::HIDE_PASSWORD_SVG); return imageSourceInfo; @@ -1999,13 +1883,7 @@ void TextFieldPattern::UpdateInternalResource(ImageSourceInfo& sourceInfo) LOGE("Icon path empty"); return; } - auto theme = pipeline->GetTheme(); - CHECK_NULL_VOID(theme); - if (IsDisabled()) { - sourceInfo.SetSrc(iconPath, theme->GetDisabledIconFillColor()); - } else { - sourceInfo.SetSrc(iconPath); - } + sourceInfo.SetSrc(iconPath); sourceInfo.SetDimension(DEFAULT_FONT, DEFAULT_FONT); auto layoutProperty = GetLayoutProperty(); CHECK_NULL_VOID(layoutProperty); @@ -2086,9 +1964,7 @@ void TextFieldPattern::OnTextInputActionUpdate(TextInputAction value) {} void TextFieldPattern::InsertValue(const std::string& insertValue) { - auto newVal = StringUtils::ToWstring(textEditingValue_.GetValueBeforePosition(textSelector_.GetStart()) + - insertValue + textEditingValue_.GetValueAfterPosition(textSelector_.GetEnd())); - if (static_cast(newVal.length()) >= GetMaxLength()) { + if (static_cast(textEditingValue_.text.length()) >= GetMaxLength()) { LOGW("Max length reached"); return; } @@ -2160,7 +2036,7 @@ bool TextFieldPattern::FilterWithRegex( if (!errorText.empty()) { auto textFieldEventHub = GetHost()->GetEventHub(); CHECK_NULL_RETURN(textFieldEventHub, false); - LOGI("Error text %{private}s", errorText.c_str()); + LOGD("Error text %{public}s", errorText.c_str()); textFieldEventHub->FireOnInputFilterError(errorText); } return !errorText.empty(); @@ -2230,13 +2106,12 @@ float TextFieldPattern::PreferredLineHeight() std::string textContent; // use text or placeHolder value if exists, space otherwise if (!layoutProperty->GetValueValue("").empty() || layoutProperty->GetPlaceholderValue("").empty()) { - TextFieldLayoutAlgorithm::UpdateTextStyle( - layoutProperty, textFieldTheme, lineHeightMeasureUtilTextStyle_, false); - textContent = layoutProperty->GetValueValue("a"); + TextFieldLayoutAlgorithm::UpdateTextStyle(layoutProperty, textFieldTheme, lineHeightMeasureUtilTextStyle_); + textContent = layoutProperty->GetValueValue(" "); } else { TextFieldLayoutAlgorithm::UpdatePlaceholderTextStyle( - layoutProperty, textFieldTheme, lineHeightMeasureUtilTextStyle_, false); - textContent = layoutProperty->GetPlaceholderValue("a"); + layoutProperty, textFieldTheme, lineHeightMeasureUtilTextStyle_); + textContent = layoutProperty->GetPlaceholderValue(" "); } RSParagraphStyle paraStyle; paraStyle.textDirection_ = ToRSTextDirection(TextFieldLayoutAlgorithm::GetTextDirection(textEditingValue_.text)); @@ -2315,7 +2190,7 @@ void TextFieldPattern::CursorMoveDown() void TextFieldPattern::Delete(int32_t start, int32_t end) { - LOGI("Handle Delete within [%{public}d, %{public}d]", start, end); + LOGD("Handle Delete within [%{public}d, %{public}d]", start, end); textEditingValue_.text = textEditingValue_.GetValueBeforePosition(start) + textEditingValue_.GetValueAfterPosition(end); textEditingValue_.caretPosition = start; @@ -2353,7 +2228,7 @@ void TextFieldPattern::ClearEditingValue() void TextFieldPattern::PerformAction(TextInputAction action, bool forceCloseKeyboard) { - LOGI("PerformAction %{public}d", static_cast(action)); + LOGD("PerformAction %{public}d", static_cast(action)); auto host = GetHost(); CHECK_NULL_VOID(host); // If the parent node is a Search, the Search callback is executed. @@ -2389,9 +2264,9 @@ void TextFieldPattern::OnAreaChangedInner() if (parentGlobalOffset != parentGlobalOffset_) { parentGlobalOffset_ = parentGlobalOffset; textSelector_.selectionBaseOffset.SetX( - CalcCursorOffsetByPosition(textSelector_.GetStart()).offset.GetX() + textRect_.GetX()); + CalcCursorOffsetByPosition(textSelector_.GetStart()).GetX() + textRect_.GetX()); textSelector_.selectionDestinationOffset.SetX( - CalcCursorOffsetByPosition(textSelector_.GetEnd()).offset.GetX() + textRect_.GetX()); + CalcCursorOffsetByPosition(textSelector_.GetEnd()).GetX() + textRect_.GetX()); UpdateSelection(textSelector_.GetStart(), textSelector_.GetEnd()); if (isSingleHandle_) { CloseSelectOverlay(); @@ -2405,7 +2280,6 @@ void TextFieldPattern::OnAreaChangedInner() void TextFieldPattern::OnVisibleChange(bool isVisible) { - LOGI("visible change to %{public}d", isVisible); if (!isVisible) { LOGI("TextField is not visible"); caretUpdateType_ = CaretUpdateType::INPUT; @@ -2418,7 +2292,7 @@ void TextFieldPattern::OnVisibleChange(bool isVisible) void TextFieldPattern::HandleSurfaceChanged( int32_t newWidth, int32_t newHeight, int32_t prevWidth, int32_t prevHeight) const { - LOGI("Textfield handle surface change, new width %{public}d, new height %{public}d, prev width %{public}d, prev " + LOGD("Textfield handle surface change, new width %{public}d, new height %{public}d, prev width %{public}d, prev " "height %{public}d", newWidth, newHeight, prevWidth, prevHeight); UpdateCaretInfoToController(); @@ -2426,13 +2300,13 @@ void TextFieldPattern::HandleSurfaceChanged( void TextFieldPattern::HandleSurfacePositionChanged(int32_t posX, int32_t posY) const { - LOGI("Textfield handle surface position change, posX %{public}d, posY %{public}d", posX, posY); + LOGD("Textfield handle surface position change, posX %{public}d, posY %{public}d", posX, posY); UpdateCaretInfoToController(); } void TextFieldPattern::DeleteForward(int32_t length) { - LOGI("Handle DeleteForward %{public}d characters", length); + LOGD("Handle DeleteForward %{public}d characters", length); if (textEditingValue_.caretPosition <= 0) { LOGW("Caret position at the beginning , cannot DeleteForward"); return; @@ -2461,7 +2335,7 @@ void TextFieldPattern::DeleteForward(int32_t length) void TextFieldPattern::DeleteBackward(int32_t length) { - LOGI("Handle DeleteBackward %{public}d characters", length); + LOGD("Handle DeleteBackward %{public}d characters", length); if (textEditingValue_.caretPosition >= static_cast(textEditingValue_.text.length())) { LOGW("Caret position at the end , cannot DeleteBackward"); return; @@ -2486,7 +2360,7 @@ void TextFieldPattern::DeleteBackward(int32_t length) void TextFieldPattern::HandleSelectionUp() { - LOGI("Handle selection up"); + LOGD("Handle selection up"); if (!IsTextArea()) { LOGW("Unsupported operation for text field"); return; @@ -2505,7 +2379,7 @@ void TextFieldPattern::HandleSelectionUp() void TextFieldPattern::HandleSelectionDown() { - LOGI("Handle selection down"); + LOGD("Handle selection down"); if (!IsTextArea()) { LOGW("Unsupported operation for text field"); return; @@ -2523,10 +2397,9 @@ void TextFieldPattern::HandleSelectionDown() void TextFieldPattern::HandleSelectionLeft() { - LOGI("Handle selection left"); if (!InSelectMode()) { if (textEditingValue_.caretPosition == 0) { - LOGW("Caret position at beginning, cannot update selection to left"); + LOGD("Caret position at beginning, cannot update selection to left"); return; } textSelector_.baseOffset = textEditingValue_.caretPosition; @@ -2544,11 +2417,10 @@ void TextFieldPattern::HandleSelectionLeft() void TextFieldPattern::HandleSelectionRight() { - LOGI("Handle selection right"); // if currently not in select mode, reset baseOffset and move destinationOffset and caret position if (!InSelectMode()) { if (textEditingValue_.caretPosition == static_cast(textEditingValue_.text.length())) { - LOGW("Caret position at the end, cannot update selection to right"); + LOGD("Caret position at the end, cannot update selection to right"); return; } textSelector_.baseOffset = textEditingValue_.caretPosition; @@ -2569,7 +2441,6 @@ void TextFieldPattern::HandleSelectionRight() void TextFieldPattern::SetCaretPosition(int32_t position) { - LOGI("Set caret position to %{public}d", position); textEditingValue_.caretPosition = std::clamp(position, 0, static_cast(textEditingValue_.text.length())); selectionMode_ = SelectionMode::NONE; caretUpdateType_ = CaretUpdateType::EVENT; diff --git a/frameworks/core/components_ng/pattern/text_field/text_field_pattern.h b/frameworks/core/components_ng/pattern/text_field/text_field_pattern.h index 979569a88957ebe9ed7c04953e9ff26dd8fd479c..179672c357b2bb0a8cdf4002bd5ad180b082d309 100644 --- a/frameworks/core/components_ng/pattern/text_field/text_field_pattern.h +++ b/frameworks/core/components_ng/pattern/text_field/text_field_pattern.h @@ -22,7 +22,6 @@ #include "base/geometry/ng/offset_t.h" #include "base/geometry/ng/rect_t.h" -#include "base/mousestyle/mouse_style.h" #include "core/common/clipboard/clipboard.h" #include "core/common/ime/text_edit_controller.h" #include "core/common/ime/text_input_action.h" @@ -75,26 +74,6 @@ enum { ACTION_AUTOFILL, }; -struct CaretMetricsF { - void Reset() - { - offset.Reset(); - height = 0.0; - } - - OffsetF offset; - // When caret is close to different glyphs, the height will be different. - float height = 0.0; - std::string ToString() const - { - std::string result = "Offset: "; - result += offset.ToString(); - result += ", height: "; - result += std::to_string(height); - return result; - } -}; - class TextFieldPattern : public Pattern, public ValueChangeObserver { DECLARE_ACE_TYPE(TextFieldPattern, Pattern, ValueChangeObserver); @@ -137,13 +116,10 @@ public: void UpdateCaretPositionByPressOffset(); void UpdateSelectionOffset(); - CaretMetricsF CalcCursorOffsetByPosition(int32_t position); - - bool ComputeOffsetForCaretDownstream(int32_t extent, CaretMetricsF& result); + OffsetF CalcCursorOffsetByPosition(int32_t position); - bool ComputeOffsetForCaretUpstream(int32_t extent, CaretMetricsF& result) const; - - OffsetF MakeEmptyOffset() const; + bool ComputeOffsetForCaretDownstream( + const TextEditingValueNG& TextEditingValueNG, int32_t extent, CaretMetrics& result); int32_t ConvertTouchOffsetToCaretPosition(const Offset& localOffset); @@ -460,9 +436,6 @@ public: } void OnCursorMoveDone(); - bool IsDisabled(); - - bool LastInputIsNewLine() const; private: void HandleBlurEvent(); @@ -494,7 +467,6 @@ private: void CursorMoveOnClick(const Offset& offset); void UpdateCaretInfoToController() const; - void SetMouseStyle(MouseFormat format); void ProcessOverlay(); void OnHandleMove(const RectF& handleRect, bool isFirstHandle); void OnHandleMoveDone(const RectF& handleRect, bool isFirstHandle); @@ -562,7 +534,6 @@ private: bool CursorInContentRegion(); bool OffsetInContentRegion(const Offset& offset); void ProcessPadding(); - void SetDisabledStyle(); void ProcessPasswordIcon(); void UpdateInternalResource(ImageSourceInfo& sourceInfo); @@ -581,8 +552,6 @@ private: std::shared_ptr paragraph_; TextStyle lineHeightMeasureUtilTextStyle_; std::shared_ptr lineHeightMeasureUtilParagraph_; - TextStyle nextLineUtilTextStyle_; - std::shared_ptr nextLineUtilParagraph_; RefPtr showPasswordImageLoadingCtx_; RefPtr hidePasswordImageLoadingCtx_; @@ -627,7 +596,6 @@ private: CaretUpdateType caretUpdateType_ = CaretUpdateType::NONE; uint32_t twinklingInterval_ = 0; int32_t obscureTickCountDown_ = 0; - float placeholderParagraphHeight_ = 0.0f; CancelableCallback cursorTwinklingTask_; diff --git a/frameworks/core/components_ng/property/measure_property.h b/frameworks/core/components_ng/property/measure_property.h index b330eb2a7407b1ef88f4fa6335716456d0977d87..b163382f150311b5954fc00c983dadbbd3b080aa 100644 --- a/frameworks/core/components_ng/property/measure_property.h +++ b/frameworks/core/components_ng/property/measure_property.h @@ -107,18 +107,6 @@ public: return true; } - bool ClearSize(bool isWidth) - { - if (isWidth && width_.has_value()) { - width_.reset(); - return true; - } else if (!isWidth && height_.has_value()) { - height_.reset(); - return true; - } - return false; - } - std::string ToString() const { static const int32_t precision = 2; @@ -167,14 +155,6 @@ struct MeasureProperty { return true; } - bool ClearSelfIdealSize(bool isWidth) - { - if (selfIdealSize.has_value()) { - return selfIdealSize->ClearSize(isWidth); - } - return false; - } - bool UpdateMaxSizeWithCheck(const CalcSize& size) { if (maxSize == size) {