Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 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_INTENTS_WEB_INTENT_PICKER_MODEL_H_ | |
| 6 #define CHROME_BROWSER_UI_INTENTS_WEB_INTENT_PICKER_MODEL_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/string16.h" | |
| 12 #include "base/memory/scoped_ptr.h" | |
| 13 #include "googleurl/src/gurl.h" | |
| 14 | |
| 15 class WebIntentPickerModelObserver; | |
| 16 | |
| 17 namespace gfx { | |
| 18 class Image; | |
| 19 } | |
| 20 | |
| 21 // Model for the WebIntentPicker. | |
| 22 class WebIntentPickerModel { | |
| 23 public: | |
| 24 // The intent service disposition. | |
| 25 enum Disposition { | |
| 26 DISPOSITION_WINDOW, // Display the intent service in a new window. | |
| 27 DISPOSITION_INLINE, // Display the intent service in the picker. | |
| 28 }; | |
| 29 | |
| 30 // An intent service to display in the picker. | |
| 31 struct Item { | |
| 32 Item(const string16& title, const GURL& url, Disposition disposition); | |
| 33 ~Item(); | |
| 34 | |
| 35 // The title of this service. | |
| 36 string16 title; | |
| 37 | |
| 38 // The URL of this service. | |
| 39 GURL url; | |
| 40 | |
| 41 // A favicon of this service, or NULL if the default favicon should be | |
| 42 // used. | |
| 43 scoped_ptr<gfx::Image> favicon; | |
| 44 | |
| 45 // The disposition to use when displaying this service. | |
| 46 Disposition disposition; | |
| 47 | |
| 48 DISALLOW_COPY_AND_ASSIGN(Item); | |
|
groby-ooo-7-16
2012/01/25 22:03:13
This macro only works in private: section
binji
2012/01/26 00:27:41
Done.
| |
| 49 }; | |
| 50 | |
| 51 WebIntentPickerModel(); | |
| 52 ~WebIntentPickerModel(); | |
| 53 | |
| 54 void set_observer(WebIntentPickerModelObserver* observer) { | |
| 55 observer_ = observer; | |
| 56 } | |
| 57 | |
| 58 // Add a new item with |title|, |url| and |disposition| to the picker. | |
| 59 void AddItem(const string16& title, const GURL& url, Disposition disposition); | |
| 60 | |
| 61 // Remove an item from the picker at |index|. | |
| 62 void RemoveItemAt(size_t index); | |
| 63 | |
| 64 // Remove all items from the picker, and resets to not displaying inline | |
| 65 // disposition. Note that this does not clear the observer. | |
| 66 void Clear(); | |
| 67 | |
| 68 // Return the intent service item at |index|. | |
| 69 const Item& GetItemAt(size_t index) const; | |
| 70 | |
| 71 // Return the number of intent services in the picker. | |
| 72 size_t GetItemCount() const; | |
| 73 | |
| 74 // Update the favicon for the intent service at |index| to |image|. | |
| 75 void UpdateFaviconAt(size_t index, const gfx::Image& image); | |
| 76 | |
| 77 // Set the picker to display the intent service at |index| inline. | |
| 78 void SetInlineDisposition(size_t index); | |
| 79 | |
| 80 // Returns true if the picker is currently displaying an inline service. | |
| 81 bool IsInlineDisposition() const; | |
| 82 | |
| 83 // Returns the index of the intent service that is being displayed inline, or | |
| 84 // std::string::npos if none. | |
| 85 size_t inline_disposition_index() const { return inline_disposition_index_; } | |
|
groby-ooo-7-16
2012/01/25 22:03:13
That is an odd thing to have on the model - should
binji
2012/01/26 00:27:41
Maybe... I was thinking of the model as any necess
| |
| 86 | |
| 87 private: | |
| 88 // Delete all of |items_| and clear it. | |
| 89 void DestroyItems(); | |
| 90 | |
| 91 // A vector of all items in the picker. Each item is owned by this model. | |
| 92 std::vector<Item*> items_; | |
| 93 | |
| 94 // The observer to send notifications to, or NULL if none. | |
| 95 WebIntentPickerModelObserver* observer_; | |
|
groby-ooo-7-16
2012/01/25 22:03:13
The observer should probably be a WeakPtr<> - that
binji
2012/01/26 00:27:41
I don't see any examples of this.
| |
| 96 | |
| 97 // The index of the intent service that is being displayed inline, or | |
| 98 // std::string::npos if none. | |
| 99 size_t inline_disposition_index_; | |
| 100 | |
| 101 DISALLOW_COPY_AND_ASSIGN(WebIntentPickerModel); | |
| 102 }; | |
| 103 | |
| 104 #endif // CHROME_BROWSER_UI_INTENTS_WEB_INTENT_PICKER_MODEL_H_ | |
| OLD | NEW |