1 /* 2 * Copyright (c) 2021-2022 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_ACE_UI_CONTENT_H 17 #define FOUNDATION_ACE_INTERFACE_INNERKITS_ACE_UI_CONTENT_H 18 19 #include <map> 20 #include <memory> 21 #include <string> 22 23 #include "viewport_config.h" 24 #include "foundation/multimedia/image_framework/interfaces/innerkits/include/pixel_map.h" 25 26 namespace OHOS { 27 28 namespace AbilityRuntime { 29 class Context; 30 } 31 32 namespace AppExecFwk { 33 class Configuration; 34 class Ability; 35 class FormAshmem; 36 } 37 38 namespace Rosen { 39 class Window; 40 enum class WindowSizeChangeReason : uint32_t; 41 enum class WindowMode : uint32_t; 42 class RSSurfaceNode; 43 } 44 45 namespace AAFwk { 46 class Want; 47 } 48 49 namespace MMI { 50 class PointerEvent; 51 class KeyEvent; 52 class AxisEvent; 53 } // namespace MMI 54 55 } // namespace OHOS 56 57 class NativeEngine; 58 class NativeValue; 59 60 namespace OHOS::Ace { 61 62 #ifndef ACE_EXPORT 63 #define ACE_EXPORT __attribute__((visibility("default"))) 64 #endif 65 66 class ACE_EXPORT UIContent { 67 public: 68 static std::unique_ptr<UIContent> Create(OHOS::AbilityRuntime::Context* context, NativeEngine* runtime, 69 bool isFormRender); 70 static std::unique_ptr<UIContent> Create(OHOS::AbilityRuntime::Context* context, NativeEngine* runtime); 71 static std::unique_ptr<UIContent> Create(OHOS::AppExecFwk::Ability* ability); 72 static void ShowDumpHelp(std::vector<std::string>& info); 73 74 virtual ~UIContent() = default; 75 76 // UI content life-cycles 77 virtual void Initialize(OHOS::Rosen::Window* window, const std::string& url, NativeValue* storage) = 0; 78 virtual void Foreground() = 0; 79 virtual void Background() = 0; 80 virtual void Focus() = 0; 81 virtual void UnFocus() = 0; 82 virtual void Destroy() = 0; 83 virtual void OnNewWant(const OHOS::AAFwk::Want& want) = 0; 84 85 // distribute 86 virtual void Restore(OHOS::Rosen::Window* window, const std::string& contentInfo, NativeValue* storage) = 0; 87 virtual std::string GetContentInfo() const = 0; 88 virtual void DestroyUIDirector() = 0; 89 90 // UI content event process 91 virtual bool ProcessBackPressed() = 0; 92 virtual bool ProcessPointerEvent(const std::shared_ptr<OHOS::MMI::PointerEvent>& pointerEvent) = 0; 93 virtual bool ProcessKeyEvent(const std::shared_ptr<OHOS::MMI::KeyEvent>& keyEvent) = 0; 94 virtual bool ProcessAxisEvent(const std::shared_ptr<OHOS::MMI::AxisEvent>& axisEvent) = 0; 95 virtual bool ProcessVsyncEvent(uint64_t timeStampNanos) = 0; 96 virtual void UpdateConfiguration(const std::shared_ptr<OHOS::AppExecFwk::Configuration>& config) = 0; 97 virtual void UpdateViewportConfig(const ViewportConfig& config, OHOS::Rosen::WindowSizeChangeReason reason) = 0; 98 virtual void UpdateWindowMode(OHOS::Rosen::WindowMode mode) = 0; 99 virtual void HideWindowTitleButton(bool hideSplit, bool hideMaximize, bool hideMinimize) = 0; 100 101 // Window color 102 virtual uint32_t GetBackgroundColor() = 0; 103 virtual void SetBackgroundColor(uint32_t color) = 0; 104 105 virtual void DumpInfo(const std::vector<std::string>& params, std::vector<std::string>& info) = 0; 106 107 // Set UIContent callback for custom window animation 108 virtual void SetNextFrameLayoutCallback(std::function<void()>&& callback) = 0; 109 110 // Receive memory level notification 111 virtual void NotifyMemoryLevel(int32_t level) = 0; 112 113 virtual void SetAppWindowTitle(const std::string& title) = 0; 114 virtual void SetAppWindowIcon(const std::shared_ptr<Media::PixelMap>& pixelMap) = 0; 115 116 // ArkTS Form 117 virtual std::shared_ptr<Rosen::RSSurfaceNode> GetFormRootNode() = 0; 118 119 virtual void UpdateFormData(const std::string& data) = 0; UpdateFormSharedImage(const std::map<std::string,sptr<OHOS::AppExecFwk::FormAshmem>> & imageDataMap)120 virtual void UpdateFormSharedImage( 121 const std::map<std::string, sptr<OHOS::AppExecFwk::FormAshmem>>& imageDataMap) {} 122 123 virtual void SetFormWidth(const float width) = 0; 124 virtual void SetFormHeight(const float height) = 0; 125 virtual float GetFormWidth() = 0; 126 virtual float GetFormHeight() = 0; ReloadForm()127 virtual void ReloadForm() {}; OnFormSurfaceChange(float width,float height)128 virtual void OnFormSurfaceChange(float width, float height) {} 129 130 virtual void SetActionEventHandler(std::function<void(const std::string&)>&& actionCallback) = 0; 131 virtual void SetErrorEventHandler(std::function<void(const std::string&, const std::string&)>&& errorCallback) = 0; 132 }; 133 134 } // namespace OHOS::Ace 135 136 #endif // FOUNDATION_ACE_INTERFACE_INNERKITS_ACE_UI_CONTENT_H 137