123b3eb3cSopenharmony_ci/* 223b3eb3cSopenharmony_ci * Copyright (c) 2023 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 FOUNDATION_ACE_ADAPTER_OHOS_ENTRANCE_ACE_VIEW_OHOS_H 1723b3eb3cSopenharmony_ci#define FOUNDATION_ACE_ADAPTER_OHOS_ENTRANCE_ACE_VIEW_OHOS_H 1823b3eb3cSopenharmony_ci 1923b3eb3cSopenharmony_ci#include <functional> 2023b3eb3cSopenharmony_ci#include <memory> 2123b3eb3cSopenharmony_ci 2223b3eb3cSopenharmony_ci#include "interfaces/inner_api/ace/viewport_config.h" 2323b3eb3cSopenharmony_ci#include "key_event.h" 2423b3eb3cSopenharmony_ci#include "wm/window.h" 2523b3eb3cSopenharmony_ci 2623b3eb3cSopenharmony_ci#include "base/memory/ace_type.h" 2723b3eb3cSopenharmony_ci#include "base/memory/referenced.h" 2823b3eb3cSopenharmony_ci#include "base/perfmonitor/perf_monitor.h" 2923b3eb3cSopenharmony_ci#include "base/utils/noncopyable.h" 3023b3eb3cSopenharmony_ci#include "core/common/ace_view.h" 3123b3eb3cSopenharmony_ci#include "core/common/platform_res_register.h" 3223b3eb3cSopenharmony_ci#include "core/common/thread_model_impl.h" 3323b3eb3cSopenharmony_ci#include "core/components_ng/base/frame_node.h" 3423b3eb3cSopenharmony_ci#include "core/event/key_event_recognizer.h" 3523b3eb3cSopenharmony_ci 3623b3eb3cSopenharmony_cinamespace OHOS::Ace::Platform { 3723b3eb3cSopenharmony_ci 3823b3eb3cSopenharmony_ciusing ReleaseCallback = std::function<void()>; 3923b3eb3cSopenharmony_ci 4023b3eb3cSopenharmony_ciclass ACE_FORCE_EXPORT AceViewOhos : public AceView { 4123b3eb3cSopenharmony_ci DECLARE_ACE_TYPE(AceViewOhos, AceView); 4223b3eb3cSopenharmony_cipublic: 4323b3eb3cSopenharmony_ci explicit AceViewOhos(int32_t id, std::unique_ptr<ThreadModelImpl> threadModelImpl); 4423b3eb3cSopenharmony_ci ~AceViewOhos() override = default; 4523b3eb3cSopenharmony_ci static RefPtr<AceViewOhos> CreateView( 4623b3eb3cSopenharmony_ci int32_t instanceId, bool useCurrentEventRunner = false, bool usePlatformThread = false); 4723b3eb3cSopenharmony_ci static void SurfaceCreated(const RefPtr<AceViewOhos>& view, OHOS::sptr<OHOS::Rosen::Window> window); 4823b3eb3cSopenharmony_ci static void ChangeViewSize(const RefPtr<AceViewOhos>& view, int32_t width, int32_t height); 4923b3eb3cSopenharmony_ci static void SurfaceChanged(const RefPtr<AceViewOhos>& view, int32_t width, int32_t height, int32_t orientation, 5023b3eb3cSopenharmony_ci WindowSizeChangeReason type = WindowSizeChangeReason::UNDEFINED, 5123b3eb3cSopenharmony_ci const std::shared_ptr<Rosen::RSTransaction>& rsTransaction = nullptr); 5223b3eb3cSopenharmony_ci static void SurfacePositionChanged(const RefPtr<AceViewOhos>& view, int32_t posX, int32_t posY); 5323b3eb3cSopenharmony_ci static void SetViewportMetrics(const RefPtr<AceViewOhos>& view, const ViewportConfig& config); 5423b3eb3cSopenharmony_ci static void TransformHintChanged(const RefPtr<AceViewOhos>& view, uint32_t transform); 5523b3eb3cSopenharmony_ci 5623b3eb3cSopenharmony_ci static void DispatchTouchEvent(const RefPtr<AceViewOhos>& view, 5723b3eb3cSopenharmony_ci const std::shared_ptr<MMI::PointerEvent>& pointerEvent, const RefPtr<OHOS::Ace::NG::FrameNode>& node = nullptr, 5823b3eb3cSopenharmony_ci const std::function<void()>& callback = nullptr, bool isInjected = false); 5923b3eb3cSopenharmony_ci static bool DispatchKeyEvent( 6023b3eb3cSopenharmony_ci const RefPtr<AceViewOhos>& view, const std::shared_ptr<MMI::KeyEvent>& keyEvent, bool isPreIme = false); 6123b3eb3cSopenharmony_ci static bool DispatchRotationEvent(const RefPtr<AceViewOhos>& view, float rotationValue); 6223b3eb3cSopenharmony_ci static void DispatchEventToPerf(const std::shared_ptr<MMI::PointerEvent>& pointerEvent); 6323b3eb3cSopenharmony_ci static void DispatchEventToPerf(const std::shared_ptr<MMI::KeyEvent>& keyEvent); 6423b3eb3cSopenharmony_ci 6523b3eb3cSopenharmony_ci static uint32_t GetBackgroundColor(); 6623b3eb3cSopenharmony_ci 6723b3eb3cSopenharmony_ci void RegisterTouchEventCallback(TouchEventCallback&& callback) override; 6823b3eb3cSopenharmony_ci void RegisterDragEventCallback(DragEventCallBack&& callback) override; 6923b3eb3cSopenharmony_ci void RegisterKeyEventCallback(KeyEventCallback&& callback) override; 7023b3eb3cSopenharmony_ci void RegisterMouseEventCallback(MouseEventCallback&& callback) override; 7123b3eb3cSopenharmony_ci void RegisterAxisEventCallback(AxisEventCallback&& callback) override; 7223b3eb3cSopenharmony_ci void RegisterRotationEventCallback(RotationEventCallBack&& callback) override; 7323b3eb3cSopenharmony_ci void RegisterCardViewPositionCallback(CardViewPositionCallBack&& callback) override {} 7423b3eb3cSopenharmony_ci void RegisterCardViewAccessibilityParamsCallback(CardViewAccessibilityParamsCallback&& callback) override {} 7523b3eb3cSopenharmony_ci 7623b3eb3cSopenharmony_ci void Launch() override; 7723b3eb3cSopenharmony_ci 7823b3eb3cSopenharmony_ci void ProcessTouchEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent, 7923b3eb3cSopenharmony_ci const RefPtr<OHOS::Ace::NG::FrameNode>& node = nullptr, const std::function<void()>& callback = nullptr, 8023b3eb3cSopenharmony_ci bool isInjected = false); 8123b3eb3cSopenharmony_ci 8223b3eb3cSopenharmony_ci void ProcessMouseEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent, 8323b3eb3cSopenharmony_ci const RefPtr<OHOS::Ace::NG::FrameNode>& node = nullptr, bool isInjected = false); 8423b3eb3cSopenharmony_ci 8523b3eb3cSopenharmony_ci void ProcessAxisEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent, 8623b3eb3cSopenharmony_ci const RefPtr<OHOS::Ace::NG::FrameNode>& node = nullptr, bool isInjected = false); 8723b3eb3cSopenharmony_ci 8823b3eb3cSopenharmony_ci bool ProcessKeyEvent(const std::shared_ptr<MMI::KeyEvent>& keyEvent, bool isPreIme); 8923b3eb3cSopenharmony_ci 9023b3eb3cSopenharmony_ci bool ProcessRotationEvent(float rotationValue); 9123b3eb3cSopenharmony_ci 9223b3eb3cSopenharmony_ci void ProcessDragEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent, 9323b3eb3cSopenharmony_ci const RefPtr<OHOS::Ace::NG::FrameNode>& node = nullptr); 9423b3eb3cSopenharmony_ci 9523b3eb3cSopenharmony_ci void ProcessDragEvent(int32_t x, int32_t y, const DragEventAction& action, 9623b3eb3cSopenharmony_ci const RefPtr<OHOS::Ace::NG::FrameNode>& node = nullptr); 9723b3eb3cSopenharmony_ci 9823b3eb3cSopenharmony_ci int32_t GetInstanceId() const override 9923b3eb3cSopenharmony_ci { 10023b3eb3cSopenharmony_ci return instanceId_; 10123b3eb3cSopenharmony_ci } 10223b3eb3cSopenharmony_ci 10323b3eb3cSopenharmony_ci void RegisterViewChangeCallback(ViewChangeCallback&& callback) override 10423b3eb3cSopenharmony_ci { 10523b3eb3cSopenharmony_ci viewChangeCallback_ = std::move(callback); 10623b3eb3cSopenharmony_ci } 10723b3eb3cSopenharmony_ci 10823b3eb3cSopenharmony_ci void RegisterViewPositionChangeCallback(ViewPositionChangeCallback&& callback) override 10923b3eb3cSopenharmony_ci { 11023b3eb3cSopenharmony_ci viewPositionChangeCallback_ = std::move(callback); 11123b3eb3cSopenharmony_ci } 11223b3eb3cSopenharmony_ci 11323b3eb3cSopenharmony_ci void RegisterDensityChangeCallback(DensityChangeCallback&& callback) override 11423b3eb3cSopenharmony_ci { 11523b3eb3cSopenharmony_ci densityChangeCallback_ = std::move(callback); 11623b3eb3cSopenharmony_ci } 11723b3eb3cSopenharmony_ci 11823b3eb3cSopenharmony_ci void RegisterTransformHintChangeCallback(TransformHintChangeCallback&& callback) override 11923b3eb3cSopenharmony_ci { 12023b3eb3cSopenharmony_ci transformHintChangeCallback_ = std::move(callback); 12123b3eb3cSopenharmony_ci } 12223b3eb3cSopenharmony_ci 12323b3eb3cSopenharmony_ci void RegisterSystemBarHeightChangeCallback(SystemBarHeightChangeCallback&& callback) override 12423b3eb3cSopenharmony_ci { 12523b3eb3cSopenharmony_ci systemBarHeightChangeCallback_ = std::move(callback); 12623b3eb3cSopenharmony_ci } 12723b3eb3cSopenharmony_ci 12823b3eb3cSopenharmony_ci void RegisterSurfaceDestroyCallback(SurfaceDestroyCallback&& callback) override 12923b3eb3cSopenharmony_ci { 13023b3eb3cSopenharmony_ci surfaceDestroyCallback_ = std::move(callback); 13123b3eb3cSopenharmony_ci } 13223b3eb3cSopenharmony_ci 13323b3eb3cSopenharmony_ci void RegisterIdleCallback(IdleCallback&& callback) override {} 13423b3eb3cSopenharmony_ci 13523b3eb3cSopenharmony_ci void SetPlatformResRegister(const RefPtr<PlatformResRegister>& resRegister) 13623b3eb3cSopenharmony_ci { 13723b3eb3cSopenharmony_ci resRegister_ = resRegister; 13823b3eb3cSopenharmony_ci } 13923b3eb3cSopenharmony_ci 14023b3eb3cSopenharmony_ci const RefPtr<PlatformResRegister>& GetPlatformResRegister() const override 14123b3eb3cSopenharmony_ci { 14223b3eb3cSopenharmony_ci return resRegister_; 14323b3eb3cSopenharmony_ci } 14423b3eb3cSopenharmony_ci 14523b3eb3cSopenharmony_ci ViewType GetViewType() const override 14623b3eb3cSopenharmony_ci { 14723b3eb3cSopenharmony_ci return AceView::ViewType::SURFACE_VIEW; 14823b3eb3cSopenharmony_ci } 14923b3eb3cSopenharmony_ci 15023b3eb3cSopenharmony_ci std::unique_ptr<DrawDelegate> GetDrawDelegate() override 15123b3eb3cSopenharmony_ci { 15223b3eb3cSopenharmony_ci return nullptr; 15323b3eb3cSopenharmony_ci } 15423b3eb3cSopenharmony_ci 15523b3eb3cSopenharmony_ci std::unique_ptr<PlatformWindow> GetPlatformWindow() override 15623b3eb3cSopenharmony_ci { 15723b3eb3cSopenharmony_ci return nullptr; 15823b3eb3cSopenharmony_ci } 15923b3eb3cSopenharmony_ci 16023b3eb3cSopenharmony_ci bool Dump(const std::vector<std::string>& params) override; 16123b3eb3cSopenharmony_ci const void* GetNativeWindowById(uint64_t textureId) override; 16223b3eb3cSopenharmony_ci 16323b3eb3cSopenharmony_ci ThreadModelImpl* GetThreadModelImpl() const 16423b3eb3cSopenharmony_ci { 16523b3eb3cSopenharmony_ci return threadModelImpl_.get(); 16623b3eb3cSopenharmony_ci } 16723b3eb3cSopenharmony_ci 16823b3eb3cSopenharmony_ciprivate: 16923b3eb3cSopenharmony_ci void NotifySurfaceChanged(int width, int height, WindowSizeChangeReason type, 17023b3eb3cSopenharmony_ci const std::shared_ptr<Rosen::RSTransaction>& rsTransaction = nullptr) 17123b3eb3cSopenharmony_ci { 17223b3eb3cSopenharmony_ci width_ = width; 17323b3eb3cSopenharmony_ci height_ = height; 17423b3eb3cSopenharmony_ci if (viewChangeCallback_) { 17523b3eb3cSopenharmony_ci viewChangeCallback_(width, height, type, rsTransaction); 17623b3eb3cSopenharmony_ci } 17723b3eb3cSopenharmony_ci } 17823b3eb3cSopenharmony_ci 17923b3eb3cSopenharmony_ci void ChangeSize(int width, int height) 18023b3eb3cSopenharmony_ci { 18123b3eb3cSopenharmony_ci width_ = width; 18223b3eb3cSopenharmony_ci height_ = height; 18323b3eb3cSopenharmony_ci } 18423b3eb3cSopenharmony_ci 18523b3eb3cSopenharmony_ci void NotifySurfacePositionChanged(int32_t posX, int32_t posY) 18623b3eb3cSopenharmony_ci { 18723b3eb3cSopenharmony_ci if (posX_ == posX && posY_ == posY) { 18823b3eb3cSopenharmony_ci return; 18923b3eb3cSopenharmony_ci } 19023b3eb3cSopenharmony_ci if (viewPositionChangeCallback_) { 19123b3eb3cSopenharmony_ci viewPositionChangeCallback_(posX, posY); 19223b3eb3cSopenharmony_ci } 19323b3eb3cSopenharmony_ci posX_ = posX; 19423b3eb3cSopenharmony_ci posY_ = posY; 19523b3eb3cSopenharmony_ci } 19623b3eb3cSopenharmony_ci 19723b3eb3cSopenharmony_ci void NotifyDensityChanged(double density) const 19823b3eb3cSopenharmony_ci { 19923b3eb3cSopenharmony_ci if (densityChangeCallback_) { 20023b3eb3cSopenharmony_ci densityChangeCallback_(density); 20123b3eb3cSopenharmony_ci } 20223b3eb3cSopenharmony_ci } 20323b3eb3cSopenharmony_ci 20423b3eb3cSopenharmony_ci void NotifyTransformHintChanged(uint32_t transform) 20523b3eb3cSopenharmony_ci { 20623b3eb3cSopenharmony_ci if (transform_ == transform) { 20723b3eb3cSopenharmony_ci return; 20823b3eb3cSopenharmony_ci } 20923b3eb3cSopenharmony_ci if (transformHintChangeCallback_) { 21023b3eb3cSopenharmony_ci transformHintChangeCallback_(transform); 21123b3eb3cSopenharmony_ci } 21223b3eb3cSopenharmony_ci transform_ = transform; 21323b3eb3cSopenharmony_ci } 21423b3eb3cSopenharmony_ci 21523b3eb3cSopenharmony_ci void NotifySystemBarHeightChanged(double statusBar, double navigationBar) const 21623b3eb3cSopenharmony_ci { 21723b3eb3cSopenharmony_ci if (systemBarHeightChangeCallback_) { 21823b3eb3cSopenharmony_ci systemBarHeightChangeCallback_(statusBar, navigationBar); 21923b3eb3cSopenharmony_ci } 22023b3eb3cSopenharmony_ci } 22123b3eb3cSopenharmony_ci 22223b3eb3cSopenharmony_ci void NotifySurfaceDestroyed() const 22323b3eb3cSopenharmony_ci { 22423b3eb3cSopenharmony_ci if (surfaceDestroyCallback_) { 22523b3eb3cSopenharmony_ci surfaceDestroyCallback_(); 22623b3eb3cSopenharmony_ci } 22723b3eb3cSopenharmony_ci } 22823b3eb3cSopenharmony_ci 22923b3eb3cSopenharmony_ci TouchEventCallback touchEventCallback_; 23023b3eb3cSopenharmony_ci MouseEventCallback mouseEventCallback_; 23123b3eb3cSopenharmony_ci AxisEventCallback axisEventCallback_; 23223b3eb3cSopenharmony_ci RotationEventCallBack rotationEventCallBack_; 23323b3eb3cSopenharmony_ci ViewChangeCallback viewChangeCallback_; 23423b3eb3cSopenharmony_ci ViewPositionChangeCallback viewPositionChangeCallback_; 23523b3eb3cSopenharmony_ci DensityChangeCallback densityChangeCallback_; 23623b3eb3cSopenharmony_ci TransformHintChangeCallback transformHintChangeCallback_; 23723b3eb3cSopenharmony_ci SystemBarHeightChangeCallback systemBarHeightChangeCallback_; 23823b3eb3cSopenharmony_ci SurfaceDestroyCallback surfaceDestroyCallback_; 23923b3eb3cSopenharmony_ci DragEventCallBack dragEventCallback_; 24023b3eb3cSopenharmony_ci int32_t instanceId_ = -1; 24123b3eb3cSopenharmony_ci RefPtr<PlatformResRegister> resRegister_; 24223b3eb3cSopenharmony_ci KeyEventCallback keyEventCallback_; 24323b3eb3cSopenharmony_ci KeyEventRecognizer keyEventRecognizer_; 24423b3eb3cSopenharmony_ci // mark the touch event's state, HORIZONTAL_STATE: the event should send to platform, VERTICAL_STATE: should not 24523b3eb3cSopenharmony_ci enum class EventState { INITIAL_STATE, HORIZONTAL_STATE, VERTICAL_STATE }; 24623b3eb3cSopenharmony_ci 24723b3eb3cSopenharmony_ci struct TouchPointInfo { 24823b3eb3cSopenharmony_ci Offset offset_; 24923b3eb3cSopenharmony_ci EventState eventState_ = EventState::INITIAL_STATE; 25023b3eb3cSopenharmony_ci 25123b3eb3cSopenharmony_ci TouchPointInfo() = default; 25223b3eb3cSopenharmony_ci explicit TouchPointInfo(const Offset& offset) : offset_(offset) {} 25323b3eb3cSopenharmony_ci ~TouchPointInfo() = default; 25423b3eb3cSopenharmony_ci }; 25523b3eb3cSopenharmony_ci std::unordered_map<int32_t, TouchPointInfo> touchPointInfoMap_; 25623b3eb3cSopenharmony_ci 25723b3eb3cSopenharmony_ci std::unique_ptr<ThreadModelImpl> threadModelImpl_; 25823b3eb3cSopenharmony_ci 25923b3eb3cSopenharmony_ci ACE_DISALLOW_COPY_AND_MOVE(AceViewOhos); 26023b3eb3cSopenharmony_ci}; 26123b3eb3cSopenharmony_ci} // namespace OHOS::Ace::Platform 26223b3eb3cSopenharmony_ci 26323b3eb3cSopenharmony_ci#endif // FOUNDATION_ACE_ADAPTER_OHOS_ENTRANCE_ACE_VIEW_OHOS_H 264