1 /* 2 * Copyright (c) 2021-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_FRAMEWORKS_CORE_COMMON_ACE_VIEW_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_ACE_VIEW_H 18 19 #include <chrono> 20 21 #include "base/memory/ace_type.h" 22 #include "base/resource/asset_manager.h" 23 #include "base/utils/noncopyable.h" 24 #include "core/common/container.h" 25 #include "core/common/draw_delegate.h" 26 #include "core/common/platform_res_register.h" 27 #include "core/common/platform_window.h" 28 29 namespace OHOS::Rosen { 30 class RSTransaction; 31 } 32 33 namespace OHOS::Ace { 34 35 class AceView : public AceType { 36 DECLARE_ACE_TYPE(AceView, AceType); 37 38 public: 39 enum class ViewType : int32_t { 40 SURFACE_VIEW = 0, 41 NATIVE_VIEW, 42 AGP_COMPONENT, 43 }; 44 45 AceView() = default; 46 virtual ~AceView() = default; 47 QueryIfWindowInScreen()48 virtual bool QueryIfWindowInScreen() 49 { 50 return true; 51 } RegisterScreenBroadcast()52 virtual void RegisterScreenBroadcast() {} 53 virtual void RegisterTouchEventCallback(TouchEventCallback&& callback) = 0; 54 virtual void RegisterDragEventCallback(DragEventCallBack&& callback) = 0; 55 virtual void RegisterKeyEventCallback(KeyEventCallback&& callback) = 0; 56 virtual void RegisterNonPointerEventCallback(NonPointerEventCallback&& callback) = 0; 57 virtual void RegisterMouseEventCallback(MouseEventCallback&& callback) = 0; 58 virtual void RegisterAxisEventCallback(AxisEventCallback&& callback) = 0; 59 virtual void RegisterRotationEventCallback(RotationEventCallBack&& callback) = 0; 60 virtual void RegisterCardViewPositionCallback(CardViewPositionCallBack&& callback) = 0; 61 virtual void Launch() = 0; 62 virtual int32_t GetInstanceId() const = 0; 63 virtual const RefPtr<PlatformResRegister>& GetPlatformResRegister() const = 0; 64 65 using CardViewAccessibilityParamsCallback = std::function<void(const std::string& key, bool focus)>; 66 virtual void RegisterCardViewAccessibilityParamsCallback(CardViewAccessibilityParamsCallback&& callback) = 0; 67 68 using ViewChangeCallback = std::function<void(int32_t width, int32_t height, 69 WindowSizeChangeReason type, const std::shared_ptr<Rosen::RSTransaction>& rsTransaction)>; 70 virtual void RegisterViewChangeCallback(ViewChangeCallback&& callback) = 0; 71 72 using ViewPositionChangeCallback = std::function<void(int32_t posX, int32_t posY)>; 73 virtual void RegisterViewPositionChangeCallback(ViewPositionChangeCallback&& callback) = 0; 74 75 using DensityChangeCallback = std::function<void(double density)>; 76 virtual void RegisterDensityChangeCallback(DensityChangeCallback&& callback) = 0; 77 78 using TransformHintChangeCallback = std::function<void(uint32_t transform)>; 79 virtual void RegisterTransformHintChangeCallback(TransformHintChangeCallback&& callback) = 0; 80 81 using SystemBarHeightChangeCallback = std::function<void(double statusBar, double navigationBar)>; 82 virtual void RegisterSystemBarHeightChangeCallback(SystemBarHeightChangeCallback&& callback) = 0; 83 84 using SurfaceDestroyCallback = std::function<void()>; 85 virtual void RegisterSurfaceDestroyCallback(SurfaceDestroyCallback&& callback) = 0; 86 87 using IdleCallback = std::function<void(int64_t)>; 88 virtual void RegisterIdleCallback(IdleCallback&& callback) = 0; 89 90 using PreDrawCallback = std::function<void()>; RegisterPreDrawCallback(PreDrawCallback && callback)91 virtual void RegisterPreDrawCallback(PreDrawCallback&& callback) {} 92 93 using RequestFrameCallback = std::function<void()>; RegisterRequestFrameCallback(RequestFrameCallback && callback)94 virtual void RegisterRequestFrameCallback(RequestFrameCallback&& callback) {} 95 96 virtual bool Dump(const std::vector<std::string>& params) = 0; 97 98 // Use to receive event from pc previewer HandleTouchEvent(const TouchEvent & touchEvent)99 virtual bool HandleTouchEvent(const TouchEvent& touchEvent) 100 { 101 return false; 102 } 103 // Use to receive key event from pc previewer HandleKeyEvent(const KeyEvent & keyEvent)104 virtual bool HandleKeyEvent(const KeyEvent& keyEvent) 105 { 106 return false; 107 } 108 // Use to get native window handle by texture id 109 virtual const void* GetNativeWindowById(uint64_t textureId) = 0; 110 111 virtual ViewType GetViewType() const = 0; 112 virtual std::unique_ptr<DrawDelegate> GetDrawDelegate() = 0; 113 virtual std::unique_ptr<PlatformWindow> GetPlatformWindow() = 0; UpdateWindowBlurRegion(const std::vector<std::vector<float>> & blurRRects)114 virtual void UpdateWindowBlurRegion(const std::vector<std::vector<float>>& blurRRects) {} UpdateWindowblurDrawOp()115 virtual void UpdateWindowblurDrawOp() {} StartSystemDrag(const std::string & str,void * pixelMapManager,int32_t byteCount)116 virtual void StartSystemDrag(const std::string& str, void* pixelMapManager, int32_t byteCount) {} InitDragListener()117 virtual void InitDragListener() {} 118 #ifdef WEARABLE_PRODUCT CloseSwipeToRight(bool isEnabled)119 virtual void CloseSwipeToRight(bool isEnabled) {} 120 #endif GetScale(float & scaleX,float & scaleY)121 virtual bool GetScale(float& scaleX, float& scaleY) 122 { 123 return false; 124 } 125 SetBackgroundColor(const Color & color)126 void SetBackgroundColor(const Color& color) 127 { 128 backgroundColor_ = color; 129 if (!hasSet_) { 130 promise_.set_value(true); 131 } 132 } 133 GetBackgroundColor()134 const Color& GetBackgroundColor() 135 { 136 if (!hasSet_) { 137 hasSet_ = future_.get(); 138 } 139 return backgroundColor_; 140 } 141 SetCachePath(const std::string & cachePath)142 void SetCachePath(const std::string& cachePath) 143 { 144 cachePath_ = cachePath; 145 } 146 GetCachePath()147 const std::string& GetCachePath() 148 { 149 return cachePath_; 150 } 151 SetCreateTime(std::chrono::time_point<std::chrono::high_resolution_clock> time)152 void SetCreateTime(std::chrono::time_point<std::chrono::high_resolution_clock> time) 153 { 154 createTime_ = time; 155 } 156 SetFirstUpDating(std::chrono::time_point<std::chrono::high_resolution_clock> time)157 void SetFirstUpDating(std::chrono::time_point<std::chrono::high_resolution_clock> time) 158 { 159 firstUpdating_ = true; 160 firstUpdateBegin_ = time; 161 } 162 SetSessionID(const std::string & sessionID)163 void SetSessionID(const std::string& sessionID) 164 { 165 sessionID_ = sessionID; 166 } 167 GetWidth()168 int32_t GetWidth() const 169 { 170 return width_; 171 } 172 GetHeight()173 int32_t GetHeight() const 174 { 175 return height_; 176 } 177 GetPosX()178 int32_t GetPosX() const 179 { 180 return posX_; 181 } 182 GetPosY()183 int32_t GetPosY() const 184 { 185 return posY_; 186 } 187 188 protected: 189 std::chrono::time_point<std::chrono::high_resolution_clock> createTime_; 190 std::chrono::time_point<std::chrono::high_resolution_clock> firstUpdateBegin_; 191 std::string sessionID_; 192 bool firstUpdating_ = false; 193 int32_t width_ = 0; 194 int32_t height_ = 0; 195 int32_t posX_ = 0; 196 int32_t posY_ = 0; 197 uint32_t transform_ = 0; 198 199 private: 200 std::mutex backgroundColorMutex_; 201 Color backgroundColor_; 202 std::string cachePath_; 203 std::promise<bool> promise_; 204 std::shared_future<bool> future_ = promise_.get_future(); 205 bool hasSet_ = false; 206 207 ACE_DISALLOW_COPY_AND_MOVE(AceView); 208 }; 209 210 } // namespace OHOS::Ace 211 212 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_ACE_VIEW_H 213