mirror of
https://gitee.com/openharmony/arkui_ace_engine
synced 2025-01-08 09:53:20 +00:00
!34566 Add EnableForm interface
Merge pull request !34566 from jiangzhijun8/master
This commit is contained in:
commit
1968734de8
@ -424,6 +424,15 @@ void FormManagerDelegate::AddActionEventHandle(const ActionEventHandle& callback
|
||||
actionEventHandle_ = callback;
|
||||
}
|
||||
|
||||
void FormManagerDelegate::AddEnableFormCallback(EnableFormCallback&& callback)
|
||||
{
|
||||
if (!callback || state_ == State::RELEASED) {
|
||||
TAG_LOGE(AceLogTag::ACE_FORM, "EnableFormCallback is null");
|
||||
return;
|
||||
}
|
||||
enableFormCallback_ = std::move(callback);
|
||||
}
|
||||
|
||||
void FormManagerDelegate::OnActionEventHandle(const std::string& action)
|
||||
{
|
||||
if (actionEventHandle_) {
|
||||
@ -558,6 +567,14 @@ void FormManagerDelegate::RegisterRenderDelegateEvent()
|
||||
formManagerDelegate->OnGetRectRelativeToWindow(top, left);
|
||||
};
|
||||
renderDelegate_->SetGetRectRelativeToWindowHandler(onGetRectRelativeToWindowHandler);
|
||||
|
||||
auto&& enableFormEventHandler = [weak = WeakClaim(this)](const OHOS::AppExecFwk::FormJsInfo& formInfo,
|
||||
const bool enable) {
|
||||
auto formManagerDelegate = weak.Upgrade();
|
||||
CHECK_NULL_VOID(formManagerDelegate);
|
||||
formManagerDelegate->OnEnableForm(formInfo, enable);
|
||||
};
|
||||
renderDelegate_->SetEnableFormEventHandler(std::move(enableFormEventHandler));
|
||||
}
|
||||
|
||||
void FormManagerDelegate::OnActionEvent(const std::string& action)
|
||||
@ -753,6 +770,13 @@ void FormManagerDelegate::OnFormError(const std::string& code, const std::string
|
||||
}
|
||||
}
|
||||
|
||||
void FormManagerDelegate::OnEnableForm(const AppExecFwk::FormJsInfo& formInfo, const bool enable)
|
||||
{
|
||||
TAG_LOGI(AceLogTag::ACE_FORM, "FormManagerDelegate::OnEnableForm,formInfo.formId = %{public}" PRId64 "",
|
||||
formInfo.formId);
|
||||
HandleEnableFormCallback(enable);
|
||||
}
|
||||
|
||||
void FormManagerDelegate::HandleUnTrustFormCallback()
|
||||
{
|
||||
TAG_LOGI(AceLogTag::ACE_FORM, "HandleUnTrustFormCallback.");
|
||||
@ -769,6 +793,14 @@ void FormManagerDelegate::HandleSnapshotCallback(const uint32_t& delayTime)
|
||||
}
|
||||
}
|
||||
|
||||
void FormManagerDelegate::HandleEnableFormCallback(const bool enable)
|
||||
{
|
||||
if (!enableFormCallback_) {
|
||||
TAG_LOGE(AceLogTag::ACE_FORM, "enableFormCallback_. is null");
|
||||
}
|
||||
enableFormCallback_(enable);
|
||||
}
|
||||
|
||||
void FormManagerDelegate::ReAddForm()
|
||||
{
|
||||
{
|
||||
|
@ -61,6 +61,7 @@ public:
|
||||
using ActionEventHandle = std::function<void(const std::string&)>;
|
||||
using UnTrustFormCallback = std::function<void()>;
|
||||
using SnapshotCallback = std::function<void(const uint32_t&)>;
|
||||
using EnableFormCallback = std::function<void(const bool enable)>;
|
||||
|
||||
enum class State : char {
|
||||
WAITINGFORSIZE,
|
||||
@ -102,6 +103,7 @@ public:
|
||||
void AddActionEventHandle(const ActionEventHandle& callback);
|
||||
void AddUnTrustFormCallback(const UnTrustFormCallback& callback);
|
||||
void AddSnapshotCallback(SnapshotCallback&& callback);
|
||||
void AddEnableFormCallback(EnableFormCallback&& callback);
|
||||
void OnActionEventHandle(const std::string& action);
|
||||
void SetAllowUpdate(bool allowUpdate);
|
||||
void OnActionEvent(const std::string& action);
|
||||
@ -117,6 +119,7 @@ public:
|
||||
void OnAccessibilityChildTreeRegister(uint32_t windowId, int32_t treeId, int64_t accessibilityId);
|
||||
void OnAccessibilityChildTreeDeregister();
|
||||
void OnAccessibilityDumpChildInfo(const std::vector<std::string>& params, std::vector<std::string>& info);
|
||||
void OnEnableForm(const AppExecFwk::FormJsInfo& formInfo, const bool enable);
|
||||
#ifdef OHOS_STANDARD_SYSTEM
|
||||
void ProcessFormUpdate(const AppExecFwk::FormJsInfo& formJsInfo);
|
||||
void ProcessFormUninstall(const int64_t formId);
|
||||
@ -149,6 +152,7 @@ private:
|
||||
void HandleSnapshotCallback(const uint32_t& delayTime);
|
||||
bool ParseAction(const std::string& action, const std::string& type, AAFwk::Want& want);
|
||||
void HandleCachedClickEvents();
|
||||
void HandleEnableFormCallback(const bool enable);
|
||||
|
||||
onFormAcquiredCallbackForJava onFormAcquiredCallbackForJava_;
|
||||
OnFormUpdateCallbackForJava onFormUpdateCallbackForJava_;
|
||||
@ -164,6 +168,7 @@ private:
|
||||
ActionEventHandle actionEventHandle_;
|
||||
UnTrustFormCallback unTrustFormCallback_;
|
||||
SnapshotCallback snapshotCallback_;
|
||||
EnableFormCallback enableFormCallback_;
|
||||
|
||||
State state_ { State::WAITINGFORSIZE };
|
||||
bool isDynamic_ = true;
|
||||
|
@ -30,6 +30,7 @@ build_component_ng("form_pattern_ng") {
|
||||
"form_fwk:fmskit_native",
|
||||
"form_fwk:form_manager",
|
||||
"graphic_2d:librender_service_client",
|
||||
"i18n:intl_util",
|
||||
"input:libmmi-client",
|
||||
"ipc:ipc_core",
|
||||
]
|
||||
|
@ -35,13 +35,21 @@
|
||||
#include "core/components_ng/pattern/form/form_theme.h"
|
||||
#include "core/components_ng/pattern/image/image_layout_property.h"
|
||||
#include "core/components_ng/pattern/image/image_pattern.h"
|
||||
#include "core/components_ng/pattern/text/text_pattern.h"
|
||||
#include "core/components_ng/pattern/symbol/constants.h"
|
||||
#include "core/components_ng/pattern/linear_layout/linear_layout_pattern.h"
|
||||
#include "core/components_ng/pattern/shape/rect_pattern.h"
|
||||
#include "core/components_ng/property/property.h"
|
||||
#include "core/components_ng/render/adapter/rosen_render_context.h"
|
||||
#include "core/pipeline_ng/pipeline_context.h"
|
||||
|
||||
#include "core/common/resource/resource_manager.h"
|
||||
#include "adapter/ohos/osal/resource_adapter_impl_v2.h"
|
||||
#include "base/i18n/localization.h"
|
||||
|
||||
#include "form_constants.h"
|
||||
#include "locale_info.h"
|
||||
#include "locale_config.h"
|
||||
|
||||
#if OHOS_STANDARD_SYSTEM
|
||||
#include "form_info.h"
|
||||
@ -63,6 +71,10 @@ constexpr int32_t MAX_CLICK_DURATION = 500000000; // ns
|
||||
constexpr int32_t DOUBLE = 2;
|
||||
constexpr char FORM_DIMENSION_SPLITTER = '*';
|
||||
constexpr int32_t FORM_SHAPE_CIRCLE = 2;
|
||||
constexpr Dimension TIME_LIMIT_FONT_SIZE_VAL = 18.0_fp;
|
||||
constexpr double TIME_LIMIT_TRANSPARENT_VAL = 0.3;
|
||||
constexpr int32_t TIME_LIMIT_RADIUS_SIZE = 60;
|
||||
constexpr char TIME_LIMIT_RESOURCE_NAME[] = "form_disable_time_limit";
|
||||
|
||||
class FormSnapshotCallback : public Rosen::SurfaceCaptureCallback {
|
||||
public:
|
||||
@ -264,6 +276,16 @@ void FormPattern::HandleStaticFormEvent(const PointF& touchPoint)
|
||||
}
|
||||
}
|
||||
|
||||
void FormPattern::HandleEnableForm(const bool enable)
|
||||
{
|
||||
TAG_LOGI(AceLogTag::ACE_FORM, "FormPattern::HandleEnableForm, enable = %{public}d", enable);
|
||||
if (enable) {
|
||||
RemoveDisableFormStyle();
|
||||
} else {
|
||||
LoadDisableFormStyle();
|
||||
}
|
||||
}
|
||||
|
||||
void FormPattern::TakeSurfaceCaptureForUI()
|
||||
{
|
||||
if (isFrsNodeDetached_) {
|
||||
@ -715,6 +737,70 @@ void FormPattern::UpdateFormComponentSize(const RequestFormInfo& info)
|
||||
}
|
||||
}
|
||||
|
||||
void FormPattern::RemoveDisableFormStyle()
|
||||
{
|
||||
ContainerScope scope(scopeId_);
|
||||
auto host = GetHost();
|
||||
CHECK_NULL_VOID(host);
|
||||
RefPtr<UINode> findText = FindUINodeByTag(V2::TEXT_ETS_TAG);
|
||||
RefPtr<UINode> findColumn = FindUINodeByTag(V2::COLUMN_ETS_TAG);
|
||||
if (findText && findColumn) {
|
||||
host->RemoveChild(findText);
|
||||
host->RemoveChild(findColumn);
|
||||
}
|
||||
// FormNode节点标脏;
|
||||
host->MarkModifyDone();
|
||||
host->MarkDirtyNode(PROPERTY_UPDATE_MEASURE);
|
||||
}
|
||||
|
||||
void FormPattern::LoadDisableFormStyle()
|
||||
{
|
||||
auto findColumnNode = FindUINodeByTag(V2::COLUMN_ETS_TAG);
|
||||
auto findTextNode = FindUINodeByTag(V2::TEXT_ETS_TAG);
|
||||
if (findColumnNode && findTextNode) {
|
||||
TAG_LOGI(AceLogTag::ACE_FORM, "findColumnNode && findTextNode ready exit");
|
||||
return;
|
||||
}
|
||||
TAG_LOGI(AceLogTag::ACE_FORM, "FormPattern::LoadDisableFormStyle");
|
||||
int32_t dimension = cardInfo_.dimension;
|
||||
int32_t dimensionHeight = GetFormDimensionHeight(dimension);
|
||||
if (dimensionHeight <= 0) {
|
||||
TAG_LOGE(AceLogTag::ACE_FORM, "LoadDisableFormStyle failed, invalid dimensionHeight!");
|
||||
return;
|
||||
}
|
||||
auto columnNode = CreateColumnNode();
|
||||
CHECK_NULL_VOID(columnNode);
|
||||
auto renderContext = columnNode->GetRenderContext();
|
||||
if (renderContext == nullptr) {
|
||||
TAG_LOGE(AceLogTag::ACE_FORM, "LoadDisableFormStyle(), renderContext is null");
|
||||
return;
|
||||
}
|
||||
BlurOption blurOption;
|
||||
blurOption.grayscale.assign(blurOption.grayscale.data(),
|
||||
blurOption.grayscale.data() + blurOption.grayscale.size());
|
||||
CalcDimension dimensionRadius(TIME_LIMIT_RADIUS_SIZE, DimensionUnit::PX);
|
||||
renderContext->UpdateFrontBlur(dimensionRadius, blurOption);
|
||||
if (renderContext->GetFrontBlurStyle().has_value()) {
|
||||
renderContext->UpdateFrontBlurStyle(std::nullopt);
|
||||
}
|
||||
renderContext->UpdateBackgroundColor(Color(CONTENT_BG_COLOR_DARK));
|
||||
renderContext->UpdateOpacity(TIME_LIMIT_TRANSPARENT_VAL);
|
||||
|
||||
auto textNode = CreateTimeLimitNode();
|
||||
CHECK_NULL_VOID(textNode);
|
||||
textNode->MarkModifyDone();
|
||||
textNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE);
|
||||
columnNode->MarkModifyDone();
|
||||
columnNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE);
|
||||
|
||||
auto host = GetHost();
|
||||
CHECK_NULL_VOID(host);
|
||||
auto layoutProperty = host->GetLayoutProperty<FormLayoutProperty>();
|
||||
CHECK_NULL_VOID(layoutProperty);
|
||||
auto visible = layoutProperty->GetVisibleType().value_or(VisibleType::VISIBLE);
|
||||
layoutProperty->UpdateVisibility(visible);
|
||||
}
|
||||
|
||||
void FormPattern::LoadFormSkeleton()
|
||||
{
|
||||
TAG_LOGI(AceLogTag::ACE_FORM, "LoadFormSkeleton");
|
||||
@ -737,7 +823,7 @@ void FormPattern::LoadFormSkeleton()
|
||||
std::shared_ptr<FormSkeletonParams> params = std::make_shared<FormSkeletonParams>(cardWidth,
|
||||
cardHeight, dimension, dimensionHeight, isDarkMode);
|
||||
CreateSkeletonView(columnNode, params, dimensionHeight);
|
||||
|
||||
|
||||
auto renderContext = columnNode->GetRenderContext();
|
||||
if (renderContext != nullptr) {
|
||||
BlurStyleOption styleOption;
|
||||
@ -777,6 +863,40 @@ int32_t FormPattern::GetFormDimensionHeight(int32_t dimension)
|
||||
return StringUtils::StringToInt(dimensionHeightStr);
|
||||
}
|
||||
|
||||
RefPtr<FrameNode> FormPattern::CreateTimeLimitNode()
|
||||
{
|
||||
auto host = GetHost();
|
||||
CHECK_NULL_RETURN(host, nullptr);
|
||||
|
||||
std::string content;
|
||||
GetTimeLimitResource(content);
|
||||
TAG_LOGI(AceLogTag::ACE_FORM, "GetTimeLimitContent, content = %{public}s", content.c_str());
|
||||
|
||||
auto textNode = FrameNode::CreateFrameNode(V2::TEXT_ETS_TAG,
|
||||
ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<TextPattern>());
|
||||
CHECK_NULL_RETURN(textNode, nullptr);
|
||||
auto textLayoutProperty = textNode->GetLayoutProperty<TextLayoutProperty>();
|
||||
CHECK_NULL_RETURN(textLayoutProperty, nullptr);
|
||||
|
||||
auto width = static_cast<float>(cardInfo_.width.Value()) - cardInfo_.borderWidth * DOUBLE;
|
||||
auto height = static_cast<float>(cardInfo_.height.Value()) - cardInfo_.borderWidth * DOUBLE;
|
||||
CalcSize idealSize = { CalcLength(width), CalcLength(height) };
|
||||
MeasureProperty layoutConstraint;
|
||||
layoutConstraint.selfIdealSize = idealSize;
|
||||
layoutConstraint.maxSize = idealSize;
|
||||
textNode->UpdateLayoutConstraint(layoutConstraint);
|
||||
textLayoutProperty->UpdateContent(content);
|
||||
textLayoutProperty->UpdateFontWeight(FontWeight::BOLDER);
|
||||
textLayoutProperty->UpdateFontSize(TIME_LIMIT_FONT_SIZE_VAL);
|
||||
textLayoutProperty->UpdateTextColor(Color::WHITE);
|
||||
textLayoutProperty->UpdateTextAlign(TextAlign::CENTER);
|
||||
auto externalContext = DynamicCast<NG::RosenRenderContext>(textNode->GetRenderContext());
|
||||
CHECK_NULL_RETURN(externalContext, nullptr);
|
||||
externalContext->SetVisible(true);
|
||||
host->AddChild(textNode);
|
||||
return textNode;
|
||||
}
|
||||
|
||||
void FormPattern::CreateSkeletonView(const RefPtr<FrameNode>& parent,
|
||||
const std::shared_ptr<FormSkeletonParams>& params, int32_t dimensionHeight)
|
||||
{
|
||||
@ -831,11 +951,26 @@ void FormPattern::RemoveFormSkeleton()
|
||||
}
|
||||
}
|
||||
|
||||
RefPtr<UINode> FormPattern::FindUINodeByTag(const std::string &tag)
|
||||
{
|
||||
auto host = GetHost();
|
||||
CHECK_NULL_RETURN(host, nullptr);
|
||||
std::list<RefPtr<UINode>> children = host->GetChildren();
|
||||
for (auto child : children) {
|
||||
if (child->GetTag() == tag) {
|
||||
TAG_LOGI(AceLogTag::ACE_FORM, "FindUINodeByTag Sucessful, child->GetTag() = %{public}s,",
|
||||
child->GetTag().c_str());
|
||||
return child;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
RefPtr<FrameNode> FormPattern::CreateColumnNode()
|
||||
{
|
||||
auto host = GetHost();
|
||||
CHECK_NULL_RETURN(host, nullptr);
|
||||
|
||||
|
||||
auto columnNode = FrameNode::CreateFrameNode(V2::COLUMN_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
|
||||
AceType::MakeRefPtr<LinearLayoutPattern>(true));
|
||||
CHECK_NULL_RETURN(columnNode, nullptr);
|
||||
@ -1068,6 +1203,14 @@ void FormPattern::InitFormManagerDelegate()
|
||||
CHECK_NULL_VOID(formPattern);
|
||||
formPattern->GetRectRelativeToWindow(top, left);
|
||||
});
|
||||
|
||||
formManagerBridge_->AddEnableFormCallback(
|
||||
[weak = WeakClaim(this), instanceID](const bool enable) {
|
||||
ContainerScope scope(instanceID);
|
||||
auto formPattern = weak.Upgrade();
|
||||
CHECK_NULL_VOID(formPattern);
|
||||
formPattern->HandleEnableForm(enable);
|
||||
});
|
||||
}
|
||||
|
||||
void FormPattern::GetRectRelativeToWindow(int32_t &top, int32_t &left)
|
||||
@ -1492,4 +1635,57 @@ void FormPattern::UpdateConfiguration()
|
||||
subContainer_->UpdateConfiguration();
|
||||
}
|
||||
}
|
||||
|
||||
void FormPattern::OnLanguageConfigurationUpdate()
|
||||
{
|
||||
std::string content;
|
||||
GetTimeLimitResource(content);
|
||||
TAG_LOGI(AceLogTag::ACE_FORM, "FormPattern::OnLanguageConfigurationUpdate, %{public}s", content.c_str());
|
||||
UpdateTimeLimitResource(content);
|
||||
}
|
||||
|
||||
void FormPattern::GetTimeLimitResource(std::string &content)
|
||||
{
|
||||
std::shared_ptr<Global::Resource::ResourceManager> sysResMgr(Global::Resource::CreateResourceManager());
|
||||
if (sysResMgr == nullptr) {
|
||||
TAG_LOGE(AceLogTag::ACE_FORM, "init sysMgr failed!");
|
||||
return;
|
||||
}
|
||||
std::unique_ptr<Global::Resource::ResConfig> resConfig(Global::Resource::CreateResConfig());
|
||||
if (resConfig == nullptr) {
|
||||
TAG_LOGE(AceLogTag::ACE_FORM, "init resConfig failed!");
|
||||
return;
|
||||
}
|
||||
|
||||
sysResMgr->GetResConfig(*resConfig);
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
std::string language = Global::I18n::LocaleConfig::GetSystemLanguage();
|
||||
icu::Locale locale = icu::Locale::forLanguageTag(language, status);
|
||||
if (status != U_ZERO_ERROR) {
|
||||
TAG_LOGE(AceLogTag::ACE_FORM, "forLanguageTag failed, errCode:%{public}d", status);
|
||||
return;
|
||||
}
|
||||
|
||||
resConfig->SetLocaleInfo(locale.getLanguage(), locale.getScript(), locale.getCountry());
|
||||
Global::Resource::RState state = sysResMgr->UpdateResConfig(*resConfig);
|
||||
if (state != Global::Resource::RState::SUCCESS) {
|
||||
TAG_LOGE(AceLogTag::ACE_FORM, "UpdateResConfig failed! errcode:%{public}d.", state);
|
||||
return;
|
||||
}
|
||||
sysResMgr->GetStringByName(TIME_LIMIT_RESOURCE_NAME, content);
|
||||
}
|
||||
|
||||
void FormPattern::UpdateTimeLimitResource(std::string &content)
|
||||
{
|
||||
TAG_LOGI(AceLogTag::ACE_FORM, "UpdateTimeLimitResource");
|
||||
auto host = GetHost();
|
||||
CHECK_NULL_VOID(host);
|
||||
auto findTextNode = FindUINodeByTag(V2::TEXT_ETS_TAG);
|
||||
if (findTextNode == nullptr) {
|
||||
TAG_LOGE(AceLogTag::ACE_FORM, "Not find TimeLimitTextNode");
|
||||
}
|
||||
auto textNode = AceType::DynamicCast<FrameNode>(findTextNode);
|
||||
auto textLayoutProperty = textNode->GetLayoutProperty<TextLayoutProperty>();
|
||||
textLayoutProperty->UpdateContent(content);
|
||||
}
|
||||
} // namespace OHOS::Ace::NG
|
||||
|
@ -94,6 +94,8 @@ public:
|
||||
return isJsCard_;
|
||||
}
|
||||
|
||||
RefPtr<UINode> FindUINodeByTag(const std::string &tag);
|
||||
|
||||
void SetObscured(bool isObscured)
|
||||
{
|
||||
isFormObscured_ = isObscured;
|
||||
@ -105,6 +107,11 @@ public:
|
||||
|
||||
void OnAccessibilityDumpChildInfo(const std::vector<std::string>& params, std::vector<std::string>& info);
|
||||
|
||||
void OnLanguageConfigurationUpdate() override;
|
||||
|
||||
void GetTimeLimitResource(std::string &content);
|
||||
|
||||
void UpdateTimeLimitResource(std::string &content);
|
||||
private:
|
||||
void OnAttachToFrameNode() override;
|
||||
bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, const DirtySwapConfig& config) override;
|
||||
@ -147,20 +154,24 @@ private:
|
||||
RefPtr<FrameNode> GetImageNode();
|
||||
void HandleStaticFormEvent(const PointF& touchPoint);
|
||||
void ProcDeleteImageNode(bool isRecover);
|
||||
void HandleEnableForm(const bool enable);
|
||||
|
||||
void InitClickEvent();
|
||||
void HandleTouchDownEvent(const TouchEventInfo& event);
|
||||
void HandleTouchUpEvent(const TouchEventInfo& event);
|
||||
|
||||
void LoadFormSkeleton();
|
||||
void LoadDisableFormStyle();
|
||||
void RemoveDisableFormStyle();
|
||||
int32_t GetFormDimensionHeight(int32_t dimension);
|
||||
void RemoveFormSkeleton();
|
||||
RefPtr<FrameNode> CreateColumnNode();
|
||||
RefPtr<FrameNode> CreateTimeLimitNode();
|
||||
RefPtr<FrameNode> CreateRectNode(const RefPtr<FrameNode>& parent, const CalcSize& idealSize,
|
||||
const MarginProperty& margin, uint32_t fillColor, double opacity);
|
||||
void CreateSkeletonView(const RefPtr<FrameNode>& parent, const std::shared_ptr<FormSkeletonParams>& params,
|
||||
int32_t dimensionHeight);
|
||||
|
||||
|
||||
// used by ArkTS Card, for RSSurfaceNode from FRS,
|
||||
RefPtr<RenderContext> externalRenderContext_;
|
||||
|
||||
|
@ -59,6 +59,7 @@ public:
|
||||
void OnError(const std::string& code, const std::string& msg);
|
||||
void OnSurfaceChange(float width, float height, float borderWidth = 0.0);
|
||||
void OnFormLinkInfoUpdate(const std::vector<std::string>& formLinkInfos);
|
||||
void OnEnableForm(const OHOS::AppExecFwk::FormJsInfo& formJsInfo, const bool enable);
|
||||
void UpdateConfiguration(const std::shared_ptr<OHOS::AppExecFwk::Configuration>& config);
|
||||
void AttachForm(const OHOS::AAFwk::Want& want, const OHOS::AppExecFwk::FormJsInfo& formJsInfo);
|
||||
void RecycleForm(std::string& statusData);
|
||||
|
@ -63,6 +63,8 @@ public:
|
||||
|
||||
int32_t OnGetRectRelativeToWindow(int32_t &top, int32_t &left) override;
|
||||
|
||||
int32_t OnEnableForm(const OHOS::AppExecFwk::FormJsInfo& formJsInfo, const bool enable) override;
|
||||
|
||||
void SetSurfaceCreateEventHandler(std::function<void(const std::shared_ptr<Rosen::RSSurfaceNode>&,
|
||||
const OHOS::AppExecFwk::FormJsInfo&, const AAFwk::Want&)>&& listener);
|
||||
void SetActionEventHandler(std::function<void(const std::string&)>&& listener);
|
||||
@ -71,6 +73,7 @@ public:
|
||||
void SetSurfaceDetachEventHandler(std::function<void()>&& listener);
|
||||
void SetFormLinkInfoUpdateHandler(std::function<void(const std::vector<std::string>&)>&& listener);
|
||||
void SetGetRectRelativeToWindowHandler(std::function<void(int32_t&, int32_t&)>&& listener);
|
||||
void SetEnableFormEventHandler(std::function<void(const OHOS::AppExecFwk::FormJsInfo&, const bool)>&& listener);
|
||||
|
||||
private:
|
||||
std::function<void(
|
||||
@ -82,6 +85,7 @@ private:
|
||||
std::function<void()> surfaceDetachEventHandler_;
|
||||
std::function<void(const std::vector<std::string>&)> formLinkInfoUpdateHandler_;
|
||||
std::function<void(int32_t&, int32_t&)> getRectRelativeToWindowHandler_;
|
||||
std::function<void(const OHOS::AppExecFwk::FormJsInfo&, const bool enable)> enableFormEventHandler_;
|
||||
};
|
||||
} // namespace Ace
|
||||
} // namespace OHOS
|
||||
|
@ -98,6 +98,8 @@ public:
|
||||
*/
|
||||
virtual int32_t OnGetRectRelativeToWindow(int32_t &top, int32_t &left) = 0;
|
||||
|
||||
virtual int32_t OnEnableForm(const OHOS::AppExecFwk::FormJsInfo& formJsInfo, const bool enable) {return 0;}
|
||||
|
||||
enum Message : uint32_t {
|
||||
ON_SURFACE_CREATE = 1,
|
||||
ON_SURFACE_REUSE,
|
||||
@ -107,7 +109,8 @@ public:
|
||||
ON_SURFACE_CHANGE,
|
||||
ON_FORM_LINK_INFO_UPDATE,
|
||||
ON_FORMSURFACE_DETACH,
|
||||
ON_GET_RECT_RELATIVE_TO_WINDOW
|
||||
ON_GET_RECT_RELATIVE_TO_WINDOW,
|
||||
ON_ENABLE_FORM,
|
||||
};
|
||||
};
|
||||
} // namespace Ace
|
||||
|
@ -52,6 +52,8 @@ public:
|
||||
|
||||
int32_t OnGetRectRelativeToWindow(int32_t &top, int32_t &left) override;
|
||||
|
||||
int32_t OnEnableForm(const OHOS::AppExecFwk::FormJsInfo& formJsInfo, const bool enable) override;
|
||||
|
||||
private:
|
||||
static bool WriteInterfaceToken(MessageParcel& data);
|
||||
|
||||
|
@ -53,6 +53,7 @@ private:
|
||||
int32_t HandleOnSurfaceDetach(MessageParcel& data, MessageParcel& reply);
|
||||
int32_t HandleOnFormLinkInfoUpdate(MessageParcel& data, MessageParcel& reply);
|
||||
int32_t HandleOnGetRectRelativeToWindow(MessageParcel& data, MessageParcel& reply);
|
||||
int32_t HandleOnEnableForm(MessageParcel& data, MessageParcel& reply);
|
||||
|
||||
using FormRendererDelegateFunc = int32_t (FormRendererDelegateStub::*)(MessageParcel& data, MessageParcel& reply);
|
||||
std::map<uint32_t, FormRendererDelegateFunc> memberFuncMap_;
|
||||
|
@ -81,6 +81,7 @@ public:
|
||||
bool IsFormRequestsEmpty();
|
||||
const std::vector<FormRequest>& GetAllRendererFormRequests() const;
|
||||
void RecycleForm(std::string& statusData) const;
|
||||
void EnableForm(const AppExecFwk::FormJsInfo& formJsInfo, const bool enable);
|
||||
private:
|
||||
enum class FormRendererInitState {
|
||||
UNINITIALIZED,
|
||||
|
@ -358,6 +358,15 @@ void FormRenderer::OnFormLinkInfoUpdate(const std::vector<std::string>& formLink
|
||||
formRendererDelegate_->OnFormLinkInfoUpdate(formLinkInfos);
|
||||
}
|
||||
|
||||
void FormRenderer::OnEnableForm(const OHOS::AppExecFwk::FormJsInfo& formJsInfo, const bool enable)
|
||||
{
|
||||
if (!formRendererDelegate_) {
|
||||
HILOG_ERROR("formRendererDelegate is null!");
|
||||
return;
|
||||
}
|
||||
formRendererDelegate_->OnEnableForm(formJsInfo, enable);
|
||||
}
|
||||
|
||||
void FormRenderer::SetRenderDelegate(const sptr<IRemoteObject>& remoteObj)
|
||||
{
|
||||
HILOG_INFO("Get renderRemoteObj, add death recipient.");
|
||||
|
@ -109,6 +109,18 @@ int32_t FormRendererDelegateImpl::OnGetRectRelativeToWindow(int32_t &top, int32_
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
int32_t FormRendererDelegateImpl::OnEnableForm(
|
||||
const OHOS::AppExecFwk::FormJsInfo& formJsInfo, const bool enable)
|
||||
{
|
||||
HILOG_DEBUG("FormRendererDelegateImpl::OnEnableForm");
|
||||
if (!enableFormEventHandler_) {
|
||||
HILOG_ERROR("enableFormEventHandler_ is null");
|
||||
return ERR_INVALID_DATA;
|
||||
}
|
||||
enableFormEventHandler_(formJsInfo, enable);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
void FormRendererDelegateImpl::SetSurfaceCreateEventHandler(
|
||||
std::function<void(const std::shared_ptr<Rosen::RSSurfaceNode>&, const OHOS::AppExecFwk::FormJsInfo&,
|
||||
const AAFwk::Want&)>&& listener)
|
||||
@ -148,5 +160,11 @@ void FormRendererDelegateImpl::SetGetRectRelativeToWindowHandler(std::function<v
|
||||
{
|
||||
getRectRelativeToWindowHandler_ = std::move(listener);
|
||||
}
|
||||
|
||||
void FormRendererDelegateImpl::SetEnableFormEventHandler(std::function<void(
|
||||
const OHOS::AppExecFwk::FormJsInfo&, const bool enable)>&& listener)
|
||||
{
|
||||
enableFormEventHandler_ = std::move(listener);
|
||||
}
|
||||
} // namespace Ace
|
||||
} // namespace OHOS
|
||||
|
@ -296,6 +296,40 @@ int32_t FormRendererDelegateProxy::OnGetRectRelativeToWindow(int32_t &top, int32
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
int32_t FormRendererDelegateProxy::OnEnableForm(
|
||||
const OHOS::AppExecFwk::FormJsInfo& formJsInfo, const bool enable)
|
||||
{
|
||||
MessageParcel data;
|
||||
if (!WriteInterfaceToken(data)) {
|
||||
HILOG_ERROR("%{public}s, failed to write interface token", __func__);
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
if (!data.WriteParcelable(&formJsInfo)) {
|
||||
HILOG_ERROR("%{public}s fail, write formJsInfo error", __func__);
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
if (!data.WriteBool(enable)) {
|
||||
HILOG_ERROR("%{public}s fail, write enable error", __func__);
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
auto remoteProxy = Remote();
|
||||
if (!remoteProxy) {
|
||||
HILOG_ERROR("Send surfaceNode failed, ipc remoteObj is null");
|
||||
return IPC_PROXY_ERR;
|
||||
}
|
||||
int32_t error = remoteProxy->SendRequest(
|
||||
static_cast<uint32_t>(IFormRendererDelegate::Message::ON_ENABLE_FORM), data, reply, option);
|
||||
if (error != NO_ERROR) {
|
||||
HILOG_ERROR("%{public}s, failed to SendRequest: %{public}d", __func__, error);
|
||||
return error;
|
||||
}
|
||||
|
||||
return reply.ReadInt32();
|
||||
}
|
||||
|
||||
bool FormRendererDelegateProxy::WriteInterfaceToken(MessageParcel& data)
|
||||
{
|
||||
if (!data.WriteInterfaceToken(FormRendererDelegateProxy::GetDescriptor())) {
|
||||
|
@ -41,6 +41,8 @@ FormRendererDelegateStub::FormRendererDelegateStub()
|
||||
&FormRendererDelegateStub::HandleOnSurfaceDetach;
|
||||
memberFuncMap_[static_cast<uint32_t>(IFormRendererDelegate::Message::ON_GET_RECT_RELATIVE_TO_WINDOW)] =
|
||||
&FormRendererDelegateStub::HandleOnGetRectRelativeToWindow;
|
||||
memberFuncMap_[static_cast<uint32_t>(IFormRendererDelegate::Message::ON_ENABLE_FORM)] =
|
||||
&FormRendererDelegateStub::HandleOnEnableForm;
|
||||
}
|
||||
|
||||
FormRendererDelegateStub::~FormRendererDelegateStub()
|
||||
@ -210,5 +212,18 @@ int32_t FormRendererDelegateStub::HandleOnGetRectRelativeToWindow(MessageParcel&
|
||||
reply.WriteInt32(left);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
int32_t FormRendererDelegateStub::HandleOnEnableForm(MessageParcel& data, MessageParcel& reply)
|
||||
{
|
||||
std::unique_ptr<AppExecFwk::FormJsInfo> formJsInfo(data.ReadParcelable<AppExecFwk::FormJsInfo>());
|
||||
if (formJsInfo == nullptr) {
|
||||
HILOG_ERROR("formJsInfo is nullptr");
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
bool enable = data.ReadBool();
|
||||
int32_t errCode = OnEnableForm(*formJsInfo, enable);
|
||||
reply.WriteInt32(errCode);
|
||||
return ERR_OK;
|
||||
}
|
||||
} // namespace Ace
|
||||
} // namespace OHOS
|
||||
|
@ -247,5 +247,14 @@ void FormRendererGroup::RecycleForm(std::string& statusData) const
|
||||
}
|
||||
formRenderer_->RecycleForm(statusData);
|
||||
}
|
||||
|
||||
void FormRendererGroup::EnableForm(const AppExecFwk::FormJsInfo& formJsInfo, const bool enable)
|
||||
{
|
||||
if (formRenderer_ == nullptr) {
|
||||
HILOG_ERROR("EnableForm failed, formRenderer is null");
|
||||
return;
|
||||
}
|
||||
formRenderer_->OnEnableForm(formJsInfo, enable);
|
||||
}
|
||||
} // namespace Ace
|
||||
} // namespace OHOS
|
||||
|
@ -41,6 +41,7 @@ ace_unittest("form_test_ng") {
|
||||
"form_fwk:fmskit_native",
|
||||
"form_fwk:form_manager",
|
||||
"graphic_2d:librender_service_client",
|
||||
"i18n:intl_util",
|
||||
"input:libmmi-client",
|
||||
]
|
||||
}
|
||||
|
@ -84,6 +84,8 @@ void FormManagerDelegate::AddGetRectRelativeToWindowCallback(OnGetRectRelativeTo
|
||||
|
||||
void FormManagerDelegate::AddSnapshotCallback(SnapshotCallback&& callback) {}
|
||||
|
||||
void FormManagerDelegate::AddEnableFormCallback(EnableFormCallback&& callback) {}
|
||||
|
||||
void FormManagerDelegate::ResetForm() {}
|
||||
|
||||
void FormManagerDelegate::ReleaseForm() {}
|
||||
|
Loading…
Reference in New Issue
Block a user