summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorsidchat@google.com <sidchat@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-02 20:49:45 +0000
committersidchat@google.com <sidchat@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-02 20:49:45 +0000
commitad573f16ef06760e855f3e13ad0902d19449cbd6 (patch)
tree6217bcdb61c5f54758f2cb606bb2aa4ff97ad3c1 /chrome/browser
parenta9d589c3000d0e72f32dcd47842374d306e29176 (diff)
downloadchromium_src-ad573f16ef06760e855f3e13ad0902d19449cbd6.zip
chromium_src-ad573f16ef06760e855f3e13ad0902d19449cbd6.tar.gz
chromium_src-ad573f16ef06760e855f3e13ad0902d19449cbd6.tar.bz2
Infrastructure to allow putting Extension Shelf on top along with Bookmarks.
BUG=http://code.google.com/p/chromium/issues/detail?id=20517 TEST=none Review URL: http://codereview.chromium.org/173613 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25236 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/views/bookmark_bar_view.cc477
-rw-r--r--chrome/browser/views/bookmark_bar_view.h24
-rw-r--r--chrome/browser/views/extensions/extension_shelf.cc119
-rw-r--r--chrome/browser/views/extensions/extension_shelf.h6
-rw-r--r--chrome/browser/views/frame/browser_view.cc333
-rw-r--r--chrome/browser/views/frame/browser_view.h5
6 files changed, 556 insertions, 408 deletions
diff --git a/chrome/browser/views/bookmark_bar_view.cc b/chrome/browser/views/bookmark_bar_view.cc
index 260d0df..4bee007 100644
--- a/chrome/browser/views/bookmark_bar_view.cc
+++ b/chrome/browser/views/bookmark_bar_view.cc
@@ -70,11 +70,6 @@ static const int kBarHeight = 29;
// Preferred height of the bookmarks bar when only shown on the new tab page.
const int BookmarkBarView::kNewtabBarHeight = 57;
-// How inset the bookmarks bar is when displayed on the new tab page. This is
-// in addition to the margins above.
-static const int kNewtabHorizontalPadding = 8;
-static const int kNewtabVerticalPadding = 12;
-
// Padding between buttons.
static const int kButtonPadding = 0;
@@ -376,6 +371,8 @@ class BookmarkBarView::ButtonSeparatorView : public views::View {
// static
const int BookmarkBarView::kMaxButtonWidth = 150;
+const int BookmarkBarView::kNewtabHorizontalPadding = 8;
+const int BookmarkBarView::kNewtabVerticalPadding = 12;
// static
bool BookmarkBarView::testing_ = false;
@@ -478,21 +475,7 @@ void BookmarkBarView::SetPageNavigator(PageNavigator* navigator) {
}
gfx::Size BookmarkBarView::GetPreferredSize() {
- gfx::Size prefsize;
- if (OnNewTabPage()) {
- prefsize.set_height(kBarHeight + static_cast<int>(static_cast<double>
- (kNewtabBarHeight - kBarHeight) *
- (1 - size_animation_->GetCurrentValue())));
- } else {
- prefsize.set_height(static_cast<int>(static_cast<double>(kBarHeight) *
- size_animation_->GetCurrentValue()));
- }
-
- // Width doesn't matter, we're always given a width based on the browser
- // size.
- prefsize.set_width(1);
-
- return prefsize;
+ return LayoutItems(true);
}
gfx::Size BookmarkBarView::GetMinimumSize() {
@@ -500,113 +483,7 @@ gfx::Size BookmarkBarView::GetMinimumSize() {
}
void BookmarkBarView::Layout() {
- if (!GetParent())
- return;
-
- int x = kLeftMargin;
- int y = kTopMargin;
- int width = View::width() - kRightMargin - kLeftMargin;
- int height = View::height() - kTopMargin - kBottomMargin;
- int separator_margin = kSeparatorMargin;
-
- if (OnNewTabPage()) {
- double current_state = 1 - size_animation_->GetCurrentValue();
- x += static_cast<int>(static_cast<double>
- (kNewtabHorizontalPadding) * current_state);
- y += static_cast<int>(static_cast<double>
- (kNewtabVerticalPadding) * current_state);
- width -= static_cast<int>(static_cast<double>
- (kNewtabHorizontalPadding) * current_state);
- height -= static_cast<int>(static_cast<double>
- (kNewtabVerticalPadding * 2) * current_state);
- separator_margin -= static_cast<int>(static_cast<double>
- (kSeparatorMargin) * current_state);
- }
-
- gfx::Size other_bookmarked_pref =
- other_bookmarked_button_->GetPreferredSize();
- gfx::Size overflow_pref = overflow_button_->GetPreferredSize();
- gfx::Size bookmarks_separator_pref =
- bookmarks_separator_view_->GetPreferredSize();
-
-#ifdef CHROME_PERSONALIZATION
- gfx::Size sync_error_button_pref = sync_error_button_->GetPreferredSize();
- const bool should_show_sync_error_button = ShouldShowSyncErrorButton();
- int sync_error_total_width = 0;
- if (should_show_sync_error_button) {
- sync_error_total_width += kButtonPadding + sync_error_button_pref.width();
- }
- const int max_x = width - other_bookmarked_pref.width() - kButtonPadding -
- overflow_pref.width() - kButtonPadding -
- bookmarks_separator_pref.width() - sync_error_total_width;
-#else
- const int max_x = width - other_bookmarked_pref.width() - kButtonPadding -
- overflow_pref.width() - kButtonPadding -
- bookmarks_separator_pref.width();
-#endif
-
- // Next, layout out the buttons. Any buttons that are placed beyond the
- // visible region and made invisible.
- if (GetBookmarkButtonCount() == 0 && model_ && model_->IsLoaded()) {
- gfx::Size pref = instructions_->GetPreferredSize();
- instructions_->SetBounds(
- x + kInstructionsPadding, y,
- std::min(static_cast<int>(pref.width()),
- max_x - x),
- height);
- instructions_->SetVisible(true);
- } else {
- instructions_->SetVisible(false);
-
- for (int i = 0; i < GetBookmarkButtonCount(); ++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 ||
- GetChildViewAt(GetBookmarkButtonCount() - 1)->IsVisible());
-
- // Layout the right side buttons.
- x = max_x + kButtonPadding;
-
- // The overflow button.
- overflow_button_->SetBounds(x, y, overflow_pref.width(), height);
- overflow_button_->SetVisible(!all_visible);
- x += overflow_pref.width();
-
- // Separator.
- bookmarks_separator_view_->SetBounds(x,
- y - kTopMargin,
- bookmarks_separator_pref.width(),
- height + kTopMargin + kBottomMargin -
- separator_margin);
- x += bookmarks_separator_pref.width();
-
- // The other bookmarks button.
- other_bookmarked_button_->SetBounds(x, y, other_bookmarked_pref.width(),
- height);
- x += other_bookmarked_pref.width() + kButtonPadding;
-
-#ifdef CHROME_PERSONALIZATION
- // Set the real bounds of the sync error button only if it needs to appear on
- // the bookmarks bar.
- if (should_show_sync_error_button) {
- x += kButtonPadding;
- sync_error_button_->SetBounds(x, y, sync_error_button_pref.width(), height);
- sync_error_button_->SetVisible(true);
- x += sync_error_button_pref.width();
- } else {
- sync_error_button_->SetBounds(x, y, 0, height);
- sync_error_button_->SetVisible(false);
- }
-#endif
+ LayoutItems(false);
}
void BookmarkBarView::DidChangeBounds(const gfx::Rect& previous,
@@ -632,206 +509,6 @@ void BookmarkBarView::ViewHierarchyChanged(bool is_add,
}
}
-void BookmarkBarView::Paint(gfx::Canvas* canvas) {
- if (IsDetachedStyle()) {
- // Draw the background to match the new tab page.
- ThemeProvider* tp = GetThemeProvider();
- canvas->FillRectInt(
- tp->GetColor(BrowserThemeProvider::COLOR_NTP_BACKGROUND),
- 0, 0, width(), height());
-
- if (tp->HasCustomImage(IDR_THEME_NTP_BACKGROUND)) {
- int tiling = BrowserThemeProvider::NO_REPEAT;
- tp->GetDisplayProperty(BrowserThemeProvider::NTP_BACKGROUND_TILING,
- &tiling);
- int alignment;
- if (tp->GetDisplayProperty(BrowserThemeProvider::NTP_BACKGROUND_ALIGNMENT,
- &alignment)) {
- SkBitmap* ntp_background = tp->GetBitmapNamed(
- IDR_THEME_NTP_BACKGROUND);
-
- if (alignment & BrowserThemeProvider::ALIGN_TOP) {
- PaintThemeBackgroundTopAligned(
- canvas, ntp_background, tiling, alignment);
- } else {
- PaintThemeBackgroundBottomAligned(
- canvas, ntp_background, tiling, alignment);
- }
- }
- }
-
- // Draw the 'bottom' of the toolbar above our bubble.
- canvas->FillRectInt(ResourceBundle::toolbar_separator_color,
- 0, 0, width(), 1);
-
- SkRect rect;
-
- // As 'hidden' according to the animation is the full in-tab state,
- // we invert the value - when current_state is at '0', we expect the
- // bar to be docked.
- double current_state = 1 - size_animation_->GetCurrentValue();
-
- // The 0.5 is to correct for Skia's "draw on pixel boundaries"ness.
- double h_padding = static_cast<double>
- (kNewtabHorizontalPadding) * current_state;
- double v_padding = static_cast<double>
- (kNewtabVerticalPadding) * current_state;
- rect.set(SkDoubleToScalar(h_padding - 0.5),
- SkDoubleToScalar(v_padding - 0.5),
- SkDoubleToScalar(width() - h_padding - 0.5),
- SkDoubleToScalar(height() - v_padding - 0.5));
-
- double roundness = static_cast<double>
- (kNewtabBarRoundness) * current_state;
-
- // Draw our background.
- SkPaint paint;
- paint.setAntiAlias(true);
- paint.setColor(
- GetThemeProvider()->GetColor(BrowserThemeProvider::COLOR_TOOLBAR));
-
- canvas->drawRoundRect(rect,
- SkDoubleToScalar(roundness),
- SkDoubleToScalar(roundness), paint);
-
- // Draw border
- SkPaint border_paint;
- border_paint.setColor(
- GetThemeProvider()->GetColor(BrowserThemeProvider::COLOR_NTP_HEADER));
- border_paint.setStyle(SkPaint::kStroke_Style);
- border_paint.setAlpha(96);
- border_paint.setAntiAlias(true);
-
- canvas->drawRoundRect(rect,
- SkDoubleToScalar(roundness),
- SkDoubleToScalar(roundness), border_paint);
- } else {
- gfx::Rect bounds = GetBounds(views::View::APPLY_MIRRORING_TRANSFORMATION);
-
- SkColor theme_toolbar_color =
- GetThemeProvider()->GetColor(BrowserThemeProvider::COLOR_TOOLBAR);
- canvas->FillRectInt(theme_toolbar_color, 0, 0, width(), height());
-
- canvas->TileImageInt(*GetThemeProvider()->
- GetBitmapNamed(IDR_THEME_TOOLBAR),
- GetParent()->GetBounds(views::View::APPLY_MIRRORING_TRANSFORMATION).x()
- + bounds.x(), bounds.y(), 0, 0, width(), height());
- canvas->FillRectInt(ResourceBundle::toolbar_separator_color,
- 0, height() - 1, width(), 1);
- }
-}
-
-void BookmarkBarView::PaintThemeBackgroundTopAligned(gfx::Canvas* canvas,
- SkBitmap* ntp_background, int tiling, int alignment) {
-
- if (alignment & BrowserThemeProvider::ALIGN_LEFT) {
- if (tiling == BrowserThemeProvider::REPEAT)
- canvas->TileImageInt(*ntp_background, 0, 0, width(), height());
- else if (tiling == BrowserThemeProvider::REPEAT_X)
- canvas->TileImageInt(*ntp_background, 0, 0, width(),
- ntp_background->height());
- else
- canvas->TileImageInt(*ntp_background, 0, 0,
- ntp_background->width(), ntp_background->height());
-
- } else if (alignment & BrowserThemeProvider::ALIGN_RIGHT) {
- int x_pos = width() % ntp_background->width() - ntp_background->width();
- if (tiling == BrowserThemeProvider::REPEAT)
- canvas->TileImageInt(*ntp_background, x_pos, 0,
- width() + ntp_background->width(), height());
- else if (tiling == BrowserThemeProvider::REPEAT_X)
- canvas->TileImageInt(*ntp_background, x_pos,
- 0, width() + ntp_background->width(), ntp_background->height());
- else
- canvas->TileImageInt(*ntp_background, width() - ntp_background->width(),
- 0, ntp_background->width(), ntp_background->height());
-
- } else { // ALIGN == CENTER
- int x_pos = width() > ntp_background->width() ?
- ((width() / 2 - ntp_background->width() / 2) %
- ntp_background->width()) - ntp_background->width() :
- width() / 2 - ntp_background->width() / 2;
- if (tiling == BrowserThemeProvider::REPEAT)
- canvas->TileImageInt(*ntp_background, x_pos, 0,
- width() + ntp_background->width(), height());
- else if (tiling == BrowserThemeProvider::REPEAT_X)
- canvas->TileImageInt(*ntp_background, x_pos, 0,
- width() + ntp_background->width(),
- ntp_background->height());
- else
- canvas->TileImageInt(*ntp_background,
- width() / 2 - ntp_background->width() / 2,
- 0, ntp_background->width(), ntp_background->height());
- }
-}
-
-void BookmarkBarView::PaintThemeBackgroundBottomAligned(gfx::Canvas* canvas,
- SkBitmap* ntp_background, int tiling, int alignment) {
- int browser_height = GetParent()->GetBounds(
- views::View::APPLY_MIRRORING_TRANSFORMATION).height();
- int border_width = 5;
- int y_pos = ((tiling == BrowserThemeProvider::REPEAT_X) ||
- (tiling == BrowserThemeProvider::NO_REPEAT)) ?
- browser_height - ntp_background->height() - height() - border_width :
- browser_height % ntp_background->height() - height() - border_width -
- ntp_background->height();
-
- if (alignment & BrowserThemeProvider::ALIGN_LEFT) {
- if (tiling == BrowserThemeProvider::REPEAT)
- canvas->TileImageInt(*ntp_background, 0, y_pos, width(),
- 2 * height() + ntp_background->height() + 5);
- else if (tiling == BrowserThemeProvider::REPEAT_X)
- canvas->TileImageInt(*ntp_background, 0, y_pos, width(),
- ntp_background->height());
- else if (tiling == BrowserThemeProvider::REPEAT_Y)
- canvas->TileImageInt(*ntp_background, 0, y_pos,
- ntp_background->width(),
- 2 * height() + ntp_background->height() + 5);
- else
- canvas->TileImageInt(*ntp_background, 0, y_pos, ntp_background->width(),
- ntp_background->height());
-
- } else if (alignment & BrowserThemeProvider::ALIGN_RIGHT) {
- int x_pos = width() % ntp_background->width() - ntp_background->width();
- if (tiling == BrowserThemeProvider::REPEAT)
- canvas->TileImageInt(*ntp_background, x_pos, y_pos,
- width() + ntp_background->width(),
- 2 * height() + ntp_background->height() + 5);
- else if (tiling == BrowserThemeProvider::REPEAT_X)
- canvas->TileImageInt(*ntp_background, x_pos, y_pos,
- width() + ntp_background->width(), ntp_background->height());
- else if (tiling == BrowserThemeProvider::REPEAT_Y)
- canvas->TileImageInt(*ntp_background, width() - ntp_background->width(),
- y_pos, ntp_background->width(),
- 2 * height() + ntp_background->height() + 5);
- else
- canvas->TileImageInt(*ntp_background, width() - ntp_background->width(),
- y_pos, ntp_background->width(), ntp_background->height());
-
- } else { // ALIGN == CENTER
- int x_pos = width() > ntp_background->width() ?
- ((width() / 2 - ntp_background->width() / 2) %
- ntp_background->width()) - ntp_background->width() :
- width() / 2 - ntp_background->width() / 2;
- if (tiling == BrowserThemeProvider::REPEAT)
- canvas->TileImageInt(*ntp_background, x_pos, y_pos,
- width() + ntp_background->width(),
- 2 * height() + ntp_background->height() + 5);
- else if (tiling == BrowserThemeProvider::REPEAT_X)
- canvas->TileImageInt(*ntp_background, x_pos, y_pos,
- width() + ntp_background->width(), ntp_background->height());
- else if (tiling == BrowserThemeProvider::REPEAT_Y)
- canvas->TileImageInt(*ntp_background,
- width() / 2 - ntp_background->width() / 2,
- y_pos, ntp_background->width(),
- 2 * height() + ntp_background->height() + 5);
- else
- canvas->TileImageInt(*ntp_background,
- width() / 2 - ntp_background->width() / 2,
- y_pos, ntp_background->width(), ntp_background->height());
- }
-}
-
void BookmarkBarView::PaintChildren(gfx::Canvas* canvas) {
View::PaintChildren(canvas);
@@ -1872,6 +1549,151 @@ void BookmarkBarView::UpdateButtonColors() {
}
}
+gfx::Size BookmarkBarView::LayoutItems(bool compute_bounds_only) {
+ gfx::Size prefsize;
+ if (!GetParent() && !compute_bounds_only)
+ return prefsize;
+
+ int x = kLeftMargin;
+ int y = kTopMargin;
+ int width = View::width() - kRightMargin - kLeftMargin;
+ int height = View::height() - kTopMargin - kBottomMargin;
+ int separator_margin = kSeparatorMargin;
+
+ if (OnNewTabPage()) {
+ double current_state = 1 - size_animation_->GetCurrentValue();
+ x += static_cast<int>(static_cast<double>
+ (kNewtabHorizontalPadding) * current_state);
+ y += static_cast<int>(static_cast<double>
+ (kNewtabVerticalPadding) * current_state);
+ width -= static_cast<int>(static_cast<double>
+ (kNewtabHorizontalPadding) * current_state);
+ height -= static_cast<int>(static_cast<double>
+ (kNewtabVerticalPadding * 2) * current_state);
+ separator_margin -= static_cast<int>(static_cast<double>
+ (kSeparatorMargin) * current_state);
+ }
+
+ gfx::Size other_bookmarked_pref =
+ other_bookmarked_button_->GetPreferredSize();
+ gfx::Size overflow_pref = overflow_button_->GetPreferredSize();
+ gfx::Size bookmarks_separator_pref =
+ bookmarks_separator_view_->GetPreferredSize();
+
+#ifdef CHROME_PERSONALIZATION
+ gfx::Size sync_error_button_pref = sync_error_button_->GetPreferredSize();
+ const bool should_show_sync_error_button = ShouldShowSyncErrorButton();
+ int sync_error_total_width = 0;
+ if (should_show_sync_error_button) {
+ sync_error_total_width += kButtonPadding + sync_error_button_pref.width();
+ }
+ const int max_x = width - other_bookmarked_pref.width() - kButtonPadding -
+ overflow_pref.width() - kButtonPadding -
+ bookmarks_separator_pref.width() - sync_error_total_width;
+#else
+ const int max_x = width - other_bookmarked_pref.width() - kButtonPadding -
+ overflow_pref.width() - kButtonPadding -
+ bookmarks_separator_pref.width();
+#endif
+
+ // Next, layout out the buttons. Any buttons that are placed beyond the
+ // visible region and made invisible.
+ if (GetBookmarkButtonCount() == 0 && model_ && model_->IsLoaded()) {
+ gfx::Size pref = instructions_->GetPreferredSize();
+ if (!compute_bounds_only) {
+ instructions_->SetBounds(
+ x + kInstructionsPadding, y,
+ std::min(static_cast<int>(pref.width()),
+ max_x - x),
+ height);
+ instructions_->SetVisible(true);
+ }
+ } else {
+ if (!compute_bounds_only)
+ instructions_->SetVisible(false);
+
+ for (int i = 0; i < GetBookmarkButtonCount(); ++i) {
+ views::View* child = GetChildViewAt(i);
+ gfx::Size pref = child->GetPreferredSize();
+ int next_x = x + pref.width() + kButtonPadding;
+ if (!compute_bounds_only) {
+ 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 ||
+ GetChildViewAt(GetBookmarkButtonCount() - 1)->IsVisible());
+
+ // Layout the right side buttons.
+ if (!compute_bounds_only)
+ x = max_x + kButtonPadding;
+ else
+ x += kButtonPadding;
+
+ // The overflow button.
+ if (!compute_bounds_only) {
+ overflow_button_->SetBounds(x, y, overflow_pref.width(), height);
+ overflow_button_->SetVisible(!all_visible);
+ }
+ x += overflow_pref.width();
+
+ // Separator.
+ if (!compute_bounds_only) {
+ bookmarks_separator_view_->SetBounds(x,
+ y - kTopMargin,
+ bookmarks_separator_pref.width(),
+ height + kTopMargin + kBottomMargin -
+ separator_margin);
+ }
+
+ x += bookmarks_separator_pref.width();
+
+ // The other bookmarks button.
+ if (!compute_bounds_only) {
+ other_bookmarked_button_->SetBounds(x, y, other_bookmarked_pref.width(),
+ height);
+ }
+ x += other_bookmarked_pref.width() + kButtonPadding;
+
+#ifdef CHROME_PERSONALIZATION
+ // Set the real bounds of the sync error button only if it needs to appear on
+ // the bookmarks bar.
+ if (should_show_sync_error_button) {
+ x += kButtonPadding;
+ if (!compute_bounds_only) {
+ sync_error_button_->SetBounds(x, y, sync_error_button_pref.width(), height);
+ sync_error_button_->SetVisible(true);
+ }
+ x += sync_error_button_pref.width();
+ } else if (!compute_bounds_only) {
+ sync_error_button_->SetBounds(x, y, 0, height);
+ sync_error_button_->SetVisible(false);
+ }
+#endif
+
+ // Set the preferred size computed so far.
+ if (compute_bounds_only) {
+ x += kRightMargin;
+ prefsize.set_width(x);
+ if (OnNewTabPage()) {
+ x += static_cast<int>(static_cast<double>(kNewtabHorizontalPadding) *
+ (1 - size_animation_->GetCurrentValue()));
+ prefsize.set_height(kBarHeight + static_cast<int>(static_cast<double>
+ (kNewtabBarHeight - kBarHeight) *
+ (1 - size_animation_->GetCurrentValue())));
+ } else {
+ prefsize.set_height(static_cast<int>(static_cast<double>(kBarHeight) *
+ size_animation_->GetCurrentValue()));
+ }
+ }
+ return prefsize;
+}
+
#ifdef CHROME_PERSONALIZATION
// The sync state reported by the profile sync service determines whether or
// not the re-login indicator button should be visible.
@@ -1907,3 +1729,4 @@ views::TextButton* BookmarkBarView::CreateSyncErrorButton() {
return sync_error_button;
}
#endif
+
diff --git a/chrome/browser/views/bookmark_bar_view.h b/chrome/browser/views/bookmark_bar_view.h
index caca1aa..4cb02f8 100644
--- a/chrome/browser/views/bookmark_bar_view.h
+++ b/chrome/browser/views/bookmark_bar_view.h
@@ -95,7 +95,6 @@ class BookmarkBarView : public views::View,
virtual void DidChangeBounds(const gfx::Rect& previous,
const gfx::Rect& current);
virtual void ViewHierarchyChanged(bool is_add, View* parent, View* child);
- virtual void Paint(gfx::Canvas* canvas);
virtual void PaintChildren(gfx::Canvas* canvas);
virtual bool GetDropFormats(
int* formats,
@@ -109,6 +108,9 @@ class BookmarkBarView : public views::View,
virtual bool GetAccessibleName(std::wstring* name);
virtual bool GetAccessibleRole(AccessibilityTypes::Role* role);
virtual void SetAccessibleName(const std::wstring& name);
+ double GetSizeAnimationValue() const {
+ return size_animation_->GetCurrentValue();
+ }
#ifdef CHROME_PERSONALIZATION
// ProfileSyncServiceObserver method.
@@ -192,16 +194,15 @@ class BookmarkBarView : public views::View,
// If true we're running tests. This short circuits a couple of animations.
static bool testing_;
+ // Constants used in Browser View, as well as here.
+ // How inset the bookmarks bar is when displayed on the new tab page.
+ static const int kNewtabHorizontalPadding;
+ static const int kNewtabVerticalPadding;
+
private:
class ButtonSeparatorView;
struct DropInfo;
- // Paint the theme background with the proper alignment.
- void PaintThemeBackgroundTopAligned(gfx::Canvas* canvas,
- SkBitmap* ntp_background, int tiling, int alignment);
- void PaintThemeBackgroundBottomAligned(gfx::Canvas* canvas,
- SkBitmap* ntp_background, int tiling, int alignment);
-
// Task that invokes ShowDropFolderForNode when run. ShowFolderDropMenuTask
// deletes itself once run.
class ShowFolderDropMenuTask : public Task {
@@ -396,6 +397,12 @@ class BookmarkBarView : public views::View,
// Updates the colors for all the buttons in the bookmarks bar.
void UpdateButtonColors();
+ // This method computes the bounds for the bookmark bar items. If
+ // |compute_bounds_only| = TRUE, the bounds for the items are just computed,
+ // but are not set. This mode is used by GetPreferredSize() to obtain the
+ // desired bounds. If |compute_bounds_only| = FALSE, the bounds are set.
+ gfx::Size LayoutItems(bool compute_bounds_only);
+
#ifdef CHROME_PERSONALIZATION
// Determines whether the sync error button should appear on the bookmarks
// bar.
@@ -404,7 +411,6 @@ class BookmarkBarView : public views::View,
// Creates the sync error button and adds it as a child view.
views::TextButton* CreateSyncErrorButton();
#endif
-
NotificationRegistrar registrar_;
Profile* profile_;
@@ -454,7 +460,7 @@ class BookmarkBarView : public views::View,
ButtonSeparatorView* bookmarks_separator_view_;
- // Owning browser. This is NULL duing testing.
+ // Owning browser. This is NULL during testing.
Browser* browser_;
// Animation controlling showing and hiding of the bar.
diff --git a/chrome/browser/views/extensions/extension_shelf.cc b/chrome/browser/views/extensions/extension_shelf.cc
index 0d0fb0a..6841dc9 100644
--- a/chrome/browser/views/extensions/extension_shelf.cc
+++ b/chrome/browser/views/extensions/extension_shelf.cc
@@ -698,24 +698,7 @@ void ExtensionShelf::ToggleWhenExtensionShelfVisible(Profile* profile) {
}
gfx::Size ExtensionShelf::GetPreferredSize() {
- if (!model_->count())
- return gfx::Size(0, 0);
-
- gfx::Size prefsize;
- if (OnNewTabPage()) {
- prefsize.set_height(kShelfHeight + static_cast<int>(static_cast<double>
- (kNewtabShelfHeight - kShelfHeight) *
- (1 - size_animation_->GetCurrentValue())));
- } else {
- prefsize.set_height(static_cast<int>(static_cast<double>(kShelfHeight) *
- size_animation_->GetCurrentValue()));
- }
-
- // Width doesn't matter, we're always given a width based on the browser
- // size.
- prefsize.set_width(1);
-
- return prefsize;
+ return LayoutItems(true);
}
void ExtensionShelf::ChildPreferredSizeChanged(View* child) {
@@ -726,46 +709,10 @@ void ExtensionShelf::ChildPreferredSizeChanged(View* child) {
}
void ExtensionShelf::Layout() {
- if (!GetParent())
- return;
- if (!model_)
- return;
-
- int x = kLeftMargin;
- int y = kTopMargin;
- int content_height = kShelfHeight - kTopMargin - kBottomMargin;
- int max_x = width() - kRightMargin;
-
- if (OnNewTabPage()) {
- double current_state = 1 - size_animation_->GetCurrentValue();
- x += static_cast<int>(static_cast<double>
- (kNewtabHorizontalPadding + kNewtabExtraHorMargin) * current_state);
- y += static_cast<int>(static_cast<double>
- (kNewtabVerticalPadding + kNewtabExtraVerMargin) * current_state);
- max_x -= static_cast<int>(static_cast<double>
- (kNewtabHorizontalPadding) * current_state);
- }
-
- int count = model_->count();
- for (int i = 0; i < count; ++i) {
- x += kToolstripPadding; // left padding
- Toolstrip* toolstrip = ToolstripAtIndex(i);
- if (!toolstrip) // can be NULL while in the process of removing
- continue;
- View* view = toolstrip->GetShelfView();
- gfx::Size pref = view->GetPreferredSize();
- int next_x = x + pref.width() + kToolstripPadding; // right padding
- if (view == toolstrip->view())
- toolstrip->view()->set_is_clipped(next_x >= max_x);
- view->SetBounds(x, y, pref.width(), content_height);
- view->Layout();
- if (toolstrip->handle_visible())
- toolstrip->LayoutHandle();
- x = next_x + kToolstripDividerWidth;
- }
- SchedulePaint();
+ LayoutItems(false);
}
+
void ExtensionShelf::OnMouseEntered(const views::MouseEvent& event) {
}
@@ -1004,6 +951,66 @@ void ExtensionShelf::LoadFromModel() {
ToolstripInsertedAt(model_->ToolstripAt(i).host, i);
}
+gfx::Size ExtensionShelf::LayoutItems(bool compute_bounds_only) {
+ if (!GetParent() || !model_ || !model_->count())
+ return gfx::Size(0, 0);
+
+ gfx::Size prefsize;
+ int x = kLeftMargin;
+ int y = kTopMargin;
+ int content_height = kShelfHeight - kTopMargin - kBottomMargin;
+ int max_x = width() - kRightMargin;
+
+ if (OnNewTabPage()) {
+ double current_state = 1 - size_animation_->GetCurrentValue();
+ x += static_cast<int>(static_cast<double>
+ (kNewtabHorizontalPadding + kNewtabExtraHorMargin) * current_state);
+ y += static_cast<int>(static_cast<double>
+ (kNewtabVerticalPadding + kNewtabExtraVerMargin) * current_state);
+ max_x -= static_cast<int>(static_cast<double>
+ (kNewtabHorizontalPadding) * current_state);
+ }
+
+ int count = model_->count();
+ for (int i = 0; i < count; ++i) {
+ x += kToolstripPadding; // left padding
+ Toolstrip* toolstrip = ToolstripAtIndex(i);
+ if (!toolstrip) // can be NULL while in the process of removing
+ continue;
+ View* view = toolstrip->GetShelfView();
+ gfx::Size pref = view->GetPreferredSize();
+ int next_x = x + pref.width() + kToolstripPadding; // right padding
+ if (!compute_bounds_only) {
+ if (view == toolstrip->view())
+ toolstrip->view()->set_is_clipped(next_x >= max_x);
+ view->SetBounds(x, y, pref.width(), content_height);
+ view->Layout();
+ if (toolstrip->handle_visible())
+ toolstrip->LayoutHandle();
+ }
+ x = next_x + kToolstripDividerWidth;
+ }
+
+ if (!compute_bounds_only)
+ SchedulePaint();
+
+ if (compute_bounds_only) {
+ if (OnNewTabPage()) {
+ prefsize.set_height(kShelfHeight + static_cast<int>(static_cast<double>
+ (kNewtabShelfHeight - kShelfHeight) *
+ (1 - size_animation_->GetCurrentValue())));
+ } else {
+ prefsize.set_height(static_cast<int>(static_cast<double>(kShelfHeight) *
+ size_animation_->GetCurrentValue()));
+ }
+
+ x += kRightMargin;
+ prefsize.set_width(x);
+ }
+
+ return prefsize;
+}
+
bool ExtensionShelf::IsDetachedStyle() {
return OnNewTabPage() && (size_animation_->GetCurrentValue() != 1);
}
diff --git a/chrome/browser/views/extensions/extension_shelf.h b/chrome/browser/views/extensions/extension_shelf.h
index 08f3d1c..3f994e4 100644
--- a/chrome/browser/views/extensions/extension_shelf.h
+++ b/chrome/browser/views/extensions/extension_shelf.h
@@ -108,6 +108,12 @@ class ExtensionShelf : public views::View,
// Loads initial state from |model_|.
void LoadFromModel();
+ // This method computes the bounds for the extension shelf items. If
+ // |compute_bounds_only| = TRUE, the bounds for the items are just computed,
+ // but are not set. This mode is used by GetPreferredSize() to obtain the
+ // desired bounds. If |compute_bounds_only| = FALSE, the bounds are set.
+ gfx::Size LayoutItems(bool compute_bounds_only);
+
// Returns whether the extension shelf always shown (checks pref value).
bool IsAlwaysShown();
diff --git a/chrome/browser/views/frame/browser_view.cc b/chrome/browser/views/frame/browser_view.cc
index b7e7f28..c7ee766 100644
--- a/chrome/browser/views/frame/browser_view.cc
+++ b/chrome/browser/views/frame/browser_view.cc
@@ -109,9 +109,273 @@ static const int kWindowBorderWidth = 5;
// If not -1, windows are shown with this state.
static int explicit_show_state = -1;
+static const float kMinimumBookmarkBarWidthAsRatioOfWidth = 0.5;
+
+// How round the 'new tab' style bookmarks bar is.
+static const int kNewtabBarRoundness = 5;
+// ------------
+
// Returned from BrowserView::GetClassName.
static const char kBrowserViewClassName[] = "browser/views/BrowserView";
+
+///////////////////////////////////////////////////////////////////////////////
+// BookmarkExtensionBackground, private:
+// This object serves as the views::Background object which is used to layout
+// and paint the bookmark bar.
+class BookmarkExtensionBackground : public views::Background {
+ public:
+ explicit BookmarkExtensionBackground(BrowserView* browser_view);
+
+ // View methods overridden from views:Background.
+ virtual void Paint(gfx::Canvas* canvas, views::View* view) const;
+
+ private:
+ // Paint the theme background with the proper alignment.
+ void PaintThemeBackgroundTopAligned(gfx::Canvas* canvas,
+ SkBitmap* ntp_background, int tiling, int alignment) const;
+ void PaintThemeBackgroundBottomAligned(gfx::Canvas* canvas,
+ SkBitmap* ntp_background, int tiling, int alignment) const;
+
+ BrowserView* browser_view_;
+
+ DISALLOW_COPY_AND_ASSIGN(BookmarkExtensionBackground);
+};
+
+BookmarkExtensionBackground::BookmarkExtensionBackground(
+ BrowserView* browser_view)
+ : browser_view_(browser_view) {
+}
+
+void BookmarkExtensionBackground::Paint(gfx::Canvas* canvas,
+ views::View* view) const {
+ // Paint the bookmark bar.
+ BookmarkBarView* bookmark_bar_view = browser_view_->GetBookmarkBarView();
+ if (bookmark_bar_view->IsDetachedStyle()) {
+ // Draw the background to match the new tab page.
+ ThemeProvider* tp = bookmark_bar_view->GetThemeProvider();
+ canvas->FillRectInt(
+ tp->GetColor(BrowserThemeProvider::COLOR_NTP_BACKGROUND),
+ 0, 0, bookmark_bar_view->width(), bookmark_bar_view->height());
+
+ if (tp->HasCustomImage(IDR_THEME_NTP_BACKGROUND)) {
+ int tiling = BrowserThemeProvider::NO_REPEAT;
+ tp->GetDisplayProperty(BrowserThemeProvider::NTP_BACKGROUND_TILING,
+ &tiling);
+ int alignment;
+ if (tp->GetDisplayProperty(BrowserThemeProvider::NTP_BACKGROUND_ALIGNMENT,
+ &alignment)) {
+ SkBitmap* ntp_background = tp->GetBitmapNamed(
+ IDR_THEME_NTP_BACKGROUND);
+
+ if (alignment & BrowserThemeProvider::ALIGN_TOP) {
+ PaintThemeBackgroundTopAligned(canvas, ntp_background, tiling,
+ alignment);
+ } else {
+ PaintThemeBackgroundBottomAligned(canvas, ntp_background, tiling,
+ alignment);
+ }
+ }
+ }
+
+ // Draw the 'bottom' of the toolbar above our bubble.
+ canvas->FillRectInt(ResourceBundle::toolbar_separator_color, 0, 0,
+ bookmark_bar_view->width(), 1);
+
+ SkRect rect;
+
+ // As 'hidden' according to the animation is the full in-tab state,
+ // we invert the value - when current_state is at '0', we expect the
+ // bar to be docked.
+ double current_state = 1 - bookmark_bar_view->GetSizeAnimationValue();
+
+ // The 0.5 is to correct for Skia's "draw on pixel boundaries"ness.
+ double h_padding = static_cast<double>
+ (BookmarkBarView::kNewtabHorizontalPadding) * current_state;
+ double v_padding = static_cast<double>
+ (BookmarkBarView::kNewtabVerticalPadding) * current_state;
+ rect.set(SkDoubleToScalar(h_padding - 0.5),
+ SkDoubleToScalar(v_padding - 0.5),
+ SkDoubleToScalar(bookmark_bar_view->width() - h_padding - 0.5),
+ SkDoubleToScalar(bookmark_bar_view->height() - v_padding - 0.5));
+
+ double roundness = static_cast<double>
+ (kNewtabBarRoundness) * current_state;
+
+ // Draw our background.
+ SkPaint paint;
+ paint.setAntiAlias(true);
+ paint.setColor(bookmark_bar_view->GetThemeProvider()->GetColor(
+ BrowserThemeProvider::COLOR_TOOLBAR));
+
+ canvas->drawRoundRect(rect,
+ SkDoubleToScalar(roundness),
+ SkDoubleToScalar(roundness), paint);
+
+ // Draw border
+ SkPaint border_paint;
+ border_paint.setColor(bookmark_bar_view->GetThemeProvider()->GetColor(
+ BrowserThemeProvider::COLOR_NTP_HEADER));
+ border_paint.setStyle(SkPaint::kStroke_Style);
+ border_paint.setAlpha(96);
+ border_paint.setAntiAlias(true);
+
+ canvas->drawRoundRect(rect,
+ SkDoubleToScalar(roundness),
+ SkDoubleToScalar(roundness), border_paint);
+ } else {
+ gfx::Rect bounds = bookmark_bar_view->GetBounds(views::View::
+ APPLY_MIRRORING_TRANSFORMATION);
+
+ SkColor theme_toolbar_color =
+ bookmark_bar_view->GetThemeProvider()->GetColor(BrowserThemeProvider::
+ COLOR_TOOLBAR);
+ canvas->FillRectInt(theme_toolbar_color, 0, 0,
+ bookmark_bar_view->width(),
+ bookmark_bar_view->height());
+
+ canvas->TileImageInt(
+ *browser_view_->GetBookmarkBarView()->GetThemeProvider()->
+ GetBitmapNamed(IDR_THEME_TOOLBAR),
+ bookmark_bar_view->GetParent()->GetBounds(views::
+ View::APPLY_MIRRORING_TRANSFORMATION).x() + bounds.x(), bounds.y(),
+ 0, 0,
+ bookmark_bar_view->width(),
+ bookmark_bar_view->height());
+ canvas->FillRectInt(ResourceBundle::toolbar_separator_color,
+ 0,
+ bookmark_bar_view->height() - 1,
+ bookmark_bar_view->width(), 1);
+ }
+}
+
+void BookmarkExtensionBackground::PaintThemeBackgroundTopAligned(
+ gfx::Canvas* canvas, SkBitmap* ntp_background, int tiling,
+ int alignment) const {
+ BookmarkBarView* bookmark_bar_view = browser_view_->GetBookmarkBarView();
+ if (alignment & BrowserThemeProvider::ALIGN_LEFT) {
+ if (tiling == BrowserThemeProvider::REPEAT)
+ canvas->TileImageInt(*ntp_background, 0, 0,
+ bookmark_bar_view->width(), bookmark_bar_view->height());
+ else if (tiling == BrowserThemeProvider::REPEAT_X)
+ canvas->TileImageInt(*ntp_background, 0, 0,
+ bookmark_bar_view->width(),
+ ntp_background->height());
+ else
+ canvas->TileImageInt(*ntp_background, 0, 0,
+ ntp_background->width(), ntp_background->height());
+
+ } else if (alignment & BrowserThemeProvider::ALIGN_RIGHT) {
+ int x_pos = bookmark_bar_view->width() % ntp_background->width() -
+ ntp_background->width();
+ if (tiling == BrowserThemeProvider::REPEAT)
+ canvas->TileImageInt(*ntp_background, x_pos, 0,
+ bookmark_bar_view->width() + ntp_background->width(),
+ bookmark_bar_view->height());
+ else if (tiling == BrowserThemeProvider::REPEAT_X)
+ canvas->TileImageInt(*ntp_background, x_pos,
+ 0, bookmark_bar_view->width() + ntp_background->width(),
+ ntp_background->height());
+ else
+ canvas->TileImageInt(*ntp_background,
+ bookmark_bar_view->width() - ntp_background->width(), 0,
+ ntp_background->width(), ntp_background->height());
+
+ } else { // ALIGN == CENTER
+ int x_pos = bookmark_bar_view->width() > ntp_background->width() ?
+ ((bookmark_bar_view->width() / 2 - ntp_background->width() / 2) %
+ ntp_background->width()) - ntp_background->width() :
+ bookmark_bar_view->width() / 2 - ntp_background->width() / 2;
+ if (tiling == BrowserThemeProvider::REPEAT)
+ canvas->TileImageInt(*ntp_background, x_pos, 0,
+ bookmark_bar_view->width() + ntp_background->width(),
+ bookmark_bar_view->height());
+ else if (tiling == BrowserThemeProvider::REPEAT_X)
+ canvas->TileImageInt(*ntp_background, x_pos, 0,
+ bookmark_bar_view->width() + ntp_background->width(),
+ ntp_background->height());
+ else
+ canvas->TileImageInt(*ntp_background,
+ bookmark_bar_view->width() / 2 - ntp_background->width() / 2,
+ 0, ntp_background->width(), ntp_background->height());
+ }
+}
+
+void BookmarkExtensionBackground::PaintThemeBackgroundBottomAligned(
+ gfx::Canvas* canvas, SkBitmap* ntp_background, int tiling,
+ int alignment) const {
+ BookmarkBarView* bookmark_bar_view = browser_view_->GetBookmarkBarView();
+ int browser_height = bookmark_bar_view->GetParent()->GetBounds(
+ views::View::APPLY_MIRRORING_TRANSFORMATION).height();
+ int border_width = 5;
+ int y_pos = ((tiling == BrowserThemeProvider::REPEAT_X) ||
+ (tiling == BrowserThemeProvider::NO_REPEAT)) ?
+ browser_height - ntp_background->height() - bookmark_bar_view->height() -
+ border_width :
+ browser_height % ntp_background->height() - bookmark_bar_view->height() -
+ border_width - ntp_background->height();
+
+ if (alignment & BrowserThemeProvider::ALIGN_LEFT) {
+ if (tiling == BrowserThemeProvider::REPEAT)
+ canvas->TileImageInt(*ntp_background, 0, y_pos,
+ bookmark_bar_view->width(),
+ 2 * bookmark_bar_view->height() + ntp_background->height() + 5);
+ else if (tiling == BrowserThemeProvider::REPEAT_X)
+ canvas->TileImageInt(*ntp_background, 0, y_pos,
+ bookmark_bar_view->width(), ntp_background->height());
+ else if (tiling == BrowserThemeProvider::REPEAT_Y)
+ canvas->TileImageInt(*ntp_background, 0, y_pos,
+ ntp_background->width(),
+ 2 * bookmark_bar_view->height() + ntp_background->height() + 5);
+ else
+ canvas->TileImageInt(*ntp_background, 0, y_pos, ntp_background->width(),
+ ntp_background->height());
+
+ } else if (alignment & BrowserThemeProvider::ALIGN_RIGHT) {
+ int x_pos = bookmark_bar_view->width() % ntp_background->width() -
+ ntp_background->width();
+ if (tiling == BrowserThemeProvider::REPEAT)
+ canvas->TileImageInt(*ntp_background, x_pos, y_pos,
+ bookmark_bar_view->width() + ntp_background->width(),
+ 2 * bookmark_bar_view->height() + ntp_background->height() + 5);
+ else if (tiling == BrowserThemeProvider::REPEAT_X)
+ canvas->TileImageInt(*ntp_background, x_pos, y_pos,
+ bookmark_bar_view->width() + ntp_background->width(),
+ ntp_background->height());
+ else if (tiling == BrowserThemeProvider::REPEAT_Y)
+ canvas->TileImageInt(*ntp_background, bookmark_bar_view->width() -
+ ntp_background->width(), y_pos, ntp_background->width(),
+ 2 * bookmark_bar_view->height() + ntp_background->height() + 5);
+ else
+ canvas->TileImageInt(*ntp_background,
+ bookmark_bar_view->width() - ntp_background->width(),
+ y_pos, ntp_background->width(), ntp_background->height());
+
+ } else { // ALIGN == CENTER
+ int x_pos = bookmark_bar_view->width() > ntp_background->width() ?
+ ((bookmark_bar_view->width() / 2 - ntp_background->width() / 2) %
+ ntp_background->width()) - ntp_background->width() :
+ bookmark_bar_view->width() / 2 - ntp_background->width() / 2;
+ if (tiling == BrowserThemeProvider::REPEAT)
+ canvas->TileImageInt(*ntp_background, x_pos, y_pos,
+ bookmark_bar_view->width() + ntp_background->width(),
+ 2 * bookmark_bar_view->height() + ntp_background->height() + 5);
+ else if (tiling == BrowserThemeProvider::REPEAT_X)
+ canvas->TileImageInt(*ntp_background, x_pos, y_pos,
+ bookmark_bar_view->width() + ntp_background->width(),
+ ntp_background->height());
+ else if (tiling == BrowserThemeProvider::REPEAT_Y)
+ canvas->TileImageInt(*ntp_background,
+ bookmark_bar_view->width() / 2 - ntp_background->width() / 2,
+ y_pos, ntp_background->width(),
+ 2 * bookmark_bar_view->height() + ntp_background->height() + 5);
+ else
+ canvas->TileImageInt(*ntp_background,
+ bookmark_bar_view->width() / 2 - ntp_background->width() / 2,
+ y_pos, ntp_background->width(), ntp_background->height());
+ }
+}
+
///////////////////////////////////////////////////////////////////////////////
// ResizeCorner, private:
@@ -311,7 +575,7 @@ BrowserView::~BrowserView() {
// notifications will call back into deleted objects).
download_shelf_.reset();
- // Explicitly set browser_ to NULL
+ // Explicitly set browser_ to NULL.
browser_.reset();
}
@@ -1586,28 +1850,57 @@ int BrowserView::LayoutBookmarkAndInfoBars(int top) {
// any Info bar _above_ the Bookmark bar, since the Bookmark bar is styled
// to look like it's part of the page.
if (bookmark_bar_view_->IsDetachedStyle())
- return LayoutBookmarkBar(LayoutInfoBar(top));
+ return LayoutTopBar(LayoutInfoBar(top));
// Otherwise, Bookmark bar first, Info bar second.
- top = LayoutBookmarkBar(top);
+ top = LayoutTopBar(top);
}
find_bar_y_ = top + y() - 1;
return LayoutInfoBar(top);
}
-int BrowserView::LayoutBookmarkBar(int top) {
+int BrowserView::LayoutTopBar(int top) {
DCHECK(active_bookmark_bar_);
- bool visible = IsBookmarkBarVisible();
- int height, y = top;
- if (visible) {
- y -= kSeparationLineHeight + (bookmark_bar_view_->IsDetachedStyle() ?
- 0 : bookmark_bar_view_->GetToolbarOverlap(false));
- height = bookmark_bar_view_->GetPreferredSize().height();
- } else {
- height = 0;
+ int y = top;
+ if (!IsBookmarkBarVisible()) {
+ bookmark_bar_view_->SetVisible(false);
+ bookmark_bar_view_->SetBounds(0, y, width(), 0);
+ if (ShowExtensionsOnTop())
+ extension_shelf_->SetVisible(false);
+ return y;
+ }
+
+ int bookmark_bar_width = width();
+ int bookmark_bar_height = bookmark_bar_view_->GetPreferredSize().height();
+ y -= kSeparationLineHeight + (bookmark_bar_view_->IsDetachedStyle() ?
+ 0 : bookmark_bar_view_->GetToolbarOverlap(false));
+
+ if (ShowExtensionsOnTop()) {
+ int extensionshelf_height = extension_shelf_->GetPreferredSize().height();
+ if (extensionshelf_height >= bookmark_bar_height)
+ bookmark_bar_height = extensionshelf_height;
+
+ if (!bookmark_bar_view_->IsDetachedStyle()) {
+ int extension_shelf_min_width =
+ extension_shelf_->GetPreferredSize().width();
+ bookmark_bar_width -= extension_shelf_min_width;
+ int minimum_allowed_bookmark_bar_width =
+ static_cast<int>(width() * kMinimumBookmarkBarWidthAsRatioOfWidth);
+ if (bookmark_bar_width < minimum_allowed_bookmark_bar_width)
+ bookmark_bar_width = minimum_allowed_bookmark_bar_width;
+ extension_shelf_->SetVisible(true);
+ extension_shelf_->SetBounds(bookmark_bar_width, y,
+ width() - bookmark_bar_width,
+ bookmark_bar_height);
+ } else {
+ // TODO (sidchat): For detached style bookmark bar, set the extensions
+ // shelf in a better position. Issue = 20741.
+ extension_shelf_->SetVisible(false);
+ }
}
- bookmark_bar_view_->SetVisible(visible);
- bookmark_bar_view_->SetBounds(0, y, width(), height);
- return y + height;
+
+ bookmark_bar_view_->SetVisible(true);
+ bookmark_bar_view_->SetBounds(0, y, bookmark_bar_width, bookmark_bar_height);
+ return y + bookmark_bar_height;
}
int BrowserView::LayoutInfoBar(int top) {
@@ -1667,6 +1960,9 @@ void BrowserView::LayoutStatusBubble(int top) {
}
int BrowserView::LayoutExtensionShelf(int bottom) {
+ if (ShowExtensionsOnTop())
+ return bottom;
+
if (extension_shelf_) {
bool visible = browser_->SupportsWindowFeature(
Browser::FEATURE_EXTENSIONSHELF);
@@ -1688,6 +1984,7 @@ bool BrowserView::MaybeShowBookmarkBar(TabContents* contents) {
bookmark_bar_view_.reset(new BookmarkBarView(contents->profile(),
browser_.get()));
bookmark_bar_view_->SetParentOwned(false);
+ bookmark_bar_view_->set_background(new BookmarkExtensionBackground(this));
} else {
bookmark_bar_view_->SetProfile(contents->profile());
}
@@ -1729,6 +2026,7 @@ void BrowserView::UpdateDevToolsForContents(TabContents* tab_contents) {
// Store split offset when hiding devtools window only.
g_browser_process->local_state()->SetInteger(
prefs::kDevToolsSplitLocation, contents_split_->divider_offset());
+
// Restore focus to the last focused view when hiding devtools window.
devtools_focus_tracker_->FocusLastFocusedExternalView();
@@ -1972,6 +2270,11 @@ void BrowserView::InitHangMonitor() {
#endif
}
+bool BrowserView::ShowExtensionsOnTop() {
+ return extension_shelf_ && CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kShowExtensionsOnTop);
+}
+
// static
void BrowserView::InitClass() {
static bool initialized = false;
diff --git a/chrome/browser/views/frame/browser_view.h b/chrome/browser/views/frame/browser_view.h
index bbdfd6f..0b97b33 100644
--- a/chrome/browser/views/frame/browser_view.h
+++ b/chrome/browser/views/frame/browser_view.h
@@ -342,7 +342,7 @@ class BrowserView : public BrowserWindow,
// of the bottom of the control, for laying out the next control.
int LayoutToolbar(int top);
int LayoutBookmarkAndInfoBars(int top);
- int LayoutBookmarkBar(int top);
+ int LayoutTopBar(int top);
int LayoutInfoBar(int top);
// Layout the TabContents container, between the coordinates |top| and
// |bottom|.
@@ -404,6 +404,9 @@ class BrowserView : public BrowserWindow,
// Initialize the hung plugin detector.
void InitHangMonitor();
+ // Returns true if extensions and bookmarks are positioned next to each other.
+ bool ShowExtensionsOnTop();
+
// Initialize class statics.
static void InitClass();