1 /*
2 * Copyright (c) 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 #include "adapter/preview/entrance/rs_ace_view.h"
17
18 #include <cinttypes>
19
20 #include "base/log/dump_log.h"
21 #include "base/log/event_report.h"
22 #include "base/log/log.h"
23 #include "base/utils/macros.h"
24 #include "base/utils/system_properties.h"
25 #include "base/utils/utils.h"
26 #include "core/common/ace_engine.h"
27 #include "core/components/theme/theme_manager.h"
28 #include "core/event/mouse_event.h"
29 #include "core/event/touch_event.h"
30 #include "core/image/image_cache.h"
31
32 namespace OHOS::Ace::Platform {
RegisterTouchEventCallback(TouchEventCallback && callback)33 void RSAceView::RegisterTouchEventCallback(TouchEventCallback&& callback)
34 {
35 ACE_DCHECK(callback);
36 touchEventCallback_ = std::move(callback);
37 }
38
RegisterKeyEventCallback(KeyEventCallback && callback)39 void RSAceView::RegisterKeyEventCallback(KeyEventCallback&& callback)
40 {
41 ACE_DCHECK(callback);
42 keyEventCallback_ = std::move(callback);
43 }
44
RegisterMouseEventCallback(MouseEventCallback && callback)45 void RSAceView::RegisterMouseEventCallback(MouseEventCallback&& callback)
46 {
47 ACE_DCHECK(callback);
48 mouseEventCallback_ = std::move(callback);
49 }
50
RegisterAxisEventCallback(AxisEventCallback && callback)51 void RSAceView::RegisterAxisEventCallback(AxisEventCallback&& callback)
52 {
53 ACE_DCHECK(callback);
54 axisEventCallback_ = std::move(callback);
55 }
56
RegisterRotationEventCallback(RotationEventCallBack && callback)57 void RSAceView::RegisterRotationEventCallback(RotationEventCallBack&& callback)
58 {
59 ACE_DCHECK(callback);
60 rotationEventCallBack_ = std::move(callback);
61 }
62
Launch()63 void RSAceView::Launch()
64 {
65 }
66
Dump(const std::vector<std::string> & params)67 bool RSAceView::Dump(const std::vector<std::string>& params)
68 {
69 return false;
70 }
71
ProcessIdleEvent(int64_t deadline)72 void RSAceView::ProcessIdleEvent(int64_t deadline)
73 {
74 if (idleCallback_) {
75 idleCallback_(deadline);
76 }
77 }
78
HandleTouchEvent(const TouchEvent & touchEvent)79 bool RSAceView::HandleTouchEvent(const TouchEvent& touchEvent)
80 {
81 if (touchEvent.type == TouchType::UNKNOWN) {
82 LOGW("Unknown event.");
83 return false;
84 }
85
86 LOGD("HandleTouchEvent touchEvent.x: %{public}lf, touchEvent.y: %{public}lf, touchEvent.size: %{public}lf",
87 touchEvent.x, touchEvent.y, touchEvent.size);
88 auto event = touchEvent.UpdatePointers();
89 if (touchEventCallback_) {
90 touchEventCallback_(event, nullptr);
91 }
92
93 return true;
94 }
95
HandleKeyEvent(const KeyEvent & keyEvent)96 bool RSAceView::HandleKeyEvent(const KeyEvent& keyEvent)
97 {
98 if (!keyEventCallback_) {
99 return false;
100 }
101
102 return keyEventCallback_(keyEvent);
103 }
104
GetDrawDelegate()105 std::unique_ptr<DrawDelegate> RSAceView::GetDrawDelegate()
106 {
107 auto drawDelegate = std::make_unique<DrawDelegate>();
108
109 drawDelegate->SetDrawRSFrameCallback([this](std::shared_ptr<Rosen::RSNode>& node, const Rect& rect) {
110 if (!node) {
111 return;
112 }
113 LOGD("DrawRSFrameCallback called!!");
114 });
115
116 return drawDelegate;
117 }
118
GetPlatformWindow()119 std::unique_ptr<PlatformWindow> RSAceView::GetPlatformWindow()
120 {
121 return nullptr;
122 }
123
GetNativeWindowById(uint64_t textureId)124 const void* RSAceView::GetNativeWindowById(uint64_t textureId)
125 {
126 return nullptr;
127 }
128 } // namespace OHOS::Ace::Platform
129