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