1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78
   79
   80
   81
   82
   83
   84
   85
   86
   87
   88
   89
   90
   91
   92
   93
   94
   95
   96
   97
   98
   99
  100
  101
  102
  103
  104
  105
  106
  107
  108
  109
  110
  111
  112
  113
  114
  115
  116
  117
  118
  119
  120
  121
  122
  123
  124
  125
  126

ash / system / notification_center / message_center_utils.h [blame]

// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef ASH_SYSTEM_NOTIFICATION_CENTER_MESSAGE_CENTER_UTILS_H_
#define ASH_SYSTEM_NOTIFICATION_CENTER_MESSAGE_CENTER_UTILS_H_

#include <string>

#include "ash/ash_export.h"
#include "base/functional/callback_forward.h"
#include "ui/gfx/animation/tween.h"
#include "ui/message_center/public/cpp/notification.h"
#include "ui/message_center/public/cpp/notifier_id.h"

namespace message_center {
class NotificationViewController;
}

namespace views {
class View;
}

namespace ash {

class NotificationGroupingController;

namespace message_center_utils {

// Return a hash string derived from `notifier_id` data. This is appended to a
// notification's `id` to create a unique identifier for a grouped notification.
std::string ASH_EXPORT
GenerateGroupParentNotificationIdSuffix(message_center::NotifierId notifier_id);

// Comparator function for sorting the notifications in the order that they
// should be displayed. Currently the ordering rule is very simple (subject to
// change):
//     1. All pinned notifications are displayed first.
//     2. Otherwise, display in order of most recent timestamp.
bool CompareNotifications(message_center::Notification* n1,
                          message_center::Notification* n2);

// Returns a vector of notifications that should have their own message
// view sorted for display, using CompareNotifications() above for the sorting
// order.
std::vector<message_center::Notification*> ASH_EXPORT
GetSortedNotificationsWithOwnView();

// Returns total notifications count, with a filter to not count some of them
// These notifications such as camera, media controls, etc. don't need an
// indicator in status area since they already have a dedicated tray item, and
// grouped notifications only need to be counted as one.
size_t ASH_EXPORT GetNotificationCount();

// Returns true if there are any notifications hidden because we're on the
// lockscreen. Should be only called if the screen is locked.
bool AreNotificationsHiddenOnLockscreen();

// Get the notification view controller associated to a certain display.
message_center::NotificationViewController*
GetActiveNotificationViewControllerForDisplay(int64_t display_id);

// Get the currently active notification view controller for the provided
// `notification_view`. Each screen has it's own `MessagePopupCollection` and
// `UnifiedMessageListView`.
message_center::NotificationViewController*
GetActiveNotificationViewControllerForNotificationView(
    views::View* notification_view);

// Gets the grouping controller for the provided notification view. Each display
// has it's own `NotificationGroupingController` so we need to look up the
// display for the provide view first.
NotificationGroupingController* ASH_EXPORT
GetGroupingControllerForNotificationView(views::View* notification_view);

// Utils for animation within a notification view.

// Initializes the layer for the specified `view` for animations.
void ASH_EXPORT InitLayerForAnimations(views::View* view);

// Fade in animation using AnimationBuilder.
void ASH_EXPORT
FadeInView(views::View* view,
           int delay_in_ms,
           int duration_in_ms,
           gfx::Tween::Type tween_type = gfx::Tween::LINEAR,
           const std::string& animation_histogram_name = std::string());

// Fade out animation using AnimationBuilder.
void ASH_EXPORT
FadeOutView(views::View* view,
            base::OnceClosure on_animation_ended,
            int delay_in_ms,
            int duration_in_ms,
            gfx::Tween::Type tween_type = gfx::Tween::LINEAR,
            const std::string& animation_histogram_name = std::string());

// Slide out animation using AnimationBuilder.
void SlideOutView(views::View* view,
                  base::OnceClosure on_animation_ended,
                  base::OnceClosure on_animation_aborted,
                  int delay_in_ms,
                  int duration_in_ms,
                  gfx::Tween::Type tween_type = gfx::Tween::LINEAR,
                  const std::string& animation_histogram_name = std::string());

// Returns the resized image if the binary size of `input_image` is greater than
// `size_limit_in_byte`. Otherwise, returns `std::nullopt`.
[[nodiscard]] ASH_EXPORT std::optional<gfx::ImageSkia>
ResizeImageIfExceedSizeLimit(const gfx::ImageSkia& input_image,
                             size_t size_limit_in_byte);

// Check if the view can be casted to `AshNotificationView`.
// TODO(b/308814203): remove this function after cleaning the static_cast
// checks for casting `AshNotificationView*`.
bool IsAshNotificationView(views::View* sender);

// Check if the notification is Ash notification.
// TODO(b/308814203): remove this function after cleaning the static_cast
// checks for casting `AshNotificationView*`.
bool IsAshNotification(const message_center::Notification* notification);

}  // namespace message_center_utils
}  // namespace ash

#endif  // ASH_SYSTEM_NOTIFICATION_CENTER_MESSAGE_CENTER_UTILS_H_