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_OVERVIEW_OVERVIEW_ITEM_VIEW_H_
6 #define ASH_WM_OVERVIEW_OVERVIEW_ITEM_VIEW_H_
7 
8 #include "ash/wm/overview/overview_highlight_controller.h"
9 #include "ash/wm/window_mini_view.h"
10 #include "base/macros.h"
11 #include "ui/views/controls/button/button.h"
12 
13 namespace aura {
14 class Window;
15 }  // namespace aura
16 
17 namespace views {
18 class ImageButton;
19 class View;
20 }  // namespace views
21 
22 namespace ash {
23 class OverviewItem;
24 
25 // OverviewItemView covers the overview window and listens for events.
26 class ASH_EXPORT OverviewItemView
27     : public WindowMiniView,
28       public OverviewHighlightController::OverviewHighlightableView {
29  public:
30   // The visibility of the header. It may be fully visible or invisible, or
31   // everything but the close button is visible.
32   enum class HeaderVisibility {
33     kInvisible,
34     kCloseButtonInvisibleOnly,
35     kVisible,
36   };
37 
38   // If |show_preview| is true, this class will contain a child view which
39   // mirrors |window|.
40   OverviewItemView(OverviewItem* overview_item,
41                    views::Button::PressedCallback close_callback,
42                    aura::Window* window,
43                    bool show_preview);
44   ~OverviewItemView() override;
45 
46   // Fades the app icon and title out if |visibility| is kInvisible, in
47   // otherwise. If |close_button_| is not null, also fades the close button in
48   // if |visibility| is kVisible, out otherwise. Sets
49   // |current_header_visibility_| to |visibility|.
50   void SetHeaderVisibility(HeaderVisibility visibility);
51 
52   // Hides the close button instantaneously, and then fades it in slowly and
53   // with a long delay. Sets |current_header_visibility_| to kVisible. Assumes
54   // that |close_button_| is not null, and that |current_header_visibility_| is
55   // not kInvisible.
56   void HideCloseInstantlyAndThenShowItSlowly();
57 
58   // Called when |overview_item_| is about to be restored to its original state
59   // outside of overview.
60   void OnOverviewItemWindowRestoring();
61 
62   // Refreshes |preview_view_| so that its content is up-to-date. Used by tab
63   // dragging.
64   void RefreshPreviewView();
65 
66   // WindowMiniView:
67   gfx::Rect GetHeaderBounds() const override;
68   gfx::Size GetPreviewViewSize() const override;
69   gfx::ImageSkia ModifyIcon(gfx::ImageSkia* image) const override;
70   void Layout() override;
71 
72   // OverviewHighlightController::OverviewHighlightableView:
73   views::View* GetView() override;
74   void MaybeActivateHighlightedView() override;
75   void MaybeCloseHighlightedView() override;
76   void OnViewHighlighted() override;
77   void OnViewUnhighlighted() override;
78   gfx::Point GetMagnifierFocusPointInScreen() override;
79 
close_button()80   views::ImageButton* close_button() { return close_button_; }
81 
82  protected:
83   // views::View:
84   const char* GetClassName() const override;
85   bool OnMousePressed(const ui::MouseEvent& event) override;
86   bool OnMouseDragged(const ui::MouseEvent& event) override;
87   void OnMouseReleased(const ui::MouseEvent& event) override;
88   void OnGestureEvent(ui::GestureEvent* event) override;
89   bool CanAcceptEvent(const ui::Event& event) override;
90   void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
91 
92  private:
93   // The OverviewItem which owns the widget which houses this view. Non-null
94   // until |OnOverviewItemWindowRestoring| is called.
95   OverviewItem* overview_item_;
96 
97   views::ImageButton* close_button_;
98 
99   HeaderVisibility current_header_visibility_ = HeaderVisibility::kVisible;
100 
101   DISALLOW_COPY_AND_ASSIGN(OverviewItemView);
102 };
103 
104 }  // namespace ash
105 
106 #endif  // ASH_WM_OVERVIEW_OVERVIEW_ITEM_VIEW_H_
107