mirror of
https://gitee.com/openharmony/window_window_manager
synced 2024-11-27 17:11:51 +00:00
add root scene
Signed-off-by: qpzeng <zengqingpeng6@huawei.com> Change-Id: I5bd54a9e30ea7fbbe002be4cdd7668274bcd852d
This commit is contained in:
parent
3d81275b67
commit
6110c69992
@ -642,7 +642,7 @@ public:
|
||||
*
|
||||
* @return WMError
|
||||
*/
|
||||
virtual WMError Destroy() = 0;
|
||||
virtual WMError Destroy() { return WMError::WM_OK; }
|
||||
/**
|
||||
* @brief Show window
|
||||
*
|
||||
@ -650,7 +650,7 @@ public:
|
||||
* @param withAnimation True means window show with animation, false means window show without animation.
|
||||
* @return WM_OK means window show success, others means failed.
|
||||
*/
|
||||
virtual WMError Show(uint32_t reason = 0, bool withAnimation = false) = 0;
|
||||
virtual WMError Show(uint32_t reason = 0, bool withAnimation = false) { return WMError::WM_OK; }
|
||||
/**
|
||||
* @brief Hide window
|
||||
*
|
||||
@ -659,7 +659,10 @@ public:
|
||||
* @param isFromInnerkits True means remove command is from inner kits.
|
||||
* @return WM_OK means window hide success, others means failed.
|
||||
*/
|
||||
virtual WMError Hide(uint32_t reason = 0, bool withAnimation = false, bool isFromInnerkits = true) = 0;
|
||||
virtual WMError Hide(uint32_t reason = 0, bool withAnimation = false, bool isFromInnerkits = true)
|
||||
{
|
||||
return WMError::WM_OK;
|
||||
}
|
||||
/**
|
||||
* @brief move the window to (x, y)
|
||||
*
|
||||
|
@ -23,7 +23,7 @@
|
||||
namespace OHOS::Rosen {
|
||||
class JsScreenSessionManager final : public IScreenConnectionListener {
|
||||
public:
|
||||
JsScreenSessionManager(NativeEngine& engine);
|
||||
explicit JsScreenSessionManager(NativeEngine& engine);
|
||||
~JsScreenSessionManager();
|
||||
|
||||
static NativeValue* Init(NativeEngine* engine, NativeValue* exportObj);
|
||||
|
@ -14,6 +14,13 @@
|
||||
import("//build/ohos.gni")
|
||||
import("../../windowmanager_aafwk.gni")
|
||||
|
||||
config("session_manager_private_config") {
|
||||
include_dirs = [
|
||||
"${window_base_path}/interfaces/innerkits/wm",
|
||||
"${window_base_path}/wm/include",
|
||||
]
|
||||
}
|
||||
|
||||
config("session_manager_public_config") {
|
||||
include_dirs = [
|
||||
"${window_base_path}/window_scene",
|
||||
@ -34,6 +41,8 @@ ohos_shared_library("scene_session_manager") {
|
||||
"src/zidl/scene_session_manager_stub.cpp",
|
||||
]
|
||||
|
||||
configs = [ ":session_manager_private_config" ]
|
||||
|
||||
public_configs = [ ":session_manager_public_config" ]
|
||||
|
||||
deps = [
|
||||
@ -45,12 +54,13 @@ ohos_shared_library("scene_session_manager") {
|
||||
external_deps = [
|
||||
"ability_base:want",
|
||||
"ability_runtime:ability_manager",
|
||||
"ace_engine:ace_uicontent",
|
||||
"c_utils:utils",
|
||||
"eventhandler:libeventhandler",
|
||||
"hilog_native:libhilog",
|
||||
"ipc:ipc_single",
|
||||
"window_manager:libwm",
|
||||
]
|
||||
|
||||
innerapi_tags = [ "platformsdk" ]
|
||||
part_name = "window_manager"
|
||||
subsystem_name = "window"
|
||||
@ -72,6 +82,7 @@ ohos_shared_library("screen_session_manager") {
|
||||
"eventhandler:libeventhandler",
|
||||
"hilog_native:libhilog",
|
||||
]
|
||||
|
||||
innerapi_tags = [ "platformsdk" ]
|
||||
part_name = "window_manager"
|
||||
subsystem_name = "window"
|
||||
@ -106,6 +117,7 @@ ohos_shared_library("session_manager") {
|
||||
"ipc:ipc_single",
|
||||
]
|
||||
|
||||
innerapi_tags = [ "platformsdk" ]
|
||||
part_name = "window_manager"
|
||||
subsystem_name = "window"
|
||||
}
|
||||
|
@ -23,15 +23,12 @@
|
||||
#include "session_manager_base.h"
|
||||
#include "session_manager/include/zidl/scene_session_manager_stub.h"
|
||||
|
||||
namespace OHOS::Ace::NG {
|
||||
class UIWindow;
|
||||
}
|
||||
|
||||
namespace OHOS::AAFwk {
|
||||
class SessionInfo;
|
||||
}
|
||||
|
||||
namespace OHOS::Rosen {
|
||||
class RootScene;
|
||||
class SceneSession;
|
||||
using NotifyCreateSpecificSessionFunc = std::function<void(const sptr<SceneSession>& session)>;
|
||||
class SceneSessionManager : public SceneSessionManagerStub,
|
||||
@ -60,7 +57,7 @@ private:
|
||||
sptr<AAFwk::SessionInfo> SetAbilitySessionInfo(const sptr<SceneSession>& scnSession);
|
||||
std::map<uint64_t, sptr<SceneSession>> abilitySceneMap_;
|
||||
sptr<RootSceneSession> rootSceneSession_;
|
||||
std::shared_ptr<Ace::NG::UIWindow> rootScene_;
|
||||
sptr<RootScene> rootScene_;
|
||||
NotifyCreateSpecificSessionFunc createSpecificSessionFunc_;
|
||||
};
|
||||
} // namespace OHOS::Rosen
|
||||
|
@ -17,10 +17,10 @@
|
||||
|
||||
#include <ability_manager_client.h>
|
||||
#include <start_options.h>
|
||||
#include <ui_window.h>
|
||||
#include <want.h>
|
||||
|
||||
#include "common/include/message_scheduler.h"
|
||||
#include "root_scene.h"
|
||||
#include "session/host/include/scene_session.h"
|
||||
#include "session_info.h"
|
||||
#include "window_manager_hilog.h"
|
||||
@ -52,7 +52,7 @@ sptr<RootSceneSession> SceneSessionManager::GetRootSceneSession()
|
||||
}
|
||||
|
||||
rootSceneSession_ = new (std::nothrow) RootSceneSession();
|
||||
rootScene_ = Ace::NG::UIWindow::CreateRootScene();
|
||||
rootScene_ = new (std::nothrow) RootScene();
|
||||
if (!rootSceneSession_ || !rootScene_) {
|
||||
WLOGFE("rootSceneSession or rootScene is nullptr");
|
||||
return sptr<RootSceneSession>(nullptr);
|
||||
|
@ -142,6 +142,7 @@ ohos_shared_library("libwm") {
|
||||
"../wmserver/src/zidl/window_manager_proxy.cpp",
|
||||
"src/color_parser.cpp",
|
||||
"src/input_transfer_station.cpp",
|
||||
"src/root_scene.cpp",
|
||||
"src/static_call.cpp",
|
||||
"src/vsync_station.cpp",
|
||||
"src/window.cpp",
|
||||
|
65
wm/include/root_scene.h
Normal file
65
wm/include/root_scene.h
Normal file
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* 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_ROOT_SCENE_H
|
||||
#define OHOS_ROSEN_ROOT_SCENE_H
|
||||
|
||||
#include <mutex>
|
||||
|
||||
#include "window.h"
|
||||
|
||||
namespace OHOS::AppExecFwk {
|
||||
class EventHandler;
|
||||
} // namespace OHOS::AppExecFwk
|
||||
|
||||
namespace OHOS::Ace {
|
||||
class UIContent;
|
||||
} // namespace OHOS::Ace
|
||||
|
||||
namespace OHOS {
|
||||
namespace Rosen {
|
||||
class RootScene : public Window {
|
||||
public:
|
||||
RootScene();
|
||||
virtual ~RootScene();
|
||||
|
||||
void LoadContent(const std::string& contentUrl,
|
||||
NativeEngine* engine, NativeValue* storage, AbilityRuntime::Context* context);
|
||||
void UpdateViewportConfig(const Rect& rect, WindowSizeChangeReason reason);
|
||||
|
||||
void RequestVsync(const std::shared_ptr<VsyncCallback>& vsyncCallback) override;
|
||||
|
||||
void ConsumePointerEvent(const std::shared_ptr<MMI::PointerEvent>& inputEvent) override;
|
||||
void ConsumeKeyEvent(std::shared_ptr<MMI::KeyEvent>& inputEvent) override;
|
||||
|
||||
void SetDisplayDensity(float density)
|
||||
{
|
||||
density_ = density;
|
||||
}
|
||||
|
||||
private:
|
||||
void RegisterInputEventListener();
|
||||
|
||||
std::unique_ptr<Ace::UIContent> uiContent_;
|
||||
std::shared_ptr<AppExecFwk::EventHandler> eventHandler_;
|
||||
|
||||
std::recursive_mutex mutex_;
|
||||
|
||||
float density_ = 1.0f;
|
||||
};
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // OHOS_ROSEN_ROOT_SCENE_H
|
@ -22,6 +22,7 @@
|
||||
OHOS::Rosen::WindowManager*;
|
||||
OHOS::Rosen::Window*;
|
||||
OHOS::Rosen::WindowAccessibilityController*;
|
||||
OHOS::Rosen::RootScene*;
|
||||
|
||||
VTT*FocusChangeInfo*;
|
||||
VTT*WindowVisibilityInfo*;
|
||||
|
137
wm/src/root_scene.cpp
Normal file
137
wm/src/root_scene.cpp
Normal file
@ -0,0 +1,137 @@
|
||||
/*
|
||||
* 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 "root_scene.h"
|
||||
|
||||
#include <event_handler.h>
|
||||
#include <input_manager.h>
|
||||
#include <ui_content.h>
|
||||
#include <viewport_config.h>
|
||||
|
||||
#include "vsync_station.h"
|
||||
#include "window_manager_hilog.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<MMI::PointerEvent> pointerEvent) const override
|
||||
{
|
||||
rootScene_->ConsumePointerEvent(pointerEvent);
|
||||
}
|
||||
|
||||
void OnInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent) const override
|
||||
{
|
||||
rootScene_->ConsumeKeyEvent(keyEvent);
|
||||
}
|
||||
|
||||
void OnInputEvent(std::shared_ptr<MMI::AxisEvent> axisEvent) const override
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
RootScene* rootScene_;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
RootScene::RootScene()
|
||||
{
|
||||
}
|
||||
|
||||
RootScene::~RootScene()
|
||||
{
|
||||
}
|
||||
|
||||
void RootScene::LoadContent(const std::string& contentUrl, NativeEngine* engine, NativeValue* storage,
|
||||
AbilityRuntime::Context* context)
|
||||
{
|
||||
if (context == nullptr) {
|
||||
WLOGFE("context is nullptr!");
|
||||
return;
|
||||
}
|
||||
uiContent_ = Ace::UIContent::Create(context, engine);
|
||||
if (uiContent_ == nullptr) {
|
||||
WLOGFE("uiContent_ is nullptr!");
|
||||
return;
|
||||
}
|
||||
|
||||
uiContent_->Initialize(this, contentUrl, storage);
|
||||
uiContent_->Foreground();
|
||||
|
||||
RegisterInputEventListener();
|
||||
}
|
||||
|
||||
void RootScene::UpdateViewportConfig(const Rect& rect, WindowSizeChangeReason reason)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> 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<MMI::PointerEvent>& inputEvent)
|
||||
{
|
||||
if (uiContent_) {
|
||||
uiContent_->ProcessPointerEvent(inputEvent);
|
||||
}
|
||||
}
|
||||
|
||||
void RootScene::ConsumeKeyEvent(std::shared_ptr<MMI::KeyEvent>& inputEvent)
|
||||
{
|
||||
if (uiContent_) {
|
||||
uiContent_->ProcessKeyEvent(inputEvent);
|
||||
}
|
||||
}
|
||||
|
||||
void RootScene::RegisterInputEventListener()
|
||||
{
|
||||
auto listener = std::make_shared<InputEventListener>(this);
|
||||
auto mainEventRunner = AppExecFwk::EventRunner::GetMainEventRunner();
|
||||
if (mainEventRunner) {
|
||||
WLOGFD("MainEventRunner is available");
|
||||
eventHandler_ = std::make_shared<AppExecFwk::EventHandler>(mainEventRunner);
|
||||
} else {
|
||||
WLOGFD("MainEventRunner is not available");
|
||||
eventHandler_ = AppExecFwk::EventHandler::Current();
|
||||
if (!eventHandler_) {
|
||||
eventHandler_ =
|
||||
std::make_shared<AppExecFwk::EventHandler>(AppExecFwk::EventRunner::Create(INPUT_AND_VSYNC_THREAD));
|
||||
}
|
||||
VsyncStation::GetInstance().SetIsMainHandlerAvailable(false);
|
||||
VsyncStation::GetInstance().SetVsyncEventHandler(eventHandler_);
|
||||
}
|
||||
MMI::InputManager::GetInstance()->SetWindowInputEventConsumer(listener, eventHandler_);
|
||||
}
|
||||
|
||||
void RootScene::RequestVsync(const std::shared_ptr<VsyncCallback>& vsyncCallback)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
VsyncStation::GetInstance().RequestVsync(vsyncCallback);
|
||||
}
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
@ -690,8 +690,6 @@ void WindowSessionImpl::RequestVsync(const std::shared_ptr<VsyncCallback>& vsync
|
||||
return;
|
||||
}
|
||||
VsyncStation::GetInstance().RequestVsync(vsyncCallback);
|
||||
return;
|
||||
}
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user