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/views | |
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/views')
21 files changed, 272 insertions, 253 deletions
diff --git a/chrome/browser/views/bookmark_bar_view.cc b/chrome/browser/views/bookmark_bar_view.cc index 0483ca6..459e4c2 100644 --- a/chrome/browser/views/bookmark_bar_view.cc +++ b/chrome/browser/views/bookmark_bar_view.cc @@ -740,7 +740,7 @@ int BookmarkBarView::OnDragUpdated(const DropTargetEvent& event) { } if (drop_on || is_over_overflow || is_over_other) { - BookmarkNode* node; + const BookmarkNode* node; if (is_over_other) node = model_->other_node(); else if (is_over_overflow) @@ -777,8 +777,9 @@ int BookmarkBarView::OnPerformDrop(const DropTargetEvent& event) { if (!drop_info_.get() || !drop_info_->drag_operation) return DragDropTypes::DRAG_NONE; - BookmarkNode* root = drop_info_->is_over_other ? model_->other_node() : - model_->GetBookmarkBarNode(); + const BookmarkNode* root = + drop_info_->is_over_other ? model_->other_node() : + model_->GetBookmarkBarNode(); int index = drop_info_->drop_index; const bool drop_on = drop_info_->drop_on; const BookmarkDragData data = drop_info_->data; @@ -791,7 +792,7 @@ int BookmarkBarView::OnPerformDrop(const DropTargetEvent& event) { } drop_info_.reset(); - BookmarkNode* parent_node; + const BookmarkNode* parent_node; if (is_over_other) { parent_node = root; index = parent_node->GetChildCount(); @@ -928,7 +929,7 @@ int BookmarkBarView::GetBookmarkButtonCount() { } void BookmarkBarView::Loaded(BookmarkModel* model) { - BookmarkNode* node = model_->GetBookmarkBarNode(); + const BookmarkNode* node = model_->GetBookmarkBarNode(); DCHECK(node && model_->other_node()); // Create a button for each of the children on the bookmark bar. for (int i = 0; i < node->GetChildCount(); ++i) @@ -960,9 +961,9 @@ void BookmarkBarView::BookmarkModelBeingDeleted(BookmarkModel* model) { } void BookmarkBarView::BookmarkNodeMoved(BookmarkModel* model, - BookmarkNode* old_parent, + const BookmarkNode* old_parent, int old_index, - BookmarkNode* new_parent, + const BookmarkNode* new_parent, int new_index) { StopThrobbing(true); BookmarkNodeRemovedImpl(model, old_parent, old_index); @@ -971,7 +972,7 @@ void BookmarkBarView::BookmarkNodeMoved(BookmarkModel* model, } void BookmarkBarView::BookmarkNodeAdded(BookmarkModel* model, - BookmarkNode* parent, + const BookmarkNode* parent, int index) { StopThrobbing(true); BookmarkNodeAddedImpl(model, parent, index); @@ -979,7 +980,7 @@ void BookmarkBarView::BookmarkNodeAdded(BookmarkModel* model, } void BookmarkBarView::BookmarkNodeAddedImpl(BookmarkModel* model, - BookmarkNode* parent, + const BookmarkNode* parent, int index) { NotifyModelChanged(); if (parent != model_->GetBookmarkBarNode()) { @@ -993,7 +994,7 @@ void BookmarkBarView::BookmarkNodeAddedImpl(BookmarkModel* model, } void BookmarkBarView::BookmarkNodeRemoved(BookmarkModel* model, - BookmarkNode* parent, + const BookmarkNode* parent, int index) { StopThrobbing(true); BookmarkNodeRemovedImpl(model, parent, index); @@ -1001,7 +1002,7 @@ void BookmarkBarView::BookmarkNodeRemoved(BookmarkModel* model, } void BookmarkBarView::BookmarkNodeRemovedImpl(BookmarkModel* model, - BookmarkNode* parent, + const BookmarkNode* parent, int index) { StopThrobbing(true); // No need to start throbbing again as the bookmark bubble can't be up at @@ -1021,13 +1022,13 @@ void BookmarkBarView::BookmarkNodeRemovedImpl(BookmarkModel* model, } void BookmarkBarView::BookmarkNodeChanged(BookmarkModel* model, - BookmarkNode* node) { + const BookmarkNode* node) { NotifyModelChanged(); BookmarkNodeChangedImpl(model, node); } void BookmarkBarView::BookmarkNodeChangedImpl(BookmarkModel* model, - BookmarkNode* node) { + const BookmarkNode* node) { if (node->GetParent() != model_->GetBookmarkBarNode()) { // We only care about nodes on the bookmark bar. return; @@ -1047,7 +1048,7 @@ void BookmarkBarView::BookmarkNodeChangedImpl(BookmarkModel* model, } void BookmarkBarView::BookmarkNodeChildrenReordered(BookmarkModel* model, - BookmarkNode* node) { + const BookmarkNode* node) { NotifyModelChanged(); if (node != model_->GetBookmarkBarNode()) return; // We only care about reordering of the bookmark bar node. @@ -1068,7 +1069,7 @@ void BookmarkBarView::BookmarkNodeChildrenReordered(BookmarkModel* model, } void BookmarkBarView::BookmarkNodeFavIconLoaded(BookmarkModel* model, - BookmarkNode* node) { + const BookmarkNode* node) { BookmarkNodeChangedImpl(model, node); } @@ -1093,7 +1094,7 @@ void BookmarkBarView::WriteDragData(View* sender, NOTREACHED(); } -void BookmarkBarView::WriteDragData(BookmarkNode* node, +void BookmarkBarView::WriteDragData(const BookmarkNode* node, OSExchangeData* data) { DCHECK(node && data); BookmarkDragData drag_data(node); @@ -1123,7 +1124,7 @@ int BookmarkBarView::GetDragOperations(View* sender, int x, int y) { void BookmarkBarView::RunMenu(views::View* view, const gfx::Point& pt, gfx::NativeView hwnd) { - BookmarkNode* node; + const BookmarkNode* node; MenuItemView::AnchorPosition anchor_point = MenuItemView::TOPLEFT; // When we set the menu's position, we must take into account the mirrored @@ -1176,7 +1177,7 @@ void BookmarkBarView::RunMenu(views::View* view, } void BookmarkBarView::ButtonPressed(views::Button* sender) { - BookmarkNode* node; + const BookmarkNode* node; if (sender->tag() == kOtherFolderButtonTag) { node = model_->other_node(); } else { @@ -1214,8 +1215,8 @@ void BookmarkBarView::ShowContextMenu(View* source, return; } - BookmarkNode* parent = NULL; - std::vector<BookmarkNode*> nodes; + const BookmarkNode* parent = NULL; + std::vector<const BookmarkNode*> nodes; if (source == other_bookmarked_button_) { parent = model_->other_node(); // Do this so the user can open all bookmarks. BookmarkContextMenu makes @@ -1227,7 +1228,7 @@ void BookmarkBarView::ShowContextMenu(View* source, int bookmark_button_index = GetChildIndex(source); DCHECK(bookmark_button_index != -1 && bookmark_button_index < GetBookmarkButtonCount()); - BookmarkNode* node = + const BookmarkNode* node = model_->GetBookmarkBarNode()->GetChild(bookmark_button_index); nodes.push_back(node); parent = node->GetParent(); @@ -1242,7 +1243,7 @@ void BookmarkBarView::ShowContextMenu(View* source, controller.RunMenuAt(x, y); } -views::View* BookmarkBarView::CreateBookmarkButton(BookmarkNode* node) { +views::View* BookmarkBarView::CreateBookmarkButton(const BookmarkNode* node) { if (node->is_url()) { BookmarkButton* button = new BookmarkButton(this, node->GetURL(), @@ -1259,7 +1260,7 @@ views::View* BookmarkBarView::CreateBookmarkButton(BookmarkNode* node) { } } -void BookmarkBarView::ConfigureButton(BookmarkNode* node, +void BookmarkBarView::ConfigureButton(const BookmarkNode* node, views::TextButton* button) { button->SetText(node->GetTitle()); @@ -1325,7 +1326,7 @@ void BookmarkBarView::NotifyModelChanged() { model_changed_listener_->ModelChanged(); } -void BookmarkBarView::ShowDropFolderForNode(BookmarkNode* node) { +void BookmarkBarView::ShowDropFolderForNode(const BookmarkNode* node) { if (bookmark_drop_menu_) { if (bookmark_drop_menu_->node() == node) { // Already showing for the specified node. @@ -1388,7 +1389,7 @@ void BookmarkBarView::StopShowFolderDropMenuTimer() { show_folder_drop_menu_task_->Cancel(); } -void BookmarkBarView::StartShowFolderDropMenuTimer(BookmarkNode* node) { +void BookmarkBarView::StartShowFolderDropMenuTimer(const BookmarkNode* node) { if (testing_) { // So that tests can run as fast as possible disable the delay during // testing. @@ -1462,7 +1463,7 @@ int BookmarkBarView::CalculateDropOperation(const DropTargetEvent& event, int button_w = button->width(); if (button_x < button_w) { found = true; - BookmarkNode* node = model_->GetBookmarkBarNode()->GetChild(i); + const BookmarkNode* node = model_->GetBookmarkBarNode()->GetChild(i); if (node->is_folder()) { if (button_x <= views::kDropBetweenPixels) { *index = i; @@ -1507,7 +1508,7 @@ int BookmarkBarView::CalculateDropOperation(const DropTargetEvent& event, } if (*drop_on) { - BookmarkNode* parent = + const BookmarkNode* parent = *is_over_other ? model_->other_node() : model_->GetBookmarkBarNode()->GetChild(*index); int operation = @@ -1544,15 +1545,16 @@ void BookmarkBarView::StartThrobbing() { if (!GetWidget()) return; // We're not showing, don't do anything. - BookmarkNode* node = model_->GetMostRecentlyAddedNodeForURL(bubble_url_); + const BookmarkNode* node = + model_->GetMostRecentlyAddedNodeForURL(bubble_url_); if (!node) return; // Generally shouldn't happen. // Determine which visible button is showing the url (or is an ancestor of // the url). if (node->HasAncestor(model_->GetBookmarkBarNode())) { - BookmarkNode* bbn = model_->GetBookmarkBarNode(); - BookmarkNode* parent_on_bb = node; + const BookmarkNode* bbn = model_->GetBookmarkBarNode(); + const BookmarkNode* parent_on_bb = node; while (parent_on_bb->GetParent() != bbn) parent_on_bb = parent_on_bb->GetParent(); int index = bbn->IndexOfChild(parent_on_bb); diff --git a/chrome/browser/views/bookmark_bar_view.h b/chrome/browser/views/bookmark_bar_view.h index c747610..e53a2db 100644 --- a/chrome/browser/views/bookmark_bar_view.h +++ b/chrome/browser/views/bookmark_bar_view.h @@ -184,7 +184,7 @@ class BookmarkBarView : public views::View, // deletes itself once run. class ShowFolderDropMenuTask : public Task { public: - ShowFolderDropMenuTask(BookmarkBarView* view, BookmarkNode* node) + ShowFolderDropMenuTask(BookmarkBarView* view, const BookmarkNode* node) : view_(view), node_(node) { } @@ -204,7 +204,7 @@ class BookmarkBarView : public views::View, private: BookmarkBarView* view_; - BookmarkNode* node_; + const BookmarkNode* node_; DISALLOW_COPY_AND_ASSIGN(ShowFolderDropMenuTask); }; @@ -233,51 +233,51 @@ class BookmarkBarView : public views::View, // Invokes added followed by removed. 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); // Notifies ModelChangeListener of change. // If the node was added to the root node, a button is created and added to // this bookmark bar view. virtual void BookmarkNodeAdded(BookmarkModel* model, - BookmarkNode* parent, + const BookmarkNode* parent, int index); // Implementation for BookmarkNodeAddedImpl. void BookmarkNodeAddedImpl(BookmarkModel* model, - BookmarkNode* parent, + const BookmarkNode* parent, int index); // Notifies ModelChangeListener of change. // If the node was a child of the root node, the button corresponding to it // is removed. virtual void BookmarkNodeRemoved(BookmarkModel* model, - BookmarkNode* parent, + const BookmarkNode* parent, int index); // Implementation for BookmarkNodeRemoved. void BookmarkNodeRemovedImpl(BookmarkModel* model, - BookmarkNode* parent, + const BookmarkNode* parent, int index); // Notifies ModelChangedListener and invokes BookmarkNodeChangedImpl. virtual void BookmarkNodeChanged(BookmarkModel* model, - BookmarkNode* node); + const BookmarkNode* node); // If the node is a child of the root node, the button is updated // appropriately. - void BookmarkNodeChangedImpl(BookmarkModel* model, BookmarkNode* node); + void BookmarkNodeChangedImpl(BookmarkModel* model, const BookmarkNode* node); virtual void BookmarkNodeChildrenReordered(BookmarkModel* model, - BookmarkNode* node); + const BookmarkNode* node); // Invoked when the favicon is available. If the node is a child of the // root node, the appropriate button is updated. If a menu is showing, the // call is forwarded to the menu to allow for it to update the icon. virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model, - BookmarkNode* node); + const BookmarkNode* node); // DragController method. Determines the node representing sender and invokes // WriteDragData to write the actual data. @@ -287,7 +287,7 @@ class BookmarkBarView : public views::View, OSExchangeData* data); // Writes a BookmarkDragData for node to data. - void WriteDragData(BookmarkNode* node, OSExchangeData* data); + void WriteDragData(const BookmarkNode* node, OSExchangeData* data); // Returns the drag operations for the specified button. virtual int GetDragOperations(views::View* sender, int x, int y); @@ -313,11 +313,11 @@ class BookmarkBarView : public views::View, bool is_mouse_gesture); // Creates the button for rendering the specified bookmark node. - views::View* CreateBookmarkButton(BookmarkNode* node); + views::View* CreateBookmarkButton(const BookmarkNode* node); // COnfigures the button from the specified node. This sets the text, // and icon. - void ConfigureButton(BookmarkNode* node, views::TextButton* button); + void ConfigureButton(const BookmarkNode* node, views::TextButton* button); // Used when showing the menu allowing the user to choose when the bar is // visible. Return value corresponds to the users preference for when the @@ -337,13 +337,13 @@ class BookmarkBarView : public views::View, void NotifyModelChanged(); // Shows the menu used during drag and drop for the specified node. - void ShowDropFolderForNode(BookmarkNode* node); + void ShowDropFolderForNode(const BookmarkNode* node); // Cancels the timer used to show a drop menu. void StopShowFolderDropMenuTimer(); // Stars the timer used to show a drop menu for node. - void StartShowFolderDropMenuTimer(BookmarkNode* node); + void StartShowFolderDropMenuTimer(const BookmarkNode* node); // Returns the drop operation and index for the drop based on the event // and data. Returns DragDropTypes::DRAG_NONE if not a valid location. diff --git a/chrome/browser/views/bookmark_bar_view_test.cc b/chrome/browser/views/bookmark_bar_view_test.cc index 73eb686..8313920 100644 --- a/chrome/browser/views/bookmark_bar_view_test.cc +++ b/chrome/browser/views/bookmark_bar_view_test.cc @@ -137,9 +137,10 @@ class BookmarkBarViewEventTestBase : public ViewEventTestBase { void AddTestData(bool big_menu) { std::string test_base = "file:///c:/tmp/"; - BookmarkNode* f1 = model_->AddGroup(model_->GetBookmarkBarNode(), 0, L"F1"); + const BookmarkNode* f1 = model_->AddGroup( + model_->GetBookmarkBarNode(), 0, 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")); if (big_menu) { for (int i = 1; i <= 100; ++i) { @@ -156,10 +157,10 @@ class BookmarkBarViewEventTestBase : public ViewEventTestBase { model_->AddURL(model_->GetBookmarkBarNode(), 4, L"d", GURL(test_base + "d")); model_->AddURL(model_->other_node(), 0, L"oa", GURL(test_base + "oa")); - BookmarkNode* of = model_->AddGroup(model_->other_node(), 1, L"OF"); + const BookmarkNode* of = model_->AddGroup(model_->other_node(), 1, L"OF"); model_->AddURL(of, 0, L"ofa", GURL(test_base + "ofa")); model_->AddURL(of, 1, L"ofb", GURL(test_base + "ofb")); - BookmarkNode* of2 = model_->AddGroup(model_->other_node(), 2, L"OF2"); + const BookmarkNode* of2 = model_->AddGroup(model_->other_node(), 2, L"OF2"); model_->AddURL(of2, 0, L"of2a", GURL(test_base + "of2a")); model_->AddURL(of2, 1, L"of2b", GURL(test_base + "of2b")); } diff --git a/chrome/browser/views/bookmark_bubble_view.cc b/chrome/browser/views/bookmark_bubble_view.cc index 9a2a8f6..69af750 100644 --- a/chrome/browser/views/bookmark_bubble_view.cc +++ b/chrome/browser/views/bookmark_bubble_view.cc @@ -74,7 +74,7 @@ bool IsBookmarkBubbleViewShowing() { // RecentlyUsedFoldersModel --------------------------------------------------- BookmarkBubbleView::RecentlyUsedFoldersModel::RecentlyUsedFoldersModel( - BookmarkModel* bb_model, BookmarkNode* node) + BookmarkModel* bb_model, const BookmarkNode* node) // Use + 2 to account for bookmark bar and other node. : nodes_(bookmark_utils::GetMostRecentlyModifiedGroups( bb_model, kMaxMRUFolders + 2)), @@ -117,14 +117,14 @@ std::wstring BookmarkBubbleView::RecentlyUsedFoldersModel::GetItemAt( return nodes_[index]->GetTitle(); } -BookmarkNode* BookmarkBubbleView::RecentlyUsedFoldersModel::GetNodeAt( +const BookmarkNode* BookmarkBubbleView::RecentlyUsedFoldersModel::GetNodeAt( int index) { return nodes_[index]; } void BookmarkBubbleView::RecentlyUsedFoldersModel::RemoveNode( - BookmarkNode* node) { - std::vector<BookmarkNode*>::iterator i = + const BookmarkNode* node) { + std::vector<const BookmarkNode*>::iterator i = find(nodes_.begin(), nodes_.end(), node); if (i != nodes_.end()) nodes_.erase(i); @@ -169,7 +169,7 @@ BookmarkBubbleView::~BookmarkBubbleView() { 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)); } @@ -304,7 +304,8 @@ void BookmarkBubbleView::Init() { std::wstring BookmarkBubbleView::GetTitle() { BookmarkModel* bookmark_model= profile_->GetBookmarkModel(); - BookmarkNode* node = bookmark_model->GetMostRecentlyAddedNodeForURL(url_); + const BookmarkNode* node = + bookmark_model->GetMostRecentlyAddedNodeForURL(url_); if (node) return node->GetTitle(); else @@ -374,7 +375,7 @@ void BookmarkBubbleView::Close() { } void BookmarkBubbleView::ShowEditor() { - BookmarkNode* node = + const BookmarkNode* node = profile_->GetBookmarkModel()->GetMostRecentlyAddedNodeForURL(url_); // Commit any edits now. @@ -408,7 +409,7 @@ void BookmarkBubbleView::ApplyEdits() { apply_edits_ = false; BookmarkModel* model = profile_->GetBookmarkModel(); - BookmarkNode* node = model->GetMostRecentlyAddedNodeForURL(url_); + const BookmarkNode* node = model->GetMostRecentlyAddedNodeForURL(url_); if (node) { const std::wstring new_title = title_tf_->text(); if (new_title != node->GetTitle()) { @@ -419,7 +420,7 @@ void BookmarkBubbleView::ApplyEdits() { // Last index means 'Choose another folder...' if (parent_combobox_->selected_item() < parent_model_.GetItemCount(parent_combobox_) - 1) { - BookmarkNode* new_parent = + const BookmarkNode* new_parent = parent_model_.GetNodeAt(parent_combobox_->selected_item()); if (new_parent != node->GetParent()) { UserMetrics::RecordAction(L"BookmarkBubble_ChangeParent", profile_); diff --git a/chrome/browser/views/bookmark_bubble_view.h b/chrome/browser/views/bookmark_bubble_view.h index 5083a52..517aea9 100644 --- a/chrome/browser/views/bookmark_bubble_view.h +++ b/chrome/browser/views/bookmark_bubble_view.h @@ -62,23 +62,23 @@ class BookmarkBubbleView : public views::View, // also contains an extra item that shows the text 'Choose another folder...'. class RecentlyUsedFoldersModel : public views::Combobox::Model { public: - RecentlyUsedFoldersModel(BookmarkModel* bb_model, BookmarkNode* node); + RecentlyUsedFoldersModel(BookmarkModel* bb_model, const BookmarkNode* node); // Combobox::Model methods. Call through to nodes_. virtual int GetItemCount(views::Combobox* source); virtual std::wstring GetItemAt(views::Combobox* source, int index); // Returns the node at the specified index. - BookmarkNode* GetNodeAt(int index); + const BookmarkNode* GetNodeAt(int index); // Returns the index of the original parent folder. int node_parent_index() const { return node_parent_index_; } private: // Removes node from nodes_. Does nothing if node is not in nodes_. - void RemoveNode(BookmarkNode* node); + void RemoveNode(const BookmarkNode* node); - std::vector<BookmarkNode*> nodes_; + std::vector<const BookmarkNode*> nodes_; int node_parent_index_; DISALLOW_COPY_AND_ASSIGN(RecentlyUsedFoldersModel); diff --git a/chrome/browser/views/bookmark_context_menu.cc b/chrome/browser/views/bookmark_context_menu.cc index a29336b..9d9ca29 100644 --- a/chrome/browser/views/bookmark_context_menu.cc +++ b/chrome/browser/views/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/views/bookmark_context_menu.h b/chrome/browser/views/bookmark_context_menu.h index 9903f44..f9e6584 100644 --- a/chrome/browser/views/bookmark_context_menu.h +++ b/chrome/browser/views/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/views/bookmark_context_menu_test.cc b/chrome/browser/views/bookmark_context_menu_test.cc index 44b9609..217764c 100644 --- a/chrome/browser/views/bookmark_context_menu_test.cc +++ b/chrome/browser/views/bookmark_context_menu_test.cc @@ -86,14 +86,14 @@ class BookmarkContextMenuTest : public testing::Test { model_->AddURL(model_->GetBookmarkBarNode(), 0, L"a", GURL(test_base + "a")); - BookmarkNode* 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"); model_->AddGroup(model_->GetBookmarkBarNode(), 3, L"F3"); - BookmarkNode* f4 = + const BookmarkNode* f4 = model_->AddGroup(model_->GetBookmarkBarNode(), 4, L"F4"); model_->AddURL(f4, 0, L"f4a", GURL(test_base + "f4a")); } @@ -101,7 +101,7 @@ class BookmarkContextMenuTest : public testing::Test { // Tests Deleting from the menu. TEST_F(BookmarkContextMenuTest, DeleteURL) { - std::vector<BookmarkNode*> nodes; + std::vector<const BookmarkNode*> nodes; nodes.push_back(model_->GetBookmarkBarNode()->GetChild(0)); BookmarkContextMenu controller( NULL, profile_.get(), NULL, NULL, nodes[0]->GetParent(), nodes, @@ -116,7 +116,7 @@ TEST_F(BookmarkContextMenuTest, DeleteURL) { // Tests open all on a folder with a couple of bookmarks. TEST_F(BookmarkContextMenuTest, OpenAll) { - BookmarkNode* folder = model_->GetBookmarkBarNode()->GetChild(1); + const BookmarkNode* folder = model_->GetBookmarkBarNode()->GetChild(1); bookmark_utils::OpenAll( NULL, profile_.get(), &navigator_, folder, NEW_FOREGROUND_TAB); @@ -131,7 +131,7 @@ TEST_F(BookmarkContextMenuTest, OpenAll) { TEST_F(BookmarkContextMenuTest, EmptyNodes) { BookmarkContextMenu controller( NULL, profile_.get(), NULL, NULL, model_->other_node(), - std::vector<BookmarkNode*>(), BookmarkContextMenu::BOOKMARK_BAR); + std::vector<const BookmarkNode*>(), BookmarkContextMenu::BOOKMARK_BAR); EXPECT_FALSE(controller.IsCommandEnabled(IDS_BOOMARK_BAR_OPEN_ALL)); EXPECT_FALSE( controller.IsCommandEnabled(IDS_BOOMARK_BAR_OPEN_ALL_NEW_WINDOW)); @@ -148,7 +148,7 @@ TEST_F(BookmarkContextMenuTest, EmptyNodes) { // Tests the enabled state of the menus when supplied a vector with a single // url. TEST_F(BookmarkContextMenuTest, SingleURL) { - std::vector<BookmarkNode*> nodes; + std::vector<const BookmarkNode*> nodes; nodes.push_back(model_->GetBookmarkBarNode()->GetChild(0)); BookmarkContextMenu controller( NULL, profile_.get(), NULL, NULL, nodes[0]->GetParent(), @@ -169,7 +169,7 @@ TEST_F(BookmarkContextMenuTest, SingleURL) { // Tests the enabled state of the menus when supplied a vector with multiple // urls. TEST_F(BookmarkContextMenuTest, MultipleURLs) { - std::vector<BookmarkNode*> nodes; + std::vector<const BookmarkNode*> nodes; nodes.push_back(model_->GetBookmarkBarNode()->GetChild(0)); nodes.push_back(model_->GetBookmarkBarNode()->GetChild(1)->GetChild(0)); BookmarkContextMenu controller( @@ -191,7 +191,7 @@ TEST_F(BookmarkContextMenuTest, MultipleURLs) { // Tests the enabled state of the menus when supplied an vector with a single // folder. TEST_F(BookmarkContextMenuTest, SingleFolder) { - std::vector<BookmarkNode*> nodes; + std::vector<const BookmarkNode*> nodes; nodes.push_back(model_->GetBookmarkBarNode()->GetChild(2)); BookmarkContextMenu controller( NULL, profile_.get(), NULL, NULL, nodes[0]->GetParent(), @@ -212,7 +212,7 @@ TEST_F(BookmarkContextMenuTest, SingleFolder) { // Tests the enabled state of the menus when supplied a vector with multiple // folders, all of which are empty. TEST_F(BookmarkContextMenuTest, MultipleEmptyFolders) { - std::vector<BookmarkNode*> nodes; + std::vector<const BookmarkNode*> nodes; nodes.push_back(model_->GetBookmarkBarNode()->GetChild(2)); nodes.push_back(model_->GetBookmarkBarNode()->GetChild(3)); BookmarkContextMenu controller( @@ -234,7 +234,7 @@ TEST_F(BookmarkContextMenuTest, MultipleEmptyFolders) { // Tests the enabled state of the menus when supplied a vector with multiple // folders, some of which contain URLs. TEST_F(BookmarkContextMenuTest, MultipleFoldersWithURLs) { - std::vector<BookmarkNode*> nodes; + std::vector<const BookmarkNode*> nodes; nodes.push_back(model_->GetBookmarkBarNode()->GetChild(3)); nodes.push_back(model_->GetBookmarkBarNode()->GetChild(4)); BookmarkContextMenu controller( @@ -255,7 +255,7 @@ TEST_F(BookmarkContextMenuTest, MultipleFoldersWithURLs) { // Tests the enabled state of open incognito. TEST_F(BookmarkContextMenuTest, DisableIncognito) { - std::vector<BookmarkNode*> nodes; + std::vector<const BookmarkNode*> nodes; nodes.push_back(model_->GetBookmarkBarNode()->GetChild(0)); BookmarkContextMenu controller( NULL, profile_.get(), NULL, NULL, nodes[0]->GetParent(), @@ -267,7 +267,7 @@ TEST_F(BookmarkContextMenuTest, DisableIncognito) { // Tests that you can't remove/edit when showing the other node. TEST_F(BookmarkContextMenuTest, DisabledItemsWithOtherNode) { - std::vector<BookmarkNode*> nodes; + std::vector<const BookmarkNode*> nodes; nodes.push_back(model_->other_node()); BookmarkContextMenu controller( NULL, profile_.get(), NULL, NULL, nodes[0], nodes, @@ -280,7 +280,8 @@ TEST_F(BookmarkContextMenuTest, DisabledItemsWithOtherNode) { // parent. TEST_F(BookmarkContextMenuTest, EmptyNodesNullParent) { BookmarkContextMenu controller( - NULL, profile_.get(), NULL, NULL, NULL, std::vector<BookmarkNode*>(), + NULL, profile_.get(), NULL, NULL, NULL, + std::vector<const BookmarkNode*>(), BookmarkContextMenu::BOOKMARK_MANAGER_ORGANIZE_MENU); EXPECT_FALSE(controller.IsCommandEnabled(IDS_BOOMARK_BAR_OPEN_ALL)); EXPECT_FALSE( diff --git a/chrome/browser/views/bookmark_editor_view.cc b/chrome/browser/views/bookmark_editor_view.cc index 3208099..ed51083 100644 --- a/chrome/browser/views/bookmark_editor_view.cc +++ b/chrome/browser/views/bookmark_editor_view.cc @@ -47,8 +47,8 @@ static const int kNewGroupButtonID = 1002; // static void BookmarkEditor::Show(HWND parent_hwnd, Profile* profile, - BookmarkNode* parent, - BookmarkNode* node, + const BookmarkNode* parent, + const BookmarkNode* node, Configuration configuration, Handler* handler) { DCHECK(profile); @@ -59,8 +59,8 @@ void BookmarkEditor::Show(HWND parent_hwnd, BookmarkEditorView::BookmarkEditorView( Profile* profile, - BookmarkNode* parent, - BookmarkNode* node, + const BookmarkNode* parent, + const BookmarkNode* node, BookmarkEditor::Configuration configuration, BookmarkEditor::Handler* handler) : profile_(profile), @@ -339,23 +339,23 @@ void BookmarkEditorView::Init() { } void BookmarkEditorView::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 BookmarkEditorView::BookmarkNodeAdded(BookmarkModel* model, - BookmarkNode* parent, + const BookmarkNode* parent, int index) { Reset(); } void BookmarkEditorView::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. @@ -365,8 +365,8 @@ void BookmarkEditorView::BookmarkNodeRemoved(BookmarkModel* model, } } -void BookmarkEditorView::BookmarkNodeChildrenReordered(BookmarkModel* model, - BookmarkNode* node) { +void BookmarkEditorView::BookmarkNodeChildrenReordered( + BookmarkModel* model, const BookmarkNode* node) { Reset(); } @@ -440,7 +440,7 @@ BookmarkEditorView::EditorNode* BookmarkEditorView::AddNewGroup( void BookmarkEditorView::ExpandAndSelect() { tree_view_->ExpandAll(); - BookmarkNode* to_select = node_ ? node_->GetParent() : parent_; + const BookmarkNode* to_select = node_ ? node_->GetParent() : parent_; int group_id_to_select = to_select->id(); DCHECK(group_id_to_select); // GetMostRecentParent should never return NULL. EditorNode* b_node = @@ -453,7 +453,7 @@ void BookmarkEditorView::ExpandAndSelect() { BookmarkEditorView::EditorNode* BookmarkEditorView::CreateRootNode() { EditorNode* root_node = new EditorNode(std::wstring(), 0); - BookmarkNode* bb_root_node = bb_model_->root_node(); + const BookmarkNode* bb_root_node = bb_model_->root_node(); CreateNodes(bb_root_node, root_node); DCHECK(root_node->GetChildCount() == 2); DCHECK(bb_root_node->GetChild(0)->GetType() == @@ -462,10 +462,10 @@ BookmarkEditorView::EditorNode* BookmarkEditorView::CreateRootNode() { return root_node; } -void BookmarkEditorView::CreateNodes(BookmarkNode* bb_node, +void BookmarkEditorView::CreateNodes(const BookmarkNode* bb_node, BookmarkEditorView::EditorNode* b_node) { for (int i = 0; i < bb_node->GetChildCount(); ++i) { - BookmarkNode* child_bb_node = bb_node->GetChild(i); + const BookmarkNode* child_bb_node = bb_node->GetChild(i); if (child_bb_node->is_folder()) { EditorNode* new_b_node = new EditorNode(child_bb_node->GetTitle(), child_bb_node->id()); @@ -518,7 +518,7 @@ void BookmarkEditorView::ApplyEdits(EditorNode* parent) { } // Create the new groups and update the titles. - BookmarkNode* new_parent = NULL; + const BookmarkNode* new_parent = NULL; ApplyNameChangesAndCreateNewGroups( bb_model_->root_node(), tree_model_->GetRoot(), parent, &new_parent); @@ -527,15 +527,15 @@ void BookmarkEditorView::ApplyEdits(EditorNode* parent) { } void BookmarkEditorView::ApplyNameChangesAndCreateNewGroups( - BookmarkNode* bb_node, + const BookmarkNode* bb_node, BookmarkEditorView::EditorNode* b_node, BookmarkEditorView::EditorNode* parent_b_node, - BookmarkNode** parent_bb_node) { + const BookmarkNode** parent_bb_node) { if (parent_b_node == b_node) *parent_bb_node = bb_node; for (int i = 0; i < b_node->GetChildCount(); ++i) { EditorNode* child_b_node = b_node->GetChild(i); - BookmarkNode* child_bb_node = NULL; + const BookmarkNode* child_bb_node = NULL; if (child_b_node->value == 0) { // New group. child_bb_node = bb_model_->AddGroup(bb_node, @@ -544,7 +544,7 @@ void BookmarkEditorView::ApplyNameChangesAndCreateNewGroups( // 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() == child_b_node->value) { child_bb_node = node; break; diff --git a/chrome/browser/views/bookmark_editor_view.h b/chrome/browser/views/bookmark_editor_view.h index 51ef925..a03d3e9 100644 --- a/chrome/browser/views/bookmark_editor_view.h +++ b/chrome/browser/views/bookmark_editor_view.h @@ -54,8 +54,8 @@ class BookmarkEditorView : public BookmarkEditor, FRIEND_TEST(BookmarkEditorViewTest, ChangeTitleNoTree); public: BookmarkEditorView(Profile* profile, - BookmarkNode* parent, - BookmarkNode* node, + const BookmarkNode* parent, + const BookmarkNode* node, BookmarkEditor::Configuration configuration, BookmarkEditor::Handler* handler); @@ -140,23 +140,23 @@ class BookmarkEditorView : 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(); @@ -172,7 +172,7 @@ class BookmarkEditorView : public BookmarkEditor, // Adds and creates a child node in b_node for all children of bb_node that // are groups. - void CreateNodes(BookmarkNode* bb_node, EditorNode* b_node); + void CreateNodes(const BookmarkNode* bb_node, EditorNode* b_node); // Returns the node with the specified id, or NULL if one can't be found. EditorNode* FindNodeWithID(BookmarkEditorView::EditorNode* node, int id); @@ -194,10 +194,10 @@ class BookmarkEditorView : public BookmarkEditor, // used to determine the new BookmarkNode parent based on the EditorNode // parent. void ApplyNameChangesAndCreateNewGroups( - BookmarkNode* bb_node, + const BookmarkNode* bb_node, BookmarkEditorView::EditorNode* b_node, BookmarkEditorView::EditorNode* parent_b_node, - BookmarkNode** parent_bb_node); + const BookmarkNode** parent_bb_node); // Returns the current url the user has input. GURL GetInputURL() const; @@ -238,10 +238,10 @@ class BookmarkEditorView : public BookmarkEditor, views::Textfield title_tf_; // 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_; // The context menu. scoped_ptr<views::SimpleMenuModel> context_menu_contents_; diff --git a/chrome/browser/views/bookmark_editor_view_unittest.cc b/chrome/browser/views/bookmark_editor_view_unittest.cc index 4024c34..22570bb 100644 --- a/chrome/browser/views/bookmark_editor_view_unittest.cc +++ b/chrome/browser/views/bookmark_editor_view_unittest.cc @@ -41,10 +41,14 @@ class BookmarkEditorViewTest : 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)); } + BookmarkNode* GetMutableNode(const std::string& name) { + return const_cast<BookmarkNode*>(GetNode(name)); + } + private: // Creates the following structure: // bookmark bar node @@ -63,16 +67,18 @@ class BookmarkEditorViewTest : 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")); } }; @@ -110,7 +116,8 @@ TEST_F(BookmarkEditorViewTest, EditTitleKeepsPosition) { editor.ApplyEdits(editor.tree_model_->GetRoot()->GetChild(0)); - 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()); @@ -119,7 +126,7 @@ TEST_F(BookmarkEditorViewTest, EditTitleKeepsPosition) { // Changes the url and makes sure parent/visual order doesn't change. TEST_F(BookmarkEditorViewTest, EditURLKeepsPosition) { Time node_time = Time::Now() + TimeDelta::FromDays(2); - GetNode("a")->date_added_ = node_time; + GetMutableNode("a")->set_date_added(node_time); BookmarkEditorView editor(profile_.get(), NULL, GetNode("a"), BookmarkEditorView::SHOW_TREE, NULL); @@ -127,7 +134,8 @@ TEST_F(BookmarkEditorViewTest, EditURLKeepsPosition) { editor.ApplyEdits(editor.tree_model_->GetRoot()->GetChild(0)); - 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()); @@ -141,7 +149,7 @@ TEST_F(BookmarkEditorViewTest, ChangeParent) { editor.ApplyEdits(editor.tree_model_->GetRoot()->GetChild(1)); - 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()); } @@ -149,7 +157,7 @@ TEST_F(BookmarkEditorViewTest, ChangeParent) { // Moves 'a' to be a child of the other node and changes its url to new_a. TEST_F(BookmarkEditorViewTest, ChangeParentAndURL) { Time node_time = Time::Now() + TimeDelta::FromDays(2); - GetNode("a")->date_added_ = node_time; + GetMutableNode("a")->set_date_added(node_time); BookmarkEditorView editor(profile_.get(), NULL, GetNode("a"), BookmarkEditorView::SHOW_TREE, NULL); @@ -157,7 +165,7 @@ TEST_F(BookmarkEditorViewTest, ChangeParentAndURL) { editor.ApplyEdits(editor.tree_model_->GetRoot()->GetChild(1)); - 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()); @@ -179,8 +187,9 @@ TEST_F(BookmarkEditorViewTest, MoveToNewParent) { // Parent the node to "F21". editor.ApplyEdits(f2); - 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()); @@ -190,7 +199,7 @@ TEST_F(BookmarkEditorViewTest, 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()); } @@ -205,10 +214,11 @@ TEST_F(BookmarkEditorViewTest, NewURL) { editor.ApplyEdits(editor.tree_model_->GetRoot()->GetChild(0)); - 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()); @@ -225,10 +235,10 @@ TEST_F(BookmarkEditorViewTest, 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()); @@ -244,10 +254,10 @@ TEST_F(BookmarkEditorViewTest, ChangeTitleNoTree) { 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()); } diff --git a/chrome/browser/views/bookmark_folder_tree_view.cc b/chrome/browser/views/bookmark_folder_tree_view.cc index eda92f5..bd464c8 100644 --- a/chrome/browser/views/bookmark_folder_tree_view.cc +++ b/chrome/browser/views/bookmark_folder_tree_view.cc @@ -78,7 +78,7 @@ int BookmarkFolderTreeView::OnPerformDrop(const views::DropTargetEvent& event) { return drop_operation; } -BookmarkNode* BookmarkFolderTreeView::GetSelectedBookmarkNode() { +const BookmarkNode* BookmarkFolderTreeView::GetSelectedBookmarkNode() { TreeModelNode* selected_node = GetSelectedNode(); if (!selected_node) return NULL; @@ -113,7 +113,7 @@ int BookmarkFolderTreeView::UpdateDropInfo() { return drop_info_->drop_operation(); } -void BookmarkFolderTreeView::BeginDrag(BookmarkNode* node) { +void BookmarkFolderTreeView::BeginDrag(const BookmarkNode* node) { BookmarkModel* model = profile_->GetBookmarkModel(); // Only allow the drag if the user has selected a node of type bookmark and it // isn't the bookmark bar or other bookmarks folders. @@ -122,7 +122,7 @@ void BookmarkFolderTreeView::BeginDrag(BookmarkNode* node) { return; } - std::vector<BookmarkNode*> nodes_to_drag; + std::vector<const BookmarkNode*> nodes_to_drag; nodes_to_drag.push_back(node); scoped_refptr<OSExchangeData> data = new OSExchangeData; @@ -212,7 +212,7 @@ int BookmarkFolderTreeView::CalculateDropOperation( } void BookmarkFolderTreeView::OnPerformDropImpl() { - BookmarkNode* parent_node = + const BookmarkNode* parent_node = TreeNodeAsBookmarkNode(drop_info_->position().parent); int drop_index = FolderIndexToBookmarkIndex(drop_info_->position()); BookmarkModel* model = profile_->GetBookmarkModel(); @@ -226,7 +226,8 @@ void BookmarkFolderTreeView::OnPerformDropImpl() { } // else, move. - std::vector<BookmarkNode*> nodes = drop_info_->data().GetNodes(profile_); + std::vector<const BookmarkNode*> nodes = + drop_info_->data().GetNodes(profile_); if (nodes.empty()) return; @@ -286,13 +287,14 @@ BookmarkFolderTreeModel* BookmarkFolderTreeView::folder_model() const { return static_cast<BookmarkFolderTreeModel*>(model()); } -BookmarkNode* BookmarkFolderTreeView::TreeNodeAsBookmarkNode(FolderNode* node) { +const BookmarkNode* BookmarkFolderTreeView::TreeNodeAsBookmarkNode( + FolderNode* node) { return folder_model()->TreeNodeAsBookmarkNode(node); } int BookmarkFolderTreeView::FolderIndexToBookmarkIndex( const DropPosition& position) { - BookmarkNode* parent_node = TreeNodeAsBookmarkNode(position.parent); + const BookmarkNode* parent_node = TreeNodeAsBookmarkNode(position.parent); if (position.on || position.index == position.parent->GetChildCount()) return parent_node->GetChildCount(); diff --git a/chrome/browser/views/bookmark_folder_tree_view.h b/chrome/browser/views/bookmark_folder_tree_view.h index 2a47b1b..93f5205 100644 --- a/chrome/browser/views/bookmark_folder_tree_view.h +++ b/chrome/browser/views/bookmark_folder_tree_view.h @@ -32,7 +32,7 @@ class BookmarkFolderTreeView : public views::TreeView { // Returns the selected node as a BookmarkNode. This returns NULL if the // selected node is not of type BookmarkFolderTreeModel::BOOKMARK or // nothing is selected. - BookmarkNode* GetSelectedBookmarkNode(); + const BookmarkNode* GetSelectedBookmarkNode(); protected: // Overriden to start a drag. @@ -96,7 +96,7 @@ class BookmarkFolderTreeView : public views::TreeView { int UpdateDropInfo(); // Starts a drag operation for the specified node. - void BeginDrag(BookmarkNode* node); + void BeginDrag(const BookmarkNode* node); // Calculates the drop position. DropPosition CalculateDropPosition(int y, bool only_folders); @@ -115,7 +115,7 @@ class BookmarkFolderTreeView : public views::TreeView { BookmarkFolderTreeModel* folder_model() const; // Converts FolderNode into a BookmarkNode. - BookmarkNode* TreeNodeAsBookmarkNode(FolderNode* node); + const BookmarkNode* TreeNodeAsBookmarkNode(FolderNode* node); // Converts the position in terms of the BookmarkFolderTreeModel to an index // in terms of the BookmarkModel. The returned index is the index the drop diff --git a/chrome/browser/views/bookmark_manager_view.cc b/chrome/browser/views/bookmark_manager_view.cc index 3582b86..b873249 100644 --- a/chrome/browser/views/bookmark_manager_view.cc +++ b/chrome/browser/views/bookmark_manager_view.cc @@ -80,7 +80,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); manager->ExpandAll(imported_node); @@ -145,7 +145,7 @@ void ShowBookmarkManagerView(Profile* profile) { // BookmarkManager ------------------------------------------------------------- -void BookmarkManager::SelectInTree(Profile* profile, BookmarkNode* node) { +void BookmarkManager::SelectInTree(Profile* profile, const BookmarkNode* node) { if (manager && manager->profile() == profile) manager->SelectInTree(node); } @@ -276,11 +276,11 @@ BookmarkManagerView* BookmarkManagerView::current() { return manager; } -void BookmarkManagerView::SelectInTree(BookmarkNode* node) { +void BookmarkManagerView::SelectInTree(const BookmarkNode* node) { if (!node) return; - BookmarkNode* parent = node->is_url() ? node->GetParent() : node; + const BookmarkNode* parent = node->is_url() ? node->GetParent() : node; FolderNode* folder_node = tree_model_->GetFolderNodeForBookmarkNode(parent); if (!folder_node) { NOTREACHED(); @@ -298,8 +298,8 @@ void BookmarkManagerView::SelectInTree(BookmarkNode* node) { } } -void BookmarkManagerView::ExpandAll(BookmarkNode* node) { - BookmarkNode* parent = node->is_url() ? node->GetParent() : node; +void BookmarkManagerView::ExpandAll(const BookmarkNode* node) { + const BookmarkNode* parent = node->is_url() ? node->GetParent() : node; FolderNode* folder_node = tree_model_->GetFolderNodeForBookmarkNode(parent); if (!folder_node) { NOTREACHED(); @@ -308,12 +308,12 @@ void BookmarkManagerView::ExpandAll(BookmarkNode* node) { tree_view_->ExpandAll(folder_node); } -BookmarkNode* BookmarkManagerView::GetSelectedFolder() { +const BookmarkNode* BookmarkManagerView::GetSelectedFolder() { return tree_view_->GetSelectedBookmarkNode(); } -std::vector<BookmarkNode*> BookmarkManagerView::GetSelectedTableNodes() { - std::vector<BookmarkNode*> nodes; +std::vector<const BookmarkNode*> BookmarkManagerView::GetSelectedTableNodes() { + std::vector<const BookmarkNode*> nodes; for (views::TableView::iterator i = table_view_->SelectionBegin(); i != table_view_->SelectionEnd(); ++i) { nodes.push_back(table_model_->GetNodeForRow(*i)); @@ -362,7 +362,7 @@ bool BookmarkManagerView::AcceleratorPressed( } void BookmarkManagerView::OnDoubleClick() { - std::vector<BookmarkNode*> nodes = GetSelectedTableNodes(); + std::vector<const BookmarkNode*> nodes = GetSelectedTableNodes(); if (nodes.empty()) return; if (nodes.size() == 1 && nodes[0]->is_folder()) { @@ -378,7 +378,7 @@ void BookmarkManagerView::OnDoubleClick() { } void BookmarkManagerView::OnMiddleClick() { - std::vector<BookmarkNode*> nodes = GetSelectedTableNodes(); + std::vector<const BookmarkNode*> nodes = GetSelectedTableNodes(); if (nodes.empty()) return; if (nodes.size() == 1 && nodes[0]->is_folder()) { @@ -391,7 +391,7 @@ void BookmarkManagerView::OnMiddleClick() { } void BookmarkManagerView::OnTableViewDelete(views::TableView* table) { - std::vector<BookmarkNode*> nodes = GetSelectedTableNodes(); + std::vector<const BookmarkNode*> nodes = GetSelectedTableNodes(); if (nodes.empty()) return; for (size_t i = 0; i < nodes.size(); ++i) { @@ -403,7 +403,7 @@ void BookmarkManagerView::OnTableViewDelete(views::TableView* table) { void BookmarkManagerView::OnKeyDown(unsigned short virtual_keycode) { switch (virtual_keycode) { case VK_RETURN: { - std::vector<BookmarkNode*> selected_nodes = GetSelectedTableNodes(); + std::vector<const BookmarkNode*> selected_nodes = GetSelectedTableNodes(); if (selected_nodes.size() == 1 && selected_nodes[0]->is_folder()) { SelectInTree(selected_nodes[0]); } else { @@ -415,7 +415,7 @@ void BookmarkManagerView::OnKeyDown(unsigned short virtual_keycode) { } case VK_BACK: { - BookmarkNode* selected_folder = GetSelectedFolder(); + const BookmarkNode* selected_folder = GetSelectedFolder(); if (selected_folder != NULL && selected_folder->GetParent() != GetBookmarkModel()->root_node()) { SelectInTree(selected_folder->GetParent()); @@ -434,7 +434,7 @@ void BookmarkManagerView::OnTreeViewSelectionChanged( TreeModelNode* node = tree_view_->GetSelectedNode(); BookmarkTableModel* new_table_model = NULL; - BookmarkNode* table_parent_node = NULL; + const BookmarkNode* table_parent_node = NULL; bool is_search = false; if (node) { @@ -470,11 +470,11 @@ void BookmarkManagerView::OnTreeViewSelectionChanged( void BookmarkManagerView::OnTreeViewKeyDown(unsigned short virtual_keycode) { switch (virtual_keycode) { case VK_DELETE: { - BookmarkNode* node = GetSelectedFolder(); + const BookmarkNode* node = GetSelectedFolder(); if (!node || node->GetParent() == GetBookmarkModel()->root_node()) return; - BookmarkNode* parent = node->GetParent(); + const BookmarkNode* parent = node->GetParent(); GetBookmarkModel()->Remove(parent, parent->IndexOfChild(node)); break; } @@ -599,7 +599,7 @@ BookmarkTableModel* BookmarkManagerView::CreateSearchTableModel() { } void BookmarkManagerView::SetTableModel(BookmarkTableModel* new_table_model, - BookmarkNode* parent_node, + const BookmarkNode* parent_node, bool is_search) { // Be sure and reset the model on the view before updating table_model_. // Otherwise the view will attempt to use the deleted model when we set the @@ -656,7 +656,7 @@ void BookmarkManagerView::PrepareForShow() { void BookmarkManagerView::LoadedImpl() { BookmarkModel* bookmark_model = GetBookmarkModel(); - BookmarkNode* bookmark_bar_node = bookmark_model->GetBookmarkBarNode(); + const BookmarkNode* bookmark_bar_node = bookmark_model->GetBookmarkBarNode(); table_model_.reset( BookmarkTableModel::CreateBookmarkTableModelForFolder(bookmark_model, bookmark_bar_node)); @@ -693,8 +693,8 @@ void BookmarkManagerView::ShowMenu( if (config == BookmarkContextMenu::BOOKMARK_MANAGER_TABLE || (config == BookmarkContextMenu::BOOKMARK_MANAGER_ORGANIZE_MENU && table_view_->HasFocus())) { - std::vector<BookmarkNode*> nodes = GetSelectedTableNodes(); - BookmarkNode* parent = GetSelectedFolder(); + std::vector<const BookmarkNode*> nodes = GetSelectedTableNodes(); + const BookmarkNode* parent = GetSelectedFolder(); if (!parent) { if (config == BookmarkContextMenu::BOOKMARK_MANAGER_TABLE) config = BookmarkContextMenu::BOOKMARK_MANAGER_TABLE_OTHER; @@ -705,8 +705,8 @@ void BookmarkManagerView::ShowMenu( config); menu.RunMenuAt(x, y); } else { - BookmarkNode* node = GetSelectedFolder(); - std::vector<BookmarkNode*> nodes; + const BookmarkNode* node = GetSelectedFolder(); + std::vector<const BookmarkNode*> nodes; if (node) nodes.push_back(node); BookmarkContextMenu menu(GetWidget()->GetNativeView(), profile_, NULL, NULL, @@ -718,11 +718,11 @@ void BookmarkManagerView::ShowMenu( void BookmarkManagerView::OnCutCopyPaste(CutCopyPasteType type, bool from_table) { if (type == CUT || type == COPY) { - std::vector<BookmarkNode*> nodes; + std::vector<const BookmarkNode*> nodes; if (from_table) { nodes = GetSelectedTableNodes(); } else { - BookmarkNode* node = GetSelectedFolder(); + const BookmarkNode* node = GetSelectedFolder(); if (!node || node->GetParent() == GetBookmarkModel()->root_node()) return; nodes.push_back(node); diff --git a/chrome/browser/views/bookmark_manager_view.h b/chrome/browser/views/bookmark_manager_view.h index 2139a0b..a8f3ca6 100644 --- a/chrome/browser/views/bookmark_manager_view.h +++ b/chrome/browser/views/bookmark_manager_view.h @@ -62,16 +62,16 @@ class BookmarkManagerView : public views::View, // Selects the specified node in the tree. If node is a URL it's parent is // selected and node is selected in the table. - void SelectInTree(BookmarkNode* node); + void SelectInTree(const BookmarkNode* node); // Expands all the children of the selected folder. - void ExpandAll(BookmarkNode* node); + void ExpandAll(const BookmarkNode* node); // Returns the selected folder in the tree, which may be null. - BookmarkNode* GetSelectedFolder(); + const BookmarkNode* GetSelectedFolder(); // Returns the selection of the table. - std::vector<BookmarkNode*> GetSelectedTableNodes(); + std::vector<const BookmarkNode*> GetSelectedTableNodes(); virtual void PaintBackground(gfx::Canvas* canvas); @@ -112,26 +112,26 @@ class BookmarkManagerView : public views::View, 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) {} // Textfield::Controller methods. // Starts a timer to search for the search text. @@ -165,7 +165,7 @@ class BookmarkManagerView : public views::View, // Sets the model of the table and its parent node. If |is_search| is true, // it means the table is showing search results. void SetTableModel(BookmarkTableModel* new_table_model, - BookmarkNode* parent_node, + const BookmarkNode* parent_node, bool is_search); // Sets the table's model to the results of CreateSearchTableModel and selects diff --git a/chrome/browser/views/bookmark_menu_button.cc b/chrome/browser/views/bookmark_menu_button.cc index 2b299cb..4a4889b 100644 --- a/chrome/browser/views/bookmark_menu_button.cc +++ b/chrome/browser/views/bookmark_menu_button.cc @@ -89,7 +89,7 @@ int BookmarkMenuButton::OnPerformDrop(const views::DropTargetEvent& event) { if (!model) return DragDropTypes::DRAG_NONE; - BookmarkNode* parent = model->GetBookmarkBarNode(); + const BookmarkNode* parent = model->GetBookmarkBarNode(); return bookmark_utils::PerformBookmarkDrop( browser_->profile(), data, parent, parent->GetChildCount()); } diff --git a/chrome/browser/views/bookmark_menu_controller_views.cc b/chrome/browser/views/bookmark_menu_controller_views.cc index cd550ca..5fc5c97 100644 --- a/chrome/browser/views/bookmark_menu_controller_views.cc +++ b/chrome/browser/views/bookmark_menu_controller_views.cc @@ -22,7 +22,7 @@ BookmarkMenuController::BookmarkMenuController(Browser* browser, Profile* profile, PageNavigator* navigator, gfx::NativeView parent, - BookmarkNode* node, + const BookmarkNode* node, int start_child_index, bool show_other_folder) : browser_(browser), @@ -84,7 +84,7 @@ bool BookmarkMenuController::CanDrop(views::MenuItemView* menu, if (drop_data_.has_single_url()) return true; - BookmarkNode* drag_node = drop_data_.GetFirstNode(profile_); + const BookmarkNode* drag_node = drop_data_.GetFirstNode(profile_); if (!drag_node) { // Dragging a group from another profile, always accept. return true; @@ -92,7 +92,7 @@ bool BookmarkMenuController::CanDrop(views::MenuItemView* menu, // Drag originated from same profile and is not a URL. Only accept it if // the dragged node is not a parent of the node menu represents. - BookmarkNode* drop_node = menu_id_to_node_map_[menu->GetCommand()]; + const BookmarkNode* drop_node = menu_id_to_node_map_[menu->GetCommand()]; DCHECK(drop_node); while (drop_node && drop_node != drag_node) drop_node = drop_node->GetParent(); @@ -106,8 +106,8 @@ int BookmarkMenuController::GetDropOperation( // Should only get here if we have drop data. DCHECK(drop_data_.is_valid()); - BookmarkNode* node = menu_id_to_node_map_[item->GetCommand()]; - BookmarkNode* drop_parent = node->GetParent(); + const BookmarkNode* node = menu_id_to_node_map_[item->GetCommand()]; + const BookmarkNode* drop_parent = node->GetParent(); int index_to_drop_at = drop_parent->IndexOfChild(node); if (*position == DROP_AFTER) { if (node == profile_->GetBookmarkModel()->other_node()) { @@ -128,11 +128,11 @@ int BookmarkMenuController::GetDropOperation( int BookmarkMenuController::OnPerformDrop(views::MenuItemView* menu, DropPosition position, const views::DropTargetEvent& event) { - BookmarkNode* drop_node = menu_id_to_node_map_[menu->GetCommand()]; + const BookmarkNode* drop_node = menu_id_to_node_map_[menu->GetCommand()]; DCHECK(drop_node); BookmarkModel* model = profile_->GetBookmarkModel(); DCHECK(model); - BookmarkNode* drop_parent = drop_node->GetParent(); + const BookmarkNode* drop_parent = drop_node->GetParent(); DCHECK(drop_parent); int index_to_drop_at = drop_parent->IndexOfChild(drop_node); if (position == DROP_AFTER) { @@ -156,7 +156,7 @@ bool BookmarkMenuController::ShowContextMenu(views::MenuItemView* source, int y, bool is_mouse_gesture) { DCHECK(menu_id_to_node_map_.find(id) != menu_id_to_node_map_.end()); - std::vector<BookmarkNode*> nodes; + std::vector<const BookmarkNode*> nodes; nodes.push_back(menu_id_to_node_map_[id]); context_menu_.reset( new BookmarkContextMenu(parent_, @@ -176,7 +176,7 @@ void BookmarkMenuController::DropMenuClosed(views::MenuItemView* menu) { } bool BookmarkMenuController::CanDrag(views::MenuItemView* menu) { - BookmarkNode* node = menu_id_to_node_map_[menu->GetCommand()]; + const BookmarkNode* node = menu_id_to_node_map_[menu->GetCommand()]; // Don't let users drag the other folder. return node->GetParent() != profile_->GetBookmarkModel()->root_node(); } @@ -200,14 +200,14 @@ void BookmarkMenuController::BookmarkModelChanged() { menu_->Cancel(); } -void BookmarkMenuController::BookmarkNodeFavIconLoaded(BookmarkModel* model, - BookmarkNode* node) { +void BookmarkMenuController::BookmarkNodeFavIconLoaded( + BookmarkModel* model, const BookmarkNode* node) { if (node_to_menu_id_map_.find(node) != node_to_menu_id_map_.end()) menu_->SetIcon(model->GetFavIcon(node), node_to_menu_id_map_[node]); } void BookmarkMenuController::BuildOtherFolderMenu(int* next_menu_id) { - BookmarkNode* other_folder = profile_->GetBookmarkModel()->other_node(); + const BookmarkNode* other_folder = profile_->GetBookmarkModel()->other_node(); int id = *next_menu_id; (*next_menu_id)++; SkBitmap* folder_icon = ResourceBundle::GetSharedInstance(). @@ -218,14 +218,14 @@ void BookmarkMenuController::BuildOtherFolderMenu(int* next_menu_id) { menu_id_to_node_map_[id] = other_folder; } -void BookmarkMenuController::BuildMenu(BookmarkNode* parent, +void BookmarkMenuController::BuildMenu(const BookmarkNode* parent, int start_child_index, views::MenuItemView* menu, int* next_menu_id) { 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); int id = *next_menu_id; (*next_menu_id)++; diff --git a/chrome/browser/views/bookmark_menu_controller_views.h b/chrome/browser/views/bookmark_menu_controller_views.h index a87ecfe..e9bd5d3 100644 --- a/chrome/browser/views/bookmark_menu_controller_views.h +++ b/chrome/browser/views/bookmark_menu_controller_views.h @@ -39,7 +39,7 @@ class BookmarkMenuController : public BaseBookmarkModelObserver, Profile* profile, PageNavigator* page_navigator, gfx::NativeView parent, - BookmarkNode* node, + const BookmarkNode* node, int start_child_index, bool show_other_folder); @@ -52,7 +52,7 @@ class BookmarkMenuController : public BaseBookmarkModelObserver, void Cancel(); // Returns the node the menu is showing for. - BookmarkNode* node() const { return node_; } + const BookmarkNode* node() const { return node_; } // Returns the menu. views::MenuItemView* menu() const { return menu_.get(); } @@ -86,7 +86,7 @@ class BookmarkMenuController : public BaseBookmarkModelObserver, virtual void BookmarkModelChanged(); virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model, - BookmarkNode* node); + const BookmarkNode* node); private: // BookmarkMenuController deletes itself as necessary. @@ -98,7 +98,7 @@ class BookmarkMenuController : public BaseBookmarkModelObserver, // Creates an entry in menu for each child node of |parent| starting at // |start_child_index|. - void BuildMenu(BookmarkNode* parent, + void BuildMenu(const BookmarkNode* parent, int start_child_index, views::MenuItemView* menu, int* next_menu_id); @@ -113,14 +113,14 @@ class BookmarkMenuController : public BaseBookmarkModelObserver, gfx::NativeView parent_; // The node we're showing the contents of. - BookmarkNode* node_; + const BookmarkNode* node_; // Maps from menu id to BookmarkNode. - std::map<int, BookmarkNode*> menu_id_to_node_map_; + std::map<int, const BookmarkNode*> menu_id_to_node_map_; // Mapping from node to menu id. This only contains entries for nodes of type // URL. - std::map<BookmarkNode*, int> node_to_menu_id_map_; + std::map<const BookmarkNode*, int> node_to_menu_id_map_; // The menu. scoped_ptr<views::MenuItemView> menu_; diff --git a/chrome/browser/views/bookmark_table_view.cc b/chrome/browser/views/bookmark_table_view.cc index 7705d1b..3eaa2f3 100644 --- a/chrome/browser/views/bookmark_table_view.cc +++ b/chrome/browser/views/bookmark_table_view.cc @@ -64,7 +64,7 @@ bool BookmarkTableView::CanDrop(const OSExchangeData& data) { // Don't allow the user to drop an ancestor of the parent node onto the // parent node. This would create a cycle, which is definitely a no-no. - std::vector<BookmarkNode*> nodes = drag_data.GetNodes(profile_); + std::vector<const BookmarkNode*> nodes = drag_data.GetNodes(profile_); for (size_t i = 0; i < nodes.size(); ++i) { if (parent_node_->HasAncestor(nodes[i])) return false; @@ -187,7 +187,7 @@ int BookmarkTableView::UpdateDropInfo() { } void BookmarkTableView::BeginDrag() { - std::vector<BookmarkNode*> nodes_to_drag; + std::vector<const BookmarkNode*> nodes_to_drag; for (TableView::iterator i = SelectionBegin(); i != SelectionEnd(); ++i) nodes_to_drag.push_back(bookmark_table_model()->GetNodeForRow(*i)); if (nodes_to_drag.empty()) @@ -213,7 +213,7 @@ int BookmarkTableView::CalculateDropOperation(const DropPosition& position) { return DragDropTypes::DRAG_COPY; int real_drop_index; - BookmarkNode* drop_parent = GetDropParentAndIndex(position, + const BookmarkNode* drop_parent = GetDropParentAndIndex(position, &real_drop_index); if (!bookmark_utils::IsValidDropLocation( profile_, drop_info_->data(), drop_parent, real_drop_index)) { @@ -230,7 +230,7 @@ int BookmarkTableView::CalculateDropOperation(const DropPosition& position) { void BookmarkTableView::OnPerformDropImpl() { int drop_index; - BookmarkNode* drop_parent = GetDropParentAndIndex( + const BookmarkNode* drop_parent = GetDropParentAndIndex( drop_info_->position(), &drop_index); BookmarkModel* model = profile_->GetBookmarkModel(); int min_selection; @@ -246,7 +246,8 @@ void BookmarkTableView::OnPerformDropImpl() { static_cast<int>(drop_info_->data().elements.size()); } else { // else, move. - std::vector<BookmarkNode*> nodes = drop_info_->data().GetNodes(profile_); + std::vector<const BookmarkNode*> nodes = + drop_info_->data().GetNodes(profile_); if (nodes.empty()) return; @@ -330,11 +331,11 @@ BookmarkTableView::DropPosition return DropPosition(row_count, false); } -BookmarkNode* BookmarkTableView::GetDropParentAndIndex( +const BookmarkNode* BookmarkTableView::GetDropParentAndIndex( const DropPosition& position, int* index) { if (position.on) { - BookmarkNode* parent = parent_node_->GetChild(position.index); + const BookmarkNode* parent = parent_node_->GetChild(position.index); *index = parent->GetChildCount(); return parent; } diff --git a/chrome/browser/views/bookmark_table_view.h b/chrome/browser/views/bookmark_table_view.h index b80d1fa..2cd6891 100644 --- a/chrome/browser/views/bookmark_table_view.h +++ b/chrome/browser/views/bookmark_table_view.h @@ -35,7 +35,7 @@ class BookmarkTableView : public views::TableView { // Sets the parent of the nodes being displayed. For search and recently // found results |parent| is NULL. - void set_parent_node(BookmarkNode* parent) { parent_node_ = parent; } + void set_parent_node(const BookmarkNode* parent) { parent_node_ = parent; } // Sets whether the path column should be shown. The path column is shown // for search results and recently bookmarked. @@ -127,8 +127,8 @@ class BookmarkTableView : public views::TableView { DropPosition CalculateDropPosition(int y); // Returns the BookmarkNode the drop should occur on. - BookmarkNode* GetDropParentAndIndex(const DropPosition& position, - int* index); + const BookmarkNode* GetDropParentAndIndex(const DropPosition& position, + int* index); // Returns the bounds of drop indicator shown when the drop is to occur // between rows (drop_on is false). @@ -149,7 +149,7 @@ class BookmarkTableView : public views::TableView { Profile* profile_; - BookmarkNode* parent_node_; + const BookmarkNode* parent_node_; scoped_ptr<DropInfo> drop_info_; diff --git a/chrome/browser/views/toolbar_view.cc b/chrome/browser/views/toolbar_view.cc index 83c9107..430da1c 100644 --- a/chrome/browser/views/toolbar_view.cc +++ b/chrome/browser/views/toolbar_view.cc @@ -757,7 +757,7 @@ void ToolbarView::WriteDragData(views::View* sender, TabContents* tab = browser_->GetSelectedTabContents(); if (tab) { if (profile_ && profile_->GetBookmarkModel()) { - BookmarkNode* node = profile_->GetBookmarkModel()-> + const BookmarkNode* node = profile_->GetBookmarkModel()-> GetMostRecentlyAddedNodeForURL(tab->GetURL()); if (node) { BookmarkDragData bookmark_data(node); |