diff options
-rw-r--r-- | chrome/browser/gtk/options/cookies_view.cc | 44 | ||||
-rw-r--r-- | chrome/browser/gtk/options/exceptions_page_gtk.cc | 37 | ||||
-rw-r--r-- | chrome/browser/gtk/options/passwords_page_gtk.cc | 44 | ||||
-rw-r--r-- | chrome/browser/gtk/options/url_picker_dialog_gtk.cc | 41 | ||||
-rw-r--r-- | chrome/chrome.gyp | 6 | ||||
-rw-r--r-- | chrome/common/gtk_tree_util.cc | 35 | ||||
-rw-r--r-- | chrome/common/gtk_tree_util.h | 29 |
7 files changed, 96 insertions, 140 deletions
diff --git a/chrome/browser/gtk/options/cookies_view.cc b/chrome/browser/gtk/options/cookies_view.cc index 4c784e4..12087ec 100644 --- a/chrome/browser/gtk/options/cookies_view.cc +++ b/chrome/browser/gtk/options/cookies_view.cc @@ -10,6 +10,7 @@ #include "base/string_util.h" #include "base/time_format.h" #include "chrome/browser/cookies_table_model.h" +#include "chrome/common/gtk_tree_util.h" #include "chrome/common/gtk_util.h" #include "grit/generated_resources.h" #include "third_party/skia/include/core/SkBitmap.h" @@ -40,37 +41,6 @@ enum { // The currently open cookie manager, if any. CookiesView* instance_ = NULL; -// TODO(mattm): These functions are also in url_picker_dialog_gtk. Move them to -// some sort of gtk table model helper? -// Get the row number corresponding to |path|. -gint GetRowNumForPath(GtkTreePath* path) { - gint* indices = gtk_tree_path_get_indices(path); - if (!indices) { - NOTREACHED(); - return -1; - } - return indices[0]; -} - -// Get the row number corresponding to |iter|. -gint GetRowNumForIter(GtkTreeModel* model, GtkTreeIter* iter) { - GtkTreePath* path = gtk_tree_model_get_path(model, iter); - int row = GetRowNumForPath(path); - gtk_tree_path_free(path); - return row; -} - -// Get the row number in the child tree model corresponding to |sort_path| in -// the parent tree model. -gint GetTreeSortChildRowNumForPath(GtkTreeModel* sort_model, - GtkTreePath* sort_path) { - GtkTreePath *child_path = gtk_tree_model_sort_convert_path_to_child_path( - GTK_TREE_MODEL_SORT(sort_model), sort_path); - int row = GetRowNumForPath(child_path); - gtk_tree_path_free(child_path); - return row; -} - } // namespace CookiesView::~CookiesView() { @@ -314,7 +284,7 @@ void CookiesView::PopulateCookieDetails() { NOTREACHED(); return; } - int selected_index = GetTreeSortChildRowNumForPath( + int selected_index = GtkTreeUtil::GetTreeSortChildRowNumForPath( list_sort_, static_cast<GtkTreePath*>(list->data)); g_list_foreach(list, (GFunc)gtk_tree_path_free, NULL); g_list_free(list); @@ -366,7 +336,7 @@ void CookiesView::RemoveSelectedCookies() { GList* node; size_t i; for (i = 0, node = list; node != NULL; ++i, node = node->next) { - selected_rows[i] = GetTreeSortChildRowNumForPath( + selected_rows[i] = GtkTreeUtil::GetTreeSortChildRowNumForPath( list_sort_, static_cast<GtkTreePath*>(node->data)); } g_list_foreach(list, (GFunc)gtk_tree_path_free, NULL); @@ -446,8 +416,8 @@ void CookiesView::OnItemsRemoved(int start, int length) { // static gint CookiesView::CompareSite(GtkTreeModel* model, GtkTreeIter* a, GtkTreeIter* b, gpointer window) { - int row1 = GetRowNumForIter(model, a); - int row2 = GetRowNumForIter(model, b); + int row1 = GtkTreeUtil::GetRowNumForIter(model, a); + int row2 = GtkTreeUtil::GetRowNumForIter(model, b); return reinterpret_cast<CookiesView*>(window)->cookies_table_model_-> CompareValues(row1, row2, IDS_COOKIES_DOMAIN_COLUMN_HEADER); } @@ -455,8 +425,8 @@ gint CookiesView::CompareSite(GtkTreeModel* model, GtkTreeIter* a, // static gint CookiesView::CompareCookieName(GtkTreeModel* model, GtkTreeIter* a, GtkTreeIter* b, gpointer window) { - int row1 = GetRowNumForIter(model, a); - int row2 = GetRowNumForIter(model, b); + int row1 = GtkTreeUtil::GetRowNumForIter(model, a); + int row2 = GtkTreeUtil::GetRowNumForIter(model, b); return reinterpret_cast<CookiesView*>(window)->cookies_table_model_-> CompareValues(row1, row2, IDS_COOKIES_NAME_COLUMN_HEADER); } diff --git a/chrome/browser/gtk/options/exceptions_page_gtk.cc b/chrome/browser/gtk/options/exceptions_page_gtk.cc index c0b5597..ecdbf60 100644 --- a/chrome/browser/gtk/options/exceptions_page_gtk.cc +++ b/chrome/browser/gtk/options/exceptions_page_gtk.cc @@ -7,6 +7,7 @@ #include "app/l10n_util.h" #include "app/resource_bundle.h" #include "base/gfx/gtk_util.h" +#include "chrome/common/gtk_tree_util.h" #include "chrome/common/gtk_util.h" #include "chrome/common/pref_names.h" #include "chrome/common/pref_service.h" @@ -24,35 +25,6 @@ enum { COL_COUNT, }; -// Get the row number corresponding to |path|. -gint GetRowNumForPath(GtkTreePath* path) { - gint* indices = gtk_tree_path_get_indices(path); - if (!indices) { - NOTREACHED(); - return -1; - } - return indices[0]; -} - -// Get the row number corresponding to |iter|. -gint GetRowNumForIter(GtkTreeModel* model, GtkTreeIter* iter) { - GtkTreePath* path = gtk_tree_model_get_path(model, iter); - int row = GetRowNumForPath(path); - gtk_tree_path_free(path); - return row; -} - -// Get the row number in the child tree model corresponding to |sort_path| in -// the parent tree model. -gint GetTreeSortChildRowNumForPath(GtkTreeModel* sort_model, - GtkTreePath* sort_path) { - GtkTreePath *child_path = gtk_tree_model_sort_convert_path_to_child_path( - GTK_TREE_MODEL_SORT(sort_model), sort_path); - int row = GetRowNumForPath(child_path); - gtk_tree_path_free(child_path); - return row; -} - } // anonymous namespace /////////////////////////////////////////////////////////////////////////////// @@ -161,7 +133,8 @@ void ExceptionsPageGtk::OnRemoveButtonClicked(GtkButton* widget, GtkTreePath* path = gtk_tree_model_get_path( GTK_TREE_MODEL(page->exception_list_sort_), &iter); - gint index = GetTreeSortChildRowNumForPath(page->exception_list_sort_, path); + gint index = GtkTreeUtil::GetTreeSortChildRowNumForPath( + page->exception_list_sort_, path); gtk_tree_path_free(path); GtkTreeIter child_iter; @@ -205,8 +178,8 @@ void ExceptionsPageGtk::OnExceptionSelectionChanged(GtkTreeSelection* selection, gint ExceptionsPageGtk::CompareSite(GtkTreeModel* model, GtkTreeIter* a, GtkTreeIter* b, gpointer window) { - int row1 = GetRowNumForIter(model, a); - int row2 = GetRowNumForIter(model, b); + int row1 = GtkTreeUtil::GetRowNumForIter(model, a); + int row2 = GtkTreeUtil::GetRowNumForIter(model, b); ExceptionsPageGtk* page = reinterpret_cast<ExceptionsPageGtk*>(window); return page->exception_list_[row1].origin.spec().compare( page->exception_list_[row2].origin.spec()); diff --git a/chrome/browser/gtk/options/passwords_page_gtk.cc b/chrome/browser/gtk/options/passwords_page_gtk.cc index 4d6692c..7a3ef2e 100644 --- a/chrome/browser/gtk/options/passwords_page_gtk.cc +++ b/chrome/browser/gtk/options/passwords_page_gtk.cc @@ -7,6 +7,7 @@ #include "app/l10n_util.h" #include "app/resource_bundle.h" #include "base/gfx/gtk_util.h" +#include "chrome/common/gtk_tree_util.h" #include "chrome/common/gtk_util.h" #include "chrome/common/pref_names.h" #include "chrome/common/pref_service.h" @@ -28,35 +29,6 @@ enum { COL_COUNT, }; -// Get the row number corresponding to |path|. -gint GetRowNumForPath(GtkTreePath* path) { - gint* indices = gtk_tree_path_get_indices(path); - if (!indices) { - NOTREACHED(); - return -1; - } - return indices[0]; -} - -// Get the row number corresponding to |iter|. -gint GetRowNumForIter(GtkTreeModel* model, GtkTreeIter* iter) { - GtkTreePath* path = gtk_tree_model_get_path(model, iter); - int row = GetRowNumForPath(path); - gtk_tree_path_free(path); - return row; -} - -// Get the row number in the child tree model corresponding to |sort_path| in -// the parent tree model. -gint GetTreeSortChildRowNumForPath(GtkTreeModel* sort_model, - GtkTreePath* sort_path) { - GtkTreePath *child_path = gtk_tree_model_sort_convert_path_to_child_path( - GTK_TREE_MODEL_SORT(sort_model), sort_path); - int row = GetRowNumForPath(child_path); - gtk_tree_path_free(child_path); - return row; -} - } // anonymous namespace /////////////////////////////////////////////////////////////////////////////// @@ -206,7 +178,8 @@ void PasswordsPageGtk::OnRemoveButtonClicked(GtkButton* widget, GtkTreePath* path = gtk_tree_model_get_path( GTK_TREE_MODEL(page->password_list_sort_), &iter); - gint index = GetTreeSortChildRowNumForPath(page->password_list_sort_, path); + gint index = GtkTreeUtil::GetTreeSortChildRowNumForPath( + page->password_list_sort_, path); gtk_tree_path_free(path); GtkTreeIter child_iter; @@ -286,7 +259,8 @@ void PasswordsPageGtk::OnShowPasswordButtonClicked(GtkButton* widget, } GtkTreePath* path = gtk_tree_model_get_path( GTK_TREE_MODEL(page->password_list_sort_), &iter); - gint index = GetTreeSortChildRowNumForPath(page->password_list_sort_, path); + gint index = GtkTreeUtil::GetTreeSortChildRowNumForPath( + page->password_list_sort_, path); gtk_tree_path_free(path); std::string pass = WideToUTF8(page->password_list_[index].password_value); gtk_label_set_text(GTK_LABEL(page->password_), pass.c_str()); @@ -317,8 +291,8 @@ void PasswordsPageGtk::OnPasswordSelectionChanged(GtkTreeSelection* selection, gint PasswordsPageGtk::CompareSite(GtkTreeModel* model, GtkTreeIter* a, GtkTreeIter* b, gpointer window) { - int row1 = GetRowNumForIter(model, a); - int row2 = GetRowNumForIter(model, b); + int row1 = GtkTreeUtil::GetRowNumForIter(model, a); + int row2 = GtkTreeUtil::GetRowNumForIter(model, b); PasswordsPageGtk* page = reinterpret_cast<PasswordsPageGtk*>(window); return page->password_list_[row1].origin.spec().compare( page->password_list_[row2].origin.spec()); @@ -328,8 +302,8 @@ gint PasswordsPageGtk::CompareSite(GtkTreeModel* model, gint PasswordsPageGtk::CompareUsername(GtkTreeModel* model, GtkTreeIter* a, GtkTreeIter* b, gpointer window) { - int row1 = GetRowNumForIter(model, a); - int row2 = GetRowNumForIter(model, b); + int row1 = GtkTreeUtil::GetRowNumForIter(model, a); + int row2 = GtkTreeUtil::GetRowNumForIter(model, b); PasswordsPageGtk* page = reinterpret_cast<PasswordsPageGtk*>(window); return page->password_list_[row1].username_value.compare( page->password_list_[row2].username_value); diff --git a/chrome/browser/gtk/options/url_picker_dialog_gtk.cc b/chrome/browser/gtk/options/url_picker_dialog_gtk.cc index d6bf0eb..3e4d9a6 100644 --- a/chrome/browser/gtk/options/url_picker_dialog_gtk.cc +++ b/chrome/browser/gtk/options/url_picker_dialog_gtk.cc @@ -11,6 +11,7 @@ #include "chrome/browser/net/url_fixer_upper.h" #include "chrome/browser/possible_url_model.h" #include "chrome/browser/profile.h" +#include "chrome/common/gtk_tree_util.h" #include "chrome/common/gtk_util.h" #include "chrome/common/pref_names.h" #include "googleurl/src/gurl.h" @@ -38,35 +39,6 @@ enum { COL_COUNT, }; -// Get the row number corresponding to |path|. -gint GetRowNumForPath(GtkTreePath* path) { - gint* indices = gtk_tree_path_get_indices(path); - if (!indices) { - NOTREACHED(); - return -1; - } - return indices[0]; -} - -// Get the row number corresponding to |iter|. -gint GetRowNumForIter(GtkTreeModel* model, GtkTreeIter* iter) { - GtkTreePath* path = gtk_tree_model_get_path(model, iter); - int row = GetRowNumForPath(path); - gtk_tree_path_free(path); - return row; -} - -// Get the row number in the child tree model corresponding to |sort_path| in -// the parent tree model. -gint GetTreeSortChildRowNumForPath(GtkTreeModel* sort_model, - GtkTreePath* sort_path) { - GtkTreePath *child_path = gtk_tree_model_sort_convert_path_to_child_path( - GTK_TREE_MODEL_SORT(sort_model), sort_path); - int row = GetRowNumForPath(child_path); - gtk_tree_path_free(child_path); - return row; -} - } // anonymous namespace UrlPickerDialogGtk::UrlPickerDialogGtk(UrlPickerCallback* callback, @@ -205,7 +177,8 @@ void UrlPickerDialogGtk::EnableControls() { } std::string UrlPickerDialogGtk::GetURLForPath(GtkTreePath* path) const { - gint row = GetTreeSortChildRowNumForPath(history_list_sort_, path); + gint row = GtkTreeUtil::GetTreeSortChildRowNumForPath(history_list_sort_, + path); if (row < 0) { NOTREACHED(); return std::string(); @@ -280,8 +253,8 @@ gint UrlPickerDialogGtk::CompareTitle(GtkTreeModel* model, GtkTreeIter* a, GtkTreeIter* b, gpointer window) { - int row1 = GetRowNumForIter(model, a); - int row2 = GetRowNumForIter(model, b); + int row1 = GtkTreeUtil::GetRowNumForIter(model, a); + int row2 = GtkTreeUtil::GetRowNumForIter(model, b); return reinterpret_cast<UrlPickerDialogGtk*>(window)->url_table_model_-> CompareValues(row1, row2, IDS_ASI_PAGE_COLUMN); } @@ -291,8 +264,8 @@ gint UrlPickerDialogGtk::CompareURL(GtkTreeModel* model, GtkTreeIter* a, GtkTreeIter* b, gpointer window) { - int row1 = GetRowNumForIter(model, a); - int row2 = GetRowNumForIter(model, b); + int row1 = GtkTreeUtil::GetRowNumForIter(model, a); + int row2 = GtkTreeUtil::GetRowNumForIter(model, b); return reinterpret_cast<UrlPickerDialogGtk*>(window)->url_table_model_-> CompareValues(row1, row2, IDS_ASI_URL_COLUMN); } diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index e75d2d2..1db6f8a 100644 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -393,6 +393,8 @@ 'common/env_vars.h', 'common/filter_policy.h', 'common/gears_api.h', + 'common/gtk_tree_util.cc', + 'common/gtk_tree_util.h', 'common/gtk_util.cc', 'common/gtk_util.h', 'common/histogram_synchronizer.cc', @@ -1130,6 +1132,8 @@ 'browser/gtk/options/content_page_gtk.h', 'browser/gtk/options/cookies_view.cc', 'browser/gtk/options/cookies_view.h', + 'browser/gtk/options/exceptions_page_gtk.cc', + 'browser/gtk/options/exceptions_page_gtk.h', 'browser/gtk/options/fonts_languages_window_gtk.cc', 'browser/gtk/options/fonts_page_gtk.cc', 'browser/gtk/options/fonts_page_gtk.h', @@ -1138,8 +1142,6 @@ 'browser/gtk/options/options_layout_gtk.cc', 'browser/gtk/options/options_layout_gtk.h', 'browser/gtk/options/options_window_gtk.cc', - 'browser/gtk/options/exceptions_page_gtk.cc', - 'browser/gtk/options/exceptions_page_gtk.h', 'browser/gtk/options/passwords_exceptions_window_gtk.cc', 'browser/gtk/options/passwords_exceptions_window_gtk.h', 'browser/gtk/options/passwords_page_gtk.cc', diff --git a/chrome/common/gtk_tree_util.cc b/chrome/common/gtk_tree_util.cc new file mode 100644 index 0000000..bc4ed021 --- /dev/null +++ b/chrome/common/gtk_tree_util.cc @@ -0,0 +1,35 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/common/gtk_tree_util.h" + +#include "base/logging.h" + +// static +gint GtkTreeUtil::GetRowNumForPath(GtkTreePath* path) { + gint* indices = gtk_tree_path_get_indices(path); + if (!indices) { + NOTREACHED(); + return -1; + } + return indices[0]; +} + +// static +gint GtkTreeUtil::GetRowNumForIter(GtkTreeModel* model, GtkTreeIter* iter) { + GtkTreePath* path = gtk_tree_model_get_path(model, iter); + int row = GetRowNumForPath(path); + gtk_tree_path_free(path); + return row; +} + +// static +gint GtkTreeUtil::GetTreeSortChildRowNumForPath(GtkTreeModel* sort_model, + GtkTreePath* sort_path) { + GtkTreePath *child_path = gtk_tree_model_sort_convert_path_to_child_path( + GTK_TREE_MODEL_SORT(sort_model), sort_path); + int row = GetRowNumForPath(child_path); + gtk_tree_path_free(child_path); + return row; +} diff --git a/chrome/common/gtk_tree_util.h b/chrome/common/gtk_tree_util.h new file mode 100644 index 0000000..abd9ee6 --- /dev/null +++ b/chrome/common/gtk_tree_util.h @@ -0,0 +1,29 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_COMMON_GTK_TREE_UTIL_H_ +#define CHROME_COMMON_GTK_TREE_UTIL_H_ + +#include <gtk/gtk.h> + +#include "base/basictypes.h" + +class GtkTreeUtil { + public: + // Get the row number corresponding to |path|. + static gint GetRowNumForPath(GtkTreePath* path); + + // Get the row number corresponding to |iter|. + static gint GetRowNumForIter(GtkTreeModel* model, GtkTreeIter* iter); + + // Get the row number in the child tree model corresponding to |sort_path| in + // the parent tree model. + static gint GetTreeSortChildRowNumForPath(GtkTreeModel* sort_model, + GtkTreePath* sort_path); + + private: + DISALLOW_IMPLICIT_CONSTRUCTORS(GtkTreeUtil); +}; + +#endif // CHROME_COMMON_GTK_TREE_UTIL_H_ |