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

Side by Side Diff: chrome/browser/views/keyword_editor_view.h

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

Powered by Google App Engine
This is Rietveld 408576698