Cleanup redundant model_ field in BookmarkBarView.

BUG=None
R=sky@chromium.org

Review URL: https://codereview.chromium.org/321553004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@275677 0039d316-1c4b-4281-b951-d872f2087c98
parent 25b51679
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#include <algorithm> #include <algorithm>
#include <limits> #include <limits>
#include <set> #include <string>
#include <vector> #include <vector>
#include "base/bind.h" #include "base/bind.h"
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/browser/bookmarks/bookmark_model_factory.h" #include "chrome/browser/bookmarks/bookmark_model_factory.h"
#include "chrome/browser/bookmarks/chrome_bookmark_client.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/defaults.h" #include "chrome/browser/defaults.h"
...@@ -439,7 +438,6 @@ static const gfx::ImageSkia& GetFolderIcon() { ...@@ -439,7 +438,6 @@ static const gfx::ImageSkia& GetFolderIcon() {
BookmarkBarView::BookmarkBarView(Browser* browser, BrowserView* browser_view) BookmarkBarView::BookmarkBarView(Browser* browser, BrowserView* browser_view)
: page_navigator_(NULL), : page_navigator_(NULL),
model_(NULL),
client_(NULL), client_(NULL),
bookmark_menu_(NULL), bookmark_menu_(NULL),
bookmark_drop_menu_(NULL), bookmark_drop_menu_(NULL),
...@@ -463,8 +461,8 @@ BookmarkBarView::BookmarkBarView(Browser* browser, BrowserView* browser_view) ...@@ -463,8 +461,8 @@ BookmarkBarView::BookmarkBarView(Browser* browser, BrowserView* browser_view)
} }
BookmarkBarView::~BookmarkBarView() { BookmarkBarView::~BookmarkBarView() {
if (model_) if (client_)
model_->RemoveObserver(this); model()->RemoveObserver(this);
// It's possible for the menu to outlive us, reset the observer to make sure // It's possible for the menu to outlive us, reset the observer to make sure
// it doesn't have a reference to us. // it doesn't have a reference to us.
...@@ -544,20 +542,20 @@ const BookmarkNode* BookmarkBarView::GetNodeForButtonAtModelIndex( ...@@ -544,20 +542,20 @@ const BookmarkNode* BookmarkBarView::GetNodeForButtonAtModelIndex(
if (!child->visible()) if (!child->visible())
break; break;
if (child->bounds().Contains(adjusted_loc)) if (child->bounds().Contains(adjusted_loc))
return model_->bookmark_bar_node()->GetChild(i); return model()->bookmark_bar_node()->GetChild(i);
} }
// Then the overflow button. // Then the overflow button.
if (overflow_button_->visible() && if (overflow_button_->visible() &&
overflow_button_->bounds().Contains(adjusted_loc)) { overflow_button_->bounds().Contains(adjusted_loc)) {
*model_start_index = GetFirstHiddenNodeIndex(); *model_start_index = GetFirstHiddenNodeIndex();
return model_->bookmark_bar_node(); return model()->bookmark_bar_node();
} }
// And finally the other folder. // And finally the other folder.
if (other_bookmarked_button_->visible() && if (other_bookmarked_button_->visible() &&
other_bookmarked_button_->bounds().Contains(adjusted_loc)) { other_bookmarked_button_->bounds().Contains(adjusted_loc)) {
return model_->other_node(); return model()->other_node();
} }
return NULL; return NULL;
...@@ -567,11 +565,11 @@ views::MenuButton* BookmarkBarView::GetMenuButtonForNode( ...@@ -567,11 +565,11 @@ views::MenuButton* BookmarkBarView::GetMenuButtonForNode(
const BookmarkNode* node) { const BookmarkNode* node) {
if (node == client_->managed_node()) if (node == client_->managed_node())
return managed_bookmarks_button_; return managed_bookmarks_button_;
if (node == model_->other_node()) if (node == model()->other_node())
return other_bookmarked_button_; return other_bookmarked_button_;
if (node == model_->bookmark_bar_node()) if (node == model()->bookmark_bar_node())
return overflow_button_; return overflow_button_;
int index = model_->bookmark_bar_node()->GetIndexOf(node); int index = model()->bookmark_bar_node()->GetIndexOf(node);
if (index == -1 || !node->is_folder()) if (index == -1 || !node->is_folder())
return NULL; return NULL;
return static_cast<views::MenuButton*>(child_at(index)); return static_cast<views::MenuButton*>(child_at(index));
...@@ -811,7 +809,7 @@ void BookmarkBarView::PaintChildren(gfx::Canvas* canvas, ...@@ -811,7 +809,7 @@ void BookmarkBarView::PaintChildren(gfx::Canvas* canvas,
bool BookmarkBarView::GetDropFormats( bool BookmarkBarView::GetDropFormats(
int* formats, int* formats,
std::set<ui::OSExchangeData::CustomFormat>* custom_formats) { std::set<ui::OSExchangeData::CustomFormat>* custom_formats) {
if (!model_ || !model_->loaded()) if (!client_ || !model()->loaded())
return false; return false;
*formats = ui::OSExchangeData::URL; *formats = ui::OSExchangeData::URL;
custom_formats->insert(BookmarkNodeData::GetBookmarkCustomFormat()); custom_formats->insert(BookmarkNodeData::GetBookmarkCustomFormat());
...@@ -823,7 +821,7 @@ bool BookmarkBarView::AreDropTypesRequired() { ...@@ -823,7 +821,7 @@ bool BookmarkBarView::AreDropTypesRequired() {
} }
bool BookmarkBarView::CanDrop(const ui::OSExchangeData& data) { bool BookmarkBarView::CanDrop(const ui::OSExchangeData& data) {
if (!model_ || !model_->loaded() || if (!client_ || !model()->loaded() ||
!browser_->profile()->GetPrefs()->GetBoolean( !browser_->profile()->GetPrefs()->GetBoolean(
prefs::kEditBookmarksEnabled)) prefs::kEditBookmarksEnabled))
return false; return false;
...@@ -880,11 +878,11 @@ int BookmarkBarView::OnDragUpdated(const DropTargetEvent& event) { ...@@ -880,11 +878,11 @@ int BookmarkBarView::OnDragUpdated(const DropTargetEvent& event) {
location.button_type == DROP_OTHER_FOLDER) { location.button_type == DROP_OTHER_FOLDER) {
const BookmarkNode* node; const BookmarkNode* node;
if (location.button_type == DROP_OTHER_FOLDER) if (location.button_type == DROP_OTHER_FOLDER)
node = model_->other_node(); node = model()->other_node();
else if (location.button_type == DROP_OVERFLOW) else if (location.button_type == DROP_OVERFLOW)
node = model_->bookmark_bar_node(); node = model()->bookmark_bar_node();
else else
node = model_->bookmark_bar_node()->GetChild(location.index); node = model()->bookmark_bar_node()->GetChild(location.index);
StartShowFolderDropMenuTimer(node); StartShowFolderDropMenuTimer(node);
} }
...@@ -917,7 +915,7 @@ int BookmarkBarView::OnPerformDrop(const DropTargetEvent& event) { ...@@ -917,7 +915,7 @@ int BookmarkBarView::OnPerformDrop(const DropTargetEvent& event) {
const BookmarkNode* root = const BookmarkNode* root =
(drop_info_->location.button_type == DROP_OTHER_FOLDER) ? (drop_info_->location.button_type == DROP_OTHER_FOLDER) ?
model_->other_node() : model_->bookmark_bar_node(); model()->other_node() : model()->bookmark_bar_node();
int index = drop_info_->location.index; int index = drop_info_->location.index;
if (index != -1) { if (index != -1) {
...@@ -994,7 +992,7 @@ void BookmarkBarView::ShowImportDialog() { ...@@ -994,7 +992,7 @@ void BookmarkBarView::ShowImportDialog() {
void BookmarkBarView::OnBookmarkBubbleShown(const GURL& url) { void BookmarkBarView::OnBookmarkBubbleShown(const GURL& url) {
StopThrobbing(true); StopThrobbing(true);
const BookmarkNode* node = model_->GetMostRecentlyAddedUserNodeForURL(url); const BookmarkNode* node = model()->GetMostRecentlyAddedUserNodeForURL(url);
if (!node) if (!node)
return; // Generally shouldn't happen. return; // Generally shouldn't happen.
StartThrobbing(node, false); StartThrobbing(node, false);
...@@ -1009,14 +1007,14 @@ void BookmarkBarView::BookmarkModelLoaded(BookmarkModel* model, ...@@ -1009,14 +1007,14 @@ void BookmarkBarView::BookmarkModelLoaded(BookmarkModel* model,
// There should be no buttons. If non-zero it means Load was invoked more than // There should be no buttons. If non-zero it means Load was invoked more than
// once, or we didn't properly clear things. Either of which shouldn't happen. // once, or we didn't properly clear things. Either of which shouldn't happen.
DCHECK_EQ(0, GetBookmarkButtonCount()); DCHECK_EQ(0, GetBookmarkButtonCount());
const BookmarkNode* node = model_->bookmark_bar_node(); const BookmarkNode* node = model->bookmark_bar_node();
DCHECK(node); DCHECK(node);
// Create a button for each of the children on the bookmark bar. // Create a button for each of the children on the bookmark bar.
for (int i = 0, child_count = node->child_count(); i < child_count; ++i) for (int i = 0, child_count = node->child_count(); i < child_count; ++i)
AddChildViewAt(CreateBookmarkButton(node->GetChild(i)), i); AddChildViewAt(CreateBookmarkButton(node->GetChild(i)), i);
DCHECK(model_->other_node()); DCHECK(model->other_node());
other_bookmarked_button_->SetAccessibleName(model_->other_node()->GetTitle()); other_bookmarked_button_->SetAccessibleName(model->other_node()->GetTitle());
other_bookmarked_button_->SetText(model_->other_node()->GetTitle()); other_bookmarked_button_->SetText(model->other_node()->GetTitle());
managed_bookmarks_button_->SetAccessibleName( managed_bookmarks_button_->SetAccessibleName(
client_->managed_node()->GetTitle()); client_->managed_node()->GetTitle());
managed_bookmarks_button_->SetText(client_->managed_node()->GetTitle()); managed_bookmarks_button_->SetText(client_->managed_node()->GetTitle());
...@@ -1032,8 +1030,7 @@ void BookmarkBarView::BookmarkModelLoaded(BookmarkModel* model, ...@@ -1032,8 +1030,7 @@ void BookmarkBarView::BookmarkModelLoaded(BookmarkModel* model,
void BookmarkBarView::BookmarkModelBeingDeleted(BookmarkModel* model) { void BookmarkBarView::BookmarkModelBeingDeleted(BookmarkModel* model) {
NOTREACHED(); NOTREACHED();
// Do minimal cleanup, presumably we'll be deleted shortly. // Do minimal cleanup, presumably we'll be deleted shortly.
model_->RemoveObserver(this); model->RemoveObserver(this);
model_ = NULL;
client_ = NULL; client_ = NULL;
} }
...@@ -1092,7 +1089,7 @@ void BookmarkBarView::BookmarkNodeChanged(BookmarkModel* model, ...@@ -1092,7 +1089,7 @@ void BookmarkBarView::BookmarkNodeChanged(BookmarkModel* model,
void BookmarkBarView::BookmarkNodeChildrenReordered(BookmarkModel* model, void BookmarkBarView::BookmarkNodeChildrenReordered(BookmarkModel* model,
const BookmarkNode* node) { const BookmarkNode* node) {
if (node != model_->bookmark_bar_node()) if (node != model->bookmark_bar_node())
return; // We only care about reordering of the bookmark bar node. return; // We only care about reordering of the bookmark bar node.
// Remove the existing buttons. // Remove the existing buttons.
...@@ -1130,7 +1127,7 @@ void BookmarkBarView::WriteDragDataForView(View* sender, ...@@ -1130,7 +1127,7 @@ void BookmarkBarView::WriteDragDataForView(View* sender,
drag_utils::SetDragImageOnDataObject(*canvas, button->size(), drag_utils::SetDragImageOnDataObject(*canvas, button->size(),
press_pt.OffsetFromOrigin(), press_pt.OffsetFromOrigin(),
data); data);
WriteBookmarkDragData(model_->bookmark_bar_node()->GetChild(i), data); WriteBookmarkDragData(model()->bookmark_bar_node()->GetChild(i), data);
return; return;
} }
} }
...@@ -1152,7 +1149,7 @@ int BookmarkBarView::GetDragOperationsForView(View* sender, ...@@ -1152,7 +1149,7 @@ int BookmarkBarView::GetDragOperationsForView(View* sender,
for (int i = 0; i < GetBookmarkButtonCount(); ++i) { for (int i = 0; i < GetBookmarkButtonCount(); ++i) {
if (sender == GetBookmarkButton(i)) { if (sender == GetBookmarkButton(i)) {
return chrome::GetBookmarkDragOperation( return chrome::GetBookmarkDragOperation(
browser_->profile(), model_->bookmark_bar_node()->GetChild(i)); browser_->profile(), model()->bookmark_bar_node()->GetChild(i));
} }
} }
NOTREACHED(); NOTREACHED();
...@@ -1169,7 +1166,7 @@ bool BookmarkBarView::CanStartDragForView(views::View* sender, ...@@ -1169,7 +1166,7 @@ bool BookmarkBarView::CanStartDragForView(views::View* sender,
if (!View::ExceededDragThreshold(horizontal_offset) && move_offset.y() > 0) { if (!View::ExceededDragThreshold(horizontal_offset) && move_offset.y() > 0) {
for (int i = 0; i < GetBookmarkButtonCount(); ++i) { for (int i = 0; i < GetBookmarkButtonCount(); ++i) {
if (sender == GetBookmarkButton(i)) { if (sender == GetBookmarkButton(i)) {
const BookmarkNode* node = model_->bookmark_bar_node()->GetChild(i); const BookmarkNode* node = model()->bookmark_bar_node()->GetChild(i);
// If the folder button was dragged, show the menu instead. // If the folder button was dragged, show the menu instead.
if (node && node->is_folder()) { if (node && node->is_folder()) {
views::MenuButton* menu_button = views::MenuButton* menu_button =
...@@ -1190,16 +1187,16 @@ void BookmarkBarView::OnMenuButtonClicked(views::View* view, ...@@ -1190,16 +1187,16 @@ void BookmarkBarView::OnMenuButtonClicked(views::View* view,
int start_index = 0; int start_index = 0;
if (view == other_bookmarked_button_) { if (view == other_bookmarked_button_) {
node = model_->other_node(); node = model()->other_node();
} else if (view == managed_bookmarks_button_) { } else if (view == managed_bookmarks_button_) {
node = client_->managed_node(); node = client_->managed_node();
} else if (view == overflow_button_) { } else if (view == overflow_button_) {
node = model_->bookmark_bar_node(); node = model()->bookmark_bar_node();
start_index = GetFirstHiddenNodeIndex(); start_index = GetFirstHiddenNodeIndex();
} else { } else {
int button_index = GetIndexOf(view); int button_index = GetIndexOf(view);
DCHECK_NE(-1, button_index); DCHECK_NE(-1, button_index);
node = model_->bookmark_bar_node()->GetChild(button_index); node = model()->bookmark_bar_node()->GetChild(button_index);
} }
RecordBookmarkFolderOpen(GetBookmarkLaunchLocation()); RecordBookmarkFolderOpen(GetBookmarkLaunchLocation());
...@@ -1227,13 +1224,13 @@ void BookmarkBarView::ButtonPressed(views::Button* sender, ...@@ -1227,13 +1224,13 @@ void BookmarkBarView::ButtonPressed(views::Button* sender,
const BookmarkNode* node; const BookmarkNode* node;
if (sender->tag() == kOtherFolderButtonTag) { if (sender->tag() == kOtherFolderButtonTag) {
node = model_->other_node(); node = model()->other_node();
} else if (sender->tag() == kManagedFolderButtonTag) { } else if (sender->tag() == kManagedFolderButtonTag) {
node = client_->managed_node(); node = client_->managed_node();
} else { } else {
int index = GetIndexOf(sender); int index = GetIndexOf(sender);
DCHECK_NE(-1, index); DCHECK_NE(-1, index);
node = model_->bookmark_bar_node()->GetChild(index); node = model()->bookmark_bar_node()->GetChild(index);
} }
DCHECK(page_navigator_); DCHECK(page_navigator_);
...@@ -1254,7 +1251,7 @@ void BookmarkBarView::ButtonPressed(views::Button* sender, ...@@ -1254,7 +1251,7 @@ void BookmarkBarView::ButtonPressed(views::Button* sender,
void BookmarkBarView::ShowContextMenuForView(views::View* source, void BookmarkBarView::ShowContextMenuForView(views::View* source,
const gfx::Point& point, const gfx::Point& point,
ui::MenuSourceType source_type) { ui::MenuSourceType source_type) {
if (!model_->loaded()) { if (!model()->loaded()) {
// Don't do anything if the model isn't loaded. // Don't do anything if the model isn't loaded.
return; return;
} }
...@@ -1262,7 +1259,7 @@ void BookmarkBarView::ShowContextMenuForView(views::View* source, ...@@ -1262,7 +1259,7 @@ void BookmarkBarView::ShowContextMenuForView(views::View* source,
const BookmarkNode* parent = NULL; const BookmarkNode* parent = NULL;
std::vector<const BookmarkNode*> nodes; std::vector<const BookmarkNode*> nodes;
if (source == other_bookmarked_button_) { if (source == other_bookmarked_button_) {
parent = model_->other_node(); parent = model()->other_node();
// Do this so the user can open all bookmarks. BookmarkContextMenu makes // Do this so the user can open all bookmarks. BookmarkContextMenu makes
// sure the user can't edit/delete the node in this case. // sure the user can't edit/delete the node in this case.
nodes.push_back(parent); nodes.push_back(parent);
...@@ -1277,15 +1274,15 @@ void BookmarkBarView::ShowContextMenuForView(views::View* source, ...@@ -1277,15 +1274,15 @@ void BookmarkBarView::ShowContextMenuForView(views::View* source,
DCHECK(bookmark_button_index != -1 && DCHECK(bookmark_button_index != -1 &&
bookmark_button_index < GetBookmarkButtonCount()); bookmark_button_index < GetBookmarkButtonCount());
const BookmarkNode* node = const BookmarkNode* node =
model_->bookmark_bar_node()->GetChild(bookmark_button_index); model()->bookmark_bar_node()->GetChild(bookmark_button_index);
nodes.push_back(node); nodes.push_back(node);
parent = node->parent(); parent = node->parent();
} else { } else {
parent = model_->bookmark_bar_node(); parent = model()->bookmark_bar_node();
nodes.push_back(parent); nodes.push_back(parent);
} }
bool close_on_remove = bool close_on_remove =
(parent == model_->other_node()) && (parent->child_count() == 1); (parent == model()->other_node()) && (parent->child_count() == 1);
context_menu_.reset(new BookmarkContextMenu( context_menu_.reset(new BookmarkContextMenu(
GetWidget(), browser_, browser_->profile(), GetWidget(), browser_, browser_->profile(),
...@@ -1340,10 +1337,9 @@ void BookmarkBarView::Init() { ...@@ -1340,10 +1337,9 @@ void BookmarkBarView::Init() {
client_ = BookmarkModelFactory::GetChromeBookmarkClientForProfile( client_ = BookmarkModelFactory::GetChromeBookmarkClientForProfile(
browser_->profile()); browser_->profile());
if (client_) { if (client_) {
model_ = client_->model(); model()->AddObserver(this);
model_->AddObserver(this); if (model()->loaded())
if (model_->loaded()) BookmarkModelLoaded(model(), false);
BookmarkModelLoaded(model_, false);
// else case: we'll receive notification back from the BookmarkModel when // else case: we'll receive notification back from the BookmarkModel when
// done loading, then we'll populate the bar. // done loading, then we'll populate the bar.
} }
...@@ -1464,7 +1460,7 @@ void BookmarkBarView::ConfigureButton(const BookmarkNode* node, ...@@ -1464,7 +1460,7 @@ void BookmarkBarView::ConfigureButton(const BookmarkNode* node,
button->set_context_menu_controller(this); button->set_context_menu_controller(this);
button->set_drag_controller(this); button->set_drag_controller(this);
if (node->is_url()) { if (node->is_url()) {
const gfx::Image& favicon = model_->GetFavicon(node); const gfx::Image& favicon = model()->GetFavicon(node);
if (!favicon.IsEmpty()) if (!favicon.IsEmpty())
button->SetIcon(*favicon.ToImageSkia()); button->SetIcon(*favicon.ToImageSkia());
else else
...@@ -1477,7 +1473,7 @@ void BookmarkBarView::BookmarkNodeAddedImpl(BookmarkModel* model, ...@@ -1477,7 +1473,7 @@ void BookmarkBarView::BookmarkNodeAddedImpl(BookmarkModel* model,
const BookmarkNode* parent, const BookmarkNode* parent,
int index) { int index) {
UpdateButtonsVisibility(); UpdateButtonsVisibility();
if (parent != model_->bookmark_bar_node()) { if (parent != model->bookmark_bar_node()) {
// We only care about nodes on the bookmark bar. // We only care about nodes on the bookmark bar.
return; return;
} }
...@@ -1502,7 +1498,7 @@ void BookmarkBarView::BookmarkNodeRemovedImpl(BookmarkModel* model, ...@@ -1502,7 +1498,7 @@ void BookmarkBarView::BookmarkNodeRemovedImpl(BookmarkModel* model,
// No need to start throbbing again as the bookmark bubble can't be up at // No need to start throbbing again as the bookmark bubble can't be up at
// the same time as the user reorders. // the same time as the user reorders.
if (parent != model_->bookmark_bar_node()) { if (parent != model->bookmark_bar_node()) {
// We only care about nodes on the bookmark bar. // We only care about nodes on the bookmark bar.
return; return;
} }
...@@ -1516,11 +1512,11 @@ void BookmarkBarView::BookmarkNodeRemovedImpl(BookmarkModel* model, ...@@ -1516,11 +1512,11 @@ void BookmarkBarView::BookmarkNodeRemovedImpl(BookmarkModel* model,
void BookmarkBarView::BookmarkNodeChangedImpl(BookmarkModel* model, void BookmarkBarView::BookmarkNodeChangedImpl(BookmarkModel* model,
const BookmarkNode* node) { const BookmarkNode* node) {
if (node->parent() != model_->bookmark_bar_node()) { if (node->parent() != model->bookmark_bar_node()) {
// We only care about nodes on the bookmark bar. // We only care about nodes on the bookmark bar.
return; return;
} }
int index = model_->bookmark_bar_node()->GetIndexOf(node); int index = model->bookmark_bar_node()->GetIndexOf(node);
DCHECK_NE(-1, index); DCHECK_NE(-1, index);
views::TextButton* button = GetBookmarkButton(index); views::TextButton* button = GetBookmarkButton(index);
gfx::Size old_pref = button->GetPreferredSize(); gfx::Size old_pref = button->GetPreferredSize();
...@@ -1548,7 +1544,7 @@ void BookmarkBarView::ShowDropFolderForNode(const BookmarkNode* node) { ...@@ -1548,7 +1544,7 @@ void BookmarkBarView::ShowDropFolderForNode(const BookmarkNode* node) {
return; return;
int start_index = 0; int start_index = 0;
if (node == model_->bookmark_bar_node()) if (node == model()->bookmark_bar_node())
start_index = GetFirstHiddenNodeIndex(); start_index = GetFirstHiddenNodeIndex();
drop_info_->is_menu_showing = true; drop_info_->is_menu_showing = true;
...@@ -1581,8 +1577,8 @@ void BookmarkBarView::StartShowFolderDropMenuTimer(const BookmarkNode* node) { ...@@ -1581,8 +1577,8 @@ void BookmarkBarView::StartShowFolderDropMenuTimer(const BookmarkNode* node) {
void BookmarkBarView::CalculateDropLocation(const DropTargetEvent& event, void BookmarkBarView::CalculateDropLocation(const DropTargetEvent& event,
const BookmarkNodeData& data, const BookmarkNodeData& data,
DropLocation* location) { DropLocation* location) {
DCHECK(model_); DCHECK(client_);
DCHECK(model_->loaded()); DCHECK(model()->loaded());
DCHECK(data.is_valid()); DCHECK(data.is_valid());
*location = DropLocation(); *location = DropLocation();
...@@ -1606,7 +1602,7 @@ void BookmarkBarView::CalculateDropLocation(const DropTargetEvent& event, ...@@ -1606,7 +1602,7 @@ void BookmarkBarView::CalculateDropLocation(const DropTargetEvent& event,
} else if (!GetBookmarkButtonCount()) { } else if (!GetBookmarkButtonCount()) {
// No bookmarks, accept the drop. // No bookmarks, accept the drop.
location->index = 0; location->index = 0;
const BookmarkNode* node = data.GetFirstNode(model_, profile->GetPath()); const BookmarkNode* node = data.GetFirstNode(model(), profile->GetPath());
int ops = node && client_->CanBeEditedByUser(node) ? int ops = node && client_->CanBeEditedByUser(node) ?
ui::DragDropTypes::DRAG_MOVE : ui::DragDropTypes::DRAG_MOVE :
ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_LINK; ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_LINK;
...@@ -1622,7 +1618,7 @@ void BookmarkBarView::CalculateDropLocation(const DropTargetEvent& event, ...@@ -1622,7 +1618,7 @@ void BookmarkBarView::CalculateDropLocation(const DropTargetEvent& event,
int button_w = button->width(); int button_w = button->width();
if (button_x < button_w) { if (button_x < button_w) {
found = true; found = true;
const BookmarkNode* node = model_->bookmark_bar_node()->GetChild(i); const BookmarkNode* node = model()->bookmark_bar_node()->GetChild(i);
if (node->is_folder()) { if (node->is_folder()) {
if (button_x <= views::kDropBetweenPixels) { if (button_x <= views::kDropBetweenPixels) {
location->index = i; location->index = i;
...@@ -1669,18 +1665,18 @@ void BookmarkBarView::CalculateDropLocation(const DropTargetEvent& event, ...@@ -1669,18 +1665,18 @@ void BookmarkBarView::CalculateDropLocation(const DropTargetEvent& event,
if (location->on) { if (location->on) {
const BookmarkNode* parent = (location->button_type == DROP_OTHER_FOLDER) ? const BookmarkNode* parent = (location->button_type == DROP_OTHER_FOLDER) ?
model_->other_node() : model()->other_node() :
model_->bookmark_bar_node()->GetChild(location->index); model()->bookmark_bar_node()->GetChild(location->index);
location->operation = chrome::GetBookmarkDropOperation( location->operation = chrome::GetBookmarkDropOperation(
profile, event, data, parent, parent->child_count()); profile, event, data, parent, parent->child_count());
if (!location->operation && !data.has_single_url() && if (!location->operation && !data.has_single_url() &&
data.GetFirstNode(model_, profile->GetPath()) == parent) { data.GetFirstNode(model(), profile->GetPath()) == parent) {
// Don't open a menu if the node being dragged is the menu to open. // Don't open a menu if the node being dragged is the menu to open.
location->on = false; location->on = false;
} }
} else { } else {
location->operation = chrome::GetBookmarkDropOperation( location->operation = chrome::GetBookmarkDropOperation(
profile, event, data, model_->bookmark_bar_node(), location->index); profile, event, data, model()->bookmark_bar_node(), location->index);
} }
} }
...@@ -1697,7 +1693,7 @@ void BookmarkBarView::StartThrobbing(const BookmarkNode* node, ...@@ -1697,7 +1693,7 @@ void BookmarkBarView::StartThrobbing(const BookmarkNode* node,
// Determine which visible button is showing the bookmark (or is an ancestor // Determine which visible button is showing the bookmark (or is an ancestor
// of the bookmark). // of the bookmark).
const BookmarkNode* bbn = model_->bookmark_bar_node(); const BookmarkNode* bbn = model()->bookmark_bar_node();
const BookmarkNode* parent_on_bb = node; const BookmarkNode* parent_on_bb = node;
while (parent_on_bb) { while (parent_on_bb) {
const BookmarkNode* parent = parent_on_bb->parent(); const BookmarkNode* parent = parent_on_bb->parent();
...@@ -1727,7 +1723,7 @@ void BookmarkBarView::StartThrobbing(const BookmarkNode* node, ...@@ -1727,7 +1723,7 @@ void BookmarkBarView::StartThrobbing(const BookmarkNode* node,
views::CustomButton* BookmarkBarView::DetermineViewToThrobFromRemove( views::CustomButton* BookmarkBarView::DetermineViewToThrobFromRemove(
const BookmarkNode* parent, const BookmarkNode* parent,
int old_index) { int old_index) {
const BookmarkNode* bbn = model_->bookmark_bar_node(); const BookmarkNode* bbn = model()->bookmark_bar_node();
const BookmarkNode* old_node = parent; const BookmarkNode* old_node = parent;
int old_index_on_bb = old_index; int old_index_on_bb = old_index;
while (old_node && old_node != bbn) { while (old_node && old_node != bbn) {
...@@ -1767,7 +1763,7 @@ void BookmarkBarView::UpdateColors() { ...@@ -1767,7 +1763,7 @@ void BookmarkBarView::UpdateColors() {
} }
void BookmarkBarView::UpdateButtonsVisibility() { void BookmarkBarView::UpdateButtonsVisibility() {
bool has_other_children = !model_->other_node()->empty(); bool has_other_children = !model()->other_node()->empty();
bool update_other = has_other_children != other_bookmarked_button_->visible(); bool update_other = has_other_children != other_bookmarked_button_->visible();
if (update_other) { if (update_other) {
other_bookmarked_button_->SetVisible(has_other_children); other_bookmarked_button_->SetVisible(has_other_children);
...@@ -1851,7 +1847,7 @@ void BookmarkBarView::LayoutItems() { ...@@ -1851,7 +1847,7 @@ void BookmarkBarView::LayoutItems() {
} }
// Then go through the bookmark buttons. // Then go through the bookmark buttons.
if (GetBookmarkButtonCount() == 0 && model_ && model_->loaded()) { if (GetBookmarkButtonCount() == 0 && client_ && model()->loaded()) {
gfx::Size pref = instructions_->GetPreferredSize(); gfx::Size pref = instructions_->GetPreferredSize();
instructions_->SetBounds( instructions_->SetBounds(
x + kInstructionsPadding, y, x + kInstructionsPadding, y,
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#define CHROME_BROWSER_UI_VIEWS_BOOKMARKS_BOOKMARK_BAR_VIEW_H_ #define CHROME_BROWSER_UI_VIEWS_BOOKMARKS_BOOKMARK_BAR_VIEW_H_
#include <set> #include <set>
#include <string>
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
...@@ -14,6 +13,7 @@ ...@@ -14,6 +13,7 @@
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/prefs/pref_change_registrar.h" #include "base/prefs/pref_change_registrar.h"
#include "chrome/browser/bookmarks/bookmark_stats.h" #include "chrome/browser/bookmarks/bookmark_stats.h"
#include "chrome/browser/bookmarks/chrome_bookmark_client.h"
#include "chrome/browser/ui/bookmarks/bookmark_bar.h" #include "chrome/browser/ui/bookmarks/bookmark_bar.h"
#include "chrome/browser/ui/bookmarks/bookmark_bar_instructions_delegate.h" #include "chrome/browser/ui/bookmarks/bookmark_bar_instructions_delegate.h"
#include "chrome/browser/ui/views/bookmarks/bookmark_bubble_view_observer.h" #include "chrome/browser/ui/views/bookmarks/bookmark_bubble_view_observer.h"
...@@ -276,6 +276,8 @@ class BookmarkBarView : public DetachableToolbarView, ...@@ -276,6 +276,8 @@ class BookmarkBarView : public DetachableToolbarView,
// calculating the preferred height. // calculating the preferred height.
void Init(); void Init();
BookmarkModel* model() { return client_->model(); }
// NOTE: unless otherwise stated all methods that take an int for an index are // NOTE: unless otherwise stated all methods that take an int for an index are
// in terms of the bookmark bar view. Typically the view index and model index // in terms of the bookmark bar view. Typically the view index and model index
// are the same, but they may differ during animations or drag and drop. // are the same, but they may differ during animations or drag and drop.
...@@ -385,11 +387,8 @@ class BookmarkBarView : public DetachableToolbarView, ...@@ -385,11 +387,8 @@ class BookmarkBarView : public DetachableToolbarView,
// Used for opening urls. // Used for opening urls.
content::PageNavigator* page_navigator_; content::PageNavigator* page_navigator_;
// Model providing details as to the starred entries/folders that should be // ChromeBookmarkClient that owns the model whose entries and folders are
// shown. This is owned by the Profile. // shown in this view. This is owned by the Profile.
BookmarkModel* model_;
// The ChromeBookmarkClient that owns the |model_|.
ChromeBookmarkClient* client_; ChromeBookmarkClient* client_;
// Used to manage showing a Menu, either for the most recently bookmarked // Used to manage showing a Menu, either for the most recently bookmarked
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment