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