| Index: chrome/browser/views/bookmark_bar_view.cc
|
| ===================================================================
|
| --- chrome/browser/views/bookmark_bar_view.cc (revision 11270)
|
| +++ chrome/browser/views/bookmark_bar_view.cc (working copy)
|
| @@ -16,6 +16,9 @@
|
| #include "chrome/browser/browser_window.h"
|
| #include "chrome/browser/drag_utils.h"
|
| #include "chrome/browser/download/download_util.h"
|
| +#include "chrome/browser/extensions/extension.h"
|
| +#include "chrome/browser/extensions/extension_view.h"
|
| +#include "chrome/browser/extensions/extensions_service.h"
|
| #include "chrome/browser/history/history.h"
|
| #include "chrome/browser/metrics/user_metrics.h"
|
| #include "chrome/browser/profile.h"
|
| @@ -315,6 +318,37 @@
|
| DISALLOW_COPY_AND_ASSIGN(BookmarkFolderButton);
|
| };
|
|
|
| +// ExtensionToolstrip -------------------------------------------------------
|
| +
|
| +// A simple container with a border for an ExtensionView.
|
| +class ExtensionToolstrip : public views::View {
|
| + public:
|
| + static const int kPadding = 2;
|
| +
|
| + ExtensionToolstrip(const GURL& url, Profile* profile)
|
| + : view_(new ExtensionView(url, profile)) {
|
| + AddChildView(view_);
|
| + set_border(views::Border::CreateEmptyBorder(
|
| + kPadding, kPadding, kPadding, kPadding));
|
| + }
|
| +
|
| + virtual gfx::Size GetPreferredSize() {
|
| + gfx::Size size = view_->GetPreferredSize();
|
| + size.Enlarge(kPadding*2, kPadding*2);
|
| + return size;
|
| + }
|
| +
|
| + virtual void DidChangeBounds(const gfx::Rect& previous,
|
| + const gfx::Rect& current) {
|
| + view_->SetBounds(GetLocalBounds(false));
|
| + }
|
| +
|
| + private:
|
| + ExtensionView* view_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(ExtensionToolstrip);
|
| +};
|
| +
|
| // DropInfo -------------------------------------------------------------------
|
|
|
| // Tracks drops on the BookmarkBarView.
|
| @@ -689,7 +723,8 @@
|
| overflow_button_(NULL),
|
| instructions_(NULL),
|
| bookmarks_separator_view_(NULL),
|
| - throbbing_view_(NULL) {
|
| + throbbing_view_(NULL),
|
| + num_extension_toolstrips_(0) {
|
| SetID(VIEW_ID_BOOKMARK_BAR);
|
| Init();
|
| SetProfile(profile);
|
| @@ -720,8 +755,9 @@
|
| // Cancels the current cancelable.
|
| NotifyModelChanged();
|
|
|
| - // Remove the current buttons.
|
| - for (int i = GetBookmarkButtonCount() - 1; i >= 0; --i) {
|
| + // Remove the current buttons and extension toolstrips.
|
| + for (int i = GetBookmarkButtonCount() + num_extension_toolstrips_ - 1;
|
| + i >= 0; --i) {
|
| View* child = GetChildViewAt(i);
|
| RemoveChildView(child);
|
| delete child;
|
| @@ -742,6 +778,8 @@
|
| ns->AddObserver(this, NotificationType::BOOKMARK_BUBBLE_HIDDEN, ns_source);
|
| ns->AddObserver(this, NotificationType::BOOKMARK_BAR_VISIBILITY_PREF_CHANGED,
|
| NotificationService::AllSources());
|
| + ns->AddObserver(this, NotificationType::EXTENSIONS_LOADED,
|
| + NotificationService::AllSources());
|
|
|
| model_ = profile_->GetBookmarkModel();
|
| model_->AddObserver(this);
|
| @@ -835,6 +873,17 @@
|
| }
|
| }
|
|
|
| + // Extension toolstrips.
|
| + for (int i = GetBookmarkButtonCount();
|
| + i < GetBookmarkButtonCount() + num_extension_toolstrips_; ++i) {
|
| + views::View* child = GetChildViewAt(i);
|
| + gfx::Size pref = child->GetPreferredSize();
|
| + int next_x = x + pref.width() + kButtonPadding;
|
| + child->SetVisible(next_x < max_x);
|
| + child->SetBounds(x, y, pref.width(), height);
|
| + x = next_x;
|
| + }
|
| +
|
| // Layout the right side of the bar.
|
| const bool all_visible =
|
| (GetBookmarkButtonCount() == 0 ||
|
| @@ -1218,10 +1267,10 @@
|
| }
|
|
|
| int BookmarkBarView::GetBookmarkButtonCount() {
|
| - // We contain four non-bookmark button views: recently bookmarked,
|
| - // bookmarks separator, chevrons (for overflow) and the instruction
|
| - // label.
|
| - return GetChildViewCount() - 4;
|
| + // We contain at least four non-bookmark button views: recently bookmarked,
|
| + // bookmarks separator, chevrons (for overflow), the instruction
|
| + // label, as well as any ExtensionViews displaying toolstrips.
|
| + return GetChildViewCount() - 4 - num_extension_toolstrips_;
|
| }
|
|
|
| void BookmarkBarView::Loaded(BookmarkModel* model) {
|
| @@ -1231,6 +1280,9 @@
|
| for (int i = 0; i < node->GetChildCount(); ++i)
|
| AddChildView(i, CreateBookmarkButton(node->GetChild(i)));
|
| other_bookmarked_button_->SetEnabled(true);
|
| +
|
| + AddExtensionToolstrips(profile_->GetExtensionsService()->extensions());
|
| +
|
| Layout();
|
| SchedulePaint();
|
| }
|
| @@ -1582,9 +1634,35 @@
|
| StopThrobbing(false);
|
| bubble_url_ = GURL();
|
| break;
|
| +
|
| + case NotificationType::EXTENSIONS_LOADED: {
|
| + const ExtensionList* extensions = Details<ExtensionList>(details).ptr();
|
| + if (AddExtensionToolstrips(extensions)) {
|
| + Layout();
|
| + SchedulePaint();
|
| + }
|
| + break;
|
| + }
|
| }
|
| }
|
|
|
| +bool BookmarkBarView::AddExtensionToolstrips(const ExtensionList* extensions) {
|
| + bool added_toolstrip = false;
|
| + for (ExtensionList::const_iterator extension = extensions->begin();
|
| + extension != extensions->end(); ++extension) {
|
| + if (!(*extension)->toolstrip_url().is_empty()) {
|
| + ExtensionToolstrip* view =
|
| + new ExtensionToolstrip((*extension)->toolstrip_url(), profile_);
|
| + int index = GetBookmarkButtonCount() + num_extension_toolstrips_;
|
| + AddChildView(index, view);
|
| + added_toolstrip = true;
|
| + ++num_extension_toolstrips_;
|
| + }
|
| + }
|
| +
|
| + return added_toolstrip;
|
| +}
|
| +
|
| void BookmarkBarView::RemoveNotificationObservers() {
|
| NotificationService* ns = NotificationService::current();
|
| Source<Profile> ns_source(profile_->GetOriginalProfile());
|
| @@ -1593,6 +1671,8 @@
|
| ns->RemoveObserver(this,
|
| NotificationType::BOOKMARK_BAR_VISIBILITY_PREF_CHANGED,
|
| NotificationService::AllSources());
|
| + ns->RemoveObserver(this, NotificationType::EXTENSIONS_LOADED,
|
| + NotificationService::AllSources());
|
| }
|
|
|
| void BookmarkBarView::NotifyModelChanged() {
|
|
|