[NDK] add textinput content size change event

Signed-off-by:lisitaolisitao3@huawei.com

Signed-off-by: lisitao <lisitao3@huawei.com>
Change-Id: Iae5f9285d05df7102e3e16039811305815577902
This commit is contained in:
lisitao 2024-05-01 09:11:13 +00:00
parent 6192e902f7
commit 3ef84581e5
7 changed files with 48 additions and 4 deletions

View File

@ -142,10 +142,14 @@ public:
onContentSizeChange_ = std::move(func);
}
const std::function<void(float, float)>& GetOnContentSizeChange() const
{
return onContentSizeChange_;
}
void FireOnContentSizeChange(float width, float height)
{
if (onContentSizeChange_) {
LOGI("On Content Size Change width %{private}f, height %{private}f", width, height);
onContentSizeChange_(width, height);
}
}

View File

@ -464,6 +464,7 @@ bool TextFieldPattern::OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dir
needToRefreshSelectOverlay_ = false;
}
paragraphWidth_ = paragraphWidth;
HandleContentSizeChange(textRect);
textRect_ = textRect;
if (textFieldContentModifier_) {
@ -509,6 +510,24 @@ bool TextFieldPattern::OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dir
return true;
}
void TextFieldPattern::HandleContentSizeChange(RectF textRect)
{
if (textRect_ == textRect) {
return;
}
auto host = GetHost();
CHECK_NULL_VOID(host);
auto eventHub = host->GetEventHub<TextFieldEventHub>();
CHECK_NULL_VOID(eventHub);
if (eventHub->GetOnContentSizeChange()) {
auto pipeline = PipelineContext::GetCurrentContextSafely();
CHECK_NULL_VOID(pipeline);
pipeline->AddAfterLayoutTask([textRect, eventHub]() {
eventHub->FireOnContentSizeChange(textRect.Width(), textRect.Height());
});
}
}
void TextFieldPattern::ProcessOverlayAfterLayout(bool isGlobalAreaChanged)
{
if (processOverlayDelayTask_) {
@ -1476,7 +1495,6 @@ void TextFieldPattern::FireEventHubOnChange(const std::string& text)
auto eventHub = host->GetEventHub<TextFieldEventHub>();
CHECK_NULL_VOID(eventHub);
eventHub->FireOnChange(text);
eventHub->FireOnContentSizeChange(textRect_.Width(), textRect_.Height());
}
void TextFieldPattern::HandleTouchEvent(const TouchEventInfo& info)
@ -2474,7 +2492,6 @@ bool TextFieldPattern::FireOnTextChangeEvent()
host->OnAccessibilityEvent(AccessibilityEventType::TEXT_CHANGE, textCache, contentController_->GetTextValue());
AutoFillValueChanged();
eventHub->FireOnChange(contentController_->GetTextValue());
eventHub->FireOnContentSizeChange(textRect_.Width(), textRect_.Height());
auto context = PipelineContext::GetCurrentContextSafely();
CHECK_NULL_RETURN(context, false);
auto taskExecutor = context->GetTaskExecutor();

View File

@ -1384,6 +1384,7 @@ private:
Offset ConvertGlobalToLocalOffset(const Offset& globalOffset);
void HandleCountStyle();
void HandleDeleteOnCounterScene();
void HandleContentSizeChange();
void UpdatePreviewIndex(int32_t start, int32_t end)
{

View File

@ -5761,6 +5761,14 @@ typedef struct {
* @return Returns <b>0</b> if the operation is successful; returns <b>401</b> if a parameter error occurs.
*/
int32_t (*setLengthMetricUnit)(ArkUI_NodeHandle node, ArkUI_LengthMetricUnit unit);
/**
* @brief
*
* @param node
* @return NULL
*/
ArkUI_NodeHandle (*getParent)(ArkUI_NodeHandle node);
} ArkUI_NativeNodeAPI_1;
/**

View File

@ -88,6 +88,7 @@ ArkUI_NativeNodeAPI_1 nodeImpl_1 = {
nullptr,
nullptr,
OHOS::Ace::NodeModel::SetLengthMetricUnit,
OHOS::Ace::NodeModel::GetParent,
};
ArkUI_NativeDialogAPI_1 dialogImpl_1 = {

View File

@ -422,4 +422,17 @@ ArkUI_NodeHandle GetNextSibling(ArkUI_NodeHandle node)
return nullptr;
}
ArkUI_NodeHandle GetParent(ArkUI_NodeHandle node)
{
if (node == nullptr) {
return nullptr;
}
auto* impl = GetFullImpl();
auto* value = impl->getNodeModifiers()->getFrameNodeModifier()->getParent(node->uiNodeHandle);
void* attachNode = impl->getExtendedAPI()->getAttachNodePtr(value);
if (attachNode) {
return reinterpret_cast<ArkUI_NodeHandle>(attachNode);
}
return nullptr;
}
} // namespace OHOS::Ace::NodeModel

View File

@ -108,5 +108,5 @@ ArkUI_NodeHandle GetFirstChild(ArkUI_NodeHandle node);
ArkUI_NodeHandle GetLastChild(ArkUI_NodeHandle node);
ArkUI_NodeHandle GetPreviousSibling(ArkUI_NodeHandle node);
ArkUI_NodeHandle GetNextSibling(ArkUI_NodeHandle node);
ArkUI_NodeHandle GetParent(ArkUI_NodeHandle node);
} // namespace OHOS::Ace::NodeModel