Commit 62591398 authored by Andre Le's avatar Andre Le Committed by Chromium LUCI CQ

Notification: Only start hot mode when needed.

In Nearby Share, we encounter a problem of an image notification not
showing entirely. This happens because of this use case:
- The popup notification A is showing and we hover over that
notification.
- Notification A is then removed automatically to show notification B
with image.
- Notification B with image is cut off because we accidentally enter hot
mode.

This CL added a check so that we only start hot mode when necessary
(when a notification is closed by an actual user).

Fixed: 1154741
Change-Id: I306e66e92d2e28ba11cb1526089789ad1eb9331b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2591267
Commit-Queue: Andre Le <leandre@chromium.org>
Reviewed-by: default avatarPeter Beverloo <peter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#843219}
parent 2a33506c
......@@ -7,6 +7,7 @@
#include "base/bind.h"
#include "base/stl_util.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/timer/timer.h"
#include "ui/gfx/animation/linear_animation.h"
#include "ui/gfx/animation/tween.h"
#include "ui/message_center/message_center.h"
......@@ -25,6 +26,9 @@ constexpr base::TimeDelta kFadeInFadeOutDuration =
constexpr base::TimeDelta kMoveDownDuration =
base::TimeDelta::FromMilliseconds(120);
// Time to wait until we reset |recently_closed_by_user_|.
constexpr base::TimeDelta kWaitForReset = base::TimeDelta::FromSeconds(10);
} // namespace
MessagePopupCollection::MessagePopupCollection()
......@@ -132,9 +136,22 @@ void MessagePopupCollection::OnNotificationAdded(
void MessagePopupCollection::OnNotificationRemoved(
const std::string& notification_id,
bool by_user) {
if (by_user) {
recently_closed_by_user_ = true;
recently_closed_by_user_timer_ = std::make_unique<base::OneShotTimer>();
recently_closed_by_user_timer_->Start(
FROM_HERE, kWaitForReset,
base::BindOnce(&MessagePopupCollection::ResetRecentlyClosedByUser,
base::Unretained(this)));
}
Update();
}
void MessagePopupCollection::ResetRecentlyClosedByUser() {
recently_closed_by_user_ = false;
recently_closed_by_user_timer_.reset();
}
void MessagePopupCollection::OnNotificationUpdated(
const std::string& notification_id) {
if (is_updating_)
......@@ -272,7 +289,9 @@ void MessagePopupCollection::TransitionToAnimation() {
MarkRemovedPopup();
// Start hot mode to allow a user to continually close many notifications.
StartHotMode();
// Only start hot mode if there's a notification recently closed by user.
if (recently_closed_by_user_)
StartHotMode();
if (CloseTransparentPopups()) {
// If the popup is already transparent, skip FADE_OUT.
......
......@@ -15,6 +15,10 @@
#include "ui/message_center/message_center_observer.h"
#include "ui/views/widget/widget.h"
namespace base {
class OneShotTimer;
} // namespace base
namespace gfx {
class LinearAnimation;
} // namespace gfx
......@@ -255,6 +259,10 @@ class MESSAGE_CENTER_EXPORT MessagePopupCollection
// When |inverse_| is false, it's same as popup_items_[i].
PopupItem* GetPopupItem(size_t index_from_top);
// Reset |recently_closed_by_user_| to false. Used by
// |recently_closed_by_user_timer_|
void ResetRecentlyClosedByUser();
// Animation state. See the comment of State.
State state_ = State::IDLE;
......@@ -279,6 +287,14 @@ class MESSAGE_CENTER_EXPORT MessagePopupCollection
// Hot mode related variables. See StartHotMode() and ResetHotMode().
// True if a notification is just closed by an user and hot mode should start.
// After a brief moment, this boolean will be set to false by the timer.
bool recently_closed_by_user_ = false;
// Timer that fires to reset |recently_closed_by_user_| to false, indicating
// that we should not start hot mode.
std::unique_ptr<base::OneShotTimer> recently_closed_by_user_timer_;
// True if the close button of the popup at |hot_index_| is hot.
bool is_hot_ = false;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment