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

ash / wm / overview / birch / coral_chip_button.h [blame]

// Copyright 2024 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_WM_OVERVIEW_BIRCH_CORAL_CHIP_BUTTON_H_
#define ASH_WM_OVERVIEW_BIRCH_CORAL_CHIP_BUTTON_H_

#include "ash/wm/overview/birch/birch_chip_button.h"

namespace views {
class AnimatedImageView;
}  // namespace views

namespace ash {

class TabAppSelectionHost;

class ASH_EXPORT CoralChipButton : public BirchChipButton {
  METADATA_HEADER(CoralChipButton, BirchChipButton)

 public:
  CoralChipButton();
  CoralChipButton(const CoralChipButton&) = delete;
  CoralChipButton& operator=(const CoralChipButton&) = delete;
  ~CoralChipButton() override;

  TabAppSelectionHost* tab_app_selection_widget() {
    return tab_app_selection_widget_.get();
  }

  void OnSelectionWidgetVisibilityChanged();

  void ShutdownSelectionWidget();

  // Called when the coral selection view has an item removed, then we need to
  // update the `CoralGroupedIconImage`.
  void ReloadIcon();

  // Called during `Init()` and for a coral chip, when the title gets updated.
  // Handles the title loading animation for a coral chip.
  void UpdateTitle(const std::optional<std::string>& group_title);

  // BirchChipButton:
  void Init(BirchItem* item) override;
  void ExecuteCommand(int command_id, int event_flags) override;

 private:
  FRIEND_TEST_ALL_PREFIXES(CoralBrowserTest, AsyncGroupTitle);
  FRIEND_TEST_ALL_PREFIXES(CoralBrowserTest, GroupTitleLoadingFail);

  // Callback for the coral addon button. Should only be clicked for a coral
  // item.
  void OnCoralAddonClicked();

  // Builds `title_loading_animated_image_`.
  void BuildTitleLoadingAnimation();

  raw_ptr<views::AnimatedImageView> title_loading_animated_image_ = nullptr;

  // The selection menu to select tabs and apps for coral launching. Created
  // once the coral add on button is clicked.
  std::unique_ptr<TabAppSelectionHost> tab_app_selection_widget_;

  base::WeakPtrFactory<CoralChipButton> weak_factory_{this};
};

BEGIN_VIEW_BUILDER(/*no export*/, CoralChipButton, BirchChipButton)
VIEW_BUILDER_METHOD(Init, BirchItem*)
END_VIEW_BUILDER

}  // namespace ash

DEFINE_VIEW_BUILDER(/*no export*/, ash::CoralChipButton)

#endif  // ASH_WM_OVERVIEW_BIRCH_CORAL_CHIP_BUTTON_H_