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

ash / wm / window_mini_view_header_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_WM_WINDOW_MINI_VIEW_HEADER_VIEW_H_
#define ASH_WM_WINDOW_MINI_VIEW_HEADER_VIEW_H_

#include "ash/ash_export.h"
#include "base/memory/raw_ptr.h"
#include "ui/base/metadata/metadata_header_macros.h"
#include "ui/gfx/geometry/rounded_corners_f.h"
#include "ui/views/layout/box_layout_view.h"

namespace aura {
class Window;
}  // namespace aura

namespace views {
class FlexLayoutView;
class ImageView;
class Label;
}  // namespace views

namespace ash {

class WindowMiniView;

// A view that represents the header for the window mini view. It contains an
// icon and a title label from the source window of the `window_mini_view_` and
// has a stroke at the bottom of it.
class ASH_EXPORT WindowMiniViewHeaderView : public views::BoxLayoutView {
  METADATA_HEADER(WindowMiniViewHeaderView, views::BoxLayoutView)

 public:
  // Flex layout priorities for the `icon_label_view()`. The enums are listed
  // in highest to lowest priority (high priority has the least flexibility to
  // grow/shrink is more likely to get its preferred size).
  enum IconLabelFlexPriorities {
    kIconOrCloseButton = 1,
    kTitleLabel,
    kLeftoverSpace
  };

  explicit WindowMiniViewHeaderView(WindowMiniView* window_mini_view);
  WindowMiniViewHeaderView(const WindowMiniViewHeaderView&) = delete;
  WindowMiniViewHeaderView& operator=(const WindowMiniViewHeaderView&) = delete;
  ~WindowMiniViewHeaderView() override;

  views::Label* title_label() { return title_label_; }
  views::FlexLayoutView* icon_label_view() { return icon_label_view_; }

  void UpdateIconView(aura::Window* window);
  void UpdateTitleLabel(aura::Window* window);

  // Refreshes the rounded corners on `this` by recreating the background view.
  // Please note that there might be minor pixel difference if the rounded
  // corner is set on the layer of this since the way to draw the rounded
  // corners is different which may fail the pixel test
  // (WmPixelDiffTest.WindowCycleBasic).
  void RefreshHeaderViewRoundedCorners();

  void SetHeaderViewRoundedCornerRadius(
      gfx::RoundedCornersF& header_view_rounded_corners);

  // Resets the preset rounded corners values i.e.
  // `custom_header_view_rounded_corners_`.
  void ResetRoundedCorners();

 private:
  // views::View:
  void OnThemeChanged() override;

  // The parent view of `this`, which is guaranteed not null during the lifetime
  // of `this`.
  raw_ptr<WindowMiniView> window_mini_view_;

  // A view that wraps up the icon and title label. Owned by the views
  // hierarchy.
  raw_ptr<views::FlexLayoutView> icon_label_view_;

  // Views for the icon and title. Owned by the views hierarchy.
  raw_ptr<views::Label> title_label_ = nullptr;
  raw_ptr<views::ImageView> icon_view_ = nullptr;

  // Separator between the header and the overview window.
  raw_ptr<views::View> separator_ = nullptr;

  // The current rounded corner parameters for this view's background. May be
  // `nullopt` if a background is not set yet.
  std::optional<gfx::RoundedCornersF> current_header_view_rounded_corners_;

  // Custom rounded corner parameters specified by the caller via
  // `SetHeaderViewRoundedCornerRadius()`. If set, this will match
  // `current_header_view_rounded_corners_`. Otherwise,
  // `current_header_view_rounded_corners_` will be set to a default value
  // picked internally.
  std::optional<gfx::RoundedCornersF> custom_header_view_rounded_corners_;
};

}  // namespace ash

#endif  // ASH_WM_WINDOW_MINI_VIEW_HEADER_VIEW_H_