diff options
author | munjal@chromium.org <munjal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-26 22:29:20 +0000 |
---|---|---|
committer | munjal@chromium.org <munjal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-26 22:29:20 +0000 |
commit | b3c33d463366d2725ec4d669b98dc468a751c541 (patch) | |
tree | d8496a8ae8fc73ed71b93d67c055e9f1bba4fcc7 /chrome/browser/gtk | |
parent | 7b91dfd0bce7b4f864d9654e8bd0a9f93683cec0 (diff) | |
download | chromium_src-b3c33d463366d2725ec4d669b98dc468a751c541.zip chromium_src-b3c33d463366d2725ec4d669b98dc468a751c541.tar.gz chromium_src-b3c33d463366d2725ec4d669b98dc468a751c541.tar.bz2 |
Make bookmark model public interface use const BookmarkNode* instead of
BookmarkNode*. This helps in making the BookmarkNode class setters public
also without worrying about someone inadvertently changing BookmarkNode
properties directly for bookmark model bookmarks.
Change all the call sites to reflect this.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/146116
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19428 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/gtk')
-rw-r--r-- | chrome/browser/gtk/bookmark_bar_gtk.cc | 56 | ||||
-rw-r--r-- | chrome/browser/gtk/bookmark_bar_gtk.h | 32 | ||||
-rw-r--r-- | chrome/browser/gtk/bookmark_bubble_gtk.cc | 29 | ||||
-rw-r--r-- | chrome/browser/gtk/bookmark_bubble_gtk.h | 2 | ||||
-rw-r--r-- | chrome/browser/gtk/bookmark_context_menu.cc | 51 | ||||
-rw-r--r-- | chrome/browser/gtk/bookmark_context_menu.h | 26 | ||||
-rw-r--r-- | chrome/browser/gtk/bookmark_editor_gtk.cc | 25 | ||||
-rw-r--r-- | chrome/browser/gtk/bookmark_editor_gtk.h | 24 | ||||
-rw-r--r-- | chrome/browser/gtk/bookmark_editor_gtk_unittest.cc | 46 | ||||
-rw-r--r-- | chrome/browser/gtk/bookmark_manager_gtk.cc | 65 | ||||
-rw-r--r-- | chrome/browser/gtk/bookmark_manager_gtk.h | 26 | ||||
-rw-r--r-- | chrome/browser/gtk/bookmark_menu_controller_gtk.cc | 30 | ||||
-rw-r--r-- | chrome/browser/gtk/bookmark_menu_controller_gtk.h | 10 | ||||
-rw-r--r-- | chrome/browser/gtk/bookmark_tree_model.cc | 24 | ||||
-rw-r--r-- | chrome/browser/gtk/bookmark_tree_model.h | 4 | ||||
-rw-r--r-- | chrome/browser/gtk/bookmark_utils_gtk.cc | 12 | ||||
-rw-r--r-- | chrome/browser/gtk/bookmark_utils_gtk.h | 8 |
17 files changed, 242 insertions, 228 deletions
diff --git a/chrome/browser/gtk/bookmark_bar_gtk.cc b/chrome/browser/gtk/bookmark_bar_gtk.cc index cfadd13..dc86bab 100644 --- a/chrome/browser/gtk/bookmark_bar_gtk.cc +++ b/chrome/browser/gtk/bookmark_bar_gtk.cc @@ -279,7 +279,7 @@ void BookmarkBarGtk::Loaded(BookmarkModel* model) { return; RemoveAllBookmarkButtons(); - BookmarkNode* node = model_->GetBookmarkBarNode(); + const BookmarkNode* node = model_->GetBookmarkBarNode(); DCHECK(node && model_->other_node()); CreateAllBookmarkButtons(node); @@ -297,16 +297,16 @@ void BookmarkBarGtk::BookmarkModelBeingDeleted(BookmarkModel* model) { } void BookmarkBarGtk::BookmarkNodeMoved(BookmarkModel* model, - BookmarkNode* old_parent, + const BookmarkNode* old_parent, int old_index, - BookmarkNode* new_parent, + const BookmarkNode* new_parent, int new_index) { BookmarkNodeRemoved(model, old_parent, old_index); BookmarkNodeAdded(model, new_parent, new_index); } void BookmarkBarGtk::BookmarkNodeAdded(BookmarkModel* model, - BookmarkNode* parent, + const BookmarkNode* parent, int index) { if (parent != model_->GetBookmarkBarNode()) { // We only care about nodes on the bookmark bar. @@ -322,7 +322,7 @@ void BookmarkBarGtk::BookmarkNodeAdded(BookmarkModel* model, } void BookmarkBarGtk::BookmarkNodeRemoved(BookmarkModel* model, - BookmarkNode* parent, + const BookmarkNode* parent, int index) { if (parent != model_->GetBookmarkBarNode()) { // We only care about nodes on the bookmark bar. @@ -339,7 +339,7 @@ void BookmarkBarGtk::BookmarkNodeRemoved(BookmarkModel* model, } void BookmarkBarGtk::BookmarkNodeChanged(BookmarkModel* model, - BookmarkNode* node) { + const BookmarkNode* node) { if (node->GetParent() != model_->GetBookmarkBarNode()) { // We only care about nodes on the bookmark bar. return; @@ -354,12 +354,12 @@ void BookmarkBarGtk::BookmarkNodeChanged(BookmarkModel* model, } void BookmarkBarGtk::BookmarkNodeFavIconLoaded(BookmarkModel* model, - BookmarkNode* node) { + const BookmarkNode* node) { BookmarkNodeChanged(model, node); } void BookmarkBarGtk::BookmarkNodeChildrenReordered(BookmarkModel* model, - BookmarkNode* node) { + const BookmarkNode* node) { if (node != model_->GetBookmarkBarNode()) return; // We only care about reordering of the bookmark bar node. @@ -368,7 +368,7 @@ void BookmarkBarGtk::BookmarkNodeChildrenReordered(BookmarkModel* model, CreateAllBookmarkButtons(node); } -void BookmarkBarGtk::CreateAllBookmarkButtons(BookmarkNode* node) { +void BookmarkBarGtk::CreateAllBookmarkButtons(const BookmarkNode* node) { // Create a button for each of the children on the bookmark bar. for (int i = 0; i < node->GetChildCount(); ++i) { GtkToolItem* item = CreateBookmarkToolItem(node->GetChild(i)); @@ -378,7 +378,8 @@ void BookmarkBarGtk::CreateAllBookmarkButtons(BookmarkNode* node) { SetInstructionState(node); } -void BookmarkBarGtk::SetInstructionState(BookmarkNode* boomarks_bar_node) { +void BookmarkBarGtk::SetInstructionState( + const BookmarkNode* boomarks_bar_node) { show_instructions_ = (boomarks_bar_node->GetChildCount() == 0); if (show_instructions_) { gtk_widget_show_all(instructions_); @@ -418,7 +419,7 @@ void BookmarkBarGtk::AnimationEnded(const Animation* animation) { gtk_widget_hide(bookmark_hbox_.get()); } -void BookmarkBarGtk::ConfigureButtonForNode(BookmarkNode* node, +void BookmarkBarGtk::ConfigureButtonForNode(const BookmarkNode* node, GtkWidget* button) { std::string tooltip = BuildTooltip(node); if (!tooltip.empty()) @@ -439,10 +440,10 @@ void BookmarkBarGtk::ConfigureButtonForNode(BookmarkNode* node, SetButtonTextColors(button); g_object_set_data(G_OBJECT(button), kBookmarkNode, - reinterpret_cast<void*>(node)); + reinterpret_cast<void*>(const_cast<BookmarkNode*>(node))); } -GtkWidget* BookmarkBarGtk::CreateBookmarkButton(BookmarkNode* node) { +GtkWidget* BookmarkBarGtk::CreateBookmarkButton(const BookmarkNode* node) { GtkWidget* button = gtk_chrome_button_new(); ConfigureButtonForNode(node, button); @@ -477,7 +478,7 @@ GtkWidget* BookmarkBarGtk::CreateBookmarkButton(BookmarkNode* node) { return button; } -GtkToolItem* BookmarkBarGtk::CreateBookmarkToolItem(BookmarkNode* node) { +GtkToolItem* BookmarkBarGtk::CreateBookmarkToolItem(const BookmarkNode* node) { GtkWidget* button = CreateBookmarkButton(node); g_object_set_data(G_OBJECT(button), "left-align-popup", reinterpret_cast<void*>(true)); @@ -499,13 +500,13 @@ void BookmarkBarGtk::ConnectFolderButtonEvents(GtkWidget* widget) { G_CALLBACK(OnFolderButtonReleased), this); } -std::string BookmarkBarGtk::BuildTooltip(BookmarkNode* node) { +std::string BookmarkBarGtk::BuildTooltip(const BookmarkNode* node) { // TODO(erg): Actually build the tooltip. For now, we punt and just return // the URL. return node->GetURL().possibly_invalid_spec(); } -BookmarkNode* BookmarkBarGtk::GetNodeForToolButton(GtkWidget* widget) { +const BookmarkNode* BookmarkBarGtk::GetNodeForToolButton(GtkWidget* widget) { // First check to see if |button| is special cased. if (widget == other_bookmarks_button_) return model_->other_node(); @@ -542,15 +543,16 @@ void BookmarkBarGtk::InitBackground() { 0, IDR_THEME_TOOLBAR, 0, 0, 0, 0, 0, 0, 0)); } -void BookmarkBarGtk::PopupMenuForNode(GtkWidget* sender, BookmarkNode* node, +void BookmarkBarGtk::PopupMenuForNode(GtkWidget* sender, + const BookmarkNode* node, GdkEventButton* event) { if (!model_->IsLoaded()) { // Don't do anything if the model isn't loaded. return; } - BookmarkNode* parent = NULL; - std::vector<BookmarkNode*> nodes; + const BookmarkNode* parent = NULL; + std::vector<const BookmarkNode*> nodes; if (sender == other_bookmarks_button_) { parent = model_->GetBookmarkBarNode(); nodes.push_back(parent); @@ -578,7 +580,7 @@ gboolean BookmarkBarGtk::OnButtonPressed(GtkWidget* sender, bar->ignore_button_release_ = false; if (event->button == 3) { - BookmarkNode* node = bar->GetNodeForToolButton(sender); + const BookmarkNode* node = bar->GetNodeForToolButton(sender); DCHECK(node); DCHECK(bar->page_navigator_); bar->PopupMenuForNode(sender, node, event); @@ -597,7 +599,7 @@ gboolean BookmarkBarGtk::OnButtonReleased(GtkWidget* sender, return FALSE; } - BookmarkNode* node = bar->GetNodeForToolButton(sender); + const BookmarkNode* node = bar->GetNodeForToolButton(sender); DCHECK(node); DCHECK(bar->page_navigator_); @@ -630,7 +632,7 @@ void BookmarkBarGtk::OnButtonDragBegin(GtkWidget* button, // pressing. bar->ignore_button_release_ = true; - BookmarkNode* node = bar->GetNodeForToolButton(button); + const BookmarkNode* node = bar->GetNodeForToolButton(button); DCHECK(!bar->dragged_node_); bar->dragged_node_ = node; DCHECK(bar->dragged_node_); @@ -680,8 +682,8 @@ void BookmarkBarGtk::OnButtonDragGet(GtkWidget* widget, GdkDragContext* context, GtkSelectionData* selection_data, guint target_type, guint time, BookmarkBarGtk* bar) { - BookmarkNode* node = - reinterpret_cast<BookmarkNode*>( + const BookmarkNode* node = + reinterpret_cast<const BookmarkNode*>( g_object_get_data(G_OBJECT(widget), kBookmarkNode)); bookmark_utils::WriteBookmarkToSelection(node, selection_data, target_type, bar->profile_); @@ -697,7 +699,7 @@ gboolean BookmarkBarGtk::OnFolderButtonReleased(GtkWidget* sender, return FALSE; } - BookmarkNode* node = bar->GetNodeForToolButton(sender); + const BookmarkNode* node = bar->GetNodeForToolButton(sender); DCHECK(node); DCHECK(bar->page_navigator_); @@ -807,7 +809,7 @@ void BookmarkBarGtk::OnToolbarDragReceived(GtkWidget* widget, gboolean dnd_success = FALSE; gboolean delete_selection_data = FALSE; - std::vector<BookmarkNode*> nodes = + std::vector<const BookmarkNode*> nodes = bookmark_utils::GetNodesFromSelection(context, selection_data, target_type, bar->profile_, @@ -816,7 +818,7 @@ void BookmarkBarGtk::OnToolbarDragReceived(GtkWidget* widget, DCHECK(!nodes.empty()); gint index = gtk_toolbar_get_drop_index( GTK_TOOLBAR(bar->bookmark_toolbar_.get()), x, y); - for (std::vector<BookmarkNode*>::iterator it = nodes.begin(); + for (std::vector<const BookmarkNode*>::iterator it = nodes.begin(); it != nodes.end(); ++it) { bar->model_->Move(*it, bar->model_->GetBookmarkBarNode(), index); index = bar->model_->GetBookmarkBarNode()->IndexOfChild(*it) + 1; diff --git a/chrome/browser/gtk/bookmark_bar_gtk.h b/chrome/browser/gtk/bookmark_bar_gtk.h index 154dc36..be07088 100644 --- a/chrome/browser/gtk/bookmark_bar_gtk.h +++ b/chrome/browser/gtk/bookmark_bar_gtk.h @@ -74,15 +74,15 @@ class BookmarkBarGtk : public AnimationDelegate, private: // Helper function that sets visual properties of GtkButton |button| to the // contents of |node|. - void ConfigureButtonForNode(BookmarkNode* node, + void ConfigureButtonForNode(const BookmarkNode* node, GtkWidget* button); // Helper function which generates GtkToolItems for |bookmark_toolbar_|. - void CreateAllBookmarkButtons(BookmarkNode* node); + void CreateAllBookmarkButtons(const BookmarkNode* node); // Sets the visibility of the instructional text based on whether there are // any bookmarks in |node|. |node| is assumed to be the bookmarks bar node. - void SetInstructionState(BookmarkNode* boomarks_bar_node); + void SetInstructionState(const BookmarkNode* boomarks_bar_node); // Helper function which destroys all the bookmark buttons in the GtkToolbar. void RemoveAllBookmarkButtons(); @@ -103,40 +103,40 @@ class BookmarkBarGtk : public AnimationDelegate, // Invoked when a node has moved. virtual void BookmarkNodeMoved(BookmarkModel* model, - BookmarkNode* old_parent, + const BookmarkNode* old_parent, int old_index, - BookmarkNode* new_parent, + const BookmarkNode* new_parent, int new_index); virtual void BookmarkNodeAdded(BookmarkModel* model, - BookmarkNode* parent, + const BookmarkNode* parent, int index); virtual void BookmarkNodeRemoved(BookmarkModel* model, - BookmarkNode* parent, + const BookmarkNode* parent, int index); virtual void BookmarkNodeChanged(BookmarkModel* model, - BookmarkNode* node); + const BookmarkNode* node); // Invoked when a favicon has finished loading. virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model, - BookmarkNode* node); + const BookmarkNode* node); virtual void BookmarkNodeChildrenReordered(BookmarkModel* model, - BookmarkNode* node); + const BookmarkNode* node); private: - GtkWidget* CreateBookmarkButton(BookmarkNode* node); - GtkToolItem* CreateBookmarkToolItem(BookmarkNode* node); + GtkWidget* CreateBookmarkButton(const BookmarkNode* node); + GtkToolItem* CreateBookmarkToolItem(const BookmarkNode* node); void ConnectFolderButtonEvents(GtkWidget* widget); - std::string BuildTooltip(BookmarkNode* node); + std::string BuildTooltip(const BookmarkNode* node); // Finds the BookmarkNode from the model associated with |button|. - BookmarkNode* GetNodeForToolButton(GtkWidget* button); + const BookmarkNode* GetNodeForToolButton(GtkWidget* button); // Loads the background image into memory, or does nothing if already loaded. void InitBackground(); // Creates and displays a popup menu for BookmarkNode |node|. - void PopupMenuForNode(GtkWidget* sender, BookmarkNode* node, + void PopupMenuForNode(GtkWidget* sender, const BookmarkNode* node, GdkEventButton* event); // GtkButton callbacks @@ -221,7 +221,7 @@ class BookmarkBarGtk : public AnimationDelegate, // The BookmarkNode from the model being dragged. NULL when we aren't // dragging. - BookmarkNode* dragged_node_; + const BookmarkNode* dragged_node_; // We create a GtkToolbarItem from |dragged_node_| for display. GtkToolItem* toolbar_drop_item_; diff --git a/chrome/browser/gtk/bookmark_bubble_gtk.cc b/chrome/browser/gtk/bookmark_bubble_gtk.cc index ae07e3d..30e93d6 100644 --- a/chrome/browser/gtk/bookmark_bubble_gtk.cc +++ b/chrome/browser/gtk/bookmark_bubble_gtk.cc @@ -31,19 +31,19 @@ BookmarkBubbleGtk* g_bubble = NULL; // Max number of most recently used folders. const size_t kMaxMRUFolders = 5; -std::vector<BookmarkNode*> PopulateFolderCombo(BookmarkModel* model, - const GURL& url, - GtkWidget* folder_combo) { - BookmarkNode* node = model->GetMostRecentlyAddedNodeForURL(url); - BookmarkNode* parent = node->GetParent(); - BookmarkNode* bookmark_bar = model->GetBookmarkBarNode(); - BookmarkNode* other = model->other_node(); +std::vector<const BookmarkNode*> PopulateFolderCombo(BookmarkModel* model, + const GURL& url, + GtkWidget* folder_combo) { + const BookmarkNode* node = model->GetMostRecentlyAddedNodeForURL(url); + const BookmarkNode* parent = node->GetParent(); + const BookmarkNode* bookmark_bar = model->GetBookmarkBarNode(); + const BookmarkNode* other = model->other_node(); // Use + 2 to account for bookmark bar and other node. - std::vector<BookmarkNode*> recent_nodes = + std::vector<const BookmarkNode*> recent_nodes = bookmark_utils::GetMostRecentlyModifiedGroups(model, kMaxMRUFolders + 2); - std::vector<BookmarkNode*> nodes; + std::vector<const BookmarkNode*> nodes; // Make the parent the first item, unless it's the bookmark bar or other node. if (parent != bookmark_bar && parent != other) nodes.push_back(parent); @@ -217,7 +217,7 @@ BookmarkBubbleGtk::~BookmarkBubbleGtk() { ApplyEdits(); } else if (remove_bookmark_) { BookmarkModel* model = profile_->GetBookmarkModel(); - BookmarkNode* node = model->GetMostRecentlyAddedNodeForURL(url_); + const BookmarkNode* node = model->GetMostRecentlyAddedNodeForURL(url_); if (node) model->Remove(node->GetParent(), node->GetParent()->IndexOfChild(node)); } @@ -269,7 +269,7 @@ void BookmarkBubbleGtk::ApplyEdits() { apply_edits_ = false; BookmarkModel* model = profile_->GetBookmarkModel(); - BookmarkNode* node = model->GetMostRecentlyAddedNodeForURL(url_); + const BookmarkNode* node = model->GetMostRecentlyAddedNodeForURL(url_); if (node) { // NOTE: Would be nice to save a strlen and use gtk_entry_get_text_length, // but it is fairly new and not always in our GTK version. @@ -286,7 +286,7 @@ void BookmarkBubbleGtk::ApplyEdits() { // Last index ('Choose another folder...') is not in folder_nodes_. if (cur_folder < folder_nodes_.size()) { - BookmarkNode* new_parent = folder_nodes_[cur_folder]; + const BookmarkNode* new_parent = folder_nodes_[cur_folder]; if (new_parent != node->GetParent()) { UserMetrics::RecordAction(L"BookmarkBubble_ChangeParent", profile_); model->Move(node, new_parent, new_parent->GetChildCount()); @@ -297,7 +297,8 @@ void BookmarkBubbleGtk::ApplyEdits() { std::string BookmarkBubbleGtk::GetTitle() { BookmarkModel* bookmark_model= profile_->GetBookmarkModel(); - BookmarkNode* node = bookmark_model->GetMostRecentlyAddedNodeForURL(url_); + const BookmarkNode* node = + bookmark_model->GetMostRecentlyAddedNodeForURL(url_); if (!node) { NOTREACHED(); return std::string(); @@ -307,7 +308,7 @@ std::string BookmarkBubbleGtk::GetTitle() { } void BookmarkBubbleGtk::ShowEditor() { - BookmarkNode* node = + const BookmarkNode* node = profile_->GetBookmarkModel()->GetMostRecentlyAddedNodeForURL(url_); // Commit any edits now. diff --git a/chrome/browser/gtk/bookmark_bubble_gtk.h b/chrome/browser/gtk/bookmark_bubble_gtk.h index 8e67f6c..48890b6 100644 --- a/chrome/browser/gtk/bookmark_bubble_gtk.h +++ b/chrome/browser/gtk/bookmark_bubble_gtk.h @@ -121,7 +121,7 @@ class BookmarkBubbleGtk : public InfoBubbleGtkDelegate { GtkWidget* folder_combo_; // The bookmark nodes in |folder_combo_|. - std::vector<BookmarkNode*> folder_nodes_; + std::vector<const BookmarkNode*> folder_nodes_; InfoBubbleGtk* bubble_; diff --git a/chrome/browser/gtk/bookmark_context_menu.cc b/chrome/browser/gtk/bookmark_context_menu.cc index ff92135..8af8058 100644 --- a/chrome/browser/gtk/bookmark_context_menu.cc +++ b/chrome/browser/gtk/bookmark_context_menu.cc @@ -30,7 +30,7 @@ namespace { // Returns true if the specified node is of type URL, or has a descendant // of type URL. -bool NodeHasURLs(BookmarkNode* node) { +bool NodeHasURLs(const BookmarkNode* node) { if (node->is_url()) return true; @@ -57,7 +57,7 @@ class EditFolderController : public InputWindowDialog::Delegate, static void Show(Profile* profile, gfx::NativeView wnd, - BookmarkNode* node, + const BookmarkNode* node, bool is_new, bool show_in_manager) { // EditFolderController deletes itself when done. @@ -69,7 +69,7 @@ class EditFolderController : public InputWindowDialog::Delegate, private: EditFolderController(Profile* profile, gfx::NativeView wnd, - BookmarkNode* node, + const BookmarkNode* node, bool is_new, bool show_in_manager) : profile_(profile), @@ -103,7 +103,7 @@ class EditFolderController : public InputWindowDialog::Delegate, virtual void InputAccepted(const std::wstring& text) { if (is_new_) { - ALLOW_UNUSED BookmarkNode* node = + ALLOW_UNUSED const BookmarkNode* node = model_->AddGroup(node_, node_->GetChildCount(), text); if (show_in_manager_) { #if defined(OS_WIN) || (defined(OS_LINUX) && !defined(TOOLKIT_VIEWS)) @@ -130,35 +130,36 @@ class EditFolderController : public InputWindowDialog::Delegate, } virtual void BookmarkNodeMoved(BookmarkModel* model, - BookmarkNode* old_parent, + const BookmarkNode* old_parent, int old_index, - BookmarkNode* new_parent, + const BookmarkNode* new_parent, int new_index) { ModelChanged(); } virtual void BookmarkNodeAdded(BookmarkModel* model, - BookmarkNode* parent, + const BookmarkNode* parent, int index) { ModelChanged(); } virtual void BookmarkNodeRemoved(BookmarkModel* model, - BookmarkNode* parent, + const BookmarkNode* parent, int index, - BookmarkNode* node) { + const BookmarkNode* node) { ModelChanged(); } - virtual void BookmarkNodeChanged(BookmarkModel* model, BookmarkNode* node) { + virtual void BookmarkNodeChanged(BookmarkModel* model, + const BookmarkNode* node) { ModelChanged(); } virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model, - BookmarkNode* node) {} + const BookmarkNode* node) {} virtual void BookmarkNodeChildrenReordered(BookmarkModel* model, - BookmarkNode* node) { + const BookmarkNode* node) { ModelChanged(); } @@ -170,7 +171,7 @@ class EditFolderController : public InputWindowDialog::Delegate, BookmarkModel* model_; // If is_new is true, this is the parent to create the new node under. // Otherwise this is the node to change the title of. - BookmarkNode* node_; + const BookmarkNode* node_; bool is_new_; @@ -192,7 +193,7 @@ class SelectOnCreationHandler : public BookmarkEditor::Handler { explicit SelectOnCreationHandler(Profile* profile) : profile_(profile) { } - virtual void NodeCreated(BookmarkNode* new_node) { + virtual void NodeCreated(const BookmarkNode* new_node) { BookmarkManager::SelectInTree(profile_, new_node); } @@ -212,8 +213,8 @@ BookmarkContextMenu::BookmarkContextMenu( Profile* profile, Browser* browser, PageNavigator* navigator, - BookmarkNode* parent, - const std::vector<BookmarkNode*>& selection, + const BookmarkNode* parent, + const std::vector<const BookmarkNode*>& selection, ConfigurationType configuration) : wnd_(wnd), profile_(profile), @@ -502,33 +503,33 @@ void BookmarkContextMenu::BookmarkModelBeingDeleted(BookmarkModel* model) { } void BookmarkContextMenu::BookmarkNodeMoved(BookmarkModel* model, - BookmarkNode* old_parent, + const BookmarkNode* old_parent, int old_index, - BookmarkNode* new_parent, + const BookmarkNode* new_parent, int new_index) { ModelChanged(); } void BookmarkContextMenu::BookmarkNodeAdded(BookmarkModel* model, - BookmarkNode* parent, + const BookmarkNode* parent, int index) { ModelChanged(); } void BookmarkContextMenu::BookmarkNodeRemoved(BookmarkModel* model, - BookmarkNode* parent, + const BookmarkNode* parent, int index, - BookmarkNode* node) { + const BookmarkNode* node) { ModelChanged(); } void BookmarkContextMenu::BookmarkNodeChanged(BookmarkModel* model, - BookmarkNode* node) { + const BookmarkNode* node) { ModelChanged(); } -void BookmarkContextMenu::BookmarkNodeChildrenReordered(BookmarkModel* model, - BookmarkNode* node) { +void BookmarkContextMenu::BookmarkNodeChildrenReordered( + BookmarkModel* model, const BookmarkNode* node) { ModelChanged(); } @@ -551,7 +552,7 @@ bool BookmarkContextMenu::HasURLs() const { return false; } -BookmarkNode* BookmarkContextMenu::GetParentForNewNodes() const { +const BookmarkNode* BookmarkContextMenu::GetParentForNewNodes() const { return (selection_.size() == 1 && selection_[0]->is_folder()) ? selection_[0] : parent_; } diff --git a/chrome/browser/gtk/bookmark_context_menu.h b/chrome/browser/gtk/bookmark_context_menu.h index 38dc37a..db601c9 100644 --- a/chrome/browser/gtk/bookmark_context_menu.h +++ b/chrome/browser/gtk/bookmark_context_menu.h @@ -59,8 +59,8 @@ class BookmarkContextMenu : public BookmarkModelObserver, Profile* profile, Browser* browser, PageNavigator* navigator, - BookmarkNode* parent, - const std::vector<BookmarkNode*>& selection, + const BookmarkNode* parent, + const std::vector<const BookmarkNode*>& selection, ConfigurationType configuration); virtual ~BookmarkContextMenu(); @@ -89,23 +89,23 @@ class BookmarkContextMenu : public BookmarkModelObserver, virtual void Loaded(BookmarkModel* model) {} virtual void BookmarkModelBeingDeleted(BookmarkModel* model); virtual void BookmarkNodeMoved(BookmarkModel* model, - BookmarkNode* old_parent, + const BookmarkNode* old_parent, int old_index, - BookmarkNode* new_parent, + const BookmarkNode* new_parent, int new_index); virtual void BookmarkNodeAdded(BookmarkModel* model, - BookmarkNode* parent, + const BookmarkNode* parent, int index); virtual void BookmarkNodeRemoved(BookmarkModel* model, - BookmarkNode* parent, + const BookmarkNode* parent, int index, - BookmarkNode* node); + const BookmarkNode* node); virtual void BookmarkNodeChanged(BookmarkModel* model, - BookmarkNode* node); + const BookmarkNode* node); virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model, - BookmarkNode* node) {} + const BookmarkNode* node) {} virtual void BookmarkNodeChildrenReordered(BookmarkModel* model, - BookmarkNode* node); + const BookmarkNode* node); // Invoked from the various bookmark model observer methods. Closes the menu. void ModelChanged(); @@ -131,14 +131,14 @@ class BookmarkContextMenu : public BookmarkModelObserver, // Returns the parent for newly created folders/bookmarks. If selection_ // has one element and it is a folder, selection_[0] is returned, otherwise // parent_ is returned. - BookmarkNode* GetParentForNewNodes() const; + const BookmarkNode* GetParentForNewNodes() const; gfx::NativeView wnd_; Profile* profile_; Browser* browser_; PageNavigator* navigator_; - BookmarkNode* parent_; - std::vector<BookmarkNode*> selection_; + const BookmarkNode* parent_; + std::vector<const BookmarkNode*> selection_; BookmarkModel* model_; ConfigurationType configuration_; diff --git a/chrome/browser/gtk/bookmark_editor_gtk.cc b/chrome/browser/gtk/bookmark_editor_gtk.cc index 05d1ec2..1a6171c 100644 --- a/chrome/browser/gtk/bookmark_editor_gtk.cc +++ b/chrome/browser/gtk/bookmark_editor_gtk.cc @@ -37,8 +37,8 @@ static const int kTreeHeight = 150; // static void BookmarkEditor::Show(gfx::NativeView parent_hwnd, Profile* profile, - BookmarkNode* parent, - BookmarkNode* node, + const BookmarkNode* parent, + const BookmarkNode* node, Configuration configuration, Handler* handler) { DCHECK(profile); @@ -51,8 +51,8 @@ void BookmarkEditor::Show(gfx::NativeView parent_hwnd, BookmarkEditorGtk::BookmarkEditorGtk( GtkWindow* window, Profile* profile, - BookmarkNode* parent, - BookmarkNode* node, + const BookmarkNode* parent, + const BookmarkNode* node, BookmarkEditor::Configuration configuration, BookmarkEditor::Handler* handler) : profile_(profile), @@ -228,23 +228,23 @@ void BookmarkEditorGtk::Close() { } void BookmarkEditorGtk::BookmarkNodeMoved(BookmarkModel* model, - BookmarkNode* old_parent, + const BookmarkNode* old_parent, int old_index, - BookmarkNode* new_parent, + const BookmarkNode* new_parent, int new_index) { Reset(); } void BookmarkEditorGtk::BookmarkNodeAdded(BookmarkModel* model, - BookmarkNode* parent, + const BookmarkNode* parent, int index) { Reset(); } void BookmarkEditorGtk::BookmarkNodeRemoved(BookmarkModel* model, - BookmarkNode* parent, + const BookmarkNode* parent, int index, - BookmarkNode* node) { + const BookmarkNode* node) { if ((node_ && node_->HasAncestor(node)) || (parent_ && parent_->HasAncestor(node))) { // The node, or its parent was removed. Close the dialog. @@ -254,8 +254,8 @@ void BookmarkEditorGtk::BookmarkNodeRemoved(BookmarkModel* model, } } -void BookmarkEditorGtk::BookmarkNodeChildrenReordered(BookmarkModel* model, - BookmarkNode* node) { +void BookmarkEditorGtk::BookmarkNodeChildrenReordered( + BookmarkModel* model, const BookmarkNode* node) { Reset(); } @@ -306,7 +306,8 @@ void BookmarkEditorGtk::ApplyEdits(GtkTreeIter* selected_parent) { } // Create the new groups and update the titles. - BookmarkNode* new_parent = bookmark_utils::CommitTreeStoreDifferencesBetween( + const BookmarkNode* new_parent = + bookmark_utils::CommitTreeStoreDifferencesBetween( bb_model_, tree_store_, selected_parent); if (!new_parent) { diff --git a/chrome/browser/gtk/bookmark_editor_gtk.h b/chrome/browser/gtk/bookmark_editor_gtk.h index 4149a05..70ed8c4 100644 --- a/chrome/browser/gtk/bookmark_editor_gtk.h +++ b/chrome/browser/gtk/bookmark_editor_gtk.h @@ -26,8 +26,8 @@ class BookmarkEditorGtk : public BookmarkEditor, public: BookmarkEditorGtk(GtkWindow* window, Profile* profile, - BookmarkNode* parent, - BookmarkNode* node, + const BookmarkNode* parent, + const BookmarkNode* node, BookmarkEditor::Configuration configuration, BookmarkEditor::Handler* handler); @@ -43,23 +43,23 @@ class BookmarkEditorGtk : public BookmarkEditor, // resetting the tree model. virtual void Loaded(BookmarkModel* model) { } virtual void BookmarkNodeMoved(BookmarkModel* model, - BookmarkNode* old_parent, + const BookmarkNode* old_parent, int old_index, - BookmarkNode* new_parent, + const BookmarkNode* new_parent, int new_index); virtual void BookmarkNodeAdded(BookmarkModel* model, - BookmarkNode* parent, + const BookmarkNode* parent, int index); virtual void BookmarkNodeRemoved(BookmarkModel* model, - BookmarkNode* parent, + const BookmarkNode* parent, int index, - BookmarkNode* node); + const BookmarkNode* node); virtual void BookmarkNodeChanged(BookmarkModel* model, - BookmarkNode* node) {} + const BookmarkNode* node) {} virtual void BookmarkNodeChildrenReordered(BookmarkModel* model, - BookmarkNode* node); + const BookmarkNode* node); virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model, - BookmarkNode* node) {} + const BookmarkNode* node) {} // Resets the model of the tree and updates the various buttons appropriately. void Reset(); @@ -117,10 +117,10 @@ class BookmarkEditorGtk : public BookmarkEditor, // that into a GObject that implements the interface GtkTreeModel. // Initial parent to select. Is only used if node_ is NULL. - BookmarkNode* parent_; + const BookmarkNode* parent_; // Node being edited. Is NULL if creating a new node. - BookmarkNode* node_; + const BookmarkNode* node_; // Mode used to create nodes from. BookmarkModel* bb_model_; diff --git a/chrome/browser/gtk/bookmark_editor_gtk_unittest.cc b/chrome/browser/gtk/bookmark_editor_gtk_unittest.cc index ccbd033..7cb3a44 100644 --- a/chrome/browser/gtk/bookmark_editor_gtk_unittest.cc +++ b/chrome/browser/gtk/bookmark_editor_gtk_unittest.cc @@ -48,7 +48,7 @@ class BookmarkEditorGtkTest : public testing::Test { std::string base_path() const { return "file:///c:/tmp/"; } - BookmarkNode* GetNode(const std::string& name) { + const BookmarkNode* GetNode(const std::string& name) { return model_->GetMostRecentlyAddedNodeForURL(GURL(base_path() + name)); } @@ -70,16 +70,18 @@ class BookmarkEditorGtkTest : public testing::Test { model_->AddURL(model_->GetBookmarkBarNode(), 0, L"a", GURL(test_base + "a")); - BookmarkNode* f1 = model_->AddGroup(model_->GetBookmarkBarNode(), 1, L"F1"); + const BookmarkNode* f1 = + model_->AddGroup(model_->GetBookmarkBarNode(), 1, L"F1"); model_->AddURL(f1, 0, L"f1a", GURL(test_base + "f1a")); - BookmarkNode* f11 = model_->AddGroup(f1, 1, L"F11"); + const BookmarkNode* f11 = model_->AddGroup(f1, 1, L"F11"); model_->AddURL(f11, 0, L"f11a", GURL(test_base + "f11a")); model_->AddGroup(model_->GetBookmarkBarNode(), 2, L"F2"); // Children of the other node. model_->AddURL(model_->other_node(), 0, L"oa", GURL(test_base + "oa")); - BookmarkNode* of1 = model_->AddGroup(model_->other_node(), 1, L"OF1"); + const BookmarkNode* of1 = + model_->AddGroup(model_->other_node(), 1, L"OF1"); model_->AddURL(of1, 0, L"of1a", GURL(test_base + "of1a")); } }; @@ -134,7 +136,8 @@ TEST_F(BookmarkEditorGtkTest, EditTitleKeepsPosition) { ASSERT_TRUE(gtk_tree_model_get_iter_first(store, &bookmark_bar_node)); editor.ApplyEdits(&bookmark_bar_node); - BookmarkNode* bb_node = profile_->GetBookmarkModel()->GetBookmarkBarNode(); + const BookmarkNode* bb_node = + profile_->GetBookmarkModel()->GetBookmarkBarNode(); ASSERT_EQ(L"new_a", bb_node->GetChild(0)->GetTitle()); // The URL shouldn't have changed. ASSERT_TRUE(GURL(base_path() + "a") == bb_node->GetChild(0)->GetURL()); @@ -142,8 +145,7 @@ TEST_F(BookmarkEditorGtkTest, EditTitleKeepsPosition) { // Changes the url and makes sure parent/visual order doesn't change. TEST_F(BookmarkEditorGtkTest, EditURLKeepsPosition) { - Time node_time = Time::Now() + TimeDelta::FromDays(2); - GetNode("a")->date_added_ = node_time; + Time node_time = GetNode("a")->date_added(); BookmarkEditorGtk editor(NULL, profile_.get(), NULL, GetNode("a"), BookmarkEditor::SHOW_TREE, NULL); gtk_entry_set_text(GTK_ENTRY(editor.url_entry_), @@ -154,7 +156,8 @@ TEST_F(BookmarkEditorGtkTest, EditURLKeepsPosition) { ASSERT_TRUE(gtk_tree_model_get_iter_first(store, &bookmark_bar_node)); editor.ApplyEdits(&bookmark_bar_node); - BookmarkNode* bb_node = profile_->GetBookmarkModel()->GetBookmarkBarNode(); + const BookmarkNode* bb_node = + profile_->GetBookmarkModel()->GetBookmarkBarNode(); ASSERT_EQ(L"a", bb_node->GetChild(0)->GetTitle()); // The URL should have changed. ASSERT_TRUE(GURL(base_path() + "new_a") == bb_node->GetChild(0)->GetURL()); @@ -172,7 +175,7 @@ TEST_F(BookmarkEditorGtkTest, ChangeParent) { ASSERT_TRUE(gtk_tree_model_iter_next(store, >k_other_node)); editor.ApplyEdits(>k_other_node); - BookmarkNode* other_node = profile_->GetBookmarkModel()->other_node(); + const BookmarkNode* other_node = profile_->GetBookmarkModel()->other_node(); ASSERT_EQ(L"a", other_node->GetChild(2)->GetTitle()); ASSERT_TRUE(GURL(base_path() + "a") == other_node->GetChild(2)->GetURL()); } @@ -180,8 +183,7 @@ TEST_F(BookmarkEditorGtkTest, ChangeParent) { // Moves 'a' to be a child of the other node. // Moves 'a' to be a child of the other node and changes its url to new_a. TEST_F(BookmarkEditorGtkTest, ChangeParentAndURL) { - Time node_time = Time::Now() + TimeDelta::FromDays(2); - GetNode("a")->date_added_ = node_time; + Time node_time = GetNode("a")->date_added(); BookmarkEditorGtk editor(NULL, profile_.get(), NULL, GetNode("a"), BookmarkEditor::SHOW_TREE, NULL); @@ -194,7 +196,7 @@ TEST_F(BookmarkEditorGtkTest, ChangeParentAndURL) { ASSERT_TRUE(gtk_tree_model_iter_next(store, >k_other_node)); editor.ApplyEdits(>k_other_node); - BookmarkNode* other_node = profile_->GetBookmarkModel()->other_node(); + const BookmarkNode* other_node = profile_->GetBookmarkModel()->other_node(); ASSERT_EQ(L"a", other_node->GetChild(2)->GetTitle()); ASSERT_TRUE(GURL(base_path() + "new_a") == other_node->GetChild(2)->GetURL()); ASSERT_TRUE(node_time == other_node->GetChild(2)->date_added()); @@ -230,8 +232,9 @@ TEST_F(BookmarkEditorGtkTest, MoveToNewParent) { editor.ApplyEdits(&f2_iter); - BookmarkNode* bb_node = profile_->GetBookmarkModel()->GetBookmarkBarNode(); - BookmarkNode* mf2 = bb_node->GetChild(1); + const BookmarkNode* bb_node = + profile_->GetBookmarkModel()->GetBookmarkBarNode(); + const BookmarkNode* mf2 = bb_node->GetChild(1); // F2 in the model should have two children now: F21 and the node edited. ASSERT_EQ(2, mf2->GetChildCount()); @@ -241,7 +244,7 @@ TEST_F(BookmarkEditorGtkTest, MoveToNewParent) { ASSERT_EQ(L"a", mf2->GetChild(1)->GetTitle()); // F21 should have one child, F211. - BookmarkNode* mf21 = mf2->GetChild(0); + const BookmarkNode* mf21 = mf2->GetChild(0); ASSERT_EQ(1, mf21->GetChildCount()); ASSERT_EQ(L"F211", mf21->GetChild(0)->GetTitle()); } @@ -260,10 +263,11 @@ TEST_F(BookmarkEditorGtkTest, NewURL) { ASSERT_TRUE(gtk_tree_model_get_iter_first(store, &bookmark_bar_node)); editor.ApplyEdits(&bookmark_bar_node); - BookmarkNode* bb_node = profile_->GetBookmarkModel()->GetBookmarkBarNode(); + const BookmarkNode* bb_node = + profile_->GetBookmarkModel()->GetBookmarkBarNode(); ASSERT_EQ(4, bb_node->GetChildCount()); - BookmarkNode* new_node = bb_node->GetChild(3); + const BookmarkNode* new_node = bb_node->GetChild(3); EXPECT_EQ(L"new_a", new_node->GetTitle()); EXPECT_TRUE(GURL(base_path() + "a") == new_node->GetURL()); } @@ -280,10 +284,10 @@ TEST_F(BookmarkEditorGtkTest, ChangeURLNoTree) { editor.ApplyEdits(NULL); - BookmarkNode* other_node = profile_->GetBookmarkModel()->other_node(); + const BookmarkNode* other_node = profile_->GetBookmarkModel()->other_node(); ASSERT_EQ(2, other_node->GetChildCount()); - BookmarkNode* new_node = other_node->GetChild(0); + const BookmarkNode* new_node = other_node->GetChild(0); EXPECT_EQ(L"new_a", new_node->GetTitle()); EXPECT_TRUE(GURL(base_path() + "a") == new_node->GetURL()); @@ -298,9 +302,9 @@ TEST_F(BookmarkEditorGtkTest, ChangeTitleNoTree) { editor.ApplyEdits(); - BookmarkNode* other_node = profile_->GetBookmarkModel()->other_node(); + const BookmarkNode* other_node = profile_->GetBookmarkModel()->other_node(); ASSERT_EQ(2, other_node->GetChildCount()); - BookmarkNode* new_node = other_node->GetChild(0); + const BookmarkNode* new_node = other_node->GetChild(0); EXPECT_EQ(L"new_a", new_node->GetTitle()); } diff --git a/chrome/browser/gtk/bookmark_manager_gtk.cc b/chrome/browser/gtk/bookmark_manager_gtk.cc index fca5f1f..b1db3ad 100644 --- a/chrome/browser/gtk/bookmark_manager_gtk.cc +++ b/chrome/browser/gtk/bookmark_manager_gtk.cc @@ -72,7 +72,7 @@ class ImportObserverImpl : public ImportObserver { BookmarkModel* model = profile_->GetBookmarkModel(); int other_count = model->other_node()->GetChildCount(); if (other_count == initial_other_count_ + 1) { - BookmarkNode* imported_node = + const BookmarkNode* imported_node = model->other_node()->GetChild(initial_other_count_); manager->SelectInTree(imported_node, true); } @@ -112,7 +112,7 @@ void SetMenuBarStyle() { // BookmarkManager ------------------------------------------------------------- -void BookmarkManager::SelectInTree(Profile* profile, BookmarkNode* node) { +void BookmarkManager::SelectInTree(Profile* profile, const BookmarkNode* node) { if (manager && manager->profile() == profile) manager->SelectInTree(node, false); } @@ -123,7 +123,7 @@ void BookmarkManager::Show(Profile* profile) { // BookmarkManagerGtk, public -------------------------------------------------- -void BookmarkManagerGtk::SelectInTree(BookmarkNode* node, bool expand) { +void BookmarkManagerGtk::SelectInTree(const BookmarkNode* node, bool expand) { GtkTreeIter iter = { 0, }; if (RecursiveFind(GTK_TREE_MODEL(left_store_), &iter, node->id())) { GtkTreePath* path = gtk_tree_model_get_path(GTK_TREE_MODEL(left_store_), @@ -160,9 +160,9 @@ void BookmarkManagerGtk::BookmarkModelBeingDeleted(BookmarkModel* model) { } void BookmarkManagerGtk::BookmarkNodeMoved(BookmarkModel* model, - BookmarkNode* old_parent, + const BookmarkNode* old_parent, int old_index, - BookmarkNode* new_parent, + const BookmarkNode* new_parent, int new_index) { BookmarkNodeRemoved(model, old_parent, old_index, new_parent->GetChild(new_index)); @@ -170,9 +170,9 @@ void BookmarkManagerGtk::BookmarkNodeMoved(BookmarkModel* model, } void BookmarkManagerGtk::BookmarkNodeAdded(BookmarkModel* model, - BookmarkNode* parent, + const BookmarkNode* parent, int index) { - BookmarkNode* node = parent->GetChild(index); + const BookmarkNode* node = parent->GetChild(index); if (node->is_folder()) { GtkTreeIter iter = { 0, }; if (RecursiveFind(GTK_TREE_MODEL(left_store_), &iter, parent->id())) @@ -181,15 +181,15 @@ void BookmarkManagerGtk::BookmarkNodeAdded(BookmarkModel* model, } void BookmarkManagerGtk::BookmarkNodeRemoved(BookmarkModel* model, - BookmarkNode* parent, + const BookmarkNode* parent, int index) { NOTREACHED(); } void BookmarkManagerGtk::BookmarkNodeRemoved(BookmarkModel* model, - BookmarkNode* parent, + const BookmarkNode* parent, int old_index, - BookmarkNode* node) { + const BookmarkNode* node) { if (node->is_folder()) { GtkTreeIter iter = { 0, }; if (RecursiveFind(GTK_TREE_MODEL(left_store_), &iter, node->id())) { @@ -207,17 +207,17 @@ void BookmarkManagerGtk::BookmarkNodeRemoved(BookmarkModel* model, } void BookmarkManagerGtk::BookmarkNodeChanged(BookmarkModel* model, - BookmarkNode* node) { + const BookmarkNode* node) { // TODO(estade): rename in the left tree view. } -void BookmarkManagerGtk::BookmarkNodeChildrenReordered(BookmarkModel* model, - BookmarkNode* node) { +void BookmarkManagerGtk::BookmarkNodeChildrenReordered( + BookmarkModel* model, const BookmarkNode* node) { // TODO(estade): reorder in the left tree view. } void BookmarkManagerGtk::BookmarkNodeFavIconLoaded(BookmarkModel* model, - BookmarkNode* node) { + const BookmarkNode* node) { // I don't think we have anything to do, as we should never get this for a // folder node and we handle it via OnItemsChanged for any URL node. } @@ -473,8 +473,8 @@ GtkWidget* BookmarkManagerGtk::MakeRightPane() { void BookmarkManagerGtk::ResetOrganizeMenu(bool left) { organize_is_for_left_ = left; - BookmarkNode* parent = GetFolder(); - std::vector<BookmarkNode*> nodes; + const BookmarkNode* parent = GetFolder(); + std::vector<const BookmarkNode*> nodes; if (!left) nodes = GetRightSelection(); else if (parent) @@ -520,7 +520,7 @@ void BookmarkManagerGtk::BuildLeftStore() { } void BookmarkManagerGtk::BuildRightStore() { - BookmarkNode* node = GetFolder(); + const BookmarkNode* node = GetFolder(); gtk_list_store_clear(right_store_); @@ -574,8 +574,8 @@ int BookmarkManagerGtk::GetRowIDAt(GtkTreeModel* model, GtkTreeIter* iter) { return id; } -BookmarkNode* BookmarkManagerGtk::GetNodeAt(GtkTreeModel* model, - GtkTreeIter* iter) { +const BookmarkNode* BookmarkManagerGtk::GetNodeAt(GtkTreeModel* model, + GtkTreeIter* iter) { int id = GetRowIDAt(model, iter); if (id > 0) return model_->GetNodeByID(id); @@ -583,7 +583,7 @@ BookmarkNode* BookmarkManagerGtk::GetNodeAt(GtkTreeModel* model, return NULL; } -BookmarkNode* BookmarkManagerGtk::GetFolder() { +const BookmarkNode* BookmarkManagerGtk::GetFolder() { GtkTreeModel* model; GtkTreeIter iter; if (!gtk_tree_selection_get_selected(left_selection(), &model, &iter)) @@ -598,11 +598,11 @@ int BookmarkManagerGtk::GetSelectedRowID() { return GetRowIDAt(model, &iter); } -std::vector<BookmarkNode*> BookmarkManagerGtk::GetRightSelection() { +std::vector<const BookmarkNode*> BookmarkManagerGtk::GetRightSelection() { GtkTreeModel* model; GList* paths = gtk_tree_selection_get_selected_rows(right_selection(), &model); - std::vector<BookmarkNode*> nodes; + std::vector<const BookmarkNode*> nodes; for (GList* item = paths; item; item = item->next) { GtkTreeIter iter; gtk_tree_model_get_iter(model, &iter, @@ -617,7 +617,7 @@ std::vector<BookmarkNode*> BookmarkManagerGtk::GetRightSelection() { void BookmarkManagerGtk::SetRightSideColumnValues(int row, GtkTreeIter* iter) { // TODO(estade): building the path could be optimized out when we aren't // showing the path column. - BookmarkNode* node = right_tree_model_->GetNodeForRow(row); + const BookmarkNode* node = right_tree_model_->GetNodeForRow(row); GdkPixbuf* pixbuf = bookmark_utils::GetPixbufForNode(node, model_); std::wstring title = right_tree_model_->GetText(row, IDS_BOOKMARK_TABLE_TITLE); @@ -742,7 +742,7 @@ void BookmarkManagerGtk::OnLeftTreeViewDragReceived( gboolean dnd_success = FALSE; gboolean delete_selection_data = FALSE; - std::vector<BookmarkNode*> nodes = + std::vector<const BookmarkNode*> nodes = bookmark_utils::GetNodesFromSelection(context, selection_data, target_type, bm->profile_, @@ -765,8 +765,9 @@ void BookmarkManagerGtk::OnLeftTreeViewDragReceived( GtkTreeIter iter; gtk_tree_model_get_iter(GTK_TREE_MODEL(bm->left_store_), &iter, path); - BookmarkNode* folder = bm->GetNodeAt(GTK_TREE_MODEL(bm->left_store_), &iter); - for (std::vector<BookmarkNode*>::iterator it = nodes.begin(); + const BookmarkNode* folder = bm->GetNodeAt( + GTK_TREE_MODEL(bm->left_store_), &iter); + for (std::vector<const BookmarkNode*>::iterator it = nodes.begin(); it != nodes.end(); ++it) { // Don't try to drop a node into one of its descendants. if (!folder->HasAncestor(*it)) @@ -836,7 +837,7 @@ void BookmarkManagerGtk::OnRightTreeViewDragReceived( gboolean dnd_success = FALSE; gboolean delete_selection_data = FALSE; - std::vector<BookmarkNode*> nodes = + std::vector<const BookmarkNode*> nodes = bookmark_utils::GetNodesFromSelection(context, selection_data, target_type, bm->profile_, @@ -857,7 +858,7 @@ void BookmarkManagerGtk::OnRightTreeViewDragReceived( bool drop_after = pos == GTK_TREE_VIEW_DROP_AFTER; // The parent folder and index therein to drop the nodes. - BookmarkNode* parent = NULL; + const BookmarkNode* parent = NULL; int idx = -1; // |path| will be null when we are looking at an empty folder. @@ -865,7 +866,7 @@ void BookmarkManagerGtk::OnRightTreeViewDragReceived( GtkTreeIter iter; GtkTreeModel* model = GTK_TREE_MODEL(bm->right_store_); gtk_tree_model_get_iter(model, &iter, path); - BookmarkNode* node = bm->GetNodeAt(model, &iter); + const BookmarkNode* node = bm->GetNodeAt(model, &iter); if (node->is_folder()) { parent = node; idx = parent->GetChildCount(); @@ -883,7 +884,7 @@ void BookmarkManagerGtk::OnRightTreeViewDragReceived( idx = !path ? parent->GetChildCount() : gtk_tree_path_get_indices(path)[0]; } - for (std::vector<BookmarkNode*>::iterator it = nodes.begin(); + for (std::vector<const BookmarkNode*>::iterator it = nodes.begin(); it != nodes.end(); ++it) { // Don't try to drop a node into one of its descendants. if (!parent->HasAncestor(*it)) { @@ -913,7 +914,7 @@ gboolean BookmarkManagerGtk::OnRightTreeViewDragMotion( gtk_tree_view_get_dest_row_at_pos(GTK_TREE_VIEW(tree_view), x, y, &path, &pos); - BookmarkNode* parent = bm->GetFolder(); + const BookmarkNode* parent = bm->GetFolder(); if (path) { int idx = gtk_tree_path_get_indices(path)[gtk_tree_path_get_depth(path) - 1]; @@ -937,7 +938,7 @@ gboolean BookmarkManagerGtk::OnRightTreeViewDragMotion( // static void BookmarkManagerGtk::OnRightTreeViewRowActivated(GtkTreeView* tree_view, GtkTreePath* path, GtkTreeViewColumn* column, BookmarkManagerGtk* bm) { - std::vector<BookmarkNode*> nodes = bm->GetRightSelection(); + std::vector<const BookmarkNode*> nodes = bm->GetRightSelection(); if (nodes.empty()) return; if (nodes.size() == 1 && nodes[0]->is_folder()) { diff --git a/chrome/browser/gtk/bookmark_manager_gtk.h b/chrome/browser/gtk/bookmark_manager_gtk.h index 1ef9041..64586b1 100644 --- a/chrome/browser/gtk/bookmark_manager_gtk.h +++ b/chrome/browser/gtk/bookmark_manager_gtk.h @@ -28,7 +28,7 @@ class BookmarkManagerGtk : public BookmarkModelObserver, Profile* profile() { return profile_; } // Show the node in the tree. - void SelectInTree(BookmarkNode* node, bool expand); + void SelectInTree(const BookmarkNode* node, bool expand); // Shows the bookmark manager. Only one bookmark manager exists. static void Show(Profile* profile); @@ -39,26 +39,26 @@ class BookmarkManagerGtk : public BookmarkModelObserver, virtual void Loaded(BookmarkModel* model); virtual void BookmarkModelBeingDeleted(BookmarkModel* model); virtual void BookmarkNodeMoved(BookmarkModel* model, - BookmarkNode* old_parent, + const BookmarkNode* old_parent, int old_index, - BookmarkNode* new_parent, + const BookmarkNode* new_parent, int new_index); virtual void BookmarkNodeAdded(BookmarkModel* model, - BookmarkNode* parent, + const BookmarkNode* parent, int index); virtual void BookmarkNodeRemoved(BookmarkModel* model, - BookmarkNode* parent, + const BookmarkNode* parent, int index); virtual void BookmarkNodeRemoved(BookmarkModel* model, - BookmarkNode* parent, + const BookmarkNode* parent, int old_index, - BookmarkNode* node); + const BookmarkNode* node); virtual void BookmarkNodeChanged(BookmarkModel* model, - BookmarkNode* node); + const BookmarkNode* node); virtual void BookmarkNodeChildrenReordered(BookmarkModel* model, - BookmarkNode* node); + const BookmarkNode* node); virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model, - BookmarkNode* node); + const BookmarkNode* node); // TableModelObserver implementation. virtual void OnModelChanged(); @@ -93,16 +93,16 @@ class BookmarkManagerGtk : public BookmarkModelObserver, // Get the node from |model| at |iter|. If the item is not a node, return // NULL. - BookmarkNode* GetNodeAt(GtkTreeModel* model, GtkTreeIter* iter); + const BookmarkNode* GetNodeAt(GtkTreeModel* model, GtkTreeIter* iter); // Get the node that is selected in the left tree view. - BookmarkNode* GetFolder(); + const BookmarkNode* GetFolder(); // Get the ID of the selected row. int GetSelectedRowID(); // Get the nodes that are selected in the right tree view. - std::vector<BookmarkNode*> GetRightSelection(); + std::vector<const BookmarkNode*> GetRightSelection(); // Set the fields for a row. void SetRightSideColumnValues(int row, GtkTreeIter* iter); diff --git a/chrome/browser/gtk/bookmark_menu_controller_gtk.cc b/chrome/browser/gtk/bookmark_menu_controller_gtk.cc index 68b4ffdf..a0d905b 100644 --- a/chrome/browser/gtk/bookmark_menu_controller_gtk.cc +++ b/chrome/browser/gtk/bookmark_menu_controller_gtk.cc @@ -29,18 +29,22 @@ void SetImageMenuItem(GtkWidget* menu_item, const SkBitmap& bitmap) { g_object_unref(pixbuf); } -BookmarkNode* GetNodeFromMenuItem(GtkWidget* menu_item) { - return static_cast<BookmarkNode*>( +const BookmarkNode* GetNodeFromMenuItem(GtkWidget* menu_item) { + return static_cast<const BookmarkNode*>( g_object_get_data(G_OBJECT(menu_item), "bookmark-node")); } +void* AsVoid(const BookmarkNode* node) { + return const_cast<BookmarkNode*>(node); +} + } // namespace BookmarkMenuController::BookmarkMenuController(Browser* browser, Profile* profile, PageNavigator* navigator, GtkWindow* window, - BookmarkNode* node, + const BookmarkNode* node, int start_child_index, bool show_other_folder) : browser_(browser), @@ -71,9 +75,9 @@ void BookmarkMenuController::BookmarkModelChanged() { gtk_menu_popdown(GTK_MENU(menu_.get())); } -void BookmarkMenuController::BookmarkNodeFavIconLoaded(BookmarkModel* model, - BookmarkNode* node) { - std::map<BookmarkNode*, GtkWidget*>::iterator it = +void BookmarkMenuController::BookmarkNodeFavIconLoaded( + BookmarkModel* model, const BookmarkNode* node) { + std::map<const BookmarkNode*, GtkWidget*>::iterator it = node_to_menu_widget_map_.find(node); if (it != node_to_menu_widget_map_.end()) SetImageMenuItem(it->second, model->GetFavIcon(node)); @@ -82,20 +86,20 @@ void BookmarkMenuController::BookmarkNodeFavIconLoaded(BookmarkModel* model, void BookmarkMenuController::NavigateToMenuItem( GtkWidget* menu_item, WindowOpenDisposition disposition) { - BookmarkNode* node = GetNodeFromMenuItem(menu_item); + const BookmarkNode* node = GetNodeFromMenuItem(menu_item); DCHECK(node); DCHECK(page_navigator_); page_navigator_->OpenURL( node->GetURL(), GURL(), disposition, PageTransition::AUTO_BOOKMARK); } -void BookmarkMenuController::BuildMenu(BookmarkNode* parent, +void BookmarkMenuController::BuildMenu(const BookmarkNode* parent, int start_child_index, GtkWidget* menu) { DCHECK(!parent->GetChildCount() || start_child_index < parent->GetChildCount()); for (int i = start_child_index; i < parent->GetChildCount(); ++i) { - BookmarkNode* node = parent->GetChild(i); + const BookmarkNode* node = parent->GetChild(i); GtkWidget* menu_item = gtk_image_menu_item_new_with_label( WideToUTF8(node->GetTitle()).c_str()); @@ -107,7 +111,7 @@ void BookmarkMenuController::BuildMenu(BookmarkNode* parent, GetBitmapNamed(IDR_DEFAULT_FAVICON); } SetImageMenuItem(menu_item, icon); - g_object_set_data(G_OBJECT(menu_item), "bookmark-node", node); + g_object_set_data(G_OBJECT(menu_item), "bookmark-node", AsVoid(node)); g_signal_connect(G_OBJECT(menu_item), "activate", G_CALLBACK(OnMenuItemActivated), this); g_signal_connect(G_OBJECT(menu_item), "button-press-event", @@ -144,9 +148,9 @@ gboolean BookmarkMenuController::OnButtonPressed( BookmarkMenuController* controller) { if (event->button == 3) { // Show the right click menu and stop processing this button event. - BookmarkNode* node = GetNodeFromMenuItem(sender); - BookmarkNode* parent = node->GetParent(); - std::vector<BookmarkNode*> nodes; + const BookmarkNode* node = GetNodeFromMenuItem(sender); + const BookmarkNode* parent = node->GetParent(); + std::vector<const BookmarkNode*> nodes; nodes.push_back(node); controller->context_menu_.reset( new BookmarkContextMenu( diff --git a/chrome/browser/gtk/bookmark_menu_controller_gtk.h b/chrome/browser/gtk/bookmark_menu_controller_gtk.h index 4d8e7b5..07993c4 100644 --- a/chrome/browser/gtk/bookmark_menu_controller_gtk.h +++ b/chrome/browser/gtk/bookmark_menu_controller_gtk.h @@ -29,7 +29,7 @@ class BookmarkMenuController : public BaseBookmarkModelObserver { Profile* profile, PageNavigator* page_navigator, GtkWindow* window, - BookmarkNode* node, + const BookmarkNode* node, int start_child_index, bool show_other_folder); virtual ~BookmarkMenuController(); @@ -40,12 +40,12 @@ class BookmarkMenuController : public BaseBookmarkModelObserver { // Overridden from BaseBookmarkModelObserver: virtual void BookmarkModelChanged(); virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model, - BookmarkNode* node); + const BookmarkNode* node); private: // Recursively change the bookmark hierarchy rooted in |parent| into a set of // gtk menus rooted in |menu|. - void BuildMenu(BookmarkNode* parent, + void BuildMenu(const BookmarkNode* parent, int start_child_index, GtkWidget* menu); @@ -80,7 +80,7 @@ class BookmarkMenuController : public BaseBookmarkModelObserver { BookmarkModel* model_; // The node we're showing the contents of. - BookmarkNode* node_; + const BookmarkNode* node_; // Our bookmark menus. We don't use the MenuGtk class because we have to do // all sorts of weird non-standard things with this menu, like: @@ -90,7 +90,7 @@ class BookmarkMenuController : public BaseBookmarkModelObserver { // Mapping from node to GtkMenuItem menu id. This only contains entries for // nodes of type URL. - std::map<BookmarkNode*, GtkWidget*> node_to_menu_widget_map_; + std::map<const BookmarkNode*, GtkWidget*> node_to_menu_widget_map_; // Owns our right click context menu. scoped_ptr<BookmarkContextMenu> context_menu_; diff --git a/chrome/browser/gtk/bookmark_tree_model.cc b/chrome/browser/gtk/bookmark_tree_model.cc index 14f7471..ab3b24e 100644 --- a/chrome/browser/gtk/bookmark_tree_model.cc +++ b/chrome/browser/gtk/bookmark_tree_model.cc @@ -13,7 +13,7 @@ namespace { -void AddSingleNodeToTreeStore(GtkTreeStore* store, BookmarkNode* node, +void AddSingleNodeToTreeStore(GtkTreeStore* store, const BookmarkNode* node, GtkTreeIter *iter, GtkTreeIter* parent) { gtk_tree_store_append(store, iter, parent); // TODO(estade): we should show the folder open icon when it's expanded. @@ -29,10 +29,10 @@ void AddSingleNodeToTreeStore(GtkTreeStore* store, BookmarkNode* node, // Helper function for CommitTreeStoreDifferencesBetween() which recursively // merges changes back from a GtkTreeStore into a tree of BookmarkNodes. This // function only works on non-root nodes; our caller handles that special case. -void RecursiveResolve(BookmarkModel* bb_model, BookmarkNode* bb_node, +void RecursiveResolve(BookmarkModel* bb_model, const BookmarkNode* bb_node, GtkTreeModel* tree_model, GtkTreeIter* parent_iter, GtkTreePath* selected_path, - BookmarkNode** selected_node) { + const BookmarkNode** selected_node) { GtkTreePath* current_path = gtk_tree_model_get_path(tree_model, parent_iter); if (gtk_tree_path_compare(current_path, selected_path) == 0) *selected_node = bb_node; @@ -44,7 +44,7 @@ void RecursiveResolve(BookmarkModel* bb_model, BookmarkNode* bb_node, int id = bookmark_utils::GetIdFromTreeIter(tree_model, &child_iter); std::wstring title = bookmark_utils::GetTitleFromTreeIter(tree_model, &child_iter); - BookmarkNode* child_bb_node = NULL; + const BookmarkNode* child_bb_node = NULL; if (id == 0) { child_bb_node = bb_model->AddGroup(bb_node, bb_node->GetChildCount(), title); @@ -52,7 +52,7 @@ void RecursiveResolve(BookmarkModel* bb_model, BookmarkNode* bb_node, // Existing node, reset the title (BBModel ignores changes if the title // is the same). for (int j = 0; j < bb_node->GetChildCount(); ++j) { - BookmarkNode* node = bb_node->GetChild(j); + const BookmarkNode* node = bb_node->GetChild(j); if (node->is_folder() && node->id() == id) { child_bb_node = node; break; @@ -79,14 +79,14 @@ GtkTreeStore* MakeFolderTreeStore() { void AddToTreeStore(BookmarkModel* model, int selected_id, GtkTreeStore* store, GtkTreeIter* selected_iter) { - BookmarkNode* root_node = model->root_node(); + const BookmarkNode* root_node = model->root_node(); for (int i = 0; i < root_node->GetChildCount(); ++i) { AddToTreeStoreAt(root_node->GetChild(i), selected_id, store, selected_iter, NULL); } } -void AddToTreeStoreAt(BookmarkNode* node, int selected_id, +void AddToTreeStoreAt(const BookmarkNode* node, int selected_id, GtkTreeStore* store, GtkTreeIter* selected_iter, GtkTreeIter* parent) { if (!node->is_folder()) @@ -107,9 +107,9 @@ void AddToTreeStoreAt(BookmarkNode* node, int selected_id, } } -BookmarkNode* CommitTreeStoreDifferencesBetween( +const BookmarkNode* CommitTreeStoreDifferencesBetween( BookmarkModel* bb_model, GtkTreeStore* tree_store, GtkTreeIter* selected) { - BookmarkNode* node_to_return = NULL; + const BookmarkNode* node_to_return = NULL; GtkTreeModel* tree_model = GTK_TREE_MODEL(tree_store); GtkTreePath* selected_path = gtk_tree_model_get_path(tree_model, selected); @@ -123,15 +123,15 @@ BookmarkNode* CommitTreeStoreDifferencesBetween( // set of top level nodes that are the root BookmarksNode's children. These // items in the top level are not editable and therefore don't need the extra // complexity of trying to modify their title. - BookmarkNode* root_node = bb_model->root_node(); + const BookmarkNode* root_node = bb_model->root_node(); do { DCHECK(GetIdFromTreeIter(tree_model, &tree_root) != 0) << "It should be impossible to add another toplevel node"; int id = GetIdFromTreeIter(tree_model, &tree_root); - BookmarkNode* child_node = NULL; + const BookmarkNode* child_node = NULL; for (int j = 0; j < root_node->GetChildCount(); ++j) { - BookmarkNode* node = root_node->GetChild(j); + const BookmarkNode* node = root_node->GetChild(j); if (node->is_folder() && node->id() == id) { child_node = node; break; diff --git a/chrome/browser/gtk/bookmark_tree_model.h b/chrome/browser/gtk/bookmark_tree_model.h index 4ca0c5b..c691212 100644 --- a/chrome/browser/gtk/bookmark_tree_model.h +++ b/chrome/browser/gtk/bookmark_tree_model.h @@ -41,14 +41,14 @@ void AddToTreeStore(BookmarkModel* model, int selected_id, // As above, but inserts just the tree rooted at |node| as a child of |parent|. // If |parent| is NULL, add it at the top level. -void AddToTreeStoreAt(BookmarkNode* node, int selected_id, +void AddToTreeStoreAt(const BookmarkNode* node, int selected_id, GtkTreeStore* store, GtkTreeIter* selected_iter, GtkTreeIter* parent); // Commits changes to a GtkTreeStore built from BuildTreeStoreFrom() back // into the BookmarkModel it was generated from. Returns the BookmarkNode that // represented by |selected|. -BookmarkNode* CommitTreeStoreDifferencesBetween( +const BookmarkNode* CommitTreeStoreDifferencesBetween( BookmarkModel* model, GtkTreeStore* tree_store, GtkTreeIter* selected); diff --git a/chrome/browser/gtk/bookmark_utils_gtk.cc b/chrome/browser/gtk/bookmark_utils_gtk.cc index 313dca4..4551794 100644 --- a/chrome/browser/gtk/bookmark_utils_gtk.cc +++ b/chrome/browser/gtk/bookmark_utils_gtk.cc @@ -48,7 +48,7 @@ GdkPixbuf* GetDefaultFavicon() { return default_bookmark_icon; } -GdkPixbuf* GetPixbufForNode(BookmarkNode* node, BookmarkModel* model) { +GdkPixbuf* GetPixbufForNode(const BookmarkNode* node, BookmarkModel* model) { GdkPixbuf* pixbuf; if (node->is_url()) { @@ -68,17 +68,17 @@ GdkPixbuf* GetPixbufForNode(BookmarkNode* node, BookmarkModel* model) { // DnD-related ----------------------------------------------------------------- -void WriteBookmarkToSelection(BookmarkNode* node, +void WriteBookmarkToSelection(const BookmarkNode* node, GtkSelectionData* selection_data, guint target_type, Profile* profile) { DCHECK(node); - std::vector<BookmarkNode*> nodes; + std::vector<const BookmarkNode*> nodes; nodes.push_back(node); WriteBookmarksToSelection(nodes, selection_data, target_type, profile); } -void WriteBookmarksToSelection(const std::vector<BookmarkNode*>& nodes, +void WriteBookmarksToSelection(const std::vector<const BookmarkNode*>& nodes, GtkSelectionData* selection_data, guint target_type, Profile* profile) { @@ -100,7 +100,7 @@ void WriteBookmarksToSelection(const std::vector<BookmarkNode*>& nodes, } } -std::vector<BookmarkNode*> GetNodesFromSelection( +std::vector<const BookmarkNode*> GetNodesFromSelection( GdkDragContext* context, GtkSelectionData* selection_data, guint target_type, @@ -130,7 +130,7 @@ std::vector<BookmarkNode*> GetNodesFromSelection( } } - return std::vector<BookmarkNode*>(); + return std::vector<const BookmarkNode*>(); } } // namespace bookmark_utils diff --git a/chrome/browser/gtk/bookmark_utils_gtk.h b/chrome/browser/gtk/bookmark_utils_gtk.h index 819748c..32fe615 100644 --- a/chrome/browser/gtk/bookmark_utils_gtk.h +++ b/chrome/browser/gtk/bookmark_utils_gtk.h @@ -25,25 +25,25 @@ GdkPixbuf* GetDefaultFavicon(); // Get the image that is used to represent the node. This function adds a ref // to the returned pixbuf, so it requires a matching call to g_object_unref(). -GdkPixbuf* GetPixbufForNode(BookmarkNode* node, BookmarkModel* model); +GdkPixbuf* GetPixbufForNode(const BookmarkNode* node, BookmarkModel* model); // Drag and drop. -------------------------------------------------------------- // Pickle a node into a GtkSelection. -void WriteBookmarkToSelection(BookmarkNode* node, +void WriteBookmarkToSelection(const BookmarkNode* node, GtkSelectionData* selection_data, guint target_type, Profile* profile); // Pickle a vector of nodes into a GtkSelection. -void WriteBookmarksToSelection(const std::vector<BookmarkNode*>& nodes, +void WriteBookmarksToSelection(const std::vector<const BookmarkNode*>& nodes, GtkSelectionData* selection_data, guint target_type, Profile* profile); // Un-pickle node(s) from a GtkSelection. // The last two arguments are out parameters. -std::vector<BookmarkNode*> GetNodesFromSelection( +std::vector<const BookmarkNode*> GetNodesFromSelection( GdkDragContext* context, GtkSelectionData* selection_data, guint target_type, |