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