1 // Copyright 2019 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef ASH_WM_DESKS_NEW_DESK_BUTTON_H_
6 #define ASH_WM_DESKS_NEW_DESK_BUTTON_H_
7 
8 #include <memory>
9 
10 #include "ash/ash_export.h"
11 #include "ash/wm/overview/overview_highlight_controller.h"
12 #include "base/macros.h"
13 #include "ui/views/controls/button/label_button.h"
14 
15 namespace ash {
16 
17 class WmHighlightItemBorder;
18 
19 // A button view that shows up in the top-right corner of the screen when
20 // overview mode is on, which is used to create a new virtual desk.
21 class ASH_EXPORT NewDeskButton
22     : public views::LabelButton,
23       public OverviewHighlightController::OverviewHighlightableView {
24  public:
25   NewDeskButton();
26   ~NewDeskButton() override = default;
27 
28   // Update the button's enable/disable state based on current desks state.
29   void UpdateButtonState();
30 
31   void OnButtonPressed();
32 
33   void SetLabelVisible(bool visible);
34 
35   // Gets the minimum size of this view to properly lay out all its contents.
36   // |compact| is set to true for compact mode or false for default mode.
37   // The view containing this object can use the size returned from this
38   // function to decide its own proper size or layout in default or compact
39   // mode.
40   gfx::Size GetMinSize(bool compact) const;
41 
42   gfx::Size CalculatePreferredSize() const override;
43   void Layout() override;
44 
45   // LabelButton:
46   const char* GetClassName() const override;
47   void OnPaintBackground(gfx::Canvas* canvas) override;
48   std::unique_ptr<views::InkDrop> CreateInkDrop() override;
49   std::unique_ptr<views::InkDropHighlight> CreateInkDropHighlight()
50       const override;
51   SkColor GetInkDropBaseColor() const override;
52   std::unique_ptr<views::LabelButtonBorder> CreateDefaultBorder()
53       const override;
54   void OnThemeChanged() override;
55 
56   // OverviewHighlightController::OverviewHighlightableView:
57   views::View* GetView() override;
58   void MaybeActivateHighlightedView() override;
59   void MaybeCloseHighlightedView() override;
60   void OnViewHighlighted() override;
61   void OnViewUnhighlighted() override;
62 
GetBackgroundColorForTesting()63   SkColor GetBackgroundColorForTesting() const { return background_color_; }
64   bool IsLabelVisibleForTesting() const;
65 
66  private:
67   void UpdateBorderState();
68 
69   // Owned by this View via `View::border_`. This is just a convenient pointer
70   // to it.
71   WmHighlightItemBorder* border_ptr_;
72 
73   SkColor background_color_;
74 
75   DISALLOW_COPY_AND_ASSIGN(NewDeskButton);
76 };
77 
78 }  // namespace ash
79 
80 #endif  // ASH_WM_DESKS_NEW_DESK_BUTTON_H_
81