diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-09 22:47:22 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-09 22:47:22 +0000 |
commit | 109d31f08853a4aa5c64e3b52ad7d8bf1bce7196 (patch) | |
tree | c857d0d595897144a2a22ae5dfd4ce3bbff9a212 /chrome/browser | |
parent | 1f37cf1e1302c79aa4f1854633c7b38d05432155 (diff) | |
download | chromium_src-109d31f08853a4aa5c64e3b52ad7d8bf1bce7196.zip chromium_src-109d31f08853a4aa5c64e3b52ad7d8bf1bce7196.tar.gz chromium_src-109d31f08853a4aa5c64e3b52ad7d8bf1bce7196.tar.bz2 |
Windows: use NtpBackgroundUtil to draw detached bookmark bar.
BUG=23836
Review URL: http://codereview.chromium.org/268027
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28618 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/views/detachable_toolbar_view.cc | 147 | ||||
-rw-r--r-- | chrome/browser/views/detachable_toolbar_view.h | 19 | ||||
-rw-r--r-- | chrome/browser/views/frame/browser_view.cc | 27 |
3 files changed, 21 insertions, 172 deletions
diff --git a/chrome/browser/views/detachable_toolbar_view.cc b/chrome/browser/views/detachable_toolbar_view.cc index 10613bb..0664d01 100644 --- a/chrome/browser/views/detachable_toolbar_view.cc +++ b/chrome/browser/views/detachable_toolbar_view.cc @@ -20,39 +20,6 @@ const SkColor DetachableToolbarView::kMiddleDividerColor = SkColorSetRGB(194, 205, 212); // static -void DetachableToolbarView::PaintBackgroundDetachedMode(gfx::Canvas* canvas, - views::View* view) { - int browser_height = view->GetParent()->GetBounds( - views::View::APPLY_MIRRORING_TRANSFORMATION).height(); - - // Draw the background to match the new tab page. - ThemeProvider* tp = view->GetThemeProvider(); - canvas->FillRectInt(tp->GetColor(BrowserThemeProvider::COLOR_NTP_BACKGROUND), - 0, 0, view->width(), 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, - view->width(), view->height()); - } else { - PaintThemeBackgroundBottomAligned( - canvas, ntp_background, tiling, alignment, - view->width(), view->height(), browser_height); - } - } - } -} - -// static void DetachableToolbarView::PaintBackgroundAttachedMode(gfx::Canvas* canvas, views::View* view) { gfx::Rect bounds = @@ -153,117 +120,3 @@ void DetachableToolbarView::PaintVerticalDivider( SkIntToScalar(height - vertical_padding) }; canvas->drawRect(rc_down, paint_down); } - -// static -void DetachableToolbarView::PaintThemeBackgroundTopAligned( - gfx::Canvas* canvas, SkBitmap* ntp_background, int tiling, int alignment, - int width, int height) { - 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()); - } - } -} - -// static -void DetachableToolbarView::PaintThemeBackgroundBottomAligned( - gfx::Canvas* canvas, SkBitmap* ntp_background, int tiling, int alignment, - int width, int height, int browser_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()); - } - } -} diff --git a/chrome/browser/views/detachable_toolbar_view.h b/chrome/browser/views/detachable_toolbar_view.h index 266a41d..875ad98 100644 --- a/chrome/browser/views/detachable_toolbar_view.h +++ b/chrome/browser/views/detachable_toolbar_view.h @@ -32,11 +32,6 @@ class DetachableToolbarView : public views::View { virtual double GetAnimationValue() const = 0; // Paint the background (including the theme image behind content area) when - // in bar/shelf is detached from the Chrome frame. - static void PaintBackgroundDetachedMode(gfx::Canvas* canvas, - views::View* view); - - // Paint the background (including the theme image behind content area) when // in bar/shelf is attached to the Chrome frame. static void PaintBackgroundAttachedMode(gfx::Canvas* canvas, views::View* view); @@ -82,20 +77,6 @@ class DetachableToolbarView : public views::View { const SkColor& middle_color, const SkColor& bottom_color); - // Paint the theme background with the proper alignment. - static void PaintThemeBackgroundTopAligned(gfx::Canvas* canvas, - SkBitmap* ntp_background, - int tiling, - int alignment, - int width, - int height); - static void PaintThemeBackgroundBottomAligned(gfx::Canvas* canvas, - SkBitmap* ntp_background, - int tiling, - int alignment, - int width, - int height, - int browser_height); private: DISALLOW_COPY_AND_ASSIGN(DetachableToolbarView); }; diff --git a/chrome/browser/views/frame/browser_view.cc b/chrome/browser/views/frame/browser_view.cc index 32ab509..c3da7dd 100644 --- a/chrome/browser/views/frame/browser_view.cc +++ b/chrome/browser/views/frame/browser_view.cc @@ -24,6 +24,7 @@ #include "chrome/browser/download/download_manager.h" #include "chrome/browser/find_bar.h" #include "chrome/browser/find_bar_controller.h" +#include "chrome/browser/ntp_background_util.h" #include "chrome/browser/page_info_window.h" #include "chrome/browser/profile.h" #include "chrome/browser/view_ids.h" @@ -130,7 +131,8 @@ static const char kBrowserViewClassName[] = "browser/views/BrowserView"; class BookmarkExtensionBackground : public views::Background { public: explicit BookmarkExtensionBackground(BrowserView* browser_view, - DetachableToolbarView* host_view); + DetachableToolbarView* host_view, + Browser* browser); // View methods overridden from views:Background. virtual void Paint(gfx::Canvas* canvas, views::View* view) const; @@ -141,14 +143,18 @@ class BookmarkExtensionBackground : public views::Background { // The view hosting this background. DetachableToolbarView* host_view_; + Browser* browser_; + DISALLOW_COPY_AND_ASSIGN(BookmarkExtensionBackground); }; BookmarkExtensionBackground::BookmarkExtensionBackground( BrowserView* browser_view, - DetachableToolbarView* host_view) + DetachableToolbarView* host_view, + Browser* browser) : browser_view_(browser_view), - host_view_(host_view) { + host_view_(host_view), + browser_(browser) { } void BookmarkExtensionBackground::Paint(gfx::Canvas* canvas, @@ -156,7 +162,14 @@ void BookmarkExtensionBackground::Paint(gfx::Canvas* canvas, ThemeProvider* tp = host_view_->GetThemeProvider(); if (host_view_->IsDetached()) { // Draw the background to match the new tab page. - DetachableToolbarView::PaintBackgroundDetachedMode(canvas, host_view_); + int height = 0; + TabContents* contents = browser_->GetSelectedTabContents(); + if (contents && contents->view()) + height = contents->view()->GetContainerSize().height(); + NtpBackgroundUtil::PaintBackgroundDetachedMode( + host_view_->GetThemeProvider(), canvas, + gfx::Rect(0, 0, host_view_->width(), host_view_->height()), + height); SkRect rect; @@ -1672,7 +1685,8 @@ void BrowserView::Init() { if (browser_->SupportsWindowFeature(Browser::FEATURE_EXTENSIONSHELF)) { extension_shelf_ = new ExtensionShelf(browser_.get()); extension_shelf_->set_background( - new BookmarkExtensionBackground(this, extension_shelf_)); + new BookmarkExtensionBackground(this, extension_shelf_, + browser_.get())); extension_shelf_-> SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_EXTENSIONS)); AddChildView(extension_shelf_); @@ -1886,7 +1900,8 @@ bool BrowserView::MaybeShowBookmarkBar(TabContents* contents) { browser_.get())); bookmark_bar_view_->SetParentOwned(false); bookmark_bar_view_->set_background( - new BookmarkExtensionBackground(this, bookmark_bar_view_.get())); + new BookmarkExtensionBackground(this, bookmark_bar_view_.get(), + browser_.get())); } else { bookmark_bar_view_->SetProfile(contents->profile()); } |