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