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

ash / game_dashboard / game_dashboard_toolbar_view.h [blame]

// Copyright 2023 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_GAME_DASHBOARD_GAME_DASHBOARD_TOOLBAR_VIEW_H_
#define ASH_GAME_DASHBOARD_GAME_DASHBOARD_TOOLBAR_VIEW_H_

#include "ash/ash_export.h"
#include "ash/public/cpp/arc_game_controls_flag.h"
#include "base/memory/raw_ptr.h"
#include "ui/base/metadata/metadata_header_macros.h"
#include "ui/views/layout/box_layout_view.h"

namespace ash {

class GameDashboardContext;
class IconButton;
class ToolbarDragHandler;
class SystemShadow;

// GameDashboardToolbarView is the movable toolbar that's attached to the game
// window. It contains various quick action tiles for users to access without
// having to open the entire main menu view.
class ASH_EXPORT GameDashboardToolbarView : public views::BoxLayoutView {
  METADATA_HEADER(GameDashboardToolbarView, views::BoxLayoutView)

 public:
  explicit GameDashboardToolbarView(GameDashboardContext* context);
  GameDashboardToolbarView(const GameDashboardToolbarView&) = delete;
  GameDashboardToolbarView& operator=(const GameDashboardToolbarView) = delete;
  ~GameDashboardToolbarView() override;

  // Updates `record_game_button_` to the stop button. Called when
  // `CaptureModeController` has started a recording session. If
  // `is_recording_game_window` is true, then the `context_`'s game_window is
  // being recorded.
  void OnRecordingStarted(bool is_recording_game_window);

  // Updates `record_game_button_` to the default state. Called when
  // `CaptureModeController` has ended a recording session or was aborted.
  void OnRecordingEnded();

  // Handles repositioning the toolbar view within the game window.
  void RepositionToolbar(const gfx::Vector2d& offset);

  // Handles completion of the toolbar movement.
  void EndDraggingToolbar(const gfx::Vector2d& offset);

  // Updates this view's widget visibility. If it is visible, updates
  // game_controls_button_'s state, and the tooltip text according to flags.
  void UpdateViewForGameControls(ArcGameControlsFlag flags);

  // views::View:
  bool OnKeyPressed(const ui::KeyEvent& event) override;
  bool OnKeyReleased(const ui::KeyEvent& event) override;

 private:
  friend class GameDashboardContextTestApi;

  // Used for testing. Starts at 1 because view IDs should not be 0.
  enum class ToolbarViewId : int32_t {
    kGamepadButton = 1,
    kGameControlsButton = 2,
    kScreenRecordButton = 3,
    kScreenshotButton = 4,
  };

  // Callbacks for the tiles and buttons in the toolbar view.
  // Expands or collapses the toolbar by iterating through the toolbar's
  // children and updating their visibility. The `gamepad_button_` is always
  // visible since it expands/collapses the toolbar.
  void OnGamepadButtonPressed();
  // Enables or disables Game Controls.
  void OnGameControlsButtonPressed();
  // Starts or stops recording the game window.
  void OnRecordButtonPressed();
  // Takes a screenshot of the game window.
  void OnScreenshotButtonPressed();

  // Adds a list of shortcut tiles to the toolbar view.
  void AddShortcutTiles();
  // Adds Game Controls button if needed.
  void MayAddGameControlsTile();

  // Updates the `record_game_button_` UI. If `is_recording_game_window` is
  // true, then the button will change to a stop button, otherwise it will show
  // the default UI.
  void UpdateRecordGameButton(bool is_recording_game_window);

  // Updates the 'gamepad_button_' tooltip text. If the toolbar is collapsed,
  // the tooltip text will say "Open toolbar" and if the toolbar is expanded,
  // the tooltip text will say "Close toolbar".
  void UpdateGamepadButtonTooltipText();

  // The topmost `IconButton` in the toolbar's collection, which stays visible
  // in both the expanded and collapsed toolbar states.
  raw_ptr<IconButton> gamepad_button_ = nullptr;

  // Game Controls toggle button for enabling or disabling the feature.
  raw_ptr<IconButton> game_controls_button_ = nullptr;

  // Record game button to start recording the game window, skipping the
  // countdown timer and preset screen capture options.
  raw_ptr<IconButton> record_game_button_ = nullptr;

  // The current state indicating if the toolbar view is expanded or collapsed.
  bool is_expanded_ = true;

  const raw_ptr<GameDashboardContext> context_;

  // Handles all dragging logic for the toolbar.
  std::unique_ptr<ToolbarDragHandler> drag_handler_;

  std::unique_ptr<SystemShadow> shadow_;
};

}  // namespace ash

#endif  // ASH_GAME_DASHBOARD_GAME_DASHBOARD_TOOLBAR_VIEW_H_