[go: nahoru, domu]

blob: 5d4ca394d2778da6d51e104e0a40d8470d60d177 [file] [log] [blame]
Ahmed Fakhryec3483792019-03-04 18:09:271// 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_DESK_MINI_VIEW_H_
6#define ASH_WM_DESKS_DESK_MINI_VIEW_H_
7
8#include <memory>
9
10#include "ash/ash_export.h"
Ahmed Fakhry927eabc2019-05-11 00:14:1511#include "ash/wm/desks/desk.h"
Sammie Quona4a91422019-07-11 03:00:5712#include "ash/wm/overview/overview_highlight_controller.h"
Ahmed Fakhryec3483792019-03-04 18:09:2713#include "base/macros.h"
14#include "ui/views/controls/button/button.h"
15#include "ui/views/controls/label.h"
Ahmed Fakhry5d041ef2020-02-20 21:39:0516#include "ui/views/controls/textfield/textfield_controller.h"
17#include "ui/views/view_observer.h"
Ahmed Fakhryec3483792019-03-04 18:09:2718
19namespace ash {
20
21class CloseDeskButton;
Ahmed Fakhry5d041ef2020-02-20 21:39:0522class DeskNameView;
Ahmed Fakhryec3483792019-03-04 18:09:2723class DeskPreviewView;
Ahmed Fakhry5d041ef2020-02-20 21:39:0524class DesksBarView;
Ahmed Fakhryec3483792019-03-04 18:09:2725
26// A view that acts as a mini representation (a.k.a. desk thumbnail) of a
27// virtual desk in the desk bar view when overview mode is active. This view
28// shows a preview of the contents of the associated desk, its title, and
29// supports desk activation and removal.
Sammie Quona4a91422019-07-11 03:00:5730class ASH_EXPORT DeskMiniView
Ahmed Fakhry5d041ef2020-02-20 21:39:0531 : public views::View,
Sammie Quona4a91422019-07-11 03:00:5732 public Desk::Observer,
Ahmed Fakhry5d041ef2020-02-20 21:39:0533 public OverviewHighlightController::OverviewHighlightableView,
34 public views::TextfieldController,
35 public views::ViewObserver {
Ahmed Fakhryec3483792019-03-04 18:09:2736 public:
minch221b59fb2021-01-28 23:29:1837 // Returns the width of the desk preview based on its |preview_height| and the
38 // aspect ratio of the root window taken from |root_window_size|.
39 static int GetPreviewWidth(const gfx::Size& root_window_size,
40 int preview_height);
41
42 // The desk preview bounds are proportional to the bounds of the display on
43 // which it resides, and whether the |compact| layout is used.
44 static gfx::Rect GetDeskPreviewBounds(aura::Window* root_window,
45 bool compact);
46
Ahmed Fakhrya1c9db72020-01-29 03:14:5347 DeskMiniView(DesksBarView* owner_bar, aura::Window* root_window, Desk* desk);
Ahmed Fakhryec3483792019-03-04 18:09:2748 ~DeskMiniView() override;
49
Ahmed Fakhry927eabc2019-05-11 00:14:1550 aura::Window* root_window() { return root_window_; }
51
Ahmed Fakhrybab46dd2019-05-23 00:27:3452 Desk* desk() { return desk_; }
Ahmed Fakhryec3483792019-03-04 18:09:2753
Ahmed Fakhry5d041ef2020-02-20 21:39:0554 DeskNameView* desk_name_view() { return desk_name_view_; }
55
Ahmed Fakhryec3483792019-03-04 18:09:2756 const CloseDeskButton* close_desk_button() const {
57 return close_desk_button_;
58 }
59
Xiaodan Zhuacbbf5442021-01-15 01:29:5160 DesksBarView* owner_bar() { return owner_bar_; }
minch657fada2021-02-24 21:42:4761 const DeskPreviewView* desk_preview() const { return desk_preview_; }
Xiaodan Zhuacbbf5442021-01-15 01:29:5162
63 gfx::Rect GetPreviewBoundsInScreen() const;
64
Ahmed Fakhry927eabc2019-05-11 00:14:1565 // Returns the associated desk's container window on the display this
66 // mini_view resides on.
67 aura::Window* GetDeskContainer() const;
68
Ahmed Fakhry5d041ef2020-02-20 21:39:0569 // Returns true if the desk's name is being modified (i.e. the DeskNameView
70 // has the focus).
71 bool IsDeskNameBeingModified() const;
72
Ahmed Fakhryec3483792019-03-04 18:09:2773 // Updates the visibility state of the close button depending on whether this
Richard Chui77c7b9b2020-09-10 02:16:0874 // view is mouse hovered, or if switch access is enabled.
75 void UpdateCloseButtonVisibility();
Ahmed Fakhryec3483792019-03-04 18:09:2776
Ahmed Fakhry2dd65b52019-06-10 22:28:5677 // Gesture tapping may affect the visibility of the close button. There's only
78 // one mini_view that shows the close button on long press at any time.
79 // This is useful for touch-only UIs.
Xiaoqian Daia44fc98c2019-07-25 01:01:0780 void OnWidgetGestureTap(const gfx::Rect& screen_rect, bool is_long_gesture);
Ahmed Fakhry2dd65b52019-06-10 22:28:5681
Ahmed Fakhryce8bf1d822019-04-30 22:06:2482 // Updates the border color of the DeskPreviewView based on the activation
83 // state of the corresponding desk.
Ahmed Fakhrybab46dd2019-05-23 00:27:3484 void UpdateBorderColor();
Ahmed Fakhryce8bf1d822019-04-30 22:06:2485
minchae1e8a82021-01-26 20:43:1186 // Gets the preview border's insets.
87 gfx::Insets GetPreviewBorderInsets() const;
88
minch9f1b0c8a2020-10-22 18:23:3489 // views::View:
Ahmed Fakhryec3483792019-03-04 18:09:2790 const char* GetClassName() const override;
91 void Layout() override;
92 gfx::Size CalculatePreferredSize() const override;
Ahmed Fakhrya93ae8c2019-08-28 03:06:5293 void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
minch9f1b0c8a2020-10-22 18:23:3494 void OnThemeChanged() override;
Ahmed Fakhryec3483792019-03-04 18:09:2795
Ahmed Fakhry927eabc2019-05-11 00:14:1596 // Desk::Observer:
Ahmed Fakhry9df7b432019-05-15 17:02:2497 void OnContentChanged() override;
98 void OnDeskDestroyed(const Desk* desk) override;
Jan Wilken Dörrie85285b02021-03-11 23:38:4799 void OnDeskNameChanged(const std::u16string& new_name) override;
Ahmed Fakhryec3483792019-03-04 18:09:27100
Sammie Quona4a91422019-07-11 03:00:57101 // OverviewHighlightController::OverviewHighlightableView:
102 views::View* GetView() override;
Sammie Quon9c7cfb92019-08-03 00:55:19103 void MaybeActivateHighlightedView() override;
104 void MaybeCloseHighlightedView() override;
Xiaodan Zhu5918ed42021-01-21 06:54:08105 void MaybeSwapHighlightedView(bool right) override;
Sammie Quon93844722020-01-18 00:56:11106 void OnViewHighlighted() override;
Sammie Quon21c94192019-08-28 23:11:52107 void OnViewUnhighlighted() override;
Sammie Quona4a91422019-07-11 03:00:57108
Ahmed Fakhry5d041ef2020-02-20 21:39:05109 // views::TextfieldController:
110 void ContentsChanged(views::Textfield* sender,
Jan Wilken Dörrie85285b02021-03-11 23:38:47111 const std::u16string& new_contents) override;
Ahmed Fakhry5d041ef2020-02-20 21:39:05112 bool HandleKeyEvent(views::Textfield* sender,
113 const ui::KeyEvent& key_event) override;
Ahmed9d475ac52020-03-06 17:49:54114 bool HandleMouseEvent(views::Textfield* sender,
115 const ui::MouseEvent& mouse_event) override;
Ahmed Fakhry5d041ef2020-02-20 21:39:05116
117 // views::ViewObserver:
118 void OnViewFocused(views::View* observed_view) override;
119 void OnViewBlurred(views::View* observed_view) override;
120
Ahmed Fakhrybab46dd2019-05-23 00:27:34121 bool IsPointOnMiniView(const gfx::Point& screen_location) const;
122
yjliued7a8492019-10-23 15:19:17123 // Gets the minimum width of this view to properly lay out all its contents in
124 // default layout.
125 // The view containing this object can use the width returned from this
126 // function to decide its own proper size or layout.
127 int GetMinWidthForDefaultLayout() const;
128
Ahmed Fakhry5d041ef2020-02-20 21:39:05129 bool IsDeskNameViewVisibleForTesting() const;
yjliu3088155f2019-10-08 23:25:36130
Ahmed Fakhryec3483792019-03-04 18:09:27131 private:
Sammie Quon9c7cfb92019-08-03 00:55:19132 void OnCloseButtonPressed();
133
Ahmed Fakhry5d041ef2020-02-20 21:39:05134 void OnDeskPreviewPressed();
135
chinsenj7befc53332020-09-18 21:07:01136 // Layout |desk_name_view_| given the current bounds of the desk preview.
137 void LayoutDeskNameView(const gfx::Rect& preview_bounds);
138
Ahmed Fakhrybab46dd2019-05-23 00:27:34139 DesksBarView* const owner_bar_;
140
Ahmed Fakhry927eabc2019-05-11 00:14:15141 // The root window on which this mini_view is created.
142 aura::Window* root_window_;
143
144 // The associated desk. Can be null when the desk is deleted before this
145 // mini_view completes its removal animation. See comment above
146 // OnDeskRemoved().
147 Desk* desk_; // Not owned.
Ahmed Fakhryec3483792019-03-04 18:09:27148
149 // The view that shows a preview of the desk contents.
Wei Li8429ca702020-05-28 04:04:55150 DeskPreviewView* desk_preview_;
Ahmed Fakhryec3483792019-03-04 18:09:27151
Ahmed Fakhry5d041ef2020-02-20 21:39:05152 // The editable desk name.
Wei Li8429ca702020-05-28 04:04:55153 DeskNameView* desk_name_view_;
Ahmed Fakhryec3483792019-03-04 18:09:27154
155 // The close button that shows on hover.
Wei Li8429ca702020-05-28 04:04:55156 CloseDeskButton* close_desk_button_;
Ahmed Fakhryec3483792019-03-04 18:09:27157
Ahmed Fakhry2dd65b52019-06-10 22:28:56158 // We force showing the close button when the mini_view is long pressed or
159 // tapped using touch gestures.
160 bool force_show_close_button_ = false;
161
Ahmed9d475ac52020-03-06 17:49:54162 // When the DeskNameView is focused, we select all its text. However, if it is
163 // focused via a mouse press event, on mouse release will clear the selection.
164 // Therefore, we defer selecting all text until we receive that mouse release.
165 bool defer_select_all_ = false;
166
Ahmed Fakhry5d041ef2020-02-20 21:39:05167 bool is_desk_name_being_modified_ = false;
168
Ahmed Fakhryec3483792019-03-04 18:09:27169 DISALLOW_COPY_AND_ASSIGN(DeskMiniView);
170};
171
172} // namespace ash
173
174#endif // ASH_WM_DESKS_DESK_MINI_VIEW_H_