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 RegisterCrownEventCallback(CrownEventCallback&& callback) = 0; 62 virtual void Launch() = 0; 63 virtual int32_t GetInstanceId() const = 0; 64 virtual const RefPtr<PlatformResRegister>& GetPlatformResRegister() const = 0; 65 66 using CardViewAccessibilityParamsCallback = std::function<void(const std::string& key, bool focus)>; 67 virtual void RegisterCardViewAccessibilityParamsCallback(CardViewAccessibilityParamsCallback&& callback) = 0; 68 69 using ViewChangeCallback = std::function<void(int32_t width, int32_t height, 70 WindowSizeChangeReason type, const std::shared_ptr<Rosen::RSTransaction>& rsTransaction)>; 71 virtual void RegisterViewChangeCallback(ViewChangeCallback&& callback) = 0; 72 73 using ViewPositionChangeCallback = std::function<void(int32_t posX, int32_t posY)>; 74 virtual void RegisterViewPositionChangeCallback(ViewPositionChangeCallback&& callback) = 0; 75 76 using DensityChangeCallback = std::function<void(double density)>; 77 virtual void RegisterDensityChangeCallback(DensityChangeCallback&& callback) = 0; 78 79 using TransformHintChangeCallback = std::function<void(uint32_t transform)>; 80 virtual void RegisterTransformHintChangeCallback(TransformHintChangeCallback&& callback) = 0; 81 82 using SystemBarHeightChangeCallback = std::function<void(double statusBar, double navigationBar)>; 83 virtual void RegisterSystemBarHeightChangeCallback(SystemBarHeightChangeCallback&& callback) = 0; 84 85 using SurfaceDestroyCallback = std::function<void()>; 86 virtual void RegisterSurfaceDestroyCallback(SurfaceDestroyCallback&& callback) = 0; 87 88 using IdleCallback = std::function<void(int64_t)>; 89 virtual void RegisterIdleCallback(IdleCallback&& callback) = 0; 90 91 using PreDrawCallback = std::function<void()>; RegisterPreDrawCallback(PreDrawCallback && callback)92 virtual void RegisterPreDrawCallback(PreDrawCallback&& callback) {} 93 94 using RequestFrameCallback = std::function<void()>; RegisterRequestFrameCallback(RequestFrameCallback && callback)95 virtual void RegisterRequestFrameCallback(RequestFrameCallback&& callback) {} 96 97 virtual bool Dump(const std::vector<std::string>& params) = 0; 98 99 // Use to receive event from pc previewer HandleTouchEvent(const TouchEvent & touchEvent)100 virtual bool HandleTouchEvent(const TouchEvent& touchEvent) 101 { 102 return false; 103 } 104 // Use to receive key event from pc previewer HandleKeyEvent(const KeyEvent & keyEvent)105 virtual bool HandleKeyEvent(const KeyEvent& keyEvent) 106 { 107 return false; 108 } 109 // Use to get native window handle by texture id 110 virtual const void* GetNativeWindowById(uint64_t textureId) = 0; 111 112 virtual ViewType GetViewType() const = 0; 113 virtual std::unique_ptr<DrawDelegate> GetDrawDelegate() = 0; 114 virtual std::unique_ptr<PlatformWindow> GetPlatformWindow() = 0; UpdateWindowBlurRegion(const std::vector<std::vector<float>> & blurRRects)115 virtual void UpdateWindowBlurRegion(const std::vector<std::vector<float>>& blurRRects) {} UpdateWindowblurDrawOp()116 virtual void UpdateWindowblurDrawOp() {} StartSystemDrag(const std::string & str,void * pixelMapManager,int32_t byteCount)117 virtual void StartSystemDrag(const std::string& str, void* pixelMapManager, int32_t byteCount) {} InitDragListener()118 virtual void InitDragListener() {} 119 #ifdef WEARABLE_PRODUCT CloseSwipeToRight(bool isEnabled)120 virtual void CloseSwipeToRight(bool isEnabled) {} 121 #endif GetScale(float & scaleX,float & scaleY)122 virtual bool GetScale(float& scaleX, float& scaleY) 123 { 124 return false; 125 } 126 SetBackgroundColor(const Color & color)127 void SetBackgroundColor(const Color& color) 128 { 129 backgroundColor_ = color; 130 if (!hasSet_) { 131 promise_.set_value(true); 132 } 133 } 134 GetBackgroundColor()135 const Color& GetBackgroundColor() 136 { 137 if (!hasSet_) { 138 hasSet_ = future_.get(); 139 } 140 return backgroundColor_; 141 } 142 SetCachePath(const std::string & cachePath)143 void SetCachePath(const std::string& cachePath) 144 { 145 cachePath_ = cachePath; 146 } 147 GetCachePath()148 const std::string& GetCachePath() 149 { 150 return cachePath_; 151 } 152 SetCreateTime(std::chrono::time_point<std::chrono::high_resolution_clock> time)153 void SetCreateTime(std::chrono::time_point<std::chrono::high_resolution_clock> time) 154 { 155 createTime_ = time; 156 } 157 SetFirstUpDating(std::chrono::time_point<std::chrono::high_resolution_clock> time)158 void SetFirstUpDating(std::chrono::time_point<std::chrono::high_resolution_clock> time) 159 { 160 firstUpdating_ = true; 161 firstUpdateBegin_ = time; 162 } 163 SetSessionID(const std::string & sessionID)164 void SetSessionID(const std::string& sessionID) 165 { 166 sessionID_ = sessionID; 167 } 168 GetWidth()169 int32_t GetWidth() const 170 { 171 return width_; 172 } 173 GetHeight()174 int32_t GetHeight() const 175 { 176 return height_; 177 } 178 GetPosX()179 int32_t GetPosX() const 180 { 181 return posX_; 182 } 183 GetPosY()184 int32_t GetPosY() const 185 { 186 return posY_; 187 } 188 189 protected: 190 std::chrono::time_point<std::chrono::high_resolution_clock> createTime_; 191 std::chrono::time_point<std::chrono::high_resolution_clock> firstUpdateBegin_; 192 std::string sessionID_; 193 bool firstUpdating_ = false; 194 int32_t width_ = 0; 195 int32_t height_ = 0; 196 int32_t posX_ = 0; 197 int32_t posY_ = 0; 198 uint32_t transform_ = 0; 199 200 private: 201 std::mutex backgroundColorMutex_; 202 Color backgroundColor_; 203 std::string cachePath_; 204 std::promise<bool> promise_; 205 std::shared_future<bool> future_ = promise_.get_future(); 206 bool hasSet_ = false; 207 208 ACE_DISALLOW_COPY_AND_MOVE(AceView); 209 }; 210 211 } // namespace OHOS::Ace 212 213 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_ACE_VIEW_H 214