diff --git a/adapter/ohos/entrance/ace_ability.cpp b/adapter/ohos/entrance/ace_ability.cpp index 2e23005f99ff631852e67c80f5924722402bc512..e31677b6d7b95e112ea0dedd84618063caf11f39 100644 --- a/adapter/ohos/entrance/ace_ability.cpp +++ b/adapter/ohos/entrance/ace_ability.cpp @@ -184,33 +184,34 @@ void AceAbility::OnStart(const Want& want) ImageCache::SetCacheFileInfo(); }); OHOS::sptr window = Ability::GetWindow(); - // register surface change callback + // register surface change callback and window mode change callback OHOS::sptr thisAbility(this); window->RegisterWindowChangeListener(thisAbility); + // register input event callback + OHOS::sptr inputEventListener(this); + window->RegisterInputEventListener(inputEventListener); + // register drag event callback OHOS::sptr dragWindowListener(this); window->RegisterDragListener(dragWindowListener); - // register drag event callback + // register Occupied Area callback OHOS::sptr occupiedAreaChangeListener(this); window->RegisterOccupiedAreaChangeListener(occupiedAreaChangeListener); - int32_t width = window->GetRect().width_; - int32_t height = window->GetRect().height_; - LOGI("AceAbility: windowConfig: width: %{public}d, height: %{public}d, left: %{public}d, top: %{public}d", width, - height, window->GetRect().posX_, window->GetRect().posY_); - // get density + int32_t deviceWidth = 0; + int32_t deviceHeight = 0; auto defaultDisplay = Rosen::DisplayManager::GetInstance().GetDefaultDisplay(); if (defaultDisplay) { density_ = defaultDisplay->GetVirtualPixelRatio(); - LOGI("AceAbility: Default display density set: %{public}f", density_); - } else { - LOGI("AceAbility: Default display is null, set density failed. Use default density: %{public}f", density_); + deviceWidth = defaultDisplay->GetWidth(); + deviceHeight = defaultDisplay->GetHeight(); + LOGI("AceAbility: deviceWidth: %{public}d, deviceHeight: %{public}d, default density: %{public}f", deviceWidth, + deviceHeight, density_); } - SystemProperties::InitDeviceInfo(width, height, height >= width ? 0 : 1, density_, false); + SystemProperties::InitDeviceInfo(deviceWidth, deviceHeight, deviceHeight >= deviceWidth ? 0 : 1, density_, false); SystemProperties::SetColorMode(ColorMode::LIGHT); - SystemProperties::SetWindowPos(window->GetRect().posX_, window->GetRect().posY_); std::unique_ptr resConfig(Global::Resource::CreateResConfig()); auto resourceManager = GetResourceManager(); @@ -290,17 +291,16 @@ void AceAbility::OnStart(const Want& want) container->SetPackagePathStr(resPath); container->SetBundlePath(abilityContext->GetBundleCodeDir()); container->SetFilesDataPath(abilityContext->GetFilesDir()); + if (window->IsDecorEnable() && SystemProperties::GetDeviceType() == DeviceType::TABLET) { + LOGI("AceAbility: Container modal is enabled."); + container->SetWindowModal(WindowModal::CONTAINER_MODAL); + } + container->SetWindowName(window->GetWindowName()); } - container->SetWindowName(window->GetWindowName()); SubwindowManager::GetInstance()->AddContainerId(window->GetWindowId(), abilityId_); // create view. auto flutterAceView = Platform::FlutterAceView::CreateView(abilityId_); Platform::FlutterAceView::SurfaceCreated(flutterAceView, window); - flutter::ViewportMetrics metrics; - metrics.physical_width = width; - metrics.physical_height = height; - metrics.device_pixel_ratio = density_; - Platform::FlutterAceView::SetViewportMetrics(flutterAceView, metrics); if (srcPath.empty()) { auto assetBasePathStr = { std::string("assets/js/default/"), std::string("assets/js/share/") }; @@ -326,15 +326,11 @@ void AceAbility::OnStart(const Want& want) Ace::Platform::UIEnvCallback callback = nullptr; #ifdef ENABLE_ROSEN_BACKEND - callback = [window, thisAbility, id = abilityId_]( - const OHOS::Ace::RefPtr& context) mutable { + callback = [window, id = abilityId_](const OHOS::Ace::RefPtr& context) mutable { if (SystemProperties::GetRosenBackendEnabled()) { auto rsUiDirector = OHOS::Rosen::RSUIDirector::Create(); if (rsUiDirector != nullptr) { rsUiDirector->SetRSSurfaceNode(window->GetSurfaceNode()); - - window->RegisterWindowChangeListener(thisAbility); - rsUiDirector->SetUITaskRunner( [taskExecutor = Platform::AceContainer::GetContainer(id)->GetTaskExecutor(), id]( const std::function& task) { @@ -353,8 +349,8 @@ void AceAbility::OnStart(const Want& want) }; #endif // set view - Platform::AceContainer::SetView(flutterAceView, density_, width, height, window->GetWindowId(), callback); - Platform::FlutterAceView::SurfaceChanged(flutterAceView, width, height, 0); + Platform::AceContainer::SetView(flutterAceView, density_, 0, 0, window->GetWindowId(), callback); + Platform::FlutterAceView::SurfaceChanged(flutterAceView, 0, 0, deviceHeight >= deviceWidth ? 0 : 1); // action event handler auto&& actionEventHandler = [this](const std::string& action) { @@ -461,59 +457,6 @@ void AceAbility::OnBackPressed() LOGI("AceAbility::OnBackPressed called End"); } -void AceAbility::OnPointerEvent(std::shared_ptr& pointerEvent) -{ - auto container = Platform::AceContainer::GetContainer(abilityId_); - if (!container) { - LOGE("container may be destroyed."); - return; - } - auto flutterAceView = static_cast(container->GetView()); - if (!flutterAceView) { - LOGE("flutterAceView is null"); - return; - } - flutterAceView->DispatchTouchEvent(flutterAceView, pointerEvent); -} - -void AceAbility::OnKeyUp(const std::shared_ptr& keyEvent) -{ - auto container = Platform::AceContainer::GetContainer(abilityId_); - if (!container) { - LOGE("container may be destroyed."); - return; - } - auto flutterAceView = static_cast(container->GetView()); - if (!flutterAceView) { - LOGI("flutterAceView is null, keyboard event does not take effect"); - return; - } - auto result = flutterAceView->DispatchKeyEvent(flutterAceView, keyEvent); - if (!result) { - LOGI("AceAbility::OnKeyUp: passed to Ability to process"); - Ability::OnKeyUp(keyEvent); - } -} - -void AceAbility::OnKeyDown(const std::shared_ptr& keyEvent) -{ - auto container = Platform::AceContainer::GetContainer(abilityId_); - if (!container) { - LOGE("container may be destroyed."); - return; - } - auto flutterAceView = static_cast(container->GetView()); - if (!flutterAceView) { - LOGI("flutterAceView is null, keyboard event does not take effect"); - return; - } - auto result = flutterAceView->DispatchKeyEvent(flutterAceView, keyEvent); - if (!result) { - LOGI("AceAbility::OnKeyDown: passed to Ability to process"); - Ability::OnKeyDown(keyEvent); - } -} - void AceAbility::OnNewWant(const Want& want) { LOGI("AceAbility::OnNewWant called "); @@ -669,7 +612,31 @@ void AceAbility::OnSizeChange(OHOS::Rosen::Rect rect, OHOS::Rosen::WindowSizeCha void AceAbility::OnModeChange(OHOS::Rosen::WindowMode mode) { - LOGI("AceAbility::OnModeChange"); + LOGI("OnModeChange, window mode is %{public}d", mode); + auto container = Platform::AceContainer::GetContainer(abilityId_); + if (!container) { + LOGE("OnModeChange failed, get container(id=%{public}d) failed", abilityId_); + return; + } + auto taskExecutor = container->GetTaskExecutor(); + if (!taskExecutor) { + LOGE("OnModeChange failed: taskExecutor is null."); + return; + } + taskExecutor->PostTask([container, mode]() { + auto pipelineContext = container->GetPipelineContext(); + if (!pipelineContext) { + LOGE("OnModeChange failed, pipeline context is null."); + return; + } + if (mode == OHOS::Rosen::WindowMode::WINDOW_MODE_FULLSCREEN || + mode == OHOS::Rosen::WindowMode::WINDOW_MODE_SPLIT_PRIMARY || + mode == OHOS::Rosen::WindowMode::WINDOW_MODE_SPLIT_SECONDARY) { + pipelineContext->ShowContainerTitle(false); + } else { + pipelineContext->ShowContainerTitle(true); + } + }, TaskExecutor::TaskType::UI); } void AceAbility::OnSizeChange(const sptr& info) @@ -750,5 +717,41 @@ void AceAbility::OnDrag(int32_t x, int32_t y, OHOS::Rosen::DragEvent event) flutterAceView->ProcessDragEvent(x, y, action); } + +void AceAbility::OnPointerInputEvent(std::shared_ptr& pointerEvent) +{ + auto container = Platform::AceContainer::GetContainer(abilityId_); + if (!container) { + LOGE("OnPointerInputEvent: container may be destroyed."); + return; + } + auto flutterAceView = static_cast(container->GetView()); + if (!flutterAceView) { + LOGE("OnPointerInputEvent: flutterAceView is null."); + return; + } + flutterAceView->DispatchTouchEvent(flutterAceView, pointerEvent); +} + +void AceAbility::OnKeyEvent(std::shared_ptr& keyEvent) +{ + auto container = Platform::AceContainer::GetContainer(abilityId_); + if (!container) { + LOGE("OnKeyEvent: container may be destroyed."); + return; + } + auto flutterAceView = static_cast(container->GetView()); + if (!flutterAceView) { + LOGI("OnKeyEvent: flutterAceView is null, keyboard event does not take effect."); + return; + } + int32_t keyCode = keyEvent->GetKeyCode(); + int32_t keyAction = keyEvent->GetKeyAction(); + if (keyCode == MMI::KeyEvent::KEYCODE_BACK && keyAction == MMI::KeyEvent::KEY_ACTION_UP) { + OnBackPressed(); + return; + } + flutterAceView->DispatchKeyEvent(flutterAceView, keyEvent); +} } // namespace Ace } // namespace OHOS diff --git a/adapter/ohos/entrance/ace_ability.h b/adapter/ohos/entrance/ace_ability.h index 65a2dcf01b5609e53722666a22d57947065ec881..17eb12e70ce489bffb985ef0bd7ccb275d117abc 100644 --- a/adapter/ohos/entrance/ace_ability.h +++ b/adapter/ohos/entrance/ace_ability.h @@ -31,7 +31,8 @@ namespace OHOS::Ace { class AceAbility final : public OHOS::AppExecFwk::Ability, public OHOS::Rosen::IWindowChangeListener, public OHOS::Rosen::IWindowDragListener, - public OHOS::Rosen::IOccupiedAreaChangeListener { + public OHOS::Rosen::IOccupiedAreaChangeListener, + public OHOS::Rosen::IInputEventListener { public: AceAbility() { @@ -47,9 +48,6 @@ public: void OnForeground(const OHOS::AAFwk::Want& want) override; void OnBackground() override; void OnBackPressed() override; - void OnKeyUp(const std::shared_ptr& keyEvent) override; - void OnKeyDown(const std::shared_ptr& keyEvent) override; - void OnPointerEvent(std::shared_ptr& pointerEvent) override; void OnNewWant(const OHOS::AAFwk::Want& want) override; void OnRestoreAbilityState(const OHOS::AppExecFwk::PacMap& inState) override; void OnSaveAbilityState(OHOS::AppExecFwk::PacMap& outState) override; @@ -66,12 +64,18 @@ public: // override Rosen::IWindowDragListener virtual callback function void OnDrag(int32_t x, int32_t y, OHOS::Rosen::DragEvent event) override; + // override Rosen::IWindowChangeListener virtual callback function void OnSizeChange(OHOS::Rosen::Rect rect, OHOS::Rosen::WindowSizeChangeReason reason) override; void OnModeChange(OHOS::Rosen::WindowMode mode) override; + // override Rosen::IOccupiedAreaChangeListener virtual callback function void OnSizeChange(const sptr& info) override; + // override Rosen::IInputEventListener virtual callback function + void OnPointerInputEvent(std::shared_ptr& pointerEvent) override; + void OnKeyEvent(std::shared_ptr& keyEvent) override; + void Dump(const std::vector& params, std::vector& info) override; private: diff --git a/adapter/ohos/entrance/ace_container.cpp b/adapter/ohos/entrance/ace_container.cpp index 8a78d7a1878d2d7ec6e06df48a0dd620bda81b70..c54ce71dd05efa1f273dca3af79fa3900c9de382 100644 --- a/adapter/ohos/entrance/ace_container.cpp +++ b/adapter/ohos/entrance/ace_container.cpp @@ -37,10 +37,8 @@ #include "core/common/text_field_manager.h" #include "core/common/watch_dog.h" #include "core/common/window.h" -#include "core/components/theme/app_theme.h" #include "core/components/theme/theme_constants.h" #include "core/components/theme/theme_manager.h" -#include "core/pipeline/base/element.h" #include "core/pipeline/pipeline_context.h" #include "frameworks/bridge/card_frontend/card_frontend.h" #include "frameworks/bridge/common/utils/engine_helper.h" @@ -551,6 +549,8 @@ void AceContainer::InitializeCallback() [context, x, y, action]() { context->OnDragEvent(x, y, action); }, TaskExecutor::TaskType::UI); }; aceView_->RegisterDragEventCallback(dragEventCallback); + + InitWindowCallback(); } void AceContainer::CreateContainer(int32_t instanceId, FrontendType type, bool isArkApp, std::string instanceName, @@ -1077,4 +1077,47 @@ void AceContainer::InitializeSubContainer(int32_t parentContainerId) taskExecutor_ = AceType::DynamicCast(std::move(taskExec)); GetSettings().useUIAsJSThread = true; } + +void AceContainer::InitWindowCallback() +{ + LOGI("AceContainer InitWindowCallback"); + auto aceAbility = aceAbility_.lock(); + if (aceAbility == nullptr) { + LOGW("AceContainer::InitWindowCallback failed, aceAbility is null."); + return; + } + if (pipelineContext_ == nullptr) { + LOGE("AceContainer::InitWindowCallback failed, pipelineContext_ is null."); + return; + } + auto& window = aceAbility->GetWindow(); + if (window == nullptr) { + LOGE("AceContainer::InitWindowCallback failed, window is null."); + return; + } + std::shared_ptr info = aceAbility->GetAbilityInfo(); + if (info != nullptr) { + pipelineContext_->SetAppLabelId(info->labelId); + pipelineContext_->SetAppIconId(info->iconId); + } + pipelineContext_->SetWindowMinimizeCallBack( + [window]() -> bool { return (OHOS::Rosen::WMError::WM_OK == window->Minimize()); }); + pipelineContext_->SetWindowMaximizeCallBack( + [window]() -> bool { return (OHOS::Rosen::WMError::WM_OK == window->Maximize()); }); + + pipelineContext_->SetWindowRecoverCallBack( + [window]() -> bool { return (OHOS::Rosen::WMError::WM_OK == window->Recover()); }); + + pipelineContext_->SetWindowCloseCallBack( + [window]() -> bool { return (OHOS::Rosen::WMError::WM_OK == window->Close()); }); + + pipelineContext_->SetWindowStartMoveCallBack([window]() { window->StartMove(); }); + + pipelineContext_->SetWindowSplitCallBack([window]() -> bool { + return ( + OHOS::Rosen::WMError::WM_OK == window->SetWindowMode(OHOS::Rosen::WindowMode::WINDOW_MODE_SPLIT_PRIMARY)); + }); + + pipelineContext_->SetWindowGetModeCallBack([window]() -> WindowMode { return (WindowMode)window->GetMode(); }); +} } // namespace OHOS::Ace::Platform diff --git a/adapter/ohos/entrance/ace_container.h b/adapter/ohos/entrance/ace_container.h index 2f15f18a5584580fd7e36379aa46e2d9f7ab5863..be6fed3f080957d92c3471fbb52c599439258d75 100644 --- a/adapter/ohos/entrance/ace_container.h +++ b/adapter/ohos/entrance/ace_container.h @@ -270,6 +270,7 @@ private: void InitializeFrontend(); void InitializeCallback(); void InitializeTask(); + void InitWindowCallback(); void AttachView(std::unique_ptr window, AceView* view, double density, int32_t width, int32_t height, int32_t windowId, UIEnvCallback callback = nullptr); diff --git a/adapter/ohos/entrance/ui_content_impl.cpp b/adapter/ohos/entrance/ui_content_impl.cpp index b87bb602ae4395eeceacb76af57a128511002ba2..e302ecdc893e098c01b887e3e5d82a64790dd759 100644 --- a/adapter/ohos/entrance/ui_content_impl.cpp +++ b/adapter/ohos/entrance/ui_content_impl.cpp @@ -17,7 +17,6 @@ #include #include -#include #include "ability_context.h" #include "ability_info.h" @@ -41,7 +40,6 @@ #include "base/geometry/rect.h" #include "base/log/log.h" #include "base/subwindow/subwindow_manager.h" -#include "base/utils/string_utils.h" #include "base/utils/system_properties.h" #include "core/common/ace_engine.h" #include "core/common/container_scope.h" @@ -55,28 +53,6 @@ const std::string ABS_BUNDLE_CODE_PATH = "/data/app/el1/bundle/public/"; const std::string LOCAL_BUNDLE_CODE_PATH = "/data/storage/el1/bundle/"; const std::string FILE_SEPARATOR = "/"; -WindowMode GetWindowMode(OHOS::Rosen::Window* window) -{ - if (!window) { - LOGE("Get window mode failed, window is null!"); - return WindowMode::WINDOW_MODE_UNDEFINED; - } - switch (window->GetMode()) { - case OHOS::Rosen::WindowMode::WINDOW_MODE_FULLSCREEN: - return WindowMode::WINDOW_MODE_FULLSCREEN; - case OHOS::Rosen::WindowMode::WINDOW_MODE_SPLIT_PRIMARY: - return WindowMode::WINDOW_MODE_SPLIT_PRIMARY; - case OHOS::Rosen::WindowMode::WINDOW_MODE_SPLIT_SECONDARY: - return WindowMode::WINDOW_MODE_SPLIT_SECONDARY; - case OHOS::Rosen::WindowMode::WINDOW_MODE_FLOATING: - return WindowMode::WINDOW_MODE_FLOATING; - case OHOS::Rosen::WindowMode::WINDOW_MODE_PIP: - return WindowMode::WINDOW_MODE_PIP; - default: - return WindowMode::WINDOW_MODE_UNDEFINED; - } -} - } // namespace static std::atomic gInstanceId = 0; @@ -715,15 +691,20 @@ void UIContentImpl::DumpInfo(const std::vector& params, std::vector void UIContentImpl::InitWindowCallback(const std::shared_ptr& info) { - LOGE("UIContent InitWindowCallback"); + LOGI("UIContent InitWindowCallback"); auto container = Platform::AceContainer::GetContainer(instanceId_); if (!container) { - LOGE("get container(id=%{public}d) failed", instanceId_); + LOGE("InitWindowCallback failed, container(id=%{public}d) is null.", instanceId_); return; } auto pipelineContext = container->GetPipelineContext(); if (!pipelineContext) { - LOGE("get pipeline context failed"); + LOGE("InitWindowCallback failed, pipelineContext is null."); + return; + } + auto& window = window_; + if (!window) { + LOGE("InitWindowCallback failed, window is null."); return; } if (info != nullptr) { @@ -731,53 +712,28 @@ void UIContentImpl::InitWindowCallback(const std::shared_ptrSetAppIconId(info->iconId); } - auto& window = window_; - pipelineContext->SetWindowMinimizeCallBack([&window]() -> bool { - if (!window) { - return false; - } - return (OHOS::Rosen::WMError::WM_OK == window->Minimize()); - }); + pipelineContext->SetWindowMinimizeCallBack( + [window]() -> bool { return (OHOS::Rosen::WMError::WM_OK == window->Minimize()); }); - pipelineContext->SetWindowMaximizeCallBack([&window]() -> bool { - if (!window) { - return false; - } - return (OHOS::Rosen::WMError::WM_OK == window->Maximize()); - }); + pipelineContext->SetWindowMaximizeCallBack( + [window]() -> bool { return (OHOS::Rosen::WMError::WM_OK == window->Maximize()); }); - pipelineContext->SetWindowRecoverCallBack([&window]() -> bool { - if (!window) { - return false; - } - return (OHOS::Rosen::WMError::WM_OK == window->Recover()); - }); + pipelineContext->SetWindowRecoverCallBack( + [window]() -> bool { return (OHOS::Rosen::WMError::WM_OK == window->Recover()); }); - pipelineContext->SetWindowCloseCallBack([&window]() -> bool { - if (!window) { - return false; - } - return (OHOS::Rosen::WMError::WM_OK == window->Close()); - }); + pipelineContext->SetWindowCloseCallBack( + [window]() -> bool { return (OHOS::Rosen::WMError::WM_OK == window->Close()); }); - pipelineContext->SetWindowStartMoveCallBack([&window]() { - if (!window) { - return; - } - window->StartMove(); - }); + pipelineContext->SetWindowStartMoveCallBack([window]() { window->StartMove(); }); - pipelineContext->SetWindowSplitCallBack([&window]() -> bool { - if (!window) { - return false; - } + pipelineContext->SetWindowSplitCallBack([window]() -> bool { return ( OHOS::Rosen::WMError::WM_OK == window->SetWindowMode(OHOS::Rosen::WindowMode::WINDOW_MODE_SPLIT_PRIMARY)); }); - pipelineContext->SetWindowGetModeCallBack([&window]() -> WindowMode { return GetWindowMode(window); }); + pipelineContext->SetWindowGetModeCallBack([window]() -> WindowMode { return (WindowMode)window->GetMode(); }); - pipelineContext->SetGetWindowRectImpl([&window]() -> Rect { + pipelineContext->SetGetWindowRectImpl([window]() -> Rect { Rect rect; if (!window) { return rect; diff --git a/frameworks/core/pipeline/pipeline_context.cpp b/frameworks/core/pipeline/pipeline_context.cpp index 49a7f3457f85ced3e08df9ece925efcc258a7f16..9ac48212af1a7ce7ae49c411ecf82fba8cdbe0e2 100644 --- a/frameworks/core/pipeline/pipeline_context.cpp +++ b/frameworks/core/pipeline/pipeline_context.cpp @@ -1814,7 +1814,7 @@ void PipelineContext::WindowSizeChangeAnimate(int32_t width, int32_t height, Win { static const bool IsWindowSizeAnimationEnabled = SystemProperties::IsWindowSizeAnimationEnabled(); if (!rootElement_ || !rootElement_->GetRenderNode() || !IsWindowSizeAnimationEnabled) { - LOGE("RootNodeAnimation: no rootelement found, no animation configured"); + LOGE("RootNodeAnimation: no root element found, no animation configured"); SetRootSizeWithWidthHeight(width, height); return; } @@ -1822,7 +1822,7 @@ void PipelineContext::WindowSizeChangeAnimate(int32_t width, int32_t height, Win switch (type) { case WindowSizeChangeReason::RECOVER: case WindowSizeChangeReason::MAXIMIZE: { - LOGD("PipelineContext::Rootnodeanimation, width = %{private}d, height = %{private}d", width, height); + LOGD("PipelineContext::Root node animation, width = %{private}d, height = %{private}d", width, height); AnimationOption option; constexpr int32_t duration = 400; option.SetDuration(duration);