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 29 namespace OHOS { 30 namespace AppExecFwk { 31 class Configuration; 32 class EventHandler; 33 } 34 namespace Ace { 35 /** 36 * @class FormRenderer 37 */ 38 class FormRenderer : public std::enable_shared_from_this<FormRenderer> { 39 public: 40 FormRenderer(const std::shared_ptr<OHOS::AbilityRuntime::Context> context, 41 const std::shared_ptr<OHOS::AbilityRuntime::Runtime> runtime, 42 std::weak_ptr<OHOS::AppExecFwk::EventHandler> eventHandler); 43 ~FormRenderer(); 44 45 void AddForm(const OHOS::AAFwk::Want& want, const OHOS::AppExecFwk::FormJsInfo& formJsInfo); 46 void PreInitAddForm(const OHOS::AAFwk::Want& want, const OHOS::AppExecFwk::FormJsInfo& formJsInfo); 47 void RunFormPage(const OHOS::AAFwk::Want& want, const OHOS::AppExecFwk::FormJsInfo& formJsInfo); 48 void UpdateForm(const OHOS::AppExecFwk::FormJsInfo& formJsInfo); 49 void ReloadForm(const std::string& url); 50 void Destroy(); 51 void ResetRenderDelegate(); 52 void SetAllowUpdate(bool allowUpdate); 53 bool IsAllowUpdate(); 54 55 void OnSurfaceCreate(const OHOS::AppExecFwk::FormJsInfo& formJsInfo, bool isRecoverFormToHandleClickEvent); 56 void OnSurfaceReuse(const OHOS::AppExecFwk::FormJsInfo& formJsInfo); 57 void OnSurfaceDetach(); 58 void OnActionEvent(const std::string& action); 59 void OnError(const std::string& code, const std::string& msg); 60 void OnSurfaceChange(float width, float height, float borderWidth = 0.0); 61 void OnFormLinkInfoUpdate(const std::vector<std::string>& formLinkInfos); 62 void UpdateConfiguration(const std::shared_ptr<OHOS::AppExecFwk::Configuration>& config); 63 void AttachForm(const OHOS::AAFwk::Want& want, const OHOS::AppExecFwk::FormJsInfo& formJsInfo); 64 void RecycleForm(std::string& statusData); 65 void RecoverForm(const std::string& statusData); 66 void GetRectRelativeToWindow(int32_t &top, int32_t &left) const; 67 void SetVisibleChange(bool isVisible); 68 69 private: 70 void InitUIContent(const OHOS::AAFwk::Want& want, const OHOS::AppExecFwk::FormJsInfo& formJsInfo); 71 void ParseWant(const OHOS::AAFwk::Want& want); 72 void SetRenderDelegate(const sptr<IRemoteObject>& renderRemoteObj); 73 void AttachUIContent(const OHOS::AAFwk::Want& want, const OHOS::AppExecFwk::FormJsInfo& formJsInfo); 74 void PreInitUIContent(const OHOS::AAFwk::Want& want, const OHOS::AppExecFwk::FormJsInfo& formJsInfo); 75 void RunFormPageInner(const OHOS::AAFwk::Want& want, const OHOS::AppExecFwk::FormJsInfo& formJsInfo); 76 77 bool allowUpdate_ = true; 78 bool obscurationMode_ = false; 79 float width_ = 0.0f; 80 float height_ = 0.0f; 81 float borderWidth_ = 0.0f; 82 float lastBorderWidth_ = 0.0f; 83 bool fontScaleFollowSystem_ = true; 84 std::string backgroundColor_; 85 AppExecFwk::Constants::RenderingMode renderingMode_ = AppExecFwk::Constants::RenderingMode::FULL_COLOR; 86 std::vector<std::string> cachedInfos_; 87 std::shared_ptr<OHOS::AbilityRuntime::Context> context_; 88 std::shared_ptr<OHOS::AbilityRuntime::Runtime> runtime_; 89 std::weak_ptr<OHOS::AppExecFwk::EventHandler> eventHandler_; 90 sptr<FormRendererDispatcherImpl> formRendererDispatcherImpl_; 91 sptr<IFormRendererDelegate> formRendererDelegate_; 92 std::shared_ptr<UIContent> uiContent_; 93 sptr<IRemoteObject::DeathRecipient> renderDelegateDeathRecipient_; 94 sptr<IRemoteObject> proxy_; 95 }; 96 97 /** 98 * @class FormRenderDelegateRecipient 99 * FormRenderDelegateRecipient notices IRemoteBroker died. 100 */ 101 class FormRenderDelegateRecipient : public IRemoteObject::DeathRecipient { 102 public: 103 using RemoteDiedHandler = std::function<void()>; FormRenderDelegateRecipient(RemoteDiedHandler handler)104 explicit FormRenderDelegateRecipient(RemoteDiedHandler handler) : handler_(std::move(handler)) {} 105 106 ~FormRenderDelegateRecipient() override = default; 107 108 void OnRemoteDied(const wptr<IRemoteObject>& remote) override; 109 110 private: 111 RemoteDiedHandler handler_; 112 }; 113 } // namespace Ace 114 } // namespace OHOS 115 #endif // FOUNDATION_ACE_INTERFACE_INNERKITS_FORM_RENDERER_H 116