Ahmed Fakhry | ec348379 | 2019-03-04 18:09:27 | [diff] [blame] | 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_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 Fakhry | 927eabc | 2019-05-11 00:14:15 | [diff] [blame] | 11 | #include "ash/wm/desks/desk.h" |
Sammie Quon | a4a9142 | 2019-07-11 03:00:57 | [diff] [blame] | 12 | #include "ash/wm/overview/overview_highlight_controller.h" |
Ahmed Fakhry | ec348379 | 2019-03-04 18:09:27 | [diff] [blame] | 13 | #include "base/macros.h" |
| 14 | #include "ui/views/controls/button/button.h" |
| 15 | #include "ui/views/controls/label.h" |
Ahmed Fakhry | 5d041ef | 2020-02-20 21:39:05 | [diff] [blame] | 16 | #include "ui/views/controls/textfield/textfield_controller.h" |
| 17 | #include "ui/views/view_observer.h" |
Ahmed Fakhry | ec348379 | 2019-03-04 18:09:27 | [diff] [blame] | 18 | |
| 19 | namespace ash { |
| 20 | |
| 21 | class CloseDeskButton; |
Ahmed Fakhry | 5d041ef | 2020-02-20 21:39:05 | [diff] [blame] | 22 | class DeskNameView; |
Ahmed Fakhry | ec348379 | 2019-03-04 18:09:27 | [diff] [blame] | 23 | class DeskPreviewView; |
Ahmed Fakhry | 5d041ef | 2020-02-20 21:39:05 | [diff] [blame] | 24 | class DesksBarView; |
Ahmed Fakhry | ec348379 | 2019-03-04 18:09:27 | [diff] [blame] | 25 | |
| 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 Quon | a4a9142 | 2019-07-11 03:00:57 | [diff] [blame] | 30 | class ASH_EXPORT DeskMiniView |
Ahmed Fakhry | 5d041ef | 2020-02-20 21:39:05 | [diff] [blame] | 31 | : public views::View, |
Sammie Quon | a4a9142 | 2019-07-11 03:00:57 | [diff] [blame] | 32 | public Desk::Observer, |
Ahmed Fakhry | 5d041ef | 2020-02-20 21:39:05 | [diff] [blame] | 33 | public OverviewHighlightController::OverviewHighlightableView, |
| 34 | public views::TextfieldController, |
| 35 | public views::ViewObserver { |
Ahmed Fakhry | ec348379 | 2019-03-04 18:09:27 | [diff] [blame] | 36 | public: |
minch | 221b59fb | 2021-01-28 23:29:18 | [diff] [blame] | 37 | // 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 Fakhry | a1c9db7 | 2020-01-29 03:14:53 | [diff] [blame] | 47 | DeskMiniView(DesksBarView* owner_bar, aura::Window* root_window, Desk* desk); |
Ahmed Fakhry | ec348379 | 2019-03-04 18:09:27 | [diff] [blame] | 48 | ~DeskMiniView() override; |
| 49 | |
Ahmed Fakhry | 927eabc | 2019-05-11 00:14:15 | [diff] [blame] | 50 | aura::Window* root_window() { return root_window_; } |
| 51 | |
Ahmed Fakhry | bab46dd | 2019-05-23 00:27:34 | [diff] [blame] | 52 | Desk* desk() { return desk_; } |
Ahmed Fakhry | ec348379 | 2019-03-04 18:09:27 | [diff] [blame] | 53 | |
Ahmed Fakhry | 5d041ef | 2020-02-20 21:39:05 | [diff] [blame] | 54 | DeskNameView* desk_name_view() { return desk_name_view_; } |
| 55 | |
Ahmed Fakhry | ec348379 | 2019-03-04 18:09:27 | [diff] [blame] | 56 | const CloseDeskButton* close_desk_button() const { |
| 57 | return close_desk_button_; |
| 58 | } |
| 59 | |
Xiaodan Zhu | acbbf544 | 2021-01-15 01:29:51 | [diff] [blame] | 60 | DesksBarView* owner_bar() { return owner_bar_; } |
minch | 657fada | 2021-02-24 21:42:47 | [diff] [blame] | 61 | const DeskPreviewView* desk_preview() const { return desk_preview_; } |
Xiaodan Zhu | acbbf544 | 2021-01-15 01:29:51 | [diff] [blame] | 62 | |
| 63 | gfx::Rect GetPreviewBoundsInScreen() const; |
| 64 | |
Ahmed Fakhry | 927eabc | 2019-05-11 00:14:15 | [diff] [blame] | 65 | // Returns the associated desk's container window on the display this |
| 66 | // mini_view resides on. |
| 67 | aura::Window* GetDeskContainer() const; |
| 68 | |
Ahmed Fakhry | 5d041ef | 2020-02-20 21:39:05 | [diff] [blame] | 69 | // Returns true if the desk's name is being modified (i.e. the DeskNameView |
| 70 | // has the focus). |
| 71 | bool IsDeskNameBeingModified() const; |
| 72 | |
Ahmed Fakhry | ec348379 | 2019-03-04 18:09:27 | [diff] [blame] | 73 | // Updates the visibility state of the close button depending on whether this |
Richard Chui | 77c7b9b | 2020-09-10 02:16:08 | [diff] [blame] | 74 | // view is mouse hovered, or if switch access is enabled. |
| 75 | void UpdateCloseButtonVisibility(); |
Ahmed Fakhry | ec348379 | 2019-03-04 18:09:27 | [diff] [blame] | 76 | |
Ahmed Fakhry | 2dd65b5 | 2019-06-10 22:28:56 | [diff] [blame] | 77 | // 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 Dai | a44fc98c | 2019-07-25 01:01:07 | [diff] [blame] | 80 | void OnWidgetGestureTap(const gfx::Rect& screen_rect, bool is_long_gesture); |
Ahmed Fakhry | 2dd65b5 | 2019-06-10 22:28:56 | [diff] [blame] | 81 | |
Ahmed Fakhry | ce8bf1d82 | 2019-04-30 22:06:24 | [diff] [blame] | 82 | // Updates the border color of the DeskPreviewView based on the activation |
| 83 | // state of the corresponding desk. |
Ahmed Fakhry | bab46dd | 2019-05-23 00:27:34 | [diff] [blame] | 84 | void UpdateBorderColor(); |
Ahmed Fakhry | ce8bf1d82 | 2019-04-30 22:06:24 | [diff] [blame] | 85 | |
minch | ae1e8a8 | 2021-01-26 20:43:11 | [diff] [blame] | 86 | // Gets the preview border's insets. |
| 87 | gfx::Insets GetPreviewBorderInsets() const; |
| 88 | |
minch | 9f1b0c8a | 2020-10-22 18:23:34 | [diff] [blame] | 89 | // views::View: |
Ahmed Fakhry | ec348379 | 2019-03-04 18:09:27 | [diff] [blame] | 90 | const char* GetClassName() const override; |
| 91 | void Layout() override; |
| 92 | gfx::Size CalculatePreferredSize() const override; |
Ahmed Fakhry | a93ae8c | 2019-08-28 03:06:52 | [diff] [blame] | 93 | void GetAccessibleNodeData(ui::AXNodeData* node_data) override; |
minch | 9f1b0c8a | 2020-10-22 18:23:34 | [diff] [blame] | 94 | void OnThemeChanged() override; |
Ahmed Fakhry | ec348379 | 2019-03-04 18:09:27 | [diff] [blame] | 95 | |
Ahmed Fakhry | 927eabc | 2019-05-11 00:14:15 | [diff] [blame] | 96 | // Desk::Observer: |
Ahmed Fakhry | 9df7b43 | 2019-05-15 17:02:24 | [diff] [blame] | 97 | void OnContentChanged() override; |
| 98 | void OnDeskDestroyed(const Desk* desk) override; |
Jan Wilken Dörrie | 85285b0 | 2021-03-11 23:38:47 | [diff] [blame^] | 99 | void OnDeskNameChanged(const std::u16string& new_name) override; |
Ahmed Fakhry | ec348379 | 2019-03-04 18:09:27 | [diff] [blame] | 100 | |
Sammie Quon | a4a9142 | 2019-07-11 03:00:57 | [diff] [blame] | 101 | // OverviewHighlightController::OverviewHighlightableView: |
| 102 | views::View* GetView() override; |
Sammie Quon | 9c7cfb9 | 2019-08-03 00:55:19 | [diff] [blame] | 103 | void MaybeActivateHighlightedView() override; |
| 104 | void MaybeCloseHighlightedView() override; |
Xiaodan Zhu | 5918ed4 | 2021-01-21 06:54:08 | [diff] [blame] | 105 | void MaybeSwapHighlightedView(bool right) override; |
Sammie Quon | 9384472 | 2020-01-18 00:56:11 | [diff] [blame] | 106 | void OnViewHighlighted() override; |
Sammie Quon | 21c9419 | 2019-08-28 23:11:52 | [diff] [blame] | 107 | void OnViewUnhighlighted() override; |
Sammie Quon | a4a9142 | 2019-07-11 03:00:57 | [diff] [blame] | 108 | |
Ahmed Fakhry | 5d041ef | 2020-02-20 21:39:05 | [diff] [blame] | 109 | // views::TextfieldController: |
| 110 | void ContentsChanged(views::Textfield* sender, |
Jan Wilken Dörrie | 85285b0 | 2021-03-11 23:38:47 | [diff] [blame^] | 111 | const std::u16string& new_contents) override; |
Ahmed Fakhry | 5d041ef | 2020-02-20 21:39:05 | [diff] [blame] | 112 | bool HandleKeyEvent(views::Textfield* sender, |
| 113 | const ui::KeyEvent& key_event) override; |
Ahmed | 9d475ac5 | 2020-03-06 17:49:54 | [diff] [blame] | 114 | bool HandleMouseEvent(views::Textfield* sender, |
| 115 | const ui::MouseEvent& mouse_event) override; |
Ahmed Fakhry | 5d041ef | 2020-02-20 21:39:05 | [diff] [blame] | 116 | |
| 117 | // views::ViewObserver: |
| 118 | void OnViewFocused(views::View* observed_view) override; |
| 119 | void OnViewBlurred(views::View* observed_view) override; |
| 120 | |
Ahmed Fakhry | bab46dd | 2019-05-23 00:27:34 | [diff] [blame] | 121 | bool IsPointOnMiniView(const gfx::Point& screen_location) const; |
| 122 | |
yjliu | ed7a849 | 2019-10-23 15:19:17 | [diff] [blame] | 123 | // 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 Fakhry | 5d041ef | 2020-02-20 21:39:05 | [diff] [blame] | 129 | bool IsDeskNameViewVisibleForTesting() const; |
yjliu | 3088155f | 2019-10-08 23:25:36 | [diff] [blame] | 130 | |
Ahmed Fakhry | ec348379 | 2019-03-04 18:09:27 | [diff] [blame] | 131 | private: |
Sammie Quon | 9c7cfb9 | 2019-08-03 00:55:19 | [diff] [blame] | 132 | void OnCloseButtonPressed(); |
| 133 | |
Ahmed Fakhry | 5d041ef | 2020-02-20 21:39:05 | [diff] [blame] | 134 | void OnDeskPreviewPressed(); |
| 135 | |
chinsenj | 7befc5333 | 2020-09-18 21:07:01 | [diff] [blame] | 136 | // Layout |desk_name_view_| given the current bounds of the desk preview. |
| 137 | void LayoutDeskNameView(const gfx::Rect& preview_bounds); |
| 138 | |
Ahmed Fakhry | bab46dd | 2019-05-23 00:27:34 | [diff] [blame] | 139 | DesksBarView* const owner_bar_; |
| 140 | |
Ahmed Fakhry | 927eabc | 2019-05-11 00:14:15 | [diff] [blame] | 141 | // 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 Fakhry | ec348379 | 2019-03-04 18:09:27 | [diff] [blame] | 148 | |
| 149 | // The view that shows a preview of the desk contents. |
Wei Li | 8429ca70 | 2020-05-28 04:04:55 | [diff] [blame] | 150 | DeskPreviewView* desk_preview_; |
Ahmed Fakhry | ec348379 | 2019-03-04 18:09:27 | [diff] [blame] | 151 | |
Ahmed Fakhry | 5d041ef | 2020-02-20 21:39:05 | [diff] [blame] | 152 | // The editable desk name. |
Wei Li | 8429ca70 | 2020-05-28 04:04:55 | [diff] [blame] | 153 | DeskNameView* desk_name_view_; |
Ahmed Fakhry | ec348379 | 2019-03-04 18:09:27 | [diff] [blame] | 154 | |
| 155 | // The close button that shows on hover. |
Wei Li | 8429ca70 | 2020-05-28 04:04:55 | [diff] [blame] | 156 | CloseDeskButton* close_desk_button_; |
Ahmed Fakhry | ec348379 | 2019-03-04 18:09:27 | [diff] [blame] | 157 | |
Ahmed Fakhry | 2dd65b5 | 2019-06-10 22:28:56 | [diff] [blame] | 158 | // 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 | |
Ahmed | 9d475ac5 | 2020-03-06 17:49:54 | [diff] [blame] | 162 | // 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 Fakhry | 5d041ef | 2020-02-20 21:39:05 | [diff] [blame] | 167 | bool is_desk_name_being_modified_ = false; |
| 168 | |
Ahmed Fakhry | ec348379 | 2019-03-04 18:09:27 | [diff] [blame] | 169 | DISALLOW_COPY_AND_ASSIGN(DeskMiniView); |
| 170 | }; |
| 171 | |
| 172 | } // namespace ash |
| 173 | |
| 174 | #endif // ASH_WM_DESKS_DESK_MINI_VIEW_H_ |