From f011fbbc81ce4a27367e04bb313b5c50253f0053 Mon Sep 17 00:00:00 2001 From: jiangdayuan Date: Tue, 1 Mar 2022 17:37:17 +0800 Subject: [PATCH 1/3] add window title auto hide Signed-off-by: jiangdayuan Change-Id: I9de0ad2f9ae37257aa822ff3d212a2eb492054ab --- frameworks/core/common/watch_dog.cpp | 3 -- .../container_modal_element.cpp | 52 ++++++++++++++++--- .../container_modal/container_modal_element.h | 1 + .../side_bar/side_bar_container_component.cpp | 2 - 4 files changed, 46 insertions(+), 12 deletions(-) diff --git a/frameworks/core/common/watch_dog.cpp b/frameworks/core/common/watch_dog.cpp index 2bc4e472b08..6d929d3d9e1 100644 --- a/frameworks/core/common/watch_dog.cpp +++ b/frameworks/core/common/watch_dog.cpp @@ -381,9 +381,6 @@ void ThreadWatcher::PostCheckTask() type_); std::unique_lock lock(mutex_); ++loopTime_; - } else { - LOGW("task executor with instanceId %{public}d invalid when check %{public}s thread whether stuck or not", - instanceId_, threadName_.c_str()); } } diff --git a/frameworks/core/components/container_modal/container_modal_element.cpp b/frameworks/core/components/container_modal/container_modal_element.cpp index 04276331ae4..329b3abe37a 100644 --- a/frameworks/core/components/container_modal/container_modal_element.cpp +++ b/frameworks/core/components/container_modal/container_modal_element.cpp @@ -20,6 +20,7 @@ #include "core/components/container_modal/render_container_modal.h" #include "core/components/flex/flex_element.h" #include "core/components/flex/flex_item_element.h" +#include "core/gestures/tap_gesture.h" namespace OHOS::Ace { namespace { @@ -246,28 +247,52 @@ void ContainerModalElement::Update() } if (info.GetChangedTouches().begin()->GetGlobalLocation().GetY() <= TITLE_POPUP_DISTANCE) { containerElement->floatingTitleDisplay_->UpdateVisibleType(VisibleType::VISIBLE); + containerElement->controller_->ClearStopListeners(); containerElement->controller_->Forward(); } }); - // mouse move top to pop-up title bar. - containerBox->SetOnMouseId([week = WeakClaim(this)](MouseInfo& info) { - auto containerElement = week.Upgrade(); - if (!containerElement || !containerElement->CanShowFloatingTitle()) { + // mouse move top to pop up title bar and move other area to hide title bar. + containerBox->SetOnMouseId([weak = WeakClaim(this)](MouseInfo& info) { + auto containerElement = weak.Upgrade(); + if (!containerElement || info.GetAction() != MouseAction::MOVE) { return; } - if (info.GetAction() == MouseAction::MOVE && info.GetLocalLocation().GetY() <= TITLE_POPUP_DISTANCE) { + if (info.GetLocalLocation().GetY() <= TITLE_POPUP_DISTANCE && containerElement->CanShowFloatingTitle()) { containerElement->floatingTitleDisplay_->UpdateVisibleType(VisibleType::VISIBLE); + containerElement->controller_->ClearStopListeners(); containerElement->controller_->Forward(); } + if (info.GetLocalLocation().GetY() > TITLE_POPUP_DISTANCE && containerElement->CanHideFloatingTitle()) { + containerElement->controller_->AddStopListener([weak] { + auto container = weak.Upgrade(); + container->floatingTitleDisplay_->UpdateVisibleType(VisibleType::GONE); + }); + containerElement->controller_->Backward(); + } + }); + + // touch other area of screen to hide title bar. + auto tapGesture = AceType::MakeRefPtr(); + tapGesture->SetOnActionId([weak = WeakClaim(this)](GestureEvent& info) { + auto containerElement = weak.Upgrade(); + if (!containerElement || !containerElement->CanHideFloatingTitle()) { + return; + } + containerElement->controller_->AddStopListener([weak] { + auto container = weak.Upgrade(); + container->floatingTitleDisplay_->UpdateVisibleType(VisibleType::GONE); + }); + containerElement->controller_->Backward(); }); + containerBox->SetOnClick(tapGesture); } bool ContainerModalElement::CanShowFloatingTitle() { auto context = context_.Upgrade(); if (!context || !floatingTitleDisplay_ || !controller_) { - LOGI("Show floating title failed, context, floatingTitleDisplay_ or controller is null."); + LOGI("Show floating title failed, context, floatingTitleDisplay or controller is null."); return false; } auto mode = context->FireWindowGetModeCallBack(); @@ -276,13 +301,26 @@ bool ContainerModalElement::CanShowFloatingTitle() LOGI("Window is not full screen or split screen, can not show floating title."); return false; } - if (floatingTitleDisplay_->GetVisibleType() == VisibleType::VISIBLE) { + if (floatingTitleDisplay_->GetVisible()) { LOGI("Floating tittle is visible now, no need to show again."); return false; } return true; } +bool ContainerModalElement::CanHideFloatingTitle() +{ + if (!floatingTitleDisplay_ || !controller_) { + LOGI("Hide floating title failed, floatingTitleDisplay or controller is null."); + return false; + } + if (!floatingTitleDisplay_->GetVisible()) { + LOGI("Hide floating title failed, title is not visible."); + return false; + } + return true; +} + void ContainerModalElement::ChangeFloatingTitleIcon() { if (!floatingTitleBox_ || !titleChildrenRow_ || !floatingTitleChildrenRow_) { diff --git a/frameworks/core/components/container_modal/container_modal_element.h b/frameworks/core/components/container_modal/container_modal_element.h index 3431ff327ce..7e2703688ca 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 @@ public: private: RefPtr GetStackElement() const; bool CanShowFloatingTitle(); + bool CanHideFloatingTitle(); void ChangeFloatingTitleIcon(); RefPtr controller_; RefPtr floatingTitleDisplay_; diff --git a/frameworks/core/components/side_bar/side_bar_container_component.cpp b/frameworks/core/components/side_bar/side_bar_container_component.cpp index e6e99b62505..07b72a95638 100644 --- a/frameworks/core/components/side_bar/side_bar_container_component.cpp +++ b/frameworks/core/components/side_bar/side_bar_container_component.cpp @@ -18,11 +18,9 @@ #include "base/geometry/dimension.h" #include "core/components/box/box_component.h" #include "core/components/display/display_component.h" -#include "core/components/gesture_listener/gesture_listener_component.h" #include "core/components/image/image_component.h" #include "core/components/side_bar/render_side_bar_container.h" #include "core/components/side_bar/side_bar_container_element.h" -#include "core/components/split_container/row_split_component.h" #include "core/gestures/tap_gesture.h" #include "core/pipeline/base/component.h" #include "frameworks/bridge/declarative_frontend/view_stack_processor.h" -- Gitee From bdcbb16d0ea86f5bbc436ff983d27c085ce0066a Mon Sep 17 00:00:00 2001 From: jiangdayuan Date: Tue, 1 Mar 2022 13:16:26 +0000 Subject: [PATCH 2/3] update frameworks/core/common/watch_dog.cpp. Signed-off-by: jiangdayuan --- frameworks/core/common/watch_dog.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/frameworks/core/common/watch_dog.cpp b/frameworks/core/common/watch_dog.cpp index 6d929d3d9e1..611982959bc 100644 --- a/frameworks/core/common/watch_dog.cpp +++ b/frameworks/core/common/watch_dog.cpp @@ -381,7 +381,10 @@ void ThreadWatcher::PostCheckTask() type_); std::unique_lock lock(mutex_); ++loopTime_; - } + } else { + LOGW("task executor with instanceId %{public}d invalid when check %{public}s thread whether stuck or not", + instanceId_, threadName_.c_str()); + } } void ThreadWatcher::TagIncrease() @@ -414,6 +417,8 @@ void WatchDog::Register(int32_t instanceId, const RefPtr& taskExec watchers.uiWatcher->SetTaskExecutor(taskExecutor); if (!useUIAsJSThread) { watchers.jsWatcher->SetTaskExecutor(taskExecutor); + } else { + watchers.jsWatcher = nullptr; } const auto resExecutor = watchMap_.try_emplace(instanceId, watchers); if (!resExecutor.second) { -- Gitee From 34e3a587dc3683a654bdc1f6700a73765aca900e Mon Sep 17 00:00:00 2001 From: jiangdayuan Date: Tue, 1 Mar 2022 13:17:38 +0000 Subject: [PATCH 3/3] update frameworks/core/common/watch_dog.cpp. Signed-off-by: jiangdayuan --- frameworks/core/common/watch_dog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/core/common/watch_dog.cpp b/frameworks/core/common/watch_dog.cpp index 611982959bc..756860c6fef 100644 --- a/frameworks/core/common/watch_dog.cpp +++ b/frameworks/core/common/watch_dog.cpp @@ -384,7 +384,7 @@ void ThreadWatcher::PostCheckTask() } else { LOGW("task executor with instanceId %{public}d invalid when check %{public}s thread whether stuck or not", instanceId_, threadName_.c_str()); - } + } } void ThreadWatcher::TagIncrease() -- Gitee