diff --git a/frameworks/core/common/manager_interface.h b/frameworks/core/common/manager_interface.h index 2cc0b7dc587503d98d06d2ce753663d31d10fbda..f062bd0e7056401d46a0c6471e5abe5faa89dbaf 100644 --- a/frameworks/core/common/manager_interface.h +++ b/frameworks/core/common/manager_interface.h @@ -36,8 +36,9 @@ public: virtual void MovePage(int32_t pageId, const Offset& rootRect, double offsetHeight) {} virtual void SetScrollElement(int32_t pageId, const WeakPtr& scrollElement) {} virtual void RemovePageId(int32_t pageId) {} - virtual bool GetImeShow() const { return false; } + virtual bool GetImeShow() const { return false; } // exclude uiExtension virtual void SetUIExtensionImeShow(bool imeShow) {} + virtual bool HasKeyboard() const { return false; } // include uiExtension }; } // namespace OHOS::Ace diff --git a/frameworks/core/components_ng/pattern/text/text_pattern.cpp b/frameworks/core/components_ng/pattern/text/text_pattern.cpp index 11384b3ad40e60e93b6c14f3654f106dbd40a074..65f9770d1e078de72f7722b174838e394fb38d0f 100644 --- a/frameworks/core/components_ng/pattern/text/text_pattern.cpp +++ b/frameworks/core/components_ng/pattern/text/text_pattern.cpp @@ -1877,7 +1877,7 @@ void TextPattern::OnModifyDone() auto obscuredReasons = renderContext->GetObscured().value_or(std::vector()); bool ifHaveObscured = std::any_of(obscuredReasons.begin(), obscuredReasons.end(), [](const auto& reason) { return reason == ObscuredReasons::PLACEHOLDER; }); - if (ifHaveObscured) { + if (ifHaveObscured && !isSpanStringMode_) { CloseSelectOverlay(); ResetSelection(); copyOption_ = CopyOptions::None; diff --git a/frameworks/core/components_ng/pattern/text_field/text_field_manager.h b/frameworks/core/components_ng/pattern/text_field/text_field_manager.h index eda65f0555020c390cbbe9e726aca879c000103b..0014897bd9972c3d9c692f175ec59c1dbe89c68f 100644 --- a/frameworks/core/components_ng/pattern/text_field/text_field_manager.h +++ b/frameworks/core/components_ng/pattern/text_field/text_field_manager.h @@ -93,11 +93,12 @@ public: void UpdatePrevHasTextFieldPattern() { - if (onFocusTextField_.Upgrade()) { - prevHasTextFieldPattern_ = true; - } else { - prevHasTextFieldPattern_ = false; - } + prevHasTextFieldPattern_ = onFocusTextField_.Upgrade(); + } + + bool HasKeyboard() const override + { + return imeShow_ || uiExtensionImeShow_; } private: 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 48cf2e2ad977b924bb5d1c49e8bcb8a80c26ff24..8765303724ef8f2d9dbe475aca1f1e9ed995e050 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 @@ -562,11 +562,6 @@ void TextFieldModelNG::SetShowCounter(bool value) auto pattern = frameNode->GetPattern(); CHECK_NULL_VOID(pattern); pattern->SetCounterState(false); - if (value) { - pattern->AddCounterNode(); - } else { - pattern->CleanCounterNode(); - } ACE_UPDATE_LAYOUT_PROPERTY(TextFieldLayoutProperty, ShowCounter, value); } @@ -1015,13 +1010,6 @@ void TextFieldModelNG::SetSelectionMenuHidden(FrameNode* frameNode, bool selecti void TextFieldModelNG::SetShowCounter(FrameNode* frameNode, bool value) { ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextFieldLayoutProperty, ShowCounter, value, frameNode); - auto pattern = frameNode->GetPattern(); - CHECK_NULL_VOID(pattern); - if (value) { - pattern->AddCounterNode(); - } else { - pattern->CleanCounterNode(); - } } void TextFieldModelNG::SetShowError(FrameNode* frameNode, const std::string& errorText, bool visible) 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 a468d596aefe64bc7d4acee192dcca928a0527f5..b776c54fdf15d0a14db527ab6fde5f4f06b07405 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 @@ -712,6 +712,7 @@ void TextFieldPattern::HandleFocusEvent() TAG_LOGI(AceLogTag::ACE_TEXT_FIELD, "TextField %{public}d on focus", host->GetId()); auto context = PipelineContext::GetCurrentContextSafely(); CHECK_NULL_VOID(context); + context->AddOnAreaChangeNode(host->GetId()); auto globalOffset = host->GetPaintRectOffset() - context->GetRootRect().GetOffset(); UpdateTextFieldManager(Offset(globalOffset.GetX(), globalOffset.GetY()), frameRect_.Height()); needToRequestKeyboardInner_ = !isLongPress_ && (dragRecipientStatus_ != DragStatus::DRAGGING); @@ -1042,6 +1043,11 @@ void TextFieldPattern::HandleBlurEvent() selectController_->UpdateCaretIndex(selectController_->GetCaretIndex()); NotifyOnEditChanged(false); host->MarkDirtyNode(PROPERTY_UPDATE_RENDER); + auto eventHub = host->GetEventHub(); + CHECK_NULL_VOID(eventHub); + if (!eventHub->HasOnAreaChanged()) { + context->RemoveOnAreaChangeNode(host->GetId()); + } } bool TextFieldPattern::OnKeyEvent(const KeyEvent& event) @@ -1686,7 +1692,7 @@ void TextFieldPattern::InitDragDropCallBack() auto touchX = event->GetX(); auto touchY = event->GetY(); Offset offset = Offset(touchX, touchY) - Offset(pattern->textRect_.GetX(), pattern->textRect_.GetY()) - - Offset(pattern->parentGlobalOffset_.GetX(), pattern->parentGlobalOffset_.GetY()) - + Offset(pattern->GetTextPaintOffset().GetX(), pattern->GetTextPaintOffset().GetY()) - Offset(0, theme->GetInsertCursorOffset().ConvertToPx()); auto position = pattern->ConvertTouchOffsetToCaretPosition(offset); pattern->SetCaretPosition(position); @@ -2125,6 +2131,75 @@ void TextFieldPattern::CheckIfNeedToResetKeyboard() } #endif } + +RefPtr TextFieldPattern::GetTextFieldLayoutProperty() +{ + auto host = GetHost(); + CHECK_NULL_RETURN(host, nullptr); + auto layoutProperty = host->GetLayoutProperty(); + CHECK_NULL_RETURN(layoutProperty, nullptr); + return layoutProperty; +} + +void TextFieldPattern::ProcessScroll() +{ + auto layoutProperty = GetTextFieldLayoutProperty(); + CHECK_NULL_VOID(layoutProperty); + if (IsTextArea() || IsNormalInlineState()) { + SetAxis(Axis::VERTICAL); + if (!GetScrollableEvent()) { + AddScrollEvent(); + } + auto barState = layoutProperty->GetDisplayModeValue(DisplayMode::AUTO); + if (!barState_.has_value()) { + barState_ = barState; + } + scrollBarVisible_ = barState != DisplayMode::OFF; + SetScrollBar(barState == DisplayMode::OFF ? DisplayMode::ON : barState); + auto scrollBar = GetScrollBar(); + if (scrollBar) { + scrollBar->SetMinHeight(SCROLL_BAR_MIN_HEIGHT); + } + if (textFieldOverlayModifier_) { + textFieldOverlayModifier_->SetScrollBar(scrollBar); + UpdateScrollBarOffset(); + } + } else { + SetAxis(Axis::HORIZONTAL); + SetScrollBar(DisplayMode::OFF); + if (!GetScrollableEvent()) { + AddScrollEvent(); + SetScrollEnable(false); + } + } +} + +void TextFieldPattern::ProcessCounter() +{ + auto layoutProperty = GetTextFieldLayoutProperty(); + CHECK_NULL_VOID(layoutProperty); + if (layoutProperty->GetShowCounterValue(false) && !IsNormalInlineState() && !IsInPasswordMode()) { + AddCounterNode(); + } else { + CleanCounterNode(); + } + if (IsTextArea()) { + if (setBorderFlag_ && layoutProperty->HasMaxLength()) { + auto textFieldTheme = GetTheme(); + lastDiffBorderColor_.SetColor(textFieldTheme->GetOverCountBorderColor()); + lastDiffBorderWidth_.SetBorderWidth(OVER_COUNT_BORDER_WIDTH); + setBorderFlag_ = false; + } + HandleCounterBorder(); + } else { + isTextInput_ = true; + } + UpdateCounterMargin(); + auto maxlength = GetMaxLength(); + auto originLength = static_cast(contentController_->GetWideText().length()); + HandleInputCounterBorder(originLength, maxlength); +} + void TextFieldPattern::OnModifyDone() { Pattern::OnModifyDone(); @@ -2163,7 +2238,6 @@ void TextFieldPattern::OnModifyDone() ProcessResponseArea(); InitDragEvent(); Register2DragDropManager(); - context->AddOnAreaChangeNode(host->GetId()); if (!clipboard_ && context) { clipboard_ = ClipboardProxy::GetInstance()->GetClipboard(context->GetTaskExecutor()); } @@ -2197,45 +2271,8 @@ void TextFieldPattern::OnModifyDone() operationRecords_.clear(); redoOperationRecords_.clear(); } - if (IsTextArea() || IsNormalInlineState()) { - SetAxis(Axis::VERTICAL); - if (!GetScrollableEvent()) { - AddScrollEvent(); - } - auto barState = layoutProperty->GetDisplayModeValue(DisplayMode::AUTO); - if (!barState_.has_value()) { - barState_ = barState; - } - scrollBarVisible_ = barState != DisplayMode::OFF; - SetScrollBar(barState == DisplayMode::OFF ? DisplayMode::ON : barState); - auto scrollBar = GetScrollBar(); - if (scrollBar) { - scrollBar->SetMinHeight(SCROLL_BAR_MIN_HEIGHT); - } - if (textFieldOverlayModifier_) { - textFieldOverlayModifier_->SetScrollBar(scrollBar); - UpdateScrollBarOffset(); - } - } else { - SetAxis(Axis::HORIZONTAL); - SetScrollBar(DisplayMode::OFF); - if (!GetScrollableEvent()) { - AddScrollEvent(); - SetScrollEnable(false); - } - } - if (IsTextArea()) { - if (setBorderFlag_ && layoutProperty->HasMaxLength()) { - auto textFieldTheme = GetTheme(); - lastDiffBorderColor_.SetColor(textFieldTheme->GetOverCountBorderColor()); - lastDiffBorderWidth_.SetBorderWidth(OVER_COUNT_BORDER_WIDTH); - setBorderFlag_ = false; - } - HandleCounterBorder(); - } else { - isTextInput_ = true; - } - UpdateCounterMargin(); + ProcessScroll(); + ProcessCounter(); bool underline = layoutProperty->GetShowUnderlineValue(false) && IsUnspecifiedOrTextType() && (!IsNormalInlineState() || !HasFocus()); if (preUnderline && !underline) { @@ -2265,9 +2302,6 @@ void TextFieldPattern::OnModifyDone() } host->MarkDirtyNode(PROPERTY_UPDATE_MEASURE); } - auto maxlength = GetMaxLength(); - auto originLength = static_cast(contentController_->GetWideText().length()); - HandleInputCounterBorder(originLength, maxlength); preInline = IsNormalInlineState(); preUnderline = underline; Register2DragDropManager(); @@ -2804,7 +2838,7 @@ void TextFieldPattern::OnHandleMove(const RectF& handleRect, bool isFirstHandle) { CHECK_NULL_VOID(SelectOverlayIsOn()); CHECK_NULL_VOID(!contentController_->IsEmpty()); - auto localOffset = handleRect.GetOffset() - parentGlobalOffset_; + auto localOffset = handleRect.GetOffset() - GetTextPaintOffset(); magnifierController_->SetLocalOffset(localOffset); if (isSingleHandle_) { selectController_->UpdateCaretInfoByOffset(Offset(localOffset.GetX(), localOffset.GetY())); @@ -3354,7 +3388,7 @@ std::optional TextFieldPattern::GetMiscTextConfig() co double height = frameRect_.Height(); auto offset = AVOID_OFFSET.ConvertToPx(); height = - selectController_->GetCaretRect().Bottom() + windowRect.Top() + parentGlobalOffset_.GetY() + offset - positionY; + selectController_->GetCaretRect().Bottom() + windowRect.Top() + GetTextPaintOffset().GetY() + offset - positionY; if (IsNormalInlineState()) { auto safeBoundary = theme->GetInlineBorderWidth().ConvertToPx() * 2; @@ -3363,8 +3397,8 @@ std::optional TextFieldPattern::GetMiscTextConfig() co } MiscServices::CursorInfo cursorInfo { .left = selectController_->GetCaretRect().Left() + windowRect.Left() + - parentGlobalOffset_.GetX(), - .top = selectController_->GetCaretRect().Top() + windowRect.Top() + parentGlobalOffset_.GetY(), + GetTextPaintOffset().GetX(), + .top = selectController_->GetCaretRect().Top() + windowRect.Top() + GetTextPaintOffset().GetY(), .width = theme->GetCursorWidth().ConvertToPx(), .height = selectController_->GetCaretRect().Height() }; MiscServices::InputAttribute inputAttribute = { .inputPattern = (int32_t)keyboard_, @@ -6042,7 +6076,7 @@ bool TextFieldPattern::CheckHandleVisible(const RectF& paintRect) auto host = GetHost(); CHECK_NULL_RETURN(host, false); // use global offset. - RectF visibleContentRect(contentRect_.GetOffset() + parentGlobalOffset_, contentRect_.GetSize()); + RectF visibleContentRect(contentRect_.GetOffset() + GetTextPaintOffset(), contentRect_.GetSize()); auto parent = host->GetAncestorNodeOfFrame(); visibleContentRect = GetVisibleContentRect(parent, visibleContentRect); if (!IsTextArea()) { @@ -6260,7 +6294,7 @@ OffsetF TextFieldPattern::GetDragUpperLeftCoordinates() if (startOffset.GetX() < contentRect_.GetX()) { startOffset.SetX(contentRect_.GetX()); } - return startOffset + parentGlobalOffset_; + return startOffset + GetTextPaintOffset(); } void TextFieldPattern::OnColorConfigurationUpdate() 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 033ee24147e4d99feb6ca501c184c9539103aa10..0e68dc873da6a8a7dc00e01ccc18497b782068bd 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 @@ -1311,6 +1311,9 @@ private: bool IsAutoFillPasswordType(const AceAutoFillType& autoFillType); void DoProcessAutoFill(); void KeyboardContentTypeToInputType(); + void ProcessScroll(); + void ProcessCounter(); + RefPtr GetTextFieldLayoutProperty(); RectF frameRect_; RectF textRect_; diff --git a/frameworks/core/pipeline_ng/pipeline_context.cpp b/frameworks/core/pipeline_ng/pipeline_context.cpp index 9a542bd4fc33aa669f5e9bce69f82fa9a09a63e5..08b9e936db83b2c6c6a0837db64eb12d490c097d 100755 --- a/frameworks/core/pipeline_ng/pipeline_context.cpp +++ b/frameworks/core/pipeline_ng/pipeline_context.cpp @@ -537,7 +537,9 @@ void PipelineContext::IsCloseSCBKeyboard() { auto container = Container::Current(); CHECK_NULL_VOID(container); - if (container->IsKeyboard()) { + auto manager = DynamicCast(textFieldManager_); + CHECK_NULL_VOID(manager); + if (container->IsKeyboard() || !manager->HasKeyboard()) { TAG_LOGI(AceLogTag::ACE_KEYBOARD, "focus in keyboard."); return; }