1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef FOUNDATION_ACE_INTERFACE_INNERKITS_FORM_RENDERER_H 17 #define FOUNDATION_ACE_INTERFACE_INNERKITS_FORM_RENDERER_H 18 19 #include "ability_context.h" 20 #include "form_js_info.h" 21 #include "form_renderer_delegate_interface.h" 22 #include "form_renderer_dispatcher_impl.h" 23 #include "js_runtime.h" 24 #include "runtime.h" 25 #include "ui_content.h" 26 #include "event_handler.h" 27 #include "form_constants.h" 28 #include "core/accessibility/accessibility_manager.h" 29 30 namespace OHOS { 31 namespace AppExecFwk { 32 class Configuration; 33 class EventHandler; 34 } 35 namespace Ace { 36 /** 37 * @class FormRenderer 38 */ 39 class FormRenderer : public std::enable_shared_from_this<FormRenderer> { 40 public: 41 FormRenderer(const std::shared_ptr<OHOS::AbilityRuntime::Context> context, 42 const std::shared_ptr<OHOS::AbilityRuntime::Runtime> runtime, 43 std::weak_ptr<OHOS::AppExecFwk::EventHandler> eventHandler); 44 ~FormRenderer(); 45 46 void AddForm(const OHOS::AAFwk::Want& want, const OHOS::AppExecFwk::FormJsInfo& formJsInfo); 47 void PreInitAddForm(const OHOS::AAFwk::Want& want, const OHOS::AppExecFwk::FormJsInfo& formJsInfo); 48 void RunFormPage(const OHOS::AAFwk::Want& want, const OHOS::AppExecFwk::FormJsInfo& formJsInfo); 49 void UpdateForm(const OHOS::AppExecFwk::FormJsInfo& formJsInfo); 50 void ReloadForm(const std::string& url); 51 void Destroy(); 52 void ResetRenderDelegate(); 53 void SetAllowUpdate(bool allowUpdate); 54 bool IsAllowUpdate(); 55 56 void OnSurfaceCreate(const OHOS::AppExecFwk::FormJsInfo& formJsInfo, bool isRecoverFormToHandleClickEvent); 57 void OnSurfaceReuse(const OHOS::AppExecFwk::FormJsInfo& formJsInfo); 58 void OnSurfaceDetach(); 59 void OnActionEvent(const std::string& action); 60 void OnError(const std::string& code, const std::string& msg); 61 void OnSurfaceChange(float width, float height, float borderWidth = 0.0); 62 void OnFormLinkInfoUpdate(const std::vector<std::string>& formLinkInfos); 63 void UpdateConfiguration(const std::shared_ptr<OHOS::AppExecFwk::Configuration>& config); 64 void AttachForm(const OHOS::AAFwk::Want& want, const OHOS::AppExecFwk::FormJsInfo& formJsInfo); 65 void RecycleForm(std::string& statusData); 66 void RecoverForm(const std::string& statusData); 67 void GetRectRelativeToWindow(AccessibilityParentRectInfo& parentRectInfo) const; 68 void SetVisibleChange(bool isVisible); 69 void UpdateFormSize(float width, float height, float borderWidth); 70 bool IsManagerDelegateValid(const OHOS::AAFwk::Want& want); 71 72 private: 73 void InitUIContent(const OHOS::AAFwk::Want& want, const OHOS::AppExecFwk::FormJsInfo& formJsInfo); 74 void ParseWant(const OHOS::AAFwk::Want& want); 75 void SetRenderDelegate(const sptr<IRemoteObject>& renderRemoteObj); 76 void AttachUIContent(const OHOS::AAFwk::Want& want, const OHOS::AppExecFwk::FormJsInfo& formJsInfo); 77 void PreInitUIContent(const OHOS::AAFwk::Want& want, const OHOS::AppExecFwk::FormJsInfo& formJsInfo); 78 void RunFormPageInner(const OHOS::AAFwk::Want& want, const OHOS::AppExecFwk::FormJsInfo& formJsInfo); 79 void RemoveFormDeathRecipient(); 80 81 bool allowUpdate_ = true; 82 bool obscurationMode_ = false; 83 float width_ = 0.0f; 84 float height_ = 0.0f; 85 float borderWidth_ = 0.0f; 86 float lastBorderWidth_ = 0.0f; 87 bool fontScaleFollowSystem_ = true; 88 std::string backgroundColor_; 89 AppExecFwk::Constants::RenderingMode renderingMode_ = AppExecFwk::Constants::RenderingMode::FULL_COLOR; 90 bool enableBlurBackground_ = false; 91 std::vector<std::string> cachedInfos_; 92 std::shared_ptr<OHOS::AbilityRuntime::Context> context_; 93 std::shared_ptr<OHOS::AbilityRuntime::Runtime> runtime_; 94 std::weak_ptr<OHOS::AppExecFwk::EventHandler> eventHandler_; 95 sptr<FormRendererDispatcherImpl> formRendererDispatcherImpl_; 96 sptr<IFormRendererDelegate> formRendererDelegate_; 97 std::shared_ptr<UIContent> uiContent_; 98 sptr<IRemoteObject::DeathRecipient> renderDelegateDeathRecipient_; 99 sptr<IRemoteObject> proxy_; 100 }; 101 102 /** 103 * @class FormRenderDelegateRecipient 104 * FormRenderDelegateRecipient notices IRemoteBroker died. 105 */ 106 class FormRenderDelegateRecipient : public IRemoteObject::DeathRecipient { 107 public: 108 using RemoteDiedHandler = std::function<void()>; FormRenderDelegateRecipient(RemoteDiedHandler handler)109 explicit FormRenderDelegateRecipient(RemoteDiedHandler handler) : handler_(std::move(handler)) {} 110 111 ~FormRenderDelegateRecipient() override = default; 112 113 void OnRemoteDied(const wptr<IRemoteObject>& remote) override; 114 115 private: 116 RemoteDiedHandler handler_; 117 }; 118 } // namespace Ace 119 } // namespace OHOS 120 #endif // FOUNDATION_ACE_INTERFACE_INNERKITS_FORM_RENDERER_H 121