OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 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_GTK_KEYWORD_EDITOR_VIEW_H_ |
| 6 #define CHROME_BROWSER_UI_GTK_KEYWORD_EDITOR_VIEW_H_ |
| 7 #pragma once |
| 8 |
| 9 #include <gtk/gtk.h> |
| 10 |
| 11 #include "app/table_model_observer.h" |
| 12 #include "base/basictypes.h" |
| 13 #include "base/gtest_prod_util.h" |
| 14 #include "base/scoped_ptr.h" |
| 15 #include "base/string16.h" |
| 16 #include "chrome/browser/search_engines/edit_search_engine_controller.h" |
| 17 #include "chrome/browser/search_engines/template_url_model_observer.h" |
| 18 |
| 19 class AccessibleWidgetHelper; |
| 20 class KeywordEditorController; |
| 21 class Profile; |
| 22 class TemplateURLTableModel; |
| 23 |
| 24 class KeywordEditorView : public TableModelObserver, |
| 25 public TemplateURLModelObserver, |
| 26 public EditSearchEngineControllerDelegate { |
| 27 public: |
| 28 virtual ~KeywordEditorView(); |
| 29 |
| 30 // Create (if necessary) and show the keyword editor window. |
| 31 static void Show(Profile* profile); |
| 32 |
| 33 // Overriden from EditSearchEngineControllerDelegate. |
| 34 virtual void OnEditedKeyword(const TemplateURL* template_url, |
| 35 const string16& title, |
| 36 const string16& keyword, |
| 37 const std::string& url); |
| 38 private: |
| 39 // Column ids for |list_store_|. |
| 40 enum { |
| 41 COL_FAVICON, |
| 42 COL_TITLE, |
| 43 COL_KEYWORD, |
| 44 COL_IS_HEADER, |
| 45 COL_IS_SEPARATOR, |
| 46 COL_WEIGHT, |
| 47 COL_WEIGHT_SET, |
| 48 COL_COUNT, |
| 49 }; |
| 50 |
| 51 explicit KeywordEditorView(Profile* profile); |
| 52 void Init(); |
| 53 |
| 54 // Enable buttons based on selection state. |
| 55 void EnableControls(); |
| 56 |
| 57 // Set the column values for |row| of |table_model_| in the |list_store_| at |
| 58 // |iter|. |
| 59 void SetColumnValues(int row, GtkTreeIter* iter); |
| 60 |
| 61 // Get the row number in the GtkListStore corresponding to |model_row|. |
| 62 int GetListStoreRowForModelRow(int model_row) const; |
| 63 |
| 64 // Get the row number in the TemplateURLTableModel corresponding to |path|. |
| 65 int GetModelRowForPath(GtkTreePath* path) const; |
| 66 |
| 67 // Get the row number in the TemplateURLTableModel corresponding to |iter|. |
| 68 int GetModelRowForIter(GtkTreeIter* iter) const; |
| 69 |
| 70 // Get the row number in the TemplateURLTableModel of the current selection, |
| 71 // or -1 if no row is selected. |
| 72 int GetSelectedModelRow() const; |
| 73 |
| 74 // Select the row in the |tree_| corresponding to |model_row|. |
| 75 void SelectModelRow(int model_row); |
| 76 |
| 77 // Add the values from |row| of |table_model_|. |
| 78 void AddNodeToList(int row); |
| 79 |
| 80 // TableModelObserver implementation. |
| 81 virtual void OnModelChanged(); |
| 82 virtual void OnItemsChanged(int start, int length); |
| 83 virtual void OnItemsAdded(int start, int length); |
| 84 virtual void OnItemsRemoved(int start, int length); |
| 85 |
| 86 // TemplateURLModelObserver notification. |
| 87 virtual void OnTemplateURLModelChanged(); |
| 88 |
| 89 // Callback for window destruction. |
| 90 static void OnWindowDestroy(GtkWidget* widget, KeywordEditorView* window); |
| 91 |
| 92 // Callback for dialog buttons. |
| 93 static void OnResponse(GtkDialog* dialog, int response_id, |
| 94 KeywordEditorView* window); |
| 95 |
| 96 // Callback checking whether a row should be drawn as a separator. |
| 97 static gboolean OnCheckRowIsSeparator(GtkTreeModel* model, |
| 98 GtkTreeIter* iter, |
| 99 gpointer user_data); |
| 100 |
| 101 // Callback checking whether a row may be selected. We use some rows in the |
| 102 // table as headers/separators for the groups, which should not be selectable. |
| 103 static gboolean OnSelectionFilter(GtkTreeSelection* selection, |
| 104 GtkTreeModel* model, |
| 105 GtkTreePath* path, |
| 106 gboolean path_currently_selected, |
| 107 gpointer user_data); |
| 108 |
| 109 // Callback for when user selects something. |
| 110 static void OnSelectionChanged(GtkTreeSelection* selection, |
| 111 KeywordEditorView* editor); |
| 112 |
| 113 // Callbacks for user actions modifying the table. |
| 114 static void OnRowActivated(GtkTreeView* tree_view, |
| 115 GtkTreePath* path, |
| 116 GtkTreeViewColumn* column, |
| 117 KeywordEditorView* editor); |
| 118 static void OnAddButtonClicked(GtkButton* button, |
| 119 KeywordEditorView* editor); |
| 120 static void OnEditButtonClicked(GtkButton* button, |
| 121 KeywordEditorView* editor); |
| 122 static void OnRemoveButtonClicked(GtkButton* button, |
| 123 KeywordEditorView* editor); |
| 124 static void OnMakeDefaultButtonClicked(GtkButton* button, |
| 125 KeywordEditorView* editor); |
| 126 |
| 127 // The table listing the search engines. |
| 128 GtkWidget* tree_; |
| 129 GtkListStore* list_store_; |
| 130 GtkTreeSelection* selection_; |
| 131 |
| 132 // Buttons for acting on the table. |
| 133 GtkWidget* add_button_; |
| 134 GtkWidget* edit_button_; |
| 135 GtkWidget* remove_button_; |
| 136 GtkWidget* make_default_button_; |
| 137 |
| 138 // The containing dialog. |
| 139 GtkWidget* dialog_; |
| 140 |
| 141 // The profile. |
| 142 Profile* profile_; |
| 143 |
| 144 scoped_ptr<KeywordEditorController> controller_; |
| 145 |
| 146 TemplateURLTableModel* table_model_; |
| 147 |
| 148 // We store our own index of the start of the second group within the model, |
| 149 // as when OnItemsRemoved is called the value in the model is already updated |
| 150 // but we need the old value to know which row to remove from the |
| 151 // |list_store_|. |
| 152 int model_second_group_index_; |
| 153 |
| 154 // Helper object to manage accessibility metadata. |
| 155 scoped_ptr<AccessibleWidgetHelper> accessible_widget_helper_; |
| 156 |
| 157 friend class KeywordEditorViewTest; |
| 158 FRIEND_TEST_ALL_PREFIXES(KeywordEditorViewTest, Empty); |
| 159 FRIEND_TEST_ALL_PREFIXES(KeywordEditorViewTest, Add); |
| 160 FRIEND_TEST_ALL_PREFIXES(KeywordEditorViewTest, MakeDefault); |
| 161 FRIEND_TEST_ALL_PREFIXES(KeywordEditorViewTest, Remove); |
| 162 FRIEND_TEST_ALL_PREFIXES(KeywordEditorViewTest, Edit); |
| 163 |
| 164 DISALLOW_COPY_AND_ASSIGN(KeywordEditorView); |
| 165 }; |
| 166 |
| 167 #endif // CHROME_BROWSER_UI_GTK_KEYWORD_EDITOR_VIEW_H_ |
OLD | NEW |