mirror of
https://gitee.com/openharmony/arkui_ace_engine
synced 2024-11-27 09:12:41 +00:00
add modal ui extension native interfaces
Signed-off-by: liyujie <liyujie43@huawei.com> Change-Id: Ib33a32a52ca7e41937299adc400b7badd9dac817
This commit is contained in:
parent
036632f411
commit
430c7ea8ff
@ -302,8 +302,6 @@ frameworks/core/components_ng/components_plugin.gni @sunfei2021
|
||||
frameworks/core/components_ng/components.gni @sunfei2021
|
||||
|
||||
[Test source]
|
||||
frameworks/core/components_ng/test/ @liyujie43
|
||||
frameworks/core/components/test/ @liyujie43
|
||||
frameworks/bridge/test/ @liyujie43
|
||||
test/mock/ @liyujie43
|
||||
test/unittest/ @liyujie43
|
||||
|
@ -1809,4 +1809,49 @@ void UIContentImpl::SetFocusWindowId(uint32_t focusWindowId)
|
||||
},
|
||||
TaskExecutor::TaskType::UI);
|
||||
}
|
||||
|
||||
int32_t UIContentImpl::CreateModalUIExtension(const AAFwk::Want& want, const ModalUIExtensionCallbacks& callbacks)
|
||||
{
|
||||
LOGI("create ui extension modal page start");
|
||||
auto container = Platform::AceContainer::GetContainer(instanceId_);
|
||||
CHECK_NULL_RETURN_NOLOG(container, 0);
|
||||
ContainerScope scope(instanceId_);
|
||||
auto taskExecutor = Container::CurrentTaskExecutor();
|
||||
CHECK_NULL_RETURN_NOLOG(taskExecutor, 0);
|
||||
int32_t sessionId = 0;
|
||||
taskExecutor->PostSyncTask(
|
||||
[container, &sessionId, want, callbacks = callbacks]() {
|
||||
auto pipeline = AceType::DynamicCast<NG::PipelineContext>(container->GetPipelineContext());
|
||||
CHECK_NULL_VOID_NOLOG(pipeline);
|
||||
auto overlay = pipeline->GetOverlayManager();
|
||||
CHECK_NULL_VOID_NOLOG(overlay);
|
||||
sessionId = overlay->CreateModalUIExtension(want, callbacks);
|
||||
},
|
||||
TaskExecutor::TaskType::UI);
|
||||
LOGI("create ui extension modal page end, sessionId=%{public}d", sessionId);
|
||||
return sessionId;
|
||||
}
|
||||
|
||||
void UIContentImpl::CloseModalUIExtension(int32_t sessionId)
|
||||
{
|
||||
LOGI("close ui extension modal page, sessionId=%{public}d", sessionId);
|
||||
if (sessionId == 0) {
|
||||
LOGW("refuse to close ui extension modal page");
|
||||
return;
|
||||
}
|
||||
auto container = Platform::AceContainer::GetContainer(instanceId_);
|
||||
CHECK_NULL_VOID_NOLOG(container);
|
||||
ContainerScope scope(instanceId_);
|
||||
auto taskExecutor = Container::CurrentTaskExecutor();
|
||||
CHECK_NULL_VOID_NOLOG(taskExecutor);
|
||||
taskExecutor->PostTask(
|
||||
[container, sessionId]() {
|
||||
auto pipeline = AceType::DynamicCast<NG::PipelineContext>(container->GetPipelineContext());
|
||||
CHECK_NULL_VOID_NOLOG(pipeline);
|
||||
auto overlay = pipeline->GetOverlayManager();
|
||||
CHECK_NULL_VOID_NOLOG(overlay);
|
||||
overlay->CloseModalUIExtension(sessionId);
|
||||
},
|
||||
TaskExecutor::TaskType::UI);
|
||||
}
|
||||
} // namespace OHOS::Ace
|
||||
|
@ -153,6 +153,9 @@ public:
|
||||
void SetIsFocusActive(bool isFocusActive) override;
|
||||
void SetFocusWindowId(uint32_t focusWindowId) override;
|
||||
|
||||
int32_t CreateModalUIExtension(const AAFwk::Want& want, const ModalUIExtensionCallbacks& callbacks) override;
|
||||
void CloseModalUIExtension(int32_t sessionId) override;
|
||||
|
||||
private:
|
||||
void CommonInitialize(OHOS::Rosen::Window* window, const std::string& contentInfo, NativeValue* storage);
|
||||
void CommonInitializeForm(OHOS::Rosen::Window* window, const std::string& contentInfo, NativeValue* storage);
|
||||
|
@ -63,6 +63,7 @@ template("ace_osal_ohos_source_set") {
|
||||
"frame_report.cpp",
|
||||
"layout_inspector.cpp",
|
||||
"log_wrapper.cpp",
|
||||
"modal_ui_extension_impl.cpp",
|
||||
"ressched_report.cpp",
|
||||
"socperf_client_impl.cpp",
|
||||
"system_properties.cpp",
|
||||
@ -140,6 +141,7 @@ template("ace_osal_ohos_source_set") {
|
||||
"hitrace:libhitracechain",
|
||||
"safwk:system_ability_fwk",
|
||||
"samgr:samgr_proxy",
|
||||
"window_manager:scene_session",
|
||||
]
|
||||
deps += [
|
||||
"$ace_root/interfaces/inner_api/drawable_descriptor:drawable_descriptor",
|
||||
|
32
adapter/ohos/osal/modal_ui_extension_impl.cpp
Normal file
32
adapter/ohos/osal/modal_ui_extension_impl.cpp
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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 "core/common/modal_ui_extension.h"
|
||||
#include "core/components_ng/pattern/ui_extension/ui_extension_model_ng.h"
|
||||
#include "core/components_ng/pattern/ui_extension/ui_extension_pattern.h"
|
||||
|
||||
namespace OHOS::Ace {
|
||||
RefPtr<NG::FrameNode> ModalUIExtension::Create(const AAFwk::Want& want, const ModalUIExtensionCallbacks& callbacks)
|
||||
{
|
||||
return NG::UIExtensionModelNG::Create(want, callbacks);
|
||||
}
|
||||
|
||||
int32_t ModalUIExtension::GetSessionId(const RefPtr<NG::FrameNode>& uiExtNode)
|
||||
{
|
||||
auto pattern = uiExtNode->GetPattern<NG::UIExtensionPattern>();
|
||||
CHECK_NULL_RETURN(pattern, 0);
|
||||
return pattern->GetSessionId();
|
||||
}
|
||||
} // namespace OHOS::Ace
|
@ -443,4 +443,10 @@ void UIContentImpl::NotifyMemoryLevel(int32_t level)
|
||||
pipelineContext->NotifyMemoryLevel(level);
|
||||
}
|
||||
|
||||
int32_t UIContentImpl::CreateModalUIExtension(const AAFwk::Want& want, const ModalUIExtensionCallbacks& callbacks)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void UIContentImpl::CloseModalUIExtension(int32_t sessionId) {}
|
||||
} // namespace OHOS::Ace
|
||||
|
@ -109,6 +109,9 @@ public:
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int32_t CreateModalUIExtension(const AAFwk::Want& want, const ModalUIExtensionCallbacks& callbacks) override;
|
||||
void CloseModalUIExtension(int32_t sessionId) override;
|
||||
|
||||
private:
|
||||
void CommonInitialize(OHOS::Rosen::Window* window, const std::string& contentInfo, NativeValue* storage);
|
||||
void DestroyCallback() const;
|
||||
|
@ -68,6 +68,7 @@ ohos_source_set("preview_osal_source") {
|
||||
"fetch_manager.cpp",
|
||||
"frame_report.cpp",
|
||||
"image_source_preview.cpp",
|
||||
"modal_ui_extension_impl.cpp",
|
||||
"mouse_style_ohos.cpp",
|
||||
"pixel_map_preview.cpp",
|
||||
"response_data.cpp",
|
||||
|
29
adapter/preview/osal/modal_ui_extension_impl.cpp
Normal file
29
adapter/preview/osal/modal_ui_extension_impl.cpp
Normal file
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* 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 "core/common/modal_ui_extension.h"
|
||||
|
||||
namespace OHOS::Ace {
|
||||
|
||||
RefPtr<NG::FrameNode> ModalUIExtension::Create(const AAFwk::Want& want, const ModalUIExtensionCallbacks& callbacks)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int32_t ModalUIExtension::GetSessionId(const RefPtr<NG::FrameNode>& uiExtNode)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
} // namespace OHOS::Ace
|
@ -114,7 +114,8 @@
|
||||
"header_files": [
|
||||
"ui_content.h",
|
||||
"viewport_config.h",
|
||||
"serializeable_object.h"
|
||||
"serializeable_object.h",
|
||||
"modal_ui_extension_callbacks.h"
|
||||
]
|
||||
},
|
||||
"name": "//foundation/arkui/ace_engine/interfaces/inner_api/ace:ace_uicontent"
|
||||
|
40
frameworks/core/common/modal_ui_extension.h
Normal file
40
frameworks/core/common/modal_ui_extension.h
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* 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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_MODAL_UI_EXTENSION_HELPER_H
|
||||
#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_MODAL_UI_EXTENSION_HELPER_H
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "core/components_ng/base/frame_node.h"
|
||||
|
||||
namespace OHOS::AAFwk {
|
||||
class Want;
|
||||
} // namespace OHOS::AAFwk
|
||||
|
||||
namespace OHOS::Ace {
|
||||
struct ModalUIExtensionCallbacks;
|
||||
} // namespace OHOS::Ace
|
||||
|
||||
namespace OHOS::Ace {
|
||||
class ModalUIExtension final {
|
||||
public:
|
||||
static RefPtr<NG::FrameNode> Create(const AAFwk::Want& want, const ModalUIExtensionCallbacks& callbacks);
|
||||
|
||||
static int32_t GetSessionId(const RefPtr<NG::FrameNode>& uiExtNode);
|
||||
};
|
||||
|
||||
} // namespace OHOS::Ace
|
||||
#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_MODAL_UI_EXTENSION_HELPER_H
|
@ -28,6 +28,7 @@
|
||||
#include "core/animation/spring_curve.h"
|
||||
#include "core/common/ace_application_info.h"
|
||||
#include "core/common/container.h"
|
||||
#include "core/common/modal_ui_extension.h"
|
||||
#include "core/components/common/properties/color.h"
|
||||
#include "core/components/select/select_theme.h"
|
||||
#include "core/components/toast/toast_theme.h"
|
||||
@ -1933,4 +1934,30 @@ void OverlayManager::RemoveEventColumn()
|
||||
hasEvent_ = false;
|
||||
}
|
||||
#endif // ENABLE_DRAG_FRAMEWORK
|
||||
|
||||
int32_t OverlayManager::CreateModalUIExtension(const AAFwk::Want& want, const ModalUIExtensionCallbacks& callbacks)
|
||||
{
|
||||
ModalStyle modalStyle;
|
||||
modalStyle.modalTransition = NG::ModalTransition::NONE;
|
||||
auto uiExtNode = ModalUIExtension::Create(want, callbacks);
|
||||
auto layoutProperty = uiExtNode->GetLayoutProperty();
|
||||
CHECK_NULL_RETURN(layoutProperty, 0);
|
||||
auto full = CalcLength(Dimension(1.0, DimensionUnit::PERCENT));
|
||||
layoutProperty->UpdateUserDefinedIdealSize(CalcSize(full, full));
|
||||
auto buildNodeFunc = [uiExtNode]() -> RefPtr<UINode> {
|
||||
uiExtNode->MarkModifyDone();
|
||||
return uiExtNode;
|
||||
};
|
||||
auto sessionId = ModalUIExtension::GetSessionId(uiExtNode);
|
||||
// Convert the sessionId into a negative number to distinguish it from the targetId of other modal pages
|
||||
BindContentCover(true, nullptr, std::move(buildNodeFunc), modalStyle, nullptr, nullptr, -(sessionId));
|
||||
return sessionId;
|
||||
}
|
||||
|
||||
void OverlayManager::CloseModalUIExtension(int32_t sessionId)
|
||||
{
|
||||
ModalStyle modalStyle;
|
||||
modalStyle.modalTransition = NG::ModalTransition::NONE;
|
||||
BindContentCover(false, nullptr, nullptr, modalStyle, nullptr, nullptr, -(sessionId));
|
||||
}
|
||||
} // namespace OHOS::Ace::NG
|
||||
|
@ -16,6 +16,7 @@
|
||||
#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_OVERLAY_OVERLAY_MANAGER_H
|
||||
#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_OVERLAY_OVERLAY_MANAGER_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <unordered_map>
|
||||
#include <utility>
|
||||
@ -35,6 +36,14 @@
|
||||
#include "core/components_ng/pattern/text_picker/textpicker_event_hub.h"
|
||||
#include "core/pipeline_ng/ui_task_scheduler.h"
|
||||
|
||||
namespace OHOS::Ace {
|
||||
struct ModalUIExtensionCallbacks;
|
||||
} // namespace OHOS::Ace
|
||||
|
||||
namespace OHOS::AAFwk {
|
||||
class Want;
|
||||
} // namespace OHOS::AAFwk
|
||||
|
||||
namespace OHOS::Ace::NG {
|
||||
|
||||
struct PopupInfo {
|
||||
@ -250,6 +259,10 @@ public:
|
||||
|
||||
RefPtr<UINode> FindWindowScene(RefPtr<FrameNode> targetNode);
|
||||
|
||||
// ui extension
|
||||
int32_t CreateModalUIExtension(const AAFwk::Want& want, const ModalUIExtensionCallbacks& callbacks);
|
||||
void CloseModalUIExtension(int32_t sessionId);
|
||||
|
||||
private:
|
||||
void PopToast(int32_t targetId);
|
||||
|
||||
|
@ -15,6 +15,8 @@
|
||||
|
||||
#include "core/components_ng/pattern/ui_extension/ui_extension_model_ng.h"
|
||||
|
||||
#include "interfaces/inner_api/ace/modal_ui_extension_callbacks.h"
|
||||
|
||||
#include "core/components/common/layout/constants.h"
|
||||
#include "core/components_ng/base/view_stack_processor.h"
|
||||
#include "core/components_ng/pattern/ui_extension/ui_extension_pattern.h"
|
||||
@ -38,6 +40,23 @@ RefPtr<FrameNode> UIExtensionModelNG::Create(const std::string& bundleName, cons
|
||||
return frameNode;
|
||||
}
|
||||
|
||||
RefPtr<FrameNode> UIExtensionModelNG::Create(const AAFwk::Want& want, const ModalUIExtensionCallbacks& callbacks)
|
||||
{
|
||||
auto nodeId = ElementRegister::GetInstance()->MakeUniqueId();
|
||||
auto frameNode = FrameNode::GetOrCreateFrameNode(
|
||||
V2::UI_EXTENSION_COMPONENT_ETS_TAG, nodeId, [want]() { return AceType::MakeRefPtr<UIExtensionPattern>(want); });
|
||||
auto pipeline = PipelineContext::GetCurrentContext();
|
||||
CHECK_NULL_RETURN(pipeline, frameNode);
|
||||
pipeline->AddWindowStateChangedCallback(nodeId);
|
||||
auto pattern = frameNode->GetPattern<UIExtensionPattern>();
|
||||
CHECK_NULL_RETURN(pattern, frameNode);
|
||||
pattern->SetOnReleaseCallback(std::move(callbacks.onRelease));
|
||||
pattern->SetOnErrorCallback(std::move(callbacks.onError));
|
||||
pattern->SetOnResultCallback(std::move(callbacks.onResult));
|
||||
pattern->SetOnReceiveCallback(std::move(callbacks.onReceive));
|
||||
return frameNode;
|
||||
}
|
||||
|
||||
void UIExtensionModelNG::Create(const RefPtr<OHOS::Ace::WantWrap>& wantWrap)
|
||||
{
|
||||
auto* stack = ViewStackProcessor::GetInstance();
|
||||
|
@ -22,12 +22,18 @@
|
||||
#include "core/components_ng/base/frame_node.h"
|
||||
#include "core/components_ng/pattern/ui_extension/ui_extension_model.h"
|
||||
|
||||
namespace OHOS::Ace {
|
||||
struct ModalUIExtensionCallbacks;
|
||||
} // namespace OHOS::Ace
|
||||
|
||||
namespace OHOS::Ace::NG {
|
||||
class ACE_EXPORT UIExtensionModelNG : public UIExtensionModel {
|
||||
public:
|
||||
static RefPtr<FrameNode> Create(const std::string& bundleName, const std::string& abilityName,
|
||||
const std::map<std::string, std::string>& params, std::function<void(int32_t)>&& onRelease,
|
||||
std::function<void(int32_t, const std::string&, const std::string&)>&& onError);
|
||||
static RefPtr<FrameNode> Create(const AAFwk::Want& want, const ModalUIExtensionCallbacks& callbacks);
|
||||
|
||||
void Create(const RefPtr<OHOS::Ace::WantWrap>& wantWrap) override;
|
||||
void SetOnRemoteReady(std::function<void(const RefPtr<UIExtensionProxy>&)>&& onRemoteReady) override;
|
||||
void SetOnRelease(std::function<void(int32_t)>&& onRelease) override;
|
||||
|
@ -15,6 +15,8 @@
|
||||
|
||||
#include "core/components_ng/pattern/ui_extension/ui_extension_pattern.h"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "session/host/include/extension_session.h"
|
||||
#include "session_manager/include/extension_session_manager.h"
|
||||
#include "ui/rs_surface_node.h"
|
||||
@ -62,6 +64,28 @@ UIExtensionPattern::UIExtensionPattern(const RefPtr<OHOS::Ace::WantWrap>& wantWr
|
||||
extensionSession->RegisterExtensionSessionEventCallback(extSessionEventCallback);
|
||||
}
|
||||
|
||||
UIExtensionPattern::UIExtensionPattern(const AAFwk::Want& want)
|
||||
{
|
||||
auto container = AceType::DynamicCast<Platform::AceContainer>(Container::Current());
|
||||
CHECK_NULL_VOID_NOLOG(container);
|
||||
auto callerToken = container->GetToken();
|
||||
Rosen::SessionInfo extensionSessionInfo = {
|
||||
.bundleName_ = want.GetElement().GetBundleName(),
|
||||
.abilityName_ = want.GetElement().GetAbilityName(),
|
||||
.callerToken_ = callerToken,
|
||||
.want = new (std::nothrow) Want(want),
|
||||
};
|
||||
session_ = Rosen::ExtensionSessionManager::GetInstance().RequestExtensionSession(extensionSessionInfo);
|
||||
CHECK_NULL_VOID(session_);
|
||||
RegisterLifecycleListener();
|
||||
LOGI("Native Modal UIExtension request UIExtensionAbility start");
|
||||
RequestExtensionSessionActivation();
|
||||
sptr<Rosen::ExtensionSession> extensionSession(static_cast<Rosen::ExtensionSession*>(session_.GetRefPtr()));
|
||||
sptr<Rosen::ExtensionSession::ExtensionSessionEventCallback> extSessionEventCallback =
|
||||
new (std::nothrow) Rosen::ExtensionSession::ExtensionSessionEventCallback();
|
||||
extensionSession->RegisterExtensionSessionEventCallback(extSessionEventCallback);
|
||||
}
|
||||
|
||||
UIExtensionPattern::~UIExtensionPattern()
|
||||
{
|
||||
UnregisterLifecycleListener();
|
||||
@ -71,7 +95,7 @@ UIExtensionPattern::~UIExtensionPattern()
|
||||
|
||||
void UIExtensionPattern::OnConnect()
|
||||
{
|
||||
LOGI("UIExtensionPattern OnConnect called");
|
||||
LOGI("UIExtension OnConnect called");
|
||||
ContainerScope scope(instanceId_);
|
||||
auto pipeline = PipelineBase::GetCurrentContext();
|
||||
CHECK_NULL_VOID_NOLOG(pipeline);
|
||||
@ -111,12 +135,13 @@ void UIExtensionPattern::OnConnectInner()
|
||||
|
||||
void UIExtensionPattern::OnDisconnect()
|
||||
{
|
||||
LOGI("UIExtensionPattern OnDisconnect called");
|
||||
LOGI("UIExtension OnDisconnect called");
|
||||
ContainerScope scope(instanceId_);
|
||||
auto pipeline = PipelineBase::GetCurrentContext();
|
||||
CHECK_NULL_VOID_NOLOG(pipeline);
|
||||
auto taskExecutor = pipeline->GetTaskExecutor();
|
||||
CHECK_NULL_VOID_NOLOG(taskExecutor);
|
||||
isDestruction_ = true;
|
||||
taskExecutor->PostTask(
|
||||
[weak = WeakClaim(this)]() {
|
||||
auto extensionPattern = weak.Upgrade();
|
||||
@ -180,30 +205,36 @@ void UIExtensionPattern::RequestExtensionSessionActivation()
|
||||
|
||||
void UIExtensionPattern::RequestExtensionSessionBackground()
|
||||
{
|
||||
LOGI("UIExtension request UIExtensionAbility background");
|
||||
sptr<Rosen::ExtensionSession> extensionSession(static_cast<Rosen::ExtensionSession*>(session_.GetRefPtr()));
|
||||
auto errcode = Rosen::ExtensionSessionManager::GetInstance().RequestExtensionSessionBackground(extensionSession);
|
||||
if (errcode != OHOS::Rosen::WSError::WS_OK) {
|
||||
if (onErrorCallback_) {
|
||||
int32_t code = static_cast<int32_t>(errcode);
|
||||
std::string name = "background_fail";
|
||||
std::string message = "background ui extension ability failed, please check AMS log.";
|
||||
onErrorCallback_(code, name, message);
|
||||
LOGI("UIExtension request UIExtensionAbility background, isDestruction_=%{public}u", isDestruction_);
|
||||
if (!isDestruction_) {
|
||||
sptr<Rosen::ExtensionSession> extensionSession(static_cast<Rosen::ExtensionSession*>(session_.GetRefPtr()));
|
||||
auto errcode =
|
||||
Rosen::ExtensionSessionManager::GetInstance().RequestExtensionSessionBackground(extensionSession);
|
||||
if (errcode != OHOS::Rosen::WSError::WS_OK) {
|
||||
if (onErrorCallback_) {
|
||||
int32_t code = static_cast<int32_t>(errcode);
|
||||
std::string name = "background_fail";
|
||||
std::string message = "background ui extension ability failed, please check AMS log.";
|
||||
onErrorCallback_(code, name, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UIExtensionPattern::RequestExtensionSessionDestruction()
|
||||
{
|
||||
LOGI("UIExtension request UIExtensionAbility destroy");
|
||||
sptr<Rosen::ExtensionSession> extensionSession(static_cast<Rosen::ExtensionSession*>(session_.GetRefPtr()));
|
||||
auto errcode = Rosen::ExtensionSessionManager::GetInstance().RequestExtensionSessionDestruction(extensionSession);
|
||||
if (errcode != OHOS::Rosen::WSError::WS_OK) {
|
||||
if (onErrorCallback_) {
|
||||
int32_t code = static_cast<int32_t>(errcode);
|
||||
std::string name = "terminate_fail";
|
||||
std::string message = "terminate ui extension ability failed, please check AMS log.";
|
||||
onErrorCallback_(code, name, message);
|
||||
LOGI("UIExtension request UIExtensionAbility destroy, isDestruction_=%{public}u", isDestruction_);
|
||||
if (!isDestruction_) {
|
||||
sptr<Rosen::ExtensionSession> extensionSession(static_cast<Rosen::ExtensionSession*>(session_.GetRefPtr()));
|
||||
auto errcode =
|
||||
Rosen::ExtensionSessionManager::GetInstance().RequestExtensionSessionDestruction(extensionSession);
|
||||
if (errcode != OHOS::Rosen::WSError::WS_OK) {
|
||||
if (onErrorCallback_) {
|
||||
int32_t code = static_cast<int32_t>(errcode);
|
||||
std::string name = "terminate_fail";
|
||||
std::string message = "terminate ui extension ability failed, please check AMS log.";
|
||||
onErrorCallback_(code, name, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -367,8 +398,7 @@ void UIExtensionPattern::HandleTouchEvent(const TouchEventInfo& info)
|
||||
auto touchOffsetToWindow = info.GetTouches().front().GetGlobalLocation();
|
||||
auto touchOffsetToFrameNode = info.GetTouches().front().GetLocalLocation();
|
||||
auto rectToWindow = host->GetTransformRectRelativeToWindow();
|
||||
UpdateTextFieldManager(
|
||||
{ rectToWindow.GetOffset().GetX(), touchOffsetToWindow.GetY() },
|
||||
UpdateTextFieldManager({ rectToWindow.GetOffset().GetX(), touchOffsetToWindow.GetY() },
|
||||
rectToWindow.Height() - touchOffsetToFrameNode.GetY());
|
||||
}
|
||||
|
||||
@ -391,6 +421,12 @@ void UIExtensionPattern::HandleMouseEvent(const MouseInfo& info)
|
||||
auto hub = host->GetFocusHub();
|
||||
CHECK_NULL_VOID(hub);
|
||||
hub->RequestFocusImmediately();
|
||||
|
||||
auto mouseOffsetToWindow = info.GetGlobalLocation();
|
||||
auto mouseOffsetToFrameNode = info.GetLocalLocation();
|
||||
auto rectToWindow = host->GetTransformRectRelativeToWindow();
|
||||
UpdateTextFieldManager({ rectToWindow.GetOffset().GetX(), mouseOffsetToWindow.GetY() },
|
||||
rectToWindow.Height() - mouseOffsetToFrameNode.GetY());
|
||||
}
|
||||
WindowPattern::DispatchPointerEvent(pointerEvent);
|
||||
}
|
||||
@ -418,7 +454,7 @@ void UIExtensionPattern::UnregisterAbilityResultListener()
|
||||
sptr<Rosen::ExtensionSession> extensionSession(static_cast<Rosen::ExtensionSession*>(session_.GetRefPtr()));
|
||||
}
|
||||
|
||||
void UIExtensionPattern::SetOnRemoteReadyCallback(std::function<void(const RefPtr<UIExtensionProxy>&)>&& callback)
|
||||
void UIExtensionPattern::SetOnRemoteReadyCallback(const std::function<void(const RefPtr<UIExtensionProxy>&)>&& callback)
|
||||
{
|
||||
onRemoteReadyCallback_ = std::move(callback);
|
||||
|
||||
@ -432,7 +468,7 @@ void UIExtensionPattern::SetOnRemoteReadyCallback(std::function<void(const RefPt
|
||||
[weak = WeakClaim(this), instanceId = instanceId_, taskExecutor]() {
|
||||
taskExecutor->PostTask([weak, instanceId]() {
|
||||
ContainerScope scope(instanceId);
|
||||
LOGI("UIExtensionPattern OnRemoteReady called");
|
||||
LOGI("UIExtension OnRemoteReady called");
|
||||
auto pattern = weak.Upgrade();
|
||||
if (pattern && pattern->onRemoteReadyCallback_) {
|
||||
pattern->onRemoteReadyCallback_(MakeRefPtr<UIExtensionProxy>(pattern->session_));
|
||||
@ -441,13 +477,13 @@ void UIExtensionPattern::SetOnRemoteReadyCallback(std::function<void(const RefPt
|
||||
};
|
||||
}
|
||||
|
||||
void UIExtensionPattern::SetOnReleaseCallback(std::function<void(int32_t)>&& callback)
|
||||
void UIExtensionPattern::SetOnReleaseCallback(const std::function<void(int32_t)>&& callback)
|
||||
{
|
||||
onReleaseCallback_ = std::move(callback);
|
||||
}
|
||||
|
||||
void UIExtensionPattern::SetOnErrorCallback(
|
||||
std::function<void(int32_t code, const std::string& name, const std::string& message)>&& callback)
|
||||
const std::function<void(int32_t code, const std::string& name, const std::string& message)>&& callback)
|
||||
{
|
||||
onErrorCallback_ = std::move(callback);
|
||||
if (lastError_.code != 0) {
|
||||
@ -457,7 +493,7 @@ void UIExtensionPattern::SetOnErrorCallback(
|
||||
}
|
||||
}
|
||||
|
||||
void UIExtensionPattern::SetOnResultCallback(std::function<void(int32_t, const AAFwk::Want&)>&& callback)
|
||||
void UIExtensionPattern::SetOnResultCallback(const std::function<void(int32_t, const AAFwk::Want&)>&& callback)
|
||||
{
|
||||
onResultCallback_ = std::move(callback);
|
||||
|
||||
@ -471,7 +507,7 @@ void UIExtensionPattern::SetOnResultCallback(std::function<void(int32_t, const A
|
||||
[weak = WeakClaim(this), instanceId = instanceId_, taskExecutor](int32_t code, const AAFwk::Want& want) {
|
||||
taskExecutor->PostTask([weak, instanceId, code, want]() {
|
||||
ContainerScope scope(instanceId);
|
||||
LOGI("UIExtensionPattern OnResult called");
|
||||
LOGI("UIExtension OnResult called");
|
||||
auto pattern = weak.Upgrade();
|
||||
if (pattern && pattern->onResultCallback_) {
|
||||
pattern->onResultCallback_(code, want);
|
||||
@ -480,7 +516,7 @@ void UIExtensionPattern::SetOnResultCallback(std::function<void(int32_t, const A
|
||||
};
|
||||
}
|
||||
|
||||
void UIExtensionPattern::SetOnReceiveCallback(std::function<void(const AAFwk::WantParams&)>&& callback)
|
||||
void UIExtensionPattern::SetOnReceiveCallback(const std::function<void(const AAFwk::WantParams&)>&& callback)
|
||||
{
|
||||
onReceiveCallback_ = std::move(callback);
|
||||
|
||||
@ -494,7 +530,7 @@ void UIExtensionPattern::SetOnReceiveCallback(std::function<void(const AAFwk::Wa
|
||||
[weak = WeakClaim(this), instanceId = instanceId_, taskExecutor](const AAFwk::WantParams& params) {
|
||||
taskExecutor->PostTask([weak, instanceId, params]() {
|
||||
ContainerScope scope(instanceId);
|
||||
LOGI("UIExtensionPattern OnReceive called");
|
||||
LOGI("UIExtension OnReceive called");
|
||||
auto pattern = weak.Upgrade();
|
||||
if (pattern && pattern->onReceiveCallback_) {
|
||||
pattern->onReceiveCallback_(params);
|
||||
@ -548,4 +584,10 @@ bool UIExtensionPattern::IsCurrentFocus() const
|
||||
CHECK_NULL_RETURN_NOLOG(focusHub, false);
|
||||
return focusHub->IsCurrentFocus();
|
||||
}
|
||||
|
||||
int32_t UIExtensionPattern::GetSessionId()
|
||||
{
|
||||
CHECK_NULL_RETURN(session_, 0);
|
||||
return session_->GetPersistentId();
|
||||
}
|
||||
} // namespace OHOS::Ace::NG
|
||||
|
@ -16,6 +16,8 @@
|
||||
#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_UI_EXTENSION_UI_EXTENSION_PATTERN_H
|
||||
#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_UI_EXTENSION_UI_EXTENSION_PATTERN_H
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "base/memory/referenced.h"
|
||||
#include "base/want/want_wrap.h"
|
||||
#include "core/components_ng/event/gesture_event_hub.h"
|
||||
@ -35,6 +37,7 @@ class UIExtensionPattern : public WindowPattern {
|
||||
|
||||
public:
|
||||
explicit UIExtensionPattern(const RefPtr<OHOS::Ace::WantWrap>& wantWrap);
|
||||
explicit UIExtensionPattern(const AAFwk::Want& want);
|
||||
~UIExtensionPattern() override;
|
||||
|
||||
void OnWindowShow() override;
|
||||
@ -49,12 +52,14 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
void SetOnRemoteReadyCallback(std::function<void(const RefPtr<UIExtensionProxy>&)>&& callback);
|
||||
void SetOnReleaseCallback(std::function<void(int32_t)>&& callback);
|
||||
void SetOnResultCallback(std::function<void(int32_t, const AAFwk::Want&)>&& callback);
|
||||
void SetOnReceiveCallback(std::function<void(const AAFwk::WantParams&)>&& callback);
|
||||
int32_t GetSessionId();
|
||||
|
||||
void SetOnRemoteReadyCallback(const std::function<void(const RefPtr<UIExtensionProxy>&)>&& callback);
|
||||
void SetOnReleaseCallback(const std::function<void(int32_t)>&& callback);
|
||||
void SetOnResultCallback(const std::function<void(int32_t, const AAFwk::Want&)>&& callback);
|
||||
void SetOnReceiveCallback(const std::function<void(const AAFwk::WantParams&)>&& callback);
|
||||
void SetOnErrorCallback(
|
||||
std::function<void(int32_t code, const std::string& name, const std::string& message)>&& callback);
|
||||
const std::function<void(int32_t code, const std::string& name, const std::string& message)>&& callback);
|
||||
|
||||
void OnConnect() override;
|
||||
void OnDisconnect() override;
|
||||
@ -104,6 +109,7 @@ private:
|
||||
std::function<void(const AAFwk::WantParams&)> onReceiveCallback_;
|
||||
std::function<void(int32_t code, const std::string& name, const std::string& message)> onErrorCallback_;
|
||||
|
||||
bool isDestruction_ = false;
|
||||
ErrorMsg lastError_;
|
||||
ACE_DISALLOW_COPY_AND_MOVE(UIExtensionPattern);
|
||||
};
|
||||
|
@ -24,16 +24,18 @@
|
||||
|
||||
namespace OHOS::Rosen {
|
||||
class Session;
|
||||
}
|
||||
} // namespace OHOS::Rosen
|
||||
|
||||
namespace OHOS::Ace::NG {
|
||||
class UIExtensionProxy : public AceType {
|
||||
DECLARE_ACE_TYPE(UIExtensionProxy, AceType);
|
||||
|
||||
public:
|
||||
explicit UIExtensionProxy(const sptr<Rosen::Session>& session);
|
||||
void SendData(const RefPtr<WantParamsWrap>& params);
|
||||
|
||||
private:
|
||||
sptr<Rosen::Session> session_;
|
||||
};
|
||||
} // // namespace OHOS::Ace::NG
|
||||
} // namespace OHOS::Ace::NG
|
||||
#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_UI_EXTENSION_UI_EXTENSION_PROXY_H
|
||||
|
37
interfaces/inner_api/ace/modal_ui_extension_callbacks.h
Normal file
37
interfaces/inner_api/ace/modal_ui_extension_callbacks.h
Normal file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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 FOUNDATION_ACE_INTERFACE_INNERKITS_ACE_MODAL_CONFIG_H
|
||||
#define FOUNDATION_ACE_INTERFACE_INNERKITS_ACE_MODAL_CONFIG_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
namespace OHOS::AAFwk {
|
||||
class Want;
|
||||
class WantParams;
|
||||
} // namespace OHOS::AAFwk
|
||||
|
||||
namespace OHOS::Ace {
|
||||
struct ModalUIExtensionCallbacks {
|
||||
std::function<void(int32_t)> onRelease;
|
||||
std::function<void(int32_t, const AAFwk::Want&)> onResult;
|
||||
std::function<void(const AAFwk::WantParams&)> onReceive;
|
||||
std::function<void(int32_t, const std::string&, const std::string&)> onError;
|
||||
};
|
||||
} // namespace OHOS::Ace
|
||||
#endif // FOUNDATION_ACE_INTERFACE_INNERKITS_ACE_MODAL_CONFIG_H
|
@ -24,6 +24,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "macros.h"
|
||||
#include "modal_ui_extension_callbacks.h"
|
||||
#include "serializeable_object.h"
|
||||
#include "viewport_config.h"
|
||||
|
||||
@ -167,7 +168,23 @@ public:
|
||||
virtual NativeValue* GetUIContext()
|
||||
{
|
||||
return nullptr;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Create a full-window modal UIExtensionComponent.
|
||||
* @param want Indicates the want of UIExtensionAbility.
|
||||
* @param callbacks Indicates the UIExtensionComponent callbacks.
|
||||
* @return The return value is the ID of the session held by the UIExtensionComponent
|
||||
* if creation is not successful, it returns 0 by default.
|
||||
*/
|
||||
virtual int32_t CreateModalUIExtension(const AAFwk::Want& want, const ModalUIExtensionCallbacks& callbacks) = 0;
|
||||
|
||||
/**
|
||||
* @description: Close the full-window modal.
|
||||
* @param sessionId Indicates the sessionId of UIExtensionAbility.
|
||||
* If the sessionId is 0, refuse to close
|
||||
*/
|
||||
virtual void CloseModalUIExtension(int32_t sessionId) = 0;
|
||||
};
|
||||
|
||||
} // namespace OHOS::Ace
|
||||
|
@ -73,6 +73,9 @@ public:
|
||||
MOCK_METHOD1(ReloadForm, void(const std::string& url));
|
||||
MOCK_METHOD1(SetIsFocusActive, void(bool isFocusActive));
|
||||
MOCK_METHOD1(SetFocusWindowId, void(uint32_t windowId));
|
||||
|
||||
MOCK_METHOD2(CreateModalUIExtension, int32_t(const AAFwk::Want& want, const ModalUIExtensionCallbacks& callbacks));
|
||||
MOCK_METHOD1(CloseModalUIExtension, void(int32_t sessionId));
|
||||
};
|
||||
} // namespace Ace
|
||||
} // namespace OHOS
|
||||
|
Loading…
Reference in New Issue
Block a user