From f731f36d6ec3d1b94b3dcad1b95cbc82a4057647 Mon Sep 17 00:00:00 2001 From: jyj-0306 Date: Wed, 22 Nov 2023 23:12:44 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=BF=AB=E9=80=9F=E7=82=B9?= =?UTF-8?q?=E5=87=BB=E5=87=BA=E7=8E=B0=E5=A4=9A=E4=B8=AA=E5=85=89=E6=A0=87?= =?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: jyj-0306 Change-Id: I370ece535a5fbe8624cddf2ed2325523cb07a257 --- .../text_area/text_area_layout_algorithm.cpp | 2 +- .../text_field/text_field_layout_algorithm.cpp | 4 ++-- .../pattern/text_field/text_field_pattern.cpp | 18 ++++++++---------- .../pattern/text_field/text_field_pattern.h | 9 ++------- 4 files changed, 13 insertions(+), 20 deletions(-) diff --git a/frameworks/core/components_ng/pattern/text_area/text_area_layout_algorithm.cpp b/frameworks/core/components_ng/pattern/text_area/text_area_layout_algorithm.cpp index 9c610dd0de1..ff31f2a0be5 100644 --- a/frameworks/core/components_ng/pattern/text_area/text_area_layout_algorithm.cpp +++ b/frameworks/core/components_ng/pattern/text_area/text_area_layout_algorithm.cpp @@ -116,7 +116,7 @@ void TextAreaLayoutAlgorithm::Measure(LayoutWrapper* layoutWrapper) contentHeight += counterSize.Height(); } - if (pattern->IsNormalInlineState() && pattern->IsFocus()) { + if (pattern->IsNormalInlineState() && pattern->HasFocus()) { frameSize.SetWidth(contentWidth + pattern->GetHorizontalPaddingAndBorderSum() + PARAGRAPH_SAVE_BOUNDARY); frameSize.SetHeight(contentHeight + pattern->GetVerticalPaddingAndBorderSum() + PARAGRAPH_SAVE_BOUNDARY); } else { 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 628c7fe7004..2b9e2766f42 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 @@ -91,7 +91,7 @@ std::optional TextFieldLayoutAlgorithm::InlineMeasureContent( CHECK_NULL_RETURN(pattern, std::nullopt); float contentWidth = 0.0f; - if (pattern->IsFocus()) { + if (pattern->HasFocus()) { auto safeBoundary = textFieldTheme->GetInlineBorderWidth().ConvertToPx() * 2; paragraph_->Layout( contentConstraint.maxSize.Width() - static_cast(safeBoundary) - PARAGRAPH_SAVE_BOUNDARY); @@ -107,7 +107,7 @@ std::optional TextFieldLayoutAlgorithm::InlineMeasureContent( textRect_.SetSize(SizeF(GetVisualTextWidth(), paragraph_->GetHeight())); auto inlineIdealHieght = contentConstraint.maxSize.Height(); - if (pattern->IsFocus() && paragraph_->GetLineCount() != 0) { + if (pattern->HasFocus() && paragraph_->GetLineCount() != 0) { pattern->SetSingleLineHeight(paragraph_->GetHeight() / paragraph_->GetLineCount()); // The maximum height of the inline mode defaults to a maximum of three rows. inlineIdealHieght = 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 ea517b7cd0b..0d50a74bf59 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 @@ -1452,6 +1452,13 @@ void TextFieldPattern::HandleClickEvent(GestureEvent& info) if (!focusHub->IsFocusable()) { return; } + if (!HasFocus()) { + if (!focusHub->IsFocusOnTouch().value_or(true) || !focusHub->RequestFocusImmediately()) { + CloseSelectOverlay(true); + StopTwinkling(); + return; + } + } TimeStamp clickTimeStamp = info.GetTimeStamp(); std::chrono::duration> timeout = clickTimeStamp - lastClickTimeStamp_; lastClickTimeStamp_ = info.GetTimeStamp(); @@ -1477,15 +1484,6 @@ void TextFieldPattern::HandleSingleClickEvent(GestureEvent& info) auto host = GetHost(); CHECK_NULL_VOID(host); auto layoutProperty = GetLayoutProperty(); - auto hasFocus = HasFocus(); - auto focusHub = GetFocusHub(); - if (!hasFocus) { - if (!focusHub->IsFocusOnTouch().value_or(true) || !focusHub->RequestFocusImmediately()) { - CloseSelectOverlay(true); - StopTwinkling(); - return; - } - } auto lastCaretIndex = selectController_->GetCaretIndex(); selectController_->UpdateCaretInfoByOffset(info.GetLocalLocation()); StartTwinkling(); @@ -1508,7 +1506,7 @@ void TextFieldPattern::HandleSingleClickEvent(GestureEvent& info) // emulate clicking bottom of the textField UpdateTextFieldManager(Offset(parentGlobalOffset_.GetX(), parentGlobalOffset_.GetY()), frameRect_.Height()); auto isSelectAll = layoutProperty->GetSelectAllValueValue(false); - if (isSelectAll && !contentController_->IsEmpty() && !hasFocus) { + if (isSelectAll && !contentController_->IsEmpty() && !HasFocus()) { HandleOnSelectAll(true); } host->MarkDirtyNode(PROPERTY_UPDATE_RENDER); 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 b8aaf1f7c58..e4b2819a95a 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 @@ -872,11 +872,6 @@ public: return isCustomFont_; } - bool IsFocus() - { - return HasFocus(); - } - void SetISCounterIdealHeight(bool IsIdealHeight) { isCounterIdealheight_ = IsIdealHeight; @@ -984,6 +979,8 @@ public: } void ShowMenu(); + bool HasFocus() const; + void StopTwinkling(); #ifdef ENABLE_DRAG_FRAMEWORK protected: @@ -992,7 +989,6 @@ protected: private: void GetTextSelectRectsInRangeAndWillChange(); - bool HasFocus() const; void HandleTouchEvent(const TouchEventInfo& info); void HandleTouchDown(const Offset& offset); void HandleTouchUp(); @@ -1067,7 +1063,6 @@ private: void ScheduleCursorTwinkling(); void OnCursorTwinkling(); void StartTwinkling(); - void StopTwinkling(); void CheckIfNeedToResetKeyboard(); float PreferredTextHeight(bool isPlaceholder, bool isAlgorithmMeasure = false); -- Gitee