• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 DensityChangeCallback = std::function<void(double density)>;
64     virtual void RegisterDensityChangeCallback(DensityChangeCallback&& callback) = 0;
65 
66     using SystemBarHeightChangeCallbak = std::function<void(double statusBar, double navigationBar)>;
67     virtual void RegisterSystemBarHeightChangeCallback(SystemBarHeightChangeCallbak&& callback) = 0;
68 
69     using SurfaceDestroyCallback = std::function<void()>;
70     virtual void RegisterSurfaceDestroyCallback(SurfaceDestroyCallback&& callback) = 0;
71 
72     using IdleCallback = std::function<void(int64_t)>;
73     virtual void RegisterIdleCallback(IdleCallback&& callback) = 0;
74 
75     using PreDrawCallback = std::function<void()>;
RegisterPreDrawCallback(PreDrawCallback && callback)76     virtual void RegisterPreDrawCallback(PreDrawCallback&& callback) {}
77 
78     using RequestFrameCallback = std::function<void()>;
RegisterRequestFrameCallback(RequestFrameCallback && callback)79     virtual void RegisterRequestFrameCallback(RequestFrameCallback&& callback) {}
80 
81     virtual bool Dump(const std::vector<std::string>& params) = 0;
82 
83     // Use to receive event from glfw window
HandleTouchEvent(const std::vector<uint8_t> & data)84     virtual bool HandleTouchEvent(const std::vector<uint8_t>& data)
85     {
86         return false;
87     }
88     // Use to receive event from pc previewer
HandleTouchEvent(const TouchEvent & touchEvent)89     virtual bool HandleTouchEvent(const TouchEvent& touchEvent)
90     {
91         return false;
92     }
93     // Use to get native window handle by texture id
94     virtual const void* GetNativeWindowById(uint64_t textureId) = 0;
95 
96     virtual ViewType GetViewType() const = 0;
97     virtual std::unique_ptr<DrawDelegate> GetDrawDelegate() = 0;
98     virtual std::unique_ptr<PlatformWindow> GetPlatformWindow() = 0;
UpdateWindowBlurRegion(const std::vector<std::vector<float>> & blurRRects)99     virtual void UpdateWindowBlurRegion(const std::vector<std::vector<float>>& blurRRects) {}
UpdateWindowblurDrawOp()100     virtual void UpdateWindowblurDrawOp() {}
StartSystemDrag(const std::string & str,void * pixelMapManager,int32_t byteCount)101     virtual void StartSystemDrag(const std::string& str, void* pixelMapManager, int32_t byteCount) {}
InitDragListener()102     virtual void InitDragListener() {}
103 #ifdef WEARABLE_PRODUCT
CloseSwipeToRight(bool isEnabled)104     virtual void CloseSwipeToRight(bool isEnabled) {}
105 #endif
GetScale(float & scaleX,float & scaleY)106     virtual bool GetScale(float& scaleX, float& scaleY)
107     {
108         return false;
109     }
110 
SetBackgroundColor(const Color & color)111     void SetBackgroundColor(const Color& color)
112     {
113         backgroundColor_ = color;
114         if (!hasSet_) {
115             promise_.set_value(true);
116         }
117     }
118 
GetBackgroundColor()119     const Color& GetBackgroundColor()
120     {
121         if (!hasSet_) {
122             hasSet_ = future_.get();
123         }
124         return backgroundColor_;
125     }
126 
SetCachePath(const std::string & cachePath)127     void SetCachePath(const std::string& cachePath)
128     {
129         cachePath_ = cachePath;
130     }
131 
GetCachePath()132     const std::string& GetCachePath()
133     {
134         return cachePath_;
135     }
136 
SetCreateTime(std::chrono::time_point<std::chrono::high_resolution_clock> time)137     void SetCreateTime(std::chrono::time_point<std::chrono::high_resolution_clock> time)
138     {
139         createTime_ = time;
140     }
141 
SetFirstUpDating(std::chrono::time_point<std::chrono::high_resolution_clock> time)142     void SetFirstUpDating(std::chrono::time_point<std::chrono::high_resolution_clock> time)
143     {
144         firstUpdating_ = true;
145         firstUpdateBegin_ = time;
146     }
147 
SetSessionID(const std::string & sessionID)148     void SetSessionID(const std::string& sessionID)
149     {
150         sessionID_ = sessionID;
151     }
152 
GetWidth()153     int32_t GetWidth() const
154     {
155         return width_;
156     }
157 
GetHeight()158     int32_t GetHeight() const
159     {
160         return height_;
161     }
162 
163 protected:
164     std::chrono::time_point<std::chrono::high_resolution_clock> createTime_;
165     std::chrono::time_point<std::chrono::high_resolution_clock> firstUpdateBegin_;
166     std::string sessionID_;
167     bool firstUpdating_ = false;
168     int32_t width_ = 0;
169     int32_t height_ = 0;
170 
171 private:
172     std::mutex backgroundColorMutex_;
173     Color backgroundColor_;
174     std::string cachePath_;
175     std::promise<bool> promise_;
176     std::shared_future<bool> future_ = promise_.get_future();
177     bool hasSet_ = false;
178 
179     ACE_DISALLOW_COPY_AND_MOVE(AceView);
180 };
181 
182 } // namespace OHOS::Ace
183 
184 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_ACE_VIEW_H
185