123b3eb3cSopenharmony_ci/* 223b3eb3cSopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 323b3eb3cSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 423b3eb3cSopenharmony_ci * you may not use this file except in compliance with the License. 523b3eb3cSopenharmony_ci * You may obtain a copy of the License at 623b3eb3cSopenharmony_ci * 723b3eb3cSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 823b3eb3cSopenharmony_ci * 923b3eb3cSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1023b3eb3cSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1123b3eb3cSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1223b3eb3cSopenharmony_ci * See the License for the specific language governing permissions and 1323b3eb3cSopenharmony_ci * limitations under the License. 1423b3eb3cSopenharmony_ci */ 1523b3eb3cSopenharmony_ci 1623b3eb3cSopenharmony_ci#ifndef COMPONENT_EXT_MOVING_PHOTO_MOVING_PHOTO_EVENT_HUB_H 1723b3eb3cSopenharmony_ci#define COMPONENT_EXT_MOVING_PHOTO_MOVING_PHOTO_EVENT_HUB_H 1823b3eb3cSopenharmony_ci 1923b3eb3cSopenharmony_ci#include <functional> 2023b3eb3cSopenharmony_ci 2123b3eb3cSopenharmony_ci#include "base/memory/ace_type.h" 2223b3eb3cSopenharmony_ci#include "core/common/recorder/event_recorder.h" 2323b3eb3cSopenharmony_ci#include "core/components_ng/base/frame_node.h" 2423b3eb3cSopenharmony_ci#include "core/components_ng/event/event_hub.h" 2523b3eb3cSopenharmony_ci#include "core/components_ng/event/gesture_event_hub.h" 2623b3eb3cSopenharmony_ci 2723b3eb3cSopenharmony_cinamespace OHOS::Ace::NG { 2823b3eb3cSopenharmony_ci 2923b3eb3cSopenharmony_ciusing MovingPhotoEventFunc = std::function<void()>; 3023b3eb3cSopenharmony_ci 3123b3eb3cSopenharmony_ciclass MovingPhotoEventHub : public EventHub { 3223b3eb3cSopenharmony_ci DECLARE_ACE_TYPE(MovingPhotoEventHub, EventHub) 3323b3eb3cSopenharmony_ci 3423b3eb3cSopenharmony_cipublic: 3523b3eb3cSopenharmony_ci MovingPhotoEventHub() = default; 3623b3eb3cSopenharmony_ci ~MovingPhotoEventHub() override = default; 3723b3eb3cSopenharmony_ci 3823b3eb3cSopenharmony_ci void SetOnComplete(MovingPhotoEventFunc&& onComplete) 3923b3eb3cSopenharmony_ci { 4023b3eb3cSopenharmony_ci onComplete_ = std::move(onComplete); 4123b3eb3cSopenharmony_ci } 4223b3eb3cSopenharmony_ci 4323b3eb3cSopenharmony_ci MovingPhotoEventFunc GetOnComplete() 4423b3eb3cSopenharmony_ci { 4523b3eb3cSopenharmony_ci return onComplete_; 4623b3eb3cSopenharmony_ci } 4723b3eb3cSopenharmony_ci 4823b3eb3cSopenharmony_ci void FireCompleteEvent() 4923b3eb3cSopenharmony_ci { 5023b3eb3cSopenharmony_ci if (onComplete_) { 5123b3eb3cSopenharmony_ci onComplete_(); 5223b3eb3cSopenharmony_ci } 5323b3eb3cSopenharmony_ci } 5423b3eb3cSopenharmony_ci 5523b3eb3cSopenharmony_ci void SetOnStart(MovingPhotoEventFunc&& onStart) 5623b3eb3cSopenharmony_ci { 5723b3eb3cSopenharmony_ci onStart_ = std ::move(onStart); 5823b3eb3cSopenharmony_ci } 5923b3eb3cSopenharmony_ci 6023b3eb3cSopenharmony_ci MovingPhotoEventFunc GetOnStart() 6123b3eb3cSopenharmony_ci { 6223b3eb3cSopenharmony_ci return onStart_; 6323b3eb3cSopenharmony_ci } 6423b3eb3cSopenharmony_ci 6523b3eb3cSopenharmony_ci void FireStartEvent() 6623b3eb3cSopenharmony_ci { 6723b3eb3cSopenharmony_ci if (onStart_) { 6823b3eb3cSopenharmony_ci auto onStart = onStart_; 6923b3eb3cSopenharmony_ci onStart(); 7023b3eb3cSopenharmony_ci } 7123b3eb3cSopenharmony_ci } 7223b3eb3cSopenharmony_ci 7323b3eb3cSopenharmony_ci void SetOnPause(MovingPhotoEventFunc&& onPause) 7423b3eb3cSopenharmony_ci { 7523b3eb3cSopenharmony_ci onPause_ = std ::move(onPause); 7623b3eb3cSopenharmony_ci } 7723b3eb3cSopenharmony_ci 7823b3eb3cSopenharmony_ci void FirePauseEvent() 7923b3eb3cSopenharmony_ci { 8023b3eb3cSopenharmony_ci if (onPause_) { 8123b3eb3cSopenharmony_ci auto onPause = onPause_; 8223b3eb3cSopenharmony_ci onPause(); 8323b3eb3cSopenharmony_ci } 8423b3eb3cSopenharmony_ci } 8523b3eb3cSopenharmony_ci 8623b3eb3cSopenharmony_ci void SetOnStop(MovingPhotoEventFunc&& onStop) 8723b3eb3cSopenharmony_ci { 8823b3eb3cSopenharmony_ci onStop_ = std ::move(onStop); 8923b3eb3cSopenharmony_ci } 9023b3eb3cSopenharmony_ci 9123b3eb3cSopenharmony_ci MovingPhotoEventFunc GetOnStop() 9223b3eb3cSopenharmony_ci { 9323b3eb3cSopenharmony_ci return onStop_; 9423b3eb3cSopenharmony_ci } 9523b3eb3cSopenharmony_ci 9623b3eb3cSopenharmony_ci void FireStopEvent() 9723b3eb3cSopenharmony_ci { 9823b3eb3cSopenharmony_ci if (onStop_) { 9923b3eb3cSopenharmony_ci auto onStop = onStop_; 10023b3eb3cSopenharmony_ci onStop(); 10123b3eb3cSopenharmony_ci } 10223b3eb3cSopenharmony_ci } 10323b3eb3cSopenharmony_ci 10423b3eb3cSopenharmony_ci void SetOnFinish(MovingPhotoEventFunc&& onFinish) 10523b3eb3cSopenharmony_ci { 10623b3eb3cSopenharmony_ci onFinish_ = std ::move(onFinish); 10723b3eb3cSopenharmony_ci } 10823b3eb3cSopenharmony_ci 10923b3eb3cSopenharmony_ci MovingPhotoEventFunc GetOnFinish() 11023b3eb3cSopenharmony_ci { 11123b3eb3cSopenharmony_ci return onFinish_; 11223b3eb3cSopenharmony_ci } 11323b3eb3cSopenharmony_ci 11423b3eb3cSopenharmony_ci void FireFinishEvent() 11523b3eb3cSopenharmony_ci { 11623b3eb3cSopenharmony_ci if (onFinish_) { 11723b3eb3cSopenharmony_ci auto onFinish = onFinish_; 11823b3eb3cSopenharmony_ci onFinish(); 11923b3eb3cSopenharmony_ci } 12023b3eb3cSopenharmony_ci } 12123b3eb3cSopenharmony_ci 12223b3eb3cSopenharmony_ci void SetOnError(MovingPhotoEventFunc&& onError) 12323b3eb3cSopenharmony_ci { 12423b3eb3cSopenharmony_ci onError_ = std ::move(onError); 12523b3eb3cSopenharmony_ci } 12623b3eb3cSopenharmony_ci 12723b3eb3cSopenharmony_ci MovingPhotoEventFunc GetOnError() 12823b3eb3cSopenharmony_ci { 12923b3eb3cSopenharmony_ci return onError_; 13023b3eb3cSopenharmony_ci } 13123b3eb3cSopenharmony_ci 13223b3eb3cSopenharmony_ci void FireErrorEvent() 13323b3eb3cSopenharmony_ci { 13423b3eb3cSopenharmony_ci if (onError_) { 13523b3eb3cSopenharmony_ci auto onError = onError_; 13623b3eb3cSopenharmony_ci onError(); 13723b3eb3cSopenharmony_ci } 13823b3eb3cSopenharmony_ci } 13923b3eb3cSopenharmony_ci 14023b3eb3cSopenharmony_ciprivate: 14123b3eb3cSopenharmony_ci MovingPhotoEventFunc onComplete_; 14223b3eb3cSopenharmony_ci MovingPhotoEventFunc onStart_; 14323b3eb3cSopenharmony_ci MovingPhotoEventFunc onStop_; 14423b3eb3cSopenharmony_ci MovingPhotoEventFunc onPause_; 14523b3eb3cSopenharmony_ci MovingPhotoEventFunc onFinish_; 14623b3eb3cSopenharmony_ci MovingPhotoEventFunc onError_; 14723b3eb3cSopenharmony_ci}; 14823b3eb3cSopenharmony_ci 14923b3eb3cSopenharmony_ci} // namespace OHOS::Ace::NG 15023b3eb3cSopenharmony_ci 15123b3eb3cSopenharmony_ci#endif // COMPONENT_EXT_MOVING_PHOTO_MOVING_PHOTO_EVENT_HUB_H 152