Abbas Nayebi | 5416138 | 2022-11-17 23:17:33 | [diff] [blame] | 1 | // Copyright 2022 The Chromium Authors |
| 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_SYSTEM_PHONEHUB_APP_STREAM_LAUNCHER_VIEW_H_ |
| 6 | #define ASH_SYSTEM_PHONEHUB_APP_STREAM_LAUNCHER_VIEW_H_ |
| 7 | |
Abbas Nayebi | 21b5ed1 | 2022-11-22 23:31:15 | [diff] [blame] | 8 | #include <cstdint> |
Abbas Nayebi | 5416138 | 2022-11-17 23:17:33 | [diff] [blame] | 9 | #include <memory> |
Henrique Ferreiro | fadda06 | 2022-12-01 16:27:14 | [diff] [blame] | 10 | |
Abbas Nayebi | 5416138 | 2022-11-17 23:17:33 | [diff] [blame] | 11 | #include "ash/ash_export.h" |
| 12 | #include "ash/system/phonehub/phone_hub_content_view.h" |
Daniel Cheng | bceeb1f | 2023-05-11 19:19:34 | [diff] [blame] | 13 | #include "base/gtest_prod_util.h" |
Arthur Sonzogni | 834e018f | 2023-04-22 10:20:02 | [diff] [blame] | 14 | #include "base/memory/raw_ptr.h" |
Henrique Ferreiro | fadda06 | 2022-12-01 16:27:14 | [diff] [blame] | 15 | #include "chromeos/ash/components/phonehub/app_stream_launcher_data_model.h" |
| 16 | #include "chromeos/ash/components/phonehub/notification.h" |
| 17 | #include "chromeos/ash/components/phonehub/recent_app_click_observer.h" |
| 18 | #include "chromeos/ash/components/phonehub/recent_apps_interaction_handler.h" |
Abbas Nayebi | 5416138 | 2022-11-17 23:17:33 | [diff] [blame] | 19 | #include "ui/gfx/vector_icon_types.h" |
| 20 | #include "ui/views/controls/button/button.h" |
| 21 | #include "ui/views/view.h" |
| 22 | |
| 23 | namespace views { |
| 24 | class Button; |
| 25 | } |
| 26 | namespace ash { |
| 27 | |
| 28 | namespace phonehub { |
| 29 | class PhoneHubManager; |
| 30 | } |
| 31 | |
| 32 | // A view of the Phone Hub panel, displaying the apps that user can launch for |
| 33 | // app streaming. |
Abbas Nayebi | 21b5ed1 | 2022-11-22 23:31:15 | [diff] [blame] | 34 | class ASH_EXPORT AppStreamLauncherView |
| 35 | : public PhoneHubContentView, |
| 36 | public phonehub::AppStreamLauncherDataModel::Observer { |
Abbas Nayebi | 5416138 | 2022-11-17 23:17:33 | [diff] [blame] | 37 | public: |
| 38 | explicit AppStreamLauncherView(phonehub::PhoneHubManager* phone_hub_manager); |
| 39 | ~AppStreamLauncherView() override; |
| 40 | |
| 41 | // views::View: |
| 42 | void ChildPreferredSizeChanged(View* child) override; |
| 43 | void ChildVisibilityChanged(View* child) override; |
| 44 | const char* GetClassName() const override; |
| 45 | |
| 46 | // PhoneHubContentView: |
| 47 | phone_hub_metrics::Screen GetScreenForMetrics() const override; |
Pu Shi | 7d04c29 | 2023-04-11 20:13:59 | [diff] [blame] | 48 | void OnBubbleClose() override; |
Abbas Nayebi | 5416138 | 2022-11-17 23:17:33 | [diff] [blame] | 49 | |
Abbas Nayebi | 21b5ed1 | 2022-11-22 23:31:15 | [diff] [blame] | 50 | // phonehub::AppStreamLauncherDataModel::Observer: |
| 51 | void OnAppListChanged() override; |
| 52 | |
Abbas Nayebi | 5ef3f3d | 2022-11-29 00:06:22 | [diff] [blame] | 53 | views::View* items_container_for_test() { return items_container_; } |
| 54 | |
Abbas Nayebi | 5416138 | 2022-11-17 23:17:33 | [diff] [blame] | 55 | private: |
| 56 | friend class AppStreamLauncherViewTest; |
| 57 | FRIEND_TEST_ALL_PREFIXES(AppStreamLauncherViewTest, OpenView); |
Abbas Nayebi | 5ef3f3d | 2022-11-29 00:06:22 | [diff] [blame] | 58 | FRIEND_TEST_ALL_PREFIXES(AppStreamLauncherViewTest, AddItems); |
| 59 | FRIEND_TEST_ALL_PREFIXES(AppStreamLauncherViewTest, ClickOnItem); |
Abbas Nayebi | 5416138 | 2022-11-17 23:17:33 | [diff] [blame] | 60 | |
| 61 | std::unique_ptr<views::View> CreateAppListView(); |
Abbas Nayebi | 21b5ed1 | 2022-11-22 23:31:15 | [diff] [blame] | 62 | std::unique_ptr<views::View> CreateItemView( |
| 63 | const phonehub::Notification::AppMetadata& app); |
Pu Shi | a161460a | 2022-12-20 23:37:29 | [diff] [blame] | 64 | std::unique_ptr<views::View> CreateListItemView( |
| 65 | const phonehub::Notification::AppMetadata& app); |
Abbas Nayebi | 5416138 | 2022-11-17 23:17:33 | [diff] [blame] | 66 | std::unique_ptr<views::View> CreateHeaderView(); |
| 67 | std::unique_ptr<views::Button> CreateButton( |
| 68 | views::Button::PressedCallback callback, |
| 69 | const gfx::VectorIcon& icon, |
| 70 | int message_id); |
Daniel Cheng | 667d190 | 2023-12-01 23:16:32 | [diff] [blame^] | 71 | void AppIconActivated(phonehub::Notification::AppMetadata app); |
Abbas Nayebi | 21b5ed1 | 2022-11-22 23:31:15 | [diff] [blame] | 72 | |
| 73 | // Update the UI based on the information in the data model. |
| 74 | void UpdateFromDataModel(); |
Abbas Nayebi | 5416138 | 2022-11-17 23:17:33 | [diff] [blame] | 75 | |
| 76 | // Handles the click on the "back" arrow in the header. |
| 77 | void OnArrowBackActivated(); |
| 78 | |
Pu Shi | a161460a | 2022-12-20 23:37:29 | [diff] [blame] | 79 | void CreateListView( |
| 80 | const std::vector<phonehub::Notification::AppMetadata>* apps_list); |
| 81 | void CreateGridView( |
| 82 | const std::vector<phonehub::Notification::AppMetadata>* apps_list); |
| 83 | |
Arthur Sonzogni | 34efeb8 | 2023-08-17 12:55:11 | [diff] [blame] | 84 | raw_ptr<views::Button, DanglingUntriaged | ExperimentalAsh> |
| 85 | arrow_back_button_ = nullptr; |
Arthur Sonzogni | 834e018f | 2023-04-22 10:20:02 | [diff] [blame] | 86 | raw_ptr<phonehub::PhoneHubManager, ExperimentalAsh> phone_hub_manager_; |
Abbas Nayebi | 5416138 | 2022-11-17 23:17:33 | [diff] [blame] | 87 | |
| 88 | // Contains all the apps |
Arthur Sonzogni | 34efeb8 | 2023-08-17 12:55:11 | [diff] [blame] | 89 | raw_ptr<views::View, DanglingUntriaged | ExperimentalAsh> items_container_; |
Abbas Nayebi | 5416138 | 2022-11-17 23:17:33 | [diff] [blame] | 90 | |
| 91 | base::WeakPtrFactory<AppStreamLauncherView> weak_factory_{this}; |
| 92 | }; |
| 93 | |
| 94 | } // namespace ash |
| 95 | |
| 96 | #endif // ASH_SYSTEM_PHONEHUB_APP_STREAM_LAUNCHER_VIEW_H_ |