summaryrefslogtreecommitdiffstats
path: root/chrome/browser/views
diff options
context:
space:
mode:
authormpcomplete@google.com <mpcomplete@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-10 19:15:08 +0000
committermpcomplete@google.com <mpcomplete@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-10 19:15:08 +0000
commit4a8d3279cc9f2149c90d36550a55d01a264ba0a3 (patch)
tree10686a040d5bbb5af5dc4686564ceec0189fee22 /chrome/browser/views
parenta724b6ad91affee34adc5c3ab25b05536bb51f6d (diff)
downloadchromium_src-4a8d3279cc9f2149c90d36550a55d01a264ba0a3.zip
chromium_src-4a8d3279cc9f2149c90d36550a55d01a264ba0a3.tar.gz
chromium_src-4a8d3279cc9f2149c90d36550a55d01a264ba0a3.tar.bz2
Unrevert 11294.
- include stub fix so that linux/mac still build. - fix DCHECK in views code. - fix unit test. Review URL: http://codereview.chromium.org/41020 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@11360 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views')
-rw-r--r--chrome/browser/views/bookmark_bar_view.cc94
-rw-r--r--chrome/browser/views/bookmark_bar_view.h9
2 files changed, 96 insertions, 7 deletions
diff --git a/chrome/browser/views/bookmark_bar_view.cc b/chrome/browser/views/bookmark_bar_view.cc
index 43c48bdf..6738791 100644
--- a/chrome/browser/views/bookmark_bar_view.cc
+++ b/chrome/browser/views/bookmark_bar_view.cc
@@ -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 @@ class BookmarkFolderButton : public views::MenuButton {
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 @@ BookmarkBarView::BookmarkBarView(Profile* profile, Browser* browser)
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 @@ void BookmarkBarView::SetProfile(Profile* profile) {
// 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 @@ void BookmarkBarView::SetProfile(Profile* profile) {
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 @@ void BookmarkBarView::Layout() {
}
}
+ // 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 @@ MenuButton* BookmarkBarView::CreateOverflowButton() {
}
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 @@ void BookmarkBarView::Loaded(BookmarkModel* model) {
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 @@ void BookmarkBarView::Observe(NotificationType type,
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 @@ void BookmarkBarView::RemoveNotificationObservers() {
ns->RemoveObserver(this,
NotificationType::BOOKMARK_BAR_VISIBILITY_PREF_CHANGED,
NotificationService::AllSources());
+ ns->RemoveObserver(this, NotificationType::EXTENSIONS_LOADED,
+ NotificationService::AllSources());
}
void BookmarkBarView::NotifyModelChanged() {
diff --git a/chrome/browser/views/bookmark_bar_view.h b/chrome/browser/views/bookmark_bar_view.h
index 3475a61..5982fbf 100644
--- a/chrome/browser/views/bookmark_bar_view.h
+++ b/chrome/browser/views/bookmark_bar_view.h
@@ -7,6 +7,7 @@
#include "chrome/browser/bookmarks/bookmark_drag_data.h"
#include "chrome/browser/bookmarks/bookmark_model.h"
+#include "chrome/browser/extensions/extensions_service.h"
#include "chrome/common/slide_animation.h"
#include "chrome/views/label.h"
#include "chrome/views/menu.h"
@@ -384,6 +385,11 @@ class BookmarkBarView : public views::View,
// throbs.
void StopThrobbing(bool immediate);
+ // Add any extension toolstrips which may be requested by the given
+ // extensions. Views for the toolstrips are inserted after the last bookmark
+ // button. Returns true if there were any new toolstrips added.
+ bool AddExtensionToolstrips(const ExtensionList* extensions);
+
Profile* profile_;
// Used for opening urls.
@@ -436,6 +442,9 @@ class BookmarkBarView : public views::View,
// overflow_button_ or a button on the bar.
views::BaseButton* throbbing_view_;
+ // How many extension toolstrips we have showing in the toolbar.
+ int num_extension_toolstrips_;
+
DISALLOW_COPY_AND_ASSIGN(BookmarkBarView);
};