From 92f50affc4f9c7a0a160c0c1331b34d7f47fb979 Mon Sep 17 00:00:00 2001 From: jiangdayuan Date: Wed, 16 Feb 2022 17:19:03 +0800 Subject: [PATCH] add mouse hide window title Signed-off-by: jiangdayuan Change-Id: I7c261c647343effcc1baeb3bf1dc8cd197d2b7ba --- .../container_modal_element.cpp | 43 ++++++++++++++----- .../container_modal/container_modal_element.h | 1 + 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/frameworks/core/components/container_modal/container_modal_element.cpp b/frameworks/core/components/container_modal/container_modal_element.cpp index f5cf6d99c0a..80f5a0f488e 100644 --- a/frameworks/core/components/container_modal/container_modal_element.cpp +++ b/frameworks/core/components/container_modal/container_modal_element.cpp @@ -194,27 +194,48 @@ void ContainerModalElement::Update() LOGE("ContainerModalElement update failed, container box component is null."); return; } - containerBox->SetOnTouchMoveId([week = WeakClaim(this), weakContext = context_](const TouchEventInfo& info) { + + // touch top to pop-up title bar. + containerBox->SetOnTouchMoveId([week = WeakClaim(this)](const TouchEventInfo& info) { auto containerElement = week.Upgrade(); - auto context = weakContext.Upgrade(); - if (!containerElement || !context) { + if (!containerElement || !containerElement->CanShowFloatingTitle()) { return; } - if (context->FireWindowGetModeCallBack() != WindowMode::WINDOW_MODE_FULLSCREEN) { - LOGI("Window is not full screen, can not show floating title."); - return; + if (info.GetChangedTouches().begin()->GetGlobalLocation().GetY() <= TITLE_POPUP_DISTANCE) { + containerElement->renderDisplay_->UpdateVisibleType(VisibleType::VISIBLE); + containerElement->controller_->Forward(); } - if (containerElement->renderDisplay_ && - containerElement->renderDisplay_->GetVisibleType() == VisibleType::VISIBLE) { - LOGI("Floating tittle is visible now, no need to show again."); + }); + + // mouse move top to pop-up title bar. + containerBox->SetOnMouseId([week = WeakClaim(this)](MouseInfo& info) { + auto containerElement = week.Upgrade(); + if (!containerElement || !containerElement->CanShowFloatingTitle()) { return; } - // touch top to pop-up title bar. - if (info.GetChangedTouches().begin()->GetGlobalLocation().GetY() <= TITLE_POPUP_DISTANCE) { + if (info.GetAction() == MouseAction::MOVE && info.GetLocalLocation().GetY() <= TITLE_POPUP_DISTANCE) { containerElement->renderDisplay_->UpdateVisibleType(VisibleType::VISIBLE); containerElement->controller_->Forward(); } }); } +bool ContainerModalElement::CanShowFloatingTitle() +{ + auto context = context_.Upgrade(); + if (!context || !renderDisplay_ || !controller_) { + LOGI("Show floating title failed, context, renderDisplay_ or controller is null."); + return false; + } + if (context->FireWindowGetModeCallBack() != WindowMode::WINDOW_MODE_FULLSCREEN) { + LOGI("Window is not full screen, can not show floating title."); + return false; + } + if (renderDisplay_->GetVisibleType() == VisibleType::VISIBLE) { + LOGI("Floating tittle is visible now, no need to show again."); + return false; + } + return true; +} + } // namespace OHOS::Ace \ No newline at end of file diff --git a/frameworks/core/components/container_modal/container_modal_element.h b/frameworks/core/components/container_modal/container_modal_element.h index dbbaaedb634..c2f20590be2 100644 --- a/frameworks/core/components/container_modal/container_modal_element.h +++ b/frameworks/core/components/container_modal/container_modal_element.h @@ -36,6 +36,7 @@ private: RefPtr GetStackElement() const; RefPtr controller_; RefPtr renderDisplay_; + bool CanShowFloatingTitle(); }; } // namespace OHOS::Ace -- Gitee