Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 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_UI_WEBSITE_SETTINGS_CHOOSER_BUBBLE_DELEGATE_H_ | |
| 6 #define CHROME_BROWSER_UI_WEBSITE_SETTINGS_CHOOSER_BUBBLE_DELEGATE_H_ | |
| 7 | |
| 8 #include <vector> | |
| 9 | |
| 10 #include "base/macros.h" | |
| 11 #include "base/strings/string16.h" | |
| 12 #include "components/bubble/bubble_delegate.h" | |
| 13 | |
| 14 // Subclass ChooserBubbleDelegate to implement a chooser bubble, which has | |
| 15 // some introductory text and a list of options that users can pick one of. | |
| 16 // Create an instance of your subclass and pass it to | |
| 17 // BubbleManager::ShowBubble() to show the bubble. Your subclass must define | |
| 18 // the set of options users can pick from; the actions taken after users | |
| 19 // select an item or press the 'Cancel' button or the bubble is closed. | |
| 20 // You can also override GetName() to xyz. | |
|
Jeffrey Yasskin
2015/12/08 20:19:09
You have to read the comments I suggest and make s
juncai
2015/12/08 20:59:02
Done.
| |
| 21 // After Select/Cancel/Close is called, this object is destroyed and call back | |
| 22 // into it is not allowed. | |
| 23 class ChooserBubbleDelegate : public BubbleDelegate { | |
| 24 public: | |
| 25 ChooserBubbleDelegate(); | |
| 26 ~ChooserBubbleDelegate() override; | |
| 27 | |
| 28 // Since the set of options can change while the UI is visible an | |
| 29 // implementation should register an observer. | |
| 30 class Observer { | |
| 31 public: | |
| 32 // Called after the options list is initialized for the first time. | |
| 33 // OnOptionsInitialized should only be called once. | |
| 34 virtual void OnOptionsInitialized() = 0; | |
| 35 // Called after GetOptions()[index] has been added to the options and the | |
| 36 // newly added option is the last element in the options list. Calling | |
| 37 // GetOptions()[index] from inside a call to OnOptionAdded will see the | |
| 38 // added string since the options have already been updated. | |
| 39 virtual void OnOptionAdded(int index) = 0; | |
| 40 // Called when GetOptions()[index] is no longer present, and all later | |
| 41 // options have been moved earlier by 1 slot. Calling GetOptions()[index] | |
| 42 // from inside a call to OnOptionRemoved will NOT see the removed string | |
| 43 // since the options have already been updated. | |
| 44 virtual void OnOptionRemoved(int index) = 0; | |
| 45 | |
| 46 protected: | |
| 47 virtual ~Observer() {} | |
| 48 }; | |
| 49 | |
| 50 // BubbleDelegate: | |
| 51 std::string GetName() const override; | |
| 52 | |
| 53 // The set of options users can pick from. For example, it can be | |
| 54 // USB/Bluetooth devices names which are listed in the chooser bubble | |
| 55 // so that users can grant permission. | |
| 56 virtual const std::vector<base::string16>& GetOptions() const = 0; | |
| 57 | |
| 58 // These three functions are called just before this object is destroyed: | |
| 59 // Called when the user selects the |index|th element from the dialog. | |
| 60 virtual void Select(int index) = 0; | |
| 61 // Called when the user presses the 'Cancel' button in the dialog. | |
| 62 virtual void Cancel() = 0; | |
| 63 // Called when the user clicks outside the dialog or the dialog otherwise | |
| 64 // closes without the user taking an explicit action. | |
| 65 virtual void Close() = 0; | |
| 66 | |
| 67 // Only one observer may be registered at a time. | |
| 68 void set_observer(Observer* observer) { observer_ = observer; } | |
| 69 Observer* observer() const { return observer_; } | |
| 70 | |
| 71 private: | |
| 72 Observer* observer_ = nullptr; | |
| 73 | |
| 74 DISALLOW_COPY_AND_ASSIGN(ChooserBubbleDelegate); | |
| 75 }; | |
| 76 | |
| 77 #endif // CHROME_BROWSER_UI_WEBSITE_SETTINGS_CHOOSER_BUBBLE_DELEGATE_H_ | |
| OLD | NEW |