123b3eb3cSopenharmony_ci 223b3eb3cSopenharmony_ci/* 323b3eb3cSopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd. 423b3eb3cSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 523b3eb3cSopenharmony_ci * you may not use this file except in compliance with the License. 623b3eb3cSopenharmony_ci * You may obtain a copy of the License at 723b3eb3cSopenharmony_ci * 823b3eb3cSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 923b3eb3cSopenharmony_ci * 1023b3eb3cSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1123b3eb3cSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1223b3eb3cSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1323b3eb3cSopenharmony_ci * See the License for the specific language governing permissions and 1423b3eb3cSopenharmony_ci * limitations under the License. 1523b3eb3cSopenharmony_ci */ 1623b3eb3cSopenharmony_ci 1723b3eb3cSopenharmony_ci#ifndef FOUNDATION_ACE_ADAPTER_PREVIEW_ENTRANCE_ACE_VIEW_OHOS_H 1823b3eb3cSopenharmony_ci#define FOUNDATION_ACE_ADAPTER_PREVIEW_ENTRANCE_ACE_VIEW_OHOS_H 1923b3eb3cSopenharmony_ci 2023b3eb3cSopenharmony_ci#include <memory> 2123b3eb3cSopenharmony_ci 2223b3eb3cSopenharmony_ci#include "adapter/preview/entrance/ace_resource_register.h" 2323b3eb3cSopenharmony_ci#include "adapter/preview/external/multimodalinput/pointer_event.h" 2423b3eb3cSopenharmony_ci#include "base/utils/noncopyable.h" 2523b3eb3cSopenharmony_ci#include "core/common/ace_view.h" 2623b3eb3cSopenharmony_ci#include "core/event/key_event_recognizer.h" 2723b3eb3cSopenharmony_ci#include "core/common/thread_model_impl.h" 2823b3eb3cSopenharmony_ci 2923b3eb3cSopenharmony_cinamespace OHOS::Ace::Platform { 3023b3eb3cSopenharmony_ciusing ReleaseCallback = std::function<void()>; 3123b3eb3cSopenharmony_ci 3223b3eb3cSopenharmony_ciclass AceViewPreview : public AceView { 3323b3eb3cSopenharmony_ci DECLARE_ACE_TYPE(AceViewPreview, AceView); 3423b3eb3cSopenharmony_ci 3523b3eb3cSopenharmony_cipublic: 3623b3eb3cSopenharmony_ci AceViewPreview(int32_t instanceId, std::unique_ptr<ThreadModelImpl> threadModelImpl); 3723b3eb3cSopenharmony_ci ~AceViewPreview() override = default; 3823b3eb3cSopenharmony_ci static AceViewPreview* CreateView( 3923b3eb3cSopenharmony_ci int32_t instanceId, bool useCurrentEventRunner = false, bool usePlatformThread = false); 4023b3eb3cSopenharmony_ci 4123b3eb3cSopenharmony_ci void Launch() override {} 4223b3eb3cSopenharmony_ci int32_t GetInstanceId() const override 4323b3eb3cSopenharmony_ci { 4423b3eb3cSopenharmony_ci return instanceId_; 4523b3eb3cSopenharmony_ci } 4623b3eb3cSopenharmony_ci 4723b3eb3cSopenharmony_ci void RegisterTouchEventCallback(TouchEventCallback&& callback) override 4823b3eb3cSopenharmony_ci { 4923b3eb3cSopenharmony_ci ACE_DCHECK(callback); 5023b3eb3cSopenharmony_ci touchEventCallback_ = std::move(callback); 5123b3eb3cSopenharmony_ci } 5223b3eb3cSopenharmony_ci 5323b3eb3cSopenharmony_ci void RegisterKeyEventCallback(KeyEventCallback&& callback) override 5423b3eb3cSopenharmony_ci { 5523b3eb3cSopenharmony_ci ACE_DCHECK(callback); 5623b3eb3cSopenharmony_ci keyEventCallback_ = std::move(callback); 5723b3eb3cSopenharmony_ci } 5823b3eb3cSopenharmony_ci 5923b3eb3cSopenharmony_ci void RegisterMouseEventCallback(MouseEventCallback&& callback) override 6023b3eb3cSopenharmony_ci { 6123b3eb3cSopenharmony_ci ACE_DCHECK(callback); 6223b3eb3cSopenharmony_ci mouseEventCallback_ = std::move(callback); 6323b3eb3cSopenharmony_ci } 6423b3eb3cSopenharmony_ci 6523b3eb3cSopenharmony_ci void RegisterAxisEventCallback(AxisEventCallback&& callback) override 6623b3eb3cSopenharmony_ci { 6723b3eb3cSopenharmony_ci ACE_DCHECK(callback); 6823b3eb3cSopenharmony_ci axisEventCallback_ = std::move(callback); 6923b3eb3cSopenharmony_ci } 7023b3eb3cSopenharmony_ci 7123b3eb3cSopenharmony_ci void RegisterRotationEventCallback(RotationEventCallBack&& callback) override 7223b3eb3cSopenharmony_ci { 7323b3eb3cSopenharmony_ci ACE_DCHECK(callback); 7423b3eb3cSopenharmony_ci rotationEventCallBack_ = std::move(callback); 7523b3eb3cSopenharmony_ci } 7623b3eb3cSopenharmony_ci 7723b3eb3cSopenharmony_ci void RegisterDragEventCallback(DragEventCallBack&& callback) override {} 7823b3eb3cSopenharmony_ci 7923b3eb3cSopenharmony_ci void RegisterCardViewPositionCallback(CardViewPositionCallBack&& callback) override 8023b3eb3cSopenharmony_ci { 8123b3eb3cSopenharmony_ci ACE_DCHECK(callback); 8223b3eb3cSopenharmony_ci cardViewPositionCallBack_ = std::move(callback); 8323b3eb3cSopenharmony_ci } 8423b3eb3cSopenharmony_ci 8523b3eb3cSopenharmony_ci void RegisterCardViewAccessibilityParamsCallback(CardViewAccessibilityParamsCallback&& callback) override 8623b3eb3cSopenharmony_ci { 8723b3eb3cSopenharmony_ci ACE_DCHECK(callback); 8823b3eb3cSopenharmony_ci cardViewAccessibilityParamsCallback_ = std::move(callback); 8923b3eb3cSopenharmony_ci } 9023b3eb3cSopenharmony_ci 9123b3eb3cSopenharmony_ci void RegisterViewChangeCallback(ViewChangeCallback&& callback) override 9223b3eb3cSopenharmony_ci { 9323b3eb3cSopenharmony_ci ACE_DCHECK(callback); 9423b3eb3cSopenharmony_ci viewChangeCallback_ = std::move(callback); 9523b3eb3cSopenharmony_ci } 9623b3eb3cSopenharmony_ci 9723b3eb3cSopenharmony_ci void RegisterViewPositionChangeCallback(ViewPositionChangeCallback&& callback) override {} 9823b3eb3cSopenharmony_ci 9923b3eb3cSopenharmony_ci void RegisterDensityChangeCallback(DensityChangeCallback&& callback) override 10023b3eb3cSopenharmony_ci { 10123b3eb3cSopenharmony_ci ACE_DCHECK(callback); 10223b3eb3cSopenharmony_ci densityChangeCallback_ = std::move(callback); 10323b3eb3cSopenharmony_ci } 10423b3eb3cSopenharmony_ci 10523b3eb3cSopenharmony_ci void RegisterTransformHintChangeCallback(TransformHintChangeCallback&& callback) override {} 10623b3eb3cSopenharmony_ci 10723b3eb3cSopenharmony_ci void RegisterSystemBarHeightChangeCallback(SystemBarHeightChangeCallback&& callback) override 10823b3eb3cSopenharmony_ci { 10923b3eb3cSopenharmony_ci ACE_DCHECK(callback); 11023b3eb3cSopenharmony_ci systemBarHeightChangeCallback_ = std::move(callback); 11123b3eb3cSopenharmony_ci } 11223b3eb3cSopenharmony_ci 11323b3eb3cSopenharmony_ci void RegisterSurfaceDestroyCallback(SurfaceDestroyCallback&& callback) override 11423b3eb3cSopenharmony_ci { 11523b3eb3cSopenharmony_ci ACE_DCHECK(callback); 11623b3eb3cSopenharmony_ci surfaceDestroyCallback_ = std::move(callback); 11723b3eb3cSopenharmony_ci } 11823b3eb3cSopenharmony_ci 11923b3eb3cSopenharmony_ci void RegisterIdleCallback(IdleCallback&& callback) override 12023b3eb3cSopenharmony_ci { 12123b3eb3cSopenharmony_ci ACE_DCHECK(callback); 12223b3eb3cSopenharmony_ci idleCallback_ = std::move(callback); 12323b3eb3cSopenharmony_ci } 12423b3eb3cSopenharmony_ci 12523b3eb3cSopenharmony_ci void NotifyDensityChanged(double density) const 12623b3eb3cSopenharmony_ci { 12723b3eb3cSopenharmony_ci CHECK_NULL_VOID(densityChangeCallback_); 12823b3eb3cSopenharmony_ci densityChangeCallback_(density); 12923b3eb3cSopenharmony_ci } 13023b3eb3cSopenharmony_ci 13123b3eb3cSopenharmony_ci void NotifySystemBarHeightChanged(double statusBar, double navigationBar) const 13223b3eb3cSopenharmony_ci { 13323b3eb3cSopenharmony_ci CHECK_NULL_VOID(systemBarHeightChangeCallback_); 13423b3eb3cSopenharmony_ci systemBarHeightChangeCallback_(statusBar, navigationBar); 13523b3eb3cSopenharmony_ci } 13623b3eb3cSopenharmony_ci 13723b3eb3cSopenharmony_ci void NotifySurfaceDestroyed() const 13823b3eb3cSopenharmony_ci { 13923b3eb3cSopenharmony_ci CHECK_NULL_VOID(surfaceDestroyCallback_); 14023b3eb3cSopenharmony_ci surfaceDestroyCallback_(); 14123b3eb3cSopenharmony_ci } 14223b3eb3cSopenharmony_ci 14323b3eb3cSopenharmony_ci bool HandleKeyEvent(const KeyEvent& keyEvent) override 14423b3eb3cSopenharmony_ci { 14523b3eb3cSopenharmony_ci return keyEventCallback_ && keyEventCallback_(keyEvent); 14623b3eb3cSopenharmony_ci } 14723b3eb3cSopenharmony_ci 14823b3eb3cSopenharmony_ci const RefPtr<PlatformResRegister>& GetPlatformResRegister() const override 14923b3eb3cSopenharmony_ci { 15023b3eb3cSopenharmony_ci return resRegister_; 15123b3eb3cSopenharmony_ci } 15223b3eb3cSopenharmony_ci 15323b3eb3cSopenharmony_ci bool Dump(const std::vector<std::string>& params) override 15423b3eb3cSopenharmony_ci { 15523b3eb3cSopenharmony_ci return false; 15623b3eb3cSopenharmony_ci } 15723b3eb3cSopenharmony_ci 15823b3eb3cSopenharmony_ci void ProcessIdleEvent(int64_t deadline) 15923b3eb3cSopenharmony_ci { 16023b3eb3cSopenharmony_ci CHECK_NULL_VOID(idleCallback_); 16123b3eb3cSopenharmony_ci idleCallback_(deadline); 16223b3eb3cSopenharmony_ci } 16323b3eb3cSopenharmony_ci 16423b3eb3cSopenharmony_ci ViewType GetViewType() const override 16523b3eb3cSopenharmony_ci { 16623b3eb3cSopenharmony_ci return AceView::ViewType::SURFACE_VIEW; 16723b3eb3cSopenharmony_ci } 16823b3eb3cSopenharmony_ci 16923b3eb3cSopenharmony_ci std::unique_ptr<PlatformWindow> GetPlatformWindow() override 17023b3eb3cSopenharmony_ci { 17123b3eb3cSopenharmony_ci return nullptr; 17223b3eb3cSopenharmony_ci } 17323b3eb3cSopenharmony_ci 17423b3eb3cSopenharmony_ci const void* GetNativeWindowById(uint64_t textureId) override 17523b3eb3cSopenharmony_ci { 17623b3eb3cSopenharmony_ci return nullptr; 17723b3eb3cSopenharmony_ci } 17823b3eb3cSopenharmony_ci 17923b3eb3cSopenharmony_ci ThreadModelImpl* GetThreadModelImpl() const 18023b3eb3cSopenharmony_ci { 18123b3eb3cSopenharmony_ci return threadModelImpl_.get(); 18223b3eb3cSopenharmony_ci } 18323b3eb3cSopenharmony_ci 18423b3eb3cSopenharmony_ci void NotifySurfaceChanged( 18523b3eb3cSopenharmony_ci int32_t width, int32_t height, WindowSizeChangeReason type = WindowSizeChangeReason::UNDEFINED, 18623b3eb3cSopenharmony_ci const std::shared_ptr<Rosen::RSTransaction>& rsTransaction = nullptr); 18723b3eb3cSopenharmony_ci 18823b3eb3cSopenharmony_ci bool HandleMouseEvent(const MouseEvent& mouseEvent); 18923b3eb3cSopenharmony_ci bool HandleAxisEvent(const AxisEvent& axisEvent); 19023b3eb3cSopenharmony_ci bool HandleTouchEvent(const TouchEvent& touchEvent) override; 19123b3eb3cSopenharmony_ci std::unique_ptr<DrawDelegate> GetDrawDelegate() override; 19223b3eb3cSopenharmony_ci 19323b3eb3cSopenharmony_ciprivate: 19423b3eb3cSopenharmony_ci int32_t instanceId_ = 0; 19523b3eb3cSopenharmony_ci RefPtr<PlatformResRegister> resRegister_ = Referenced::MakeRefPtr<AceResourceRegister>(); 19623b3eb3cSopenharmony_ci 19723b3eb3cSopenharmony_ci TouchEventCallback touchEventCallback_; 19823b3eb3cSopenharmony_ci MouseEventCallback mouseEventCallback_; 19923b3eb3cSopenharmony_ci AxisEventCallback axisEventCallback_; 20023b3eb3cSopenharmony_ci RotationEventCallBack rotationEventCallBack_; 20123b3eb3cSopenharmony_ci CardViewPositionCallBack cardViewPositionCallBack_; 20223b3eb3cSopenharmony_ci CardViewAccessibilityParamsCallback cardViewAccessibilityParamsCallback_; 20323b3eb3cSopenharmony_ci ViewChangeCallback viewChangeCallback_; 20423b3eb3cSopenharmony_ci DensityChangeCallback densityChangeCallback_; 20523b3eb3cSopenharmony_ci SystemBarHeightChangeCallback systemBarHeightChangeCallback_; 20623b3eb3cSopenharmony_ci SurfaceDestroyCallback surfaceDestroyCallback_; 20723b3eb3cSopenharmony_ci IdleCallback idleCallback_; 20823b3eb3cSopenharmony_ci KeyEventCallback keyEventCallback_; 20923b3eb3cSopenharmony_ci KeyEventRecognizer keyEventRecognizer_; 21023b3eb3cSopenharmony_ci std::unique_ptr<ThreadModelImpl> threadModelImpl_; 21123b3eb3cSopenharmony_ci 21223b3eb3cSopenharmony_ci ACE_DISALLOW_COPY_AND_MOVE(AceViewPreview); 21323b3eb3cSopenharmony_ci}; 21423b3eb3cSopenharmony_ci} // namespace OHOS::Ace::Platform 21523b3eb3cSopenharmony_ci 21623b3eb3cSopenharmony_ci#endif // FOUNDATION_ACE_ADAPTER_PREVIEW_ENTRANCE_ACE_VIEW_OHOS_H 217