Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_CHOOSER_CONTROLLER_CHOOSER_CONTROLLER_H_ | 5 #ifndef CHROME_BROWSER_CHOOSER_CONTROLLER_CHOOSER_CONTROLLER_H_ |
| 6 #define CHROME_BROWSER_CHOOSER_CONTROLLER_CHOOSER_CONTROLLER_H_ | 6 #define CHROME_BROWSER_CHOOSER_CONTROLLER_CHOOSER_CONTROLLER_H_ |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
| 10 | 10 |
| 11 namespace content { | 11 namespace content { |
| 12 class RenderFrameHost; | 12 class RenderFrameHost; |
| 13 } | 13 } |
| 14 | 14 |
| 15 // Subclass ChooserController to implement a chooser, which has some | 15 // Subclass ChooserController to implement a chooser, which has some |
| 16 // introductory text and a list of options that users can pick one of. | 16 // introductory text and a list of options that users can pick one of. |
| 17 // Your subclass must define the set of options users can pick from; | 17 // Your subclass must define the set of options users can pick from; |
| 18 // the actions taken after users select an item or press the 'Cancel' | 18 // the actions taken after users select an item or press the 'Cancel' |
| 19 // button or the chooser is closed. | 19 // button or the chooser is closed. |
| 20 // After Select/Cancel/Close is called, this object is destroyed and | 20 // After Select/Cancel/Close is called, this object is destroyed and |
| 21 // calls back into it are not allowed. | 21 // calls back into it are not allowed. |
| 22 class ChooserController { | 22 class ChooserController { |
| 23 public: | 23 public: |
| 24 ChooserController(content::RenderFrameHost* owner, | 24 ChooserController(content::RenderFrameHost* owner, |
| 25 int title_string_id_origin, | 25 int title_string_id_origin, |
| 26 int title_string_id_extension); | 26 int title_string_id_extension); |
| 27 virtual ~ChooserController(); | 27 virtual ~ChooserController(); |
| 28 | 28 |
| 29 // Since the set of options can change while the UI is visible an | 29 // Since the set of options can change while the UI is visible an |
| 30 // implementation should register an observer. | 30 // implementation should register a view. |
|
msw
2016/07/20 20:37:07
nit: "a view to observe changes"
juncai
2016/07/20 22:37:45
Done.
| |
| 31 class Observer { | 31 class View { |
| 32 public: | 32 public: |
| 33 // Called after the options list is initialized for the first time. | 33 // Called after the options list is initialized for the first time. |
| 34 // OnOptionsInitialized should only be called once. | 34 // OnOptionsInitialized should only be called once. |
| 35 virtual void OnOptionsInitialized() = 0; | 35 virtual void OnOptionsInitialized() = 0; |
| 36 | 36 |
| 37 // Called after GetOption(index) has been added to the options and the | 37 // Called after GetOption(index) has been added to the options and the |
| 38 // newly added option is the last element in the options list. Calling | 38 // newly added option is the last element in the options list. Calling |
| 39 // GetOption(index) from inside a call to OnOptionAdded will see the | 39 // GetOption(index) from inside a call to OnOptionAdded will see the |
| 40 // added string since the options have already been updated. | 40 // added string since the options have already been updated. |
| 41 virtual void OnOptionAdded(size_t index) = 0; | 41 virtual void OnOptionAdded(size_t index) = 0; |
| 42 | 42 |
| 43 // Called when GetOption(index) is no longer present, and all later | 43 // Called when GetOption(index) is no longer present, and all later |
| 44 // options have been moved earlier by 1 slot. Calling GetOption(index) | 44 // options have been moved earlier by 1 slot. Calling GetOption(index) |
| 45 // from inside a call to OnOptionRemoved will NOT see the removed string | 45 // from inside a call to OnOptionRemoved will NOT see the removed string |
| 46 // since the options have already been updated. | 46 // since the options have already been updated. |
| 47 virtual void OnOptionRemoved(size_t index) = 0; | 47 virtual void OnOptionRemoved(size_t index) = 0; |
| 48 | 48 |
| 49 // Called when the device adapter is turned on or off. | 49 // Called when the device adapter is turned on or off. |
| 50 virtual void OnAdapterEnabledChanged(bool enabled) = 0; | 50 virtual void OnAdapterEnabledChanged(bool enabled) = 0; |
| 51 | 51 |
| 52 // Called when refreshing options is in progress or complete. | 52 // Called when refreshing options is in progress or complete. |
| 53 virtual void OnRefreshStateChanged(bool refreshing) = 0; | 53 virtual void OnRefreshStateChanged(bool refreshing) = 0; |
| 54 | 54 |
| 55 protected: | 55 protected: |
| 56 virtual ~Observer() {} | 56 virtual ~View() {} |
| 57 }; | 57 }; |
| 58 | 58 |
| 59 // Returns the text to be displayed in the chooser title. | 59 // Returns the text to be displayed in the chooser title. |
| 60 base::string16 GetTitle() const; | 60 base::string16 GetTitle() const; |
| 61 | 61 |
| 62 // Returns the text to be displayed in the chooser when there are no options. | 62 // Returns the text to be displayed in the chooser when there are no options. |
| 63 virtual base::string16 GetNoOptionsText() const = 0; | 63 virtual base::string16 GetNoOptionsText() const = 0; |
| 64 | 64 |
| 65 // Returns the label for OK button. | 65 // Returns the label for OK button. |
| 66 virtual base::string16 GetOkButtonLabel() const = 0; | 66 virtual base::string16 GetOkButtonLabel() const = 0; |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 87 // Called when the user presses the 'Cancel' button in the dialog. | 87 // Called when the user presses the 'Cancel' button in the dialog. |
| 88 virtual void Cancel() = 0; | 88 virtual void Cancel() = 0; |
| 89 | 89 |
| 90 // Called when the user clicks outside the dialog or the dialog otherwise | 90 // Called when the user clicks outside the dialog or the dialog otherwise |
| 91 // closes without the user taking an explicit action. | 91 // closes without the user taking an explicit action. |
| 92 virtual void Close() = 0; | 92 virtual void Close() = 0; |
| 93 | 93 |
| 94 // Open help center URL. | 94 // Open help center URL. |
| 95 virtual void OpenHelpCenterUrl() const = 0; | 95 virtual void OpenHelpCenterUrl() const = 0; |
| 96 | 96 |
| 97 // Only one observer may be registered at a time. | 97 // Only one view may be registered at a time. |
| 98 void set_observer(Observer* observer) { observer_ = observer; } | 98 void set_view(View* view) { view_ = view; } |
| 99 Observer* observer() const { return observer_; } | 99 View* view() const { return view_; } |
| 100 | 100 |
| 101 private: | 101 private: |
| 102 content::RenderFrameHost* const owning_frame_; | 102 content::RenderFrameHost* const owning_frame_; |
| 103 const int title_string_id_origin_; | 103 const int title_string_id_origin_; |
| 104 const int title_string_id_extension_; | 104 const int title_string_id_extension_; |
| 105 Observer* observer_ = nullptr; | 105 View* view_ = nullptr; |
| 106 | 106 |
| 107 DISALLOW_COPY_AND_ASSIGN(ChooserController); | 107 DISALLOW_COPY_AND_ASSIGN(ChooserController); |
| 108 }; | 108 }; |
| 109 | 109 |
| 110 #endif // CHROME_BROWSER_CHOOSER_CONTROLLER_CHOOSER_CONTROLLER_H_ | 110 #endif // CHROME_BROWSER_CHOOSER_CONTROLLER_CHOOSER_CONTROLLER_H_ |
| OLD | NEW |