diff --git a/window_scene/BUILD.gn b/window_scene/BUILD.gn index 59c2deb1b8f89a6380e4f87e38f17dd691d8e396..6a135eeac4f19c64a0b0e2b280feb8c3e3413ffa 100644 --- a/window_scene/BUILD.gn +++ b/window_scene/BUILD.gn @@ -15,6 +15,8 @@ import("//build/ohos.gni") group("window_scene") { public_deps = [ + "intention_event:libintention_event", + "intention_event:libwindow_event_process", "session:scene_session", "session:screen_session", "session_manager:scene_session_manager", diff --git a/window_scene/intention_event/BUILD.gn b/window_scene/intention_event/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..2e5626c80481c6fd99aa7b7142688425c48f5a0c --- /dev/null +++ b/window_scene/intention_event/BUILD.gn @@ -0,0 +1,66 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") +import("../../windowmanager_aafwk.gni") + +ohos_shared_library("libintention_event") { + include_dirs = [ + "./include", + "../../wm/include", + ] + + sources = [ "src/intention_event_manager.cpp" ] + + deps = [ + "${window_base_path}/utils:libwmutil", + "../common:window_scene_common", + "../session:scene_session", + "../session_manager:scene_session_manager", + ] + + external_deps = [ + "ace_engine:ace_uicontent", + "c_utils:utils", + "eventhandler:libeventhandler", + "hilog_native:libhilog", + "hisysevent_native:libhisysevent", + "hitrace_native:hitrace_meter", + "input:libmmi-client", + ] + part_name = "window_manager" + subsystem_name = "window" +} + +ohos_shared_library("libwindow_event_process") { + include_dirs = [ + "./include", + "${arkui_base_path}/ace_engine/frameworks", + "${arkui_base_path}/ace_engine", + "${window_base_path}/utils/include", + ] + + sources = [ "src/window_event_process.cpp" ] + + deps = [ "${window_base_path}/utils:libwmutil" ] + + external_deps = [ + "c_utils:utils", + "graphic_standard:window_animation", + "hilog_native:libhilog", + "hisysevent_native:libhisysevent", + "hitrace_native:hitrace_meter", + ] + part_name = "window_manager" + subsystem_name = "window" +} diff --git a/window_scene/intention_event/include/intention_event_manager.h b/window_scene/intention_event/include/intention_event_manager.h new file mode 100644 index 0000000000000000000000000000000000000000..b2b1cf254d707c2b148c5ac242fd7ac6347936f5 --- /dev/null +++ b/window_scene/intention_event/include/intention_event_manager.h @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_ROSEN_WINDOW_SCENE_INTENTION_EVENT_MANAGER_H +#define OHOS_ROSEN_WINDOW_SCENE_INTENTION_EVENT_MANAGER_H + +#include "singleton.h" + +#include +#include + +namespace OHOS::AppExecFwk { +class EventHandler; +} // namespace OHOS::AppExecFwk + +namespace OHOS::Rosen { +class IntentionEventManager { + DECLARE_DELAYED_SINGLETON(IntentionEventManager); +public: + DISALLOW_COPY_AND_MOVE(IntentionEventManager); + bool EnableInputEventListener(Ace::UIContent* uiContent, + std::shared_ptr); + +private: +class InputEventListener : public MMI::IInputEventConsumer { +public: + explicit InputEventListener(Ace::UIContent* uiContent): uiContent_(uiContent) {} + virtual ~InputEventListener() = default; + void OnInputEvent(std::shared_ptr pointerEvent) const override; + void OnInputEvent(std::shared_ptr keyEvent) const override; + void OnInputEvent(std::shared_ptr axisEvent) const override; + +private: + Ace::UIContent* uiContent_ = nullptr; +}; +}; + +#define IntentionManager DelayedSingleton::GetInstance() +} // namespace OHOS::Rosen +#endif // OHOS_ROSEN_WINDOW_SCENE_INTENTION_EVENT_MANAGER_H diff --git a/window_scene/intention_event/include/window_event_process.h b/window_scene/intention_event/include/window_event_process.h new file mode 100644 index 0000000000000000000000000000000000000000..33232316d0b11addc1f6b002fbe1af3f9c391b5d --- /dev/null +++ b/window_scene/intention_event/include/window_event_process.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_ROSEN_WINDOW_SCENE_WINDOW_EVENT_PROCESS_H +#define OHOS_ROSEN_WINDOW_SCENE_WINDOW_EVENT_PROCESS_H + +#include "singleton.h" + +#include "base/geometry/ng/point_t.h" +#include "base/geometry/ng/rect_t.h" + +namespace OHOS::Rosen { +class WindowEventProcess { + DECLARE_DELAYED_SINGLETON(WindowEventProcess); +public: + DISALLOW_COPY_AND_MOVE(WindowEventProcess); + bool IsInWindowHotRect(const Ace::NG::RectF& windowSceneRect, + const Ace::NG::PointF& parentLocalPoint, int32_t souceType); + +private: + bool GreatOrEqual(double left, double right); + bool LessOrEqual(double left, double right); +}; + +#define WindowEventHandler DelayedSingleton::GetInstance() +} // namespace OHOS::Rosen +#endif // OHOS_ROSEN_WINDOW_SCENE_WINDOW_EVENT_PROCESS_H diff --git a/window_scene/intention_event/src/intention_event_manager.cpp b/window_scene/intention_event/src/intention_event_manager.cpp new file mode 100644 index 0000000000000000000000000000000000000000..af4bd3fae8fa7bed71a12e912db834fcb094ddbe --- /dev/null +++ b/window_scene/intention_event/src/intention_event_manager.cpp @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "intention_event_manager.h" + +#include "window_manager_hilog.h" +#include "session_manager/include/scene_session_manager.h" + +namespace OHOS { +namespace Rosen { +namespace { +constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, HILOG_DOMAIN_WINDOW, "IntentionEventManager" }; +} // namespace + +IntentionEventManager::IntentionEventManager() {} +IntentionEventManager::~IntentionEventManager() {} + +bool IntentionEventManager::EnableInputEventListener(Ace::UIContent* uiContent, + std::shared_ptr eventHandler) +{ + if (uiContent == nullptr) { + WLOGFE("uiContent is null"); + return false; + } + if (eventHandler == nullptr) { + WLOGFE("eventHandler is null"); + return false; + } + auto listener = std::make_shared(uiContent); + MMI::InputManager::GetInstance()->SetWindowInputEventConsumer(listener, eventHandler); + return true; +} + +void IntentionEventManager::InputEventListener::OnInputEvent( + std::shared_ptr pointerEvent) const +{ + if (uiContent_ == nullptr) { + WLOGFE("uiContent_ is null"); + return; + } + uiContent_->ProcessPointerEvent(pointerEvent); +} + +void IntentionEventManager::InputEventListener::OnInputEvent( + std::shared_ptr keyEvent) const +{ + uint64_t focusedSessionId = SceneSessionManager::GetInstance().GetFocusedSession(); + if (focusedSessionId == INVALID_SESSION_ID) { + WLOGFE("focusedSessionId is invalid"); + return; + } + auto focusedSceneSession = SceneSessionManager::GetInstance().GetSceneSession(focusedSessionId); + if (focusedSceneSession == nullptr) { + WLOGFE("focusedSceneSession is null"); + return; + } + focusedSceneSession->TransferKeyEvent(keyEvent); +} + +void IntentionEventManager::InputEventListener::OnInputEvent( + std::shared_ptr axisEvent) const +{ +} +} +} \ No newline at end of file diff --git a/window_scene/intention_event/src/window_event_process.cpp b/window_scene/intention_event/src/window_event_process.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4d41511ba35f6e823dbdfe5b4e1935222df08a09 --- /dev/null +++ b/window_scene/intention_event/src/window_event_process.cpp @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "window_event_process.h" + +#include "frameworks/core/event/ace_events.h" +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +namespace { +// constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowEventProcess" }; +constexpr double epsilon = -0.001f; +constexpr float MOUSE_RECT_HOT = 4; +constexpr float TOUCH_RECT_HOT = 20; +} // namespace + +WindowEventProcess::WindowEventProcess() {} +WindowEventProcess::~WindowEventProcess() {} + +bool WindowEventProcess::IsInWindowHotRect(const Ace::NG::RectF& windowSceneRect, + const Ace::NG::PointF& parentLocalPoint, int32_t souceType) +{ + float hotOffset = (souceType == static_cast(Ace::SourceType::MOUSE)) + ? MOUSE_RECT_HOT : TOUCH_RECT_HOT; + + float x = windowSceneRect.GetX(); + float y = windowSceneRect.GetY(); + float width = windowSceneRect.Width(); + float height = windowSceneRect.Height(); + float hotX = x - hotOffset; + float hotWidth = width + hotOffset * 2; + float hotY = y - hotOffset; + float hotHeight = height + hotOffset * 2; + + return GreatOrEqual(parentLocalPoint.GetX(), hotX) && + LessOrEqual(parentLocalPoint.GetX(), hotX + hotWidth) && + GreatOrEqual(parentLocalPoint.GetY(), hotY) && + LessOrEqual(parentLocalPoint.GetY(), hotY + hotHeight); +} + +bool WindowEventProcess::LessOrEqual(double left, double right) +{ + constexpr double epsilon = 0.001f; + return (left - right) < epsilon; +} + +bool WindowEventProcess::GreatOrEqual(double left, double right) +{ + return (left - right) > epsilon; +} +} +} \ No newline at end of file diff --git a/windowmanager_aafwk.gni b/windowmanager_aafwk.gni index f5138eb180e62820d1167bf2e65e6d9aabe23c53..7222c076e1194a1d1209961a077b9ca824508500 100644 --- a/windowmanager_aafwk.gni +++ b/windowmanager_aafwk.gni @@ -20,6 +20,7 @@ ability_runtime_napi_path = "${ability_runtime_path}/frameworks/js/napi" window_base_path = "//foundation/window/window_manager" graphic_base_path = "//foundation/graphic" screenlock_mgr_path = "//base/theme/screenlock_mgr" +arkui_base_path = "//foundation/arkui" declare_args() { efficiency_manager_enable = true diff --git a/wm/BUILD.gn b/wm/BUILD.gn index f6ac70c001b063c5a075dc947948f585560449ad..74719732d42d53c9868f1f8844c362cf0096bd83 100644 --- a/wm/BUILD.gn +++ b/wm/BUILD.gn @@ -35,7 +35,11 @@ config("libwm_public_config") { ## Build libwm_static.a ohos_static_library("libwm_static") { - include_dirs = [ "../utils/include" ] + include_dirs = [ + "../utils/include", + "${arkui_base_path}/ace_engine/frameworks", + "${window_base_path}/window_scene/intention_event/include", + ] sources = [ "../wmserver/src/zidl/window_manager_proxy.cpp", @@ -73,6 +77,7 @@ ohos_static_library("libwm_static") { "${window_base_path}/dm:libdm", "${window_base_path}/utils:libwmutil", "${window_base_path}/window_scene/common:window_scene_common", + "${window_base_path}/window_scene/intention_event:libintention_event", "${window_base_path}/window_scene/session:scene_session", "${window_base_path}/window_scene/session_manager:session_manager", ] @@ -137,7 +142,11 @@ ohos_static_library("libwm_static") { ## Build libwm.so ohos_shared_library("libwm") { - include_dirs = [ "../utils/include" ] + include_dirs = [ + "../utils/include", + "${arkui_base_path}/ace_engine/frameworks", + "${window_base_path}/window_scene/intention_event/include", + ] sources = [ "../wmserver/src/zidl/window_manager_proxy.cpp", @@ -172,6 +181,7 @@ ohos_shared_library("libwm") { deps = [ "${window_base_path}/window_scene/common:window_scene_common", + "${window_base_path}/window_scene/intention_event:libintention_event", "${window_base_path}/window_scene/session:scene_session", "${window_base_path}/window_scene/session_manager:session_manager", "../dm:libdm", diff --git a/wm/include/root_scene.h b/wm/include/root_scene.h index 366be9eb65d8706a3301c940b46bd217d32f92eb..b63df64dd9c7e02bb9579305a9d791b818c02075 100644 --- a/wm/include/root_scene.h +++ b/wm/include/root_scene.h @@ -41,9 +41,6 @@ public: void RequestVsync(const std::shared_ptr& vsyncCallback) override; - void ConsumePointerEvent(const std::shared_ptr& inputEvent) override; - void ConsumeKeyEvent(std::shared_ptr& inputEvent) override; - void SetDisplayDensity(float density) { density_ = density; @@ -65,13 +62,11 @@ public: } private: - void RegisterInputEventListener(); std::unique_ptr uiContent_; - std::shared_ptr eventHandler_; std::recursive_mutex mutex_; - + std::shared_ptr eventHandler_; float density_ = 1.0f; WindowType type_ = WindowType::WINDOW_TYPE_DESKTOP; diff --git a/wm/src/root_scene.cpp b/wm/src/root_scene.cpp index 056314080e8eebafca285dc23fb6417aaa9dbeeb..dbc1c2ac046325a9b470b0d5e27611540b275df7 100644 --- a/wm/src/root_scene.cpp +++ b/wm/src/root_scene.cpp @@ -22,35 +22,13 @@ #include "vsync_station.h" #include "window_manager_hilog.h" +#include "intention_event_manager.h" namespace OHOS { namespace Rosen { namespace { constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, HILOG_DOMAIN_WINDOW, "RootScene" }; const std::string INPUT_AND_VSYNC_THREAD = "InputAndVsyncThread"; - -class InputEventListener : public MMI::IInputEventConsumer { -public: - explicit InputEventListener(RootScene* rootScene): rootScene_(rootScene) {} - virtual ~InputEventListener() = default; - - void OnInputEvent(std::shared_ptr pointerEvent) const override - { - rootScene_->ConsumePointerEvent(pointerEvent); - } - - void OnInputEvent(std::shared_ptr keyEvent) const override - { - rootScene_->ConsumeKeyEvent(keyEvent); - } - - void OnInputEvent(std::shared_ptr axisEvent) const override - { - } - -private: - RootScene* rootScene_; -}; } // namespace RootScene::RootScene() @@ -64,6 +42,7 @@ RootScene::~RootScene() void RootScene::LoadContent(const std::string& contentUrl, NativeEngine* engine, NativeValue* storage, AbilityRuntime::Context* context) { + WLOGFI("HYH_TEST LoadContent IN"); if (context == nullptr) { WLOGFE("context is nullptr!"); return; @@ -77,40 +56,6 @@ void RootScene::LoadContent(const std::string& contentUrl, NativeEngine* engine, uiContent_->Initialize(this, contentUrl, storage); uiContent_->Foreground(); - RegisterInputEventListener(); -} - -void RootScene::UpdateViewportConfig(const Rect& rect, WindowSizeChangeReason reason) -{ - std::lock_guard lock(mutex_); - if (uiContent_ == nullptr) { - WLOGFE("uiContent_ is nullptr!"); - return; - } - Ace::ViewportConfig config; - config.SetSize(rect.width_, rect.height_); - config.SetPosition(rect.posX_, rect.posY_); - config.SetDensity(density_); - uiContent_->UpdateViewportConfig(config, reason); -} - -void RootScene::ConsumePointerEvent(const std::shared_ptr& inputEvent) -{ - if (uiContent_) { - uiContent_->ProcessPointerEvent(inputEvent); - } -} - -void RootScene::ConsumeKeyEvent(std::shared_ptr& inputEvent) -{ - if (uiContent_) { - uiContent_->ProcessKeyEvent(inputEvent); - } -} - -void RootScene::RegisterInputEventListener() -{ - auto listener = std::make_shared(this); auto mainEventRunner = AppExecFwk::EventRunner::GetMainEventRunner(); if (mainEventRunner) { WLOGFD("MainEventRunner is available"); @@ -125,7 +70,24 @@ void RootScene::RegisterInputEventListener() VsyncStation::GetInstance().SetIsMainHandlerAvailable(false); VsyncStation::GetInstance().SetVsyncEventHandler(eventHandler_); } - MMI::InputManager::GetInstance()->SetWindowInputEventConsumer(listener, eventHandler_); + + if (!IntentionManager->EnableInputEventListener(uiContent_.get(), eventHandler_)) { + WLOGFE("EnableInputEventListener fail"); + } +} + +void RootScene::UpdateViewportConfig(const Rect& rect, WindowSizeChangeReason reason) +{ + std::lock_guard lock(mutex_); + if (uiContent_ == nullptr) { + WLOGFE("uiContent_ is nullptr!"); + return; + } + Ace::ViewportConfig config; + config.SetSize(rect.width_, rect.height_); + config.SetPosition(rect.posX_, rect.posY_); + config.SetDensity(density_); + uiContent_->UpdateViewportConfig(config, reason); } void RootScene::RequestVsync(const std::shared_ptr& vsyncCallback)