!41698 同层渲染区域支持可见性上报

Merge pull request !41698 from 丁鑫/master
This commit is contained in:
openharmony_ci 2024-08-31 01:59:56 +00:00 committed by Gitee
commit e5df02defd
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
15 changed files with 141 additions and 4 deletions

View File

@ -1922,6 +1922,7 @@ void JSWeb::JSBind(BindingTarget globalObj)
JSClass<JSWeb>::StaticMethod("onControllerAttached", &JSWeb::OnControllerAttached);
JSClass<JSWeb>::StaticMethod("onOverScroll", &JSWeb::OnOverScroll);
JSClass<JSWeb>::StaticMethod("onNativeEmbedLifecycleChange", &JSWeb::OnNativeEmbedLifecycleChange);
JSClass<JSWeb>::StaticMethod("onNativeEmbedVisibilityChange", &JSWeb::OnNativeEmbedVisibilityChange);
JSClass<JSWeb>::StaticMethod("onNativeEmbedGestureEvent", &JSWeb::OnNativeEmbedGestureEvent);
JSClass<JSWeb>::StaticMethod("copyOptions", &JSWeb::CopyOption);
JSClass<JSWeb>::StaticMethod("onScreenCaptureRequest", &JSWeb::OnScreenCaptureRequest);
@ -4465,6 +4466,15 @@ JSRef<JSVal> EmbedLifecycleChangeToJSValue(const NativeEmbedDataInfo& eventInfo)
return JSRef<JSVal>::Cast(obj);
}
JSRef<JSVal> EmbedVisibilityChangeToJSValue(const NativeEmbedVisibilityInfo& visibilityInfo)
{
JSRef<JSObject> obj = JSRef<JSObject>::New();
obj->SetProperty("visibility", visibilityInfo.GetVisibility());
obj->SetProperty("embedId", visibilityInfo.GetEmbedId());
return JSRef<JSVal>::Cast(obj);
}
void JSWeb::OnNativeEmbedLifecycleChange(const JSCallbackInfo& args)
{
if (args.Length() < 1 || !args[0]->IsFunction()) {
@ -4483,6 +4493,25 @@ void JSWeb::OnNativeEmbedLifecycleChange(const JSCallbackInfo& args)
WebModel::GetInstance()->SetNativeEmbedLifecycleChangeId(jsCallback);
}
void JSWeb::OnNativeEmbedVisibilityChange(const JSCallbackInfo& args)
{
if (args.Length() < 1 || !args[0]->IsFunction()) {
return;
}
auto jsFunc = AceType::MakeRefPtr<JsEventFunction<NativeEmbedVisibilityInfo, 1>>(
JSRef<JSFunc>::Cast(args[0]), EmbedVisibilityChangeToJSValue);
auto instanceId = Container::CurrentId();
auto jsCallback = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), instanceId](
const BaseEventInfo* info) {
ContainerScope scope(instanceId);
JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
auto* eventInfo = TypeInfoHelper::DynamicCast<NativeEmbedVisibilityInfo>(info);
func->Execute(*eventInfo);
};
WebModel::GetInstance()->SetNativeEmbedVisibilityChangeId(jsCallback);
}
JSRef<JSObject> CreateTouchInfo(const TouchLocationInfo& touchInfo, TouchEventInfo& info)
{
JSRef<JSObjTemplate> objectTemplate = JSRef<JSObjTemplate>::New();

View File

@ -143,6 +143,7 @@ public:
static void EnableNativeEmbedMode(bool isEmbedModeEnabled);
static void RegisterNativeEmbedRule(const std::string& tag, const std::string& type);
static void OnNativeEmbedLifecycleChange(const JSCallbackInfo& args);
static void OnNativeEmbedVisibilityChange(const JSCallbackInfo& args);
static void OnNativeEmbedGestureEvent(const JSCallbackInfo& args);
static void JavaScriptOnDocumentStart(const JSCallbackInfo& args);
static void JavaScriptOnDocumentEnd(const JSCallbackInfo& args);

View File

@ -606,6 +606,15 @@ void WebModelImpl::SetNativeEmbedLifecycleChangeId(std::function<void(const Base
webComponent->SetNativeEmbedLifecycleChangeId(eventMarker);
}
void WebModelImpl::SetNativeEmbedVisibilityChangeId(std::function<void(const BaseEventInfo* info)>&& jsCallback)
{
auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
CHECK_NULL_VOID(webComponent);
auto eventMarker = EventMarker(std::move(jsCallback));
webComponent->SetNativeEmbedVisibilityChangeId(eventMarker);
}
void WebModelImpl::SetNativeEmbedGestureEventId(std::function<void(const BaseEventInfo* info)>&& jsCallback)
{
auto webComponent = AceType::DynamicCast<WebComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());

View File

@ -109,6 +109,7 @@ public:
void SetNativeEmbedModeEnabled(bool isEmbedModeEnabled) override;
void RegisterNativeEmbedRule(const std::string& tag, const std::string& type) override;
void SetNativeEmbedLifecycleChangeId(std::function<void(const BaseEventInfo* info)>&& jsCallback) override;
void SetNativeEmbedVisibilityChangeId(std::function<void(const BaseEventInfo* info)>&& jsCallback) override;
void SetNativeEmbedGestureEventId(std::function<void(const BaseEventInfo* info)>&& jsCallback) override;
void SetOnOverrideUrlLoading(std::function<bool(const BaseEventInfo* info)>&& jsCallback) override;
void SetNativeVideoPlayerConfig(bool enable, bool shouldOverlay) override;

View File

@ -49,6 +49,7 @@ struct WebEvent : Event {
EventMarker windowExitId;
EventMarker overScrollId;
EventMarker nativeEmbedLifecycleChangeId;
EventMarker nativeEmbedVisibilityChangeId;
EventMarker nativeEmbedGestureEventId;
EventMarker renderProcessNotRespondingId;
EventMarker renderProcessRespondingId;
@ -346,6 +347,19 @@ public:
auto& event = static_cast<WebEvent&>(GetEvent(EventTag::SPECIALIZED_EVENT));
return event.nativeEmbedLifecycleChangeId;
}
void SetNativeEmbedVisibilityChangeId(const EventMarker& embedVisibilityChangeId)
{
auto& event = MaybeResetEvent<WebEvent>(EventTag::SPECIALIZED_EVENT);
event.nativeEmbedVisibilityChangeId = embedVisibilityChangeId;
}
const EventMarker& GetNativeEmbedVisibilityChangeId() const
{
auto& event = static_cast<WebEvent&>(GetEvent(EventTag::SPECIALIZED_EVENT));
return event.nativeEmbedVisibilityChangeId;
}
void SetNativeEmbedGestureEventId(const EventMarker& embedGestureEventId)
{
auto& event = MaybeResetEvent<WebEvent>(EventTag::SPECIALIZED_EVENT);

View File

@ -1261,4 +1261,13 @@ void WebClientImpl::StartVibraFeedback(const std::string& vibratorType)
ContainerScope scope(delegate->GetInstanceId());
delegate->StartVibraFeedback(vibratorType);
}
void WebClientImpl::OnNativeEmbedVisibilityChange(const std::string& embedId, bool visibility)
{
auto delegate = webDelegate_.Upgrade();
CHECK_NULL_VOID(delegate);
ContainerScope scope(delegate->GetInstanceId());
delegate->OnNativeEmbedVisibilityChange(embedId, visibility);
}
} // namespace OHOS::Ace

View File

@ -298,6 +298,8 @@ public:
void StartVibraFeedback(const std::string& vibratorType) override;
void OnNativeEmbedVisibilityChange(const std::string& embedId, bool visibility) override;
private:
std::weak_ptr<OHOS::NWeb::NWeb> webviewWeak_;
WeakPtr<WebDelegate> webDelegate_;

View File

@ -1836,6 +1836,9 @@ bool WebDelegate::PrepareInitOHOSWeb(const WeakPtr<PipelineBase>& context)
OnNativeEmbedLifecycleChangeV2_ = useNewPipe ? eventHub->GetOnNativeEmbedLifecycleChangeEvent()
: AceAsyncEvent<void(const std::shared_ptr<BaseEventInfo>&)>::Create(
webCom->GetNativeEmbedLifecycleChangeId(), oldContext);
OnNativeEmbedVisibilityChangeV2_ = useNewPipe ? eventHub->GetOnNativeEmbedVisibilityChangeEvent()
: AceAsyncEvent<void(const std::shared_ptr<BaseEventInfo>&)>::Create(
webCom->GetNativeEmbedVisibilityChangeId(), oldContext);
OnNativeEmbedGestureEventV2_ = useNewPipe ? eventHub->GetOnNativeEmbedGestureEvent()
: AceAsyncEvent<void(const std::shared_ptr<BaseEventInfo>&)>::Create(
webCom->GetNativeEmbedGestureEventId(), oldContext);
@ -6477,6 +6480,29 @@ void WebDelegate::OnNativeEmbedLifecycleChange(std::shared_ptr<OHOS::NWeb::NWebN
},
TaskExecutor::TaskType::JS, "ArkUIWebNativeEmbedLifecycleChange");
}
void WebDelegate::OnNativeEmbedVisibilityChange(const std::string& embedId, bool visibility)
{
if (!isEmbedModeEnabled_) {
return;
}
auto context = context_.Upgrade();
CHECK_NULL_VOID(context);
context->GetTaskExecutor()->PostTask(
[weak = WeakClaim(this), embedId, visibility]() {
auto delegate = weak.Upgrade();
CHECK_NULL_VOID(delegate);
auto OnNativeEmbedVisibilityChangeV2_ = delegate->OnNativeEmbedVisibilityChangeV2_;
if (OnNativeEmbedVisibilityChangeV2_) {
OnNativeEmbedVisibilityChangeV2_(
std::make_shared<NativeEmbedVisibilityInfo>(visibility, embedId));
}
},
TaskExecutor::TaskType::JS, "ArkUIWebNativeEmbedVisibilityChange");
}
void WebDelegate::OnNativeEmbedGestureEvent(std::shared_ptr<OHOS::NWeb::NWebNativeEmbedTouchEvent> event)
{
if (event->GetId() == NO_NATIVE_FINGER_TYPE) {

View File

@ -894,6 +894,7 @@ public:
bool FilterScrollEvent(const float x, const float y, const float xVelocity, const float yVelocity);
void OnNativeEmbedAllDestory();
void OnNativeEmbedLifecycleChange(std::shared_ptr<NWeb::NWebNativeEmbedDataInfo> dataInfo);
void OnNativeEmbedVisibilityChange(const std::string& embedId, bool visibility);
void OnNativeEmbedGestureEvent(std::shared_ptr<NWeb::NWebNativeEmbedTouchEvent> event);
void SetNGWebPattern(const RefPtr<NG::WebPattern>& webPattern);
bool RequestFocus(OHOS::NWeb::NWebFocusSource source = OHOS::NWeb::NWebFocusSource::FOCUS_SOURCE_DEFAULT);
@ -1163,6 +1164,7 @@ private:
EventCallbackV2 onSafeBrowsingCheckResultV2_;
EventCallbackV2 OnNativeEmbedAllDestoryV2_;
EventCallbackV2 OnNativeEmbedLifecycleChangeV2_;
EventCallbackV2 OnNativeEmbedVisibilityChangeV2_;
EventCallbackV2 OnNativeEmbedGestureEventV2_;
EventCallbackV2 onIntelligentTrackingPreventionResultV2_;
EventCallbackV2 onRenderProcessNotRespondingV2_;

View File

@ -1059,6 +1059,17 @@ public:
return declaration_->GetNativeEmbedLifecycleChangeId();
}
void SetNativeEmbedVisibilityChangeId(const EventMarker& embedVisibilityChangeId)
{
CHECK_NULL_VOID(declaration_);
declaration_->SetNativeEmbedVisibilityChangeId(embedVisibilityChangeId);
}
const EventMarker& GetNativeEmbedVisibilityChangeId() const
{
return declaration_->GetNativeEmbedVisibilityChangeId();
}
void SetNativeEmbedGestureEventId(const EventMarker& embedGestureEventId)
{
CHECK_NULL_VOID(declaration_);

View File

@ -35,9 +35,7 @@ enum class NativeEmbedStatus {
UPDATE = 1,
DESTROY = 2,
ENTER_BFCACHE = 3,
LEAVE_BFCACHE = 4,
VISIBLE = 5,
HIDDEN = 6
LEAVE_BFCACHE = 4
};
enum class NavigationType {
@ -1878,6 +1876,30 @@ private:
EmbedInfo embedInfo_;
};
class ACE_EXPORT NativeEmbedVisibilityInfo : public BaseEventInfo {
DECLARE_RELATIONSHIP_OF_CLASSES(NativeEmbedVisibilityInfo, BaseEventInfo)
public:
NativeEmbedVisibilityInfo(bool visibility, const std::string& embed_id)
: BaseEventInfo("NativeEmbedVisibilityInfo"), visibility_(visibility),
embed_id_(embed_id) {}
~NativeEmbedVisibilityInfo() = default;
bool GetVisibility() const
{
return visibility_;
}
const std::string& GetEmbedId() const
{
return embed_id_;
}
private:
bool visibility_;
std::string embed_id_ = "";
};
class ACE_EXPORT RenderProcessNotRespondingEvent : public BaseEventInfo {
DECLARE_RELATIONSHIP_OF_CLASSES(RenderProcessNotRespondingEvent, BaseEventInfo);

View File

@ -164,6 +164,7 @@ public:
ACE_WEB_EVENT_PROPERTY(OnNavigationEntryCommitted, void);
ACE_WEB_EVENT_PROPERTY(OnSafeBrowsingCheckResult, void);
ACE_WEB_EVENT_PROPERTY(OnNativeEmbedLifecycleChange, void);
ACE_WEB_EVENT_PROPERTY(OnNativeEmbedVisibilityChange, void);
ACE_WEB_EVENT_PROPERTY(OnNativeEmbedGesture, void);
ACE_WEB_EVENT_PROPERTY(OnIntelligentTrackingPreventionResult, void);
ACE_WEB_EVENT_PROPERTY(OnRenderProcessNotResponding, void);

View File

@ -157,7 +157,7 @@ public:
virtual void RegisterNativeEmbedRule(const std::string&, const std::string&) = 0;
virtual void SetNativeEmbedLifecycleChangeId(std::function<void(const BaseEventInfo* info)>&& jsCallback) = 0;
virtual void SetNativeEmbedGestureEventId(std::function<void(const BaseEventInfo* info)>&& jsCallback) = 0;
virtual void SetNativeEmbedVisibilityChangeId(std::function<void(const BaseEventInfo* info)>&& jsCallback) = 0;
virtual void SetScreenCaptureRequestEventId(std::function<void(const BaseEventInfo* info)>&& jsCallback) {};
virtual void SetNestedScroll(const NestedScrollOptions& nestedOpt) {}
virtual void SetNestedScrollExt(const NestedScrollOptionsExt& nestedOpt) {}

View File

@ -995,6 +995,15 @@ void WebModelNG::SetNativeEmbedLifecycleChangeId(std::function<void(const BaseEv
webEventHub->SetOnNativeEmbedLifecycleChangeEvent(std::move(uiCallback));
}
void WebModelNG::SetNativeEmbedVisibilityChangeId(std::function<void(const BaseEventInfo* info)>&& jsCallback)
{
auto func = jsCallback;
auto uiCallback = [func](const std::shared_ptr<BaseEventInfo>& info) { func(info.get()); };
auto webEventHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub<WebEventHub>();
CHECK_NULL_VOID(webEventHub);
webEventHub->SetOnNativeEmbedVisibilityChangeEvent(std::move(uiCallback));
}
void WebModelNG::SetNativeEmbedGestureEventId(std::function<void(const BaseEventInfo* info)>&& jsCallback)
{
auto func = jsCallback;

View File

@ -163,6 +163,7 @@ public:
void SetNativeEmbedModeEnabled(bool isEmbedModeEnabled) override;
void RegisterNativeEmbedRule(const std::string& tag, const std::string& type) override;
void SetNativeEmbedLifecycleChangeId(std::function<void(const BaseEventInfo* info)>&& jsCallback) override;
void SetNativeEmbedVisibilityChangeId(std::function<void(const BaseEventInfo* info)>&& jsCallback) override;
void SetNativeEmbedGestureEventId(std::function<void(const BaseEventInfo* info)>&& jsCallback) override;
void SetLayoutMode(WebLayoutMode mode) override;
void SetNestedScroll(const NestedScrollOptions& nestedOpt) override;