juncai | bf183dd | 2016-05-27 16:57:24 | [diff] [blame] | 1 | // Copyright 2016 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 | |
juncai | badc1daa | 2016-07-11 20:36:54 | [diff] [blame] | 5 | #ifndef CHROME_BROWSER_CHOOSER_CONTROLLER_CHOOSER_CONTROLLER_H_ |
| 6 | #define CHROME_BROWSER_CHOOSER_CONTROLLER_CHOOSER_CONTROLLER_H_ |
juncai | bf183dd | 2016-05-27 16:57:24 | [diff] [blame] | 7 | |
juncai | 0f6d279 | 2016-11-23 18:38:07 | [diff] [blame] | 8 | #include <vector> |
| 9 | |
juncai | bf183dd | 2016-05-27 16:57:24 | [diff] [blame] | 10 | #include "base/macros.h" |
| 11 | #include "base/strings/string16.h" |
| 12 | |
| 13 | namespace content { |
| 14 | class RenderFrameHost; |
| 15 | } |
| 16 | |
juncai | bf183dd | 2016-05-27 16:57:24 | [diff] [blame] | 17 | // Subclass ChooserController to implement a chooser, which has some |
| 18 | // introductory text and a list of options that users can pick one of. |
| 19 | // Your subclass must define the set of options users can pick from; |
| 20 | // the actions taken after users select an item or press the 'Cancel' |
| 21 | // button or the chooser is closed. |
| 22 | // After Select/Cancel/Close is called, this object is destroyed and |
| 23 | // calls back into it are not allowed. |
| 24 | class ChooserController { |
| 25 | public: |
juncai | 6d9f773 | 2016-07-14 00:46:54 | [diff] [blame] | 26 | ChooserController(content::RenderFrameHost* owner, |
| 27 | int title_string_id_origin, |
| 28 | int title_string_id_extension); |
juncai | bf183dd | 2016-05-27 16:57:24 | [diff] [blame] | 29 | virtual ~ChooserController(); |
| 30 | |
| 31 | // Since the set of options can change while the UI is visible an |
juncai | 79673301 | 2016-07-20 22:30:46 | [diff] [blame] | 32 | // implementation should register a view to observe changes. |
| 33 | class View { |
juncai | bf183dd | 2016-05-27 16:57:24 | [diff] [blame] | 34 | public: |
| 35 | // Called after the options list is initialized for the first time. |
| 36 | // OnOptionsInitialized should only be called once. |
| 37 | virtual void OnOptionsInitialized() = 0; |
| 38 | |
| 39 | // Called after GetOption(index) has been added to the options and the |
| 40 | // newly added option is the last element in the options list. Calling |
| 41 | // GetOption(index) from inside a call to OnOptionAdded will see the |
| 42 | // added string since the options have already been updated. |
| 43 | virtual void OnOptionAdded(size_t index) = 0; |
| 44 | |
| 45 | // Called when GetOption(index) is no longer present, and all later |
| 46 | // options have been moved earlier by 1 slot. Calling GetOption(index) |
| 47 | // from inside a call to OnOptionRemoved will NOT see the removed string |
| 48 | // since the options have already been updated. |
| 49 | virtual void OnOptionRemoved(size_t index) = 0; |
| 50 | |
juncai | bb5ba230 | 2016-08-16 18:01:13 | [diff] [blame] | 51 | // Called when the option at |index| has been updated. |
| 52 | virtual void OnOptionUpdated(size_t index) = 0; |
| 53 | |
juncai | 9c9d751 | 2016-07-20 00:56:23 | [diff] [blame] | 54 | // Called when the device adapter is turned on or off. |
| 55 | virtual void OnAdapterEnabledChanged(bool enabled) = 0; |
| 56 | |
| 57 | // Called when refreshing options is in progress or complete. |
| 58 | virtual void OnRefreshStateChanged(bool refreshing) = 0; |
| 59 | |
juncai | bf183dd | 2016-05-27 16:57:24 | [diff] [blame] | 60 | protected: |
juncai | 79673301 | 2016-07-20 22:30:46 | [diff] [blame] | 61 | virtual ~View() {} |
juncai | bf183dd | 2016-05-27 16:57:24 | [diff] [blame] | 62 | }; |
| 63 | |
juncai | a29e116d | 2016-07-13 02:53:34 | [diff] [blame] | 64 | // Returns the text to be displayed in the chooser title. |
| 65 | base::string16 GetTitle() const; |
juncai | bf183dd | 2016-05-27 16:57:24 | [diff] [blame] | 66 | |
Bret Sepulveda | a4975e7a5e | 2017-12-18 23:16:38 | [diff] [blame^] | 67 | // Returns whether the chooser needs to show an icon before the text. |
juncai | 3ecef4e | 2016-08-23 00:10:16 | [diff] [blame] | 68 | // For WebBluetooth, it is a signal strength icon. |
| 69 | virtual bool ShouldShowIconBeforeText() const; |
| 70 | |
Bret Sepulveda | a4975e7a5e | 2017-12-18 23:16:38 | [diff] [blame^] | 71 | // Returns whether the chooser needs to show a help button. |
| 72 | virtual bool ShouldShowHelpButton() const; |
juncai | 4300362 | 2016-11-29 20:43:18 | [diff] [blame] | 73 | |
Bret Sepulveda | a4975e7a5e | 2017-12-18 23:16:38 | [diff] [blame^] | 74 | // Returns whether the chooser needs to show a button to re-scan for devices. |
| 75 | virtual bool ShouldShowReScanButton() const; |
| 76 | |
| 77 | // Returns whether the chooser allows multiple items to be selected. |
juncai | 0f6d279 | 2016-11-23 18:38:07 | [diff] [blame] | 78 | virtual bool AllowMultipleSelection() const; |
| 79 | |
juncai | 9c9d751 | 2016-07-20 00:56:23 | [diff] [blame] | 80 | // Returns the text to be displayed in the chooser when there are no options. |
| 81 | virtual base::string16 GetNoOptionsText() const = 0; |
| 82 | |
juncai | 3f5e325 | 2016-07-13 05:21:19 | [diff] [blame] | 83 | // Returns the label for OK button. |
| 84 | virtual base::string16 GetOkButtonLabel() const = 0; |
| 85 | |
juncai | bf183dd | 2016-05-27 16:57:24 | [diff] [blame] | 86 | // The number of options users can pick from. For example, it can be |
| 87 | // the number of USB/Bluetooth device names which are listed in the |
| 88 | // chooser so that users can grant permission. |
| 89 | virtual size_t NumOptions() const = 0; |
| 90 | |
juncai | 3ecef4e | 2016-08-23 00:10:16 | [diff] [blame] | 91 | // The signal strength level (0-4 inclusive) of the device at |index|, which |
| 92 | // is used to retrieve the corresponding icon to be displayed before the |
| 93 | // text. Returns -1 if no icon should be shown. |
| 94 | virtual int GetSignalStrengthLevel(size_t index) const; |
| 95 | |
juncai | bf183dd | 2016-05-27 16:57:24 | [diff] [blame] | 96 | // The |index|th option string which is listed in the chooser. |
juncai | 830ffff7 | 2016-07-01 21:27:28 | [diff] [blame] | 97 | virtual base::string16 GetOption(size_t index) const = 0; |
juncai | bf183dd | 2016-05-27 16:57:24 | [diff] [blame] |
|