navigation适配autofill

Signed-off-by: jsjzju <jinsenjun@huawei.com>
Change-Id: I943600b986aafd855d67ad7fcedb36e80169d7f6
This commit is contained in:
jsjzju 2024-04-27 22:33:36 +08:00
parent a9d8f3019c
commit 5bb4dfd282
18 changed files with 183 additions and 66 deletions

View File

@ -1149,7 +1149,8 @@ bool AceContainer::UpdatePopupUIExtension(const RefPtr<NG::FrameNode>& node)
auto uiContentImpl = reinterpret_cast<UIContentImpl*>(uiContent);
CHECK_NULL_RETURN(uiContentImpl, false);
auto viewDataWrap = ViewDataWrap::CreateViewDataWrap();
uiContentImpl->DumpViewData(node, viewDataWrap);
auto autoFillContainerNode = node->GetFirstAutoFillContainerNode();
uiContentImpl->DumpViewData(autoFillContainerNode, viewDataWrap, true);
auto viewDataWrapOhos = AceType::DynamicCast<ViewDataWrapOhos>(viewDataWrap);
CHECK_NULL_RETURN(viewDataWrapOhos, false);
auto viewData = viewDataWrapOhos->GetViewData();
@ -1170,7 +1171,8 @@ bool AceContainer::RequestAutoFill(const RefPtr<NG::FrameNode>& node, AceAutoFil
CHECK_NULL_RETURN(uiContentImpl, false);
auto viewDataWrap = ViewDataWrap::CreateViewDataWrap();
CHECK_NULL_RETURN(viewDataWrap, false);
uiContentImpl->DumpViewData(node, viewDataWrap);
auto autoFillContainerNode = node->GetFirstAutoFillContainerNode();
uiContentImpl->DumpViewData(autoFillContainerNode, viewDataWrap, true);
auto callback = std::make_shared<FillRequestCallback>(pipelineContext, node, autoFillType);
auto viewDataWrapOhos = AceType::DynamicCast<ViewDataWrapOhos>(viewDataWrap);

View File

@ -2580,7 +2580,8 @@ bool UIContentImpl::DumpViewData(AbilityBase::ViewData& viewData, AbilityBase::A
return ret;
}
bool UIContentImpl::DumpViewData(const RefPtr<NG::FrameNode>& node, RefPtr<ViewDataWrap> viewDataWrap)
bool UIContentImpl::DumpViewData(const RefPtr<NG::FrameNode>& node, RefPtr<ViewDataWrap> viewDataWrap,
bool skipSubAutoFillContainer)
{
CHECK_NULL_RETURN(viewDataWrap, false);
auto context = context_.lock();
@ -2608,7 +2609,7 @@ bool UIContentImpl::DumpViewData(const RefPtr<NG::FrameNode>& node, RefPtr<ViewD
CHECK_NULL_RETURN(container, false);
auto pipelineContext = AceType::DynamicCast<NG::PipelineContext>(container->GetPipelineContext());
CHECK_NULL_RETURN(pipelineContext, false);
return pipelineContext->DumpPageViewData(node, viewDataWrap);
return pipelineContext->DumpPageViewData(node, viewDataWrap, skipSubAutoFillContainer);
}
void UIContentImpl::SearchElementInfoByAccessibilityId(

View File

@ -215,7 +215,8 @@ public:
AbilityBase::AutoFillType ViewDataToType(const AbilityBase::ViewData& viewData);
bool DumpViewData(AbilityBase::ViewData& viewData, AbilityBase::AutoFillType& type) override;
bool CheckNeedAutoSave() override;
bool DumpViewData(const RefPtr<NG::FrameNode>& node, RefPtr<ViewDataWrap> viewDataWrap);
bool DumpViewData(const RefPtr<NG::FrameNode>& node, RefPtr<ViewDataWrap> viewDataWrap,
bool skipSubAutoFillContainer = false);
void SearchElementInfoByAccessibilityId(
int64_t elementId, int32_t mode,

View File

@ -0,0 +1,53 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_AUTO_FILL_TRIGGER_STATE_HOLDER_H
#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_AUTO_FILL_TRIGGER_STATE_HOLDER_H
#include "base/memory/ace_type.h"
namespace OHOS::Ace {
class AutoFillTriggerStateHolder : public virtual AceType {
DECLARE_ACE_TYPE(AutoFillTriggerStateHolder, AceType);
public:
AutoFillTriggerStateHolder() = default;
~AutoFillTriggerStateHolder() override = default;
void SetAutoFillPasswordTriggered(bool value)
{
autoFillPasswordTriggered_ = value;
}
bool IsAutoFillPasswordTriggered() const
{
return autoFillPasswordTriggered_;
}
void SetAutoFillNewPasswordTriggered(bool value)
{
autoFillNewPasswordTriggered_ = value;
}
bool IsAutoFillNewPasswordTriggered() const
{
return autoFillNewPasswordTriggered_;
}
private:
bool autoFillPasswordTriggered_ = false;
bool autoFillNewPasswordTriggered_ = false;
};
} // namespace OHOS::Ace
#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_AUTO_FILL_TRIGGER_STATE_HOLDER_H

View File

@ -1659,6 +1659,18 @@ RefPtr<FrameNode> FrameNode::GetPageNode()
return AceType::DynamicCast<FrameNode>(parent);
}
RefPtr<FrameNode> FrameNode::GetFirstAutoFillContainerNode()
{
if (IsAutoFillContainerNode()) {
return Claim(this);
}
auto parent = GetParent();
while (parent && !parent->IsAutoFillContainerNode()) {
parent = parent->GetParent();
}
return AceType::DynamicCast<FrameNode>(parent);
}
void FrameNode::NotifyFillRequestSuccess(RefPtr<PageNodeInfoWrap> nodeWrap, AceAutoFillType autoFillType)
{
if (pattern_) {

View File

@ -774,6 +774,7 @@ public:
OffsetF GetOffsetInScreen();
RefPtr<PixelMap> GetPixelMap();
RefPtr<FrameNode> GetPageNode();
RefPtr<FrameNode> GetFirstAutoFillContainerNode();
RefPtr<FrameNode> GetNodeContainer();
RefPtr<ContentModifier> GetContentModifier();

View File

@ -574,11 +574,22 @@ void UINode::OnAttachToMainTree(bool)
}
}
void UINode::DumpViewDataPageNodes(RefPtr<ViewDataWrap> viewDataWrap)
bool UINode::IsAutoFillContainerNode()
{
return tag_ == V2::PAGE_ETS_TAG || tag_ == V2::NAVDESTINATION_VIEW_ETS_TAG;
}
void UINode::DumpViewDataPageNodes(RefPtr<ViewDataWrap> viewDataWrap, bool skipSubAutoFillContainer)
{
DumpViewDataPageNode(viewDataWrap);
for (const auto& item : GetChildren()) {
item->DumpViewDataPageNodes(viewDataWrap);
if (!item) {
continue;
}
if (skipSubAutoFillContainer && item->IsAutoFillContainerNode()) {
continue;
}
item->DumpViewDataPageNodes(viewDataWrap, skipSubAutoFillContainer);
}
}

View File

@ -164,7 +164,8 @@ public:
// the corresponding LayoutWrapper tree node at this time like add self wrapper to wrapper tree.
virtual void AdjustLayoutWrapperTree(const RefPtr<LayoutWrapperNode>& parent, bool forceMeasure, bool forceLayout);
void DumpViewDataPageNodes(RefPtr<ViewDataWrap> viewDataWrap);
bool IsAutoFillContainerNode();
void DumpViewDataPageNodes(RefPtr<ViewDataWrap> viewDataWrap, bool skipSubAutoFillContainer = false);
bool NeedRequestAutoSave();
// DFX info.
void DumpTree(int32_t depth);

View File

@ -1750,6 +1750,11 @@ void NavigationPattern::StartTransition(const RefPtr<NavDestinationGroupNode>& p
// fire onWillHide
auto hostNode = AceType::DynamicCast<NavigationGroupNode>(GetHost());
CHECK_NULL_VOID(hostNode);
if (!isPopPage && !preDestination && navigationMode_ == NavigationMode::STACK) {
// NavBar will be covered in STACK mode
auto navBarNode = AceType::DynamicCast<FrameNode>(hostNode->GetNavBarNode());
ProcessAutoSave(navBarNode);
}
if (isPopPage || (preDestination && hostNode->GetLastStandardIndex() > preDestination->GetIndex())) {
NotifyDestinationLifecycle(preDestination, NavDestinationLifecycle::ON_WILL_HIDE, true);
}
@ -1779,6 +1784,17 @@ void NavigationPattern::StartTransition(const RefPtr<NavDestinationGroupNode>& p
});
}
void NavigationPattern::ProcessAutoSave(const RefPtr<FrameNode>& node)
{
CHECK_NULL_VOID(node);
if (!node->NeedRequestAutoSave()) {
return;
}
auto container = Container::Current();
CHECK_NULL_VOID(container);
container->RequestAutoSave(node);
}
void NavigationPattern::NotifyDestinationLifecycle(const RefPtr<UINode>& uiNode,
NavDestinationLifecycle lifecycle, bool isNavigationChanged)
{

View File

@ -411,6 +411,7 @@ private:
void StartTransition(const RefPtr<NavDestinationGroupNode>& preDestination,
const RefPtr<NavDestinationGroupNode>& topDestination,
bool isAnimated, bool isPopPage, bool isNeedVisible = false);
void ProcessAutoSave(const RefPtr<FrameNode>& node);
void PerformanceEventReport(int32_t nodeCount, int32_t depth, const std::string& navDestinationName);
void FireShowAndHideLifecycle(const RefPtr<NavDestinationGroupNode>& preDestination,

View File

@ -14,6 +14,7 @@
*/
#include "frameworks/core/components_ng/pattern/navrouter/navdestination_event_hub.h"
#include "core/common/container.h"
#include "frameworks/core/components_ng/pattern/navrouter/navdestination_group_node.h"
#include "frameworks/core/components_ng/pattern/navrouter/navdestination_pattern.h"
namespace OHOS::Ace::NG {
@ -38,4 +39,16 @@ void NavDestinationEventHub::FireOnDisappear()
pattern->SetCustomNode(nullptr);
});
}
void NavDestinationEventHub::FireAutoSave()
{
auto node = GetFrameNode();
CHECK_NULL_VOID(node);
if (!node->NeedRequestAutoSave()) {
return;
}
auto container = Container::Current();
CHECK_NULL_VOID(container);
container->RequestAutoSave(node);
}
}

View File

@ -231,6 +231,8 @@ public:
if (onWillHide_) {
onWillHide_();
}
FireAutoSave();
}
void SetOnWillDisAppear(std::function<void()>& willDisAppear)
@ -256,6 +258,8 @@ private:
return node->GetPattern();
}
void FireAutoSave();
OnStateChangeEvent onStateChangeEvent_;
std::function<void()> onShownEvent_;
std::function<void()> onHiddenEvent_;

View File

@ -18,6 +18,7 @@
#include "base/memory/referenced.h"
#include "base/utils/utils.h"
#include "core/common/autofill/auto_fill_trigger_state_holder.h"
#include "core/components_ng/base/ui_node.h"
#include "core/components_ng/pattern/navigation/navigation_event_hub.h"
#include "core/components_ng/pattern/navigation/navigation_stack.h"
@ -32,8 +33,8 @@
namespace OHOS::Ace::NG {
class NavDestinationPattern : public Pattern, public FocusView {
DECLARE_ACE_TYPE(NavDestinationPattern, Pattern, FocusView);
class NavDestinationPattern : public Pattern, public FocusView, public AutoFillTriggerStateHolder {
DECLARE_ACE_TYPE(NavDestinationPattern, Pattern, FocusView, AutoFillTriggerStateHolder);
public:
explicit NavDestinationPattern(const RefPtr<ShallowBuilder>& shallowBuilder);

View File

@ -22,6 +22,7 @@
#include "base/utils/noncopyable.h"
#include "core/animation/animator_info.h"
#include "core/animation/page_transition_common.h"
#include "core/common/autofill/auto_fill_trigger_state_holder.h"
#include "core/components_ng/pattern/stage/content_root_pattern.h"
#include "core/components_ng/pattern/stage/page_event_hub.h"
#include "core/components_ng/pattern/stage/page_info.h"
@ -44,8 +45,8 @@ enum class RouterPageState {
};
// PagePattern is the base class for page root render node.
class ACE_EXPORT PagePattern : public ContentRootPattern, public FocusView {
DECLARE_ACE_TYPE(PagePattern, ContentRootPattern, FocusView);
class ACE_EXPORT PagePattern : public ContentRootPattern, public FocusView, public AutoFillTriggerStateHolder {
DECLARE_ACE_TYPE(PagePattern, ContentRootPattern, FocusView, AutoFillTriggerStateHolder);
public:
explicit PagePattern(const RefPtr<PageInfo>& pageInfo) : pageInfo_(pageInfo) {}
@ -161,26 +162,6 @@ public:
isRenderDone_ = true;
}
void SetAutoFillPasswordTriggered(bool value)
{
autoFillPasswordTriggered_ = value;
}
bool IsAutoFillPasswordTriggered() const
{
return autoFillPasswordTriggered_;
}
void SetAutoFillNewPasswordTriggered(bool value)
{
autoFillNewPasswordTriggered_ = value;
}
bool IsAutoFillNewPasswordTriggered() const
{
return autoFillNewPasswordTriggered_;
}
void SetDynamicPageSizeCallback(DynamicPageSizeCallback&& dynamicPageSizeCallback)
{
dynamicPageSizeCallback_ = std::move(dynamicPageSizeCallback);
@ -247,8 +228,6 @@ private:
bool isFirstLoad_ = true;
bool isPageInTransition_ = false;
bool isRenderDone_ = false;
bool autoFillPasswordTriggered_ = false;
bool autoFillNewPasswordTriggered_ = false;
SharedTransitionMap sharedTransitionMap_;
JSAnimatorMap jsAnimatorMap_;

View File

@ -49,6 +49,7 @@
#include "core/components_ng/base/inspector_filter.h"
#include "core/components_ng/event/focus_hub.h"
#include "core/components_ng/image_provider/image_loading_context.h"
#include "core/components_ng/pattern/navrouter/navdestination_pattern.h"
#include "core/components_ng/pattern/overlay/modal_style.h"
#include "core/components_ng/pattern/search/search_event_hub.h"
#include "core/components_ng/pattern/search/search_pattern.h"
@ -1948,26 +1949,47 @@ bool TextFieldPattern::IsAutoFillPasswordType(const AceAutoFillType& autoFillTyp
autoFillType == AceAutoFillType::ACE_NEW_PASSWORD);
}
bool TextFieldPattern::CheckAutoFillType(const AceAutoFillType& aceAutoFillAllType)
bool TextFieldPattern::CheckAutoFillType(const AceAutoFillType& autoFillType)
{
if (autoFillType == AceAutoFillType::ACE_UNSPECIFIED) {
TAG_LOGE(AceLogTag::ACE_AUTO_FILL, "CheckAutoFillType :autoFillType is ACE_UNSPECIFIED.");
return false;
} else if (IsAutoFillPasswordType(autoFillType)) {
return GetAutoFillTriggeredStateByType(autoFillType);
}
return true;
}
bool TextFieldPattern::GetAutoFillTriggeredStateByType(const AceAutoFillType& autoFillType)
{
auto host = GetHost();
CHECK_NULL_RETURN(host, false);
auto pageNode = host->GetPageNode();
CHECK_NULL_RETURN(pageNode, false);
auto pagePattern = pageNode->GetPattern<PagePattern>();
CHECK_NULL_RETURN(pagePattern, false);
auto layoutProperty = GetLayoutProperty<TextFieldLayoutProperty>();
CHECK_NULL_RETURN(layoutProperty, false);
if (aceAutoFillAllType == AceAutoFillType::ACE_UNSPECIFIED) {
TAG_LOGE(AceLogTag::ACE_AUTO_FILL, "CheckAutoFillType :aceAutoFillAllType is ACE_UNSPECIFIED.");
return false;
} else if (aceAutoFillAllType == AceAutoFillType::ACE_USER_NAME ||
aceAutoFillAllType == AceAutoFillType::ACE_PASSWORD) {
return !pagePattern->IsAutoFillPasswordTriggered();
} else if (aceAutoFillAllType == AceAutoFillType::ACE_NEW_PASSWORD) {
return !pagePattern->IsAutoFillNewPasswordTriggered();
auto autoFillContainerNode = host->GetFirstAutoFillContainerNode();
CHECK_NULL_RETURN(autoFillContainerNode, false);
auto stateHolder = autoFillContainerNode->GetPattern<AutoFillTriggerStateHolder>();
CHECK_NULL_RETURN(stateHolder, false);
if (autoFillType == AceAutoFillType::ACE_USER_NAME || autoFillType == AceAutoFillType::ACE_PASSWORD) {
return !stateHolder->IsAutoFillPasswordTriggered();
}
if (autoFillType == AceAutoFillType::ACE_NEW_PASSWORD) {
return !stateHolder->IsAutoFillNewPasswordTriggered();
}
return false;
}
void TextFieldPattern::SetAutoFillTriggeredStateByType(const AceAutoFillType& autoFillType)
{
auto host = GetHost();
CHECK_NULL_VOID(host);
auto autoFillContainerNode = host->GetFirstAutoFillContainerNode();
CHECK_NULL_VOID(autoFillContainerNode);
auto stateHolder = autoFillContainerNode->GetPattern<AutoFillTriggerStateHolder>();
CHECK_NULL_VOID(stateHolder);
if (autoFillType == AceAutoFillType::ACE_USER_NAME || autoFillType == AceAutoFillType::ACE_PASSWORD) {
stateHolder->SetAutoFillPasswordTriggered(true);
} else if (autoFillType == AceAutoFillType::ACE_NEW_PASSWORD) {
stateHolder->SetAutoFillNewPasswordTriggered(true);
}
return true;
}
AceAutoFillType TextFieldPattern::GetAutoFillType()
@ -2009,22 +2031,12 @@ bool TextFieldPattern::ProcessAutoFill(bool& isPopup)
}
auto host = GetHost();
CHECK_NULL_RETURN(host, false);
auto pageNode = host->GetPageNode();
CHECK_NULL_RETURN(pageNode, false);
auto pagePattern = pageNode->GetPattern<PagePattern>();
CHECK_NULL_RETURN(pagePattern, false);
auto layoutProperty = GetLayoutProperty<TextFieldLayoutProperty>();
CHECK_NULL_RETURN(layoutProperty, false);
auto autoFillType = GetAutoFillType();
auto container = Container::Current();
CHECK_NULL_RETURN(container, false);
if (autoFillType == AceAutoFillType::ACE_USER_NAME || autoFillType == AceAutoFillType::ACE_PASSWORD) {
pagePattern->SetAutoFillPasswordTriggered(true);
} else if (autoFillType == AceAutoFillType::ACE_NEW_PASSWORD) {
pagePattern->SetAutoFillNewPasswordTriggered(true);
}
SetAutoFillTriggeredStateByType(autoFillType);
SetFillRequestFinish(false);
return (container->RequestAutoFill(host, autoFillType, isPopup));
return container->RequestAutoFill(host, autoFillType, isPopup);
}
void TextFieldPattern::HandleDoubleClickEvent(GestureEvent& info)

View File

@ -29,6 +29,7 @@
#include "base/memory/referenced.h"
#include "base/mousestyle/mouse_style.h"
#include "base/view_data/view_data_wrap.h"
#include "core/common/autofill/auto_fill_trigger_state_holder.h"
#include "core/common/clipboard/clipboard.h"
#include "core/common/ime/text_edit_controller.h"
#include "core/common/ime/text_input_action.h"
@ -1291,7 +1292,9 @@ private:
void InitDragDropEventWithOutDragStart();
void UpdateBlurReason();
AceAutoFillType TextContentTypeToAceAutoFillType(const TextContentType& type);
bool CheckAutoFillType(const AceAutoFillType& aceAutoFillAllType);
bool CheckAutoFillType(const AceAutoFillType& autoFillType);
bool GetAutoFillTriggeredStateByType(const AceAutoFillType& autoFillType);
void SetAutoFillTriggeredStateByType(const AceAutoFillType& autoFillType);
AceAutoFillType GetAutoFillType();
bool IsAutoFillPasswordType(const AceAutoFillType& autoFillType);
void DoProcessAutoFill();

View File

@ -2114,19 +2114,24 @@ void PipelineContext::RegisterDumpInfoListener(const std::function<void(const st
dumpListeners_.push_back(callback);
}
bool PipelineContext::DumpPageViewData(const RefPtr<FrameNode>& node, RefPtr<ViewDataWrap> viewDataWrap)
bool PipelineContext::DumpPageViewData(const RefPtr<FrameNode>& node, RefPtr<ViewDataWrap> viewDataWrap,
bool skipSubAutoFillContainer)
{
CHECK_NULL_RETURN(viewDataWrap, false);
RefPtr<FrameNode> pageNode = nullptr;
RefPtr<FrameNode> dumpNode = nullptr;
if (node == nullptr) {
if (stageManager_) {
pageNode = stageManager_->GetLastPage();
dumpNode = pageNode;
}
} else {
pageNode = node->GetPageNode();
dumpNode = node;
}
CHECK_NULL_RETURN(pageNode, false);
pageNode->DumpViewDataPageNodes(viewDataWrap);
CHECK_NULL_RETURN(dumpNode, false);
dumpNode->DumpViewDataPageNodes(viewDataWrap, skipSubAutoFillContainer);
auto pagePattern = pageNode->GetPattern<NG::PagePattern>();
CHECK_NULL_RETURN(pagePattern, false);
auto pageInfo = pagePattern->GetPageInfo();

View File

@ -539,7 +539,8 @@ public:
void RegisterDumpInfoListener(const std::function<void(const std::vector<std::string>&)>& callback);
void DumpJsInfo(const std::vector<std::string>& params) const;
bool DumpPageViewData(const RefPtr<FrameNode>& node, RefPtr<ViewDataWrap> viewDataWrap);
bool DumpPageViewData(const RefPtr<FrameNode>& node, RefPtr<ViewDataWrap> viewDataWrap,
bool skipSubAutoFillContainer = false);
bool CheckNeedAutoSave();
bool CheckPageFocus();
bool CheckOverlayFocus();