Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(578)

Side by Side Diff: chrome/browser/search_engines/template_url_table_model.h

Issue 146138: Refactor the win KeywordEditorView for cross platform friendliness. (Closed)
Patch Set: '' Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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_VIEWS_KEYWORD_EDITOR_VIEW_H_ 5 #ifndef CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_TABLE_MODEL_H_
6 #define CHROME_BROWSER_VIEWS_KEYWORD_EDITOR_VIEW_H_ 6 #define CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_TABLE_MODEL_H_
7
8 #include <Windows.h>
9 #include <map>
10 7
11 #include "app/table_model.h" 8 #include "app/table_model.h"
12 #include "chrome/browser/search_engines/edit_search_engine_controller.h"
13 #include "chrome/browser/search_engines/template_url_model.h" 9 #include "chrome/browser/search_engines/template_url_model.h"
14 #include "views/controls/button/button.h"
15 #include "views/controls/table/table_view_observer.h"
16 #include "views/view.h"
17 #include "views/window/dialog_delegate.h"
18
19 namespace views {
20 class Label;
21 class NativeButton;
22 }
23
24 namespace {
25 class BorderView;
26 }
27 10
28 class ModelEntry; 11 class ModelEntry;
29 class SkBitmap; 12 class SkBitmap;
13 class TemplateURL;
30 class TemplateURLModel; 14 class TemplateURLModel;
31 class TemplateURLTableModel; 15 class TemplateURLTableModel;
32 16
33 // TemplateURLTableModel is the TableModel implementation used by 17 // TemplateURLTableModel is the TableModel implementation used by
34 // KeywordEditorView to show the keywords in a TableView. 18 // KeywordEditorView to show the keywords in a TableView.
35 // 19 //
36 // TemplateURLTableModel has two columns, the first showing the description, 20 // TemplateURLTableModel has two columns, the first showing the description,
37 // the second the keyword. 21 // the second the keyword.
38 // 22 //
39 // TemplateURLTableModel maintains a vector of ModelEntrys that correspond to 23 // TemplateURLTableModel maintains a vector of ModelEntrys that correspond to
40 // each row in the tableview. Each ModelEntry wraps a TemplateURL, providing 24 // each row in the tableview. Each ModelEntry wraps a TemplateURL, providing
41 // the favicon. The entries in the model are sorted such that non-generated 25 // the favicon. The entries in the model are sorted such that non-generated
42 // appear first (grouped together) and are followed by generated keywords. 26 // appear first (grouped together) and are followed by generated keywords.
43 27
44 class TemplateURLTableModel : public TableModel { 28 class TemplateURLTableModel : public TableModel,
29 TemplateURLModelObserver {
45 public: 30 public:
46 explicit TemplateURLTableModel(TemplateURLModel* template_url_model); 31 explicit TemplateURLTableModel(TemplateURLModel* template_url_model);
47 32
48 virtual ~TemplateURLTableModel(); 33 virtual ~TemplateURLTableModel();
49 34
50 // Reloads the entries from the TemplateURLModel. This should ONLY be invoked 35 // Reloads the entries from the TemplateURLModel. This should ONLY be invoked
51 // if the TemplateURLModel wasn't initially loaded and has been loaded. 36 // if the TemplateURLModel wasn't initially loaded and has been loaded.
52 void Reload(); 37 void Reload();
53 38
54 // TableModel overrides. 39 // TableModel overrides.
55 virtual int RowCount(); 40 virtual int RowCount();
56 virtual std::wstring GetText(int row, int column); 41 virtual std::wstring GetText(int row, int column);
57 virtual SkBitmap GetIcon(int row); 42 virtual SkBitmap GetIcon(int row);
58 virtual void SetObserver(TableModelObserver* observer); 43 virtual void SetObserver(TableModelObserver* observer);
59 virtual bool HasGroups(); 44 virtual bool HasGroups();
60 virtual Groups GetGroups(); 45 virtual Groups GetGroups();
61 virtual int GetGroupID(int row); 46 virtual int GetGroupID(int row);
62 47
63 // Removes the entry at the specified index. This does NOT propagate the 48 // Removes the entry at the specified index.
64 // change to the backend.
65 void Remove(int index); 49 void Remove(int index);
66 50
67 // Adds a new entry at the specified index. This does not propagate the 51 // Adds a new entry at the specified index.
68 // change to the backend. 52 void Add(int index, TemplateURL* template_url);
69 void Add(int index, const TemplateURL* template_url); 53
54 // Update the entry at the specified index.
55 void ModifyTemplateURL(int index, const std::wstring& title,
56 const std::wstring& keyword, const std::wstring& url);
70 57
71 // Reloads the icon at the specified index. 58 // Reloads the icon at the specified index.
72 void ReloadIcon(int index); 59 void ReloadIcon(int index);
73 60
74 // Returns The TemplateURL at the specified index. 61 // Returns The TemplateURL at the specified index.
75 const TemplateURL& GetTemplateURL(int index); 62 const TemplateURL& GetTemplateURL(int index);
76 63
77 // Returns the index of the TemplateURL, or -1 if it the TemplateURL is not 64 // Returns the index of the TemplateURL, or -1 if it the TemplateURL is not
78 // found. 65 // found.
79 int IndexOfTemplateURL(const TemplateURL* template_url); 66 int IndexOfTemplateURL(const TemplateURL* template_url);
80 67
81 // Moves the keyword at the specified index to be at the end of the main 68 // Moves the keyword at the specified index to be at the end of the main
82 // group. Returns the new index. This does nothing if the entry is already 69 // group. Returns the new index. This does nothing if the entry is already
83 // in the main group. 70 // in the main group.
84 void MoveToMainGroup(int index); 71 int MoveToMainGroup(int index);
72
73 // Make the TemplateURL at |index| the default. Returns the new index, or -1
74 // if the index is invalid or it is already the default.
75 int MakeDefaultTemplateURL(int index);
85 76
86 // If there is an observer, it's notified the selected row has changed. 77 // If there is an observer, it's notified the selected row has changed.
87 void NotifyChanged(int index); 78 void NotifyChanged(int index);
88 79
89 TemplateURLModel* template_url_model() const { return template_url_model_; } 80 TemplateURLModel* template_url_model() const { return template_url_model_; }
90 81
91 // Returns the index of the last entry shown in the search engines group. 82 // Returns the index of the last entry shown in the search engines group.
92 int last_search_engine_index() const { return last_search_engine_index_; } 83 int last_search_engine_index() const { return last_search_engine_index_; }
93 84
94 private: 85 private:
95 friend class ModelEntry; 86 friend class ModelEntry;
96 87
97 // Notification that a model entry has fetched its icon. 88 // Notification that a model entry has fetched its icon.
98 void FavIconAvailable(ModelEntry* entry); 89 void FavIconAvailable(ModelEntry* entry);
99 90
91 // TemplateURLModelObserver notification.
92 virtual void OnTemplateURLModelChanged();
93
100 TableModelObserver* observer_; 94 TableModelObserver* observer_;
101 95
102 // The entries. 96 // The entries.
103 std::vector<ModelEntry*> entries_; 97 std::vector<ModelEntry*> entries_;
104 98
105 // The model we're displaying entries from. 99 // The model we're displaying entries from.
106 TemplateURLModel* template_url_model_; 100 TemplateURLModel* template_url_model_;
107 101
108 // Index of the last search engine in entries_. This is used to determine the 102 // Index of the last search engine in entries_. This is used to determine the
109 // group boundaries. 103 // group boundaries.
110 int last_search_engine_index_; 104 int last_search_engine_index_;
111 105
112 DISALLOW_EVIL_CONSTRUCTORS(TemplateURLTableModel); 106 DISALLOW_EVIL_CONSTRUCTORS(TemplateURLTableModel);
113 }; 107 };
114 108
115 // KeywordEditorView ----------------------------------------------------------
116 109
117 // KeywordEditorView allows the user to edit keywords. 110 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_TABLE_MODEL_H_
118
119 class KeywordEditorView : public views::View,
120 public views::TableViewObserver,
121 public views::ButtonListener,
122 public TemplateURLModelObserver,
123 public views::DialogDelegate,
124 public EditSearchEngineControllerDelegate {
125 friend class KeywordEditorViewTest;
126 FRIEND_TEST(KeywordEditorViewTest, MakeDefault);
127 public:
128 // Shows the KeywordEditorView for the specified profile. If there is a
129 // KeywordEditorView already open, it is closed and a new one is shown.
130 static void Show(Profile* profile);
131
132 explicit KeywordEditorView(Profile* profile);
133 virtual ~KeywordEditorView();
134
135 // Overridden from EditSearchEngineControllerDelegate.
136 // Calls AddTemplateURL or ModifyTemplateURL as appropriate.
137 virtual void OnEditedKeyword(const TemplateURL* template_url,
138 const std::wstring& title,
139 const std::wstring& keyword,
140 const std::wstring& url);
141
142 // Invoked when the user succesfully fills out the add keyword dialog.
143 // Propagates the change to the TemplateURLModel and updates the table model.
144 void AddTemplateURL(const std::wstring& title,
145 const std::wstring& keyword,
146 const std::wstring& url);
147
148 // Invoked when the user modifies a TemplateURL. Updates the TemplateURLModel
149 // and table model appropriately.
150 void ModifyTemplateURL(const TemplateURL* template_url,
151 const std::wstring& title,
152 const std::wstring& keyword,
153 const std::wstring& url);
154
155 // Overriden to invoke Layout.
156 virtual gfx::Size GetPreferredSize();
157
158 // DialogDelegate methods:
159 virtual bool CanResize() const;
160 virtual std::wstring GetWindowTitle() const;
161 virtual int GetDialogButtons() const;
162 virtual bool Accept();
163 virtual bool Cancel();
164 virtual views::View* GetContentsView();
165
166 // Returns the TemplateURLModel we're using.
167 TemplateURLModel* template_url_model() const { return url_model_; }
168
169 private:
170 void Init();
171
172 // Creates the layout and adds the views to it.
173 void InitLayoutManager();
174
175 // TableViewObserver method. Updates buttons contingent on the selection.
176 virtual void OnSelectionChanged();
177 // Edits the selected item.
178 virtual void OnDoubleClick();
179
180 // Button::ButtonListener method.
181 virtual void ButtonPressed(views::Button* sender);
182
183 // TemplateURLModelObserver notification.
184 virtual void OnTemplateURLModelChanged();
185
186 // Toggles whether the selected keyword is the default search provider.
187 void MakeDefaultSearchProvider();
188
189 // Make the TemplateURL at the specified index (into the TableModel) the
190 // default search provider.
191 void MakeDefaultSearchProvider(int index);
192
193 // The profile.
194 Profile* profile_;
195
196 // Model containing TemplateURLs. We listen for changes on this and propagate
197 // them to the table model.
198 TemplateURLModel* url_model_;
199
200 // Model for the TableView.
201 scoped_ptr<TemplateURLTableModel> table_model_;
202
203 // All the views are added as children, so that we don't need to delete
204 // them directly.
205 views::TableView* table_view_;
206 views::NativeButton* add_button_;
207 views::NativeButton* edit_button_;
208 views::NativeButton* remove_button_;
209 views::NativeButton* make_default_button_;
210
211 DISALLOW_COPY_AND_ASSIGN(KeywordEditorView);
212 };
213
214 #endif // CHROME_BROWSER_VIEWS_KEYWORD_EDITOR_VIEW_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698