Melissa Zhang | db4dffa | 2020-07-01 04:03:11 | [diff] [blame] | 1 | // Copyright 2020 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 CHROME_BROWSER_SHARESHEET_SHARESHEET_SERVICE_DELEGATE_H_ |
| 6 | #define CHROME_BROWSER_SHARESHEET_SHARESHEET_SERVICE_DELEGATE_H_ |
| 7 | |
| 8 | #include <memory> |
Jan Wilken Dörrie | ad587c3 | 2021-03-11 14:09:27 | [diff] [blame] | 9 | #include <string> |
Melissa Zhang | db4dffa | 2020-07-01 04:03:11 | [diff] [blame] | 10 | |
Melissa Zhang | 12f6a07 | 2020-09-30 21:16:07 | [diff] [blame] | 11 | #include "base/callback.h" |
Melissa Zhang | 93826e69 | 2020-07-14 04:39:02 | [diff] [blame] | 12 | #include "chrome/browser/sharesheet/sharesheet_controller.h" |
Melissa Zhang | b330e5ab8 | 2020-07-21 05:51:36 | [diff] [blame] | 13 | #include "chrome/browser/sharesheet/sharesheet_types.h" |
Melissa Zhang | 59ca374f | 2020-07-22 05:55:51 | [diff] [blame] | 14 | #include "components/services/app_service/public/mojom/types.mojom.h" |
Melissa Zhang | c6105cc | 2021-03-16 05:19:43 | [diff] [blame^] | 15 | #include "ui/base/accelerators/accelerator.h" |
Melissa Zhang | 26c1693 | 2020-12-11 05:15:23 | [diff] [blame] | 16 | #include "ui/gfx/native_widget_types.h" |
Melissa Zhang | db4dffa | 2020-07-01 04:03:11 | [diff] [blame] | 17 | |
Melissa Zhang | 575490a | 2020-08-31 07:14:40 | [diff] [blame] | 18 | class Profile; |
Melissa Zhang | 93826e69 | 2020-07-14 04:39:02 | [diff] [blame] | 19 | class SharesheetBubbleView; |
Melissa Zhang | db4dffa | 2020-07-01 04:03:11 | [diff] [blame] | 20 | |
| 21 | namespace views { |
| 22 | class View; |
| 23 | } |
| 24 | |
Melissa Zhang | a8a835f | 2020-11-05 05:02:46 | [diff] [blame] | 25 | namespace gfx { |
| 26 | struct VectorIcon; |
| 27 | } |
| 28 | |
Melissa Zhang | db4dffa | 2020-07-01 04:03:11 | [diff] [blame] | 29 | namespace sharesheet { |
| 30 | |
| 31 | class SharesheetService; |
| 32 | |
Melissa Zhang | 93826e69 | 2020-07-14 04:39:02 | [diff] [blame] | 33 | // The SharesheetServiceDelegate is the middle point between the UI and the |
| 34 | // business logic in the sharesheet. |
| 35 | class SharesheetServiceDelegate : public SharesheetController { |
Melissa Zhang | db4dffa | 2020-07-01 04:03:11 | [diff] [blame] | 36 | public: |
Melissa Zhang | 26c1693 | 2020-12-11 05:15:23 | [diff] [blame] | 37 | SharesheetServiceDelegate(gfx::NativeWindow native_window, |
Maggie Cai | 6930533 | 2020-08-04 23:28:26 | [diff] [blame] | 38 | SharesheetService* sharesheet_service); |
Melissa Zhang | 93826e69 | 2020-07-14 04:39:02 | [diff] [blame] | 39 | ~SharesheetServiceDelegate() override; |
Melissa Zhang | db4dffa | 2020-07-01 04:03:11 | [diff] [blame] | 40 | SharesheetServiceDelegate(const SharesheetServiceDelegate&) = delete; |
| 41 | SharesheetServiceDelegate& operator=(const SharesheetServiceDelegate&) = |
| 42 | delete; |
| 43 | |
Melissa Zhang | 59ca374f | 2020-07-22 05:55:51 | [diff] [blame] | 44 | void ShowBubble(std::vector<TargetInfo> targets, |
Melissa Zhang | 12f6a07 | 2020-09-30 21:16:07 | [diff] [blame] | 45 | apps::mojom::IntentPtr intent, |
| 46 | sharesheet::CloseCallback close_callback); |
Jan Wilken Dörrie | dec9912 | 2021-03-11 18:02:30 | [diff] [blame] | 47 | void OnBubbleClosed(const std::u16string& active_action); |
| 48 | void OnTargetSelected(const std::u16string& target_name, |
Melissa Zhang | f55c750 | 2020-07-21 12:36:05 | [diff] [blame] | 49 | const TargetType type, |
Melissa Zhang | 59ca374f | 2020-07-22 05:55:51 | [diff] [blame] | 50 | apps::mojom::IntentPtr intent, |
Melissa Zhang | f55c750 | 2020-07-21 12:36:05 | [diff] [blame] | 51 | views::View* share_action_view); |
Melissa Zhang | c6105cc | 2021-03-16 05:19:43 | [diff] [blame^] | 52 | bool OnAcceleratorPressed(const ui::Accelerator& accelerator, |
| 53 | const std::u16string& active_action); |
Melissa Zhang | f55c750 | 2020-07-21 12:36:05 | [diff] [blame] | 54 | void OnActionLaunched(); |
Jan Wilken Dörrie | dec9912 | 2021-03-11 18:02:30 | [diff] [blame] | 55 | const gfx::VectorIcon* GetVectorIcon(const std::u16string& display_name); |
Melissa Zhang | 26c1693 | 2020-12-11 05:15:23 | [diff] [blame] | 56 | gfx::NativeWindow GetNativeWindow(); |
Melissa Zhang | 93826e69 | 2020-07-14 04:39:02 | [diff] [blame] | 57 | |
| 58 | // SharesheetController overrides |
Melissa Zhang | 575490a | 2020-08-31 07:14:40 | [diff] [blame] | 59 | Profile* GetProfile() override; |
Melissa Zhang | 0f75f3b | 2020-08-19 05:24:26 | [diff] [blame] | 60 | void SetSharesheetSize(const int& width, const int& height) override; |
Melissa Zhang | d1a8ba9 | 2020-08-07 00:32:49 | [diff] [blame] | 61 | void CloseSharesheet() override; |
Melissa Zhang | db4dffa | 2020-07-01 04:03:11 | [diff] [blame] | 62 | |
| 63 | private: |
Melissa Zhang | 26c1693 | 2020-12-11 05:15:23 | [diff] [blame] | 64 | bool is_bubble_open_ = false; |
| 65 | |
| 66 | // Only used for ID purposes. NativeWindow will always outlive the |
| 67 | // SharesheetServiceDelegate. |
| 68 | gfx::NativeWindow native_window_; |
| 69 | |
Jan Wilken Dörrie | dec9912 | 2021-03-11 18:02:30 | [diff] [blame] | 70 | std::u16string active_action_; |
Melissa Zhang | db4dffa | 2020-07-01 04:03:11 | [diff] [blame] | 71 | std::unique_ptr<SharesheetBubbleView> sharesheet_bubble_view_; |
Melissa Zhang | 93826e69 | 2020-07-14 04:39:02 | [diff] [blame] | 72 | SharesheetService* sharesheet_service_; |
Melissa Zhang | db4dffa | 2020-07-01 04:03:11 | [diff] [blame] | 73 | }; |
| 74 | |
| 75 | } // namespace sharesheet |
| 76 | |
| 77 | #endif // CHROME_BROWSER_SHARESHEET_SHARESHEET_SERVICE_DELEGATE_H_ |