OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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_UI_WEBSITE_SETTINGS_CHOOSER_BUBBLE_DELEGATE_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBSITE_SETTINGS_CHOOSER_BUBBLE_DELEGATE_H_ |
6 #define CHROME_BROWSER_UI_WEBSITE_SETTINGS_CHOOSER_BUBBLE_DELEGATE_H_ | 6 #define CHROME_BROWSER_UI_WEBSITE_SETTINGS_CHOOSER_BUBBLE_DELEGATE_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 explicit ChooserBubbleDelegate(Browser* browser); | 28 explicit ChooserBubbleDelegate(Browser* browser); |
29 ~ChooserBubbleDelegate() override; | 29 ~ChooserBubbleDelegate() override; |
30 | 30 |
31 // Since the set of options can change while the UI is visible an | 31 // Since the set of options can change while the UI is visible an |
32 // implementation should register an observer. | 32 // implementation should register an observer. |
33 class Observer { | 33 class Observer { |
34 public: | 34 public: |
35 // Called after the options list is initialized for the first time. | 35 // Called after the options list is initialized for the first time. |
36 // OnOptionsInitialized should only be called once. | 36 // OnOptionsInitialized should only be called once. |
37 virtual void OnOptionsInitialized() = 0; | 37 virtual void OnOptionsInitialized() = 0; |
38 // Called after GetOptions()[index] has been added to the options and the | 38 |
| 39 // Called after GetOption(index) has been added to the options and the |
39 // newly added option is the last element in the options list. Calling | 40 // 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 // GetOption(index) from inside a call to OnOptionAdded will see the |
41 // added string since the options have already been updated. | 42 // added string since the options have already been updated. |
42 virtual void OnOptionAdded(int index) = 0; | 43 virtual void OnOptionAdded(size_t index) = 0; |
43 // Called when GetOptions()[index] is no longer present, and all later | 44 |
44 // options have been moved earlier by 1 slot. Calling GetOptions()[index] | 45 // Called when GetOption(index) is no longer present, and all later |
| 46 // options have been moved earlier by 1 slot. Calling GetOption(index) |
45 // from inside a call to OnOptionRemoved will NOT see the removed string | 47 // from inside a call to OnOptionRemoved will NOT see the removed string |
46 // since the options have already been updated. | 48 // since the options have already been updated. |
47 virtual void OnOptionRemoved(int index) = 0; | 49 virtual void OnOptionRemoved(size_t index) = 0; |
48 | 50 |
49 protected: | 51 protected: |
50 virtual ~Observer() {} | 52 virtual ~Observer() {} |
51 }; | 53 }; |
52 | 54 |
53 // BubbleDelegate: | 55 // BubbleDelegate: |
54 std::string GetName() const override; | 56 std::string GetName() const override; |
55 scoped_ptr<BubbleUi> BuildBubbleUi() override; | 57 scoped_ptr<BubbleUi> BuildBubbleUi() override; |
56 | 58 |
57 // The set of options users can pick from. For example, it can be | 59 // The number of options users can pick from. For example, it can be |
58 // USB/Bluetooth devices names which are listed in the chooser bubble | 60 // the number of USB/Bluetooth device names which are listed in the |
59 // so that users can grant permission. | 61 // chooser bubble so that users can grant permission. |
60 virtual const std::vector<base::string16>& GetOptions() const = 0; | 62 virtual size_t NumOptions() const = 0; |
| 63 |
| 64 // The |index|th option string which is listed in the chooser bubble. |
| 65 virtual const base::string16& GetOption(size_t index) const = 0; |
61 | 66 |
62 // These three functions are called just before this object is destroyed: | 67 // These three functions are called just before this object is destroyed: |
| 68 |
63 // Called when the user selects the |index|th element from the dialog. | 69 // Called when the user selects the |index|th element from the dialog. |
64 virtual void Select(int index) = 0; | 70 virtual void Select(size_t index) = 0; |
| 71 |
65 // Called when the user presses the 'Cancel' button in the dialog. | 72 // Called when the user presses the 'Cancel' button in the dialog. |
66 virtual void Cancel() = 0; | 73 virtual void Cancel() = 0; |
| 74 |
67 // Called when the user clicks outside the dialog or the dialog otherwise | 75 // Called when the user clicks outside the dialog or the dialog otherwise |
68 // closes without the user taking an explicit action. | 76 // closes without the user taking an explicit action. |
69 virtual void Close() = 0; | 77 virtual void Close() = 0; |
70 | 78 |
71 // Only one observer may be registered at a time. | 79 // Only one observer may be registered at a time. |
72 void set_observer(Observer* observer) { observer_ = observer; } | 80 void set_observer(Observer* observer) { observer_ = observer; } |
73 Observer* observer() const { return observer_; } | 81 Observer* observer() const { return observer_; } |
74 | 82 |
75 private: | 83 private: |
76 Browser* browser_; | 84 Browser* browser_; |
77 Observer* observer_ = nullptr; | 85 Observer* observer_ = nullptr; |
78 | 86 |
79 DISALLOW_COPY_AND_ASSIGN(ChooserBubbleDelegate); | 87 DISALLOW_COPY_AND_ASSIGN(ChooserBubbleDelegate); |
80 }; | 88 }; |
81 | 89 |
82 #endif // CHROME_BROWSER_UI_WEBSITE_SETTINGS_CHOOSER_BUBBLE_DELEGATE_H_ | 90 #endif // CHROME_BROWSER_UI_WEBSITE_SETTINGS_CHOOSER_BUBBLE_DELEGATE_H_ |
OLD | NEW |