diff options
author | nsylvain@chromium.org <nsylvain@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-15 00:23:34 +0000 |
---|---|---|
committer | nsylvain@chromium.org <nsylvain@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-15 00:23:34 +0000 |
commit | a1f42985d74de36d1fc4fc173b9f2f7da4391d12 (patch) | |
tree | 140ad42c9d736bdd3002fe3df7fe507df63af262 /chrome/browser/views/frame | |
parent | fc2d3fced2e685464564407b14e57077cad3250e (diff) | |
download | chromium_src-a1f42985d74de36d1fc4fc173b9f2f7da4391d12.zip chromium_src-a1f42985d74de36d1fc4fc173b9f2f7da4391d12.tar.gz chromium_src-a1f42985d74de36d1fc4fc173b9f2f7da4391d12.tar.bz2 |
Revert change 26184, 26181 and 26178 to fix
the compile error on the toolkit builder.
TBR:finnur
Review URL: http://codereview.chromium.org/203064
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@26186 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views/frame')
-rw-r--r-- | chrome/browser/views/frame/browser_view.cc | 275 | ||||
-rw-r--r-- | chrome/browser/views/frame/browser_view.h | 3 |
2 files changed, 239 insertions, 39 deletions
diff --git a/chrome/browser/views/frame/browser_view.cc b/chrome/browser/views/frame/browser_view.cc index beef3f4..e42262d 100644 --- a/chrome/browser/views/frame/browser_view.cc +++ b/chrome/browser/views/frame/browser_view.cc @@ -127,59 +127,254 @@ static const char kBrowserViewClassName[] = "browser/views/BrowserView"; // and paint the bookmark bar. class BookmarkExtensionBackground : public views::Background { public: - explicit BookmarkExtensionBackground(BrowserView* browser_view, - DetachableToolbarView* host_view); + explicit BookmarkExtensionBackground(BrowserView* browser_view); // View methods overridden from views:Background. virtual void Paint(gfx::Canvas* canvas, views::View* view) const; private: - BrowserView* browser_view_; + // 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; - // The view hosting this background. - DetachableToolbarView* host_view_; + BrowserView* browser_view_; DISALLOW_COPY_AND_ASSIGN(BookmarkExtensionBackground); }; BookmarkExtensionBackground::BookmarkExtensionBackground( - BrowserView* browser_view, - DetachableToolbarView* host_view) - : browser_view_(browser_view), - host_view_(host_view) { + BrowserView* browser_view) + : browser_view_(browser_view) { } void BookmarkExtensionBackground::Paint(gfx::Canvas* canvas, - views::View* view) const { - ThemeProvider* tp = host_view_->GetThemeProvider(); - if (host_view_->IsDetached()) { + 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. - DetachableToolbarView::PaintBackgroundDetachedMode(canvas, host_view_); + 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 - host_view_->GetAnimationValue(); + 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; + (BookmarkBarView::kNewtabHorizontalPadding) * current_state; double v_padding = static_cast<double> - (BookmarkBarView::kNewtabVerticalPadding) * current_state; - double roundness = 0; - - DetachableToolbarView::CalculateContentArea(current_state, - h_padding, v_padding, - &rect, &roundness, host_view_); - DetachableToolbarView::PaintContentAreaBackground( - canvas, tp, rect, roundness); - DetachableToolbarView::PaintContentAreaBorder(canvas, tp, rect, roundness); - DetachableToolbarView::PaintHorizontalBorder(canvas, host_view_); + (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 { - DetachableToolbarView::PaintBackgroundAttachedMode(canvas, host_view_); - DetachableToolbarView::PaintHorizontalBorder(canvas, host_view_); + 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()); } } @@ -1634,8 +1829,6 @@ void BrowserView::Init() { if (browser_->SupportsWindowFeature(Browser::FEATURE_EXTENSIONSHELF)) { extension_shelf_ = new ExtensionShelf(browser_.get()); - extension_shelf_->set_background( - new BookmarkExtensionBackground(this, extension_shelf_)); extension_shelf_-> SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_EXTENSIONS)); AddChildView(extension_shelf_); @@ -1707,7 +1900,7 @@ int BrowserView::LayoutBookmarkAndInfoBars(int top) { // If we're showing the Bookmark bar in detached style, then we need to show // 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_->IsDetached()) + if (bookmark_bar_view_->IsDetachedStyle()) return LayoutTopBar(LayoutInfoBar(top)); // Otherwise, Bookmark bar first, Info bar second. top = LayoutTopBar(top); @@ -1729,17 +1922,17 @@ int BrowserView::LayoutTopBar(int top) { if (!IsBookmarkBarVisible()) { bookmark_bar_view_->SetVisible(false); bookmark_bar_view_->SetBounds(0, y, width(), 0); - if (extension_shelf_->IsOnTop()) + if (ShowExtensionsOnTop()) extension_shelf_->SetVisible(false); return y; } int bookmark_bar_height = bookmark_bar_view_->GetPreferredSize().height(); - y -= kSeparationLineHeight + (bookmark_bar_view_->IsDetached() ? + y -= kSeparationLineHeight + (bookmark_bar_view_->IsDetachedStyle() ? 0 : bookmark_bar_view_->GetToolbarOverlap(false)); - if (extension_shelf_->IsOnTop()) { - if (!bookmark_bar_view_->IsDetached()) { + if (ShowExtensionsOnTop()) { + if (!bookmark_bar_view_->IsDetachedStyle()) { int extension_shelf_width = extension_shelf_->GetPreferredSize().width(); int bookmark_bar_given_width = width() - extension_shelf_width; @@ -1756,7 +1949,7 @@ int BrowserView::LayoutTopBar(int top) { bookmark_bar_height); x += extension_shelf_width; } else { - // TODO(sidchat): For detached style bookmark bar, set the extensions + // TODO (sidchat): For detached style bookmark bar, set the extensions // shelf in a better position. Issue = 20741. extension_shelf_->SetVisible(false); } @@ -1785,7 +1978,7 @@ int BrowserView::LayoutExtensionAndDownloadShelves() { // to look like it's part of the page. int bottom = height(); if (extension_shelf_) { - if (extension_shelf_->IsDetached()) { + if (extension_shelf_->IsDetachedStyle()) { bottom = LayoutDownloadShelf(bottom); return LayoutExtensionShelf(bottom); } @@ -1824,7 +2017,7 @@ void BrowserView::LayoutStatusBubble(int top) { } int BrowserView::LayoutExtensionShelf(int bottom) { - if (!extension_shelf_ || extension_shelf_->IsOnTop()) + if (ShowExtensionsOnTop()) return bottom; if (extension_shelf_) { @@ -1848,8 +2041,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, bookmark_bar_view_.get())); + bookmark_bar_view_->set_background(new BookmarkExtensionBackground(this)); } else { bookmark_bar_view_->SetProfile(contents->profile()); } @@ -2135,6 +2327,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 89cf05a..2d06f98 100644 --- a/chrome/browser/views/frame/browser_view.h +++ b/chrome/browser/views/frame/browser_view.h @@ -405,6 +405,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(); |